coreboot table bus and framebuffer driver
cover coreboot table bus and framebuffer driver
On many systems, coreboot[1] firmware can initialize graphics hardware and set up a high-resolution linear framebuffer. It exports information about this framebuffer, along with various other information, in a table discoverable via ACPI or a device tree.
coreboot also supports booting Linux directly from flash as a "payload". Projects such as Heads[2], u-root[3], and petitboot[4] provide a minimal userland that can then be used to chainload (via kexec) into a full Linux system loaded from disk or over the network.
Fitting even a minimal Linux system on an SPI flash chip is challenging. Reusing the framebuffer setup from coreboot provides an enormous benefit to these projects by allowing them to omit full graphics drivers from their kernel builds. It also speeds up boot times by avoiding duplicated effort, and because coreboot's graphics initialization is often much faster than the Linux driver.
Patch 1 of this series expands coreboot table support into an enumerable bus that devices can hang off of. Patches 2-3 convert the existing drivers to use the new bus structure instead of ad-hoc platform devices, and patch 4 removes the old coreboot_table_find function.
Finally, patch 5 adds a new driver for the coreboot-initialized framebuffer. It improves on earlier work[5] by being architecture- independent and not needing to scan through low memory.
This patchset has been tested on a Lenovo ThinkPad X220, and earlier versions of these patches have been tested by various members of the coreboot community on other hardware.
[1]: https://www.coreboot.org/Welcome_to_coreboot
[2]: https://github.com/osresearch/heads
[3]: https://github.com/u-root/u-root
[4]: https://www.kernel.org/pub/linux/kernel/people/geoff/petitboot/petitboot.html
[5]: https://mail.coreboot.org/pipermail/coreboot/2014-September/078551.html
Samuel Holland (5):
firmware: coreboot: Expose the coreboot table as a bus
firmware: memconsole: Probe via coreboot bus
firmware: vpd: Probe via coreboot bus
firmware: coreboot: Remove unused coreboot_table_find
firmware: coreboot: Add coreboot framebuffer driver
drivers/firmware/google/Kconfig | 8 ++ drivers/firmware/google/Makefile | 1 + drivers/firmware/google/coreboot_table-acpi.c | 2 +- drivers/firmware/google/coreboot_table-of.c | 2 +- drivers/firmware/google/coreboot_table.c | 130 ++++++++++++++++++------- drivers/firmware/google/coreboot_table.h | 72 +++++++++++--- drivers/firmware/google/framebuffer-coreboot.c | 115 ++++++++++++++++++++++ drivers/firmware/google/memconsole-coreboot.c | 49 ++++------ drivers/firmware/google/vpd.c | 43 +++----- 9 files changed, 313 insertions(+), 109 deletions(-) create mode 100644 drivers/firmware/google/framebuffer-coreboot.c
Signature · 1 line
2.13.6
PATCH 1/5 firmware: coreboot: Expose the coreboot table as a bus
This simplifies creating device drivers for hardware or information described in the coreboot table. It also avoids needing to search through the table every time a driver is loaded.
--- drivers/firmware/google/coreboot_table-acpi.c | 2 +- drivers/firmware/google/coreboot_table-of.c | 2 +- drivers/firmware/google/coreboot_table.c | 121 ++++++++++++++++++++++++-- drivers/firmware/google/coreboot_table.h | 49 +++++++++-- 4 files changed, 156 insertions(+), 18 deletions(-)
drivers/firmware/google/coreboot_table-acpi.c +1 -1
@@ -53,7 +53,7 @@ static int coreboot_table_acpi_probe(struct platform_device *pdev)if (!ptr)return -ENOMEM ; -return coreboot_table_init (ptr); +return coreboot_table_init (&pdev->dev, ptr); }static int coreboot_table_acpi_remove (struct platform_device *pdev)
drivers/firmware/google/coreboot_table-of.c +1 -1
@@ -34,7 +34,7 @@ static int coreboot_table_of_probe(struct platform_device *pdev)if (!ptr)return -ENOMEM ; -return coreboot_table_init (ptr); +return coreboot_table_init (&pdev->dev, ptr); }static int coreboot_table_of_remove (struct platform_device *pdev)
drivers/firmware/google/coreboot_table.c +114 -7
159 lines not on this page · raw message
drivers/firmware/google/coreboot_table.h +40 -9
71 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH 2/5 firmware: memconsole: Probe via coreboot bus
In reply to Samuel HollandRemove the ad-hoc coreboot table search. Now the driver will only be probed when the necessary coreboot table entry has already been found.
--- drivers/firmware/google/memconsole-coreboot.c | 49 ++++++++++----------------- 1 file changed, 17 insertions(+), 32 deletions(-)
drivers/firmware/google/memconsole-coreboot.c +17 -32
@@ -15,9 +15,9 @@* GNU General Public License for more details. */ +#include <linux/device.h> #include <linux/kernel.h> #include <linux/module.h> -#include <linux/platform_device.h> #include "memconsole.h" #include "coreboot_table.h"
@@ -73,18 +73,19 @@ static ssize_t memconsole_coreboot_read(char *buf, loff_t pos, size_t count)return done; } -static int memconsole_coreboot_init (phys_addr_t physaddr) +static int memconsole_probe (struct coreboot_device *dev) {struct cbmem_cons __iomem *tmp_cbmc; - tmp_cbmc =memremap (physaddr,sizeof (*tmp_cbmc),MEMREMAP_WB ); + tmp_cbmc =memremap (dev->cbmem_ref.cbmem_addr, +sizeof (*tmp_cbmc),MEMREMAP_WB );if (!tmp_cbmc)return -ENOMEM ;/* Read size only once to prevent overrun attack through /dev/mem. */ cbmem_console_size = tmp_cbmc->size_dont_access_after_boot; - cbmem_console =memremap (physaddr, + cbmem_console =memremap (dev->cbmem_ref.cbmem_addr, cbmem_console_size +sizeof (*cbmem_console),MEMREMAP_WB );memunmap (tmp_cbmc);
@@ -93,26 +94,11 @@ static int memconsole_coreboot_init(phys_addr_t physaddr)return -ENOMEM ;memconsole_setup (memconsole_coreboot_read); -return 0 ; -} - -static int memconsole_probe (struct platform_device *pdev) -{ -int ret; -struct lb_cbmem_ref entry; - - ret =coreboot_table_find (CB_TAG_CBMEM_CONSOLE , &entry,sizeof (entry)); -if (ret) -return ret; - - ret =memconsole_coreboot_init (entry.cbmem_addr); -if (ret) -return ret;return memconsole_sysfs_init (); } -static int memconsole_remove (struct platform_device *pdev) +static int memconsole_remove (struct coreboot_device *dev) {memconsole_exit ();
@@ -122,28 +108,27 @@ static int memconsole_remove(struct platform_device *pdev)return 0 ; } -static struct platform_driver memconsole_driver = { +static struct coreboot_driver memconsole_driver = { .probe = memconsole_probe, .remove = memconsole_remove, - .driver = { + .drv = { .name ="memconsole" , }, + .tag =CB_TAG_CBMEM_CONSOLE , }; -static int __init platform_memconsole_init (void ) +static void coreboot_memconsole_exit (void ) { -struct platform_device *pdev; - - pdev =platform_device_register_simple ("memconsole" ,-1 ,NULL ,0 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - -platform_driver_register (&memconsole_driver); +coreboot_driver_unregister (&memconsole_driver); +} -return 0 ; +static int __init coreboot_memconsole_init (void ) +{ +return coreboot_driver_register (&memconsole_driver); } -module_init (platform_memconsole_init); +module_exit (coreboot_memconsole_exit); +module_init (coreboot_memconsole_init);MODULE_AUTHOR ("Google, Inc." );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.13.6
PATCH 3/5 firmware: vpd: Probe via coreboot bus
In reply to Samuel HollandRemove the ad-hoc coreboot table search. Now the driver will only be probed when the necessary coreboot table entry has already been found. Furthermore, since the coreboot bus takes care of creating the device, a separate platform device is no longer needed.
--- drivers/firmware/google/vpd.c | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-)
drivers/firmware/google/vpd.c +12 -31
@@ -286,20 +286,15 @@ static int vpd_sections_init(phys_addr_t physaddr)return 0 ; } -static int vpd_probe (struct platform_device *pdev) +static int vpd_probe (struct coreboot_device *dev) {int ret; -struct lb_cbmem_ref entry; - - ret =coreboot_table_find (CB_TAG_VPD , &entry,sizeof (entry)); -if (ret) -return ret; vpd_kobj =kobject_create_and_add ("vpd" , firmware_kobj);if (!vpd_kobj)return -ENOMEM ; - ret =vpd_sections_init (entry.cbmem_addr); + ret =vpd_sections_init (dev->cbmem_ref.cbmem_addr);if (ret) {kobject_put (vpd_kobj);return ret;
@@ -308,7 +303,7 @@ static int vpd_probe(struct platform_device *pdev)return 0 ; } -static int vpd_remove (struct platform_device *pdev) +static int vpd_remove (struct coreboot_device *dev) {vpd_section_destroy (&ro_vpd);vpd_section_destroy (&rw_vpd);
@@ -318,41 +313,27 @@ static int vpd_remove(struct platform_device *pdev)return 0 ; } -static struct platform_driver vpd_driver = { +static struct coreboot_driver vpd_driver = { .probe = vpd_probe, .remove = vpd_remove, - .driver = { + .drv = { .name ="vpd" , }, + .tag =CB_TAG_VPD , }; -static struct platform_device *vpd_pdev; - -static int __init vpd_platform_init (void ) +static int __init coreboot_vpd_init (void ) { -int ret; - - ret =platform_driver_register (&vpd_driver); -if (ret) -return ret; - - vpd_pdev =platform_device_register_simple ("vpd" ,-1 ,NULL ,0 ); -if (IS_ERR (vpd_pdev)) { -platform_driver_unregister (&vpd_driver); -return PTR_ERR (vpd_pdev); - } - -return 0 ; +return coreboot_driver_register (&vpd_driver); } -static void __exit vpd_platform_exit(void) +static void __exit coreboot_vpd_exit(void) { -platform_device_unregister (vpd_pdev); -platform_driver_unregister (&vpd_driver); +coreboot_driver_unregister (&vpd_driver); } -module_init (vpd_platform_init); -module_exit (vpd_platform_exit); +module_init (coreboot_vpd_init); +module_exit (coreboot_vpd_exit);MODULE_AUTHOR ("Google, Inc." );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.13.6
PATCH 4/5 firmware: coreboot: Remove unused coreboot_table_find
In reply to Samuel HollandNow that all users of the coreboot_table_find function have been updated to hang off the coreboot table bus instead, remove it.
--- drivers/firmware/google/coreboot_table.c | 43 -------------------------------- drivers/firmware/google/coreboot_table.h | 3 --- 2 files changed, 46 deletions(-)
drivers/firmware/google/coreboot_table.c +0 -43
@@ -97,49 +97,6 @@ void coreboot_driver_unregister(struct coreboot_driver *driver) }EXPORT_SYMBOL (coreboot_driver_unregister); -/* -* This function parses the coreboot table for an entry that contains the base -* address of the given entry tag. The coreboot table consists of a header -* directly followed by a number of small, variable-sized entries, which each -* contain an identifying tag and their length as the first two fields. -*/ -int coreboot_table_find (int tag,void *data,size_t data_size) -{ -struct coreboot_table_header header; -struct coreboot_table_entry entry; -void *ptr_entry; -int i; - -if (!ptr_header) -return -EPROBE_DEFER ; - -memcpy_fromio (&header, ptr_header,sizeof (header)); - -if (strncmp (header.signature,"LBIO" ,sizeof (header.signature))) { -pr_warn ("coreboot_table: coreboot table missing or corrupt!\n" ); -return -ENODEV ; - } - - ptr_entry = (void *)ptr_header + header.header_bytes; - -for (i =0 ; i < header.table_entries; i++) { -memcpy_fromio (&entry, ptr_entry,sizeof (entry)); -if (entry.tag == tag) { -if (data_size < entry.size) -return -EINVAL ; - -memcpy_fromio (data, ptr_entry, entry.size); - -return 0 ; - } - - ptr_entry += entry.size; - } - -return -ENOENT ; -} -EXPORT_SYMBOL (coreboot_table_find); -int coreboot_table_init (struct device *dev,void __iomem *ptr) {int i, ret;
drivers/firmware/google/coreboot_table.h +0 -3
@@ -69,9 +69,6 @@ int coreboot_driver_register(struct coreboot_driver *driver);/* Unregister a driver that uses the data from a coreboot table. */ void coreboot_driver_unregister (struct coreboot_driver *driver); -/* Retrieve coreboot table entry with tag *tag* and copy it to data */ -int coreboot_table_find (int tag,void *data,size_t data_size); -/* Initialize coreboot table module given a pointer to iomem */ int coreboot_table_init (struct device *dev,void __iomem *ptr);
Signature · 1 line
2.13.6
PATCH 5/5 firmware: coreboot: Add coreboot framebuffer driver
In reply to Samuel HollandRegister a simplefb framebuffer when the coreboot table contains a framebuffer entry.
--- drivers/firmware/google/Kconfig | 8 ++ drivers/firmware/google/Makefile | 1 + drivers/firmware/google/coreboot_table.h | 22 +++++ drivers/firmware/google/framebuffer-coreboot.c | 115 +++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 drivers/firmware/google/framebuffer-coreboot.c
drivers/firmware/google/Kconfig +8 -0
@@ -55,6 +55,14 @@ config GOOGLE_MEMCONSOLE_X86_LEGACY the EBDA on Google servers. If found, this log is exported to userland in the file /sys/firmware/log. +config GOOGLE_FRAMEBUFFER_COREBOOT + tristate "Coreboot Framebuffer" + depends on FB_SIMPLE + depends on GOOGLE_COREBOOT_TABLE + help + This option enables the kernel to search for a framebuffer in + the coreboot table. If found, it is registered with simplefb. + config GOOGLE_MEMCONSOLE_COREBOOT tristate "Firmware Memory Console" depends on GOOGLE_COREBOOT_TABLE
drivers/firmware/google/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_GOOGLE_SMI) += gsmi.o obj-$(CONFIG_GOOGLE_COREBOOT_TABLE) += coreboot_table.o obj-$(CONFIG_GOOGLE_COREBOOT_TABLE_ACPI) += coreboot_table-acpi.o obj-$(CONFIG_GOOGLE_COREBOOT_TABLE_OF) += coreboot_table-of.o +obj-$(CONFIG_GOOGLE_FRAMEBUFFER_COREBOOT) += framebuffer-coreboot.o obj-$(CONFIG_GOOGLE_MEMCONSOLE) += memconsole.o obj-$(CONFIG_GOOGLE_MEMCONSOLE_COREBOOT) += memconsole-coreboot.o obj-$(CONFIG_GOOGLE_MEMCONSOLE_X86_LEGACY) += memconsole-x86-legacy.o
drivers/firmware/google/coreboot_table.h +22 -0
@@ -3,6 +3,7 @@* * Internal header for coreboot table access. * +* Copyright 2014 Gerd Hoffmann <[email protected]> * Copyright 2017 Google Inc. * Copyright 2017 Samuel Holland <[email protected]> *
@@ -46,12 +47,33 @@ struct lb_cbmem_ref {u64 cbmem_addr; }; +/* Describes framebuffer setup by coreboot */ +struct lb_framebuffer { +u32 tag; +u32 size; + +u64 physical_address; +u32 x_resolution; +u32 y_resolution; +u32 bytes_per_line; +u8 bits_per_pixel; +u8 red_mask_pos; +u8 red_mask_size; +u8 green_mask_pos; +u8 green_mask_size; +u8 blue_mask_pos; +u8 blue_mask_size; +u8 reserved_mask_pos; +u8 reserved_mask_size; +}; +/* A device, additionally with information from coreboot. */ struct coreboot_device {struct device dev;union {struct coreboot_table_entry entry;struct lb_cbmem_ref cbmem_ref; +struct lb_framebuffer framebuffer; }; };
drivers/firmware/google/framebuffer-coreboot.c new file +115 -0
115 lines not on this page · raw message
Signature · 1 line
2.13.6
Quoted 22 lines · Samuel Holland
On many systems, coreboot[1] firmware can initialize graphics hardware and set up a high-resolution linear framebuffer. It exports information about this framebuffer, along with various other information, in a table discoverable via ACPI or a device tree.
coreboot also supports booting Linux directly from flash as a "payload". Projects such as Heads[2], u-root[3], and petitboot[4] provide a minimal userland that can then be used to chainload (via kexec) into a full Linux system loaded from disk or over the network.
Fitting even a minimal Linux system on an SPI flash chip is challenging. Reusing the framebuffer setup from coreboot provides an enormous benefit to these projects by allowing them to omit full graphics drivers from their kernel builds. It also speeds up boot times by avoiding duplicated effort, and because coreboot's graphics initialization is often much faster than the Linux driver.
Patch 1 of this series expands coreboot table support into an enumerable bus that devices can hang off of. Patches 2-3 convert the existing drivers to use the new bus structure instead of ad-hoc platform devices, and patch 4 removes the old
coreboot_table_findfunction.
Quoted 7 lines
Finally, patch 5 adds a new driver for the coreboot-initialized framebuffer. It improves on earlier work[5] by being architecture- independent and not needing to scan through low memory.
This patchset has been tested on a Lenovo ThinkPad X220, and earlier versions of these patches have been tested by various members of the coreboot community on other hardware.
It would be great to get some of the google developers to ack these, as this touches their code...
thanks,
greg k-h
Quoted 6 lines
It would be great to get some of the google developers to ack these, as this touches their code...
From the coreboot point of view I guess we're fine with it since it claims
to maintain all of the existing functionality. It's just changing the kernel-level plumbing for these drivers and I don't really have the expertise to comment on whether this is better or worse than the old code (maybe Dmitry or Guenter will?). It seems a little odd to me to call this a "bus", but if we think that's the most fitting abstraction the kernel has for it, I'm okay with that. All I care about is that it will work (in all combinations... e.g. regardless of probe order and even if some parts are compiled as modules and loaded/unloaded at runtime).
[resend in plain text]
Quoted 2 lines
It would be great to get some of the google developers to ack these, as this touches their code...
From the coreboot point of view I guess we're fine with it since it claims
to maintain all of the existing functionality. It's just changing the kernel-level plumbing for these drivers and I don't really have the expertise to comment on whether this is better or worse than the old code (maybe Dmitry or Guenter will?). It seems a little odd to me to call this a "bus", but if we think that's the most fitting abstraction the kernel has for it, I'm okay with that. All I care about is that it will work (in all combinations... e.g. regardless of probe order and even if some parts are compiled as modules and loaded/unloaded at runtime).
Quoted 5 lines · Julius Werner
[resend in plain text]
Quoted 2 lines
It would be great to get some of the google developers to ack these, as this touches their code...
Quoted 9 lines
From the coreboot point of view I guess we're fine with it since it claims
to maintain all of the existing functionality. It's just changing the kernel-level plumbing for these drivers and I don't really have the expertise to comment on whether this is better or worse than the old code (maybe Dmitry or Guenter will?). It seems a little odd to me to call this a "bus", but if we think that's the most fitting abstraction the kernel has for it, I'm okay with that. All I care about is that it will work (in all combinations... e.g. regardless of probe order and even if some parts are compiled as modules and loaded/unloaded at runtime).
Thanks for the response, patches are all now queued up.
greg k-h