xref: /dragonfly/lib/libefivar/efivar.h (revision 7b1120e5)
1 /*-
2  * Copyright (c) 2016 Netflix, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer
10  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD: head/lib/libefivar/efivar.h 307071 2016-10-11 22:30:41Z imp $
27  */
28 
29 #ifndef	_EFIVAR_H_
30 #define	_EFIVAR_H_
31 
32 #include <uuid.h>
33 #include <sys/efi.h>
34 #include <sys/endian.h>
35 #include <stdint.h>
36 
37 /* Shoud these be elsewhere ? */
38 #define	EFI_VARIABLE_NON_VOLATILE		0x00000001
39 #define	EFI_VARIABLE_BOOTSERVICE_ACCESS		0x00000002
40 #define	EFI_VARIABLE_RUNTIME_ACCESS		0x00000004
41 #define	EFI_VARIABLE_HARDWARE_ERROR_RECORD	0x00000008
42 #define	EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS	0x00000010
43 #define	EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS \
44 						0x00000020
45 #define	EFI_VARIABLE_APPEND_WRITE		0x00000040
46 #if 0 /* todo */
47 #define	EFI_VARIABLE_HAS_AUTH_HEADER
48 #define EFI_VARIABLE_HAS_SIGNATURE
49 #endif
50 
51 
52 typedef uuid_t efi_guid_t;
53 #if BYTE_ORDER == LITTLE_ENDIAN
54 #define	EFI_GUID(a, b, c, d, e0, e1, e2, e3, e4, e5)			\
55 	((efi_guid_t) {(a), (b), (c), (d) >> 8, (d) & 0xff,		\
56 	{ (e0), (e1), (e2), (e3), (e4), (e5) }})
57 #else
58 #define	EFI_GUID(a, b, c, d, e0, e1, e2, e3, e4, e5)			\
59 	((efi_guid_t) {(a), (b), (c), (d) & 0xff, (d) >> 8,		\
60 	{ (e0), (e1), (e2), (e3), (e4), (e5) }})
61 #endif
62 
63 #define EFI_GLOBAL_GUID EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa0d, \
64     0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
65 
66 int efi_append_variable(efi_guid_t guid, const char *name,
67     uint8_t *data, size_t data_size, uint32_t attributes);
68 int efi_del_variable(efi_guid_t guid, const char *name);
69 int efi_get_variable(efi_guid_t guid, const char *name,
70     uint8_t **data, size_t *data_size, uint32_t *attributes);
71 int efi_get_variable_attributes(efi_guid_t guid, const char *name,
72     uint32_t *attributes);
73 int efi_get_variable_size(efi_guid_t guid, const char *name, size_t *size);
74 int efi_get_next_variable_name(efi_guid_t **guid, char **name);
75 int efi_guid_cmp(const efi_guid_t *guid1, const efi_guid_t *guid2);
76 int efi_guid_is_zero(const efi_guid_t *guid1);
77 int efi_guid_to_name(efi_guid_t *guid, char **name);
78 int efi_guid_to_symbol(efi_guid_t *guid, char **symbol);
79 int efi_guid_to_str(const efi_guid_t *guid, char **sp);
80 int efi_name_to_guid(const char *name, efi_guid_t *guid);
81 int efi_set_variable(efi_guid_t guid, const char *name,
82     uint8_t *data, size_t data_size, uint32_t attributes, mode_t mode);
83 int efi_str_to_guid(const char *s, efi_guid_t *guid);
84 int efi_variables_supported(void);
85 
86 extern const efi_guid_t efi_guid_empty;
87 
88 /* Stubs that are expected, but aren't really used */
89 static inline int
90 efi_error_get(unsigned int n __unused, char ** const fn __unused,
91     char ** const func __unused, int *line __unused,
92     char ** const msg __unused, int *err __unused)
93 {
94 	return 0;
95 }
96 
97 static inline int
98 efi_error_set(const char *fn __unused, const char *func __unused,
99     int line __unused, int err __unused, const char *fmt __unused, ...)
100 {
101 	return 0;
102 }
103 
104 static inline void
105 efi_error_clear(void)
106 {
107 }
108 
109 static inline int
110 efi_error(const char *fmt __unused, ...)
111 {
112 	return 0;
113 }
114 
115 static inline int
116 efi_error_val(int val __unused, const char *fmt __unused, ...)
117 {
118 	return 0;
119 }
120 
121 #endif /* _EFIVAR_H_ */
122