blob: 5ee2cfb96698f0c8417b96a2d37ca869694b5556 [file] [log] [blame]
Tom Gundersena9499fa2013-02-08 15:37:06 +00001/*
2 * Originally from efivars.c,
3 *
4 * Copyright (C) 2001,2003,2004 Dell <Matt_Domsch@dell.com>
5 * Copyright (C) 2004 Intel Corporation <matthew.e.tolentino@intel.com>
6 *
7 * This code takes all variables accessible from EFI runtime and
8 * exports them via sysfs
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * Changelog:
25 *
26 * 17 May 2004 - Matt Domsch <Matt_Domsch@dell.com>
27 * remove check for efi_enabled in exit
28 * add MODULE_VERSION
29 *
30 * 26 Apr 2004 - Matt Domsch <Matt_Domsch@dell.com>
31 * minor bug fixes
32 *
33 * 21 Apr 2004 - Matt Tolentino <matthew.e.tolentino@intel.com)
34 * converted driver to export variable information via sysfs
35 * and moved to drivers/firmware directory
36 * bumped revision number to v0.07 to reflect conversion & move
37 *
38 * 10 Dec 2002 - Matt Domsch <Matt_Domsch@dell.com>
39 * fix locking per Peter Chubb's findings
40 *
41 * 25 Mar 2002 - Matt Domsch <Matt_Domsch@dell.com>
42 * move uuid_unparse() to include/asm-ia64/efi.h:efi_guid_unparse()
43 *
44 * 12 Feb 2002 - Matt Domsch <Matt_Domsch@dell.com>
45 * use list_for_each_safe when deleting vars.
46 * remove ifdef CONFIG_SMP around include <linux/smp.h>
47 * v0.04 release to linux-ia64@linuxia64.org
48 *
49 * 20 April 2001 - Matt Domsch <Matt_Domsch@dell.com>
50 * Moved vars from /proc/efi to /proc/efi/vars, and made
51 * efi.c own the /proc/efi directory.
52 * v0.03 release to linux-ia64@linuxia64.org
53 *
54 * 26 March 2001 - Matt Domsch <Matt_Domsch@dell.com>
55 * At the request of Stephane, moved ownership of /proc/efi
56 * to efi.c, and now efivars lives under /proc/efi/vars.
57 *
58 * 12 March 2001 - Matt Domsch <Matt_Domsch@dell.com>
59 * Feedback received from Stephane Eranian incorporated.
60 * efivar_write() checks copy_from_user() return value.
61 * efivar_read/write() returns proper errno.
62 * v0.02 release to linux-ia64@linuxia64.org
63 *
64 * 26 February 2001 - Matt Domsch <Matt_Domsch@dell.com>
65 * v0.01 release to linux-ia64@linuxia64.org
66 */
67
68#include <linux/efi.h>
69#include <linux/module.h>
Linus Torvalds20b4fb42013-05-01 17:51:54 -070070#include <linux/slab.h>
Matt Fleminga614e192013-04-30 11:30:24 +010071#include <linux/ucs2_string.h>
Tom Gundersena9499fa2013-02-08 15:37:06 +000072
73#define EFIVARS_VERSION "0.08"
74#define EFIVARS_DATE "2004-May-17"
75
76MODULE_AUTHOR("Matt Domsch <Matt_Domsch@Dell.com>");
77MODULE_DESCRIPTION("sysfs interface to EFI Variables");
78MODULE_LICENSE("GPL");
79MODULE_VERSION(EFIVARS_VERSION);
80
81LIST_HEAD(efivar_sysfs_list);
82EXPORT_SYMBOL_GPL(efivar_sysfs_list);
83
84static struct kset *efivars_kset;
85
86static struct bin_attribute *efivars_new_var;
87static struct bin_attribute *efivars_del_var;
88
89struct efivar_attribute {
90 struct attribute attr;
91 ssize_t (*show) (struct efivar_entry *entry, char *buf);
92 ssize_t (*store)(struct efivar_entry *entry, const char *buf, size_t count);
93};
94
95#define EFIVAR_ATTR(_name, _mode, _show, _store) \
96struct efivar_attribute efivar_attr_##_name = { \
97 .attr = {.name = __stringify(_name), .mode = _mode}, \
98 .show = _show, \
99 .store = _store, \
100};
101
102#define to_efivar_attr(_attr) container_of(_attr, struct efivar_attribute, attr)
103#define to_efivar_entry(obj) container_of(obj, struct efivar_entry, kobj)
104
105/*
106 * Prototype for sysfs creation function
107 */
108static int
109efivar_create_sysfs_entry(struct efivar_entry *new_var);
110
111static ssize_t
112efivar_guid_read(struct efivar_entry *entry, char *buf)
113{
114 struct efi_variable *var = &entry->var;
115 char *str = buf;
116
117 if (!entry || !buf)
118 return 0;
119
120 efi_guid_unparse(&var->VendorGuid, str);
121 str += strlen(str);
122 str += sprintf(str, "\n");
123
124 return str - buf;
125}
126
127static ssize_t
128efivar_attr_read(struct efivar_entry *entry, char *buf)
129{
130 struct efi_variable *var = &entry->var;
131 char *str = buf;
132
133 if (!entry || !buf)
134 return -EINVAL;
135
136 var->DataSize = 1024;
137 if (efivar_entry_get(entry, &var->Attributes, &var->DataSize, var->Data))
138 return -EIO;
139
140 if (var->Attributes & EFI_VARIABLE_NON_VOLATILE)
141 str += sprintf(str, "EFI_VARIABLE_NON_VOLATILE\n");
142 if (var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)
143 str += sprintf(str, "EFI_VARIABLE_BOOTSERVICE_ACCESS\n");
144 if (var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS)
145 str += sprintf(str, "EFI_VARIABLE_RUNTIME_ACCESS\n");
146 if (var->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD)
147 str += sprintf(str, "EFI_VARIABLE_HARDWARE_ERROR_RECORD\n");
148 if (var->Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
149 str += sprintf(str,
150 "EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS\n");
151 if (var->Attributes &
152 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
153 str += sprintf(str,
154 "EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS\n");
155 if (var->Attributes & EFI_VARIABLE_APPEND_WRITE)
156 str += sprintf(str, "EFI_VARIABLE_APPEND_WRITE\n");
157 return str - buf;
158}
159
160static ssize_t
161efivar_size_read(struct efivar_entry *entry, char *buf)
162{
163 struct efi_variable *var = &entry->var;
164 char *str = buf;
165
166 if (!entry || !buf)
167 return -EINVAL;
168
169 var->DataSize = 1024;
170 if (efivar_entry_get(entry, &var->Attributes, &var->DataSize, var->Data))
171 return -EIO;
172
173 str += sprintf(str, "0x%lx\n", var->DataSize);
174 return str - buf;
175}
176
177static ssize_t
178efivar_data_read(struct efivar_entry *entry, char *buf)
179{
180 struct efi_variable *var = &entry->var;
181
182 if (!entry || !buf)
183 return -EINVAL;
184
185 var->DataSize = 1024;
186 if (efivar_entry_get(entry, &var->Attributes, &var->DataSize, var->Data))
187 return -EIO;
188
189 memcpy(buf, var->Data, var->DataSize);
190 return var->DataSize;
191}
192/*
193 * We allow each variable to be edited via rewriting the
194 * entire efi variable structure.
195 */
196static ssize_t
197efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
198{
199 struct efi_variable *new_var, *var = &entry->var;
Matt Flemingbafc84d2014-03-16 12:14:49 +0000200 efi_char16_t *name;
201 unsigned long size;
202 efi_guid_t vendor;
203 u32 attributes;
204 u8 *data;
Tom Gundersena9499fa2013-02-08 15:37:06 +0000205 int err;
206
207 if (count != sizeof(struct efi_variable))
208 return -EINVAL;
209
210 new_var = (struct efi_variable *)buf;
Matt Flemingbafc84d2014-03-16 12:14:49 +0000211
212 attributes = new_var->Attributes;
213 vendor = new_var->VendorGuid;
214 name = new_var->VariableName;
215 size = new_var->DataSize;
216 data = new_var->Data;
217
Tom Gundersena9499fa2013-02-08 15:37:06 +0000218 /*
219 * If only updating the variable data, then the name
220 * and guid should remain the same
221 */
Matt Flemingbafc84d2014-03-16 12:14:49 +0000222 if (memcmp(name, var->VariableName, sizeof(var->VariableName)) ||
223 efi_guidcmp(vendor, var->VendorGuid)) {
Tom Gundersena9499fa2013-02-08 15:37:06 +0000224 printk(KERN_ERR "efivars: Cannot edit the wrong variable!\n");
225 return -EINVAL;
226 }
227
Matt Flemingbafc84d2014-03-16 12:14:49 +0000228 if ((size <= 0) || (attributes == 0)){
Tom Gundersena9499fa2013-02-08 15:37:06 +0000229 printk(KERN_ERR "efivars: DataSize & Attributes must be valid!\n");
230 return -EINVAL;
231 }
232
Matt Flemingbafc84d2014-03-16 12:14:49 +0000233 if ((attributes & ~EFI_VARIABLE_MASK) != 0 ||
Matt Fleminga5d92ad2014-03-17 10:57:00 +0000234 efivar_validate(name, data, size) == false) {
Tom Gundersena9499fa2013-02-08 15:37:06 +0000235 printk(KERN_ERR "efivars: Malformed variable content\n");
236 return -EINVAL;
237 }
238
239 memcpy(&entry->var, new_var, count);
240
Matt Flemingbafc84d2014-03-16 12:14:49 +0000241 err = efivar_entry_set(entry, attributes, size, data, NULL);
Tom Gundersena9499fa2013-02-08 15:37:06 +0000242 if (err) {
243 printk(KERN_WARNING "efivars: set_variable() failed: status=%d\n", err);
244 return -EIO;
245 }
246
247 return count;
248}
249
250static ssize_t
251efivar_show_raw(struct efivar_entry *entry, char *buf)
252{
253 struct efi_variable *var = &entry->var;
254
255 if (!entry || !buf)
256 return 0;
257
258 var->DataSize = 1024;
259 if (efivar_entry_get(entry, &entry->var.Attributes,
260 &entry->var.DataSize, entry->var.Data))
261 return -EIO;
262
263 memcpy(buf, var, sizeof(*var));
264
265 return sizeof(*var);
266}
267
268/*
269 * Generic read/write functions that call the specific functions of
270 * the attributes...
271 */
272static ssize_t efivar_attr_show(struct kobject *kobj, struct attribute *attr,
273 char *buf)
274{
275 struct efivar_entry *var = to_efivar_entry(kobj);
276 struct efivar_attribute *efivar_attr = to_efivar_attr(attr);
277 ssize_t ret = -EIO;
278
279 if (!capable(CAP_SYS_ADMIN))
280 return -EACCES;
281
282 if (efivar_attr->show) {
283 ret = efivar_attr->show(var, buf);
284 }
285 return ret;
286}
287
288static ssize_t efivar_attr_store(struct kobject *kobj, struct attribute *attr,
289 const char *buf, size_t count)
290{
291 struct efivar_entry *var = to_efivar_entry(kobj);
292 struct efivar_attribute *efivar_attr = to_efivar_attr(attr);
293 ssize_t ret = -EIO;
294
295 if (!capable(CAP_SYS_ADMIN))
296 return -EACCES;
297
298 if (efivar_attr->store)
299 ret = efivar_attr->store(var, buf, count);
300
301 return ret;
302}
303
304static const struct sysfs_ops efivar_attr_ops = {
305 .show = efivar_attr_show,
306 .store = efivar_attr_store,
307};
308
309static void efivar_release(struct kobject *kobj)
310{
311 struct efivar_entry *var = container_of(kobj, struct efivar_entry, kobj);
312 kfree(var);
313}
314
315static EFIVAR_ATTR(guid, 0400, efivar_guid_read, NULL);
316static EFIVAR_ATTR(attributes, 0400, efivar_attr_read, NULL);
317static EFIVAR_ATTR(size, 0400, efivar_size_read, NULL);
318static EFIVAR_ATTR(data, 0400, efivar_data_read, NULL);
319static EFIVAR_ATTR(raw_var, 0600, efivar_show_raw, efivar_store_raw);
320
321static struct attribute *def_attrs[] = {
322 &efivar_attr_guid.attr,
323 &efivar_attr_size.attr,
324 &efivar_attr_attributes.attr,
325 &efivar_attr_data.attr,
326 &efivar_attr_raw_var.attr,
327 NULL,
328};
329
330static struct kobj_type efivar_ktype = {
331 .release = efivar_release,
332 .sysfs_ops = &efivar_attr_ops,
333 .default_attrs = def_attrs,
334};
335
336static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
337 struct bin_attribute *bin_attr,
338 char *buf, loff_t pos, size_t count)
339{
340 struct efi_variable *new_var = (struct efi_variable *)buf;
341 struct efivar_entry *new_entry;
Matt Fleminga5d92ad2014-03-17 10:57:00 +0000342 efi_char16_t *name;
Matt Flemingbafc84d2014-03-16 12:14:49 +0000343 unsigned long size;
344 u32 attributes;
345 u8 *data;
Tom Gundersena9499fa2013-02-08 15:37:06 +0000346 int err;
347
348 if (!capable(CAP_SYS_ADMIN))
349 return -EACCES;
350
Matt Fleminge003bbe2014-03-17 09:17:28 +0000351 if (count != sizeof(*new_var))
352 return -EINVAL;
353
Matt Flemingbafc84d2014-03-16 12:14:49 +0000354 attributes = new_var->Attributes;
Matt Fleminga5d92ad2014-03-17 10:57:00 +0000355 name = new_var->VariableName;
Matt Flemingbafc84d2014-03-16 12:14:49 +0000356 size = new_var->DataSize;
357 data = new_var->Data;
358
359 if ((attributes & ~EFI_VARIABLE_MASK) != 0 ||
Matt Fleminga5d92ad2014-03-17 10:57:00 +0000360 efivar_validate(name, data, size) == false) {
Tom Gundersena9499fa2013-02-08 15:37:06 +0000361 printk(KERN_ERR "efivars: Malformed variable content\n");
362 return -EINVAL;
363 }
364
365 new_entry = kzalloc(sizeof(*new_entry), GFP_KERNEL);
366 if (!new_entry)
367 return -ENOMEM;
368
369 memcpy(&new_entry->var, new_var, sizeof(*new_var));
370
Matt Flemingbafc84d2014-03-16 12:14:49 +0000371 err = efivar_entry_set(new_entry, attributes, size,
372 data, &efivar_sysfs_list);
Tom Gundersena9499fa2013-02-08 15:37:06 +0000373 if (err) {
374 if (err == -EEXIST)
375 err = -EINVAL;
376 goto out;
377 }
378
379 if (efivar_create_sysfs_entry(new_entry)) {
380 printk(KERN_WARNING "efivars: failed to create sysfs entry.\n");
381 kfree(new_entry);
382 }
383 return count;
384
385out:
386 kfree(new_entry);
387 return err;
388}
389
390static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
391 struct bin_attribute *bin_attr,
392 char *buf, loff_t pos, size_t count)
393{
394 struct efi_variable *del_var = (struct efi_variable *)buf;
395 struct efivar_entry *entry;
Matt Flemingbafc84d2014-03-16 12:14:49 +0000396 efi_char16_t *name;
397 efi_guid_t vendor;
Tom Gundersena9499fa2013-02-08 15:37:06 +0000398 int err = 0;
399
400 if (!capable(CAP_SYS_ADMIN))
401 return -EACCES;
402
Matt Fleminge003bbe2014-03-17 09:17:28 +0000403 if (count != sizeof(*del_var))
404 return -EINVAL;
405
Matt Flemingbafc84d2014-03-16 12:14:49 +0000406 name = del_var->VariableName;
407 vendor = del_var->VendorGuid;
408
Tom Gundersena9499fa2013-02-08 15:37:06 +0000409 efivar_entry_iter_begin();
Matt Flemingbafc84d2014-03-16 12:14:49 +0000410 entry = efivar_entry_find(name, vendor, &efivar_sysfs_list, true);
Tom Gundersena9499fa2013-02-08 15:37:06 +0000411 if (!entry)
412 err = -EINVAL;
413 else if (__efivar_entry_delete(entry))
414 err = -EIO;
415
Seiji Aguchie0d59732013-10-30 15:27:26 -0400416 if (err) {
417 efivar_entry_iter_end();
Tom Gundersena9499fa2013-02-08 15:37:06 +0000418 return err;
Seiji Aguchie0d59732013-10-30 15:27:26 -0400419 }
Tom Gundersena9499fa2013-02-08 15:37:06 +0000420
Seiji Aguchie0d59732013-10-30 15:27:26 -0400421 if (!entry->scanning) {
422 efivar_entry_iter_end();
423 efivar_unregister(entry);
424 } else
425 efivar_entry_iter_end();
Tom Gundersena9499fa2013-02-08 15:37:06 +0000426
427 /* It's dead Jim.... */
428 return count;
429}
430
431/**
432 * efivar_create_sysfs_entry - create a new entry in sysfs
433 * @new_var: efivar entry to create
434 *
435 * Returns 1 on failure, 0 on success
436 */
437static int
438efivar_create_sysfs_entry(struct efivar_entry *new_var)
439{
440 int i, short_name_size;
441 char *short_name;
442 unsigned long variable_name_size;
443 efi_char16_t *variable_name;
444
445 variable_name = new_var->var.VariableName;
Matt Fleminga614e192013-04-30 11:30:24 +0100446 variable_name_size = ucs2_strlen(variable_name) * sizeof(efi_char16_t);
Tom Gundersena9499fa2013-02-08 15:37:06 +0000447
448 /*
449 * Length of the variable bytes in ASCII, plus the '-' separator,
450 * plus the GUID, plus trailing NUL
451 */
452 short_name_size = variable_name_size / sizeof(efi_char16_t)
453 + 1 + EFI_VARIABLE_GUID_LEN + 1;
454
455 short_name = kzalloc(short_name_size, GFP_KERNEL);
456
Dan Carpenter7b2dd6d2013-04-30 10:43:44 +0300457 if (!short_name)
Tom Gundersena9499fa2013-02-08 15:37:06 +0000458 return 1;
Tom Gundersena9499fa2013-02-08 15:37:06 +0000459
460 /* Convert Unicode to normal chars (assume top bits are 0),
461 ala UTF-8 */
462 for (i=0; i < (int)(variable_name_size / sizeof(efi_char16_t)); i++) {
463 short_name[i] = variable_name[i] & 0xFF;
464 }
465 /* This is ugly, but necessary to separate one vendor's
466 private variables from another's. */
467
468 *(short_name + strlen(short_name)) = '-';
469 efi_guid_unparse(&new_var->var.VendorGuid,
470 short_name + strlen(short_name));
471
472 new_var->kobj.kset = efivars_kset;
473
474 i = kobject_init_and_add(&new_var->kobj, &efivar_ktype,
475 NULL, "%s", short_name);
476 kfree(short_name);
477 if (i)
478 return 1;
479
480 kobject_uevent(&new_var->kobj, KOBJ_ADD);
481 efivar_entry_add(new_var, &efivar_sysfs_list);
482
483 return 0;
484}
485
486static int
487create_efivars_bin_attributes(void)
488{
489 struct bin_attribute *attr;
490 int error;
491
492 /* new_var */
493 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
494 if (!attr)
495 return -ENOMEM;
496
497 attr->attr.name = "new_var";
498 attr->attr.mode = 0200;
499 attr->write = efivar_create;
500 efivars_new_var = attr;
501
502 /* del_var */
503 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
504 if (!attr) {
505 error = -ENOMEM;
506 goto out_free;
507 }
508 attr->attr.name = "del_var";
509 attr->attr.mode = 0200;
510 attr->write = efivar_delete;
511 efivars_del_var = attr;
512
513 sysfs_bin_attr_init(efivars_new_var);
514 sysfs_bin_attr_init(efivars_del_var);
515
516 /* Register */
517 error = sysfs_create_bin_file(&efivars_kset->kobj, efivars_new_var);
518 if (error) {
519 printk(KERN_ERR "efivars: unable to create new_var sysfs file"
520 " due to error %d\n", error);
521 goto out_free;
522 }
523
524 error = sysfs_create_bin_file(&efivars_kset->kobj, efivars_del_var);
525 if (error) {
526 printk(KERN_ERR "efivars: unable to create del_var sysfs file"
527 " due to error %d\n", error);
528 sysfs_remove_bin_file(&efivars_kset->kobj, efivars_new_var);
529 goto out_free;
530 }
531
532 return 0;
533out_free:
534 kfree(efivars_del_var);
535 efivars_del_var = NULL;
536 kfree(efivars_new_var);
537 efivars_new_var = NULL;
538 return error;
539}
540
541static int efivar_update_sysfs_entry(efi_char16_t *name, efi_guid_t vendor,
542 unsigned long name_size, void *data)
543{
544 struct efivar_entry *entry = data;
545
546 if (efivar_entry_find(name, vendor, &efivar_sysfs_list, false))
547 return 0;
548
549 memcpy(entry->var.VariableName, name, name_size);
550 memcpy(&(entry->var.VendorGuid), &vendor, sizeof(efi_guid_t));
551
552 return 1;
553}
554
555static void efivar_update_sysfs_entries(struct work_struct *work)
556{
557 struct efivar_entry *entry;
558 int err;
559
Tom Gundersena9499fa2013-02-08 15:37:06 +0000560 /* Add new sysfs entries */
561 while (1) {
Seiji Aguchid51df2c2013-05-10 20:45:36 +0000562 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
563 if (!entry)
564 return;
Tom Gundersena9499fa2013-02-08 15:37:06 +0000565
566 err = efivar_init(efivar_update_sysfs_entry, entry,
567 true, false, &efivar_sysfs_list);
568 if (!err)
569 break;
570
571 efivar_create_sysfs_entry(entry);
572 }
573
574 kfree(entry);
575}
576
577static int efivars_sysfs_callback(efi_char16_t *name, efi_guid_t vendor,
578 unsigned long name_size, void *data)
579{
580 struct efivar_entry *entry;
581
582 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
583 if (!entry)
584 return -ENOMEM;
585
586 memcpy(entry->var.VariableName, name, name_size);
587 memcpy(&(entry->var.VendorGuid), &vendor, sizeof(efi_guid_t));
588
589 efivar_create_sysfs_entry(entry);
590
591 return 0;
592}
593
594static int efivar_sysfs_destroy(struct efivar_entry *entry, void *data)
595{
596 efivar_entry_remove(entry);
597 efivar_unregister(entry);
598 return 0;
599}
600
Bojan Prtvar6f9dd302013-09-03 08:56:20 +0200601static void efivars_sysfs_exit(void)
Tom Gundersena9499fa2013-02-08 15:37:06 +0000602{
603 /* Remove all entries and destroy */
604 __efivar_entry_iter(efivar_sysfs_destroy, &efivar_sysfs_list, NULL, NULL);
605
606 if (efivars_new_var)
607 sysfs_remove_bin_file(&efivars_kset->kobj, efivars_new_var);
608 if (efivars_del_var)
609 sysfs_remove_bin_file(&efivars_kset->kobj, efivars_del_var);
610 kfree(efivars_new_var);
611 kfree(efivars_del_var);
612 kset_unregister(efivars_kset);
613}
614
615int efivars_sysfs_init(void)
616{
617 struct kobject *parent_kobj = efivars_kobject();
618 int error = 0;
619
Matt Flemingd320c072013-07-11 07:30:33 +0100620 if (!efi_enabled(EFI_RUNTIME_SERVICES))
621 return -ENODEV;
622
Tom Gundersena9499fa2013-02-08 15:37:06 +0000623 /* No efivars has been registered yet */
624 if (!parent_kobj)
625 return 0;
626
627 printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,
628 EFIVARS_DATE);
629
630 efivars_kset = kset_create_and_add("vars", NULL, parent_kobj);
631 if (!efivars_kset) {
632 printk(KERN_ERR "efivars: Subsystem registration failed.\n");
633 return -ENOMEM;
634 }
635
636 efivar_init(efivars_sysfs_callback, NULL, false,
637 true, &efivar_sysfs_list);
638
639 error = create_efivars_bin_attributes();
640 if (error) {
641 efivars_sysfs_exit();
642 return error;
643 }
644
645 INIT_WORK(&efivar_work, efivar_update_sysfs_entries);
646
647 return 0;
648}
649EXPORT_SYMBOL_GPL(efivars_sysfs_init);
650
651module_init(efivars_sysfs_init);
652module_exit(efivars_sysfs_exit);