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