1
2
3
4
5
6
7
8
9
10
11
12
13
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
27
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,
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_store = efi_query_variable_store;
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
87
88
89
90static int __init efisubsys_init(void)
91{
92 int error;
93
94 if (!efi_enabled(EFI_BOOT))
95 return 0;
96
97
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
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);
135