2 Help functions used by PCD DXE driver.
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/DxeServicesLib.h>
18 PCD_DATABASE mPcdDatabase
;
20 UINT32 mPcdTotalTokenCount
;
21 UINT32 mPeiLocalTokenCount
;
22 UINT32 mDxeLocalTokenCount
;
23 UINT32 mPeiNexTokenCount
;
24 UINT32 mDxeNexTokenCount
;
25 UINT32 mPeiExMapppingTableSize
;
26 UINT32 mDxeExMapppingTableSize
;
27 UINT32 mPeiGuidTableSize
;
28 UINT32 mDxeGuidTableSize
;
30 BOOLEAN mPeiExMapTableEmpty
;
31 BOOLEAN mDxeExMapTableEmpty
;
32 BOOLEAN mPeiDatabaseEmpty
;
34 LIST_ENTRY
*mCallbackFnTable
;
35 EFI_GUID
**TmpTokenSpaceBuffer
;
36 UINTN TmpTokenSpaceBufferCount
;
39 Get Local Token Number by Token Number.
41 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
42 If FALSE, the pcd entry is initialized in DXE phase.
43 @param[in] TokenNumber The PCD token number.
45 @return Local Token Number.
53 UINT32
*LocalTokenNumberTable
;
54 UINT32 LocalTokenNumber
;
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.
65 LocalTokenNumberTable
= IsPeiDb
? (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
) :
66 (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
67 TokenNumber
= IsPeiDb
? TokenNumber
: TokenNumber
- mPeiLocalTokenCount
;
69 LocalTokenNumber
= LocalTokenNumberTable
[TokenNumber
];
71 Size
= (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
73 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
75 GetPtrTypeSize (TokenNumber
, &MaxSize
);
79 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
, IsPeiDb
);
82 return LocalTokenNumber
;
86 Get PCD type by Local Token Number.
88 @param[in] LocalTokenNumber The PCD local token number.
94 IN UINT32 LocalTokenNumber
97 switch (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) {
98 case PCD_DATUM_TYPE_POINTER
:
99 return EFI_PCD_TYPE_PTR
;
100 case PCD_DATUM_TYPE_UINT8
:
101 if (LocalTokenNumber
& PCD_DATUM_TYPE_UINT8_BOOLEAN
) {
102 return EFI_PCD_TYPE_BOOL
;
104 return EFI_PCD_TYPE_8
;
106 case PCD_DATUM_TYPE_UINT16
:
107 return EFI_PCD_TYPE_16
;
108 case PCD_DATUM_TYPE_UINT32
:
109 return EFI_PCD_TYPE_32
;
110 case PCD_DATUM_TYPE_UINT64
:
111 return EFI_PCD_TYPE_64
;
114 return EFI_PCD_TYPE_8
;
121 @param[in] OnlyTokenSpaceName If TRUE, only need to get the TokenSpaceCName.
122 If FALSE, need to get the full PCD name.
123 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
124 If FALSE, the pcd entry is initialized in DXE phase.
125 @param[in] TokenNumber The PCD token number.
127 @return The TokenSpaceCName or full PCD name.
131 IN BOOLEAN OnlyTokenSpaceName
,
136 PCD_DATABASE_INIT
*Database
;
138 PCD_NAME_INDEX
*PcdNameIndex
;
139 CHAR8
*TokenSpaceName
;
144 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
145 // We have to decrement TokenNumber by 1 to make it usable
146 // as the array index.
150 Database
= IsPeiDb
? mPcdDatabase
.PeiDb
: mPcdDatabase
.DxeDb
;
151 TokenNumber
= IsPeiDb
? TokenNumber
: TokenNumber
- mPeiLocalTokenCount
;
153 StringTable
= (UINT8
*) Database
+ Database
->StringTableOffset
;
156 // Get the PCD name index.
158 PcdNameIndex
= (PCD_NAME_INDEX
*)((UINT8
*) Database
+ Database
->PcdNameTableOffset
) + TokenNumber
;
159 TokenSpaceName
= (CHAR8
*)&StringTable
[PcdNameIndex
->TokenSpaceCNameIndex
];
160 PcdName
= (CHAR8
*)&StringTable
[PcdNameIndex
->PcdCNameIndex
];
162 if (OnlyTokenSpaceName
) {
164 // Only need to get the TokenSpaceCName.
166 Name
= AllocateCopyPool (AsciiStrSize (TokenSpaceName
), TokenSpaceName
);
169 // Need to get the full PCD name.
171 Name
= AllocateZeroPool (AsciiStrSize (TokenSpaceName
) + AsciiStrSize (PcdName
));
173 // Catenate TokenSpaceCName and PcdCName with a '.' to form the full PCD name.
175 AsciiStrCat (Name
, TokenSpaceName
);
176 Name
[AsciiStrSize (TokenSpaceName
) - sizeof (CHAR8
)] = '.';
177 AsciiStrCat (Name
, PcdName
);
184 Retrieve additional information associated with a PCD token.
186 This includes information such as the type of value the TokenNumber is associated with as well as possible
187 human readable name that is associated with the token.
189 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
190 If FALSE, the pcd entry is initialized in DXE phase.
191 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
192 @param[in] TokenNumber The PCD token number.
193 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
194 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
196 @retval EFI_SUCCESS The PCD information was returned successfully
197 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
202 IN CONST EFI_GUID
*Guid
,
203 IN UINTN TokenNumber
,
204 OUT EFI_PCD_INFO
*PcdInfo
207 PCD_DATABASE_INIT
*Database
;
211 DYNAMICEX_MAPPING
*ExMapTable
;
213 UINT32 LocalTokenNumber
;
215 Database
= IsPeiDb
? mPcdDatabase
.PeiDb
: mPcdDatabase
.DxeDb
;
217 GuidTable
= (EFI_GUID
*)((UINT8
*)Database
+ Database
->GuidTableOffset
);
218 MatchGuid
= ScanGuid (GuidTable
, Database
->GuidTableCount
* sizeof(EFI_GUID
), Guid
);
220 if (MatchGuid
== NULL
) {
221 return EFI_NOT_FOUND
;
224 GuidTableIdx
= MatchGuid
- GuidTable
;
226 ExMapTable
= (DYNAMICEX_MAPPING
*)((UINT8
*)Database
+ Database
->ExMapTableOffset
);
229 // Find the PCD by GuidTableIdx and ExTokenNumber in ExMapTable.
231 for (Index
= 0; Index
< Database
->ExTokenCount
; Index
++) {
232 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
233 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
235 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
236 // PcdSize to 0 and PcdName to the null-terminated ASCII string
237 // associated with the token's namespace Guid.
239 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
240 PcdInfo
->PcdSize
= 0;
242 // Here use one representative in the token space to get the TokenSpaceCName.
244 PcdInfo
->PcdName
= GetPcdName (TRUE
, IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
246 } else if (ExMapTable
[Index
].ExTokenNumber
== TokenNumber
) {
247 PcdInfo
->PcdSize
= DxePcdGetSize (ExMapTable
[Index
].TokenNumber
);
248 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
249 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
250 PcdInfo
->PcdName
= GetPcdName (FALSE
, IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
256 return EFI_NOT_FOUND
;
260 Retrieve additional information associated with a PCD token.
262 This includes information such as the type of value the TokenNumber is associated with as well as possible
263 human readable name that is associated with the token.
265 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
266 @param[in] TokenNumber The PCD token number.
267 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
268 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
270 @retval EFI_SUCCESS The PCD information was returned successfully.
271 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
275 IN CONST EFI_GUID
*Guid
,
276 IN UINTN TokenNumber
,
277 OUT EFI_PCD_INFO
*PcdInfo
281 BOOLEAN PeiExMapTableEmpty
;
282 BOOLEAN DxeExMapTableEmpty
;
283 UINT32 LocalTokenNumber
;
286 ASSERT (PcdInfo
!= NULL
);
288 Status
= EFI_NOT_FOUND
;
289 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
290 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
293 if (((TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) && (TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) ||
294 ((TokenNumber
+ 1 > (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1)))) {
295 return EFI_NOT_FOUND
;
296 } else if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
298 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
299 // PcdSize to 0 and PcdName to NULL for default Token Space.
301 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
302 PcdInfo
->PcdSize
= 0;
303 PcdInfo
->PcdName
= NULL
;
305 PcdInfo
->PcdSize
= DxePcdGetSize (TokenNumber
);
307 if ((TokenNumber
+ 1 <= mPeiNexTokenCount
+ 1)) {
310 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
);
311 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
312 PcdInfo
->PcdName
= GetPcdName (FALSE
, IsPeiDb
, TokenNumber
);
317 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
318 return EFI_NOT_FOUND
;
321 if (!PeiExMapTableEmpty
) {
322 Status
= ExGetPcdInfo (
330 if (Status
== EFI_SUCCESS
) {
334 if (!DxeExMapTableEmpty
) {
335 Status
= ExGetPcdInfo (
347 Get the PCD entry pointer in PCD database.
349 This routine will visit PCD database to find the PCD entry according to given
350 token number. The given token number is autogened by build tools and it will be
351 translated to local token number. Local token number contains PCD's type and
352 offset of PCD entry in PCD database.
354 @param TokenNumber Token's number, it is autogened by build tools
355 @param GetSize The size of token's value
357 @return PCD entry pointer in PCD database
362 IN UINTN TokenNumber
,
370 VARIABLE_HEAD
*VariableHead
;
371 UINT8
*VaraiableDefaultBuffer
;
376 UINTN TmpTokenNumber
;
379 UINT32 LocalTokenNumber
;
381 STRING_HEAD StringTableIdx
;
385 // Aquire lock to prevent reentrance from TPL_CALLBACK level
387 EfiAcquireLock (&mPcdDatabaseLock
);
391 ASSERT (TokenNumber
> 0);
393 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
394 // We have to decrement TokenNumber by 1 to make it usable
395 // as the array index.
399 TmpTokenNumber
= TokenNumber
;
402 // EBC compiler is very choosy. It may report warning about comparison
403 // between UINTN and 0 . So we add 1 in each size of the
406 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
408 ASSERT ((GetSize
== DxePcdGetSize (TokenNumber
+ 1)) || (GetSize
== 0));
410 // EBC compiler is very choosy. It may report warning about comparison
411 // between UINTN and 0 . So we add 1 in each size of the
413 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1) ? TRUE
: FALSE
);
415 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
+ 1);
417 PcdDb
= IsPeiDb
? ((UINT8
*) mPcdDatabase
.PeiDb
) : ((UINT8
*) mPcdDatabase
.DxeDb
);
420 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->StringTableOffset
);
422 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->StringTableOffset
);
426 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
428 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
430 VpdHead
= (VPD_HEAD
*) ((UINT8
*) PcdDb
+ Offset
);
431 RetPtr
= (VOID
*) (UINTN
) (PcdGet32 (PcdVpdBaseAddress
) + VpdHead
->Offset
);
435 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
438 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
440 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
443 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
444 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
445 Name
= (UINT16
*)(StringTable
+ VariableHead
->StringIndex
);
447 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
449 // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is the index of
450 // string array in string table.
452 StringTableIdx
= *(STRING_HEAD
*)((UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
);
453 VaraiableDefaultBuffer
= (VOID
*) (StringTable
+ StringTableIdx
);
455 VaraiableDefaultBuffer
= (UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
;
457 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
458 if (Status
== EFI_SUCCESS
) {
461 // It is a pointer type. So get the MaxSize reserved for
464 GetPtrTypeSize (TmpTokenNumber
, &GetSize
);
467 // If the operation is successful, we copy the data
468 // to the default value buffer in the PCD Database.
469 // So that we can free the Data allocated in GetHiiVariable.
471 CopyMem (VaraiableDefaultBuffer
, Data
+ VariableHead
->Offset
, GetSize
);
474 RetPtr
= (VOID
*) VaraiableDefaultBuffer
;
477 case PCD_TYPE_STRING
:
478 StringTableIdx
= *(STRING_HEAD
*)((UINT8
*) PcdDb
+ Offset
);
479 RetPtr
= (VOID
*) (StringTable
+ StringTableIdx
);
483 RetPtr
= (VOID
*) ((UINT8
*) PcdDb
+ Offset
);
492 EfiReleaseLock (&mPcdDatabaseLock
);
499 Register the callback function for a PCD entry.
501 This routine will register a callback function to a PCD entry by given token number
502 and token space guid.
504 @param TokenNumber PCD token's number, it is autogened by build tools.
505 @param Guid PCD token space's guid,
506 if not NULL, this PCD is dynamicEx type PCD.
507 @param CallBackFunction Callback function pointer
509 @return EFI_SUCCESS Always success for registering callback function.
513 DxeRegisterCallBackWorker (
514 IN UINTN TokenNumber
,
515 IN CONST EFI_GUID
*Guid
, OPTIONAL
516 IN PCD_PROTOCOL_CALLBACK CallBackFunction
519 CALLBACK_FN_ENTRY
*FnTableEntry
;
520 LIST_ENTRY
*ListHead
;
521 LIST_ENTRY
*ListNode
;
524 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
528 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
529 // We have to decrement TokenNumber by 1 to make it usable
530 // as the array index of mCallbackFnTable[].
532 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
533 ListNode
= GetFirstNode (ListHead
);
535 while (ListNode
!= ListHead
) {
536 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
538 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
540 // We only allow a Callback function to be register once
541 // for a TokenNumber. So just return EFI_SUCCESS
545 ListNode
= GetNextNode (ListHead
, ListNode
);
548 FnTableEntry
= AllocatePool (sizeof(CALLBACK_FN_ENTRY
));
549 ASSERT (FnTableEntry
!= NULL
);
551 FnTableEntry
->CallbackFn
= CallBackFunction
;
552 InsertTailList (ListHead
, &FnTableEntry
->Node
);
558 UnRegister the callback function for a PCD entry.
560 This routine will unregister a callback function to a PCD entry by given token number
561 and token space guid.
563 @param TokenNumber PCD token's number, it is autogened by build tools.
564 @param Guid PCD token space's guid.
565 if not NULL, this PCD is dynamicEx type PCD.
566 @param CallBackFunction Callback function pointer
568 @retval EFI_SUCCESS Callback function is success to be unregister.
569 @retval EFI_INVALID_PARAMETER Can not find the PCD entry by given token number.
572 DxeUnRegisterCallBackWorker (
573 IN UINTN TokenNumber
,
574 IN CONST EFI_GUID
*Guid
, OPTIONAL
575 IN PCD_PROTOCOL_CALLBACK CallBackFunction
578 CALLBACK_FN_ENTRY
*FnTableEntry
;
579 LIST_ENTRY
*ListHead
;
580 LIST_ENTRY
*ListNode
;
583 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
587 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
588 // We have to decrement TokenNumber by 1 to make it usable
589 // as the array index of mCallbackFnTable[].
591 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
592 ListNode
= GetFirstNode (ListHead
);
594 while (ListNode
!= ListHead
) {
595 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
597 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
599 // We only allow a Callback function to be register once
600 // for a TokenNumber. So we can safely remove the Node from
601 // the Link List and return EFI_SUCCESS.
603 RemoveEntryList (ListNode
);
604 FreePool (FnTableEntry
);
608 ListNode
= GetNextNode (ListHead
, ListNode
);
611 return EFI_INVALID_PARAMETER
;
615 Get next token number in given token space.
617 This routine is used for dynamicEx type PCD. It will firstly scan token space
618 table to get token space according to given token space guid. Then scan given
619 token number in found token space, if found, then return next token number in
622 @param Guid Token space guid. Next token number will be scaned in
624 @param TokenNumber Token number.
625 If PCD_INVALID_TOKEN_NUMBER, return first token number in
627 If not PCD_INVALID_TOKEN_NUMBER, return next token number
628 in token space table.
629 @param GuidTable Token space guid table. It will be used for scan token space
630 by given token space guid.
631 @param SizeOfGuidTable The size of guid table.
632 @param ExMapTable DynamicEx token number mapping table.
633 @param SizeOfExMapTable The size of dynamicEx token number mapping table.
635 @retval EFI_NOT_FOUND Can not given token space or token number.
636 @retval EFI_SUCCESS Success to get next token number.
640 ExGetNextTokeNumber (
641 IN CONST EFI_GUID
*Guid
,
642 IN OUT UINTN
*TokenNumber
,
643 IN EFI_GUID
*GuidTable
,
644 IN UINTN SizeOfGuidTable
,
645 IN DYNAMICEX_MAPPING
*ExMapTable
,
646 IN UINTN SizeOfExMapTable
653 UINTN ExMapTableCount
;
656 // Scan token space guid
658 MatchGuid
= ScanGuid (GuidTable
, SizeOfGuidTable
, Guid
);
659 if (MatchGuid
== NULL
) {
660 return EFI_NOT_FOUND
;
664 // Find the token space table in dynamicEx mapping table.
667 GuidTableIdx
= MatchGuid
- GuidTable
;
668 ExMapTableCount
= SizeOfExMapTable
/ sizeof(ExMapTable
[0]);
669 for (Index
= 0; Index
< ExMapTableCount
; Index
++) {
670 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
678 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
679 // token number in found token space.
681 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
682 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
686 for ( ; Index
< ExMapTableCount
; Index
++) {
687 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
692 while (Index
< ExMapTableCount
) {
694 if (Index
== ExMapTableCount
) {
696 // Exceed the length of ExMap Table
698 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
699 return EFI_NOT_FOUND
;
700 } else if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
702 // Found the next match
704 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
710 return EFI_NOT_FOUND
;
714 Find the PCD database.
716 @retval The base address of external PCD database binary.
717 @retval NULL Return NULL if not find.
724 DXE_PCD_DATABASE
*DxePcdDbBinary
;
728 DxePcdDbBinary
= NULL
;
730 // Search the External Pcd database from one section of current FFS,
731 // and read it to memory
733 Status
= GetSectionFromFfs (
736 (VOID
**) &DxePcdDbBinary
,
739 ASSERT_EFI_ERROR (Status
);
742 // Check the first bytes (Header Signature Guid) and build version.
744 if (!CompareGuid ((VOID
*)DxePcdDbBinary
, &gPcdDataBaseSignatureGuid
) ||
745 (DxePcdDbBinary
->BuildVersion
!= PCD_SERVICE_DXE_VERSION
)) {
749 return DxePcdDbBinary
;
753 Initialize the PCD database in DXE phase.
755 PCD database in DXE phase also contains PCD database in PEI phase which is copied
760 BuildPcdDxeDataBase (
764 PEI_PCD_DATABASE
*PeiDatabase
;
765 EFI_HOB_GUID_TYPE
*GuidHob
;
770 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
771 if (GuidHob
!= NULL
) {
774 // If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
775 // should not be included at all. So the GuidHob could
776 // be NULL. If it is NULL, we just copy over the DXE Default
777 // Value to PCD Database.
780 PeiDatabase
= (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
782 // Assign PCD Entries refereneced in PEI phase to PCD DATABASE
784 mPcdDatabase
.PeiDb
= PeiDatabase
;
788 // Assign PCD Entries with default value to PCD DATABASE
790 mPcdDatabase
.DxeDb
= LocateExPcdBinary ();
791 ASSERT(mPcdDatabase
.DxeDb
!= NULL
);
792 PcdDxeDbLen
= mPcdDatabase
.DxeDb
->Length
+ mPcdDatabase
.DxeDb
->UninitDataBaseSize
;
793 PcdDxeDb
= AllocateZeroPool (PcdDxeDbLen
);
794 ASSERT (PcdDxeDb
!= NULL
);
795 CopyMem (PcdDxeDb
, mPcdDatabase
.DxeDb
, mPcdDatabase
.DxeDb
->Length
);
796 FreePool (mPcdDatabase
.DxeDb
);
797 mPcdDatabase
.DxeDb
= PcdDxeDb
;
800 // Initialized the external PCD database local variables
802 mPeiLocalTokenCount
= mPcdDatabase
.PeiDb
->LocalTokenCount
;
803 mDxeLocalTokenCount
= mPcdDatabase
.DxeDb
->LocalTokenCount
;
805 mPeiExMapppingTableSize
= mPcdDatabase
.PeiDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
806 mDxeExMapppingTableSize
= mPcdDatabase
.DxeDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
807 mPeiGuidTableSize
= mPcdDatabase
.PeiDb
->GuidTableCount
* sizeof(GUID
);
808 mDxeGuidTableSize
= mPcdDatabase
.DxeDb
->GuidTableCount
* sizeof (GUID
);
810 mPcdTotalTokenCount
= mPeiLocalTokenCount
+ mDxeLocalTokenCount
;
811 mPeiNexTokenCount
= mPeiLocalTokenCount
- mPcdDatabase
.PeiDb
->ExTokenCount
;
812 mDxeNexTokenCount
= mDxeLocalTokenCount
- mPcdDatabase
.DxeDb
->ExTokenCount
;
814 mPeiExMapTableEmpty
= (mPcdDatabase
.PeiDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
815 mDxeExMapTableEmpty
= (mPcdDatabase
.DxeDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
816 mPeiDatabaseEmpty
= (mPeiLocalTokenCount
== 0) ? TRUE
: FALSE
;
818 TmpTokenSpaceBufferCount
= mPcdDatabase
.PeiDb
->ExTokenCount
+ mPcdDatabase
.DxeDb
->ExTokenCount
;
819 TmpTokenSpaceBuffer
= (EFI_GUID
**)AllocateZeroPool(TmpTokenSpaceBufferCount
* sizeof (EFI_GUID
*));
822 // Initialized the Callback Function Table
824 mCallbackFnTable
= AllocateZeroPool (mPcdTotalTokenCount
* sizeof (LIST_ENTRY
));
825 ASSERT(mCallbackFnTable
!= NULL
);
828 // EBC compiler is very choosy. It may report warning about comparison
829 // between UINTN and 0 . So we add 1 in each size of the
832 for (Index
= 0; Index
+ 1 < mPcdTotalTokenCount
+ 1; Index
++) {
833 InitializeListHead (&mCallbackFnTable
[Index
]);
838 Get Variable which contains HII type PCD entry.
840 @param VariableGuid Variable's guid
841 @param VariableName Variable's unicode name string
842 @param VariableData Variable's data pointer,
843 @param VariableSize Variable's size.
845 @return the status of gRT->GetVariable
849 IN EFI_GUID
*VariableGuid
,
850 IN UINT16
*VariableName
,
851 OUT UINT8
**VariableData
,
852 OUT UINTN
*VariableSize
863 // Firstly get the real size of HII variable
865 Status
= gRT
->GetVariable (
866 (UINT16
*)VariableName
,
874 // Allocate buffer to hold whole variable data according to variable size.
876 if (Status
== EFI_BUFFER_TOO_SMALL
) {
877 Buffer
= (UINT8
*) AllocatePool (Size
);
879 ASSERT (Buffer
!= NULL
);
881 Status
= gRT
->GetVariable (
889 ASSERT (Status
== EFI_SUCCESS
);
890 *VariableData
= Buffer
;
891 *VariableSize
= Size
;
894 // Use Default Data only when variable is not found.
895 // For other error status, correct data can't be got, and trig ASSERT().
897 ASSERT (Status
== EFI_NOT_FOUND
);
904 Find the local token number according to system SKU ID.
906 @param LocalTokenNumber PCD token number
907 @param Size The size of PCD entry.
908 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
909 If False, the PCD entry is initialized in DXE phase.
911 @return Token number according to system SKU ID.
915 GetSkuEnabledTokenNumber (
916 UINT32 LocalTokenNumber
,
928 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
930 PcdDb
= IsPeiDb
? (UINT8
*) mPcdDatabase
.PeiDb
: (UINT8
*) mPcdDatabase
.DxeDb
;
932 SkuHead
= (SKU_HEAD
*) (PcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
933 Value
= (UINT8
*) (PcdDb
+ SkuHead
->SkuDataStartOffset
);
935 SkuIdTable
= (SKU_ID
*)(PcdDb
+ SkuHead
->SkuIdTableOffset
);
937 // Find the current system's SKU ID entry in SKU ID table.
940 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
941 if (mPcdDatabase
.PeiDb
->SystemSkuId
== SkuIdTable
[Index
+ 1]) {
948 // Find the default SKU ID entry in SKU ID table.
952 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
953 if (0 == SkuIdTable
[Index
+ 1]) {
958 ASSERT (Index
< SkuIdTable
[0]);
960 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
962 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
963 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_VPD
);
966 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
967 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
);
969 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
970 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
971 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
| PCD_TYPE_STRING
);
973 case PCD_TYPE_STRING
:
974 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
975 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_STRING
);
978 Value
+= Size
* Index
;
979 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_DATA
);
992 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
993 has registered callback function.
995 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
997 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
999 @param TokenNumber PCD token number generated by build tools.
1000 @param Data Value want to be set for this PCD entry
1001 @param Size The size of value
1005 InvokeCallbackOnSet (
1006 UINT32 ExTokenNumber
,
1007 CONST EFI_GUID
*Guid
, OPTIONAL
1013 CALLBACK_FN_ENTRY
*FnTableEntry
;
1014 LIST_ENTRY
*ListHead
;
1015 LIST_ENTRY
*ListNode
;
1018 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1019 // We have to decrement TokenNumber by 1 to make it usable
1020 // as the array index of mCallbackFnTable[].
1022 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
1023 ListNode
= GetFirstNode (ListHead
);
1025 while (ListNode
!= ListHead
) {
1026 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE (ListNode
, CALLBACK_FN_ENTRY
, Node
);
1028 FnTableEntry
->CallbackFn(Guid
,
1029 (Guid
== NULL
) ? TokenNumber
: ExTokenNumber
,
1033 ListNode
= GetNextNode (ListHead
, ListNode
);
1041 Wrapper function for setting non-pointer type value for a PCD entry.
1043 @param TokenNumber Pcd token number autogenerated by build tools.
1044 @param Data Value want to be set for PCD entry
1045 @param Size Size of value.
1047 @return status of SetWorker.
1052 IN UINTN TokenNumber
,
1057 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
1062 Set value for an PCD entry
1064 @param TokenNumber Pcd token number autogenerated by build tools.
1065 @param Data Value want to be set for PCD entry
1066 @param Size Size of value.
1067 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
1068 If False, the type of PCD entry's value is not Pointer.
1070 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
1071 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
1072 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
1073 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
1074 range of UINT8, UINT16, UINT32, UINT64
1075 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
1079 IN UINTN TokenNumber
,
1086 UINT32 LocalTokenNumber
;
1087 EFI_GUID
*GuidTable
;
1091 UINTN VariableOffset
;
1093 VARIABLE_HEAD
*VariableHead
;
1098 UINTN TmpTokenNumber
;
1101 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1102 // We have to decrement TokenNumber by 1 to make it usable
1103 // as the array index.
1107 TmpTokenNumber
= TokenNumber
;
1110 // EBC compiler is very choosy. It may report warning about comparison
1111 // between UINTN and 0 . So we add 1 in each size of the
1114 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
1118 // Get MaxSize first, then check new size with max buffer size.
1120 GetPtrTypeSize (TokenNumber
, &MaxSize
);
1121 if (*Size
> MaxSize
) {
1123 return EFI_INVALID_PARAMETER
;
1126 if (*Size
!= DxePcdGetSize (TokenNumber
+ 1)) {
1127 return EFI_INVALID_PARAMETER
;
1132 // EBC compiler is very choosy. It may report warning about comparison
1133 // between UINTN and 0 . So we add 1 in each size of the
1136 if ((TokenNumber
+ 1 < mPeiNexTokenCount
+ 1) ||
1137 (TokenNumber
+ 1 >= mPeiLocalTokenCount
+ 1 && TokenNumber
+ 1 < (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1))) {
1138 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
1142 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1144 EfiAcquireLock (&mPcdDatabaseLock
);
1147 // EBC compiler is very choosy. It may report warning about comparison
1148 // between UINTN and 0 . So we add 1 in each size of the
1151 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1) ? TRUE
: FALSE
);
1153 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
+ 1);
1155 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
1157 PcdDb
= IsPeiDb
? ((UINT8
*) mPcdDatabase
.PeiDb
) : ((UINT8
*) mPcdDatabase
.DxeDb
);
1160 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->StringTableOffset
);
1162 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->StringTableOffset
);
1166 InternalData
= PcdDb
+ Offset
;
1168 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
1171 Status
= EFI_INVALID_PARAMETER
;
1174 case PCD_TYPE_STRING
:
1175 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1176 CopyMem (StringTable
+ *((STRING_HEAD
*)InternalData
), Data
, *Size
);
1177 Status
= EFI_SUCCESS
;
1179 Status
= EFI_INVALID_PARAMETER
;
1183 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
1186 if (!SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1187 Status
= EFI_INVALID_PARAMETER
;
1193 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1195 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1198 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
1200 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
1201 Name
= (UINT16
*) (StringTable
+ VariableHead
->StringIndex
);
1202 VariableOffset
= VariableHead
->Offset
;
1203 Status
= SetHiiVariable (Guid
, Name
, Data
, *Size
, VariableOffset
);
1205 if (EFI_NOT_FOUND
== Status
) {
1206 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
1208 StringTable
+ *(STRING_HEAD
*)(PcdDb
+ VariableHead
->DefaultValueOffset
),
1213 CopyMem (PcdDb
+ VariableHead
->DefaultValueOffset
, Data
, *Size
);
1215 Status
= EFI_SUCCESS
;
1221 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1222 CopyMem (InternalData
, Data
, *Size
);
1223 Status
= EFI_SUCCESS
;
1225 Status
= EFI_INVALID_PARAMETER
;
1230 Status
= EFI_SUCCESS
;
1233 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
1236 case sizeof(UINT16
):
1237 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
1240 case sizeof(UINT32
):
1241 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
1244 case sizeof(UINT64
):
1245 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
1250 Status
= EFI_NOT_FOUND
;
1257 Status
= EFI_NOT_FOUND
;
1261 EfiReleaseLock (&mPcdDatabaseLock
);
1267 Wrapper function for get PCD value for dynamic-ex PCD.
1269 @param Guid Token space guid for dynamic-ex PCD.
1270 @param ExTokenNumber Token number for dynamic-ex PCD.
1271 @param GetSize The size of dynamic-ex PCD value.
1273 @return PCD entry in PCD database.
1278 IN CONST EFI_GUID
*Guid
,
1279 IN UINTN ExTokenNumber
,
1283 return GetWorker(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
), GetSize
);
1287 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
1289 @param ExTokenNumber Token number for dynamic-ex PCD.
1290 @param Guid Token space guid for dynamic-ex PCD.
1291 @param Data Value want to be set.
1292 @param SetSize The size of value.
1294 @return status of ExSetWorker().
1299 IN UINTN ExTokenNumber
,
1300 IN CONST EFI_GUID
*Guid
,
1305 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &SetSize
, FALSE
);
1309 Set value for a dynamic-ex PCD entry.
1311 This routine find the local token number according to dynamic-ex PCD's token
1312 space guid and token number firstly, and invoke callback function if this PCD
1313 entry registered callback function. Finally, invoken general SetWorker to set
1316 @param ExTokenNumber Dynamic-ex PCD token number.
1317 @param Guid Token space guid for dynamic-ex PCD.
1318 @param Data PCD value want to be set
1319 @param SetSize Size of value.
1320 @param PtrType If TRUE, this PCD entry is pointer type.
1321 If FALSE, this PCD entry is not pointer type.
1323 @return status of SetWorker().
1328 IN UINTN ExTokenNumber
,
1329 IN CONST EFI_GUID
*Guid
,
1331 IN OUT UINTN
*SetSize
,
1337 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
);
1339 InvokeCallbackOnSet ((UINT32
) ExTokenNumber
, Guid
, TokenNumber
, Data
, *SetSize
);
1341 return SetWorker (TokenNumber
, Data
, SetSize
, PtrType
);
1346 Set value for HII-type PCD.
1348 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
1349 HII-type PCD is to visit this variable.
1351 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
1352 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
1353 @param Data Value want to be set.
1354 @param DataSize Size of value
1355 @param Offset Value offset of HII-type PCD in variable.
1357 @return status of GetVariable()/SetVariable().
1362 IN EFI_GUID
*VariableGuid
,
1363 IN UINT16
*VariableName
,
1364 IN CONST VOID
*Data
,
1379 // Try to get original variable size information.
1381 Status
= gRT
->GetVariable (
1382 (UINT16
*)VariableName
,
1389 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1391 // Patch new PCD's value to offset in given HII variable.
1393 if (Size
>= (DataSize
+ Offset
)) {
1396 SetSize
= DataSize
+ Offset
;
1398 Buffer
= AllocatePool (SetSize
);
1399 ASSERT (Buffer
!= NULL
);
1401 Status
= gRT
->GetVariable (
1409 ASSERT_EFI_ERROR (Status
);
1411 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1413 Status
= gRT
->SetVariable (
1423 } else if (Status
== EFI_NOT_FOUND
) {
1425 // If variable does not exist, a new variable need to be created.
1428 Size
= Offset
+ DataSize
;
1430 Buffer
= AllocateZeroPool (Size
);
1431 ASSERT (Buffer
!= NULL
);
1433 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1435 Status
= gRT
->SetVariable (
1438 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1448 // If we drop to here, the value is failed to be written in to variable area
1449 // So, we will save the data in the PCD Database's volatile area.
1455 Get Token Number according to dynamic-ex PCD's {token space guid:token number}
1457 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1458 in DEC file. PCD database maintain a mapping table that translate pair of {token
1459 space guid: token number} to Token Number.
1461 @param Guid Token space guid for dynamic-ex PCD entry.
1462 @param ExTokenNumber Dynamic-ex PCD token number.
1464 @return Token Number for dynamic-ex PCD.
1468 GetExPcdTokenNumber (
1469 IN CONST EFI_GUID
*Guid
,
1470 IN UINT32 ExTokenNumber
1474 DYNAMICEX_MAPPING
*ExMap
;
1475 EFI_GUID
*GuidTable
;
1476 EFI_GUID
*MatchGuid
;
1479 if (!mPeiDatabaseEmpty
) {
1480 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
);
1481 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1483 MatchGuid
= ScanGuid (GuidTable
, mPeiGuidTableSize
, Guid
);
1485 if (MatchGuid
!= NULL
) {
1487 MatchGuidIdx
= MatchGuid
- GuidTable
;
1489 for (Index
= 0; Index
< mPeiExMapppingTableSize
; Index
++) {
1490 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1491 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1492 return ExMap
[Index
].TokenNumber
;
1498 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
);
1499 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1501 MatchGuid
= ScanGuid (GuidTable
, mDxeGuidTableSize
, Guid
);
1503 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1504 // error in the BUILD system.
1506 ASSERT (MatchGuid
!= NULL
);
1508 MatchGuidIdx
= MatchGuid
- GuidTable
;
1510 for (Index
= 0; Index
< mDxeExMapppingTableSize
; Index
++) {
1511 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1512 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1513 return ExMap
[Index
].TokenNumber
;
1523 Get SKU ID table from PCD database.
1525 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1526 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1527 If FALSE, the pcd entry is initialized in DXE phase.
1528 @return Pointer to SKU ID array table
1533 IN UINTN LocalTokenNumberTableIdx
,
1538 UINTN LocalTokenNumber
;
1542 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1543 Database
= (UINT8
*) mPcdDatabase
.PeiDb
;
1545 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1546 Database
= (UINT8
*) mPcdDatabase
.DxeDb
;
1549 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1551 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1553 return (SKU_ID
*) (Database
+ SkuHead
->SkuIdTableOffset
);
1558 Wrapper function of getting index of PCD entry in size table.
1560 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1561 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1562 If FALSE, the pcd entry is initialized in DXE phase.
1564 @return index of PCD entry in size table.
1568 IN UINTN LocalTokenNumberTableIdx
,
1572 UINT32
*LocalTokenNumberTable
;
1573 UINTN LocalTokenNumber
;
1579 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1581 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1586 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
1587 LocalTokenNumber
= LocalTokenNumberTable
[Index
];
1589 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1591 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1594 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1596 // We have only two entry for VPD enabled PCD entry:
1599 // Current size is equal to MAX size.
1603 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1605 // We have only two entry for Non-Sku enabled PCD entry:
1612 // We have these entry for SKU enabled PCD entry
1614 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1616 SkuIdTable
= GetSkuIdArray (Index
, IsPeiDb
);
1617 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1624 return SizeTableIdx
;
1628 Get size of POINTER type PCD value.
1630 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1631 @param MaxSize Maxmium size of POINTER type PCD value.
1633 @return size of POINTER type PCD value.
1638 IN UINTN LocalTokenNumberTableIdx
,
1643 UINTN LocalTokenNumber
;
1645 SIZE_INFO
*SizeTable
;
1648 UINT32
*LocalTokenNumberTable
;
1650 // EBC compiler is very choosy. It may report warning about comparison
1651 // between UINTN and 0 . So we add 1 in each size of the
1653 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1657 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1658 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1660 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1661 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1662 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1665 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1667 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1669 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1671 *MaxSize
= SizeTable
[SizeTableIdx
];
1673 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1676 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1678 // We have only two entry for VPD enabled PCD entry:
1681 // We consider current size is equal to MAX size.
1685 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1687 // We have only two entry for Non-Sku enabled PCD entry:
1691 return SizeTable
[SizeTableIdx
+ 1];
1694 // We have these entry for SKU enabled PCD entry
1696 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1698 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1699 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1700 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.PeiDb
->SystemSkuId
) {
1701 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1704 return SizeTable
[SizeTableIdx
+ 1];
1710 Set size of POINTER type PCD value. The size should not exceed the maximum size
1713 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1714 @param CurrentSize Size of POINTER type PCD value.
1716 @retval TRUE Success to set size of PCD value.
1717 @retval FALSE Fail to set size of PCD value.
1721 IN UINTN LocalTokenNumberTableIdx
,
1722 IN OUT UINTN
*CurrentSize
1726 UINTN LocalTokenNumber
;
1728 SIZE_INFO
*SizeTable
;
1732 UINT32
*LocalTokenNumberTable
;
1735 // EBC compiler is very choosy. It may report warning about comparison
1736 // between UINTN and 0 . So we add 1 in each size of the
1739 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1742 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1743 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1745 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1746 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1747 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1750 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1752 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1754 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1756 MaxSize
= SizeTable
[SizeTableIdx
];
1758 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1761 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1763 // We shouldn't come here as we don't support SET for VPD
1768 if ((*CurrentSize
> MaxSize
) ||
1769 (*CurrentSize
== MAX_ADDRESS
)) {
1770 *CurrentSize
= MaxSize
;
1774 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1776 // We have only two entry for Non-Sku enabled PCD entry:
1780 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1784 // We have these entry for SKU enabled PCD entry
1786 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1788 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1789 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1790 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.PeiDb
->SystemSkuId
) {
1791 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1795 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;