2 Provides variable driver extended services.
4 Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "VariableParsing.h"
13 Finds variable in storage blocks of volatile and non-volatile storage areas.
15 This code finds variable in storage blocks of volatile and non-volatile storage areas.
16 If VariableName is an empty string, then we just return the first
17 qualified variable without comparing VariableName and VendorGuid.
19 @param[in] VariableName Name of the variable to be found.
20 @param[in] VendorGuid Variable vendor GUID to be found.
21 @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for
22 output of the variable found.
24 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
25 while VendorGuid is NULL.
26 @retval EFI_SUCCESS Variable successfully found.
27 @retval EFI_NOT_FOUND Variable not found
32 VariableExLibFindVariable (
33 IN CHAR16
*VariableName
,
34 IN EFI_GUID
*VendorGuid
,
35 OUT AUTH_VARIABLE_INFO
*AuthVariableInfo
39 VARIABLE_POINTER_TRACK Variable
;
40 AUTHENTICATED_VARIABLE_HEADER
*AuthVariable
;
42 Status
= FindVariable (
46 &mVariableModuleGlobal
->VariableGlobal
,
49 if (EFI_ERROR (Status
)) {
50 AuthVariableInfo
->Data
= NULL
;
51 AuthVariableInfo
->DataSize
= 0;
52 AuthVariableInfo
->Attributes
= 0;
53 AuthVariableInfo
->PubKeyIndex
= 0;
54 AuthVariableInfo
->MonotonicCount
= 0;
55 AuthVariableInfo
->TimeStamp
= NULL
;
59 AuthVariableInfo
->DataSize
= DataSizeOfVariable (Variable
.CurrPtr
);
60 AuthVariableInfo
->Data
= GetVariableDataPtr (Variable
.CurrPtr
);
61 AuthVariableInfo
->Attributes
= Variable
.CurrPtr
->Attributes
;
62 if (mVariableModuleGlobal
->VariableGlobal
.AuthFormat
) {
63 AuthVariable
= (AUTHENTICATED_VARIABLE_HEADER
*) Variable
.CurrPtr
;
64 AuthVariableInfo
->PubKeyIndex
= AuthVariable
->PubKeyIndex
;
65 AuthVariableInfo
->MonotonicCount
= ReadUnaligned64 (&(AuthVariable
->MonotonicCount
));
66 AuthVariableInfo
->TimeStamp
= &AuthVariable
->TimeStamp
;
73 Finds next variable in storage blocks of volatile and non-volatile storage areas.
75 This code finds next variable in storage blocks of volatile and non-volatile storage areas.
76 If VariableName is an empty string, then we just return the first
77 qualified variable without comparing VariableName and VendorGuid.
79 @param[in] VariableName Name of the variable to be found.
80 @param[in] VendorGuid Variable vendor GUID to be found.
81 @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for
82 output of the next variable.
84 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
85 while VendorGuid is NULL.
86 @retval EFI_SUCCESS Variable successfully found.
87 @retval EFI_NOT_FOUND Variable not found
92 VariableExLibFindNextVariable (
93 IN CHAR16
*VariableName
,
94 IN EFI_GUID
*VendorGuid
,
95 OUT AUTH_VARIABLE_INFO
*AuthVariableInfo
99 VARIABLE_HEADER
*VariablePtr
;
100 AUTHENTICATED_VARIABLE_HEADER
*AuthVariablePtr
;
101 VARIABLE_STORE_HEADER
*VariableStoreHeader
[VariableStoreTypeMax
];
103 VariableStoreHeader
[VariableStoreTypeVolatile
] = (VARIABLE_STORE_HEADER
*) (UINTN
) mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
;
104 VariableStoreHeader
[VariableStoreTypeHob
] = (VARIABLE_STORE_HEADER
*) (UINTN
) mVariableModuleGlobal
->VariableGlobal
.HobVariableBase
;
105 VariableStoreHeader
[VariableStoreTypeNv
] = mNvVariableCache
;
107 Status
= VariableServiceGetNextVariableInternal (
113 if (EFI_ERROR (Status
)) {
114 AuthVariableInfo
->VariableName
= NULL
;
115 AuthVariableInfo
->VendorGuid
= NULL
;
116 AuthVariableInfo
->Data
= NULL
;
117 AuthVariableInfo
->DataSize
= 0;
118 AuthVariableInfo
->Attributes
= 0;
119 AuthVariableInfo
->PubKeyIndex
= 0;
120 AuthVariableInfo
->MonotonicCount
= 0;
121 AuthVariableInfo
->TimeStamp
= NULL
;
125 AuthVariableInfo
->VariableName
= GetVariableNamePtr (VariablePtr
);
126 AuthVariableInfo
->VendorGuid
= GetVendorGuidPtr (VariablePtr
);
127 AuthVariableInfo
->DataSize
= DataSizeOfVariable (VariablePtr
);
128 AuthVariableInfo
->Data
= GetVariableDataPtr (VariablePtr
);
129 AuthVariableInfo
->Attributes
= VariablePtr
->Attributes
;
130 if (mVariableModuleGlobal
->VariableGlobal
.AuthFormat
) {
131 AuthVariablePtr
= (AUTHENTICATED_VARIABLE_HEADER
*) VariablePtr
;
132 AuthVariableInfo
->PubKeyIndex
= AuthVariablePtr
->PubKeyIndex
;
133 AuthVariableInfo
->MonotonicCount
= ReadUnaligned64 (&(AuthVariablePtr
->MonotonicCount
));
134 AuthVariableInfo
->TimeStamp
= &AuthVariablePtr
->TimeStamp
;
141 Update the variable region with Variable information.
143 @param[in] AuthVariableInfo Pointer AUTH_VARIABLE_INFO structure for
144 input of the variable.
146 @retval EFI_SUCCESS The update operation is success.
147 @retval EFI_INVALID_PARAMETER Invalid parameter.
148 @retval EFI_WRITE_PROTECTED Variable is write-protected.
149 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
154 VariableExLibUpdateVariable (
155 IN AUTH_VARIABLE_INFO
*AuthVariableInfo
158 VARIABLE_POINTER_TRACK Variable
;
160 FindVariable (AuthVariableInfo
->VariableName
, AuthVariableInfo
->VendorGuid
, &Variable
, &mVariableModuleGlobal
->VariableGlobal
, FALSE
);
161 return UpdateVariable (
162 AuthVariableInfo
->VariableName
,
163 AuthVariableInfo
->VendorGuid
,
164 AuthVariableInfo
->Data
,
165 AuthVariableInfo
->DataSize
,
166 AuthVariableInfo
->Attributes
,
167 AuthVariableInfo
->PubKeyIndex
,
168 AuthVariableInfo
->MonotonicCount
,
170 AuthVariableInfo
->TimeStamp
177 @param[in, out] ScratchBufferSize Scratch buffer size. If input size is greater than
178 the maximum supported buffer size, this value contains
179 the maximum supported buffer size as output.
180 @param[out] ScratchBuffer Pointer to scratch buffer address.
182 @retval EFI_SUCCESS Get scratch buffer successfully.
183 @retval EFI_UNSUPPORTED If input size is greater than the maximum supported buffer size.
188 VariableExLibGetScratchBuffer (
189 IN OUT UINTN
*ScratchBufferSize
,
190 OUT VOID
**ScratchBuffer
195 MaxBufferSize
= mVariableModuleGlobal
->ScratchBufferSize
;
196 if (*ScratchBufferSize
> MaxBufferSize
) {
197 *ScratchBufferSize
= MaxBufferSize
;
198 return EFI_UNSUPPORTED
;
201 *ScratchBuffer
= GetEndPointer ((VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
));
206 This function is to check if the remaining variable space is enough to set
207 all Variables from argument list successfully. The purpose of the check
208 is to keep the consistency of the Variables to be in variable storage.
210 Note: Variables are assumed to be in same storage.
211 The set sequence of Variables will be same with the sequence of VariableEntry from argument list,
212 so follow the argument sequence to check the Variables.
214 @param[in] Attributes Variable attributes for Variable entries.
215 @param ... The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.
216 A NULL terminates the list. The VariableSize of
217 VARIABLE_ENTRY_CONSISTENCY is the variable data size as input.
218 It will be changed to variable total size as output.
220 @retval TRUE Have enough variable space to set the Variables successfully.
221 @retval FALSE No enough variable space to set the Variables successfully.
226 VariableExLibCheckRemainingSpaceForConsistency (
227 IN UINT32 Attributes
,
234 VA_START (Marker
, Attributes
);
236 Return
= CheckRemainingSpaceForConsistencyInternal (Attributes
, Marker
);
244 Return TRUE if at OS runtime.
246 @retval TRUE If at OS runtime.
247 @retval FALSE If at boot time.
252 VariableExLibAtRuntime (