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 - 2016, 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 SkuIdTable
= (SKU_ID
*) ((UINT8
*) mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SkuIdTableOffset
);
276 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
277 if (SkuId
== SkuIdTable
[Index
+ 1]) {
278 mPcdDatabase
.DxeDb
->SystemSkuId
= (SKU_ID
) SkuId
;
284 // Invalid input SkuId, the default SKU Id will be used for the system.
286 DEBUG ((EFI_D_INFO
, "PcdDxe - Invalid input SkuId, the default SKU Id will be used.\n"));
287 mPcdDatabase
.DxeDb
->SystemSkuId
= (SKU_ID
) 0;
292 Retrieves an 8-bit value for a given PCD token.
294 Retrieves the current byte-sized value for a PCD token number.
295 If the TokenNumber is invalid, the results are unpredictable.
297 @param[in] TokenNumber The PCD token number.
299 @return The UINT8 value.
308 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
312 Retrieves an 16-bit value for a given PCD token.
314 Retrieves the current 16-bits value for a PCD token number.
315 If the TokenNumber is invalid, the results are unpredictable.
317 @param[in] TokenNumber The PCD token number.
319 @return The UINT16 value.
328 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
332 Retrieves an 32-bit value for a given PCD token.
334 Retrieves the current 32-bits value for a PCD token number.
335 If the TokenNumber is invalid, the results are unpredictable.
337 @param[in] TokenNumber The PCD token number.
339 @return The UINT32 value.
348 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
352 Retrieves an 64-bit value for a given PCD token.
354 Retrieves the current 64-bits value for a PCD token number.
355 If the TokenNumber is invalid, the results are unpredictable.
357 @param[in] TokenNumber The PCD token number.
359 @return The UINT64 value.
368 return ReadUnaligned64(GetWorker (TokenNumber
, sizeof (UINT64
)));
372 Retrieves a pointer to a value for a given PCD token.
374 Retrieves the current pointer to the buffer for a PCD token number.
375 Do not make any assumptions about the alignment of the pointer that
376 is returned by this function call. If the TokenNumber is invalid,
377 the results are unpredictable.
379 @param[in] TokenNumber The PCD token number.
381 @return The pointer to the buffer to be retrived.
390 return GetWorker (TokenNumber
, 0);
394 Retrieves a Boolean value for a given PCD token.
396 Retrieves the current boolean value for a PCD token number.
397 Do not make any assumptions about the alignment of the pointer that
398 is returned by this function call. If the TokenNumber is invalid,
399 the results are unpredictable.
401 @param[in] TokenNumber The PCD token number.
403 @return The Boolean value.
412 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
416 Retrieves the size of the value for a given PCD token.
418 Retrieves the current size of a particular PCD token.
419 If the TokenNumber is invalid, the results are unpredictable.
421 @param[in] TokenNumber The PCD token number.
423 @return The size of the value for the PCD token.
433 UINT32
*LocalTokenNumberTable
;
436 UINTN TmpTokenNumber
;
438 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
439 // We have to decrement TokenNumber by 1 to make it usable
440 // as the array index.
445 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
447 TmpTokenNumber
= TokenNumber
;
449 // EBC compiler is very choosy. It may report warning about comparison
450 // between UINTN and 0 . So we add 1 in each size of the
452 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
454 // EBC compiler is very choosy. It may report warning about comparison
455 // between UINTN and 0 . So we add 1 in each size of the
457 IsPeiDb
= (BOOLEAN
) (TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1);
459 TokenNumber
= IsPeiDb
? TokenNumber
:
460 (TokenNumber
- mPeiLocalTokenCount
);
462 LocalTokenNumberTable
= IsPeiDb
? (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
)
463 : (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
465 Size
= (LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
469 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
471 return GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
479 Retrieves an 8-bit value for a given PCD token.
481 Retrieves the 8-bit value of a particular PCD token.
482 If the TokenNumber is invalid or the token space
483 specified by Guid does not exist, the results are
486 @param[in] Guid The token space for the token number.
487 @param[in] ExTokenNumber The PCD token number.
489 @return The size 8-bit value for the PCD token.
495 IN CONST EFI_GUID
*Guid
,
496 IN UINTN ExTokenNumber
499 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT8
)));
503 Retrieves an 16-bit value for a given PCD token.
505 Retrieves the 16-bit value of a particular PCD token.
506 If the TokenNumber is invalid or the token space
507 specified by Guid does not exist, the results are
510 @param[in] Guid The token space for the token number.
511 @param[in] ExTokenNumber The PCD token number.
513 @return The size 16-bit value for the PCD token.
519 IN CONST EFI_GUID
*Guid
,
520 IN UINTN ExTokenNumber
523 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT16
)));
527 Retrieves an 32-bit value for a given PCD token.
529 Retrieves the 32-bit value of a particular PCD token.
530 If the TokenNumber is invalid or the token space
531 specified by Guid does not exist, the results are
534 @param[in] Guid The token space for the token number.
535 @param[in] ExTokenNumber The PCD token number.
537 @return The size 32-bit value for the PCD token.
543 IN CONST EFI_GUID
*Guid
,
544 IN UINTN ExTokenNumber
547 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT32
)));
551 Retrieves an 64-bit value for a given PCD token.
553 Retrieves the 64-bit value of a particular PCD token.
554 If the TokenNumber is invalid or the token space
555 specified by Guid does not exist, the results are
558 @param[in] Guid The token space for the token number.
559 @param[in] ExTokenNumber The PCD token number.
561 @return The size 64-bit value for the PCD token.
567 IN CONST EFI_GUID
*Guid
,
568 IN UINTN ExTokenNumber
571 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT64
)));
575 Retrieves a pointer to a value for a given PCD token.
577 Retrieves the current pointer to the buffer for a PCD token number.
578 Do not make any assumptions about the alignment of the pointer that
579 is returned by this function call. If the TokenNumber is invalid,
580 the results are unpredictable.
582 @param[in] Guid The token space for the token number.
583 @param[in] ExTokenNumber The PCD token number.
585 @return The pointer to the buffer to be retrived.
591 IN CONST EFI_GUID
*Guid
,
592 IN UINTN ExTokenNumber
595 return ExGetWorker (Guid
, ExTokenNumber
, 0);
599 Retrieves an Boolean value for a given PCD token.
601 Retrieves the Boolean value of a particular PCD token.
602 If the TokenNumber is invalid or the token space
603 specified by Guid does not exist, the results are
606 @param[in] Guid The token space for the token number.
607 @param[in] ExTokenNumber The PCD token number.
609 @return The size Boolean value for the PCD token.
615 IN CONST EFI_GUID
*Guid
,
616 IN UINTN ExTokenNumber
619 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(BOOLEAN
)));
623 Retrieves the size of the value for a given PCD token.
625 Retrieves the current size of a particular PCD token.
626 If the TokenNumber is invalid, the results are unpredictable.
628 @param[in] Guid The token space for the token number.
629 @param[in] ExTokenNumber The PCD token number.
631 @return The size of the value for the PCD token.
637 IN CONST EFI_GUID
*Guid
,
638 IN UINTN ExTokenNumber
641 return DxePcdGetSize(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
));
645 Sets an 8-bit value for a given PCD token.
647 When the PCD service sets a value, it will check to ensure that the
648 size of the value being set is compatible with the Token's existing definition.
649 If it is not, an error will be returned.
651 @param[in] TokenNumber The PCD token number.
652 @param[in] Value The value to set for the PCD token.
654 @retval EFI_SUCCESS Procedure returned successfully.
655 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
656 being set was incompatible with a call to this function.
657 Use GetSize() to retrieve the size of the target data.
658 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
664 IN UINTN TokenNumber
,
668 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
672 Sets an 16-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 32-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 64-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 a value of a specified size 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, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
761 On input, if the SizeOfValue is greater than the maximum size supported
762 for this TokenNumber then the output value of SizeOfValue will reflect
763 the maximum size supported for this TokenNumber.
764 @param[in] Buffer The buffer to set for the PCD token.
766 @retval EFI_SUCCESS Procedure returned successfully.
767 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
768 being set was incompatible with a call to this function.
769 Use GetSize() to retrieve the size of the target data.
770 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
776 IN UINTN TokenNumber
,
777 IN OUT UINTN
*SizeOfBuffer
,
781 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
785 Sets an Boolean value for a given PCD token.
787 When the PCD service sets a value, it will check to ensure that the
788 size of the value being set is compatible with the Token's existing definition.
789 If it is not, an error will be returned.
791 @param[in] TokenNumber The PCD token number.
792 @param[in] Value The value to set for the PCD token.
794 @retval EFI_SUCCESS Procedure returned successfully.
795 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
796 being set was incompatible with a call to this function.
797 Use GetSize() to retrieve the size of the target data.
798 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
804 IN UINTN TokenNumber
,
808 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
812 Sets an 8-bit 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] Guid The 128-bit unique value that designates the namespace from which to extract the value.
819 @param[in] ExTokenNumber The PCD token number.
820 @param[in] Value The value to set for the PCD token.
822 @retval EFI_SUCCESS Procedure returned successfully.
823 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
824 being set was incompatible with a call to this function.
825 Use GetSize() to retrieve the size of the target data.
826 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
832 IN CONST EFI_GUID
*Guid
,
833 IN UINTN ExTokenNumber
,
837 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
841 Sets an 16-bit value for a given PCD token.
843 When the PCD service sets a value, it will check to ensure that the
844 size of the value being set is compatible with the Token's existing definition.
845 If it is not, an error will be returned.
847 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
848 @param[in] ExTokenNumber The PCD token number.
849 @param[in] Value The value to set for the PCD token.
851 @retval EFI_SUCCESS Procedure returned successfully.
852 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
853 being set was incompatible with a call to this function.
854 Use GetSize() to retrieve the size of the target data.
855 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
861 IN CONST EFI_GUID
*Guid
,
862 IN UINTN ExTokenNumber
,
866 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
870 Sets an 32-bit value for a given PCD token.
872 When the PCD service sets a value, it will check to ensure that the
873 size of the value being set is compatible with the Token's existing definition.
874 If it is not, an error will be returned.
876 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
877 @param[in] ExTokenNumber The PCD token number.
878 @param[in] Value The value to set for the PCD token.
880 @retval EFI_SUCCESS Procedure returned successfully.
881 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
882 being set was incompatible with a call to this function.
883 Use GetSize() to retrieve the size of the target data.
884 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
890 IN CONST EFI_GUID
*Guid
,
891 IN UINTN ExTokenNumber
,
895 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
899 Sets an 64-bit value for a given PCD token.
901 When the PCD service sets a value, it will check to ensure that the
902 size of the value being set is compatible with the Token's existing definition.
903 If it is not, an error will be returned.
905 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
906 @param[in] ExTokenNumber The PCD token number.
907 @param[in] Value The value to set for the PCD token.
909 @retval EFI_SUCCESS Procedure returned successfully.
910 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
911 being set was incompatible with a call to this function.
912 Use GetSize() to retrieve the size of the target data.
913 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
919 IN CONST EFI_GUID
*Guid
,
920 IN UINTN ExTokenNumber
,
924 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
928 Sets a value of a specified size for a given PCD token.
930 When the PCD service sets a value, it will check to ensure that the
931 size of the value being set is compatible with the Token's existing definition.
932 If it is not, an error will be returned.
934 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
935 @param[in] ExTokenNumber The PCD token number.
936 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
937 On input, if the SizeOfValue is greater than the maximum size supported
938 for this TokenNumber then the output value of SizeOfValue will reflect
939 the maximum size supported for this TokenNumber.
940 @param[in] Buffer The buffer to set for the PCD token.
942 @retval EFI_SUCCESS Procedure returned successfully.
943 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
944 being set was incompatible with a call to this function.
945 Use GetSize() to retrieve the size of the target data.
946 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
952 IN CONST EFI_GUID
*Guid
,
953 IN UINTN ExTokenNumber
,
954 IN OUT UINTN
*SizeOfBuffer
,
958 return ExSetWorker(ExTokenNumber
, Guid
, Buffer
, SizeOfBuffer
, TRUE
);
962 Sets an Boolean value for a given PCD token.
964 When the PCD service sets a value, it will check to ensure that the
965 size of the value being set is compatible with the Token's existing definition.
966 If it is not, an error will be returned.
968 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
969 @param[in] ExTokenNumber The PCD token number.
970 @param[in] Value The value to set for the PCD token.
972 @retval EFI_SUCCESS Procedure returned successfully.
973 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
974 being set was incompatible with a call to this function.
975 Use GetSize() to retrieve the size of the target data.
976 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
982 IN CONST EFI_GUID
*Guid
,
983 IN UINTN ExTokenNumber
,
987 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
991 Specifies a function to be called anytime the value of a designated token is changed.
993 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
994 @param[in] TokenNumber The PCD token number.
995 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
997 @retval EFI_SUCCESS The PCD service has successfully established a call event
998 for the CallBackToken requested.
999 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1004 DxeRegisterCallBackOnSet (
1005 IN CONST EFI_GUID
*Guid
, OPTIONAL
1006 IN UINTN TokenNumber
,
1007 IN PCD_PROTOCOL_CALLBACK CallBackFunction
1012 if (CallBackFunction
== NULL
) {
1013 return EFI_INVALID_PARAMETER
;
1016 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1018 EfiAcquireLock (&mPcdDatabaseLock
);
1020 Status
= DxeRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
1022 EfiReleaseLock (&mPcdDatabaseLock
);
1028 Cancels a previously set callback function for a particular PCD token number.
1030 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
1031 @param[in] TokenNumber The PCD token number.
1032 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
1034 @retval EFI_SUCCESS The PCD service has successfully established a call event
1035 for the CallBackToken requested.
1036 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
1041 DxeUnRegisterCallBackOnSet (
1042 IN CONST EFI_GUID
*Guid
, OPTIONAL
1043 IN UINTN TokenNumber
,
1044 IN PCD_PROTOCOL_CALLBACK CallBackFunction
1049 if (CallBackFunction
== NULL
) {
1050 return EFI_INVALID_PARAMETER
;
1054 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1056 EfiAcquireLock (&mPcdDatabaseLock
);
1058 Status
= DxeUnRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
1060 EfiReleaseLock (&mPcdDatabaseLock
);
1066 Retrieves the next valid token number in a given namespace.
1068 This is useful since the PCD infrastructure contains a sparse list of token numbers,
1069 and one cannot a priori know what token numbers are valid in the database.
1071 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
1072 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
1073 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
1074 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
1075 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
1076 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
1077 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1078 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
1081 @param[in] Guid The 128-bit unique value that designates the namespace from which to retrieve the next token.
1082 This is an optional parameter that may be NULL. If this parameter is NULL, then a request is
1083 being made to retrieve tokens from the default token space.
1084 @param[in, out] TokenNumber
1085 A pointer to the PCD token number to use to find the subsequent token number.
1087 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.
1088 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.
1093 DxePcdGetNextToken (
1094 IN CONST EFI_GUID
*Guid
, OPTIONAL
1095 IN OUT UINTN
*TokenNumber
1099 BOOLEAN PeiExMapTableEmpty
;
1100 BOOLEAN DxeExMapTableEmpty
;
1102 Status
= EFI_NOT_FOUND
;
1103 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
1104 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
1107 // Scan the local token space
1110 // EBC compiler is very choosy. It may report warning about comparison
1111 // between UINTN and 0 . So we add 1 in each size of the
1113 if (((*TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) && (*TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) ||
1114 ((*TokenNumber
+ 1 > (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1)))) {
1115 return EFI_NOT_FOUND
;
1119 if ((*TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) &&
1120 (*TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) {
1122 // The first Non-Ex type Token Number for DXE PCD
1123 // database is mPeiLocalTokenCount + 1
1125 if (mDxeNexTokenCount
> 0) {
1126 *TokenNumber
= mPeiLocalTokenCount
+ 1;
1128 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1129 return EFI_NOT_FOUND
;
1131 } else if (*TokenNumber
+ 1 > mDxeNexTokenCount
+ mPeiLocalTokenCount
+ 1) {
1132 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1133 return EFI_NOT_FOUND
;
1138 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1139 return EFI_NOT_FOUND
;
1142 if (!PeiExMapTableEmpty
) {
1143 Status
= ExGetNextTokeNumber (
1146 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
),
1148 (DYNAMICEX_MAPPING
*)((UINT8
*) mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
),
1149 mPeiExMapppingTableSize
1153 if (Status
== EFI_SUCCESS
) {
1157 if (!DxeExMapTableEmpty
) {
1158 Status
= ExGetNextTokeNumber (
1161 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
),
1163 (DYNAMICEX_MAPPING
*)((UINT8
*) mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
),
1164 mDxeExMapppingTableSize
1172 Get all token space guid table which is different with given token space guid.
1174 @param ExMapTableSize The size of ExMapTable in item
1175 @param ExMapTable Token space guid table that want to be scaned.
1176 @param GuidTable Guid table
1178 @return all token space guid table which is different with given token space guid.
1182 GetDistinctTokenSpace (
1183 IN OUT UINTN
*ExMapTableSize
,
1184 IN DYNAMICEX_MAPPING
*ExMapTable
,
1185 IN EFI_GUID
*GuidTable
1188 EFI_GUID
**DistinctTokenSpace
;
1195 DistinctTokenSpace
= AllocateZeroPool (*ExMapTableSize
* sizeof (EFI_GUID
*));
1196 ASSERT (DistinctTokenSpace
!= NULL
);
1199 OldGuidIndex
= ExMapTable
[0].ExGuidIndex
;
1200 DistinctTokenSpace
[TsIdx
] = &GuidTable
[OldGuidIndex
];
1201 for (Idx
= 1; Idx
< *ExMapTableSize
; Idx
++) {
1203 OldGuidIndex
= ExMapTable
[Idx
].ExGuidIndex
;
1204 for (TempTsIdx
= 0; TempTsIdx
<= TsIdx
; TempTsIdx
++) {
1205 if (&GuidTable
[OldGuidIndex
] == DistinctTokenSpace
[TempTsIdx
]) {
1207 // Have recorded this GUID.
1214 DistinctTokenSpace
[++TsIdx
] = &GuidTable
[OldGuidIndex
];
1219 // The total number of Distinct Token Space
1220 // is TsIdx + 1 because we use TsIdx as a index
1221 // to the DistinctTokenSpace[]
1223 *ExMapTableSize
= TsIdx
+ 1;
1224 return DistinctTokenSpace
;
1229 Retrieves the next valid PCD token namespace for a given namespace.
1231 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid
1232 token namespaces on a platform.
1234 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token
1235 namespace from which the search will start. On output, it designates the next valid
1236 token namespace on the platform. If *Guid is NULL, then the GUID of the first token
1237 space of the current platform is returned. If the search cannot locate the next valid
1238 token namespace, an error is returned and the value of *Guid is undefined.
1240 @retval EFI_SUCCESS The PCD service retrieved the value requested.
1241 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.
1246 DxePcdGetNextTokenSpace (
1247 IN OUT CONST EFI_GUID
**Guid
1253 UINTN PeiTokenSpaceTableSize
;
1254 UINTN DxeTokenSpaceTableSize
;
1255 EFI_GUID
**PeiTokenSpaceTable
;
1256 EFI_GUID
**DxeTokenSpaceTable
;
1258 BOOLEAN PeiExMapTableEmpty
;
1259 BOOLEAN DxeExMapTableEmpty
;
1261 ASSERT (Guid
!= NULL
);
1263 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
1264 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
1266 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1267 return EFI_NOT_FOUND
;
1270 if (TmpTokenSpaceBuffer
[0] == NULL
) {
1271 PeiTokenSpaceTableSize
= 0;
1273 if (!PeiExMapTableEmpty
) {
1274 PeiTokenSpaceTableSize
= mPeiExMapppingTableSize
/ sizeof(DYNAMICEX_MAPPING
);
1275 PeiTokenSpaceTable
= GetDistinctTokenSpace (&PeiTokenSpaceTableSize
,
1276 (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
),
1277 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
)
1279 CopyMem (TmpTokenSpaceBuffer
, PeiTokenSpaceTable
, sizeof (EFI_GUID
*) * PeiTokenSpaceTableSize
);
1280 FreePool (PeiTokenSpaceTable
);
1283 if (!DxeExMapTableEmpty
) {
1284 DxeTokenSpaceTableSize
= mDxeExMapppingTableSize
/ sizeof(DYNAMICEX_MAPPING
);
1285 DxeTokenSpaceTable
= GetDistinctTokenSpace (&DxeTokenSpaceTableSize
,
1286 (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
),
1287 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
)
1291 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable
1293 for (Idx2
= 0, Idx3
= PeiTokenSpaceTableSize
; Idx2
< DxeTokenSpaceTableSize
; Idx2
++) {
1295 for (Idx
= 0; Idx
< PeiTokenSpaceTableSize
; Idx
++) {
1296 if (CompareGuid (TmpTokenSpaceBuffer
[Idx
], DxeTokenSpaceTable
[Idx2
])) {
1302 TmpTokenSpaceBuffer
[Idx3
++] = DxeTokenSpaceTable
[Idx2
];
1306 TmpTokenSpaceBufferCount
= Idx3
;
1307 FreePool (DxeTokenSpaceTable
);
1311 if (*Guid
== NULL
) {
1312 *Guid
= TmpTokenSpaceBuffer
[0];
1316 for (Idx
= 0; Idx
< TmpTokenSpaceBufferCount
; Idx
++) {
1317 if (CompareGuid (*Guid
, TmpTokenSpaceBuffer
[Idx
])) {
1318 if (Idx
== TmpTokenSpaceBufferCount
- 1) {
1320 // It has been the last token namespace.
1323 return EFI_NOT_FOUND
;
1326 *Guid
= TmpTokenSpaceBuffer
[Idx
];
1332 return EFI_NOT_FOUND
;