efi: split efisubsystem from efivars
PATCH v4 1/1 efi: split efisubsystem from efivars
This registers /sys/firmware/efi/{,systab,efivars/} whenever EFI is enabled and the system is booted with EFI.
This allows
*) userspace to check for the existence of /sys/firmware/efi as a way
to determine whether or it is running on an EFI system.
*) 'mount -t efivarfs none /sys/firmware/efi/efivars' without manually
loading any modules.
v4: rebase on top of the chainsaw branch:
- split into efi.c and vars.c
- move systab from vars.c to efi.c
- address checkpatch warnings
v3: rebase on top of new efi_enabled()
v2: only create /sys/firmware/efi/efivars if the module is being compiled,
and move extern's to efi.h
--- drivers/firmware/Makefile | 1 - drivers/firmware/efi/Makefile | 2 + drivers/firmware/efi/efi.c | 107 +++++ drivers/firmware/efi/vars.c | 858 +++++++++++++++++++++++++++++++++++++ drivers/firmware/efivars.c | 955 ------------------------------------------ include/linux/efi.h | 2 + 6 files changed, 969 insertions(+), 956 deletions(-) create mode 100644 drivers/firmware/efi/efi.c create mode 100644 drivers/firmware/efi/vars.c delete mode 100644 drivers/firmware/efivars.c
drivers/firmware/Makefile +0 -1
@@ -4,7 +4,6 @@ obj-$(CONFIG_DMI) += dmi_scan.o obj-$(CONFIG_DMI_SYSFS) += dmi-sysfs.o obj-$(CONFIG_EDD) += edd.o -obj-$(CONFIG_EFI_VARS) += efivars.o obj-$(CONFIG_EFI_PCDP) += pcdp.o obj-$(CONFIG_DELL_RBU) += dell_rbu.o obj-$(CONFIG_DCDBAS) += dcdbas.o
drivers/firmware/efi/Makefile +2 -0
@@ -1,6 +1,8 @@ # # Makefile for linux kernel # +obj-$(CONFIG_EFI) += efi.o +obj-$(CONFIG_EFI_VARS) += vars.o obj-$(CONFIG_EFI_VARS_SYSFS) += sysfs.o obj-$(CONFIG_EFI_VARS_PSTORE) += pstore.o obj-$(CONFIG_EFI_VARS_GENERIC_OPS) += generic-ops.o
drivers/firmware/efi/efi.c new file +107 -0
107 lines not on this page · raw message
drivers/firmware/efi/vars.c new file +858 -0
858 lines not on this page · raw message
drivers/firmware/efivars.c deleted +0 -955
955 lines not on this page · raw message
include/linux/efi.h +2 -0
@@ -742,6 +742,8 @@ utf16_strlen(efi_char16_t *s)return utf16_strnlen (s, ~0UL ); } +extern struct kobject *efi_kobj; +#ifdef CONFIG_EFI_VARS /* * Return the number of bytes is the length of this string
Signature · 1 line
1.8.1.2
Quoted 54 lines · Tom Gundersen
This registers
/sys/firmware/efi/{,systab,efivars/}whenever EFI is enabled and the system is booted with EFI.This allows
*) userspace to check for the existence of/sys/firmware/efias a way
to determine whether or it is running on an EFI system.
*) 'mount -t efivarfs none/sys/firmware/efi/efivars' without manually
loading any modules.v4: rebase on top of the chainsaw branch:
- split intoefi.candvars.c
- move systab fromvars.ctoefi.c
- address checkpatch warnings
v3: rebase on top of newefi_enabled()
v2: only create/sys/firmware/efi/efivarsif the module is being compiled,
and move extern's toefi.hCc Matt Fleming <[email protected]>Cc Kay Sievers <[email protected]>Cc Jeremy Kerr <[email protected]>Cc Matthew Garrett <[email protected]>Cc Chun-Yi Lee <jlee-IBi9RG/[email protected]>Cc Andy Whitcroft <[email protected]>Cc Tobias Powalowski <tpowa-fd97jBR+K/[email protected]>Signed-off-by Tom Gundersen <[email protected]>--- drivers/firmware/Makefile | 1 - drivers/firmware/efi/Makefile | 2 + drivers/firmware/efi/efi.c | 107 +++++ drivers/firmware/efi/vars.c | 858 +++++++++++++++++++++++++++++++++++++ drivers/firmware/efivars.c | 955 ------------------------------------------ include/linux/efi.h | 2 + 6 files changed, 969 insertions(+), 956 deletions(-) create mode 100644 drivers/firmware/efi/efi.c create mode 100644 drivers/firmware/efi/vars.c delete mode 100644 drivers/firmware/efivars.cdrivers/firmware/Makefile +0
-1@@ -4,7 +4,6 @@ obj-$(CONFIG_DMI) += dmi_scan.o obj-$(CONFIG_DMI_SYSFS) += dmi-sysfs.o obj-$(CONFIG_EDD) += edd.o -obj-$(CONFIG_EFI_VARS) += efivars.o obj-$(CONFIG_EFI_PCDP) += pcdp.o obj-$(CONFIG_DELL_RBU) += dell_rbu.o obj-$(CONFIG_DCDBAS) += dcdbas.odrivers/firmware/efi/Makefile +0
-0
drivers/firmware/efi/Makefile line 4
Quoted 4 lines
drivers/firmware/efi/Makefile +1
-0@@ -1,6 +1,8 @@ # # Makefile for linux kernel # +obj-$(CONFIG_EFI) += efi.o
The $(CONFIG_EFI) part is redundant. We only build things in drivers/firmware/efi/ if CONFIG_EFI=y.
[...]
drivers/firmware/efi/Makefile
Quoted 11 lines
drivers/firmware/efi/Makefile +11
-0+/* + * We register the efi subsystem with the firmware subsystem and the + * efivars subsystem with the efi subsystem, if the system was booted with + * EFI. + */ +static int __init efisubsys_init(void) +{ + int error; + + if (!efi_enabled(EFI_BOOT)) + return 0;
OK, this makes sense, and you've highlighted a really good point. We need to add checks in a bunch of places to see if EFI runtime services are available. But you don't need to worry about that, I need to do that in earlier patches, not this one.
Quoted 12 lines
drivers/firmware/efi/Makefile +12
-0+ /* We register the efi directory at /sys/firmware/efi */ + efi_kobj = kobject_create_and_add("efi", firmware_kobj); + if (!efi_kobj) { + pr_err("efi: Firmware registration failed.\n"); + return -ENOMEM; + } + + error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); + if (error) { + pr_err("efi: Sysfs attribute export failed with error %d.\n", + error); + }
drivers/firmware/efi/Makefile
Quoted 10 lines
drivers/firmware/efi/Makefile +10
-0+ +#if defined(CONFIG_EFIVAR_FS) || defined(CONFIG_EFIVAR_FS_MODULE) + /* and the standard mountpoint for efivarfs */ + efivars_kobj = kobject_create_and_add("efivars", efi_kobj); + if (!efivars_kobj) { + pr_err("efivars: Subsystem registration failed.\n"); + kobject_put(efi_kobj); + return -ENOMEM; + } +#endif /* CONFIG_EFIVAR_FS */
Does it make sense to hide the efivarfs mount point? I'm not crazy about sprinkling more #ifdef's around. If the efivarfs code isn't compiled into the kernel/built as a module then mounting will fail anyway.
Quoted 6 lines · Matt Fleming
Quoted 2 lines · Tom Gundersen
#
+obj-$(CONFIG_EFI) += efi.oThe $(CONFIG_EFI) part is redundant. We only build things in
drivers/firmware/efi/ifCONFIG_EFI=y.
Ah, good point.
Quoted 18 lines
Quoted 18 lines
drivers/firmware/efi/efi.c new file +18
-0+/* We register the efi directory at /sys/firmware/efi */ + efi_kobj =kobject_create_and_add ("efi" , firmware_kobj); +if (!efi_kobj) { +pr_err ("efi: Firmware registration failed.\n" ); +return -ENOMEM ; + } + + error =sysfs_create_group (efi_kobj, &efi_subsys_attr_group); +if (error) { +pr_err ("efi: Sysfs attribute export failed with error %d.\n" , + error); + } + +#if defined(CONFIG_EFIVAR_FS ) || defined(CONFIG_EFIVAR_FS_MODULE ) +/* and the standard mountpoint for efivarfs */ + efivars_kobj =kobject_create_and_add ("efivars" , efi_kobj); +if (!efivars_kobj) { +pr_err ("efivars: Subsystem registration failed.\n" );
Quoted 8 lines
drivers/firmware/efi/efi.c line 102
Quoted 4 lines
drivers/firmware/efi/efi.c new file +4
-0+kobject_put (efi_kobj); + return -ENOMEM; + } +#endif /* CONFIG_EFIVAR_FS */ Does it make sense to hide the efivarfs mount point? I'm not crazy about sprinkling more #ifdef's around. If the efivarfs code isn't compiled into the kernel/built as a module then mounting will fail anyway.
I was 50/50 on that, so if you prefer to remove the ifdef that's fine with me.
I'll send out a new version soon, unless you prefer to just fix it up as you apply it?
Cheers,
Tom
Quoted 2 lines · Tom Gundersen
I'll send out a new version soon, unless you prefer to just fix it up as you apply it?
A new version would be super. Thanks.