aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware/efi/efi.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2013-02-08 10:37:06 -0500
committerMatt Fleming <matt.fleming@intel.com>2013-04-17 08:27:06 -0400
commita9499fa7cd3fd4824a7202d00c766b269fa3bda6 (patch)
tree02d1ba3dcf46f6dd1765ef645b223ea0d4758ae6 /drivers/firmware/efi/efi.c
parentd68772b7c83f4b518be15ae96f4827c8ed02f684 (diff)
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. [ Also, move the efivar API into vars.c and unconditionally compile it. This allows us to move efivars.c, which now only contains the sysfs variable code, into the firmware/efi directory. Note that the efivars.c filename is kept to maintain backwards compatability with the old efivars.ko module. With this patch it is now possible for efivarfs to be built without CONFIG_EFI_VARS - Matt ] Cc: Seiji Aguchi <seiji.aguchi@hds.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Mike Waychison <mikew@google.com> Cc: Kay Sievers <kay@vrfy.org> Cc: Jeremy Kerr <jk@ozlabs.org> Cc: Matthew Garrett <mjg59@srcf.ucam.org> Cc: Chun-Yi Lee <jlee@suse.com> Cc: Andy Whitcroft <apw@canonical.com> Cc: Tobias Powalowski <tpowa@archlinux.org> Signed-off-by: Tom Gundersen <teg@jklm.no> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'drivers/firmware/efi/efi.c')
-rw-r--r--drivers/firmware/efi/efi.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
new file mode 100644
index 000000000000..32bdf4f8e432
--- /dev/null
+++ b/drivers/firmware/efi/efi.c
@@ -0,0 +1,134 @@
1/*
2 * efi.c - EFI subsystem
3 *
4 * Copyright (C) 2001,2003,2004 Dell <Matt_Domsch@dell.com>
5 * Copyright (C) 2004 Intel Corporation <matthew.e.tolentino@intel.com>
6 * Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
7 *
8 * This code registers /sys/firmware/efi{,/efivars} when EFI is supported,
9 * allowing the efivarfs to be mounted or the efivars module to be loaded.
10 * The existance of /sys/firmware/efi may also be used by userspace to
11 * determine that the system supports EFI.
12 *
13 * This file is released under the GPLv2.
14 */
15
16#include <linux/kobject.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/device.h>
20#include <linux/efi.h>
21
22static struct kobject *efi_kobj;
23static struct kobject *efivars_kobj;
24
25/*
26 * Let's not leave out systab information that snuck into
27 * the efivars driver
28 */
29static ssize_t systab_show(struct kobject *kobj,
30 struct kobj_attribute *attr, char *buf)
31{
32 char *str = buf;
33
34 if (!kobj || !buf)
35 return -EINVAL;
36
37 if (efi.mps != EFI_INVALID_TABLE_ADDR)
38 str += sprintf(str, "MPS=0x%lx\n", efi.mps);
39 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
40 str += sprintf(str, "ACPI20=0x%lx\n", efi.acpi20);
41 if (efi.acpi != EFI_INVALID_TABLE_ADDR)
42 str += sprintf(str, "ACPI=0x%lx\n", efi.acpi);
43 if (efi.smbios != EFI_INVALID_TABLE_ADDR)
44 str += sprintf(str, "SMBIOS=0x%lx\n", efi.smbios);
45 if (efi.hcdp != EFI_INVALID_TABLE_ADDR)
46 str += sprintf(str, "HCDP=0x%lx\n", efi.hcdp);
47 if (efi.boot_info != EFI_INVALID_TABLE_ADDR)
48 str += sprintf(str, "BOOTINFO=0x%lx\n", efi.boot_info);
49 if (efi.uga != EFI_INVALID_TABLE_ADDR)
50 str += sprintf(str, "UGA=0x%lx\n", efi.uga);
51
52 return str - buf;
53}
54
55static struct kobj_attribute efi_attr_systab =
56 __ATTR(systab, 0400, systab_show, NULL);
57
58static struct attribute *efi_subsys_attrs[] = {
59 &efi_attr_systab.attr,
60 NULL, /* maybe more in the future? */
61};
62
63static struct attribute_group efi_subsys_attr_group = {
64 .attrs = efi_subsys_attrs,
65};
66
67static struct efivars generic_efivars;
68static struct efivar_operations generic_ops;
69
70static int generic_ops_register(void)
71{
72 generic_ops.get_variable = efi.get_variable;
73 generic_ops.set_variable = efi.set_variable;
74 generic_ops.get_next_variable = efi.get_next_variable;
75 generic_ops.query_variable_info = efi.query_variable_info;
76
77 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
78}
79
80static void generic_ops_unregister(void)
81{
82 efivars_unregister(&generic_efivars);
83}
84
85/*
86 * We register the efi subsystem with the firmware subsystem and the
87 * efivars subsystem with the efi subsystem, if the system was booted with
88 * EFI.
89 */
90static int __init efisubsys_init(void)
91{
92 int error;
93
94 if (!efi_enabled(EFI_BOOT))
95 return 0;
96
97 /* We register the efi directory at /sys/firmware/efi */
98 efi_kobj = kobject_create_and_add("efi", firmware_kobj);
99 if (!efi_kobj) {
100 pr_err("efi: Firmware registration failed.\n");
101 return -ENOMEM;
102 }
103
104 error = generic_ops_register();
105 if (error)
106 goto err_put;
107
108 error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group);
109 if (error) {
110 pr_err("efi: Sysfs attribute export failed with error %d.\n",
111 error);
112 goto err_unregister;
113 }
114
115 /* and the standard mountpoint for efivarfs */
116 efivars_kobj = kobject_create_and_add("efivars", efi_kobj);
117 if (!efivars_kobj) {
118 pr_err("efivars: Subsystem registration failed.\n");
119 error = -ENOMEM;
120 goto err_remove_group;
121 }
122
123 return 0;
124
125err_remove_group:
126 sysfs_remove_group(efi_kobj, &efi_subsys_attr_group);
127err_unregister:
128 generic_ops_unregister();
129err_put:
130 kobject_put(efi_kobj);
131 return error;
132}
133
134subsys_initcall(efisubsys_init);