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 - 2013, 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
92 EFI_HANDLE mPcdHandle
= NULL
;
95 Main entry for PCD DXE driver.
97 This routine initialize the PCD database and install PCD_PROTOCOL.
99 @param ImageHandle Image handle for PCD DXE driver.
100 @param SystemTable Pointer to SystemTable.
102 @return Status of gBS->InstallProtocolInterface()
108 IN EFI_HANDLE ImageHandle
,
109 IN EFI_SYSTEM_TABLE
*SystemTable
115 // Make sure the Pcd Protocol is not already installed in the system
118 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gPcdProtocolGuid
);
120 BuildPcdDxeDataBase ();
123 // Install PCD_PROTOCOL to handle dynamic type PCD
124 // Install EFI_PCD_PROTOCOL to handle dynamicEx type PCD
126 Status
= gBS
->InstallMultipleProtocolInterfaces (
128 &gPcdProtocolGuid
, &mPcdInstance
,
129 &gEfiPcdProtocolGuid
, &mEfiPcdInstance
,
133 ASSERT_EFI_ERROR (Status
);
140 Sets the SKU value for subsequent calls to set or get PCD token values.
142 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
143 SetSku() is normally called only once by the system.
145 For each item (token), the database can hold a single value that applies to all SKUs,
146 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
147 SKU-specific values are called SKU enabled.
149 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
150 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
151 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
152 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
153 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
154 set for that Id, the results are unpredictable.
156 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
157 set values associated with a PCD token.
166 mPcdDatabase
.PeiDb
->SystemSkuId
= (SKU_ID
) SkuId
;
172 Retrieves an 8-bit value for a given PCD token.
174 Retrieves the current byte-sized value for a PCD token number.
175 If the TokenNumber is invalid, the results are unpredictable.
177 @param[in] TokenNumber The PCD token number.
179 @return The UINT8 value.
188 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
192 Retrieves an 16-bit value for a given PCD token.
194 Retrieves the current 16-bits value for a PCD token number.
195 If the TokenNumber is invalid, the results are unpredictable.
197 @param[in] TokenNumber The PCD token number.
199 @return The UINT16 value.
208 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
212 Retrieves an 32-bit value for a given PCD token.
214 Retrieves the current 32-bits value for a PCD token number.
215 If the TokenNumber is invalid, the results are unpredictable.
217 @param[in] TokenNumber The PCD token number.
219 @return The UINT32 value.
228 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
232 Retrieves an 64-bit value for a given PCD token.
234 Retrieves the current 64-bits value for a PCD token number.
235 If the TokenNumber is invalid, the results are unpredictable.
237 @param[in] TokenNumber The PCD token number.
239 @return The UINT64 value.
248 return ReadUnaligned64(GetWorker (TokenNumber
, sizeof (UINT64
)));
252 Retrieves a pointer to a value for a given PCD token.
254 Retrieves the current pointer to the buffer for a PCD token number.
255 Do not make any assumptions about the alignment of the pointer that
256 is returned by this function call. If the TokenNumber is invalid,
257 the results are unpredictable.
259 @param[in] TokenNumber The PCD token number.
261 @return The pointer to the buffer to be retrived.
270 return GetWorker (TokenNumber
, 0);
274 Retrieves a Boolean value for a given PCD token.
276 Retrieves the current boolean value for a PCD token number.
277 Do not make any assumptions about the alignment of the pointer that
278 is returned by this function call. If the TokenNumber is invalid,
279 the results are unpredictable.
281 @param[in] TokenNumber The PCD token number.
283 @return The Boolean value.
292 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
296 Retrieves the size of the value for a given PCD token.
298 Retrieves the current size of a particular PCD token.
299 If the TokenNumber is invalid, the results are unpredictable.
301 @param[in] TokenNumber The PCD token number.
303 @return The size of the value for the PCD token.
313 UINT32
*LocalTokenNumberTable
;
316 UINTN TmpTokenNumber
;
318 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
319 // We have to decrement TokenNumber by 1 to make it usable
320 // as the array index.
325 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
327 TmpTokenNumber
= TokenNumber
;
329 // EBC compiler is very choosy. It may report warning about comparison
330 // between UINTN and 0 . So we add 1 in each size of the
332 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
334 // EBC compiler is very choosy. It may report warning about comparison
335 // between UINTN and 0 . So we add 1 in each size of the
337 IsPeiDb
= (BOOLEAN
) (TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1);
339 TokenNumber
= IsPeiDb
? TokenNumber
:
340 (TokenNumber
- mPeiLocalTokenCount
);
342 LocalTokenNumberTable
= IsPeiDb
? (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
)
343 : (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
345 Size
= (LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
349 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
351 return GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
359 Retrieves an 8-bit value for a given PCD token.
361 Retrieves the 8-bit value of a particular PCD token.
362 If the TokenNumber is invalid or the token space
363 specified by Guid does not exist, the results are
366 @param[in] Guid The token space for the token number.
367 @param[in] ExTokenNumber The PCD token number.
369 @return The size 8-bit value for the PCD token.
375 IN CONST EFI_GUID
*Guid
,
376 IN UINTN ExTokenNumber
379 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT8
)));
383 Retrieves an 16-bit value for a given PCD token.
385 Retrieves the 16-bit value of a particular PCD token.
386 If the TokenNumber is invalid or the token space
387 specified by Guid does not exist, the results are
390 @param[in] Guid The token space for the token number.
391 @param[in] ExTokenNumber The PCD token number.
393 @return The size 16-bit value for the PCD token.
399 IN CONST EFI_GUID
*Guid
,
400 IN UINTN ExTokenNumber
403 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT16
)));
407 Retrieves an 32-bit value for a given PCD token.
409 Retrieves the 32-bit value of a particular PCD token.
410 If the TokenNumber is invalid or the token space
411 specified by Guid does not exist, the results are
414 @param[in] Guid The token space for the token number.
415 @param[in] ExTokenNumber The PCD token number.
417 @return The size 32-bit value for the PCD token.
423 IN CONST EFI_GUID
*Guid
,
424 IN UINTN ExTokenNumber
427 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT32
)));
431 Retrieves an 64-bit value for a given PCD token.
433 Retrieves the 64-bit value of a particular PCD token.
434 If the TokenNumber is invalid or the token space
435 specified by Guid does not exist, the results are
438 @param[in] Guid The token space for the token number.
439 @param[in] ExTokenNumber The PCD token number.
441 @return The size 64-bit value for the PCD token.
447 IN CONST EFI_GUID
*Guid
,
448 IN UINTN ExTokenNumber
451 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT64
)));
455 Retrieves a pointer to a value for a given PCD token.
457 Retrieves the current pointer to the buffer for a PCD token number.
458 Do not make any assumptions about the alignment of the pointer that
459 is returned by this function call. If the TokenNumber is invalid,
460 the results are unpredictable.
462 @param[in] Guid The token space for the token number.
463 @param[in] ExTokenNumber The PCD token number.
465 @return The pointer to the buffer to be retrived.
471 IN CONST EFI_GUID
*Guid
,
472 IN UINTN ExTokenNumber
475 return ExGetWorker (Guid
, ExTokenNumber
, 0);
479 Retrieves an Boolean value for a given PCD token.
481 Retrieves the Boolean 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 Boolean value for the PCD token.
495 IN CONST EFI_GUID
*Guid
,
496 IN UINTN ExTokenNumber
499 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(BOOLEAN
)));
503 Retrieves the size of the value for a given PCD token.
505 Retrieves the current size of a particular PCD token.
506 If the TokenNumber is invalid, the results are unpredictable.
508 @param[in] Guid The token space for the token number.
509 @param[in] ExTokenNumber The PCD token number.
511 @return The size of the value for the PCD token.
517 IN CONST EFI_GUID
*Guid
,
518 IN UINTN ExTokenNumber
521 return DxePcdGetSize(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
));
525 Sets an 8-bit value for a given PCD token.
527 When the PCD service sets a value, it will check to ensure that the
528 size of the value being set is compatible with the Token's existing definition.
529 If it is not, an error will be returned.
531 @param[in] TokenNumber The PCD token number.
532 @param[in] Value The value to set for the PCD token.
534 @retval EFI_SUCCESS Procedure returned successfully.
535 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
536 being set was incompatible with a call to this function.
537 Use GetSize() to retrieve the size of the target data.
538 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
544 IN UINTN TokenNumber
,
548 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
552 Sets an 16-bit value for a given PCD token.
554 When the PCD service sets a value, it will check to ensure that the
555 size of the value being set is compatible with the Token's existing definition.
556 If it is not, an error will be returned.
558 @param[in] TokenNumber The PCD token number.
559 @param[in] Value The value to set for the PCD token.
561 @retval EFI_SUCCESS Procedure returned successfully.
562 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
563 being set was incompatible with a call to this function.
564 Use GetSize() to retrieve the size of the target data.
565 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
571 IN UINTN TokenNumber
,
575 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
579 Sets an 32-bit value for a given PCD token.
581 When the PCD service sets a value, it will check to ensure that the
582 size of the value being set is compatible with the Token's existing definition.
583 If it is not, an error will be returned.
585 @param[in] TokenNumber The PCD token number.
586 @param[in] Value The value to set for the PCD token.
588 @retval EFI_SUCCESS Procedure returned successfully.
589 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
590 being set was incompatible with a call to this function.
591 Use GetSize() to retrieve the size of the target data.
592 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
598 IN UINTN TokenNumber
,
602 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
606 Sets an 64-bit value for a given PCD token.
608 When the PCD service sets a value, it will check to ensure that the
609 size of the value being set is compatible with the Token's existing definition.
610 If it is not, an error will be returned.
612 @param[in] TokenNumber The PCD token number.
613 @param[in] Value The value to set for the PCD token.
615 @retval EFI_SUCCESS Procedure returned successfully.
616 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
617 being set was incompatible with a call to this function.
618 Use GetSize() to retrieve the size of the target data.
619 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
625 IN UINTN TokenNumber
,
629 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
633 Sets a value of a specified size for a given PCD token.
635 When the PCD service sets a value, it will check to ensure that the
636 size of the value being set is compatible with the Token's existing definition.
637 If it is not, an error will be returned.
639 @param[in] TokenNumber The PCD token number.
640 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
641 On input, if the SizeOfValue is greater than the maximum size supported
642 for this TokenNumber then the output value of SizeOfValue will reflect
643 the maximum size supported for this TokenNumber.
644 @param[in] Buffer The buffer to set for the PCD token.
646 @retval EFI_SUCCESS Procedure returned successfully.
647 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
648 being set was incompatible with a call to this function.
649 Use GetSize() to retrieve the size of the target data.
650 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
656 IN UINTN TokenNumber
,
657 IN OUT UINTN
*SizeOfBuffer
,
661 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
665 Sets an Boolean value for a given PCD token.
667 When the PCD service sets a value, it will check to ensure that the
668 size of the value being set is compatible with the Token's existing definition.
669 If it is not, an error will be returned.
671 @param[in] TokenNumber The PCD token number.
672 @param[in] Value The value to set for the PCD token.
674 @retval EFI_SUCCESS Procedure returned successfully.
675 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
676 being set was incompatible with a call to this function.
677 Use GetSize() to retrieve the size of the target data.
678 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
684 IN UINTN TokenNumber
,
688 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
692 Sets an 8-bit value for a given PCD token.
694 When the PCD service sets a value, it will check to ensure that the
695 size of the value being set is compatible with the Token's existing definition.
696 If it is not, an error will be returned.
698 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
699 @param[in] ExTokenNumber The PCD token number.
700 @param[in] Value The value to set for the PCD token.
702 @retval EFI_SUCCESS Procedure returned successfully.
703 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
704 being set was incompatible with a call to this function.
705 Use GetSize() to retrieve the size of the target data.
706 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
712 IN CONST EFI_GUID
*Guid
,
713 IN UINTN ExTokenNumber
,
717 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
721 Sets an 16-bit value for a given PCD token.
723 When the PCD service sets a value, it will check to ensure that the
724 size of the value being set is compatible with the Token's existing definition.
725 If it is not, an error will be returned.
727 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
728 @param[in] ExTokenNumber The PCD token number.
729 @param[in] Value The value to set for the PCD token.
731 @retval EFI_SUCCESS Procedure returned successfully.
732 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
733 being set was incompatible with a call to this function.
734 Use GetSize() to retrieve the size of the target data.
735 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
741 IN CONST EFI_GUID
*Guid
,
742 IN UINTN ExTokenNumber
,
746 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
750 Sets an 32-bit value for a given PCD token.
752 When the PCD service sets a value, it will check to ensure that the
753 size of the value being set is compatible with the Token's existing definition.
754 If it is not, an error will be returned.
756 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
757 @param[in] ExTokenNumber The PCD token number.
758 @param[in] Value The value to set for the PCD token.
760 @retval EFI_SUCCESS Procedure returned successfully.
761 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
762 being set was incompatible with a call to this function.
763 Use GetSize() to retrieve the size of the target data.
764 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
770 IN CONST EFI_GUID
*Guid
,
771 IN UINTN ExTokenNumber
,
775 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
779 Sets an 64-bit value for a given PCD token.
781 When the PCD service sets a value, it will check to ensure that the
782 size of the value being set is compatible with the Token's existing definition.
783 If it is not, an error will be returned.
785 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
786 @param[in] ExTokenNumber The PCD token number.
787 @param[in] Value The value to set for the PCD token.
789 @retval EFI_SUCCESS Procedure returned successfully.
790 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
791 being set was incompatible with a call to this function.
792 Use GetSize() to retrieve the size of the target data.
793 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
799 IN CONST EFI_GUID
*Guid
,
800 IN UINTN ExTokenNumber
,
804 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
808 Sets a value of a specified size for a given PCD token.
810 When the PCD service sets a value, it will check to ensure that the
811 size of the value being set is compatible with the Token's existing definition.
812 If it is not, an error will be returned.
814 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
815 @param[in] ExTokenNumber The PCD token number.
816 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
817 On input, if the SizeOfValue is greater than the maximum size supported
818 for this TokenNumber then the output value of SizeOfValue will reflect
819 the maximum size supported for this TokenNumber.
820 @param[in] Buffer The buffer 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
,
834 IN OUT UINTN
*SizeOfBuffer
,
838 return ExSetWorker(ExTokenNumber
, Guid
, Buffer
, SizeOfBuffer
, TRUE
);
842 Sets an Boolean value for a given PCD token.
844 When the PCD service sets a value, it will check to ensure that the
845 size of the value being set is compatible with the Token's existing definition.
846 If it is not, an error will be returned.
848 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
849 @param[in] ExTokenNumber The PCD token number.
850 @param[in] Value The value to set for the PCD token.
852 @retval EFI_SUCCESS Procedure returned successfully.
853 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
854 being set was incompatible with a call to this function.
855 Use GetSize() to retrieve the size of the target data.
856 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
862 IN CONST EFI_GUID
*Guid
,
863 IN UINTN ExTokenNumber
,
867 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
871 Specifies a function to be called anytime the value of a designated token is changed.
873 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
874 @param[in] TokenNumber The PCD token number.
875 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
877 @retval EFI_SUCCESS The PCD service has successfully established a call event
878 for the CallBackToken requested.
879 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
884 DxeRegisterCallBackOnSet (
885 IN CONST EFI_GUID
*Guid
, OPTIONAL
886 IN UINTN TokenNumber
,
887 IN PCD_PROTOCOL_CALLBACK CallBackFunction
892 if (CallBackFunction
== NULL
) {
893 return EFI_INVALID_PARAMETER
;
896 // Aquire lock to prevent reentrance from TPL_CALLBACK level
898 EfiAcquireLock (&mPcdDatabaseLock
);
900 Status
= DxeRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
902 EfiReleaseLock (&mPcdDatabaseLock
);
908 Cancels a previously set callback function for a particular PCD token number.
910 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
911 @param[in] TokenNumber The PCD token number.
912 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
914 @retval EFI_SUCCESS The PCD service has successfully established a call event
915 for the CallBackToken requested.
916 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
921 DxeUnRegisterCallBackOnSet (
922 IN CONST EFI_GUID
*Guid
, OPTIONAL
923 IN UINTN TokenNumber
,
924 IN PCD_PROTOCOL_CALLBACK CallBackFunction
929 if (CallBackFunction
== NULL
) {
930 return EFI_INVALID_PARAMETER
;
934 // Aquire lock to prevent reentrance from TPL_CALLBACK level
936 EfiAcquireLock (&mPcdDatabaseLock
);
938 Status
= DxeUnRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
940 EfiReleaseLock (&mPcdDatabaseLock
);
946 Retrieves the next valid token number in a given namespace.
948 This is useful since the PCD infrastructure contains a sparse list of token numbers,
949 and one cannot a priori know what token numbers are valid in the database.
951 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
952 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
953 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
954 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
955 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
956 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
957 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
958 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
961 @param[in] Guid The 128-bit unique value that designates the namespace from which to retrieve the next token.
962 This is an optional parameter that may be NULL. If this parameter is NULL, then a request is
963 being made to retrieve tokens from the default token space.
964 @param[in, out] TokenNumber
965 A pointer to the PCD token number to use to find the subsequent token number.
967 @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.
968 @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.
974 IN CONST EFI_GUID
*Guid
, OPTIONAL
975 IN OUT UINTN
*TokenNumber
979 BOOLEAN PeiExMapTableEmpty
;
980 BOOLEAN DxeExMapTableEmpty
;
982 Status
= EFI_NOT_FOUND
;
983 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
984 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
987 // Scan the local token space
990 // EBC compiler is very choosy. It may report warning about comparison
991 // between UINTN and 0 . So we add 1 in each size of the
993 if (((*TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) && (*TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) ||
994 ((*TokenNumber
+ 1 > (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1)))) {
995 return EFI_NOT_FOUND
;
999 if ((*TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) &&
1000 (*TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) {
1002 // The first Non-Ex type Token Number for DXE PCD
1003 // database is mPeiLocalTokenCount + 1
1005 if (mDxeNexTokenCount
> 0) {
1006 *TokenNumber
= mPeiLocalTokenCount
+ 1;
1008 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1009 return EFI_NOT_FOUND
;
1011 } else if (*TokenNumber
+ 1 > mDxeNexTokenCount
+ mPeiLocalTokenCount
+ 1) {
1012 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1013 return EFI_NOT_FOUND
;
1018 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1019 return EFI_NOT_FOUND
;
1022 if (!PeiExMapTableEmpty
) {
1023 Status
= ExGetNextTokeNumber (
1026 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
),
1028 (DYNAMICEX_MAPPING
*)((UINT8
*) mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
),
1029 mPeiExMapppingTableSize
1033 if (Status
== EFI_SUCCESS
) {
1037 if (!DxeExMapTableEmpty
) {
1038 Status
= ExGetNextTokeNumber (
1041 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
),
1043 (DYNAMICEX_MAPPING
*)((UINT8
*) mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
),
1044 mDxeExMapppingTableSize
1052 Get all token space guid table which is different with given token space guid.
1054 @param ExMapTableSize The size of ExMapTable in item
1055 @param ExMapTable Token space guid table that want to be scaned.
1056 @param GuidTable Guid table
1058 @return all token space guid table which is different with given token space guid.
1062 GetDistinctTokenSpace (
1063 IN OUT UINTN
*ExMapTableSize
,
1064 IN DYNAMICEX_MAPPING
*ExMapTable
,
1065 IN EFI_GUID
*GuidTable
1068 EFI_GUID
**DistinctTokenSpace
;
1075 DistinctTokenSpace
= AllocateZeroPool (*ExMapTableSize
* sizeof (EFI_GUID
*));
1076 ASSERT (DistinctTokenSpace
!= NULL
);
1079 OldGuidIndex
= ExMapTable
[0].ExGuidIndex
;
1080 DistinctTokenSpace
[TsIdx
] = &GuidTable
[OldGuidIndex
];
1081 for (Idx
= 1; Idx
< *ExMapTableSize
; Idx
++) {
1083 OldGuidIndex
= ExMapTable
[Idx
].ExGuidIndex
;
1084 for (TempTsIdx
= 0; TempTsIdx
<= TsIdx
; TempTsIdx
++) {
1085 if (&GuidTable
[OldGuidIndex
] == DistinctTokenSpace
[TempTsIdx
]) {
1087 // Have recorded this GUID.
1094 DistinctTokenSpace
[++TsIdx
] = &GuidTable
[OldGuidIndex
];
1099 // The total number of Distinct Token Space
1100 // is TsIdx + 1 because we use TsIdx as a index
1101 // to the DistinctTokenSpace[]
1103 *ExMapTableSize
= TsIdx
+ 1;
1104 return DistinctTokenSpace
;
1109 Retrieves the next valid PCD token namespace for a given namespace.
1111 Gets the next valid token namespace for a given namespace. This is useful to traverse the valid
1112 token namespaces on a platform.
1114 @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token
1115 namespace from which the search will start. On output, it designates the next valid
1116 token namespace on the platform. If *Guid is NULL, then the GUID of the first token
1117 space of the current platform is returned. If the search cannot locate the next valid
1118 token namespace, an error is returned and the value of *Guid is undefined.
1120 @retval EFI_SUCCESS The PCD service retrieved the value requested.
1121 @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.
1126 DxePcdGetNextTokenSpace (
1127 IN OUT CONST EFI_GUID
**Guid
1133 UINTN PeiTokenSpaceTableSize
;
1134 UINTN DxeTokenSpaceTableSize
;
1135 EFI_GUID
**PeiTokenSpaceTable
;
1136 EFI_GUID
**DxeTokenSpaceTable
;
1138 BOOLEAN PeiExMapTableEmpty
;
1139 BOOLEAN DxeExMapTableEmpty
;
1141 ASSERT (Guid
!= NULL
);
1143 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
1144 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
1146 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1147 return EFI_NOT_FOUND
;
1150 if (TmpTokenSpaceBuffer
[0] == NULL
) {
1151 PeiTokenSpaceTableSize
= 0;
1153 if (!PeiExMapTableEmpty
) {
1154 PeiTokenSpaceTableSize
= mPeiExMapppingTableSize
/ sizeof(DYNAMICEX_MAPPING
);
1155 PeiTokenSpaceTable
= GetDistinctTokenSpace (&PeiTokenSpaceTableSize
,
1156 (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
),
1157 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
)
1159 CopyMem (TmpTokenSpaceBuffer
, PeiTokenSpaceTable
, sizeof (EFI_GUID
*) * PeiTokenSpaceTableSize
);
1160 FreePool (PeiTokenSpaceTable
);
1163 if (!DxeExMapTableEmpty
) {
1164 DxeTokenSpaceTableSize
= mDxeExMapppingTableSize
/ sizeof(DYNAMICEX_MAPPING
);
1165 DxeTokenSpaceTable
= GetDistinctTokenSpace (&DxeTokenSpaceTableSize
,
1166 (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
),
1167 (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
)
1171 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable
1173 for (Idx2
= 0, Idx3
= PeiTokenSpaceTableSize
; Idx2
< DxeTokenSpaceTableSize
; Idx2
++) {
1175 for (Idx
= 0; Idx
< PeiTokenSpaceTableSize
; Idx
++) {
1176 if (CompareGuid (TmpTokenSpaceBuffer
[Idx
], DxeTokenSpaceTable
[Idx2
])) {
1182 TmpTokenSpaceBuffer
[Idx3
++] = DxeTokenSpaceTable
[Idx2
];
1186 TmpTokenSpaceBufferCount
= Idx3
;
1187 FreePool (DxeTokenSpaceTable
);
1191 if (*Guid
== NULL
) {
1192 *Guid
= TmpTokenSpaceBuffer
[0];
1196 for (Idx
= 0; Idx
< TmpTokenSpaceBufferCount
; Idx
++) {
1197 if (CompareGuid (*Guid
, TmpTokenSpaceBuffer
[Idx
])) {
1198 if (Idx
== TmpTokenSpaceBufferCount
- 1) {
1200 // It has been the last token namespace.
1203 return EFI_NOT_FOUND
;
1206 *Guid
= TmpTokenSpaceBuffer
[Idx
];
1212 return EFI_NOT_FOUND
;