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