]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/PCD/Pei/Pcd.c
MdeModulePkg HiiDataBase: Enable Firmware to retrieve the default setting
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Pei / Pcd.c
CommitLineData
fc547e08 1/** @file \r
5944a83b 2 All Pcd Ppi services are implemented here.\r
fc547e08 3 \r
2db48a1f 4Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
bfb4c2ba
CS
5(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
80408db0 13\r
80408db0 14**/\r
15\r
80408db0 16#include "Service.h"\r
17\r
17e7fa8f 18///\r
19/// Instance of PCD_PPI protocol is EDKII native implementation.\r
20/// This protocol instance support dynamic and dynamicEx type PCDs.\r
21///\r
80408db0 22PCD_PPI mPcdPpiInstance = {\r
23 PeiPcdSetSku,\r
24\r
25 PeiPcdGet8,\r
26 PeiPcdGet16, \r
27 PeiPcdGet32, \r
28 PeiPcdGet64, \r
29 PeiPcdGetPtr, \r
30 PeiPcdGetBool, \r
31 PeiPcdGetSize,\r
32\r
33 PeiPcdGet8Ex,\r
34 PeiPcdGet16Ex, \r
35 PeiPcdGet32Ex, \r
36 PeiPcdGet64Ex, \r
37 PeiPcdGetPtrEx, \r
38 PeiPcdGetBoolEx, \r
39 PeiPcdGetSizeEx,\r
40 \r
41 PeiPcdSet8,\r
42 PeiPcdSet16, \r
43 PeiPcdSet32, \r
44 PeiPcdSet64, \r
45 PeiPcdSetPtr, \r
46 PeiPcdSetBool, \r
47\r
48 PeiPcdSet8Ex,\r
49 PeiPcdSet16Ex, \r
50 PeiPcdSet32Ex, \r
51 PeiPcdSet64Ex, \r
52 PeiPcdSetPtrEx, \r
53 PeiPcdSetBoolEx,\r
54\r
55 PeiRegisterCallBackOnSet,\r
56 PcdUnRegisterCallBackOnSet,\r
57 PeiPcdGetNextToken,\r
58 PeiPcdGetNextTokenSpace\r
59};\r
60\r
17e7fa8f 61///\r
62/// Instance of EFI_PEI_PCD_PPI which is defined in PI 1.2 Vol 3.\r
63/// This PPI instance only support dyanmicEx type PCD.\r
64///\r
c896d682 65EFI_PEI_PCD_PPI mEfiPcdPpiInstance = {\r
66 PeiPcdSetSku,\r
67 \r
68 PeiPcdGet8Ex,\r
69 PeiPcdGet16Ex,\r
70 PeiPcdGet32Ex,\r
71 PeiPcdGet64Ex,\r
72 PeiPcdGetPtrEx,\r
73 PeiPcdGetBoolEx,\r
74 PeiPcdGetSizeEx,\r
75 PeiPcdSet8Ex,\r
76 PeiPcdSet16Ex,\r
77 PeiPcdSet32Ex,\r
78 PeiPcdSet64Ex,\r
79 PeiPcdSetPtrEx,\r
80 PeiPcdSetBoolEx,\r
81 (EFI_PEI_PCD_PPI_CALLBACK_ON_SET) PeiRegisterCallBackOnSet,\r
82 (EFI_PEI_PCD_PPI_CANCEL_CALLBACK) PcdUnRegisterCallBackOnSet,\r
83 PeiPcdGetNextToken,\r
84 PeiPcdGetNextTokenSpace\r
85};\r
86\r
96d6d004
SZ
87///\r
88/// Instance of GET_PCD_INFO_PPI protocol is EDKII native implementation.\r
89/// This protocol instance support dynamic and dynamicEx type PCDs.\r
90///\r
91GET_PCD_INFO_PPI mGetPcdInfoInstance = {\r
92 PeiGetPcdInfoGetInfo,\r
93 PeiGetPcdInfoGetInfoEx,\r
94 PeiGetPcdInfoGetSku\r
95};\r
96\r
97///\r
98/// Instance of EFI_GET_PCD_INFO_PPI which is defined in PI 1.2.1 Vol 3.\r
99/// This PPI instance only support dyanmicEx type PCD.\r
100///\r
101EFI_GET_PCD_INFO_PPI mEfiGetPcdInfoInstance = {\r
102 PeiGetPcdInfoGetInfoEx,\r
103 PeiGetPcdInfoGetSku\r
104};\r
105\r
17e7fa8f 106EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {\r
107 {\r
108 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
109 &gPcdPpiGuid,\r
110 &mPcdPpiInstance\r
111 },\r
112 {\r
113 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
114 &gEfiPeiPcdPpiGuid,\r
115 &mEfiPcdPpiInstance\r
116 }\r
c896d682 117};\r
118\r
96d6d004
SZ
119EFI_PEI_PPI_DESCRIPTOR mPpiList2[] = {\r
120 {\r
121 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
122 &gGetPcdInfoPpiGuid,\r
123 &mGetPcdInfoInstance\r
124 },\r
125 {\r
126 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
127 &gEfiGetPcdInfoPpiGuid,\r
128 &mEfiGetPcdInfoInstance\r
129 }\r
130};\r
131\r
fc547e08 132/**\r
133 Main entry for PCD PEIM driver.\r
134 \r
8a541f0a 135 This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.\r
80408db0 136\r
8bd22b8a
LG
137 @param FileHandle Handle of the file being invoked.\r
138 @param PeiServices Describes the list of possible PEI Services.\r
80408db0 139\r
fc547e08 140 @return Status of install PCD_PPI\r
141\r
142**/\r
80408db0 143EFI_STATUS\r
144EFIAPI\r
145PcdPeimInit (\r
8bd22b8a
LG
146 IN EFI_PEI_FILE_HANDLE FileHandle,\r
147 IN CONST EFI_PEI_SERVICES **PeiServices\r
80408db0 148 )\r
149{\r
a78d3a27 150 EFI_STATUS Status;\r
96d6d004 151\r
a78d3a27 152 BuildPcdDatabase (FileHandle);\r
80408db0 153\r
8a541f0a 154 //\r
17e7fa8f 155 // Install PCD_PPI and EFI_PEI_PCD_PPI.\r
8a541f0a 156 //\r
17e7fa8f 157 Status = PeiServicesInstallPpi (&mPpiList[0]);\r
8a541f0a 158 ASSERT_EFI_ERROR (Status);\r
96d6d004
SZ
159\r
160 //\r
85d0b97d 161 // Install GET_PCD_INFO_PPI and EFI_GET_PCD_INFO_PPI.\r
96d6d004 162 //\r
85d0b97d
SZ
163 Status = PeiServicesInstallPpi (&mPpiList2[0]);\r
164 ASSERT_EFI_ERROR (Status);\r
96d6d004 165\r
8a541f0a 166 return Status;\r
80408db0 167}\r
168\r
96d6d004
SZ
169/**\r
170 Retrieve additional information associated with a PCD token in the default token space.\r
171\r
172 This includes information such as the type of value the TokenNumber is associated with as well as possible\r
173 human readable name that is associated with the token.\r
174\r
175 @param[in] TokenNumber The PCD token number.\r
176 @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
177 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
178\r
179 @retval EFI_SUCCESS The PCD information was returned successfully.\r
180 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
181**/\r
182EFI_STATUS\r
183EFIAPI\r
184PeiGetPcdInfoGetInfo (\r
185 IN UINTN TokenNumber,\r
186 OUT EFI_PCD_INFO *PcdInfo\r
187 )\r
188{\r
189 return PeiGetPcdInfo (NULL, TokenNumber, PcdInfo);\r
190}\r
191\r
192/**\r
193 Retrieve additional information associated with a PCD token.\r
194\r
195 This includes information such as the type of value the TokenNumber is associated with as well as possible\r
196 human readable name that is associated with the token.\r
197\r
198 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
199 @param[in] TokenNumber The PCD token number.\r
200 @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r
201 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
202\r
203 @retval EFI_SUCCESS The PCD information was returned successfully.\r
204 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
205**/\r
206EFI_STATUS\r
207EFIAPI\r
208PeiGetPcdInfoGetInfoEx (\r
209 IN CONST EFI_GUID *Guid,\r
210 IN UINTN TokenNumber,\r
211 OUT EFI_PCD_INFO *PcdInfo\r
212 )\r
213{\r
214 return PeiGetPcdInfo (Guid, TokenNumber, PcdInfo);\r
215}\r
216\r
217/**\r
218 Retrieve the currently set SKU Id.\r
219\r
220 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the\r
221 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU\r
222 Id is returned.\r
223**/\r
224UINTN\r
225EFIAPI\r
226PeiGetPcdInfoGetSku (\r
227 VOID\r
228 )\r
229{\r
b6e89910 230 return (UINTN) GetPcdDatabase()->SystemSkuId;\r
96d6d004
SZ
231}\r
232\r
fc547e08 233/**\r
234 Sets the SKU value for subsequent calls to set or get PCD token values.\r
235\r
236 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values. \r
237 SetSku() is normally called only once by the system.\r
238\r
239 For each item (token), the database can hold a single value that applies to all SKUs, \r
240 or multiple values, where each value is associated with a specific SKU Id. Items with multiple, \r
241 SKU-specific values are called SKU enabled. \r
242 \r
120ca3ce 243 The SKU Id of zero is reserved as a default.\r
fc547e08 244 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the \r
245 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the \r
246 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token, \r
247 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been \r
248 set for that Id, the results are unpredictable.\r
249\r
250 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and \r
251 set values associated with a PCD token.\r
252\r
fc547e08 253**/\r
80408db0 254VOID\r
255EFIAPI\r
256PeiPcdSetSku (\r
257 IN UINTN SkuId\r
258 )\r
259{\r
85d0b97d
SZ
260 PEI_PCD_DATABASE *PeiPcdDb;\r
261 SKU_ID *SkuIdTable;\r
262 UINTN Index;\r
263\r
264 PeiPcdDb = GetPcdDatabase();\r
2db48a1f
SZ
265\r
266 if (SkuId == PeiPcdDb->SystemSkuId) {\r
267 //\r
268 // The input SKU Id is equal to current SKU Id, return directly.\r
269 //\r
270 return;\r
271 }\r
272\r
273 if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {\r
274 DEBUG ((DEBUG_ERROR, "PcdPei - The SKU Id could be changed only once."));\r
275 DEBUG ((\r
276 DEBUG_ERROR,\r
277 "PcdPei - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",\r
278 PeiPcdDb->SystemSkuId,\r
279 (SKU_ID) SkuId\r
280 ));\r
281 ASSERT (FALSE);\r
282 return;\r
283 }\r
284\r
85d0b97d
SZ
285 SkuIdTable = (SKU_ID *) ((UINT8 *) PeiPcdDb + PeiPcdDb->SkuIdTableOffset);\r
286 for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
287 if (SkuId == SkuIdTable[Index + 1]) {\r
2db48a1f 288 DEBUG ((EFI_D_INFO, "PcdPei - Set current SKU Id to 0x%lx.\n", (SKU_ID) SkuId));\r
85d0b97d
SZ
289 PeiPcdDb->SystemSkuId = (SKU_ID) SkuId;\r
290 return;\r
291 }\r
292 }\r
80408db0 293\r
85d0b97d 294 //\r
2db48a1f 295 // Invalid input SkuId, the default SKU Id will be still used for the system.\r
85d0b97d 296 //\r
2db48a1f 297 DEBUG ((EFI_D_INFO, "PcdPei - Invalid input SkuId, the default SKU Id will be still used.\n"));\r
80408db0 298 return;\r
299}\r
300\r
fc547e08 301/**\r
302 Retrieves an 8-bit value for a given PCD token.\r
80408db0 303\r
fc547e08 304 Retrieves the current byte-sized value for a PCD token number. \r
305 If the TokenNumber is invalid, the results are unpredictable.\r
306 \r
307 @param[in] TokenNumber The PCD token number. \r
80408db0 308\r
fc547e08 309 @return The UINT8 value.\r
310 \r
311**/\r
80408db0 312UINT8\r
313EFIAPI\r
314PeiPcdGet8 (\r
315 IN UINTN TokenNumber\r
316 )\r
317{\r
318 return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
319}\r
320\r
fc547e08 321/**\r
322 Retrieves an 16-bit value for a given PCD token.\r
80408db0 323\r
fc547e08 324 Retrieves the current 16-bits value for a PCD token number. \r
325 If the TokenNumber is invalid, the results are unpredictable.\r
326 \r
327 @param[in] TokenNumber The PCD token number. \r
80408db0 328\r
fc547e08 329 @return The UINT16 value.\r
330 \r
331**/\r
80408db0 332UINT16\r
333EFIAPI\r
334PeiPcdGet16 (\r
335 IN UINTN TokenNumber\r
336 )\r
337{\r
338 return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
339}\r
340\r
fc547e08 341/**\r
342 Retrieves an 32-bit value for a given PCD token.\r
80408db0 343\r
fc547e08 344 Retrieves the current 32-bits value for a PCD token number. \r
345 If the TokenNumber is invalid, the results are unpredictable.\r
346 \r
347 @param[in] TokenNumber The PCD token number. \r
80408db0 348\r
fc547e08 349 @return The UINT32 value.\r
350 \r
351**/\r
80408db0 352UINT32\r
353EFIAPI\r
354PeiPcdGet32 (\r
355 IN UINTN TokenNumber\r
356 )\r
357{\r
358 return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
359}\r
360\r
fc547e08 361/**\r
362 Retrieves an 64-bit value for a given PCD token.\r
80408db0 363\r
fc547e08 364 Retrieves the current 64-bits value for a PCD token number. \r
365 If the TokenNumber is invalid, the results are unpredictable.\r
366 \r
367 @param[in] TokenNumber The PCD token number. \r
80408db0 368\r
fc547e08 369 @return The UINT64 value.\r
370 \r
371**/\r
80408db0 372UINT64\r
373EFIAPI\r
374PeiPcdGet64 (\r
375 IN UINTN TokenNumber\r
376 )\r
377{\r
378 return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));\r
379}\r
380\r
fc547e08 381/**\r
382 Retrieves a pointer to a value for a given PCD token.\r
383\r
384 Retrieves the current pointer to the buffer for a PCD token number. \r
385 Do not make any assumptions about the alignment of the pointer that \r
386 is returned by this function call. If the TokenNumber is invalid, \r
387 the results are unpredictable.\r
80408db0 388\r
fc547e08 389 @param[in] TokenNumber The PCD token number. \r
80408db0 390\r
3fd8027e 391 @return The pointer to the buffer to be retrieved.\r
fc547e08 392 \r
393**/\r
80408db0 394VOID *\r
395EFIAPI\r
396PeiPcdGetPtr (\r
397 IN UINTN TokenNumber\r
398 )\r
399{\r
400 return GetWorker (TokenNumber, 0);\r
401}\r
402\r
fc547e08 403/**\r
404 Retrieves a Boolean value for a given PCD token.\r
80408db0 405\r
fc547e08 406 Retrieves the current boolean value for a PCD token number. \r
407 Do not make any assumptions about the alignment of the pointer that \r
408 is returned by this function call. If the TokenNumber is invalid, \r
409 the results are unpredictable.\r
80408db0 410\r
fc547e08 411 @param[in] TokenNumber The PCD token number. \r
412\r
413 @return The Boolean value.\r
414 \r
415**/\r
80408db0 416BOOLEAN\r
417EFIAPI\r
418PeiPcdGetBool (\r
419 IN UINTN TokenNumber\r
420 )\r
421{\r
422 return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
423}\r
424\r
fc547e08 425/**\r
426 Retrieves the size of the value for a given PCD token.\r
427\r
428 Retrieves the current size of a particular PCD token. \r
429 If the TokenNumber is invalid, the results are unpredictable.\r
80408db0 430\r
fc547e08 431 @param[in] TokenNumber The PCD token number. \r
80408db0 432\r
fc547e08 433 @return The size of the value for the PCD token.\r
434 \r
435**/\r
80408db0 436UINTN\r
437EFIAPI\r
438PeiPcdGetSize (\r
439 IN UINTN TokenNumber\r
440 )\r
441{\r
442 PEI_PCD_DATABASE *PeiPcdDb;\r
443 UINTN Size;\r
444 UINTN MaxSize;\r
419db80b 445 UINT32 LocalTokenCount;\r
80408db0 446\r
419db80b
BF
447 PeiPcdDb = GetPcdDatabase ();\r
448 LocalTokenCount = PeiPcdDb->LocalTokenCount;\r
80408db0 449 //\r
450 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r
451 // We have to decrement TokenNumber by 1 to make it usable\r
452 // as the array index.\r
453 //\r
454 TokenNumber--;\r
455\r
456 // EBC compiler is very choosy. It may report warning about comparison\r
457 // between UINTN and 0 . So we add 1 in each size of the \r
458 // comparison.\r
419db80b 459 ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));\r
80408db0 460\r
419db80b 461 Size = (*((UINT32 *)((UINT8 *)PeiPcdDb + PeiPcdDb->LocalTokenNumberTableOffset) + TokenNumber) & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r
80408db0 462\r
463 if (Size == 0) {\r
464 //\r
465 // For pointer type, we need to scan the SIZE_TABLE to get the current size.\r
466 //\r
467 return GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);\r
468 } else {\r
469 return Size;\r
470 }\r
471\r
472}\r
473\r
fc547e08 474/**\r
475 Retrieves an 8-bit value for a given PCD token.\r
80408db0 476\r
fc547e08 477 Retrieves the 8-bit value of a particular PCD token. \r
478 If the TokenNumber is invalid or the token space\r
479 specified by Guid does not exist, the results are \r
480 unpredictable.\r
80408db0 481\r
fc547e08 482 @param[in] Guid The token space for the token number.\r
483 @param[in] ExTokenNumber The PCD token number. \r
484\r
485 @return The size 8-bit value for the PCD token.\r
486 \r
487**/\r
80408db0 488UINT8\r
489EFIAPI\r
490PeiPcdGet8Ex (\r
491 IN CONST EFI_GUID *Guid,\r
492 IN UINTN ExTokenNumber\r
493 )\r
494{\r
495 return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r
496}\r
497\r
fc547e08 498/**\r
499 Retrieves an 16-bit value for a given PCD token.\r
80408db0 500\r
fc547e08 501 Retrieves the 16-bit value of a particular PCD token. \r
502 If the TokenNumber is invalid or the token space\r
503 specified by Guid does not exist, the results are \r
504 unpredictable.\r
80408db0 505\r
fc547e08 506 @param[in] Guid The token space for the token number.\r
507 @param[in] ExTokenNumber The PCD token number. \r
508\r
509 @return The size 16-bit value for the PCD token.\r
510 \r
511**/\r
80408db0 512UINT16\r
513EFIAPI\r
514PeiPcdGet16Ex (\r
515 IN CONST EFI_GUID *Guid,\r
516 IN UINTN ExTokenNumber\r
517 )\r
518{\r
519 return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));\r
520}\r
521\r
fc547e08 522/**\r
523 Retrieves an 32-bit value for a given PCD token.\r
524\r
525 Retrieves the 32-bit value of a particular PCD token. \r
526 If the TokenNumber is invalid or the token space\r
527 specified by Guid does not exist, the results are \r
528 unpredictable.\r
80408db0 529\r
fc547e08 530 @param[in] Guid The token space for the token number.\r
531 @param[in] ExTokenNumber The PCD token number. \r
80408db0 532\r
fc547e08 533 @return The size 32-bit value for the PCD token.\r
534 \r
535**/\r
80408db0 536UINT32\r
537EFIAPI\r
538PeiPcdGet32Ex (\r
539 IN CONST EFI_GUID *Guid,\r
540 IN UINTN ExTokenNumber\r
541 )\r
542{\r
543 return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));\r
544}\r
545\r
fc547e08 546/**\r
547 Retrieves an 64-bit value for a given PCD token.\r
548\r
549 Retrieves the 64-bit value of a particular PCD token. \r
550 If the TokenNumber is invalid or the token space\r
551 specified by Guid does not exist, the results are \r
552 unpredictable.\r
80408db0 553\r
fc547e08 554 @param[in] Guid The token space for the token number.\r
555 @param[in] ExTokenNumber The PCD token number. \r
80408db0 556\r
fc547e08 557 @return The size 64-bit value for the PCD token.\r
558 \r
559**/\r
80408db0 560UINT64\r
561EFIAPI\r
562PeiPcdGet64Ex (\r
563 IN CONST EFI_GUID *Guid,\r
564 IN UINTN ExTokenNumber\r
565 )\r
566{\r
567 return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));\r
568}\r
569\r
fc547e08 570/**\r
571 Retrieves a pointer to a value for a given PCD token.\r
80408db0 572\r
fc547e08 573 Retrieves the current pointer to the buffer for a PCD token number. \r
574 Do not make any assumptions about the alignment of the pointer that \r
575 is returned by this function call. If the TokenNumber is invalid, \r
576 the results are unpredictable.\r
80408db0 577\r
fc547e08 578 @param[in] Guid The token space for the token number.\r
579 @param[in] ExTokenNumber The PCD token number. \r
580\r
3fd8027e 581 @return The pointer to the buffer to be retrieved.\r
fc547e08 582 \r
583**/\r
80408db0 584VOID *\r
585EFIAPI\r
586PeiPcdGetPtrEx (\r
587 IN CONST EFI_GUID *Guid,\r
588 IN UINTN ExTokenNumber\r
589 )\r
590{\r
591 return ExGetWorker (Guid, ExTokenNumber, 0);\r
592}\r
593\r
fc547e08 594/**\r
595 Retrieves an Boolean value for a given PCD token.\r
596\r
597 Retrieves the Boolean value of a particular PCD token. \r
598 If the TokenNumber is invalid or the token space\r
599 specified by Guid does not exist, the results are \r
600 unpredictable.\r
80408db0 601\r
fc547e08 602 @param[in] Guid The token space for the token number.\r
603 @param[in] ExTokenNumber The PCD token number. \r
80408db0 604\r
fc547e08 605 @return The size Boolean value for the PCD token.\r
606 \r
607**/\r
80408db0 608BOOLEAN\r
609EFIAPI\r
610PeiPcdGetBoolEx (\r
611 IN CONST EFI_GUID *Guid,\r
612 IN UINTN ExTokenNumber\r
613 )\r
614{\r
615 return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r
616}\r
617\r
fc547e08 618/**\r
619 Retrieves the size of the value for a given PCD token.\r
620\r
621 Retrieves the current size of a particular PCD token. \r
622 If the TokenNumber is invalid, the results are unpredictable.\r
80408db0 623\r
fc547e08 624 @param[in] Guid The token space for the token number.\r
625 @param[in] ExTokenNumber The PCD token number. \r
80408db0 626\r
fc547e08 627 @return The size of the value for the PCD token.\r
628 \r
629**/\r
80408db0 630UINTN\r
631EFIAPI\r
632PeiPcdGetSizeEx (\r
633 IN CONST EFI_GUID *Guid,\r
634 IN UINTN ExTokenNumber\r
635 )\r
636{\r
80408db0 637 return PeiPcdGetSize (GetExPcdTokenNumber (Guid, ExTokenNumber));\r
638}\r
639\r
fc547e08 640/**\r
641 Sets an 8-bit value for a given PCD token.\r
80408db0 642\r
fc547e08 643 When the PCD service sets a value, it will check to ensure that the \r
644 size of the value being set is compatible with the Token's existing definition. \r
645 If it is not, an error will be returned.\r
80408db0 646\r
fc547e08 647 @param[in] TokenNumber The PCD token number. \r
648 @param[in] Value The value to set for the PCD token.\r
649\r
650 @retval EFI_SUCCESS Procedure returned successfully.\r
651 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
652 being set was incompatible with a call to this function. \r
653 Use GetSize() to retrieve the size of the target data.\r
654 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
655 \r
656**/\r
80408db0 657EFI_STATUS\r
658EFIAPI\r
659PeiPcdSet8 (\r
660 IN UINTN TokenNumber,\r
661 IN UINT8 Value\r
662 )\r
663{\r
664 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
665}\r
666\r
fc547e08 667/**\r
668 Sets an 16-bit value for a given PCD token.\r
669\r
670 When the PCD service sets a value, it will check to ensure that the \r
671 size of the value being set is compatible with the Token's existing definition. \r
672 If it is not, an error will be returned.\r
80408db0 673\r
fc547e08 674 @param[in] TokenNumber The PCD token number. \r
675 @param[in] Value The value to set for the PCD token.\r
80408db0 676\r
fc547e08 677 @retval EFI_SUCCESS Procedure returned successfully.\r
678 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
679 being set was incompatible with a call to this function. \r
680 Use GetSize() to retrieve the size of the target data.\r
681 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
682 \r
683**/\r
80408db0 684EFI_STATUS\r
685EFIAPI\r
686PeiPcdSet16 (\r
687 IN UINTN TokenNumber,\r
688 IN UINT16 Value\r
689 )\r
690{\r
691 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
692}\r
693\r
fc547e08 694/**\r
695 Sets an 32-bit value for a given PCD token.\r
80408db0 696\r
fc547e08 697 When the PCD service sets a value, it will check to ensure that the \r
698 size of the value being set is compatible with the Token's existing definition. \r
699 If it is not, an error will be returned.\r
80408db0 700\r
fc547e08 701 @param[in] TokenNumber The PCD token number. \r
702 @param[in] Value The value to set for the PCD token.\r
703\r
704 @retval EFI_SUCCESS Procedure returned successfully.\r
705 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
706 being set was incompatible with a call to this function. \r
707 Use GetSize() to retrieve the size of the target data.\r
708 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
709 \r
710**/\r
80408db0 711EFI_STATUS\r
712EFIAPI\r
713PeiPcdSet32 (\r
714 IN UINTN TokenNumber,\r
715 IN UINT32 Value\r
716 )\r
717{\r
718 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
719}\r
720\r
fc547e08 721/**\r
722 Sets an 64-bit value for a given PCD token.\r
723\r
724 When the PCD service sets a value, it will check to ensure that the \r
725 size of the value being set is compatible with the Token's existing definition. \r
726 If it is not, an error will be returned.\r
80408db0 727\r
fc547e08 728 @param[in] TokenNumber The PCD token number. \r
729 @param[in] Value The value to set for the PCD token.\r
80408db0 730\r
fc547e08 731 @retval EFI_SUCCESS Procedure returned successfully.\r
732 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
733 being set was incompatible with a call to this function. \r
734 Use GetSize() to retrieve the size of the target data.\r
735 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
736 \r
737**/\r
80408db0 738EFI_STATUS\r
739EFIAPI\r
740PeiPcdSet64 (\r
741 IN UINTN TokenNumber,\r
742 IN UINT64 Value\r
743 )\r
744{\r
745 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
746}\r
747\r
fc547e08 748/**\r
749 Sets a value of a specified size for a given PCD token.\r
750\r
751 When the PCD service sets a value, it will check to ensure that the \r
752 size of the value being set is compatible with the Token's existing definition. \r
753 If it is not, an error will be returned.\r
754\r
755 @param[in] TokenNumber The PCD token number. \r
756 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r
757 On input, if the SizeOfValue is greater than the maximum size supported \r
758 for this TokenNumber then the output value of SizeOfValue will reflect \r
759 the maximum size supported for this TokenNumber.\r
760 @param[in] Buffer The buffer to set for the PCD token.\r
761\r
762 @retval EFI_SUCCESS Procedure returned successfully.\r
763 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
764 being set was incompatible with a call to this function. \r
765 Use GetSize() to retrieve the size of the target data.\r
766 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
767 \r
768**/\r
80408db0 769EFI_STATUS\r
770EFIAPI\r
771PeiPcdSetPtr (\r
772 IN UINTN TokenNumber,\r
773 IN OUT UINTN *SizeOfBuffer,\r
774 IN VOID *Buffer\r
775 )\r
776{\r
777 return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
778}\r
779\r
fc547e08 780/**\r
781 Sets an Boolean value for a given PCD token.\r
80408db0 782\r
fc547e08 783 When the PCD service sets a value, it will check to ensure that the \r
784 size of the value being set is compatible with the Token's existing definition. \r
785 If it is not, an error will be returned.\r
80408db0 786\r
fc547e08 787 @param[in] TokenNumber The PCD token number. \r
788 @param[in] Value The value to set for the PCD token.\r
789\r
790 @retval EFI_SUCCESS Procedure returned successfully.\r
791 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
792 being set was incompatible with a call to this function. \r
793 Use GetSize() to retrieve the size of the target data.\r
794 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
795 \r
796**/\r
80408db0 797EFI_STATUS\r
798EFIAPI\r
799PeiPcdSetBool (\r
800 IN UINTN TokenNumber,\r
801 IN BOOLEAN Value\r
802 )\r
803{\r
804 return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
805}\r
806\r
fc547e08 807/**\r
808 Sets an 8-bit value for a given PCD token.\r
80408db0 809\r
fc547e08 810 When the PCD service sets a value, it will check to ensure that the \r
811 size of the value being set is compatible with the Token's existing definition. \r
812 If it is not, an error will be returned.\r
80408db0 813\r
fc547e08 814 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
815 @param[in] ExTokenNumber The PCD token number. \r
816 @param[in] Value The value to set for the PCD token.\r
817\r
818 @retval EFI_SUCCESS Procedure returned successfully.\r
819 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
820 being set was incompatible with a call to this function. \r
821 Use GetSize() to retrieve the size of the target data.\r
822 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
823 \r
824**/\r
80408db0 825EFI_STATUS\r
826EFIAPI\r
827PeiPcdSet8Ex (\r
828 IN CONST EFI_GUID *Guid,\r
829 IN UINTN ExTokenNumber,\r
830 IN UINT8 Value\r
831 )\r
832{\r
833 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
834}\r
835\r
fc547e08 836/**\r
837 Sets an 16-bit value for a given PCD token.\r
838\r
839 When the PCD service sets a value, it will check to ensure that the \r
840 size of the value being set is compatible with the Token's existing definition. \r
841 If it is not, an error will be returned.\r
80408db0 842\r
fc547e08 843 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
844 @param[in] ExTokenNumber The PCD token number. \r
845 @param[in] Value The value to set for the PCD token.\r
80408db0 846\r
fc547e08 847 @retval EFI_SUCCESS Procedure returned successfully.\r
848 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
849 being set was incompatible with a call to this function. \r
850 Use GetSize() to retrieve the size of the target data.\r
851 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
852 \r
853**/\r
80408db0 854EFI_STATUS\r
855EFIAPI\r
856PeiPcdSet16Ex (\r
857 IN CONST EFI_GUID *Guid,\r
858 IN UINTN ExTokenNumber,\r
859 IN UINT16 Value\r
860 )\r
861{\r
862 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
863}\r
864\r
fc547e08 865/**\r
866 Sets an 32-bit value for a given PCD token.\r
867\r
868 When the PCD service sets a value, it will check to ensure that the \r
869 size of the value being set is compatible with the Token's existing definition. \r
870 If it is not, an error will be returned.\r
80408db0 871\r
fc547e08 872 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
873 @param[in] ExTokenNumber The PCD token number. \r
874 @param[in] Value The value to set for the PCD token.\r
80408db0 875\r
fc547e08 876 @retval EFI_SUCCESS Procedure returned successfully.\r
877 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
878 being set was incompatible with a call to this function. \r
879 Use GetSize() to retrieve the size of the target data.\r
880 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
881 \r
882**/\r
80408db0 883EFI_STATUS\r
884EFIAPI\r
885PeiPcdSet32Ex (\r
886 IN CONST EFI_GUID *Guid,\r
887 IN UINTN ExTokenNumber,\r
888 IN UINT32 Value\r
889 )\r
890{\r
891 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
892}\r
893\r
fc547e08 894/**\r
895 Sets an 64-bit value for a given PCD token.\r
80408db0 896\r
fc547e08 897 When the PCD service sets a value, it will check to ensure that the \r
898 size of the value being set is compatible with the Token's existing definition. \r
899 If it is not, an error will be returned.\r
80408db0 900\r
fc547e08 901 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
902 @param[in] ExTokenNumber The PCD token number. \r
903 @param[in] Value The value to set for the PCD token.\r
904\r
905 @retval EFI_SUCCESS Procedure returned successfully.\r
906 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
907 being set was incompatible with a call to this function. \r
908 Use GetSize() to retrieve the size of the target data.\r
909 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
910 \r
911**/\r
80408db0 912EFI_STATUS\r
913EFIAPI\r
914PeiPcdSet64Ex (\r
915 IN CONST EFI_GUID *Guid,\r
916 IN UINTN ExTokenNumber,\r
917 IN UINT64 Value\r
918 )\r
919{\r
920 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
921}\r
922\r
fc547e08 923/**\r
924 Sets a value of a specified size for a given PCD token.\r
925\r
926 When the PCD service sets a value, it will check to ensure that the \r
927 size of the value being set is compatible with the Token's existing definition. \r
928 If it is not, an error will be returned.\r
929\r
930 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
931 @param[in] ExTokenNumber The PCD token number. \r
932 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token. \r
933 On input, if the SizeOfValue is greater than the maximum size supported \r
934 for this TokenNumber then the output value of SizeOfValue will reflect \r
935 the maximum size supported for this TokenNumber.\r
936 @param[in] Value The buffer to set for the PCD token.\r
937\r
938 @retval EFI_SUCCESS Procedure returned successfully.\r
939 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
940 being set was incompatible with a call to this function. \r
941 Use GetSize() to retrieve the size of the target data.\r
942 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
943 \r
944**/\r
80408db0 945EFI_STATUS\r
946EFIAPI\r
947PeiPcdSetPtrEx (\r
fc547e08 948 IN CONST EFI_GUID *Guid,\r
949 IN UINTN ExTokenNumber,\r
950 IN OUT UINTN *SizeOfBuffer,\r
951 IN VOID *Value\r
80408db0 952 )\r
953{\r
954 return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);\r
955}\r
956\r
fc547e08 957/**\r
958 Sets an Boolean value for a given PCD token.\r
959\r
960 When the PCD service sets a value, it will check to ensure that the \r
961 size of the value being set is compatible with the Token's existing definition. \r
962 If it is not, an error will be returned.\r
80408db0 963\r
fc547e08 964 @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
965 @param [in] ExTokenNumber The PCD token number. \r
966 @param [in] Value The value to set for the PCD token.\r
80408db0 967\r
fc547e08 968 @retval EFI_SUCCESS Procedure returned successfully.\r
969 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
970 being set was incompatible with a call to this function. \r
971 Use GetSize() to retrieve the size of the target data.\r
972 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
973 \r
974**/\r
80408db0 975EFI_STATUS\r
976EFIAPI\r
977PeiPcdSetBoolEx (\r
978 IN CONST EFI_GUID *Guid,\r
979 IN UINTN ExTokenNumber,\r
980 IN BOOLEAN Value\r
981 )\r
982{\r
983 return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
984}\r
985\r
fc547e08 986/**\r
987 Specifies a function to be called anytime the value of a designated token is changed.\r
80408db0 988\r
fc547e08 989 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
990 @param[in] ExTokenNumber The PCD token number. \r
991 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r
80408db0 992\r
fc547e08 993 @retval EFI_SUCCESS The PCD service has successfully established a call event \r
994 for the CallBackToken requested.\r
995 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
80408db0 996\r
fc547e08 997**/\r
80408db0 998EFI_STATUS\r
999EFIAPI\r
1000PeiRegisterCallBackOnSet (\r
1001 IN CONST EFI_GUID *Guid, OPTIONAL\r
1002 IN UINTN ExTokenNumber,\r
1003 IN PCD_PPI_CALLBACK CallBackFunction\r
1004 )\r
1005{\r
f806dd27 1006 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1007 return EFI_UNSUPPORTED;\r
1008 }\r
1009\r
e4a3922f 1010 if (CallBackFunction == NULL) {\r
1011 return EFI_INVALID_PARAMETER;\r
1012 }\r
1013\r
80408db0 1014 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);\r
1015}\r
1016\r
fc547e08 1017/**\r
1018 Cancels a previously set callback function for a particular PCD token number.\r
80408db0 1019\r
fc547e08 1020 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
1021 @param[in] ExTokenNumber The PCD token number. \r
1022 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set. \r
80408db0 1023\r
fc547e08 1024 @retval EFI_SUCCESS The PCD service has successfully established a call event \r
1025 for the CallBackToken requested.\r
1026 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
1027\r
1028**/\r
80408db0 1029EFI_STATUS\r
1030EFIAPI\r
1031PcdUnRegisterCallBackOnSet (\r
1032 IN CONST EFI_GUID *Guid, OPTIONAL\r
1033 IN UINTN ExTokenNumber,\r
1034 IN PCD_PPI_CALLBACK CallBackFunction\r
1035 )\r
1036{\r
f806dd27 1037 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1038 return EFI_UNSUPPORTED;\r
1039 }\r
1040\r
e4a3922f 1041 if (CallBackFunction == NULL) {\r
1042 return EFI_INVALID_PARAMETER;\r
1043 }\r
1044\r
80408db0 1045 return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, FALSE);\r
1046}\r
1047\r
fc547e08 1048/**\r
90e06556 1049 Retrieves the next valid token number in a given namespace. \r
1050 \r
1051 This is useful since the PCD infrastructure contains a sparse list of token numbers, \r
1052 and one cannot a priori know what token numbers are valid in the database. \r
1053 \r
1054 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned. \r
1055 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned. \r
1056 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned. \r
1057 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned. \r
1058 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid. \r
1059 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned. \r
1060 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned. \r
1061 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r
1062\r
1063\r
1064 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value. \r
1065 This is an optional parameter that may be NULL. If this parameter is NULL, then a request \r
1066 is being made to retrieve tokens from the default token space.\r
1067 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.\r
1068 \r
419db80b
BF
1069 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.\r
1070 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.\r
fc547e08 1071\r
1072**/\r
80408db0 1073EFI_STATUS\r
1074EFIAPI\r
1075PeiPcdGetNextToken (\r
1076 IN CONST EFI_GUID *Guid, OPTIONAL\r
1077 IN OUT UINTN *TokenNumber\r
1078 )\r
1079{\r
1080 UINTN GuidTableIdx;\r
1081 PEI_PCD_DATABASE *PeiPcdDb;\r
1082 EFI_GUID *MatchGuid;\r
419db80b 1083 EFI_GUID *GuidTable;\r
80408db0 1084 DYNAMICEX_MAPPING *ExMapTable;\r
fc547e08 1085 UINTN Index;\r
80408db0 1086 BOOLEAN Found;\r
1087 BOOLEAN PeiExMapTableEmpty;\r
419db80b 1088 UINTN PeiNexTokenNumber; \r
80408db0 1089\r
f806dd27 1090 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1091 return EFI_UNSUPPORTED;\r
1092 }\r
1093\r
419db80b
BF
1094 PeiPcdDb = GetPcdDatabase ();\r
1095 PeiNexTokenNumber = PeiPcdDb->LocalTokenCount - PeiPcdDb->ExTokenCount;\r
1096 GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r
80408db0 1097\r
419db80b
BF
1098 if (PeiPcdDb->ExTokenCount == 0) {\r
1099 PeiExMapTableEmpty = TRUE;\r
1100 } else {\r
1101 PeiExMapTableEmpty = FALSE;\r
1102 }\r
80408db0 1103 if (Guid == NULL) {\r
419db80b 1104 if (*TokenNumber > PeiNexTokenNumber) {\r
80408db0 1105 return EFI_NOT_FOUND;\r
1106 }\r
1107 (*TokenNumber)++;\r
419db80b 1108 if (*TokenNumber > PeiNexTokenNumber) {\r
80408db0 1109 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
419db80b 1110 return EFI_NOT_FOUND;\r
80408db0 1111 }\r
1112 return EFI_SUCCESS;\r
1113 } else {\r
1114 if (PeiExMapTableEmpty) {\r
419db80b 1115 return EFI_NOT_FOUND;\r
80408db0 1116 }\r
419db80b
BF
1117\r
1118 MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid);\r
80408db0 1119\r
1120 if (MatchGuid == NULL) {\r
80408db0 1121 return EFI_NOT_FOUND;\r
1122 }\r
1123\r
419db80b 1124 GuidTableIdx = MatchGuid - GuidTable;\r
80408db0 1125\r
419db80b 1126 ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r
80408db0 1127\r
1128 Found = FALSE;\r
1129 //\r
1130 // Locate the GUID in ExMapTable first.\r
1131 //\r
419db80b 1132 for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r
fc547e08 1133 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
80408db0 1134 Found = TRUE;\r
1135 break;\r
1136 }\r
1137 }\r
1138\r
1139 if (Found) {\r
bfb4c2ba
CS
1140 //\r
1141 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first\r
1142 // token number in found token space.\r
1143 //\r
80408db0 1144 if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r
fc547e08 1145 *TokenNumber = ExMapTable[Index].ExTokenNumber;\r
80408db0 1146 return EFI_SUCCESS;\r
1147 }\r
1148\r
419db80b 1149 for ( ; Index < PeiPcdDb->ExTokenCount; Index++) {\r
bfb4c2ba 1150 if ((ExMapTable[Index].ExTokenNumber == *TokenNumber) && (ExMapTable[Index].ExGuidIndex == GuidTableIdx)) {\r
419db80b
BF
1151 break;\r
1152 }\r
1153 }\r
1154\r
1155 while (Index < PeiPcdDb->ExTokenCount) {\r
1156 Index++;\r
1157 if (Index == PeiPcdDb->ExTokenCount) {\r
1158 //\r
1159 // Exceed the length of ExMap Table\r
1160 //\r
1161 *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
1162 return EFI_NOT_FOUND;\r
1163 } else if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
1164 //\r
1165 // Found the next match\r
1166 //\r
1167 *TokenNumber = ExMapTable[Index].ExTokenNumber;\r
1168 return EFI_SUCCESS;\r
80408db0 1169 }\r
1170 }\r
80408db0 1171 }\r
1172 }\r
1173\r
1174 return EFI_NOT_FOUND;\r
1175}\r
1176\r
fc547e08 1177/**\r
1178 Retrieves the next valid PCD token namespace for a given namespace.\r
1179\r
419db80b
BF
1180 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid\r
1181 token namespaces on a platform.\r
1182\r
1183 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token\r
1184 namespace from which the search will start. On output, it designates the next valid\r
1185 token namespace on the platform. If *Guid is NULL, then the GUID of the first token\r
1186 space of the current platform is returned. If the search cannot locate the next valid\r
1187 token namespace, an error is returned and the value of *Guid is undefined.\r
1188 \r
1189 @retval EFI_SUCCESS The PCD service retrieved the value requested.\r
1190 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.\r
80408db0 1191\r
fc547e08 1192**/\r
80408db0 1193EFI_STATUS\r
1194EFIAPI\r
1195PeiPcdGetNextTokenSpace (\r
1196 IN OUT CONST EFI_GUID **Guid\r
1197 )\r
1198{\r
1199 UINTN GuidTableIdx;\r
1200 EFI_GUID *MatchGuid;\r
1201 PEI_PCD_DATABASE *PeiPcdDb;\r
1202 DYNAMICEX_MAPPING *ExMapTable;\r
fc547e08 1203 UINTN Index;\r
419db80b 1204 UINTN Index2;\r
80408db0 1205 BOOLEAN Found;\r
1206 BOOLEAN PeiExMapTableEmpty;\r
419db80b 1207 EFI_GUID *GuidTable;\r
80408db0 1208\r
f806dd27 1209 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
80408db0 1210 return EFI_UNSUPPORTED;\r
1211 }\r
1212\r
1213 ASSERT (Guid != NULL);\r
1214\r
419db80b 1215 PeiPcdDb = GetPcdDatabase ();\r
80408db0 1216\r
419db80b
BF
1217 if (PeiPcdDb->ExTokenCount == 0) {\r
1218 PeiExMapTableEmpty = TRUE;\r
1219 } else {\r
1220 PeiExMapTableEmpty = FALSE;\r
1221 }\r
1222 \r
80408db0 1223 if (PeiExMapTableEmpty) {\r
419db80b 1224 return EFI_NOT_FOUND;\r
80408db0 1225 }\r
1226\r
419db80b
BF
1227 ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r
1228 GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r
1229 \r
80408db0 1230 if (*Guid == NULL) {\r
1231 //\r
1232 // return the first Token Space Guid.\r
1233 //\r
419db80b 1234 *Guid = GuidTable + ExMapTable[0].ExGuidIndex;\r
80408db0 1235 return EFI_SUCCESS;\r
1236 }\r
1237\r
419db80b 1238 MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(GuidTable[0]), *Guid);\r
80408db0 1239\r
1240 if (MatchGuid == NULL) {\r
1241 return EFI_NOT_FOUND;\r
1242 }\r
1243 \r
419db80b 1244 GuidTableIdx = MatchGuid - GuidTable;\r
80408db0 1245\r
1246 Found = FALSE;\r
419db80b 1247 for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r
fc547e08 1248 if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r
80408db0 1249 Found = TRUE;\r
1250 break;\r
1251 }\r
1252 }\r
1253\r
1254 if (Found) {\r
fc547e08 1255 Index++;\r
419db80b
BF
1256 for ( ; Index < PeiPcdDb->ExTokenCount; Index++ ) {\r
1257 if (ExMapTable[Index].ExGuidIndex != GuidTableIdx) {\r
1258 Found = FALSE;\r
1259 for (Index2 = 0 ; Index2 < Index; Index2++) {\r
1260 if (ExMapTable[Index2].ExGuidIndex == ExMapTable[Index].ExGuidIndex) {\r
1261 //\r
1262 // This token namespace should have been found and output at preceding getting.\r
1263 //\r
1264 Found = TRUE;\r
1265 break;\r
1266 }\r
1267 }\r
1268 if (!Found) {\r
1269 *Guid = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + ExMapTable[Index].ExGuidIndex;\r
1270 return EFI_SUCCESS;\r
1271 }\r
80408db0 1272 }\r
1273 }\r
1274 *Guid = NULL;\r
80408db0 1275 }\r
1276\r
1277 return EFI_NOT_FOUND;\r
1278\r
1279}\r
1280\r
fc547e08 1281/**\r
1282 Get PCD value's size for POINTER type PCD.\r
1283 \r
419db80b 1284 The POINTER type PCD's value will be stored into a buffer in specified size.\r
fc547e08 1285 The max size of this PCD's value is described in PCD's definition in DEC file.\r
1286\r
1287 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r
3fd8027e 1288 @param MaxSize Maximum size of PCD's value\r
fc547e08 1289 @param Database Pcd database in PEI phase.\r
1290\r
1291 @return PCD value's size for POINTER type PCD.\r
1292\r
1293**/\r
80408db0 1294UINTN\r
1295GetPtrTypeSize (\r
1296 IN UINTN LocalTokenNumberTableIdx,\r
1297 OUT UINTN *MaxSize,\r
1298 IN PEI_PCD_DATABASE *Database\r
1299 )\r
1300{\r
1301 INTN SizeTableIdx;\r
1302 UINTN LocalTokenNumber;\r
1303 SKU_ID *SkuIdTable;\r
1304 SIZE_INFO *SizeTable;\r
fc547e08 1305 UINTN Index;\r
80408db0 1306\r
1307 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
1308\r
419db80b 1309 LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r
80408db0 1310\r
1311 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
1312 \r
419db80b 1313 SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r
80408db0 1314\r
1315 *MaxSize = SizeTable[SizeTableIdx];\r
1316 //\r
1317 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
1318 // PCD entry.\r
1319 //\r
fc547e08 1320 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r
80408db0 1321 //\r
419db80b 1322 // We have only two entry for VPD enabled PCD entry:\r
80408db0 1323 // 1) MAX Size.\r
419db80b 1324 // 2) Current Size\r
80408db0 1325 // We consider current size is equal to MAX size.\r
1326 //\r
1327 return *MaxSize;\r
1328 } else {\r
1329 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {\r
1330 //\r
1331 // We have only two entry for Non-Sku enabled PCD entry:\r
1332 // 1) MAX SIZE\r
1333 // 2) Current Size\r
1334 //\r
1335 return SizeTable[SizeTableIdx + 1];\r
1336 } else {\r
1337 //\r
1338 // We have these entry for SKU enabled PCD entry\r
1339 // 1) MAX SIZE\r
1340 // 2) Current Size for each SKU_ID (It is equal to MaxSku).\r
1341 //\r
1342 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);\r
fc547e08 1343 for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
419db80b 1344 if (SkuIdTable[1 + Index] == Database->SystemSkuId) {\r
fc547e08 1345 return SizeTable[SizeTableIdx + 1 + Index];\r
80408db0 1346 }\r
1347 }\r
1348 return SizeTable[SizeTableIdx + 1];\r
1349 }\r
1350 }\r
1351}\r
1352\r
fc547e08 1353/**\r
1354 Set PCD value's size for POINTER type PCD.\r
1355 \r
419db80b 1356 The POINTER type PCD's value will be stored into a buffer in specified size.\r
fc547e08 1357 The max size of this PCD's value is described in PCD's definition in DEC file.\r
1358\r
1359 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r
3fd8027e 1360 @param CurrentSize Maximum size of PCD's value\r
fc547e08 1361 @param Database Pcd database in PEI phase.\r
80408db0 1362\r
3fd8027e 1363 @retval TRUE Success to set PCD's value size, which is not exceed maximum size\r
1364 @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size\r
80408db0 1365\r
fc547e08 1366**/\r
80408db0 1367BOOLEAN\r
1368SetPtrTypeSize (\r
1369 IN UINTN LocalTokenNumberTableIdx,\r
1370 IN OUT UINTN *CurrentSize,\r
1371 IN PEI_PCD_DATABASE *Database\r
1372 )\r
1373{\r
1374 INTN SizeTableIdx;\r
1375 UINTN LocalTokenNumber;\r
1376 SKU_ID *SkuIdTable;\r
1377 SIZE_INFO *SizeTable;\r
fc547e08 1378 UINTN Index;\r
80408db0 1379 UINTN MaxSize;\r
1380 \r
1381 SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
1382\r
419db80b 1383 LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r
80408db0 1384\r
1385 ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
419db80b
BF
1386\r
1387 SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r
80408db0 1388\r
1389 MaxSize = SizeTable[SizeTableIdx];\r
1390 //\r
1391 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
1392 // PCD entry.\r
1393 //\r
fc547e08 1394 if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r
80408db0 1395 //\r
1396 // We shouldn't come here as we don't support SET for VPD\r
1397 //\r
1398 ASSERT (FALSE);\r
1399 return FALSE;\r
1400 } else {\r
1401 if ((*CurrentSize > MaxSize) ||\r
1402 (*CurrentSize == MAX_ADDRESS)) {\r
1403 *CurrentSize = MaxSize;\r
1404 return FALSE;\r
5944a83b 1405 }\r
80408db0 1406 \r
1407 if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {\r
1408 //\r
1409 // We have only two entry for Non-Sku enabled PCD entry:\r
1410 // 1) MAX SIZE\r
1411 // 2) Current Size\r
1412 //\r
1413 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r
1414 return TRUE;\r
1415 } else {\r
1416 //\r
1417 // We have these entry for SKU enabled PCD entry\r
1418 // 1) MAX SIZE\r
1419 // 2) Current Size for each SKU_ID (It is equal to MaxSku).\r
1420 //\r
1421 SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);\r
fc547e08 1422 for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
419db80b 1423 if (SkuIdTable[1 + Index] == Database->SystemSkuId) {\r
fc547e08 1424 SizeTable[SizeTableIdx + 1 + Index] = (SIZE_INFO) *CurrentSize;\r
80408db0 1425 return TRUE;\r
1426 }\r
1427 }\r
1428 SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r
1429 return TRUE;\r
1430 }\r
1431 }\r
1432\r
1433}\r