2 Help functions used by PCD DXE driver.
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. 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.
17 PCD_DATABASE
* mPcdDatabase
;
19 LIST_ENTRY
*mCallbackFnTable
;
22 Get the PCD entry pointer in PCD database.
24 This routine will visit PCD database to find the PCD entry according to given
25 token number. The given token number is autogened by build tools and it will be
26 translated to local token number. Local token number contains PCD's type and
27 offset of PCD entry in PCD database.
29 @param TokenNumber Token's number, it is autogened by build tools
30 @param GetSize The size of token's value
32 @return PCD entry pointer in PCD database
41 UINT32
*LocalTokenNumberTable
;
46 VARIABLE_HEAD
*VariableHead
;
47 UINT8
*VaraiableDefaultBuffer
;
56 UINT32 LocalTokenNumber
;
58 UINT16 StringTableIdx
;
62 // Aquire lock to prevent reentrance from TPL_CALLBACK level
64 EfiAcquireLock (&mPcdDatabaseLock
);
68 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
69 // We have to decrement TokenNumber by 1 to make it usable
70 // as the array index.
74 TmpTokenNumber
= TokenNumber
;
77 // PCD_TOTAL_TOKEN_NUMBER is a auto-generated constant.
78 // It could be zero. EBC compiler is very choosy. It may
79 // report warning. So we add 1 in each size of the
82 ASSERT (TokenNumber
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1);
84 ASSERT ((GetSize
== DxePcdGetSize (TokenNumber
+ 1)) || (GetSize
== 0));
86 // EBC compiler is very choosy. It may report warning about comparison
87 // between UINTN and 0 . So we add 1 in each size of the
89 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1) ? TRUE
: FALSE
);
91 LocalTokenNumberTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
:
92 mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
94 TokenNumber
= IsPeiDb
? TokenNumber
:
95 TokenNumber
- PEI_LOCAL_TOKEN_NUMBER
;
97 LocalTokenNumber
= LocalTokenNumberTable
[TokenNumber
];
99 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
101 GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
105 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
, IsPeiDb
);
108 PcdDb
= IsPeiDb
? ((UINT8
*) &mPcdDatabase
->PeiDb
) : ((UINT8
*) &mPcdDatabase
->DxeDb
);
109 StringTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.StringTable
:
110 mPcdDatabase
->DxeDb
.Init
.StringTable
;
112 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
114 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
116 VpdHead
= (VPD_HEAD
*) ((UINT8
*) PcdDb
+ Offset
);
117 RetPtr
= (VOID
*) (UINTN
) (FixedPcdGet32(PcdVpdBaseAddress
) + VpdHead
->Offset
);
121 GuidTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.GuidTable
:
122 mPcdDatabase
->DxeDb
.Init
.GuidTable
;
124 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
126 Guid
= &(GuidTable
[VariableHead
->GuidTableIndex
]);
127 Name
= &(StringTable
[VariableHead
->StringIndex
]);
128 VaraiableDefaultBuffer
= (UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
;
130 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
131 if (Status
== EFI_SUCCESS
) {
134 // It is a pointer type. So get the MaxSize reserved for
137 GetPtrTypeSize (TmpTokenNumber
, &GetSize
);
139 CopyMem (VaraiableDefaultBuffer
, Data
+ VariableHead
->Offset
, GetSize
);
143 // If the operation is successful, we copy the data
144 // to the default value buffer in the PCD Database.
145 // So that we can free the Data allocated in GetHiiVariable.
148 // If the operation is not successful,
149 // Return 1) either the default value specified by Platform Integrator
150 // 2) Or the value Set by a PCD set operation.
152 RetPtr
= (VOID
*) VaraiableDefaultBuffer
;
155 case PCD_TYPE_STRING
:
156 StringTableIdx
= (UINT16
) *((UINT8
*) PcdDb
+ Offset
);
157 RetPtr
= (VOID
*) &StringTable
[StringTableIdx
];
161 RetPtr
= (VOID
*) ((UINT8
*) PcdDb
+ Offset
);
170 EfiReleaseLock (&mPcdDatabaseLock
);
177 Register the callback function for a PCD entry.
179 This routine will register a callback function to a PCD entry by given token number
180 and token space guid.
182 @param TokenNumber PCD token's number, it is autogened by build tools.
183 @param Guid PCD token space's guid,
184 if not NULL, this PCD is dynamicEx type PCD.
185 @param CallBackFunction Callback function pointer
187 @return EFI_SUCCESS Always success for registering callback function.
191 DxeRegisterCallBackWorker (
192 IN UINTN TokenNumber
,
193 IN CONST EFI_GUID
*Guid
, OPTIONAL
194 IN PCD_PROTOCOL_CALLBACK CallBackFunction
197 CALLBACK_FN_ENTRY
*FnTableEntry
;
198 LIST_ENTRY
*ListHead
;
199 LIST_ENTRY
*ListNode
;
202 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
206 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
207 // We have to decrement TokenNumber by 1 to make it usable
208 // as the array index.
212 ListHead
= &mCallbackFnTable
[TokenNumber
];
213 ListNode
= GetFirstNode (ListHead
);
215 while (ListNode
!= ListHead
) {
216 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
218 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
220 // We only allow a Callback function to be register once
221 // for a TokenNumber. So just return EFI_SUCCESS
225 ListNode
= GetNextNode (ListHead
, ListNode
);
228 FnTableEntry
= AllocatePool (sizeof(CALLBACK_FN_ENTRY
));
229 ASSERT (FnTableEntry
!= NULL
);
231 FnTableEntry
->CallbackFn
= CallBackFunction
;
232 InsertTailList (ListHead
, &FnTableEntry
->Node
);
238 UnRegister the callback function for a PCD entry.
240 This routine will unregister a callback function to a PCD entry by given token number
241 and token space guid.
243 @param TokenNumber PCD token's number, it is autogened by build tools.
244 @param Guid PCD token space's guid.
245 if not NULL, this PCD is dynamicEx type PCD.
246 @param CallBackFunction Callback function pointer
248 @retval EFI_SUCCESS Callback function is success to be unregister.
249 @retval EFI_INVALID_PARAMETER Can not find the PCD entry by given token number.
252 DxeUnRegisterCallBackWorker (
253 IN UINTN TokenNumber
,
254 IN CONST EFI_GUID
*Guid
, OPTIONAL
255 IN PCD_PROTOCOL_CALLBACK CallBackFunction
258 CALLBACK_FN_ENTRY
*FnTableEntry
;
259 LIST_ENTRY
*ListHead
;
260 LIST_ENTRY
*ListNode
;
263 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
267 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
268 // We have to decrement TokenNumber by 1 to make it usable
269 // as the array index.
273 ListHead
= &mCallbackFnTable
[TokenNumber
];
274 ListNode
= GetFirstNode (ListHead
);
276 while (ListNode
!= ListHead
) {
277 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
279 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
281 // We only allow a Callback function to be register once
282 // for a TokenNumber. So we can safely remove the Node from
283 // the Link List and return EFI_SUCCESS.
285 RemoveEntryList (ListNode
);
286 FreePool (FnTableEntry
);
290 ListNode
= GetNextNode (ListHead
, ListNode
);
293 return EFI_INVALID_PARAMETER
;
297 Get next token number in given token space.
299 This routine is used for dynamicEx type PCD. It will firstly scan token space
300 table to get token space according to given token space guid. Then scan given
301 token number in found token space, if found, then return next token number in
304 @param Guid Token space guid. Next token number will be scaned in
306 @param TokenNumber Token number.
307 If PCD_INVALID_TOKEN_NUMBER, return first token number in
309 If not PCD_INVALID_TOKEN_NUMBER, return next token number
310 in token space table.
311 @param GuidTable Token space guid table. It will be used for scan token space
312 by given token space guid.
313 @param SizeOfGuidTable The size of guid table.
314 @param ExMapTable DynamicEx token number mapping table.
315 @param SizeOfExMapTable The size of dynamicEx token number mapping table.
317 @retval EFI_NOT_FOUND Can not given token space or token number.
318 @retval EFI_SUCCESS Success to get next token number.
322 ExGetNextTokeNumber (
323 IN CONST EFI_GUID
*Guid
,
324 IN OUT UINTN
*TokenNumber
,
325 IN EFI_GUID
*GuidTable
,
326 IN UINTN SizeOfGuidTable
,
327 IN DYNAMICEX_MAPPING
*ExMapTable
,
328 IN UINTN SizeOfExMapTable
337 // Scan token space guid
339 MatchGuid
= ScanGuid (GuidTable
, SizeOfGuidTable
, Guid
);
340 if (MatchGuid
== NULL
) {
341 return EFI_NOT_FOUND
;
345 // Find the token space table in dynamicEx mapping table.
348 GuidTableIdx
= MatchGuid
- GuidTable
;
349 for (Index
= 0; Index
< SizeOfExMapTable
; Index
++) {
350 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
358 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
359 // token number in found token space.
361 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
362 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
366 for ( ; Index
< SizeOfExMapTable
; Index
++) {
367 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
369 if (Index
== SizeOfExMapTable
) {
371 // Exceed the length of ExMap Table
373 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
375 } else if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
377 // Found the next match
379 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
383 // Guid has been changed. It is the next Token Space Guid.
384 // We should flag no more TokenNumber.
386 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
393 return EFI_NOT_FOUND
;
398 Initialize the PCD database in DXE phase.
400 PCD database in DXE phase also contains PCD database in PEI phase which is copied
405 BuildPcdDxeDataBase (
409 PEI_PCD_DATABASE
*PeiDatabase
;
410 EFI_HOB_GUID_TYPE
*GuidHob
;
413 mPcdDatabase
= AllocateZeroPool (sizeof(PCD_DATABASE
));
414 ASSERT (mPcdDatabase
!= NULL
);
416 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
417 if (GuidHob
!= NULL
) {
420 // We will copy over the PEI phase's PCD Database.
422 // If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
423 // should not be included at all. So the GuidHob could
424 // be NULL. If it is NULL, we just copy over the DXE Default
425 // Value to PCD Database.
428 PeiDatabase
= (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
430 // Copy PCD Entries refereneced in PEI phase to PCD DATABASE
432 CopyMem (&mPcdDatabase
->PeiDb
, PeiDatabase
, sizeof (PEI_PCD_DATABASE
));
436 // Copy PCD Entries with default value to PCD DATABASE
438 CopyMem (&mPcdDatabase
->DxeDb
.Init
, &gDXEPcdDbInit
, sizeof(DXE_PCD_DATABASE_INIT
));
442 // Initialized the Callback Function Table
445 mCallbackFnTable
= AllocateZeroPool (PCD_TOTAL_TOKEN_NUMBER
* sizeof (LIST_ENTRY
));
447 // EBC compiler is very choosy. It may report warning about comparison
448 // between UINTN and 0 . So we add 1 in each size of the
450 for (Index
= 0; Index
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1; Index
++) {
451 InitializeListHead (&mCallbackFnTable
[Index
]);
456 Get Variable which contains HII type PCD entry.
458 @param VariableGuid Variable's guid
459 @param VariableName Variable's unicode name string
460 @param VariableData Variable's data pointer,
461 @param VariableSize Variable's size.
463 @return the status of gRT->GetVariable
467 IN EFI_GUID
*VariableGuid
,
468 IN UINT16
*VariableName
,
469 OUT UINT8
**VariableData
,
470 OUT UINTN
*VariableSize
481 // Firstly get the real size of HII variable
483 Status
= gRT
->GetVariable (
484 (UINT16
*)VariableName
,
492 // Allocate buffer to hold whole variable data according to variable size.
494 if (Status
== EFI_BUFFER_TOO_SMALL
) {
495 Buffer
= (UINT8
*) AllocatePool (Size
);
497 ASSERT (Buffer
!= NULL
);
499 Status
= gRT
->GetVariable (
507 ASSERT (Status
== EFI_SUCCESS
);
508 *VariableData
= Buffer
;
509 *VariableSize
= Size
;
516 Find the local token number according to system SKU ID.
518 @param LocalTokenNumber PCD token number
519 @param Size The size of PCD entry.
520 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
521 If False, the PCD entry is initialized in DXE phase.
523 @return Token number according to system SKU ID.
527 GetSkuEnabledTokenNumber (
528 UINT32 LocalTokenNumber
,
537 SKU_ID
*PhaseSkuIdTable
;
540 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
542 PcdDb
= IsPeiDb
? (UINT8
*) &mPcdDatabase
->PeiDb
: (UINT8
*) &mPcdDatabase
->DxeDb
;
544 SkuHead
= (SKU_HEAD
*) (PcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
545 Value
= (UINT8
*) (PcdDb
+ SkuHead
->SkuDataStartOffset
);
547 PhaseSkuIdTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.SkuIdTable
:
548 mPcdDatabase
->DxeDb
.Init
.SkuIdTable
;
550 SkuIdTable
= &PhaseSkuIdTable
[SkuHead
->SkuIdTableOffset
];
553 // Find the current system's SKU ID entry in SKU ID table.
555 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
556 if (mPcdDatabase
->PeiDb
.Init
.SystemSkuId
== SkuIdTable
[Index
+ 1]) {
560 ASSERT (Index
< SkuIdTable
[0]);
562 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
564 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
565 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_VPD
);
568 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
569 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
);
571 case PCD_TYPE_STRING
:
572 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
573 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_STRING
);
576 Value
+= Size
* Index
;
577 return (UINT32
) (Value
- PcdDb
);
590 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
591 has registered callback function.
593 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
595 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
597 @param TokenNumber PCD token number generated by build tools.
598 @param Data Value want to be set for this PCD entry
599 @param Size The size of value
603 InvokeCallbackOnSet (
604 UINT32 ExTokenNumber
,
605 CONST EFI_GUID
*Guid
, OPTIONAL
611 CALLBACK_FN_ENTRY
*FnTableEntry
;
612 LIST_ENTRY
*ListHead
;
613 LIST_ENTRY
*ListNode
;
616 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
617 // We have to decrement TokenNumber by 1 to make it usable
618 // as the array index.
622 ListHead
= &mCallbackFnTable
[TokenNumber
];
623 ListNode
= GetFirstNode (ListHead
);
625 while (ListNode
!= ListHead
) {
626 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
628 FnTableEntry
->CallbackFn(Guid
,
629 (Guid
== NULL
) ? TokenNumber
: ExTokenNumber
,
633 ListNode
= GetNextNode (ListHead
, ListNode
);
641 Wrapper function for setting non-pointer type value for a PCD entry.
643 @param TokenNumber Pcd token number autogenerated by build tools.
644 @param Data Value want to be set for PCD entry
645 @param Size Size of value.
647 @return status of SetWorker.
652 IN UINTN TokenNumber
,
657 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
662 Set value for an PCD entry
664 @param TokenNumber Pcd token number autogenerated by build tools.
665 @param Data Value want to be set for PCD entry
666 @param Size Size of value.
667 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
668 If False, the type of PCD entry's value is not Pointer.
670 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
671 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
672 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
673 range of UINT8, UINT16, UINT32, UINT64
674 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
678 IN UINTN TokenNumber
,
684 UINT32
*LocalTokenNumberTable
;
686 UINT32 LocalTokenNumber
;
691 UINTN VariableOffset
;
693 VARIABLE_HEAD
*VariableHead
;
698 UINTN TmpTokenNumber
;
701 // Aquire lock to prevent reentrance from TPL_CALLBACK level
703 EfiAcquireLock (&mPcdDatabaseLock
);
706 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
707 // We have to decrement TokenNumber by 1 to make it usable
708 // as the array index.
712 TmpTokenNumber
= TokenNumber
;
715 // EBC compiler is very choosy. It may report warning about comparison
716 // between UINTN and 0 . So we add 1 in each size of the
719 ASSERT (TokenNumber
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1);
722 ASSERT (*Size
== DxePcdGetSize (TokenNumber
+ 1));
726 // EBC compiler is very choosy. It may report warning about comparison
727 // between UINTN and 0 . So we add 1 in each size of the
730 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1) ? TRUE
: FALSE
);
732 LocalTokenNumberTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
:
733 mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
736 // EBC compiler is very choosy. It may report warning about comparison
737 // between UINTN and 0 . So we add 1 in each size of the
740 if ((TokenNumber
+ 1 < PEI_NEX_TOKEN_NUMBER
+ 1) ||
741 (TokenNumber
+ 1 >= PEI_LOCAL_TOKEN_NUMBER
+ 1 || TokenNumber
+ 1 < (PEI_LOCAL_TOKEN_NUMBER
+ DXE_NEX_TOKEN_NUMBER
+ 1))) {
742 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
745 TokenNumber
= IsPeiDb
? TokenNumber
746 : TokenNumber
- PEI_LOCAL_TOKEN_NUMBER
;
748 LocalTokenNumber
= LocalTokenNumberTable
[TokenNumber
];
750 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
752 GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
756 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
, IsPeiDb
);
759 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
761 PcdDb
= IsPeiDb
? ((UINT8
*) &mPcdDatabase
->PeiDb
) : ((UINT8
*) &mPcdDatabase
->DxeDb
);
763 StringTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.StringTable
:
764 mPcdDatabase
->DxeDb
.Init
.StringTable
;
766 InternalData
= PcdDb
+ Offset
;
768 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
771 Status
= EFI_INVALID_PARAMETER
;
774 case PCD_TYPE_STRING
:
775 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
776 CopyMem (&StringTable
[*((UINT16
*)InternalData
)], Data
, *Size
);
777 Status
= EFI_SUCCESS
;
779 Status
= EFI_INVALID_PARAMETER
;
785 if (!SetPtrTypeSize (TmpTokenNumber
, Size
)) {
786 Status
= EFI_INVALID_PARAMETER
;
791 GuidTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.GuidTable
:
792 mPcdDatabase
->DxeDb
.Init
.GuidTable
;
794 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
796 Guid
= &(GuidTable
[VariableHead
->GuidTableIndex
]);
797 Name
= &(StringTable
[VariableHead
->StringIndex
]);
798 VariableOffset
= VariableHead
->Offset
;
800 Status
= SetHiiVariable (Guid
, Name
, Data
, *Size
, VariableOffset
);
802 if (EFI_NOT_FOUND
== Status
) {
803 CopyMem (PcdDb
+ VariableHead
->DefaultValueOffset
, Data
, *Size
);
804 Status
= EFI_SUCCESS
;
810 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
811 CopyMem (InternalData
, Data
, *Size
);
812 Status
= EFI_SUCCESS
;
814 Status
= EFI_INVALID_PARAMETER
;
819 Status
= EFI_SUCCESS
;
822 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
826 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
830 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
834 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
839 Status
= EFI_NOT_FOUND
;
846 Status
= EFI_NOT_FOUND
;
850 EfiReleaseLock (&mPcdDatabaseLock
);
856 Wrapper function for get PCD value for dynamic-ex PCD.
858 @param Guid Token space guid for dynamic-ex PCD.
859 @param ExTokenNumber Token number for dyanmic-ex PCD.
860 @param GetSize The size of dynamic-ex PCD value.
862 @return PCD entry in PCD database.
867 IN CONST EFI_GUID
*Guid
,
868 IN UINTN ExTokenNumber
,
872 return GetWorker(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
), GetSize
);
876 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
878 @param ExTokenNumber Token number for dynamic-ex PCD.
879 @param Guid Token space guid for dynamic-ex PCD.
880 @param Data Value want to be set.
881 @param SetSize The size of value.
883 @return status of ExSetWorker().
888 IN UINTN ExTokenNumber
,
889 IN CONST EFI_GUID
*Guid
,
894 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &SetSize
, FALSE
);
898 Set value for a dynamic PCD entry.
900 This routine find the local token number according to dynamic-ex PCD's token
901 space guid and token number firstly, and invoke callback function if this PCD
902 entry registered callback function. Finally, invoken general SetWorker to set
905 @param ExTokenNumber Dynamic-ex PCD token number.
906 @param Guid Token space guid for dynamic-ex PCD.
907 @param Data PCD value want to be set
908 @param SetSize Size of value.
909 @param PtrType If TRUE, this PCD entry is pointer type.
910 If FALSE, this PCD entry is not pointer type.
912 @return status of SetWorker().
917 IN UINTN ExTokenNumber
,
918 IN CONST EFI_GUID
*Guid
,
920 IN OUT UINTN
*SetSize
,
926 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
);
928 InvokeCallbackOnSet ((UINT32
) ExTokenNumber
, Guid
, TokenNumber
, Data
, *SetSize
);
930 return SetWorker (TokenNumber
, Data
, SetSize
, PtrType
);
935 Set value for HII-type PCD.
937 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
938 HII-type PCD is to visit this variable.
940 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
941 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
942 @param Data Value want to be set.
943 @param DataSize Size of value
944 @param Offset Value offset of HII-type PCD in variable.
946 @return status of GetVariable()/SetVariable().
951 IN EFI_GUID
*VariableGuid
,
952 IN UINT16
*VariableName
,
965 Status
= gRT
->GetVariable (
966 (UINT16
*)VariableName
,
973 if (Status
== EFI_BUFFER_TOO_SMALL
) {
975 Buffer
= AllocatePool (Size
);
977 ASSERT (Buffer
!= NULL
);
979 Status
= gRT
->GetVariable (
987 ASSERT_EFI_ERROR (Status
);
989 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
991 Status
= gRT
->SetVariable (
1005 // If we drop to here, we don't have a Variable entry in
1006 // the variable service yet. So, we will save the data
1007 // in the PCD Database's volatile area.
1013 Get local token number according to dynamic-ex PCD's {token space guid:token number}
1015 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1016 in DEC file. PCD database maintain a mapping table that translate pair of {token
1017 space guid: token number} to local token number.
1019 @param Guid Token space guid for dynamic-ex PCD entry.
1020 @param ExTokenNumber EDES_TODO: Add parameter description
1022 @return local token number for dynamic-ex PCD.
1026 GetExPcdTokenNumber (
1027 IN CONST EFI_GUID
*Guid
,
1028 IN UINT32 ExTokenNumber
1032 DYNAMICEX_MAPPING
*ExMap
;
1033 EFI_GUID
*GuidTable
;
1034 EFI_GUID
*MatchGuid
;
1037 if (!PEI_DATABASE_EMPTY
) {
1038 ExMap
= mPcdDatabase
->PeiDb
.Init
.ExMapTable
;
1039 GuidTable
= mPcdDatabase
->PeiDb
.Init
.GuidTable
;
1041 MatchGuid
= ScanGuid (GuidTable
, sizeof(mPcdDatabase
->PeiDb
.Init
.GuidTable
), Guid
);
1043 if (MatchGuid
!= NULL
) {
1045 MatchGuidIdx
= MatchGuid
- GuidTable
;
1047 for (Index
= 0; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
1048 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1049 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1050 return ExMap
[Index
].LocalTokenNumber
;
1057 ExMap
= mPcdDatabase
->DxeDb
.Init
.ExMapTable
;
1058 GuidTable
= mPcdDatabase
->DxeDb
.Init
.GuidTable
;
1060 MatchGuid
= ScanGuid (GuidTable
, sizeof(mPcdDatabase
->DxeDb
.Init
.GuidTable
), Guid
);
1062 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1063 // error in the BUILD system.
1065 ASSERT (MatchGuid
!= NULL
);
1067 MatchGuidIdx
= MatchGuid
- GuidTable
;
1069 for (Index
= 0; Index
< DXE_EXMAPPING_TABLE_SIZE
; Index
++) {
1070 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1071 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1072 return ExMap
[Index
].LocalTokenNumber
;
1082 Get SKU ID tabble from PCD database.
1084 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1085 @param IsPeiPcd If TRUE,
1087 @return Pointer to SKU ID array table
1092 IN UINTN LocalTokenNumberTableIdx
,
1097 UINTN LocalTokenNumber
;
1101 LocalTokenNumber
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1102 Database
= (UINT8
*) &mPcdDatabase
->PeiDb
;
1104 LocalTokenNumber
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
- PEI_LOCAL_TOKEN_NUMBER
];
1105 Database
= (UINT8
*) &mPcdDatabase
->DxeDb
;
1108 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1110 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1112 return (SKU_ID
*) (Database
+ SkuHead
->SkuIdTableOffset
);
1118 Get index of PCD entry in size table.
1120 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1121 @param LocalTokenNumberTable Pointer to local token number table in PCD database.
1122 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1123 If FALSE, the pcd entry is initialized in DXE phase.
1125 @return index of PCD entry in size table.
1129 GetSizeTableIndexA (
1130 IN UINTN LocalTokenNumberTableIdx
,
1131 IN UINT32
*LocalTokenNumberTable
,
1137 UINTN LocalTokenNumber
;
1142 for (Index
=0; Index
<LocalTokenNumberTableIdx
; Index
++) {
1143 LocalTokenNumber
= LocalTokenNumberTable
[Index
];
1145 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1147 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1150 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1152 // We have only one entry for VPD enabled PCD entry:
1154 // We consider current size is equal to MAX size.
1158 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1160 // We have only two entry for Non-Sku enabled PCD entry:
1167 // We have these entry for SKU enabled PCD entry
1169 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1171 SkuIdTable
= GetSkuIdArray (Index
, IsPeiDb
);
1172 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1179 return SizeTableIdx
;
1185 Wrapper function of getting index of PCD entry in size table.
1187 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1188 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1189 If FALSE, the pcd entry is initialized in DXE phase.
1191 @return index of PCD entry in size table.
1195 IN UINTN LocalTokenNumberTableIdx
,
1199 UINT32
*LocalTokenNumberTable
;
1202 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1204 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1206 return GetSizeTableIndexA (LocalTokenNumberTableIdx
,
1207 LocalTokenNumberTable
,
1212 Get size of POINTER type PCD value.
1214 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1215 @param MaxSize Maxmium size of POINTER type PCD value.
1217 @return size of POINTER type PCD value.
1222 IN UINTN LocalTokenNumberTableIdx
,
1227 UINTN LocalTokenNumber
;
1229 SIZE_INFO
*SizeTable
;
1232 UINT32
*LocalTokenNumberTable
;
1234 // EBC compiler is very choosy. It may report warning about comparison
1235 // between UINTN and 0 . So we add 1 in each size of the
1237 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
1241 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1242 SizeTable
= mPcdDatabase
->PeiDb
.Init
.SizeTable
;
1244 LocalTokenNumberTableIdx
-= PEI_LOCAL_TOKEN_NUMBER
;
1245 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1246 SizeTable
= mPcdDatabase
->DxeDb
.Init
.SizeTable
;
1249 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1251 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1253 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1255 *MaxSize
= SizeTable
[SizeTableIdx
];
1257 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1260 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1262 // We have only one entry for VPD enabled PCD entry:
1264 // We consider current size is equal to MAX size.
1268 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1270 // We have only two entry for Non-Sku enabled PCD entry:
1274 return SizeTable
[SizeTableIdx
+ 1];
1277 // We have these entry for SKU enabled PCD entry
1279 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1281 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1282 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1283 if (SkuIdTable
[1 + Index
] == mPcdDatabase
->PeiDb
.Init
.SystemSkuId
) {
1284 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1287 return SizeTable
[SizeTableIdx
+ 1];
1293 Set size of POINTER type PCD value. The size should not exceed the maxmium size
1296 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1297 @param CurrentSize Size of POINTER type PCD value.
1299 @retval TRUE Success to set size of PCD value.
1300 @retval FALSE Fail to set size of PCD value.
1304 IN UINTN LocalTokenNumberTableIdx
,
1305 IN OUT UINTN
*CurrentSize
1309 UINTN LocalTokenNumber
;
1311 SIZE_INFO
*SizeTable
;
1315 UINT32
*LocalTokenNumberTable
;
1318 // EBC compiler is very choosy. It may report warning about comparison
1319 // between UINTN and 0 . So we add 1 in each size of the
1322 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
1325 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1326 SizeTable
= mPcdDatabase
->PeiDb
.Init
.SizeTable
;
1328 LocalTokenNumberTableIdx
-= PEI_LOCAL_TOKEN_NUMBER
;
1329 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1330 SizeTable
= mPcdDatabase
->DxeDb
.Init
.SizeTable
;
1333 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1335 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1337 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1339 MaxSize
= SizeTable
[SizeTableIdx
];
1341 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1344 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1346 // We shouldn't come here as we don't support SET for VPD
1351 if ((*CurrentSize
> MaxSize
) ||
1352 (*CurrentSize
== MAX_ADDRESS
)) {
1353 *CurrentSize
= MaxSize
;
1357 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1359 // We have only two entry for Non-Sku enabled PCD entry:
1363 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1367 // We have these entry for SKU enabled PCD entry
1369 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1371 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1372 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1373 if (SkuIdTable
[1 + Index
] == mPcdDatabase
->PeiDb
.Init
.SystemSkuId
) {
1374 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1378 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;