2 PCD DXE driver manage all PCD entry initialized in PEI phase and DXE phase, and
3 produce the implementation of PCD protocol.
5 Copyright (c) 2006 - 2009, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 // Just pre-allocate a memory buffer that is big enough to
20 // host all distinct TokenSpace guid in both
21 // PEI ExMap and DXE ExMap.
23 EFI_GUID
*TmpTokenSpaceBuffer
[PEI_EXMAPPING_TABLE_SIZE
+ DXE_EXMAPPING_TABLE_SIZE
] = { 0 };
26 /// PCD database lock.
28 EFI_LOCK mPcdDatabaseLock
= EFI_INITIALIZE_LOCK_VARIABLE(TPL_NOTIFY
);
30 PCD_PROTOCOL mPcdInstance
= {
63 DxeRegisterCallBackOnSet
,
64 DxeUnRegisterCallBackOnSet
,
66 DxePcdGetNextTokenSpace
69 EFI_PCD_PROTOCOL mEfiPcdInstance
= {
84 (EFI_PCD_PROTOCOL_CALLBACK_ON_SET
) DxeRegisterCallBackOnSet
,
85 (EFI_PCD_PROTOCOL_CANCEL_CALLBACK
) DxeUnRegisterCallBackOnSet
,
87 DxePcdGetNextTokenSpace
91 // Static global to reduce the code size
93 EFI_HANDLE mNewHandle
= NULL
;
96 Main entry for PCD DXE driver.
98 This routine initialize the PCD database and install PCD_PROTOCOL.
100 @param ImageHandle Image handle for PCD DXE driver.
101 @param SystemTable Pointer to SystemTable.
103 @return Status of gBS->InstallProtocolInterface()
109 IN EFI_HANDLE ImageHandle
,
110 IN EFI_SYSTEM_TABLE
*SystemTable
116 // Make sure the Pcd Protocol is not already installed in the system
119 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gPcdProtocolGuid
);
121 BuildPcdDxeDataBase ();
123 Status
= gBS
->InstallProtocolInterface (
126 EFI_NATIVE_INTERFACE
,
132 // Also install gEfiPcdProtocolGuid which is only support dynamic-ex type
136 Status
= gBS
->InstallProtocolInterface (
138 &gEfiPcdProtocolGuid
,
139 EFI_NATIVE_INTERFACE
,
143 ASSERT_EFI_ERROR (Status
);
150 Sets the SKU value for subsequent calls to set or get PCD token values.
152 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
153 SetSku() is normally called only once by the system.
155 For each item (token), the database can hold a single value that applies to all SKUs,
156 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
157 SKU-specific values are called SKU enabled.
159 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
160 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
161 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
162 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
163 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
164 set for that Id, the results are unpredictable.
166 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
167 set values associated with a PCD token.
176 mPcdDatabase
->PeiDb
.Init
.SystemSkuId
= (SKU_ID
) SkuId
;
182 Retrieves an 8-bit value for a given PCD token.
184 Retrieves the current byte-sized value for a PCD token number.
185 If the TokenNumber is invalid, the results are unpredictable.
187 @param[in] TokenNumber The PCD token number.
189 @return The UINT8 value.
198 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
202 Retrieves an 16-bit value for a given PCD token.
204 Retrieves the current 16-bits value for a PCD token number.
205 If the TokenNumber is invalid, the results are unpredictable.
207 @param[in] TokenNumber The PCD token number.
209 @return The UINT16 value.
218 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
222 Retrieves an 32-bit value for a given PCD token.
224 Retrieves the current 32-bits value for a PCD token number.
225 If the TokenNumber is invalid, the results are unpredictable.
227 @param[in] TokenNumber The PCD token number.
229 @return The UINT32 value.
238 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
242 Retrieves an 64-bit value for a given PCD token.
244 Retrieves the current 64-bits value for a PCD token number.
245 If the TokenNumber is invalid, the results are unpredictable.
247 @param[in] TokenNumber The PCD token number.
249 @return The UINT64 value.
258 return ReadUnaligned64(GetWorker (TokenNumber
, sizeof (UINT64
)));
262 Retrieves a pointer to a value for a given PCD token.
264 Retrieves the current pointer to the buffer for a PCD token number.
265 Do not make any assumptions about the alignment of the pointer that
266 is returned by this function call. If the TokenNumber is invalid,
267 the results are unpredictable.
269 @param[in] TokenNumber The PCD token number.
271 @return The pointer to the buffer to be retrived.
280 return GetWorker (TokenNumber
, 0);
284 Retrieves a Boolean value for a given PCD token.
286 Retrieves the current boolean value for a PCD token number.
287 Do not make any assumptions about the alignment of the pointer that
288 is returned by this function call. If the TokenNumber is invalid,
289 the results are unpredictable.
291 @param[in] TokenNumber The PCD token number.
293 @return The Boolean value.
302 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
306 Retrieves the size of the value for a given PCD token.
308 Retrieves the current size of a particular PCD token.
309 If the TokenNumber is invalid, the results are unpredictable.
311 @param[in] TokenNumber The PCD token number.
313 @return The size of the value for the PCD token.
323 UINT32
*LocalTokenNumberTable
;
326 UINTN TmpTokenNumber
;
328 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
329 // We have to decrement TokenNumber by 1 to make it usable
330 // as the array index.
335 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
337 TmpTokenNumber
= TokenNumber
;
339 // EBC compiler is very choosy. It may report warning about comparison
340 // between UINTN and 0 . So we add 1 in each size of the
342 ASSERT (TokenNumber
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1);
344 // EBC compiler is very choosy. It may report warning about comparison
345 // between UINTN and 0 . So we add 1 in each size of the
347 IsPeiDb
= (BOOLEAN
) (TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
349 TokenNumber
= IsPeiDb
? TokenNumber
:
350 (TokenNumber
- PEI_LOCAL_TOKEN_NUMBER
);
352 LocalTokenNumberTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
353 : mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
355 Size
= (LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
359 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
361 return GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
369 Retrieves an 8-bit value for a given PCD token.
371 Retrieves the 8-bit value of a particular PCD token.
372 If the TokenNumber is invalid or the token space
373 specified by Guid does not exist, the results are
376 @param[in] Guid The token space for the token number.
377 @param[in] ExTokenNumber The PCD token number.
379 @return The size 8-bit value for the PCD token.
385 IN CONST EFI_GUID
*Guid
,
386 IN UINTN ExTokenNumber
389 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT8
)));
393 Retrieves an 16-bit value for a given PCD token.
395 Retrieves the 16-bit value of a particular PCD token.
396 If the TokenNumber is invalid or the token space
397 specified by Guid does not exist, the results are
400 @param[in] Guid The token space for the token number.
401 @param[in] ExTokenNumber The PCD token number.
403 @return The size 16-bit value for the PCD token.
409 IN CONST EFI_GUID
*Guid
,
410 IN UINTN ExTokenNumber
413 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT16
)));
417 Retrieves an 32-bit value for a given PCD token.
419 Retrieves the 32-bit value of a particular PCD token.
420 If the TokenNumber is invalid or the token space
421 specified by Guid does not exist, the results are
424 @param[in] Guid The token space for the token number.
425 @param[in] ExTokenNumber The PCD token number.
427 @return The size 32-bit value for the PCD token.
433 IN CONST EFI_GUID
*Guid
,
434 IN UINTN ExTokenNumber
437 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT32
)));
441 Retrieves an 64-bit value for a given PCD token.
443 Retrieves the 64-bit value of a particular PCD token.
444 If the TokenNumber is invalid or the token space
445 specified by Guid does not exist, the results are
448 @param[in] Guid The token space for the token number.
449 @param[in] ExTokenNumber The PCD token number.
451 @return The size 64-bit value for the PCD token.
457 IN CONST EFI_GUID
*Guid
,
458 IN UINTN ExTokenNumber
461 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT64
)));
465 Retrieves a pointer to a value for a given PCD token.
467 Retrieves the current pointer to the buffer for a PCD token number.
468 Do not make any assumptions about the alignment of the pointer that
469 is returned by this function call. If the TokenNumber is invalid,
470 the results are unpredictable.
472 @param[in] Guid The token space for the token number.
473 @param[in] ExTokenNumber The PCD token number.
475 @return The pointer to the buffer to be retrived.
481 IN CONST EFI_GUID
*Guid
,
482 IN UINTN ExTokenNumber
485 return ExGetWorker (Guid
, ExTokenNumber
, 0);
489 Retrieves an Boolean value for a given PCD token.
491 Retrieves the Boolean value of a particular PCD token.
492 If the TokenNumber is invalid or the token space
493 specified by Guid does not exist, the results are
496 @param[in] Guid The token space for the token number.
497 @param[in] ExTokenNumber The PCD token number.
499 @return The size Boolean value for the PCD token.
505 IN CONST EFI_GUID
*Guid
,
506 IN UINTN ExTokenNumber
509 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(BOOLEAN
)));
513 Retrieves the size of the value for a given PCD token.
515 Retrieves the current size of a particular PCD token.
516 If the TokenNumber is invalid, the results are unpredictable.
518 @param[in] Guid The token space for the token number.
519 @param[in] ExTokenNumber The PCD token number.
521 @return The size of the value for the PCD token.
527 IN CONST EFI_GUID
*Guid
,
528 IN UINTN ExTokenNumber
531 return DxePcdGetSize(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
));
535 Sets an 8-bit value for a given PCD token.
537 When the PCD service sets a value, it will check to ensure that the
538 size of the value being set is compatible with the Token's existing definition.
539 If it is not, an error will be returned.
541 @param[in] TokenNumber The PCD token number.
542 @param[in] Value The value to set for the PCD token.
544 @retval EFI_SUCCESS Procedure returned successfully.
545 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
546 being set was incompatible with a call to this function.
547 Use GetSize() to retrieve the size of the target data.
548 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
554 IN UINTN TokenNumber
,
558 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
562 Sets an 16-bit value for a given PCD token.
564 When the PCD service sets a value, it will check to ensure that the
565 size of the value being set is compatible with the Token's existing definition.
566 If it is not, an error will be returned.
568 @param[in] TokenNumber The PCD token number.
569 @param[in] Value The value to set for the PCD token.
571 @retval EFI_SUCCESS Procedure returned successfully.
572 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
573 being set was incompatible with a call to this function.
574 Use GetSize() to retrieve the size of the target data.
575 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
581 IN UINTN TokenNumber
,
585 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
589 Sets an 32-bit value for a given PCD token.
591 When the PCD service sets a value, it will check to ensure that the
592 size of the value being set is compatible with the Token's existing definition.
593 If it is not, an error will be returned.
595 @param[in] TokenNumber The PCD token number.
596 @param[in] Value The value to set for the PCD token.
598 @retval EFI_SUCCESS Procedure returned successfully.
599 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
600 being set was incompatible with a call to this function.
601 Use GetSize() to retrieve the size of the target data.
602 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
608 IN UINTN TokenNumber
,
612 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
616 Sets an 64-bit value for a given PCD token.
618 When the PCD service sets a value, it will check to ensure that the
619 size of the value being set is compatible with the Token's existing definition.
620 If it is not, an error will be returned.
622 @param[in] TokenNumber The PCD token number.
623 @param[in] Value The value to set for the PCD token.
625 @retval EFI_SUCCESS Procedure returned successfully.
626 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
627 being set was incompatible with a call to this function.
628 Use GetSize() to retrieve the size of the target data.
629 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
635 IN UINTN TokenNumber
,
639 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
643 Sets a value of a specified size for a given PCD token.
645 When the PCD service sets a value, it will check to ensure that the
646 size of the value being set is compatible with the Token's existing definition.
647 If it is not, an error will be returned.
649 @param[in] TokenNumber The PCD token number.
650 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
651 On input, if the SizeOfValue is greater than the maximum size supported
652 for this TokenNumber then the output value of SizeOfValue will reflect
653 the maximum size supported for this TokenNumber.
654 @param[in] Buffer The buffer to set for the PCD token.
656 @retval EFI_SUCCESS Procedure returned successfully.
657 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
658 being set was incompatible with a call to this function.
659 Use GetSize() to retrieve the size of the target data.
660 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
666 IN UINTN TokenNumber
,
667 IN OUT UINTN
*SizeOfBuffer
,
671 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
675 Sets an Boolean value for a given PCD token.
677 When the PCD service sets a value, it will check to ensure that the
678 size of the value being set is compatible with the Token's existing definition.
679 If it is not, an error will be returned.
681 @param[in] TokenNumber The PCD token number.
682 @param[in] Value The value to set for the PCD token.
684 @retval EFI_SUCCESS Procedure returned successfully.
685 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
686 being set was incompatible with a call to this function.
687 Use GetSize() to retrieve the size of the target data.
688 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
694 IN UINTN TokenNumber
,
698 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
702 Sets an 8-bit value for a given PCD token.
704 When the PCD service sets a value, it will check to ensure that the
705 size of the value being set is compatible with the Token's existing definition.
706 If it is not, an error will be returned.
708 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
709 @param[in] ExTokenNumber The PCD token number.
710 @param[in] Value The value to set for the PCD token.
712 @retval EFI_SUCCESS Procedure returned successfully.
713 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
714 being set was incompatible with a call to this function.
715 Use GetSize() to retrieve the size of the target data.
716 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
722 IN CONST EFI_GUID
*Guid
,
723 IN UINTN ExTokenNumber
,
727 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
731 Sets an 16-bit value for a given PCD token.
733 When the PCD service sets a value, it will check to ensure that the
734 size of the value being set is compatible with the Token's existing definition.
735 If it is not, an error will be returned.
737 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
738 @param[in] ExTokenNumber The PCD token number.
739 @param[in] Value The value to set for the PCD token.
741 @retval EFI_SUCCESS Procedure returned successfully.
742 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
743 being set was incompatible with a call to this function.
744 Use GetSize() to retrieve the size of the target data.
745 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
751 IN CONST EFI_GUID
*Guid
,
752 IN UINTN ExTokenNumber
,
756 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
760 Sets an 32-bit value for a given PCD token.
762 When the PCD service sets a value, it will check to ensure that the
763 size of the value being set is compatible with the Token's existing definition.
764 If it is not, an error will be returned.
766 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
767 @param[in] ExTokenNumber The PCD token number.
768 @param[in] Value The value to set for the PCD token.
770 @retval EFI_SUCCESS Procedure returned successfully.
771 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
772 being set was incompatible with a call to this function.
773 Use GetSize() to retrieve the size of the target data.
774 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
780 IN CONST EFI_GUID
*Guid
,
781 IN UINTN ExTokenNumber
,
785 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
789 Sets an 64-bit value for a given PCD token.
791 When the PCD service sets a value, it will check to ensure that the
792 size of the value being set is compatible with the Token's existing definition.
793 If it is not, an error will be returned.
795 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
796 @param[in] ExTokenNumber The PCD token number.
797 @param[in] Value The value to set for the PCD token.
799 @retval EFI_SUCCESS Procedure returned successfully.
800 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
801 being set was incompatible with a call to this function.
802 Use GetSize() to retrieve the size of the target data.
803 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
809 IN CONST EFI_GUID
*Guid
,
810 IN UINTN ExTokenNumber
,
814 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
818 Sets a value of a specified size for a given PCD token.
820 When the PCD service sets a value, it will check to ensure that the
821 size of the value being set is compatible with the Token's existing definition.
822 If it is not, an error will be returned.
824 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
825 @param[in] ExTokenNumber The PCD token number.
826 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
827 On input, if the SizeOfValue is greater than the maximum size supported
828 for this TokenNumber then the output value of SizeOfValue will reflect
829 the maximum size supported for this TokenNumber.
830 @param[in] Buffer The buffer to set for the PCD token.
832 @retval EFI_SUCCESS Procedure returned successfully.
833 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
834 being set was incompatible with a call to this function.
835 Use GetSize() to retrieve the size of the target data.
836 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
842 IN CONST EFI_GUID
*Guid
,
843 IN UINTN ExTokenNumber
,
844 IN OUT UINTN
*SizeOfBuffer
,
848 return ExSetWorker(ExTokenNumber
, Guid
, Buffer
, SizeOfBuffer
, TRUE
);
852 Sets an Boolean value for a given PCD token.
854 When the PCD service sets a value, it will check to ensure that the
855 size of the value being set is compatible with the Token's existing definition.
856 If it is not, an error will be returned.
858 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
859 @param[in] ExTokenNumber The PCD token number.
860 @param[in] Value The value to set for the PCD token.
862 @retval EFI_SUCCESS Procedure returned successfully.
863 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
864 being set was incompatible with a call to this function.
865 Use GetSize() to retrieve the size of the target data.
866 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
872 IN CONST EFI_GUID
*Guid
,
873 IN UINTN ExTokenNumber
,
877 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
881 Specifies a function to be called anytime the value of a designated token is changed.
883 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
884 @param[in] TokenNumber The PCD token number.
885 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
887 @retval EFI_SUCCESS The PCD service has successfully established a call event
888 for the CallBackToken requested.
889 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
894 DxeRegisterCallBackOnSet (
895 IN CONST EFI_GUID
*Guid
, OPTIONAL
896 IN UINTN TokenNumber
,
897 IN PCD_PROTOCOL_CALLBACK CallBackFunction
902 if (CallBackFunction
== NULL
) {
903 return EFI_INVALID_PARAMETER
;
906 // Aquire lock to prevent reentrance from TPL_CALLBACK level
908 EfiAcquireLock (&mPcdDatabaseLock
);
910 Status
= DxeRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
912 EfiReleaseLock (&mPcdDatabaseLock
);
918 Cancels a previously set callback function for a particular PCD token number.
920 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
921 @param[in] TokenNumber The PCD token number.
922 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
924 @retval EFI_SUCCESS The PCD service has successfully established a call event
925 for the CallBackToken requested.
926 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
931 DxeUnRegisterCallBackOnSet (
932 IN CONST EFI_GUID
*Guid
, OPTIONAL
933 IN UINTN TokenNumber
,
934 IN PCD_PROTOCOL_CALLBACK CallBackFunction
939 if (CallBackFunction
== NULL
) {
940 return EFI_INVALID_PARAMETER
;
944 // Aquire lock to prevent reentrance from TPL_CALLBACK level
946 EfiAcquireLock (&mPcdDatabaseLock
);
948 Status
= DxeUnRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
950 EfiReleaseLock (&mPcdDatabaseLock
);
956 Retrieves the next valid token number in a given namespace.
958 This is useful since the PCD infrastructure contains a sparse list of token numbers,
959 and one cannot a priori know what token numbers are valid in the database.
961 If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.
962 If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.
963 If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.
964 If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.
965 The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.
966 If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.
967 If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.
968 If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.
971 @param[in] Guid The 128-bit unique value that designates the namespace from which to retrieve the next token.
972 This is an optional parameter that may be NULL. If this parameter is NULL, then a request is
973 being made to retrieve tokens from the default token space.
974 @param[in,out] TokenNumber
975 A pointer to the PCD token number to use to find the subsequent token number.
977 @retval EFI_SUCCESS The PCD service retrieved the next valid token number. Or the input token number
978 is already the last valid token number in the PCD database.
979 In the later case, *TokenNumber is updated with the value of 0.
980 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
986 IN CONST EFI_GUID
*Guid
, OPTIONAL
987 IN OUT UINTN
*TokenNumber
991 BOOLEAN PeiExMapTableEmpty
;
992 BOOLEAN DxeExMapTableEmpty
;
994 Status
= EFI_NOT_FOUND
;
995 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
996 DxeExMapTableEmpty
= DXE_EXMAP_TABLE_EMPTY
;
999 // Scan the local token space
1002 // EBC compiler is very choosy. It may report warning about comparison
1003 // between UINTN and 0 . So we add 1 in each size of the
1005 if (((*TokenNumber
+ 1 > PEI_NEX_TOKEN_NUMBER
+ 1) && (*TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1)) ||
1006 ((*TokenNumber
+ 1 > (PEI_LOCAL_TOKEN_NUMBER
+ DXE_NEX_TOKEN_NUMBER
+ 1)))) {
1007 return EFI_NOT_FOUND
;
1011 if ((*TokenNumber
+ 1 > PEI_NEX_TOKEN_NUMBER
+ 1) &&
1012 (*TokenNumber
<= PEI_LOCAL_TOKEN_NUMBER
)) {
1014 // The first Non-Ex type Token Number for DXE PCD
1015 // database is PEI_LOCAL_TOKEN_NUMBER
1017 *TokenNumber
= PEI_LOCAL_TOKEN_NUMBER
;
1018 } else if (*TokenNumber
+ 1 > DXE_NEX_TOKEN_NUMBER
+ PEI_LOCAL_TOKEN_NUMBER
+ 1) {
1019 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1024 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1025 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
1026 return EFI_NOT_FOUND
;
1029 if (!PeiExMapTableEmpty
) {
1030 Status
= ExGetNextTokeNumber (
1033 mPcdDatabase
->PeiDb
.Init
.GuidTable
,
1034 sizeof(mPcdDatabase
->PeiDb
.Init
.GuidTable
),
1035 mPcdDatabase
->PeiDb
.Init
.ExMapTable
,
1036 sizeof(mPcdDatabase
->PeiDb
.Init
.ExMapTable
)
1040 if (Status
== EFI_SUCCESS
) {
1044 if (!DxeExMapTableEmpty
) {
1045 Status
= ExGetNextTokeNumber (
1048 mPcdDatabase
->DxeDb
.Init
.GuidTable
,
1049 sizeof(mPcdDatabase
->DxeDb
.Init
.GuidTable
),
1050 mPcdDatabase
->DxeDb
.Init
.ExMapTable
,
1051 sizeof(mPcdDatabase
->DxeDb
.Init
.ExMapTable
)
1059 Get all token space guid table which is different with given token space guid.
1061 @param ExMapTableSize The size of guid table
1062 @param ExMapTable Token space guid table that want to be scaned.
1063 @param GuidTable Guid table
1065 @return all token space guid table which is different with given token space guid.
1069 GetDistinctTokenSpace (
1070 IN OUT UINTN
*ExMapTableSize
,
1071 IN DYNAMICEX_MAPPING
*ExMapTable
,
1072 IN EFI_GUID
*GuidTable
1075 EFI_GUID
**DistinctTokenSpace
;
1081 DistinctTokenSpace
= AllocateZeroPool (*ExMapTableSize
* sizeof (EFI_GUID
*));
1082 ASSERT (DistinctTokenSpace
!= NULL
);
1085 OldGuidIndex
= ExMapTable
[0].ExGuidIndex
;
1086 DistinctTokenSpace
[TsIdx
] = &GuidTable
[OldGuidIndex
];
1087 for (Idx
= 1; Idx
< *ExMapTableSize
; Idx
++) {
1088 if (ExMapTable
[Idx
].ExGuidIndex
!= OldGuidIndex
) {
1089 OldGuidIndex
= ExMapTable
[Idx
].ExGuidIndex
;
1090 DistinctTokenSpace
[++TsIdx
] = &GuidTable
[OldGuidIndex
];
1095 // The total number of Distinct Token Space
1096 // is TsIdx + 1 because we use TsIdx as a index
1097 // to the DistinctTokenSpace[]
1099 *ExMapTableSize
= TsIdx
+ 1;
1100 return DistinctTokenSpace
;
1105 Get next token space in PCD database according to given token space guid.
1107 @param Guid Given token space guid. If NULL, then Guid will be set to
1108 the first PCD token space in PCD database, If not NULL, then
1109 Guid will be set to next PCD token space.
1111 @retval EFI_UNSUPPORTED
1112 @retval EFI_NOT_FOUND If PCD database has no token space table or can not find given
1113 token space in PCD database.
1114 @retval EFI_SUCCESS Success to get next token space guid.
1118 DxePcdGetNextTokenSpace (
1119 IN OUT CONST EFI_GUID
**Guid
1125 UINTN PeiTokenSpaceTableSize
;
1126 UINTN DxeTokenSpaceTableSize
;
1127 EFI_GUID
**PeiTokenSpaceTable
;
1128 EFI_GUID
**DxeTokenSpaceTable
;
1130 BOOLEAN PeiExMapTableEmpty
;
1131 BOOLEAN DxeExMapTableEmpty
;
1133 ASSERT (Guid
!= NULL
);
1135 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
1136 DxeExMapTableEmpty
= DXE_EXMAP_TABLE_EMPTY
;
1138 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1139 if (*Guid
!= NULL
) {
1140 return EFI_NOT_FOUND
;
1147 if (TmpTokenSpaceBuffer
[0] == NULL
) {
1148 PeiTokenSpaceTableSize
= 0;
1150 if (!PeiExMapTableEmpty
) {
1151 PeiTokenSpaceTableSize
= PEI_EXMAPPING_TABLE_SIZE
;
1152 PeiTokenSpaceTable
= GetDistinctTokenSpace (&PeiTokenSpaceTableSize
,
1153 mPcdDatabase
->PeiDb
.Init
.ExMapTable
,
1154 mPcdDatabase
->PeiDb
.Init
.GuidTable
1156 CopyMem (TmpTokenSpaceBuffer
, PeiTokenSpaceTable
, sizeof (EFI_GUID
*) * PeiTokenSpaceTableSize
);
1159 if (!DxeExMapTableEmpty
) {
1160 DxeTokenSpaceTableSize
= DXE_EXMAPPING_TABLE_SIZE
;
1161 DxeTokenSpaceTable
= GetDistinctTokenSpace (&DxeTokenSpaceTableSize
,
1162 mPcdDatabase
->DxeDb
.Init
.ExMapTable
,
1163 mPcdDatabase
->DxeDb
.Init
.GuidTable
1167 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable
1169 for (Idx2
= 0, Idx3
= PeiTokenSpaceTableSize
; Idx2
< DxeTokenSpaceTableSize
; Idx2
++) {
1171 for (Idx
= 0; Idx
< PeiTokenSpaceTableSize
; Idx
++) {
1172 if (CompareGuid (TmpTokenSpaceBuffer
[Idx
], DxeTokenSpaceTable
[Idx2
])) {
1178 TmpTokenSpaceBuffer
[Idx3
++] = DxeTokenSpaceTable
[Idx2
];
1184 if (*Guid
== NULL
) {
1185 *Guid
= TmpTokenSpaceBuffer
[0];
1189 for (Idx
= 0; Idx
< (PEI_EXMAPPING_TABLE_SIZE
+ DXE_EXMAPPING_TABLE_SIZE
); Idx
++) {
1190 if(CompareGuid (*Guid
, TmpTokenSpaceBuffer
[Idx
])) {
1192 *Guid
= TmpTokenSpaceBuffer
[Idx
];
1197 return EFI_NOT_FOUND
;