2 Help functions used by PCD DXE driver.
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/DxeServicesLib.h>
18 PCD_DATABASE mPcdDatabase
;
20 UINT32 mPcdTotalTokenCount
;
21 UINT32 mPeiLocalTokenCount
;
22 UINT32 mDxeLocalTokenCount
;
23 UINT32 mPeiNexTokenCount
;
24 UINT32 mDxeNexTokenCount
;
25 UINT32 mPeiExMapppingTableSize
;
26 UINT32 mDxeExMapppingTableSize
;
27 UINT32 mPeiGuidTableSize
;
28 UINT32 mDxeGuidTableSize
;
30 BOOLEAN mPeiExMapTableEmpty
;
31 BOOLEAN mDxeExMapTableEmpty
;
32 BOOLEAN mPeiDatabaseEmpty
;
34 LIST_ENTRY
*mCallbackFnTable
;
35 EFI_GUID
**TmpTokenSpaceBuffer
;
36 UINTN TmpTokenSpaceBufferCount
;
39 Get Local Token Number by Token Number.
41 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
42 If FALSE, the pcd entry is initialized in DXE phase.
43 @param[in] TokenNumber The PCD token number.
45 @return Local Token Number.
53 UINT32
*LocalTokenNumberTable
;
54 UINT32 LocalTokenNumber
;
59 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
60 // We have to decrement TokenNumber by 1 to make it usable
61 // as the array index.
65 LocalTokenNumberTable
= IsPeiDb
? (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
) :
66 (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
67 TokenNumber
= IsPeiDb
? TokenNumber
: TokenNumber
- mPeiLocalTokenCount
;
69 LocalTokenNumber
= LocalTokenNumberTable
[TokenNumber
];
71 Size
= (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) >> PCD_DATUM_TYPE_SHIFT
;
73 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
75 GetPtrTypeSize (TokenNumber
, &MaxSize
);
79 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
, IsPeiDb
);
82 return LocalTokenNumber
;
86 Get PCD type by Local Token Number.
88 @param[in] LocalTokenNumber The PCD local token number.
94 IN UINT32 LocalTokenNumber
97 switch (LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) {
98 case PCD_DATUM_TYPE_POINTER
:
99 return EFI_PCD_TYPE_PTR
;
100 case PCD_DATUM_TYPE_UINT8
:
101 if ((LocalTokenNumber
& PCD_DATUM_TYPE_UINT8_BOOLEAN
) == PCD_DATUM_TYPE_UINT8_BOOLEAN
) {
102 return EFI_PCD_TYPE_BOOL
;
104 return EFI_PCD_TYPE_8
;
106 case PCD_DATUM_TYPE_UINT16
:
107 return EFI_PCD_TYPE_16
;
108 case PCD_DATUM_TYPE_UINT32
:
109 return EFI_PCD_TYPE_32
;
110 case PCD_DATUM_TYPE_UINT64
:
111 return EFI_PCD_TYPE_64
;
114 return EFI_PCD_TYPE_8
;
121 @param[in] OnlyTokenSpaceName If TRUE, only need to get the TokenSpaceCName.
122 If FALSE, need to get the full PCD name.
123 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
124 If FALSE, the pcd entry is initialized in DXE phase.
125 @param[in] TokenNumber The PCD token number.
127 @return The TokenSpaceCName or full PCD name.
131 IN BOOLEAN OnlyTokenSpaceName
,
136 PCD_DATABASE_INIT
*Database
;
138 PCD_NAME_INDEX
*PcdNameIndex
;
139 CHAR8
*TokenSpaceName
;
144 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
145 // We have to decrement TokenNumber by 1 to make it usable
146 // as the array index.
150 Database
= IsPeiDb
? mPcdDatabase
.PeiDb
: mPcdDatabase
.DxeDb
;
151 TokenNumber
= IsPeiDb
? TokenNumber
: TokenNumber
- mPeiLocalTokenCount
;
153 StringTable
= (UINT8
*) Database
+ Database
->StringTableOffset
;
156 // Get the PCD name index.
158 PcdNameIndex
= (PCD_NAME_INDEX
*)((UINT8
*) Database
+ Database
->PcdNameTableOffset
) + TokenNumber
;
159 TokenSpaceName
= (CHAR8
*)&StringTable
[PcdNameIndex
->TokenSpaceCNameIndex
];
160 PcdName
= (CHAR8
*)&StringTable
[PcdNameIndex
->PcdCNameIndex
];
162 if (OnlyTokenSpaceName
) {
164 // Only need to get the TokenSpaceCName.
166 Name
= AllocateCopyPool (AsciiStrSize (TokenSpaceName
), TokenSpaceName
);
169 // Need to get the full PCD name.
171 Name
= AllocateZeroPool (AsciiStrSize (TokenSpaceName
) + AsciiStrSize (PcdName
));
172 ASSERT (Name
!= NULL
);
174 // Catenate TokenSpaceCName and PcdCName with a '.' to form the full PCD name.
176 AsciiStrCat (Name
, TokenSpaceName
);
177 Name
[AsciiStrSize (TokenSpaceName
) - sizeof (CHAR8
)] = '.';
178 AsciiStrCat (Name
, PcdName
);
185 Retrieve additional information associated with a PCD token.
187 This includes information such as the type of value the TokenNumber is associated with as well as possible
188 human readable name that is associated with the token.
190 @param[in] IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
191 If FALSE, the pcd entry is initialized in DXE phase.
192 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
193 @param[in] TokenNumber The PCD token number.
194 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
195 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
197 @retval EFI_SUCCESS The PCD information was returned successfully
198 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
203 IN CONST EFI_GUID
*Guid
,
204 IN UINTN TokenNumber
,
205 OUT EFI_PCD_INFO
*PcdInfo
208 PCD_DATABASE_INIT
*Database
;
212 DYNAMICEX_MAPPING
*ExMapTable
;
214 UINT32 LocalTokenNumber
;
216 Database
= IsPeiDb
? mPcdDatabase
.PeiDb
: mPcdDatabase
.DxeDb
;
218 GuidTable
= (EFI_GUID
*)((UINT8
*)Database
+ Database
->GuidTableOffset
);
219 MatchGuid
= ScanGuid (GuidTable
, Database
->GuidTableCount
* sizeof(EFI_GUID
), Guid
);
221 if (MatchGuid
== NULL
) {
222 return EFI_NOT_FOUND
;
225 GuidTableIdx
= MatchGuid
- GuidTable
;
227 ExMapTable
= (DYNAMICEX_MAPPING
*)((UINT8
*)Database
+ Database
->ExMapTableOffset
);
230 // Find the PCD by GuidTableIdx and ExTokenNumber in ExMapTable.
232 for (Index
= 0; Index
< Database
->ExTokenCount
; Index
++) {
233 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
234 if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
236 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
237 // PcdSize to 0 and PcdName to the null-terminated ASCII string
238 // associated with the token's namespace Guid.
240 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
241 PcdInfo
->PcdSize
= 0;
243 // Here use one representative in the token space to get the TokenSpaceCName.
245 PcdInfo
->PcdName
= GetPcdName (TRUE
, IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
247 } else if (ExMapTable
[Index
].ExTokenNumber
== TokenNumber
) {
248 PcdInfo
->PcdSize
= DxePcdGetSize (ExMapTable
[Index
].TokenNumber
);
249 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
250 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
251 PcdInfo
->PcdName
= GetPcdName (FALSE
, IsPeiDb
, ExMapTable
[Index
].TokenNumber
);
257 return EFI_NOT_FOUND
;
261 Retrieve additional information associated with a PCD token.
263 This includes information such as the type of value the TokenNumber is associated with as well as possible
264 human readable name that is associated with the token.
266 @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.
267 @param[in] TokenNumber The PCD token number.
268 @param[out] PcdInfo The returned information associated with the requested TokenNumber.
269 The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.
271 @retval EFI_SUCCESS The PCD information was returned successfully.
272 @retval EFI_NOT_FOUND The PCD service could not find the requested token number.
276 IN CONST EFI_GUID
*Guid
,
277 IN UINTN TokenNumber
,
278 OUT EFI_PCD_INFO
*PcdInfo
282 BOOLEAN PeiExMapTableEmpty
;
283 BOOLEAN DxeExMapTableEmpty
;
284 UINT32 LocalTokenNumber
;
287 ASSERT (PcdInfo
!= NULL
);
289 Status
= EFI_NOT_FOUND
;
290 PeiExMapTableEmpty
= mPeiExMapTableEmpty
;
291 DxeExMapTableEmpty
= mDxeExMapTableEmpty
;
294 if (((TokenNumber
+ 1 > mPeiNexTokenCount
+ 1) && (TokenNumber
+ 1 <= mPeiLocalTokenCount
+ 1)) ||
295 ((TokenNumber
+ 1 > (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1)))) {
296 return EFI_NOT_FOUND
;
297 } else if (TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
299 // TokenNumber is 0, follow spec to set PcdType to EFI_PCD_TYPE_8,
300 // PcdSize to 0 and PcdName to NULL for default Token Space.
302 PcdInfo
->PcdType
= EFI_PCD_TYPE_8
;
303 PcdInfo
->PcdSize
= 0;
304 PcdInfo
->PcdName
= NULL
;
306 PcdInfo
->PcdSize
= DxePcdGetSize (TokenNumber
);
308 if ((TokenNumber
+ 1 <= mPeiNexTokenCount
+ 1)) {
311 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
);
312 PcdInfo
->PcdType
= GetPcdType (LocalTokenNumber
);
313 PcdInfo
->PcdName
= GetPcdName (FALSE
, IsPeiDb
, TokenNumber
);
318 if (PeiExMapTableEmpty
&& DxeExMapTableEmpty
) {
319 return EFI_NOT_FOUND
;
322 if (!PeiExMapTableEmpty
) {
323 Status
= ExGetPcdInfo (
331 if (Status
== EFI_SUCCESS
) {
335 if (!DxeExMapTableEmpty
) {
336 Status
= ExGetPcdInfo (
348 Get the PCD entry pointer in PCD database.
350 This routine will visit PCD database to find the PCD entry according to given
351 token number. The given token number is autogened by build tools and it will be
352 translated to local token number. Local token number contains PCD's type and
353 offset of PCD entry in PCD database.
355 @param TokenNumber Token's number, it is autogened by build tools
356 @param GetSize The size of token's value
358 @return PCD entry pointer in PCD database
363 IN UINTN TokenNumber
,
371 VARIABLE_HEAD
*VariableHead
;
372 UINT8
*VaraiableDefaultBuffer
;
377 UINTN TmpTokenNumber
;
380 UINT32 LocalTokenNumber
;
382 STRING_HEAD StringTableIdx
;
386 // Aquire lock to prevent reentrance from TPL_CALLBACK level
388 EfiAcquireLock (&mPcdDatabaseLock
);
392 ASSERT (TokenNumber
> 0);
394 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
395 // We have to decrement TokenNumber by 1 to make it usable
396 // as the array index.
400 TmpTokenNumber
= TokenNumber
;
403 // EBC compiler is very choosy. It may report warning about comparison
404 // between UINTN and 0 . So we add 1 in each size of the
407 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
409 ASSERT ((GetSize
== DxePcdGetSize (TokenNumber
+ 1)) || (GetSize
== 0));
411 // EBC compiler is very choosy. It may report warning about comparison
412 // between UINTN and 0 . So we add 1 in each size of the
414 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1) ? TRUE
: FALSE
);
416 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
+ 1);
418 PcdDb
= IsPeiDb
? ((UINT8
*) mPcdDatabase
.PeiDb
) : ((UINT8
*) mPcdDatabase
.DxeDb
);
421 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->StringTableOffset
);
423 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->StringTableOffset
);
427 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
429 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
431 VpdHead
= (VPD_HEAD
*) ((UINT8
*) PcdDb
+ Offset
);
432 RetPtr
= (VOID
*) (UINTN
) (PcdGet32 (PcdVpdBaseAddress
) + VpdHead
->Offset
);
436 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
439 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
441 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
444 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
445 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
446 Name
= (UINT16
*)(StringTable
+ VariableHead
->StringIndex
);
448 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
450 // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is the index of
451 // string array in string table.
453 StringTableIdx
= *(STRING_HEAD
*)((UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
);
454 VaraiableDefaultBuffer
= (VOID
*) (StringTable
+ StringTableIdx
);
456 VaraiableDefaultBuffer
= (UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
;
458 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
459 if (Status
== EFI_SUCCESS
) {
462 // It is a pointer type. So get the MaxSize reserved for
465 GetPtrTypeSize (TmpTokenNumber
, &GetSize
);
468 // If the operation is successful, we copy the data
469 // to the default value buffer in the PCD Database.
470 // So that we can free the Data allocated in GetHiiVariable.
472 CopyMem (VaraiableDefaultBuffer
, Data
+ VariableHead
->Offset
, GetSize
);
475 RetPtr
= (VOID
*) VaraiableDefaultBuffer
;
478 case PCD_TYPE_STRING
:
479 StringTableIdx
= *(STRING_HEAD
*)((UINT8
*) PcdDb
+ Offset
);
480 RetPtr
= (VOID
*) (StringTable
+ StringTableIdx
);
484 RetPtr
= (VOID
*) ((UINT8
*) PcdDb
+ Offset
);
493 EfiReleaseLock (&mPcdDatabaseLock
);
500 Register the callback function for a PCD entry.
502 This routine will register a callback function to a PCD entry by given token number
503 and token space guid.
505 @param TokenNumber PCD token's number, it is autogened by build tools.
506 @param Guid PCD token space's guid,
507 if not NULL, this PCD is dynamicEx type PCD.
508 @param CallBackFunction Callback function pointer
510 @return EFI_SUCCESS Always success for registering callback function.
514 DxeRegisterCallBackWorker (
515 IN UINTN TokenNumber
,
516 IN CONST EFI_GUID
*Guid
, OPTIONAL
517 IN PCD_PROTOCOL_CALLBACK CallBackFunction
520 CALLBACK_FN_ENTRY
*FnTableEntry
;
521 LIST_ENTRY
*ListHead
;
522 LIST_ENTRY
*ListNode
;
525 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
529 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
530 // We have to decrement TokenNumber by 1 to make it usable
531 // as the array index of mCallbackFnTable[].
533 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
534 ListNode
= GetFirstNode (ListHead
);
536 while (ListNode
!= ListHead
) {
537 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
539 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
541 // We only allow a Callback function to be register once
542 // for a TokenNumber. So just return EFI_SUCCESS
546 ListNode
= GetNextNode (ListHead
, ListNode
);
549 FnTableEntry
= AllocatePool (sizeof(CALLBACK_FN_ENTRY
));
550 ASSERT (FnTableEntry
!= NULL
);
552 FnTableEntry
->CallbackFn
= CallBackFunction
;
553 InsertTailList (ListHead
, &FnTableEntry
->Node
);
559 UnRegister the callback function for a PCD entry.
561 This routine will unregister a callback function to a PCD entry by given token number
562 and token space guid.
564 @param TokenNumber PCD token's number, it is autogened by build tools.
565 @param Guid PCD token space's guid.
566 if not NULL, this PCD is dynamicEx type PCD.
567 @param CallBackFunction Callback function pointer
569 @retval EFI_SUCCESS Callback function is success to be unregister.
570 @retval EFI_INVALID_PARAMETER Can not find the PCD entry by given token number.
573 DxeUnRegisterCallBackWorker (
574 IN UINTN TokenNumber
,
575 IN CONST EFI_GUID
*Guid
, OPTIONAL
576 IN PCD_PROTOCOL_CALLBACK CallBackFunction
579 CALLBACK_FN_ENTRY
*FnTableEntry
;
580 LIST_ENTRY
*ListHead
;
581 LIST_ENTRY
*ListNode
;
584 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
588 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
589 // We have to decrement TokenNumber by 1 to make it usable
590 // as the array index of mCallbackFnTable[].
592 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
593 ListNode
= GetFirstNode (ListHead
);
595 while (ListNode
!= ListHead
) {
596 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
598 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
600 // We only allow a Callback function to be register once
601 // for a TokenNumber. So we can safely remove the Node from
602 // the Link List and return EFI_SUCCESS.
604 RemoveEntryList (ListNode
);
605 FreePool (FnTableEntry
);
609 ListNode
= GetNextNode (ListHead
, ListNode
);
612 return EFI_INVALID_PARAMETER
;
616 Get next token number in given token space.
618 This routine is used for dynamicEx type PCD. It will firstly scan token space
619 table to get token space according to given token space guid. Then scan given
620 token number in found token space, if found, then return next token number in
623 @param Guid Token space guid. Next token number will be scaned in
625 @param TokenNumber Token number.
626 If PCD_INVALID_TOKEN_NUMBER, return first token number in
628 If not PCD_INVALID_TOKEN_NUMBER, return next token number
629 in token space table.
630 @param GuidTable Token space guid table. It will be used for scan token space
631 by given token space guid.
632 @param SizeOfGuidTable The size of guid table.
633 @param ExMapTable DynamicEx token number mapping table.
634 @param SizeOfExMapTable The size of dynamicEx token number mapping table.
636 @retval EFI_NOT_FOUND Can not given token space or token number.
637 @retval EFI_SUCCESS Success to get next token number.
641 ExGetNextTokeNumber (
642 IN CONST EFI_GUID
*Guid
,
643 IN OUT UINTN
*TokenNumber
,
644 IN EFI_GUID
*GuidTable
,
645 IN UINTN SizeOfGuidTable
,
646 IN DYNAMICEX_MAPPING
*ExMapTable
,
647 IN UINTN SizeOfExMapTable
654 UINTN ExMapTableCount
;
657 // Scan token space guid
659 MatchGuid
= ScanGuid (GuidTable
, SizeOfGuidTable
, Guid
);
660 if (MatchGuid
== NULL
) {
661 return EFI_NOT_FOUND
;
665 // Find the token space table in dynamicEx mapping table.
668 GuidTableIdx
= MatchGuid
- GuidTable
;
669 ExMapTableCount
= SizeOfExMapTable
/ sizeof(ExMapTable
[0]);
670 for (Index
= 0; Index
< ExMapTableCount
; Index
++) {
671 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
679 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
680 // token number in found token space.
682 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
683 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
687 for ( ; Index
< ExMapTableCount
; Index
++) {
688 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
693 while (Index
< ExMapTableCount
) {
695 if (Index
== ExMapTableCount
) {
697 // Exceed the length of ExMap Table
699 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
700 return EFI_NOT_FOUND
;
701 } else if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
703 // Found the next match
705 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
711 return EFI_NOT_FOUND
;
715 Find the PCD database.
717 @retval The base address of external PCD database binary.
718 @retval NULL Return NULL if not find.
725 DXE_PCD_DATABASE
*DxePcdDbBinary
;
729 DxePcdDbBinary
= NULL
;
731 // Search the External Pcd database from one section of current FFS,
732 // and read it to memory
734 Status
= GetSectionFromFfs (
737 (VOID
**) &DxePcdDbBinary
,
740 ASSERT_EFI_ERROR (Status
);
743 // Check the first bytes (Header Signature Guid) and build version.
745 if (!CompareGuid ((VOID
*)DxePcdDbBinary
, &gPcdDataBaseSignatureGuid
) ||
746 (DxePcdDbBinary
->BuildVersion
!= PCD_SERVICE_DXE_VERSION
)) {
750 return DxePcdDbBinary
;
754 Initialize the PCD database in DXE phase.
756 PCD database in DXE phase also contains PCD database in PEI phase which is copied
761 BuildPcdDxeDataBase (
765 PEI_PCD_DATABASE
*PeiDatabase
;
766 EFI_HOB_GUID_TYPE
*GuidHob
;
771 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
772 if (GuidHob
!= NULL
) {
775 // If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
776 // should not be included at all. So the GuidHob could
777 // be NULL. If it is NULL, we just copy over the DXE Default
778 // Value to PCD Database.
781 PeiDatabase
= (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
783 // Assign PCD Entries refereneced in PEI phase to PCD DATABASE
785 mPcdDatabase
.PeiDb
= PeiDatabase
;
789 // Assign PCD Entries with default value to PCD DATABASE
791 mPcdDatabase
.DxeDb
= LocateExPcdBinary ();
792 ASSERT(mPcdDatabase
.DxeDb
!= NULL
);
793 PcdDxeDbLen
= mPcdDatabase
.DxeDb
->Length
+ mPcdDatabase
.DxeDb
->UninitDataBaseSize
;
794 PcdDxeDb
= AllocateZeroPool (PcdDxeDbLen
);
795 ASSERT (PcdDxeDb
!= NULL
);
796 CopyMem (PcdDxeDb
, mPcdDatabase
.DxeDb
, mPcdDatabase
.DxeDb
->Length
);
797 FreePool (mPcdDatabase
.DxeDb
);
798 mPcdDatabase
.DxeDb
= PcdDxeDb
;
801 // Initialized the external PCD database local variables
803 mPeiLocalTokenCount
= mPcdDatabase
.PeiDb
->LocalTokenCount
;
804 mDxeLocalTokenCount
= mPcdDatabase
.DxeDb
->LocalTokenCount
;
806 mPeiExMapppingTableSize
= mPcdDatabase
.PeiDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
807 mDxeExMapppingTableSize
= mPcdDatabase
.DxeDb
->ExTokenCount
* sizeof (DYNAMICEX_MAPPING
);
808 mPeiGuidTableSize
= mPcdDatabase
.PeiDb
->GuidTableCount
* sizeof(GUID
);
809 mDxeGuidTableSize
= mPcdDatabase
.DxeDb
->GuidTableCount
* sizeof (GUID
);
811 mPcdTotalTokenCount
= mPeiLocalTokenCount
+ mDxeLocalTokenCount
;
812 mPeiNexTokenCount
= mPeiLocalTokenCount
- mPcdDatabase
.PeiDb
->ExTokenCount
;
813 mDxeNexTokenCount
= mDxeLocalTokenCount
- mPcdDatabase
.DxeDb
->ExTokenCount
;
815 mPeiExMapTableEmpty
= (mPcdDatabase
.PeiDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
816 mDxeExMapTableEmpty
= (mPcdDatabase
.DxeDb
->ExTokenCount
== 0) ? TRUE
: FALSE
;
817 mPeiDatabaseEmpty
= (mPeiLocalTokenCount
== 0) ? TRUE
: FALSE
;
819 TmpTokenSpaceBufferCount
= mPcdDatabase
.PeiDb
->ExTokenCount
+ mPcdDatabase
.DxeDb
->ExTokenCount
;
820 TmpTokenSpaceBuffer
= (EFI_GUID
**)AllocateZeroPool(TmpTokenSpaceBufferCount
* sizeof (EFI_GUID
*));
823 // Initialized the Callback Function Table
825 mCallbackFnTable
= AllocateZeroPool (mPcdTotalTokenCount
* sizeof (LIST_ENTRY
));
826 ASSERT(mCallbackFnTable
!= NULL
);
829 // EBC compiler is very choosy. It may report warning about comparison
830 // between UINTN and 0 . So we add 1 in each size of the
833 for (Index
= 0; Index
+ 1 < mPcdTotalTokenCount
+ 1; Index
++) {
834 InitializeListHead (&mCallbackFnTable
[Index
]);
839 Get Variable which contains HII type PCD entry.
841 @param VariableGuid Variable's guid
842 @param VariableName Variable's unicode name string
843 @param VariableData Variable's data pointer,
844 @param VariableSize Variable's size.
846 @return the status of gRT->GetVariable
850 IN EFI_GUID
*VariableGuid
,
851 IN UINT16
*VariableName
,
852 OUT UINT8
**VariableData
,
853 OUT UINTN
*VariableSize
864 // Firstly get the real size of HII variable
866 Status
= gRT
->GetVariable (
867 (UINT16
*)VariableName
,
875 // Allocate buffer to hold whole variable data according to variable size.
877 if (Status
== EFI_BUFFER_TOO_SMALL
) {
878 Buffer
= (UINT8
*) AllocatePool (Size
);
880 ASSERT (Buffer
!= NULL
);
882 Status
= gRT
->GetVariable (
890 ASSERT (Status
== EFI_SUCCESS
);
891 *VariableData
= Buffer
;
892 *VariableSize
= Size
;
895 // Use Default Data only when variable is not found.
896 // For other error status, correct data can't be got, and trig ASSERT().
898 ASSERT (Status
== EFI_NOT_FOUND
);
905 Find the local token number according to system SKU ID.
907 @param LocalTokenNumber PCD token number
908 @param Size The size of PCD entry.
909 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
910 If False, the PCD entry is initialized in DXE phase.
912 @return Token number according to system SKU ID.
916 GetSkuEnabledTokenNumber (
917 UINT32 LocalTokenNumber
,
929 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
931 PcdDb
= IsPeiDb
? (UINT8
*) mPcdDatabase
.PeiDb
: (UINT8
*) mPcdDatabase
.DxeDb
;
933 SkuHead
= (SKU_HEAD
*) (PcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
934 Value
= (UINT8
*) (PcdDb
+ SkuHead
->SkuDataStartOffset
);
936 SkuIdTable
= (SKU_ID
*)(PcdDb
+ SkuHead
->SkuIdTableOffset
);
938 // Find the current system's SKU ID entry in SKU ID table.
941 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
942 if (mPcdDatabase
.PeiDb
->SystemSkuId
== SkuIdTable
[Index
+ 1]) {
949 // Find the default SKU ID entry in SKU ID table.
953 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
954 if (0 == SkuIdTable
[Index
+ 1]) {
959 ASSERT (Index
< SkuIdTable
[0]);
961 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
963 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
964 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_VPD
);
967 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
968 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
);
970 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
971 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
972 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
| PCD_TYPE_STRING
);
974 case PCD_TYPE_STRING
:
975 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
976 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_STRING
);
979 Value
+= Size
* Index
;
980 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_DATA
);
993 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
994 has registered callback function.
996 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
998 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
1000 @param TokenNumber PCD token number generated by build tools.
1001 @param Data Value want to be set for this PCD entry
1002 @param Size The size of value
1006 InvokeCallbackOnSet (
1007 UINT32 ExTokenNumber
,
1008 CONST EFI_GUID
*Guid
, OPTIONAL
1014 CALLBACK_FN_ENTRY
*FnTableEntry
;
1015 LIST_ENTRY
*ListHead
;
1016 LIST_ENTRY
*ListNode
;
1019 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1020 // We have to decrement TokenNumber by 1 to make it usable
1021 // as the array index of mCallbackFnTable[].
1023 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
1024 ListNode
= GetFirstNode (ListHead
);
1026 while (ListNode
!= ListHead
) {
1027 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE (ListNode
, CALLBACK_FN_ENTRY
, Node
);
1029 FnTableEntry
->CallbackFn(Guid
,
1030 (Guid
== NULL
) ? TokenNumber
: ExTokenNumber
,
1034 ListNode
= GetNextNode (ListHead
, ListNode
);
1042 Wrapper function for setting non-pointer type value for a PCD entry.
1044 @param TokenNumber Pcd token number autogenerated by build tools.
1045 @param Data Value want to be set for PCD entry
1046 @param Size Size of value.
1048 @return status of SetWorker.
1053 IN UINTN TokenNumber
,
1058 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
1063 Set value for an 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.
1068 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
1069 If False, the type of PCD entry's value is not Pointer.
1071 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
1072 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
1073 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
1074 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
1075 range of UINT8, UINT16, UINT32, UINT64
1076 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
1080 IN UINTN TokenNumber
,
1087 UINT32 LocalTokenNumber
;
1088 EFI_GUID
*GuidTable
;
1092 UINTN VariableOffset
;
1094 VARIABLE_HEAD
*VariableHead
;
1099 UINTN TmpTokenNumber
;
1102 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
1103 // We have to decrement TokenNumber by 1 to make it usable
1104 // as the array index.
1108 TmpTokenNumber
= TokenNumber
;
1111 // EBC compiler is very choosy. It may report warning about comparison
1112 // between UINTN and 0 . So we add 1 in each size of the
1115 ASSERT (TokenNumber
+ 1 < mPcdTotalTokenCount
+ 1);
1119 // Get MaxSize first, then check new size with max buffer size.
1121 GetPtrTypeSize (TokenNumber
, &MaxSize
);
1122 if (*Size
> MaxSize
) {
1124 return EFI_INVALID_PARAMETER
;
1127 if (*Size
!= DxePcdGetSize (TokenNumber
+ 1)) {
1128 return EFI_INVALID_PARAMETER
;
1133 // EBC compiler is very choosy. It may report warning about comparison
1134 // between UINTN and 0 . So we add 1 in each size of the
1137 if ((TokenNumber
+ 1 < mPeiNexTokenCount
+ 1) ||
1138 (TokenNumber
+ 1 >= mPeiLocalTokenCount
+ 1 && TokenNumber
+ 1 < (mPeiLocalTokenCount
+ mDxeNexTokenCount
+ 1))) {
1139 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
1143 // Aquire lock to prevent reentrance from TPL_CALLBACK level
1145 EfiAcquireLock (&mPcdDatabaseLock
);
1148 // EBC compiler is very choosy. It may report warning about comparison
1149 // between UINTN and 0 . So we add 1 in each size of the
1152 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < mPeiLocalTokenCount
+ 1) ? TRUE
: FALSE
);
1154 LocalTokenNumber
= GetLocalTokenNumber (IsPeiDb
, TokenNumber
+ 1);
1156 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
1158 PcdDb
= IsPeiDb
? ((UINT8
*) mPcdDatabase
.PeiDb
) : ((UINT8
*) mPcdDatabase
.DxeDb
);
1161 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->StringTableOffset
);
1163 StringTable
= (UINT8
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->StringTableOffset
);
1167 InternalData
= PcdDb
+ Offset
;
1169 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
1172 Status
= EFI_INVALID_PARAMETER
;
1175 case PCD_TYPE_STRING
:
1176 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1177 CopyMem (StringTable
+ *((STRING_HEAD
*)InternalData
), Data
, *Size
);
1178 Status
= EFI_SUCCESS
;
1180 Status
= EFI_INVALID_PARAMETER
;
1184 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
1187 if (!SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1188 Status
= EFI_INVALID_PARAMETER
;
1194 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1196 GuidTable
= (EFI_GUID
*) ((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1199 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
1201 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
1202 Name
= (UINT16
*) (StringTable
+ VariableHead
->StringIndex
);
1203 VariableOffset
= VariableHead
->Offset
;
1204 Status
= SetHiiVariable (Guid
, Name
, Data
, *Size
, VariableOffset
);
1206 if (EFI_NOT_FOUND
== Status
) {
1207 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
1209 StringTable
+ *(STRING_HEAD
*)(PcdDb
+ VariableHead
->DefaultValueOffset
),
1214 CopyMem (PcdDb
+ VariableHead
->DefaultValueOffset
, Data
, *Size
);
1216 Status
= EFI_SUCCESS
;
1222 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
1223 CopyMem (InternalData
, Data
, *Size
);
1224 Status
= EFI_SUCCESS
;
1226 Status
= EFI_INVALID_PARAMETER
;
1231 Status
= EFI_SUCCESS
;
1234 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
1237 case sizeof(UINT16
):
1238 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
1241 case sizeof(UINT32
):
1242 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
1245 case sizeof(UINT64
):
1246 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
1251 Status
= EFI_NOT_FOUND
;
1258 Status
= EFI_NOT_FOUND
;
1262 EfiReleaseLock (&mPcdDatabaseLock
);
1268 Wrapper function for get PCD value for dynamic-ex PCD.
1270 @param Guid Token space guid for dynamic-ex PCD.
1271 @param ExTokenNumber Token number for dynamic-ex PCD.
1272 @param GetSize The size of dynamic-ex PCD value.
1274 @return PCD entry in PCD database.
1279 IN CONST EFI_GUID
*Guid
,
1280 IN UINTN ExTokenNumber
,
1284 return GetWorker(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
), GetSize
);
1288 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
1290 @param ExTokenNumber Token number for dynamic-ex PCD.
1291 @param Guid Token space guid for dynamic-ex PCD.
1292 @param Data Value want to be set.
1293 @param SetSize The size of value.
1295 @return status of ExSetWorker().
1300 IN UINTN ExTokenNumber
,
1301 IN CONST EFI_GUID
*Guid
,
1306 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &SetSize
, FALSE
);
1310 Set value for a dynamic-ex PCD entry.
1312 This routine find the local token number according to dynamic-ex PCD's token
1313 space guid and token number firstly, and invoke callback function if this PCD
1314 entry registered callback function. Finally, invoken general SetWorker to set
1317 @param ExTokenNumber Dynamic-ex PCD token number.
1318 @param Guid Token space guid for dynamic-ex PCD.
1319 @param Data PCD value want to be set
1320 @param SetSize Size of value.
1321 @param PtrType If TRUE, this PCD entry is pointer type.
1322 If FALSE, this PCD entry is not pointer type.
1324 @return status of SetWorker().
1329 IN UINTN ExTokenNumber
,
1330 IN CONST EFI_GUID
*Guid
,
1332 IN OUT UINTN
*SetSize
,
1338 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
);
1340 InvokeCallbackOnSet ((UINT32
) ExTokenNumber
, Guid
, TokenNumber
, Data
, *SetSize
);
1342 return SetWorker (TokenNumber
, Data
, SetSize
, PtrType
);
1347 Set value for HII-type PCD.
1349 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
1350 HII-type PCD is to visit this variable.
1352 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
1353 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
1354 @param Data Value want to be set.
1355 @param DataSize Size of value
1356 @param Offset Value offset of HII-type PCD in variable.
1358 @return status of GetVariable()/SetVariable().
1363 IN EFI_GUID
*VariableGuid
,
1364 IN UINT16
*VariableName
,
1365 IN CONST VOID
*Data
,
1380 // Try to get original variable size information.
1382 Status
= gRT
->GetVariable (
1383 (UINT16
*)VariableName
,
1390 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1392 // Patch new PCD's value to offset in given HII variable.
1394 if (Size
>= (DataSize
+ Offset
)) {
1397 SetSize
= DataSize
+ Offset
;
1399 Buffer
= AllocatePool (SetSize
);
1400 ASSERT (Buffer
!= NULL
);
1402 Status
= gRT
->GetVariable (
1410 ASSERT_EFI_ERROR (Status
);
1412 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1414 Status
= gRT
->SetVariable (
1424 } else if (Status
== EFI_NOT_FOUND
) {
1426 // If variable does not exist, a new variable need to be created.
1429 Size
= Offset
+ DataSize
;
1431 Buffer
= AllocateZeroPool (Size
);
1432 ASSERT (Buffer
!= NULL
);
1434 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1436 Status
= gRT
->SetVariable (
1439 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1449 // If we drop to here, the value is failed to be written in to variable area
1450 // So, we will save the data in the PCD Database's volatile area.
1456 Get Token Number according to dynamic-ex PCD's {token space guid:token number}
1458 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1459 in DEC file. PCD database maintain a mapping table that translate pair of {token
1460 space guid: token number} to Token Number.
1462 @param Guid Token space guid for dynamic-ex PCD entry.
1463 @param ExTokenNumber Dynamic-ex PCD token number.
1465 @return Token Number for dynamic-ex PCD.
1469 GetExPcdTokenNumber (
1470 IN CONST EFI_GUID
*Guid
,
1471 IN UINT32 ExTokenNumber
1475 DYNAMICEX_MAPPING
*ExMap
;
1476 EFI_GUID
*GuidTable
;
1477 EFI_GUID
*MatchGuid
;
1480 if (!mPeiDatabaseEmpty
) {
1481 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->ExMapTableOffset
);
1482 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->GuidTableOffset
);
1484 MatchGuid
= ScanGuid (GuidTable
, mPeiGuidTableSize
, Guid
);
1486 if (MatchGuid
!= NULL
) {
1488 MatchGuidIdx
= MatchGuid
- GuidTable
;
1490 for (Index
= 0; Index
< mPeiExMapppingTableSize
; Index
++) {
1491 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1492 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1493 return ExMap
[Index
].TokenNumber
;
1499 ExMap
= (DYNAMICEX_MAPPING
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->ExMapTableOffset
);
1500 GuidTable
= (EFI_GUID
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->GuidTableOffset
);
1502 MatchGuid
= ScanGuid (GuidTable
, mDxeGuidTableSize
, Guid
);
1504 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1505 // error in the BUILD system.
1507 ASSERT (MatchGuid
!= NULL
);
1509 MatchGuidIdx
= MatchGuid
- GuidTable
;
1511 for (Index
= 0; Index
< mDxeExMapppingTableSize
; Index
++) {
1512 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1513 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1514 return ExMap
[Index
].TokenNumber
;
1524 Get SKU ID table from PCD database.
1526 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1527 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1528 If FALSE, the pcd entry is initialized in DXE phase.
1529 @return Pointer to SKU ID array table
1534 IN UINTN LocalTokenNumberTableIdx
,
1539 UINTN LocalTokenNumber
;
1543 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1544 Database
= (UINT8
*) mPcdDatabase
.PeiDb
;
1546 LocalTokenNumber
= *((UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
) + LocalTokenNumberTableIdx
);
1547 Database
= (UINT8
*) mPcdDatabase
.DxeDb
;
1550 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1552 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1554 return (SKU_ID
*) (Database
+ SkuHead
->SkuIdTableOffset
);
1559 Wrapper function of getting index of PCD entry in size table.
1561 @param LocalTokenNumberTableIdx Index of this PCD in local 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.
1565 @return index of PCD entry in size table.
1569 IN UINTN LocalTokenNumberTableIdx
,
1573 UINT32
*LocalTokenNumberTable
;
1574 UINTN LocalTokenNumber
;
1580 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1582 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1587 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
1588 LocalTokenNumber
= LocalTokenNumberTable
[Index
];
1590 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1592 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1595 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1597 // We have only two entry for VPD enabled PCD entry:
1600 // Current size is equal to MAX size.
1604 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1606 // We have only two entry for Non-Sku enabled PCD entry:
1613 // We have these entry for SKU enabled PCD entry
1615 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1617 SkuIdTable
= GetSkuIdArray (Index
, IsPeiDb
);
1618 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1625 return SizeTableIdx
;
1629 Get size of POINTER type PCD value.
1631 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1632 @param MaxSize Maxmium size of POINTER type PCD value.
1634 @return size of POINTER type PCD value.
1639 IN UINTN LocalTokenNumberTableIdx
,
1644 UINTN LocalTokenNumber
;
1646 SIZE_INFO
*SizeTable
;
1649 UINT32
*LocalTokenNumberTable
;
1651 // EBC compiler is very choosy. It may report warning about comparison
1652 // between UINTN and 0 . So we add 1 in each size of the
1654 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1658 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1659 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1661 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1662 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1663 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1666 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1668 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1670 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1672 *MaxSize
= SizeTable
[SizeTableIdx
];
1674 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1677 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1679 // We have only two entry for VPD enabled PCD entry:
1682 // We consider current size is equal to MAX size.
1686 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1688 // We have only two entry for Non-Sku enabled PCD entry:
1692 return SizeTable
[SizeTableIdx
+ 1];
1695 // We have these entry for SKU enabled PCD entry
1697 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1699 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1700 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1701 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.PeiDb
->SystemSkuId
) {
1702 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1705 return SizeTable
[SizeTableIdx
+ 1];
1711 Set size of POINTER type PCD value. The size should not exceed the maximum size
1714 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1715 @param CurrentSize Size of POINTER type PCD value.
1717 @retval TRUE Success to set size of PCD value.
1718 @retval FALSE Fail to set size of PCD value.
1722 IN UINTN LocalTokenNumberTableIdx
,
1723 IN OUT UINTN
*CurrentSize
1727 UINTN LocalTokenNumber
;
1729 SIZE_INFO
*SizeTable
;
1733 UINT32
*LocalTokenNumberTable
;
1736 // EBC compiler is very choosy. It may report warning about comparison
1737 // between UINTN and 0 . So we add 1 in each size of the
1740 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < mPeiLocalTokenCount
+ 1);
1743 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->LocalTokenNumberTableOffset
);
1744 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.PeiDb
+ mPcdDatabase
.PeiDb
->SizeTableOffset
);
1746 LocalTokenNumberTableIdx
-= mPeiLocalTokenCount
;
1747 LocalTokenNumberTable
= (UINT32
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->LocalTokenNumberTableOffset
);
1748 SizeTable
= (SIZE_INFO
*)((UINT8
*)mPcdDatabase
.DxeDb
+ mPcdDatabase
.DxeDb
->SizeTableOffset
);
1751 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1753 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1755 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1757 MaxSize
= SizeTable
[SizeTableIdx
];
1759 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1762 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1764 // We shouldn't come here as we don't support SET for VPD
1769 if ((*CurrentSize
> MaxSize
) ||
1770 (*CurrentSize
== MAX_ADDRESS
)) {
1771 *CurrentSize
= MaxSize
;
1775 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1777 // We have only two entry for Non-Sku enabled PCD entry:
1781 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1785 // We have these entry for SKU enabled PCD entry
1787 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1789 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1790 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1791 if (SkuIdTable
[1 + Index
] == mPcdDatabase
.PeiDb
->SystemSkuId
) {
1792 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1796 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;