1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/capability.h>
23#include <linux/types.h>
24#include <linux/errno.h>
25#include <linux/init.h>
26#include <linux/mm.h>
27#include <linux/module.h>
28#include <linux/string.h>
29#include <linux/smp.h>
30#include <linux/efi.h>
31#include <linux/sysfs.h>
32#include <linux/device.h>
33#include <linux/slab.h>
34#include <linux/ctype.h>
35#include <linux/ucs2_string.h>
36
37
38static struct efivars *__efivars;
39
40static bool efivar_wq_enabled = true;
41DECLARE_WORK(efivar_work, NULL);
42EXPORT_SYMBOL_GPL(efivar_work);
43
44static bool
45validate_device_path(efi_char16_t *var_name, int match, u8 *buffer,
46 unsigned long len)
47{
48 struct efi_generic_dev_path *node;
49 int offset = 0;
50
51 node = (struct efi_generic_dev_path *)buffer;
52
53 if (len < sizeof(*node))
54 return false;
55
56 while (offset <= len - sizeof(*node) &&
57 node->length >= sizeof(*node) &&
58 node->length <= len - offset) {
59 offset += node->length;
60
61 if ((node->type == EFI_DEV_END_PATH ||
62 node->type == EFI_DEV_END_PATH2) &&
63 node->sub_type == EFI_DEV_END_ENTIRE)
64 return true;
65
66 node = (struct efi_generic_dev_path *)(buffer + offset);
67 }
68
69
70
71
72
73
74 return false;
75}
76
77static bool
78validate_boot_order(efi_char16_t *var_name, int match, u8 *buffer,
79 unsigned long len)
80{
81
82 if ((len % 2) != 0)
83 return false;
84
85 return true;
86}
87
88static bool
89validate_load_option(efi_char16_t *var_name, int match, u8 *buffer,
90 unsigned long len)
91{
92 u16 filepathlength;
93 int i, desclength = 0, namelen;
94
95 namelen = ucs2_strnlen(var_name, EFI_VAR_NAME_LEN);
96
97
98 for (i = match; i < match+4; i++) {
99 if (var_name[i] > 127 ||
100 hex_to_bin(var_name[i] & 0xff) < 0)
101 return true;
102 }
103
104
105 if (namelen > match + 4)
106 return false;
107
108
109 if (len < 8)
110 return false;
111
112 filepathlength = buffer[4] | buffer[5] << 8;
113
114
115
116
117
118 desclength = ucs2_strsize((efi_char16_t *)(buffer + 6), len - 6) + 2;
119
120
121 if (!desclength)
122 return false;
123
124
125
126
127
128
129 if ((desclength + filepathlength + 6) > len)
130 return false;
131
132
133
134
135 return validate_device_path(var_name, match, buffer + desclength + 6,
136 filepathlength);
137}
138
139static bool
140validate_uint16(efi_char16_t *var_name, int match, u8 *buffer,
141 unsigned long len)
142{
143
144 if (len != 2)
145 return false;
146
147 return true;
148}
149
150static bool
151validate_ascii_string(efi_char16_t *var_name, int match, u8 *buffer,
152 unsigned long len)
153{
154 int i;
155
156 for (i = 0; i < len; i++) {
157 if (buffer[i] > 127)
158 return false;
159
160 if (buffer[i] == 0)
161 return true;
162 }
163
164 return false;
165}
166
167struct variable_validate {
168 efi_guid_t vendor;
169 char *name;
170 bool (*validate)(efi_char16_t *var_name, int match, u8 *data,
171 unsigned long len);
172};
173
174
175
176
177
178
179
180
181
182
183
184
185static const struct variable_validate variable_validate[] = {
186 { EFI_GLOBAL_VARIABLE_GUID, "BootNext", validate_uint16 },
187 { EFI_GLOBAL_VARIABLE_GUID, "BootOrder", validate_boot_order },
188 { EFI_GLOBAL_VARIABLE_GUID, "Boot*", validate_load_option },
189 { EFI_GLOBAL_VARIABLE_GUID, "DriverOrder", validate_boot_order },
190 { EFI_GLOBAL_VARIABLE_GUID, "Driver*", validate_load_option },
191 { EFI_GLOBAL_VARIABLE_GUID, "ConIn", validate_device_path },
192 { EFI_GLOBAL_VARIABLE_GUID, "ConInDev", validate_device_path },
193 { EFI_GLOBAL_VARIABLE_GUID, "ConOut", validate_device_path },
194 { EFI_GLOBAL_VARIABLE_GUID, "ConOutDev", validate_device_path },
195 { EFI_GLOBAL_VARIABLE_GUID, "ErrOut", validate_device_path },
196 { EFI_GLOBAL_VARIABLE_GUID, "ErrOutDev", validate_device_path },
197 { EFI_GLOBAL_VARIABLE_GUID, "Lang", validate_ascii_string },
198 { EFI_GLOBAL_VARIABLE_GUID, "OsIndications", NULL },
199 { EFI_GLOBAL_VARIABLE_GUID, "PlatformLang", validate_ascii_string },
200 { EFI_GLOBAL_VARIABLE_GUID, "Timeout", validate_uint16 },
201 { LINUX_EFI_CRASH_GUID, "*", NULL },
202 { NULL_GUID, "", NULL },
203};
204
205
206
207
208
209
210
211
212
213
214
215
216static bool
217variable_matches(const char *var_name, size_t len, const char *match_name,
218 int *match)
219{
220 for (*match = 0; ; (*match)++) {
221 char c = match_name[*match];
222
223 switch (c) {
224 case '*':
225
226 return true;
227
228 case '\0':
229
230 return (*match == len);
231
232 default:
233
234
235
236
237
238 if (*match < len && c == var_name[*match])
239 continue;
240 return false;
241 }
242 }
243}
244
245bool
246efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
247 unsigned long data_size)
248{
249 int i;
250 unsigned long utf8_size;
251 u8 *utf8_name;
252
253 utf8_size = ucs2_utf8size(var_name);
254 utf8_name = kmalloc(utf8_size + 1, GFP_KERNEL);
255 if (!utf8_name)
256 return false;
257
258 ucs2_as_utf8(utf8_name, var_name, utf8_size);
259 utf8_name[utf8_size] = '\0';
260
261 for (i = 0; variable_validate[i].name[0] != '\0'; i++) {
262 const char *name = variable_validate[i].name;
263 int match = 0;
264
265 if (efi_guidcmp(vendor, variable_validate[i].vendor))
266 continue;
267
268 if (variable_matches(utf8_name, utf8_size+1, name, &match)) {
269 if (variable_validate[i].validate == NULL)
270 break;
271 kfree(utf8_name);
272 return variable_validate[i].validate(var_name, match,
273 data, data_size);
274 }
275 }
276 kfree(utf8_name);
277 return true;
278}
279EXPORT_SYMBOL_GPL(efivar_validate);
280
281bool
282efivar_variable_is_removable(efi_guid_t vendor, const char *var_name,
283 size_t len)
284{
285 int i;
286 bool found = false;
287 int match = 0;
288
289
290
291
292 for (i = 0; variable_validate[i].name[0] != '\0'; i++) {
293 if (efi_guidcmp(variable_validate[i].vendor, vendor))
294 continue;
295
296 if (variable_matches(var_name, len,
297 variable_validate[i].name, &match)) {
298 found = true;
299 break;
300 }
301 }
302
303
304
305
306 return found;
307}
308EXPORT_SYMBOL_GPL(efivar_variable_is_removable);
309
310static efi_status_t
311check_var_size(u32 attributes, unsigned long size)
312{
313 const struct efivar_operations *fops = __efivars->ops;
314
315 if (!fops->query_variable_store)
316 return EFI_UNSUPPORTED;
317
318 return fops->query_variable_store(attributes, size, false);
319}
320
321static efi_status_t
322check_var_size_nonblocking(u32 attributes, unsigned long size)
323{
324 const struct efivar_operations *fops = __efivars->ops;
325
326 if (!fops->query_variable_store)
327 return EFI_UNSUPPORTED;
328
329 return fops->query_variable_store(attributes, size, true);
330}
331
332static int efi_status_to_err(efi_status_t status)
333{
334 int err;
335
336 switch (status) {
337 case EFI_SUCCESS:
338 err = 0;
339 break;
340 case EFI_INVALID_PARAMETER:
341 err = -EINVAL;
342 break;
343 case EFI_OUT_OF_RESOURCES:
344 err = -ENOSPC;
345 break;
346 case EFI_DEVICE_ERROR:
347 err = -EIO;
348 break;
349 case EFI_WRITE_PROTECTED:
350 err = -EROFS;
351 break;
352 case EFI_SECURITY_VIOLATION:
353 err = -EACCES;
354 break;
355 case EFI_NOT_FOUND:
356 err = -ENOENT;
357 break;
358 default:
359 err = -EINVAL;
360 }
361
362 return err;
363}
364
365static bool variable_is_present(efi_char16_t *variable_name, efi_guid_t *vendor,
366 struct list_head *head)
367{
368 struct efivar_entry *entry, *n;
369 unsigned long strsize1, strsize2;
370 bool found = false;
371
372 strsize1 = ucs2_strsize(variable_name, 1024);
373 list_for_each_entry_safe(entry, n, head, list) {
374 strsize2 = ucs2_strsize(entry->var.VariableName, 1024);
375 if (strsize1 == strsize2 &&
376 !memcmp(variable_name, &(entry->var.VariableName),
377 strsize2) &&
378 !efi_guidcmp(entry->var.VendorGuid,
379 *vendor)) {
380 found = true;
381 break;
382 }
383 }
384 return found;
385}
386
387
388
389
390
391
392static unsigned long var_name_strnsize(efi_char16_t *variable_name,
393 unsigned long variable_name_size)
394{
395 unsigned long len;
396 efi_char16_t c;
397
398
399
400
401
402
403 for (len = 2; len <= variable_name_size; len += sizeof(c)) {
404 c = variable_name[(len / sizeof(c)) - 1];
405 if (!c)
406 break;
407 }
408
409 return min(len, variable_name_size);
410}
411
412
413
414
415
416static void dup_variable_bug(efi_char16_t *str16, efi_guid_t *vendor_guid,
417 unsigned long len16)
418{
419 size_t i, len8 = len16 / sizeof(efi_char16_t);
420 char *str8;
421
422
423
424
425
426
427 efivar_wq_enabled = false;
428
429 str8 = kzalloc(len8, GFP_KERNEL);
430 if (!str8)
431 return;
432
433 for (i = 0; i < len8; i++)
434 str8[i] = str16[i];
435
436 printk(KERN_WARNING "efivars: duplicate variable: %s-%pUl\n",
437 str8, vendor_guid);
438 kfree(str8);
439}
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
455 void *data, bool atomic, bool duplicates,
456 struct list_head *head)
457{
458 const struct efivar_operations *ops = __efivars->ops;
459 unsigned long variable_name_size = 1024;
460 efi_char16_t *variable_name;
461 efi_status_t status;
462 efi_guid_t vendor_guid;
463 int err = 0;
464
465 variable_name = kzalloc(variable_name_size, GFP_KERNEL);
466 if (!variable_name) {
467 printk(KERN_ERR "efivars: Memory allocation failed.\n");
468 return -ENOMEM;
469 }
470
471 spin_lock_irq(&__efivars->lock);
472
473
474
475
476
477
478 do {
479 variable_name_size = 1024;
480
481 status = ops->get_next_variable(&variable_name_size,
482 variable_name,
483 &vendor_guid);
484 switch (status) {
485 case EFI_SUCCESS:
486 if (!atomic)
487 spin_unlock_irq(&__efivars->lock);
488
489 variable_name_size = var_name_strnsize(variable_name,
490 variable_name_size);
491
492
493
494
495
496
497
498
499
500 if (duplicates &&
501 variable_is_present(variable_name, &vendor_guid, head)) {
502 dup_variable_bug(variable_name, &vendor_guid,
503 variable_name_size);
504 if (!atomic)
505 spin_lock_irq(&__efivars->lock);
506
507 status = EFI_NOT_FOUND;
508 break;
509 }
510
511 err = func(variable_name, vendor_guid, variable_name_size, data);
512 if (err)
513 status = EFI_NOT_FOUND;
514
515 if (!atomic)
516 spin_lock_irq(&__efivars->lock);
517
518 break;
519 case EFI_NOT_FOUND:
520 break;
521 default:
522 printk(KERN_WARNING "efivars: get_next_variable: status=%lx\n",
523 status);
524 status = EFI_NOT_FOUND;
525 break;
526 }
527
528 } while (status != EFI_NOT_FOUND);
529
530 spin_unlock_irq(&__efivars->lock);
531
532 kfree(variable_name);
533
534 return err;
535}
536EXPORT_SYMBOL_GPL(efivar_init);
537
538
539
540
541
542
543void efivar_entry_add(struct efivar_entry *entry, struct list_head *head)
544{
545 spin_lock_irq(&__efivars->lock);
546 list_add(&entry->list, head);
547 spin_unlock_irq(&__efivars->lock);
548}
549EXPORT_SYMBOL_GPL(efivar_entry_add);
550
551
552
553
554
555void efivar_entry_remove(struct efivar_entry *entry)
556{
557 spin_lock_irq(&__efivars->lock);
558 list_del(&entry->list);
559 spin_unlock_irq(&__efivars->lock);
560}
561EXPORT_SYMBOL_GPL(efivar_entry_remove);
562
563
564
565
566
567
568
569
570
571
572
573
574static void efivar_entry_list_del_unlock(struct efivar_entry *entry)
575{
576 lockdep_assert_held(&__efivars->lock);
577
578 list_del(&entry->list);
579 spin_unlock_irq(&__efivars->lock);
580}
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597int __efivar_entry_delete(struct efivar_entry *entry)
598{
599 const struct efivar_operations *ops = __efivars->ops;
600 efi_status_t status;
601
602 lockdep_assert_held(&__efivars->lock);
603
604 status = ops->set_variable(entry->var.VariableName,
605 &entry->var.VendorGuid,
606 0, 0, NULL);
607
608 return efi_status_to_err(status);
609}
610EXPORT_SYMBOL_GPL(__efivar_entry_delete);
611
612
613
614
615
616
617
618
619
620
621
622
623int efivar_entry_delete(struct efivar_entry *entry)
624{
625 const struct efivar_operations *ops = __efivars->ops;
626 efi_status_t status;
627
628 spin_lock_irq(&__efivars->lock);
629 status = ops->set_variable(entry->var.VariableName,
630 &entry->var.VendorGuid,
631 0, 0, NULL);
632 if (!(status == EFI_SUCCESS || status == EFI_NOT_FOUND)) {
633 spin_unlock_irq(&__efivars->lock);
634 return efi_status_to_err(status);
635 }
636
637 efivar_entry_list_del_unlock(entry);
638 return 0;
639}
640EXPORT_SYMBOL_GPL(efivar_entry_delete);
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
664 unsigned long size, void *data, struct list_head *head)
665{
666 const struct efivar_operations *ops = __efivars->ops;
667 efi_status_t status;
668 efi_char16_t *name = entry->var.VariableName;
669 efi_guid_t vendor = entry->var.VendorGuid;
670
671 spin_lock_irq(&__efivars->lock);
672
673 if (head && efivar_entry_find(name, vendor, head, false)) {
674 spin_unlock_irq(&__efivars->lock);
675 return -EEXIST;
676 }
677
678 status = check_var_size(attributes, size + ucs2_strsize(name, 1024));
679 if (status == EFI_SUCCESS || status == EFI_UNSUPPORTED)
680 status = ops->set_variable(name, &vendor,
681 attributes, size, data);
682
683 spin_unlock_irq(&__efivars->lock);
684
685 return efi_status_to_err(status);
686
687}
688EXPORT_SYMBOL_GPL(efivar_entry_set);
689
690
691
692
693
694
695
696
697
698
699static int
700efivar_entry_set_nonblocking(efi_char16_t *name, efi_guid_t vendor,
701 u32 attributes, unsigned long size, void *data)
702{
703 const struct efivar_operations *ops = __efivars->ops;
704 unsigned long flags;
705 efi_status_t status;
706
707 if (!spin_trylock_irqsave(&__efivars->lock, flags))
708 return -EBUSY;
709
710 status = check_var_size_nonblocking(attributes,
711 size + ucs2_strsize(name, 1024));
712 if (status != EFI_SUCCESS) {
713 spin_unlock_irqrestore(&__efivars->lock, flags);
714 return -ENOSPC;
715 }
716
717 status = ops->set_variable_nonblocking(name, &vendor, attributes,
718 size, data);
719
720 spin_unlock_irqrestore(&__efivars->lock, flags);
721 return efi_status_to_err(status);
722}
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
742 bool block, unsigned long size, void *data)
743{
744 const struct efivar_operations *ops = __efivars->ops;
745 unsigned long flags;
746 efi_status_t status;
747
748 if (!ops->query_variable_store)
749 return -ENOSYS;
750
751
752
753
754
755
756
757
758
759
760
761 if (!block && ops->set_variable_nonblocking)
762 return efivar_entry_set_nonblocking(name, vendor, attributes,
763 size, data);
764
765 if (!block) {
766 if (!spin_trylock_irqsave(&__efivars->lock, flags))
767 return -EBUSY;
768 } else {
769 spin_lock_irqsave(&__efivars->lock, flags);
770 }
771
772 status = check_var_size(attributes, size + ucs2_strsize(name, 1024));
773 if (status != EFI_SUCCESS) {
774 spin_unlock_irqrestore(&__efivars->lock, flags);
775 return -ENOSPC;
776 }
777
778 status = ops->set_variable(name, &vendor, attributes, size, data);
779
780 spin_unlock_irqrestore(&__efivars->lock, flags);
781
782 return efi_status_to_err(status);
783}
784EXPORT_SYMBOL_GPL(efivar_entry_set_safe);
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
804 struct list_head *head, bool remove)
805{
806 struct efivar_entry *entry, *n;
807 int strsize1, strsize2;
808 bool found = false;
809
810 lockdep_assert_held(&__efivars->lock);
811
812 list_for_each_entry_safe(entry, n, head, list) {
813 strsize1 = ucs2_strsize(name, 1024);
814 strsize2 = ucs2_strsize(entry->var.VariableName, 1024);
815 if (strsize1 == strsize2 &&
816 !memcmp(name, &(entry->var.VariableName), strsize1) &&
817 !efi_guidcmp(guid, entry->var.VendorGuid)) {
818 found = true;
819 break;
820 }
821 }
822
823 if (!found)
824 return NULL;
825
826 if (remove) {
827 if (entry->scanning) {
828
829
830
831
832 entry->deleting = true;
833 } else
834 list_del(&entry->list);
835 }
836
837 return entry;
838}
839EXPORT_SYMBOL_GPL(efivar_entry_find);
840
841
842
843
844
845
846int efivar_entry_size(struct efivar_entry *entry, unsigned long *size)
847{
848 const struct efivar_operations *ops = __efivars->ops;
849 efi_status_t status;
850
851 *size = 0;
852
853 spin_lock_irq(&__efivars->lock);
854 status = ops->get_variable(entry->var.VariableName,
855 &entry->var.VendorGuid, NULL, size, NULL);
856 spin_unlock_irq(&__efivars->lock);
857
858 if (status != EFI_BUFFER_TOO_SMALL)
859 return efi_status_to_err(status);
860
861 return 0;
862}
863EXPORT_SYMBOL_GPL(efivar_entry_size);
864
865
866
867
868
869
870
871
872
873
874
875
876int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
877 unsigned long *size, void *data)
878{
879 const struct efivar_operations *ops = __efivars->ops;
880 efi_status_t status;
881
882 lockdep_assert_held(&__efivars->lock);
883
884 status = ops->get_variable(entry->var.VariableName,
885 &entry->var.VendorGuid,
886 attributes, size, data);
887
888 return efi_status_to_err(status);
889}
890EXPORT_SYMBOL_GPL(__efivar_entry_get);
891
892
893
894
895
896
897
898
899int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
900 unsigned long *size, void *data)
901{
902 const struct efivar_operations *ops = __efivars->ops;
903 efi_status_t status;
904
905 spin_lock_irq(&__efivars->lock);
906 status = ops->get_variable(entry->var.VariableName,
907 &entry->var.VendorGuid,
908 attributes, size, data);
909 spin_unlock_irq(&__efivars->lock);
910
911 return efi_status_to_err(status);
912}
913EXPORT_SYMBOL_GPL(efivar_entry_get);
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
938 unsigned long *size, void *data, bool *set)
939{
940 const struct efivar_operations *ops = __efivars->ops;
941 efi_char16_t *name = entry->var.VariableName;
942 efi_guid_t *vendor = &entry->var.VendorGuid;
943 efi_status_t status;
944 int err;
945
946 *set = false;
947
948 if (efivar_validate(*vendor, name, data, *size) == false)
949 return -EINVAL;
950
951
952
953
954
955
956 spin_lock_irq(&__efivars->lock);
957
958
959
960
961 status = check_var_size(attributes, *size + ucs2_strsize(name, 1024));
962 if (status != EFI_SUCCESS) {
963 if (status != EFI_UNSUPPORTED) {
964 err = efi_status_to_err(status);
965 goto out;
966 }
967
968 if (*size > 65536) {
969 err = -ENOSPC;
970 goto out;
971 }
972 }
973
974 status = ops->set_variable(name, vendor, attributes, *size, data);
975 if (status != EFI_SUCCESS) {
976 err = efi_status_to_err(status);
977 goto out;
978 }
979
980 *set = true;
981
982
983
984
985
986
987
988 *size = 0;
989 status = ops->get_variable(entry->var.VariableName,
990 &entry->var.VendorGuid,
991 NULL, size, NULL);
992
993 if (status == EFI_NOT_FOUND)
994 efivar_entry_list_del_unlock(entry);
995 else
996 spin_unlock_irq(&__efivars->lock);
997
998 if (status && status != EFI_BUFFER_TOO_SMALL)
999 return efi_status_to_err(status);
1000
1001 return 0;
1002
1003out:
1004 spin_unlock_irq(&__efivars->lock);
1005 return err;
1006
1007}
1008EXPORT_SYMBOL_GPL(efivar_entry_set_get_size);
1009
1010
1011
1012
1013
1014
1015
1016
1017void efivar_entry_iter_begin(void)
1018{
1019 spin_lock_irq(&__efivars->lock);
1020}
1021EXPORT_SYMBOL_GPL(efivar_entry_iter_begin);
1022
1023
1024
1025
1026
1027
1028void efivar_entry_iter_end(void)
1029{
1030 spin_unlock_irq(&__efivars->lock);
1031}
1032EXPORT_SYMBOL_GPL(efivar_entry_iter_end);
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1057 struct list_head *head, void *data,
1058 struct efivar_entry **prev)
1059{
1060 struct efivar_entry *entry, *n;
1061 int err = 0;
1062
1063 if (!prev || !*prev) {
1064 list_for_each_entry_safe(entry, n, head, list) {
1065 err = func(entry, data);
1066 if (err)
1067 break;
1068 }
1069
1070 if (prev)
1071 *prev = entry;
1072
1073 return err;
1074 }
1075
1076
1077 list_for_each_entry_safe_continue((*prev), n, head, list) {
1078 err = func(*prev, data);
1079 if (err)
1080 break;
1081 }
1082
1083 return err;
1084}
1085EXPORT_SYMBOL_GPL(__efivar_entry_iter);
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1102 struct list_head *head, void *data)
1103{
1104 int err = 0;
1105
1106 efivar_entry_iter_begin();
1107 err = __efivar_entry_iter(func, head, data, NULL);
1108 efivar_entry_iter_end();
1109
1110 return err;
1111}
1112EXPORT_SYMBOL_GPL(efivar_entry_iter);
1113
1114
1115
1116
1117
1118
1119
1120struct kobject *efivars_kobject(void)
1121{
1122 if (!__efivars)
1123 return NULL;
1124
1125 return __efivars->kobject;
1126}
1127EXPORT_SYMBOL_GPL(efivars_kobject);
1128
1129
1130
1131
1132void efivar_run_worker(void)
1133{
1134 if (efivar_wq_enabled)
1135 schedule_work(&efivar_work);
1136}
1137EXPORT_SYMBOL_GPL(efivar_run_worker);
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147int efivars_register(struct efivars *efivars,
1148 const struct efivar_operations *ops,
1149 struct kobject *kobject)
1150{
1151 spin_lock_init(&efivars->lock);
1152 efivars->ops = ops;
1153 efivars->kobject = kobject;
1154
1155 __efivars = efivars;
1156
1157 return 0;
1158}
1159EXPORT_SYMBOL_GPL(efivars_register);
1160
1161
1162
1163
1164
1165
1166
1167
1168int efivars_unregister(struct efivars *efivars)
1169{
1170 int rv;
1171
1172 if (!__efivars) {
1173 printk(KERN_ERR "efivars not registered\n");
1174 rv = -EINVAL;
1175 goto out;
1176 }
1177
1178 if (__efivars != efivars) {
1179 rv = -EINVAL;
1180 goto out;
1181 }
1182
1183 __efivars = NULL;
1184
1185 rv = 0;
1186out:
1187 return rv;
1188}
1189EXPORT_SYMBOL_GPL(efivars_unregister);
1190