2 The driver internal functions are implmented here.
3 They build Pei PCD database, and provide access service to PCD database.
5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Get Local Token Number by Token Number.
15 @param[in] Database PCD database.
16 @param[in] TokenNumber The PCD token number.
18 @return Local Token Number.
22 IN PEI_PCD_DATABASE
*Database
,
26 UINT32 LocalTokenNumber
;
29 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
30 // We have to decrement TokenNumber by 1 to make it usable
31 // as the array index.
35 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + TokenNumber
);
37 return LocalTokenNumber
;
41 Get PCD type by Local Token Number.
43 @param[in] LocalTokenNumber The PCD local token number.
49 IN UINT32 LocalTokenNumber
52 switch (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) {
53 case PCD_DATUM_TYPE_POINTER
:
54 return EFI_PCD_TYPE_PTR
;
55 case PCD_DATUM_TYPE_UINT8
:
56 if ((LocalTokenNumber
& PCD_DATUM_TYPE_UINT8_BOOLEAN
) == PCD_DATUM_TYPE_UINT8_BOOLEAN
) {
57 return EFI_PCD_TYPE_BOOL
;
59 return EFI_PCD_TYPE_8
;
62 case PCD_DATUM_TYPE_UINT16
:
63 return EFI_PCD_TYPE_16
;
64 case PCD_DATUM_TYPE_UINT32
:
65 return EFI_PCD_TYPE_32
;
66 case PCD_DATUM_TYPE_UINT64
:
67 return EFI_PCD_TYPE_64
;
70 return EFI_PCD_TYPE_8
;
77 @param[in] OnlyTokenSpaceName If TRUE, only need to get the TokenSpaceCName.
78 If FALSE, need to get the full PCD name.
79 @param[in] Database PCD database.
80 @param[in] TokenNumber The PCD token number.
82 @return The TokenSpaceCName or full PCD name.
86 IN BOOLEAN OnlyTokenSpaceName
,
87 IN PEI_PCD_DATABASE
*Database
,
93 PCD_NAME_INDEX
*PcdNameIndex
;
94 CHAR8
*TokenSpaceName
;
99 // Return NULL when PCD name table is absent.
101 if (Database
->PcdNameTableOffset
== 0) {
106 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
107 // We have to decrement TokenNumber by 1 to make it usable
108 // as the array index.
112 StringTable
= (UINT8
*)Database
+ Database
->StringTableOffset
;
115 // Get the PCD name index.
117 PcdNameIndex
= (PCD_NAME_INDEX
*)((UINT8
*)Database
+ Database
->PcdNameTableOffset
) + TokenNumber
;
118 TokenSpaceName
= (CHAR8
*)&StringTable
[PcdNameIndex
->TokenSpaceCNameIndex
];
119 PcdName
= (CHAR8
*)&StringTable
[PcdNameIndex
->PcdCNameIndex
];
121 if (OnlyTokenSpaceName
) {
123 // Only need to get the TokenSpaceCName.
125 Name
= AllocateCopyPool (AsciiStrSize (TokenSpaceName
), TokenSpaceName
);
128 // Need to get the full PCD name.
130 NameSize
= AsciiStrSize (TokenSpaceName
) + AsciiStrSize (PcdName
);
131 Name
= AllocateZeroPool (NameSize
);
132 ASSERT (Name
!= NULL
);
134 // Catenate TokenSpaceCName and PcdCName with a '.' to form the full PCD name.
136 AsciiStrCatS (Name
, NameSize
, TokenSpaceName
);
137 Name
[AsciiStrSize (TokenSpaceName
) - sizeof (CHAR8
)] = '.';
138 AsciiStrCatS (Name
, NameSize
, PcdName
);
145 Retrieve additional information associated with a PCD token.
147 This includes information such as the type of value the TokenNumber is associated with as well as possible
148 human readable name that is associated with the token.
150 @param[in] Database PCD database.
151 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
152 @param[in] TokenNumber The PCD token number.
153 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
154 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
156 @retval EFI_SUCCESS The PCD information was returned successfully
157 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
161 IN PEI_PCD_DATABASE
*Database
,
162 IN CONST EFI_GUID
*Guid
,
163 IN UINTN TokenNumber
,
164 OUT EFI_PCD_INFO
*PcdInfo
170 DYNAMICEX_MAPPING
*ExMapTable
;
172 UINT32 LocalTokenNumber
;
174 GuidTable
= (EFI_GUID
*)((UINT8
*)Database
+ Database
->GuidTableOffset
);
175 MatchGuid
= ScanGuid (GuidTable
, Database
->GuidTableCount
* sizeof (EFI_GUID
), Guid
);
177 if (MatchGuid
== NULL
) {
178 return EFI_NOT_FOUND
;
181 GuidTableIdx
= MatchGuid
- GuidTable
;
183 ExMapTable
= (DYNAMICEX_MAPPING
*)((UINT8
*)Database
+ Database
->ExMapTableOffset
);
186 // Find the PCD by GuidTableIdx and ExTokenNumber in ExMapTable.
188 for (Index
= 0; Index
< Database
->ExTokenCount
; Index
++) {
189 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
190 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
192 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
193 // PcdSize to 0 and PcdName to the null-terminated ASCII string
194 // associated with the token's namespace Guid.
196 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
197 PcdInfo
->PcdSize
= 0;
199 // Here use one representative in the token space to get the TokenSpaceCName.
201 PcdInfo
->PcdName
= GetPcdName (TRUE
, Database
, ExMapTable
[Index
].TokenNumber
);
203 } else if (ExMapTable
[Index
].ExTokenNumber
== TokenNumber
) {
204 PcdInfo
->PcdSize
= PeiPcdGetSize (ExMapTable
[Index
].TokenNumber
);
205 LocalTokenNumber
= GetLocalTokenNumber (Database
, ExMapTable
[Index
].TokenNumber
);
206 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
207 PcdInfo
->PcdName
= GetPcdName (FALSE
, Database
, ExMapTable
[Index
].TokenNumber
);
213 return EFI_NOT_FOUND
;
217 Retrieve additional information associated with a PCD token.
219 This includes information such as the type of value the TokenNumber is associated with as well as possible
220 human readable name that is associated with the token.
222 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
223 @param[in] TokenNumber The PCD token number.
224 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
225 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
227 @retval EFI_SUCCESS The PCD information was returned successfully.
228 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
232 IN CONST EFI_GUID
*Guid
,
233 IN UINTN TokenNumber
,
234 OUT EFI_PCD_INFO
*PcdInfo
237 PEI_PCD_DATABASE
*PeiPcdDb
;
238 BOOLEAN PeiExMapTableEmpty
;
239 UINTN PeiNexTokenNumber
;
240 UINT32 LocalTokenNumber
;
242 ASSERT (PcdInfo
!= NULL
);
244 PeiPcdDb
= GetPcdDatabase ();
245 PeiNexTokenNumber
= PeiPcdDb
->LocalTokenCount
- PeiPcdDb
->ExTokenCount
;
247 if (PeiPcdDb
->ExTokenCount
== 0) {
248 PeiExMapTableEmpty
= TRUE
;
250 PeiExMapTableEmpty
= FALSE
;
254 if (TokenNumber
> PeiNexTokenNumber
) {
255 return EFI_NOT_FOUND
;
256 } else if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
258 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
259 // PcdSize to 0 and PcdName to NULL for default Token Space.
261 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
262 PcdInfo
->PcdSize
= 0;
263 PcdInfo
->PcdName
= NULL
;
265 PcdInfo
->PcdSize
= PeiPcdGetSize (TokenNumber
);
266 LocalTokenNumber
= GetLocalTokenNumber (PeiPcdDb
, TokenNumber
);
267 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
268 PcdInfo
->PcdName
= GetPcdName (FALSE
, PeiPcdDb
, TokenNumber
);
273 if (PeiExMapTableEmpty
) {
274 return EFI_NOT_FOUND
;
277 return ExGetPcdInfo (
287 The function registers the CallBackOnSet fucntion
288 according to TokenNumber and EFI_GUID space.
290 @param ExTokenNumber The token number.
291 @param Guid The GUID space.
292 @param CallBackFunction The Callback function to be registered.
293 @param Register To register or unregister the callback function.
295 @retval EFI_SUCCESS If the Callback function is registered.
296 @retval EFI_NOT_FOUND If the PCD Entry is not found according to Token Number and GUID space.
297 @retval EFI_OUT_OF_RESOURCES If the callback function can't be registered because there is not free
298 slot left in the CallbackFnTable.
299 @retval EFI_INVALID_PARAMETER If the callback function want to be de-registered can not be found.
302 PeiRegisterCallBackWorker (
303 IN UINTN ExTokenNumber
,
304 IN CONST EFI_GUID
*Guid OPTIONAL
,
305 IN PCD_PPI_CALLBACK CallBackFunction
,
309 EFI_HOB_GUID_TYPE
*GuidHob
;
310 PCD_PPI_CALLBACK
*CallbackTable
;
311 PCD_PPI_CALLBACK Compare
;
312 PCD_PPI_CALLBACK Assign
;
313 UINT32 LocalTokenNumber
;
314 UINT32 LocalTokenCount
;
315 UINTN PeiNexTokenNumber
;
318 PEI_PCD_DATABASE
*PeiPcdDb
;
320 PeiPcdDb
= GetPcdDatabase ();
321 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
322 PeiNexTokenNumber
= PeiPcdDb
->LocalTokenCount
- PeiPcdDb
->ExTokenCount
;
325 TokenNumber
= ExTokenNumber
;
327 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
328 // We have to decrement TokenNumber by 1 to make it usable
329 // as the array index.
332 ASSERT (TokenNumber
+ 1 < (PeiNexTokenNumber
+ 1));
334 TokenNumber
= GetExPcdTokenNumber (Guid
, ExTokenNumber
);
335 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
336 return EFI_NOT_FOUND
;
340 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
341 // We have to decrement TokenNumber by 1 to make it usable
342 // as the array index.
345 // EBC compiler is very choosy. It may report warning about comparison
346 // between UINTN and 0 . So we add 1 in each size of the
348 ASSERT ((TokenNumber
+ 1) < (LocalTokenCount
+ 1));
351 LocalTokenNumber
= *((UINT32
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->LocalTokenNumberTableOffset
) + TokenNumber
);
354 // We don't support SET for HII and VPD type PCD entry in PEI phase.
355 // So we will assert if any register callback for such PCD entry.
357 ASSERT ((LocalTokenNumber
& PCD_TYPE_HII
) == 0);
358 ASSERT ((LocalTokenNumber
& PCD_TYPE_VPD
) == 0);
360 GuidHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
361 ASSERT (GuidHob
!= NULL
);
363 CallbackTable
= GET_GUID_HOB_DATA (GuidHob
);
364 CallbackTable
= CallbackTable
+ (TokenNumber
* PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
));
366 Compare
= Register
? NULL
: CallBackFunction
;
367 Assign
= Register
? CallBackFunction
: NULL
;
369 for (Idx
= 0; Idx
< PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
); Idx
++) {
370 if (CallbackTable
[Idx
] == Compare
) {
371 CallbackTable
[Idx
] = Assign
;
376 return Register
? EFI_OUT_OF_RESOURCES
: EFI_INVALID_PARAMETER
;
380 Find the Pcd database.
382 @param FileHandle Handle of the file the external PCD database binary located.
384 @retval The base address of external PCD database binary.
385 @retval NULL Return NULL if not find.
389 IN EFI_PEI_FILE_HANDLE FileHandle
397 ASSERT (FileHandle
!= NULL
);
399 Status
= PeiServicesFfsFindSectionData (EFI_SECTION_RAW
, FileHandle
, &PcdDb
);
400 ASSERT_EFI_ERROR (Status
);
403 // Check the first bytes (Header Signature Guid) and build version.
405 if (!CompareGuid (PcdDb
, &gPcdDataBaseSignatureGuid
) ||
406 (((PEI_PCD_DATABASE
*)PcdDb
)->BuildVersion
!= PCD_SERVICE_PEIM_VERSION
))
415 The function builds the PCD database.
417 @param FileHandle Handle of the file the external PCD database binary located.
419 @return Pointer to PCD database.
423 IN EFI_PEI_FILE_HANDLE FileHandle
426 PEI_PCD_DATABASE
*Database
;
427 PEI_PCD_DATABASE
*PeiPcdDbBinary
;
428 VOID
*CallbackFnTable
;
429 UINTN SizeOfCallbackFnTable
;
432 // Locate the external PCD database binary for one section of current FFS
434 PeiPcdDbBinary
= LocateExPcdBinary (FileHandle
);
436 ASSERT (PeiPcdDbBinary
!= NULL
);
438 Database
= BuildGuidHob (&gPcdDataBaseHobGuid
, PeiPcdDbBinary
->Length
+ PeiPcdDbBinary
->UninitDataBaseSize
);
440 ZeroMem (Database
, PeiPcdDbBinary
->Length
+ PeiPcdDbBinary
->UninitDataBaseSize
);
443 // PeiPcdDbBinary is smaller than Database
445 CopyMem (Database
, PeiPcdDbBinary
, PeiPcdDbBinary
->Length
);
447 SizeOfCallbackFnTable
= Database
->LocalTokenCount
* sizeof (PCD_PPI_CALLBACK
) * PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
);
449 CallbackFnTable
= BuildGuidHob (&gEfiCallerIdGuid
, SizeOfCallbackFnTable
);
451 ZeroMem (CallbackFnTable
, SizeOfCallbackFnTable
);
457 The function is provided by PCD PEIM and PCD DXE driver to
458 do the work of reading a HII variable from variable service.
460 @param VariableGuid The Variable GUID.
461 @param VariableName The Variable Name.
462 @param VariableData The output data.
463 @param VariableSize The size of the variable.
465 @retval EFI_SUCCESS Operation successful.
466 @retval EFI_NOT_FOUND Variablel not found.
470 IN CONST EFI_GUID
*VariableGuid
,
471 IN UINT16
*VariableName
,
472 OUT VOID
**VariableData
,
473 OUT UINTN
*VariableSize
479 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariablePpi
;
481 Status
= PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid
, 0, NULL
, (VOID
**)&VariablePpi
);
482 ASSERT_EFI_ERROR (Status
);
485 Status
= VariablePpi
->GetVariable (
488 (EFI_GUID
*)VariableGuid
,
494 if (Status
== EFI_BUFFER_TOO_SMALL
) {
495 Status
= PeiServicesAllocatePool (Size
, &Buffer
);
496 ASSERT_EFI_ERROR (Status
);
498 Status
= VariablePpi
->GetVariable (
500 (UINT16
*)VariableName
,
501 (EFI_GUID
*)VariableGuid
,
506 ASSERT_EFI_ERROR (Status
);
508 *VariableSize
= Size
;
509 *VariableData
= Buffer
;
514 return EFI_NOT_FOUND
;
518 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
519 has registered callback function.
521 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
523 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
525 @param TokenNumber PCD token number generated by build tools.
526 @param Data Value want to be set for this PCD entry
527 @param Size The size of value
531 InvokeCallbackOnSet (
533 CONST EFI_GUID
*Guid OPTIONAL
,
539 EFI_HOB_GUID_TYPE
*GuidHob
;
540 PCD_PPI_CALLBACK
*CallbackTable
;
542 PEI_PCD_DATABASE
*PeiPcdDb
;
543 UINT32 LocalTokenCount
;
546 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
547 // We have to decrement TokenNumber by 1 to make it usable
548 // as the array index.
552 PeiPcdDb
= GetPcdDatabase ();
553 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
556 // EBC compiler is very choosy. It may report warning about comparison
557 // between UINTN and 0 . So we add 1 in each size of the
559 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
562 GuidHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
563 ASSERT (GuidHob
!= NULL
);
565 CallbackTable
= GET_GUID_HOB_DATA (GuidHob
);
567 CallbackTable
+= (TokenNumber
* PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
));
569 for (Idx
= 0; Idx
< PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
); Idx
++) {
570 if (CallbackTable
[Idx
] != NULL
) {
571 CallbackTable
[Idx
](Guid
,
572 (Guid
== NULL
) ? (TokenNumber
+ 1) : ExTokenNumber
,
581 Wrapper function for setting non-pointer type value for a PCD entry.
583 @param TokenNumber Pcd token number autogenerated by build tools.
584 @param Data Value want to be set for PCD entry
585 @param Size Size of value.
587 @return status of SetWorker.
592 IN UINTN TokenNumber
,
597 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
601 Set value for an PCD entry
603 @param TokenNumber Pcd token number autogenerated by build tools.
604 @param Data Value want to be set for PCD entry
605 @param Size Size of value.
606 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
607 If False, the type of PCD entry's value is not Pointer.
609 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
610 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
611 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
612 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
613 range of UINT8, UINT16, UINT32, UINT64
614 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
618 IN UINTN TokenNumber
,
624 UINT32 LocalTokenNumber
;
625 UINTN PeiNexTokenNumber
;
626 PEI_PCD_DATABASE
*PeiPcdDb
;
627 STRING_HEAD StringTableIdx
;
631 UINT32 LocalTokenCount
;
633 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable
)) {
634 return EFI_UNSUPPORTED
;
638 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
639 // We have to decrement TokenNumber by 1 to make it usable
640 // as the array index.
643 PeiPcdDb
= GetPcdDatabase ();
644 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
646 // EBC compiler is very choosy. It may report warning about comparison
647 // between UINTN and 0 . So we add 1 in each size of the
649 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
653 // Get MaxSize first, then check new size with max buffer size.
655 GetPtrTypeSize (TokenNumber
, &MaxSize
, PeiPcdDb
);
656 if (*Size
> MaxSize
) {
658 return EFI_INVALID_PARAMETER
;
661 if (*Size
!= PeiPcdGetSize (TokenNumber
+ 1)) {
662 return EFI_INVALID_PARAMETER
;
667 // We only invoke the callback function for Dynamic Type PCD Entry.
668 // For Dynamic EX PCD entry, we have invoked the callback function for Dynamic EX
669 // type PCD entry in ExSetWorker.
671 PeiNexTokenNumber
= PeiPcdDb
->LocalTokenCount
- PeiPcdDb
->ExTokenCount
;
672 if (TokenNumber
+ 1 < PeiNexTokenNumber
+ 1) {
673 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
676 LocalTokenNumber
= GetLocalTokenNumber (PeiPcdDb
, TokenNumber
+ 1);
678 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
679 InternalData
= (VOID
*)((UINT8
*)PeiPcdDb
+ Offset
);
681 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
684 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
687 return EFI_INVALID_PARAMETER
;
690 case PCD_TYPE_STRING
:
691 if (SetPtrTypeSize (TokenNumber
, Size
, PeiPcdDb
)) {
692 StringTableIdx
= *((STRING_HEAD
*)InternalData
);
693 CopyMem ((UINT8
*)PeiPcdDb
+ PeiPcdDb
->StringTableOffset
+ StringTableIdx
, Data
, *Size
);
696 return EFI_INVALID_PARAMETER
;
702 if (SetPtrTypeSize (TokenNumber
, Size
, PeiPcdDb
)) {
703 CopyMem (InternalData
, Data
, *Size
);
706 return EFI_INVALID_PARAMETER
;
712 *((UINT8
*)InternalData
) = *((UINT8
*)Data
);
715 case sizeof (UINT16
):
716 *((UINT16
*)InternalData
) = *((UINT16
*)Data
);
719 case sizeof (UINT32
):
720 *((UINT32
*)InternalData
) = *((UINT32
*)Data
);
723 case sizeof (UINT64
):
724 *((UINT64
*)InternalData
) = *((UINT64
*)Data
);
729 return EFI_NOT_FOUND
;
735 return EFI_NOT_FOUND
;
739 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
741 @param ExTokenNumber Token number for dynamic-ex PCD.
742 @param Guid Token space guid for dynamic-ex PCD.
743 @param Data Value want to be set.
744 @param SetSize The size of value.
746 @return status of ExSetWorker().
751 IN UINTN ExTokenNumber
,
752 IN CONST EFI_GUID
*Guid
,
757 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &Size
, FALSE
);
761 Set value for a dynamic-ex PCD entry.
763 This routine find the local token number according to dynamic-ex PCD's token
764 space guid and token number firstly, and invoke callback function if this PCD
765 entry registered callback function. Finally, invoken general SetWorker to set
768 @param ExTokenNumber Dynamic-ex PCD token number.
769 @param Guid Token space guid for dynamic-ex PCD.
770 @param Data PCD value want to be set
771 @param SetSize Size of value.
772 @param PtrType If TRUE, this PCD entry is pointer type.
773 If FALSE, this PCD entry is not pointer type.
775 @return status of SetWorker().
780 IN UINTN ExTokenNumber
,
781 IN CONST EFI_GUID
*Guid
,
789 if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable
)) {
790 return EFI_UNSUPPORTED
;
793 TokenNumber
= GetExPcdTokenNumber (Guid
, ExTokenNumber
);
794 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
795 return EFI_NOT_FOUND
;
798 InvokeCallbackOnSet (ExTokenNumber
, Guid
, TokenNumber
, Data
, *Size
);
800 return SetWorker (TokenNumber
, Data
, Size
, PtrType
);
804 Wrapper function for get PCD value for dynamic-ex PCD.
806 @param Guid Token space guid for dynamic-ex PCD.
807 @param ExTokenNumber Token number for dyanmic-ex PCD.
808 @param GetSize The size of dynamic-ex PCD value.
810 @return PCD entry in PCD database.
815 IN CONST EFI_GUID
*Guid
,
816 IN UINTN ExTokenNumber
,
820 return GetWorker (GetExPcdTokenNumber (Guid
, ExTokenNumber
), GetSize
);
824 Get the PCD entry pointer in PCD database.
826 This routine will visit PCD database to find the PCD entry according to given
827 token number. The given token number is autogened by build tools and it will be
828 translated to local token number. Local token number contains PCD's type and
829 offset of PCD entry in PCD database.
831 @param TokenNumber Token's number, it is autogened by build tools
832 @param GetSize The size of token's value
834 @return PCD entry pointer in PCD database
839 IN UINTN TokenNumber
,
846 VARIABLE_HEAD
*VariableHead
;
851 STRING_HEAD StringTableIdx
;
852 PEI_PCD_DATABASE
*PeiPcdDb
;
853 UINT32 LocalTokenNumber
;
854 UINT32 LocalTokenCount
;
855 UINT8
*VaraiableDefaultBuffer
;
856 UINTN VpdBaseAddress
;
859 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
860 // We have to decrement TokenNumber by 1 to make it usable
861 // as the array index.
865 PeiPcdDb
= GetPcdDatabase ();
866 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
868 // EBC compiler is very choosy. It may report warning about comparison
869 // between UINTN and 0 . So we add 1 in each size of the
871 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
873 ASSERT ((GetSize
== PeiPcdGetSize (TokenNumber
+ 1)) || (GetSize
== 0));
875 LocalTokenNumber
= GetLocalTokenNumber (PeiPcdDb
, TokenNumber
+ 1);
877 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
878 StringTable
= (UINT8
*)PeiPcdDb
+ PeiPcdDb
->StringTableOffset
;
880 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
884 VpdHead
= (VPD_HEAD
*)((UINT8
*)PeiPcdDb
+ Offset
);
887 // PcdVpdBaseAddress64 is DynamicEx PCD only. So, PeiPcdGet64Ex() is used to get its value.
889 VpdBaseAddress
= (UINTN
)PeiPcdGet64Ex (&gEfiMdeModulePkgTokenSpaceGuid
, PcdToken (PcdVpdBaseAddress64
));
890 if (VpdBaseAddress
== 0) {
892 // PcdVpdBaseAddress64 is not set, get value from PcdVpdBaseAddress.
894 VpdBaseAddress
= (UINTN
)PcdGet32 (PcdVpdBaseAddress
);
897 ASSERT (VpdBaseAddress
!= 0);
898 return (VOID
*)(VpdBaseAddress
+ VpdHead
->Offset
);
901 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
904 VariableHead
= (VARIABLE_HEAD
*)((UINT8
*)PeiPcdDb
+ Offset
);
906 Guid
= (EFI_GUID
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
) + VariableHead
->GuidTableIndex
;
907 Name
= (UINT16
*)&StringTable
[VariableHead
->StringIndex
];
909 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
911 // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is the index of
912 // string array in string table.
914 VaraiableDefaultBuffer
= (UINT8
*)&StringTable
[*(STRING_HEAD
*)((UINT8
*)PeiPcdDb
+ VariableHead
->DefaultValueOffset
)];
916 VaraiableDefaultBuffer
= (UINT8
*)PeiPcdDb
+ VariableHead
->DefaultValueOffset
;
919 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
920 if ((Status
== EFI_SUCCESS
) && (DataSize
>= (VariableHead
->Offset
+ GetSize
))) {
923 // It is a pointer type. So get the MaxSize reserved for
926 GetPtrTypeSize (TokenNumber
, &GetSize
, PeiPcdDb
);
927 if (GetSize
> (DataSize
- VariableHead
->Offset
)) {
929 // Use actual valid size.
931 GetSize
= DataSize
- VariableHead
->Offset
;
936 // If the operation is successful, we copy the data
937 // to the default value buffer in the PCD Database.
939 CopyMem (VaraiableDefaultBuffer
, (UINT8
*)Data
+ VariableHead
->Offset
, GetSize
);
942 return (VOID
*)VaraiableDefaultBuffer
;
946 return (VOID
*)((UINT8
*)PeiPcdDb
+ Offset
);
948 case PCD_TYPE_STRING
:
949 StringTableIdx
= *(STRING_HEAD
*)((UINT8
*)PeiPcdDb
+ Offset
);
950 return (VOID
*)(&StringTable
[StringTableIdx
]);
963 Get Token Number according to dynamic-ex PCD's {token space guid:token number}
965 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
966 in DEC file. PCD database maintain a mapping table that translate pair of {token
967 space guid: token number} to Token Number.
969 @param Guid Token space guid for dynamic-ex PCD entry.
970 @param ExTokenNumber Dynamic-ex PCD token number.
972 @return Token Number for dynamic-ex PCD.
976 GetExPcdTokenNumber (
977 IN CONST EFI_GUID
*Guid
,
978 IN UINTN ExTokenNumber
982 DYNAMICEX_MAPPING
*ExMap
;
986 PEI_PCD_DATABASE
*PeiPcdDb
;
988 PeiPcdDb
= GetPcdDatabase ();
990 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->ExMapTableOffset
);
991 GuidTable
= (EFI_GUID
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
);
993 MatchGuid
= ScanGuid (GuidTable
, PeiPcdDb
->GuidTableCount
* sizeof (EFI_GUID
), Guid
);
995 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
996 // error in the BUILD system.
998 ASSERT (MatchGuid
!= NULL
);
1000 MatchGuidIdx
= MatchGuid
- GuidTable
;
1002 for (Index
= 0; Index
< PeiPcdDb
->ExTokenCount
; Index
++) {
1003 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1004 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
))
1006 return ExMap
[Index
].TokenNumber
;
1010 return PCD_INVALID_TOKEN_NUMBER
;
1014 Get PCD database from GUID HOB in PEI phase.
1016 @return Pointer to PCD database.
1024 EFI_HOB_GUID_TYPE
*GuidHob
;
1026 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
1027 ASSERT (GuidHob
!= NULL
);
1029 return (PEI_PCD_DATABASE
*)GET_GUID_HOB_DATA (GuidHob
);
1033 Get index of PCD entry in size table.
1035 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1036 @param Database Pointer to PCD database in PEI phase.
1038 @return index of PCD entry in size table.
1043 IN UINTN LocalTokenNumberTableIdx
,
1044 IN PEI_PCD_DATABASE
*Database
1049 UINTN LocalTokenNumber
;
1053 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
1054 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + Index
);
1056 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1058 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1061 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1063 // We have only two entry for VPD enabled PCD entry:
1066 // Current size is equal to MAX size.
1071 // We have only two entry for Non-Sku enabled PCD entry:
1080 return SizeTableIdx
;