Skip to contentSkip to conversation

coreboot CFR firmware attributes

PATCH Superseded Sean Rhodes 3 participants 4 messages Jul 9 – Jul 10

Subsystems (3)

v2 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v2 cover coreboot CFR firmware attributes

Hi,

This adds a firmware-attributes driver for coreboot CFR tables.

Changes since v1:
- Add explicit includes for the helper APIs used by the driver.
- Use __free(kfree) and no_free_ptr() for EFI name allocation.
- Use isascii() for EFI variable name validation.
- Convert the EFI write path mutex to scoped_guard().
- Rename the label/current-value parser to avoid default-value ambiguity.
- Use devm_kzalloc() and devm_mutex_init() for the driver state.
- Clarify that -EOPNOTSUPP after a successful EFI write is the reboot-required path.

Tested on Star Labs Lite GLKR, firmware 26.07, Linux 6.17.0-35-generic:
loaded coreboot_table and coreboot-cfr as test modules, verified firmware-attributes sysfs exposure, fwupd BIOS settings enumeration, and the reboot-required write path with debug_level.

Thanks,
Sean

Sean Rhodes (1):
platform/x86: Add coreboot CFR firmware attributes

 MAINTAINERS                              |   6 +
 drivers/firmware/google/coreboot_table.h |  45 --
 drivers/platform/x86/Kconfig             |  13 +
 drivers/platform/x86/Makefile            |   1 +
 drivers/platform/x86/coreboot-cfr.c      | 986 +++++++++++++++++++++++
 include/linux/coreboot.h                 | 147 ++++
 6 files changed, 1153 insertions(+), 45 deletions(-)
 create mode 100644 drivers/platform/x86/coreboot-cfr.c
#1 lore raw

PATCH v2 1/1 platform/x86: Add coreboot CFR firmware attributes

coreboot can publish a CFR tree in its coreboot table to describe firmware setup options. Add a firmware-attributes driver for that table entry and move the coreboot table bus definitions into <linux/coreboot.h> so the driver can bind from outside drivers/firmware/google.

The driver exposes runtime EFI variable-backed boolean, enum and integer settings through the firmware-attributes ABI. It only registers settings with readable runtime EFI variables, skips suppressed, volatile, dependency-gated and non-runtime options, and keeps read-only or inactive options read-only in sysfs.

For settings with an APM_CNT runtime-apply record, write the EFI variable and ask firmware to apply the setting immediately. If firmware reports a failure, restore the old EFI variable value. Settings without a runtime apply hook keep the EFI variable update and set pending_reboot.

Tested on a Star Labs Byte with firmware 26.07 and the driver built as a module against Linux 6.17: runtime APM_CNT apply was verified with power_led, and reboot-needed behavior was verified with debug_level.

---
 MAINTAINERS                              |   6 +
 drivers/firmware/google/coreboot_table.h |  45 --
 drivers/platform/x86/Kconfig             |  13 +
 drivers/platform/x86/Makefile            |   1 +
 drivers/platform/x86/coreboot-cfr.c      | 986 +++++++++++++++++++++++
 include/linux/coreboot.h                 | 147 ++++
 6 files changed, 1153 insertions(+), 45 deletions(-)
 create mode 100644 drivers/platform/x86/coreboot-cfr.c
MAINTAINERS +6 -0
index 15011f5752a9..c5d8daab2196 100644
@@ -6665,6 +6665,12 @@ F:	tools/testing/selftests/cgroup/test_hugetlb_memcg.c
 F:	tools/testing/selftests/cgroup/test_kmem.c
 F:	tools/testing/selftests/cgroup/test_memcontrol.c
 
+COREBOOT CFR FIRMWARE ATTRIBUTES DRIVER
+M:	Sean Rhodes <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/x86/coreboot-cfr.c
+
 CORETEMP HARDWARE MONITORING DRIVER
 L:	[email protected]
 S:	Orphan
drivers/firmware/google/coreboot_table.h +0 -45

50 lines not on this page · raw message

drivers/platform/x86/Kconfig +13 -0
index b54b5212b204..683c35a9d288 100644
@@ -851,6 +851,19 @@ config SONYPI_COMPAT
 	help
 	  Build the sonypi driver compatibility code into the sony-laptop driver.
 
