]>
Commit | Line | Data |
---|---|---|
0c18794e | 1 | /** @file\r |
2 | Implement ReadOnly Variable Services required by PEIM and install PEI\r | |
3 | ReadOnly Varaiable2 PPI. These services operates the non-volatile \r | |
4 | storage space.\r | |
5 | \r | |
6 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r | |
7 | This program and the accompanying materials \r | |
8 | are licensed and made available under the terms and conditions of the BSD License \r | |
9 | which accompanies this distribution. The full text of the license may be found at \r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | \r | |
18 | #include "Variable.h"\r | |
19 | \r | |
20 | //\r | |
21 | // Module globals\r | |
22 | //\r | |
23 | EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = {\r | |
24 | PeiGetVariable,\r | |
25 | PeiGetNextVariableName\r | |
26 | };\r | |
27 | \r | |
28 | EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {\r | |
29 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
30 | &gEfiPeiReadOnlyVariable2PpiGuid,\r | |
31 | &mVariablePpi\r | |
32 | };\r | |
33 | \r | |
34 | \r | |
1f58a5dc | 35 | /**\r |
36 | Check if it runs in Recovery mode.\r | |
37 | \r | |
38 | @param PeiServices General purpose services available to every PEIM.\r | |
39 | \r | |
40 | @retval TRUE It's in Recovery mode.\r | |
41 | @retval FALSE It's not in Recovery mode.\r | |
42 | \r | |
43 | **/\r | |
44 | BOOLEAN\r | |
45 | IsInRecoveryMode (\r | |
46 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
47 | )\r | |
48 | {\r | |
49 | EFI_STATUS Status;\r | |
50 | EFI_BOOT_MODE BootMode;\r | |
51 | \r | |
52 | Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode);\r | |
53 | ASSERT_EFI_ERROR (Status);\r | |
54 | \r | |
55 | if (BootMode == BOOT_IN_RECOVERY_MODE) {\r | |
56 | return TRUE;\r | |
57 | }\r | |
58 | return FALSE;\r | |
59 | }\r | |
60 | \r | |
0c18794e | 61 | /**\r |
62 | Provide the functionality of the variable services.\r | |
63 | \r | |
64 | @param FileHandle Handle of the file being invoked. \r | |
65 | Type EFI_PEI_FILE_HANDLE is defined in FfsFindNextFile().\r | |
66 | @param PeiServices General purpose services available to every PEIM.\r | |
67 | \r | |
68 | @retval EFI_SUCCESS If the interface could be successfully installed\r | |
69 | @retval Others Returned from PeiServicesInstallPpi()\r | |
70 | \r | |
71 | **/\r | |
72 | EFI_STATUS\r | |
73 | EFIAPI\r | |
74 | PeimInitializeVariableServices (\r | |
75 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
76 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
77 | )\r | |
78 | {\r | |
0c18794e | 79 | return PeiServicesInstallPpi (&mPpiListVariable);\r |
0c18794e | 80 | }\r |
81 | \r | |
82 | /**\r | |
83 | \r | |
84 | Gets the pointer to the first variable header in given variable store area.\r | |
85 | \r | |
86 | @param VarStoreHeader Pointer to the Variable Store Header.\r | |
87 | \r | |
88 | @return Pointer to the first variable header\r | |
89 | \r | |
90 | **/\r | |
91 | VARIABLE_HEADER *\r | |
92 | GetStartPointer (\r | |
93 | IN VARIABLE_STORE_HEADER *VarStoreHeader\r | |
94 | )\r | |
95 | {\r | |
96 | //\r | |
97 | // The end of variable store\r | |
98 | //\r | |
99 | return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1);\r | |
100 | }\r | |
101 | \r | |
102 | \r | |
103 | /**\r | |
104 | This code gets the pointer to the last variable memory pointer byte.\r | |
105 | \r | |
106 | @param VarStoreHeader Pointer to the Variable Store Header.\r | |
107 | \r | |
108 | @return VARIABLE_HEADER* pointer to last unavailable Variable Header.\r | |
109 | \r | |
110 | **/\r | |
111 | VARIABLE_HEADER *\r | |
112 | GetEndPointer (\r | |
113 | IN VARIABLE_STORE_HEADER *VarStoreHeader\r | |
114 | )\r | |
115 | {\r | |
116 | //\r | |
117 | // The end of variable store\r | |
118 | //\r | |
119 | return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size);\r | |
120 | }\r | |
121 | \r | |
122 | \r | |
123 | /**\r | |
124 | This code checks if variable header is valid or not.\r | |
125 | \r | |
126 | @param Variable Pointer to the Variable Header.\r | |
127 | \r | |
128 | @retval TRUE Variable header is valid.\r | |
129 | @retval FALSE Variable header is not valid.\r | |
130 | \r | |
131 | **/\r | |
132 | BOOLEAN\r | |
133 | IsValidVariableHeader (\r | |
134 | IN VARIABLE_HEADER *Variable\r | |
135 | )\r | |
136 | {\r | |
137 | if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) {\r | |
138 | return FALSE;\r | |
139 | }\r | |
140 | \r | |
141 | return TRUE;\r | |
142 | }\r | |
143 | \r | |
144 | \r | |
145 | /**\r | |
146 | This code gets the size of name of variable.\r | |
147 | \r | |
148 | @param Variable Pointer to the Variable Header.\r | |
149 | \r | |
150 | @return Size of variable in bytes in type UINTN.\r | |
151 | \r | |
152 | **/\r | |
153 | UINTN\r | |
154 | NameSizeOfVariable (\r | |
155 | IN VARIABLE_HEADER *Variable\r | |
156 | )\r | |
157 | {\r | |
158 | if (Variable->State == (UINT8) (-1) ||\r | |
159 | Variable->DataSize == (UINT32) (-1) ||\r | |
160 | Variable->NameSize == (UINT32) (-1) ||\r | |
161 | Variable->Attributes == (UINT32) (-1)) {\r | |
162 | return 0;\r | |
163 | }\r | |
164 | return (UINTN) Variable->NameSize;\r | |
165 | }\r | |
166 | \r | |
167 | \r | |
168 | /**\r | |
169 | This code gets the size of data of variable.\r | |
170 | \r | |
171 | @param Variable Pointer to the Variable Header.\r | |
172 | \r | |
173 | @return Size of variable in bytes in type UINTN.\r | |
174 | \r | |
175 | **/\r | |
176 | UINTN\r | |
177 | DataSizeOfVariable (\r | |
178 | IN VARIABLE_HEADER *Variable\r | |
179 | )\r | |
180 | {\r | |
181 | if (Variable->State == (UINT8) (-1) ||\r | |
182 | Variable->DataSize == (UINT32) (-1) ||\r | |
183 | Variable->NameSize == (UINT32) (-1) ||\r | |
184 | Variable->Attributes == (UINT32) (-1)) {\r | |
185 | return 0;\r | |
186 | }\r | |
187 | return (UINTN) Variable->DataSize;\r | |
188 | }\r | |
189 | \r | |
190 | /**\r | |
191 | This code gets the pointer to the variable name.\r | |
192 | \r | |
193 | @param Variable Pointer to the Variable Header.\r | |
194 | \r | |
195 | @return A CHAR16* pointer to Variable Name.\r | |
196 | \r | |
197 | **/\r | |
198 | CHAR16 *\r | |
199 | GetVariableNamePtr (\r | |
200 | IN VARIABLE_HEADER *Variable\r | |
201 | )\r | |
202 | {\r | |
203 | \r | |
204 | return (CHAR16 *) (Variable + 1);\r | |
205 | }\r | |
206 | \r | |
207 | \r | |
208 | /**\r | |
209 | This code gets the pointer to the variable data.\r | |
210 | \r | |
211 | @param Variable Pointer to the Variable Header.\r | |
212 | \r | |
213 | @return A UINT8* pointer to Variable Data.\r | |
214 | \r | |
215 | **/\r | |
216 | UINT8 *\r | |
217 | GetVariableDataPtr (\r | |
218 | IN VARIABLE_HEADER *Variable\r | |
219 | )\r | |
220 | {\r | |
221 | UINTN Value;\r | |
222 | \r | |
223 | //\r | |
224 | // Be careful about pad size for alignment\r | |
225 | //\r | |
226 | Value = (UINTN) GetVariableNamePtr (Variable);\r | |
227 | Value += NameSizeOfVariable (Variable);\r | |
228 | Value += GET_PAD_SIZE (NameSizeOfVariable (Variable));\r | |
229 | \r | |
230 | return (UINT8 *) Value;\r | |
231 | }\r | |
232 | \r | |
233 | \r | |
234 | /**\r | |
235 | This code gets the pointer to the next variable header.\r | |
236 | \r | |
237 | @param Variable Pointer to the Variable Header.\r | |
238 | \r | |
239 | @return A VARIABLE_HEADER* pointer to next variable header.\r | |
240 | \r | |
241 | **/\r | |
242 | VARIABLE_HEADER *\r | |
243 | GetNextVariablePtr (\r | |
244 | IN VARIABLE_HEADER *Variable\r | |
245 | )\r | |
246 | {\r | |
247 | UINTN Value;\r | |
248 | \r | |
249 | if (!IsValidVariableHeader (Variable)) {\r | |
250 | return NULL;\r | |
251 | }\r | |
252 | \r | |
253 | Value = (UINTN) GetVariableDataPtr (Variable);\r | |
254 | Value += DataSizeOfVariable (Variable);\r | |
255 | Value += GET_PAD_SIZE (DataSizeOfVariable (Variable));\r | |
256 | \r | |
257 | //\r | |
258 | // Be careful about pad size for alignment\r | |
259 | //\r | |
260 | return (VARIABLE_HEADER *) HEADER_ALIGN (Value);\r | |
261 | }\r | |
262 | \r | |
263 | /**\r | |
264 | This code gets the pointer to the variable name.\r | |
265 | \r | |
266 | @param VarStoreHeader Pointer to the Variable Store Header.\r | |
267 | \r | |
268 | @retval EfiRaw Variable store is raw\r | |
269 | @retval EfiValid Variable store is valid\r | |
270 | @retval EfiInvalid Variable store is invalid\r | |
271 | \r | |
272 | **/\r | |
273 | VARIABLE_STORE_STATUS\r | |
274 | GetVariableStoreStatus (\r | |
275 | IN VARIABLE_STORE_HEADER *VarStoreHeader\r | |
276 | )\r | |
277 | {\r | |
278 | \r | |
279 | if (CompareGuid (&VarStoreHeader->Signature, &gEfiAuthenticatedVariableGuid) &&\r | |
280 | VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&\r | |
281 | VarStoreHeader->State == VARIABLE_STORE_HEALTHY\r | |
282 | ) {\r | |
283 | \r | |
284 | return EfiValid;\r | |
285 | }\r | |
286 | \r | |
287 | if (((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff &&\r | |
288 | ((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff &&\r | |
289 | ((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff &&\r | |
290 | ((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff &&\r | |
291 | VarStoreHeader->Size == 0xffffffff &&\r | |
292 | VarStoreHeader->Format == 0xff &&\r | |
293 | VarStoreHeader->State == 0xff\r | |
294 | ) {\r | |
295 | \r | |
296 | return EfiRaw;\r | |
297 | } else {\r | |
298 | return EfiInvalid;\r | |
299 | }\r | |
300 | }\r | |
301 | \r | |
302 | \r | |
303 | /**\r | |
304 | This function compares a variable with variable entries in database.\r | |
305 | \r | |
306 | @param Variable Pointer to the variable in our database\r | |
307 | @param VariableName Name of the variable to compare to 'Variable'\r | |
308 | @param VendorGuid GUID of the variable to compare to 'Variable'\r | |
309 | @param PtrTrack Variable Track Pointer structure that contains Variable Information.\r | |
310 | \r | |
311 | @retval EFI_SUCCESS Found match variable\r | |
312 | @retval EFI_NOT_FOUND Variable not found\r | |
313 | \r | |
314 | **/\r | |
315 | EFI_STATUS\r | |
316 | CompareWithValidVariable (\r | |
317 | IN VARIABLE_HEADER *Variable,\r | |
318 | IN CONST CHAR16 *VariableName,\r | |
319 | IN CONST EFI_GUID *VendorGuid,\r | |
320 | OUT VARIABLE_POINTER_TRACK *PtrTrack\r | |
321 | )\r | |
322 | {\r | |
323 | VOID *Point;\r | |
324 | \r | |
325 | if (VariableName[0] == 0) {\r | |
326 | PtrTrack->CurrPtr = Variable;\r | |
327 | return EFI_SUCCESS;\r | |
328 | } else {\r | |
329 | //\r | |
330 | // Don't use CompareGuid function here for performance reasons.\r | |
331 | // Instead we compare the GUID a UINT32 at a time and branch\r | |
332 | // on the first failed comparison.\r | |
333 | //\r | |
334 | if ((((INT32 *) VendorGuid)[0] == ((INT32 *) &Variable->VendorGuid)[0]) &&\r | |
335 | (((INT32 *) VendorGuid)[1] == ((INT32 *) &Variable->VendorGuid)[1]) &&\r | |
336 | (((INT32 *) VendorGuid)[2] == ((INT32 *) &Variable->VendorGuid)[2]) &&\r | |
337 | (((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3])\r | |
338 | ) {\r | |
339 | ASSERT (NameSizeOfVariable (Variable) != 0);\r | |
340 | Point = (VOID *) GetVariableNamePtr (Variable);\r | |
341 | if (CompareMem (VariableName, Point, NameSizeOfVariable (Variable)) == 0) {\r | |
342 | PtrTrack->CurrPtr = Variable;\r | |
343 | return EFI_SUCCESS;\r | |
344 | }\r | |
345 | }\r | |
346 | }\r | |
347 | \r | |
348 | return EFI_NOT_FOUND;\r | |
349 | }\r | |
350 | \r | |
351 | \r | |
352 | /**\r | |
353 | This code finds variable in storage blocks (Non-Volatile).\r | |
354 | \r | |
355 | @param PeiServices General purpose services available to every PEIM.\r | |
356 | @param VariableName Name of the variable to be found\r | |
357 | @param VendorGuid Vendor GUID to be found.\r | |
358 | @param PtrTrack Variable Track Pointer structure that contains Variable Information.\r | |
359 | \r | |
360 | @retval EFI_SUCCESS Variable found successfully\r | |
361 | @retval EFI_NOT_FOUND Variable not found\r | |
362 | @retval EFI_INVALID_PARAMETER Invalid variable name\r | |
363 | \r | |
364 | **/\r | |
365 | EFI_STATUS\r | |
366 | FindVariable (\r | |
367 | IN CONST EFI_PEI_SERVICES **PeiServices,\r | |
368 | IN CONST CHAR16 *VariableName,\r | |
369 | IN CONST EFI_GUID *VendorGuid,\r | |
370 | OUT VARIABLE_POINTER_TRACK *PtrTrack\r | |
371 | )\r | |
372 | {\r | |
373 | EFI_HOB_GUID_TYPE *GuidHob;\r | |
374 | VARIABLE_STORE_HEADER *VariableStoreHeader;\r | |
375 | VARIABLE_HEADER *Variable;\r | |
376 | VARIABLE_HEADER *LastVariable;\r | |
377 | VARIABLE_HEADER *MaxIndex;\r | |
378 | VARIABLE_INDEX_TABLE *IndexTable;\r | |
379 | UINT32 Count;\r | |
380 | UINT32 Offset;\r | |
381 | UINT8 *VariableBase;\r | |
382 | BOOLEAN StopRecord;\r | |
383 | \r | |
384 | if (VariableName[0] != 0 && VendorGuid == NULL) {\r | |
385 | return EFI_INVALID_PARAMETER;\r | |
386 | }\r | |
387 | //\r | |
388 | // No Variable Address equals zero, so 0 as initial value is safe.\r | |
389 | //\r | |
390 | MaxIndex = 0;\r | |
391 | StopRecord = FALSE;\r | |
392 | \r | |
393 | GuidHob = GetFirstGuidHob (&gEfiVariableIndexTableGuid);\r | |
394 | if (GuidHob == NULL) {\r | |
395 | //\r | |
396 | // If it's the first time to access variable region in flash, create a guid hob to record\r | |
397 | // VAR_ADDED type variable info.\r | |
398 | // Note that as the resource of PEI phase is limited, only store the number of \r | |
399 | // VARIABLE_INDEX_TABLE_VOLUME of VAR_ADDED type variables to reduce access time.\r | |
400 | //\r | |
401 | IndexTable = BuildGuidHob (&gEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));\r | |
402 | IndexTable->Length = 0;\r | |
403 | IndexTable->StartPtr = NULL;\r | |
404 | IndexTable->EndPtr = NULL;\r | |
405 | IndexTable->GoneThrough = 0;\r | |
406 | } else {\r | |
407 | IndexTable = GET_GUID_HOB_DATA (GuidHob);\r | |
408 | for (Offset = 0, Count = 0; Count < IndexTable->Length; Count++) {\r | |
409 | //\r | |
410 | // traverse the variable info list to look for varible.\r | |
411 | // The IndexTable->Index[Count] records the distance of two neighbouring VAR_ADDED type variables.\r | |
412 | //\r | |
413 | ASSERT (Count < VARIABLE_INDEX_TABLE_VOLUME);\r | |
414 | Offset += IndexTable->Index[Count];\r | |
415 | MaxIndex = (VARIABLE_HEADER *)((CHAR8 *)(IndexTable->StartPtr) + Offset);\r | |
416 | if (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r | |
417 | PtrTrack->StartPtr = IndexTable->StartPtr;\r | |
418 | PtrTrack->EndPtr = IndexTable->EndPtr;\r | |
419 | \r | |
420 | return EFI_SUCCESS;\r | |
421 | }\r | |
422 | }\r | |
423 | \r | |
424 | if (IndexTable->GoneThrough != 0) {\r | |
425 | return EFI_NOT_FOUND;\r | |
426 | }\r | |
427 | }\r | |
428 | //\r | |
429 | // If not found in HOB, then let's start from the MaxIndex we've found.\r | |
430 | //\r | |
431 | if (MaxIndex != NULL) {\r | |
432 | Variable = GetNextVariablePtr (MaxIndex);\r | |
433 | LastVariable = MaxIndex;\r | |
434 | } else {\r | |
435 | if ((IndexTable->StartPtr != NULL) || (IndexTable->EndPtr != NULL)) {\r | |
436 | Variable = IndexTable->StartPtr;\r | |
437 | } else {\r | |
438 | VariableBase = (UINT8 *) (UINTN) PcdGet64 (PcdFlashNvStorageVariableBase64);\r | |
439 | if (VariableBase == NULL) {\r | |
440 | VariableBase = (UINT8 *) (UINTN) PcdGet32 (PcdFlashNvStorageVariableBase);\r | |
441 | }\r | |
442 | \r | |
443 | VariableStoreHeader = (VARIABLE_STORE_HEADER *) (VariableBase + \\r | |
444 | ((EFI_FIRMWARE_VOLUME_HEADER *) (VariableBase)) -> HeaderLength);\r | |
445 | \r | |
446 | if (GetVariableStoreStatus (VariableStoreHeader) != EfiValid) {\r | |
447 | return EFI_UNSUPPORTED;\r | |
448 | }\r | |
449 | \r | |
450 | if (~VariableStoreHeader->Size == 0) {\r | |
451 | return EFI_NOT_FOUND;\r | |
452 | }\r | |
453 | //\r | |
454 | // Find the variable by walk through non-volatile variable store\r | |
455 | //\r | |
456 | IndexTable->StartPtr = GetStartPointer (VariableStoreHeader);\r | |
457 | IndexTable->EndPtr = GetEndPointer (VariableStoreHeader);\r | |
458 | \r | |
459 | //\r | |
460 | // Start Pointers for the variable.\r | |
461 | // Actual Data Pointer where data can be written.\r | |
462 | //\r | |
463 | Variable = IndexTable->StartPtr;\r | |
464 | }\r | |
465 | \r | |
466 | LastVariable = IndexTable->StartPtr;\r | |
467 | }\r | |
468 | //\r | |
469 | // Find the variable by walk through non-volatile variable store\r | |
470 | //\r | |
471 | PtrTrack->StartPtr = IndexTable->StartPtr;\r | |
472 | PtrTrack->EndPtr = IndexTable->EndPtr;\r | |
473 | \r | |
474 | while ((Variable < IndexTable->EndPtr) && IsValidVariableHeader (Variable)) {\r | |
475 | if (Variable->State == VAR_ADDED) {\r | |
476 | //\r | |
477 | // Record Variable in VariableIndex HOB\r | |
478 | //\r | |
479 | if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME && !StopRecord) {\r | |
480 | Offset = (UINT32)((UINTN)Variable - (UINTN)LastVariable);\r | |
481 | //\r | |
482 | // The distance of two neighbouring VAR_ADDED variable is larger than 2^16, \r | |
483 | // which is beyond the allowable scope(UINT16) of record. In such case, need not to\r | |
484 | // record the subsequent VAR_ADDED type variables again.\r | |
485 | //\r | |
486 | if ((Offset & 0xFFFF0000UL) != 0) {\r | |
487 | StopRecord = TRUE;\r | |
488 | }\r | |
489 | \r | |
490 | if (!StopRecord) {\r | |
491 | IndexTable->Index[IndexTable->Length++] = (UINT16) Offset;\r | |
492 | }\r | |
493 | LastVariable = Variable;\r | |
494 | }\r | |
495 | \r | |
496 | if (CompareWithValidVariable (Variable, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r | |
497 | return EFI_SUCCESS;\r | |
498 | }\r | |
499 | }\r | |
500 | \r | |
501 | Variable = GetNextVariablePtr (Variable);\r | |
502 | }\r | |
503 | //\r | |
504 | // If gone through the VariableStore, that means we never find in Firmware any more.\r | |
505 | //\r | |
506 | if ((IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) && (!StopRecord)) {\r | |
507 | IndexTable->GoneThrough = 1;\r | |
508 | }\r | |
509 | \r | |
510 | PtrTrack->CurrPtr = NULL;\r | |
511 | \r | |
512 | return EFI_NOT_FOUND;\r | |
513 | }\r | |
514 | \r | |
515 | /**\r | |
516 | This service retrieves a variable's value using its name and GUID.\r | |
517 | \r | |
518 | Read the specified variable from the UEFI variable store. If the Data \r | |
519 | buffer is too small to hold the contents of the variable, the error\r | |
520 | EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the required buffer\r | |
521 | size to obtain the data.\r | |
522 | \r | |
523 | @param This A pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.\r | |
524 | @param VariableName A pointer to a null-terminated string that is the variable's name.\r | |
525 | @param VariableGuid A pointer to an EFI_GUID that is the variable's GUID. The combination of\r | |
526 | VariableGuid and VariableName must be unique.\r | |
527 | @param Attributes If non-NULL, on return, points to the variable's attributes.\r | |
528 | @param DataSize On entry, points to the size in bytes of the Data buffer.\r | |
529 | On return, points to the size of the data returned in Data.\r | |
530 | @param Data Points to the buffer which will hold the returned variable value.\r | |
531 | \r | |
532 | @retval EFI_SUCCESS The variable was read successfully.\r | |
533 | @retval EFI_NOT_FOUND The variable could not be found.\r | |
534 | @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the resulting data. \r | |
535 | DataSize is updated with the size required for \r | |
536 | the specified variable.\r | |
537 | @retval EFI_INVALID_PARAMETER VariableName, VariableGuid, DataSize or Data is NULL.\r | |
538 | @retval EFI_DEVICE_ERROR The variable could not be retrieved because of a device error.\r | |
539 | \r | |
540 | **/\r | |
541 | EFI_STATUS\r | |
542 | EFIAPI\r | |
543 | PeiGetVariable (\r | |
544 | IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r | |
545 | IN CONST CHAR16 *VariableName,\r | |
546 | IN CONST EFI_GUID *VariableGuid,\r | |
547 | OUT UINT32 *Attributes,\r | |
548 | IN OUT UINTN *DataSize,\r | |
549 | OUT VOID *Data\r | |
550 | )\r | |
551 | {\r | |
552 | VARIABLE_POINTER_TRACK Variable;\r | |
553 | UINTN VarDataSize;\r | |
554 | EFI_STATUS Status;\r | |
555 | CONST EFI_PEI_SERVICES **PeiServices;\r | |
556 | \r | |
557 | PeiServices = GetPeiServicesTablePointer ();\r | |
558 | if (VariableName == NULL || VariableGuid == NULL || DataSize == NULL) {\r | |
559 | return EFI_INVALID_PARAMETER;\r | |
560 | }\r | |
1f58a5dc | 561 | \r |
562 | //\r | |
563 | // Check if this is recovery boot path.\r | |
564 | // If yes, the content of variable area is not reliable. Therefore we directly\r | |
565 | // return EFI_NOT_FOUND. \r | |
566 | // \r | |
567 | if (IsInRecoveryMode(PeiServices)) {\r | |
568 | return EFI_NOT_FOUND;\r | |
569 | }\r | |
570 | \r | |
0c18794e | 571 | //\r |
572 | // Find existing variable\r | |
573 | //\r | |
574 | Status = FindVariable (PeiServices, VariableName, VariableGuid, &Variable);\r | |
575 | if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r | |
576 | return Status;\r | |
577 | }\r | |
578 | //\r | |
579 | // Get data size\r | |
580 | //\r | |
581 | VarDataSize = DataSizeOfVariable (Variable.CurrPtr);\r | |
582 | if (*DataSize >= VarDataSize) {\r | |
583 | if (Data == NULL) {\r | |
584 | return EFI_INVALID_PARAMETER;\r | |
585 | }\r | |
586 | \r | |
587 | CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r | |
588 | \r | |
589 | if (Attributes != NULL) {\r | |
590 | *Attributes = Variable.CurrPtr->Attributes;\r | |
591 | }\r | |
592 | \r | |
593 | *DataSize = VarDataSize;\r | |
594 | return EFI_SUCCESS;\r | |
595 | } else {\r | |
596 | *DataSize = VarDataSize;\r | |
597 | return EFI_BUFFER_TOO_SMALL;\r | |
598 | }\r | |
599 | }\r | |
600 | \r | |
601 | /**\r | |
602 | Return the next variable name and GUID.\r | |
603 | \r | |
604 | This function is called multiple times to retrieve the VariableName \r | |
605 | and VariableGuid of all variables currently available in the system. \r | |
606 | On each call, the previous results are passed into the interface, \r | |
607 | and, on return, the interface returns the data for the next \r | |
608 | interface. When the entire variable list has been returned, \r | |
609 | EFI_NOT_FOUND is returned.\r | |
610 | \r | |
611 | @param This A pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.\r | |
612 | \r | |
613 | @param VariableNameSize On entry, points to the size of the buffer pointed to by VariableName.\r | |
614 | On return, the size of the variable name buffer.\r | |
615 | @param VariableName On entry, a pointer to a null-terminated string that is the variable's name.\r | |
616 | On return, points to the next variable's null-terminated name string.\r | |
617 | @param VariableGuid On entry, a pointer to an EFI_GUID that is the variable's GUID. \r | |
618 | On return, a pointer to the next variable's GUID.\r | |
619 | \r | |
620 | @retval EFI_SUCCESS The variable was read successfully.\r | |
621 | @retval EFI_NOT_FOUND The variable could not be found.\r | |
622 | @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the resulting\r | |
623 | data. VariableNameSize is updated with the size\r | |
624 | required for the specified variable.\r | |
625 | @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or\r | |
626 | VariableNameSize is NULL.\r | |
627 | @retval EFI_DEVICE_ERROR The variable could not be retrieved because of a device error.\r | |
628 | \r | |
629 | **/\r | |
630 | EFI_STATUS\r | |
631 | EFIAPI\r | |
632 | PeiGetNextVariableName (\r | |
633 | IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r | |
634 | IN OUT UINTN *VariableNameSize,\r | |
635 | IN OUT CHAR16 *VariableName,\r | |
636 | IN OUT EFI_GUID *VariableGuid\r | |
637 | )\r | |
638 | {\r | |
639 | VARIABLE_POINTER_TRACK Variable;\r | |
640 | UINTN VarNameSize;\r | |
641 | EFI_STATUS Status;\r | |
642 | CONST EFI_PEI_SERVICES **PeiServices;\r | |
643 | \r | |
644 | PeiServices = GetPeiServicesTablePointer ();\r | |
645 | if (VariableName == NULL || VariableGuid == NULL || VariableNameSize == NULL) {\r | |
646 | return EFI_INVALID_PARAMETER;\r | |
647 | }\r | |
648 | \r | |
1f58a5dc | 649 | //\r |
650 | // Check if this is recovery boot path.\r | |
651 | // If yes, the content of variable area is not reliable. Therefore we directly\r | |
652 | // return EFI_NOT_FOUND. \r | |
653 | // \r | |
654 | if (IsInRecoveryMode(PeiServices)) {\r | |
655 | return EFI_NOT_FOUND;\r | |
656 | }\r | |
657 | \r | |
0c18794e | 658 | Status = FindVariable (PeiServices, VariableName, VariableGuid, &Variable);\r |
659 | if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r | |
660 | return Status;\r | |
661 | }\r | |
662 | \r | |
663 | if (VariableName[0] != 0) {\r | |
664 | //\r | |
665 | // If variable name is not NULL, get next variable\r | |
666 | //\r | |
667 | Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r | |
668 | }\r | |
669 | \r | |
670 | while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) {\r | |
671 | if (IsValidVariableHeader (Variable.CurrPtr)) {\r | |
672 | if (Variable.CurrPtr->State == VAR_ADDED) {\r | |
673 | ASSERT (NameSizeOfVariable (Variable.CurrPtr) != 0);\r | |
674 | \r | |
675 | VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr);\r | |
676 | if (VarNameSize <= *VariableNameSize) {\r | |
677 | CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize);\r | |
678 | \r | |
679 | CopyMem (VariableGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));\r | |
680 | \r | |
681 | Status = EFI_SUCCESS;\r | |
682 | } else {\r | |
683 | Status = EFI_BUFFER_TOO_SMALL;\r | |
684 | }\r | |
685 | \r | |
686 | *VariableNameSize = VarNameSize;\r | |
687 | return Status;\r | |
688 | //\r | |
689 | // Variable is found\r | |
690 | //\r | |
691 | } else {\r | |
692 | Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r | |
693 | }\r | |
694 | } else {\r | |
695 | break;\r | |
696 | }\r | |
697 | }\r | |
698 | \r | |
699 | return EFI_NOT_FOUND;\r | |
700 | }\r |