2 All Pcd Ppi services are implemented here.
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 /// Instance of PCD_PPI protocol is EDKII native implementation.
20 /// This protocol instance support dynamic and dynamicEx type PCDs.
22 PCD_PPI mPcdPpiInstance
= {
55 PeiRegisterCallBackOnSet
,
56 PcdUnRegisterCallBackOnSet
,
58 PeiPcdGetNextTokenSpace
62 /// Instance of EFI_PEI_PCD_PPI which is defined in PI 1.2 Vol 3.
63 /// This PPI instance only support dyanmicEx type PCD.
65 EFI_PEI_PCD_PPI mEfiPcdPpiInstance
= {
81 (EFI_PEI_PCD_PPI_CALLBACK_ON_SET
) PeiRegisterCallBackOnSet
,
82 (EFI_PEI_PCD_PPI_CANCEL_CALLBACK
) PcdUnRegisterCallBackOnSet
,
84 PeiPcdGetNextTokenSpace
88 /// Instance of GET_PCD_INFO_PPI protocol is EDKII native implementation.
89 /// This protocol instance support dynamic and dynamicEx type PCDs.
91 GET_PCD_INFO_PPI mGetPcdInfoInstance
= {
93 PeiGetPcdInfoGetInfoEx
,
98 /// Instance of EFI_GET_PCD_INFO_PPI which is defined in PI 1.2.1 Vol 3.
99 /// This PPI instance only support dyanmicEx type PCD.
101 EFI_GET_PCD_INFO_PPI mEfiGetPcdInfoInstance
= {
102 PeiGetPcdInfoGetInfoEx
,
106 EFI_PEI_PPI_DESCRIPTOR mPpiList
[] = {
108 EFI_PEI_PPI_DESCRIPTOR_PPI
,
113 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
119 EFI_PEI_PPI_DESCRIPTOR mPpiList2
[] = {
121 EFI_PEI_PPI_DESCRIPTOR_PPI
,
126 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
127 &gEfiGetPcdInfoPpiGuid
,
128 &mEfiGetPcdInfoInstance
133 Main entry for PCD PEIM driver.
135 This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.
137 @param FileHandle Handle of the file being invoked.
138 @param PeiServices Describes the list of possible PEI Services.
140 @return Status of install PCD_PPI
146 IN EFI_PEI_FILE_HANDLE FileHandle
,
147 IN CONST EFI_PEI_SERVICES
**PeiServices
152 BuildPcdDatabase (FileHandle
);
155 // Install PCD_PPI and EFI_PEI_PCD_PPI.
157 Status
= PeiServicesInstallPpi (&mPpiList
[0]);
158 ASSERT_EFI_ERROR (Status
);
161 // Install GET_PCD_INFO_PPI and EFI_GET_PCD_INFO_PPI.
163 Status
= PeiServicesInstallPpi (&mPpiList2
[0]);
164 ASSERT_EFI_ERROR (Status
);
170 Retrieve additional information associated with a PCD token in the default token space.
172 This includes information such as the type of value the TokenNumber is associated with as well as possible
173 human readable name that is associated with the token.
175 @param[in] TokenNumber The PCD token number.
176 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
177 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
179 @retval EFI_SUCCESS The PCD information was returned successfully.
180 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
184 PeiGetPcdInfoGetInfo (
185 IN UINTN TokenNumber
,
186 OUT EFI_PCD_INFO
*PcdInfo
189 return PeiGetPcdInfo (NULL
, TokenNumber
, PcdInfo
);
193 Retrieve additional information associated with a PCD token.
195 This includes information such as the type of value the TokenNumber is associated with as well as possible
196 human readable name that is associated with the token.
198 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
199 @param[in] TokenNumber The PCD token number.
200 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
201 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
203 @retval EFI_SUCCESS The PCD information was returned successfully.
204 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
208 PeiGetPcdInfoGetInfoEx (
209 IN CONST EFI_GUID
*Guid
,
210 IN UINTN TokenNumber
,
211 OUT EFI_PCD_INFO
*PcdInfo
214 return PeiGetPcdInfo (Guid
, TokenNumber
, PcdInfo
);
218 Retrieve the currently set SKU Id.
220 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the
221 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU
226 PeiGetPcdInfoGetSku (
230 return (UINTN
) GetPcdDatabase()->SystemSkuId
;
234 Sets the SKU value for subsequent calls to set or get PCD token values.
236 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
237 SetSku() is normally called only once by the system.
239 For each item (token), the database can hold a single value that applies to all SKUs,
240 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
241 SKU-specific values are called SKU enabled.
243 The SKU Id of zero is reserved as a default.
244 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
245 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
246 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
247 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
248 set for that Id, the results are unpredictable.
250 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
251 set values associated with a PCD token.
260 PEI_PCD_DATABASE
*PeiPcdDb
;
264 PeiPcdDb
= GetPcdDatabase();
265 SkuIdTable
= (SKU_ID
*) ((UINT8
*) PeiPcdDb
+ PeiPcdDb
->SkuIdTableOffset
);
266 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
267 if (SkuId
== SkuIdTable
[Index
+ 1]) {
268 PeiPcdDb
->SystemSkuId
= (SKU_ID
) SkuId
;
274 // Invalid input SkuId, the default SKU Id will be used for the system.
276 DEBUG ((EFI_D_INFO
, "PcdPei - Invalid input SkuId, the default SKU Id will be used.\n"));
277 PeiPcdDb
->SystemSkuId
= (SKU_ID
) 0;
282 Retrieves an 8-bit value for a given PCD token.
284 Retrieves the current byte-sized value for a PCD token number.
285 If the TokenNumber is invalid, the results are unpredictable.
287 @param[in] TokenNumber The PCD token number.
289 @return The UINT8 value.
298 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
302 Retrieves an 16-bit value for a given PCD token.
304 Retrieves the current 16-bits value for a PCD token number.
305 If the TokenNumber is invalid, the results are unpredictable.
307 @param[in] TokenNumber The PCD token number.
309 @return The UINT16 value.
318 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
322 Retrieves an 32-bit value for a given PCD token.
324 Retrieves the current 32-bits value for a PCD token number.
325 If the TokenNumber is invalid, the results are unpredictable.
327 @param[in] TokenNumber The PCD token number.
329 @return The UINT32 value.
338 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
342 Retrieves an 64-bit value for a given PCD token.
344 Retrieves the current 64-bits value for a PCD token number.
345 If the TokenNumber is invalid, the results are unpredictable.
347 @param[in] TokenNumber The PCD token number.
349 @return The UINT64 value.
358 return ReadUnaligned64 (GetWorker (TokenNumber
, sizeof (UINT64
)));
362 Retrieves a pointer to a value for a given PCD token.
364 Retrieves the current pointer to the buffer for a PCD token number.
365 Do not make any assumptions about the alignment of the pointer that
366 is returned by this function call. If the TokenNumber is invalid,
367 the results are unpredictable.
369 @param[in] TokenNumber The PCD token number.
371 @return The pointer to the buffer to be retrieved.
380 return GetWorker (TokenNumber
, 0);
384 Retrieves a Boolean value for a given PCD token.
386 Retrieves the current boolean value for a PCD token number.
387 Do not make any assumptions about the alignment of the pointer that
388 is returned by this function call. If the TokenNumber is invalid,
389 the results are unpredictable.
391 @param[in] TokenNumber The PCD token number.
393 @return The Boolean value.
402 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
406 Retrieves the size of the value for a given PCD token.
408 Retrieves the current size of a particular PCD token.
409 If the TokenNumber is invalid, the results are unpredictable.
411 @param[in] TokenNumber The PCD token number.
413 @return The size of the value for the PCD token.
422 PEI_PCD_DATABASE
*PeiPcdDb
;
425 UINT32 LocalTokenCount
;
427 PeiPcdDb
= GetPcdDatabase ();
428 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
430 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
431 // We have to decrement TokenNumber by 1 to make it usable
432 // as the array index.
436 // EBC compiler is very choosy. It may report warning about comparison
437 // between UINTN and 0 . So we add 1 in each size of the
439 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
441 Size
= (*((UINT32
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->LocalTokenNumberTableOffset
) + TokenNumber
) & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
445 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
447 return GetPtrTypeSize (TokenNumber
, &MaxSize
, PeiPcdDb
);
455 Retrieves an 8-bit value for a given PCD token.
457 Retrieves the 8-bit 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 8-bit value for the PCD token.
471 IN CONST EFI_GUID
*Guid
,
472 IN UINTN ExTokenNumber
475 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT8
)));
479 Retrieves an 16-bit value for a given PCD token.
481 Retrieves the 16-bit value of a particular PCD token.
482 If the TokenNumber is invalid or the token space
483 specified by Guid does not exist, the results are
486 @param[in] Guid The token space for the token number.
487 @param[in] ExTokenNumber The PCD token number.
489 @return The size 16-bit value for the PCD token.
495 IN CONST EFI_GUID
*Guid
,
496 IN UINTN ExTokenNumber
499 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT16
)));
503 Retrieves an 32-bit value for a given PCD token.
505 Retrieves the 32-bit value of a particular PCD token.
506 If the TokenNumber is invalid or the token space
507 specified by Guid does not exist, the results are
510 @param[in] Guid The token space for the token number.
511 @param[in] ExTokenNumber The PCD token number.
513 @return The size 32-bit value for the PCD token.
519 IN CONST EFI_GUID
*Guid
,
520 IN UINTN ExTokenNumber
523 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT32
)));
527 Retrieves an 64-bit value for a given PCD token.
529 Retrieves the 64-bit value of a particular PCD token.
530 If the TokenNumber is invalid or the token space
531 specified by Guid does not exist, the results are
534 @param[in] Guid The token space for the token number.
535 @param[in] ExTokenNumber The PCD token number.
537 @return The size 64-bit value for the PCD token.
543 IN CONST EFI_GUID
*Guid
,
544 IN UINTN ExTokenNumber
547 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof (UINT64
)));
551 Retrieves a pointer to a value for a given PCD token.
553 Retrieves the current pointer to the buffer for a PCD token number.
554 Do not make any assumptions about the alignment of the pointer that
555 is returned by this function call. If the TokenNumber is invalid,
556 the results are unpredictable.
558 @param[in] Guid The token space for the token number.
559 @param[in] ExTokenNumber The PCD token number.
561 @return The pointer to the buffer to be retrieved.
567 IN CONST EFI_GUID
*Guid
,
568 IN UINTN ExTokenNumber
571 return ExGetWorker (Guid
, ExTokenNumber
, 0);
575 Retrieves an Boolean value for a given PCD token.
577 Retrieves the Boolean value of a particular PCD token.
578 If the TokenNumber is invalid or the token space
579 specified by Guid does not exist, the results are
582 @param[in] Guid The token space for the token number.
583 @param[in] ExTokenNumber The PCD token number.
585 @return The size Boolean value for the PCD token.
591 IN CONST EFI_GUID
*Guid
,
592 IN UINTN ExTokenNumber
595 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof (BOOLEAN
)));
599 Retrieves the size of the value for a given PCD token.
601 Retrieves the current size of a particular PCD token.
602 If the TokenNumber is invalid, the results are unpredictable.
604 @param[in] Guid The token space for the token number.
605 @param[in] ExTokenNumber The PCD token number.
607 @return The size of the value for the PCD token.
613 IN CONST EFI_GUID
*Guid
,
614 IN UINTN ExTokenNumber
617 return PeiPcdGetSize (GetExPcdTokenNumber (Guid
, ExTokenNumber
));
621 Sets an 8-bit value for a given PCD token.
623 When the PCD service sets a value, it will check to ensure that the
624 size of the value being set is compatible with the Token's existing definition.
625 If it is not, an error will be returned.
627 @param[in] TokenNumber The PCD token number.
628 @param[in] Value The value to set for the PCD token.
630 @retval EFI_SUCCESS Procedure returned successfully.
631 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
632 being set was incompatible with a call to this function.
633 Use GetSize() to retrieve the size of the target data.
634 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
640 IN UINTN TokenNumber
,
644 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
648 Sets an 16-bit value for a given PCD token.
650 When the PCD service sets a value, it will check to ensure that the
651 size of the value being set is compatible with the Token's existing definition.
652 If it is not, an error will be returned.
654 @param[in] TokenNumber The PCD token number.
655 @param[in] Value The value to set for the PCD token.
657 @retval EFI_SUCCESS Procedure returned successfully.
658 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
659 being set was incompatible with a call to this function.
660 Use GetSize() to retrieve the size of the target data.
661 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
667 IN UINTN TokenNumber
,
671 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
675 Sets an 32-bit value for a given PCD token.
677 When the PCD service sets a value, it will check to ensure that the
678 size of the value being set is compatible with the Token's existing definition.
679 If it is not, an error will be returned.
681 @param[in] TokenNumber 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 UINTN TokenNumber
,
698 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
702 Sets an 64-bit value for a given PCD token.
704 When the PCD service sets a value, it will check to ensure that the
705 size of the value being set is compatible with the Token's existing definition.
706 If it is not, an error will be returned.
708 @param[in] TokenNumber The PCD token number.
709 @param[in] Value The value to set for the PCD token.
711 @retval EFI_SUCCESS Procedure returned successfully.
712 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
713 being set was incompatible with a call to this function.
714 Use GetSize() to retrieve the size of the target data.
715 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
721 IN UINTN TokenNumber
,
725 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
729 Sets a value of a specified size for a given PCD token.
731 When the PCD service sets a value, it will check to ensure that the
732 size of the value being set is compatible with the Token's existing definition.
733 If it is not, an error will be returned.
735 @param[in] TokenNumber The PCD token number.
736 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
737 On input, if the SizeOfValue is greater than the maximum size supported
738 for this TokenNumber then the output value of SizeOfValue will reflect
739 the maximum size supported for this TokenNumber.
740 @param[in] Buffer The buffer 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 UINTN TokenNumber
,
753 IN OUT UINTN
*SizeOfBuffer
,
757 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
761 Sets an Boolean 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] TokenNumber The PCD token number.
768 @param[in] Value The value to set for the PCD token.
770 @retval EFI_SUCCESS Procedure returned successfully.
771 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
772 being set was incompatible with a call to this function.
773 Use GetSize() to retrieve the size of the target data.
774 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
780 IN UINTN TokenNumber
,
784 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
788 Sets an 8-bit value for a given PCD token.
790 When the PCD service sets a value, it will check to ensure that the
791 size of the value being set is compatible with the Token's existing definition.
792 If it is not, an error will be returned.
794 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
795 @param[in] ExTokenNumber The PCD token number.
796 @param[in] Value The value 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
,
813 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
817 Sets an 16-bit value for a given PCD token.
819 When the PCD service sets a value, it will check to ensure that the
820 size of the value being set is compatible with the Token's existing definition.
821 If it is not, an error will be returned.
823 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
824 @param[in] ExTokenNumber The PCD token number.
825 @param[in] Value The value to set for the PCD token.
827 @retval EFI_SUCCESS Procedure returned successfully.
828 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
829 being set was incompatible with a call to this function.
830 Use GetSize() to retrieve the size of the target data.
831 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
837 IN CONST EFI_GUID
*Guid
,
838 IN UINTN ExTokenNumber
,
842 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
846 Sets an 32-bit value for a given PCD token.
848 When the PCD service sets a value, it will check to ensure that the
849 size of the value being set is compatible with the Token's existing definition.
850 If it is not, an error will be returned.
852 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
853 @param[in] ExTokenNumber The PCD token number.
854 @param[in] Value The value to set for the PCD token.
856 @retval EFI_SUCCESS Procedure returned successfully.
857 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
858 being set was incompatible with a call to this function.
859 Use GetSize() to retrieve the size of the target data.
860 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
866 IN CONST EFI_GUID
*Guid
,
867 IN UINTN ExTokenNumber
,
871 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
875 Sets an 64-bit value for a given PCD token.
877 When the PCD service sets a value, it will check to ensure that the
878 size of the value being set is compatible with the Token's existing definition.
879 If it is not, an error will be returned.
881 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
882 @param[in] ExTokenNumber The PCD token number.
883 @param[in] Value The value to set for the PCD token.
885 @retval EFI_SUCCESS Procedure returned successfully.
886 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
887 being set was incompatible with a call to this function.
888 Use GetSize() to retrieve the size of the target data.
889 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
895 IN CONST EFI_GUID
*Guid
,
896 IN UINTN ExTokenNumber
,
900 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
904 Sets a value of a specified size for a given PCD token.
906 When the PCD service sets a value, it will check to ensure that the
907 size of the value being set is compatible with the Token's existing definition.
908 If it is not, an error will be returned.
910 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
911 @param[in] ExTokenNumber The PCD token number.
912 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
913 On input, if the SizeOfValue is greater than the maximum size supported
914 for this TokenNumber then the output value of SizeOfValue will reflect
915 the maximum size supported for this TokenNumber.
916 @param[in] Value The buffer to set for the PCD token.
918 @retval EFI_SUCCESS Procedure returned successfully.
919 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
920 being set was incompatible with a call to this function.
921 Use GetSize() to retrieve the size of the target data.
922 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
928 IN CONST EFI_GUID
*Guid
,
929 IN UINTN ExTokenNumber
,
930 IN OUT UINTN
*SizeOfBuffer
,
934 return ExSetWorker (ExTokenNumber
, Guid
, Value
, SizeOfBuffer
, TRUE
);
938 Sets an Boolean value for a given PCD token.
940 When the PCD service sets a value, it will check to ensure that the
941 size of the value being set is compatible with the Token's existing definition.
942 If it is not, an error will be returned.
944 @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
945 @param [in] ExTokenNumber The PCD token number.
946 @param [in] Value The value to set for the PCD token.
948 @retval EFI_SUCCESS Procedure returned successfully.
949 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
950 being set was incompatible with a call to this function.
951 Use GetSize() to retrieve the size of the target data.
952 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
958 IN CONST EFI_GUID
*Guid
,
959 IN UINTN ExTokenNumber
,
963 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
967 Specifies a function to be called anytime the value of a designated token is changed.
969 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
970 @param[in] ExTokenNumber The PCD token number.
971 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
973 @retval EFI_SUCCESS The PCD service has successfully established a call event
974 for the CallBackToken requested.
975 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
980 PeiRegisterCallBackOnSet (
981 IN CONST EFI_GUID
*Guid
, OPTIONAL
982 IN UINTN ExTokenNumber
,
983 IN PCD_PPI_CALLBACK CallBackFunction
986 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
987 return EFI_UNSUPPORTED
;
990 if (CallBackFunction
== NULL
) {
991 return EFI_INVALID_PARAMETER
;
994 return PeiRegisterCallBackWorker (ExTokenNumber
, Guid
, CallBackFunction
, TRUE
);
998 Cancels a previously set callback function for a particular PCD token number.
1000 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1001 @param[in] ExTokenNumber The PCD token number.
1002 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1004 @retval EFI_SUCCESS The PCD service has successfully established a call event
1005 for the CallBackToken requested.
1006 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1011 PcdUnRegisterCallBackOnSet (
1012 IN CONST EFI_GUID
*Guid
, OPTIONAL
1013 IN UINTN ExTokenNumber
,
1014 IN PCD_PPI_CALLBACK CallBackFunction
1017 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
1018 return EFI_UNSUPPORTED
;
1021 if (CallBackFunction
== NULL
) {
1022 return EFI_INVALID_PARAMETER
;
1025 return PeiRegisterCallBackWorker (ExTokenNumber
, Guid
, CallBackFunction
, FALSE
);
1029 Retrieves the next valid token number in a given namespace.
1031 This is useful since the PCD infrastructure contains a sparse list of token numbers,
1032 and one cannot a priori know what token numbers are valid in the database.
1034 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
1035 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
1036 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
1037 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
1038 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
1039 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
1040 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1041 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1044 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1045 This is an optional parameter that may be NULL. If this parameter is NULL, then a request
1046 is being made to retrieve tokens from the default token space.
1047 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.
1049 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.
1050 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.
1055 PeiPcdGetNextToken (
1056 IN CONST EFI_GUID
*Guid
, OPTIONAL
1057 IN OUT UINTN
*TokenNumber
1061 PEI_PCD_DATABASE
*PeiPcdDb
;
1062 EFI_GUID
*MatchGuid
;
1063 EFI_GUID
*GuidTable
;
1064 DYNAMICEX_MAPPING
*ExMapTable
;
1067 BOOLEAN PeiExMapTableEmpty
;
1068 UINTN PeiNexTokenNumber
;
1070 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable
)) {
1071 return EFI_UNSUPPORTED
;
1074 PeiPcdDb
= GetPcdDatabase ();
1075 PeiNexTokenNumber
= PeiPcdDb
->LocalTokenCount
- PeiPcdDb
->ExTokenCount
;
1076 GuidTable
= (EFI_GUID
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
);
1078 if (PeiPcdDb
->ExTokenCount
== 0) {
1079 PeiExMapTableEmpty
= TRUE
;
1081 PeiExMapTableEmpty
= FALSE
;
1084 if (*TokenNumber
> PeiNexTokenNumber
) {
1085 return EFI_NOT_FOUND
;
1088 if (*TokenNumber
> PeiNexTokenNumber
) {
1089 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1090 return EFI_NOT_FOUND
;
1094 if (PeiExMapTableEmpty
) {
1095 return EFI_NOT_FOUND
;
1098 MatchGuid
= ScanGuid (GuidTable
, PeiPcdDb
->GuidTableCount
* sizeof(EFI_GUID
), Guid
);
1100 if (MatchGuid
== NULL
) {
1101 return EFI_NOT_FOUND
;
1104 GuidTableIdx
= MatchGuid
- GuidTable
;
1106 ExMapTable
= (DYNAMICEX_MAPPING
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->ExMapTableOffset
);
1110 // Locate the GUID in ExMapTable first.
1112 for (Index
= 0; Index
< PeiPcdDb
->ExTokenCount
; Index
++) {
1113 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1121 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
1122 // token number in found token space.
1124 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
1125 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
1129 for ( ; Index
< PeiPcdDb
->ExTokenCount
; Index
++) {
1130 if ((ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) && (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
)) {
1135 while (Index
< PeiPcdDb
->ExTokenCount
) {
1137 if (Index
== PeiPcdDb
->ExTokenCount
) {
1139 // Exceed the length of ExMap Table
1141 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1142 return EFI_NOT_FOUND
;
1143 } else if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1145 // Found the next match
1147 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
1154 return EFI_NOT_FOUND
;
1158 Retrieves the next valid PCD token namespace for a given namespace.
1160 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid
1161 token namespaces on a platform.
1163 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token
1164 namespace from which the search will start. On output, it designates the next valid
1165 token namespace on the platform. If *Guid is NULL, then the GUID of the first token
1166 space of the current platform is returned. If the search cannot locate the next valid
1167 token namespace, an error is returned and the value of *Guid is undefined.
1169 @retval EFI_SUCCESS The PCD service retrieved the value requested.
1170 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.
1175 PeiPcdGetNextTokenSpace (
1176 IN OUT CONST EFI_GUID
**Guid
1180 EFI_GUID
*MatchGuid
;
1181 PEI_PCD_DATABASE
*PeiPcdDb
;
1182 DYNAMICEX_MAPPING
*ExMapTable
;
1186 BOOLEAN PeiExMapTableEmpty
;
1187 EFI_GUID
*GuidTable
;
1189 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable
)) {
1190 return EFI_UNSUPPORTED
;
1193 ASSERT (Guid
!= NULL
);
1195 PeiPcdDb
= GetPcdDatabase ();
1197 if (PeiPcdDb
->ExTokenCount
== 0) {
1198 PeiExMapTableEmpty
= TRUE
;
1200 PeiExMapTableEmpty
= FALSE
;
1203 if (PeiExMapTableEmpty
) {
1204 return EFI_NOT_FOUND
;
1207 ExMapTable
= (DYNAMICEX_MAPPING
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->ExMapTableOffset
);
1208 GuidTable
= (EFI_GUID
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
);
1210 if (*Guid
== NULL
) {
1212 // return the first Token Space Guid.
1214 *Guid
= GuidTable
+ ExMapTable
[0].ExGuidIndex
;
1218 MatchGuid
= ScanGuid (GuidTable
, PeiPcdDb
->GuidTableCount
* sizeof(GuidTable
[0]), *Guid
);
1220 if (MatchGuid
== NULL
) {
1221 return EFI_NOT_FOUND
;
1224 GuidTableIdx
= MatchGuid
- GuidTable
;
1227 for (Index
= 0; Index
< PeiPcdDb
->ExTokenCount
; Index
++) {
1228 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
1236 for ( ; Index
< PeiPcdDb
->ExTokenCount
; Index
++ ) {
1237 if (ExMapTable
[Index
].ExGuidIndex
!= GuidTableIdx
) {
1239 for (Index2
= 0 ; Index2
< Index
; Index2
++) {
1240 if (ExMapTable
[Index2
].ExGuidIndex
== ExMapTable
[Index
].ExGuidIndex
) {
1242 // This token namespace should have been found and output at preceding getting.
1249 *Guid
= (EFI_GUID
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
) + ExMapTable
[Index
].ExGuidIndex
;
1257 return EFI_NOT_FOUND
;
1262 Get PCD value's size for POINTER type PCD.
1264 The POINTER type PCD's value will be stored into a buffer in specified size.
1265 The max size of this PCD's value is described in PCD's definition in DEC file.
1267 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1268 @param MaxSize Maximum size of PCD's value
1269 @param Database Pcd database in PEI phase.
1271 @return PCD value's size for POINTER type PCD.
1276 IN UINTN LocalTokenNumberTableIdx
,
1278 IN PEI_PCD_DATABASE
*Database
1282 UINTN LocalTokenNumber
;
1284 SIZE_INFO
*SizeTable
;
1287 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, Database
);
1289 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1291 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1293 SizeTable
= (SIZE_INFO
*)((UINT8
*)Database
+ Database
->SizeTableOffset
);
1295 *MaxSize
= SizeTable
[SizeTableIdx
];
1297 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1300 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1302 // We have only two entry for VPD enabled PCD entry:
1305 // We consider current size is equal to MAX size.
1309 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1311 // We have only two entry for Non-Sku enabled PCD entry:
1315 return SizeTable
[SizeTableIdx
+ 1];
1318 // We have these entry for SKU enabled PCD entry
1320 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1322 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, Database
);
1323 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1324 if (SkuIdTable
[1 + Index
] == Database
->SystemSkuId
) {
1325 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1328 return SizeTable
[SizeTableIdx
+ 1];
1334 Set PCD value's size for POINTER type PCD.
1336 The POINTER type PCD's value will be stored into a buffer in specified size.
1337 The max size of this PCD's value is described in PCD's definition in DEC file.
1339 @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table
1340 @param CurrentSize Maximum size of PCD's value
1341 @param Database Pcd database in PEI phase.
1343 @retval TRUE Success to set PCD's value size, which is not exceed maximum size
1344 @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size
1349 IN UINTN LocalTokenNumberTableIdx
,
1350 IN OUT UINTN
*CurrentSize
,
1351 IN PEI_PCD_DATABASE
*Database
1355 UINTN LocalTokenNumber
;
1357 SIZE_INFO
*SizeTable
;
1361 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, Database
);
1363 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1365 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1367 SizeTable
= (SIZE_INFO
*)((UINT8
*)Database
+ Database
->SizeTableOffset
);
1369 MaxSize
= SizeTable
[SizeTableIdx
];
1371 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1374 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1376 // We shouldn't come here as we don't support SET for VPD
1381 if ((*CurrentSize
> MaxSize
) ||
1382 (*CurrentSize
== MAX_ADDRESS
)) {
1383 *CurrentSize
= MaxSize
;
1387 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1389 // We have only two entry for Non-Sku enabled PCD entry:
1393 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1397 // We have these entry for SKU enabled PCD entry
1399 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1401 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, Database
);
1402 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1403 if (SkuIdTable
[1 + Index
] == Database
->SystemSkuId
) {
1404 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1408 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;