Skip to contentSkip to conversation

firmware: google: Expose coreboot tables and CBMEM

PATCH Superseded [email protected] 2 participants 6 messages Nov 20, 2019

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover firmware: google: Expose coreboot tables and CBMEM

From: Patrick Rudolph <[email protected]>

As user land tools currently use /dev/mem to access coreboot tables and CBMEM, provide a better way by using read-only sysfs attributes.

Unconditionally expose all tables and buffers making future changes in coreboot possible without modifying a kernel driver.

Changes in v2:
- Add ABI documentation
- Add 0x prefix on hex values
- Remove wrong ioremap hint as found by CI

Patrick Rudolph (2):
firmware: google: Expose CBMEM over sysfs
firmware: google: Expose coreboot tables over sysfs

 Documentation/ABI/stable/sysfs-bus-coreboot |  73 +++++++++
 drivers/firmware/google/Kconfig             |   9 ++
 drivers/firmware/google/Makefile            |   1 +
 drivers/firmware/google/cbmem-coreboot.c    | 162 ++++++++++++++++++++
 drivers/firmware/google/coreboot_table.c    |  60 ++++++++
 drivers/firmware/google/coreboot_table.h    |  13 ++
 6 files changed, 318 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-bus-coreboot
 create mode 100644 drivers/firmware/google/cbmem-coreboot.c
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/2 firmware: google: Expose CBMEM over sysfs

From: Patrick Rudolph <[email protected]>

Make all CBMEM buffers available to userland. This is useful for tools that are currently using /dev/mem.

Make the id, size and address available, as well as the raw table data.

Tools can easily scan the right CBMEM buffer by reading /sys/bus/coreboot/drivers/cbmem/coreboot*/cbmem_attributes/id or /sys/bus/coreboot/devices/coreboot*/cbmem_attributes/id

The binary table data can then be read from /sys/bus/coreboot/drivers/cbmem/coreboot*/cbmem_attributes/data or /sys/bus/coreboot/devices/coreboot*/cbmem_attributes/data

---
-v2:
- Add ABI documentation
- Add 0x prefix on hex values

---
 Documentation/ABI/stable/sysfs-bus-coreboot |  43 ++++++
 drivers/firmware/google/Kconfig             |   9 ++
 drivers/firmware/google/Makefile            |   1 +
 drivers/firmware/google/cbmem-coreboot.c    | 162 ++++++++++++++++++++
 drivers/firmware/google/coreboot_table.h    |  13 ++
 5 files changed, 228 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-bus-coreboot
 create mode 100644 drivers/firmware/google/cbmem-coreboot.c
Documentation/ABI/stable/sysfs-bus-coreboot new file +43 -0
new file mode 100644
index 000000000000..1b04b8abc858
@@ -0,0 +1,43 @@
+What:		/sys/bus/coreboot/devices/.../cbmem_attributes/id
+Date:		Nov 2019
+KernelVersion:	5.5
+Contact:	Patrick Rudolph <[email protected]>
+Description:
+		coreboot device directory can contain a file named
+		cbmem_attributes/id if the device corresponds to a CBMEM
+		buffer.
+		The file holds an ASCII representation of the CBMEM ID in hex
+		(e.g. 0xdeadbeef).
+
+What:		/sys/bus/coreboot/devices/.../cbmem_attributes/size
+Date:		Nov 2019
+KernelVersion:	5.5
+Contact:	Patrick Rudolph <[email protected]>
+Description:
+		coreboot device directory can contain a file named
+		cbmem_attributes/size if the device corresponds to a CBMEM
+		buffer.
+		The file holds an representation as decimal number of the
+		CBMEM buffer size (e.g. 64).
+
+What:		/sys/bus/coreboot/devices/.../cbmem_attributes/address
+Date:		Nov 2019
+KernelVersion:	5.5
+Contact:	Patrick Rudolph <[email protected]>
+Description:
+		coreboot device directory can contain a file named
+		cbmem_attributes/address if the device corresponds to a CBMEM
+		buffer.
+		The file holds an ASCII representation of the physical address
+		of the CBMEM buffer in hex (e.g. 0x000000008000d000).
+
+What:		/sys/bus/coreboot/devices/.../cbmem_attributes/data
+Date:		Nov 2019
+KernelVersion:	5.5
+Contact:	Patrick Rudolph <[email protected]>
+Description:
+		coreboot device directory can contain a file named
+		cbmem_attributes/data if the device corresponds to a CBMEM
+		buffer.
+		The file holds a read-only binary representation of the CBMEM
+		buffer.
drivers/firmware/google/Kconfig +9 -0
index a3a6ca659ffa..11a67c397ab3 100644
@@ -58,6 +58,15 @@ config GOOGLE_FRAMEBUFFER_COREBOOT
 	  This option enables the kernel to search for a framebuffer in
 	  the coreboot table.  If found, it is registered with simplefb.
 
