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
;
778 // Assign PCD Entries with default value to PCD DATABASE
780 mPcdDatabase
.DxeDb
= LocateExPcdBinary ();
781 ASSERT(mPcdDatabase
.DxeDb
!= NULL
);
782 PcdDxeDbLen
= mPcdDatabase
.DxeDb
->Length
+ mPcdDatabase
.DxeDb
->UninitDataBaseSize
;
783 PcdDxeDb
= AllocateZeroPool (PcdDxeDbLen
);
784 ASSERT (PcdDxeDb
!= NULL
);
785 CopyMem (PcdDxeDb
, mPcdDatabase
.DxeDb
, mPcdDatabase
.DxeDb
->Length
);
786 FreePool (mPcdDatabase
.DxeDb
);
787 mPcdDatabase
.DxeDb
= PcdDxeDb
;
789 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
790 if (GuidHob
!= NULL
) {
793 // If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
794 // should not be included at all. So the GuidHob could
795 // be NULL. If it is NULL, we just copy over the DXE Default
796 // Value to PCD Database.
799 PeiDatabase
= (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
801 // Assign PCD Entries refereneced in PEI phase to PCD DATABASE
803 mPcdDatabase
.PeiDb
= PeiDatabase
;
805 // Inherit the SystemSkuId from PEI phase.
807 mPcdDatabase
.DxeDb
->SystemSkuId
= mPcdDatabase
.PeiDb
->SystemSkuId
;
809 mPcdDatabase
.PeiDb
= AllocateZeroPool (sizeof (PEI_PCD_DATABASE
));
810 ASSERT(mPcdDatabase
.PeiDb
!= NULL
);
814 // Initialized the external PCD database local variables
816 mPeiLocalTokenCount
= mPcdDatabase
.PeiDb
->LocalTokenCount
;
817 mDxeLocalTokenCount
= mPcdDatabase
.DxeDb
->LocalTokenCount
;
819 mPeiExMapppingTableSize
= mPcdDatabase
.PeiDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
820 mDxeExMapppingTableSize
= mPcdDatabase
.DxeDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
821 mPeiGuidTableSize
= mPcdDatabase
.PeiDb
->GuidTableCount
* sizeof(GUID
);
822 mDxeGuidTableSize
= mPcdDatabase
.DxeDb
->GuidTableCount
* sizeof (GUID
);
824 mPcdTotalTokenCount
= mPeiLocalTokenCount
+ mDxeLocalTokenCount
;
825 mPeiNexTokenCount
= mPeiLocalTokenCount
- mPcdDatabase
.PeiDb
->ExTokenCount
;
826 mDxeNexTokenCount
= mDxeLocalTokenCount
- mPcdDatabase
.DxeDb
->ExTokenCount
;
828 mPeiExMapTableEmpty
= (mPcdDatabase
.PeiDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
829 mDxeExMapTableEmpty
= (mPcdDatabase
.DxeDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
830 mPeiDatabaseEmpty
= (mPeiLocalTokenCount
== 0) ? TRUE
: FALSE
;
832 TmpTokenSpaceBufferCount
= mPcdDatabase
.PeiDb
->ExTokenCount
+ mPcdDatabase
.DxeDb
->ExTokenCount
;
833 TmpTokenSpaceBuffer
= (EFI_GUID
**)AllocateZeroPool(TmpTokenSpaceBufferCount
* sizeof (EFI_GUID
*));
836 // Initialized the Callback Function Table
838 mCallbackFnTable
= AllocateZeroPool (mPcdTotalTokenCount
* sizeof (LIST_ENTRY
));
839 ASSERT(mCallbackFnTable
!= NULL
);
842 // EBC compiler is very choosy. It may report warning about comparison
843 // between UINTN and 0 . So we add 1 in each size of the
846 for (Index
= 0; Index
+ 1 < mPcdTotalTokenCount
+ 1; Index
++) {
847 InitializeListHead (&mCallbackFnTable
[Index
]);
852 Get Variable which contains HII type PCD entry.
854 @param VariableGuid Variable's guid
855 @param VariableName Variable's unicode name string
856 @param VariableData Variable's data pointer,
857 @param VariableSize Variable's size.
859 @return the status of gRT->GetVariable
863 IN EFI_GUID
*VariableGuid
,
864 IN UINT16
*VariableName
,
865 OUT UINT8
**VariableData
,
866 OUT UINTN
*VariableSize
877 // Firstly get the real size of HII variable
879 Status
= gRT
->GetVariable (
880 (UINT16
*)VariableName
,
888 // Allocate buffer to hold whole variable data according to variable size.
890 if (Status
== EFI_BUFFER_TOO_SMALL
) {
891 Buffer
= (UINT8
*) AllocatePool (Size
);
893 ASSERT (Buffer
!= NULL
);
895 Status
= gRT
->GetVariable (
903 ASSERT (Status
== EFI_SUCCESS
);
904 *VariableData
= Buffer
;
905 *VariableSize
= Size
;
908 // Use Default Data only when variable is not found.
909 // For other error status, correct data can't be got, and trig ASSERT().
911 ASSERT (Status
== EFI_NOT_FOUND
);
918 Find the local token number according to system SKU ID.
920 @param LocalTokenNumber PCD token number
921 @param Size The size of PCD entry.
922 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
923 If False, the PCD entry is initialized in DXE phase.
925 @return Token number according to system SKU ID.
929 GetSkuEnabledTokenNumber (
930 UINT32 LocalTokenNumber
,
942 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
944 PcdDb
= IsPeiDb
? (UINT8
*) mPcdDatabase
.PeiDb
: (UINT8
*) mPcdDatabase
.DxeDb
;
946 SkuHead
= (SKU_HEAD
*) (PcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
947 Value
= (UINT8
*) (PcdDb
+ SkuHead
->SkuDataStartOffset
);
949 SkuIdTable
= (SKU_ID
*)(PcdDb
+ SkuHead
->SkuIdTableOffset
);
951 // Find the current system's SKU ID entry in SKU ID table.
954 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
955 if (mPcdDatabase
.DxeDb
->SystemSkuId
== SkuIdTable
[Index
+ 1]) {
962 // Find the default SKU ID entry in SKU ID table.
966 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
967 if (0 == SkuIdTable
[Index
+ 1]) {
972 ASSERT (Index
< SkuIdTable
[0]);
974 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
976 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
977 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_VPD
);
980 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
981 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
);
983 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
984 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
985 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
| PCD_TYPE_STRING
);
987 case PCD_TYPE_STRING
:
988 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
989 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_STRING
);
992 Value
+= Size
* Index
;
993 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_DATA
);
1006 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
1007 has registered callback function.
1009 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
1011 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
1013 @param TokenNumber PCD token number generated by build tools.
1014 @param Data Value want to be set for this PCD entry
1015 @param Size The size of value
1019 InvokeCallbackOnSet (
1020 UINT32 ExTokenNumber
,
1021 CONST EFI_GUID
*Guid
, OPTIONAL
1027 CALLBACK_FN_ENTRY
*FnTableEntry
;
1028 LIST_ENTRY
*ListHead
;
1029 LIST_ENTRY
*ListNode
;
1032 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1033 // We have to decrement TokenNumber by 1 to make it usable
1034 // as the array index of mCallbackFnTable[].
1036 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
1037 ListNode
= GetFirstNode (ListHead
);
1039 while (ListNode
!= ListHead
) {
1040 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE (ListNode
, CALLBACK_FN_ENTRY
, Node
);
1042 FnTableEntry
->CallbackFn(Guid
,
1043 (Guid
== NULL
) ? TokenNumber
: ExTokenNumber
,
1047 ListNode
= GetNextNode (ListHead
, ListNode
);
1055 Wrapper function for setting non-pointer type value for a PCD entry.
1057 @param TokenNumber Pcd token number autogenerated by build tools.
1058 @param Data Value want to be set for PCD entry
1059 @param Size Size of value.
1061 @return status of SetWorker.
1066 IN UINTN TokenNumber
,
1071 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
1076 Set value for an PCD entry
1078 @param TokenNumber Pcd token number autogenerated by build tools.
1079 @param Data Value want to be set for PCD entry
1080 @param Size Size of value.
1081 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
1082 If False, the type of PCD entry's value is not Pointer.
1084 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
1085 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
1086 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
1087 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
1088 range of UINT8, UINT16, UINT32, UINT64
1089 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
1093 IN UINTN TokenNumber
,
1100 UINT32 LocalTokenNumber
;
1101 EFI_GUID
*GuidTable
;
1105 UINTN VariableOffset
;
1107 VARIABLE_HEAD
*VariableHead
;
1112 UINTN TmpTokenNumber
;
1115 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1116 // We have to decrement TokenNumber by 1 to make it usable
1117 // as the array index.
1121 TmpTokenNumber
= TokenNumber
;
1124 // EBC compiler is very choosy. It may report warning about comparison
1125 // between UINTN and 0 . So we add 1 in each size of the
1128 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
1132 // Get MaxSize first, then check new size with max buffer size.
1134 GetPtrTypeSize (TokenNumber
, &MaxSize
);
1135 if (*Size
> MaxSize
) {
1137 return EFI_INVALID_PARAMETER
;
1140 if (*Size
!= DxePcdGetSize (TokenNumber
+ 1)) {
1141 return EFI_INVALID_PARAMETER
;
1146 // EBC compiler is very choosy. It may report warning about comparison
1147 // between UINTN and 0 . So we add 1 in each size of the
1150 if ((TokenNumber
+ 1 < mPeiNexTokenCount
+ 1) ||
1151 (TokenNumber
+ 1 >= mPeiLocalTokenCount
+ 1 && TokenNumber
+ 1 < (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1))) {
1152 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
1156 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1158 EfiAcquireLock (&mPcdDatabaseLock
);
1161 // EBC compiler is very choosy. It may report warning about comparison
1162 // between UINTN and 0 . So we add 1 in each size of the
1165 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1) ? TRUE
: FALSE
);
1167 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
+ 1);
1169 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
1171 PcdDb
= IsPeiDb
? ((UINT8
*) mPcdDatabase
.PeiDb
) : ((UINT8
*) mPcdDatabase
.DxeDb
);
1174 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->StringTableOffset
);
1176 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->StringTableOffset
);
1180 InternalData
= PcdDb
+ Offset
;
1182 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
1185 Status
= EFI_INVALID_PARAMETER
;
1188 case PCD_TYPE_STRING
:
1189 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1190 CopyMem (StringTable
+ *((STRING_HEAD
*)InternalData
), Data
, *Size
);
1191 Status
= EFI_SUCCESS
;
1193 Status
= EFI_INVALID_PARAMETER
;
1197 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
1200 if (!SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1201 Status
= EFI_INVALID_PARAMETER
;
1207 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1209 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1212 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
1214 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
1215 Name
= (UINT16
*) (StringTable
+ VariableHead
->StringIndex
);
1216 VariableOffset
= VariableHead
->Offset
;
1217 Status
= SetHiiVariable (Guid
, Name
, Data
, *Size
, VariableOffset
);
1219 if (EFI_NOT_FOUND
== Status
) {
1220 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
1222 StringTable
+ *(STRING_HEAD
*)(PcdDb
+ VariableHead
->DefaultValueOffset
),
1227 CopyMem (PcdDb
+ VariableHead
->DefaultValueOffset
, Data
, *Size
);
1229 Status
= EFI_SUCCESS
;
1235 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1236 CopyMem (InternalData
, Data
, *Size
);
1237 Status
= EFI_SUCCESS
;
1239 Status
= EFI_INVALID_PARAMETER
;
1244 Status
= EFI_SUCCESS
;
1247 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
1250 case sizeof(UINT16
):
1251 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
1254 case sizeof(UINT32
):
1255 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
1258 case sizeof(UINT64
):
1259 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
1264 Status
= EFI_NOT_FOUND
;
1271 Status
= EFI_NOT_FOUND
;
1275 EfiReleaseLock (&mPcdDatabaseLock
);
1281 Wrapper function for get PCD value for dynamic-ex PCD.
1283 @param Guid Token space guid for dynamic-ex PCD.
1284 @param ExTokenNumber Token number for dynamic-ex PCD.
1285 @param GetSize The size of dynamic-ex PCD value.
1287 @return PCD entry in PCD database.
1292 IN CONST EFI_GUID
*Guid
,
1293 IN UINTN ExTokenNumber
,
1297 return GetWorker(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
), GetSize
);
1301 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
1303 @param ExTokenNumber Token number for dynamic-ex PCD.
1304 @param Guid Token space guid for dynamic-ex PCD.
1305 @param Data Value want to be set.
1306 @param SetSize The size of value.
1308 @return status of ExSetWorker().
1313 IN UINTN ExTokenNumber
,
1314 IN CONST EFI_GUID
*Guid
,
1319 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &SetSize
, FALSE
);
1323 Set value for a dynamic-ex PCD entry.
1325 This routine find the local token number according to dynamic-ex PCD's token
1326 space guid and token number firstly, and invoke callback function if this PCD
1327 entry registered callback function. Finally, invoken general SetWorker to set
1330 @param ExTokenNumber Dynamic-ex PCD token number.
1331 @param Guid Token space guid for dynamic-ex PCD.
1332 @param Data PCD value want to be set
1333 @param SetSize Size of value.
1334 @param PtrType If TRUE, this PCD entry is pointer type.
1335 If FALSE, this PCD entry is not pointer type.
1337 @return status of SetWorker().
1342 IN UINTN ExTokenNumber
,
1343 IN CONST EFI_GUID
*Guid
,
1345 IN OUT UINTN
*SetSize
,
1351 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
);
1353 InvokeCallbackOnSet ((UINT32
) ExTokenNumber
, Guid
, TokenNumber
, Data
, *SetSize
);
1355 return SetWorker (TokenNumber
, Data
, SetSize
, PtrType
);
1360 Set value for HII-type PCD.
1362 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
1363 HII-type PCD is to visit this variable.
1365 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
1366 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
1367 @param Data Value want to be set.
1368 @param DataSize Size of value
1369 @param Offset Value offset of HII-type PCD in variable.
1371 @return status of GetVariable()/SetVariable().
1376 IN EFI_GUID
*VariableGuid
,
1377 IN UINT16
*VariableName
,
1378 IN CONST VOID
*Data
,
1393 // Try to get original variable size information.
1395 Status
= gRT
->GetVariable (
1396 (UINT16
*)VariableName
,
1403 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1405 // Patch new PCD's value to offset in given HII variable.
1407 if (Size
>= (DataSize
+ Offset
)) {
1410 SetSize
= DataSize
+ Offset
;
1412 Buffer
= AllocatePool (SetSize
);
1413 ASSERT (Buffer
!= NULL
);
1415 Status
= gRT
->GetVariable (
1423 ASSERT_EFI_ERROR (Status
);
1425 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1427 Status
= gRT
->SetVariable (
1437 } else if (Status
== EFI_NOT_FOUND
) {
1439 // If variable does not exist, a new variable need to be created.
1442 Size
= Offset
+ DataSize
;
1444 Buffer
= AllocateZeroPool (Size
);
1445 ASSERT (Buffer
!= NULL
);
1447 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1449 Status
= gRT
->SetVariable (
1452 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1462 // If we drop to here, the value is failed to be written in to variable area
1463 // So, we will save the data in the PCD Database's volatile area.
1469 Get Token Number according to dynamic-ex PCD's {token space guid:token number}
1471 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1472 in DEC file. PCD database maintain a mapping table that translate pair of {token
1473 space guid: token number} to Token Number.
1475 @param Guid Token space guid for dynamic-ex PCD entry.
1476 @param ExTokenNumber Dynamic-ex PCD token number.
1478 @return Token Number for dynamic-ex PCD.
1482 GetExPcdTokenNumber (
1483 IN CONST EFI_GUID
*Guid
,
1484 IN UINT32 ExTokenNumber
1488 DYNAMICEX_MAPPING
*ExMap
;
1489 EFI_GUID
*GuidTable
;
1490 EFI_GUID
*MatchGuid
;
1493 if (!mPeiDatabaseEmpty
) {
1494 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
);
1495 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1497 MatchGuid
= ScanGuid (GuidTable
, mPeiGuidTableSize
, Guid
);
1499 if (MatchGuid
!= NULL
) {
1501 MatchGuidIdx
= MatchGuid
- GuidTable
;
1503 for (Index
= 0; Index
< mPeiExMapppingTableSize
; Index
++) {
1504 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1505 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1506 return ExMap
[Index
].TokenNumber
;
1512 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
);
1513 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1515 MatchGuid
= ScanGuid (GuidTable
, mDxeGuidTableSize
, Guid
);
1517 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1518 // error in the BUILD system.
1520 ASSERT (MatchGuid
!= NULL
);
1522 MatchGuidIdx
= MatchGuid
- GuidTable
;
1524 for (Index
= 0; Index
< mDxeExMapppingTableSize
; Index
++) {
1525 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1526 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1527 return ExMap
[Index
].TokenNumber
;
1537 Get SKU ID table from PCD database.
1539 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1540 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1541 If FALSE, the pcd entry is initialized in DXE phase.
1542 @return Pointer to SKU ID array table
1547 IN UINTN LocalTokenNumberTableIdx
,
1552 UINTN LocalTokenNumber
;
1556 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1557 Database
= (UINT8
*) mPcdDatabase
.PeiDb
;
1559 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1560 Database
= (UINT8
*) mPcdDatabase
.DxeDb
;
1563 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1565 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1567 return (SKU_ID
*) (Database
+ SkuHead
->SkuIdTableOffset
);
1572 Wrapper function of getting index of PCD entry in size table.
1574 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1575 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1576 If FALSE, the pcd entry is initialized in DXE phase.
1578 @return index of PCD entry in size table.
1582 IN UINTN LocalTokenNumberTableIdx
,
1586 UINT32
*LocalTokenNumberTable
;
1587 UINTN LocalTokenNumber
;
1593 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1595 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1600 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
1601 LocalTokenNumber
= LocalTokenNumberTable
[Index
];
1603 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1605 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1608 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1610 // We have only two entry for VPD enabled PCD entry:
1613 // Current size is equal to MAX size.
1617 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1619 // We have only two entry for Non-Sku enabled PCD entry:
1626 // We have these entry for SKU enabled PCD entry
1628 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1630 SkuIdTable
= GetSkuIdArray (Index
, IsPeiDb
);
1631 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1638 return SizeTableIdx
;
1642 Get size of POINTER type PCD value.
1644 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1645 @param MaxSize Maxmium size of POINTER type PCD value.
1647 @return size of POINTER type PCD value.
1652 IN UINTN LocalTokenNumberTableIdx
,
1657 UINTN LocalTokenNumber
;
1659 SIZE_INFO
*SizeTable
;
1662 UINT32
*LocalTokenNumberTable
;
1664 // EBC compiler is very choosy. It may report warning about comparison
1665 // between UINTN and 0 . So we add 1 in each size of the
1667 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1671 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1672 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1674 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1675 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1676 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1679 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1681 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1683 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1685 *MaxSize
= SizeTable
[SizeTableIdx
];
1687 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1690 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1692 // We have only two entry for VPD enabled PCD entry:
1695 // We consider current size is equal to MAX size.
1699 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1701 // We have only two entry for Non-Sku enabled PCD entry:
1705 return SizeTable
[SizeTableIdx
+ 1];
1708 // We have these entry for SKU enabled PCD entry
1710 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1712 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1713 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1714 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.DxeDb
->SystemSkuId
) {
1715 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1718 return SizeTable
[SizeTableIdx
+ 1];
1724 Set size of POINTER type PCD value. The size should not exceed the maximum size
1727 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1728 @param CurrentSize Size of POINTER type PCD value.
1730 @retval TRUE Success to set size of PCD value.
1731 @retval FALSE Fail to set size of PCD value.
1735 IN UINTN LocalTokenNumberTableIdx
,
1736 IN OUT UINTN
*CurrentSize
1740 UINTN LocalTokenNumber
;
1742 SIZE_INFO
*SizeTable
;
1746 UINT32
*LocalTokenNumberTable
;
1749 // EBC compiler is very choosy. It may report warning about comparison
1750 // between UINTN and 0 . So we add 1 in each size of the
1753 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1756 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1757 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1759 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1760 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1761 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1764 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1766 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1768 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1770 MaxSize
= SizeTable
[SizeTableIdx
];
1772 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1775 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1777 // We shouldn't come here as we don't support SET for VPD
1782 if ((*CurrentSize
> MaxSize
) ||
1783 (*CurrentSize
== MAX_ADDRESS
)) {
1784 *CurrentSize
= MaxSize
;
1788 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1790 // We have only two entry for Non-Sku enabled PCD entry:
1794 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1798 // We have these entry for SKU enabled PCD entry
1800 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1802 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1803 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1804 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.DxeDb
->SystemSkuId
) {
1805 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1809 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;