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