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