Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: google: memconsole: Make memconsole interface more flexible

This patch redesigns the interface between the generic memconsole driver
and its implementations to become more flexible than a flat memory
buffer with unchanging bounds. This allows memconsoles like coreboot's
to include lines that were added by runtime firmware after the driver
was initialized. Since the console log size is thus no longer static,
this means that the /sys/firmware/log file has to become unseekable.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Julius Werner and committed by
Greg Kroah-Hartman
7918cfc4 acec09e6

+34 -17
+9 -3
drivers/firmware/google/memconsole-coreboot.c
··· 33 33 34 34 static struct cbmem_cons __iomem *cbmem_console; 35 35 36 + static ssize_t memconsole_coreboot_read(char *buf, loff_t pos, size_t count) 37 + { 38 + return memory_read_from_buffer(buf, count, &pos, 39 + cbmem_console->buffer_body, 40 + min(cbmem_console->buffer_cursor, 41 + cbmem_console->buffer_size)); 42 + } 43 + 36 44 static int memconsole_coreboot_init(phys_addr_t physaddr) 37 45 { 38 46 struct cbmem_cons __iomem *tmp_cbmc; ··· 58 50 if (!cbmem_console) 59 51 return -ENOMEM; 60 52 61 - memconsole_setup(cbmem_console->buffer_body, 62 - min(cbmem_console->buffer_cursor, cbmem_console->buffer_size)); 63 - 53 + memconsole_setup(memconsole_coreboot_read); 64 54 return 0; 65 55 } 66 56
+15 -3
drivers/firmware/google/memconsole-x86-legacy.c
··· 48 48 }; 49 49 } __packed; 50 50 51 + static char *memconsole_baseaddr; 52 + static size_t memconsole_length; 53 + 54 + static ssize_t memconsole_read(char *buf, loff_t pos, size_t count) 55 + { 56 + return memory_read_from_buffer(buf, count, &pos, memconsole_baseaddr, 57 + memconsole_length); 58 + } 59 + 51 60 static void found_v1_header(struct biosmemcon_ebda *hdr) 52 61 { 53 62 pr_info("memconsole: BIOS console v1 EBDA structure found at %p\n", ··· 65 56 hdr->v1.buffer_addr, hdr->v1.start, 66 57 hdr->v1.end, hdr->v1.num_chars); 67 58 68 - memconsole_setup(phys_to_virt(hdr->v1.buffer_addr), hdr->v1.num_chars); 59 + memconsole_baseaddr = phys_to_virt(hdr->v1.buffer_addr); 60 + memconsole_length = hdr->v1.num_chars; 61 + memconsole_setup(memconsole_read); 69 62 } 70 63 71 64 static void found_v2_header(struct biosmemcon_ebda *hdr) ··· 78 67 hdr->v2.buffer_addr, hdr->v2.start, 79 68 hdr->v2.end, hdr->v2.num_bytes); 80 69 81 - memconsole_setup(phys_to_virt(hdr->v2.buffer_addr + hdr->v2.start), 82 - hdr->v2.end - hdr->v2.start); 70 + memconsole_baseaddr = phys_to_virt(hdr->v2.buffer_addr + hdr->v2.start); 71 + memconsole_length = hdr->v2.end - hdr->v2.start; 72 + memconsole_setup(memconsole_read); 83 73 } 84 74 85 75 /*
+6 -8
drivers/firmware/google/memconsole.c
··· 22 22 23 23 #include "memconsole.h" 24 24 25 - static char *memconsole_baseaddr; 26 - static size_t memconsole_length; 25 + static ssize_t (*memconsole_read_func)(char *, loff_t, size_t); 27 26 28 27 static ssize_t memconsole_read(struct file *filp, struct kobject *kobp, 29 28 struct bin_attribute *bin_attr, char *buf, 30 29 loff_t pos, size_t count) 31 30 { 32 - return memory_read_from_buffer(buf, count, &pos, memconsole_baseaddr, 33 - memconsole_length); 31 + if (WARN_ON_ONCE(!memconsole_read_func)) 32 + return -EIO; 33 + return memconsole_read_func(buf, pos, count); 34 34 } 35 35 36 36 static struct bin_attribute memconsole_bin_attr = { ··· 38 38 .read = memconsole_read, 39 39 }; 40 40 41 - void memconsole_setup(void *baseaddr, size_t length) 41 + void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t)) 42 42 { 43 - memconsole_baseaddr = baseaddr; 44 - memconsole_length = length; 43 + memconsole_read_func = read_func; 45 44 } 46 45 EXPORT_SYMBOL(memconsole_setup); 47 46 48 47 int memconsole_sysfs_init(void) 49 48 { 50 - memconsole_bin_attr.size = memconsole_length; 51 49 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr); 52 50 } 53 51 EXPORT_SYMBOL(memconsole_sysfs_init);
+4 -3
drivers/firmware/google/memconsole.h
··· 18 18 #ifndef __FIRMWARE_GOOGLE_MEMCONSOLE_H 19 19 #define __FIRMWARE_GOOGLE_MEMCONSOLE_H 20 20 21 + #include <linux/types.h> 22 + 21 23 /* 22 24 * memconsole_setup 23 25 * 24 - * Initialize the memory console from raw (virtual) base 25 - * address and length. 26 + * Initialize the memory console, passing the function to handle read accesses. 26 27 */ 27 - void memconsole_setup(void *baseaddr, size_t length); 28 + void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t)); 28 29 29 30 /* 30 31 * memconsole_sysfs_init