2 All Pcd Ppi services are implemented here.
4 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
5 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 EDKII native implementation.
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 mPpiList
[] = {
88 EFI_PEI_PPI_DESCRIPTOR_PPI
,
93 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
100 Main entry for PCD PEIM driver.
102 This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.
104 @param FileHandle Handle of the file being invoked.
105 @param PeiServices Describes the list of possible PEI Services.
107 @return Status of install PCD_PPI
113 IN EFI_PEI_FILE_HANDLE FileHandle
,
114 IN CONST EFI_PEI_SERVICES
**PeiServices
122 // Install PCD_PPI and EFI_PEI_PCD_PPI.
124 Status
= PeiServicesInstallPpi (&mPpiList
[0]);
125 ASSERT_EFI_ERROR (Status
);
131 Sets the SKU value for subsequent calls to set or get PCD token values.
133 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
134 SetSku() is normally called only once by the system.
136 For each item (token), the database can hold a single value that applies to all SKUs,
137 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
138 SKU-specific values are called SKU enabled.
140 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
141 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
142 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
143 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
144 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
145 set for that Id, the results are unpredictable.
147 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
148 set values associated with a PCD token.
158 GetPcdDatabase()->Init
.SystemSkuId
= (SKU_ID
) SkuId
;
164 Retrieves an 8-bit value for a given PCD token.
166 Retrieves the current byte-sized value for a PCD token number.
167 If the TokenNumber is invalid, the results are unpredictable.
169 @param[in] TokenNumber The PCD token number.
171 @return The UINT8 value.
180 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
184 Retrieves an 16-bit value for a given PCD token.
186 Retrieves the current 16-bits value for a PCD token number.
187 If the TokenNumber is invalid, the results are unpredictable.
189 @param[in] TokenNumber The PCD token number.
191 @return The UINT16 value.
200 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
204 Retrieves an 32-bit value for a given PCD token.
206 Retrieves the current 32-bits value for a PCD token number.
207 If the TokenNumber is invalid, the results are unpredictable.
209 @param[in] TokenNumber The PCD token number.
211 @return The UINT32 value.
220 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
224 Retrieves an 64-bit value for a given PCD token.
226 Retrieves the current 64-bits value for a PCD token number.
227 If the TokenNumber is invalid, the results are unpredictable.
229 @param[in] TokenNumber The PCD token number.
231 @return The UINT64 value.
240 return ReadUnaligned64 (GetWorker (TokenNumber
, sizeof (UINT64
)));
244 Retrieves a pointer to a value for a given PCD token.
246 Retrieves the current pointer to the buffer for a PCD token number.
247 Do not make any assumptions about the alignment of the pointer that
248 is returned by this function call. If the TokenNumber is invalid,
249 the results are unpredictable.
251 @param[in] TokenNumber The PCD token number.
253 @return The pointer to the buffer to be retrieved.
262 return GetWorker (TokenNumber
, 0);
266 Retrieves a Boolean value for a given PCD token.
268 Retrieves the current boolean value for a PCD token number.
269 Do not make any assumptions about the alignment of the pointer that
270 is returned by this function call. If the TokenNumber is invalid,
271 the results are unpredictable.
273 @param[in] TokenNumber The PCD token number.
275 @return The Boolean value.
284 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
288 Retrieves the size of the value for a given PCD token.
290 Retrieves the current size of a particular PCD token.
291 If the TokenNumber is invalid, the results are unpredictable.
293 @param[in] TokenNumber The PCD token number.
295 @return The size of the value for the PCD token.
304 PEI_PCD_DATABASE
*PeiPcdDb
;
308 PeiPcdDb
= GetPcdDatabase ();
310 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
311 // We have to decrement TokenNumber by 1 to make it usable
312 // as the array index.
316 // EBC compiler is very choosy. It may report warning about comparison
317 // between UINTN and 0 . So we add 1 in each size of the
319 ASSERT (TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
321 Size
= (PeiPcdDb
->Init
.LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
325 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
327 return GetPtrTypeSize (TokenNumber
, &MaxSize
, PeiPcdDb
);
335 Retrieves an 8-bit value for a given PCD token.
337 Retrieves the 8-bit value of a particular PCD token.
338 If the TokenNumber is invalid or the token space
339 specified by Guid does not exist, the results are
342 @param[in] Guid The token space for the token number.
343 @param[in] ExTokenNumber The PCD token number.
345 @return The size 8-bit value for the PCD token.
351 IN CONST EFI_GUID
*Guid
,
352 IN UINTN ExTokenNumber
355 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT8
)));
359 Retrieves an 16-bit value for a given PCD token.
361 Retrieves the 16-bit value of a particular PCD token.
362 If the TokenNumber is invalid or the token space
363 specified by Guid does not exist, the results are
366 @param[in] Guid The token space for the token number.
367 @param[in] ExTokenNumber The PCD token number.
369 @return The size 16-bit value for the PCD token.
375 IN CONST EFI_GUID
*Guid
,
376 IN UINTN ExTokenNumber
379 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT16
)));
383 Retrieves an 32-bit value for a given PCD token.
385 Retrieves the 32-bit value of a particular PCD token.
386 If the TokenNumber is invalid or the token space
387 specified by Guid does not exist, the results are
390 @param[in] Guid The token space for the token number.
391 @param[in] ExTokenNumber The PCD token number.
393 @return The size 32-bit value for the PCD token.
399 IN CONST EFI_GUID
*Guid
,
400 IN UINTN ExTokenNumber
403 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT32
)));
407 Retrieves an 64-bit value for a given PCD token.
409 Retrieves the 64-bit value of a particular PCD token.
410 If the TokenNumber is invalid or the token space
411 specified by Guid does not exist, the results are
414 @param[in] Guid The token space for the token number.
415 @param[in] ExTokenNumber The PCD token number.
417 @return The size 64-bit value for the PCD token.
423 IN CONST EFI_GUID
*Guid
,
424 IN UINTN ExTokenNumber
427 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT64
)));
431 Retrieves a pointer to a value for a given PCD token.
433 Retrieves the current pointer to the buffer for a PCD token number.
434 Do not make any assumptions about the alignment of the pointer that
435 is returned by this function call. If the TokenNumber is invalid,
436 the results are unpredictable.
438 @param[in] Guid The token space for the token number.
439 @param[in] ExTokenNumber The PCD token number.
441 @return The pointer to the buffer to be retrieved.
447 IN CONST EFI_GUID
*Guid
,
448 IN UINTN ExTokenNumber
451 return ExGetWorker (Guid
, ExTokenNumber
, 0);
455 Retrieves an Boolean value for a given PCD token.
457 Retrieves the Boolean value of a particular PCD token.
458 If the TokenNumber is invalid or the token space
459 specified by Guid does not exist, the results are
462 @param[in] Guid The token space for the token number.
463 @param[in] ExTokenNumber The PCD token number.
465 @return The size Boolean value for the PCD token.
471 IN CONST EFI_GUID
*Guid
,
472 IN UINTN ExTokenNumber
475 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof (BOOLEAN
)));
479 Retrieves the size of the value for a given PCD token.
481 Retrieves the current size of a particular PCD token.
482 If the TokenNumber is invalid, the results are unpredictable.
484 @param[in] Guid The token space for the token number.
485 @param[in] ExTokenNumber The PCD token number.
487 @return The size of the value for the PCD token.
493 IN CONST EFI_GUID
*Guid
,
494 IN UINTN ExTokenNumber
497 return PeiPcdGetSize (GetExPcdTokenNumber (Guid
, ExTokenNumber
));
501 Sets an 8-bit value for a given PCD token.
503 When the PCD service sets a value, it will check to ensure that the
504 size of the value being set is compatible with the Token's existing definition.
505 If it is not, an error will be returned.
507 @param[in] TokenNumber The PCD token number.
508 @param[in] Value The value to set for the PCD token.
510 @retval EFI_SUCCESS Procedure returned successfully.
511 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
512 being set was incompatible with a call to this function.
513 Use GetSize() to retrieve the size of the target data.
514 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
520 IN UINTN TokenNumber
,
524 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
528 Sets an 16-bit value for a given PCD token.
530 When the PCD service sets a value, it will check to ensure that the
531 size of the value being set is compatible with the Token's existing definition.
532 If it is not, an error will be returned.
534 @param[in] TokenNumber The PCD token number.
535 @param[in] Value The value to set for the PCD token.
537 @retval EFI_SUCCESS Procedure returned successfully.
538 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
539 being set was incompatible with a call to this function.
540 Use GetSize() to retrieve the size of the target data.
541 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
547 IN UINTN TokenNumber
,
551 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
555 Sets an 32-bit value for a given PCD token.
557 When the PCD service sets a value, it will check to ensure that the
558 size of the value being set is compatible with the Token's existing definition.
559 If it is not, an error will be returned.
561 @param[in] TokenNumber The PCD token number.
562 @param[in] Value The value to set for the PCD token.
564 @retval EFI_SUCCESS Procedure returned successfully.
565 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
566 being set was incompatible with a call to this function.
567 Use GetSize() to retrieve the size of the target data.
568 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
574 IN UINTN TokenNumber
,
578 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
582 Sets an 64-bit value for a given PCD token.
584 When the PCD service sets a value, it will check to ensure that the
585 size of the value being set is compatible with the Token's existing definition.
586 If it is not, an error will be returned.
588 @param[in] TokenNumber The PCD token number.
589 @param[in] Value The value to set for the PCD token.
591 @retval EFI_SUCCESS Procedure returned successfully.
592 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
593 being set was incompatible with a call to this function.
594 Use GetSize() to retrieve the size of the target data.
595 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
601 IN UINTN TokenNumber
,
605 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
609 Sets a value of a specified size 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, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
617 On input, if the SizeOfValue is greater than the maximum size supported
618 for this TokenNumber then the output value of SizeOfValue will reflect
619 the maximum size supported for this TokenNumber.
620 @param[in] Buffer The buffer to set for the PCD token.
622 @retval EFI_SUCCESS Procedure returned successfully.
623 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
624 being set was incompatible with a call to this function.
625 Use GetSize() to retrieve the size of the target data.
626 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
632 IN UINTN TokenNumber
,
633 IN OUT UINTN
*SizeOfBuffer
,
637 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
641 Sets an Boolean value for a given PCD token.
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.
647 @param[in] TokenNumber The PCD token number.
648 @param[in] Value The value to set for the PCD token.
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.
660 IN UINTN TokenNumber
,
664 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
668 Sets an 8-bit value for a given PCD token.
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.
674 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
675 @param[in] ExTokenNumber The PCD token number.
676 @param[in] Value The value to set for the PCD token.
678 @retval EFI_SUCCESS Procedure returned successfully.
679 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
680 being set was incompatible with a call to this function.
681 Use GetSize() to retrieve the size of the target data.
682 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
688 IN CONST EFI_GUID
*Guid
,
689 IN UINTN ExTokenNumber
,
693 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
697 Sets an 16-bit value for a given PCD token.
699 When the PCD service sets a value, it will check to ensure that the
700 size of the value being set is compatible with the Token's existing definition.
701 If it is not, an error will be returned.
703 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
704 @param[in] ExTokenNumber The PCD token number.
705 @param[in] Value The value to set for the PCD token.
707 @retval EFI_SUCCESS Procedure returned successfully.
708 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
709 being set was incompatible with a call to this function.
710 Use GetSize() to retrieve the size of the target data.
711 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
717 IN CONST EFI_GUID
*Guid
,
718 IN UINTN ExTokenNumber
,
722 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
726 Sets an 32-bit value for a given PCD token.
728 When the PCD service sets a value, it will check to ensure that the
729 size of the value being set is compatible with the Token's existing definition.
730 If it is not, an error will be returned.
732 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
733 @param[in] ExTokenNumber The PCD token number.
734 @param[in] Value The value to set for the PCD token.
736 @retval EFI_SUCCESS Procedure returned successfully.
737 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
738 being set was incompatible with a call to this function.
739 Use GetSize() to retrieve the size of the target data.
740 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
746 IN CONST EFI_GUID
*Guid
,
747 IN UINTN ExTokenNumber
,
751 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
755 Sets an 64-bit value for a given PCD token.
757 When the PCD service sets a value, it will check to ensure that the
758 size of the value being set is compatible with the Token's existing definition.
759 If it is not, an error will be returned.
761 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
762 @param[in] ExTokenNumber The PCD token number.
763 @param[in] Value The value to set for the PCD token.
765 @retval EFI_SUCCESS Procedure returned successfully.
766 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
767 being set was incompatible with a call to this function.
768 Use GetSize() to retrieve the size of the target data.
769 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
775 IN CONST EFI_GUID
*Guid
,
776 IN UINTN ExTokenNumber
,
780 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
784 Sets a value of a specified size for a given PCD token.
786 When the PCD service sets a value, it will check to ensure that the
787 size of the value being set is compatible with the Token's existing definition.
788 If it is not, an error will be returned.
790 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
791 @param[in] ExTokenNumber The PCD token number.
792 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
793 On input, if the SizeOfValue is greater than the maximum size supported
794 for this TokenNumber then the output value of SizeOfValue will reflect
795 the maximum size supported for this TokenNumber.
796 @param[in] Value The buffer to set for the PCD token.
798 @retval EFI_SUCCESS Procedure returned successfully.
799 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
800 being set was incompatible with a call to this function.
801 Use GetSize() to retrieve the size of the target data.
802 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
808 IN CONST EFI_GUID
*Guid
,
809 IN UINTN ExTokenNumber
,
810 IN OUT UINTN
*SizeOfBuffer
,
814 return ExSetWorker (ExTokenNumber
, Guid
, Value
, SizeOfBuffer
, TRUE
);
818 Sets an Boolean value for a given PCD token.
820 When the PCD service sets a value, it will check to ensure that the
821 size of the value being set is compatible with the Token's existing definition.
822 If it is not, an error will be returned.
824 @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
825 @param [in] ExTokenNumber The PCD token number.
826 @param [in] Value The value to set for the PCD token.
828 @retval EFI_SUCCESS Procedure returned successfully.
829 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
830 being set was incompatible with a call to this function.
831 Use GetSize() to retrieve the size of the target data.
832 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
838 IN CONST EFI_GUID
*Guid
,
839 IN UINTN ExTokenNumber
,
843 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
847 Specifies a function to be called anytime the value of a designated token is changed.
849 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
850 @param[in] ExTokenNumber The PCD token number.
851 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
853 @retval EFI_SUCCESS The PCD service has successfully established a call event
854 for the CallBackToken requested.
855 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
860 PeiRegisterCallBackOnSet (
861 IN CONST EFI_GUID
*Guid
, OPTIONAL
862 IN UINTN ExTokenNumber
,
863 IN PCD_PPI_CALLBACK CallBackFunction
866 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
867 return EFI_UNSUPPORTED
;
870 if (CallBackFunction
== NULL
) {
871 return EFI_INVALID_PARAMETER
;
874 return PeiRegisterCallBackWorker (ExTokenNumber
, Guid
, CallBackFunction
, TRUE
);
878 Cancels a previously set callback function for a particular PCD token number.
880 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
881 @param[in] ExTokenNumber The PCD token number.
882 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
884 @retval EFI_SUCCESS The PCD service has successfully established a call event
885 for the CallBackToken requested.
886 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
891 PcdUnRegisterCallBackOnSet (
892 IN CONST EFI_GUID
*Guid
, OPTIONAL
893 IN UINTN ExTokenNumber
,
894 IN PCD_PPI_CALLBACK CallBackFunction
897 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
898 return EFI_UNSUPPORTED
;
901 if (CallBackFunction
== NULL
) {
902 return EFI_INVALID_PARAMETER
;
905 return PeiRegisterCallBackWorker (ExTokenNumber
, Guid
, CallBackFunction
, FALSE
);
909 Retrieves the next valid token number in a given namespace.
911 This is useful since the PCD infrastructure contains a sparse list of token numbers,
912 and one cannot a priori know what token numbers are valid in the database.
914 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
915 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
916 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
917 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
918 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
919 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
920 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
921 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
924 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
925 This is an optional parameter that may be NULL. If this parameter is NULL, then a request
926 is being made to retrieve tokens from the default token space.
927 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.
929 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.
930 Or the input token number is already the last valid token number in the PCD database.
931 In the later case, *TokenNumber is updated with the value of 0.
932 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
938 IN CONST EFI_GUID
*Guid
, OPTIONAL
939 IN OUT UINTN
*TokenNumber
943 PEI_PCD_DATABASE
*PeiPcdDb
;
945 DYNAMICEX_MAPPING
*ExMapTable
;
948 BOOLEAN PeiExMapTableEmpty
;
950 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable
)) {
951 return EFI_UNSUPPORTED
;
954 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
957 if (*TokenNumber
> PEI_NEX_TOKEN_NUMBER
) {
958 return EFI_NOT_FOUND
;
961 if (*TokenNumber
> PEI_NEX_TOKEN_NUMBER
) {
962 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
966 if (PeiExMapTableEmpty
) {
967 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
972 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
976 PeiPcdDb
= GetPcdDatabase ();
978 MatchGuid
= ScanGuid (PeiPcdDb
->Init
.GuidTable
, sizeof(PeiPcdDb
->Init
.GuidTable
), Guid
);
980 if (MatchGuid
== NULL
) {
981 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
982 return EFI_NOT_FOUND
;
985 GuidTableIdx
= MatchGuid
- PeiPcdDb
->Init
.GuidTable
;
987 ExMapTable
= PeiPcdDb
->Init
.ExMapTable
;
991 // Locate the GUID in ExMapTable first.
993 for (Index
= 0; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
994 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1001 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
1002 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
1006 for ( ; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
1007 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
1009 if (Index
== PEI_EXMAPPING_TABLE_SIZE
) {
1011 // Exceed the length of ExMap Table
1013 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1016 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1017 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
1020 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1025 return EFI_NOT_FOUND
;
1029 return EFI_NOT_FOUND
;
1033 Retrieves the next valid PCD token namespace for a given namespace.
1035 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates
1036 a known token namespace from which the search will start. On output,
1037 it designates the next valid token namespace on the platform. If the input
1038 token namespace does not exist on the platform, an error is returned and
1039 the value of *Guid is undefined. If *Guid is NULL, then the GUID of the
1040 first token space of the current platform is assigned to *Guid the function
1041 return EFI_SUCCESS. If *Guid is NULL and there is no namespace exist in
1042 the platform other than the default (NULL) tokennamespace, *Guid is unchanged
1043 and the function return EFI_SUCCESS. If this input token namespace is the last
1044 namespace on the platform, *Guid will be assigned to NULL and the function return
1047 @retval EFI_SUCCESS The PCD service retrieved the next valid token space Guid.
1048 Or the input token space Guid is already the last valid token space Guid
1049 in the PCD database. In the later case, *Guid is updated with the value of NULL.
1050 @retval EFI_NOT_FOUND If the input token namespace does not exist on the platform.
1055 PeiPcdGetNextTokenSpace (
1056 IN OUT CONST EFI_GUID
**Guid
1060 EFI_GUID
*MatchGuid
;
1061 PEI_PCD_DATABASE
*PeiPcdDb
;
1062 DYNAMICEX_MAPPING
*ExMapTable
;
1065 BOOLEAN PeiExMapTableEmpty
;
1067 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable
)) {
1068 return EFI_UNSUPPORTED
;
1071 ASSERT (Guid
!= NULL
);
1073 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
1075 if (PeiExMapTableEmpty
) {
1076 if (*Guid
!= NULL
) {
1077 return EFI_NOT_FOUND
;
1084 // Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
1088 PeiPcdDb
= GetPcdDatabase ();
1090 ExMapTable
= PeiPcdDb
->Init
.ExMapTable
;
1092 if (*Guid
== NULL
) {
1094 // return the first Token Space Guid.
1096 *Guid
= &PeiPcdDb
->Init
.GuidTable
[ExMapTable
[0].ExGuidIndex
];
1100 MatchGuid
= ScanGuid (PeiPcdDb
->Init
.GuidTable
, sizeof(PeiPcdDb
->Init
.GuidTable
), *Guid
);
1102 if (MatchGuid
== NULL
) {
1103 return EFI_NOT_FOUND
;
1106 GuidTableIdx
= MatchGuid
- PeiPcdDb
->Init
.GuidTable
;
1109 for (Index
= 0; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
1110 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1118 for ( ; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++ ) {
1119 if (ExMapTable
[Index
].ExGuidIndex
!= GuidTableIdx
) {
1120 *Guid
= &PeiPcdDb
->Init
.GuidTable
[ExMapTable
[Index
].ExGuidIndex
];
1128 return EFI_NOT_FOUND
;
1133 Get PCD value's size for POINTER type PCD.
1135 The POINTER type PCD's value will be stored into a buffer in specificed size.
1136 The max size of this PCD's value is described in PCD's definition in DEC file.
1138 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1139 @param MaxSize Maximum size of PCD's value
1140 @param Database Pcd database in PEI phase.
1142 @return PCD value's size for POINTER type PCD.
1147 IN UINTN LocalTokenNumberTableIdx
,
1149 IN PEI_PCD_DATABASE
*Database
1153 UINTN LocalTokenNumber
;
1155 SIZE_INFO
*SizeTable
;
1158 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, Database
);
1160 LocalTokenNumber
= Database
->Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1162 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1164 SizeTable
= Database
->Init
.SizeTable
;
1166 *MaxSize
= SizeTable
[SizeTableIdx
];
1168 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1171 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1173 // We have only one entry for VPD enabled PCD entry:
1175 // We consider current size is equal to MAX size.
1179 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1181 // We have only two entry for Non-Sku enabled PCD entry:
1185 return SizeTable
[SizeTableIdx
+ 1];
1188 // We have these entry for SKU enabled PCD entry
1190 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1192 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, Database
);
1193 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1194 if (SkuIdTable
[1 + Index
] == Database
->Init
.SystemSkuId
) {
1195 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1198 return SizeTable
[SizeTableIdx
+ 1];
1204 Set PCD value's size for POINTER type PCD.
1206 The POINTER type PCD's value will be stored into a buffer in specificed size.
1207 The max size of this PCD's value is described in PCD's definition in DEC file.
1209 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1210 @param CurrentSize Maximum size of PCD's value
1211 @param Database Pcd database in PEI phase.
1213 @retval TRUE Success to set PCD's value size, which is not exceed maximum size
1214 @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size
1219 IN UINTN LocalTokenNumberTableIdx
,
1220 IN OUT UINTN
*CurrentSize
,
1221 IN PEI_PCD_DATABASE
*Database
1225 UINTN LocalTokenNumber
;
1227 SIZE_INFO
*SizeTable
;
1231 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, Database
);
1233 LocalTokenNumber
= Database
->Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1235 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1237 SizeTable
= Database
->Init
.SizeTable
;
1239 MaxSize
= SizeTable
[SizeTableIdx
];
1241 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1244 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1246 // We shouldn't come here as we don't support SET for VPD
1251 if ((*CurrentSize
> MaxSize
) ||
1252 (*CurrentSize
== MAX_ADDRESS
)) {
1253 *CurrentSize
= MaxSize
;
1257 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1259 // We have only two entry for Non-Sku enabled PCD entry:
1263 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1267 // We have these entry for SKU enabled PCD entry
1269 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1271 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, Database
);
1272 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1273 if (SkuIdTable
[1 + Index
] == Database
->Init
.SystemSkuId
) {
1274 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1278 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;