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 - 2009, Intel Corporation
7 All rights reserved. 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 // Just pre-allocate a memory buffer that is big enough to
21 // host all distinct TokenSpace guid in both
22 // PEI ExMap and DXE ExMap.
24 EFI_GUID
*TmpTokenSpaceBuffer
[PEI_EXMAPPING_TABLE_SIZE
+ DXE_EXMAPPING_TABLE_SIZE
] = { 0 };
27 /// PCD database lock.
29 EFI_LOCK mPcdDatabaseLock
= EFI_INITIALIZE_LOCK_VARIABLE(TPL_NOTIFY
);
32 /// PCD_PROTOCOL the EDKII native implementation which support dynamic
33 /// type and dynamicEx type PCDs.
35 PCD_PROTOCOL mPcdInstance
= {
68 DxeRegisterCallBackOnSet
,
69 DxeUnRegisterCallBackOnSet
,
71 DxePcdGetNextTokenSpace
75 /// EFI_PCD_PROTOCOL is defined in PI 1.2 Vol 3 which only support dynamicEx type
78 EFI_PCD_PROTOCOL mEfiPcdInstance
= {
93 (EFI_PCD_PROTOCOL_CALLBACK_ON_SET
) DxeRegisterCallBackOnSet
,
94 (EFI_PCD_PROTOCOL_CANCEL_CALLBACK
) DxeUnRegisterCallBackOnSet
,
96 DxePcdGetNextTokenSpace
99 EFI_HANDLE mPcdHandle
= NULL
;
102 Main entry for PCD DXE driver.
104 This routine initialize the PCD database and install PCD_PROTOCOL.
106 @param ImageHandle Image handle for PCD DXE driver.
107 @param SystemTable Pointer to SystemTable.
109 @return Status of gBS->InstallProtocolInterface()
115 IN EFI_HANDLE ImageHandle
,
116 IN EFI_SYSTEM_TABLE
*SystemTable
122 // Make sure the Pcd Protocol is not already installed in the system
125 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gPcdProtocolGuid
);
127 BuildPcdDxeDataBase ();
130 // Install PCD_PROTOCOL to handle dynamic type PCD
131 // Install EFI_PCD_PROTOCOL to handle dynamicEx type PCD
133 Status
= gBS
->InstallMultipleProtocolInterfaces (
135 &gPcdProtocolGuid
, &mPcdInstance
,
136 &gEfiPcdProtocolGuid
, &mEfiPcdInstance
,
140 ASSERT_EFI_ERROR (Status
);
147 Sets the SKU value for subsequent calls to set or get PCD token values.
149 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
150 SetSku() is normally called only once by the system.
152 For each item (token), the database can hold a single value that applies to all SKUs,
153 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
154 SKU-specific values are called SKU enabled.
156 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
157 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
158 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
159 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
160 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
161 set for that Id, the results are unpredictable.
163 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
164 set values associated with a PCD token.
173 mPcdDatabase
->PeiDb
.Init
.SystemSkuId
= (SKU_ID
) SkuId
;
179 Retrieves an 8-bit value for a given PCD token.
181 Retrieves the current byte-sized value for a PCD token number.
182 If the TokenNumber is invalid, the results are unpredictable.
184 @param[in] TokenNumber The PCD token number.
186 @return The UINT8 value.
195 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
199 Retrieves an 16-bit value for a given PCD token.
201 Retrieves the current 16-bits value for a PCD token number.
202 If the TokenNumber is invalid, the results are unpredictable.
204 @param[in] TokenNumber The PCD token number.
206 @return The UINT16 value.
215 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
219 Retrieves an 32-bit value for a given PCD token.
221 Retrieves the current 32-bits value for a PCD token number.
222 If the TokenNumber is invalid, the results are unpredictable.
224 @param[in] TokenNumber The PCD token number.
226 @return The UINT32 value.
235 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
239 Retrieves an 64-bit value for a given PCD token.
241 Retrieves the current 64-bits value for a PCD token number.
242 If the TokenNumber is invalid, the results are unpredictable.
244 @param[in] TokenNumber The PCD token number.
246 @return The UINT64 value.
255 return ReadUnaligned64(GetWorker (TokenNumber
, sizeof (UINT64
)));
259 Retrieves a pointer to a value for a given PCD token.
261 Retrieves the current pointer to the buffer for a PCD token number.
262 Do not make any assumptions about the alignment of the pointer that
263 is returned by this function call. If the TokenNumber is invalid,
264 the results are unpredictable.
266 @param[in] TokenNumber The PCD token number.
268 @return The pointer to the buffer to be retrived.
277 return GetWorker (TokenNumber
, 0);
281 Retrieves a Boolean value for a given PCD token.
283 Retrieves the current boolean value for a PCD token number.
284 Do not make any assumptions about the alignment of the pointer that
285 is returned by this function call. If the TokenNumber is invalid,
286 the results are unpredictable.
288 @param[in] TokenNumber The PCD token number.
290 @return The Boolean value.
299 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
303 Retrieves the size of the value for a given PCD token.
305 Retrieves the current size of a particular PCD token.
306 If the TokenNumber is invalid, the results are unpredictable.
308 @param[in] TokenNumber The PCD token number.
310 @return The size of the value for the PCD token.
320 UINT32
*LocalTokenNumberTable
;
323 UINTN TmpTokenNumber
;
325 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
326 // We have to decrement TokenNumber by 1 to make it usable
327 // as the array index.
332 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
334 TmpTokenNumber
= TokenNumber
;
336 // EBC compiler is very choosy. It may report warning about comparison
337 // between UINTN and 0 . So we add 1 in each size of the
339 ASSERT (TokenNumber
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1);
341 // EBC compiler is very choosy. It may report warning about comparison
342 // between UINTN and 0 . So we add 1 in each size of the
344 IsPeiDb
= (BOOLEAN
) (TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
346 TokenNumber
= IsPeiDb
? TokenNumber
:
347 (TokenNumber
- PEI_LOCAL_TOKEN_NUMBER
);
349 LocalTokenNumberTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
350 : mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
352 Size
= (LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
356 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
358 return GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
366 Retrieves an 8-bit value for a given PCD token.
368 Retrieves the 8-bit value of a particular PCD token.
369 If the TokenNumber is invalid or the token space
370 specified by Guid does not exist, the results are
373 @param[in] Guid The token space for the token number.
374 @param[in] ExTokenNumber The PCD token number.
376 @return The size 8-bit value for the PCD token.
382 IN CONST EFI_GUID
*Guid
,
383 IN UINTN ExTokenNumber
386 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT8
)));
390 Retrieves an 16-bit value for a given PCD token.
392 Retrieves the 16-bit value of a particular PCD token.
393 If the TokenNumber is invalid or the token space
394 specified by Guid does not exist, the results are
397 @param[in] Guid The token space for the token number.
398 @param[in] ExTokenNumber The PCD token number.
400 @return The size 16-bit value for the PCD token.
406 IN CONST EFI_GUID
*Guid
,
407 IN UINTN ExTokenNumber
410 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT16
)));
414 Retrieves an 32-bit value for a given PCD token.
416 Retrieves the 32-bit value of a particular PCD token.
417 If the TokenNumber is invalid or the token space
418 specified by Guid does not exist, the results are
421 @param[in] Guid The token space for the token number.
422 @param[in] ExTokenNumber The PCD token number.
424 @return The size 32-bit value for the PCD token.
430 IN CONST EFI_GUID
*Guid
,
431 IN UINTN ExTokenNumber
434 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT32
)));
438 Retrieves an 64-bit value for a given PCD token.
440 Retrieves the 64-bit value of a particular PCD token.
441 If the TokenNumber is invalid or the token space
442 specified by Guid does not exist, the results are
445 @param[in] Guid The token space for the token number.
446 @param[in] ExTokenNumber The PCD token number.
448 @return The size 64-bit value for the PCD token.
454 IN CONST EFI_GUID
*Guid
,
455 IN UINTN ExTokenNumber
458 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT64
)));
462 Retrieves a pointer to a value for a given PCD token.
464 Retrieves the current pointer to the buffer for a PCD token number.
465 Do not make any assumptions about the alignment of the pointer that
466 is returned by this function call. If the TokenNumber is invalid,
467 the results are unpredictable.
469 @param[in] Guid The token space for the token number.
470 @param[in] ExTokenNumber The PCD token number.
472 @return The pointer to the buffer to be retrived.
478 IN CONST EFI_GUID
*Guid
,
479 IN UINTN ExTokenNumber
482 return ExGetWorker (Guid
, ExTokenNumber
, 0);
486 Retrieves an Boolean value for a given PCD token.
488 Retrieves the Boolean value of a particular PCD token.
489 If the TokenNumber is invalid or the token space
490 specified by Guid does not exist, the results are
493 @param[in] Guid The token space for the token number.
494 @param[in] ExTokenNumber The PCD token number.
496 @return The size Boolean value for the PCD token.
502 IN CONST EFI_GUID
*Guid
,
503 IN UINTN ExTokenNumber
506 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(BOOLEAN
)));
510 Retrieves the size of the value for a given PCD token.
512 Retrieves the current size of a particular PCD token.
513 If the TokenNumber is invalid, the results are unpredictable.
515 @param[in] Guid The token space for the token number.
516 @param[in] ExTokenNumber The PCD token number.
518 @return The size of the value for the PCD token.
524 IN CONST EFI_GUID
*Guid
,
525 IN UINTN ExTokenNumber
528 return DxePcdGetSize(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
));
532 Sets an 8-bit value for a given PCD token.
534 When the PCD service sets a value, it will check to ensure that the
535 size of the value being set is compatible with the Token's existing definition.
536 If it is not, an error will be returned.
538 @param[in] TokenNumber The PCD token number.
539 @param[in] Value The value to set for the PCD token.
541 @retval EFI_SUCCESS Procedure returned successfully.
542 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
543 being set was incompatible with a call to this function.
544 Use GetSize() to retrieve the size of the target data.
545 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
551 IN UINTN TokenNumber
,
555 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
559 Sets an 16-bit value for a given PCD token.
561 When the PCD service sets a value, it will check to ensure that the
562 size of the value being set is compatible with the Token's existing definition.
563 If it is not, an error will be returned.
565 @param[in] TokenNumber The PCD token number.
566 @param[in] Value The value to set for the PCD token.
568 @retval EFI_SUCCESS Procedure returned successfully.
569 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
570 being set was incompatible with a call to this function.
571 Use GetSize() to retrieve the size of the target data.
572 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
578 IN UINTN TokenNumber
,
582 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
586 Sets an 32-bit value for a given PCD token.
588 When the PCD service sets a value, it will check to ensure that the
589 size of the value being set is compatible with the Token's existing definition.
590 If it is not, an error will be returned.
592 @param[in] TokenNumber The PCD token number.
593 @param[in] Value The value to set for the PCD token.
595 @retval EFI_SUCCESS Procedure returned successfully.
596 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
597 being set was incompatible with a call to this function.
598 Use GetSize() to retrieve the size of the target data.
599 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
605 IN UINTN TokenNumber
,
609 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
613 Sets an 64-bit value for a given PCD token.
615 When the PCD service sets a value, it will check to ensure that the
616 size of the value being set is compatible with the Token's existing definition.
617 If it is not, an error will be returned.
619 @param[in] TokenNumber The PCD token number.
620 @param[in] Value The value to set for the PCD token.
622 @retval EFI_SUCCESS Procedure returned successfully.
623 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
624 being set was incompatible with a call to this function.
625 Use GetSize() to retrieve the size of the target data.
626 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
632 IN UINTN TokenNumber
,
636 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
640 Sets a value of a specified size for a given PCD token.
642 When the PCD service sets a value, it will check to ensure that the
643 size of the value being set is compatible with the Token's existing definition.
644 If it is not, an error will be returned.
646 @param[in] TokenNumber The PCD token number.
647 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
648 On input, if the SizeOfValue is greater than the maximum size supported
649 for this TokenNumber then the output value of SizeOfValue will reflect
650 the maximum size supported for this TokenNumber.
651 @param[in] Buffer The buffer to set for the PCD token.
653 @retval EFI_SUCCESS Procedure returned successfully.
654 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
655 being set was incompatible with a call to this function.
656 Use GetSize() to retrieve the size of the target data.
657 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
663 IN UINTN TokenNumber
,
664 IN OUT UINTN
*SizeOfBuffer
,
668 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
672 Sets an Boolean 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 8-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] Guid The 128-bit unique value that designates the namespace from which to extract the value.
706 @param[in] ExTokenNumber The PCD token number.
707 @param[in] Value The value to set for the PCD token.
709 @retval EFI_SUCCESS Procedure returned successfully.
710 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
711 being set was incompatible with a call to this function.
712 Use GetSize() to retrieve the size of the target data.
713 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
719 IN CONST EFI_GUID
*Guid
,
720 IN UINTN ExTokenNumber
,
724 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
728 Sets an 16-bit value for a given PCD token.
730 When the PCD service sets a value, it will check to ensure that the
731 size of the value being set is compatible with the Token's existing definition.
732 If it is not, an error will be returned.
734 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
735 @param[in] ExTokenNumber The PCD token number.
736 @param[in] Value The value to set for the PCD token.
738 @retval EFI_SUCCESS Procedure returned successfully.
739 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
740 being set was incompatible with a call to this function.
741 Use GetSize() to retrieve the size of the target data.
742 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
748 IN CONST EFI_GUID
*Guid
,
749 IN UINTN ExTokenNumber
,
753 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
757 Sets an 32-bit value for a given PCD token.
759 When the PCD service sets a value, it will check to ensure that the
760 size of the value being set is compatible with the Token's existing definition.
761 If it is not, an error will be returned.
763 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
764 @param[in] ExTokenNumber The PCD token number.
765 @param[in] Value The value to set for the PCD token.
767 @retval EFI_SUCCESS Procedure returned successfully.
768 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
769 being set was incompatible with a call to this function.
770 Use GetSize() to retrieve the size of the target data.
771 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
777 IN CONST EFI_GUID
*Guid
,
778 IN UINTN ExTokenNumber
,
782 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
786 Sets an 64-bit value for a given PCD token.
788 When the PCD service sets a value, it will check to ensure that the
789 size of the value being set is compatible with the Token's existing definition.
790 If it is not, an error will be returned.
792 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
793 @param[in] ExTokenNumber The PCD token number.
794 @param[in] Value The value to set for the PCD token.
796 @retval EFI_SUCCESS Procedure returned successfully.
797 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
798 being set was incompatible with a call to this function.
799 Use GetSize() to retrieve the size of the target data.
800 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
806 IN CONST EFI_GUID
*Guid
,
807 IN UINTN ExTokenNumber
,
811 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
815 Sets a value of a specified size for a given PCD token.
817 When the PCD service sets a value, it will check to ensure that the
818 size of the value being set is compatible with the Token's existing definition.
819 If it is not, an error will be returned.
821 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
822 @param[in] ExTokenNumber The PCD token number.
823 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
824 On input, if the SizeOfValue is greater than the maximum size supported
825 for this TokenNumber then the output value of SizeOfValue will reflect
826 the maximum size supported for this TokenNumber.
827 @param[in] Buffer The buffer to set for the PCD token.
829 @retval EFI_SUCCESS Procedure returned successfully.
830 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
831 being set was incompatible with a call to this function.
832 Use GetSize() to retrieve the size of the target data.
833 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
839 IN CONST EFI_GUID
*Guid
,
840 IN UINTN ExTokenNumber
,
841 IN OUT UINTN
*SizeOfBuffer
,
845 return ExSetWorker(ExTokenNumber
, Guid
, Buffer
, SizeOfBuffer
, TRUE
);
849 Sets an Boolean value for a given PCD token.
851 When the PCD service sets a value, it will check to ensure that the
852 size of the value being set is compatible with the Token's existing definition.
853 If it is not, an error will be returned.
855 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
856 @param[in] ExTokenNumber The PCD token number.
857 @param[in] Value The value to set for the PCD token.
859 @retval EFI_SUCCESS Procedure returned successfully.
860 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
861 being set was incompatible with a call to this function.
862 Use GetSize() to retrieve the size of the target data.
863 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
869 IN CONST EFI_GUID
*Guid
,
870 IN UINTN ExTokenNumber
,
874 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
878 Specifies a function to be called anytime the value of a designated token is changed.
880 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
881 @param[in] TokenNumber The PCD token number.
882 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
884 @retval EFI_SUCCESS The PCD service has successfully established a call event
885 for the CallBackToken requested.
886 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
891 DxeRegisterCallBackOnSet (
892 IN CONST EFI_GUID
*Guid
, OPTIONAL
893 IN UINTN TokenNumber
,
894 IN PCD_PROTOCOL_CALLBACK CallBackFunction
899 if (CallBackFunction
== NULL
) {
900 return EFI_INVALID_PARAMETER
;
903 // Aquire lock to prevent reentrance from TPL_CALLBACK level
905 EfiAcquireLock (&mPcdDatabaseLock
);
907 Status
= DxeRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
909 EfiReleaseLock (&mPcdDatabaseLock
);
915 Cancels a previously set callback function for a particular PCD token number.
917 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
918 @param[in] TokenNumber The PCD token number.
919 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
921 @retval EFI_SUCCESS The PCD service has successfully established a call event
922 for the CallBackToken requested.
923 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
928 DxeUnRegisterCallBackOnSet (
929 IN CONST EFI_GUID
*Guid
, OPTIONAL
930 IN UINTN TokenNumber
,
931 IN PCD_PROTOCOL_CALLBACK CallBackFunction
936 if (CallBackFunction
== NULL
) {
937 return EFI_INVALID_PARAMETER
;
941 // Aquire lock to prevent reentrance from TPL_CALLBACK level
943 EfiAcquireLock (&mPcdDatabaseLock
);
945 Status
= DxeUnRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
947 EfiReleaseLock (&mPcdDatabaseLock
);
953 Retrieves the next valid token number in a given namespace.
955 This is useful since the PCD infrastructure contains a sparse list of token numbers,
956 and one cannot a priori know what token numbers are valid in the database.
958 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
959 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
960 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
961 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
962 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
963 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
964 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
965 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
968 @param[in] Guid The 128-bit unique value that designates the namespace from which to retrieve the next token.
969 This is an optional parameter that may be NULL. If this parameter is NULL, then a request is
970 being made to retrieve tokens from the default token space.
971 @param[in,out] TokenNumber
972 A pointer to the PCD token number to use to find the subsequent token number.
974 @retval EFI_SUCCESS The PCD service retrieved the next valid token number. Or the input token number
975 is already the last valid token number in the PCD database.
976 In the later case, *TokenNumber is updated with the value of 0.
977 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
983 IN CONST EFI_GUID
*Guid
, OPTIONAL
984 IN OUT UINTN
*TokenNumber
988 BOOLEAN PeiExMapTableEmpty
;
989 BOOLEAN DxeExMapTableEmpty
;
991 Status
= EFI_NOT_FOUND
;
992 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
993 DxeExMapTableEmpty
= DXE_EXMAP_TABLE_EMPTY
;
996 // Scan the local token space
999 // EBC compiler is very choosy. It may report warning about comparison
1000 // between UINTN and 0 . So we add 1 in each size of the
1002 if (((*TokenNumber
+ 1 > PEI_NEX_TOKEN_NUMBER
+ 1) && (*TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1)) ||
1003 ((*TokenNumber
+ 1 > (PEI_LOCAL_TOKEN_NUMBER
+ DXE_NEX_TOKEN_NUMBER
+ 1)))) {
1004 return EFI_NOT_FOUND
;
1008 if ((*TokenNumber
+ 1 > PEI_NEX_TOKEN_NUMBER
+ 1) &&
1009 (*TokenNumber
<= PEI_LOCAL_TOKEN_NUMBER
)) {
1011 // The first Non-Ex type Token Number for DXE PCD
1012 // database is PEI_LOCAL_TOKEN_NUMBER
1014 *TokenNumber
= PEI_LOCAL_TOKEN_NUMBER
;
1015 } else if (*TokenNumber
+ 1 > DXE_NEX_TOKEN_NUMBER
+ PEI_LOCAL_TOKEN_NUMBER
+ 1) {
1016 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1021 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1022 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1023 return EFI_NOT_FOUND
;
1026 if (!PeiExMapTableEmpty
) {
1027 Status
= ExGetNextTokeNumber (
1030 mPcdDatabase
->PeiDb
.Init
.GuidTable
,
1031 sizeof(mPcdDatabase
->PeiDb
.Init
.GuidTable
),
1032 mPcdDatabase
->PeiDb
.Init
.ExMapTable
,
1033 sizeof(mPcdDatabase
->PeiDb
.Init
.ExMapTable
)
1037 if (Status
== EFI_SUCCESS
) {
1041 if (!DxeExMapTableEmpty
) {
1042 Status
= ExGetNextTokeNumber (
1045 mPcdDatabase
->DxeDb
.Init
.GuidTable
,
1046 sizeof(mPcdDatabase
->DxeDb
.Init
.GuidTable
),
1047 mPcdDatabase
->DxeDb
.Init
.ExMapTable
,
1048 sizeof(mPcdDatabase
->DxeDb
.Init
.ExMapTable
)
1056 Get all token space guid table which is different with given token space guid.
1058 @param ExMapTableSize The size of guid table
1059 @param ExMapTable Token space guid table that want to be scaned.
1060 @param GuidTable Guid table
1062 @return all token space guid table which is different with given token space guid.
1066 GetDistinctTokenSpace (
1067 IN OUT UINTN
*ExMapTableSize
,
1068 IN DYNAMICEX_MAPPING
*ExMapTable
,
1069 IN EFI_GUID
*GuidTable
1072 EFI_GUID
**DistinctTokenSpace
;
1078 DistinctTokenSpace
= AllocateZeroPool (*ExMapTableSize
* sizeof (EFI_GUID
*));
1079 ASSERT (DistinctTokenSpace
!= NULL
);
1082 OldGuidIndex
= ExMapTable
[0].ExGuidIndex
;
1083 DistinctTokenSpace
[TsIdx
] = &GuidTable
[OldGuidIndex
];
1084 for (Idx
= 1; Idx
< *ExMapTableSize
; Idx
++) {
1085 if (ExMapTable
[Idx
].ExGuidIndex
!= OldGuidIndex
) {
1086 OldGuidIndex
= ExMapTable
[Idx
].ExGuidIndex
;
1087 DistinctTokenSpace
[++TsIdx
] = &GuidTable
[OldGuidIndex
];
1092 // The total number of Distinct Token Space
1093 // is TsIdx + 1 because we use TsIdx as a index
1094 // to the DistinctTokenSpace[]
1096 *ExMapTableSize
= TsIdx
+ 1;
1097 return DistinctTokenSpace
;
1102 Get next token space in PCD database according to given token space guid.
1104 @param Guid Given token space guid. If NULL, then Guid will be set to
1105 the first PCD token space in PCD database, If not NULL, then
1106 Guid will be set to next PCD token space.
1108 @retval EFI_UNSUPPORTED
1109 @retval EFI_NOT_FOUND If PCD database has no token space table or can not find given
1110 token space in PCD database.
1111 @retval EFI_SUCCESS Success to get next token space guid.
1115 DxePcdGetNextTokenSpace (
1116 IN OUT CONST EFI_GUID
**Guid
1122 UINTN PeiTokenSpaceTableSize
;
1123 UINTN DxeTokenSpaceTableSize
;
1124 EFI_GUID
**PeiTokenSpaceTable
;
1125 EFI_GUID
**DxeTokenSpaceTable
;
1127 BOOLEAN PeiExMapTableEmpty
;
1128 BOOLEAN DxeExMapTableEmpty
;
1130 ASSERT (Guid
!= NULL
);
1132 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
1133 DxeExMapTableEmpty
= DXE_EXMAP_TABLE_EMPTY
;
1135 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1136 if (*Guid
!= NULL
) {
1137 return EFI_NOT_FOUND
;
1144 if (TmpTokenSpaceBuffer
[0] == NULL
) {
1145 PeiTokenSpaceTableSize
= 0;
1147 if (!PeiExMapTableEmpty
) {
1148 PeiTokenSpaceTableSize
= PEI_EXMAPPING_TABLE_SIZE
;
1149 PeiTokenSpaceTable
= GetDistinctTokenSpace (&PeiTokenSpaceTableSize
,
1150 mPcdDatabase
->PeiDb
.Init
.ExMapTable
,
1151 mPcdDatabase
->PeiDb
.Init
.GuidTable
1153 CopyMem (TmpTokenSpaceBuffer
, PeiTokenSpaceTable
, sizeof (EFI_GUID
*) * PeiTokenSpaceTableSize
);
1156 if (!DxeExMapTableEmpty
) {
1157 DxeTokenSpaceTableSize
= DXE_EXMAPPING_TABLE_SIZE
;
1158 DxeTokenSpaceTable
= GetDistinctTokenSpace (&DxeTokenSpaceTableSize
,
1159 mPcdDatabase
->DxeDb
.Init
.ExMapTable
,
1160 mPcdDatabase
->DxeDb
.Init
.GuidTable
1164 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable
1166 for (Idx2
= 0, Idx3
= PeiTokenSpaceTableSize
; Idx2
< DxeTokenSpaceTableSize
; Idx2
++) {
1168 for (Idx
= 0; Idx
< PeiTokenSpaceTableSize
; Idx
++) {
1169 if (CompareGuid (TmpTokenSpaceBuffer
[Idx
], DxeTokenSpaceTable
[Idx2
])) {
1175 TmpTokenSpaceBuffer
[Idx3
++] = DxeTokenSpaceTable
[Idx2
];
1181 if (*Guid
== NULL
) {
1182 *Guid
= TmpTokenSpaceBuffer
[0];
1186 for (Idx
= 0; Idx
< (PEI_EXMAPPING_TABLE_SIZE
+ DXE_EXMAPPING_TABLE_SIZE
); Idx
++) {
1187 if(CompareGuid (*Guid
, TmpTokenSpaceBuffer
[Idx
])) {
1189 *Guid
= TmpTokenSpaceBuffer
[Idx
];
1194 return EFI_NOT_FOUND
;