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