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