1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
6 #ifndef _EFI_VARIABLE_H
7 #define _EFI_VARIABLE_H
9 #include <linux/bitops.h>
11 #define EFI_VARIABLE_READ_ONLY BIT(31)
13 enum efi_auth_var_type {
14 EFI_AUTH_VAR_NONE = 0,
24 * efi_get_variable() - retrieve value of a UEFI variable
26 * @variable_name: name of the variable
27 * @vendor: vendor GUID
28 * @attributes: attributes of the variable
29 * @data_size: size of the buffer to which the variable value is copied
30 * @data: buffer to which the variable value is copied
31 * @timep: authentication time (seconds since start of epoch)
34 efi_status_t efi_get_variable_int(u16 *variable_name, const efi_guid_t *vendor,
35 u32 *attributes, efi_uintn_t *data_size,
36 void *data, u64 *timep);
39 * efi_set_variable() - set value of a UEFI variable
41 * @variable_name: name of the variable
42 * @vendor: vendor GUID
43 * @attributes: attributes of the variable
44 * @data_size: size of the buffer with the variable value
45 * @data: buffer with the variable value
46 * @ro_check: check the read only read only bit in attributes
49 efi_status_t efi_set_variable_int(u16 *variable_name, const efi_guid_t *vendor,
50 u32 attributes, efi_uintn_t data_size,
51 const void *data, bool ro_check);
54 * efi_get_next_variable_name_int() - enumerate the current variable names
56 * @variable_name_size: size of variable_name buffer in byte
57 * @variable_name: name of uefi variable's name in u16
58 * @vendor: vendor's guid
60 * See the Unified Extensible Firmware Interface (UEFI) specification for
65 efi_status_t efi_get_next_variable_name_int(efi_uintn_t *variable_name_size,
70 * efi_query_variable_info_int() - get information about EFI variables
72 * This function implements the QueryVariableInfo() runtime service.
74 * See the Unified Extensible Firmware Interface (UEFI) specification for
77 * @attributes: bitmask to select variables to be
79 * @maximum_variable_storage_size: maximum size of storage area for the
80 * selected variable types
81 * @remaining_variable_storage_size: remaining size of storage are for the
82 * selected variable types
83 * @maximum_variable_size: maximum size of a variable of the
85 * Returns: status code
87 efi_status_t efi_query_variable_info_int(u32 attributes,
88 u64 *maximum_variable_storage_size,
89 u64 *remaining_variable_storage_size,
90 u64 *maximum_variable_size);
92 #define EFI_VAR_FILE_NAME "ubootefi.var"
94 #define EFI_VAR_BUF_SIZE 0x4000
96 #define EFI_VAR_FILE_MAGIC 0x0161566966456255 /* UbEfiVa, version 1 */
99 * struct efi_var_entry - UEFI variable file entry
101 * @length: length of enty, multiple of 8
102 * @attr: variable attributes
103 * @time: authentication time (seconds since start of epoch)
105 * @name: UTF16 variable name
107 struct efi_var_entry {
116 * struct efi_var_file - file for storing UEFI variables
118 * @reserved: unused, may be overwritten by memory probing
119 * @magic: identifies file format
120 * @length: length including header
121 * @crc32: CRC32 without header
124 struct efi_var_file {
129 struct efi_var_entry var[];
133 * efi_var_to_file() - save non-volatile variables as file
135 * File ubootefi.var is created on the EFI system partion.
137 * Return: status code
139 efi_status_t efi_var_to_file(void);
142 * efi_var_restore() - restore EFI variables from buffer
145 * Return: status code
147 efi_status_t efi_var_restore(struct efi_var_file *buf);
150 * efi_var_from_file() - read variables from file
152 * File ubootefi.var is read from the EFI system partitions and the variables
153 * stored in the file are created.
155 * In case the file does not exist yet or a variable cannot be set EFI_SUCCESS
158 * Return: status code
160 efi_status_t efi_var_from_file(void);
163 * efi_var_mem_init() - set-up variable list
165 * Return: status code
167 efi_status_t efi_var_mem_init(void);
170 * efi_var_mem_find() - find a variable in the list
172 * @guid: GUID of the variable
173 * @name: name of the variable
174 * @next: on exit pointer to the next variable after the found one
175 * Return: found variable
177 struct efi_var_entry *efi_var_mem_find(const efi_guid_t *guid, const u16 *name,
178 struct efi_var_entry **next);
181 * efi_var_mem_del() - delete a variable from the list of variables
183 * @var: variable to delete
185 void efi_var_mem_del(struct efi_var_entry *var);
188 * efi_var_mem_ins() - append a variable to the list of variables
190 * The variable is appended without checking if a variable of the same name
191 * already exists. The two data buffers are concatenated.
193 * @variable_name: variable name
195 * @attributes: variable attributes
196 * @size1: size of the first data buffer
197 * @data1: first data buffer
198 * @size2: size of the second data field
199 * @data2: second data buffer
200 * @time: time of authentication (as seconds since start of epoch)
201 * Result: status code
203 efi_status_t efi_var_mem_ins(u16 *variable_name,
204 const efi_guid_t *vendor, u32 attributes,
205 const efi_uintn_t size1, const void *data1,
206 const efi_uintn_t size2, const void *data2,
210 * efi_var_mem_free() - determine free memory for variables
212 * Return: maximum data size plus variable name size
214 u64 efi_var_mem_free(void);
217 * efi_init_secure_state - initialize secure boot state
219 * Return: status code
221 efi_status_t efi_init_secure_state(void);
224 * efi_auth_var_get_type() - convert variable name and guid to enum
226 * @name: name of UEFI variable
227 * @guid: guid of UEFI variable
228 * Return: identifier for authentication related variables
230 enum efi_auth_var_type efi_auth_var_get_type(u16 *name, const efi_guid_t *guid);