+config GOOGLE_CBMEM_COREBOOT
+	tristate "Coreboot CBMEM access"
+	depends on GOOGLE_COREBOOT_TABLE
+	help
+	  This option exposes all available CBMEM buffers to userland.
+	  The CBMEM id, size and address as well as the raw table data
+	  are exported as sysfs attributes of the corresponding coreboot
+	  table.
+
 config GOOGLE_MEMCONSOLE_COREBOOT
 	tristate "Firmware Memory Console"
 	depends on GOOGLE_COREBOOT_TABLE
drivers/firmware/google/Makefile +1 -0
index d17caded5d88..62053cd6d058 100644
@@ -2,6 +2,7 @@
 
 obj-$(CONFIG_GOOGLE_SMI)		+= gsmi.o
 obj-$(CONFIG_GOOGLE_COREBOOT_TABLE)        += coreboot_table.o
+obj-$(CONFIG_GOOGLE_CBMEM_COREBOOT)        += cbmem-coreboot.o
 obj-$(CONFIG_GOOGLE_FRAMEBUFFER_COREBOOT)  += framebuffer-coreboot.o
 obj-$(CONFIG_GOOGLE_MEMCONSOLE)            += memconsole.o
 obj-$(CONFIG_GOOGLE_MEMCONSOLE_COREBOOT)   += memconsole-coreboot.o
drivers/firmware/google/cbmem-coreboot.c new file +162 -0

162 lines not on this page · raw message

drivers/firmware/google/coreboot_table.h +13 -0
index 7b7b4a6eedda..506048c724d8 100644
@@ -59,6 +59,18 @@ struct lb_framebuffer {
 	u8  reserved_mask_size;
 };
 
+/* There can be more than one of these records as there is one per cbmem entry.
+ * Describes a buffer in memory containing runtime data.
+ */
+struct lb_cbmem_entry {
+	u32 tag;
+	u32 size;
+
+	u64 address;
+	u32 entry_size;
+	u32 id;
+};
+
 /* A device, additionally with information from coreboot. */
 struct coreboot_device {
 	struct device dev;
@@ -66,6 +78,7 @@ struct coreboot_device {
 		struct coreboot_table_entry entry;
 		struct lb_cbmem_ref cbmem_ref;
 		struct lb_framebuffer framebuffer;
+		struct lb_cbmem_entry cbmem_entry;
 	};
 };
 
Signature · 1 line
2.21.0
#2 lore raw

Re: [PATCH 1/2] firmware: google: Expose CBMEM over sysfs

