2 All Pcd Ppi services are implemented here.
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 PCD_PPI mPcdPpiInstance
= {
50 PeiRegisterCallBackOnSet
,
51 PcdUnRegisterCallBackOnSet
,
53 PeiPcdGetNextTokenSpace
56 EFI_PEI_PPI_DESCRIPTOR mPpiPCD
= {
57 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
63 Main entry for PCD PEIM driver.
65 This routine initialize the PCD database for PEI phase and install PCD_PPI.
67 @param FileHandle Handle of the file being invoked.
68 @param PeiServices Describes the list of possible PEI Services.
70 @return Status of install PCD_PPI
76 IN EFI_PEI_FILE_HANDLE FileHandle
,
77 IN CONST EFI_PEI_SERVICES
**PeiServices
82 return PeiServicesInstallPpi (&mPpiPCD
);
86 Sets the SKU value for subsequent calls to set or get PCD token values.
88 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
89 SetSku() is normally called only once by the system.
91 For each item (token), the database can hold a single value that applies to all SKUs,
92 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
93 SKU-specific values are called SKU enabled.
95 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
96 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
97 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
98 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
99 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
100 set for that Id, the results are unpredictable.
102 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
103 set values associated with a PCD token.
113 GetPcdDatabase()->Init
.SystemSkuId
= (SKU_ID
) SkuId
;
119 Retrieves an 8-bit value for a given PCD token.
121 Retrieves the current byte-sized value for a PCD token number.
122 If the TokenNumber is invalid, the results are unpredictable.
124 @param[in] TokenNumber The PCD token number.
126 @return The UINT8 value.
135 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
139 Retrieves an 16-bit value for a given PCD token.
141 Retrieves the current 16-bits value for a PCD token number.
142 If the TokenNumber is invalid, the results are unpredictable.
144 @param[in] TokenNumber The PCD token number.
146 @return The UINT16 value.
155 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
159 Retrieves an 32-bit value for a given PCD token.
161 Retrieves the current 32-bits value for a PCD token number.
162 If the TokenNumber is invalid, the results are unpredictable.
164 @param[in] TokenNumber The PCD token number.
166 @return The UINT32 value.
175 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
179 Retrieves an 64-bit value for a given PCD token.
181 Retrieves the current 64-bits value for a PCD token number.
182 If the TokenNumber is invalid, the results are unpredictable.
184 @param[in] TokenNumber The PCD token number.
186 @return The UINT64 value.
195 return ReadUnaligned64 (GetWorker (TokenNumber
, sizeof (UINT64
)));
199 Retrieves a pointer to a value for a given PCD token.
201 Retrieves the current pointer to the buffer for a PCD token number.
202 Do not make any assumptions about the alignment of the pointer that
203 is returned by this function call. If the TokenNumber is invalid,
204 the results are unpredictable.
206 @param[in] TokenNumber The PCD token number.
208 @return The pointer to the buffer to be retrieved.
217 return GetWorker (TokenNumber
, 0);
221 Retrieves a Boolean value for a given PCD token.
223 Retrieves the current boolean value for a PCD token number.
224 Do not make any assumptions about the alignment of the pointer that
225 is returned by this function call. If the TokenNumber is invalid,
226 the results are unpredictable.
228 @param[in] TokenNumber The PCD token number.
230 @return The Boolean value.
239 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
243 Retrieves the size of the value for a given PCD token.
245 Retrieves the current size of a particular PCD token.
246 If the TokenNumber is invalid, the results are unpredictable.
248 @param[in] TokenNumber The PCD token number.
250 @return The size of the value for the PCD token.
259 PEI_PCD_DATABASE
*PeiPcdDb
;
264 // If DebugAssertEnabled is TRUE, we still need to provide the GET size
265 // function as GetWorker and SetWoker need this function to do ASSERT.
267 if ((!FeaturePcdGet(PcdPeiPcdDatabaseGetSizeEnabled
)) &&
268 (!DebugAssertEnabled ())) {
272 PeiPcdDb
= GetPcdDatabase ();
274 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
275 // We have to decrement TokenNumber by 1 to make it usable
276 // as the array index.
280 // EBC compiler is very choosy. It may report warning about comparison
281 // between UINTN and 0 . So we add 1 in each size of the
283 ASSERT (TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
285 Size
= (PeiPcdDb
->Init
.LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
289 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
291 return GetPtrTypeSize (TokenNumber
, &MaxSize
, PeiPcdDb
);
299 Retrieves an 8-bit value for a given PCD token.
301 Retrieves the 8-bit value of a particular PCD token.
302 If the TokenNumber is invalid or the token space
303 specified by Guid does not exist, the results are
306 @param[in] Guid The token space for the token number.
307 @param[in] ExTokenNumber The PCD token number.
309 @return The size 8-bit value for the PCD token.
315 IN CONST EFI_GUID
*Guid
,
316 IN UINTN ExTokenNumber
319 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT8
)));
323 Retrieves an 16-bit value for a given PCD token.
325 Retrieves the 16-bit value of a particular PCD token.
326 If the TokenNumber is invalid or the token space
327 specified by Guid does not exist, the results are
330 @param[in] Guid The token space for the token number.
331 @param[in] ExTokenNumber The PCD token number.
333 @return The size 16-bit value for the PCD token.
339 IN CONST EFI_GUID
*Guid
,
340 IN UINTN ExTokenNumber
343 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT16
)));
347 Retrieves an 32-bit value for a given PCD token.
349 Retrieves the 32-bit value of a particular PCD token.
350 If the TokenNumber is invalid or the token space
351 specified by Guid does not exist, the results are
354 @param[in] Guid The token space for the token number.
355 @param[in] ExTokenNumber The PCD token number.
357 @return The size 32-bit value for the PCD token.
363 IN CONST EFI_GUID
*Guid
,
364 IN UINTN ExTokenNumber
367 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT32
)));
371 Retrieves an 64-bit value for a given PCD token.
373 Retrieves the 64-bit value of a particular PCD token.
374 If the TokenNumber is invalid or the token space
375 specified by Guid does not exist, the results are
378 @param[in] Guid The token space for the token number.
379 @param[in] ExTokenNumber The PCD token number.
381 @return The size 64-bit value for the PCD token.
387 IN CONST EFI_GUID
*Guid
,
388 IN UINTN ExTokenNumber
391 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT64
)));
395 Retrieves a pointer to a value for a given PCD token.
397 Retrieves the current pointer to the buffer for a PCD token number.
398 Do not make any assumptions about the alignment of the pointer that
399 is returned by this function call. If the TokenNumber is invalid,
400 the results are unpredictable.
402 @param[in] Guid The token space for the token number.
403 @param[in] ExTokenNumber The PCD token number.
405 @return The pointer to the buffer to be retrieved.
411 IN CONST EFI_GUID
*Guid
,
412 IN UINTN ExTokenNumber
415 return ExGetWorker (Guid
, ExTokenNumber
, 0);
419 Retrieves an Boolean value for a given PCD token.
421 Retrieves the Boolean value of a particular PCD token.
422 If the TokenNumber is invalid or the token space
423 specified by Guid does not exist, the results are
426 @param[in] Guid The token space for the token number.
427 @param[in] ExTokenNumber The PCD token number.
429 @return The size Boolean value for the PCD token.
435 IN CONST EFI_GUID
*Guid
,
436 IN UINTN ExTokenNumber
439 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof (BOOLEAN
)));
443 Retrieves the size of the value for a given PCD token.
445 Retrieves the current size of a particular PCD token.
446 If the TokenNumber is invalid, the results are unpredictable.
448 @param[in] Guid The token space for the token number.
449 @param[in] ExTokenNumber The PCD token number.
451 @return The size of the value for the PCD token.
457 IN CONST EFI_GUID
*Guid
,
458 IN UINTN ExTokenNumber
461 if ((!FeaturePcdGet (PcdPeiPcdDatabaseGetSizeEnabled
)) || !FeaturePcdGet (PcdPeiPcdDatabaseExEnabled
)) {
465 return PeiPcdGetSize (GetExPcdTokenNumber (Guid
, ExTokenNumber
));
469 Sets an 8-bit value for a given PCD token.
471 When the PCD service sets a value, it will check to ensure that the
472 size of the value being set is compatible with the Token's existing definition.
473 If it is not, an error will be returned.
475 @param[in] TokenNumber The PCD token number.
476 @param[in] Value The value to set for the PCD token.
478 @retval EFI_SUCCESS Procedure returned successfully.
479 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
480 being set was incompatible with a call to this function.
481 Use GetSize() to retrieve the size of the target data.
482 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
488 IN UINTN TokenNumber
,
492 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
496 Sets an 16-bit value for a given PCD token.
498 When the PCD service sets a value, it will check to ensure that the
499 size of the value being set is compatible with the Token's existing definition.
500 If it is not, an error will be returned.
502 @param[in] TokenNumber The PCD token number.
503 @param[in] Value The value to set for the PCD token.
505 @retval EFI_SUCCESS Procedure returned successfully.
506 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
507 being set was incompatible with a call to this function.
508 Use GetSize() to retrieve the size of the target data.
509 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
515 IN UINTN TokenNumber
,
519 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
523 Sets an 32-bit value for a given PCD token.
525 When the PCD service sets a value, it will check to ensure that the
526 size of the value being set is compatible with the Token's existing definition.
527 If it is not, an error will be returned.
529 @param[in] TokenNumber The PCD token number.
530 @param[in] Value The value to set for the PCD token.
532 @retval EFI_SUCCESS Procedure returned successfully.
533 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
534 being set was incompatible with a call to this function.
535 Use GetSize() to retrieve the size of the target data.
536 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
542 IN UINTN TokenNumber
,
546 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
550 Sets an 64-bit value for a given PCD token.
552 When the PCD service sets a value, it will check to ensure that the
553 size of the value being set is compatible with the Token's existing definition.
554 If it is not, an error will be returned.
556 @param[in] TokenNumber The PCD token number.
557 @param[in] Value The value to set for the PCD token.
559 @retval EFI_SUCCESS Procedure returned successfully.
560 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
561 being set was incompatible with a call to this function.
562 Use GetSize() to retrieve the size of the target data.
563 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
569 IN UINTN TokenNumber
,
573 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
577 Sets a value of a specified size for a given PCD token.
579 When the PCD service sets a value, it will check to ensure that the
580 size of the value being set is compatible with the Token's existing definition.
581 If it is not, an error will be returned.
583 @param[in] TokenNumber The PCD token number.
584 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
585 On input, if the SizeOfValue is greater than the maximum size supported
586 for this TokenNumber then the output value of SizeOfValue will reflect
587 the maximum size supported for this TokenNumber.
588 @param[in] Buffer The buffer to set for the PCD token.
590 @retval EFI_SUCCESS Procedure returned successfully.
591 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
592 being set was incompatible with a call to this function.
593 Use GetSize() to retrieve the size of the target data.
594 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
600 IN UINTN TokenNumber
,
601 IN OUT UINTN
*SizeOfBuffer
,
605 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
609 Sets an Boolean value for a given PCD token.
611 When the PCD service sets a value, it will check to ensure that the
612 size of the value being set is compatible with the Token's existing definition.
613 If it is not, an error will be returned.
615 @param[in] TokenNumber The PCD token number.
616 @param[in] Value The value to set for the PCD token.
618 @retval EFI_SUCCESS Procedure returned successfully.
619 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
620 being set was incompatible with a call to this function.
621 Use GetSize() to retrieve the size of the target data.
622 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
628 IN UINTN TokenNumber
,
632 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
636 Sets an 8-bit value for a given PCD token.
638 When the PCD service sets a value, it will check to ensure that the
639 size of the value being set is compatible with the Token's existing definition.
640 If it is not, an error will be returned.
642 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
643 @param[in] ExTokenNumber The PCD token number.
644 @param[in] Value The value to set for the PCD token.
646 @retval EFI_SUCCESS Procedure returned successfully.
647 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
648 being set was incompatible with a call to this function.
649 Use GetSize() to retrieve the size of the target data.
650 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
656 IN CONST EFI_GUID
*Guid
,
657 IN UINTN ExTokenNumber
,
661 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
665 Sets an 16-bit value for a given PCD token.
667 When the PCD service sets a value, it will check to ensure that the
668 size of the value being set is compatible with the Token's existing definition.
669 If it is not, an error will be returned.
671 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
672 @param[in] ExTokenNumber The PCD token number.
673 @param[in] Value The value to set for the PCD token.
675 @retval EFI_SUCCESS Procedure returned successfully.
676 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
677 being set was incompatible with a call to this function.
678 Use GetSize() to retrieve the size of the target data.
679 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
685 IN CONST EFI_GUID
*Guid
,
686 IN UINTN ExTokenNumber
,
690 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
694 Sets an 32-bit value for a given PCD token.
696 When the PCD service sets a value, it will check to ensure that the
697 size of the value being set is compatible with the Token's existing definition.
698 If it is not, an error will be returned.
700 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
701 @param[in] ExTokenNumber The PCD token number.
702 @param[in] Value The value to set for the PCD token.
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.
714 IN CONST EFI_GUID
*Guid
,
715 IN UINTN ExTokenNumber
,
719 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
723 Sets an 64-bit value for a given PCD token.
725 When the PCD service sets a value, it will check to ensure that the
726 size of the value being set is compatible with the Token's existing definition.
727 If it is not, an error will be returned.
729 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
730 @param[in] ExTokenNumber The PCD token number.
731 @param[in] Value The value to set for the PCD token.
733 @retval EFI_SUCCESS Procedure returned successfully.
734 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
735 being set was incompatible with a call to this function.
736 Use GetSize() to retrieve the size of the target data.
737 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
743 IN CONST EFI_GUID
*Guid
,
744 IN UINTN ExTokenNumber
,
748 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
752 Sets a value of a specified size for a given PCD token.
754 When the PCD service sets a value, it will check to ensure that the
755 size of the value being set is compatible with the Token's existing definition.
756 If it is not, an error will be returned.
758 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
759 @param[in] ExTokenNumber The PCD token number.
760 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
761 On input, if the SizeOfValue is greater than the maximum size supported
762 for this TokenNumber then the output value of SizeOfValue will reflect
763 the maximum size supported for this TokenNumber.
764 @param[in] Value The buffer to set for the PCD token.
766 @retval EFI_SUCCESS Procedure returned successfully.
767 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
768 being set was incompatible with a call to this function.
769 Use GetSize() to retrieve the size of the target data.
770 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
776 IN CONST EFI_GUID
*Guid
,
777 IN UINTN ExTokenNumber
,
778 IN OUT UINTN
*SizeOfBuffer
,
782 return ExSetWorker (ExTokenNumber
, Guid
, Value
, SizeOfBuffer
, TRUE
);
786 Sets an Boolean value for a given PCD token.
788 When the PCD service sets a value, it will check to ensure that the
789 size of the value being set is compatible with the Token's existing definition.
790 If it is not, an error will be returned.
792 @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
793 @param [in] ExTokenNumber The PCD token number.
794 @param [in] Value The value to set for the PCD token.
796 @retval EFI_SUCCESS Procedure returned successfully.
797 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
798 being set was incompatible with a call to this function.
799 Use GetSize() to retrieve the size of the target data.
800 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
806 IN CONST EFI_GUID
*Guid
,
807 IN UINTN ExTokenNumber
,
811 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
815 Specifies a function to be called anytime the value of a designated token is changed.
817 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
818 @param[in] ExTokenNumber The PCD token number.
819 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
821 @retval EFI_SUCCESS The PCD service has successfully established a call event
822 for the CallBackToken requested.
823 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
828 PeiRegisterCallBackOnSet (
829 IN CONST EFI_GUID
*Guid
, OPTIONAL
830 IN UINTN ExTokenNumber
,
831 IN PCD_PPI_CALLBACK CallBackFunction
834 if (!FeaturePcdGet(PcdPeiPcdDatabaseCallbackOnSetEnabled
)) {
835 return EFI_UNSUPPORTED
;
838 ASSERT (CallBackFunction
!= NULL
);
840 return PeiRegisterCallBackWorker (ExTokenNumber
, Guid
, CallBackFunction
, TRUE
);
844 Cancels a previously set callback function for a particular PCD token number.
846 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
847 @param[in] ExTokenNumber The PCD token number.
848 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
850 @retval EFI_SUCCESS The PCD service has successfully established a call event
851 for the CallBackToken requested.
852 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
857 PcdUnRegisterCallBackOnSet (
858 IN CONST EFI_GUID
*Guid
, OPTIONAL
859 IN UINTN ExTokenNumber
,
860 IN PCD_PPI_CALLBACK CallBackFunction
863 if (!FeaturePcdGet(PcdPeiPcdDatabaseCallbackOnSetEnabled
)) {
864 return EFI_UNSUPPORTED
;
867 ASSERT (CallBackFunction
!= NULL
);
869 return PeiRegisterCallBackWorker (ExTokenNumber
, Guid
, CallBackFunction
, FALSE
);
873 Retrieves the next valid PCD token for a given namespace.
875 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
876 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.
877 If the input token namespace or token number does not exist on the platform,
878 an error is returned and the value of *TokenNumber is undefined. To retrieve the "first" token,
879 have the pointer reference a TokenNumber value of 0. If the input token number is 0 and
880 there is no valid token number for this token namespace, *TokenNumber will be assigned to
881 0 and the function return EFI_SUCCESS. If the token number is the last valid token number,
882 *TokenNumber will be assigned to 0 and the function return EFI_SUCCESS.
884 @retval EFI_SUCCESS The PCD service retrieved the next valid token number. Or the input token number
885 is already the last valid token number in the PCD database.
886 In the later case, *TokenNumber is updated with the value of 0.
887 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
893 IN CONST EFI_GUID
*Guid
, OPTIONAL
894 IN OUT UINTN
*TokenNumber
898 PEI_PCD_DATABASE
*PeiPcdDb
;
900 DYNAMICEX_MAPPING
*ExMapTable
;
903 BOOLEAN PeiExMapTableEmpty
;
905 if (!FeaturePcdGet (PcdPeiPcdDatabaseTraverseEnabled
)) {
906 return EFI_UNSUPPORTED
;
909 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
912 if (*TokenNumber
> PEI_NEX_TOKEN_NUMBER
) {
913 return EFI_NOT_FOUND
;
916 if (*TokenNumber
> PEI_NEX_TOKEN_NUMBER
) {
917 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
921 if (PeiExMapTableEmpty
) {
922 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
927 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
931 PeiPcdDb
= GetPcdDatabase ();
933 MatchGuid
= ScanGuid (PeiPcdDb
->Init
.GuidTable
, sizeof(PeiPcdDb
->Init
.GuidTable
), Guid
);
935 if (MatchGuid
== NULL
) {
936 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
937 return EFI_NOT_FOUND
;
940 GuidTableIdx
= MatchGuid
- PeiPcdDb
->Init
.GuidTable
;
942 ExMapTable
= PeiPcdDb
->Init
.ExMapTable
;
946 // Locate the GUID in ExMapTable first.
948 for (Index
= 0; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
949 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
956 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
957 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
961 for ( ; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
962 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
964 if (Index
== PEI_EXMAPPING_TABLE_SIZE
) {
966 // Exceed the length of ExMap Table
968 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
971 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
972 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
975 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
980 return EFI_NOT_FOUND
;
984 return EFI_NOT_FOUND
;
988 Retrieves the next valid PCD token namespace for a given namespace.
990 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates
991 a known token namespace from which the search will start. On output,
992 it designates the next valid token namespace on the platform. If the input
993 token namespace does not exist on the platform, an error is returned and
994 the value of *Guid is undefined. If *Guid is NULL, then the GUID of the
995 first token space of the current platform is assigned to *Guid the function
996 return EFI_SUCCESS. If *Guid is NULL and there is no namespace exist in
997 the platform other than the default (NULL) tokennamespace, *Guid is unchanged
998 and the function return EFI_SUCCESS. If this input token namespace is the last
999 namespace on the platform, *Guid will be assigned to NULL and the function return
1002 @retval EFI_SUCCESS The PCD service retrieved the next valid token space Guid.
1003 Or the input token space Guid is already the last valid token space Guid
1004 in the PCD database. In the later case, *Guid is updated with the value of NULL.
1005 @retval EFI_NOT_FOUND If the input token namespace does not exist on the platform.
1010 PeiPcdGetNextTokenSpace (
1011 IN OUT CONST EFI_GUID
**Guid
1015 EFI_GUID
*MatchGuid
;
1016 PEI_PCD_DATABASE
*PeiPcdDb
;
1017 DYNAMICEX_MAPPING
*ExMapTable
;
1020 BOOLEAN PeiExMapTableEmpty
;
1022 if (!FeaturePcdGet (PcdPeiPcdDatabaseTraverseEnabled
)) {
1023 return EFI_UNSUPPORTED
;
1026 ASSERT (Guid
!= NULL
);
1028 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
1030 if (PeiExMapTableEmpty
) {
1031 if (*Guid
!= NULL
) {
1032 return EFI_NOT_FOUND
;
1039 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
1043 PeiPcdDb
= GetPcdDatabase ();
1045 ExMapTable
= PeiPcdDb
->Init
.ExMapTable
;
1047 if (*Guid
== NULL
) {
1049 // return the first Token Space Guid.
1051 *Guid
= &PeiPcdDb
->Init
.GuidTable
[ExMapTable
[0].ExGuidIndex
];
1055 MatchGuid
= ScanGuid (PeiPcdDb
->Init
.GuidTable
, sizeof(PeiPcdDb
->Init
.GuidTable
), *Guid
);
1057 if (MatchGuid
== NULL
) {
1058 return EFI_NOT_FOUND
;
1061 GuidTableIdx
= MatchGuid
- PeiPcdDb
->Init
.GuidTable
;
1064 for (Index
= 0; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
1065 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1073 for ( ; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++ ) {
1074 if (ExMapTable
[Index
].ExGuidIndex
!= GuidTableIdx
) {
1075 *Guid
= &PeiPcdDb
->Init
.GuidTable
[ExMapTable
[Index
].ExGuidIndex
];
1083 return EFI_NOT_FOUND
;
1088 Get PCD value's size for POINTER type PCD.
1090 The POINTER type PCD's value will be stored into a buffer in specificed size.
1091 The max size of this PCD's value is described in PCD's definition in DEC file.
1093 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1094 @param MaxSize Maximum size of PCD's value
1095 @param Database Pcd database in PEI phase.
1097 @return PCD value's size for POINTER type PCD.
1102 IN UINTN LocalTokenNumberTableIdx
,
1104 IN PEI_PCD_DATABASE
*Database
1108 UINTN LocalTokenNumber
;
1110 SIZE_INFO
*SizeTable
;
1113 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, Database
);
1115 LocalTokenNumber
= Database
->Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1117 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1119 SizeTable
= Database
->Init
.SizeTable
;
1121 *MaxSize
= SizeTable
[SizeTableIdx
];
1123 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1126 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1128 // We have only one entry for VPD enabled PCD entry:
1130 // We consider current size is equal to MAX size.
1134 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1136 // We have only two entry for Non-Sku enabled PCD entry:
1140 return SizeTable
[SizeTableIdx
+ 1];
1143 // We have these entry for SKU enabled PCD entry
1145 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1147 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, Database
);
1148 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1149 if (SkuIdTable
[1 + Index
] == Database
->Init
.SystemSkuId
) {
1150 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1153 return SizeTable
[SizeTableIdx
+ 1];
1159 Set PCD value's size for POINTER type PCD.
1161 The POINTER type PCD's value will be stored into a buffer in specificed size.
1162 The max size of this PCD's value is described in PCD's definition in DEC file.
1164 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1165 @param CurrentSize Maximum size of PCD's value
1166 @param Database Pcd database in PEI phase.
1168 @retval TRUE Success to set PCD's value size, which is not exceed maximum size
1169 @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size
1174 IN UINTN LocalTokenNumberTableIdx
,
1175 IN OUT UINTN
*CurrentSize
,
1176 IN PEI_PCD_DATABASE
*Database
1180 UINTN LocalTokenNumber
;
1182 SIZE_INFO
*SizeTable
;
1186 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, Database
);
1188 LocalTokenNumber
= Database
->Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1190 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1192 SizeTable
= Database
->Init
.SizeTable
;
1194 MaxSize
= SizeTable
[SizeTableIdx
];
1196 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1199 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1201 // We shouldn't come here as we don't support SET for VPD
1206 if ((*CurrentSize
> MaxSize
) ||
1207 (*CurrentSize
== MAX_ADDRESS
)) {
1208 *CurrentSize
= MaxSize
;
1212 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1214 // We have only two entry for Non-Sku enabled PCD entry:
1218 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1222 // We have these entry for SKU enabled PCD entry
1224 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1226 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, Database
);
1227 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1228 if (SkuIdTable
[1 + Index
] == Database
->Init
.SystemSkuId
) {
1229 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1233 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;