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.
54 UINT32
*LocalTokenNumberTable
;
55 UINT32 LocalTokenNumber
;
60 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
61 // We have to decrement TokenNumber by 1 to make it usable
62 // as the array index.
67 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
69 TmpTokenNumber
= TokenNumber
;
71 LocalTokenNumberTable
= IsPeiDb
? (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
) :
72 (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
73 TokenNumber
= IsPeiDb
? TokenNumber
: TokenNumber
- mPeiLocalTokenCount
;
75 LocalTokenNumber
= LocalTokenNumberTable
[TokenNumber
];
77 Size
= (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
79 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
81 GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
85 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
, IsPeiDb
);
88 return LocalTokenNumber
;
92 Get PCD type by Local Token Number.
94 @param[in] LocalTokenNumber The PCD local token number.
100 IN UINT32 LocalTokenNumber
103 switch (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) {
104 case PCD_DATUM_TYPE_POINTER
:
105 return EFI_PCD_TYPE_PTR
;
106 case PCD_DATUM_TYPE_UINT8
:
107 if ((LocalTokenNumber
& PCD_DATUM_TYPE_UINT8_BOOLEAN
) == PCD_DATUM_TYPE_UINT8_BOOLEAN
) {
108 return EFI_PCD_TYPE_BOOL
;
110 return EFI_PCD_TYPE_8
;
112 case PCD_DATUM_TYPE_UINT16
:
113 return EFI_PCD_TYPE_16
;
114 case PCD_DATUM_TYPE_UINT32
:
115 return EFI_PCD_TYPE_32
;
116 case PCD_DATUM_TYPE_UINT64
:
117 return EFI_PCD_TYPE_64
;
120 return EFI_PCD_TYPE_8
;
127 @param[in] OnlyTokenSpaceName If TRUE, only need to get the TokenSpaceCName.
128 If FALSE, need to get the full PCD name.
129 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
130 If FALSE, the pcd entry is initialized in DXE phase.
131 @param[in] TokenNumber The PCD token number.
133 @return The TokenSpaceCName or full PCD name.
137 IN BOOLEAN OnlyTokenSpaceName
,
142 PCD_DATABASE_INIT
*Database
;
144 PCD_NAME_INDEX
*PcdNameIndex
;
145 CHAR8
*TokenSpaceName
;
150 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
151 // We have to decrement TokenNumber by 1 to make it usable
152 // as the array index.
156 Database
= IsPeiDb
? mPcdDatabase
.PeiDb
: mPcdDatabase
.DxeDb
;
157 TokenNumber
= IsPeiDb
? TokenNumber
: TokenNumber
- mPeiLocalTokenCount
;
159 StringTable
= (UINT8
*) Database
+ Database
->StringTableOffset
;
162 // Get the PCD name index.
164 PcdNameIndex
= (PCD_NAME_INDEX
*)((UINT8
*) Database
+ Database
->PcdNameTableOffset
) + TokenNumber
;
165 TokenSpaceName
= (CHAR8
*)&StringTable
[PcdNameIndex
->TokenSpaceCNameIndex
];
166 PcdName
= (CHAR8
*)&StringTable
[PcdNameIndex
->PcdCNameIndex
];
168 if (OnlyTokenSpaceName
) {
170 // Only need to get the TokenSpaceCName.
172 Name
= AllocateCopyPool (AsciiStrSize (TokenSpaceName
), TokenSpaceName
);
175 // Need to get the full PCD name.
177 Name
= AllocateZeroPool (AsciiStrSize (TokenSpaceName
) + AsciiStrSize (PcdName
));
178 ASSERT (Name
!= NULL
);
180 // Catenate TokenSpaceCName and PcdCName with a '.' to form the full PCD name.
182 AsciiStrCat (Name
, TokenSpaceName
);
183 Name
[AsciiStrSize (TokenSpaceName
) - sizeof (CHAR8
)] = '.';
184 AsciiStrCat (Name
, PcdName
);
191 Retrieve additional information associated with a PCD token.
193 This includes information such as the type of value the TokenNumber is associated with as well as possible
194 human readable name that is associated with the token.
196 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
197 If FALSE, the pcd entry is initialized in DXE phase.
198 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
199 @param[in] TokenNumber The PCD token number.
200 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
201 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
203 @retval EFI_SUCCESS The PCD information was returned successfully
204 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
209 IN CONST EFI_GUID
*Guid
,
210 IN UINTN TokenNumber
,
211 OUT EFI_PCD_INFO
*PcdInfo
214 PCD_DATABASE_INIT
*Database
;
218 DYNAMICEX_MAPPING
*ExMapTable
;
220 UINT32 LocalTokenNumber
;
222 Database
= IsPeiDb
? mPcdDatabase
.PeiDb
: mPcdDatabase
.DxeDb
;
224 GuidTable
= (EFI_GUID
*)((UINT8
*)Database
+ Database
->GuidTableOffset
);
225 MatchGuid
= ScanGuid (GuidTable
, Database
->GuidTableCount
* sizeof(EFI_GUID
), Guid
);
227 if (MatchGuid
== NULL
) {
228 return EFI_NOT_FOUND
;
231 GuidTableIdx
= MatchGuid
- GuidTable
;
233 ExMapTable
= (DYNAMICEX_MAPPING
*)((UINT8
*)Database
+ Database
->ExMapTableOffset
);
236 // Find the PCD by GuidTableIdx and ExTokenNumber in ExMapTable.
238 for (Index
= 0; Index
< Database
->ExTokenCount
; Index
++) {
239 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
240 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
242 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
243 // PcdSize to 0 and PcdName to the null-terminated ASCII string
244 // associated with the token's namespace Guid.
246 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
247 PcdInfo
->PcdSize
= 0;
249 // Here use one representative in the token space to get the TokenSpaceCName.
251 PcdInfo
->PcdName
= GetPcdName (TRUE
, IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
253 } else if (ExMapTable
[Index
].ExTokenNumber
== TokenNumber
) {
254 PcdInfo
->PcdSize
= DxePcdGetSize (ExMapTable
[Index
].TokenNumber
);
255 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
256 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
257 PcdInfo
->PcdName
= GetPcdName (FALSE
, IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
263 return EFI_NOT_FOUND
;
267 Retrieve additional information associated with a PCD token.
269 This includes information such as the type of value the TokenNumber is associated with as well as possible
270 human readable name that is associated with the token.
272 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
273 @param[in] TokenNumber The PCD token number.
274 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
275 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
277 @retval EFI_SUCCESS The PCD information was returned successfully.
278 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
282 IN CONST EFI_GUID
*Guid
,
283 IN UINTN TokenNumber
,
284 OUT EFI_PCD_INFO
*PcdInfo
288 BOOLEAN PeiExMapTableEmpty
;
289 BOOLEAN DxeExMapTableEmpty
;
290 UINT32 LocalTokenNumber
;
293 ASSERT (PcdInfo
!= NULL
);
295 Status
= EFI_NOT_FOUND
;
296 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
297 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
300 if (((TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) && (TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) ||
301 ((TokenNumber
+ 1 > (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1)))) {
302 return EFI_NOT_FOUND
;
303 } else if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
305 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
306 // PcdSize to 0 and PcdName to NULL for default Token Space.
308 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
309 PcdInfo
->PcdSize
= 0;
310 PcdInfo
->PcdName
= NULL
;
312 PcdInfo
->PcdSize
= DxePcdGetSize (TokenNumber
);
314 if ((TokenNumber
+ 1 <= mPeiNexTokenCount
+ 1)) {
317 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
);
318 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
319 PcdInfo
->PcdName
= GetPcdName (FALSE
, IsPeiDb
, TokenNumber
);
324 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
325 return EFI_NOT_FOUND
;
328 if (!PeiExMapTableEmpty
) {
329 Status
= ExGetPcdInfo (
337 if (Status
== EFI_SUCCESS
) {
341 if (!DxeExMapTableEmpty
) {
342 Status
= ExGetPcdInfo (
354 Get the PCD entry pointer in PCD database.
356 This routine will visit PCD database to find the PCD entry according to given
357 token number. The given token number is autogened by build tools and it will be
358 translated to local token number. Local token number contains PCD's type and
359 offset of PCD entry in PCD database.
361 @param TokenNumber Token's number, it is autogened by build tools
362 @param GetSize The size of token's value
364 @return PCD entry pointer in PCD database
369 IN UINTN TokenNumber
,
377 VARIABLE_HEAD
*VariableHead
;
378 UINT8
*VaraiableDefaultBuffer
;
383 UINTN TmpTokenNumber
;
386 UINT32 LocalTokenNumber
;
388 STRING_HEAD StringTableIdx
;
392 // Aquire lock to prevent reentrance from TPL_CALLBACK level
394 EfiAcquireLock (&mPcdDatabaseLock
);
398 ASSERT (TokenNumber
> 0);
400 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
401 // We have to decrement TokenNumber by 1 to make it usable
402 // as the array index.
406 TmpTokenNumber
= TokenNumber
;
409 // EBC compiler is very choosy. It may report warning about comparison
410 // between UINTN and 0 . So we add 1 in each size of the
413 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
415 ASSERT ((GetSize
== DxePcdGetSize (TokenNumber
+ 1)) || (GetSize
== 0));
417 // EBC compiler is very choosy. It may report warning about comparison
418 // between UINTN and 0 . So we add 1 in each size of the
420 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1) ? TRUE
: FALSE
);
422 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
+ 1);
424 PcdDb
= IsPeiDb
? ((UINT8
*) mPcdDatabase
.PeiDb
) : ((UINT8
*) mPcdDatabase
.DxeDb
);
427 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->StringTableOffset
);
429 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->StringTableOffset
);
433 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
435 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
437 VpdHead
= (VPD_HEAD
*) ((UINT8
*) PcdDb
+ Offset
);
438 RetPtr
= (VOID
*) (UINTN
) (PcdGet32 (PcdVpdBaseAddress
) + VpdHead
->Offset
);
442 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
445 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
447 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
450 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
451 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
452 Name
= (UINT16
*)(StringTable
+ VariableHead
->StringIndex
);
454 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
456 // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is the index of
457 // string array in string table.
459 StringTableIdx
= *(STRING_HEAD
*)((UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
);
460 VaraiableDefaultBuffer
= (VOID
*) (StringTable
+ StringTableIdx
);
462 VaraiableDefaultBuffer
= (UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
;
464 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
465 if (Status
== EFI_SUCCESS
) {
468 // It is a pointer type. So get the MaxSize reserved for
471 GetPtrTypeSize (TmpTokenNumber
, &GetSize
);
474 // If the operation is successful, we copy the data
475 // to the default value buffer in the PCD Database.
476 // So that we can free the Data allocated in GetHiiVariable.
478 CopyMem (VaraiableDefaultBuffer
, Data
+ VariableHead
->Offset
, GetSize
);
481 RetPtr
= (VOID
*) VaraiableDefaultBuffer
;
484 case PCD_TYPE_STRING
:
485 StringTableIdx
= *(STRING_HEAD
*)((UINT8
*) PcdDb
+ Offset
);
486 RetPtr
= (VOID
*) (StringTable
+ StringTableIdx
);
490 RetPtr
= (VOID
*) ((UINT8
*) PcdDb
+ Offset
);
499 EfiReleaseLock (&mPcdDatabaseLock
);
506 Register the callback function for a PCD entry.
508 This routine will register a callback function to a PCD entry by given token number
509 and token space guid.
511 @param TokenNumber PCD token's number, it is autogened by build tools.
512 @param Guid PCD token space's guid,
513 if not NULL, this PCD is dynamicEx type PCD.
514 @param CallBackFunction Callback function pointer
516 @return EFI_SUCCESS Always success for registering callback function.
520 DxeRegisterCallBackWorker (
521 IN UINTN TokenNumber
,
522 IN CONST EFI_GUID
*Guid
, OPTIONAL
523 IN PCD_PROTOCOL_CALLBACK CallBackFunction
526 CALLBACK_FN_ENTRY
*FnTableEntry
;
527 LIST_ENTRY
*ListHead
;
528 LIST_ENTRY
*ListNode
;
531 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
535 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
536 // We have to decrement TokenNumber by 1 to make it usable
537 // as the array index of mCallbackFnTable[].
539 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
540 ListNode
= GetFirstNode (ListHead
);
542 while (ListNode
!= ListHead
) {
543 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
545 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
547 // We only allow a Callback function to be register once
548 // for a TokenNumber. So just return EFI_SUCCESS
552 ListNode
= GetNextNode (ListHead
, ListNode
);
555 FnTableEntry
= AllocatePool (sizeof(CALLBACK_FN_ENTRY
));
556 ASSERT (FnTableEntry
!= NULL
);
558 FnTableEntry
->CallbackFn
= CallBackFunction
;
559 InsertTailList (ListHead
, &FnTableEntry
->Node
);
565 UnRegister the callback function for a PCD entry.
567 This routine will unregister a callback function to a PCD entry by given token number
568 and token space guid.
570 @param TokenNumber PCD token's number, it is autogened by build tools.
571 @param Guid PCD token space's guid.
572 if not NULL, this PCD is dynamicEx type PCD.
573 @param CallBackFunction Callback function pointer
575 @retval EFI_SUCCESS Callback function is success to be unregister.
576 @retval EFI_INVALID_PARAMETER Can not find the PCD entry by given token number.
579 DxeUnRegisterCallBackWorker (
580 IN UINTN TokenNumber
,
581 IN CONST EFI_GUID
*Guid
, OPTIONAL
582 IN PCD_PROTOCOL_CALLBACK CallBackFunction
585 CALLBACK_FN_ENTRY
*FnTableEntry
;
586 LIST_ENTRY
*ListHead
;
587 LIST_ENTRY
*ListNode
;
590 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
594 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
595 // We have to decrement TokenNumber by 1 to make it usable
596 // as the array index of mCallbackFnTable[].
598 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
599 ListNode
= GetFirstNode (ListHead
);
601 while (ListNode
!= ListHead
) {
602 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
604 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
606 // We only allow a Callback function to be register once
607 // for a TokenNumber. So we can safely remove the Node from
608 // the Link List and return EFI_SUCCESS.
610 RemoveEntryList (ListNode
);
611 FreePool (FnTableEntry
);
615 ListNode
= GetNextNode (ListHead
, ListNode
);
618 return EFI_INVALID_PARAMETER
;
622 Get next token number in given token space.
624 This routine is used for dynamicEx type PCD. It will firstly scan token space
625 table to get token space according to given token space guid. Then scan given
626 token number in found token space, if found, then return next token number in
629 @param Guid Token space guid. Next token number will be scaned in
631 @param TokenNumber Token number.
632 If PCD_INVALID_TOKEN_NUMBER, return first token number in
634 If not PCD_INVALID_TOKEN_NUMBER, return next token number
635 in token space table.
636 @param GuidTable Token space guid table. It will be used for scan token space
637 by given token space guid.
638 @param SizeOfGuidTable The size of guid table.
639 @param ExMapTable DynamicEx token number mapping table.
640 @param SizeOfExMapTable The size of dynamicEx token number mapping table.
642 @retval EFI_NOT_FOUND Can not given token space or token number.
643 @retval EFI_SUCCESS Success to get next token number.
647 ExGetNextTokeNumber (
648 IN CONST EFI_GUID
*Guid
,
649 IN OUT UINTN
*TokenNumber
,
650 IN EFI_GUID
*GuidTable
,
651 IN UINTN SizeOfGuidTable
,
652 IN DYNAMICEX_MAPPING
*ExMapTable
,
653 IN UINTN SizeOfExMapTable
660 UINTN ExMapTableCount
;
663 // Scan token space guid
665 MatchGuid
= ScanGuid (GuidTable
, SizeOfGuidTable
, Guid
);
666 if (MatchGuid
== NULL
) {
667 return EFI_NOT_FOUND
;
671 // Find the token space table in dynamicEx mapping table.
674 GuidTableIdx
= MatchGuid
- GuidTable
;
675 ExMapTableCount
= SizeOfExMapTable
/ sizeof(ExMapTable
[0]);
676 for (Index
= 0; Index
< ExMapTableCount
; Index
++) {
677 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
685 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
686 // token number in found token space.
688 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
689 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
693 for ( ; Index
< ExMapTableCount
; Index
++) {
694 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
699 while (Index
< ExMapTableCount
) {
701 if (Index
== ExMapTableCount
) {
703 // Exceed the length of ExMap Table
705 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
706 return EFI_NOT_FOUND
;
707 } else if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
709 // Found the next match
711 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
717 return EFI_NOT_FOUND
;
721 Find the PCD database.
723 @retval The base address of external PCD database binary.
724 @retval NULL Return NULL if not find.
731 DXE_PCD_DATABASE
*DxePcdDbBinary
;
735 DxePcdDbBinary
= NULL
;
737 // Search the External Pcd database from one section of current FFS,
738 // and read it to memory
740 Status
= GetSectionFromFfs (
743 (VOID
**) &DxePcdDbBinary
,
746 ASSERT_EFI_ERROR (Status
);
749 // Check the first bytes (Header Signature Guid) and build version.
751 if (!CompareGuid ((VOID
*)DxePcdDbBinary
, &gPcdDataBaseSignatureGuid
) ||
752 (DxePcdDbBinary
->BuildVersion
!= PCD_SERVICE_DXE_VERSION
)) {
756 return DxePcdDbBinary
;
760 Initialize the PCD database in DXE phase.
762 PCD database in DXE phase also contains PCD database in PEI phase which is copied
767 BuildPcdDxeDataBase (
771 PEI_PCD_DATABASE
*PeiDatabase
;
772 EFI_HOB_GUID_TYPE
*GuidHob
;
777 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
778 if (GuidHob
!= NULL
) {
781 // If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
782 // should not be included at all. So the GuidHob could
783 // be NULL. If it is NULL, we just copy over the DXE Default
784 // Value to PCD Database.
787 PeiDatabase
= (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
789 // Assign PCD Entries refereneced in PEI phase to PCD DATABASE
791 mPcdDatabase
.PeiDb
= PeiDatabase
;
795 // Assign PCD Entries with default value to PCD DATABASE
797 mPcdDatabase
.DxeDb
= LocateExPcdBinary ();
798 ASSERT(mPcdDatabase
.DxeDb
!= NULL
);
799 PcdDxeDbLen
= mPcdDatabase
.DxeDb
->Length
+ mPcdDatabase
.DxeDb
->UninitDataBaseSize
;
800 PcdDxeDb
= AllocateZeroPool (PcdDxeDbLen
);
801 ASSERT (PcdDxeDb
!= NULL
);
802 CopyMem (PcdDxeDb
, mPcdDatabase
.DxeDb
, mPcdDatabase
.DxeDb
->Length
);
803 FreePool (mPcdDatabase
.DxeDb
);
804 mPcdDatabase
.DxeDb
= PcdDxeDb
;
807 // Initialized the external PCD database local variables
809 mPeiLocalTokenCount
= mPcdDatabase
.PeiDb
->LocalTokenCount
;
810 mDxeLocalTokenCount
= mPcdDatabase
.DxeDb
->LocalTokenCount
;
812 mPeiExMapppingTableSize
= mPcdDatabase
.PeiDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
813 mDxeExMapppingTableSize
= mPcdDatabase
.DxeDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
814 mPeiGuidTableSize
= mPcdDatabase
.PeiDb
->GuidTableCount
* sizeof(GUID
);
815 mDxeGuidTableSize
= mPcdDatabase
.DxeDb
->GuidTableCount
* sizeof (GUID
);
817 mPcdTotalTokenCount
= mPeiLocalTokenCount
+ mDxeLocalTokenCount
;
818 mPeiNexTokenCount
= mPeiLocalTokenCount
- mPcdDatabase
.PeiDb
->ExTokenCount
;
819 mDxeNexTokenCount
= mDxeLocalTokenCount
- mPcdDatabase
.DxeDb
->ExTokenCount
;
821 mPeiExMapTableEmpty
= (mPcdDatabase
.PeiDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
822 mDxeExMapTableEmpty
= (mPcdDatabase
.DxeDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
823 mPeiDatabaseEmpty
= (mPeiLocalTokenCount
== 0) ? TRUE
: FALSE
;
825 TmpTokenSpaceBufferCount
= mPcdDatabase
.PeiDb
->ExTokenCount
+ mPcdDatabase
.DxeDb
->ExTokenCount
;
826 TmpTokenSpaceBuffer
= (EFI_GUID
**)AllocateZeroPool(TmpTokenSpaceBufferCount
* sizeof (EFI_GUID
*));
829 // Initialized the Callback Function Table
831 mCallbackFnTable
= AllocateZeroPool (mPcdTotalTokenCount
* sizeof (LIST_ENTRY
));
832 ASSERT(mCallbackFnTable
!= NULL
);
835 // EBC compiler is very choosy. It may report warning about comparison
836 // between UINTN and 0 . So we add 1 in each size of the
839 for (Index
= 0; Index
+ 1 < mPcdTotalTokenCount
+ 1; Index
++) {
840 InitializeListHead (&mCallbackFnTable
[Index
]);
845 Get Variable which contains HII type PCD entry.
847 @param VariableGuid Variable's guid
848 @param VariableName Variable's unicode name string
849 @param VariableData Variable's data pointer,
850 @param VariableSize Variable's size.
852 @return the status of gRT->GetVariable
856 IN EFI_GUID
*VariableGuid
,
857 IN UINT16
*VariableName
,
858 OUT UINT8
**VariableData
,
859 OUT UINTN
*VariableSize
870 // Firstly get the real size of HII variable
872 Status
= gRT
->GetVariable (
873 (UINT16
*)VariableName
,
881 // Allocate buffer to hold whole variable data according to variable size.
883 if (Status
== EFI_BUFFER_TOO_SMALL
) {
884 Buffer
= (UINT8
*) AllocatePool (Size
);
886 ASSERT (Buffer
!= NULL
);
888 Status
= gRT
->GetVariable (
896 ASSERT (Status
== EFI_SUCCESS
);
897 *VariableData
= Buffer
;
898 *VariableSize
= Size
;
901 // Use Default Data only when variable is not found.
902 // For other error status, correct data can't be got, and trig ASSERT().
904 ASSERT (Status
== EFI_NOT_FOUND
);
911 Find the local token number according to system SKU ID.
913 @param LocalTokenNumber PCD token number
914 @param Size The size of PCD entry.
915 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
916 If False, the PCD entry is initialized in DXE phase.
918 @return Token number according to system SKU ID.
922 GetSkuEnabledTokenNumber (
923 UINT32 LocalTokenNumber
,
935 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
937 PcdDb
= IsPeiDb
? (UINT8
*) mPcdDatabase
.PeiDb
: (UINT8
*) mPcdDatabase
.DxeDb
;
939 SkuHead
= (SKU_HEAD
*) (PcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
940 Value
= (UINT8
*) (PcdDb
+ SkuHead
->SkuDataStartOffset
);
942 SkuIdTable
= (SKU_ID
*)(PcdDb
+ SkuHead
->SkuIdTableOffset
);
944 // Find the current system's SKU ID entry in SKU ID table.
947 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
948 if (mPcdDatabase
.PeiDb
->SystemSkuId
== SkuIdTable
[Index
+ 1]) {
955 // Find the default SKU ID entry in SKU ID table.
959 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
960 if (0 == SkuIdTable
[Index
+ 1]) {
965 ASSERT (Index
< SkuIdTable
[0]);
967 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
969 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
970 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_VPD
);
973 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
974 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
);
976 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
977 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
978 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
| PCD_TYPE_STRING
);
980 case PCD_TYPE_STRING
:
981 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
982 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_STRING
);
985 Value
+= Size
* Index
;
986 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_DATA
);
999 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
1000 has registered callback function.
1002 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
1004 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
1006 @param TokenNumber PCD token number generated by build tools.
1007 @param Data Value want to be set for this PCD entry
1008 @param Size The size of value
1012 InvokeCallbackOnSet (
1013 UINT32 ExTokenNumber
,
1014 CONST EFI_GUID
*Guid
, OPTIONAL
1020 CALLBACK_FN_ENTRY
*FnTableEntry
;
1021 LIST_ENTRY
*ListHead
;
1022 LIST_ENTRY
*ListNode
;
1025 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1026 // We have to decrement TokenNumber by 1 to make it usable
1027 // as the array index of mCallbackFnTable[].
1029 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
1030 ListNode
= GetFirstNode (ListHead
);
1032 while (ListNode
!= ListHead
) {
1033 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE (ListNode
, CALLBACK_FN_ENTRY
, Node
);
1035 FnTableEntry
->CallbackFn(Guid
,
1036 (Guid
== NULL
) ? TokenNumber
: ExTokenNumber
,
1040 ListNode
= GetNextNode (ListHead
, ListNode
);
1048 Wrapper function for setting non-pointer type value for a PCD entry.
1050 @param TokenNumber Pcd token number autogenerated by build tools.
1051 @param Data Value want to be set for PCD entry
1052 @param Size Size of value.
1054 @return status of SetWorker.
1059 IN UINTN TokenNumber
,
1064 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
1069 Set value for an PCD entry
1071 @param TokenNumber Pcd token number autogenerated by build tools.
1072 @param Data Value want to be set for PCD entry
1073 @param Size Size of value.
1074 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
1075 If False, the type of PCD entry's value is not Pointer.
1077 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
1078 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
1079 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
1080 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
1081 range of UINT8, UINT16, UINT32, UINT64
1082 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
1086 IN UINTN TokenNumber
,
1093 UINT32 LocalTokenNumber
;
1094 EFI_GUID
*GuidTable
;
1098 UINTN VariableOffset
;
1100 VARIABLE_HEAD
*VariableHead
;
1105 UINTN TmpTokenNumber
;
1108 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1109 // We have to decrement TokenNumber by 1 to make it usable
1110 // as the array index.
1114 TmpTokenNumber
= TokenNumber
;
1117 // EBC compiler is very choosy. It may report warning about comparison
1118 // between UINTN and 0 . So we add 1 in each size of the
1121 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
1125 // Get MaxSize first, then check new size with max buffer size.
1127 GetPtrTypeSize (TokenNumber
, &MaxSize
);
1128 if (*Size
> MaxSize
) {
1130 return EFI_INVALID_PARAMETER
;
1133 if (*Size
!= DxePcdGetSize (TokenNumber
+ 1)) {
1134 return EFI_INVALID_PARAMETER
;
1139 // EBC compiler is very choosy. It may report warning about comparison
1140 // between UINTN and 0 . So we add 1 in each size of the
1143 if ((TokenNumber
+ 1 < mPeiNexTokenCount
+ 1) ||
1144 (TokenNumber
+ 1 >= mPeiLocalTokenCount
+ 1 && TokenNumber
+ 1 < (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1))) {
1145 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
1149 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1151 EfiAcquireLock (&mPcdDatabaseLock
);
1154 // EBC compiler is very choosy. It may report warning about comparison
1155 // between UINTN and 0 . So we add 1 in each size of the
1158 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1) ? TRUE
: FALSE
);
1160 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
+ 1);
1162 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
1164 PcdDb
= IsPeiDb
? ((UINT8
*) mPcdDatabase
.PeiDb
) : ((UINT8
*) mPcdDatabase
.DxeDb
);
1167 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->StringTableOffset
);
1169 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->StringTableOffset
);
1173 InternalData
= PcdDb
+ Offset
;
1175 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
1178 Status
= EFI_INVALID_PARAMETER
;
1181 case PCD_TYPE_STRING
:
1182 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1183 CopyMem (StringTable
+ *((STRING_HEAD
*)InternalData
), Data
, *Size
);
1184 Status
= EFI_SUCCESS
;
1186 Status
= EFI_INVALID_PARAMETER
;
1190 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
1193 if (!SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1194 Status
= EFI_INVALID_PARAMETER
;
1200 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1202 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1205 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
1207 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
1208 Name
= (UINT16
*) (StringTable
+ VariableHead
->StringIndex
);
1209 VariableOffset
= VariableHead
->Offset
;
1210 Status
= SetHiiVariable (Guid
, Name
, Data
, *Size
, VariableOffset
);
1212 if (EFI_NOT_FOUND
== Status
) {
1213 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
1215 StringTable
+ *(STRING_HEAD
*)(PcdDb
+ VariableHead
->DefaultValueOffset
),
1220 CopyMem (PcdDb
+ VariableHead
->DefaultValueOffset
, Data
, *Size
);
1222 Status
= EFI_SUCCESS
;
1228 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1229 CopyMem (InternalData
, Data
, *Size
);
1230 Status
= EFI_SUCCESS
;
1232 Status
= EFI_INVALID_PARAMETER
;
1237 Status
= EFI_SUCCESS
;
1240 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
1243 case sizeof(UINT16
):
1244 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
1247 case sizeof(UINT32
):
1248 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
1251 case sizeof(UINT64
):
1252 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
1257 Status
= EFI_NOT_FOUND
;
1264 Status
= EFI_NOT_FOUND
;
1268 EfiReleaseLock (&mPcdDatabaseLock
);
1274 Wrapper function for get PCD value for dynamic-ex PCD.
1276 @param Guid Token space guid for dynamic-ex PCD.
1277 @param ExTokenNumber Token number for dynamic-ex PCD.
1278 @param GetSize The size of dynamic-ex PCD value.
1280 @return PCD entry in PCD database.
1285 IN CONST EFI_GUID
*Guid
,
1286 IN UINTN ExTokenNumber
,
1290 return GetWorker(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
), GetSize
);
1294 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
1296 @param ExTokenNumber Token number for dynamic-ex PCD.
1297 @param Guid Token space guid for dynamic-ex PCD.
1298 @param Data Value want to be set.
1299 @param SetSize The size of value.
1301 @return status of ExSetWorker().
1306 IN UINTN ExTokenNumber
,
1307 IN CONST EFI_GUID
*Guid
,
1312 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &SetSize
, FALSE
);
1316 Set value for a dynamic-ex PCD entry.
1318 This routine find the local token number according to dynamic-ex PCD's token
1319 space guid and token number firstly, and invoke callback function if this PCD
1320 entry registered callback function. Finally, invoken general SetWorker to set
1323 @param ExTokenNumber Dynamic-ex PCD token number.
1324 @param Guid Token space guid for dynamic-ex PCD.
1325 @param Data PCD value want to be set
1326 @param SetSize Size of value.
1327 @param PtrType If TRUE, this PCD entry is pointer type.
1328 If FALSE, this PCD entry is not pointer type.
1330 @return status of SetWorker().
1335 IN UINTN ExTokenNumber
,
1336 IN CONST EFI_GUID
*Guid
,
1338 IN OUT UINTN
*SetSize
,
1344 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
);
1346 InvokeCallbackOnSet ((UINT32
) ExTokenNumber
, Guid
, TokenNumber
, Data
, *SetSize
);
1348 return SetWorker (TokenNumber
, Data
, SetSize
, PtrType
);
1353 Set value for HII-type PCD.
1355 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
1356 HII-type PCD is to visit this variable.
1358 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
1359 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
1360 @param Data Value want to be set.
1361 @param DataSize Size of value
1362 @param Offset Value offset of HII-type PCD in variable.
1364 @return status of GetVariable()/SetVariable().
1369 IN EFI_GUID
*VariableGuid
,
1370 IN UINT16
*VariableName
,
1371 IN CONST VOID
*Data
,
1386 // Try to get original variable size information.
1388 Status
= gRT
->GetVariable (
1389 (UINT16
*)VariableName
,
1396 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1398 // Patch new PCD's value to offset in given HII variable.
1400 if (Size
>= (DataSize
+ Offset
)) {
1403 SetSize
= DataSize
+ Offset
;
1405 Buffer
= AllocatePool (SetSize
);
1406 ASSERT (Buffer
!= NULL
);
1408 Status
= gRT
->GetVariable (
1416 ASSERT_EFI_ERROR (Status
);
1418 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1420 Status
= gRT
->SetVariable (
1430 } else if (Status
== EFI_NOT_FOUND
) {
1432 // If variable does not exist, a new variable need to be created.
1435 Size
= Offset
+ DataSize
;
1437 Buffer
= AllocateZeroPool (Size
);
1438 ASSERT (Buffer
!= NULL
);
1440 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1442 Status
= gRT
->SetVariable (
1445 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1455 // If we drop to here, the value is failed to be written in to variable area
1456 // So, we will save the data in the PCD Database's volatile area.
1462 Get Token Number according to dynamic-ex PCD's {token space guid:token number}
1464 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1465 in DEC file. PCD database maintain a mapping table that translate pair of {token
1466 space guid: token number} to Token Number.
1468 @param Guid Token space guid for dynamic-ex PCD entry.
1469 @param ExTokenNumber Dynamic-ex PCD token number.
1471 @return Token Number for dynamic-ex PCD.
1475 GetExPcdTokenNumber (
1476 IN CONST EFI_GUID
*Guid
,
1477 IN UINT32 ExTokenNumber
1481 DYNAMICEX_MAPPING
*ExMap
;
1482 EFI_GUID
*GuidTable
;
1483 EFI_GUID
*MatchGuid
;
1486 if (!mPeiDatabaseEmpty
) {
1487 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
);
1488 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1490 MatchGuid
= ScanGuid (GuidTable
, mPeiGuidTableSize
, Guid
);
1492 if (MatchGuid
!= NULL
) {
1494 MatchGuidIdx
= MatchGuid
- GuidTable
;
1496 for (Index
= 0; Index
< mPeiExMapppingTableSize
; Index
++) {
1497 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1498 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1499 return ExMap
[Index
].TokenNumber
;
1505 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
);
1506 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1508 MatchGuid
= ScanGuid (GuidTable
, mDxeGuidTableSize
, Guid
);
1510 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1511 // error in the BUILD system.
1513 ASSERT (MatchGuid
!= NULL
);
1515 MatchGuidIdx
= MatchGuid
- GuidTable
;
1517 for (Index
= 0; Index
< mDxeExMapppingTableSize
; Index
++) {
1518 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1519 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1520 return ExMap
[Index
].TokenNumber
;
1530 Get SKU ID table from PCD database.
1532 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1533 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1534 If FALSE, the pcd entry is initialized in DXE phase.
1535 @return Pointer to SKU ID array table
1540 IN UINTN LocalTokenNumberTableIdx
,
1545 UINTN LocalTokenNumber
;
1549 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1550 Database
= (UINT8
*) mPcdDatabase
.PeiDb
;
1552 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1553 Database
= (UINT8
*) mPcdDatabase
.DxeDb
;
1556 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1558 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1560 return (SKU_ID
*) (Database
+ SkuHead
->SkuIdTableOffset
);
1565 Wrapper function of getting index of PCD entry in size table.
1567 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1568 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1569 If FALSE, the pcd entry is initialized in DXE phase.
1571 @return index of PCD entry in size table.
1575 IN UINTN LocalTokenNumberTableIdx
,
1579 UINT32
*LocalTokenNumberTable
;
1580 UINTN LocalTokenNumber
;
1586 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1588 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1593 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
1594 LocalTokenNumber
= LocalTokenNumberTable
[Index
];
1596 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1598 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1601 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1603 // We have only two entry for VPD enabled PCD entry:
1606 // Current size is equal to MAX size.
1610 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1612 // We have only two entry for Non-Sku enabled PCD entry:
1619 // We have these entry for SKU enabled PCD entry
1621 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1623 SkuIdTable
= GetSkuIdArray (Index
, IsPeiDb
);
1624 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1631 return SizeTableIdx
;
1635 Get size of POINTER type PCD value.
1637 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1638 @param MaxSize Maxmium size of POINTER type PCD value.
1640 @return size of POINTER type PCD value.
1645 IN UINTN LocalTokenNumberTableIdx
,
1650 UINTN LocalTokenNumber
;
1652 SIZE_INFO
*SizeTable
;
1655 UINT32
*LocalTokenNumberTable
;
1657 // EBC compiler is very choosy. It may report warning about comparison
1658 // between UINTN and 0 . So we add 1 in each size of the
1660 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1664 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1665 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1667 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1668 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1669 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1672 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1674 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1676 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1678 *MaxSize
= SizeTable
[SizeTableIdx
];
1680 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1683 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1685 // We have only two entry for VPD enabled PCD entry:
1688 // We consider current size is equal to MAX size.
1692 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1694 // We have only two entry for Non-Sku enabled PCD entry:
1698 return SizeTable
[SizeTableIdx
+ 1];
1701 // We have these entry for SKU enabled PCD entry
1703 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1705 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1706 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1707 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.PeiDb
->SystemSkuId
) {
1708 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1711 return SizeTable
[SizeTableIdx
+ 1];
1717 Set size of POINTER type PCD value. The size should not exceed the maximum size
1720 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1721 @param CurrentSize Size of POINTER type PCD value.
1723 @retval TRUE Success to set size of PCD value.
1724 @retval FALSE Fail to set size of PCD value.
1728 IN UINTN LocalTokenNumberTableIdx
,
1729 IN OUT UINTN
*CurrentSize
1733 UINTN LocalTokenNumber
;
1735 SIZE_INFO
*SizeTable
;
1739 UINT32
*LocalTokenNumberTable
;
1742 // EBC compiler is very choosy. It may report warning about comparison
1743 // between UINTN and 0 . So we add 1 in each size of the
1746 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1749 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1750 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1752 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1753 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1754 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1757 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1759 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1761 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1763 MaxSize
= SizeTable
[SizeTableIdx
];
1765 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1768 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1770 // We shouldn't come here as we don't support SET for VPD
1775 if ((*CurrentSize
> MaxSize
) ||
1776 (*CurrentSize
== MAX_ADDRESS
)) {
1777 *CurrentSize
= MaxSize
;
1781 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1783 // We have only two entry for Non-Sku enabled PCD entry:
1787 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1791 // We have these entry for SKU enabled PCD entry
1793 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1795 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1796 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1797 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.PeiDb
->SystemSkuId
) {
1798 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1802 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;