2 All Pcd Ppi services are implemented here.
4 Copyright (c) 2006 - 2009, 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.
18 // Instance of PCD_PPI protocol is native implementation by MdePkg.
19 // This protocol instance support dynamic and dynamicEx type PCDs.
21 PCD_PPI mPcdPpiInstance
= {
54 PeiRegisterCallBackOnSet
,
55 PcdUnRegisterCallBackOnSet
,
57 PeiPcdGetNextTokenSpace
61 // Instance of EFI_PEI_PCD_PPI which is defined in PI 1.2 Vol 3.
62 // This PPI instance only support dyanmicEx type PCD.
64 EFI_PEI_PCD_PPI mEfiPcdPpiInstance
= {
80 (EFI_PEI_PCD_PPI_CALLBACK_ON_SET
) PeiRegisterCallBackOnSet
,
81 (EFI_PEI_PCD_PPI_CANCEL_CALLBACK
) PcdUnRegisterCallBackOnSet
,
83 PeiPcdGetNextTokenSpace
86 EFI_PEI_PPI_DESCRIPTOR mPpiPCD
= {
87 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
92 EFI_PEI_PPI_DESCRIPTOR mEfiPpiPCD
= {
93 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
99 Main entry for PCD PEIM driver.
101 This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.
103 @param FileHandle Handle of the file being invoked.
104 @param PeiServices Describes the list of possible PEI Services.
106 @return Status of install PCD_PPI
112 IN EFI_PEI_FILE_HANDLE FileHandle
,
113 IN CONST EFI_PEI_SERVICES
**PeiServices
121 // Install PCD_PPI which produce support for dynamic and dynamicEx PCD
123 Status
= PeiServicesInstallPpi (&mPpiPCD
);
124 ASSERT_EFI_ERROR (Status
);
127 // Install EFI_PCD_PPI which produce support for dynamicEx PCD which is defined
128 // in PI 1.2 Vol 3 specification.
130 Status
= PeiServicesInstallPpi (&mEfiPpiPCD
);
131 ASSERT_EFI_ERROR (Status
);
137 Sets the SKU value for subsequent calls to set or get PCD token values.
139 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
140 SetSku() is normally called only once by the system.
142 For each item (token), the database can hold a single value that applies to all SKUs,
143 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
144 SKU-specific values are called SKU enabled.
146 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
147 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
148 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
149 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
150 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
151 set for that Id, the results are unpredictable.
153 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
154 set values associated with a PCD token.
164 GetPcdDatabase()->Init
.SystemSkuId
= (SKU_ID
) SkuId
;
170 Retrieves an 8-bit value for a given PCD token.
172 Retrieves the current byte-sized value for a PCD token number.
173 If the TokenNumber is invalid, the results are unpredictable.
175 @param[in] TokenNumber The PCD token number.
177 @return The UINT8 value.
186 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
190 Retrieves an 16-bit value for a given PCD token.
192 Retrieves the current 16-bits value for a PCD token number.
193 If the TokenNumber is invalid, the results are unpredictable.
195 @param[in] TokenNumber The PCD token number.
197 @return The UINT16 value.
206 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
210 Retrieves an 32-bit value for a given PCD token.
212 Retrieves the current 32-bits value for a PCD token number.
213 If the TokenNumber is invalid, the results are unpredictable.
215 @param[in] TokenNumber The PCD token number.
217 @return The UINT32 value.
226 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
230 Retrieves an 64-bit value for a given PCD token.
232 Retrieves the current 64-bits value for a PCD token number.
233 If the TokenNumber is invalid, the results are unpredictable.
235 @param[in] TokenNumber The PCD token number.
237 @return The UINT64 value.
246 return ReadUnaligned64 (GetWorker (TokenNumber
, sizeof (UINT64
)));
250 Retrieves a pointer to a value for a given PCD token.
252 Retrieves the current pointer to the buffer for a PCD token number.
253 Do not make any assumptions about the alignment of the pointer that
254 is returned by this function call. If the TokenNumber is invalid,
255 the results are unpredictable.
257 @param[in] TokenNumber The PCD token number.
259 @return The pointer to the buffer to be retrieved.
268 return GetWorker (TokenNumber
, 0);
272 Retrieves a Boolean value for a given PCD token.
274 Retrieves the current boolean value for a PCD token number.
275 Do not make any assumptions about the alignment of the pointer that
276 is returned by this function call. If the TokenNumber is invalid,
277 the results are unpredictable.
279 @param[in] TokenNumber The PCD token number.
281 @return The Boolean value.
290 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
294 Retrieves the size of the value for a given PCD token.
296 Retrieves the current size of a particular PCD token.
297 If the TokenNumber is invalid, the results are unpredictable.
299 @param[in] TokenNumber The PCD token number.
301 @return The size of the value for the PCD token.
310 PEI_PCD_DATABASE
*PeiPcdDb
;
314 PeiPcdDb
= GetPcdDatabase ();
316 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
317 // We have to decrement TokenNumber by 1 to make it usable
318 // as the array index.
322 // EBC compiler is very choosy. It may report warning about comparison
323 // between UINTN and 0 . So we add 1 in each size of the
325 ASSERT (TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
327 Size
= (PeiPcdDb
->Init
.LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
331 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
333 return GetPtrTypeSize (TokenNumber
, &MaxSize
, PeiPcdDb
);
341 Retrieves an 8-bit value for a given PCD token.
343 Retrieves the 8-bit value of a particular PCD token.
344 If the TokenNumber is invalid or the token space
345 specified by Guid does not exist, the results are
348 @param[in] Guid The token space for the token number.
349 @param[in] ExTokenNumber The PCD token number.
351 @return The size 8-bit value for the PCD token.
357 IN CONST EFI_GUID
*Guid
,
358 IN UINTN ExTokenNumber
361 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT8
)));
365 Retrieves an 16-bit value for a given PCD token.
367 Retrieves the 16-bit value of a particular PCD token.
368 If the TokenNumber is invalid or the token space
369 specified by Guid does not exist, the results are
372 @param[in] Guid The token space for the token number.
373 @param[in] ExTokenNumber The PCD token number.
375 @return The size 16-bit value for the PCD token.
381 IN CONST EFI_GUID
*Guid
,
382 IN UINTN ExTokenNumber
385 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT16
)));
389 Retrieves an 32-bit value for a given PCD token.
391 Retrieves the 32-bit value of a particular PCD token.
392 If the TokenNumber is invalid or the token space
393 specified by Guid does not exist, the results are
396 @param[in] Guid The token space for the token number.
397 @param[in] ExTokenNumber The PCD token number.
399 @return The size 32-bit value for the PCD token.
405 IN CONST EFI_GUID
*Guid
,
406 IN UINTN ExTokenNumber
409 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT32
)));
413 Retrieves an 64-bit value for a given PCD token.
415 Retrieves the 64-bit value of a particular PCD token.
416 If the TokenNumber is invalid or the token space
417 specified by Guid does not exist, the results are
420 @param[in] Guid The token space for the token number.
421 @param[in] ExTokenNumber The PCD token number.
423 @return The size 64-bit value for the PCD token.
429 IN CONST EFI_GUID
*Guid
,
430 IN UINTN ExTokenNumber
433 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT64
)));
437 Retrieves a pointer to a value for a given PCD token.
439 Retrieves the current pointer to the buffer for a PCD token number.
440 Do not make any assumptions about the alignment of the pointer that
441 is returned by this function call. If the TokenNumber is invalid,
442 the results are unpredictable.
444 @param[in] Guid The token space for the token number.
445 @param[in] ExTokenNumber The PCD token number.
447 @return The pointer to the buffer to be retrieved.
453 IN CONST EFI_GUID
*Guid
,
454 IN UINTN ExTokenNumber
457 return ExGetWorker (Guid
, ExTokenNumber
, 0);
461 Retrieves an Boolean value for a given PCD token.
463 Retrieves the Boolean value of a particular PCD token.
464 If the TokenNumber is invalid or the token space
465 specified by Guid does not exist, the results are
468 @param[in] Guid The token space for the token number.
469 @param[in] ExTokenNumber The PCD token number.
471 @return The size Boolean value for the PCD token.
477 IN CONST EFI_GUID
*Guid
,
478 IN UINTN ExTokenNumber
481 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof (BOOLEAN
)));
485 Retrieves the size of the value for a given PCD token.
487 Retrieves the current size of a particular PCD token.
488 If the TokenNumber is invalid, the results are unpredictable.
490 @param[in] Guid The token space for the token number.
491 @param[in] ExTokenNumber The PCD token number.
493 @return The size of the value for the PCD token.
499 IN CONST EFI_GUID
*Guid
,
500 IN UINTN ExTokenNumber
503 return PeiPcdGetSize (GetExPcdTokenNumber (Guid
, ExTokenNumber
));
507 Sets an 8-bit value for a given PCD token.
509 When the PCD service sets a value, it will check to ensure that the
510 size of the value being set is compatible with the Token's existing definition.
511 If it is not, an error will be returned.
513 @param[in] TokenNumber The PCD token number.
514 @param[in] Value The value to set for the PCD token.
516 @retval EFI_SUCCESS Procedure returned successfully.
517 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
518 being set was incompatible with a call to this function.
519 Use GetSize() to retrieve the size of the target data.
520 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
526 IN UINTN TokenNumber
,
530 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
534 Sets an 16-bit value for a given PCD token.
536 When the PCD service sets a value, it will check to ensure that the
537 size of the value being set is compatible with the Token's existing definition.
538 If it is not, an error will be returned.
540 @param[in] TokenNumber The PCD token number.
541 @param[in] Value The value to set for the PCD token.
543 @retval EFI_SUCCESS Procedure returned successfully.
544 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
545 being set was incompatible with a call to this function.
546 Use GetSize() to retrieve the size of the target data.
547 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
553 IN UINTN TokenNumber
,
557 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
561 Sets an 32-bit value for a given PCD token.
563 When the PCD service sets a value, it will check to ensure that the
564 size of the value being set is compatible with the Token's existing definition.
565 If it is not, an error will be returned.
567 @param[in] TokenNumber The PCD token number.
568 @param[in] Value The value to set for the PCD token.
570 @retval EFI_SUCCESS Procedure returned successfully.
571 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
572 being set was incompatible with a call to this function.
573 Use GetSize() to retrieve the size of the target data.
574 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
580 IN UINTN TokenNumber
,
584 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
588 Sets an 64-bit value for a given PCD token.
590 When the PCD service sets a value, it will check to ensure that the
591 size of the value being set is compatible with the Token's existing definition.
592 If it is not, an error will be returned.
594 @param[in] TokenNumber The PCD token number.
595 @param[in] Value The value to set for the PCD token.
597 @retval EFI_SUCCESS Procedure returned successfully.
598 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
599 being set was incompatible with a call to this function.
600 Use GetSize() to retrieve the size of the target data.
601 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
607 IN UINTN TokenNumber
,
611 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
615 Sets a value of a specified size for a given PCD token.
617 When the PCD service sets a value, it will check to ensure that the
618 size of the value being set is compatible with the Token's existing definition.
619 If it is not, an error will be returned.
621 @param[in] TokenNumber The PCD token number.
622 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
623 On input, if the SizeOfValue is greater than the maximum size supported
624 for this TokenNumber then the output value of SizeOfValue will reflect
625 the maximum size supported for this TokenNumber.
626 @param[in] Buffer The buffer to set for the PCD token.
628 @retval EFI_SUCCESS Procedure returned successfully.
629 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
630 being set was incompatible with a call to this function.
631 Use GetSize() to retrieve the size of the target data.
632 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
638 IN UINTN TokenNumber
,
639 IN OUT UINTN
*SizeOfBuffer
,
643 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
647 Sets an Boolean value for a given PCD token.
649 When the PCD service sets a value, it will check to ensure that the
650 size of the value being set is compatible with the Token's existing definition.
651 If it is not, an error will be returned.
653 @param[in] TokenNumber The PCD token number.
654 @param[in] Value The value to set for the PCD token.
656 @retval EFI_SUCCESS Procedure returned successfully.
657 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
658 being set was incompatible with a call to this function.
659 Use GetSize() to retrieve the size of the target data.
660 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
666 IN UINTN TokenNumber
,
670 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
674 Sets an 8-bit value for a given PCD token.
676 When the PCD service sets a value, it will check to ensure that the
677 size of the value being set is compatible with the Token's existing definition.
678 If it is not, an error will be returned.
680 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
681 @param[in] ExTokenNumber The PCD token number.
682 @param[in] Value The value to set for the PCD token.
684 @retval EFI_SUCCESS Procedure returned successfully.
685 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
686 being set was incompatible with a call to this function.
687 Use GetSize() to retrieve the size of the target data.
688 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
694 IN CONST EFI_GUID
*Guid
,
695 IN UINTN ExTokenNumber
,
699 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
703 Sets an 16-bit value for a given PCD token.
705 When the PCD service sets a value, it will check to ensure that the
706 size of the value being set is compatible with the Token's existing definition.
707 If it is not, an error will be returned.
709 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
710 @param[in] ExTokenNumber The PCD token number.
711 @param[in] Value The value to set for the PCD token.
713 @retval EFI_SUCCESS Procedure returned successfully.
714 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
715 being set was incompatible with a call to this function.
716 Use GetSize() to retrieve the size of the target data.
717 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
723 IN CONST EFI_GUID
*Guid
,
724 IN UINTN ExTokenNumber
,
728 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
732 Sets an 32-bit value for a given PCD token.
734 When the PCD service sets a value, it will check to ensure that the
735 size of the value being set is compatible with the Token's existing definition.
736 If it is not, an error will be returned.
738 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
739 @param[in] ExTokenNumber The PCD token number.
740 @param[in] Value The value to set for the PCD token.
742 @retval EFI_SUCCESS Procedure returned successfully.
743 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
744 being set was incompatible with a call to this function.
745 Use GetSize() to retrieve the size of the target data.
746 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
752 IN CONST EFI_GUID
*Guid
,
753 IN UINTN ExTokenNumber
,
757 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
761 Sets an 64-bit value for a given PCD token.
763 When the PCD service sets a value, it will check to ensure that the
764 size of the value being set is compatible with the Token's existing definition.
765 If it is not, an error will be returned.
767 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
768 @param[in] ExTokenNumber The PCD token number.
769 @param[in] Value The value to set for the PCD token.
771 @retval EFI_SUCCESS Procedure returned successfully.
772 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
773 being set was incompatible with a call to this function.
774 Use GetSize() to retrieve the size of the target data.
775 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
781 IN CONST EFI_GUID
*Guid
,
782 IN UINTN ExTokenNumber
,
786 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
790 Sets a value of a specified size for a given PCD token.
792 When the PCD service sets a value, it will check to ensure that the
793 size of the value being set is compatible with the Token's existing definition.
794 If it is not, an error will be returned.
796 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
797 @param[in] ExTokenNumber The PCD token number.
798 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
799 On input, if the SizeOfValue is greater than the maximum size supported
800 for this TokenNumber then the output value of SizeOfValue will reflect
801 the maximum size supported for this TokenNumber.
802 @param[in] Value The buffer to set for the PCD token.
804 @retval EFI_SUCCESS Procedure returned successfully.
805 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
806 being set was incompatible with a call to this function.
807 Use GetSize() to retrieve the size of the target data.
808 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
814 IN CONST EFI_GUID
*Guid
,
815 IN UINTN ExTokenNumber
,
816 IN OUT UINTN
*SizeOfBuffer
,
820 return ExSetWorker (ExTokenNumber
, Guid
, Value
, SizeOfBuffer
, TRUE
);
824 Sets an Boolean value for a given PCD token.
826 When the PCD service sets a value, it will check to ensure that the
827 size of the value being set is compatible with the Token's existing definition.
828 If it is not, an error will be returned.
830 @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
831 @param [in] ExTokenNumber The PCD token number.
832 @param [in] Value The value to set for the PCD token.
834 @retval EFI_SUCCESS Procedure returned successfully.
835 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
836 being set was incompatible with a call to this function.
837 Use GetSize() to retrieve the size of the target data.
838 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
844 IN CONST EFI_GUID
*Guid
,
845 IN UINTN ExTokenNumber
,
849 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
853 Specifies a function to be called anytime the value of a designated token is changed.
855 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
856 @param[in] ExTokenNumber The PCD token number.
857 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
859 @retval EFI_SUCCESS The PCD service has successfully established a call event
860 for the CallBackToken requested.
861 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
866 PeiRegisterCallBackOnSet (
867 IN CONST EFI_GUID
*Guid
, OPTIONAL
868 IN UINTN ExTokenNumber
,
869 IN PCD_PPI_CALLBACK CallBackFunction
872 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
873 return EFI_UNSUPPORTED
;
876 if (CallBackFunction
== NULL
) {
877 return EFI_INVALID_PARAMETER
;
880 return PeiRegisterCallBackWorker (ExTokenNumber
, Guid
, CallBackFunction
, TRUE
);
884 Cancels a previously set callback function for a particular PCD token number.
886 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
887 @param[in] ExTokenNumber The PCD token number.
888 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
890 @retval EFI_SUCCESS The PCD service has successfully established a call event
891 for the CallBackToken requested.
892 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
897 PcdUnRegisterCallBackOnSet (
898 IN CONST EFI_GUID
*Guid
, OPTIONAL
899 IN UINTN ExTokenNumber
,
900 IN PCD_PPI_CALLBACK CallBackFunction
903 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
904 return EFI_UNSUPPORTED
;
907 if (CallBackFunction
== NULL
) {
908 return EFI_INVALID_PARAMETER
;
911 return PeiRegisterCallBackWorker (ExTokenNumber
, Guid
, CallBackFunction
, FALSE
);
915 Retrieves the next valid token number in a given namespace.
917 This is useful since the PCD infrastructure contains a sparse list of token numbers,
918 and one cannot a priori know what token numbers are valid in the database.
920 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
921 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
922 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
923 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
924 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
925 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
926 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
927 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
930 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
931 This is an optional parameter that may be NULL. If this parameter is NULL, then a request
932 is being made to retrieve tokens from the default token space.
933 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.
935 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.
936 Or the input token number is already the last valid token number in the PCD database.
937 In the later case, *TokenNumber is updated with the value of 0.
938 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
944 IN CONST EFI_GUID
*Guid
, OPTIONAL
945 IN OUT UINTN
*TokenNumber
949 PEI_PCD_DATABASE
*PeiPcdDb
;
951 DYNAMICEX_MAPPING
*ExMapTable
;
954 BOOLEAN PeiExMapTableEmpty
;
956 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable
)) {
957 return EFI_UNSUPPORTED
;
960 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
963 if (*TokenNumber
> PEI_NEX_TOKEN_NUMBER
) {
964 return EFI_NOT_FOUND
;
967 if (*TokenNumber
> PEI_NEX_TOKEN_NUMBER
) {
968 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
972 if (PeiExMapTableEmpty
) {
973 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
978 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
982 PeiPcdDb
= GetPcdDatabase ();
984 MatchGuid
= ScanGuid (PeiPcdDb
->Init
.GuidTable
, sizeof(PeiPcdDb
->Init
.GuidTable
), Guid
);
986 if (MatchGuid
== NULL
) {
987 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
988 return EFI_NOT_FOUND
;
991 GuidTableIdx
= MatchGuid
- PeiPcdDb
->Init
.GuidTable
;
993 ExMapTable
= PeiPcdDb
->Init
.ExMapTable
;
997 // Locate the GUID in ExMapTable first.
999 for (Index
= 0; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
1000 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1007 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
1008 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
1012 for ( ; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
1013 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
1015 if (Index
== PEI_EXMAPPING_TABLE_SIZE
) {
1017 // Exceed the length of ExMap Table
1019 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1022 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1023 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
1026 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1031 return EFI_NOT_FOUND
;
1035 return EFI_NOT_FOUND
;
1039 Retrieves the next valid PCD token namespace for a given namespace.
1041 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates
1042 a known token namespace from which the search will start. On output,
1043 it designates the next valid token namespace on the platform. If the input
1044 token namespace does not exist on the platform, an error is returned and
1045 the value of *Guid is undefined. If *Guid is NULL, then the GUID of the
1046 first token space of the current platform is assigned to *Guid the function
1047 return EFI_SUCCESS. If *Guid is NULL and there is no namespace exist in
1048 the platform other than the default (NULL) tokennamespace, *Guid is unchanged
1049 and the function return EFI_SUCCESS. If this input token namespace is the last
1050 namespace on the platform, *Guid will be assigned to NULL and the function return
1053 @retval EFI_SUCCESS The PCD service retrieved the next valid token space Guid.
1054 Or the input token space Guid is already the last valid token space Guid
1055 in the PCD database. In the later case, *Guid is updated with the value of NULL.
1056 @retval EFI_NOT_FOUND If the input token namespace does not exist on the platform.
1061 PeiPcdGetNextTokenSpace (
1062 IN OUT CONST EFI_GUID
**Guid
1066 EFI_GUID
*MatchGuid
;
1067 PEI_PCD_DATABASE
*PeiPcdDb
;
1068 DYNAMICEX_MAPPING
*ExMapTable
;
1071 BOOLEAN PeiExMapTableEmpty
;
1073 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable
)) {
1074 return EFI_UNSUPPORTED
;
1077 ASSERT (Guid
!= NULL
);
1079 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
1081 if (PeiExMapTableEmpty
) {
1082 if (*Guid
!= NULL
) {
1083 return EFI_NOT_FOUND
;
1090 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
1094 PeiPcdDb
= GetPcdDatabase ();
1096 ExMapTable
= PeiPcdDb
->Init
.ExMapTable
;
1098 if (*Guid
== NULL
) {
1100 // return the first Token Space Guid.
1102 *Guid
= &PeiPcdDb
->Init
.GuidTable
[ExMapTable
[0].ExGuidIndex
];
1106 MatchGuid
= ScanGuid (PeiPcdDb
->Init
.GuidTable
, sizeof(PeiPcdDb
->Init
.GuidTable
), *Guid
);
1108 if (MatchGuid
== NULL
) {
1109 return EFI_NOT_FOUND
;
1112 GuidTableIdx
= MatchGuid
- PeiPcdDb
->Init
.GuidTable
;
1115 for (Index
= 0; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
1116 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1124 for ( ; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++ ) {
1125 if (ExMapTable
[Index
].ExGuidIndex
!= GuidTableIdx
) {
1126 *Guid
= &PeiPcdDb
->Init
.GuidTable
[ExMapTable
[Index
].ExGuidIndex
];
1134 return EFI_NOT_FOUND
;
1139 Get PCD value's size for POINTER type PCD.
1141 The POINTER type PCD's value will be stored into a buffer in specificed size.
1142 The max size of this PCD's value is described in PCD's definition in DEC file.
1144 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1145 @param MaxSize Maximum size of PCD's value
1146 @param Database Pcd database in PEI phase.
1148 @return PCD value's size for POINTER type PCD.
1153 IN UINTN LocalTokenNumberTableIdx
,
1155 IN PEI_PCD_DATABASE
*Database
1159 UINTN LocalTokenNumber
;
1161 SIZE_INFO
*SizeTable
;
1164 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, Database
);
1166 LocalTokenNumber
= Database
->Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1168 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1170 SizeTable
= Database
->Init
.SizeTable
;
1172 *MaxSize
= SizeTable
[SizeTableIdx
];
1174 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1177 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1179 // We have only one entry for VPD enabled PCD entry:
1181 // We consider current size is equal to MAX size.
1185 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1187 // We have only two entry for Non-Sku enabled PCD entry:
1191 return SizeTable
[SizeTableIdx
+ 1];
1194 // We have these entry for SKU enabled PCD entry
1196 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1198 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, Database
);
1199 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1200 if (SkuIdTable
[1 + Index
] == Database
->Init
.SystemSkuId
) {
1201 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1204 return SizeTable
[SizeTableIdx
+ 1];
1210 Set PCD value's size for POINTER type PCD.
1212 The POINTER type PCD's value will be stored into a buffer in specificed size.
1213 The max size of this PCD's value is described in PCD's definition in DEC file.
1215 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1216 @param CurrentSize Maximum size of PCD's value
1217 @param Database Pcd database in PEI phase.
1219 @retval TRUE Success to set PCD's value size, which is not exceed maximum size
1220 @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size
1225 IN UINTN LocalTokenNumberTableIdx
,
1226 IN OUT UINTN
*CurrentSize
,
1227 IN PEI_PCD_DATABASE
*Database
1231 UINTN LocalTokenNumber
;
1233 SIZE_INFO
*SizeTable
;
1237 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, Database
);
1239 LocalTokenNumber
= Database
->Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1241 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1243 SizeTable
= Database
->Init
.SizeTable
;
1245 MaxSize
= SizeTable
[SizeTableIdx
];
1247 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1250 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1252 // We shouldn't come here as we don't support SET for VPD
1257 if ((*CurrentSize
> MaxSize
) ||
1258 (*CurrentSize
== MAX_ADDRESS
)) {
1259 *CurrentSize
= MaxSize
;
1263 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1265 // We have only two entry for Non-Sku enabled PCD entry:
1269 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1273 // We have these entry for SKU enabled PCD entry
1275 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1277 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, Database
);
1278 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1279 if (SkuIdTable
[1 + Index
] == Database
->Init
.SystemSkuId
) {
1280 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1284 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;