]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/VariablePei/Variable.c
As variable area is not reliable in recovery path, then we should not produce Readonl...
[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
280 if (VarStoreHeader->Signature == VARIABLE_STORE_SIGNATURE &&\r
281 VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&\r
282 VarStoreHeader->State == VARIABLE_STORE_HEALTHY\r
283 ) {\r
284\r
285 return EfiValid;\r
286 }\r
287\r
288 if (VarStoreHeader->Signature == 0xffffffff &&\r
289 VarStoreHeader->Size == 0xffffffff &&\r
290 VarStoreHeader->Format == 0xff &&\r
291 VarStoreHeader->State == 0xff\r
292 ) {\r
293\r
294 return EfiRaw;\r
295 } else {\r
296 return EfiInvalid;\r
297 }\r
298}\r
299\r
bcd70414 300/**\r
301 This function compares a variable with variable entries in database\r
302\r
303 @param Variable - Pointer to the variable in our database\r
304 @param VariableName - Name of the variable to compare to 'Variable'\r
305 @param VendorGuid - GUID of the variable to compare to 'Variable'\r
306 @param PtrTrack - Variable Track Pointer structure that contains\r
307 Variable Information.\r
308\r
fdb05fa3 309 @retval EFI_SUCCESS - Found match variable\r
bcd70414 310 @retval EFI_NOT_FOUND - Variable not found\r
311\r
312**/\r
7ba905c9 313EFI_STATUS\r
314CompareWithValidVariable (\r
315 IN VARIABLE_HEADER *Variable,\r
316 IN CONST CHAR16 *VariableName,\r
317 IN CONST EFI_GUID *VendorGuid,\r
318 OUT VARIABLE_POINTER_TRACK *PtrTrack\r
319 )\r
7ba905c9 320\r
7ba905c9 321{\r
130e2569 322 VOID *Point;\r
323\r
7ba905c9 324 if (VariableName[0] == 0) {\r
325 PtrTrack->CurrPtr = Variable;\r
326 return EFI_SUCCESS;\r
327 } else {\r
328 //\r
329 // Don't use CompareGuid function here for performance reasons.\r
330 // Instead we compare the GUID a UINT32 at a time and branch\r
331 // on the first failed comparison.\r
332 //\r
333 if ((((INT32 *) VendorGuid)[0] == ((INT32 *) &Variable->VendorGuid)[0]) &&\r
334 (((INT32 *) VendorGuid)[1] == ((INT32 *) &Variable->VendorGuid)[1]) &&\r
335 (((INT32 *) VendorGuid)[2] == ((INT32 *) &Variable->VendorGuid)[2]) &&\r
336 (((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3])\r
337 ) {\r
130e2569 338 ASSERT (NameSizeOfVariable (Variable) != 0);\r
339 Point = (VOID *) GetVariableNamePtr (Variable);\r
340 if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable))) {\r
7ba905c9 341 PtrTrack->CurrPtr = Variable;\r
342 return EFI_SUCCESS;\r
343 }\r
344 }\r
345 }\r
346\r
347 return EFI_NOT_FOUND;\r
348}\r
349\r
bcd70414 350/**\r
351 This code finds variable in storage blocks (Non-Volatile)\r
352\r
353 @param PeiServices - General purpose services available to every PEIM.\r
354 @param VariableName - Name of the variable to be found\r
355 @param VendorGuid - Vendor GUID to be found.\r
356 @param PtrTrack - Variable Track Pointer structure that contains\r
357 Variable Information.\r
358\r
359 @retval EFI_SUCCESS - Variable found successfully\r
360 @retval EFI_NOT_FOUND - Variable not found\r
361 @retval EFI_INVALID_PARAMETER - Invalid variable name\r
362\r
363**/\r
7ba905c9 364EFI_STATUS\r
365EFIAPI\r
366FindVariable (\r
1b641bb8 367 IN EFI_PEI_SERVICES **PeiServices,\r
7ba905c9 368 IN CONST CHAR16 *VariableName,\r
369 IN CONST EFI_GUID *VendorGuid,\r
370 OUT VARIABLE_POINTER_TRACK *PtrTrack\r
371 )\r
7ba905c9 372\r
7ba905c9 373{\r
374 EFI_HOB_GUID_TYPE *GuidHob;\r
375 VARIABLE_STORE_HEADER *VariableStoreHeader;\r
376 VARIABLE_HEADER *Variable;\r
377 VARIABLE_HEADER *MaxIndex;\r
378 VARIABLE_INDEX_TABLE *IndexTable;\r
379 UINT32 Count;\r
380 UINT8 *VariableBase;\r
381\r
382 if (VariableName != 0 && VendorGuid == NULL) {\r
383 return EFI_INVALID_PARAMETER;\r
384 }\r
385 //\r
386 // No Variable Address equals zero, so 0 as initial value is safe.\r
387 //\r
388 MaxIndex = 0;\r
389\r
390 GuidHob = GetFirstGuidHob (&mEfiVariableIndexTableGuid);\r
391 if (GuidHob == NULL) {\r
392 IndexTable = BuildGuidHob (&mEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));\r
393 IndexTable->Length = 0;\r
394 IndexTable->StartPtr = NULL;\r
395 IndexTable->EndPtr = NULL;\r
396 IndexTable->GoneThrough = 0;\r
397 } else {\r
398 IndexTable = GET_GUID_HOB_DATA (GuidHob);\r
399 for (Count = 0; Count < IndexTable->Length; Count++)\r
400 {\r
401 MaxIndex = GetVariableByIndex (IndexTable, Count);\r
130e2569 402\r
7ba905c9 403 if (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
404 PtrTrack->StartPtr = IndexTable->StartPtr;\r
405 PtrTrack->EndPtr = IndexTable->EndPtr;\r
406\r
407 return EFI_SUCCESS;\r
408 }\r
409 }\r
410\r
411 if (IndexTable->GoneThrough) {\r
412 return EFI_NOT_FOUND;\r
413 }\r
414 }\r
415 //\r
416 // If not found in HOB, then let's start from the MaxIndex we've found.\r
417 //\r
418 if (MaxIndex != NULL) {\r
419 Variable = GetNextVariablePtr (MaxIndex);\r
420 } else {\r
421 if (IndexTable->StartPtr || IndexTable->EndPtr) {\r
422 Variable = IndexTable->StartPtr;\r
423 } else {\r
424 VariableBase = (UINT8 *) (UINTN) PcdGet32 (PcdFlashNvStorageVariableBase);\r
425 VariableStoreHeader = (VARIABLE_STORE_HEADER *) (VariableBase + \\r
426 ((EFI_FIRMWARE_VOLUME_HEADER *) (VariableBase)) -> HeaderLength);\r
427\r
428 if (GetVariableStoreStatus (VariableStoreHeader) != EfiValid) {\r
429 return EFI_UNSUPPORTED;\r
430 }\r
431\r
432 if (~VariableStoreHeader->Size == 0) {\r
433 return EFI_NOT_FOUND;\r
434 }\r
435 //\r
436 // Find the variable by walk through non-volatile variable store\r
437 //\r
130e2569 438 IndexTable->StartPtr = GetStartPointer (VariableStoreHeader);\r
439 IndexTable->EndPtr = GetEndPointer (VariableStoreHeader);\r
7ba905c9 440\r
441 //\r
442 // Start Pointers for the variable.\r
443 // Actual Data Pointer where data can be written.\r
444 //\r
445 Variable = IndexTable->StartPtr;\r
446 }\r
447 }\r
448 //\r
449 // Find the variable by walk through non-volatile variable store\r
450 //\r
451 PtrTrack->StartPtr = IndexTable->StartPtr;\r
452 PtrTrack->EndPtr = IndexTable->EndPtr;\r
453\r
454 while (IsValidVariableHeader (Variable) && (Variable <= IndexTable->EndPtr)) {\r
455 if (Variable->State == VAR_ADDED) {\r
456 //\r
457 // Record Variable in VariableIndex HOB\r
458 //\r
459 if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME)\r
460 {\r
461 VariableIndexTableUpdate (IndexTable, Variable);\r
462 }\r
463\r
464 if (CompareWithValidVariable (Variable, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
465 return EFI_SUCCESS;\r
466 }\r
467 }\r
468\r
469 Variable = GetNextVariablePtr (Variable);\r
470 }\r
471 //\r
472 // If gone through the VariableStore, that means we never find in Firmware any more.\r
473 //\r
474 if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) {\r
475 IndexTable->GoneThrough = 1;\r
476 }\r
477\r
478 PtrTrack->CurrPtr = NULL;\r
479\r
480 return EFI_NOT_FOUND;\r
481}\r
482\r
bcd70414 483/**\r
7ba905c9 484 Provide the read variable functionality of the variable services.\r
485\r
bcd70414 486 @param PeiServices - General purpose services available to every PEIM.\r
7ba905c9 487\r
bcd70414 488 @param VariableName - The variable name\r
7ba905c9 489\r
bcd70414 490 @param VendorGuid - The vendor's GUID\r
7ba905c9 491\r
bcd70414 492 @param Attributes - Pointer to the attribute\r
7ba905c9 493\r
bcd70414 494 @param DataSize - Size of data\r
7ba905c9 495\r
bcd70414 496 @param Data - Pointer to data\r
7ba905c9 497\r
bcd70414 498 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 499\r
bcd70414 500 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 501\r
bcd70414 502 @retval EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough\r
7ba905c9 503\r
bcd70414 504**/\r
505EFI_STATUS\r
506EFIAPI\r
507PeiGetVariable (\r
508 IN EFI_PEI_SERVICES **PeiServices,\r
509 IN CHAR16 *VariableName,\r
510 IN EFI_GUID * VendorGuid,\r
511 OUT UINT32 *Attributes OPTIONAL,\r
512 IN OUT UINTN *DataSize,\r
513 OUT VOID *Data\r
514 )\r
7ba905c9 515\r
7ba905c9 516{\r
517 VARIABLE_POINTER_TRACK Variable;\r
518 UINTN VarDataSize;\r
519 EFI_STATUS Status;\r
520\r
de631489 521 if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
7ba905c9 522 return EFI_INVALID_PARAMETER;\r
523 }\r
524 //\r
525 // Find existing variable\r
526 //\r
527 Status = FindVariable (PeiServices, VariableName, VendorGuid, &Variable);\r
528\r
529 if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
530 return Status;\r
531 }\r
532 //\r
533 // Get data size\r
534 //\r
130e2569 535 VarDataSize = DataSizeOfVariable (Variable.CurrPtr);\r
7ba905c9 536 if (*DataSize >= VarDataSize) {\r
fd431a9b 537 //\r
538 // PO-TKW: Address one checking in this place\r
539 //\r
540 if (Data == NULL) {\r
541 return EFI_INVALID_PARAMETER;\r
542 }\r
543\r
130e2569 544 (*PeiServices)->CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
7ba905c9 545\r
546 if (Attributes != NULL) {\r
547 *Attributes = Variable.CurrPtr->Attributes;\r
548 }\r
549\r
550 *DataSize = VarDataSize;\r
551 return EFI_SUCCESS;\r
552 } else {\r
553 *DataSize = VarDataSize;\r
554 return EFI_BUFFER_TOO_SMALL;\r
555 }\r
556}\r
557\r
bcd70414 558/**\r
7ba905c9 559 Provide the read variable functionality of the variable services.\r
560\r
bcd70414 561 @param PeiServices - General purpose services available to every PEIM.\r
7ba905c9 562\r
bcd70414 563 @param VariableName - The variable name\r
7ba905c9 564\r
bcd70414 565 @param VendorGuid - The vendor's GUID\r
7ba905c9 566\r
bcd70414 567 @param Attributes - Pointer to the attribute\r
7ba905c9 568\r
bcd70414 569 @param DataSize - Size of data\r
7ba905c9 570\r
bcd70414 571 @param Data - Pointer to data\r
7ba905c9 572\r
bcd70414 573 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 574\r
bcd70414 575 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 576\r
bcd70414 577 @retval EFI_BUFFER_TOO_SMALL - The caller buffer is not large enough\r
7ba905c9 578\r
bcd70414 579**/\r
580EFI_STATUS\r
581EFIAPI\r
582PeiGetVariable2 (\r
583 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
584 IN CONST CHAR16 *VariableName,\r
585 IN CONST EFI_GUID *VariableGuid,\r
586 OUT UINT32 *Attributes,\r
587 IN OUT UINTN *DataSize,\r
588 OUT VOID *Data\r
589 )\r
7ba905c9 590\r
7ba905c9 591{\r
592 return PeiGetVariable (\r
1b641bb8 593 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
7ba905c9 594 (CHAR16*)VariableName,\r
595 (EFI_GUID*)VariableGuid,\r
596 Attributes,\r
597 DataSize,\r
598 Data\r
599 );\r
600}\r
601\r
bcd70414 602/**\r
7ba905c9 603 Provide the get next variable functionality of the variable services.\r
604\r
bcd70414 605 @param PeiServices - General purpose services available to every PEIM.\r
606 @param VariabvleNameSize - The variable name's size.\r
607 @param VariableName - A pointer to the variable's name.\r
608 @param VendorGuid - A pointer to the EFI_GUID structure.\r
7ba905c9 609\r
bcd70414 610 @param VariableNameSize - Size of the variable name\r
7ba905c9 611\r
bcd70414 612 @param VariableName - The variable name\r
7ba905c9 613\r
bcd70414 614 @param VendorGuid - The vendor's GUID\r
7ba905c9 615\r
bcd70414 616 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 617\r
bcd70414 618 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 619\r
bcd70414 620**/\r
621EFI_STATUS\r
622EFIAPI\r
623PeiGetNextVariableName (\r
624 IN EFI_PEI_SERVICES **PeiServices,\r
625 IN OUT UINTN *VariableNameSize,\r
626 IN OUT CHAR16 *VariableName,\r
627 IN OUT EFI_GUID *VendorGuid\r
628 )\r
7ba905c9 629\r
7ba905c9 630{\r
631 VARIABLE_POINTER_TRACK Variable;\r
632 UINTN VarNameSize;\r
633 EFI_STATUS Status;\r
634\r
de631489 635 if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
7ba905c9 636 return EFI_INVALID_PARAMETER;\r
637 }\r
638\r
639 Status = FindVariable (PeiServices, VariableName, VendorGuid, &Variable);\r
640\r
641 if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
642 return Status;\r
643 }\r
644\r
645 if (VariableName[0] != 0) {\r
646 //\r
647 // If variable name is not NULL, get next variable\r
648 //\r
649 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
650 }\r
651\r
652 while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) {\r
653 if (IsValidVariableHeader (Variable.CurrPtr)) {\r
654 if (Variable.CurrPtr->State == VAR_ADDED) {\r
130e2569 655 ASSERT (NameSizeOfVariable (Variable.CurrPtr) != 0);\r
9cad030b 656\r
130e2569 657 VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr);\r
7ba905c9 658 if (VarNameSize <= *VariableNameSize) {\r
130e2569 659 (*PeiServices)->CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize);\r
7ba905c9 660\r
661 (*PeiServices)->CopyMem (VendorGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));\r
662\r
663 Status = EFI_SUCCESS;\r
664 } else {\r
665 Status = EFI_BUFFER_TOO_SMALL;\r
666 }\r
667\r
668 *VariableNameSize = VarNameSize;\r
669 return Status;\r
670 //\r
671 // Variable is found\r
672 //\r
673 } else {\r
674 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
675 }\r
676 } else {\r
677 break;\r
678 }\r
679 }\r
680\r
681 return EFI_NOT_FOUND;\r
682}\r
683\r
bcd70414 684/**\r
7ba905c9 685 Provide the get next variable functionality of the variable services.\r
686\r
bcd70414 687 @param PeiServices - General purpose services available to every PEIM.\r
688 @param VariabvleNameSize - The variable name's size.\r
689 @param VariableName - A pointer to the variable's name.\r
690 @param VariableGuid - A pointer to the EFI_GUID structure.\r
7ba905c9 691\r
bcd70414 692 @param VariableNameSize - Size of the variable name\r
7ba905c9 693\r
bcd70414 694 @param VariableName - The variable name\r
7ba905c9 695\r
bcd70414 696 @param VendorGuid - The vendor's GUID\r
7ba905c9 697\r
7ba905c9 698\r
bcd70414 699 @retval EFI_SUCCESS - The interface could be successfully installed\r
7ba905c9 700\r
bcd70414 701 @retval EFI_NOT_FOUND - The variable could not be discovered\r
7ba905c9 702\r
bcd70414 703**/\r
704EFI_STATUS\r
705EFIAPI\r
706PeiGetNextVariableName2 (\r
707 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
708 IN OUT UINTN *VariableNameSize,\r
709 IN OUT CHAR16 *VariableName,\r
710 IN OUT EFI_GUID *VariableGuid\r
711 )\r
7ba905c9 712\r
7ba905c9 713{\r
714 return PeiGetNextVariableName (\r
1b641bb8 715 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
7ba905c9 716 VariableNameSize,\r
717 VariableName,\r
718 VariableGuid\r
719 );\r
6bee1632 720}\r
bcd70414 721\r