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.
275 if (SkuId
== mPcdDatabase
.DxeDb
->SystemSkuId
) {
277 // The input SKU Id is equal to current SKU Id, return directly.
282 if (mPcdDatabase
.DxeDb
->SystemSkuId
!= (SKU_ID
) 0) {
283 DEBUG ((DEBUG_ERROR
, "PcdDxe - The SKU Id could be changed only once."));
286 "PcdDxe - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",
287 mPcdDatabase
.DxeDb
->SystemSkuId
,
294 SkuIdTable
= (SKU_ID
*) ((UINT8
*) mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SkuIdTableOffset
);
295 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
296 if (SkuId
== SkuIdTable
[Index
+ 1]) {
297 DEBUG ((EFI_D_INFO
, "PcdDxe - Set current SKU Id to 0x%lx.\n", (SKU_ID
) SkuId
));
298 mPcdDatabase
.DxeDb
->SystemSkuId
= (SKU_ID
) SkuId
;
304 // Invalid input SkuId, the default SKU Id will be still used for the system.
306 DEBUG ((EFI_D_INFO
, "PcdDxe - Invalid input SkuId, the default SKU Id will be still used.\n"));
311 Retrieves an 8-bit value for a given PCD token.
313 Retrieves the current byte-sized value for a PCD token number.
314 If the TokenNumber is invalid, the results are unpredictable.
316 @param[in] TokenNumber The PCD token number.
318 @return The UINT8 value.
327 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
331 Retrieves an 16-bit value for a given PCD token.
333 Retrieves the current 16-bits value for a PCD token number.
334 If the TokenNumber is invalid, the results are unpredictable.
336 @param[in] TokenNumber The PCD token number.
338 @return The UINT16 value.
347 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
351 Retrieves an 32-bit value for a given PCD token.
353 Retrieves the current 32-bits value for a PCD token number.
354 If the TokenNumber is invalid, the results are unpredictable.
356 @param[in] TokenNumber The PCD token number.
358 @return The UINT32 value.
367 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
371 Retrieves an 64-bit value for a given PCD token.
373 Retrieves the current 64-bits value for a PCD token number.
374 If the TokenNumber is invalid, the results are unpredictable.
376 @param[in] TokenNumber The PCD token number.
378 @return The UINT64 value.
387 return ReadUnaligned64(GetWorker (TokenNumber
, sizeof (UINT64
)));
391 Retrieves a pointer to a value for a given PCD token.
393 Retrieves the current pointer to the buffer for a PCD token number.
394 Do not make any assumptions about the alignment of the pointer that
395 is returned by this function call. If the TokenNumber is invalid,
396 the results are unpredictable.
398 @param[in] TokenNumber The PCD token number.
400 @return The pointer to the buffer to be retrived.
409 return GetWorker (TokenNumber
, 0);
413 Retrieves a Boolean value for a given PCD token.
415 Retrieves the current boolean value for a PCD token number.
416 Do not make any assumptions about the alignment of the pointer that
417 is returned by this function call. If the TokenNumber is invalid,
418 the results are unpredictable.
420 @param[in] TokenNumber The PCD token number.
422 @return The Boolean value.
431 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
435 Retrieves the size of the value for a given PCD token.
437 Retrieves the current size of a particular PCD token.
438 If the TokenNumber is invalid, the results are unpredictable.
440 @param[in] TokenNumber The PCD token number.
442 @return The size of the value for the PCD token.
452 UINT32
*LocalTokenNumberTable
;
455 UINTN TmpTokenNumber
;
457 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
458 // We have to decrement TokenNumber by 1 to make it usable
459 // as the array index.
464 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
466 TmpTokenNumber
= TokenNumber
;
468 // EBC compiler is very choosy. It may report warning about comparison
469 // between UINTN and 0 . So we add 1 in each size of the
471 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
473 // EBC compiler is very choosy. It may report warning about comparison
474 // between UINTN and 0 . So we add 1 in each size of the
476 IsPeiDb
= (BOOLEAN
) (TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1);
478 TokenNumber
= IsPeiDb
? TokenNumber
:
479 (TokenNumber
- mPeiLocalTokenCount
);
481 LocalTokenNumberTable
= IsPeiDb
? (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
)
482 : (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
484 Size
= (LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
488 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
490 return GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
498 Retrieves an 8-bit value for a given PCD token.
500 Retrieves the 8-bit value of a particular PCD token.
501 If the TokenNumber is invalid or the token space
502 specified by Guid does not exist, the results are
505 @param[in] Guid The token space for the token number.
506 @param[in] ExTokenNumber The PCD token number.
508 @return The size 8-bit value for the PCD token.
514 IN CONST EFI_GUID
*Guid
,
515 IN UINTN ExTokenNumber
518 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT8
)));
522 Retrieves an 16-bit value for a given PCD token.
524 Retrieves the 16-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 16-bit value for the PCD token.
538 IN CONST EFI_GUID
*Guid
,
539 IN UINTN ExTokenNumber
542 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT16
)));
546 Retrieves an 32-bit value for a given PCD token.
548 Retrieves the 32-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 32-bit value for the PCD token.
562 IN CONST EFI_GUID
*Guid
,
563 IN UINTN ExTokenNumber
566 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT32
)));
570 Retrieves an 64-bit value for a given PCD token.
572 Retrieves the 64-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 64-bit value for the PCD token.
586 IN CONST EFI_GUID
*Guid
,
587 IN UINTN ExTokenNumber
590 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT64
)));
594 Retrieves a pointer to a value for a given PCD token.
596 Retrieves the current pointer to the buffer for a PCD token number.
597 Do not make any assumptions about the alignment of the pointer that
598 is returned by this function call. If the TokenNumber is invalid,
599 the results are unpredictable.
601 @param[in] Guid The token space for the token number.
602 @param[in] ExTokenNumber The PCD token number.
604 @return The pointer to the buffer to be retrived.
610 IN CONST EFI_GUID
*Guid
,
611 IN UINTN ExTokenNumber
614 return ExGetWorker (Guid
, ExTokenNumber
, 0);
618 Retrieves an Boolean value for a given PCD token.
620 Retrieves the Boolean value of a particular PCD token.
621 If the TokenNumber is invalid or the token space
622 specified by Guid does not exist, the results are
625 @param[in] Guid The token space for the token number.
626 @param[in] ExTokenNumber The PCD token number.
628 @return The size Boolean value for the PCD token.
634 IN CONST EFI_GUID
*Guid
,
635 IN UINTN ExTokenNumber
638 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(BOOLEAN
)));
642 Retrieves the size of the value for a given PCD token.
644 Retrieves the current size of a particular PCD token.
645 If the TokenNumber is invalid, the results are unpredictable.
647 @param[in] Guid The token space for the token number.
648 @param[in] ExTokenNumber The PCD token number.
650 @return The size of the value for the PCD token.
656 IN CONST EFI_GUID
*Guid
,
657 IN UINTN ExTokenNumber
660 return DxePcdGetSize(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
));
664 Sets an 8-bit value for a given PCD token.
666 When the PCD service sets a value, it will check to ensure that the
667 size of the value being set is compatible with the Token's existing definition.
668 If it is not, an error will be returned.
670 @param[in] TokenNumber The PCD token number.
671 @param[in] Value The value to set for the PCD token.
673 @retval EFI_SUCCESS Procedure returned successfully.
674 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
675 being set was incompatible with a call to this function.
676 Use GetSize() to retrieve the size of the target data.
677 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
683 IN UINTN TokenNumber
,
687 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
691 Sets an 16-bit value for a given PCD token.
693 When the PCD service sets a value, it will check to ensure that the
694 size of the value being set is compatible with the Token's existing definition.
695 If it is not, an error will be returned.
697 @param[in] TokenNumber The PCD token number.
698 @param[in] Value The value to set for the PCD token.
700 @retval EFI_SUCCESS Procedure returned successfully.
701 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
702 being set was incompatible with a call to this function.
703 Use GetSize() to retrieve the size of the target data.
704 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
710 IN UINTN TokenNumber
,
714 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
718 Sets an 32-bit value for a given PCD token.
720 When the PCD service sets a value, it will check to ensure that the
721 size of the value being set is compatible with the Token's existing definition.
722 If it is not, an error will be returned.
724 @param[in] TokenNumber The PCD token number.
725 @param[in] Value The value to set for the PCD token.
727 @retval EFI_SUCCESS Procedure returned successfully.
728 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
729 being set was incompatible with a call to this function.
730 Use GetSize() to retrieve the size of the target data.
731 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
737 IN UINTN TokenNumber
,
741 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
745 Sets an 64-bit value for a given PCD token.
747 When the PCD service sets a value, it will check to ensure that the
748 size of the value being set is compatible with the Token's existing definition.
749 If it is not, an error will be returned.
751 @param[in] TokenNumber The PCD token number.
752 @param[in] Value The value to set for the PCD token.
754 @retval EFI_SUCCESS Procedure returned successfully.
755 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
756 being set was incompatible with a call to this function.
757 Use GetSize() to retrieve the size of the target data.
758 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
764 IN UINTN TokenNumber
,
768 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
772 Sets a value of a specified size for a given PCD token.
774 When the PCD service sets a value, it will check to ensure that the
775 size of the value being set is compatible with the Token's existing definition.
776 If it is not, an error will be returned.
778 @param[in] TokenNumber The PCD token number.
779 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
780 On input, if the SizeOfValue is greater than the maximum size supported
781 for this TokenNumber then the output value of SizeOfValue will reflect
782 the maximum size supported for this TokenNumber.
783 @param[in] Buffer The buffer to set for the PCD token.
785 @retval EFI_SUCCESS Procedure returned successfully.
786 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
787 being set was incompatible with a call to this function.
788 Use GetSize() to retrieve the size of the target data.
789 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
795 IN UINTN TokenNumber
,
796 IN OUT UINTN
*SizeOfBuffer
,
800 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
804 Sets an Boolean value for a given PCD token.
806 When the PCD service sets a value, it will check to ensure that the
807 size of the value being set is compatible with the Token's existing definition.
808 If it is not, an error will be returned.
810 @param[in] TokenNumber The PCD token number.
811 @param[in] Value The value to set for the PCD token.
813 @retval EFI_SUCCESS Procedure returned successfully.
814 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
815 being set was incompatible with a call to this function.
816 Use GetSize() to retrieve the size of the target data.
817 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
823 IN UINTN TokenNumber
,
827 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
831 Sets an 8-bit value for a given PCD token.
833 When the PCD service sets a value, it will check to ensure that the
834 size of the value being set is compatible with the Token's existing definition.
835 If it is not, an error will be returned.
837 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
838 @param[in] ExTokenNumber The PCD token number.
839 @param[in] Value The value to set for the PCD token.
841 @retval EFI_SUCCESS Procedure returned successfully.
842 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
843 being set was incompatible with a call to this function.
844 Use GetSize() to retrieve the size of the target data.
845 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
851 IN CONST EFI_GUID
*Guid
,
852 IN UINTN ExTokenNumber
,
856 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
860 Sets an 16-bit value for a given PCD token.
862 When the PCD service sets a value, it will check to ensure that the
863 size of the value being set is compatible with the Token's existing definition.
864 If it is not, an error will be returned.
866 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
867 @param[in] ExTokenNumber The PCD token number.
868 @param[in] Value The value to set for the PCD token.
870 @retval EFI_SUCCESS Procedure returned successfully.
871 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
872 being set was incompatible with a call to this function.
873 Use GetSize() to retrieve the size of the target data.
874 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
880 IN CONST EFI_GUID
*Guid
,
881 IN UINTN ExTokenNumber
,
885 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
889 Sets an 32-bit value for a given PCD token.
891 When the PCD service sets a value, it will check to ensure that the
892 size of the value being set is compatible with the Token's existing definition.
893 If it is not, an error will be returned.
895 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
896 @param[in] ExTokenNumber The PCD token number.
897 @param[in] Value The value to set for the PCD token.
899 @retval EFI_SUCCESS Procedure returned successfully.
900 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
901 being set was incompatible with a call to this function.
902 Use GetSize() to retrieve the size of the target data.
903 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
909 IN CONST EFI_GUID
*Guid
,
910 IN UINTN ExTokenNumber
,
914 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
918 Sets an 64-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 a value of a specified size 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, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
956 On input, if the SizeOfValue is greater than the maximum size supported
957 for this TokenNumber then the output value of SizeOfValue will reflect
958 the maximum size supported for this TokenNumber.
959 @param[in] Buffer The buffer to set for the PCD token.
961 @retval EFI_SUCCESS Procedure returned successfully.
962 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
963 being set was incompatible with a call to this function.
964 Use GetSize() to retrieve the size of the target data.
965 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
971 IN CONST EFI_GUID
*Guid
,
972 IN UINTN ExTokenNumber
,
973 IN OUT UINTN
*SizeOfBuffer
,
977 return ExSetWorker(ExTokenNumber
, Guid
, Buffer
, SizeOfBuffer
, TRUE
);
981 Sets an Boolean value for a given PCD token.
983 When the PCD service sets a value, it will check to ensure that the
984 size of the value being set is compatible with the Token's existing definition.
985 If it is not, an error will be returned.
987 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
988 @param[in] ExTokenNumber The PCD token number.
989 @param[in] Value The value to set for the PCD token.
991 @retval EFI_SUCCESS Procedure returned successfully.
992 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
993 being set was incompatible with a call to this function.
994 Use GetSize() to retrieve the size of the target data.
995 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
1001 IN CONST EFI_GUID
*Guid
,
1002 IN UINTN ExTokenNumber
,
1006 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
1010 Specifies a function to be called anytime the value of a designated token is changed.
1012 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1013 @param[in] TokenNumber The PCD token number.
1014 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1016 @retval EFI_SUCCESS The PCD service has successfully established a call event
1017 for the CallBackToken requested.
1018 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1023 DxeRegisterCallBackOnSet (
1024 IN CONST EFI_GUID
*Guid
, OPTIONAL
1025 IN UINTN TokenNumber
,
1026 IN PCD_PROTOCOL_CALLBACK CallBackFunction
1031 if (CallBackFunction
== NULL
) {
1032 return EFI_INVALID_PARAMETER
;
1035 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1037 EfiAcquireLock (&mPcdDatabaseLock
);
1039 Status
= DxeRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
1041 EfiReleaseLock (&mPcdDatabaseLock
);
1047 Cancels a previously set callback function for a particular PCD token number.
1049 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1050 @param[in] TokenNumber The PCD token number.
1051 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1053 @retval EFI_SUCCESS The PCD service has successfully established a call event
1054 for the CallBackToken requested.
1055 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1060 DxeUnRegisterCallBackOnSet (
1061 IN CONST EFI_GUID
*Guid
, OPTIONAL
1062 IN UINTN TokenNumber
,
1063 IN PCD_PROTOCOL_CALLBACK CallBackFunction
1068 if (CallBackFunction
== NULL
) {
1069 return EFI_INVALID_PARAMETER
;
1073 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1075 EfiAcquireLock (&mPcdDatabaseLock
);
1077 Status
= DxeUnRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
1079 EfiReleaseLock (&mPcdDatabaseLock
);
1085 Retrieves the next valid token number in a given namespace.
1087 This is useful since the PCD infrastructure contains a sparse list of token numbers,
1088 and one cannot a priori know what token numbers are valid in the database.
1090 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
1091 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
1092 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
1093 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
1094 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
1095 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
1096 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1097 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1100 @param[in] Guid The 128-bit unique value that designates the namespace from which to retrieve the next token.
1101 This is an optional parameter that may be NULL. If this parameter is NULL, then a request is
1102 being made to retrieve tokens from the default token space.
1103 @param[in, out] TokenNumber
1104 A pointer to the PCD token number to use to find the subsequent token number.
1106 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.
1107 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.
1112 DxePcdGetNextToken (
1113 IN CONST EFI_GUID
*Guid
, OPTIONAL
1114 IN OUT UINTN
*TokenNumber
1118 BOOLEAN PeiExMapTableEmpty
;
1119 BOOLEAN DxeExMapTableEmpty
;
1121 Status
= EFI_NOT_FOUND
;
1122 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
1123 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
1126 // Scan the local token space
1129 // EBC compiler is very choosy. It may report warning about comparison
1130 // between UINTN and 0 . So we add 1 in each size of the
1132 if (((*TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) && (*TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) ||
1133 ((*TokenNumber
+ 1 > (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1)))) {
1134 return EFI_NOT_FOUND
;
1138 if ((*TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) &&
1139 (*TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) {
1141 // The first Non-Ex type Token Number for DXE PCD
1142 // database is mPeiLocalTokenCount + 1
1144 if (mDxeNexTokenCount
> 0) {
1145 *TokenNumber
= mPeiLocalTokenCount
+ 1;
1147 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1148 return EFI_NOT_FOUND
;
1150 } else if (*TokenNumber
+ 1 > mDxeNexTokenCount
+ mPeiLocalTokenCount
+ 1) {
1151 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1152 return EFI_NOT_FOUND
;
1157 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1158 return EFI_NOT_FOUND
;
1161 if (!PeiExMapTableEmpty
) {
1162 Status
= ExGetNextTokeNumber (
1165 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
),
1167 (DYNAMICEX_MAPPING
*)((UINT8
*) mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
),
1168 mPeiExMapppingTableSize
1172 if (Status
== EFI_SUCCESS
) {
1176 if (!DxeExMapTableEmpty
) {
1177 Status
= ExGetNextTokeNumber (
1180 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
),
1182 (DYNAMICEX_MAPPING
*)((UINT8
*) mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
),
1183 mDxeExMapppingTableSize
1191 Get all token space guid table which is different with given token space guid.
1193 @param ExMapTableSize The size of ExMapTable in item
1194 @param ExMapTable Token space guid table that want to be scaned.
1195 @param GuidTable Guid table
1197 @return all token space guid table which is different with given token space guid.
1201 GetDistinctTokenSpace (
1202 IN OUT UINTN
*ExMapTableSize
,
1203 IN DYNAMICEX_MAPPING
*ExMapTable
,
1204 IN EFI_GUID
*GuidTable
1207 EFI_GUID
**DistinctTokenSpace
;
1214 DistinctTokenSpace
= AllocateZeroPool (*ExMapTableSize
* sizeof (EFI_GUID
*));
1215 ASSERT (DistinctTokenSpace
!= NULL
);
1218 OldGuidIndex
= ExMapTable
[0].ExGuidIndex
;
1219 DistinctTokenSpace
[TsIdx
] = &GuidTable
[OldGuidIndex
];
1220 for (Idx
= 1; Idx
< *ExMapTableSize
; Idx
++) {
1222 OldGuidIndex
= ExMapTable
[Idx
].ExGuidIndex
;
1223 for (TempTsIdx
= 0; TempTsIdx
<= TsIdx
; TempTsIdx
++) {
1224 if (&GuidTable
[OldGuidIndex
] == DistinctTokenSpace
[TempTsIdx
]) {
1226 // Have recorded this GUID.
1233 DistinctTokenSpace
[++TsIdx
] = &GuidTable
[OldGuidIndex
];
1238 // The total number of Distinct Token Space
1239 // is TsIdx + 1 because we use TsIdx as a index
1240 // to the DistinctTokenSpace[]
1242 *ExMapTableSize
= TsIdx
+ 1;
1243 return DistinctTokenSpace
;
1248 Retrieves the next valid PCD token namespace for a given namespace.
1250 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid
1251 token namespaces on a platform.
1253 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token
1254 namespace from which the search will start. On output, it designates the next valid
1255 token namespace on the platform. If *Guid is NULL, then the GUID of the first token
1256 space of the current platform is returned. If the search cannot locate the next valid
1257 token namespace, an error is returned and the value of *Guid is undefined.
1259 @retval EFI_SUCCESS The PCD service retrieved the value requested.
1260 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.
1265 DxePcdGetNextTokenSpace (
1266 IN OUT CONST EFI_GUID
**Guid
1272 UINTN PeiTokenSpaceTableSize
;
1273 UINTN DxeTokenSpaceTableSize
;
1274 EFI_GUID
**PeiTokenSpaceTable
;
1275 EFI_GUID
**DxeTokenSpaceTable
;
1277 BOOLEAN PeiExMapTableEmpty
;
1278 BOOLEAN DxeExMapTableEmpty
;
1280 ASSERT (Guid
!= NULL
);
1282 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
1283 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
1285 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1286 return EFI_NOT_FOUND
;
1289 if (TmpTokenSpaceBuffer
[0] == NULL
) {
1290 PeiTokenSpaceTableSize
= 0;
1292 if (!PeiExMapTableEmpty
) {
1293 PeiTokenSpaceTableSize
= mPeiExMapppingTableSize
/ sizeof(DYNAMICEX_MAPPING
);
1294 PeiTokenSpaceTable
= GetDistinctTokenSpace (&PeiTokenSpaceTableSize
,
1295 (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
),
1296 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
)
1298 CopyMem (TmpTokenSpaceBuffer
, PeiTokenSpaceTable
, sizeof (EFI_GUID
*) * PeiTokenSpaceTableSize
);
1299 FreePool (PeiTokenSpaceTable
);
1302 if (!DxeExMapTableEmpty
) {
1303 DxeTokenSpaceTableSize
= mDxeExMapppingTableSize
/ sizeof(DYNAMICEX_MAPPING
);
1304 DxeTokenSpaceTable
= GetDistinctTokenSpace (&DxeTokenSpaceTableSize
,
1305 (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
),
1306 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
)
1310 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable
1312 for (Idx2
= 0, Idx3
= PeiTokenSpaceTableSize
; Idx2
< DxeTokenSpaceTableSize
; Idx2
++) {
1314 for (Idx
= 0; Idx
< PeiTokenSpaceTableSize
; Idx
++) {
1315 if (CompareGuid (TmpTokenSpaceBuffer
[Idx
], DxeTokenSpaceTable
[Idx2
])) {
1321 TmpTokenSpaceBuffer
[Idx3
++] = DxeTokenSpaceTable
[Idx2
];
1325 TmpTokenSpaceBufferCount
= Idx3
;
1326 FreePool (DxeTokenSpaceTable
);
1330 if (*Guid
== NULL
) {
1331 *Guid
= TmpTokenSpaceBuffer
[0];
1335 for (Idx
= 0; Idx
< TmpTokenSpaceBufferCount
; Idx
++) {
1336 if (CompareGuid (*Guid
, TmpTokenSpaceBuffer
[Idx
])) {
1337 if (Idx
== TmpTokenSpaceBufferCount
- 1) {
1339 // It has been the last token namespace.
1342 return EFI_NOT_FOUND
;
1345 *Guid
= TmpTokenSpaceBuffer
[Idx
];
1351 return EFI_NOT_FOUND
;