]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/VariablePei/Variable.c
1. delete Include/Guid/VariableInfo.h
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / VariablePei / Variable.c
CommitLineData
3dbba770 1/** @file\r
bcd70414 2 Framework PEIM to provide the Variable functionality\r
3 \r
de631489 4Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
7ba905c9 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12Module Name:\r
13\r
3dbba770 14**/\r
7ba905c9 15\r
16\r
17#include "Variable.h"\r
18\r
19//\r
20// Module globals\r
21//\r
819d1488 22EFI_PEI_READ_ONLY_VARIABLE_PPI mVariablePpi = {\r
7ba905c9 23 PeiGetVariable,\r
24 PeiGetNextVariableName\r
25};\r
26\r
819d1488 27EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariable2Ppi = {\r
7ba905c9 28 PeiGetVariable2,\r
29 PeiGetNextVariableName2\r
30};\r
31\r
819d1488 32EFI_PEI_PPI_DESCRIPTOR mPpiListVariable[] = {\r
7ba905c9 33 {\r
34 (EFI_PEI_PPI_DESCRIPTOR_PPI),\r
35 &gEfiPeiReadOnlyVariable2PpiGuid,\r
36 &mVariable2Ppi\r
37 },\r
38 {\r
39 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
40 &gEfiPeiReadOnlyVariablePpiGuid,\r
41 &mVariablePpi\r
42 }\r
43};\r
44\r
45EFI_GUID mEfiVariableIndexTableGuid = EFI_VARIABLE_INDEX_TABLE_GUID;\r
46\r
bcd70414 47/**\r
48 Provide the functionality of the variable services.\r
49\r
f2fa830e 50 @param FileHandle Handle of the file being invoked.\r
51 @param PeiServices Describes the list of possible PEI Services.\r
bcd70414 52\r
f2fa830e 53 @return EFI_SUCCESS If the interface could be successfully installed.\r
54 @return EFI_UNSUPPORTED If current boot path is in recovery mode, then does not\r
55 install this interface.\r
bcd70414 56\r
57**/\r
7ba905c9 58EFI_STATUS\r
59EFIAPI\r
60PeimInitializeVariableServices (\r
8bd22b8a
LG
61 IN EFI_PEI_FILE_HANDLE FileHandle,\r
62 IN CONST EFI_PEI_SERVICES **PeiServices\r
7ba905c9 63 )\r
7ba905c9 64{\r
f2fa830e 65 EFI_BOOT_MODE BootMode;\r
66 EFI_STATUS Status;\r
67\r
7ba905c9 68 //\r
f2fa830e 69 // Check if this is recovery boot path. If no, publish the variable access capability\r
70 // to other modules. If yes, the content of variable area is not reliable. Therefore,\r
71 // in this case we should not provide variable service to other pei modules. \r
72 // \r
73 Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode);\r
74 ASSERT_EFI_ERROR (Status);\r
75 \r
76 if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
77 return EFI_UNSUPPORTED;\r
78 }\r
79 \r
8bd22b8a 80 return (**PeiServices).InstallPpi (PeiServices, &mPpiListVariable[0]);\r
7ba905c9 81\r
82}\r
83\r
bcd70414 84/**\r
130e2569 85 This code gets the pointer to the first variable memory pointer byte\r
7ba905c9 86\r
bcd70414 87 @param VarStoreHeader Pointer to the Variable Store Header.\r
130e2569 88\r
fdb05fa3 89 @return VARIABLE_HEADER* Pointer to last unavailable Variable Header\r
130e2569 90\r
bcd70414 91**/\r
92VARIABLE_HEADER *\r
93GetStartPointer (\r
94 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
95 )\r
130e2569 96{\r
97 //\r
98 // The end of variable store\r
99 //\r
100 return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1);\r
101}\r
102\r
bcd70414 103/**\r
130e2569 104 This code gets the pointer to the last variable memory pointer byte\r
105\r
bcd70414 106 @param VarStoreHeader Pointer to the Variable Store Header.\r
130e2569 107\r
fdb05fa3 108 @return VARIABLE_HEADER* Pointer to last unavailable Variable Header\r
130e2569 109\r
bcd70414 110**/\r
111VARIABLE_HEADER *\r
112GetEndPointer (\r
113 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
114 )\r
7ba905c9 115\r
7ba905c9 116{\r
130e2569 117 //\r
118 // The end of variable store\r
119 //\r
120 return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size);\r
7ba905c9 121}\r
122\r
bcd70414 123/**\r
124\r
125 This code checks if variable header is valid or not.\r
126\r
127 @param Variable Pointer to the Variable Header.\r
128\r
129 @retval TRUE Variable header is valid.\r
130 @retval FALSE Variable header is not valid.\r
131\r
132**/\r
7ba905c9 133BOOLEAN\r
134EFIAPI\r
135IsValidVariableHeader (\r
136 IN VARIABLE_HEADER *Variable\r
137 )\r
7ba905c9 138{\r
9cad030b 139 if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) {\r
7ba905c9 140 return FALSE;\r
141 }\r
142\r
143 return TRUE;\r
144}\r
145\r
bcd70414 146/**\r
147 This code gets the size of name of variable.\r
148\r
149 @param Variable Pointer to the Variable Header.\r
130e2569 150\r
fdb05fa3 151 @return UINTN Size of variable in bytes\r
bcd70414 152\r
153**/\r
130e2569 154UINTN\r
155NameSizeOfVariable (\r
156 IN VARIABLE_HEADER *Variable\r
157 )\r
130e2569 158{\r
159 if (Variable->State == (UINT8) (-1) ||\r
160 Variable->DataSize == (UINT32) -1 ||\r
161 Variable->NameSize == (UINT32) -1 ||\r
162 Variable->Attributes == (UINT32) -1) {\r
163 return 0;\r
164 }\r
165 return (UINTN) Variable->NameSize;\r
166}\r
167\r
bcd70414 168/**\r
130e2569 169 This code gets the size of name of variable.\r
170\r
bcd70414 171 @param Variable Pointer to the Variable Header.\r
130e2569 172\r
fdb05fa3 173 @return UINTN Size of variable in bytes\r
130e2569 174\r
bcd70414 175**/\r
176UINTN\r
177DataSizeOfVariable (\r
178 IN VARIABLE_HEADER *Variable\r
179 )\r
130e2569 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
bcd70414 190/**\r
130e2569 191 This code gets the pointer to the variable name.\r
192\r
bcd70414 193 @param Variable Pointer to the Variable Header.\r
130e2569 194\r
fdb05fa3 195 @return CHAR16* Pointer to Variable Name\r
130e2569 196\r
bcd70414 197**/\r
198CHAR16 *\r
199GetVariableNamePtr (\r
200 IN VARIABLE_HEADER *Variable\r
201 )\r
130e2569 202\r
130e2569 203{\r
204\r
205 return (CHAR16 *) (Variable + 1);\r
206}\r
207\r
bcd70414 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
fdb05fa3 213 @return UINT8* Pointer to Variable Data\r
130e2569 214\r
bcd70414 215**/\r
130e2569 216UINT8 *\r
217GetVariableDataPtr (\r
218 IN VARIABLE_HEADER *Variable\r
219 )\r
130e2569 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
bcd70414 233/**\r
130e2569 234 This code gets the pointer to the next variable header.\r
235\r
bcd70414 236 @param Variable Pointer to the Variable Header.\r
130e2569 237\r
fdb05fa3 238 @return VARIABLE_HEADER* Pointer to next variable header.\r
130e2569 239\r
bcd70414 240**/\r
241VARIABLE_HEADER *\r
242GetNextVariablePtr (\r
243 IN VARIABLE_HEADER *Variable\r
244 )\r
130e2569 245\r
130e2569 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
bcd70414 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
130e2569 267\r
bcd70414 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
7ba905c9 273VARIABLE_STORE_STATUS\r
274EFIAPI\r
275GetVariableStoreStatus (\r
276 IN VARIABLE_STORE_HEADER *VarStoreHeader\r
277 )\r
7ba905c9 278\r
7ba905c9 279{\r
3709c4cd 280 \r
281 if (CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid) &&\r
7ba905c9 282 VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&\r
283 VarStoreHeader->State == VARIABLE_STORE_HEALTHY\r
284 ) {\r
285\r
286 return EfiValid;\r
287 }\r
288\r
3709c4cd 289 if (((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff &&\r
290 ((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff &&\r
291 ((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff &&\r
292 ((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff &&\r
7ba905c9 293 VarStoreHeader->Size == 0xffffffff &&\r
294 VarStoreHeader->Format == 0xff &&\r
295 VarStoreHeader->State == 0xff\r
296 ) {\r
297\r
298 return EfiRaw;\r
299 } else {\r
300 return EfiInvalid;\r
301 }\r
302}\r
303\r
bcd70414 304/**\r
305 This function compares a variable with variable entries in database\r
306\r
307 @param Variable - Pointer to the variable in our database\r
308 @param VariableName - Name of the variable to compare to 'Variable'\r
309 @param VendorGuid - GUID of the variable to compare to 'Variable'\r
310 @param PtrTrack - Variable Track Pointer structure that contains\r
311 Variable Information.\r
312\r
fdb05fa3 313 @retval EFI_SUCCESS - Found match variable\r
bcd70414 314 @retval EFI_NOT_FOUND - Variable not found\r
315\r
316**/\r
7ba905c9 317EFI_STATUS\r
318CompareWithValidVariable (\r
319 IN VARIABLE_HEADER *Variable,\r
320 IN CONST CHAR16 *VariableName,\r
321 IN CONST EFI_GUID *VendorGuid,\r
322 OUT VARIABLE_POINTER_TRACK *PtrTrack\r
323 )\r
7ba905c9 324\r
7ba905c9 325{\r
130e2569 326 VOID *Point;\r
327\r
7ba905c9 328 if (VariableName[0] == 0) {\r
329 PtrTrack->CurrPtr = Variable;\r
330 return EFI_SUCCESS;\r
331 } else {\r
332 //\r
333 // Don't use CompareGuid function here for performance reasons.\r
334 // Instead we compare the GUID a UINT32 at a time and branch\r
335 // on the first failed comparison.\r
336 //\r
337 if ((((INT32 *) VendorGuid)[0] == ((INT32 *) &Variable->VendorGuid)[0]) &&\r
338 (((INT32 *) VendorGuid)[1] == ((INT32 *) &Variable->VendorGuid)[1]) &&\r
339 (((INT32 *) VendorGuid)[2] == ((INT32 *) &Variable->VendorGuid)[2]) &&\r
340 (((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3])\r
341 ) {\r
130e2569 342 ASSERT (NameSizeOfVariable (Variable) != 0);\r
343 Point = (VOID *) GetVariableNamePtr (Variable);\r
344 if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable))) {\r
7ba905c9 345 PtrTrack->CurrPtr = Variable;\r
346 return EFI_SUCCESS;\r
347 }\r
348 }\r
349 }\r
350\r
351 return EFI_NOT_FOUND;\r
352}\r
353\r
bcd70414 354/**\r
355 This code finds variable in storage blocks (Non-Volatile)\r
356\r
357 @param PeiServices - General purpose services available to every PEIM.\r
358 @param VariableName - Name of the variable to be found\r
359 @param VendorGuid - Vendor GUID to be found.\r
360 @param PtrTrack - Variable Track Pointer structure that contains\r
361 Variable Information.\r
362\r
363 @retval EFI_SUCCESS - Variable found successfully\r
364 @retval EFI_NOT_FOUND - Variable not found\r
365 @retval EFI_INVALID_PARAMETER - Invalid variable name\r
366\r
367**/\r
7ba905c9 368EFI_STATUS\r
369EFIAPI\r
370FindVariable (\r
1b641bb8 371 IN EFI_PEI_SERVICES **PeiServices,\r
7ba905c9 372 IN CONST CHAR16 *VariableName,\r
373 IN CONST EFI_GUID *VendorGuid,\r
374 OUT VARIABLE_POINTER_TRACK *PtrTrack\r
375 )\r
7ba905c9 376\r
7ba905c9 377{\r
378 EFI_HOB_GUID_TYPE *GuidHob;\r
379 VARIABLE_STORE_HEADER *VariableStoreHeader;\r
380 VARIABLE_HEADER *Variable;\r
381 VARIABLE_HEADER *MaxIndex;\r
382 VARIABLE_INDEX_TABLE *IndexTable;\r
383 UINT32 Count;\r
384 UINT8 *VariableBase;\r
385\r
6041576e 386 if (VariableName[0] != 0 && VendorGuid == NULL) {\r
7ba905c9 387 return EFI_INVALID_PARAMETER;\r
388 }\r
389 //\r
390 // No Variable Address equals zero, so 0 as initial value is safe.\r
391 //\r
392 MaxIndex = 0;\r
393\r
394 GuidHob = GetFirstGuidHob (&mEfiVariableIndexTableGuid);\r
395 if (GuidHob == NULL) {\r
396 IndexTable = BuildGuidHob (&mEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));\r
397 IndexTable->Length = 0;\r
398 IndexTable->StartPtr = NULL;\r
399 IndexTable->EndPtr = NULL;\r
400 IndexTable->GoneThrough = 0;\r
401 } else {\r
402 IndexTable = GET_GUID_HOB_DATA (GuidHob);\r
403 for (Count = 0; Count < IndexTable->Length; Count++)\r
404 {\r
405 MaxIndex = GetVariableByIndex (IndexTable, Count);\r
130e2569 406\r
7ba905c9 407 if (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
408 PtrTrack->StartPtr = IndexTable->StartPtr;\r
409 PtrTrack->EndPtr = IndexTable->EndPtr;\r
410\r
411 return EFI_SUCCESS;\r
412 }\r
413 }\r
414\r
415 if (IndexTable->GoneThrough) {\r
416 return EFI_NOT_FOUND;\r
417 }\r
418 }\r
419 //\r
420 // If not found in HOB, then let's start from the MaxIndex we've found.\r
421 //\r
422 if (MaxIndex != NULL) {\r
423 Variable = GetNextVariablePtr (MaxIndex);\r
424 } else {\r
425 if (IndexTable->StartPtr || IndexTable->EndPtr) {\r
426 Variable = IndexTable->StartPtr;\r
427 } else {\r
428 VariableBase = (UINT8 *) (UINTN) PcdGet32 (PcdFlashNvStorageVariableBase);\r
429 VariableStoreHeader = (VARIABLE_STORE_HEADER *) (VariableBase + \\r
430 ((EFI_FIRMWARE_VOLUME_HEADER *) (VariableBase)) -> HeaderLength);\r
431\r
432 if (GetVariableStoreStatus (VariableStoreHeader) != EfiValid) {\r
433 return EFI_UNSUPPORTED;\r
434 }\r
435\r
436 if (~VariableStoreHeader->Size == 0) {\r
437 return EFI_NOT_FOUND;\r
438 }\r
439 //\r
440 // Find the variable by walk through non-volatile variable store\r
441 //\r
130e2569 442 IndexTable->StartPtr = GetStartPointer (VariableStoreHeader);\r
443 IndexTable->EndPtr = GetEndPointer (VariableStoreHeader);\r
7ba905c9 444\r
445 //\r
446 // Start Pointers for the variable.\r
447 // Actual Data Pointer where data can be written.\r
448 //\r
449 Variable = IndexTable->StartPtr;\r
450 }\r
451 }\r
452 //\r
453 // Find the variable by walk through non-volatile variable store\r
454 //\r
455 PtrTrack->StartPtr = IndexTable->StartPtr;\r
456 PtrTrack->EndPtr = IndexTable->EndPtr;\r
457\r
458 while (IsValidVariableHeader (Variable) && (Variable <= IndexTable->EndPtr)) {\r
459 if (Variable->State == VAR_ADDED) {\r
460 //\r
461 // Record Variable in VariableIndex HOB\r
462 //\r
463 if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME)\r
464 {\r
465 VariableIndexTableUpdate (IndexTable, Variable);\r
466 }\r
467\r
468 if (CompareWithValidVariable (Variable, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
469 return EFI_SUCCESS;\r
470 }\r
471 }\r
472\r
473 Variable = GetNextVariablePtr (Variable);\r
474 }\r
475 //\r
476 // If gone through the VariableStore, that means we never find in Firmware any more.\r
477 //\r
478 if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) {\r
479 IndexTable->GoneThrough = 1;\r
480 }\r
481\r
482 PtrTrack->CurrPtr = NULL;\r
483\r
484 return EFI_NOT_FOUND;\r
485}\r
486\r
bcd70414 487/**\r
7ba905c9 488 Provide the read variable functionality of the variable services.\r
489\r
bcd70414 490 @param PeiServices - General purpose services available to every PEIM.\r
7ba905c9 491\r
bcd70414 492 @param VariableName - The variable name\r
7ba905c9 493\r
bcd70414 494 @param VendorGuid - The vendor's GUID\r
7ba905c9 495\r
bcd70414 496 @param Attributes - Pointer to the attribute\r
7ba905c9 497\r
bcd70414 498 @param DataSize - Size of data\r
7ba905c9 499\r
bcd70414 500 @param Data - Pointer to data\r
7ba905c9 501\r
bcd70414 502 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 503\r
bcd70414 504 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 505\r
bcd70414 506 @retval EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough\r
7ba905c9 507\r
bcd70414 508**/\r
509EFI_STATUS\r
510EFIAPI\r
511PeiGetVariable (\r
512 IN EFI_PEI_SERVICES **PeiServices,\r
513 IN CHAR16 *VariableName,\r
514 IN EFI_GUID * VendorGuid,\r
515 OUT UINT32 *Attributes OPTIONAL,\r
516 IN OUT UINTN *DataSize,\r
517 OUT VOID *Data\r
518 )\r
7ba905c9 519\r
7ba905c9 520{\r
521 VARIABLE_POINTER_TRACK Variable;\r
522 UINTN VarDataSize;\r
523 EFI_STATUS Status;\r
524\r
de631489 525 if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
7ba905c9 526 return EFI_INVALID_PARAMETER;\r
527 }\r
528 //\r
529 // Find existing variable\r
530 //\r
531 Status = FindVariable (PeiServices, VariableName, VendorGuid, &Variable);\r
532\r
533 if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
534 return Status;\r
535 }\r
536 //\r
537 // Get data size\r
538 //\r
130e2569 539 VarDataSize = DataSizeOfVariable (Variable.CurrPtr);\r
7ba905c9 540 if (*DataSize >= VarDataSize) {\r
fd431a9b 541 //\r
542 // PO-TKW: Address one checking in this place\r
543 //\r
544 if (Data == NULL) {\r
545 return EFI_INVALID_PARAMETER;\r
546 }\r
547\r
130e2569 548 (*PeiServices)->CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
7ba905c9 549\r
550 if (Attributes != NULL) {\r
551 *Attributes = Variable.CurrPtr->Attributes;\r
552 }\r
553\r
554 *DataSize = VarDataSize;\r
555 return EFI_SUCCESS;\r
556 } else {\r
557 *DataSize = VarDataSize;\r
558 return EFI_BUFFER_TOO_SMALL;\r
559 }\r
560}\r
561\r
bcd70414 562/**\r
7ba905c9 563 Provide the read variable functionality of the variable services.\r
564\r
bcd70414 565 @param PeiServices - General purpose services available to every PEIM.\r
7ba905c9 566\r
bcd70414 567 @param VariableName - The variable name\r
7ba905c9 568\r
bcd70414 569 @param VendorGuid - The vendor's GUID\r
7ba905c9 570\r
bcd70414 571 @param Attributes - Pointer to the attribute\r
7ba905c9 572\r
bcd70414 573 @param DataSize - Size of data\r
7ba905c9 574\r
bcd70414 575 @param Data - Pointer to data\r
7ba905c9 576\r
bcd70414 577 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 578\r
bcd70414 579 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 580\r
bcd70414 581 @retval EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough\r
7ba905c9 582\r
bcd70414 583**/\r
584EFI_STATUS\r
585EFIAPI\r
586PeiGetVariable2 (\r
587 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
588 IN CONST CHAR16 *VariableName,\r
589 IN CONST EFI_GUID *VariableGuid,\r
590 OUT UINT32 *Attributes,\r
591 IN OUT UINTN *DataSize,\r
592 OUT VOID *Data\r
593 )\r
7ba905c9 594\r
7ba905c9 595{\r
596 return PeiGetVariable (\r
1b641bb8 597 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
7ba905c9 598 (CHAR16*)VariableName,\r
599 (EFI_GUID*)VariableGuid,\r
600 Attributes,\r
601 DataSize,\r
602 Data\r
603 );\r
604}\r
605\r
bcd70414 606/**\r
7ba905c9 607 Provide the get next variable functionality of the variable services.\r
608\r
bcd70414 609 @param PeiServices - General purpose services available to every PEIM.\r
610 @param VariabvleNameSize - The variable name's size.\r
611 @param VariableName - A pointer to the variable's name.\r
612 @param VendorGuid - A pointer to the EFI_GUID structure.\r
7ba905c9 613\r
bcd70414 614 @param VariableNameSize - Size of the variable name\r
7ba905c9 615\r
bcd70414 616 @param VariableName - The variable name\r
7ba905c9 617\r
bcd70414 618 @param VendorGuid - The vendor's GUID\r
7ba905c9 619\r
bcd70414 620 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 621\r
bcd70414 622 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 623\r
bcd70414 624**/\r
625EFI_STATUS\r
626EFIAPI\r
627PeiGetNextVariableName (\r
628 IN EFI_PEI_SERVICES **PeiServices,\r
629 IN OUT UINTN *VariableNameSize,\r
630 IN OUT CHAR16 *VariableName,\r
631 IN OUT EFI_GUID *VendorGuid\r
632 )\r
7ba905c9 633\r
7ba905c9 634{\r
635 VARIABLE_POINTER_TRACK Variable;\r
636 UINTN VarNameSize;\r
637 EFI_STATUS Status;\r
638\r
de631489 639 if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
7ba905c9 640 return EFI_INVALID_PARAMETER;\r
641 }\r
642\r
643 Status = FindVariable (PeiServices, VariableName, VendorGuid, &Variable);\r
644\r
645 if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
646 return Status;\r
647 }\r
648\r
649 if (VariableName[0] != 0) {\r
650 //\r
651 // If variable name is not NULL, get next variable\r
652 //\r
653 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
654 }\r
655\r
656 while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) {\r
657 if (IsValidVariableHeader (Variable.CurrPtr)) {\r
658 if (Variable.CurrPtr->State == VAR_ADDED) {\r
130e2569 659 ASSERT (NameSizeOfVariable (Variable.CurrPtr) != 0);\r
9cad030b 660\r
130e2569 661 VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr);\r
7ba905c9 662 if (VarNameSize <= *VariableNameSize) {\r
130e2569 663 (*PeiServices)->CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize);\r
7ba905c9 664\r
665 (*PeiServices)->CopyMem (VendorGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));\r
666\r
667 Status = EFI_SUCCESS;\r
668 } else {\r
669 Status = EFI_BUFFER_TOO_SMALL;\r
670 }\r
671\r
672 *VariableNameSize = VarNameSize;\r
673 return Status;\r
674 //\r
675 // Variable is found\r
676 //\r
677 } else {\r
678 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
679 }\r
680 } else {\r
681 break;\r
682 }\r
683 }\r
684\r
685 return EFI_NOT_FOUND;\r
686}\r
687\r
bcd70414 688/**\r
7ba905c9 689 Provide the get next variable functionality of the variable services.\r
690\r
bcd70414 691 @param PeiServices - General purpose services available to every PEIM.\r
692 @param VariabvleNameSize - The variable name's size.\r
693 @param VariableName - A pointer to the variable's name.\r
694 @param VariableGuid - A pointer to the EFI_GUID structure.\r
7ba905c9 695\r
bcd70414 696 @param VariableNameSize - Size of the variable name\r
7ba905c9 697\r
bcd70414 698 @param VariableName - The variable name\r
7ba905c9 699\r
bcd70414 700 @param VendorGuid - The vendor's GUID\r
7ba905c9 701\r
7ba905c9 702\r
bcd70414 703 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 704\r
bcd70414 705 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 706\r
bcd70414 707**/\r
708EFI_STATUS\r
709EFIAPI\r
710PeiGetNextVariableName2 (\r
711 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
712 IN OUT UINTN *VariableNameSize,\r
713 IN OUT CHAR16 *VariableName,\r
714 IN OUT EFI_GUID *VariableGuid\r
715 )\r
7ba905c9 716\r
7ba905c9 717{\r
718 return PeiGetNextVariableName (\r
1b641bb8 719 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
7ba905c9 720 VariableNameSize,\r
721 VariableName,\r
722 VariableGuid\r
723 );\r
6bee1632 724}\r
bcd70414 725\r