]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/VariablePei/Variable.c
update the QueryVariableInfo interface to first determine if the pointer checked...
[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
33f201a0 4Copyright (c) 2006 - 2009 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
33f201a0 429\r
430 //\r
431 // Check if FV header is valid.\r
432 //\r
433 if (((EFI_FIRMWARE_VOLUME_HEADER *) VariableBase)->Signature != EFI_FVH_SIGNATURE) {\r
434 return EFI_UNSUPPORTED;\r
435 }\r
436\r
7ba905c9 437 VariableStoreHeader = (VARIABLE_STORE_HEADER *) (VariableBase + \\r
438 ((EFI_FIRMWARE_VOLUME_HEADER *) (VariableBase)) -> HeaderLength);\r
439\r
440 if (GetVariableStoreStatus (VariableStoreHeader) != EfiValid) {\r
441 return EFI_UNSUPPORTED;\r
442 }\r
443\r
444 if (~VariableStoreHeader->Size == 0) {\r
445 return EFI_NOT_FOUND;\r
446 }\r
447 //\r
448 // Find the variable by walk through non-volatile variable store\r
449 //\r
130e2569 450 IndexTable->StartPtr = GetStartPointer (VariableStoreHeader);\r
451 IndexTable->EndPtr = GetEndPointer (VariableStoreHeader);\r
7ba905c9 452\r
453 //\r
454 // Start Pointers for the variable.\r
455 // Actual Data Pointer where data can be written.\r
456 //\r
457 Variable = IndexTable->StartPtr;\r
458 }\r
459 }\r
460 //\r
461 // Find the variable by walk through non-volatile variable store\r
462 //\r
463 PtrTrack->StartPtr = IndexTable->StartPtr;\r
464 PtrTrack->EndPtr = IndexTable->EndPtr;\r
465\r
466 while (IsValidVariableHeader (Variable) && (Variable <= IndexTable->EndPtr)) {\r
467 if (Variable->State == VAR_ADDED) {\r
468 //\r
469 // Record Variable in VariableIndex HOB\r
470 //\r
471 if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME)\r
472 {\r
473 VariableIndexTableUpdate (IndexTable, Variable);\r
474 }\r
475\r
476 if (CompareWithValidVariable (Variable, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
477 return EFI_SUCCESS;\r
478 }\r
479 }\r
480\r
481 Variable = GetNextVariablePtr (Variable);\r
482 }\r
483 //\r
484 // If gone through the VariableStore, that means we never find in Firmware any more.\r
485 //\r
486 if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) {\r
487 IndexTable->GoneThrough = 1;\r
488 }\r
489\r
490 PtrTrack->CurrPtr = NULL;\r
491\r
492 return EFI_NOT_FOUND;\r
493}\r
494\r
bcd70414 495/**\r
7ba905c9 496 Provide the read variable functionality of the variable services.\r
497\r
bcd70414 498 @param PeiServices - General purpose services available to every PEIM.\r
7ba905c9 499\r
bcd70414 500 @param VariableName - The variable name\r
7ba905c9 501\r
bcd70414 502 @param VendorGuid - The vendor's GUID\r
7ba905c9 503\r
bcd70414 504 @param Attributes - Pointer to the attribute\r
7ba905c9 505\r
bcd70414 506 @param DataSize - Size of data\r
7ba905c9 507\r
bcd70414 508 @param Data - Pointer to data\r
7ba905c9 509\r
bcd70414 510 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 511\r
bcd70414 512 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 513\r
bcd70414 514 @retval EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough\r
7ba905c9 515\r
bcd70414 516**/\r
517EFI_STATUS\r
518EFIAPI\r
519PeiGetVariable (\r
520 IN EFI_PEI_SERVICES **PeiServices,\r
521 IN CHAR16 *VariableName,\r
522 IN EFI_GUID * VendorGuid,\r
523 OUT UINT32 *Attributes OPTIONAL,\r
524 IN OUT UINTN *DataSize,\r
525 OUT VOID *Data\r
526 )\r
7ba905c9 527\r
7ba905c9 528{\r
529 VARIABLE_POINTER_TRACK Variable;\r
530 UINTN VarDataSize;\r
531 EFI_STATUS Status;\r
532\r
de631489 533 if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
7ba905c9 534 return EFI_INVALID_PARAMETER;\r
535 }\r
536 //\r
537 // Find existing variable\r
538 //\r
539 Status = FindVariable (PeiServices, VariableName, VendorGuid, &Variable);\r
540\r
541 if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
542 return Status;\r
543 }\r
544 //\r
545 // Get data size\r
546 //\r
130e2569 547 VarDataSize = DataSizeOfVariable (Variable.CurrPtr);\r
7ba905c9 548 if (*DataSize >= VarDataSize) {\r
fd431a9b 549 //\r
550 // PO-TKW: Address one checking in this place\r
551 //\r
552 if (Data == NULL) {\r
553 return EFI_INVALID_PARAMETER;\r
554 }\r
555\r
130e2569 556 (*PeiServices)->CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
7ba905c9 557\r
558 if (Attributes != NULL) {\r
559 *Attributes = Variable.CurrPtr->Attributes;\r
560 }\r
561\r
562 *DataSize = VarDataSize;\r
563 return EFI_SUCCESS;\r
564 } else {\r
565 *DataSize = VarDataSize;\r
566 return EFI_BUFFER_TOO_SMALL;\r
567 }\r
568}\r
569\r
bcd70414 570/**\r
7ba905c9 571 Provide the read variable functionality of the variable services.\r
572\r
bcd70414 573 @param PeiServices - General purpose services available to every PEIM.\r
7ba905c9 574\r
bcd70414 575 @param VariableName - The variable name\r
7ba905c9 576\r
bcd70414 577 @param VendorGuid - The vendor's GUID\r
7ba905c9 578\r
bcd70414 579 @param Attributes - Pointer to the attribute\r
7ba905c9 580\r
bcd70414 581 @param DataSize - Size of data\r
7ba905c9 582\r
bcd70414 583 @param Data - Pointer to data\r
7ba905c9 584\r
bcd70414 585 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 586\r
bcd70414 587 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 588\r
bcd70414 589 @retval EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough\r
7ba905c9 590\r
bcd70414 591**/\r
592EFI_STATUS\r
593EFIAPI\r
594PeiGetVariable2 (\r
595 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
596 IN CONST CHAR16 *VariableName,\r
597 IN CONST EFI_GUID *VariableGuid,\r
598 OUT UINT32 *Attributes,\r
599 IN OUT UINTN *DataSize,\r
600 OUT VOID *Data\r
601 )\r
7ba905c9 602\r
7ba905c9 603{\r
604 return PeiGetVariable (\r
1b641bb8 605 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
7ba905c9 606 (CHAR16*)VariableName,\r
607 (EFI_GUID*)VariableGuid,\r
608 Attributes,\r
609 DataSize,\r
610 Data\r
611 );\r
612}\r
613\r
bcd70414 614/**\r
7ba905c9 615 Provide the get next variable functionality of the variable services.\r
616\r
bcd70414 617 @param PeiServices - General purpose services available to every PEIM.\r
618 @param VariabvleNameSize - The variable name's size.\r
619 @param VariableName - A pointer to the variable's name.\r
620 @param VendorGuid - A pointer to the EFI_GUID structure.\r
7ba905c9 621\r
bcd70414 622 @param VariableNameSize - Size of the variable name\r
7ba905c9 623\r
bcd70414 624 @param VariableName - The variable name\r
7ba905c9 625\r
bcd70414 626 @param VendorGuid - The vendor's GUID\r
7ba905c9 627\r
bcd70414 628 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 629\r
bcd70414 630 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 631\r
bcd70414 632**/\r
633EFI_STATUS\r
634EFIAPI\r
635PeiGetNextVariableName (\r
636 IN EFI_PEI_SERVICES **PeiServices,\r
637 IN OUT UINTN *VariableNameSize,\r
638 IN OUT CHAR16 *VariableName,\r
639 IN OUT EFI_GUID *VendorGuid\r
640 )\r
7ba905c9 641\r
7ba905c9 642{\r
643 VARIABLE_POINTER_TRACK Variable;\r
644 UINTN VarNameSize;\r
645 EFI_STATUS Status;\r
646\r
de631489 647 if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
7ba905c9 648 return EFI_INVALID_PARAMETER;\r
649 }\r
650\r
651 Status = FindVariable (PeiServices, VariableName, VendorGuid, &Variable);\r
652\r
653 if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
654 return Status;\r
655 }\r
656\r
657 if (VariableName[0] != 0) {\r
658 //\r
659 // If variable name is not NULL, get next variable\r
660 //\r
661 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
662 }\r
663\r
664 while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) {\r
665 if (IsValidVariableHeader (Variable.CurrPtr)) {\r
666 if (Variable.CurrPtr->State == VAR_ADDED) {\r
130e2569 667 ASSERT (NameSizeOfVariable (Variable.CurrPtr) != 0);\r
9cad030b 668\r
130e2569 669 VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr);\r
7ba905c9 670 if (VarNameSize <= *VariableNameSize) {\r
130e2569 671 (*PeiServices)->CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize);\r
7ba905c9 672\r
673 (*PeiServices)->CopyMem (VendorGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));\r
674\r
675 Status = EFI_SUCCESS;\r
676 } else {\r
677 Status = EFI_BUFFER_TOO_SMALL;\r
678 }\r
679\r
680 *VariableNameSize = VarNameSize;\r
681 return Status;\r
682 //\r
683 // Variable is found\r
684 //\r
685 } else {\r
686 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
687 }\r
688 } else {\r
689 break;\r
690 }\r
691 }\r
692\r
693 return EFI_NOT_FOUND;\r
694}\r
695\r
bcd70414 696/**\r
7ba905c9 697 Provide the get next variable functionality of the variable services.\r
698\r
bcd70414 699 @param PeiServices - General purpose services available to every PEIM.\r
700 @param VariabvleNameSize - The variable name's size.\r
701 @param VariableName - A pointer to the variable's name.\r
702 @param VariableGuid - A pointer to the EFI_GUID structure.\r
7ba905c9 703\r
bcd70414 704 @param VariableNameSize - Size of the variable name\r
7ba905c9 705\r
bcd70414 706 @param VariableName - The variable name\r
7ba905c9 707\r
bcd70414 708 @param VendorGuid - The vendor's GUID\r
7ba905c9 709\r
7ba905c9 710\r
bcd70414 711 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 712\r
bcd70414 713 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 714\r
bcd70414 715**/\r
716EFI_STATUS\r
717EFIAPI\r
718PeiGetNextVariableName2 (\r
719 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
720 IN OUT UINTN *VariableNameSize,\r
721 IN OUT CHAR16 *VariableName,\r
722 IN OUT EFI_GUID *VariableGuid\r
723 )\r
7ba905c9 724\r
7ba905c9 725{\r
726 return PeiGetNextVariableName (\r
1b641bb8 727 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
7ba905c9 728 VariableNameSize,\r
729 VariableName,\r
730 VariableGuid\r
731 );\r
6bee1632 732}\r
bcd70414 733\r