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