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 - 2007, 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.
22 // Just pre-allocate a memory buffer that is big enough to
23 // host all distinct TokenSpace guid in both
24 // PEI ExMap and DXE ExMap.
26 EFI_GUID
*TmpTokenSpaceBuffer
[PEI_EXMAPPING_TABLE_SIZE
+ DXE_EXMAPPING_TABLE_SIZE
] = { 0 };
29 /// PCD database lock.
31 EFI_LOCK mPcdDatabaseLock
= EFI_INITIALIZE_LOCK_VARIABLE(TPL_CALLBACK
);
33 PCD_PROTOCOL mPcdInstance
= {
66 DxeRegisterCallBackOnSet
,
67 DxeUnRegisterCallBackOnSet
,
69 DxePcdGetNextTokenSpace
74 // Static global to reduce the code size
76 EFI_HANDLE mNewHandle
= NULL
;
79 Main entry for PCD DXE driver.
81 This routine initialize the PCD database and install PCD_PROTOCOL.
83 @param ImageHandle Image handle for PCD DXE driver.
84 @param SystemTable Pointer to SystemTable.
86 @return Status of gBS->InstallProtocolInterface()
92 IN EFI_HANDLE ImageHandle
,
93 IN EFI_SYSTEM_TABLE
*SystemTable
99 // Make sure the Pcd Protocol is not already installed in the system
102 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gPcdProtocolGuid
);
104 BuildPcdDxeDataBase ();
106 Status
= gBS
->InstallProtocolInterface (
109 EFI_NATIVE_INTERFACE
,
113 ASSERT_EFI_ERROR (Status
);
120 Sets the SKU value for subsequent calls to set or get PCD token values.
122 SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.
123 SetSku() is normally called only once by the system.
125 For each item (token), the database can hold a single value that applies to all SKUs,
126 or multiple values, where each value is associated with a specific SKU Id. Items with multiple,
127 SKU-specific values are called SKU enabled.
129 The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.
130 For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the
131 single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the
132 last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,
133 the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been
134 set for that Id, the results are unpredictable.
136 @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and
137 set values associated with a PCD token.
146 mPcdDatabase
->PeiDb
.Init
.SystemSkuId
= (SKU_ID
) SkuId
;
152 Retrieves an 8-bit value for a given PCD token.
154 Retrieves the current byte-sized value for a PCD token number.
155 If the TokenNumber is invalid, the results are unpredictable.
157 @param[in] TokenNumber The PCD token number.
159 @return The UINT8 value.
168 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
172 Retrieves an 16-bit value for a given PCD token.
174 Retrieves the current 16-bits 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 UINT16 value.
188 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
192 Retrieves an 32-bit value for a given PCD token.
194 Retrieves the current 32-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 UINT32 value.
208 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
212 Retrieves an 64-bit value for a given PCD token.
214 Retrieves the current 64-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 UINT64 value.
228 return ReadUnaligned64(GetWorker (TokenNumber
, sizeof (UINT64
)));
232 Retrieves a pointer to a value for a given PCD token.
234 Retrieves the current pointer to the buffer for a PCD token number.
235 Do not make any assumptions about the alignment of the pointer that
236 is returned by this function call. If the TokenNumber is invalid,
237 the results are unpredictable.
239 @param[in] TokenNumber The PCD token number.
241 @return The pointer to the buffer to be retrived.
250 return GetWorker (TokenNumber
, 0);
254 Retrieves a Boolean value for a given PCD token.
256 Retrieves the current boolean value for a PCD token number.
257 Do not make any assumptions about the alignment of the pointer that
258 is returned by this function call. If the TokenNumber is invalid,
259 the results are unpredictable.
261 @param[in] TokenNumber The PCD token number.
263 @return The Boolean value.
272 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
276 Retrieves the size of the value for a given PCD token.
278 Retrieves the current size of a particular PCD token.
279 If the TokenNumber is invalid, the results are unpredictable.
281 @param[in] TokenNumber The PCD token number.
283 @return The size of the value for the PCD token.
293 UINT32
*LocalTokenNumberTable
;
296 UINTN TmpTokenNumber
;
298 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
299 // We have to decrement TokenNumber by 1 to make it usable
300 // as the array index.
305 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
307 TmpTokenNumber
= TokenNumber
;
309 // EBC compiler is very choosy. It may report warning about comparison
310 // between UINTN and 0 . So we add 1 in each size of the
312 ASSERT (TokenNumber
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1);
314 // EBC compiler is very choosy. It may report warning about comparison
315 // between UINTN and 0 . So we add 1 in each size of the
317 IsPeiDb
= (BOOLEAN
) (TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
319 TokenNumber
= IsPeiDb
? TokenNumber
:
320 (TokenNumber
- PEI_LOCAL_TOKEN_NUMBER
);
322 LocalTokenNumberTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
323 : mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
325 Size
= (LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
329 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
331 return GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
339 Retrieves an 8-bit value for a given PCD token.
341 Retrieves the 8-bit value of a particular PCD token.
342 If the TokenNumber is invalid or the token space
343 specified by Guid does not exist, the results are
346 @param[in] Guid The token space for the token number.
347 @param[in] ExTokenNumber The PCD token number.
349 @return The size 8-bit value for the PCD token.
355 IN CONST EFI_GUID
*Guid
,
356 IN UINTN ExTokenNumber
359 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT8
)));
363 Retrieves an 16-bit value for a given PCD token.
365 Retrieves the 16-bit value of a particular PCD token.
366 If the TokenNumber is invalid or the token space
367 specified by Guid does not exist, the results are
370 @param[in] Guid The token space for the token number.
371 @param[in] ExTokenNumber The PCD token number.
373 @return The size 16-bit value for the PCD token.
379 IN CONST EFI_GUID
*Guid
,
380 IN UINTN ExTokenNumber
383 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT16
)));
387 Retrieves an 32-bit value for a given PCD token.
389 Retrieves the 32-bit value of a particular PCD token.
390 If the TokenNumber is invalid or the token space
391 specified by Guid does not exist, the results are
394 @param[in] Guid The token space for the token number.
395 @param[in] ExTokenNumber The PCD token number.
397 @return The size 32-bit value for the PCD token.
403 IN CONST EFI_GUID
*Guid
,
404 IN UINTN ExTokenNumber
407 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT32
)));
411 Retrieves an 64-bit value for a given PCD token.
413 Retrieves the 64-bit value of a particular PCD token.
414 If the TokenNumber is invalid or the token space
415 specified by Guid does not exist, the results are
418 @param[in] Guid The token space for the token number.
419 @param[in] ExTokenNumber The PCD token number.
421 @return The size 64-bit value for the PCD token.
427 IN CONST EFI_GUID
*Guid
,
428 IN UINTN ExTokenNumber
431 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT64
)));
435 Retrieves a pointer to a value for a given PCD token.
437 Retrieves the current pointer to the buffer for a PCD token number.
438 Do not make any assumptions about the alignment of the pointer that
439 is returned by this function call. If the TokenNumber is invalid,
440 the results are unpredictable.
442 @param[in] Guid The token space for the token number.
443 @param[in] ExTokenNumber The PCD token number.
445 @return The pointer to the buffer to be retrived.
451 IN CONST EFI_GUID
*Guid
,
452 IN UINTN ExTokenNumber
455 return ExGetWorker (Guid
, ExTokenNumber
, 0);
459 Retrieves an Boolean value for a given PCD token.
461 Retrieves the Boolean value of a particular PCD token.
462 If the TokenNumber is invalid or the token space
463 specified by Guid does not exist, the results are
466 @param[in] Guid The token space for the token number.
467 @param[in] ExTokenNumber The PCD token number.
469 @return The size Boolean value for the PCD token.
475 IN CONST EFI_GUID
*Guid
,
476 IN UINTN ExTokenNumber
479 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(BOOLEAN
)));
483 Retrieves the size of the value for a given PCD token.
485 Retrieves the current size of a particular PCD token.
486 If the TokenNumber is invalid, the results are unpredictable.
488 @param[in] Guid The token space for the token number.
489 @param[in] ExTokenNumber The PCD token number.
491 @return The size of the value for the PCD token.
497 IN CONST EFI_GUID
*Guid
,
498 IN UINTN ExTokenNumber
501 return DxePcdGetSize(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
));
505 Sets an 8-bit value for a given PCD token.
507 When the PCD service sets a value, it will check to ensure that the
508 size of the value being set is compatible with the Token's existing definition.
509 If it is not, an error will be returned.
511 @param[in] TokenNumber The PCD token number.
512 @param[in] Value The value to set for the PCD token.
514 @retval EFI_SUCCESS Procedure returned successfully.
515 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
516 being set was incompatible with a call to this function.
517 Use GetSize() to retrieve the size of the target data.
518 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
524 IN UINTN TokenNumber
,
528 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
532 Sets an 16-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 32-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 64-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 a value of a specified size 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, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
621 On input, if the SizeOfValue is greater than the maximum size supported
622 for this TokenNumber then the output value of SizeOfValue will reflect
623 the maximum size supported for this TokenNumber.
624 @param[in] Buffer The buffer to set for the PCD token.
626 @retval EFI_SUCCESS Procedure returned successfully.
627 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
628 being set was incompatible with a call to this function.
629 Use GetSize() to retrieve the size of the target data.
630 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
636 IN UINTN TokenNumber
,
637 IN OUT UINTN
*SizeOfBuffer
,
641 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
645 Sets an Boolean value for a given PCD token.
647 When the PCD service sets a value, it will check to ensure that the
648 size of the value being set is compatible with the Token's existing definition.
649 If it is not, an error will be returned.
651 @param[in] TokenNumber The PCD token number.
652 @param[in] Value The value to set for the PCD token.
654 @retval EFI_SUCCESS Procedure returned successfully.
655 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
656 being set was incompatible with a call to this function.
657 Use GetSize() to retrieve the size of the target data.
658 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
664 IN UINTN TokenNumber
,
668 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
672 Sets an 8-bit value for a given PCD token.
674 When the PCD service sets a value, it will check to ensure that the
675 size of the value being set is compatible with the Token's existing definition.
676 If it is not, an error will be returned.
678 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
679 @param[in] ExTokenNumber The PCD token number.
680 @param[in] Value The value to set for the PCD token.
682 @retval EFI_SUCCESS Procedure returned successfully.
683 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
684 being set was incompatible with a call to this function.
685 Use GetSize() to retrieve the size of the target data.
686 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
692 IN CONST EFI_GUID
*Guid
,
693 IN UINTN ExTokenNumber
,
697 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
701 Sets an 16-bit value for a given PCD token.
703 When the PCD service sets a value, it will check to ensure that the
704 size of the value being set is compatible with the Token's existing definition.
705 If it is not, an error will be returned.
707 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
708 @param[in] ExTokenNumber The PCD token number.
709 @param[in] Value The value to set for the PCD token.
711 @retval EFI_SUCCESS Procedure returned successfully.
712 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
713 being set was incompatible with a call to this function.
714 Use GetSize() to retrieve the size of the target data.
715 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
721 IN CONST EFI_GUID
*Guid
,
722 IN UINTN ExTokenNumber
,
726 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
730 Sets an 32-bit value for a given PCD token.
732 When the PCD service sets a value, it will check to ensure that the
733 size of the value being set is compatible with the Token's existing definition.
734 If it is not, an error will be returned.
736 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
737 @param[in] ExTokenNumber The PCD token number.
738 @param[in] Value The value to set for the PCD token.
740 @retval EFI_SUCCESS Procedure returned successfully.
741 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
742 being set was incompatible with a call to this function.
743 Use GetSize() to retrieve the size of the target data.
744 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
750 IN CONST EFI_GUID
*Guid
,
751 IN UINTN ExTokenNumber
,
755 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
759 Sets an 64-bit value for a given PCD token.
761 When the PCD service sets a value, it will check to ensure that the
762 size of the value being set is compatible with the Token's existing definition.
763 If it is not, an error will be returned.
765 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
766 @param[in] ExTokenNumber The PCD token number.
767 @param[in] Value The value to set for the PCD token.
769 @retval EFI_SUCCESS Procedure returned successfully.
770 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
771 being set was incompatible with a call to this function.
772 Use GetSize() to retrieve the size of the target data.
773 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
779 IN CONST EFI_GUID
*Guid
,
780 IN UINTN ExTokenNumber
,
784 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
788 Sets a value of a specified size for a given PCD token.
790 When the PCD service sets a value, it will check to ensure that the
791 size of the value being set is compatible with the Token's existing definition.
792 If it is not, an error will be returned.
794 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
795 @param[in] ExTokenNumber The PCD token number.
796 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
797 On input, if the SizeOfValue is greater than the maximum size supported
798 for this TokenNumber then the output value of SizeOfValue will reflect
799 the maximum size supported for this TokenNumber.
800 @param[in] Buffer The buffer to set for the PCD token.
802 @retval EFI_SUCCESS Procedure returned successfully.
803 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
804 being set was incompatible with a call to this function.
805 Use GetSize() to retrieve the size of the target data.
806 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
812 IN CONST EFI_GUID
*Guid
,
813 IN UINTN ExTokenNumber
,
814 IN OUT UINTN
*SizeOfBuffer
,
818 return ExSetWorker(ExTokenNumber
, Guid
, Buffer
, SizeOfBuffer
, TRUE
);
822 Sets an Boolean value for a given PCD token.
824 When the PCD service sets a value, it will check to ensure that the
825 size of the value being set is compatible with the Token's existing definition.
826 If it is not, an error will be returned.
828 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
829 @param[in] ExTokenNumber The PCD token number.
830 @param[in] Value The value 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
,
847 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
851 Specifies a function to be called anytime the value of a designated token is changed.
853 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
854 @param[in] TokenNumber The PCD token number.
855 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
857 @retval EFI_SUCCESS The PCD service has successfully established a call event
858 for the CallBackToken requested.
859 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
864 DxeRegisterCallBackOnSet (
865 IN CONST EFI_GUID
*Guid
, OPTIONAL
866 IN UINTN TokenNumber
,
867 IN PCD_PROTOCOL_CALLBACK CallBackFunction
872 if (CallBackFunction
== NULL
) {
873 return EFI_INVALID_PARAMETER
;
876 // Aquire lock to prevent reentrance from TPL_CALLBACK level
878 EfiAcquireLock (&mPcdDatabaseLock
);
880 Status
= DxeRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
882 EfiReleaseLock (&mPcdDatabaseLock
);
888 Cancels a previously set callback function for a particular PCD token number.
890 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
891 @param[in] TokenNumber The PCD token number.
892 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
894 @retval EFI_SUCCESS The PCD service has successfully established a call event
895 for the CallBackToken requested.
896 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
901 DxeUnRegisterCallBackOnSet (
902 IN CONST EFI_GUID
*Guid
, OPTIONAL
903 IN UINTN TokenNumber
,
904 IN PCD_PROTOCOL_CALLBACK CallBackFunction
909 if (CallBackFunction
== NULL
) {
910 return EFI_INVALID_PARAMETER
;
914 // Aquire lock to prevent reentrance from TPL_CALLBACK level
916 EfiAcquireLock (&mPcdDatabaseLock
);
918 Status
= DxeUnRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
920 EfiReleaseLock (&mPcdDatabaseLock
);
926 Retrieves the next valid PCD token for a given namespace.
928 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
929 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.
930 If the input token namespace or token number does not exist on the platform,
931 an error is returned and the value of *TokenNumber is undefined. To retrieve the "first" token,
932 have the pointer reference a TokenNumber value of 0. If the input token number is 0 and
933 there is no valid token number for this token namespace, *TokenNumber will be assigned to
934 0 and the function return EFI_SUCCESS. If the token number is the last valid token number,
935 *TokenNumber will be assigned to 0 and the function return EFI_SUCCESS.
937 @retval EFI_SUCCESS The PCD service retrieved the next valid token number. Or the input token number
938 is already the last valid token number in the PCD database.
939 In the later case, *TokenNumber is updated with the value of 0.
940 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
946 IN CONST EFI_GUID
*Guid
, OPTIONAL
947 IN OUT UINTN
*TokenNumber
951 BOOLEAN PeiExMapTableEmpty
;
952 BOOLEAN DxeExMapTableEmpty
;
954 if (!FeaturePcdGet (PcdDxePcdDatabaseTraverseEnabled
)) {
955 return EFI_UNSUPPORTED
;
958 Status
= EFI_NOT_FOUND
;
959 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
960 DxeExMapTableEmpty
= DXE_EXMAP_TABLE_EMPTY
;
963 // Scan the local token space
966 // EBC compiler is very choosy. It may report warning about comparison
967 // between UINTN and 0 . So we add 1 in each size of the
969 if (((*TokenNumber
+ 1 > PEI_NEX_TOKEN_NUMBER
+ 1) && (*TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1)) ||
970 ((*TokenNumber
+ 1 > (PEI_LOCAL_TOKEN_NUMBER
+ DXE_NEX_TOKEN_NUMBER
+ 1)))) {
971 return EFI_NOT_FOUND
;
975 if ((*TokenNumber
+ 1 > PEI_NEX_TOKEN_NUMBER
+ 1) &&
976 (*TokenNumber
<= PEI_LOCAL_TOKEN_NUMBER
)) {
978 // The first Non-Ex type Token Number for DXE PCD
979 // database is PEI_LOCAL_TOKEN_NUMBER
981 *TokenNumber
= PEI_LOCAL_TOKEN_NUMBER
;
982 } else if (*TokenNumber
+ 1 > DXE_NEX_TOKEN_NUMBER
+ PEI_LOCAL_TOKEN_NUMBER
+ 1) {
983 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
988 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
989 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
990 return EFI_NOT_FOUND
;
993 if (!PeiExMapTableEmpty
) {
994 Status
= ExGetNextTokeNumber (
997 mPcdDatabase
->PeiDb
.Init
.GuidTable
,
998 sizeof(mPcdDatabase
->PeiDb
.Init
.GuidTable
),
999 mPcdDatabase
->PeiDb
.Init
.ExMapTable
,
1000 sizeof(mPcdDatabase
->PeiDb
.Init
.ExMapTable
)
1004 if (Status
== EFI_SUCCESS
) {
1008 if (!DxeExMapTableEmpty
) {
1009 Status
= ExGetNextTokeNumber (
1012 mPcdDatabase
->DxeDb
.Init
.GuidTable
,
1013 sizeof(mPcdDatabase
->DxeDb
.Init
.GuidTable
),
1014 mPcdDatabase
->DxeDb
.Init
.ExMapTable
,
1015 sizeof(mPcdDatabase
->DxeDb
.Init
.ExMapTable
)
1023 Get all token space guid table which is different with given token space guid.
1025 @param ExMapTableSize The size of guid table
1026 @param ExMapTable Token space guid table that want to be scaned.
1027 @param GuidTable Guid table
1029 @return all token space guid table which is different with given token space guid.
1033 GetDistinctTokenSpace (
1034 IN OUT UINTN
*ExMapTableSize
,
1035 IN DYNAMICEX_MAPPING
*ExMapTable
,
1036 IN EFI_GUID
*GuidTable
1039 EFI_GUID
**DistinctTokenSpace
;
1045 DistinctTokenSpace
= AllocateZeroPool (*ExMapTableSize
* sizeof (EFI_GUID
*));
1046 ASSERT (DistinctTokenSpace
!= NULL
);
1049 OldGuidIndex
= ExMapTable
[0].ExGuidIndex
;
1050 DistinctTokenSpace
[TsIdx
] = &GuidTable
[OldGuidIndex
];
1051 for (Idx
= 1; Idx
< *ExMapTableSize
; Idx
++) {
1052 if (ExMapTable
[Idx
].ExGuidIndex
!= OldGuidIndex
) {
1053 OldGuidIndex
= ExMapTable
[Idx
].ExGuidIndex
;
1054 DistinctTokenSpace
[++TsIdx
] = &GuidTable
[OldGuidIndex
];
1059 // The total number of Distinct Token Space
1060 // is TsIdx + 1 because we use TsIdx as a index
1061 // to the DistinctTokenSpace[]
1063 *ExMapTableSize
= TsIdx
+ 1;
1064 return DistinctTokenSpace
;
1069 Get next token space in PCD database according to given token space guid.
1071 This routine is enable only when feature flag PCD PcdDxePcdDatabaseTraverseEnabled
1074 @param Guid Given token space guid. If NULL, then Guid will be set to
1075 the first PCD token space in PCD database, If not NULL, then
1076 Guid will be set to next PCD token space.
1078 @retval EFI_UNSUPPORTED If feature flag PCD PcdDxePcdDatabaseTraverseEnabled is FALSE.
1079 @retval EFI_NOT_FOUND If PCD database has no token space table or can not find given
1080 token space in PCD database.
1081 @retval EFI_SUCCESS Success to get next token space guid.
1085 DxePcdGetNextTokenSpace (
1086 IN OUT CONST EFI_GUID
**Guid
1092 UINTN PeiTokenSpaceTableSize
;
1093 UINTN DxeTokenSpaceTableSize
;
1094 EFI_GUID
**PeiTokenSpaceTable
;
1095 EFI_GUID
**DxeTokenSpaceTable
;
1097 BOOLEAN PeiExMapTableEmpty
;
1098 BOOLEAN DxeExMapTableEmpty
;
1100 if (!FeaturePcdGet (PcdDxePcdDatabaseTraverseEnabled
)) {
1101 return EFI_UNSUPPORTED
;
1104 ASSERT (Guid
!= NULL
);
1106 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
1107 DxeExMapTableEmpty
= DXE_EXMAP_TABLE_EMPTY
;
1109 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1110 if (*Guid
!= NULL
) {
1111 return EFI_NOT_FOUND
;
1118 if (TmpTokenSpaceBuffer
[0] == NULL
) {
1119 PeiTokenSpaceTableSize
= 0;
1121 if (!PeiExMapTableEmpty
) {
1122 PeiTokenSpaceTableSize
= PEI_EXMAPPING_TABLE_SIZE
;
1123 PeiTokenSpaceTable
= GetDistinctTokenSpace (&PeiTokenSpaceTableSize
,
1124 mPcdDatabase
->PeiDb
.Init
.ExMapTable
,
1125 mPcdDatabase
->PeiDb
.Init
.GuidTable
1127 CopyMem (TmpTokenSpaceBuffer
, PeiTokenSpaceTable
, sizeof (EFI_GUID
*) * PeiTokenSpaceTableSize
);
1130 if (!DxeExMapTableEmpty
) {
1131 DxeTokenSpaceTableSize
= DXE_EXMAPPING_TABLE_SIZE
;
1132 DxeTokenSpaceTable
= GetDistinctTokenSpace (&DxeTokenSpaceTableSize
,
1133 mPcdDatabase
->DxeDb
.Init
.ExMapTable
,
1134 mPcdDatabase
->DxeDb
.Init
.GuidTable
1138 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable
1140 for (Idx2
= 0, Idx3
= PeiTokenSpaceTableSize
; Idx2
< DxeTokenSpaceTableSize
; Idx2
++) {
1142 for (Idx
= 0; Idx
< PeiTokenSpaceTableSize
; Idx
++) {
1143 if (CompareGuid (TmpTokenSpaceBuffer
[Idx
], DxeTokenSpaceTable
[Idx2
])) {
1149 TmpTokenSpaceBuffer
[Idx3
++] = DxeTokenSpaceTable
[Idx2
];
1155 if (*Guid
== NULL
) {
1156 *Guid
= TmpTokenSpaceBuffer
[0];
1160 for (Idx
= 0; Idx
< (PEI_EXMAPPING_TABLE_SIZE
+ DXE_EXMAPPING_TABLE_SIZE
); Idx
++) {
1161 if(CompareGuid (*Guid
, TmpTokenSpaceBuffer
[Idx
])) {
1163 *Guid
= TmpTokenSpaceBuffer
[Idx
];
1168 return EFI_NOT_FOUND
;