2 Help functions used by PCD DXE driver.
4 Copyright (c) 2006 - 2014, 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
= (UINT8
*) (StringTable
+ StringTableIdx
);
462 VaraiableDefaultBuffer
= (UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
;
464 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
465 if (Status
== EFI_SUCCESS
) {
466 if (DataSize
>= (VariableHead
->Offset
+ GetSize
)) {
469 // It is a pointer type. So get the MaxSize reserved for
472 GetPtrTypeSize (TmpTokenNumber
, &GetSize
);
473 if (GetSize
> (DataSize
- VariableHead
->Offset
)) {
475 // Use actual valid size.
477 GetSize
= DataSize
- VariableHead
->Offset
;
481 // If the operation is successful, we copy the data
482 // to the default value buffer in the PCD Database.
483 // So that we can free the Data allocated in GetHiiVariable.
485 CopyMem (VaraiableDefaultBuffer
, Data
+ VariableHead
->Offset
, GetSize
);
489 RetPtr
= (VOID
*) VaraiableDefaultBuffer
;
492 case PCD_TYPE_STRING
:
493 StringTableIdx
= *(STRING_HEAD
*)((UINT8
*) PcdDb
+ Offset
);
494 RetPtr
= (VOID
*) (StringTable
+ StringTableIdx
);
498 RetPtr
= (VOID
*) ((UINT8
*) PcdDb
+ Offset
);
507 EfiReleaseLock (&mPcdDatabaseLock
);
514 Register the callback function for a PCD entry.
516 This routine will register a callback function to a PCD entry by given token number
517 and token space guid.
519 @param TokenNumber PCD token's number, it is autogened by build tools.
520 @param Guid PCD token space's guid,
521 if not NULL, this PCD is dynamicEx type PCD.
522 @param CallBackFunction Callback function pointer
524 @return EFI_SUCCESS Always success for registering callback function.
528 DxeRegisterCallBackWorker (
529 IN UINTN TokenNumber
,
530 IN CONST EFI_GUID
*Guid
, OPTIONAL
531 IN PCD_PROTOCOL_CALLBACK CallBackFunction
534 CALLBACK_FN_ENTRY
*FnTableEntry
;
535 LIST_ENTRY
*ListHead
;
536 LIST_ENTRY
*ListNode
;
539 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
543 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
544 // We have to decrement TokenNumber by 1 to make it usable
545 // as the array index of mCallbackFnTable[].
547 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
548 ListNode
= GetFirstNode (ListHead
);
550 while (ListNode
!= ListHead
) {
551 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
553 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
555 // We only allow a Callback function to be register once
556 // for a TokenNumber. So just return EFI_SUCCESS
560 ListNode
= GetNextNode (ListHead
, ListNode
);
563 FnTableEntry
= AllocatePool (sizeof(CALLBACK_FN_ENTRY
));
564 ASSERT (FnTableEntry
!= NULL
);
566 FnTableEntry
->CallbackFn
= CallBackFunction
;
567 InsertTailList (ListHead
, &FnTableEntry
->Node
);
573 UnRegister the callback function for a PCD entry.
575 This routine will unregister a callback function to a PCD entry by given token number
576 and token space guid.
578 @param TokenNumber PCD token's number, it is autogened by build tools.
579 @param Guid PCD token space's guid.
580 if not NULL, this PCD is dynamicEx type PCD.
581 @param CallBackFunction Callback function pointer
583 @retval EFI_SUCCESS Callback function is success to be unregister.
584 @retval EFI_INVALID_PARAMETER Can not find the PCD entry by given token number.
587 DxeUnRegisterCallBackWorker (
588 IN UINTN TokenNumber
,
589 IN CONST EFI_GUID
*Guid
, OPTIONAL
590 IN PCD_PROTOCOL_CALLBACK CallBackFunction
593 CALLBACK_FN_ENTRY
*FnTableEntry
;
594 LIST_ENTRY
*ListHead
;
595 LIST_ENTRY
*ListNode
;
598 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
602 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
603 // We have to decrement TokenNumber by 1 to make it usable
604 // as the array index of mCallbackFnTable[].
606 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
607 ListNode
= GetFirstNode (ListHead
);
609 while (ListNode
!= ListHead
) {
610 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
612 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
614 // We only allow a Callback function to be register once
615 // for a TokenNumber. So we can safely remove the Node from
616 // the Link List and return EFI_SUCCESS.
618 RemoveEntryList (ListNode
);
619 FreePool (FnTableEntry
);
623 ListNode
= GetNextNode (ListHead
, ListNode
);
626 return EFI_INVALID_PARAMETER
;
630 Get next token number in given token space.
632 This routine is used for dynamicEx type PCD. It will firstly scan token space
633 table to get token space according to given token space guid. Then scan given
634 token number in found token space, if found, then return next token number in
637 @param Guid Token space guid. Next token number will be scaned in
639 @param TokenNumber Token number.
640 If PCD_INVALID_TOKEN_NUMBER, return first token number in
642 If not PCD_INVALID_TOKEN_NUMBER, return next token number
643 in token space table.
644 @param GuidTable Token space guid table. It will be used for scan token space
645 by given token space guid.
646 @param SizeOfGuidTable The size of guid table.
647 @param ExMapTable DynamicEx token number mapping table.
648 @param SizeOfExMapTable The size of dynamicEx token number mapping table.
650 @retval EFI_NOT_FOUND Can not given token space or token number.
651 @retval EFI_SUCCESS Success to get next token number.
655 ExGetNextTokeNumber (
656 IN CONST EFI_GUID
*Guid
,
657 IN OUT UINTN
*TokenNumber
,
658 IN EFI_GUID
*GuidTable
,
659 IN UINTN SizeOfGuidTable
,
660 IN DYNAMICEX_MAPPING
*ExMapTable
,
661 IN UINTN SizeOfExMapTable
668 UINTN ExMapTableCount
;
671 // Scan token space guid
673 MatchGuid
= ScanGuid (GuidTable
, SizeOfGuidTable
, Guid
);
674 if (MatchGuid
== NULL
) {
675 return EFI_NOT_FOUND
;
679 // Find the token space table in dynamicEx mapping table.
682 GuidTableIdx
= MatchGuid
- GuidTable
;
683 ExMapTableCount
= SizeOfExMapTable
/ sizeof(ExMapTable
[0]);
684 for (Index
= 0; Index
< ExMapTableCount
; Index
++) {
685 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
693 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
694 // token number in found token space.
696 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
697 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
701 for ( ; Index
< ExMapTableCount
; Index
++) {
702 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
707 while (Index
< ExMapTableCount
) {
709 if (Index
== ExMapTableCount
) {
711 // Exceed the length of ExMap Table
713 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
714 return EFI_NOT_FOUND
;
715 } else if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
717 // Found the next match
719 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
725 return EFI_NOT_FOUND
;
729 Find the PCD database.
731 @retval The base address of external PCD database binary.
732 @retval NULL Return NULL if not find.
739 DXE_PCD_DATABASE
*DxePcdDbBinary
;
743 DxePcdDbBinary
= NULL
;
745 // Search the External Pcd database from one section of current FFS,
746 // and read it to memory
748 Status
= GetSectionFromFfs (
751 (VOID
**) &DxePcdDbBinary
,
754 ASSERT_EFI_ERROR (Status
);
757 // Check the first bytes (Header Signature Guid) and build version.
759 if (!CompareGuid ((VOID
*)DxePcdDbBinary
, &gPcdDataBaseSignatureGuid
) ||
760 (DxePcdDbBinary
->BuildVersion
!= PCD_SERVICE_DXE_VERSION
)) {
764 return DxePcdDbBinary
;
768 Initialize the PCD database in DXE phase.
770 PCD database in DXE phase also contains PCD database in PEI phase which is copied
775 BuildPcdDxeDataBase (
779 PEI_PCD_DATABASE
*PeiDatabase
;
780 EFI_HOB_GUID_TYPE
*GuidHob
;
786 // Assign PCD Entries with default value to PCD DATABASE
788 mPcdDatabase
.DxeDb
= LocateExPcdBinary ();
789 ASSERT(mPcdDatabase
.DxeDb
!= NULL
);
790 PcdDxeDbLen
= mPcdDatabase
.DxeDb
->Length
+ mPcdDatabase
.DxeDb
->UninitDataBaseSize
;
791 PcdDxeDb
= AllocateZeroPool (PcdDxeDbLen
);
792 ASSERT (PcdDxeDb
!= NULL
);
793 CopyMem (PcdDxeDb
, mPcdDatabase
.DxeDb
, mPcdDatabase
.DxeDb
->Length
);
794 FreePool (mPcdDatabase
.DxeDb
);
795 mPcdDatabase
.DxeDb
= PcdDxeDb
;
797 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
798 if (GuidHob
!= NULL
) {
801 // If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
802 // should not be included at all. So the GuidHob could
803 // be NULL. If it is NULL, we just copy over the DXE Default
804 // Value to PCD Database.
807 PeiDatabase
= (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
809 // Assign PCD Entries refereneced in PEI phase to PCD DATABASE
811 mPcdDatabase
.PeiDb
= PeiDatabase
;
813 // Inherit the SystemSkuId from PEI phase.
815 mPcdDatabase
.DxeDb
->SystemSkuId
= mPcdDatabase
.PeiDb
->SystemSkuId
;
817 mPcdDatabase
.PeiDb
= AllocateZeroPool (sizeof (PEI_PCD_DATABASE
));
818 ASSERT(mPcdDatabase
.PeiDb
!= NULL
);
822 // Initialized the external PCD database local variables
824 mPeiLocalTokenCount
= mPcdDatabase
.PeiDb
->LocalTokenCount
;
825 mDxeLocalTokenCount
= mPcdDatabase
.DxeDb
->LocalTokenCount
;
827 mPeiExMapppingTableSize
= mPcdDatabase
.PeiDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
828 mDxeExMapppingTableSize
= mPcdDatabase
.DxeDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
829 mPeiGuidTableSize
= mPcdDatabase
.PeiDb
->GuidTableCount
* sizeof(GUID
);
830 mDxeGuidTableSize
= mPcdDatabase
.DxeDb
->GuidTableCount
* sizeof (GUID
);
832 mPcdTotalTokenCount
= mPeiLocalTokenCount
+ mDxeLocalTokenCount
;
833 mPeiNexTokenCount
= mPeiLocalTokenCount
- mPcdDatabase
.PeiDb
->ExTokenCount
;
834 mDxeNexTokenCount
= mDxeLocalTokenCount
- mPcdDatabase
.DxeDb
->ExTokenCount
;
836 mPeiExMapTableEmpty
= (mPcdDatabase
.PeiDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
837 mDxeExMapTableEmpty
= (mPcdDatabase
.DxeDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
838 mPeiDatabaseEmpty
= (mPeiLocalTokenCount
== 0) ? TRUE
: FALSE
;
840 TmpTokenSpaceBufferCount
= mPcdDatabase
.PeiDb
->ExTokenCount
+ mPcdDatabase
.DxeDb
->ExTokenCount
;
841 TmpTokenSpaceBuffer
= (EFI_GUID
**)AllocateZeroPool(TmpTokenSpaceBufferCount
* sizeof (EFI_GUID
*));
844 // Initialized the Callback Function Table
846 mCallbackFnTable
= AllocateZeroPool (mPcdTotalTokenCount
* sizeof (LIST_ENTRY
));
847 ASSERT(mCallbackFnTable
!= NULL
);
850 // EBC compiler is very choosy. It may report warning about comparison
851 // between UINTN and 0 . So we add 1 in each size of the
854 for (Index
= 0; Index
+ 1 < mPcdTotalTokenCount
+ 1; Index
++) {
855 InitializeListHead (&mCallbackFnTable
[Index
]);
860 Get Variable which contains HII type PCD entry.
862 @param VariableGuid Variable's guid
863 @param VariableName Variable's unicode name string
864 @param VariableData Variable's data pointer,
865 @param VariableSize Variable's size.
867 @return the status of gRT->GetVariable
871 IN EFI_GUID
*VariableGuid
,
872 IN UINT16
*VariableName
,
873 OUT UINT8
**VariableData
,
874 OUT UINTN
*VariableSize
885 // Firstly get the real size of HII variable
887 Status
= gRT
->GetVariable (
888 (UINT16
*)VariableName
,
896 // Allocate buffer to hold whole variable data according to variable size.
898 if (Status
== EFI_BUFFER_TOO_SMALL
) {
899 Buffer
= (UINT8
*) AllocatePool (Size
);
901 ASSERT (Buffer
!= NULL
);
903 Status
= gRT
->GetVariable (
911 ASSERT (Status
== EFI_SUCCESS
);
912 *VariableData
= Buffer
;
913 *VariableSize
= Size
;
916 // Use Default Data only when variable is not found.
917 // For other error status, correct data can't be got, and trig ASSERT().
919 ASSERT (Status
== EFI_NOT_FOUND
);
926 Find the local token number according to system SKU ID.
928 @param LocalTokenNumber PCD token number
929 @param Size The size of PCD entry.
930 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
931 If False, the PCD entry is initialized in DXE phase.
933 @return Token number according to system SKU ID.
937 GetSkuEnabledTokenNumber (
938 UINT32 LocalTokenNumber
,
950 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
952 PcdDb
= IsPeiDb
? (UINT8
*) mPcdDatabase
.PeiDb
: (UINT8
*) mPcdDatabase
.DxeDb
;
954 SkuHead
= (SKU_HEAD
*) (PcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
955 Value
= (UINT8
*) (PcdDb
+ SkuHead
->SkuDataStartOffset
);
957 SkuIdTable
= (SKU_ID
*)(PcdDb
+ SkuHead
->SkuIdTableOffset
);
959 // Find the current system's SKU ID entry in SKU ID table.
962 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
963 if (mPcdDatabase
.DxeDb
->SystemSkuId
== SkuIdTable
[Index
+ 1]) {
970 // Find the default SKU ID entry in SKU ID table.
974 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
975 if (0 == SkuIdTable
[Index
+ 1]) {
980 ASSERT (Index
< SkuIdTable
[0]);
982 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
984 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
985 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_VPD
);
988 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
989 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
);
991 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
992 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
993 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
| PCD_TYPE_STRING
);
995 case PCD_TYPE_STRING
:
996 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
997 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_STRING
);
1000 Value
+= Size
* Index
;
1001 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_DATA
);
1014 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
1015 has registered callback function.
1017 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
1019 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
1021 @param TokenNumber PCD token number generated by build tools.
1022 @param Data Value want to be set for this PCD entry
1023 @param Size The size of value
1027 InvokeCallbackOnSet (
1028 UINT32 ExTokenNumber
,
1029 CONST EFI_GUID
*Guid
, OPTIONAL
1035 CALLBACK_FN_ENTRY
*FnTableEntry
;
1036 LIST_ENTRY
*ListHead
;
1037 LIST_ENTRY
*ListNode
;
1040 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1041 // We have to decrement TokenNumber by 1 to make it usable
1042 // as the array index of mCallbackFnTable[].
1044 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
1045 ListNode
= GetFirstNode (ListHead
);
1047 while (ListNode
!= ListHead
) {
1048 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE (ListNode
, CALLBACK_FN_ENTRY
, Node
);
1050 FnTableEntry
->CallbackFn(Guid
,
1051 (Guid
== NULL
) ? TokenNumber
: ExTokenNumber
,
1055 ListNode
= GetNextNode (ListHead
, ListNode
);
1063 Wrapper function for setting non-pointer type value for a PCD entry.
1065 @param TokenNumber Pcd token number autogenerated by build tools.
1066 @param Data Value want to be set for PCD entry
1067 @param Size Size of value.
1069 @return status of SetWorker.
1074 IN UINTN TokenNumber
,
1079 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
1084 Set value for an PCD entry
1086 @param TokenNumber Pcd token number autogenerated by build tools.
1087 @param Data Value want to be set for PCD entry
1088 @param Size Size of value.
1089 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
1090 If False, the type of PCD entry's value is not Pointer.
1092 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
1093 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
1094 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
1095 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
1096 range of UINT8, UINT16, UINT32, UINT64
1097 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
1101 IN UINTN TokenNumber
,
1108 UINT32 LocalTokenNumber
;
1109 EFI_GUID
*GuidTable
;
1113 UINTN VariableOffset
;
1115 VARIABLE_HEAD
*VariableHead
;
1120 UINTN TmpTokenNumber
;
1123 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1124 // We have to decrement TokenNumber by 1 to make it usable
1125 // as the array index.
1129 TmpTokenNumber
= TokenNumber
;
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 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
1140 // Get MaxSize first, then check new size with max buffer size.
1142 GetPtrTypeSize (TokenNumber
, &MaxSize
);
1143 if (*Size
> MaxSize
) {
1145 return EFI_INVALID_PARAMETER
;
1148 if (*Size
!= DxePcdGetSize (TokenNumber
+ 1)) {
1149 return EFI_INVALID_PARAMETER
;
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 if ((TokenNumber
+ 1 < mPeiNexTokenCount
+ 1) ||
1159 (TokenNumber
+ 1 >= mPeiLocalTokenCount
+ 1 && TokenNumber
+ 1 < (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1))) {
1160 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
1164 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1166 EfiAcquireLock (&mPcdDatabaseLock
);
1169 // EBC compiler is very choosy. It may report warning about comparison
1170 // between UINTN and 0 . So we add 1 in each size of the
1173 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1) ? TRUE
: FALSE
);
1175 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
+ 1);
1177 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
1179 PcdDb
= IsPeiDb
? ((UINT8
*) mPcdDatabase
.PeiDb
) : ((UINT8
*) mPcdDatabase
.DxeDb
);
1182 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->StringTableOffset
);
1184 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->StringTableOffset
);
1188 InternalData
= PcdDb
+ Offset
;
1190 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
1193 Status
= EFI_INVALID_PARAMETER
;
1196 case PCD_TYPE_STRING
:
1197 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1198 CopyMem (StringTable
+ *((STRING_HEAD
*)InternalData
), Data
, *Size
);
1199 Status
= EFI_SUCCESS
;
1201 Status
= EFI_INVALID_PARAMETER
;
1205 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
1208 if (!SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1209 Status
= EFI_INVALID_PARAMETER
;
1215 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1217 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1220 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
1222 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
1223 Name
= (UINT16
*) (StringTable
+ VariableHead
->StringIndex
);
1224 VariableOffset
= VariableHead
->Offset
;
1225 Status
= SetHiiVariable (Guid
, Name
, Data
, *Size
, VariableOffset
);
1227 if (EFI_NOT_FOUND
== Status
) {
1228 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
1230 StringTable
+ *(STRING_HEAD
*)(PcdDb
+ VariableHead
->DefaultValueOffset
),
1235 CopyMem (PcdDb
+ VariableHead
->DefaultValueOffset
, Data
, *Size
);
1237 Status
= EFI_SUCCESS
;
1243 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1244 CopyMem (InternalData
, Data
, *Size
);
1245 Status
= EFI_SUCCESS
;
1247 Status
= EFI_INVALID_PARAMETER
;
1252 Status
= EFI_SUCCESS
;
1255 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
1258 case sizeof(UINT16
):
1259 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
1262 case sizeof(UINT32
):
1263 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
1266 case sizeof(UINT64
):
1267 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
1272 Status
= EFI_NOT_FOUND
;
1279 Status
= EFI_NOT_FOUND
;
1283 EfiReleaseLock (&mPcdDatabaseLock
);
1289 Wrapper function for get PCD value for dynamic-ex PCD.
1291 @param Guid Token space guid for dynamic-ex PCD.
1292 @param ExTokenNumber Token number for dynamic-ex PCD.
1293 @param GetSize The size of dynamic-ex PCD value.
1295 @return PCD entry in PCD database.
1300 IN CONST EFI_GUID
*Guid
,
1301 IN UINTN ExTokenNumber
,
1305 return GetWorker(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
), GetSize
);
1309 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
1311 @param ExTokenNumber Token number for dynamic-ex PCD.
1312 @param Guid Token space guid for dynamic-ex PCD.
1313 @param Data Value want to be set.
1314 @param SetSize The size of value.
1316 @return status of ExSetWorker().
1321 IN UINTN ExTokenNumber
,
1322 IN CONST EFI_GUID
*Guid
,
1327 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &SetSize
, FALSE
);
1331 Set value for a dynamic-ex PCD entry.
1333 This routine find the local token number according to dynamic-ex PCD's token
1334 space guid and token number firstly, and invoke callback function if this PCD
1335 entry registered callback function. Finally, invoken general SetWorker to set
1338 @param ExTokenNumber Dynamic-ex PCD token number.
1339 @param Guid Token space guid for dynamic-ex PCD.
1340 @param Data PCD value want to be set
1341 @param SetSize Size of value.
1342 @param PtrType If TRUE, this PCD entry is pointer type.
1343 If FALSE, this PCD entry is not pointer type.
1345 @return status of SetWorker().
1350 IN UINTN ExTokenNumber
,
1351 IN CONST EFI_GUID
*Guid
,
1353 IN OUT UINTN
*SetSize
,
1359 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
);
1361 InvokeCallbackOnSet ((UINT32
) ExTokenNumber
, Guid
, TokenNumber
, Data
, *SetSize
);
1363 return SetWorker (TokenNumber
, Data
, SetSize
, PtrType
);
1368 Set value for HII-type PCD.
1370 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
1371 HII-type PCD is to visit this variable.
1373 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
1374 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
1375 @param Data Value want to be set.
1376 @param DataSize Size of value
1377 @param Offset Value offset of HII-type PCD in variable.
1379 @return status of GetVariable()/SetVariable().
1384 IN EFI_GUID
*VariableGuid
,
1385 IN UINT16
*VariableName
,
1386 IN CONST VOID
*Data
,
1401 // Try to get original variable size information.
1403 Status
= gRT
->GetVariable (
1404 (UINT16
*)VariableName
,
1411 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1413 // Patch new PCD's value to offset in given HII variable.
1415 if (Size
>= (DataSize
+ Offset
)) {
1418 SetSize
= DataSize
+ Offset
;
1420 Buffer
= AllocatePool (SetSize
);
1421 ASSERT (Buffer
!= NULL
);
1423 Status
= gRT
->GetVariable (
1431 ASSERT_EFI_ERROR (Status
);
1433 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1435 Status
= gRT
->SetVariable (
1445 } else if (Status
== EFI_NOT_FOUND
) {
1447 // If variable does not exist, a new variable need to be created.
1450 Size
= Offset
+ DataSize
;
1452 Buffer
= AllocateZeroPool (Size
);
1453 ASSERT (Buffer
!= NULL
);
1455 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1457 Status
= gRT
->SetVariable (
1460 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1470 // If we drop to here, the value is failed to be written in to variable area
1471 // So, we will save the data in the PCD Database's volatile area.
1477 Get Token Number according to dynamic-ex PCD's {token space guid:token number}
1479 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1480 in DEC file. PCD database maintain a mapping table that translate pair of {token
1481 space guid: token number} to Token Number.
1483 @param Guid Token space guid for dynamic-ex PCD entry.
1484 @param ExTokenNumber Dynamic-ex PCD token number.
1486 @return Token Number for dynamic-ex PCD.
1490 GetExPcdTokenNumber (
1491 IN CONST EFI_GUID
*Guid
,
1492 IN UINT32 ExTokenNumber
1496 DYNAMICEX_MAPPING
*ExMap
;
1497 EFI_GUID
*GuidTable
;
1498 EFI_GUID
*MatchGuid
;
1501 if (!mPeiDatabaseEmpty
) {
1502 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
);
1503 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1505 MatchGuid
= ScanGuid (GuidTable
, mPeiGuidTableSize
, Guid
);
1507 if (MatchGuid
!= NULL
) {
1509 MatchGuidIdx
= MatchGuid
- GuidTable
;
1511 for (Index
= 0; Index
< mPeiExMapppingTableSize
; Index
++) {
1512 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1513 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1514 return ExMap
[Index
].TokenNumber
;
1520 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
);
1521 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1523 MatchGuid
= ScanGuid (GuidTable
, mDxeGuidTableSize
, Guid
);
1525 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1526 // error in the BUILD system.
1528 ASSERT (MatchGuid
!= NULL
);
1530 MatchGuidIdx
= MatchGuid
- GuidTable
;
1532 for (Index
= 0; Index
< mDxeExMapppingTableSize
; Index
++) {
1533 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1534 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1535 return ExMap
[Index
].TokenNumber
;
1545 Get SKU ID table from PCD database.
1547 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1548 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1549 If FALSE, the pcd entry is initialized in DXE phase.
1550 @return Pointer to SKU ID array table
1555 IN UINTN LocalTokenNumberTableIdx
,
1560 UINTN LocalTokenNumber
;
1564 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1565 Database
= (UINT8
*) mPcdDatabase
.PeiDb
;
1567 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1568 Database
= (UINT8
*) mPcdDatabase
.DxeDb
;
1571 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1573 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1575 return (SKU_ID
*) (Database
+ SkuHead
->SkuIdTableOffset
);
1580 Wrapper function of getting index of PCD entry in size table.
1582 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1583 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1584 If FALSE, the pcd entry is initialized in DXE phase.
1586 @return index of PCD entry in size table.
1590 IN UINTN LocalTokenNumberTableIdx
,
1594 UINT32
*LocalTokenNumberTable
;
1595 UINTN LocalTokenNumber
;
1601 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1603 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1608 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
1609 LocalTokenNumber
= LocalTokenNumberTable
[Index
];
1611 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1613 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1616 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1618 // We have only two entry for VPD enabled PCD entry:
1621 // Current size is equal to MAX size.
1625 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1627 // We have only two entry for Non-Sku enabled PCD entry:
1634 // We have these entry for SKU enabled PCD entry
1636 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1638 SkuIdTable
= GetSkuIdArray (Index
, IsPeiDb
);
1639 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1646 return SizeTableIdx
;
1650 Get size of POINTER type PCD value.
1652 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1653 @param MaxSize Maxmium size of POINTER type PCD value.
1655 @return size of POINTER type PCD value.
1660 IN UINTN LocalTokenNumberTableIdx
,
1665 UINTN LocalTokenNumber
;
1667 SIZE_INFO
*SizeTable
;
1670 UINT32
*LocalTokenNumberTable
;
1672 // EBC compiler is very choosy. It may report warning about comparison
1673 // between UINTN and 0 . So we add 1 in each size of the
1675 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1679 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1680 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1682 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1683 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1684 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1687 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1689 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1691 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1693 *MaxSize
= SizeTable
[SizeTableIdx
];
1695 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1698 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1700 // We have only two entry for VPD enabled PCD entry:
1703 // We consider current size is equal to MAX size.
1707 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1709 // We have only two entry for Non-Sku enabled PCD entry:
1713 return SizeTable
[SizeTableIdx
+ 1];
1716 // We have these entry for SKU enabled PCD entry
1718 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1720 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1721 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1722 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.DxeDb
->SystemSkuId
) {
1723 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1726 return SizeTable
[SizeTableIdx
+ 1];
1732 Set size of POINTER type PCD value. The size should not exceed the maximum size
1735 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1736 @param CurrentSize Size of POINTER type PCD value.
1738 @retval TRUE Success to set size of PCD value.
1739 @retval FALSE Fail to set size of PCD value.
1743 IN UINTN LocalTokenNumberTableIdx
,
1744 IN OUT UINTN
*CurrentSize
1748 UINTN LocalTokenNumber
;
1750 SIZE_INFO
*SizeTable
;
1754 UINT32
*LocalTokenNumberTable
;
1757 // EBC compiler is very choosy. It may report warning about comparison
1758 // between UINTN and 0 . So we add 1 in each size of the
1761 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1764 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1765 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1767 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1768 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1769 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1772 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1774 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1776 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1778 MaxSize
= SizeTable
[SizeTableIdx
];
1780 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1783 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1785 // We shouldn't come here as we don't support SET for VPD
1790 if ((*CurrentSize
> MaxSize
) ||
1791 (*CurrentSize
== MAX_ADDRESS
)) {
1792 *CurrentSize
= MaxSize
;
1796 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1798 // We have only two entry for Non-Sku enabled PCD entry:
1802 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1806 // We have these entry for SKU enabled PCD entry
1808 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1810 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1811 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1812 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.DxeDb
->SystemSkuId
) {
1813 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1817 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;