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.
148 mPcdDatabase
->PeiDb
.Init
.SystemSkuId
= (SKU_ID
) SkuId
;
154 Retrieves an 8-bit value for a given PCD token.
156 Retrieves the current byte-sized value for a PCD token number.
157 If the TokenNumber is invalid, the results are unpredictable.
159 @param[in] TokenNumber The PCD token number.
161 @return The UINT8 value.
170 return *((UINT8
*) GetWorker (TokenNumber
, sizeof (UINT8
)));
174 Retrieves an 16-bit value for a given PCD token.
176 Retrieves the current 16-bits value for a PCD token number.
177 If the TokenNumber is invalid, the results are unpredictable.
179 @param[in] TokenNumber The PCD token number.
181 @return The UINT16 value.
190 return ReadUnaligned16 (GetWorker (TokenNumber
, sizeof (UINT16
)));
194 Retrieves an 32-bit value for a given PCD token.
196 Retrieves the current 32-bits value for a PCD token number.
197 If the TokenNumber is invalid, the results are unpredictable.
199 @param[in] TokenNumber The PCD token number.
201 @return The UINT32 value.
210 return ReadUnaligned32 (GetWorker (TokenNumber
, sizeof (UINT32
)));
214 Retrieves an 64-bit value for a given PCD token.
216 Retrieves the current 64-bits value for a PCD token number.
217 If the TokenNumber is invalid, the results are unpredictable.
219 @param[in] TokenNumber The PCD token number.
221 @return The UINT64 value.
230 return ReadUnaligned64(GetWorker (TokenNumber
, sizeof (UINT64
)));
234 Retrieves a pointer to a value for a given PCD token.
236 Retrieves the current pointer to the buffer for a PCD token number.
237 Do not make any assumptions about the alignment of the pointer that
238 is returned by this function call. If the TokenNumber is invalid,
239 the results are unpredictable.
241 @param[in] TokenNumber The PCD token number.
243 @return The pointer to the buffer to be retrived.
252 return GetWorker (TokenNumber
, 0);
256 Retrieves a Boolean value for a given PCD token.
258 Retrieves the current boolean value for a PCD token number.
259 Do not make any assumptions about the alignment of the pointer that
260 is returned by this function call. If the TokenNumber is invalid,
261 the results are unpredictable.
263 @param[in] TokenNumber The PCD token number.
265 @return The Boolean value.
274 return *((BOOLEAN
*) GetWorker (TokenNumber
, sizeof (BOOLEAN
)));
278 Retrieves the size of the value for a given PCD token.
280 Retrieves the current size of a particular PCD token.
281 If the TokenNumber is invalid, the results are unpredictable.
283 @param[in] TokenNumber The PCD token number.
285 @return The size of the value for the PCD token.
295 UINT32
*LocalTokenNumberTable
;
298 UINTN TmpTokenNumber
;
300 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
301 // We have to decrement TokenNumber by 1 to make it usable
302 // as the array index.
307 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
309 TmpTokenNumber
= TokenNumber
;
311 // EBC compiler is very choosy. It may report warning about comparison
312 // between UINTN and 0 . So we add 1 in each size of the
314 ASSERT (TokenNumber
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1);
316 // EBC compiler is very choosy. It may report warning about comparison
317 // between UINTN and 0 . So we add 1 in each size of the
319 IsPeiDb
= (BOOLEAN
) (TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
321 TokenNumber
= IsPeiDb
? TokenNumber
:
322 (TokenNumber
- PEI_LOCAL_TOKEN_NUMBER
);
324 LocalTokenNumberTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
325 : mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
327 Size
= (LocalTokenNumberTable
[TokenNumber
] & PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
331 // For pointer type, we need to scan the SIZE_TABLE to get the current size.
333 return GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
341 Retrieves an 8-bit value for a given PCD token.
343 Retrieves the 8-bit value of a particular PCD token.
344 If the TokenNumber is invalid or the token space
345 specified by Guid does not exist, the results are
348 @param[in] Guid The token space for the token number.
349 @param[in] ExTokenNumber The PCD token number.
351 @return The size 8-bit value for the PCD token.
357 IN CONST EFI_GUID
*Guid
,
358 IN UINTN ExTokenNumber
361 return *((UINT8
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT8
)));
365 Retrieves an 16-bit value for a given PCD token.
367 Retrieves the 16-bit value of a particular PCD token.
368 If the TokenNumber is invalid or the token space
369 specified by Guid does not exist, the results are
372 @param[in] Guid The token space for the token number.
373 @param[in] ExTokenNumber The PCD token number.
375 @return The size 16-bit value for the PCD token.
381 IN CONST EFI_GUID
*Guid
,
382 IN UINTN ExTokenNumber
385 return ReadUnaligned16 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT16
)));
389 Retrieves an 32-bit value for a given PCD token.
391 Retrieves the 32-bit value of a particular PCD token.
392 If the TokenNumber is invalid or the token space
393 specified by Guid does not exist, the results are
396 @param[in] Guid The token space for the token number.
397 @param[in] ExTokenNumber The PCD token number.
399 @return The size 32-bit value for the PCD token.
405 IN CONST EFI_GUID
*Guid
,
406 IN UINTN ExTokenNumber
409 return ReadUnaligned32 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT32
)));
413 Retrieves an 64-bit value for a given PCD token.
415 Retrieves the 64-bit value of a particular PCD token.
416 If the TokenNumber is invalid or the token space
417 specified by Guid does not exist, the results are
420 @param[in] Guid The token space for the token number.
421 @param[in] ExTokenNumber The PCD token number.
423 @return The size 64-bit value for the PCD token.
429 IN CONST EFI_GUID
*Guid
,
430 IN UINTN ExTokenNumber
433 return ReadUnaligned64 (ExGetWorker (Guid
, ExTokenNumber
, sizeof(UINT64
)));
437 Retrieves a pointer to a value for a given PCD token.
439 Retrieves the current pointer to the buffer for a PCD token number.
440 Do not make any assumptions about the alignment of the pointer that
441 is returned by this function call. If the TokenNumber is invalid,
442 the results are unpredictable.
444 @param[in] Guid The token space for the token number.
445 @param[in] ExTokenNumber The PCD token number.
447 @return The pointer to the buffer to be retrived.
453 IN CONST EFI_GUID
*Guid
,
454 IN UINTN ExTokenNumber
457 return ExGetWorker (Guid
, ExTokenNumber
, 0);
461 Retrieves an Boolean value for a given PCD token.
463 Retrieves the Boolean value of a particular PCD token.
464 If the TokenNumber is invalid or the token space
465 specified by Guid does not exist, the results are
468 @param[in] Guid The token space for the token number.
469 @param[in] ExTokenNumber The PCD token number.
471 @return The size Boolean value for the PCD token.
477 IN CONST EFI_GUID
*Guid
,
478 IN UINTN ExTokenNumber
481 return *((BOOLEAN
*) ExGetWorker (Guid
, ExTokenNumber
, sizeof(BOOLEAN
)));
485 Retrieves the size of the value for a given PCD token.
487 Retrieves the current size of a particular PCD token.
488 If the TokenNumber is invalid, the results are unpredictable.
490 @param[in] Guid The token space for the token number.
491 @param[in] ExTokenNumber The PCD token number.
493 @return The size of the value for the PCD token.
499 IN CONST EFI_GUID
*Guid
,
500 IN UINTN ExTokenNumber
503 return DxePcdGetSize(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
));
507 Sets an 8-bit value for a given PCD token.
509 When the PCD service sets a value, it will check to ensure that the
510 size of the value being set is compatible with the Token's existing definition.
511 If it is not, an error will be returned.
513 @param[in] TokenNumber The PCD token number.
514 @param[in] Value The value to set for the PCD token.
516 @retval EFI_SUCCESS Procedure returned successfully.
517 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
518 being set was incompatible with a call to this function.
519 Use GetSize() to retrieve the size of the target data.
520 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
526 IN UINTN TokenNumber
,
530 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
534 Sets an 16-bit value for a given PCD token.
536 When the PCD service sets a value, it will check to ensure that the
537 size of the value being set is compatible with the Token's existing definition.
538 If it is not, an error will be returned.
540 @param[in] TokenNumber The PCD token number.
541 @param[in] Value The value to set for the PCD token.
543 @retval EFI_SUCCESS Procedure returned successfully.
544 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
545 being set was incompatible with a call to this function.
546 Use GetSize() to retrieve the size of the target data.
547 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
553 IN UINTN TokenNumber
,
557 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
561 Sets an 32-bit value for a given PCD token.
563 When the PCD service sets a value, it will check to ensure that the
564 size of the value being set is compatible with the Token's existing definition.
565 If it is not, an error will be returned.
567 @param[in] TokenNumber The PCD token number.
568 @param[in] Value The value to set for the PCD token.
570 @retval EFI_SUCCESS Procedure returned successfully.
571 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
572 being set was incompatible with a call to this function.
573 Use GetSize() to retrieve the size of the target data.
574 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
580 IN UINTN TokenNumber
,
584 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
588 Sets an 64-bit value for a given PCD token.
590 When the PCD service sets a value, it will check to ensure that the
591 size of the value being set is compatible with the Token's existing definition.
592 If it is not, an error will be returned.
594 @param[in] TokenNumber The PCD token number.
595 @param[in] Value The value to set for the PCD token.
597 @retval EFI_SUCCESS Procedure returned successfully.
598 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
599 being set was incompatible with a call to this function.
600 Use GetSize() to retrieve the size of the target data.
601 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
607 IN UINTN TokenNumber
,
611 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
615 Sets a value of a specified size for a given PCD token.
617 When the PCD service sets a value, it will check to ensure that the
618 size of the value being set is compatible with the Token's existing definition.
619 If it is not, an error will be returned.
621 @param[in] TokenNumber The PCD token number.
622 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
623 On input, if the SizeOfValue is greater than the maximum size supported
624 for this TokenNumber then the output value of SizeOfValue will reflect
625 the maximum size supported for this TokenNumber.
626 @param[in] Buffer The buffer to set for the PCD token.
628 @retval EFI_SUCCESS Procedure returned successfully.
629 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
630 being set was incompatible with a call to this function.
631 Use GetSize() to retrieve the size of the target data.
632 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
638 IN UINTN TokenNumber
,
639 IN OUT UINTN
*SizeOfBuffer
,
643 return SetWorker (TokenNumber
, Buffer
, SizeOfBuffer
, TRUE
);
647 Sets an Boolean value for a given PCD token.
649 When the PCD service sets a value, it will check to ensure that the
650 size of the value being set is compatible with the Token's existing definition.
651 If it is not, an error will be returned.
653 @param[in] TokenNumber The PCD token number.
654 @param[in] Value The value 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
,
670 return SetValueWorker (TokenNumber
, &Value
, sizeof (Value
));
674 Sets an 8-bit value for a given PCD token.
676 When the PCD service sets a value, it will check to ensure that the
677 size of the value being set is compatible with the Token's existing definition.
678 If it is not, an error will be returned.
680 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
681 @param[in] ExTokenNumber 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 CONST EFI_GUID
*Guid
,
695 IN UINTN ExTokenNumber
,
699 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
703 Sets an 16-bit value for a given PCD token.
705 When the PCD service sets a value, it will check to ensure that the
706 size of the value being set is compatible with the Token's existing definition.
707 If it is not, an error will be returned.
709 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
710 @param[in] ExTokenNumber The PCD token number.
711 @param[in] Value The value to set for the PCD token.
713 @retval EFI_SUCCESS Procedure returned successfully.
714 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
715 being set was incompatible with a call to this function.
716 Use GetSize() to retrieve the size of the target data.
717 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
723 IN CONST EFI_GUID
*Guid
,
724 IN UINTN ExTokenNumber
,
728 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
732 Sets an 32-bit value for a given PCD token.
734 When the PCD service sets a value, it will check to ensure that the
735 size of the value being set is compatible with the Token's existing definition.
736 If it is not, an error will be returned.
738 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
739 @param[in] ExTokenNumber The PCD token number.
740 @param[in] Value The value to set for the PCD token.
742 @retval EFI_SUCCESS Procedure returned successfully.
743 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
744 being set was incompatible with a call to this function.
745 Use GetSize() to retrieve the size of the target data.
746 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
752 IN CONST EFI_GUID
*Guid
,
753 IN UINTN ExTokenNumber
,
757 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
761 Sets an 64-bit value for a given PCD token.
763 When the PCD service sets a value, it will check to ensure that the
764 size of the value being set is compatible with the Token's existing definition.
765 If it is not, an error will be returned.
767 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
768 @param[in] ExTokenNumber The PCD token number.
769 @param[in] Value The value to set for the PCD token.
771 @retval EFI_SUCCESS Procedure returned successfully.
772 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
773 being set was incompatible with a call to this function.
774 Use GetSize() to retrieve the size of the target data.
775 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
781 IN CONST EFI_GUID
*Guid
,
782 IN UINTN ExTokenNumber
,
786 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
790 Sets a value of a specified size for a given PCD token.
792 When the PCD service sets a value, it will check to ensure that the
793 size of the value being set is compatible with the Token's existing definition.
794 If it is not, an error will be returned.
796 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
797 @param[in] ExTokenNumber The PCD token number.
798 @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.
799 On input, if the SizeOfValue is greater than the maximum size supported
800 for this TokenNumber then the output value of SizeOfValue will reflect
801 the maximum size supported for this TokenNumber.
802 @param[in] Buffer The buffer to set for the PCD token.
804 @retval EFI_SUCCESS Procedure returned successfully.
805 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
806 being set was incompatible with a call to this function.
807 Use GetSize() to retrieve the size of the target data.
808 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
814 IN CONST EFI_GUID
*Guid
,
815 IN UINTN ExTokenNumber
,
816 IN OUT UINTN
*SizeOfBuffer
,
820 return ExSetWorker(ExTokenNumber
, Guid
, Buffer
, SizeOfBuffer
, TRUE
);
824 Sets an Boolean value for a given PCD token.
826 When the PCD service sets a value, it will check to ensure that the
827 size of the value being set is compatible with the Token's existing definition.
828 If it is not, an error will be returned.
830 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
831 @param[in] ExTokenNumber The PCD token number.
832 @param[in] Value The value to set for the PCD token.
834 @retval EFI_SUCCESS Procedure returned successfully.
835 @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data
836 being set was incompatible with a call to this function.
837 Use GetSize() to retrieve the size of the target data.
838 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
844 IN CONST EFI_GUID
*Guid
,
845 IN UINTN ExTokenNumber
,
849 return ExSetValueWorker (ExTokenNumber
, Guid
, &Value
, sizeof (Value
));
853 Specifies a function to be called anytime the value of a designated token is changed.
855 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
856 @param[in] TokenNumber The PCD token number.
857 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
859 @retval EFI_SUCCESS The PCD service has successfully established a call event
860 for the CallBackToken requested.
861 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
866 DxeRegisterCallBackOnSet (
867 IN CONST EFI_GUID
*Guid
, OPTIONAL
868 IN UINTN TokenNumber
,
869 IN PCD_PROTOCOL_CALLBACK CallBackFunction
874 ASSERT (CallBackFunction
!= NULL
);
877 // Aquire lock to prevent reentrance from TPL_CALLBACK level
879 EfiAcquireLock (&mPcdDatabaseLock
);
881 Status
= DxeRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
883 EfiReleaseLock (&mPcdDatabaseLock
);
889 Cancels a previously set callback function for a particular PCD token number.
891 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
892 @param[in] TokenNumber The PCD token number.
893 @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.
895 @retval EFI_SUCCESS The PCD service has successfully established a call event
896 for the CallBackToken requested.
897 @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.
902 DxeUnRegisterCallBackOnSet (
903 IN CONST EFI_GUID
*Guid
, OPTIONAL
904 IN UINTN TokenNumber
,
905 IN PCD_PROTOCOL_CALLBACK CallBackFunction
910 ASSERT (CallBackFunction
!= NULL
);
913 // Aquire lock to prevent reentrance from TPL_CALLBACK level
915 EfiAcquireLock (&mPcdDatabaseLock
);
917 Status
= DxeUnRegisterCallBackWorker (TokenNumber
, Guid
, CallBackFunction
);
919 EfiReleaseLock (&mPcdDatabaseLock
);
925 Retrieves the next valid PCD token for a given namespace.
927 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
928 @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.
929 If the input token namespace or token number does not exist on the platform,
930 an error is returned and the value of *TokenNumber is undefined. To retrieve the "first" token,
931 have the pointer reference a TokenNumber value of 0. If the input token number is 0 and
932 there is no valid token number for this token namespace, *TokenNumber will be assigned to
933 0 and the function return EFI_SUCCESS. If the token number is the last valid token number,
934 *TokenNumber will be assigned to 0 and the function return EFI_SUCCESS.
936 @retval EFI_SUCCESS The PCD service retrieved the next valid token number. Or the input token number
937 is already the last valid token number in the PCD database.
938 In the later case, *TokenNumber is updated with the value of 0.
939 @retval EFI_NOT_FOUND If this input token number and token namespace does not exist on the platform.
945 IN CONST EFI_GUID
*Guid
, OPTIONAL
946 IN OUT UINTN
*TokenNumber
950 BOOLEAN PeiExMapTableEmpty
;
951 BOOLEAN DxeExMapTableEmpty
;
953 if (!FeaturePcdGet (PcdDxePcdDatabaseTraverseEnabled
)) {
954 return EFI_UNSUPPORTED
;
957 Status
= EFI_NOT_FOUND
;
958 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
959 DxeExMapTableEmpty
= DXE_EXMAP_TABLE_EMPTY
;
962 // Scan the local token space
965 // EBC compiler is very choosy. It may report warning about comparison
966 // between UINTN and 0 . So we add 1 in each size of the
968 if (((*TokenNumber
+ 1 > PEI_NEX_TOKEN_NUMBER
+ 1) && (*TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1)) ||
969 ((*TokenNumber
+ 1 > (PEI_LOCAL_TOKEN_NUMBER
+ DXE_NEX_TOKEN_NUMBER
+ 1)))) {
970 return EFI_NOT_FOUND
;
974 if ((*TokenNumber
+ 1 > PEI_NEX_TOKEN_NUMBER
+ 1) &&
975 (*TokenNumber
<= PEI_LOCAL_TOKEN_NUMBER
)) {
977 // The first Non-Ex type Token Number for DXE PCD
978 // database is PEI_LOCAL_TOKEN_NUMBER
980 *TokenNumber
= PEI_LOCAL_TOKEN_NUMBER
;
981 } else if (*TokenNumber
+ 1 > DXE_NEX_TOKEN_NUMBER
+ PEI_LOCAL_TOKEN_NUMBER
+ 1) {
982 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
987 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
988 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
989 return EFI_NOT_FOUND
;
992 if (!PeiExMapTableEmpty
) {
993 Status
= ExGetNextTokeNumber (
996 mPcdDatabase
->PeiDb
.Init
.GuidTable
,
997 sizeof(mPcdDatabase
->PeiDb
.Init
.GuidTable
),
998 mPcdDatabase
->PeiDb
.Init
.ExMapTable
,
999 sizeof(mPcdDatabase
->PeiDb
.Init
.ExMapTable
)
1003 if (Status
== EFI_SUCCESS
) {
1007 if (!DxeExMapTableEmpty
) {
1008 Status
= ExGetNextTokeNumber (
1011 mPcdDatabase
->DxeDb
.Init
.GuidTable
,
1012 sizeof(mPcdDatabase
->DxeDb
.Init
.GuidTable
),
1013 mPcdDatabase
->DxeDb
.Init
.ExMapTable
,
1014 sizeof(mPcdDatabase
->DxeDb
.Init
.ExMapTable
)
1022 Get all token space guid table which is different with given token space guid.
1024 @param ExMapTableSize The size of guid table
1025 @param ExMapTable Token space guid table that want to be scaned.
1026 @param GuidTable Guid table
1028 @return all token space guid table which is different with given token space guid.
1032 GetDistinctTokenSpace (
1033 IN OUT UINTN
*ExMapTableSize
,
1034 IN DYNAMICEX_MAPPING
*ExMapTable
,
1035 IN EFI_GUID
*GuidTable
1038 EFI_GUID
**DistinctTokenSpace
;
1044 DistinctTokenSpace
= AllocateZeroPool (*ExMapTableSize
* sizeof (EFI_GUID
*));
1045 ASSERT (DistinctTokenSpace
!= NULL
);
1048 OldGuidIndex
= ExMapTable
[0].ExGuidIndex
;
1049 DistinctTokenSpace
[TsIdx
] = &GuidTable
[OldGuidIndex
];
1050 for (Idx
= 1; Idx
< *ExMapTableSize
; Idx
++) {
1051 if (ExMapTable
[Idx
].ExGuidIndex
!= OldGuidIndex
) {
1052 OldGuidIndex
= ExMapTable
[Idx
].ExGuidIndex
;
1053 DistinctTokenSpace
[++TsIdx
] = &GuidTable
[OldGuidIndex
];
1058 // The total number of Distinct Token Space
1059 // is TsIdx + 1 because we use TsIdx as a index
1060 // to the DistinctTokenSpace[]
1062 *ExMapTableSize
= TsIdx
+ 1;
1063 return DistinctTokenSpace
;
1068 Get next token space in PCD database according to given token space guid.
1070 This routine is enable only when feature flag PCD PcdDxePcdDatabaseTraverseEnabled
1073 @param Guid Given token space guid. If NULL, then Guid will be set to
1074 the first PCD token space in PCD database, If not NULL, then
1075 Guid will be set to next PCD token space.
1077 @retval EFI_UNSUPPORTED If feature flag PCD PcdDxePcdDatabaseTraverseEnabled is FALSE.
1078 @retval EFI_NOT_FOUND If PCD database has no token space table or can not find given
1079 token space in PCD database.
1080 @retval EFI_SUCCESS Success to get next token space guid.
1084 DxePcdGetNextTokenSpace (
1085 IN OUT CONST EFI_GUID
**Guid
1091 UINTN PeiTokenSpaceTableSize
;
1092 UINTN DxeTokenSpaceTableSize
;
1093 EFI_GUID
**PeiTokenSpaceTable
;
1094 EFI_GUID
**DxeTokenSpaceTable
;
1096 BOOLEAN PeiExMapTableEmpty
;
1097 BOOLEAN DxeExMapTableEmpty
;
1099 if (!FeaturePcdGet (PcdDxePcdDatabaseTraverseEnabled
)) {
1100 return EFI_UNSUPPORTED
;
1103 ASSERT (Guid
!= NULL
);
1105 PeiExMapTableEmpty
= PEI_EXMAP_TABLE_EMPTY
;
1106 DxeExMapTableEmpty
= DXE_EXMAP_TABLE_EMPTY
;
1108 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
1109 if (*Guid
!= NULL
) {
1110 return EFI_NOT_FOUND
;
1117 if (TmpTokenSpaceBuffer
[0] == NULL
) {
1118 PeiTokenSpaceTableSize
= 0;
1120 if (!PeiExMapTableEmpty
) {
1121 PeiTokenSpaceTableSize
= PEI_EXMAPPING_TABLE_SIZE
;
1122 PeiTokenSpaceTable
= GetDistinctTokenSpace (&PeiTokenSpaceTableSize
,
1123 mPcdDatabase
->PeiDb
.Init
.ExMapTable
,
1124 mPcdDatabase
->PeiDb
.Init
.GuidTable
1126 CopyMem (TmpTokenSpaceBuffer
, PeiTokenSpaceTable
, sizeof (EFI_GUID
*) * PeiTokenSpaceTableSize
);
1129 if (!DxeExMapTableEmpty
) {
1130 DxeTokenSpaceTableSize
= DXE_EXMAPPING_TABLE_SIZE
;
1131 DxeTokenSpaceTable
= GetDistinctTokenSpace (&DxeTokenSpaceTableSize
,
1132 mPcdDatabase
->DxeDb
.Init
.ExMapTable
,
1133 mPcdDatabase
->DxeDb
.Init
.GuidTable
1137 // Make sure EFI_GUID in DxeTokenSpaceTable does not exist in PeiTokenSpaceTable
1139 for (Idx2
= 0, Idx3
= PeiTokenSpaceTableSize
; Idx2
< DxeTokenSpaceTableSize
; Idx2
++) {
1141 for (Idx
= 0; Idx
< PeiTokenSpaceTableSize
; Idx
++) {
1142 if (CompareGuid (TmpTokenSpaceBuffer
[Idx
], DxeTokenSpaceTable
[Idx2
])) {
1148 TmpTokenSpaceBuffer
[Idx3
++] = DxeTokenSpaceTable
[Idx2
];
1154 if (*Guid
== NULL
) {
1155 *Guid
= TmpTokenSpaceBuffer
[0];
1159 for (Idx
= 0; Idx
< (PEI_EXMAPPING_TABLE_SIZE
+ DXE_EXMAPPING_TABLE_SIZE
); Idx
++) {
1160 if(CompareGuid (*Guid
, TmpTokenSpaceBuffer
[Idx
])) {
1162 *Guid
= TmpTokenSpaceBuffer
[Idx
];
1167 return EFI_NOT_FOUND
;