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