+config COREBOOT_CFR
+	tristate "coreboot CFR firmware attributes"
+	depends on EFI
+	depends on GOOGLE_COREBOOT_TABLE
+	select FW_ATTR_CLASS
+	help
+	  This driver parses the coreboot CFR table and exposes runtime EFI
+	  variable-backed options through the firmware-attributes sysfs
+	  interface.
+
+	  If you have a system running coreboot with CFR runtime
+	  configuration support, say Y or M here.
+
 config SYSTEM76_ACPI
 	tristate "System76 ACPI Driver"
 	depends on ACPI_EC
drivers/platform/x86/Makefile +1 -0
index 872ac3842391..71a0378e4d9b 100644
@@ -129,6 +129,7 @@ obj-$(CONFIG_COMPAL_LAPTOP)	+= compal-laptop.o
 obj-$(CONFIG_LG_LAPTOP)		+= lg-laptop.o
 obj-$(CONFIG_PANASONIC_LAPTOP)	+= panasonic-laptop.o
 obj-$(CONFIG_SONY_LAPTOP)	+= sony-laptop.o
+obj-$(CONFIG_COREBOOT_CFR)	+= coreboot-cfr.o
 obj-$(CONFIG_SYSTEM76_ACPI)	+= system76_acpi.o
 obj-$(CONFIG_TOPSTAR_LAPTOP)	+= topstar-laptop.o
 
drivers/platform/x86/coreboot-cfr.c new file +986 -0

986 lines not on this page · raw message

include/linux/coreboot.h +147 -0

167 lines not on this page · raw message

reviewer
#2 lore raw

Re: [PATCH v2 1/1] platform/x86: Add coreboot CFR firmware attributes

Quoted 24 lines · Sean Rhodes

coreboot can publish a CFR tree in its coreboot table to describe firmware setup options. Add a firmware-attributes driver for that table entry and move the coreboot table bus definitions into <linux/coreboot.h> so the driver can bind from outside drivers/firmware/google.

The driver exposes runtime EFI variable-backed boolean, enum and integer settings through the firmware-attributes ABI. It only registers settings with readable runtime EFI variables, skips suppressed, volatile, dependency-gated and non-runtime options, and keeps read-only or inactive options read-only in sysfs.

For settings with an APM_CNT runtime-apply record, write the EFI variable and ask firmware to apply the setting immediately. If firmware reports a failure, restore the old EFI variable value. Settings without a runtime apply hook keep the EFI variable update and set pending_reboot.

Tested on a Star Labs Byte with firmware 26.07 and the driver built as a module against Linux 6.17: runtime APM_CNT apply was verified with power_led, and reboot-needed behavior was verified with debug_level.

Quoted 9 lines
---
 MAINTAINERS                              |   6 +
 drivers/firmware/google/coreboot_table.h |  45 --
 drivers/platform/x86/Kconfig             |  13 +
 drivers/platform/x86/Makefile            |   1 +
 drivers/platform/x86/coreboot-cfr.c      | 986 +++++++++++++++++++++++
 include/linux/coreboot.h                 | 147 ++++
 6 files changed, 1153 insertions(+), 45 deletions(-)
 create mode 100644 drivers/platform/x86/coreboot-cfr.c

Is there a specific reason to put this under platform/x86, or are you just doing that because it's not related to Google? If so I think it's just time to rename the directory from drivers/firmware/google to drivers/firmware/coreboot, and then you could just put it next to the other drivers. The only thing that's still completely unrelated to coreboot in there is memconsole-legacy.c, but since it's piggy-backing off the same buffer format as memconsole-coreboot.c I think it would be fine to just leave it there anyway.

#3 lore raw

Re: [PATCH v2 1/1] platform/x86: Add coreboot CFR firmware attributes

In reply to Sean Rhodes
Quoted 1 line · Sean Rhodes

+#include <linux/mod_devicetable.h>

Please don't add new users for this header file. Only use those <linux/device-id/*.h> that you actually need (if any).

Thanks
Uwe