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