blob: 5eec407a2b689c5043e51e39fc2215346afa6d8a [file] [log] [blame]
Heinrich Schuchardtf2d2b3a2020-06-22 18:10:27 +02001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
4 */
5
6#ifndef _EFI_VARIABLE_H
7#define _EFI_VARIABLE_H
8
9#include <linux/bitops.h>
10
11#define EFI_VARIABLE_READ_ONLY BIT(31)
12
13/**
14 * efi_get_variable() - retrieve value of a UEFI variable
15 *
16 * @variable_name: name of the variable
17 * @vendor: vendor GUID
18 * @attributes: attributes of the variable
19 * @data_size: size of the buffer to which the variable value is copied
20 * @data: buffer to which the variable value is copied
21 * @timep: authentication time (seconds since start of epoch)
22 * Return: status code
23 */
24efi_status_t efi_get_variable_int(u16 *variable_name, const efi_guid_t *vendor,
25 u32 *attributes, efi_uintn_t *data_size,
26 void *data, u64 *timep);
27
28/**
29 * efi_set_variable() - set value of a UEFI variable
30 *
31 * @variable_name: name of the variable
32 * @vendor: vendor GUID
33 * @attributes: attributes of the variable
34 * @data_size: size of the buffer with the variable value
35 * @data: buffer with the variable value
36 * @ro_check: check the read only read only bit in attributes
37 * Return: status code
38 */
39efi_status_t efi_set_variable_int(u16 *variable_name, const efi_guid_t *vendor,
40 u32 attributes, efi_uintn_t data_size,
41 const void *data, bool ro_check);
42
Heinrich Schuchardt01df8cf2020-06-26 17:57:48 +020043/**
44 * efi_get_next_variable_name_int() - enumerate the current variable names
45 *
46 * @variable_name_size: size of variable_name buffer in byte
47 * @variable_name: name of uefi variable's name in u16
48 * @vendor: vendor's guid
49 *
50 * See the Unified Extensible Firmware Interface (UEFI) specification for
51 * details.
52 *
53 * Return: status code
54 */
55efi_status_t efi_get_next_variable_name_int(efi_uintn_t *variable_name_size,
56 u16 *variable_name,
57 efi_guid_t *vendor);
58
59/**
60 * efi_query_variable_info_int() - get information about EFI variables
61 *
62 * This function implements the QueryVariableInfo() runtime service.
63 *
64 * See the Unified Extensible Firmware Interface (UEFI) specification for
65 * details.
66 *
67 * @attributes: bitmask to select variables to be
68 * queried
69 * @maximum_variable_storage_size: maximum size of storage area for the
70 * selected variable types
71 * @remaining_variable_storage_size: remaining size of storage are for the
72 * selected variable types
73 * @maximum_variable_size: maximum size of a variable of the
74 * selected type
75 * Returns: status code
76 */
77efi_status_t efi_query_variable_info_int(u32 attributes,
78 u64 *maximum_variable_storage_size,
79 u64 *remaining_variable_storage_size,
80 u64 *maximum_variable_size);
81
Heinrich Schuchardt5f7dcf02020-03-19 18:21:58 +000082#define EFI_VAR_FILE_NAME "ubootefi.var"
83
84#define EFI_VAR_BUF_SIZE 0x4000
85
86#define EFI_VAR_FILE_MAGIC 0x0161566966456255 /* UbEfiVa, version 1 */
87
88/**
89 * struct efi_var_entry - UEFI variable file entry
90 *
91 * @length: length of enty, multiple of 8
92 * @attr: variable attributes
93 * @time: authentication time (seconds since start of epoch)
94 * @guid: vendor GUID
95 * @name: UTF16 variable name
96 */
97struct efi_var_entry {
98 u32 length;
99 u32 attr;
100 u64 time;
101 efi_guid_t guid;
102 u16 name[];
103};
104
105/**
106 * struct efi_var_file - file for storing UEFI variables
107 *
108 * @reserved: unused, may be overwritten by memory probing
109 * @magic: identifies file format
110 * @length: length including header
111 * @crc32: CRC32 without header
112 * @var: variables
113 */
114struct efi_var_file {
115 u64 reserved;
116 u64 magic;
117 u32 length;
118 u32 crc32;
119 struct efi_var_entry var[];
120};
121
122/**
123 * efi_var_to_file() - save non-volatile variables as file
124 *
125 * File ubootefi.var is created on the EFI system partion.
126 *
127 * Return: status code
128 */
129efi_status_t efi_var_to_file(void);
130
131/**
132 * efi_var_from_file() - read variables from file
133 *
134 * File ubootefi.var is read from the EFI system partitions and the variables
135 * stored in the file are created.
136 *
137 * In case the file does not exist yet or a variable cannot be set EFI_SUCCESS
138 * is returned.
139 *
140 * Return: status code
141 */
142efi_status_t efi_var_from_file(void);
143
Heinrich Schuchardtf1f990a2020-03-22 09:07:50 +0100144/**
145 * efi_var_mem_init() - set-up variable list
146 *
147 * Return: status code
148 */
149efi_status_t efi_var_mem_init(void);
150
151/**
152 * efi_var_mem_find() - find a variable in the list
153 *
154 * @guid: GUID of the variable
155 * @name: name of the variable
156 * @next: on exit pointer to the next variable after the found one
157 * Return: found variable
158 */
159struct efi_var_entry *efi_var_mem_find(const efi_guid_t *guid, const u16 *name,
160 struct efi_var_entry **next);
161
162/**
163 * efi_var_mem_del() - delete a variable from the list of variables
164 *
165 * @var: variable to delete
166 */
167void efi_var_mem_del(struct efi_var_entry *var);
168
169/**
170 * efi_var_mem_ins() - append a variable to the list of variables
171 *
172 * The variable is appended without checking if a variable of the same name
173 * already exists. The two data buffers are concatenated.
174 *
175 * @variable_name: variable name
176 * @vendor: GUID
177 * @attributes: variable attributes
178 * @size1: size of the first data buffer
179 * @data1: first data buffer
180 * @size2: size of the second data field
181 * @data2: second data buffer
182 * @time: time of authentication (as seconds since start of epoch)
183 * Result: status code
184 */
185efi_status_t efi_var_mem_ins(u16 *variable_name,
186 const efi_guid_t *vendor, u32 attributes,
187 const efi_uintn_t size1, const void *data1,
188 const efi_uintn_t size2, const void *data2,
189 const u64 time);
190
191/**
192 * efi_var_mem_free() - determine free memory for variables
193 *
194 * Return: maximum data size plus variable name size
195 */
196u64 efi_var_mem_free(void);
197
Heinrich Schuchardt012c56a2020-07-14 08:04:49 +0200198/**
199 * efi_init_secure_state - initialize secure boot state
200 *
201 * Return: status code
202 */
203efi_status_t efi_init_secure_state(void);
204
Heinrich Schuchardtf2d2b3a2020-06-22 18:10:27 +0200205#endif