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 - 2017, 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
;
114 Main entry for PCD DXE driver.
116 This routine initialize the PCD database and install PCD_PROTOCOL.
118 @param ImageHandle Image handle for PCD DXE driver.
119 @param SystemTable Pointer to SystemTable.
121 @return Status of gBS->InstallProtocolInterface()
127 IN EFI_HANDLE ImageHandle
,
128 IN EFI_SYSTEM_TABLE
*SystemTable
135 // Make sure the Pcd Protocol is not already installed in the system
138 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gPcdProtocolGuid
);
140 BuildPcdDxeDataBase ();
143 // Install PCD_PROTOCOL to handle dynamic type PCD
144 // Install EFI_PCD_PROTOCOL to handle dynamicEx type PCD
146 Status
= gBS
->InstallMultipleProtocolInterfaces (
148 &gPcdProtocolGuid
, &mPcdInstance
,
149 &gEfiPcdProtocolGuid
, &mEfiPcdInstance
,
152 ASSERT_EFI_ERROR (Status
);
155 // Install GET_PCD_INFO_PROTOCOL to handle dynamic type PCD
156 // Install EFI_GET_PCD_INFO_PROTOCOL to handle dynamicEx type PCD
158 Status
= gBS
->InstallMultipleProtocolInterfaces (
160 &gGetPcdInfoProtocolGuid
, &mGetPcdInfoInstance
,
161 &gEfiGetPcdInfoProtocolGuid
, &mEfiGetPcdInfoInstance
,
164 ASSERT_EFI_ERROR (Status
);
167 // Register callback function upon VariableLockProtocol
168 // to lock the variables referenced by DynamicHii PCDs with RO property set in *.dsc.
170 EfiCreateProtocolNotifyEvent (
171 &gEdkiiVariableLockProtocolGuid
,
173 VariableLockCallBack
,
182 Retrieve additional information associated with a PCD token in the default token space.
184 This includes information such as the type of value the TokenNumber is associated with as well as possible
185 human readable name that is associated with the token.
187 @param[in] TokenNumber The PCD token number.
188 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
189 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
191 @retval EFI_SUCCESS The PCD information was returned successfully.
192 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
196 DxeGetPcdInfoGetInfo (
197 IN UINTN TokenNumber
,
198 OUT EFI_PCD_INFO
*PcdInfo
201 return DxeGetPcdInfo (NULL
, TokenNumber
, PcdInfo
);
205 Retrieve additional information associated with a PCD token.
207 This includes information such as the type of value the TokenNumber is associated with as well as possible
208 human readable name that is associated with the token.
210 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
211 @param[in] TokenNumber The PCD token number.
212 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
213 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
215 @retval EFI_SUCCESS The PCD information was returned successfully.
216 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
220 DxeGetPcdInfoGetInfoEx (
221 IN CONST EFI_GUID
*Guid
,
222 IN UINTN TokenNumber
,
223 OUT EFI_PCD_INFO
*PcdInfo
226 return DxeGetPcdInfo (Guid
, TokenNumber
, PcdInfo
);
230 Retrieve the currently set SKU Id.
232 @return The currently set SKU Id. If the platform has not set at a SKU Id, then the
233 default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU
238 DxeGetPcdInfoGetSku (
242 return (UINTN
) mPcdDatabase
.DxeDb
->SystemSkuId
;
246 Sets the SKU value for subsequent calls to set or get PCD token values.
248 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
249 SetSku() is normally called only once by the system.
251 For each item (token), the database can hold a single value that applies to all SKUs,
252 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
253 SKU-specific values are called SKU enabled.
255 The SKU Id of zero is reserved as a default.
256 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
257 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
258 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
259 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
260 set for that Id, the results are unpredictable.
262 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
263 set values associated with a PCD token.
276 DEBUG ((DEBUG_INFO
, "PcdDxe - SkuId 0x%lx is to be set.\n", (SKU_ID
) SkuId
));
278 if (SkuId
== mPcdDatabase
.DxeDb
->SystemSkuId
) {
280 // The input SKU Id is equal to current SKU Id, return directly.
282 DEBUG ((DEBUG_INFO
, "PcdDxe - SkuId is same to current system Sku.\n"));
286 if (mPcdDatabase
.DxeDb
->SystemSkuId
!= (SKU_ID
) 0) {
287 DEBUG ((DEBUG_ERROR
, "PcdDxe - The SKU Id could be changed only once."));
290 "PcdDxe - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",
291 mPcdDatabase
.DxeDb
->SystemSkuId
,
298 SkuIdTable
= (SKU_ID
*) ((UINT8
*) mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SkuIdTableOffset
);
299 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
300 if (SkuId
== SkuIdTable
[Index
+ 1]) {
301 DEBUG ((DEBUG_INFO
, "PcdDxe - SkuId is found in SkuId table.\n"));
302 Status
= UpdatePcdDatabase (SkuId
, TRUE
);
303 if (!EFI_ERROR (Status
)) {
304 mPcdDatabase
.DxeDb
->SystemSkuId
= (SKU_ID
) SkuId
;
305 DEBUG ((DEBUG_INFO
, "PcdDxe - Set current SKU Id to 0x%lx.\n", (SKU_ID
) SkuId
));
312 // Invalid input SkuId, the default SKU Id will be still used for the system.
314 DEBUG ((DEBUG_ERROR
, "PcdDxe - Invalid input SkuId, the default SKU Id will be still used.\n"));
319 Retrieves an 8-bit value for a given PCD token.
321 Retrieves the current byte-sized value for a PCD token number.
322 If the TokenNumber is invalid, the results are unpredictable.
324 @param[in] TokenNumber The PCD token number.
326 @return The UINT8 value.
335 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
339 Retrieves an 16-bit value for a given PCD token.
341 Retrieves the current 16-bits value for a PCD token number.
342 If the TokenNumber is invalid, the results are unpredictable.
344 @param[in] TokenNumber The PCD token number.
346 @return The UINT16 value.
355 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
359 Retrieves an 32-bit value for a given PCD token.
361 Retrieves the current 32-bits value for a PCD token number.
362 If the TokenNumber is invalid, the results are unpredictable.
364 @param[in] TokenNumber The PCD token number.
366 @return The UINT32 value.
375 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
379 Retrieves an 64-bit value for a given PCD token.
381 Retrieves the current 64-bits value for a PCD token number.
382 If the TokenNumber is invalid, the results are unpredictable.
384 @param[in] TokenNumber The PCD token number.
386 @return The UINT64 value.
395 return ReadUnaligned64(GetWorker (TokenNumber
, sizeof (UINT64
)));
399 Retrieves a pointer to a value for a given PCD token.
401 Retrieves the current pointer to the buffer for a PCD token number.
402 Do not make any assumptions about the alignment of the pointer that
403 is returned by this function call. If the TokenNumber is invalid,
404 the results are unpredictable.
406 @param[in] TokenNumber The PCD token number.
408 @return The pointer to the buffer to be retrived.
417 return GetWorker (TokenNumber
, 0);
421 Retrieves a Boolean value for a given PCD token.
423 Retrieves the current boolean value for a PCD token number.
424 Do not make any assumptions about the alignment of the pointer that
425 is returned by this function call. If the TokenNumber is invalid,
426 the results are unpredictable.
428 @param[in] TokenNumber The PCD token number.
430 @return The Boolean value.
439 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
443 Retrieves the size of the value for a given PCD token.
445 Retrieves the current size of a particular PCD token.
446 If the TokenNumber is invalid, the results are unpredictable.
448 @param[in] TokenNumber The PCD token number.
450 @return The size of the value for the PCD token.
460 UINT32
*LocalTokenNumberTable
;
463 UINTN TmpTokenNumber
;
465 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
466 // We have to decrement TokenNumber by 1 to make it usable
467 // as the array index.
472 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
474 TmpTokenNumber
= TokenNumber
;
476 // EBC compiler is very choosy. It may report warning about comparison
477 // between UINTN and 0 . So we add 1 in each size of the
479 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
481 // EBC compiler is very choosy. It may report warning about comparison
482 // between UINTN and 0 . So we add 1 in each size of the
484 IsPeiDb
= (BOOLEAN
) (TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1);
486 TokenNumber
= IsPeiDb
? TokenNumber
:
487 (TokenNumber
- mPeiLocalTokenCount
);
489 LocalTokenNumberTable
= IsPeiDb
? (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
)
490 : (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
492 Size
= (LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
496 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
498 return GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
506 Retrieves an 8-bit value for a given PCD token.
508 Retrieves the 8-bit value of a particular PCD token.
509 If the TokenNumber is invalid or the token space
510 specified by Guid does not exist, the results are
513 @param[in] Guid The token space for the token number.
514 @param[in] ExTokenNumber The PCD token number.
516 @return The size 8-bit value for the PCD token.
522 IN CONST EFI_GUID
*Guid
,
523 IN UINTN ExTokenNumber
526 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT8
)));
530 Retrieves an 16-bit value for a given PCD token.
532 Retrieves the 16-bit value of a particular PCD token.
533 If the TokenNumber is invalid or the token space
534 specified by Guid does not exist, the results are
537 @param[in] Guid The token space for the token number.
538 @param[in] ExTokenNumber The PCD token number.
540 @return The size 16-bit value for the PCD token.
546 IN CONST EFI_GUID
*Guid
,
547 IN UINTN ExTokenNumber
550 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT16
)));
554 Retrieves an 32-bit value for a given PCD token.
556 Retrieves the 32-bit value of a particular PCD token.
557 If the TokenNumber is invalid or the token space
558 specified by Guid does not exist, the results are
561 @param[in] Guid The token space for the token number.
562 @param[in] ExTokenNumber The PCD token number.
564 @return The size 32-bit value for the PCD token.
570 IN CONST EFI_GUID
*Guid
,
571 IN UINTN ExTokenNumber
574 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT32
)));
578 Retrieves an 64-bit value for a given PCD token.
580 Retrieves the 64-bit value of a particular PCD token.
581 If the TokenNumber is invalid or the token space
582 specified by Guid does not exist, the results are
585 @param[in] Guid The token space for the token number.
586 @param[in] ExTokenNumber The PCD token number.
588 @return The size 64-bit value for the PCD token.
594 IN CONST EFI_GUID
*Guid
,
595 IN UINTN ExTokenNumber
598 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT64
)));
602 Retrieves a pointer to a value for a given PCD token.
604 Retrieves the current pointer to the buffer for a PCD token number.
605 Do not make any assumptions about the alignment of the pointer that
606 is returned by this function call. If the TokenNumber is invalid,
607 the results are unpredictable.
609 @param[in] Guid The token space for the token number.
610 @param[in] ExTokenNumber The PCD token number.
612 @return The pointer to the buffer to be retrived.
618 IN CONST EFI_GUID
*Guid
,
619 IN UINTN ExTokenNumber
622 return ExGetWorker (Guid
, ExTokenNumber
, 0);
626 Retrieves an Boolean value for a given PCD token.
628 Retrieves the Boolean value of a particular PCD token.
629 If the TokenNumber is invalid or the token space
630 specified by Guid does not exist, the results are
633 @param[in] Guid The token space for the token number.
634 @param[in] ExTokenNumber The PCD token number.
636 @return The size Boolean value for the PCD token.
642 IN CONST EFI_GUID
*Guid
,
643 IN UINTN ExTokenNumber
646 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(BOOLEAN
)));
650 Retrieves the size of the value for a given PCD token.
652 Retrieves the current size of a particular PCD token.
653 If the TokenNumber is invalid, the results are unpredictable.
655 @param[in] Guid The token space for the token number.
656 @param[in] ExTokenNumber The PCD token number.
658 @return The size of the value for the PCD token.
664 IN CONST EFI_GUID
*Guid
,
665 IN UINTN ExTokenNumber
668 return DxePcdGetSize(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
));
672 Sets an 8-bit value for a given PCD token.
674 When the PCD service sets a value, it will check to ensure that the
675 size of the value being set is compatible with the Token's existing definition.
676 If it is not, an error will be returned.
678 @param[in] TokenNumber The PCD token number.
679 @param[in] Value The value to set for the PCD token.
681 @retval EFI_SUCCESS Procedure returned successfully.
682 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
683 being set was incompatible with a call to this function.
684 Use GetSize() to retrieve the size of the target data.
685 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
691 IN UINTN TokenNumber
,
695 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
699 Sets an 16-bit value for a given PCD token.
701 When the PCD service sets a value, it will check to ensure that the
702 size of the value being set is compatible with the Token's existing definition.
703 If it is not, an error will be returned.
705 @param[in] TokenNumber The PCD token number.
706 @param[in] Value The value to set for the PCD token.
708 @retval EFI_SUCCESS Procedure returned successfully.
709 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
710 being set was incompatible with a call to this function.
711 Use GetSize() to retrieve the size of the target data.
712 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
718 IN UINTN TokenNumber
,
722 return SetValueWorker (TokenNumber
, &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] TokenNumber The PCD token number.
733 @param[in] Value The value to set for the PCD token.
735 @retval EFI_SUCCESS Procedure returned successfully.
736 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
737 being set was incompatible with a call to this function.
738 Use GetSize() to retrieve the size of the target data.
739 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
745 IN UINTN TokenNumber
,
749 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
753 Sets an 64-bit value for a given PCD token.
755 When the PCD service sets a value, it will check to ensure that the
756 size of the value being set is compatible with the Token's existing definition.
757 If it is not, an error will be returned.
759 @param[in] TokenNumber The PCD token number.
760 @param[in] Value The value to set for the PCD token.
762 @retval EFI_SUCCESS Procedure returned successfully.
763 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
764 being set was incompatible with a call to this function.
765 Use GetSize() to retrieve the size of the target data.
766 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
772 IN UINTN TokenNumber
,
776 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
780 Sets a value of a specified size for a given PCD token.
782 When the PCD service sets a value, it will check to ensure that the
783 size of the value being set is compatible with the Token's existing definition.
784 If it is not, an error will be returned.
786 @param[in] TokenNumber The PCD token number.
787 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
788 On input, if the SizeOfValue is greater than the maximum size supported
789 for this TokenNumber then the output value of SizeOfValue will reflect
790 the maximum size supported for this TokenNumber.
791 @param[in] Buffer The buffer to set for the PCD token.
793 @retval EFI_SUCCESS Procedure returned successfully.
794 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
795 being set was incompatible with a call to this function.
796 Use GetSize() to retrieve the size of the target data.
797 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
803 IN UINTN TokenNumber
,
804 IN OUT UINTN
*SizeOfBuffer
,
808 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
812 Sets an Boolean value for a given PCD token.
814 When the PCD service sets a value, it will check to ensure that the
815 size of the value being set is compatible with the Token's existing definition.
816 If it is not, an error will be returned.
818 @param[in] TokenNumber The PCD token number.
819 @param[in] Value The value to set for the PCD token.
821 @retval EFI_SUCCESS Procedure returned successfully.
822 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
823 being set was incompatible with a call to this function.
824 Use GetSize() to retrieve the size of the target data.
825 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
831 IN UINTN TokenNumber
,
835 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
839 Sets an 8-bit value for a given PCD token.
841 When the PCD service sets a value, it will check to ensure that the
842 size of the value being set is compatible with the Token's existing definition.
843 If it is not, an error will be returned.
845 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
846 @param[in] ExTokenNumber The PCD token number.
847 @param[in] Value The value to set for the PCD token.
849 @retval EFI_SUCCESS Procedure returned successfully.
850 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
851 being set was incompatible with a call to this function.
852 Use GetSize() to retrieve the size of the target data.
853 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
859 IN CONST EFI_GUID
*Guid
,
860 IN UINTN ExTokenNumber
,
864 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
868 Sets an 16-bit value for a given PCD token.
870 When the PCD service sets a value, it will check to ensure that the
871 size of the value being set is compatible with the Token's existing definition.
872 If it is not, an error will be returned.
874 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
875 @param[in] ExTokenNumber The PCD token number.
876 @param[in] Value The value to set for the PCD token.
878 @retval EFI_SUCCESS Procedure returned successfully.
879 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
880 being set was incompatible with a call to this function.
881 Use GetSize() to retrieve the size of the target data.
882 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
888 IN CONST EFI_GUID
*Guid
,
889 IN UINTN ExTokenNumber
,
893 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
897 Sets an 32-bit value for a given PCD token.
899 When the PCD service sets a value, it will check to ensure that the
900 size of the value being set is compatible with the Token's existing definition.
901 If it is not, an error will be returned.
903 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
904 @param[in] ExTokenNumber The PCD token number.
905 @param[in] Value The value to set for the PCD token.
907 @retval EFI_SUCCESS Procedure returned successfully.
908 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
909 being set was incompatible with a call to this function.
910 Use GetSize() to retrieve the size of the target data.
911 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
917 IN CONST EFI_GUID
*Guid
,
918 IN UINTN ExTokenNumber
,
922 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
926 Sets an 64-bit value for a given PCD token.
928 When the PCD service sets a value, it will check to ensure that the
929 size of the value being set is compatible with the Token's existing definition.
930 If it is not, an error will be returned.
932 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
933 @param[in] ExTokenNumber The PCD token number.
934 @param[in] Value The value to set for the PCD token.
936 @retval EFI_SUCCESS Procedure returned successfully.
937 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
938 being set was incompatible with a call to this function.
939 Use GetSize() to retrieve the size of the target data.
940 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
946 IN CONST EFI_GUID
*Guid
,
947 IN UINTN ExTokenNumber
,
951 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
955 Sets a value of a specified size for a given PCD token.
957 When the PCD service sets a value, it will check to ensure that the
958 size of the value being set is compatible with the Token's existing definition.
959 If it is not, an error will be returned.
961 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
962 @param[in] ExTokenNumber The PCD token number.
963 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
964 On input, if the SizeOfValue is greater than the maximum size supported
965 for this TokenNumber then the output value of SizeOfValue will reflect
966 the maximum size supported for this TokenNumber.
967 @param[in] Buffer The buffer to set for the PCD token.
969 @retval EFI_SUCCESS Procedure returned successfully.
970 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
971 being set was incompatible with a call to this function.
972 Use GetSize() to retrieve the size of the target data.
973 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
979 IN CONST EFI_GUID
*Guid
,
980 IN UINTN ExTokenNumber
,
981 IN OUT UINTN
*SizeOfBuffer
,
985 return ExSetWorker(ExTokenNumber
, Guid
, Buffer
, SizeOfBuffer
, TRUE
);
989 Sets an Boolean value for a given PCD token.
991 When the PCD service sets a value, it will check to ensure that the
992 size of the value being set is compatible with the Token's existing definition.
993 If it is not, an error will be returned.
995 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
996 @param[in] ExTokenNumber The PCD token number.
997 @param[in] Value The value to set for the PCD token.
999 @retval EFI_SUCCESS Procedure returned successfully.
1000 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
1001 being set was incompatible with a call to this function.
1002 Use GetSize() to retrieve the size of the target data.
1003 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1009 IN CONST EFI_GUID
*Guid
,
1010 IN UINTN ExTokenNumber
,
1014 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
1018 Specifies a function to be called anytime the value of a designated token is changed.
1020 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1021 @param[in] TokenNumber The PCD token number.
1022 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1024 @retval EFI_SUCCESS The PCD service has successfully established a call event
1025 for the CallBackToken requested.
1026 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1031 DxeRegisterCallBackOnSet (
1032 IN CONST EFI_GUID
*Guid
, OPTIONAL
1033 IN UINTN TokenNumber
,
1034 IN PCD_PROTOCOL_CALLBACK CallBackFunction
1039 if (CallBackFunction
== NULL
) {
1040 return EFI_INVALID_PARAMETER
;
1043 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1045 EfiAcquireLock (&mPcdDatabaseLock
);
1047 Status
= DxeRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
1049 EfiReleaseLock (&mPcdDatabaseLock
);
1055 Cancels a previously set callback function for a particular PCD token number.
1057 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1058 @param[in] TokenNumber The PCD token number.
1059 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1061 @retval EFI_SUCCESS The PCD service has successfully established a call event
1062 for the CallBackToken requested.
1063 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1068 DxeUnRegisterCallBackOnSet (
1069 IN CONST EFI_GUID
*Guid
, OPTIONAL
1070 IN UINTN TokenNumber
,
1071 IN PCD_PROTOCOL_CALLBACK CallBackFunction
1076 if (CallBackFunction
== NULL
) {
1077 return EFI_INVALID_PARAMETER
;
1081 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1083 EfiAcquireLock (&mPcdDatabaseLock
);
1085 Status
= DxeUnRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
1087 EfiReleaseLock (&mPcdDatabaseLock
);
1093 Retrieves the next valid token number in a given namespace.
1095 This is useful since the PCD infrastructure contains a sparse list of token numbers,
1096 and one cannot a priori know what token numbers are valid in the database.
1098 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
1099 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
1100 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
1101 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
1102 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
1103 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
1104 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1105 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1108 @param[in] Guid The 128-bit unique value that designates the namespace from which to retrieve the next token.
1109 This is an optional parameter that may be NULL. If this parameter is NULL, then a request is
1110 being made to retrieve tokens from the default token space.
1111 @param[in, out] TokenNumber
1112 A pointer to the PCD token number to use to find the subsequent token number.
1114 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.
1115 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.
1120 DxePcdGetNextToken (
1121 IN CONST EFI_GUID
*Guid
, OPTIONAL
1122 IN OUT UINTN
*TokenNumber
1126 BOOLEAN PeiExMapTableEmpty
;
1127 BOOLEAN DxeExMapTableEmpty
;
1129 Status
= EFI_NOT_FOUND
;
1130 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
1131 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
1134 // Scan the local token space
1137 // EBC compiler is very choosy. It may report warning about comparison
1138 // between UINTN and 0 . So we add 1 in each size of the
1140 if (((*TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) && (*TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) ||
1141 ((*TokenNumber
+ 1 > (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1)))) {
1142 return EFI_NOT_FOUND
;
1146 if ((*TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) &&
1147 (*TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) {
1149 // The first Non-Ex type Token Number for DXE PCD
1150 // database is mPeiLocalTokenCount + 1
1152 if (mDxeNexTokenCount
> 0) {
1153 *TokenNumber
= mPeiLocalTokenCount
+ 1;
1155 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1156 return EFI_NOT_FOUND
;
1158 } else if (*TokenNumber
+ 1 > mDxeNexTokenCount
+ mPeiLocalTokenCount
+ 1) {
1159 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1160 return EFI_NOT_FOUND
;
1165 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1166 return EFI_NOT_FOUND
;
1169 if (!PeiExMapTableEmpty
) {
1170 Status
= ExGetNextTokeNumber (
1173 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
),
1175 (DYNAMICEX_MAPPING
*)((UINT8
*) mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
),
1176 mPeiExMapppingTableSize
1180 if (Status
== EFI_SUCCESS
) {
1184 if (!DxeExMapTableEmpty
) {
1185 Status
= ExGetNextTokeNumber (
1188 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
),
1190 (DYNAMICEX_MAPPING
*)((UINT8
*) mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
),
1191 mDxeExMapppingTableSize
1199 Get all token space guid table which is different with given token space guid.
1201 @param ExMapTableSize The size of ExMapTable in item
1202 @param ExMapTable Token space guid table that want to be scaned.
1203 @param GuidTable Guid table
1205 @return all token space guid table which is different with given token space guid.
1209 GetDistinctTokenSpace (
1210 IN OUT UINTN
*ExMapTableSize
,
1211 IN DYNAMICEX_MAPPING
*ExMapTable
,
1212 IN EFI_GUID
*GuidTable
1215 EFI_GUID
**DistinctTokenSpace
;
1222 DistinctTokenSpace
= AllocateZeroPool (*ExMapTableSize
* sizeof (EFI_GUID
*));
1223 ASSERT (DistinctTokenSpace
!= NULL
);
1226 OldGuidIndex
= ExMapTable
[0].ExGuidIndex
;
1227 DistinctTokenSpace
[TsIdx
] = &GuidTable
[OldGuidIndex
];
1228 for (Idx
= 1; Idx
< *ExMapTableSize
; Idx
++) {
1230 OldGuidIndex
= ExMapTable
[Idx
].ExGuidIndex
;
1231 for (TempTsIdx
= 0; TempTsIdx
<= TsIdx
; TempTsIdx
++) {
1232 if (&GuidTable
[OldGuidIndex
] == DistinctTokenSpace
[TempTsIdx
]) {
1234 // Have recorded this GUID.
1241 DistinctTokenSpace
[++TsIdx
] = &GuidTable
[OldGuidIndex
];
1246 // The total number of Distinct Token Space
1247 // is TsIdx + 1 because we use TsIdx as a index
1248 // to the DistinctTokenSpace[]
1250 *ExMapTableSize
= TsIdx
+ 1;
1251 return DistinctTokenSpace
;
1256 Retrieves the next valid PCD token namespace for a given namespace.
1258 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid
1259 token namespaces on a platform.
1261 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token
1262 namespace from which the search will start. On output, it designates the next valid
1263 token namespace on the platform. If *Guid is NULL, then the GUID of the first token
1264 space of the current platform is returned. If the search cannot locate the next valid
1265 token namespace, an error is returned and the value of *Guid is undefined.
1267 @retval EFI_SUCCESS The PCD service retrieved the value requested.
1268 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.
1273 DxePcdGetNextTokenSpace (
1274 IN OUT CONST EFI_GUID
**Guid
1280 UINTN PeiTokenSpaceTableSize
;
1281 UINTN DxeTokenSpaceTableSize
;
1282 EFI_GUID
**PeiTokenSpaceTable
;
1283 EFI_GUID
**DxeTokenSpaceTable
;
1285 BOOLEAN PeiExMapTableEmpty
;
1286 BOOLEAN DxeExMapTableEmpty
;
1288 ASSERT (Guid
!= NULL
);
1290 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
1291 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
1293 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1294 return EFI_NOT_FOUND
;
1297 if (TmpTokenSpaceBuffer
[0] == NULL
) {
1298 PeiTokenSpaceTableSize
= 0;
1300 if (!PeiExMapTableEmpty
) {
1301 PeiTokenSpaceTableSize
= mPeiExMapppingTableSize
/ sizeof(DYNAMICEX_MAPPING
);
1302 PeiTokenSpaceTable
= GetDistinctTokenSpace (&PeiTokenSpaceTableSize
,
1303 (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
),
1304 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
)
1306 CopyMem (TmpTokenSpaceBuffer
, PeiTokenSpaceTable
, sizeof (EFI_GUID
*) * PeiTokenSpaceTableSize
);
1307 TmpTokenSpaceBufferCount
= PeiTokenSpaceTableSize
;
1308 FreePool (PeiTokenSpaceTable
);
1311 if (!DxeExMapTableEmpty
) {
1312 DxeTokenSpaceTableSize
= mDxeExMapppingTableSize
/ sizeof(DYNAMICEX_MAPPING
);
1313 DxeTokenSpaceTable
= GetDistinctTokenSpace (&DxeTokenSpaceTableSize
,
1314 (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
),
1315 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
)
1319 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable
1321 for (Idx2
= 0, Idx3
= PeiTokenSpaceTableSize
; Idx2
< DxeTokenSpaceTableSize
; Idx2
++) {
1323 for (Idx
= 0; Idx
< PeiTokenSpaceTableSize
; Idx
++) {
1324 if (CompareGuid (TmpTokenSpaceBuffer
[Idx
], DxeTokenSpaceTable
[Idx2
])) {
1330 TmpTokenSpaceBuffer
[Idx3
++] = DxeTokenSpaceTable
[Idx2
];
1334 TmpTokenSpaceBufferCount
= Idx3
;
1335 FreePool (DxeTokenSpaceTable
);
1339 if (*Guid
== NULL
) {
1340 *Guid
= TmpTokenSpaceBuffer
[0];
1344 for (Idx
= 0; Idx
< TmpTokenSpaceBufferCount
; Idx
++) {
1345 if (CompareGuid (*Guid
, TmpTokenSpaceBuffer
[Idx
])) {
1346 if (Idx
== TmpTokenSpaceBufferCount
- 1) {
1348 // It has been the last token namespace.
1351 return EFI_NOT_FOUND
;
1354 *Guid
= TmpTokenSpaceBuffer
[Idx
];
1360 return EFI_NOT_FOUND
;