firmware: google: Implement cbmem in sysfs driver
PATCH v7 1/1 firmware: google: Implement cbmem in sysfs driver
cbmem entries can be read from coreboot table0x31 (LB_TAG_CBMEM_ENTRY). This commit exports access to cbmem entries in sysfs under /sys/firmware/coreboot/cbmem-*.
Cc Stephen Boyd <[email protected]>
Cc Tzung-Bi Shih <[email protected]>
Reviewed-by Guenter Roeck <[email protected]>
Reviewed-by Julius Werner <[email protected]>
Tested-by Jack Rosenthal <[email protected]>
Signed-off-by Jack Rosenthal <[email protected]>
---
v7: Updated based on review comments from Stephen Boyd:
- /sys/firmware/coreboot now created in coreboot_table.c
- Documentation for each sysfs file now split out into individual sections.
- now /sys/firmware/coreboot/cbmem/<id>/ instead of /sys/frimware/coreboot/cbmem-<id>/
.../ABI/testing/sysfs-firmware-coreboot | 49 ++++ drivers/firmware/google/Kconfig | 8 + drivers/firmware/google/Makefile | 3 + drivers/firmware/google/cbmem.c | 231 ++++++++++++++++++ drivers/firmware/google/coreboot_table.c | 10 + drivers/firmware/google/coreboot_table.h | 16 ++ 6 files changed, 317 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-firmware-coreboot create mode 100644 drivers/firmware/google/cbmem.c
Documentation/ABI/testing/sysfs-firmware-coreboot new file +49 -0
@@ -0,0 +1,49 @@ +What: /sys/firmware/coreboot/ +Date: August 2022 +Contact: Jack Rosenthal <[email protected]> +Description: + Kernel objects associated with the Coreboot-based BIOS firmware. + +What: /sys/firmware/coreboot/cbmem/ +Date: August 2022 +Contact: Jack Rosenthal <[email protected]> +Description: + Coreboot provides a variety of information in CBMEM. This + directory contains each CBMEM entry, which can be found via + Coreboot tables. + +What: /sys/firmware/coreboot/cbmem/<id>/ +Date: August 2022 +Contact: Jack Rosenthal <[email protected]> +Description: + Each CBMEM entry is given a directory based on the id + corresponding to the entry. A list of ids known to coreboot can + be found in the coreboot source tree at + ``src/commonlib/bsd/include/commonlib/bsd/cbmem_id.h``. + +What: /sys/firmware/coreboot/cbmem/<id>/address +Date: August 2022 +Contact: Jack Rosenthal <[email protected]> +Description: + The memory address that the CBMEM entry's data begins at. + +What: /sys/firmware/coreboot/cbmem/<id>/size +Date: August 2022 +Contact: Jack Rosenthal <[email protected]> +Description: + The size of the data being stored. + +What: /sys/firmware/coreboot/cbmem/<id>/id +Date: August 2022 +Contact: Jack Rosenthal <[email protected]> +Description: + The CBMEM id corresponding to the entry. + +What: /sys/firmware/coreboot/cbmem/<id>/mem +Date: August 2022 +Contact: Jack Rosenthal <[email protected]> +Description: + A file exposing read/write memory access to the entry's data. + Note that this file does not support mmap(), and should be used + for basic data access only. Users requiring mmap() should read + the address and size files, and mmap() /dev/mem.
drivers/firmware/google/Kconfig +8 -0
@@ -19,6 +19,14 @@ config GOOGLE_SMI driver provides an interface for reading and writing NVRAM variables. +config GOOGLE_CBMEM + tristate "CBMEM entries in sysfs" + depends on GOOGLE_COREBOOT_TABLE + help + This option enables the kernel to search for Coreboot CBMEM + entries, and expose the memory for each entry in sysfs under + /sys/firmware/coreboot. + config GOOGLE_COREBOOT_TABLE tristate "Coreboot Table Access" depends on HAS_IOMEM && (ACPI || OF)
drivers/firmware/google/Makefile +3 -0
@@ -7,5 +7,8 @@ obj-$(CONFIG_GOOGLE_MEMCONSOLE) += memconsole.o obj-$(CONFIG_GOOGLE_MEMCONSOLE_COREBOOT) += memconsole-coreboot.o obj-$(CONFIG_GOOGLE_MEMCONSOLE_X86_LEGACY) += memconsole-x86-legacy.o +# Must come after coreboot_table.o, as this driver depends on that bus type. +obj-$(CONFIG_GOOGLE_CBMEM) += cbmem.o + vpd-sysfs-y := vpd.o vpd_decode.o obj-$(CONFIG_GOOGLE_VPD) += vpd-sysfs.o
drivers/firmware/google/cbmem.c new file +231 -0
231 lines not on this page · raw message
drivers/firmware/google/coreboot_table.c +10 -0
@@ -14,16 +14,21 @@#include <linux/init.h> #include <linux/io.h> #include <linux/kernel.h> +#include <linux/kobject.h> #include <linux/module.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/slab.h> +#include <linux/sysfs.h> #include "coreboot_table.h" #define CB_DEV (d) container_of(d, struct coreboot_device, dev)#define CB_DRV (d) container_of(d, struct coreboot_driver, drv) +struct kobject *coreboot_kobj; +EXPORT_SYMBOL (coreboot_kobj); +static int coreboot_bus_match (struct device *dev,struct device_driver *drv) {struct coreboot_device *device =CB_DEV (dev);
@@ -157,6 +162,10 @@ static int coreboot_table_probe(struct platform_device *pdev) }memunmap (ptr); + coreboot_kobj =kobject_create_and_add ("coreboot" , firmware_kobj); +if (!coreboot_kobj) +return -ENOMEM ; +return ret; }
@@ -170,6 +179,7 @@ static int coreboot_table_remove(struct platform_device *pdev) {bus_for_each_dev (&coreboot_bus_type,NULL ,NULL , __cb_dev_unregister);bus_unregister (&coreboot_bus_type); +kobject_put (coreboot_kobj);return 0 ; }
drivers/firmware/google/coreboot_table.h +16 -0
@@ -14,6 +14,11 @@#include <linux/device.h> +struct kobject ; + +/* This is /sys/firmware/coreboot */ +extern struct kobject *coreboot_kobj; +/* Coreboot table header structure */ struct coreboot_table_header {char signature[4 ];
@@ -39,6 +44,16 @@ struct lb_cbmem_ref {u64 cbmem_addr; }; +/* Corresponds to LB_TAG_CBMEM_ENTRY */ +struct lb_cbmem_entry { +u32 tag; +u32 size; + +u64 address; +u32 entry_size; +u32 id; +}; +/* Describes framebuffer setup by coreboot */ struct lb_framebuffer {u32 tag;
@@ -65,6 +80,7 @@ struct coreboot_device {union {struct coreboot_table_entry entry;struct lb_cbmem_ref cbmem_ref; +struct lb_cbmem_entry cbmem_entry;struct lb_framebuffer framebuffer; }; };
Signature · 1 line
2.37.1.559.g78731f0fdb-goog