2 Help functions used by PCD DXE driver.
4 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/DxeServicesLib.h>
19 PCD_DATABASE mPcdDatabase
;
21 UINT32 mPcdTotalTokenCount
;
22 UINT32 mPeiLocalTokenCount
;
23 UINT32 mDxeLocalTokenCount
;
24 UINT32 mPeiNexTokenCount
;
25 UINT32 mDxeNexTokenCount
;
26 UINT32 mPeiExMapppingTableSize
;
27 UINT32 mDxeExMapppingTableSize
;
28 UINT32 mPeiGuidTableSize
;
29 UINT32 mDxeGuidTableSize
;
31 BOOLEAN mPeiExMapTableEmpty
;
32 BOOLEAN mDxeExMapTableEmpty
;
33 BOOLEAN mPeiDatabaseEmpty
;
35 LIST_ENTRY
*mCallbackFnTable
;
36 EFI_GUID
**TmpTokenSpaceBuffer
;
37 UINTN TmpTokenSpaceBufferCount
;
40 Get Local Token Number by Token Number.
42 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
43 If FALSE, the pcd entry is initialized in DXE phase.
44 @param[in] TokenNumber The PCD token number.
46 @return Local Token Number.
55 UINT32
*LocalTokenNumberTable
;
56 UINT32 LocalTokenNumber
;
61 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
62 // We have to decrement TokenNumber by 1 to make it usable
63 // as the array index.
68 // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
70 TmpTokenNumber
= TokenNumber
;
72 LocalTokenNumberTable
= IsPeiDb
? (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
) :
73 (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
74 TokenNumber
= IsPeiDb
? TokenNumber
: TokenNumber
- mPeiLocalTokenCount
;
76 LocalTokenNumber
= LocalTokenNumberTable
[TokenNumber
];
78 Size
= (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
80 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
82 GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
86 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
, IsPeiDb
);
89 return LocalTokenNumber
;
93 Get PCD type by Local Token Number.
95 @param[in] LocalTokenNumber The PCD local token number.
101 IN UINT32 LocalTokenNumber
104 switch (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) {
105 case PCD_DATUM_TYPE_POINTER
:
106 return EFI_PCD_TYPE_PTR
;
107 case PCD_DATUM_TYPE_UINT8
:
108 if ((LocalTokenNumber
& PCD_DATUM_TYPE_UINT8_BOOLEAN
) == PCD_DATUM_TYPE_UINT8_BOOLEAN
) {
109 return EFI_PCD_TYPE_BOOL
;
111 return EFI_PCD_TYPE_8
;
113 case PCD_DATUM_TYPE_UINT16
:
114 return EFI_PCD_TYPE_16
;
115 case PCD_DATUM_TYPE_UINT32
:
116 return EFI_PCD_TYPE_32
;
117 case PCD_DATUM_TYPE_UINT64
:
118 return EFI_PCD_TYPE_64
;
121 return EFI_PCD_TYPE_8
;
128 @param[in] OnlyTokenSpaceName If TRUE, only need to get the TokenSpaceCName.
129 If FALSE, need to get the full PCD name.
130 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
131 If FALSE, the pcd entry is initialized in DXE phase.
132 @param[in] TokenNumber The PCD token number.
134 @return The TokenSpaceCName or full PCD name.
138 IN BOOLEAN OnlyTokenSpaceName
,
143 PCD_DATABASE_INIT
*Database
;
146 PCD_NAME_INDEX
*PcdNameIndex
;
147 CHAR8
*TokenSpaceName
;
152 // Return NULL when PCD name table is absent.
155 if (mPcdDatabase
.PeiDb
->PcdNameTableOffset
== 0) {
159 if (mPcdDatabase
.DxeDb
->PcdNameTableOffset
== 0) {
165 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
166 // We have to decrement TokenNumber by 1 to make it usable
167 // as the array index.
171 Database
= IsPeiDb
? mPcdDatabase
.PeiDb
: mPcdDatabase
.DxeDb
;
172 TokenNumber
= IsPeiDb
? TokenNumber
: TokenNumber
- mPeiLocalTokenCount
;
174 StringTable
= (UINT8
*) Database
+ Database
->StringTableOffset
;
177 // Get the PCD name index.
179 PcdNameIndex
= (PCD_NAME_INDEX
*)((UINT8
*) Database
+ Database
->PcdNameTableOffset
) + TokenNumber
;
180 TokenSpaceName
= (CHAR8
*)&StringTable
[PcdNameIndex
->TokenSpaceCNameIndex
];
181 PcdName
= (CHAR8
*)&StringTable
[PcdNameIndex
->PcdCNameIndex
];
183 if (OnlyTokenSpaceName
) {
185 // Only need to get the TokenSpaceCName.
187 Name
= AllocateCopyPool (AsciiStrSize (TokenSpaceName
), TokenSpaceName
);
190 // Need to get the full PCD name.
192 NameSize
= AsciiStrSize (TokenSpaceName
) + AsciiStrSize (PcdName
);
193 Name
= AllocateZeroPool (NameSize
);
194 ASSERT (Name
!= NULL
);
196 // Catenate TokenSpaceCName and PcdCName with a '.' to form the full PCD name.
198 AsciiStrCatS (Name
, NameSize
, TokenSpaceName
);
199 Name
[AsciiStrSize (TokenSpaceName
) - sizeof (CHAR8
)] = '.';
200 AsciiStrCatS (Name
, NameSize
, PcdName
);
207 Retrieve additional information associated with a PCD token.
209 This includes information such as the type of value the TokenNumber is associated with as well as possible
210 human readable name that is associated with the token.
212 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
213 If FALSE, the pcd entry is initialized in DXE phase.
214 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
215 @param[in] TokenNumber The PCD token number.
216 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
217 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
219 @retval EFI_SUCCESS The PCD information was returned successfully
220 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
225 IN CONST EFI_GUID
*Guid
,
226 IN UINTN TokenNumber
,
227 OUT EFI_PCD_INFO
*PcdInfo
230 PCD_DATABASE_INIT
*Database
;
234 DYNAMICEX_MAPPING
*ExMapTable
;
236 UINT32 LocalTokenNumber
;
238 Database
= IsPeiDb
? mPcdDatabase
.PeiDb
: mPcdDatabase
.DxeDb
;
240 GuidTable
= (EFI_GUID
*)((UINT8
*)Database
+ Database
->GuidTableOffset
);
241 MatchGuid
= ScanGuid (GuidTable
, Database
->GuidTableCount
* sizeof(EFI_GUID
), Guid
);
243 if (MatchGuid
== NULL
) {
244 return EFI_NOT_FOUND
;
247 GuidTableIdx
= MatchGuid
- GuidTable
;
249 ExMapTable
= (DYNAMICEX_MAPPING
*)((UINT8
*)Database
+ Database
->ExMapTableOffset
);
252 // Find the PCD by GuidTableIdx and ExTokenNumber in ExMapTable.
254 for (Index
= 0; Index
< Database
->ExTokenCount
; Index
++) {
255 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
256 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
258 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
259 // PcdSize to 0 and PcdName to the null-terminated ASCII string
260 // associated with the token's namespace Guid.
262 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
263 PcdInfo
->PcdSize
= 0;
265 // Here use one representative in the token space to get the TokenSpaceCName.
267 PcdInfo
->PcdName
= GetPcdName (TRUE
, IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
269 } else if (ExMapTable
[Index
].ExTokenNumber
== TokenNumber
) {
270 PcdInfo
->PcdSize
= DxePcdGetSize (ExMapTable
[Index
].TokenNumber
);
271 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
272 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
273 PcdInfo
->PcdName
= GetPcdName (FALSE
, IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
279 return EFI_NOT_FOUND
;
283 Retrieve additional information associated with a PCD token.
285 This includes information such as the type of value the TokenNumber is associated with as well as possible
286 human readable name that is associated with the token.
288 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
289 @param[in] TokenNumber The PCD token number.
290 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
291 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
293 @retval EFI_SUCCESS The PCD information was returned successfully.
294 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
298 IN CONST EFI_GUID
*Guid
,
299 IN UINTN TokenNumber
,
300 OUT EFI_PCD_INFO
*PcdInfo
304 BOOLEAN PeiExMapTableEmpty
;
305 BOOLEAN DxeExMapTableEmpty
;
306 UINT32 LocalTokenNumber
;
309 ASSERT (PcdInfo
!= NULL
);
311 Status
= EFI_NOT_FOUND
;
312 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
313 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
316 if (((TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) && (TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) ||
317 ((TokenNumber
+ 1 > (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1)))) {
318 return EFI_NOT_FOUND
;
319 } else if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
321 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
322 // PcdSize to 0 and PcdName to NULL for default Token Space.
324 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
325 PcdInfo
->PcdSize
= 0;
326 PcdInfo
->PcdName
= NULL
;
328 PcdInfo
->PcdSize
= DxePcdGetSize (TokenNumber
);
330 if ((TokenNumber
+ 1 <= mPeiNexTokenCount
+ 1)) {
333 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
);
334 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
335 PcdInfo
->PcdName
= GetPcdName (FALSE
, IsPeiDb
, TokenNumber
);
340 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
341 return EFI_NOT_FOUND
;
344 if (!PeiExMapTableEmpty
) {
345 Status
= ExGetPcdInfo (
353 if (Status
== EFI_SUCCESS
) {
357 if (!DxeExMapTableEmpty
) {
358 Status
= ExGetPcdInfo (
370 Get the PCD entry pointer in PCD database.
372 This routine will visit PCD database to find the PCD entry according to given
373 token number. The given token number is autogened by build tools and it will be
374 translated to local token number. Local token number contains PCD's type and
375 offset of PCD entry in PCD database.
377 @param TokenNumber Token's number, it is autogened by build tools
378 @param GetSize The size of token's value
380 @return PCD entry pointer in PCD database
385 IN UINTN TokenNumber
,
393 VARIABLE_HEAD
*VariableHead
;
394 UINT8
*VaraiableDefaultBuffer
;
399 UINTN TmpTokenNumber
;
402 UINT32 LocalTokenNumber
;
404 STRING_HEAD StringTableIdx
;
408 // Aquire lock to prevent reentrance from TPL_CALLBACK level
410 EfiAcquireLock (&mPcdDatabaseLock
);
414 ASSERT (TokenNumber
> 0);
416 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
417 // We have to decrement TokenNumber by 1 to make it usable
418 // as the array index.
422 TmpTokenNumber
= TokenNumber
;
425 // EBC compiler is very choosy. It may report warning about comparison
426 // between UINTN and 0 . So we add 1 in each size of the
429 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
431 ASSERT ((GetSize
== DxePcdGetSize (TokenNumber
+ 1)) || (GetSize
== 0));
433 // EBC compiler is very choosy. It may report warning about comparison
434 // between UINTN and 0 . So we add 1 in each size of the
436 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1) ? TRUE
: FALSE
);
438 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
+ 1);
440 PcdDb
= IsPeiDb
? ((UINT8
*) mPcdDatabase
.PeiDb
) : ((UINT8
*) mPcdDatabase
.DxeDb
);
443 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->StringTableOffset
);
445 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->StringTableOffset
);
449 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
451 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
453 VpdHead
= (VPD_HEAD
*) ((UINT8
*) PcdDb
+ Offset
);
454 RetPtr
= (VOID
*) (UINTN
) (PcdGet32 (PcdVpdBaseAddress
) + VpdHead
->Offset
);
458 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
461 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
463 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
466 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
467 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
468 Name
= (UINT16
*)(StringTable
+ VariableHead
->StringIndex
);
470 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
472 // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is the index of
473 // string array in string table.
475 StringTableIdx
= *(STRING_HEAD
*)((UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
);
476 VaraiableDefaultBuffer
= (UINT8
*) (StringTable
+ StringTableIdx
);
478 VaraiableDefaultBuffer
= (UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
;
480 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
481 if (Status
== EFI_SUCCESS
) {
482 if (DataSize
>= (VariableHead
->Offset
+ GetSize
)) {
485 // It is a pointer type. So get the MaxSize reserved for
488 GetPtrTypeSize (TmpTokenNumber
, &GetSize
);
489 if (GetSize
> (DataSize
- VariableHead
->Offset
)) {
491 // Use actual valid size.
493 GetSize
= DataSize
- VariableHead
->Offset
;
497 // If the operation is successful, we copy the data
498 // to the default value buffer in the PCD Database.
499 // So that we can free the Data allocated in GetHiiVariable.
501 CopyMem (VaraiableDefaultBuffer
, Data
+ VariableHead
->Offset
, GetSize
);
505 RetPtr
= (VOID
*) VaraiableDefaultBuffer
;
508 case PCD_TYPE_STRING
:
509 StringTableIdx
= *(STRING_HEAD
*)((UINT8
*) PcdDb
+ Offset
);
510 RetPtr
= (VOID
*) (StringTable
+ StringTableIdx
);
514 RetPtr
= (VOID
*) ((UINT8
*) PcdDb
+ Offset
);
523 EfiReleaseLock (&mPcdDatabaseLock
);
530 Register the callback function for a PCD entry.
532 This routine will register a callback function to a PCD entry by given token number
533 and token space guid.
535 @param TokenNumber PCD token's number, it is autogened by build tools.
536 @param Guid PCD token space's guid,
537 if not NULL, this PCD is dynamicEx type PCD.
538 @param CallBackFunction Callback function pointer
540 @return EFI_SUCCESS Always success for registering callback function.
544 DxeRegisterCallBackWorker (
545 IN UINTN TokenNumber
,
546 IN CONST EFI_GUID
*Guid
, OPTIONAL
547 IN PCD_PROTOCOL_CALLBACK CallBackFunction
550 CALLBACK_FN_ENTRY
*FnTableEntry
;
551 LIST_ENTRY
*ListHead
;
552 LIST_ENTRY
*ListNode
;
555 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
559 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
560 // We have to decrement TokenNumber by 1 to make it usable
561 // as the array index of mCallbackFnTable[].
563 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
564 ListNode
= GetFirstNode (ListHead
);
566 while (ListNode
!= ListHead
) {
567 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
569 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
571 // We only allow a Callback function to be register once
572 // for a TokenNumber. So just return EFI_SUCCESS
576 ListNode
= GetNextNode (ListHead
, ListNode
);
579 FnTableEntry
= AllocatePool (sizeof(CALLBACK_FN_ENTRY
));
580 ASSERT (FnTableEntry
!= NULL
);
582 FnTableEntry
->CallbackFn
= CallBackFunction
;
583 InsertTailList (ListHead
, &FnTableEntry
->Node
);
589 UnRegister the callback function for a PCD entry.
591 This routine will unregister a callback function to a PCD entry by given token number
592 and token space guid.
594 @param TokenNumber PCD token's number, it is autogened by build tools.
595 @param Guid PCD token space's guid.
596 if not NULL, this PCD is dynamicEx type PCD.
597 @param CallBackFunction Callback function pointer
599 @retval EFI_SUCCESS Callback function is success to be unregister.
600 @retval EFI_INVALID_PARAMETER Can not find the PCD entry by given token number.
603 DxeUnRegisterCallBackWorker (
604 IN UINTN TokenNumber
,
605 IN CONST EFI_GUID
*Guid
, OPTIONAL
606 IN PCD_PROTOCOL_CALLBACK CallBackFunction
609 CALLBACK_FN_ENTRY
*FnTableEntry
;
610 LIST_ENTRY
*ListHead
;
611 LIST_ENTRY
*ListNode
;
614 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
618 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
619 // We have to decrement TokenNumber by 1 to make it usable
620 // as the array index of mCallbackFnTable[].
622 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
623 ListNode
= GetFirstNode (ListHead
);
625 while (ListNode
!= ListHead
) {
626 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
628 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
630 // We only allow a Callback function to be register once
631 // for a TokenNumber. So we can safely remove the Node from
632 // the Link List and return EFI_SUCCESS.
634 RemoveEntryList (ListNode
);
635 FreePool (FnTableEntry
);
639 ListNode
= GetNextNode (ListHead
, ListNode
);
642 return EFI_INVALID_PARAMETER
;
646 Get next token number in given token space.
648 This routine is used for dynamicEx type PCD. It will firstly scan token space
649 table to get token space according to given token space guid. Then scan given
650 token number in found token space, if found, then return next token number in
653 @param Guid Token space guid. Next token number will be scaned in
655 @param TokenNumber Token number.
656 If PCD_INVALID_TOKEN_NUMBER, return first token number in
658 If not PCD_INVALID_TOKEN_NUMBER, return next token number
659 in token space table.
660 @param GuidTable Token space guid table. It will be used for scan token space
661 by given token space guid.
662 @param SizeOfGuidTable The size of guid table.
663 @param ExMapTable DynamicEx token number mapping table.
664 @param SizeOfExMapTable The size of dynamicEx token number mapping table.
666 @retval EFI_NOT_FOUND Can not given token space or token number.
667 @retval EFI_SUCCESS Success to get next token number.
671 ExGetNextTokeNumber (
672 IN CONST EFI_GUID
*Guid
,
673 IN OUT UINTN
*TokenNumber
,
674 IN EFI_GUID
*GuidTable
,
675 IN UINTN SizeOfGuidTable
,
676 IN DYNAMICEX_MAPPING
*ExMapTable
,
677 IN UINTN SizeOfExMapTable
684 UINTN ExMapTableCount
;
687 // Scan token space guid
689 MatchGuid
= ScanGuid (GuidTable
, SizeOfGuidTable
, Guid
);
690 if (MatchGuid
== NULL
) {
691 return EFI_NOT_FOUND
;
695 // Find the token space table in dynamicEx mapping table.
698 GuidTableIdx
= MatchGuid
- GuidTable
;
699 ExMapTableCount
= SizeOfExMapTable
/ sizeof(ExMapTable
[0]);
700 for (Index
= 0; Index
< ExMapTableCount
; Index
++) {
701 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
709 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
710 // token number in found token space.
712 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
713 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
717 for ( ; Index
< ExMapTableCount
; Index
++) {
718 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
723 while (Index
< ExMapTableCount
) {
725 if (Index
== ExMapTableCount
) {
727 // Exceed the length of ExMap Table
729 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
730 return EFI_NOT_FOUND
;
731 } else if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
733 // Found the next match
735 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
741 return EFI_NOT_FOUND
;
745 Find the PCD database.
747 @retval The base address of external PCD database binary.
748 @retval NULL Return NULL if not find.
755 DXE_PCD_DATABASE
*DxePcdDbBinary
;
759 DxePcdDbBinary
= NULL
;
761 // Search the External Pcd database from one section of current FFS,
762 // and read it to memory
764 Status
= GetSectionFromFfs (
767 (VOID
**) &DxePcdDbBinary
,
770 ASSERT_EFI_ERROR (Status
);
773 // Check the first bytes (Header Signature Guid) and build version.
775 if (!CompareGuid ((VOID
*)DxePcdDbBinary
, &gPcdDataBaseSignatureGuid
) ||
776 (DxePcdDbBinary
->BuildVersion
!= PCD_SERVICE_DXE_VERSION
)) {
780 return DxePcdDbBinary
;
784 Initialize the PCD database in DXE phase.
786 PCD database in DXE phase also contains PCD database in PEI phase which is copied
791 BuildPcdDxeDataBase (
795 PEI_PCD_DATABASE
*PeiDatabase
;
796 EFI_HOB_GUID_TYPE
*GuidHob
;
802 // Assign PCD Entries with default value to PCD DATABASE
804 mPcdDatabase
.DxeDb
= LocateExPcdBinary ();
805 ASSERT(mPcdDatabase
.DxeDb
!= NULL
);
806 PcdDxeDbLen
= mPcdDatabase
.DxeDb
->Length
+ mPcdDatabase
.DxeDb
->UninitDataBaseSize
;
807 PcdDxeDb
= AllocateZeroPool (PcdDxeDbLen
);
808 ASSERT (PcdDxeDb
!= NULL
);
809 CopyMem (PcdDxeDb
, mPcdDatabase
.DxeDb
, mPcdDatabase
.DxeDb
->Length
);
810 FreePool (mPcdDatabase
.DxeDb
);
811 mPcdDatabase
.DxeDb
= PcdDxeDb
;
813 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
814 if (GuidHob
!= NULL
) {
817 // If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
818 // should not be included at all. So the GuidHob could
819 // be NULL. If it is NULL, we just copy over the DXE Default
820 // Value to PCD Database.
823 PeiDatabase
= (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
825 // Assign PCD Entries refereneced in PEI phase to PCD DATABASE
827 mPcdDatabase
.PeiDb
= PeiDatabase
;
829 // Inherit the SystemSkuId from PEI phase.
831 mPcdDatabase
.DxeDb
->SystemSkuId
= mPcdDatabase
.PeiDb
->SystemSkuId
;
833 mPcdDatabase
.PeiDb
= AllocateZeroPool (sizeof (PEI_PCD_DATABASE
));
834 ASSERT(mPcdDatabase
.PeiDb
!= NULL
);
838 // Initialized the external PCD database local variables
840 mPeiLocalTokenCount
= mPcdDatabase
.PeiDb
->LocalTokenCount
;
841 mDxeLocalTokenCount
= mPcdDatabase
.DxeDb
->LocalTokenCount
;
843 mPeiExMapppingTableSize
= mPcdDatabase
.PeiDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
844 mDxeExMapppingTableSize
= mPcdDatabase
.DxeDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
845 mPeiGuidTableSize
= mPcdDatabase
.PeiDb
->GuidTableCount
* sizeof(GUID
);
846 mDxeGuidTableSize
= mPcdDatabase
.DxeDb
->GuidTableCount
* sizeof (GUID
);
848 mPcdTotalTokenCount
= mPeiLocalTokenCount
+ mDxeLocalTokenCount
;
849 mPeiNexTokenCount
= mPeiLocalTokenCount
- mPcdDatabase
.PeiDb
->ExTokenCount
;
850 mDxeNexTokenCount
= mDxeLocalTokenCount
- mPcdDatabase
.DxeDb
->ExTokenCount
;
852 mPeiExMapTableEmpty
= (mPcdDatabase
.PeiDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
853 mDxeExMapTableEmpty
= (mPcdDatabase
.DxeDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
854 mPeiDatabaseEmpty
= (mPeiLocalTokenCount
== 0) ? TRUE
: FALSE
;
856 TmpTokenSpaceBufferCount
= mPcdDatabase
.PeiDb
->ExTokenCount
+ mPcdDatabase
.DxeDb
->ExTokenCount
;
857 TmpTokenSpaceBuffer
= (EFI_GUID
**)AllocateZeroPool(TmpTokenSpaceBufferCount
* sizeof (EFI_GUID
*));
860 // Initialized the Callback Function Table
862 mCallbackFnTable
= AllocateZeroPool (mPcdTotalTokenCount
* sizeof (LIST_ENTRY
));
863 ASSERT(mCallbackFnTable
!= NULL
);
866 // EBC compiler is very choosy. It may report warning about comparison
867 // between UINTN and 0 . So we add 1 in each size of the
870 for (Index
= 0; Index
+ 1 < mPcdTotalTokenCount
+ 1; Index
++) {
871 InitializeListHead (&mCallbackFnTable
[Index
]);
876 Get Variable which contains HII type PCD entry.
878 @param VariableGuid Variable's guid
879 @param VariableName Variable's unicode name string
880 @param VariableData Variable's data pointer,
881 @param VariableSize Variable's size.
883 @return the status of gRT->GetVariable
887 IN EFI_GUID
*VariableGuid
,
888 IN UINT16
*VariableName
,
889 OUT UINT8
**VariableData
,
890 OUT UINTN
*VariableSize
901 // Firstly get the real size of HII variable
903 Status
= gRT
->GetVariable (
904 (UINT16
*)VariableName
,
912 // Allocate buffer to hold whole variable data according to variable size.
914 if (Status
== EFI_BUFFER_TOO_SMALL
) {
915 Buffer
= (UINT8
*) AllocatePool (Size
);
917 ASSERT (Buffer
!= NULL
);
919 Status
= gRT
->GetVariable (
927 ASSERT (Status
== EFI_SUCCESS
);
928 *VariableData
= Buffer
;
929 *VariableSize
= Size
;
932 // Use Default Data only when variable is not found.
933 // For other error status, correct data can't be got, and trig ASSERT().
935 ASSERT (Status
== EFI_NOT_FOUND
);
942 Find the local token number according to system SKU ID.
944 @param LocalTokenNumber PCD token number
945 @param Size The size of PCD entry.
946 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
947 If False, the PCD entry is initialized in DXE phase.
949 @return Token number according to system SKU ID.
953 GetSkuEnabledTokenNumber (
954 UINT32 LocalTokenNumber
,
966 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
968 PcdDb
= IsPeiDb
? (UINT8
*) mPcdDatabase
.PeiDb
: (UINT8
*) mPcdDatabase
.DxeDb
;
970 SkuHead
= (SKU_HEAD
*) (PcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
971 Value
= (UINT8
*) (PcdDb
+ SkuHead
->SkuDataStartOffset
);
973 SkuIdTable
= (SKU_ID
*)(PcdDb
+ SkuHead
->SkuIdTableOffset
);
975 // Find the current system's SKU ID entry in SKU ID table.
978 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
979 if (mPcdDatabase
.DxeDb
->SystemSkuId
== SkuIdTable
[Index
+ 1]) {
986 // Find the default SKU ID entry in SKU ID table.
990 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
991 if (0 == SkuIdTable
[Index
+ 1]) {
996 ASSERT (Index
< SkuIdTable
[0]);
998 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
1000 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
1001 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_VPD
);
1004 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
1005 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
);
1007 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
1008 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
1009 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
| PCD_TYPE_STRING
);
1011 case PCD_TYPE_STRING
:
1012 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
1013 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_STRING
);
1016 Value
+= Size
* Index
;
1017 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_DATA
);
1030 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
1031 has registered callback function.
1033 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
1035 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
1037 @param TokenNumber PCD token number generated by build tools.
1038 @param Data Value want to be set for this PCD entry
1039 @param Size The size of value
1043 InvokeCallbackOnSet (
1044 UINT32 ExTokenNumber
,
1045 CONST EFI_GUID
*Guid
, OPTIONAL
1051 CALLBACK_FN_ENTRY
*FnTableEntry
;
1052 LIST_ENTRY
*ListHead
;
1053 LIST_ENTRY
*ListNode
;
1056 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1057 // We have to decrement TokenNumber by 1 to make it usable
1058 // as the array index of mCallbackFnTable[].
1060 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
1061 ListNode
= GetFirstNode (ListHead
);
1063 while (ListNode
!= ListHead
) {
1064 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE (ListNode
, CALLBACK_FN_ENTRY
, Node
);
1066 FnTableEntry
->CallbackFn(Guid
,
1067 (Guid
== NULL
) ? TokenNumber
: ExTokenNumber
,
1071 ListNode
= GetNextNode (ListHead
, ListNode
);
1079 Wrapper function for setting non-pointer type value for a PCD entry.
1081 @param TokenNumber Pcd token number autogenerated by build tools.
1082 @param Data Value want to be set for PCD entry
1083 @param Size Size of value.
1085 @return status of SetWorker.
1090 IN UINTN TokenNumber
,
1095 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
1100 Set value for an PCD entry
1102 @param TokenNumber Pcd token number autogenerated by build tools.
1103 @param Data Value want to be set for PCD entry
1104 @param Size Size of value.
1105 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
1106 If False, the type of PCD entry's value is not Pointer.
1108 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
1109 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
1110 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
1111 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
1112 range of UINT8, UINT16, UINT32, UINT64
1113 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
1117 IN UINTN TokenNumber
,
1124 UINT32 LocalTokenNumber
;
1125 EFI_GUID
*GuidTable
;
1129 UINTN VariableOffset
;
1132 VARIABLE_HEAD
*VariableHead
;
1137 UINTN TmpTokenNumber
;
1140 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1141 // We have to decrement TokenNumber by 1 to make it usable
1142 // as the array index.
1146 TmpTokenNumber
= TokenNumber
;
1149 // EBC compiler is very choosy. It may report warning about comparison
1150 // between UINTN and 0 . So we add 1 in each size of the
1153 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
1157 // Get MaxSize first, then check new size with max buffer size.
1159 GetPtrTypeSize (TokenNumber
, &MaxSize
);
1160 if (*Size
> MaxSize
) {
1162 return EFI_INVALID_PARAMETER
;
1165 if (*Size
!= DxePcdGetSize (TokenNumber
+ 1)) {
1166 return EFI_INVALID_PARAMETER
;
1171 // EBC compiler is very choosy. It may report warning about comparison
1172 // between UINTN and 0 . So we add 1 in each size of the
1175 if ((TokenNumber
+ 1 < mPeiNexTokenCount
+ 1) ||
1176 (TokenNumber
+ 1 >= mPeiLocalTokenCount
+ 1 && TokenNumber
+ 1 < (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1))) {
1177 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
1181 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1183 EfiAcquireLock (&mPcdDatabaseLock
);
1186 // EBC compiler is very choosy. It may report warning about comparison
1187 // between UINTN and 0 . So we add 1 in each size of the
1190 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1) ? TRUE
: FALSE
);
1192 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
+ 1);
1194 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
1196 PcdDb
= IsPeiDb
? ((UINT8
*) mPcdDatabase
.PeiDb
) : ((UINT8
*) mPcdDatabase
.DxeDb
);
1199 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->StringTableOffset
);
1201 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->StringTableOffset
);
1205 InternalData
= PcdDb
+ Offset
;
1207 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
1210 Status
= EFI_INVALID_PARAMETER
;
1213 case PCD_TYPE_STRING
:
1214 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1215 CopyMem (StringTable
+ *((STRING_HEAD
*)InternalData
), Data
, *Size
);
1216 Status
= EFI_SUCCESS
;
1218 Status
= EFI_INVALID_PARAMETER
;
1222 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
1225 if (!SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1226 Status
= EFI_INVALID_PARAMETER
;
1232 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1234 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1237 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
1239 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
1240 Name
= (UINT16
*) (StringTable
+ VariableHead
->StringIndex
);
1241 VariableOffset
= VariableHead
->Offset
;
1242 Attributes
= VariableHead
->Attributes
;
1243 Status
= SetHiiVariable (Guid
, Name
, Attributes
, Data
, *Size
, VariableOffset
);
1248 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1249 CopyMem (InternalData
, Data
, *Size
);
1250 Status
= EFI_SUCCESS
;
1252 Status
= EFI_INVALID_PARAMETER
;
1257 Status
= EFI_SUCCESS
;
1260 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
1263 case sizeof(UINT16
):
1264 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
1267 case sizeof(UINT32
):
1268 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
1271 case sizeof(UINT64
):
1272 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
1277 Status
= EFI_NOT_FOUND
;
1284 Status
= EFI_NOT_FOUND
;
1288 EfiReleaseLock (&mPcdDatabaseLock
);
1294 Wrapper function for get PCD value for dynamic-ex PCD.
1296 @param Guid Token space guid for dynamic-ex PCD.
1297 @param ExTokenNumber Token number for dynamic-ex PCD.
1298 @param GetSize The size of dynamic-ex PCD value.
1300 @return PCD entry in PCD database.
1305 IN CONST EFI_GUID
*Guid
,
1306 IN UINTN ExTokenNumber
,
1310 return GetWorker(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
), GetSize
);
1314 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
1316 @param ExTokenNumber Token number for dynamic-ex PCD.
1317 @param Guid Token space guid for dynamic-ex PCD.
1318 @param Data Value want to be set.
1319 @param SetSize The size of value.
1321 @return status of ExSetWorker().
1326 IN UINTN ExTokenNumber
,
1327 IN CONST EFI_GUID
*Guid
,
1332 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &SetSize
, FALSE
);
1336 Set value for a dynamic-ex PCD entry.
1338 This routine find the local token number according to dynamic-ex PCD's token
1339 space guid and token number firstly, and invoke callback function if this PCD
1340 entry registered callback function. Finally, invoken general SetWorker to set
1343 @param ExTokenNumber Dynamic-ex PCD token number.
1344 @param Guid Token space guid for dynamic-ex PCD.
1345 @param Data PCD value want to be set
1346 @param SetSize Size of value.
1347 @param PtrType If TRUE, this PCD entry is pointer type.
1348 If FALSE, this PCD entry is not pointer type.
1350 @return status of SetWorker().
1355 IN UINTN ExTokenNumber
,
1356 IN CONST EFI_GUID
*Guid
,
1358 IN OUT UINTN
*SetSize
,
1364 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
);
1366 InvokeCallbackOnSet ((UINT32
) ExTokenNumber
, Guid
, TokenNumber
, Data
, *SetSize
);
1368 return SetWorker (TokenNumber
, Data
, SetSize
, PtrType
);
1373 Set value for HII-type PCD.
1375 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
1376 HII-type PCD is to visit this variable.
1378 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
1379 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
1380 @param SetAttributes Attributes bitmask to set for the variable.
1381 @param Data Value want to be set.
1382 @param DataSize Size of value
1383 @param Offset Value offset of HII-type PCD in variable.
1385 @return status of GetVariable()/SetVariable().
1390 IN EFI_GUID
*VariableGuid
,
1391 IN UINT16
*VariableName
,
1392 IN UINT32 SetAttributes
,
1393 IN CONST VOID
*Data
,
1408 // Try to get original variable size information.
1410 Status
= gRT
->GetVariable (
1411 (UINT16
*)VariableName
,
1418 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1420 // Patch new PCD's value to offset in given HII variable.
1422 if (Size
>= (DataSize
+ Offset
)) {
1425 SetSize
= DataSize
+ Offset
;
1427 Buffer
= AllocatePool (SetSize
);
1428 ASSERT (Buffer
!= NULL
);
1430 Status
= gRT
->GetVariable (
1438 ASSERT_EFI_ERROR (Status
);
1440 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1442 if (SetAttributes
== 0) {
1443 SetAttributes
= Attribute
;
1446 Status
= gRT
->SetVariable (
1456 } else if (Status
== EFI_NOT_FOUND
) {
1458 // If variable does not exist, a new variable need to be created.
1461 Size
= Offset
+ DataSize
;
1463 Buffer
= AllocateZeroPool (Size
);
1464 ASSERT (Buffer
!= NULL
);
1466 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1468 if (SetAttributes
== 0) {
1469 SetAttributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
;
1472 Status
= gRT
->SetVariable (
1485 // If we drop to here, the value is failed to be written in to variable area.
1491 Get Token Number according to dynamic-ex PCD's {token space guid:token number}
1493 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1494 in DEC file. PCD database maintain a mapping table that translate pair of {token
1495 space guid: token number} to Token Number.
1497 @param Guid Token space guid for dynamic-ex PCD entry.
1498 @param ExTokenNumber Dynamic-ex PCD token number.
1500 @return Token Number for dynamic-ex PCD.
1504 GetExPcdTokenNumber (
1505 IN CONST EFI_GUID
*Guid
,
1506 IN UINT32 ExTokenNumber
1510 DYNAMICEX_MAPPING
*ExMap
;
1511 EFI_GUID
*GuidTable
;
1512 EFI_GUID
*MatchGuid
;
1515 if (!mPeiDatabaseEmpty
) {
1516 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
);
1517 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1519 MatchGuid
= ScanGuid (GuidTable
, mPeiGuidTableSize
, Guid
);
1521 if (MatchGuid
!= NULL
) {
1523 MatchGuidIdx
= MatchGuid
- GuidTable
;
1525 for (Index
= 0; Index
< mPcdDatabase
.PeiDb
->ExTokenCount
; Index
++) {
1526 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1527 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1528 return ExMap
[Index
].TokenNumber
;
1534 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
);
1535 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1537 MatchGuid
= ScanGuid (GuidTable
, mDxeGuidTableSize
, Guid
);
1539 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1540 // error in the BUILD system.
1542 ASSERT (MatchGuid
!= NULL
);
1544 MatchGuidIdx
= MatchGuid
- GuidTable
;
1546 for (Index
= 0; Index
< mPcdDatabase
.DxeDb
->ExTokenCount
; Index
++) {
1547 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1548 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1549 return ExMap
[Index
].TokenNumber
;
1559 Get SKU ID table from PCD database.
1561 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1562 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1563 If FALSE, the pcd entry is initialized in DXE phase.
1564 @return Pointer to SKU ID array table
1569 IN UINTN LocalTokenNumberTableIdx
,
1574 UINTN LocalTokenNumber
;
1578 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1579 Database
= (UINT8
*) mPcdDatabase
.PeiDb
;
1581 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1582 Database
= (UINT8
*) mPcdDatabase
.DxeDb
;
1585 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1587 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1589 return (SKU_ID
*) (Database
+ SkuHead
->SkuIdTableOffset
);
1594 Wrapper function of getting index of PCD entry in size table.
1596 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1597 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1598 If FALSE, the pcd entry is initialized in DXE phase.
1600 @return index of PCD entry in size table.
1604 IN UINTN LocalTokenNumberTableIdx
,
1608 UINT32
*LocalTokenNumberTable
;
1609 UINTN LocalTokenNumber
;
1615 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1617 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1622 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
1623 LocalTokenNumber
= LocalTokenNumberTable
[Index
];
1625 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1627 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1630 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1632 // We have only two entry for VPD enabled PCD entry:
1635 // Current size is equal to MAX size.
1639 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1641 // We have only two entry for Non-Sku enabled PCD entry:
1648 // We have these entry for SKU enabled PCD entry
1650 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1652 SkuIdTable
= GetSkuIdArray (Index
, IsPeiDb
);
1653 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1660 return SizeTableIdx
;
1664 Get size of POINTER type PCD value.
1666 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1667 @param MaxSize Maxmium size of POINTER type PCD value.
1669 @return size of POINTER type PCD value.
1674 IN UINTN LocalTokenNumberTableIdx
,
1679 UINTN LocalTokenNumber
;
1681 SIZE_INFO
*SizeTable
;
1684 UINT32
*LocalTokenNumberTable
;
1686 // EBC compiler is very choosy. It may report warning about comparison
1687 // between UINTN and 0 . So we add 1 in each size of the
1689 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1693 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1694 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1696 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1697 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1698 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1701 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1703 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1705 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1707 *MaxSize
= SizeTable
[SizeTableIdx
];
1709 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1712 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1714 // We have only two entry for VPD enabled PCD entry:
1717 // We consider current size is equal to MAX size.
1721 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1723 // We have only two entry for Non-Sku enabled PCD entry:
1727 return SizeTable
[SizeTableIdx
+ 1];
1730 // We have these entry for SKU enabled PCD entry
1732 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1734 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1735 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1736 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.DxeDb
->SystemSkuId
) {
1737 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1740 return SizeTable
[SizeTableIdx
+ 1];
1746 Set size of POINTER type PCD value. The size should not exceed the maximum size
1749 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1750 @param CurrentSize Size of POINTER type PCD value.
1752 @retval TRUE Success to set size of PCD value.
1753 @retval FALSE Fail to set size of PCD value.
1757 IN UINTN LocalTokenNumberTableIdx
,
1758 IN OUT UINTN
*CurrentSize
1762 UINTN LocalTokenNumber
;
1764 SIZE_INFO
*SizeTable
;
1768 UINT32
*LocalTokenNumberTable
;
1771 // EBC compiler is very choosy. It may report warning about comparison
1772 // between UINTN and 0 . So we add 1 in each size of the
1775 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1778 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1779 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1781 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1782 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1783 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1786 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1788 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1790 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1792 MaxSize
= SizeTable
[SizeTableIdx
];
1794 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1797 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1799 // We shouldn't come here as we don't support SET for VPD
1804 if ((*CurrentSize
> MaxSize
) ||
1805 (*CurrentSize
== MAX_ADDRESS
)) {
1806 *CurrentSize
= MaxSize
;
1810 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1812 // We have only two entry for Non-Sku enabled PCD entry:
1816 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1820 // We have these entry for SKU enabled PCD entry
1822 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1824 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1825 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1826 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.DxeDb
->SystemSkuId
) {
1827 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1831 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1838 VariableLock DynamicHiiPcd.
1840 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1841 If FALSE, the pcd entry is initialized in DXE phase.
1842 @param[in] VariableLock Pointer to VariableLockProtocol.
1846 VariableLockDynamicHiiPcd (
1848 IN EDKII_VARIABLE_LOCK_PROTOCOL
*VariableLock
1852 PCD_DATABASE_INIT
*Database
;
1853 UINT32 LocalTokenCount
;
1855 UINT32 LocalTokenNumber
;
1857 EFI_GUID
*GuidTable
;
1859 VARIABLE_HEAD
*VariableHead
;
1863 Database
= IsPeiDb
? mPcdDatabase
.PeiDb
: mPcdDatabase
.DxeDb
;
1864 LocalTokenCount
= IsPeiDb
? mPeiLocalTokenCount
: mDxeLocalTokenCount
;
1867 // Go through PCD database to find out DynamicHii PCDs.
1869 for (TokenNumber
= 1; TokenNumber
<= LocalTokenCount
; TokenNumber
++) {
1871 LocalTokenNumber
= GetLocalTokenNumber (TRUE
, TokenNumber
);
1873 LocalTokenNumber
= GetLocalTokenNumber (FALSE
, TokenNumber
+ mPeiLocalTokenCount
);
1875 if ((LocalTokenNumber
& PCD_TYPE_HII
) != 0) {
1876 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
1877 VariableHead
= (VARIABLE_HEAD
*) ((UINT8
*) Database
+ Offset
);
1879 // Why not to set property by VarCheckProtocol with Attributes and Property directly here?
1880 // It is because that set property by VarCheckProtocol will indicate the variable to
1881 // be a system variable, but the unknown max size of the variable is dangerous to
1882 // the system variable region.
1884 if ((VariableHead
->Property
& VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY
) != 0) {
1886 // DynamicHii PCD with RO property set in *.dsc.
1888 StringTable
= (UINT8
*) ((UINT8
*) Database
+ Database
->StringTableOffset
);
1889 GuidTable
= (EFI_GUID
*) ((UINT8
*) Database
+ Database
->GuidTableOffset
);
1890 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
1891 Name
= (UINT16
*) (StringTable
+ VariableHead
->StringIndex
);
1892 Status
= VariableLock
->RequestToLock (VariableLock
, Name
, Guid
);
1893 ASSERT_EFI_ERROR (Status
);
1900 VariableLockProtocol callback
1901 to lock the variables referenced by DynamicHii PCDs with RO property set in *.dsc.
1903 @param[in] Event Event whose notification function is being invoked.
1904 @param[in] Context Pointer to the notification function's context.
1909 VariableLockCallBack (
1915 EDKII_VARIABLE_LOCK_PROTOCOL
*VariableLock
;
1917 Status
= gBS
->LocateProtocol (&gEdkiiVariableLockProtocolGuid
, NULL
, (VOID
**) &VariableLock
);
1918 if (!EFI_ERROR (Status
)) {
1919 VariableLockDynamicHiiPcd (TRUE
, VariableLock
);
1920 VariableLockDynamicHiiPcd (FALSE
, VariableLock
);