Quoted 10 lines · On Wed, Nov 20, 2019 at 02:39:46PM +0100, [email protected] wrote:
drivers/firmware/google/cbmem-coreboot.c new file +10 -0
+static int cbmem_probe(struct coreboot_device *cdev)
+{
+	struct device *dev = &cdev->dev;
+	struct cb_priv *priv;
+	int err;
+
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+

drivers/firmware/google/cbmem-coreboot.c line 117

Quoted 10 lines
drivers/firmware/google/cbmem-coreboot.c new file +10 -0
+	memcpy(&priv->entry, &cdev->cbmem_entry, sizeof(priv->entry));
+
+	priv->remap = memremap(priv->entry.address,
+			       priv->entry.entry_size, MEMREMAP_WB);
+	if (!priv->remap) {
+		err = -ENOMEM;
+		goto failure;
+	}
+
+	err = sysfs_create_group(&dev->kobj, &cb_mem_attr_group);

Ick, you just raced userspace and lost :(

Please set the default group for the driver (dev_groups), so that the driver core will correctly create and remove this group without you having to do anything.

thanks,

greg k-h

#3 lore raw

PATCH 2/2 firmware: google: Expose coreboot tables over sysfs

In reply to [email protected]

From: Patrick Rudolph <[email protected]>

Make all coreboot table entries available to userland. This is useful for tools that are currently using /dev/mem.

Besides the tag and size also expose the raw table data itself.

Update the ABI documentation to explain the new sysfs interface.

Tools can easily scan for the right coreboot table by reading /sys/bus/coreboot/devices/coreboot*/attributes/id The binary table data can then be read from /sys/bus/coreboot/devices/coreboot*/attributes/data

---
-v2:
- Add ABI documentation
- Add 0x prefix on hex values
- Remove wrong ioremap hint as found by CI

---
 Documentation/ABI/stable/sysfs-bus-coreboot | 30 +++++++++++
 drivers/firmware/google/coreboot_table.c    | 60 +++++++++++++++++++++
 2 files changed, 90 insertions(+)
Documentation/ABI/stable/sysfs-bus-coreboot +30 -0
index 1b04b8abc858..0f28601229f3 100644
@@ -41,3 +41,33 @@ Description:
 		buffer.
 		The file holds a read-only binary representation of the CBMEM
 		buffer.
+
+What:		/sys/bus/coreboot/devices/.../attributes/id
+Date:		Nov 2019
+KernelVersion:	5.5
+Contact:	Patrick Rudolph <[email protected]>
+Description:
+		coreboot device directory can contain a file named attributes/id.
+		The file holds an ASCII representation of the coreboot table ID
+		in hex (e.g. 0x000000ef). On coreboot enabled platforms the ID is
+		usually called TAG.
+
+What:		/sys/bus/coreboot/devices/.../attributes/size
+Date:		Nov 2019
+KernelVersion:	5.5
+Contact:	Patrick Rudolph <[email protected]>
+Description:
+		coreboot device directory can contain a file named
+		attributes/size.
+		The file holds an ASCII representation as decimal number of the
+		coreboot table size (e.g. 64).
+
+What:		/sys/bus/coreboot/devices/.../attributes/data
+Date:		Nov 2019
+KernelVersion:	5.5
+Contact:	Patrick Rudolph <[email protected]>
+Description:
+		coreboot device directory can contain a file named
+		attributes/data.
+		The file holds a read-only binary representation of the coreboot
+		table.
drivers/firmware/google/coreboot_table.c +60 -0

78 lines not on this page · raw message

Signature · 1 line
2.21.0
#4 lore raw

Re: [PATCH 2/2] firmware: google: Expose coreboot tables over sysfs

drivers/firmware/google/coreboot_table.c void coreboot_driver_unregister(struct coreboot_driver *driver) · line 127

Quoted 4 lines · On Wed, Nov 20, 2019 at 02:39:47PM +0100, [email protected] wrote:
drivers/firmware/google/coreboot_table.c +4 -0
+static struct bin_attribute coreboot_attr_data = {
+	.attr = { .name = "data", .mode = 0444 },
+	.read = table_data_read,
+};

BIN_ATTR_RO()?

thanks,

greg k-h

#5 lore raw
In reply to [email protected]
Quoted 5 lines · On Wed, Nov 20, 2019 at 02:39:45PM +0100, [email protected] wrote:

From: Patrick Rudolph <[email protected]>

As user land tools currently use /dev/mem to access coreboot tables and CBMEM, provide a better way by using read-only sysfs attributes.

Quoted 7 lines

Unconditionally expose all tables and buffers making future changes in coreboot possible without modifying a kernel driver.

Changes in v2:
- Add ABI documentation
- Add 0x prefix on hex values
- Remove wrong ioremap hint as found by CI

I think you forgot to put "v2" in the [PATCH] area of the subject lines :(

thanks,

greg k-h