xref: /freebsd/lib/libefivar/efivar.h (revision b3e76948)
1d49a5dddSWarner Losh /*-
2d49a5dddSWarner Losh  * Copyright (c) 2016 Netflix, Inc.
3d49a5dddSWarner Losh  *
4d49a5dddSWarner Losh  * Redistribution and use in source and binary forms, with or without
5d49a5dddSWarner Losh  * modification, are permitted provided that the following conditions
6d49a5dddSWarner Losh  * are met:
7d49a5dddSWarner Losh  * 1. Redistributions of source code must retain the above copyright
86decf2ccSEd Maste  *    notice, this list of conditions and the following disclaimer.
9d49a5dddSWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
10d49a5dddSWarner Losh  *    notice, this list of conditions and the following disclaimer in the
11d49a5dddSWarner Losh  *    documentation and/or other materials provided with the distribution.
12d49a5dddSWarner Losh  *
136decf2ccSEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
146decf2ccSEd Maste  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
156decf2ccSEd Maste  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
166decf2ccSEd Maste  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
176decf2ccSEd Maste  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
186decf2ccSEd Maste  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
196decf2ccSEd Maste  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
206decf2ccSEd Maste  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
216decf2ccSEd Maste  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
226decf2ccSEd Maste  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
236decf2ccSEd Maste  * SUCH DAMAGE.
24d49a5dddSWarner Losh  */
25d49a5dddSWarner Losh 
26d49a5dddSWarner Losh #ifndef	_EFIVAR_H_
27d49a5dddSWarner Losh #define	_EFIVAR_H_
28d49a5dddSWarner Losh 
29d49a5dddSWarner Losh #include <uuid.h>
30d49a5dddSWarner Losh #include <sys/efi.h>
31d49a5dddSWarner Losh #include <sys/endian.h>
32d49a5dddSWarner Losh #include <stdint.h>
33d49a5dddSWarner Losh 
34d49a5dddSWarner Losh /* Shoud these be elsewhere ? */
35d49a5dddSWarner Losh #define	EFI_VARIABLE_NON_VOLATILE		0x00000001
36d49a5dddSWarner Losh #define	EFI_VARIABLE_BOOTSERVICE_ACCESS		0x00000002
37d49a5dddSWarner Losh #define	EFI_VARIABLE_RUNTIME_ACCESS		0x00000004
38d49a5dddSWarner Losh #define	EFI_VARIABLE_HARDWARE_ERROR_RECORD	0x00000008
39d49a5dddSWarner Losh #define	EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS	0x00000010
40d49a5dddSWarner Losh #define	EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS \
41d49a5dddSWarner Losh 						0x00000020
42d49a5dddSWarner Losh #define	EFI_VARIABLE_APPEND_WRITE		0x00000040
43d49a5dddSWarner Losh #if 0 /* todo */
44d49a5dddSWarner Losh #define	EFI_VARIABLE_HAS_AUTH_HEADER
45d49a5dddSWarner Losh #define EFI_VARIABLE_HAS_SIGNATURE
46d49a5dddSWarner Losh #endif
47d49a5dddSWarner Losh 
48d49a5dddSWarner Losh 
497270962aSWarner Losh #ifndef _EFIVAR_EFI_GUID_T_DEF
507270962aSWarner Losh #define _EFIVAR_EFI_GUID_T_DEF
51d49a5dddSWarner Losh typedef uuid_t efi_guid_t;
527270962aSWarner Losh #endif
537270962aSWarner Losh 
54d49a5dddSWarner Losh #if BYTE_ORDER == LITTLE_ENDIAN
55d49a5dddSWarner Losh #define	EFI_GUID(a, b, c, d, e0, e1, e2, e3, e4, e5)			\
56d49a5dddSWarner Losh 	((efi_guid_t) {(a), (b), (c), (d) >> 8, (d) & 0xff,		\
57d49a5dddSWarner Losh 	{ (e0), (e1), (e2), (e3), (e4), (e5) }})
58d49a5dddSWarner Losh #else
59d49a5dddSWarner Losh #define	EFI_GUID(a, b, c, d, e0, e1, e2, e3, e4, e5)			\
60d49a5dddSWarner Losh 	((efi_guid_t) {(a), (b), (c), (d) & 0xff, (d) >> 8,		\
61d49a5dddSWarner Losh 	{ (e0), (e1), (e2), (e3), (e4), (e5) }})
62d49a5dddSWarner Losh #endif
63d49a5dddSWarner Losh 
64d49a5dddSWarner Losh #define EFI_GLOBAL_GUID EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa0d, \
65d49a5dddSWarner Losh     0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
66d49a5dddSWarner Losh 
67d49a5dddSWarner Losh int efi_append_variable(efi_guid_t guid, const char *name,
68d49a5dddSWarner Losh     uint8_t *data, size_t data_size, uint32_t attributes);
69d49a5dddSWarner Losh int efi_del_variable(efi_guid_t guid, const char *name);
70d49a5dddSWarner Losh int efi_get_variable(efi_guid_t guid, const char *name,
71d49a5dddSWarner Losh     uint8_t **data, size_t *data_size, uint32_t *attributes);
72d49a5dddSWarner Losh int efi_get_variable_attributes(efi_guid_t guid, const char *name,
73d49a5dddSWarner Losh     uint32_t *attributes);
74d49a5dddSWarner Losh int efi_get_variable_size(efi_guid_t guid, const char *name, size_t *size);
75d49a5dddSWarner Losh int efi_get_next_variable_name(efi_guid_t **guid, char **name);
76d49a5dddSWarner Losh int efi_guid_cmp(const efi_guid_t *guid1, const efi_guid_t *guid2);
77d49a5dddSWarner Losh int efi_guid_is_zero(const efi_guid_t *guid1);
78d49a5dddSWarner Losh int efi_guid_to_name(efi_guid_t *guid, char **name);
79d49a5dddSWarner Losh int efi_guid_to_symbol(efi_guid_t *guid, char **symbol);
80d49a5dddSWarner Losh int efi_guid_to_str(const efi_guid_t *guid, char **sp);
81d49a5dddSWarner Losh int efi_name_to_guid(const char *name, efi_guid_t *guid);
82d49a5dddSWarner Losh int efi_set_variable(efi_guid_t guid, const char *name,
83831bec11SWarner Losh     uint8_t *data, size_t data_size, uint32_t attributes);
84d49a5dddSWarner Losh int efi_str_to_guid(const char *s, efi_guid_t *guid);
85d49a5dddSWarner Losh int efi_variables_supported(void);
86d49a5dddSWarner Losh 
87e1745513SWarner Losh /* FreeBSD extensions */
88e1745513SWarner Losh struct uuid_table
89e1745513SWarner Losh {
90e1745513SWarner Losh 	const char *uuid_str;
91e1745513SWarner Losh 	const char *name;
92e1745513SWarner Losh 	efi_guid_t guid;
93e1745513SWarner Losh };
94e1745513SWarner Losh 
95e1745513SWarner Losh int efi_known_guid(struct uuid_table **);
96e1745513SWarner Losh 
97d49a5dddSWarner Losh extern const efi_guid_t efi_guid_empty;
98d49a5dddSWarner Losh 
99d49a5dddSWarner Losh #endif /* _EFIVAR_H_ */
100