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