]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/Pei/Variable.c
Clean up meta data and code scrub for PCI Bus module.
[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
3709c4cd 271 \r
272 if (CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid) &&\r
8d3a5c82 273 VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&\r
274 VarStoreHeader->State == VARIABLE_STORE_HEALTHY\r
275 ) {\r
276\r
277 return EfiValid;\r
278 }\r
279\r
3709c4cd 280 if (((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff &&\r
281 ((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff &&\r
282 ((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff &&\r
283 ((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff &&\r
8d3a5c82 284 VarStoreHeader->Size == 0xffffffff &&\r
285 VarStoreHeader->Format == 0xff &&\r
286 VarStoreHeader->State == 0xff\r
287 ) {\r
288\r
289 return EfiRaw;\r
290 } else {\r
291 return EfiInvalid;\r
292 }\r
293}\r
294\r
33479ddf 295\r
296/**\r
297 This function compares a variable with variable entries in database.\r
298\r
299 @param Variable Pointer to the variable in our database\r
300 @param VariableName Name of the variable to compare to 'Variable'\r
301 @param VendorGuid GUID of the variable to compare to 'Variable'\r
302 @param PtrTrack Variable Track Pointer structure that contains Variable Information.\r
303\r
304 @retval EFI_SUCCESS Found match variable\r
305 @retval EFI_NOT_FOUND Variable not found\r
306\r
307**/\r
8d3a5c82 308EFI_STATUS\r
309CompareWithValidVariable (\r
310 IN VARIABLE_HEADER *Variable,\r
311 IN CONST CHAR16 *VariableName,\r
312 IN CONST EFI_GUID *VendorGuid,\r
313 OUT VARIABLE_POINTER_TRACK *PtrTrack\r
314 )\r
8d3a5c82 315{\r
130e2569 316 VOID *Point;\r
317\r
8d3a5c82 318 if (VariableName[0] == 0) {\r
319 PtrTrack->CurrPtr = Variable;\r
320 return EFI_SUCCESS;\r
321 } else {\r
322 //\r
323 // Don't use CompareGuid function here for performance reasons.\r
324 // Instead we compare the GUID a UINT32 at a time and branch\r
325 // on the first failed comparison.\r
326 //\r
327 if ((((INT32 *) VendorGuid)[0] == ((INT32 *) &Variable->VendorGuid)[0]) &&\r
328 (((INT32 *) VendorGuid)[1] == ((INT32 *) &Variable->VendorGuid)[1]) &&\r
329 (((INT32 *) VendorGuid)[2] == ((INT32 *) &Variable->VendorGuid)[2]) &&\r
330 (((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3])\r
331 ) {\r
130e2569 332 ASSERT (NameSizeOfVariable (Variable) != 0);\r
333 Point = (VOID *) GetVariableNamePtr (Variable);\r
dfc005c3 334 if (CompareMem (VariableName, Point, NameSizeOfVariable (Variable)) == 0) {\r
8d3a5c82 335 PtrTrack->CurrPtr = Variable;\r
336 return EFI_SUCCESS;\r
337 }\r
338 }\r
339 }\r
340\r
341 return EFI_NOT_FOUND;\r
342}\r
343\r
33479ddf 344\r
345/**\r
346 This code finds variable in storage blocks (Non-Volatile).\r
347\r
348 @param PeiServices General purpose services available to every PEIM.\r
349 @param VariableName Name of the variable to be found\r
350 @param VendorGuid Vendor GUID to be found.\r
351 @param PtrTrack Variable Track Pointer structure that contains Variable Information.\r
352\r
353 @retval EFI_SUCCESS Variable found successfully\r
354 @retval EFI_NOT_FOUND Variable not found\r
355 @retval EFI_INVALID_PARAMETER Invalid variable name\r
356\r
357**/\r
8d3a5c82 358EFI_STATUS\r
8d3a5c82 359FindVariable (\r
284c8400 360 IN CONST EFI_PEI_SERVICES **PeiServices,\r
8d3a5c82 361 IN CONST CHAR16 *VariableName,\r
362 IN CONST EFI_GUID *VendorGuid,\r
363 OUT VARIABLE_POINTER_TRACK *PtrTrack\r
364 )\r
8d3a5c82 365{\r
366 EFI_HOB_GUID_TYPE *GuidHob;\r
367 VARIABLE_STORE_HEADER *VariableStoreHeader;\r
368 VARIABLE_HEADER *Variable;\r
369 VARIABLE_HEADER *MaxIndex;\r
370 VARIABLE_INDEX_TABLE *IndexTable;\r
371 UINT32 Count;\r
372 UINT8 *VariableBase;\r
373\r
6041576e 374 if (VariableName[0] != 0 && VendorGuid == NULL) {\r
8d3a5c82 375 return EFI_INVALID_PARAMETER;\r
376 }\r
377 //\r
378 // No Variable Address equals zero, so 0 as initial value is safe.\r
379 //\r
380 MaxIndex = 0;\r
381\r
382 GuidHob = GetFirstGuidHob (&mEfiVariableIndexTableGuid);\r
383 if (GuidHob == NULL) {\r
384 IndexTable = BuildGuidHob (&mEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));\r
385 IndexTable->Length = 0;\r
386 IndexTable->StartPtr = NULL;\r
387 IndexTable->EndPtr = NULL;\r
388 IndexTable->GoneThrough = 0;\r
389 } else {\r
390 IndexTable = GET_GUID_HOB_DATA (GuidHob);\r
33479ddf 391 for (Count = 0; Count < IndexTable->Length; Count++) {\r
8d3a5c82 392 MaxIndex = GetVariableByIndex (IndexTable, Count);\r
393\r
394 if (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
395 PtrTrack->StartPtr = IndexTable->StartPtr;\r
396 PtrTrack->EndPtr = IndexTable->EndPtr;\r
397\r
398 return EFI_SUCCESS;\r
399 }\r
400 }\r
401\r
33479ddf 402 if (IndexTable->GoneThrough != 0) {\r
8d3a5c82 403 return EFI_NOT_FOUND;\r
404 }\r
405 }\r
406 //\r
407 // If not found in HOB, then let's start from the MaxIndex we've found.\r
408 //\r
409 if (MaxIndex != NULL) {\r
410 Variable = GetNextVariablePtr (MaxIndex);\r
411 } else {\r
33479ddf 412 if ((IndexTable->StartPtr != NULL) || (IndexTable->EndPtr != NULL)) {\r
8d3a5c82 413 Variable = IndexTable->StartPtr;\r
414 } else {\r
415 VariableBase = (UINT8 *) (UINTN) PcdGet32 (PcdFlashNvStorageVariableBase);\r
416 VariableStoreHeader = (VARIABLE_STORE_HEADER *) (VariableBase + \\r
417 ((EFI_FIRMWARE_VOLUME_HEADER *) (VariableBase)) -> HeaderLength);\r
418\r
419 if (GetVariableStoreStatus (VariableStoreHeader) != EfiValid) {\r
420 return EFI_UNSUPPORTED;\r
421 }\r
422\r
423 if (~VariableStoreHeader->Size == 0) {\r
424 return EFI_NOT_FOUND;\r
425 }\r
426 //\r
427 // Find the variable by walk through non-volatile variable store\r
428 //\r
9cad030b 429 IndexTable->StartPtr = GetStartPointer (VariableStoreHeader);\r
430 IndexTable->EndPtr = GetEndPointer (VariableStoreHeader);\r
8d3a5c82 431\r
432 //\r
433 // Start Pointers for the variable.\r
434 // Actual Data Pointer where data can be written.\r
435 //\r
436 Variable = IndexTable->StartPtr;\r
437 }\r
438 }\r
439 //\r
440 // Find the variable by walk through non-volatile variable store\r
441 //\r
442 PtrTrack->StartPtr = IndexTable->StartPtr;\r
443 PtrTrack->EndPtr = IndexTable->EndPtr;\r
444\r
fba0ee1f 445 while ((Variable < IndexTable->EndPtr) && IsValidVariableHeader (Variable)) {\r
8d3a5c82 446 if (Variable->State == VAR_ADDED) {\r
447 //\r
448 // Record Variable in VariableIndex HOB\r
449 //\r
96a5ac5b 450 VariableIndexTableUpdate (IndexTable, Variable);\r
451 \r
8d3a5c82 452 if (CompareWithValidVariable (Variable, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
453 return EFI_SUCCESS;\r
454 }\r
455 }\r
456\r
457 Variable = GetNextVariablePtr (Variable);\r
458 }\r
459 //\r
460 // If gone through the VariableStore, that means we never find in Firmware any more.\r
461 //\r
462 if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) {\r
463 IndexTable->GoneThrough = 1;\r
464 }\r
465\r
466 PtrTrack->CurrPtr = NULL;\r
467\r
468 return EFI_NOT_FOUND;\r
469}\r
470\r
33479ddf 471/**\r
472 This service retrieves a variable's value using its name and GUID.\r
473\r
474 Read the specified variable from the UEFI variable store. If the Data \r
475 buffer is too small to hold the contents of the variable, the error\r
476 EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the required buffer\r
477 size to obtain the data.\r
478\r
479 @param This A pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.\r
480 @param VariableName A pointer to a null-terminated string that is the variable's name.\r
481 @param VariableGuid A pointer to an EFI_GUID that is the variable's GUID. The combination of\r
482 VariableGuid and VariableName must be unique.\r
483 @param Attributes If non-NULL, on return, points to the variable's attributes.\r
484 @param DataSize On entry, points to the size in bytes of the Data buffer.\r
485 On return, points to the size of the data returned in Data.\r
486 @param Data Points to the buffer which will hold the returned variable value.\r
487\r
488 @retval EFI_SUCCESS The variable was read successfully.\r
489 @retval EFI_NOT_FOUND The variable could not be found.\r
490 @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the resulting data. \r
491 DataSize is updated with the size required for \r
492 the specified variable.\r
493 @retval EFI_INVALID_PARAMETER VariableName, VariableGuid, DataSize or Data is NULL.\r
494 @retval EFI_DEVICE_ERROR The variable could not be retrieved because of a device error.\r
495\r
496**/\r
8d3a5c82 497EFI_STATUS\r
498EFIAPI\r
499PeiGetVariable (\r
500 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
501 IN CONST CHAR16 *VariableName,\r
502 IN CONST EFI_GUID *VariableGuid,\r
503 OUT UINT32 *Attributes,\r
504 IN OUT UINTN *DataSize,\r
505 OUT VOID *Data\r
506 )\r
8d3a5c82 507{\r
508 VARIABLE_POINTER_TRACK Variable;\r
509 UINTN VarDataSize;\r
510 EFI_STATUS Status;\r
284c8400 511 CONST EFI_PEI_SERVICES **PeiServices;\r
8d3a5c82 512\r
513 PeiServices = GetPeiServicesTablePointer ();\r
01f352a7 514 if (VariableName == NULL || VariableGuid == NULL || DataSize == NULL) {\r
8d3a5c82 515 return EFI_INVALID_PARAMETER;\r
516 }\r
517 //\r
518 // Find existing variable\r
519 //\r
520 Status = FindVariable (PeiServices, VariableName, VariableGuid, &Variable);\r
521 if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
522 return Status;\r
523 }\r
524 //\r
525 // Get data size\r
526 //\r
130e2569 527 VarDataSize = DataSizeOfVariable (Variable.CurrPtr);\r
8d3a5c82 528 if (*DataSize >= VarDataSize) {\r
39aea48d 529 if (Data == NULL) {\r
530 return EFI_INVALID_PARAMETER;\r
531 }\r
532\r
33479ddf 533 CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
8d3a5c82 534\r
535 if (Attributes != NULL) {\r
536 *Attributes = Variable.CurrPtr->Attributes;\r
537 }\r
538\r
539 *DataSize = VarDataSize;\r
540 return EFI_SUCCESS;\r
541 } else {\r
542 *DataSize = VarDataSize;\r
543 return EFI_BUFFER_TOO_SMALL;\r
544 }\r
545}\r
546\r
33479ddf 547/**\r
548 Return the next variable name and GUID.\r
549\r
550 This function is called multiple times to retrieve the VariableName \r
551 and VariableGuid of all variables currently available in the system. \r
552 On each call, the previous results are passed into the interface, \r
553 and, on return, the interface returns the data for the next \r
554 interface. When the entire variable list has been returned, \r
555 EFI_NOT_FOUND is returned.\r
556\r
557 @param This A pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.\r
558\r
559 @param VariableNameSize On entry, points to the size of the buffer pointed to by VariableName.\r
560 @param VariableName On entry, a pointer to a null-terminated string that is the variable's name.\r
561 On return, points to the next variable's null-terminated name string.\r
562 @param VariableGuid On entry, a pointer to an UEFI _GUID that is the variable's GUID. \r
563 On return, a pointer to the next variable's GUID.\r
564\r
565 @retval EFI_SUCCESS The variable was read successfully.\r
566 @retval EFI_NOT_FOUND The variable could not be found.\r
567 @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the resulting\r
568 data. VariableNameSize is updated with the size\r
569 required for the specified variable.\r
570 @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or\r
571 VariableNameSize is NULL.\r
572 @retval EFI_DEVICE_ERROR The variable could not be retrieved because of a device error.\r
573\r
574**/\r
8d3a5c82 575EFI_STATUS\r
576EFIAPI\r
577PeiGetNextVariableName (\r
578 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
579 IN OUT UINTN *VariableNameSize,\r
580 IN OUT CHAR16 *VariableName,\r
581 IN OUT EFI_GUID *VariableGuid\r
582 )\r
8d3a5c82 583{\r
584 VARIABLE_POINTER_TRACK Variable;\r
585 UINTN VarNameSize;\r
586 EFI_STATUS Status;\r
284c8400 587 CONST EFI_PEI_SERVICES **PeiServices;\r
8d3a5c82 588\r
589 PeiServices = GetPeiServicesTablePointer ();\r
01f352a7 590 if (VariableName == NULL || VariableGuid == NULL || VariableNameSize == NULL) {\r
8d3a5c82 591 return EFI_INVALID_PARAMETER;\r
592 }\r
593\r
594 Status = FindVariable (PeiServices, VariableName, VariableGuid, &Variable);\r
595 if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
596 return Status;\r
597 }\r
598\r
599 if (VariableName[0] != 0) {\r
600 //\r
601 // If variable name is not NULL, get next variable\r
602 //\r
603 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
604 }\r
605\r
606 while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) {\r
607 if (IsValidVariableHeader (Variable.CurrPtr)) {\r
608 if (Variable.CurrPtr->State == VAR_ADDED) {\r
130e2569 609 ASSERT (NameSizeOfVariable (Variable.CurrPtr) != 0);\r
9cad030b 610\r
130e2569 611 VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr);\r
8d3a5c82 612 if (VarNameSize <= *VariableNameSize) {\r
33479ddf 613 CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize);\r
8d3a5c82 614\r
33479ddf 615 CopyMem (VariableGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));\r
8d3a5c82 616\r
617 Status = EFI_SUCCESS;\r
618 } else {\r
619 Status = EFI_BUFFER_TOO_SMALL;\r
620 }\r
621\r
622 *VariableNameSize = VarNameSize;\r
623 return Status;\r
624 //\r
625 // Variable is found\r
626 //\r
627 } else {\r
628 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
629 }\r
630 } else {\r
631 break;\r
632 }\r
633 }\r
634\r
635 return EFI_NOT_FOUND;\r
636}\r