blob: 9ecf7698ac38c86f9811989bcdf0163ce6a1413c [file] [log] [blame]
Patrick Rudolph2a72e5d2022-02-11 15:46:56 +01001/** @file
2 The variable data structures are related to EDK II-specific implementation of UEFI variables.
3 VariableFormat.h defines variable data headers and variable storage region headers.
4
5Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#ifndef __VARIABLE_FORMAT_H__
11#define __VARIABLE_FORMAT_H__
12
13#define EFI_VARIABLE_GUID \
14 { 0xddcf3616, 0x3275, 0x4164, { 0x98, 0xb6, 0xfe, 0x85, 0x70, 0x7f, 0xfe, 0x7d } }
15
16#define EFI_AUTHENTICATED_VARIABLE_GUID \
17 { 0xaaf32c78, 0x947b, 0x439a, { 0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3, 0x77, 0x92 } }
18
19extern EFI_GUID gEfiVariableGuid;
20extern EFI_GUID gEfiAuthenticatedVariableGuid;
21
22///
23/// Alignment of variable name and data, according to the architecture:
24/// * For IA-32 and Intel(R) 64 architectures: 1.
25///
26#define ALIGNMENT 1
27
28//
29// GET_PAD_SIZE calculates the miminal pad bytes needed to make the current pad size satisfy the alignment requirement.
30//
31#if (ALIGNMENT == 1)
32#define GET_PAD_SIZE(a) (0)
33#else
34#define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))
35#endif
36
37///
38/// Alignment of Variable Data Header in Variable Store region.
39///
40#define HEADER_ALIGNMENT 4
41#define HEADER_ALIGN(Header) (((UINTN) (Header) + HEADER_ALIGNMENT - 1) & (~(HEADER_ALIGNMENT - 1)))
42
43///
44/// Status of Variable Store Region.
45///
46typedef enum {
47 EfiRaw,
48 EfiValid,
49 EfiInvalid,
50 EfiUnknown
51} VARIABLE_STORE_STATUS;
52
53#pragma pack(1)
54
55#define VARIABLE_STORE_SIGNATURE EFI_VARIABLE_GUID
56#define AUTHENTICATED_VARIABLE_STORE_SIGNATURE EFI_AUTHENTICATED_VARIABLE_GUID
57
58///
59/// Variable Store Header Format and State.
60///
61#define VARIABLE_STORE_FORMATTED 0x5a
62#define VARIABLE_STORE_HEALTHY 0xfe
63
64///
65/// Variable Store region header.
66///
67typedef struct {
68 ///
69 /// Variable store region signature.
70 ///
71 EFI_GUID Signature;
72 ///
73 /// Size of entire variable store,
74 /// including size of variable store header but not including the size of FvHeader.
75 ///
76 UINT32 Size;
77 ///
78 /// Variable region format state.
79 ///
80 UINT8 Format;
81 ///
82 /// Variable region healthy state.
83 ///
84 UINT8 State;
85 UINT16 Reserved;
86 UINT32 Reserved1;
87} VARIABLE_STORE_HEADER;
88
89///
90/// Variable data start flag.
91///
92#define VARIABLE_DATA 0x55AA
93
94///
95/// Variable State flags.
96///
97#define VAR_IN_DELETED_TRANSITION 0xfe ///< Variable is in obsolete transition.
98#define VAR_DELETED 0xfd ///< Variable is obsolete.
99#define VAR_HEADER_VALID_ONLY 0x7f ///< Variable header has been valid.
100#define VAR_ADDED 0x3f ///< Variable has been completely added.
101
102///
103/// Variable Attribute combinations.
104///
105#define VARIABLE_ATTRIBUTE_NV_BS (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)
106#define VARIABLE_ATTRIBUTE_BS_RT (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)
107#define VARIABLE_ATTRIBUTE_BS_RT_AT (VARIABLE_ATTRIBUTE_BS_RT | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
108#define VARIABLE_ATTRIBUTE_NV_BS_RT (VARIABLE_ATTRIBUTE_BS_RT | EFI_VARIABLE_NON_VOLATILE)
109#define VARIABLE_ATTRIBUTE_NV_BS_RT_HR (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_HARDWARE_ERROR_RECORD)
110#define VARIABLE_ATTRIBUTE_NV_BS_RT_AT (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
111#define VARIABLE_ATTRIBUTE_AT EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
112#define VARIABLE_ATTRIBUTE_NV_BS_RT_HR_AT (VARIABLE_ATTRIBUTE_NV_BS_RT_HR | VARIABLE_ATTRIBUTE_AT)
113///
114/// EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated and should be considered as reserved
115///
116#define VARIABLE_ATTRIBUTE_AT_AW (EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
117#define VARIABLE_ATTRIBUTE_NV_BS_RT_AW (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
118#define VARIABLE_ATTRIBUTE_NV_BS_RT_HR_AT_AW (VARIABLE_ATTRIBUTE_NV_BS_RT_HR | VARIABLE_ATTRIBUTE_AT_AW)
119
120///
121/// Single Variable Data Header Structure.
122///
123typedef struct {
124 ///
125 /// Variable Data Start Flag.
126 ///
127 UINT16 StartId;
128 ///
129 /// Variable State defined above.
130 ///
131 UINT8 State;
132 UINT8 Reserved;
133 ///
134 /// Attributes of variable defined in UEFI specification.
135 ///
136 UINT32 Attributes;
137 ///
138 /// Size of variable null-terminated Unicode string name.
139 ///
140 UINT32 NameSize;
141 ///
142 /// Size of the variable data without this header.
143 ///
144 UINT32 DataSize;
145 ///
146 /// A unique identifier for the vendor that produces and consumes this varaible.
147 ///
148 EFI_GUID VendorGuid;
149} VARIABLE_HEADER;
150
151///
152/// Single Authenticated Variable Data Header Structure.
153///
154typedef struct {
155 ///
156 /// Variable Data Start Flag.
157 ///
158 UINT16 StartId;
159 ///
160 /// Variable State defined above.
161 ///
162 UINT8 State;
163 UINT8 Reserved;
164 ///
165 /// Attributes of variable defined in UEFI specification.
166 ///
167 UINT32 Attributes;
168 ///
169 /// Associated monotonic count value against replay attack.
170 ///
171 UINT64 MonotonicCount;
172 ///
173 /// Associated TimeStamp value against replay attack.
174 ///
175 EFI_TIME TimeStamp;
176 ///
177 /// Index of associated public key in database.
178 ///
179 UINT32 PubKeyIndex;
180 ///
181 /// Size of variable null-terminated Unicode string name.
182 ///
183 UINT32 NameSize;
184 ///
185 /// Size of the variable data without this header.
186 ///
187 UINT32 DataSize;
188 ///
189 /// A unique identifier for the vendor that produces and consumes this varaible.
190 ///
191 EFI_GUID VendorGuid;
192} AUTHENTICATED_VARIABLE_HEADER;
193
194typedef struct {
195 EFI_GUID *Guid;
196 CHAR16 *Name;
197 UINTN VariableSize;
198} VARIABLE_ENTRY_CONSISTENCY;
199
200#pragma pack()
201
202typedef struct _VARIABLE_INFO_ENTRY VARIABLE_INFO_ENTRY;
203
204///
205/// This structure contains the variable list that is put in EFI system table.
206/// The variable driver collects all variables that were used at boot service time and produces this list.
207/// This is an optional feature to dump all used variables in shell environment.
208///
209struct _VARIABLE_INFO_ENTRY {
210 VARIABLE_INFO_ENTRY *Next; ///< Pointer to next entry.
211 EFI_GUID VendorGuid; ///< Guid of Variable.
212 CHAR16 *Name; ///< Name of Variable.
213 UINT32 Attributes; ///< Attributes of variable defined in UEFI specification.
214 UINT32 ReadCount; ///< Number of times to read this variable.
215 UINT32 WriteCount; ///< Number of times to write this variable.
216 UINT32 DeleteCount; ///< Number of times to delete this variable.
217 UINT32 CacheCount; ///< Number of times that cache hits this variable.
218 BOOLEAN Volatile; ///< TRUE if volatile, FALSE if non-volatile.
219};
220
221#endif // _EFI_VARIABLE_H_