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