aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware/efivars.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/firmware/efivars.c')
-rw-r--r--drivers/firmware/efivars.c350
1 files changed, 213 insertions, 137 deletions
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 2a62ec6390e0..5f29aafd4462 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -90,17 +90,6 @@ MODULE_LICENSE("GPL");
90MODULE_VERSION(EFIVARS_VERSION); 90MODULE_VERSION(EFIVARS_VERSION);
91 91
92/* 92/*
93 * efivars_lock protects two things:
94 * 1) efivar_list - adds, removals, reads, writes
95 * 2) efi.[gs]et_variable() calls.
96 * It must not be held when creating sysfs entries or calling kmalloc.
97 * efi.get_next_variable() is only called from efivars_init(),
98 * which is protected by the BKL, so that path is safe.
99 */
100static DEFINE_SPINLOCK(efivars_lock);
101static LIST_HEAD(efivar_list);
102
103/*
104 * The maximum size of VariableName + Data = 1024 93 * The maximum size of VariableName + Data = 1024
105 * Therefore, it's reasonable to save that much 94 * Therefore, it's reasonable to save that much
106 * space in each part of the structure, 95 * space in each part of the structure,
@@ -118,6 +107,7 @@ struct efi_variable {
118 107
119 108
120struct efivar_entry { 109struct efivar_entry {
110 struct efivars *efivars;
121 struct efi_variable var; 111 struct efi_variable var;
122 struct list_head list; 112 struct list_head list;
123 struct kobject kobj; 113 struct kobject kobj;
@@ -144,9 +134,10 @@ struct efivar_attribute efivar_attr_##_name = { \
144 * Prototype for sysfs creation function 134 * Prototype for sysfs creation function
145 */ 135 */
146static int 136static int
147efivar_create_sysfs_entry(unsigned long variable_name_size, 137efivar_create_sysfs_entry(struct efivars *efivars,
148 efi_char16_t *variable_name, 138 unsigned long variable_name_size,
149 efi_guid_t *vendor_guid); 139 efi_char16_t *variable_name,
140 efi_guid_t *vendor_guid);
150 141
151/* Return the number of unicode characters in data */ 142/* Return the number of unicode characters in data */
152static unsigned long 143static unsigned long
@@ -170,18 +161,18 @@ utf8_strsize(efi_char16_t *data, unsigned long maxlength)
170} 161}
171 162
172static efi_status_t 163static efi_status_t
173get_var_data(struct efi_variable *var) 164get_var_data(struct efivars *efivars, struct efi_variable *var)
174{ 165{
175 efi_status_t status; 166 efi_status_t status;
176 167
177 spin_lock(&efivars_lock); 168 spin_lock(&efivars->lock);
178 var->DataSize = 1024; 169 var->DataSize = 1024;
179 status = efi.get_variable(var->VariableName, 170 status = efivars->ops->get_variable(var->VariableName,
180 &var->VendorGuid, 171 &var->VendorGuid,
181 &var->Attributes, 172 &var->Attributes,
182 &var->DataSize, 173 &var->DataSize,
183 var->Data); 174 var->Data);
184 spin_unlock(&efivars_lock); 175 spin_unlock(&efivars->lock);
185 if (status != EFI_SUCCESS) { 176 if (status != EFI_SUCCESS) {
186 printk(KERN_WARNING "efivars: get_variable() failed 0x%lx!\n", 177 printk(KERN_WARNING "efivars: get_variable() failed 0x%lx!\n",
187 status); 178 status);
@@ -215,7 +206,7 @@ efivar_attr_read(struct efivar_entry *entry, char *buf)
215 if (!entry || !buf) 206 if (!entry || !buf)
216 return -EINVAL; 207 return -EINVAL;
217 208
218 status = get_var_data(var); 209 status = get_var_data(entry->efivars, var);
219 if (status != EFI_SUCCESS) 210 if (status != EFI_SUCCESS)
220 return -EIO; 211 return -EIO;
221 212
@@ -238,7 +229,7 @@ efivar_size_read(struct efivar_entry *entry, char *buf)
238 if (!entry || !buf) 229 if (!entry || !buf)
239 return -EINVAL; 230 return -EINVAL;
240 231
241 status = get_var_data(var); 232 status = get_var_data(entry->efivars, var);
242 if (status != EFI_SUCCESS) 233 if (status != EFI_SUCCESS)
243 return -EIO; 234 return -EIO;
244 235
@@ -255,7 +246,7 @@ efivar_data_read(struct efivar_entry *entry, char *buf)
255 if (!entry || !buf) 246 if (!entry || !buf)
256 return -EINVAL; 247 return -EINVAL;
257 248
258 status = get_var_data(var); 249 status = get_var_data(entry->efivars, var);
259 if (status != EFI_SUCCESS) 250 if (status != EFI_SUCCESS)
260 return -EIO; 251 return -EIO;
261 252
@@ -270,6 +261,7 @@ static ssize_t
270efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count) 261efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
271{ 262{
272 struct efi_variable *new_var, *var = &entry->var; 263 struct efi_variable *new_var, *var = &entry->var;
264 struct efivars *efivars = entry->efivars;
273 efi_status_t status = EFI_NOT_FOUND; 265 efi_status_t status = EFI_NOT_FOUND;
274 266
275 if (count != sizeof(struct efi_variable)) 267 if (count != sizeof(struct efi_variable))
@@ -291,14 +283,14 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
291 return -EINVAL; 283 return -EINVAL;
292 } 284 }
293 285
294 spin_lock(&efivars_lock); 286 spin_lock(&efivars->lock);
295 status = efi.set_variable(new_var->VariableName, 287 status = efivars->ops->set_variable(new_var->VariableName,
296 &new_var->VendorGuid, 288 &new_var->VendorGuid,
297 new_var->Attributes, 289 new_var->Attributes,
298 new_var->DataSize, 290 new_var->DataSize,
299 new_var->Data); 291 new_var->Data);
300 292
301 spin_unlock(&efivars_lock); 293 spin_unlock(&efivars->lock);
302 294
303 if (status != EFI_SUCCESS) { 295 if (status != EFI_SUCCESS) {
304 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", 296 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
@@ -319,7 +311,7 @@ efivar_show_raw(struct efivar_entry *entry, char *buf)
319 if (!entry || !buf) 311 if (!entry || !buf)
320 return 0; 312 return 0;
321 313
322 status = get_var_data(var); 314 status = get_var_data(entry->efivars, var);
323 if (status != EFI_SUCCESS) 315 if (status != EFI_SUCCESS)
324 return -EIO; 316 return -EIO;
325 317
@@ -329,7 +321,7 @@ efivar_show_raw(struct efivar_entry *entry, char *buf)
329 321
330/* 322/*
331 * Generic read/write functions that call the specific functions of 323 * Generic read/write functions that call the specific functions of
332 * the atttributes... 324 * the attributes...
333 */ 325 */
334static ssize_t efivar_attr_show(struct kobject *kobj, struct attribute *attr, 326static ssize_t efivar_attr_show(struct kobject *kobj, struct attribute *attr,
335 char *buf) 327 char *buf)
@@ -407,6 +399,7 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
407 char *buf, loff_t pos, size_t count) 399 char *buf, loff_t pos, size_t count)
408{ 400{
409 struct efi_variable *new_var = (struct efi_variable *)buf; 401 struct efi_variable *new_var = (struct efi_variable *)buf;
402 struct efivars *efivars = bin_attr->private;
410 struct efivar_entry *search_efivar, *n; 403 struct efivar_entry *search_efivar, *n;
411 unsigned long strsize1, strsize2; 404 unsigned long strsize1, strsize2;
412 efi_status_t status = EFI_NOT_FOUND; 405 efi_status_t status = EFI_NOT_FOUND;
@@ -415,12 +408,12 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
415 if (!capable(CAP_SYS_ADMIN)) 408 if (!capable(CAP_SYS_ADMIN))
416 return -EACCES; 409 return -EACCES;
417 410
418 spin_lock(&efivars_lock); 411 spin_lock(&efivars->lock);
419 412
420 /* 413 /*
421 * Does this variable already exist? 414 * Does this variable already exist?
422 */ 415 */
423 list_for_each_entry_safe(search_efivar, n, &efivar_list, list) { 416 list_for_each_entry_safe(search_efivar, n, &efivars->list, list) {
424 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); 417 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024);
425 strsize2 = utf8_strsize(new_var->VariableName, 1024); 418 strsize2 = utf8_strsize(new_var->VariableName, 1024);
426 if (strsize1 == strsize2 && 419 if (strsize1 == strsize2 &&
@@ -433,28 +426,31 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
433 } 426 }
434 } 427 }
435 if (found) { 428 if (found) {
436 spin_unlock(&efivars_lock); 429 spin_unlock(&efivars->lock);
437 return -EINVAL; 430 return -EINVAL;
438 } 431 }
439 432
440 /* now *really* create the variable via EFI */ 433 /* now *really* create the variable via EFI */
441 status = efi.set_variable(new_var->VariableName, 434 status = efivars->ops->set_variable(new_var->VariableName,
442 &new_var->VendorGuid, 435 &new_var->VendorGuid,
443 new_var->Attributes, 436 new_var->Attributes,
444 new_var->DataSize, 437 new_var->DataSize,
445 new_var->Data); 438 new_var->Data);
446 439
447 if (status != EFI_SUCCESS) { 440 if (status != EFI_SUCCESS) {
448 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", 441 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
449 status); 442 status);
450 spin_unlock(&efivars_lock); 443 spin_unlock(&efivars->lock);
451 return -EIO; 444 return -EIO;
452 } 445 }
453 spin_unlock(&efivars_lock); 446 spin_unlock(&efivars->lock);
454 447
455 /* Create the entry in sysfs. Locking is not required here */ 448 /* Create the entry in sysfs. Locking is not required here */
456 status = efivar_create_sysfs_entry(utf8_strsize(new_var->VariableName, 449 status = efivar_create_sysfs_entry(efivars,
457 1024), new_var->VariableName, &new_var->VendorGuid); 450 utf8_strsize(new_var->VariableName,
451 1024),
452 new_var->VariableName,
453 &new_var->VendorGuid);
458 if (status) { 454 if (status) {
459 printk(KERN_WARNING "efivars: variable created, but sysfs entry wasn't.\n"); 455 printk(KERN_WARNING "efivars: variable created, but sysfs entry wasn't.\n");
460 } 456 }
@@ -466,6 +462,7 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
466 char *buf, loff_t pos, size_t count) 462 char *buf, loff_t pos, size_t count)
467{ 463{
468 struct efi_variable *del_var = (struct efi_variable *)buf; 464 struct efi_variable *del_var = (struct efi_variable *)buf;
465 struct efivars *efivars = bin_attr->private;
469 struct efivar_entry *search_efivar, *n; 466 struct efivar_entry *search_efivar, *n;
470 unsigned long strsize1, strsize2; 467 unsigned long strsize1, strsize2;
471 efi_status_t status = EFI_NOT_FOUND; 468 efi_status_t status = EFI_NOT_FOUND;
@@ -474,12 +471,12 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
474 if (!capable(CAP_SYS_ADMIN)) 471 if (!capable(CAP_SYS_ADMIN))
475 return -EACCES; 472 return -EACCES;
476 473
477 spin_lock(&efivars_lock); 474 spin_lock(&efivars->lock);
478 475
479 /* 476 /*
480 * Does this variable already exist? 477 * Does this variable already exist?
481 */ 478 */
482 list_for_each_entry_safe(search_efivar, n, &efivar_list, list) { 479 list_for_each_entry_safe(search_efivar, n, &efivars->list, list) {
483 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); 480 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024);
484 strsize2 = utf8_strsize(del_var->VariableName, 1024); 481 strsize2 = utf8_strsize(del_var->VariableName, 1024);
485 if (strsize1 == strsize2 && 482 if (strsize1 == strsize2 &&
@@ -492,44 +489,34 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
492 } 489 }
493 } 490 }
494 if (!found) { 491 if (!found) {
495 spin_unlock(&efivars_lock); 492 spin_unlock(&efivars->lock);
496 return -EINVAL; 493 return -EINVAL;
497 } 494 }
498 /* force the Attributes/DataSize to 0 to ensure deletion */ 495 /* force the Attributes/DataSize to 0 to ensure deletion */
499 del_var->Attributes = 0; 496 del_var->Attributes = 0;
500 del_var->DataSize = 0; 497 del_var->DataSize = 0;
501 498
502 status = efi.set_variable(del_var->VariableName, 499 status = efivars->ops->set_variable(del_var->VariableName,
503 &del_var->VendorGuid, 500 &del_var->VendorGuid,
504 del_var->Attributes, 501 del_var->Attributes,
505 del_var->DataSize, 502 del_var->DataSize,
506 del_var->Data); 503 del_var->Data);
507 504
508 if (status != EFI_SUCCESS) { 505 if (status != EFI_SUCCESS) {
509 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", 506 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
510 status); 507 status);
511 spin_unlock(&efivars_lock); 508 spin_unlock(&efivars->lock);
512 return -EIO; 509 return -EIO;
513 } 510 }
514 list_del(&search_efivar->list); 511 list_del(&search_efivar->list);
515 /* We need to release this lock before unregistering. */ 512 /* We need to release this lock before unregistering. */
516 spin_unlock(&efivars_lock); 513 spin_unlock(&efivars->lock);
517 efivar_unregister(search_efivar); 514 efivar_unregister(search_efivar);
518 515
519 /* It's dead Jim.... */ 516 /* It's dead Jim.... */
520 return count; 517 return count;
521} 518}
522 519
523static struct bin_attribute var_subsys_attr_new_var = {
524 .attr = {.name = "new_var", .mode = 0200},
525 .write = efivar_create,
526};
527
528static struct bin_attribute var_subsys_attr_del_var = {
529 .attr = {.name = "del_var", .mode = 0200},
530 .write = efivar_delete,
531};
532
533/* 520/*
534 * Let's not leave out systab information that snuck into 521 * Let's not leave out systab information that snuck into
535 * the efivars driver 522 * the efivars driver
@@ -572,8 +559,6 @@ static struct attribute_group efi_subsys_attr_group = {
572 .attrs = efi_subsys_attrs, 559 .attrs = efi_subsys_attrs,
573}; 560};
574 561
575
576static struct kset *vars_kset;
577static struct kobject *efi_kobj; 562static struct kobject *efi_kobj;
578 563
579/* 564/*
@@ -582,13 +567,14 @@ static struct kobject *efi_kobj;
582 * variable_name_size = number of bytes required to hold 567 * variable_name_size = number of bytes required to hold
583 * variable_name (not counting the NULL 568 * variable_name (not counting the NULL
584 * character at the end. 569 * character at the end.
585 * efivars_lock is not held on entry or exit. 570 * efivars->lock is not held on entry or exit.
586 * Returns 1 on failure, 0 on success 571 * Returns 1 on failure, 0 on success
587 */ 572 */
588static int 573static int
589efivar_create_sysfs_entry(unsigned long variable_name_size, 574efivar_create_sysfs_entry(struct efivars *efivars,
590 efi_char16_t *variable_name, 575 unsigned long variable_name_size,
591 efi_guid_t *vendor_guid) 576 efi_char16_t *variable_name,
577 efi_guid_t *vendor_guid)
592{ 578{
593 int i, short_name_size = variable_name_size / sizeof(efi_char16_t) + 38; 579 int i, short_name_size = variable_name_size / sizeof(efi_char16_t) + 38;
594 char *short_name; 580 char *short_name;
@@ -603,6 +589,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
603 return 1; 589 return 1;
604 } 590 }
605 591
592 new_efivar->efivars = efivars;
606 memcpy(new_efivar->var.VariableName, variable_name, 593 memcpy(new_efivar->var.VariableName, variable_name,
607 variable_name_size); 594 variable_name_size);
608 memcpy(&(new_efivar->var.VendorGuid), vendor_guid, sizeof(efi_guid_t)); 595 memcpy(&(new_efivar->var.VendorGuid), vendor_guid, sizeof(efi_guid_t));
@@ -618,7 +605,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
618 *(short_name + strlen(short_name)) = '-'; 605 *(short_name + strlen(short_name)) = '-';
619 efi_guid_unparse(vendor_guid, short_name + strlen(short_name)); 606 efi_guid_unparse(vendor_guid, short_name + strlen(short_name));
620 607
621 new_efivar->kobj.kset = vars_kset; 608 new_efivar->kobj.kset = efivars->kset;
622 i = kobject_init_and_add(&new_efivar->kobj, &efivar_ktype, NULL, 609 i = kobject_init_and_add(&new_efivar->kobj, &efivar_ktype, NULL,
623 "%s", short_name); 610 "%s", short_name);
624 if (i) { 611 if (i) {
@@ -631,22 +618,95 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
631 kfree(short_name); 618 kfree(short_name);
632 short_name = NULL; 619 short_name = NULL;
633 620
634 spin_lock(&efivars_lock); 621 spin_lock(&efivars->lock);
635 list_add(&new_efivar->list, &efivar_list); 622 list_add(&new_efivar->list, &efivars->list);
636 spin_unlock(&efivars_lock); 623 spin_unlock(&efivars->lock);
637 624
638 return 0; 625 return 0;
639} 626}
640/*
641 * For now we register the efi subsystem with the firmware subsystem
642 * and the vars subsystem with the efi subsystem. In the future, it
643 * might make sense to split off the efi subsystem into its own
644 * driver, but for now only efivars will register with it, so just
645 * include it here.
646 */
647 627
648static int __init 628static int
649efivars_init(void) 629create_efivars_bin_attributes(struct efivars *efivars)
630{
631 struct bin_attribute *attr;
632 int error;
633
634 /* new_var */
635 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
636 if (!attr)
637 return -ENOMEM;
638
639 attr->attr.name = "new_var";
640 attr->attr.mode = 0200;
641 attr->write = efivar_create;
642 attr->private = efivars;
643 efivars->new_var = attr;
644
645 /* del_var */
646 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
647 if (!attr) {
648 error = -ENOMEM;
649 goto out_free;
650 }
651 attr->attr.name = "del_var";
652 attr->attr.mode = 0200;
653 attr->write = efivar_delete;
654 attr->private = efivars;
655 efivars->del_var = attr;
656
657 sysfs_bin_attr_init(efivars->new_var);
658 sysfs_bin_attr_init(efivars->del_var);
659
660 /* Register */
661 error = sysfs_create_bin_file(&efivars->kset->kobj,
662 efivars->new_var);
663 if (error) {
664 printk(KERN_ERR "efivars: unable to create new_var sysfs file"
665 " due to error %d\n", error);
666 goto out_free;
667 }
668 error = sysfs_create_bin_file(&efivars->kset->kobj,
669 efivars->del_var);
670 if (error) {
671 printk(KERN_ERR "efivars: unable to create del_var sysfs file"
672 " due to error %d\n", error);
673 sysfs_remove_bin_file(&efivars->kset->kobj,
674 efivars->new_var);
675 goto out_free;
676 }
677
678 return 0;
679out_free:
680 kfree(efivars->del_var);
681 efivars->del_var = NULL;
682 kfree(efivars->new_var);
683 efivars->new_var = NULL;
684 return error;
685}
686
687void unregister_efivars(struct efivars *efivars)
688{
689 struct efivar_entry *entry, *n;
690
691 list_for_each_entry_safe(entry, n, &efivars->list, list) {
692 spin_lock(&efivars->lock);
693 list_del(&entry->list);
694 spin_unlock(&efivars->lock);
695 efivar_unregister(entry);
696 }
697 if (efivars->new_var)
698 sysfs_remove_bin_file(&efivars->kset->kobj, efivars->new_var);
699 if (efivars->del_var)
700 sysfs_remove_bin_file(&efivars->kset->kobj, efivars->del_var);
701 kfree(efivars->new_var);
702 kfree(efivars->del_var);
703 kset_unregister(efivars->kset);
704}
705EXPORT_SYMBOL_GPL(unregister_efivars);
706
707int register_efivars(struct efivars *efivars,
708 const struct efivar_operations *ops,
709 struct kobject *parent_kobj)
650{ 710{
651 efi_status_t status = EFI_NOT_FOUND; 711 efi_status_t status = EFI_NOT_FOUND;
652 efi_guid_t vendor_guid; 712 efi_guid_t vendor_guid;
@@ -654,31 +714,21 @@ efivars_init(void)
654 unsigned long variable_name_size = 1024; 714 unsigned long variable_name_size = 1024;
655 int error = 0; 715 int error = 0;
656 716
657 if (!efi_enabled)
658 return -ENODEV;
659
660 variable_name = kzalloc(variable_name_size, GFP_KERNEL); 717 variable_name = kzalloc(variable_name_size, GFP_KERNEL);
661 if (!variable_name) { 718 if (!variable_name) {
662 printk(KERN_ERR "efivars: Memory allocation failed.\n"); 719 printk(KERN_ERR "efivars: Memory allocation failed.\n");
663 return -ENOMEM; 720 return -ENOMEM;
664 } 721 }
665 722
666 printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION, 723 spin_lock_init(&efivars->lock);
667 EFIVARS_DATE); 724 INIT_LIST_HEAD(&efivars->list);
725 efivars->ops = ops;
668 726
669 /* For now we'll register the efi directory at /sys/firmware/efi */ 727 efivars->kset = kset_create_and_add("vars", NULL, parent_kobj);
670 efi_kobj = kobject_create_and_add("efi", firmware_kobj); 728 if (!efivars->kset) {
671 if (!efi_kobj) {
672 printk(KERN_ERR "efivars: Firmware registration failed.\n");
673 error = -ENOMEM;
674 goto out_free;
675 }
676
677 vars_kset = kset_create_and_add("vars", NULL, efi_kobj);
678 if (!vars_kset) {
679 printk(KERN_ERR "efivars: Subsystem registration failed.\n"); 729 printk(KERN_ERR "efivars: Subsystem registration failed.\n");
680 error = -ENOMEM; 730 error = -ENOMEM;
681 goto out_firmware_unregister; 731 goto out;
682 } 732 }
683 733
684 /* 734 /*
@@ -689,14 +739,15 @@ efivars_init(void)
689 do { 739 do {
690 variable_name_size = 1024; 740 variable_name_size = 1024;
691 741
692 status = efi.get_next_variable(&variable_name_size, 742 status = ops->get_next_variable(&variable_name_size,
693 variable_name, 743 variable_name,
694 &vendor_guid); 744 &vendor_guid);
695 switch (status) { 745 switch (status) {
696 case EFI_SUCCESS: 746 case EFI_SUCCESS:
697 efivar_create_sysfs_entry(variable_name_size, 747 efivar_create_sysfs_entry(efivars,
698 variable_name, 748 variable_name_size,
699 &vendor_guid); 749 variable_name,
750 &vendor_guid);
700 break; 751 break;
701 case EFI_NOT_FOUND: 752 case EFI_NOT_FOUND:
702 break; 753 break;
@@ -708,53 +759,78 @@ efivars_init(void)
708 } 759 }
709 } while (status != EFI_NOT_FOUND); 760 } while (status != EFI_NOT_FOUND);
710 761
711 /* 762 error = create_efivars_bin_attributes(efivars);
712 * Now add attributes to allow creation of new vars
713 * and deletion of existing ones...
714 */
715 error = sysfs_create_bin_file(&vars_kset->kobj,
716 &var_subsys_attr_new_var);
717 if (error) 763 if (error)
718 printk(KERN_ERR "efivars: unable to create new_var sysfs file" 764 unregister_efivars(efivars);
719 " due to error %d\n", error); 765
720 error = sysfs_create_bin_file(&vars_kset->kobj, 766out:
721 &var_subsys_attr_del_var); 767 kfree(variable_name);
768
769 return error;
770}
771EXPORT_SYMBOL_GPL(register_efivars);
772
773static struct efivars __efivars;
774static struct efivar_operations ops;
775
776/*
777 * For now we register the efi subsystem with the firmware subsystem
778 * and the vars subsystem with the efi subsystem. In the future, it
779 * might make sense to split off the efi subsystem into its own
780 * driver, but for now only efivars will register with it, so just
781 * include it here.
782 */
783
784static int __init
785efivars_init(void)
786{
787 int error = 0;
788
789 printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,
790 EFIVARS_DATE);
791
792 if (!efi_enabled)
793 return 0;
794
795 /* For now we'll register the efi directory at /sys/firmware/efi */
796 efi_kobj = kobject_create_and_add("efi", firmware_kobj);
797 if (!efi_kobj) {
798 printk(KERN_ERR "efivars: Firmware registration failed.\n");
799 return -ENOMEM;
800 }
801
802 ops.get_variable = efi.get_variable;
803 ops.set_variable = efi.set_variable;
804 ops.get_next_variable = efi.get_next_variable;
805 error = register_efivars(&__efivars, &ops, efi_kobj);
722 if (error) 806 if (error)
723 printk(KERN_ERR "efivars: unable to create del_var sysfs file" 807 goto err_put;
724 " due to error %d\n", error);
725 808
726 /* Don't forget the systab entry */ 809 /* Don't forget the systab entry */
727 error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); 810 error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group);
728 if (error) 811 if (error) {
729 printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error); 812 printk(KERN_ERR
730 else 813 "efivars: Sysfs attribute export failed with error %d.\n",
731 goto out_free; 814 error);
815 goto err_unregister;
816 }
732 817
733 kset_unregister(vars_kset); 818 return 0;
734 819
735out_firmware_unregister: 820err_unregister:
821 unregister_efivars(&__efivars);
822err_put:
736 kobject_put(efi_kobj); 823 kobject_put(efi_kobj);
737
738out_free:
739 kfree(variable_name);
740
741 return error; 824 return error;
742} 825}
743 826
744static void __exit 827static void __exit
745efivars_exit(void) 828efivars_exit(void)
746{ 829{
747 struct efivar_entry *entry, *n; 830 if (efi_enabled) {
748 831 unregister_efivars(&__efivars);
749 list_for_each_entry_safe(entry, n, &efivar_list, list) { 832 kobject_put(efi_kobj);
750 spin_lock(&efivars_lock);
751 list_del(&entry->list);
752 spin_unlock(&efivars_lock);
753 efivar_unregister(entry);
754 } 833 }
755
756 kset_unregister(vars_kset);
757 kobject_put(efi_kobj);
758} 834}
759 835
760module_init(efivars_init); 836module_init(efivars_init);