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
));
446 ASSERT(mCallbackFnTable
!= NULL
);
448 // EBC compiler is very choosy. It may report warning about comparison
449 // between UINTN and 0 . So we add 1 in each size of the
451 for (Index
= 0; Index
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1; Index
++) {
452 InitializeListHead (&mCallbackFnTable
[Index
]);
457 Get Variable which contains HII type PCD entry.
459 @param VariableGuid Variable's guid
460 @param VariableName Variable's unicode name string
461 @param VariableData Variable's data pointer,
462 @param VariableSize Variable's size.
464 @return the status of gRT->GetVariable
468 IN EFI_GUID
*VariableGuid
,
469 IN UINT16
*VariableName
,
470 OUT UINT8
**VariableData
,
471 OUT UINTN
*VariableSize
482 // Firstly get the real size of HII variable
484 Status
= gRT
->GetVariable (
485 (UINT16
*)VariableName
,
493 // Allocate buffer to hold whole variable data according to variable size.
495 if (Status
== EFI_BUFFER_TOO_SMALL
) {
496 Buffer
= (UINT8
*) AllocatePool (Size
);
498 ASSERT (Buffer
!= NULL
);
500 Status
= gRT
->GetVariable (
508 ASSERT (Status
== EFI_SUCCESS
);
509 *VariableData
= Buffer
;
510 *VariableSize
= Size
;
517 Find the local token number according to system SKU ID.
519 @param LocalTokenNumber PCD token number
520 @param Size The size of PCD entry.
521 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
522 If False, the PCD entry is initialized in DXE phase.
524 @return Token number according to system SKU ID.
528 GetSkuEnabledTokenNumber (
529 UINT32 LocalTokenNumber
,
538 SKU_ID
*PhaseSkuIdTable
;
541 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
543 PcdDb
= IsPeiDb
? (UINT8
*) &mPcdDatabase
->PeiDb
: (UINT8
*) &mPcdDatabase
->DxeDb
;
545 SkuHead
= (SKU_HEAD
*) (PcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
546 Value
= (UINT8
*) (PcdDb
+ SkuHead
->SkuDataStartOffset
);
548 PhaseSkuIdTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.SkuIdTable
:
549 mPcdDatabase
->DxeDb
.Init
.SkuIdTable
;
551 SkuIdTable
= &PhaseSkuIdTable
[SkuHead
->SkuIdTableOffset
];
554 // Find the current system's SKU ID entry in SKU ID table.
556 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
557 if (mPcdDatabase
->PeiDb
.Init
.SystemSkuId
== SkuIdTable
[Index
+ 1]) {
561 ASSERT (Index
< SkuIdTable
[0]);
563 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
565 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
566 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_VPD
);
569 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
570 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
);
572 case PCD_TYPE_STRING
:
573 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
574 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_STRING
);
577 Value
+= Size
* Index
;
578 return (UINT32
) (Value
- PcdDb
);
591 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
592 has registered callback function.
594 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
596 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
598 @param TokenNumber PCD token number generated by build tools.
599 @param Data Value want to be set for this PCD entry
600 @param Size The size of value
604 InvokeCallbackOnSet (
605 UINT32 ExTokenNumber
,
606 CONST EFI_GUID
*Guid
, OPTIONAL
612 CALLBACK_FN_ENTRY
*FnTableEntry
;
613 LIST_ENTRY
*ListHead
;
614 LIST_ENTRY
*ListNode
;
617 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
618 // We have to decrement TokenNumber by 1 to make it usable
619 // as the array index.
623 ListHead
= &mCallbackFnTable
[TokenNumber
];
624 ListNode
= GetFirstNode (ListHead
);
626 while (ListNode
!= ListHead
) {
627 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
629 FnTableEntry
->CallbackFn(Guid
,
630 (Guid
== NULL
) ? TokenNumber
: ExTokenNumber
,
634 ListNode
= GetNextNode (ListHead
, ListNode
);
642 Wrapper function for setting non-pointer type value for a PCD entry.
644 @param TokenNumber Pcd token number autogenerated by build tools.
645 @param Data Value want to be set for PCD entry
646 @param Size Size of value.
648 @return status of SetWorker.
653 IN UINTN TokenNumber
,
658 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
663 Set value for an PCD entry
665 @param TokenNumber Pcd token number autogenerated by build tools.
666 @param Data Value want to be set for PCD entry
667 @param Size Size of value.
668 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
669 If False, the type of PCD entry's value is not Pointer.
671 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
672 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
673 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
674 range of UINT8, UINT16, UINT32, UINT64
675 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
679 IN UINTN TokenNumber
,
685 UINT32
*LocalTokenNumberTable
;
687 UINT32 LocalTokenNumber
;
692 UINTN VariableOffset
;
694 VARIABLE_HEAD
*VariableHead
;
699 UINTN TmpTokenNumber
;
702 // Aquire lock to prevent reentrance from TPL_CALLBACK level
704 EfiAcquireLock (&mPcdDatabaseLock
);
707 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
708 // We have to decrement TokenNumber by 1 to make it usable
709 // as the array index.
713 TmpTokenNumber
= TokenNumber
;
716 // EBC compiler is very choosy. It may report warning about comparison
717 // between UINTN and 0 . So we add 1 in each size of the
720 ASSERT (TokenNumber
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1);
723 ASSERT (*Size
== DxePcdGetSize (TokenNumber
+ 1));
727 // EBC compiler is very choosy. It may report warning about comparison
728 // between UINTN and 0 . So we add 1 in each size of the
731 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1) ? TRUE
: FALSE
);
733 LocalTokenNumberTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
:
734 mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
737 // EBC compiler is very choosy. It may report warning about comparison
738 // between UINTN and 0 . So we add 1 in each size of the
741 if ((TokenNumber
+ 1 < PEI_NEX_TOKEN_NUMBER
+ 1) ||
742 (TokenNumber
+ 1 >= PEI_LOCAL_TOKEN_NUMBER
+ 1 || TokenNumber
+ 1 < (PEI_LOCAL_TOKEN_NUMBER
+ DXE_NEX_TOKEN_NUMBER
+ 1))) {
743 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
746 TokenNumber
= IsPeiDb
? TokenNumber
747 : TokenNumber
- PEI_LOCAL_TOKEN_NUMBER
;
749 LocalTokenNumber
= LocalTokenNumberTable
[TokenNumber
];
751 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
753 GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
757 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
, IsPeiDb
);
760 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
762 PcdDb
= IsPeiDb
? ((UINT8
*) &mPcdDatabase
->PeiDb
) : ((UINT8
*) &mPcdDatabase
->DxeDb
);
764 StringTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.StringTable
:
765 mPcdDatabase
->DxeDb
.Init
.StringTable
;
767 InternalData
= PcdDb
+ Offset
;
769 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
772 Status
= EFI_INVALID_PARAMETER
;
775 case PCD_TYPE_STRING
:
776 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
777 CopyMem (&StringTable
[*((UINT16
*)InternalData
)], Data
, *Size
);
778 Status
= EFI_SUCCESS
;
780 Status
= EFI_INVALID_PARAMETER
;
786 if (!SetPtrTypeSize (TmpTokenNumber
, Size
)) {
787 Status
= EFI_INVALID_PARAMETER
;
792 GuidTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.GuidTable
:
793 mPcdDatabase
->DxeDb
.Init
.GuidTable
;
795 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
797 Guid
= &(GuidTable
[VariableHead
->GuidTableIndex
]);
798 Name
= &(StringTable
[VariableHead
->StringIndex
]);
799 VariableOffset
= VariableHead
->Offset
;
801 Status
= SetHiiVariable (Guid
, Name
, Data
, *Size
, VariableOffset
);
803 if (EFI_NOT_FOUND
== Status
) {
804 CopyMem (PcdDb
+ VariableHead
->DefaultValueOffset
, Data
, *Size
);
805 Status
= EFI_SUCCESS
;
811 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
812 CopyMem (InternalData
, Data
, *Size
);
813 Status
= EFI_SUCCESS
;
815 Status
= EFI_INVALID_PARAMETER
;
820 Status
= EFI_SUCCESS
;
823 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
827 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
831 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
835 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
840 Status
= EFI_NOT_FOUND
;
847 Status
= EFI_NOT_FOUND
;
851 EfiReleaseLock (&mPcdDatabaseLock
);
857 Wrapper function for get PCD value for dynamic-ex PCD.
859 @param Guid Token space guid for dynamic-ex PCD.
860 @param ExTokenNumber Token number for dynamic-ex PCD.
861 @param GetSize The size of dynamic-ex PCD value.
863 @return PCD entry in PCD database.
868 IN CONST EFI_GUID
*Guid
,
869 IN UINTN ExTokenNumber
,
873 return GetWorker(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
), GetSize
);
877 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
879 @param ExTokenNumber Token number for dynamic-ex PCD.
880 @param Guid Token space guid for dynamic-ex PCD.
881 @param Data Value want to be set.
882 @param SetSize The size of value.
884 @return status of ExSetWorker().
889 IN UINTN ExTokenNumber
,
890 IN CONST EFI_GUID
*Guid
,
895 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &SetSize
, FALSE
);
899 Set value for a dynamic PCD entry.
901 This routine find the local token number according to dynamic-ex PCD's token
902 space guid and token number firstly, and invoke callback function if this PCD
903 entry registered callback function. Finally, invoken general SetWorker to set
906 @param ExTokenNumber Dynamic-ex PCD token number.
907 @param Guid Token space guid for dynamic-ex PCD.
908 @param Data PCD value want to be set
909 @param SetSize Size of value.
910 @param PtrType If TRUE, this PCD entry is pointer type.
911 If FALSE, this PCD entry is not pointer type.
913 @return status of SetWorker().
918 IN UINTN ExTokenNumber
,
919 IN CONST EFI_GUID
*Guid
,
921 IN OUT UINTN
*SetSize
,
927 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
);
929 InvokeCallbackOnSet ((UINT32
) ExTokenNumber
, Guid
, TokenNumber
, Data
, *SetSize
);
931 return SetWorker (TokenNumber
, Data
, SetSize
, PtrType
);
936 Set value for HII-type PCD.
938 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
939 HII-type PCD is to visit this variable.
941 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
942 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
943 @param Data Value want to be set.
944 @param DataSize Size of value
945 @param Offset Value offset of HII-type PCD in variable.
947 @return status of GetVariable()/SetVariable().
952 IN EFI_GUID
*VariableGuid
,
953 IN UINT16
*VariableName
,
966 Status
= gRT
->GetVariable (
967 (UINT16
*)VariableName
,
974 if (Status
== EFI_BUFFER_TOO_SMALL
) {
976 Buffer
= AllocatePool (Size
);
978 ASSERT (Buffer
!= NULL
);
980 Status
= gRT
->GetVariable (
988 ASSERT_EFI_ERROR (Status
);
990 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
992 Status
= gRT
->SetVariable (
1006 // If we drop to here, we don't have a Variable entry in
1007 // the variable service yet. So, we will save the data
1008 // in the PCD Database's volatile area.
1014 Get local token number according to dynamic-ex PCD's {token space guid:token number}
1016 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1017 in DEC file. PCD database maintain a mapping table that translate pair of {token
1018 space guid: token number} to local token number.
1020 @param Guid Token space guid for dynamic-ex PCD entry.
1021 @param ExTokenNumber EDES_TODO: Add parameter description
1023 @return local token number for dynamic-ex PCD.
1027 GetExPcdTokenNumber (
1028 IN CONST EFI_GUID
*Guid
,
1029 IN UINT32 ExTokenNumber
1033 DYNAMICEX_MAPPING
*ExMap
;
1034 EFI_GUID
*GuidTable
;
1035 EFI_GUID
*MatchGuid
;
1038 if (!PEI_DATABASE_EMPTY
) {
1039 ExMap
= mPcdDatabase
->PeiDb
.Init
.ExMapTable
;
1040 GuidTable
= mPcdDatabase
->PeiDb
.Init
.GuidTable
;
1042 MatchGuid
= ScanGuid (GuidTable
, sizeof(mPcdDatabase
->PeiDb
.Init
.GuidTable
), Guid
);
1044 if (MatchGuid
!= NULL
) {
1046 MatchGuidIdx
= MatchGuid
- GuidTable
;
1048 for (Index
= 0; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
1049 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1050 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1051 return ExMap
[Index
].LocalTokenNumber
;
1058 ExMap
= mPcdDatabase
->DxeDb
.Init
.ExMapTable
;
1059 GuidTable
= mPcdDatabase
->DxeDb
.Init
.GuidTable
;
1061 MatchGuid
= ScanGuid (GuidTable
, sizeof(mPcdDatabase
->DxeDb
.Init
.GuidTable
), Guid
);
1063 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1064 // error in the BUILD system.
1066 ASSERT (MatchGuid
!= NULL
);
1068 MatchGuidIdx
= MatchGuid
- GuidTable
;
1070 for (Index
= 0; Index
< DXE_EXMAPPING_TABLE_SIZE
; Index
++) {
1071 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1072 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1073 return ExMap
[Index
].LocalTokenNumber
;
1083 Get SKU ID table from PCD database.
1085 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1086 @param IsPeiPcd If TRUE,
1088 @return Pointer to SKU ID array table
1093 IN UINTN LocalTokenNumberTableIdx
,
1098 UINTN LocalTokenNumber
;
1102 LocalTokenNumber
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1103 Database
= (UINT8
*) &mPcdDatabase
->PeiDb
;
1105 LocalTokenNumber
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
- PEI_LOCAL_TOKEN_NUMBER
];
1106 Database
= (UINT8
*) &mPcdDatabase
->DxeDb
;
1109 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1111 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1113 return (SKU_ID
*) (Database
+ SkuHead
->SkuIdTableOffset
);
1119 Get index of PCD entry in size table.
1121 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1122 @param LocalTokenNumberTable Pointer to local token number table in PCD database.
1123 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1124 If FALSE, the pcd entry is initialized in DXE phase.
1126 @return index of PCD entry in size table.
1130 GetSizeTableIndexA (
1131 IN UINTN LocalTokenNumberTableIdx
,
1132 IN UINT32
*LocalTokenNumberTable
,
1138 UINTN LocalTokenNumber
;
1143 for (Index
=0; Index
<LocalTokenNumberTableIdx
; Index
++) {
1144 LocalTokenNumber
= LocalTokenNumberTable
[Index
];
1146 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1148 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1151 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1153 // We have only one entry for VPD enabled PCD entry:
1155 // We consider current size is equal to MAX size.
1159 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1161 // We have only two entry for Non-Sku enabled PCD entry:
1168 // We have these entry for SKU enabled PCD entry
1170 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1172 SkuIdTable
= GetSkuIdArray (Index
, IsPeiDb
);
1173 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1180 return SizeTableIdx
;
1186 Wrapper function of getting index of PCD entry in size table.
1188 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1189 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1190 If FALSE, the pcd entry is initialized in DXE phase.
1192 @return index of PCD entry in size table.
1196 IN UINTN LocalTokenNumberTableIdx
,
1200 UINT32
*LocalTokenNumberTable
;
1203 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1205 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1207 return GetSizeTableIndexA (LocalTokenNumberTableIdx
,
1208 LocalTokenNumberTable
,
1213 Get size of POINTER type PCD value.
1215 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1216 @param MaxSize Maxmium size of POINTER type PCD value.
1218 @return size of POINTER type PCD value.
1223 IN UINTN LocalTokenNumberTableIdx
,
1228 UINTN LocalTokenNumber
;
1230 SIZE_INFO
*SizeTable
;
1233 UINT32
*LocalTokenNumberTable
;
1235 // EBC compiler is very choosy. It may report warning about comparison
1236 // between UINTN and 0 . So we add 1 in each size of the
1238 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
1242 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1243 SizeTable
= mPcdDatabase
->PeiDb
.Init
.SizeTable
;
1245 LocalTokenNumberTableIdx
-= PEI_LOCAL_TOKEN_NUMBER
;
1246 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1247 SizeTable
= mPcdDatabase
->DxeDb
.Init
.SizeTable
;
1250 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1252 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1254 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1256 *MaxSize
= SizeTable
[SizeTableIdx
];
1258 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1261 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1263 // We have only one entry for VPD enabled PCD entry:
1265 // We consider current size is equal to MAX size.
1269 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1271 // We have only two entry for Non-Sku enabled PCD entry:
1275 return SizeTable
[SizeTableIdx
+ 1];
1278 // We have these entry for SKU enabled PCD entry
1280 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1282 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1283 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1284 if (SkuIdTable
[1 + Index
] == mPcdDatabase
->PeiDb
.Init
.SystemSkuId
) {
1285 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1288 return SizeTable
[SizeTableIdx
+ 1];
1294 Set size of POINTER type PCD value. The size should not exceed the maximum size
1297 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1298 @param CurrentSize Size of POINTER type PCD value.
1300 @retval TRUE Success to set size of PCD value.
1301 @retval FALSE Fail to set size of PCD value.
1305 IN UINTN LocalTokenNumberTableIdx
,
1306 IN OUT UINTN
*CurrentSize
1310 UINTN LocalTokenNumber
;
1312 SIZE_INFO
*SizeTable
;
1316 UINT32
*LocalTokenNumberTable
;
1319 // EBC compiler is very choosy. It may report warning about comparison
1320 // between UINTN and 0 . So we add 1 in each size of the
1323 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
1326 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1327 SizeTable
= mPcdDatabase
->PeiDb
.Init
.SizeTable
;
1329 LocalTokenNumberTableIdx
-= PEI_LOCAL_TOKEN_NUMBER
;
1330 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1331 SizeTable
= mPcdDatabase
->DxeDb
.Init
.SizeTable
;
1334 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1336 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1338 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1340 MaxSize
= SizeTable
[SizeTableIdx
];
1342 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1345 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1347 // We shouldn't come here as we don't support SET for VPD
1352 if ((*CurrentSize
> MaxSize
) ||
1353 (*CurrentSize
== MAX_ADDRESS
)) {
1354 *CurrentSize
= MaxSize
;
1358 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1360 // We have only two entry for Non-Sku enabled PCD entry:
1364 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1368 // We have these entry for SKU enabled PCD entry
1370 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1372 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1373 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1374 if (SkuIdTable
[1 + Index
] == mPcdDatabase
->PeiDb
.Init
.SystemSkuId
) {
1375 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1379 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;