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