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 Get Local Token Number by Token Number.
21 @param[in] Database PCD database.
22 @param[in] TokenNumber The PCD token number.
24 @return Local Token Number.
28 IN PEI_PCD_DATABASE
*Database
,
32 UINT32 LocalTokenNumber
;
37 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
38 // We have to decrement TokenNumber by 1 to make it usable
39 // as the array index.
43 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + TokenNumber
);
45 Size
= (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
47 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
49 GetPtrTypeSize (TokenNumber
, &MaxSize
, Database
);
53 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
);
56 return LocalTokenNumber
;
60 Get PCD type by Local Token Number.
62 @param[in] LocalTokenNumber The PCD local token number.
68 IN UINT32 LocalTokenNumber
71 switch (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) {
72 case PCD_DATUM_TYPE_POINTER
:
73 return EFI_PCD_TYPE_PTR
;
74 case PCD_DATUM_TYPE_UINT8
:
75 if (LocalTokenNumber
& PCD_DATUM_TYPE_UINT8_BOOLEAN
) {
76 return EFI_PCD_TYPE_BOOL
;
78 return EFI_PCD_TYPE_8
;
80 case PCD_DATUM_TYPE_UINT16
:
81 return EFI_PCD_TYPE_16
;
82 case PCD_DATUM_TYPE_UINT32
:
83 return EFI_PCD_TYPE_32
;
84 case PCD_DATUM_TYPE_UINT64
:
85 return EFI_PCD_TYPE_64
;
88 return EFI_PCD_TYPE_8
;
95 @param[in] OnlyTokenSpaceName If TRUE, only need to get the TokenSpaceCName.
96 If FALSE, need to get the full PCD name.
97 @param[in] Database PCD database.
98 @param[in] TokenNumber The PCD token number.
100 @return The TokenSpaceCName or full PCD name.
104 IN BOOLEAN OnlyTokenSpaceName
,
105 IN PEI_PCD_DATABASE
*Database
,
110 PCD_NAME_INDEX
*PcdNameIndex
;
111 CHAR8
*TokenSpaceName
;
116 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
117 // We have to decrement TokenNumber by 1 to make it usable
118 // as the array index.
122 StringTable
= (UINT8
*) Database
+ Database
->StringTableOffset
;
125 // Get the PCD name index.
127 PcdNameIndex
= (PCD_NAME_INDEX
*)((UINT8
*) Database
+ Database
->PcdNameTableOffset
) + TokenNumber
;
128 TokenSpaceName
= (CHAR8
*)&StringTable
[PcdNameIndex
->TokenSpaceCNameIndex
];
129 PcdName
= (CHAR8
*)&StringTable
[PcdNameIndex
->PcdCNameIndex
];
131 if (OnlyTokenSpaceName
) {
133 // Only need to get the TokenSpaceCName.
135 Name
= AllocateCopyPool (AsciiStrSize (TokenSpaceName
), TokenSpaceName
);
138 // Need to get the full PCD name.
140 Name
= AllocateZeroPool (AsciiStrSize (TokenSpaceName
) + AsciiStrSize (PcdName
));
141 ASSERT (Name
!= NULL
);
143 // Catenate TokenSpaceCName and PcdCName with a '.' to form the full PCD name.
145 AsciiStrCat (Name
, TokenSpaceName
);
146 Name
[AsciiStrSize (TokenSpaceName
) - sizeof (CHAR8
)] = '.';
147 AsciiStrCat (Name
, PcdName
);
154 Retrieve additional information associated with a PCD token.
156 This includes information such as the type of value the TokenNumber is associated with as well as possible
157 human readable name that is associated with the token.
159 @param[in] Database PCD database.
160 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
161 @param[in] TokenNumber The PCD token number.
162 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
163 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
165 @retval EFI_SUCCESS The PCD information was returned successfully
166 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
170 IN PEI_PCD_DATABASE
*Database
,
171 IN CONST EFI_GUID
*Guid
,
172 IN UINTN TokenNumber
,
173 OUT EFI_PCD_INFO
*PcdInfo
179 DYNAMICEX_MAPPING
*ExMapTable
;
181 UINT32 LocalTokenNumber
;
183 GuidTable
= (EFI_GUID
*)((UINT8
*)Database
+ Database
->GuidTableOffset
);
184 MatchGuid
= ScanGuid (GuidTable
, Database
->GuidTableCount
* sizeof(EFI_GUID
), Guid
);
186 if (MatchGuid
== NULL
) {
187 return EFI_NOT_FOUND
;
190 GuidTableIdx
= MatchGuid
- GuidTable
;
192 ExMapTable
= (DYNAMICEX_MAPPING
*)((UINT8
*)Database
+ Database
->ExMapTableOffset
);
195 // Find the PCD by GuidTableIdx and ExTokenNumber in ExMapTable.
197 for (Index
= 0; Index
< Database
->ExTokenCount
; Index
++) {
198 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
199 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
201 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
202 // PcdSize to 0 and PcdName to the null-terminated ASCII string
203 // associated with the token's namespace Guid.
205 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
206 PcdInfo
->PcdSize
= 0;
208 // Here use one representative in the token space to get the TokenSpaceCName.
210 PcdInfo
->PcdName
= GetPcdName (TRUE
, Database
, ExMapTable
[Index
].TokenNumber
);
212 } else if (ExMapTable
[Index
].ExTokenNumber
== TokenNumber
) {
213 PcdInfo
->PcdSize
= PeiPcdGetSize (ExMapTable
[Index
].TokenNumber
);
214 LocalTokenNumber
= GetLocalTokenNumber (Database
, ExMapTable
[Index
].TokenNumber
);
215 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
216 PcdInfo
->PcdName
= GetPcdName (FALSE
, Database
, ExMapTable
[Index
].TokenNumber
);
222 return EFI_NOT_FOUND
;
226 Retrieve additional information associated with a PCD token.
228 This includes information such as the type of value the TokenNumber is associated with as well as possible
229 human readable name that is associated with the token.
231 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
232 @param[in] TokenNumber The PCD token number.
233 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
234 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
236 @retval EFI_SUCCESS The PCD information was returned successfully.
237 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
241 IN CONST EFI_GUID
*Guid
,
242 IN UINTN TokenNumber
,
243 OUT EFI_PCD_INFO
*PcdInfo
246 PEI_PCD_DATABASE
*PeiPcdDb
;
247 BOOLEAN PeiExMapTableEmpty
;
248 UINTN PeiNexTokenNumber
;
249 UINT32 LocalTokenNumber
;
251 ASSERT (PcdInfo
!= NULL
);
253 PeiPcdDb
= GetPcdDatabase ();
254 PeiNexTokenNumber
= PeiPcdDb
->LocalTokenCount
- PeiPcdDb
->ExTokenCount
;
256 if (PeiPcdDb
->ExTokenCount
== 0) {
257 PeiExMapTableEmpty
= TRUE
;
259 PeiExMapTableEmpty
= FALSE
;
263 if (TokenNumber
> PeiNexTokenNumber
) {
264 return EFI_NOT_FOUND
;
265 } else if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
267 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
268 // PcdSize to 0 and PcdName to NULL for default Token Space.
270 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
271 PcdInfo
->PcdSize
= 0;
272 PcdInfo
->PcdName
= NULL
;
274 PcdInfo
->PcdSize
= PeiPcdGetSize (TokenNumber
);
275 LocalTokenNumber
= GetLocalTokenNumber (PeiPcdDb
, TokenNumber
);
276 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
277 PcdInfo
->PcdName
= GetPcdName (FALSE
, PeiPcdDb
, TokenNumber
);
281 if (PeiExMapTableEmpty
) {
282 return EFI_NOT_FOUND
;
284 return ExGetPcdInfo (
294 The function registers the CallBackOnSet fucntion
295 according to TokenNumber and EFI_GUID space.
297 @param ExTokenNumber The token number.
298 @param Guid The GUID space.
299 @param CallBackFunction The Callback function to be registered.
300 @param Register To register or unregister the callback function.
302 @retval EFI_SUCCESS If the Callback function is registered.
303 @retval EFI_NOT_FOUND If the PCD Entry is not found according to Token Number and GUID space.
304 @retval EFI_OUT_OF_RESOURCES If the callback function can't be registered because there is not free
305 slot left in the CallbackFnTable.
306 @retval EFI_INVALID_PARAMETER If the callback function want to be de-registered can not be found.
309 PeiRegisterCallBackWorker (
310 IN UINTN ExTokenNumber
,
311 IN CONST EFI_GUID
*Guid
, OPTIONAL
312 IN PCD_PPI_CALLBACK CallBackFunction
,
316 EFI_HOB_GUID_TYPE
*GuidHob
;
317 PCD_PPI_CALLBACK
*CallbackTable
;
318 PCD_PPI_CALLBACK Compare
;
319 PCD_PPI_CALLBACK Assign
;
320 UINT32 LocalTokenNumber
;
321 UINT32 LocalTokenCount
;
322 UINTN PeiNexTokenNumber
;
325 PEI_PCD_DATABASE
*PeiPcdDb
;
327 PeiPcdDb
= GetPcdDatabase();
328 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
329 PeiNexTokenNumber
= PeiPcdDb
->LocalTokenCount
- PeiPcdDb
->ExTokenCount
;
332 TokenNumber
= ExTokenNumber
;
334 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
335 // We have to decrement TokenNumber by 1 to make it usable
336 // as the array index.
339 ASSERT (TokenNumber
+ 1 < (PeiNexTokenNumber
+ 1));
341 TokenNumber
= GetExPcdTokenNumber (Guid
, ExTokenNumber
);
342 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
343 return EFI_NOT_FOUND
;
346 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
347 // We have to decrement TokenNumber by 1 to make it usable
348 // as the array index.
351 // EBC compiler is very choosy. It may report warning about comparison
352 // between UINTN and 0 . So we add 1 in each size of the
354 ASSERT ((TokenNumber
+ 1) < (LocalTokenCount
+ 1));
358 LocalTokenNumber
= *((UINT32
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->LocalTokenNumberTableOffset
) + TokenNumber
);
361 // We don't support SET for HII and VPD type PCD entry in PEI phase.
362 // So we will assert if any register callback for such PCD entry.
364 ASSERT ((LocalTokenNumber
& PCD_TYPE_HII
) == 0);
365 ASSERT ((LocalTokenNumber
& PCD_TYPE_VPD
) == 0);
367 GuidHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
368 ASSERT (GuidHob
!= NULL
);
370 CallbackTable
= GET_GUID_HOB_DATA (GuidHob
);
371 CallbackTable
= CallbackTable
+ (TokenNumber
* PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
));
373 Compare
= Register
? NULL
: CallBackFunction
;
374 Assign
= Register
? CallBackFunction
: NULL
;
377 for (Idx
= 0; Idx
< PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
); Idx
++) {
378 if (CallbackTable
[Idx
] == Compare
) {
379 CallbackTable
[Idx
] = Assign
;
384 return Register
? EFI_OUT_OF_RESOURCES
: EFI_INVALID_PARAMETER
;
390 Find the Pcd database.
392 @param FileHandle Handle of the file the external PCD database binary located.
394 @retval The base address of external PCD database binary.
395 @retval NULL Return NULL if not find.
399 IN EFI_PEI_FILE_HANDLE FileHandle
407 ASSERT (FileHandle
!= NULL
);
409 Status
= PeiServicesFfsFindSectionData (EFI_SECTION_RAW
, FileHandle
, &PcdDb
);
410 ASSERT_EFI_ERROR (Status
);
413 // Check the first bytes (Header Signature Guid) and build version.
415 if (!CompareGuid (PcdDb
, &gPcdDataBaseSignatureGuid
) ||
416 (((PEI_PCD_DATABASE
*) PcdDb
)->BuildVersion
!= PCD_SERVICE_PEIM_VERSION
)) {
424 The function builds the PCD database.
426 @param FileHandle Handle of the file the external PCD database binary located.
428 @return Pointer to PCD database.
432 IN EFI_PEI_FILE_HANDLE FileHandle
435 PEI_PCD_DATABASE
*Database
;
436 PEI_PCD_DATABASE
*PeiPcdDbBinary
;
437 VOID
*CallbackFnTable
;
438 UINTN SizeOfCallbackFnTable
;
441 // Locate the external PCD database binary for one section of current FFS
443 PeiPcdDbBinary
= LocateExPcdBinary (FileHandle
);
445 ASSERT(PeiPcdDbBinary
!= NULL
);
447 Database
= BuildGuidHob (&gPcdDataBaseHobGuid
, PeiPcdDbBinary
->Length
+ PeiPcdDbBinary
->UninitDataBaseSize
);
449 ZeroMem (Database
, PeiPcdDbBinary
->Length
+ PeiPcdDbBinary
->UninitDataBaseSize
);
452 // PeiPcdDbBinary is smaller than Database
454 CopyMem (Database
, PeiPcdDbBinary
, PeiPcdDbBinary
->Length
);
456 SizeOfCallbackFnTable
= Database
->LocalTokenCount
* sizeof (PCD_PPI_CALLBACK
) * PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
);
458 CallbackFnTable
= BuildGuidHob (&gEfiCallerIdGuid
, SizeOfCallbackFnTable
);
460 ZeroMem (CallbackFnTable
, SizeOfCallbackFnTable
);
466 The function is provided by PCD PEIM and PCD DXE driver to
467 do the work of reading a HII variable from variable service.
469 @param VariableGuid The Variable GUID.
470 @param VariableName The Variable Name.
471 @param VariableData The output data.
472 @param VariableSize The size of the variable.
474 @retval EFI_SUCCESS Operation successful.
475 @retval EFI_NOT_FOUND Variablel not found.
479 IN CONST EFI_GUID
*VariableGuid
,
480 IN UINT16
*VariableName
,
481 OUT VOID
**VariableData
,
482 OUT UINTN
*VariableSize
488 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariablePpi
;
490 Status
= PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid
, 0, NULL
, (VOID
**) &VariablePpi
);
491 ASSERT_EFI_ERROR (Status
);
494 Status
= VariablePpi
->GetVariable (
497 (EFI_GUID
*) VariableGuid
,
503 if (Status
== EFI_BUFFER_TOO_SMALL
) {
504 Status
= PeiServicesAllocatePool (Size
, &Buffer
);
505 ASSERT_EFI_ERROR (Status
);
507 Status
= VariablePpi
->GetVariable (
509 (UINT16
*) VariableName
,
510 (EFI_GUID
*) VariableGuid
,
515 ASSERT_EFI_ERROR (Status
);
517 *VariableSize
= Size
;
518 *VariableData
= Buffer
;
523 return EFI_NOT_FOUND
;
527 Find the local token number according to system SKU ID.
529 @param LocalTokenNumber PCD token number
530 @param Size The size of PCD entry.
532 @return Token number according to system SKU ID.
536 GetSkuEnabledTokenNumber (
537 UINT32 LocalTokenNumber
,
541 PEI_PCD_DATABASE
*PeiPcdDb
;
548 PeiPcdDb
= GetPcdDatabase ();
550 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
552 SkuHead
= (SKU_HEAD
*) ((UINT8
*)PeiPcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
553 Value
= (UINT8
*) ((UINT8
*)PeiPcdDb
+ (SkuHead
->SkuDataStartOffset
));
554 SkuIdTable
= (SKU_ID
*) ((UINT8
*)PeiPcdDb
+ (SkuHead
->SkuIdTableOffset
));
557 // Find the current system's SKU ID entry in SKU ID table.
560 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
561 if (PeiPcdDb
->SystemSkuId
== SkuIdTable
[Index
+ 1]) {
568 // Find the default SKU ID entry in SKU ID table.
571 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
572 if (0 == SkuIdTable
[Index
+ 1]) {
577 ASSERT (Index
< SkuIdTable
[0]);
579 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
581 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
582 return (UINT32
) ((Value
- (UINT8
*) PeiPcdDb
) | PCD_TYPE_VPD
);
585 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
586 return (UINT32
) ((Value
- (UINT8
*) PeiPcdDb
) | PCD_TYPE_HII
);
588 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
589 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
590 return (UINT32
) ((Value
- (UINT8
*) PeiPcdDb
) | PCD_TYPE_HII
| PCD_TYPE_STRING
);
592 case PCD_TYPE_STRING
:
593 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
594 return (UINT32
) ((Value
- (UINT8
*) PeiPcdDb
) | PCD_TYPE_STRING
);
597 Value
+= Size
* Index
;
598 return (UINT32
) ((Value
- (UINT8
*) PeiPcdDb
) | PCD_TYPE_DATA
);
610 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
611 has registered callback function.
613 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
615 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
617 @param TokenNumber PCD token number generated by build tools.
618 @param Data Value want to be set for this PCD entry
619 @param Size The size of value
623 InvokeCallbackOnSet (
625 CONST EFI_GUID
*Guid
, OPTIONAL
631 EFI_HOB_GUID_TYPE
*GuidHob
;
632 PCD_PPI_CALLBACK
*CallbackTable
;
634 PEI_PCD_DATABASE
*PeiPcdDb
;
635 UINT32 LocalTokenCount
;
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.
644 PeiPcdDb
= GetPcdDatabase ();
645 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
648 // EBC compiler is very choosy. It may report warning about comparison
649 // between UINTN and 0 . So we add 1 in each size of the
651 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
654 GuidHob
= GetFirstGuidHob (&gEfiCallerIdGuid
);
655 ASSERT (GuidHob
!= NULL
);
657 CallbackTable
= GET_GUID_HOB_DATA (GuidHob
);
659 CallbackTable
+= (TokenNumber
* PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
));
661 for (Idx
= 0; Idx
< PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry
); Idx
++) {
662 if (CallbackTable
[Idx
] != NULL
) {
663 CallbackTable
[Idx
] (Guid
,
664 (Guid
== NULL
) ? (TokenNumber
+ 1) : ExTokenNumber
,
673 Wrapper function for setting non-pointer type value for a PCD entry.
675 @param TokenNumber Pcd token number autogenerated by build tools.
676 @param Data Value want to be set for PCD entry
677 @param Size Size of value.
679 @return status of SetWorker.
684 IN UINTN TokenNumber
,
689 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
693 Set value for an PCD entry
695 @param TokenNumber Pcd token number autogenerated by build tools.
696 @param Data Value want to be set for PCD entry
697 @param Size Size of value.
698 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
699 If False, the type of PCD entry's value is not Pointer.
701 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
702 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
703 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
704 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
705 range of UINT8, UINT16, UINT32, UINT64
706 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
710 IN UINTN TokenNumber
,
716 UINT32 LocalTokenNumber
;
717 UINTN PeiNexTokenNumber
;
718 PEI_PCD_DATABASE
*PeiPcdDb
;
719 STRING_HEAD StringTableIdx
;
723 UINT32 LocalTokenCount
;
725 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
726 return EFI_UNSUPPORTED
;
730 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
731 // We have to decrement TokenNumber by 1 to make it usable
732 // as the array index.
735 PeiPcdDb
= GetPcdDatabase ();
736 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
738 // EBC compiler is very choosy. It may report warning about comparison
739 // between UINTN and 0 . So we add 1 in each size of the
741 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
745 // Get MaxSize first, then check new size with max buffer size.
747 GetPtrTypeSize (TokenNumber
, &MaxSize
, PeiPcdDb
);
748 if (*Size
> MaxSize
) {
750 return EFI_INVALID_PARAMETER
;
753 if (*Size
!= PeiPcdGetSize (TokenNumber
+ 1)) {
754 return EFI_INVALID_PARAMETER
;
759 // We only invoke the callback function for Dynamic Type PCD Entry.
760 // For Dynamic EX PCD entry, we have invoked the callback function for Dynamic EX
761 // type PCD entry in ExSetWorker.
763 PeiNexTokenNumber
= PeiPcdDb
->LocalTokenCount
- PeiPcdDb
->ExTokenCount
;
764 if (TokenNumber
+ 1 < PeiNexTokenNumber
+ 1) {
765 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
768 LocalTokenNumber
= GetLocalTokenNumber (PeiPcdDb
, TokenNumber
+ 1);
770 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
771 InternalData
= (VOID
*) ((UINT8
*) PeiPcdDb
+ Offset
);
773 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
776 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
779 return EFI_INVALID_PARAMETER
;
782 case PCD_TYPE_STRING
:
783 if (SetPtrTypeSize (TokenNumber
, Size
, PeiPcdDb
)) {
784 StringTableIdx
= *((STRING_HEAD
*)InternalData
);
785 CopyMem ((UINT8
*)PeiPcdDb
+ PeiPcdDb
->StringTableOffset
+ StringTableIdx
, Data
, *Size
);
788 return EFI_INVALID_PARAMETER
;
794 if (SetPtrTypeSize (TokenNumber
, Size
, PeiPcdDb
)) {
795 CopyMem (InternalData
, Data
, *Size
);
798 return EFI_INVALID_PARAMETER
;
804 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
808 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
812 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
816 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
821 return EFI_NOT_FOUND
;
828 return EFI_NOT_FOUND
;
833 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
835 @param ExTokenNumber Token number for dynamic-ex PCD.
836 @param Guid Token space guid for dynamic-ex PCD.
837 @param Data Value want to be set.
838 @param SetSize The size of value.
840 @return status of ExSetWorker().
845 IN UINTN ExTokenNumber
,
846 IN CONST EFI_GUID
*Guid
,
851 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &Size
, FALSE
);
855 Set value for a dynamic-ex PCD entry.
857 This routine find the local token number according to dynamic-ex PCD's token
858 space guid and token number firstly, and invoke callback function if this PCD
859 entry registered callback function. Finally, invoken general SetWorker to set
862 @param ExTokenNumber Dynamic-ex PCD token number.
863 @param Guid Token space guid for dynamic-ex PCD.
864 @param Data PCD value want to be set
865 @param SetSize Size of value.
866 @param PtrType If TRUE, this PCD entry is pointer type.
867 If FALSE, this PCD entry is not pointer type.
869 @return status of SetWorker().
874 IN UINTN ExTokenNumber
,
875 IN CONST EFI_GUID
*Guid
,
883 if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable
)) {
884 return EFI_UNSUPPORTED
;
887 TokenNumber
= GetExPcdTokenNumber (Guid
, ExTokenNumber
);
888 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
889 return EFI_NOT_FOUND
;
892 InvokeCallbackOnSet (ExTokenNumber
, Guid
, TokenNumber
, Data
, *Size
);
894 return SetWorker (TokenNumber
, Data
, Size
, PtrType
);
899 Wrapper function for get PCD value for dynamic-ex PCD.
901 @param Guid Token space guid for dynamic-ex PCD.
902 @param ExTokenNumber Token number for dyanmic-ex PCD.
903 @param GetSize The size of dynamic-ex PCD value.
905 @return PCD entry in PCD database.
910 IN CONST EFI_GUID
*Guid
,
911 IN UINTN ExTokenNumber
,
915 return GetWorker (GetExPcdTokenNumber (Guid
, ExTokenNumber
), GetSize
);
919 Get the PCD entry pointer in PCD database.
921 This routine will visit PCD database to find the PCD entry according to given
922 token number. The given token number is autogened by build tools and it will be
923 translated to local token number. Local token number contains PCD's type and
924 offset of PCD entry in PCD database.
926 @param TokenNumber Token's number, it is autogened by build tools
927 @param GetSize The size of token's value
929 @return PCD entry pointer in PCD database
934 IN UINTN TokenNumber
,
941 VARIABLE_HEAD
*VariableHead
;
946 STRING_HEAD StringTableIdx
;
947 PEI_PCD_DATABASE
*PeiPcdDb
;
948 UINT32 LocalTokenNumber
;
949 UINT32 LocalTokenCount
;
952 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
953 // We have to decrement TokenNumber by 1 to make it usable
954 // as the array index.
958 PeiPcdDb
= GetPcdDatabase ();
959 LocalTokenCount
= PeiPcdDb
->LocalTokenCount
;
961 // EBC compiler is very choosy. It may report warning about comparison
962 // between UINTN and 0 . So we add 1 in each size of the
964 ASSERT (TokenNumber
+ 1 < (LocalTokenCount
+ 1));
966 ASSERT ((GetSize
== PeiPcdGetSize(TokenNumber
+ 1)) || (GetSize
== 0));
968 LocalTokenNumber
= GetLocalTokenNumber (PeiPcdDb
, TokenNumber
+ 1);
970 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
971 StringTable
= (UINT8
*)PeiPcdDb
+ PeiPcdDb
->StringTableOffset
;
973 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
977 VpdHead
= (VPD_HEAD
*) ((UINT8
*)PeiPcdDb
+ Offset
);
978 return (VOID
*) (UINTN
) (PcdGet32 (PcdVpdBaseAddress
) + VpdHead
->Offset
);
981 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
984 VariableHead
= (VARIABLE_HEAD
*) ((UINT8
*)PeiPcdDb
+ Offset
);
986 Guid
= (EFI_GUID
*) ((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
) + VariableHead
->GuidTableIndex
;
987 Name
= (UINT16
*)&StringTable
[VariableHead
->StringIndex
];
989 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
991 if (Status
== EFI_SUCCESS
) {
992 return (VOID
*) ((UINT8
*) Data
+ VariableHead
->Offset
);
995 // Return the default value specified by Platform Integrator
997 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
998 return (VOID
*)&StringTable
[*(STRING_HEAD
*)((UINT8
*)PeiPcdDb
+ VariableHead
->DefaultValueOffset
)];
1000 return (VOID
*) ((UINT8
*) PeiPcdDb
+ VariableHead
->DefaultValueOffset
);
1006 return (VOID
*) ((UINT8
*)PeiPcdDb
+ Offset
);
1008 case PCD_TYPE_STRING
:
1009 StringTableIdx
= * (STRING_HEAD
*) ((UINT8
*) PeiPcdDb
+ Offset
);
1010 return (VOID
*) (&StringTable
[StringTableIdx
]);
1025 Get Token Number according to dynamic-ex PCD's {token space guid:token number}
1027 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1028 in DEC file. PCD database maintain a mapping table that translate pair of {token
1029 space guid: token number} to Token Number.
1031 @param Guid Token space guid for dynamic-ex PCD entry.
1032 @param ExTokenNumber Dynamic-ex PCD token number.
1034 @return Token Number for dynamic-ex PCD.
1038 GetExPcdTokenNumber (
1039 IN CONST EFI_GUID
*Guid
,
1040 IN UINTN ExTokenNumber
1044 DYNAMICEX_MAPPING
*ExMap
;
1045 EFI_GUID
*GuidTable
;
1046 EFI_GUID
*MatchGuid
;
1048 PEI_PCD_DATABASE
*PeiPcdDb
;
1050 PeiPcdDb
= GetPcdDatabase();
1052 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->ExMapTableOffset
);
1053 GuidTable
= (EFI_GUID
*)((UINT8
*)PeiPcdDb
+ PeiPcdDb
->GuidTableOffset
);
1055 MatchGuid
= ScanGuid (GuidTable
, PeiPcdDb
->GuidTableCount
* sizeof(EFI_GUID
), Guid
);
1057 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1058 // error in the BUILD system.
1060 ASSERT (MatchGuid
!= NULL
);
1062 MatchGuidIdx
= MatchGuid
- GuidTable
;
1064 for (Index
= 0; Index
< PeiPcdDb
->ExTokenCount
; Index
++) {
1065 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1066 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1067 return ExMap
[Index
].TokenNumber
;
1071 return PCD_INVALID_TOKEN_NUMBER
;
1075 Get PCD database from GUID HOB in PEI phase.
1077 @return Pointer to PCD database.
1085 EFI_HOB_GUID_TYPE
*GuidHob
;
1087 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
1088 ASSERT (GuidHob
!= NULL
);
1090 return (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
1094 Get SKU ID table from PCD database.
1096 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1097 @param Database PCD database.
1099 @return Pointer to SKU ID array table
1104 IN UINTN LocalTokenNumberTableIdx
,
1105 IN PEI_PCD_DATABASE
*Database
1109 UINTN LocalTokenNumber
;
1111 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1113 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1115 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1117 return (SKU_ID
*) ((UINT8
*)Database
+ SkuHead
->SkuIdTableOffset
);
1122 Get index of PCD entry in size table.
1124 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1125 @param Database Pointer to PCD database in PEI phase.
1127 @return index of PCD entry in size table.
1132 IN UINTN LocalTokenNumberTableIdx
,
1133 IN PEI_PCD_DATABASE
*Database
1138 UINTN LocalTokenNumber
;
1143 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
1144 LocalTokenNumber
= *((UINT32
*)((UINT8
*)Database
+ Database
->LocalTokenNumberTableOffset
) + Index
);
1146 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1148 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1151 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1153 // We have only two entry for VPD enabled PCD entry:
1156 // Current size is equal to MAX size.
1160 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1162 // We have only two entry for Non-Sku enabled PCD entry:
1169 // We have these entry for SKU enabled PCD entry
1171 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1173 SkuIdTable
= GetSkuIdArray (Index
, Database
);
1174 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1181 return SizeTableIdx
;