]>
Commit | Line | Data |
---|---|---|
fa0737a8 SZ |
1 | /** @file\r |
2 | Provides variable driver extended services.\r | |
3 | \r | |
4 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r | |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
fa0737a8 SZ |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "Variable.h"\r | |
10 | \r | |
11 | /**\r | |
12 | Finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
13 | \r | |
14 | This code finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
15 | If VariableName is an empty string, then we just return the first\r | |
16 | qualified variable without comparing VariableName and VendorGuid.\r | |
17 | \r | |
18 | @param[in] VariableName Name of the variable to be found.\r | |
19 | @param[in] VendorGuid Variable vendor GUID to be found.\r | |
20 | @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for\r | |
21 | output of the variable found.\r | |
22 | \r | |
23 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r | |
24 | while VendorGuid is NULL.\r | |
25 | @retval EFI_SUCCESS Variable successfully found.\r | |
26 | @retval EFI_NOT_FOUND Variable not found\r | |
27 | \r | |
28 | **/\r | |
29 | EFI_STATUS\r | |
30 | EFIAPI\r | |
31 | VariableExLibFindVariable (\r | |
32 | IN CHAR16 *VariableName,\r | |
33 | IN EFI_GUID *VendorGuid,\r | |
34 | OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
35 | )\r | |
36 | {\r | |
37 | EFI_STATUS Status;\r | |
38 | VARIABLE_POINTER_TRACK Variable;\r | |
39 | AUTHENTICATED_VARIABLE_HEADER *AuthVariable;\r | |
40 | \r | |
41 | Status = FindVariable (\r | |
42 | VariableName,\r | |
43 | VendorGuid,\r | |
44 | &Variable,\r | |
45 | &mVariableModuleGlobal->VariableGlobal,\r | |
46 | FALSE\r | |
47 | );\r | |
48 | if (EFI_ERROR (Status)) {\r | |
49 | AuthVariableInfo->Data = NULL;\r | |
50 | AuthVariableInfo->DataSize = 0;\r | |
51 | AuthVariableInfo->Attributes = 0;\r | |
52 | AuthVariableInfo->PubKeyIndex = 0;\r | |
53 | AuthVariableInfo->MonotonicCount = 0;\r | |
54 | AuthVariableInfo->TimeStamp = NULL;\r | |
55 | return Status;\r | |
56 | }\r | |
57 | \r | |
58 | AuthVariableInfo->DataSize = DataSizeOfVariable (Variable.CurrPtr);\r | |
59 | AuthVariableInfo->Data = GetVariableDataPtr (Variable.CurrPtr);\r | |
60 | AuthVariableInfo->Attributes = Variable.CurrPtr->Attributes;\r | |
61 | if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {\r | |
62 | AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable.CurrPtr;\r | |
63 | AuthVariableInfo->PubKeyIndex = AuthVariable->PubKeyIndex;\r | |
cdc83ccf | 64 | AuthVariableInfo->MonotonicCount = ReadUnaligned64 (&(AuthVariable->MonotonicCount));\r |
fa0737a8 SZ |
65 | AuthVariableInfo->TimeStamp = &AuthVariable->TimeStamp;\r |
66 | }\r | |
67 | \r | |
68 | return EFI_SUCCESS;\r | |
69 | }\r | |
70 | \r | |
71 | /**\r | |
72 | Finds next variable in storage blocks of volatile and non-volatile storage areas.\r | |
73 | \r | |
74 | This code finds next variable in storage blocks of volatile and non-volatile storage areas.\r | |
75 | If VariableName is an empty string, then we just return the first\r | |
76 | qualified variable without comparing VariableName and VendorGuid.\r | |
77 | \r | |
78 | @param[in] VariableName Name of the variable to be found.\r | |
79 | @param[in] VendorGuid Variable vendor GUID to be found.\r | |
80 | @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for\r | |
81 | output of the next variable.\r | |
82 | \r | |
83 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r | |
84 | while VendorGuid is NULL.\r | |
85 | @retval EFI_SUCCESS Variable successfully found.\r | |
86 | @retval EFI_NOT_FOUND Variable not found\r | |
87 | \r | |
88 | **/\r | |
89 | EFI_STATUS\r | |
90 | EFIAPI\r | |
91 | VariableExLibFindNextVariable (\r | |
92 | IN CHAR16 *VariableName,\r | |
93 | IN EFI_GUID *VendorGuid,\r | |
94 | OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
95 | )\r | |
96 | {\r | |
97 | EFI_STATUS Status;\r | |
98 | VARIABLE_HEADER *VariablePtr;\r | |
99 | AUTHENTICATED_VARIABLE_HEADER *AuthVariablePtr;\r | |
100 | \r | |
101 | Status = VariableServiceGetNextVariableInternal (\r | |
102 | VariableName,\r | |
103 | VendorGuid,\r | |
104 | &VariablePtr\r | |
105 | );\r | |
106 | if (EFI_ERROR (Status)) {\r | |
107 | AuthVariableInfo->VariableName = NULL;\r | |
108 | AuthVariableInfo->VendorGuid = NULL;\r | |
109 | AuthVariableInfo->Data = NULL;\r | |
110 | AuthVariableInfo->DataSize = 0;\r | |
111 | AuthVariableInfo->Attributes = 0;\r | |
112 | AuthVariableInfo->PubKeyIndex = 0;\r | |
113 | AuthVariableInfo->MonotonicCount = 0;\r | |
114 | AuthVariableInfo->TimeStamp = NULL;\r | |
115 | return Status;\r | |
116 | }\r | |
117 | \r | |
118 | AuthVariableInfo->VariableName = GetVariableNamePtr (VariablePtr);\r | |
119 | AuthVariableInfo->VendorGuid = GetVendorGuidPtr (VariablePtr);\r | |
120 | AuthVariableInfo->DataSize = DataSizeOfVariable (VariablePtr);\r | |
121 | AuthVariableInfo->Data = GetVariableDataPtr (VariablePtr);\r | |
122 | AuthVariableInfo->Attributes = VariablePtr->Attributes;\r | |
123 | if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {\r | |
124 | AuthVariablePtr = (AUTHENTICATED_VARIABLE_HEADER *) VariablePtr;\r | |
125 | AuthVariableInfo->PubKeyIndex = AuthVariablePtr->PubKeyIndex;\r | |
cdc83ccf | 126 | AuthVariableInfo->MonotonicCount = ReadUnaligned64 (&(AuthVariablePtr->MonotonicCount));\r |
fa0737a8 SZ |
127 | AuthVariableInfo->TimeStamp = &AuthVariablePtr->TimeStamp;\r |
128 | }\r | |
129 | \r | |
130 | return EFI_SUCCESS;\r | |
131 | }\r | |
132 | \r | |
133 | /**\r | |
134 | Update the variable region with Variable information.\r | |
135 | \r | |
136 | @param[in] AuthVariableInfo Pointer AUTH_VARIABLE_INFO structure for\r | |
137 | input of the variable.\r | |
138 | \r | |
139 | @retval EFI_SUCCESS The update operation is success.\r | |
140 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
141 | @retval EFI_WRITE_PROTECTED Variable is write-protected.\r | |
142 | @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r | |
143 | \r | |
144 | **/\r | |
145 | EFI_STATUS\r | |
146 | EFIAPI\r | |
147 | VariableExLibUpdateVariable (\r | |
148 | IN AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
149 | )\r | |
150 | {\r | |
151 | VARIABLE_POINTER_TRACK Variable;\r | |
152 | \r | |
153 | FindVariable (AuthVariableInfo->VariableName, AuthVariableInfo->VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r | |
154 | return UpdateVariable (\r | |
155 | AuthVariableInfo->VariableName,\r | |
156 | AuthVariableInfo->VendorGuid,\r | |
157 | AuthVariableInfo->Data,\r | |
158 | AuthVariableInfo->DataSize,\r | |
159 | AuthVariableInfo->Attributes,\r | |
160 | AuthVariableInfo->PubKeyIndex,\r | |
161 | AuthVariableInfo->MonotonicCount,\r | |
162 | &Variable,\r | |
163 | AuthVariableInfo->TimeStamp\r | |
164 | );\r | |
165 | }\r | |
166 | \r | |
167 | /**\r | |
168 | Get scratch buffer.\r | |
169 | \r | |
170 | @param[in, out] ScratchBufferSize Scratch buffer size. If input size is greater than\r | |
171 | the maximum supported buffer size, this value contains\r | |
172 | the maximum supported buffer size as output.\r | |
173 | @param[out] ScratchBuffer Pointer to scratch buffer address.\r | |
174 | \r | |
175 | @retval EFI_SUCCESS Get scratch buffer successfully.\r | |
176 | @retval EFI_UNSUPPORTED If input size is greater than the maximum supported buffer size.\r | |
177 | \r | |
178 | **/\r | |
179 | EFI_STATUS\r | |
180 | EFIAPI\r | |
181 | VariableExLibGetScratchBuffer (\r | |
182 | IN OUT UINTN *ScratchBufferSize,\r | |
183 | OUT VOID **ScratchBuffer\r | |
184 | )\r | |
185 | {\r | |
186 | UINTN MaxBufferSize;\r | |
187 | \r | |
188 | MaxBufferSize = mVariableModuleGlobal->ScratchBufferSize;\r | |
189 | if (*ScratchBufferSize > MaxBufferSize) {\r | |
190 | *ScratchBufferSize = MaxBufferSize;\r | |
191 | return EFI_UNSUPPORTED;\r | |
192 | }\r | |
193 | \r | |
194 | *ScratchBuffer = GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase));\r | |
195 | return EFI_SUCCESS;\r | |
196 | }\r | |
197 | \r | |
198 | /**\r | |
199 | This function is to check if the remaining variable space is enough to set\r | |
200 | all Variables from argument list successfully. The purpose of the check\r | |
201 | is to keep the consistency of the Variables to be in variable storage.\r | |
202 | \r | |
203 | Note: Variables are assumed to be in same storage.\r | |
204 | The set sequence of Variables will be same with the sequence of VariableEntry from argument list,\r | |
205 | so follow the argument sequence to check the Variables.\r | |
206 | \r | |
207 | @param[in] Attributes Variable attributes for Variable entries.\r | |
208 | @param ... The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.\r | |
209 | A NULL terminates the list. The VariableSize of\r | |
210 | VARIABLE_ENTRY_CONSISTENCY is the variable data size as input.\r | |
211 | It will be changed to variable total size as output.\r | |
212 | \r | |
213 | @retval TRUE Have enough variable space to set the Variables successfully.\r | |
214 | @retval FALSE No enough variable space to set the Variables successfully.\r | |
215 | \r | |
216 | **/\r | |
217 | BOOLEAN\r | |
218 | EFIAPI\r | |
219 | VariableExLibCheckRemainingSpaceForConsistency (\r | |
220 | IN UINT32 Attributes,\r | |
221 | ...\r | |
222 | )\r | |
223 | {\r | |
224 | VA_LIST Marker;\r | |
225 | BOOLEAN Return;\r | |
226 | \r | |
227 | VA_START (Marker, Attributes);\r | |
228 | \r | |
229 | Return = CheckRemainingSpaceForConsistencyInternal (Attributes, Marker);\r | |
230 | \r | |
231 | VA_END (Marker);\r | |
232 | \r | |
233 | return Return;\r | |
234 | }\r | |
235 | \r | |
236 | /**\r | |
237 | Return TRUE if at OS runtime.\r | |
238 | \r | |
239 | @retval TRUE If at OS runtime.\r | |
240 | @retval FALSE If at boot time.\r | |
241 | \r | |
242 | **/\r | |
243 | BOOLEAN\r | |
244 | EFIAPI\r | |
245 | VariableExLibAtRuntime (\r | |
246 | VOID\r | |
247 | )\r | |
248 | {\r | |
249 | return AtRuntime ();\r | |
250 | }\r |