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 - 2013, Intel Corporation. All rights reserved.<BR>
6 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 The function registers the CallBackOnSet fucntion
20 according to TokenNumber and EFI_GUID space.
22 @param ExTokenNumber The token number.
23 @param Guid The GUID space.
24 @param CallBackFunction The Callback function to be registered.
25 @param Register To register or unregister the callback function.
27 @retval EFI_SUCCESS If the Callback function is registered.
28 @retval EFI_NOT_FOUND If the PCD Entry is not found according to Token Number and GUID space.
29 @retval EFI_OUT_OF_RESOURCES If the callback function can't be registered because there is not free
30 slot left in the CallbackFnTable.
31 @retval EFI_INVALID_PARAMETER If the callback function want to be de-registered can not be found.
34 PeiRegisterCallBackWorker (
35 IN UINTN ExTokenNumber
,
36 IN CONST EFI_GUID
*Guid
, OPTIONAL
37 IN PCD_PPI_CALLBACK CallBackFunction
,
41 EFI_HOB_GUID_TYPE
*GuidHob
;
42 PCD_PPI_CALLBACK
*CallbackTable
;
43 PCD_PPI_CALLBACK Compare
;
44 PCD_PPI_CALLBACK Assign
;
45 UINT32 LocalTokenNumber
;
46 UINT32 LocalTokenCount
;
47 UINTN PeiNexTokenNumber
;
50 PEI_PCD_DATABASE
*PeiPcdDb
;
52 PeiPcdDb
= GetPcdDatabase();
53 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
54 PeiNexTokenNumber
= PeiPcdDb
->LocalTokenCount
- PeiPcdDb
->ExTokenCount
;
57 TokenNumber
= ExTokenNumber
;
59 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
60 // We have to decrement TokenNumber by 1 to make it usable
61 // as the array index.
64 ASSERT (TokenNumber
+ 1 < (PeiNexTokenNumber
+ 1));
66 TokenNumber
= GetExPcdTokenNumber (Guid
, ExTokenNumber
);
67 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
71 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
72 // We have to decrement TokenNumber by 1 to make it usable
73 // as the array index.
76 // EBC compiler is very choosy. It may report warning about comparison
77 // between UINTN and 0 . So we add 1 in each size of the
79 ASSERT ((TokenNumber
+ 1) < (LocalTokenCount
+ 1));
83 LocalTokenNumber
= *((UINT32
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->LocalTokenNumberTableOffset
) + TokenNumber
);
86 // We don't support SET for HII and VPD type PCD entry in PEI phase.
87 // So we will assert if any register callback for such PCD entry.
89 ASSERT ((LocalTokenNumber
& PCD_TYPE_HII
) == 0);
90 ASSERT ((LocalTokenNumber
& PCD_TYPE_VPD
) == 0);
92 GuidHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
93 ASSERT (GuidHob
!= NULL
);
95 CallbackTable
= GET_GUID_HOB_DATA (GuidHob
);
96 CallbackTable
= CallbackTable
+ (TokenNumber
* PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
));
98 Compare
= Register
? NULL
: CallBackFunction
;
99 Assign
= Register
? CallBackFunction
: NULL
;
102 for (Idx
= 0; Idx
< PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
); Idx
++) {
103 if (CallbackTable
[Idx
] == Compare
) {
104 CallbackTable
[Idx
] = Assign
;
109 return Register
? EFI_OUT_OF_RESOURCES
: EFI_INVALID_PARAMETER
;
115 Find the Pcd database.
117 @param FileHandle Handle of the file the external PCD database binary located.
119 @retval The base address of external PCD database binary.
120 @retval NULL Return NULL if not find.
124 IN EFI_PEI_FILE_HANDLE FileHandle
132 ASSERT (FileHandle
!= NULL
);
134 Status
= PeiServicesFfsFindSectionData (EFI_SECTION_RAW
, FileHandle
, &PcdDb
);
135 ASSERT_EFI_ERROR (Status
);
138 // Check the first bytes (Header Signature Guid) and build version.
140 if (!CompareGuid (PcdDb
, &gPcdDataBaseSignatureGuid
) ||
141 (((PEI_PCD_DATABASE
*) PcdDb
)->BuildVersion
!= PCD_SERVICE_PEIM_VERSION
)) {
149 The function builds the PCD database.
151 @param FileHandle Handle of the file the external PCD database binary located.
156 IN EFI_PEI_FILE_HANDLE FileHandle
159 PEI_PCD_DATABASE
*Database
;
160 PEI_PCD_DATABASE
*PeiPcdDbBinary
;
161 VOID
*CallbackFnTable
;
162 UINTN SizeOfCallbackFnTable
;
165 // Locate the external PCD database binary for one section of current FFS
167 PeiPcdDbBinary
= LocateExPcdBinary (FileHandle
);
169 ASSERT(PeiPcdDbBinary
!= NULL
);
171 Database
= BuildGuidHob (&gPcdDataBaseHobGuid
, PeiPcdDbBinary
->Length
+ PeiPcdDbBinary
->UninitDataBaseSize
);
173 ZeroMem (Database
, PeiPcdDbBinary
->Length
+ PeiPcdDbBinary
->UninitDataBaseSize
);
176 // PeiPcdDbBinary is smaller than Database
178 CopyMem (Database
, PeiPcdDbBinary
, PeiPcdDbBinary
->Length
);
180 SizeOfCallbackFnTable
= Database
->LocalTokenCount
* sizeof (PCD_PPI_CALLBACK
) * PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
);
182 CallbackFnTable
= BuildGuidHob (&gEfiCallerIdGuid
, SizeOfCallbackFnTable
);
184 ZeroMem (CallbackFnTable
, SizeOfCallbackFnTable
);
188 The function is provided by PCD PEIM and PCD DXE driver to
189 do the work of reading a HII variable from variable service.
191 @param VariableGuid The Variable GUID.
192 @param VariableName The Variable Name.
193 @param VariableData The output data.
194 @param VariableSize The size of the variable.
196 @retval EFI_SUCCESS Operation successful.
197 @retval EFI_NOT_FOUND Variablel not found.
201 IN CONST EFI_GUID
*VariableGuid
,
202 IN UINT16
*VariableName
,
203 OUT VOID
**VariableData
,
204 OUT UINTN
*VariableSize
210 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariablePpi
;
212 Status
= PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid
, 0, NULL
, (VOID
**) &VariablePpi
);
213 ASSERT_EFI_ERROR (Status
);
216 Status
= VariablePpi
->GetVariable (
219 (EFI_GUID
*) VariableGuid
,
225 if (Status
== EFI_BUFFER_TOO_SMALL
) {
226 Status
= PeiServicesAllocatePool (Size
, &Buffer
);
227 ASSERT_EFI_ERROR (Status
);
229 Status
= VariablePpi
->GetVariable (
231 (UINT16
*) VariableName
,
232 (EFI_GUID
*) VariableGuid
,
237 ASSERT_EFI_ERROR (Status
);
239 *VariableSize
= Size
;
240 *VariableData
= Buffer
;
245 return EFI_NOT_FOUND
;
249 Find the local token number according to system SKU ID.
251 @param LocalTokenNumber PCD token number
252 @param Size The size of PCD entry.
254 @return Token number according to system SKU ID.
258 GetSkuEnabledTokenNumber (
259 UINT32 LocalTokenNumber
,
263 PEI_PCD_DATABASE
*PeiPcdDb
;
270 PeiPcdDb
= GetPcdDatabase ();
272 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
274 SkuHead
= (SKU_HEAD
*) ((UINT8
*)PeiPcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
275 Value
= (UINT8
*) ((UINT8
*)PeiPcdDb
+ (SkuHead
->SkuDataStartOffset
));
276 SkuIdTable
= (SKU_ID
*) ((UINT8
*)PeiPcdDb
+ (SkuHead
->SkuIdTableOffset
));
279 // Find the current system's SKU ID entry in SKU ID table.
282 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
283 if (PeiPcdDb
->SystemSkuId
== SkuIdTable
[Index
+ 1]) {
290 // Find the default SKU ID entry in SKU ID table.
293 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
294 if (0 == SkuIdTable
[Index
+ 1]) {
299 ASSERT (Index
< SkuIdTable
[0]);
301 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
303 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
304 return (UINT32
) ((Value
- (UINT8
*) PeiPcdDb
) | PCD_TYPE_VPD
);
307 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
308 return (UINT32
) ((Value
- (UINT8
*) PeiPcdDb
) | PCD_TYPE_HII
);
310 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
311 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
312 return (UINT32
) ((Value
- (UINT8
*) PeiPcdDb
) | PCD_TYPE_HII
| PCD_TYPE_STRING
);
314 case PCD_TYPE_STRING
:
315 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
316 return (UINT32
) ((Value
- (UINT8
*) PeiPcdDb
) | PCD_TYPE_STRING
);
319 Value
+= Size
* Index
;
320 return (UINT32
) ((Value
- (UINT8
*) PeiPcdDb
) | PCD_TYPE_DATA
);
332 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
333 has registered callback function.
335 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
337 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
339 @param TokenNumber PCD token number generated by build tools.
340 @param Data Value want to be set for this PCD entry
341 @param Size The size of value
345 InvokeCallbackOnSet (
347 CONST EFI_GUID
*Guid
, OPTIONAL
353 EFI_HOB_GUID_TYPE
*GuidHob
;
354 PCD_PPI_CALLBACK
*CallbackTable
;
356 PEI_PCD_DATABASE
*PeiPcdDb
;
357 UINT32 LocalTokenCount
;
360 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
361 // We have to decrement TokenNumber by 1 to make it usable
362 // as the array index.
366 PeiPcdDb
= GetPcdDatabase ();
367 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
370 // EBC compiler is very choosy. It may report warning about comparison
371 // between UINTN and 0 . So we add 1 in each size of the
373 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
376 GuidHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
377 ASSERT (GuidHob
!= NULL
);
379 CallbackTable
= GET_GUID_HOB_DATA (GuidHob
);
381 CallbackTable
+= (TokenNumber
* PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
));
383 for (Idx
= 0; Idx
< PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
); Idx
++) {
384 if (CallbackTable
[Idx
] != NULL
) {
385 CallbackTable
[Idx
] (Guid
,
386 (Guid
== NULL
) ? (TokenNumber
+ 1) : ExTokenNumber
,
395 Wrapper function for setting non-pointer type value for a PCD entry.
397 @param TokenNumber Pcd token number autogenerated by build tools.
398 @param Data Value want to be set for PCD entry
399 @param Size Size of value.
401 @return status of SetWorker.
406 IN UINTN TokenNumber
,
411 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
415 Set value for an PCD entry
417 @param TokenNumber Pcd token number autogenerated by build tools.
418 @param Data Value want to be set for PCD entry
419 @param Size Size of value.
420 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
421 If False, the type of PCD entry's value is not Pointer.
423 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
424 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
425 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
426 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
427 range of UINT8, UINT16, UINT32, UINT64
428 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
432 IN UINTN TokenNumber
,
438 UINT32 LocalTokenNumber
;
439 UINTN PeiNexTokenNumber
;
440 PEI_PCD_DATABASE
*PeiPcdDb
;
441 STRING_HEAD StringTableIdx
;
445 UINT32 LocalTokenCount
;
447 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
448 return EFI_UNSUPPORTED
;
452 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
453 // We have to decrement TokenNumber by 1 to make it usable
454 // as the array index.
457 PeiPcdDb
= GetPcdDatabase ();
458 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
460 // EBC compiler is very choosy. It may report warning about comparison
461 // between UINTN and 0 . So we add 1 in each size of the
463 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
465 LocalTokenNumber
= *((UINT32
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->LocalTokenNumberTableOffset
) + TokenNumber
);
469 // Get MaxSize first, then check new size with max buffer size.
471 GetPtrTypeSize (TokenNumber
, &MaxSize
, PeiPcdDb
);
472 if (*Size
> MaxSize
) {
474 return EFI_INVALID_PARAMETER
;
477 if (*Size
!= PeiPcdGetSize (TokenNumber
+ 1)) {
478 return EFI_INVALID_PARAMETER
;
483 // We only invoke the callback function for Dynamic Type PCD Entry.
484 // For Dynamic EX PCD entry, we have invoked the callback function for Dynamic EX
485 // type PCD entry in ExSetWorker.
487 PeiNexTokenNumber
= PeiPcdDb
->LocalTokenCount
- PeiPcdDb
->ExTokenCount
;
488 if (TokenNumber
+ 1 < PeiNexTokenNumber
+ 1) {
489 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
492 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
494 GetPtrTypeSize (TokenNumber
, &MaxSize
, PeiPcdDb
);
498 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
);
501 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
502 InternalData
= (VOID
*) ((UINT8
*) PeiPcdDb
+ Offset
);
504 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
507 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
510 return EFI_INVALID_PARAMETER
;
513 case PCD_TYPE_STRING
:
514 if (SetPtrTypeSize (TokenNumber
, Size
, PeiPcdDb
)) {
515 StringTableIdx
= *((STRING_HEAD
*)InternalData
);
516 CopyMem ((UINT8
*)PeiPcdDb
+ PeiPcdDb
->StringTableOffset
+ StringTableIdx
, Data
, *Size
);
519 return EFI_INVALID_PARAMETER
;
525 if (SetPtrTypeSize (TokenNumber
, Size
, PeiPcdDb
)) {
526 CopyMem (InternalData
, Data
, *Size
);
529 return EFI_INVALID_PARAMETER
;
535 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
539 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
543 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
547 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
552 return EFI_NOT_FOUND
;
559 return EFI_NOT_FOUND
;
564 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
566 @param ExTokenNumber Token number for dynamic-ex PCD.
567 @param Guid Token space guid for dynamic-ex PCD.
568 @param Data Value want to be set.
569 @param SetSize The size of value.
571 @return status of ExSetWorker().
576 IN UINTN ExTokenNumber
,
577 IN CONST EFI_GUID
*Guid
,
582 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &Size
, FALSE
);
586 Set value for a dynamic-ex PCD entry.
588 This routine find the local token number according to dynamic-ex PCD's token
589 space guid and token number firstly, and invoke callback function if this PCD
590 entry registered callback function. Finally, invoken general SetWorker to set
593 @param ExTokenNumber Dynamic-ex PCD token number.
594 @param Guid Token space guid for dynamic-ex PCD.
595 @param Data PCD value want to be set
596 @param SetSize Size of value.
597 @param PtrType If TRUE, this PCD entry is pointer type.
598 If FALSE, this PCD entry is not pointer type.
600 @return status of SetWorker().
605 IN UINTN ExTokenNumber
,
606 IN CONST EFI_GUID
*Guid
,
614 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
615 return EFI_UNSUPPORTED
;
618 TokenNumber
= GetExPcdTokenNumber (Guid
, ExTokenNumber
);
619 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
620 return EFI_NOT_FOUND
;
623 InvokeCallbackOnSet (ExTokenNumber
, Guid
, TokenNumber
, Data
, *Size
);
625 return SetWorker (TokenNumber
, Data
, Size
, PtrType
);
630 Wrapper function for get PCD value for dynamic-ex PCD.
632 @param Guid Token space guid for dynamic-ex PCD.
633 @param ExTokenNumber Token number for dyanmic-ex PCD.
634 @param GetSize The size of dynamic-ex PCD value.
636 @return PCD entry in PCD database.
641 IN CONST EFI_GUID
*Guid
,
642 IN UINTN ExTokenNumber
,
646 return GetWorker (GetExPcdTokenNumber (Guid
, ExTokenNumber
), GetSize
);
650 Get the PCD entry pointer in PCD database.
652 This routine will visit PCD database to find the PCD entry according to given
653 token number. The given token number is autogened by build tools and it will be
654 translated to local token number. Local token number contains PCD's type and
655 offset of PCD entry in PCD database.
657 @param TokenNumber Token's number, it is autogened by build tools
658 @param GetSize The size of token's value
660 @return PCD entry pointer in PCD database
665 IN UINTN TokenNumber
,
672 VARIABLE_HEAD
*VariableHead
;
677 STRING_HEAD StringTableIdx
;
678 PEI_PCD_DATABASE
*PeiPcdDb
;
679 UINT32 LocalTokenNumber
;
681 UINT32 LocalTokenCount
;
684 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
685 // We have to decrement TokenNumber by 1 to make it usable
686 // as the array index.
690 PeiPcdDb
= GetPcdDatabase ();
691 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
693 // EBC compiler is very choosy. It may report warning about comparison
694 // between UINTN and 0 . So we add 1 in each size of the
696 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
698 ASSERT ((GetSize
== PeiPcdGetSize(TokenNumber
+ 1)) || (GetSize
== 0));
700 LocalTokenNumber
= *((UINT32
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->LocalTokenNumberTableOffset
) + TokenNumber
);
702 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
704 GetPtrTypeSize (TokenNumber
, &MaxSize
, PeiPcdDb
);
708 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
);
711 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
712 StringTable
= (UINT8
*)PeiPcdDb
+ PeiPcdDb
->StringTableOffset
;
714 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
718 VpdHead
= (VPD_HEAD
*) ((UINT8
*)PeiPcdDb
+ Offset
);
719 return (VOID
*) (UINTN
) (PcdGet32 (PcdVpdBaseAddress
) + VpdHead
->Offset
);
722 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
725 VariableHead
= (VARIABLE_HEAD
*) ((UINT8
*)PeiPcdDb
+ Offset
);
727 Guid
= (EFI_GUID
*) ((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
) + VariableHead
->GuidTableIndex
;
728 Name
= (UINT16
*)&StringTable
[VariableHead
->StringIndex
];
730 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
732 if (Status
== EFI_SUCCESS
) {
733 return (VOID
*) ((UINT8
*) Data
+ VariableHead
->Offset
);
736 // Return the default value specified by Platform Integrator
738 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
739 return (VOID
*)&StringTable
[*(STRING_HEAD
*)((UINT8
*)PeiPcdDb
+ VariableHead
->DefaultValueOffset
)];
741 return (VOID
*) ((UINT8
*) PeiPcdDb
+ VariableHead
->DefaultValueOffset
);
747 return (VOID
*) ((UINT8
*)PeiPcdDb
+ Offset
);
749 case PCD_TYPE_STRING
:
750 StringTableIdx
= * (STRING_HEAD
*) ((UINT8
*) PeiPcdDb
+ Offset
);
751 return (VOID
*) (&StringTable
[StringTableIdx
]);
766 Get Token Number according to dynamic-ex PCD's {token space guid:token number}
768 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
769 in DEC file. PCD database maintain a mapping table that translate pair of {token
770 space guid: token number} to Token Number.
772 @param Guid Token space guid for dynamic-ex PCD entry.
773 @param ExTokenNumber Dynamic-ex PCD token number.
775 @return Token Number for dynamic-ex PCD.
779 GetExPcdTokenNumber (
780 IN CONST EFI_GUID
*Guid
,
781 IN UINTN ExTokenNumber
785 DYNAMICEX_MAPPING
*ExMap
;
789 PEI_PCD_DATABASE
*PeiPcdDb
;
791 PeiPcdDb
= GetPcdDatabase();
793 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->ExMapTableOffset
);
794 GuidTable
= (EFI_GUID
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
);
796 MatchGuid
= ScanGuid (GuidTable
, PeiPcdDb
->GuidTableCount
* sizeof(EFI_GUID
), Guid
);
798 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
799 // error in the BUILD system.
801 ASSERT (MatchGuid
!= NULL
);
803 MatchGuidIdx
= MatchGuid
- GuidTable
;
805 for (Index
= 0; Index
< PeiPcdDb
->ExTokenCount
; Index
++) {
806 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
807 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
808 return ExMap
[Index
].TokenNumber
;
812 return PCD_INVALID_TOKEN_NUMBER
;
816 Get PCD database from GUID HOB in PEI phase.
818 @return Pointer to PCD database.
826 EFI_HOB_GUID_TYPE
*GuidHob
;
828 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
829 ASSERT (GuidHob
!= NULL
);
831 return (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
835 Get SKU ID table from PCD database.
837 @param LocalTokenNumberTableIdx Index of local token number in token number table.
838 @param Database PCD database.
840 @return Pointer to SKU ID array table
845 IN UINTN LocalTokenNumberTableIdx
,
846 IN PEI_PCD_DATABASE
*Database
850 UINTN LocalTokenNumber
;
852 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
854 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
856 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
858 return (SKU_ID
*) ((UINT8
*)Database
+ SkuHead
->SkuIdTableOffset
);
863 Get index of PCD entry in size table.
865 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
866 @param Database Pointer to PCD database in PEI phase.
868 @return index of PCD entry in size table.
873 IN UINTN LocalTokenNumberTableIdx
,
874 IN PEI_PCD_DATABASE
*Database
879 UINTN LocalTokenNumber
;
884 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
885 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + Index
);
887 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
889 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
892 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
894 // We have only two entry for VPD enabled PCD entry:
897 // Current size is equal to MAX size.
901 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
903 // We have only two entry for Non-Sku enabled PCD entry:
910 // We have these entry for SKU enabled PCD entry
912 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
914 SkuIdTable
= GetSkuIdArray (Index
, Database
);
915 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;