2 PCD DXE driver manage all PCD entry initialized in PEI phase and DXE phase, and
3 produce the implementation of native PCD protocol and EFI_PCD_PROTOCOL defined in
6 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 /// PCD database lock.
22 EFI_LOCK mPcdDatabaseLock
= EFI_INITIALIZE_LOCK_VARIABLE(TPL_NOTIFY
);
25 /// PCD_PROTOCOL the EDKII native implementation which support dynamic
26 /// type and dynamicEx type PCDs.
28 PCD_PROTOCOL mPcdInstance
= {
61 DxeRegisterCallBackOnSet
,
62 DxeUnRegisterCallBackOnSet
,
64 DxePcdGetNextTokenSpace
68 /// EFI_PCD_PROTOCOL is defined in PI 1.2 Vol 3 which only support dynamicEx type
71 EFI_PCD_PROTOCOL mEfiPcdInstance
= {
86 (EFI_PCD_PROTOCOL_CALLBACK_ON_SET
) DxeRegisterCallBackOnSet
,
87 (EFI_PCD_PROTOCOL_CANCEL_CALLBACK
) DxeUnRegisterCallBackOnSet
,
89 DxePcdGetNextTokenSpace
93 /// Instance of GET_PCD_INFO_PROTOCOL protocol is EDKII native implementation.
94 /// This protocol instance support dynamic and dynamicEx type PCDs.
96 GET_PCD_INFO_PROTOCOL mGetPcdInfoInstance
= {
98 DxeGetPcdInfoGetInfoEx
,
103 /// Instance of EFI_GET_PCD_INFO_PROTOCOL which is defined in PI 1.2.1 Vol 3.
104 /// This PPI instance only support dyanmicEx type PCD.
106 EFI_GET_PCD_INFO_PROTOCOL mEfiGetPcdInfoInstance
= {
107 DxeGetPcdInfoGetInfoEx
,
111 EFI_HANDLE mPcdHandle
= NULL
;
112 UINTN mVpdBaseAddress
= 0;
115 Main entry for PCD DXE driver.
117 This routine initialize the PCD database and install PCD_PROTOCOL.
119 @param ImageHandle Image handle for PCD DXE driver.
120 @param SystemTable Pointer to SystemTable.
122 @return Status of gBS->InstallProtocolInterface()
128 IN EFI_HANDLE ImageHandle
,
129 IN EFI_SYSTEM_TABLE
*SystemTable
136 // Make sure the Pcd Protocol is not already installed in the system
139 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gPcdProtocolGuid
);
141 BuildPcdDxeDataBase ();
144 // Install PCD_PROTOCOL to handle dynamic type PCD
145 // Install EFI_PCD_PROTOCOL to handle dynamicEx type PCD
147 Status
= gBS
->InstallMultipleProtocolInterfaces (
149 &gPcdProtocolGuid
, &mPcdInstance
,
150 &gEfiPcdProtocolGuid
, &mEfiPcdInstance
,
153 ASSERT_EFI_ERROR (Status
);
156 // Install GET_PCD_INFO_PROTOCOL to handle dynamic type PCD
157 // Install EFI_GET_PCD_INFO_PROTOCOL to handle dynamicEx type PCD
159 Status
= gBS
->InstallMultipleProtocolInterfaces (
161 &gGetPcdInfoProtocolGuid
, &mGetPcdInfoInstance
,
162 &gEfiGetPcdInfoProtocolGuid
, &mEfiGetPcdInfoInstance
,
165 ASSERT_EFI_ERROR (Status
);
168 // Register callback function upon VariableLockProtocol
169 // to lock the variables referenced by DynamicHii PCDs with RO property set in *.dsc.
171 EfiCreateProtocolNotifyEvent (
172 &gEdkiiVariableLockProtocolGuid
,
174 VariableLockCallBack
,
180 // Cache VpdBaseAddress in entry point for the following usage.
184 // PcdVpdBaseAddress64 is DynamicEx PCD only. So, DxePcdGet64Ex() is used to get its value.
186 mVpdBaseAddress
= (UINTN
) DxePcdGet64Ex (&gEfiMdeModulePkgTokenSpaceGuid
, PcdToken (PcdVpdBaseAddress64
));
187 if (mVpdBaseAddress
== 0) {
189 // PcdVpdBaseAddress64 is not set, get value from PcdVpdBaseAddress.
191 mVpdBaseAddress
= (UINTN
) PcdGet32 (PcdVpdBaseAddress
);
198 Retrieve additional information associated with a PCD token in the default token space.
200 This includes information such as the type of value the TokenNumber is associated with as well as possible
201 human readable name that is associated with the token.
203 @param[in] TokenNumber The PCD token number.
204 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
205 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
207 @retval EFI_SUCCESS The PCD information was returned successfully.
208 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
212 DxeGetPcdInfoGetInfo (
213 IN UINTN TokenNumber
,
214 OUT EFI_PCD_INFO
*PcdInfo
217 return DxeGetPcdInfo (NULL
, TokenNumber
, PcdInfo
);
221 Retrieve additional information associated with a PCD token.
223 This includes information such as the type of value the TokenNumber is associated with as well as possible
224 human readable name that is associated with the token.
226 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
227 @param[in] TokenNumber The PCD token number.
228 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
229 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
231 @retval EFI_SUCCESS The PCD information was returned successfully.
232 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
236 DxeGetPcdInfoGetInfoEx (
237 IN CONST EFI_GUID
*Guid
,
238 IN UINTN TokenNumber
,
239 OUT EFI_PCD_INFO
*PcdInfo
242 return DxeGetPcdInfo (Guid
, TokenNumber
, PcdInfo
);
246 Retrieve the currently set SKU Id.
248 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the
249 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU
254 DxeGetPcdInfoGetSku (
258 return (UINTN
) mPcdDatabase
.DxeDb
->SystemSkuId
;
262 Sets the SKU value for subsequent calls to set or get PCD token values.
264 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
265 SetSku() is normally called only once by the system.
267 For each item (token), the database can hold a single value that applies to all SKUs,
268 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
269 SKU-specific values are called SKU enabled.
271 The SKU Id of zero is reserved as a default.
272 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
273 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
274 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
275 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
276 set for that Id, the results are unpredictable.
278 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
279 set values associated with a PCD token.
292 DEBUG ((DEBUG_INFO
, "PcdDxe - SkuId 0x%lx is to be set.\n", (SKU_ID
) SkuId
));
294 if (SkuId
== mPcdDatabase
.DxeDb
->SystemSkuId
) {
296 // The input SKU Id is equal to current SKU Id, return directly.
298 DEBUG ((DEBUG_INFO
, "PcdDxe - SkuId is same to current system Sku.\n"));
302 if (mPcdDatabase
.DxeDb
->SystemSkuId
!= (SKU_ID
) 0) {
303 DEBUG ((DEBUG_ERROR
, "PcdDxe - The SKU Id could be changed only once."));
306 "PcdDxe - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",
307 mPcdDatabase
.DxeDb
->SystemSkuId
,
314 SkuIdTable
= (SKU_ID
*) ((UINT8
*) mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SkuIdTableOffset
);
315 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
316 if (SkuId
== SkuIdTable
[Index
+ 1]) {
317 DEBUG ((DEBUG_INFO
, "PcdDxe - SkuId is found in SkuId table.\n"));
318 Status
= UpdatePcdDatabase (SkuId
, TRUE
);
319 if (!EFI_ERROR (Status
)) {
320 mPcdDatabase
.DxeDb
->SystemSkuId
= (SKU_ID
) SkuId
;
321 DEBUG ((DEBUG_INFO
, "PcdDxe - Set current SKU Id to 0x%lx.\n", (SKU_ID
) SkuId
));
328 // Invalid input SkuId, the default SKU Id will be still used for the system.
330 DEBUG ((DEBUG_ERROR
, "PcdDxe - Invalid input SkuId, the default SKU Id will be still used.\n"));
335 Retrieves an 8-bit value for a given PCD token.
337 Retrieves the current byte-sized value for a PCD token number.
338 If the TokenNumber is invalid, the results are unpredictable.
340 @param[in] TokenNumber The PCD token number.
342 @return The UINT8 value.
351 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
355 Retrieves an 16-bit value for a given PCD token.
357 Retrieves the current 16-bits value for a PCD token number.
358 If the TokenNumber is invalid, the results are unpredictable.
360 @param[in] TokenNumber The PCD token number.
362 @return The UINT16 value.
371 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
375 Retrieves an 32-bit value for a given PCD token.
377 Retrieves the current 32-bits value for a PCD token number.
378 If the TokenNumber is invalid, the results are unpredictable.
380 @param[in] TokenNumber The PCD token number.
382 @return The UINT32 value.
391 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
395 Retrieves an 64-bit value for a given PCD token.
397 Retrieves the current 64-bits value for a PCD token number.
398 If the TokenNumber is invalid, the results are unpredictable.
400 @param[in] TokenNumber The PCD token number.
402 @return The UINT64 value.
411 return ReadUnaligned64(GetWorker (TokenNumber
, sizeof (UINT64
)));
415 Retrieves a pointer to a value for a given PCD token.
417 Retrieves the current pointer to the buffer for a PCD token number.
418 Do not make any assumptions about the alignment of the pointer that
419 is returned by this function call. If the TokenNumber is invalid,
420 the results are unpredictable.
422 @param[in] TokenNumber The PCD token number.
424 @return The pointer to the buffer to be retrived.
433 return GetWorker (TokenNumber
, 0);
437 Retrieves a Boolean value for a given PCD token.
439 Retrieves the current boolean value 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] TokenNumber The PCD token number.
446 @return The Boolean value.
455 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
459 Retrieves the size of the value for a given PCD token.
461 Retrieves the current size of a particular PCD token.
462 If the TokenNumber is invalid, the results are unpredictable.
464 @param[in] TokenNumber The PCD token number.
466 @return The size of the value for the PCD token.
476 UINT32
*LocalTokenNumberTable
;
479 UINTN TmpTokenNumber
;
481 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
482 // We have to decrement TokenNumber by 1 to make it usable
483 // as the array index.
488 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
490 TmpTokenNumber
= TokenNumber
;
492 // EBC compiler is very choosy. It may report warning about comparison
493 // between UINTN and 0 . So we add 1 in each size of the
495 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
497 // EBC compiler is very choosy. It may report warning about comparison
498 // between UINTN and 0 . So we add 1 in each size of the
500 IsPeiDb
= (BOOLEAN
) (TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1);
502 TokenNumber
= IsPeiDb
? TokenNumber
:
503 (TokenNumber
- mPeiLocalTokenCount
);
505 LocalTokenNumberTable
= IsPeiDb
? (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
)
506 : (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
508 Size
= (LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
512 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
514 return GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
522 Retrieves an 8-bit value for a given PCD token.
524 Retrieves the 8-bit value of a particular PCD token.
525 If the TokenNumber is invalid or the token space
526 specified by Guid does not exist, the results are
529 @param[in] Guid The token space for the token number.
530 @param[in] ExTokenNumber The PCD token number.
532 @return The size 8-bit value for the PCD token.
538 IN CONST EFI_GUID
*Guid
,
539 IN UINTN ExTokenNumber
542 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT8
)));
546 Retrieves an 16-bit value for a given PCD token.
548 Retrieves the 16-bit value of a particular PCD token.
549 If the TokenNumber is invalid or the token space
550 specified by Guid does not exist, the results are
553 @param[in] Guid The token space for the token number.
554 @param[in] ExTokenNumber The PCD token number.
556 @return The size 16-bit value for the PCD token.
562 IN CONST EFI_GUID
*Guid
,
563 IN UINTN ExTokenNumber
566 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT16
)));
570 Retrieves an 32-bit value for a given PCD token.
572 Retrieves the 32-bit value of a particular PCD token.
573 If the TokenNumber is invalid or the token space
574 specified by Guid does not exist, the results are
577 @param[in] Guid The token space for the token number.
578 @param[in] ExTokenNumber The PCD token number.
580 @return The size 32-bit value for the PCD token.
586 IN CONST EFI_GUID
*Guid
,
587 IN UINTN ExTokenNumber
590 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT32
)));
594 Retrieves an 64-bit value for a given PCD token.
596 Retrieves the 64-bit value of a particular PCD token.
597 If the TokenNumber is invalid or the token space
598 specified by Guid does not exist, the results are
601 @param[in] Guid The token space for the token number.
602 @param[in] ExTokenNumber The PCD token number.
604 @return The size 64-bit value for the PCD token.
610 IN CONST EFI_GUID
*Guid
,
611 IN UINTN ExTokenNumber
614 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT64
)));
618 Retrieves a pointer to a value for a given PCD token.
620 Retrieves the current pointer to the buffer for a PCD token number.
621 Do not make any assumptions about the alignment of the pointer that
622 is returned by this function call. If the TokenNumber is invalid,
623 the results are unpredictable.
625 @param[in] Guid The token space for the token number.
626 @param[in] ExTokenNumber The PCD token number.
628 @return The pointer to the buffer to be retrived.
634 IN CONST EFI_GUID
*Guid
,
635 IN UINTN ExTokenNumber
638 return ExGetWorker (Guid
, ExTokenNumber
, 0);
642 Retrieves an Boolean value for a given PCD token.
644 Retrieves the Boolean value of a particular PCD token.
645 If the TokenNumber is invalid or the token space
646 specified by Guid does not exist, the results are
649 @param[in] Guid The token space for the token number.
650 @param[in] ExTokenNumber The PCD token number.
652 @return The size Boolean value for the PCD token.
658 IN CONST EFI_GUID
*Guid
,
659 IN UINTN ExTokenNumber
662 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(BOOLEAN
)));
666 Retrieves the size of the value for a given PCD token.
668 Retrieves the current size of a particular PCD token.
669 If the TokenNumber is invalid, the results are unpredictable.
671 @param[in] Guid The token space for the token number.
672 @param[in] ExTokenNumber The PCD token number.
674 @return The size of the value for the PCD token.
680 IN CONST EFI_GUID
*Guid
,
681 IN UINTN ExTokenNumber
684 return DxePcdGetSize(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
));
688 Sets an 8-bit value for a given PCD token.
690 When the PCD service sets a value, it will check to ensure that the
691 size of the value being set is compatible with the Token's existing definition.
692 If it is not, an error will be returned.
694 @param[in] TokenNumber The PCD token number.
695 @param[in] Value The value to set for the PCD token.
697 @retval EFI_SUCCESS Procedure returned successfully.
698 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
699 being set was incompatible with a call to this function.
700 Use GetSize() to retrieve the size of the target data.
701 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
707 IN UINTN TokenNumber
,
711 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
715 Sets an 16-bit value for a given PCD token.
717 When the PCD service sets a value, it will check to ensure that the
718 size of the value being set is compatible with the Token's existing definition.
719 If it is not, an error will be returned.
721 @param[in] TokenNumber The PCD token number.
722 @param[in] Value The value to set for the PCD token.
724 @retval EFI_SUCCESS Procedure returned successfully.
725 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
726 being set was incompatible with a call to this function.
727 Use GetSize() to retrieve the size of the target data.
728 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
734 IN UINTN TokenNumber
,
738 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
742 Sets an 32-bit value for a given PCD token.
744 When the PCD service sets a value, it will check to ensure that the
745 size of the value being set is compatible with the Token's existing definition.
746 If it is not, an error will be returned.
748 @param[in] TokenNumber The PCD token number.
749 @param[in] Value The value to set for the PCD token.
751 @retval EFI_SUCCESS Procedure returned successfully.
752 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
753 being set was incompatible with a call to this function.
754 Use GetSize() to retrieve the size of the target data.
755 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
761 IN UINTN TokenNumber
,
765 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
769 Sets an 64-bit value for a given PCD token.
771 When the PCD service sets a value, it will check to ensure that the
772 size of the value being set is compatible with the Token's existing definition.
773 If it is not, an error will be returned.
775 @param[in] TokenNumber The PCD token number.
776 @param[in] Value The value to set for the PCD token.
778 @retval EFI_SUCCESS Procedure returned successfully.
779 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
780 being set was incompatible with a call to this function.
781 Use GetSize() to retrieve the size of the target data.
782 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
788 IN UINTN TokenNumber
,
792 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
796 Sets a value of a specified size for a given PCD token.
798 When the PCD service sets a value, it will check to ensure that the
799 size of the value being set is compatible with the Token's existing definition.
800 If it is not, an error will be returned.
802 @param[in] TokenNumber The PCD token number.
803 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
804 On input, if the SizeOfValue is greater than the maximum size supported
805 for this TokenNumber then the output value of SizeOfValue will reflect
806 the maximum size supported for this TokenNumber.
807 @param[in] Buffer The buffer to set for the PCD token.
809 @retval EFI_SUCCESS Procedure returned successfully.
810 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
811 being set was incompatible with a call to this function.
812 Use GetSize() to retrieve the size of the target data.
813 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
819 IN UINTN TokenNumber
,
820 IN OUT UINTN
*SizeOfBuffer
,
824 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
828 Sets an Boolean value for a given PCD token.
830 When the PCD service sets a value, it will check to ensure that the
831 size of the value being set is compatible with the Token's existing definition.
832 If it is not, an error will be returned.
834 @param[in] TokenNumber The PCD token number.
835 @param[in] Value The value to set for the PCD token.
837 @retval EFI_SUCCESS Procedure returned successfully.
838 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
839 being set was incompatible with a call to this function.
840 Use GetSize() to retrieve the size of the target data.
841 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
847 IN UINTN TokenNumber
,
851 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
855 Sets an 8-bit value for a given PCD token.
857 When the PCD service sets a value, it will check to ensure that the
858 size of the value being set is compatible with the Token's existing definition.
859 If it is not, an error will be returned.
861 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
862 @param[in] ExTokenNumber The PCD token number.
863 @param[in] Value The value to set for the PCD token.
865 @retval EFI_SUCCESS Procedure returned successfully.
866 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
867 being set was incompatible with a call to this function.
868 Use GetSize() to retrieve the size of the target data.
869 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
875 IN CONST EFI_GUID
*Guid
,
876 IN UINTN ExTokenNumber
,
880 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
884 Sets an 16-bit value for a given PCD token.
886 When the PCD service sets a value, it will check to ensure that the
887 size of the value being set is compatible with the Token's existing definition.
888 If it is not, an error will be returned.
890 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
891 @param[in] ExTokenNumber The PCD token number.
892 @param[in] Value The value to set for the PCD token.
894 @retval EFI_SUCCESS Procedure returned successfully.
895 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
896 being set was incompatible with a call to this function.
897 Use GetSize() to retrieve the size of the target data.
898 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
904 IN CONST EFI_GUID
*Guid
,
905 IN UINTN ExTokenNumber
,
910 // PcdSetNvStoreDefaultId should be set in PEI phase to take effect.
912 ASSERT (!(CompareGuid (Guid
, &gEfiMdeModulePkgTokenSpaceGuid
) &&
913 (ExTokenNumber
== PcdToken(PcdSetNvStoreDefaultId
))));
914 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
918 Sets an 32-bit value for a given PCD token.
920 When the PCD service sets a value, it will check to ensure that the
921 size of the value being set is compatible with the Token's existing definition.
922 If it is not, an error will be returned.
924 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
925 @param[in] ExTokenNumber The PCD token number.
926 @param[in] Value The value to set for the PCD token.
928 @retval EFI_SUCCESS Procedure returned successfully.
929 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
930 being set was incompatible with a call to this function.
931 Use GetSize() to retrieve the size of the target data.
932 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
938 IN CONST EFI_GUID
*Guid
,
939 IN UINTN ExTokenNumber
,
943 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
947 Sets an 64-bit value for a given PCD token.
949 When the PCD service sets a value, it will check to ensure that the
950 size of the value being set is compatible with the Token's existing definition.
951 If it is not, an error will be returned.
953 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
954 @param[in] ExTokenNumber The PCD token number.
955 @param[in] Value The value to set for the PCD token.
957 @retval EFI_SUCCESS Procedure returned successfully.
958 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
959 being set was incompatible with a call to this function.
960 Use GetSize() to retrieve the size of the target data.
961 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
967 IN CONST EFI_GUID
*Guid
,
968 IN UINTN ExTokenNumber
,
972 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
976 Sets a value of a specified size for a given PCD token.
978 When the PCD service sets a value, it will check to ensure that the
979 size of the value being set is compatible with the Token's existing definition.
980 If it is not, an error will be returned.
982 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
983 @param[in] ExTokenNumber The PCD token number.
984 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
985 On input, if the SizeOfValue is greater than the maximum size supported
986 for this TokenNumber then the output value of SizeOfValue will reflect
987 the maximum size supported for this TokenNumber.
988 @param[in] Buffer The buffer to set for the PCD token.
990 @retval EFI_SUCCESS Procedure returned successfully.
991 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
992 being set was incompatible with a call to this function.
993 Use GetSize() to retrieve the size of the target data.
994 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1000 IN CONST EFI_GUID
*Guid
,
1001 IN UINTN ExTokenNumber
,
1002 IN OUT UINTN
*SizeOfBuffer
,
1006 return ExSetWorker(ExTokenNumber
, Guid
, Buffer
, SizeOfBuffer
, TRUE
);
1010 Sets an Boolean value for a given PCD token.
1012 When the PCD service sets a value, it will check to ensure that the
1013 size of the value being set is compatible with the Token's existing definition.
1014 If it is not, an error will be returned.
1016 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1017 @param[in] ExTokenNumber The PCD token number.
1018 @param[in] Value The value to set for the PCD token.
1020 @retval EFI_SUCCESS Procedure returned successfully.
1021 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1022 being set was incompatible with a call to this function.
1023 Use GetSize() to retrieve the size of the target data.
1024 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1030 IN CONST EFI_GUID
*Guid
,
1031 IN UINTN ExTokenNumber
,
1035 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
1039 Specifies a function to be called anytime the value of a designated token is changed.
1041 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1042 @param[in] TokenNumber The PCD token number.
1043 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1045 @retval EFI_SUCCESS The PCD service has successfully established a call event
1046 for the CallBackToken requested.
1047 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1052 DxeRegisterCallBackOnSet (
1053 IN CONST EFI_GUID
*Guid
, OPTIONAL
1054 IN UINTN TokenNumber
,
1055 IN PCD_PROTOCOL_CALLBACK CallBackFunction
1060 if (CallBackFunction
== NULL
) {
1061 return EFI_INVALID_PARAMETER
;
1064 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1066 EfiAcquireLock (&mPcdDatabaseLock
);
1068 Status
= DxeRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
1070 EfiReleaseLock (&mPcdDatabaseLock
);
1076 Cancels a previously set callback function for a particular PCD token number.
1078 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1079 @param[in] TokenNumber The PCD token number.
1080 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1082 @retval EFI_SUCCESS The PCD service has successfully established a call event
1083 for the CallBackToken requested.
1084 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1089 DxeUnRegisterCallBackOnSet (
1090 IN CONST EFI_GUID
*Guid
, OPTIONAL
1091 IN UINTN TokenNumber
,
1092 IN PCD_PROTOCOL_CALLBACK CallBackFunction
1097 if (CallBackFunction
== NULL
) {
1098 return EFI_INVALID_PARAMETER
;
1102 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1104 EfiAcquireLock (&mPcdDatabaseLock
);
1106 Status
= DxeUnRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
1108 EfiReleaseLock (&mPcdDatabaseLock
);
1114 Retrieves the next valid token number in a given namespace.
1116 This is useful since the PCD infrastructure contains a sparse list of token numbers,
1117 and one cannot a priori know what token numbers are valid in the database.
1119 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
1120 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
1121 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
1122 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
1123 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
1124 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
1125 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1126 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1129 @param[in] Guid The 128-bit unique value that designates the namespace from which to retrieve the next token.
1130 This is an optional parameter that may be NULL. If this parameter is NULL, then a request is
1131 being made to retrieve tokens from the default token space.
1132 @param[in, out] TokenNumber
1133 A pointer to the PCD token number to use to find the subsequent token number.
1135 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.
1136 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.
1141 DxePcdGetNextToken (
1142 IN CONST EFI_GUID
*Guid
, OPTIONAL
1143 IN OUT UINTN
*TokenNumber
1147 BOOLEAN PeiExMapTableEmpty
;
1148 BOOLEAN DxeExMapTableEmpty
;
1150 Status
= EFI_NOT_FOUND
;
1151 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
1152 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
1155 // Scan the local token space
1158 // EBC compiler is very choosy. It may report warning about comparison
1159 // between UINTN and 0 . So we add 1 in each size of the
1161 if (((*TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) && (*TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) ||
1162 ((*TokenNumber
+ 1 > (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1)))) {
1163 return EFI_NOT_FOUND
;
1167 if ((*TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) &&
1168 (*TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) {
1170 // The first Non-Ex type Token Number for DXE PCD
1171 // database is mPeiLocalTokenCount + 1
1173 if (mDxeNexTokenCount
> 0) {
1174 *TokenNumber
= mPeiLocalTokenCount
+ 1;
1176 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1177 return EFI_NOT_FOUND
;
1179 } else if (*TokenNumber
+ 1 > mDxeNexTokenCount
+ mPeiLocalTokenCount
+ 1) {
1180 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1181 return EFI_NOT_FOUND
;
1186 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1187 return EFI_NOT_FOUND
;
1190 if (!PeiExMapTableEmpty
) {
1191 Status
= ExGetNextTokeNumber (
1194 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
),
1196 (DYNAMICEX_MAPPING
*)((UINT8
*) mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
),
1197 mPeiExMapppingTableSize
1201 if (Status
== EFI_SUCCESS
) {
1205 if (!DxeExMapTableEmpty
) {
1206 Status
= ExGetNextTokeNumber (
1209 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
),
1211 (DYNAMICEX_MAPPING
*)((UINT8
*) mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
),
1212 mDxeExMapppingTableSize
1220 Get all token space guid table which is different with given token space guid.
1222 @param ExMapTableSize The size of ExMapTable in item
1223 @param ExMapTable Token space guid table that want to be scaned.
1224 @param GuidTable Guid table
1226 @return all token space guid table which is different with given token space guid.
1230 GetDistinctTokenSpace (
1231 IN OUT UINTN
*ExMapTableSize
,
1232 IN DYNAMICEX_MAPPING
*ExMapTable
,
1233 IN EFI_GUID
*GuidTable
1236 EFI_GUID
**DistinctTokenSpace
;
1243 DistinctTokenSpace
= AllocateZeroPool (*ExMapTableSize
* sizeof (EFI_GUID
*));
1244 ASSERT (DistinctTokenSpace
!= NULL
);
1247 OldGuidIndex
= ExMapTable
[0].ExGuidIndex
;
1248 DistinctTokenSpace
[TsIdx
] = &GuidTable
[OldGuidIndex
];
1249 for (Idx
= 1; Idx
< *ExMapTableSize
; Idx
++) {
1251 OldGuidIndex
= ExMapTable
[Idx
].ExGuidIndex
;
1252 for (TempTsIdx
= 0; TempTsIdx
<= TsIdx
; TempTsIdx
++) {
1253 if (&GuidTable
[OldGuidIndex
] == DistinctTokenSpace
[TempTsIdx
]) {
1255 // Have recorded this GUID.
1262 DistinctTokenSpace
[++TsIdx
] = &GuidTable
[OldGuidIndex
];
1267 // The total number of Distinct Token Space
1268 // is TsIdx + 1 because we use TsIdx as a index
1269 // to the DistinctTokenSpace[]
1271 *ExMapTableSize
= TsIdx
+ 1;
1272 return DistinctTokenSpace
;
1277 Retrieves the next valid PCD token namespace for a given namespace.
1279 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid
1280 token namespaces on a platform.
1282 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token
1283 namespace from which the search will start. On output, it designates the next valid
1284 token namespace on the platform. If *Guid is NULL, then the GUID of the first token
1285 space of the current platform is returned. If the search cannot locate the next valid
1286 token namespace, an error is returned and the value of *Guid is undefined.
1288 @retval EFI_SUCCESS The PCD service retrieved the value requested.
1289 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.
1294 DxePcdGetNextTokenSpace (
1295 IN OUT CONST EFI_GUID
**Guid
1301 UINTN PeiTokenSpaceTableSize
;
1302 UINTN DxeTokenSpaceTableSize
;
1303 EFI_GUID
**PeiTokenSpaceTable
;
1304 EFI_GUID
**DxeTokenSpaceTable
;
1306 BOOLEAN PeiExMapTableEmpty
;
1307 BOOLEAN DxeExMapTableEmpty
;
1309 ASSERT (Guid
!= NULL
);
1311 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
1312 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
1314 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1315 return EFI_NOT_FOUND
;
1318 if (TmpTokenSpaceBuffer
[0] == NULL
) {
1319 PeiTokenSpaceTableSize
= 0;
1321 if (!PeiExMapTableEmpty
) {
1322 PeiTokenSpaceTableSize
= mPeiExMapppingTableSize
/ sizeof(DYNAMICEX_MAPPING
);
1323 PeiTokenSpaceTable
= GetDistinctTokenSpace (&PeiTokenSpaceTableSize
,
1324 (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
),
1325 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
)
1327 CopyMem (TmpTokenSpaceBuffer
, PeiTokenSpaceTable
, sizeof (EFI_GUID
*) * PeiTokenSpaceTableSize
);
1328 TmpTokenSpaceBufferCount
= PeiTokenSpaceTableSize
;
1329 FreePool (PeiTokenSpaceTable
);
1332 if (!DxeExMapTableEmpty
) {
1333 DxeTokenSpaceTableSize
= mDxeExMapppingTableSize
/ sizeof(DYNAMICEX_MAPPING
);
1334 DxeTokenSpaceTable
= GetDistinctTokenSpace (&DxeTokenSpaceTableSize
,
1335 (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
),
1336 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
)
1340 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable
1342 for (Idx2
= 0, Idx3
= PeiTokenSpaceTableSize
; Idx2
< DxeTokenSpaceTableSize
; Idx2
++) {
1344 for (Idx
= 0; Idx
< PeiTokenSpaceTableSize
; Idx
++) {
1345 if (CompareGuid (TmpTokenSpaceBuffer
[Idx
], DxeTokenSpaceTable
[Idx2
])) {
1351 TmpTokenSpaceBuffer
[Idx3
++] = DxeTokenSpaceTable
[Idx2
];
1355 TmpTokenSpaceBufferCount
= Idx3
;
1356 FreePool (DxeTokenSpaceTable
);
1360 if (*Guid
== NULL
) {
1361 *Guid
= TmpTokenSpaceBuffer
[0];
1365 for (Idx
= 0; Idx
< TmpTokenSpaceBufferCount
; Idx
++) {
1366 if (CompareGuid (*Guid
, TmpTokenSpaceBuffer
[Idx
])) {
1367 if (Idx
== TmpTokenSpaceBufferCount
- 1) {
1369 // It has been the last token namespace.
1372 return EFI_NOT_FOUND
;
1375 *Guid
= TmpTokenSpaceBuffer
[Idx
];
1381 return EFI_NOT_FOUND
;