Skip to content

Commit 7918cfc

Browse files
jwerner-chromiumgregkh
authored andcommitted
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>
1 parent acec09e commit 7918cfc

4 files changed

Lines changed: 34 additions & 17 deletions

File tree

‎drivers/firmware/google/memconsole-coreboot.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ struct cbmem_cons {
3333

3434
static struct cbmem_cons __iomem *cbmem_console;
3535

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+
3644
static int memconsole_coreboot_init(phys_addr_t physaddr)
3745
{
3846
struct cbmem_cons __iomem *tmp_cbmc;
@@ -50,9 +58,7 @@ static int memconsole_coreboot_init(phys_addr_t physaddr)
5058
if (!cbmem_console)
5159
return -ENOMEM;
5260

53-
memconsole_setup(cbmem_console->buffer_body,
54-
min(cbmem_console->buffer_cursor, cbmem_console->buffer_size));
55-
61+
memconsole_setup(memconsole_coreboot_read);
5662
return 0;
5763
}
5864

‎drivers/firmware/google/memconsole-x86-legacy.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ struct biosmemcon_ebda {
4848
};
4949
} __packed;
5050

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+
5160
static void found_v1_header(struct biosmemcon_ebda *hdr)
5261
{
5362
pr_info("memconsole: BIOS console v1 EBDA structure found at %p\n",
@@ -56,7 +65,9 @@ static void found_v1_header(struct biosmemcon_ebda *hdr)
5665
hdr->v1.buffer_addr, hdr->v1.start,
5766
hdr->v1.end, hdr->v1.num_chars);
5867

59-
memconsole_setup(phys_to_virt(hdr->v1.buffer_addr), hdr->v1.num_chars);
68+
memconsole_baseaddr = phys_to_virt(hdr->v1.buffer_addr);
69+
memconsole_length = hdr->v1.num_chars;
70+
memconsole_setup(memconsole_read);
6071
}
6172

6273
static void found_v2_header(struct biosmemcon_ebda *hdr)
@@ -67,8 +78,9 @@ static void found_v2_header(struct biosmemcon_ebda *hdr)
6778
hdr->v2.buffer_addr, hdr->v2.start,
6879
hdr->v2.end, hdr->v2.num_bytes);
6980

70-
memconsole_setup(phys_to_virt(hdr->v2.buffer_addr + hdr->v2.start),
71-
hdr->v2.end - hdr->v2.start);
81+
memconsole_baseaddr = phys_to_virt(hdr->v2.buffer_addr + hdr->v2.start);
82+
memconsole_length = hdr->v2.end - hdr->v2.start;
83+
memconsole_setup(memconsole_read);
7284
}
7385

7486
/*

‎drivers/firmware/google/memconsole.c‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,30 @@
2222

2323
#include "memconsole.h"
2424

25-
static char *memconsole_baseaddr;
26-
static size_t memconsole_length;
25+
static ssize_t (*memconsole_read_func)(char *, loff_t, size_t);
2726

2827
static ssize_t memconsole_read(struct file *filp, struct kobject *kobp,
2928
struct bin_attribute *bin_attr, char *buf,
3029
loff_t pos, size_t count)
3130
{
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);
3434
}
3535

3636
static struct bin_attribute memconsole_bin_attr = {
3737
.attr = {.name = "log", .mode = 0444},
3838
.read = memconsole_read,
3939
};
4040

41-
void memconsole_setup(void *baseaddr, size_t length)
41+
void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t))
4242
{
43-
memconsole_baseaddr = baseaddr;
44-
memconsole_length = length;
43+
memconsole_read_func = read_func;
4544
}
4645
EXPORT_SYMBOL(memconsole_setup);
4746

4847
int memconsole_sysfs_init(void)
4948
{
50-
memconsole_bin_attr.size = memconsole_length;
5149
return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
5250
}
5351
EXPORT_SYMBOL(memconsole_sysfs_init);

‎drivers/firmware/google/memconsole.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
#ifndef __FIRMWARE_GOOGLE_MEMCONSOLE_H
1919
#define __FIRMWARE_GOOGLE_MEMCONSOLE_H
2020

21+
#include <linux/types.h>
22+
2123
/*
2224
* memconsole_setup
2325
*
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.
2627
*/
27-
void memconsole_setup(void *baseaddr, size_t length);
28+
void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t));
2829

2930
/*
3031
* memconsole_sysfs_init

0 commit comments

Comments
 (0)