2 Help functions used by PCD DXE driver.
4 Copyright (c) 2006 - 2010, 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
);
111 StringTable
= (UINT8
*) (&mPcdDatabase
->PeiDb
.Init
.StringTable
[0]);
113 StringTable
= (UINT8
*) (&mPcdDatabase
->DxeDb
.Init
.StringTable
[0]);
117 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
119 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
121 VpdHead
= (VPD_HEAD
*) ((UINT8
*) PcdDb
+ Offset
);
122 RetPtr
= (VOID
*) (UINTN
) (PcdGet32 (PcdVpdBaseAddress
) + VpdHead
->Offset
);
127 GuidTable
= (EFI_GUID
*) (&mPcdDatabase
->PeiDb
.Init
.GuidTable
[0]);
129 GuidTable
= (EFI_GUID
*) (&mPcdDatabase
->DxeDb
.Init
.GuidTable
[0]);
132 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
134 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
135 Name
= (UINT16
*)(StringTable
+ VariableHead
->StringIndex
);
136 VaraiableDefaultBuffer
= (UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
;
138 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
139 if (Status
== EFI_SUCCESS
) {
142 // It is a pointer type. So get the MaxSize reserved for
145 GetPtrTypeSize (TmpTokenNumber
, &GetSize
);
147 CopyMem (VaraiableDefaultBuffer
, Data
+ VariableHead
->Offset
, GetSize
);
151 // If the operation is successful, we copy the data
152 // to the default value buffer in the PCD Database.
153 // So that we can free the Data allocated in GetHiiVariable.
156 // If the operation is not successful,
157 // Return 1) either the default value specified by Platform Integrator
158 // 2) Or the value Set by a PCD set operation.
160 RetPtr
= (VOID
*) VaraiableDefaultBuffer
;
163 case PCD_TYPE_STRING
:
164 StringTableIdx
= *(UINT16
*)((UINT8
*) PcdDb
+ Offset
);
165 RetPtr
= (VOID
*) (StringTable
+ StringTableIdx
);
169 RetPtr
= (VOID
*) ((UINT8
*) PcdDb
+ Offset
);
178 EfiReleaseLock (&mPcdDatabaseLock
);
185 Register the callback function for a PCD entry.
187 This routine will register a callback function to a PCD entry by given token number
188 and token space guid.
190 @param TokenNumber PCD token's number, it is autogened by build tools.
191 @param Guid PCD token space's guid,
192 if not NULL, this PCD is dynamicEx type PCD.
193 @param CallBackFunction Callback function pointer
195 @return EFI_SUCCESS Always success for registering callback function.
199 DxeRegisterCallBackWorker (
200 IN UINTN TokenNumber
,
201 IN CONST EFI_GUID
*Guid
, OPTIONAL
202 IN PCD_PROTOCOL_CALLBACK CallBackFunction
205 CALLBACK_FN_ENTRY
*FnTableEntry
;
206 LIST_ENTRY
*ListHead
;
207 LIST_ENTRY
*ListNode
;
210 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
214 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
215 // We have to decrement TokenNumber by 1 to make it usable
216 // as the array index.
220 ListHead
= &mCallbackFnTable
[TokenNumber
];
221 ListNode
= GetFirstNode (ListHead
);
223 while (ListNode
!= ListHead
) {
224 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
226 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
228 // We only allow a Callback function to be register once
229 // for a TokenNumber. So just return EFI_SUCCESS
233 ListNode
= GetNextNode (ListHead
, ListNode
);
236 FnTableEntry
= AllocatePool (sizeof(CALLBACK_FN_ENTRY
));
237 ASSERT (FnTableEntry
!= NULL
);
239 FnTableEntry
->CallbackFn
= CallBackFunction
;
240 InsertTailList (ListHead
, &FnTableEntry
->Node
);
246 UnRegister the callback function for a PCD entry.
248 This routine will unregister a callback function to a PCD entry by given token number
249 and token space guid.
251 @param TokenNumber PCD token's number, it is autogened by build tools.
252 @param Guid PCD token space's guid.
253 if not NULL, this PCD is dynamicEx type PCD.
254 @param CallBackFunction Callback function pointer
256 @retval EFI_SUCCESS Callback function is success to be unregister.
257 @retval EFI_INVALID_PARAMETER Can not find the PCD entry by given token number.
260 DxeUnRegisterCallBackWorker (
261 IN UINTN TokenNumber
,
262 IN CONST EFI_GUID
*Guid
, OPTIONAL
263 IN PCD_PROTOCOL_CALLBACK CallBackFunction
266 CALLBACK_FN_ENTRY
*FnTableEntry
;
267 LIST_ENTRY
*ListHead
;
268 LIST_ENTRY
*ListNode
;
271 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
275 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
276 // We have to decrement TokenNumber by 1 to make it usable
277 // as the array index.
281 ListHead
= &mCallbackFnTable
[TokenNumber
];
282 ListNode
= GetFirstNode (ListHead
);
284 while (ListNode
!= ListHead
) {
285 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
287 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
289 // We only allow a Callback function to be register once
290 // for a TokenNumber. So we can safely remove the Node from
291 // the Link List and return EFI_SUCCESS.
293 RemoveEntryList (ListNode
);
294 FreePool (FnTableEntry
);
298 ListNode
= GetNextNode (ListHead
, ListNode
);
301 return EFI_INVALID_PARAMETER
;
305 Get next token number in given token space.
307 This routine is used for dynamicEx type PCD. It will firstly scan token space
308 table to get token space according to given token space guid. Then scan given
309 token number in found token space, if found, then return next token number in
312 @param Guid Token space guid. Next token number will be scaned in
314 @param TokenNumber Token number.
315 If PCD_INVALID_TOKEN_NUMBER, return first token number in
317 If not PCD_INVALID_TOKEN_NUMBER, return next token number
318 in token space table.
319 @param GuidTable Token space guid table. It will be used for scan token space
320 by given token space guid.
321 @param SizeOfGuidTable The size of guid table.
322 @param ExMapTable DynamicEx token number mapping table.
323 @param SizeOfExMapTable The size of dynamicEx token number mapping table.
325 @retval EFI_NOT_FOUND Can not given token space or token number.
326 @retval EFI_SUCCESS Success to get next token number.
330 ExGetNextTokeNumber (
331 IN CONST EFI_GUID
*Guid
,
332 IN OUT UINTN
*TokenNumber
,
333 IN EFI_GUID
*GuidTable
,
334 IN UINTN SizeOfGuidTable
,
335 IN DYNAMICEX_MAPPING
*ExMapTable
,
336 IN UINTN SizeOfExMapTable
345 // Scan token space guid
347 MatchGuid
= ScanGuid (GuidTable
, SizeOfGuidTable
, Guid
);
348 if (MatchGuid
== NULL
) {
349 return EFI_NOT_FOUND
;
353 // Find the token space table in dynamicEx mapping table.
356 GuidTableIdx
= MatchGuid
- GuidTable
;
357 for (Index
= 0; Index
< SizeOfExMapTable
; Index
++) {
358 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
366 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
367 // token number in found token space.
369 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
370 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
374 for ( ; Index
< SizeOfExMapTable
; Index
++) {
375 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
377 if (Index
== SizeOfExMapTable
) {
379 // Exceed the length of ExMap Table
381 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
383 } else if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
385 // Found the next match
387 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
391 // Guid has been changed. It is the next Token Space Guid.
392 // We should flag no more TokenNumber.
394 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
401 return EFI_NOT_FOUND
;
406 Initialize the PCD database in DXE phase.
408 PCD database in DXE phase also contains PCD database in PEI phase which is copied
413 BuildPcdDxeDataBase (
417 PEI_PCD_DATABASE
*PeiDatabase
;
418 EFI_HOB_GUID_TYPE
*GuidHob
;
421 mPcdDatabase
= AllocateZeroPool (sizeof(PCD_DATABASE
));
422 ASSERT (mPcdDatabase
!= NULL
);
424 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
425 if (GuidHob
!= NULL
) {
428 // We will copy over the PEI phase's PCD Database.
430 // If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
431 // should not be included at all. So the GuidHob could
432 // be NULL. If it is NULL, we just copy over the DXE Default
433 // Value to PCD Database.
436 PeiDatabase
= (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
438 // Copy PCD Entries refereneced in PEI phase to PCD DATABASE
440 CopyMem (&mPcdDatabase
->PeiDb
, PeiDatabase
, sizeof (PEI_PCD_DATABASE
));
444 // Copy PCD Entries with default value to PCD DATABASE
446 CopyMem (&mPcdDatabase
->DxeDb
.Init
, &gDXEPcdDbInit
, sizeof(DXE_PCD_DATABASE_INIT
));
450 // Initialized the Callback Function Table
453 mCallbackFnTable
= AllocateZeroPool (PCD_TOTAL_TOKEN_NUMBER
* sizeof (LIST_ENTRY
));
454 ASSERT(mCallbackFnTable
!= NULL
);
456 // EBC compiler is very choosy. It may report warning about comparison
457 // between UINTN and 0 . So we add 1 in each size of the
459 for (Index
= 0; Index
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1; Index
++) {
460 InitializeListHead (&mCallbackFnTable
[Index
]);
465 Get Variable which contains HII type PCD entry.
467 @param VariableGuid Variable's guid
468 @param VariableName Variable's unicode name string
469 @param VariableData Variable's data pointer,
470 @param VariableSize Variable's size.
472 @return the status of gRT->GetVariable
476 IN EFI_GUID
*VariableGuid
,
477 IN UINT16
*VariableName
,
478 OUT UINT8
**VariableData
,
479 OUT UINTN
*VariableSize
490 // Firstly get the real size of HII variable
492 Status
= gRT
->GetVariable (
493 (UINT16
*)VariableName
,
501 // Allocate buffer to hold whole variable data according to variable size.
503 if (Status
== EFI_BUFFER_TOO_SMALL
) {
504 Buffer
= (UINT8
*) AllocatePool (Size
);
506 ASSERT (Buffer
!= NULL
);
508 Status
= gRT
->GetVariable (
516 ASSERT (Status
== EFI_SUCCESS
);
517 *VariableData
= Buffer
;
518 *VariableSize
= Size
;
525 Find the local token number according to system SKU ID.
527 @param LocalTokenNumber PCD token number
528 @param Size The size of PCD entry.
529 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
530 If False, the PCD entry is initialized in DXE phase.
532 @return Token number according to system SKU ID.
536 GetSkuEnabledTokenNumber (
537 UINT32 LocalTokenNumber
,
546 SKU_ID
*PhaseSkuIdTable
;
549 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
551 PcdDb
= IsPeiDb
? (UINT8
*) &mPcdDatabase
->PeiDb
: (UINT8
*) &mPcdDatabase
->DxeDb
;
553 SkuHead
= (SKU_HEAD
*) (PcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
554 Value
= (UINT8
*) (PcdDb
+ SkuHead
->SkuDataStartOffset
);
556 PhaseSkuIdTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.SkuIdTable
:
557 mPcdDatabase
->DxeDb
.Init
.SkuIdTable
;
559 SkuIdTable
= &PhaseSkuIdTable
[SkuHead
->SkuIdTableOffset
];
562 // Find the current system's SKU ID entry in SKU ID table.
564 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
565 if (mPcdDatabase
->PeiDb
.Init
.SystemSkuId
== SkuIdTable
[Index
+ 1]) {
569 ASSERT (Index
< SkuIdTable
[0]);
571 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
573 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
574 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_VPD
);
577 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
578 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
);
580 case PCD_TYPE_STRING
:
581 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
582 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_STRING
);
585 Value
+= Size
* Index
;
586 return (UINT32
) (Value
- PcdDb
);
599 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
600 has registered callback function.
602 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
604 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
606 @param TokenNumber PCD token number generated by build tools.
607 @param Data Value want to be set for this PCD entry
608 @param Size The size of value
612 InvokeCallbackOnSet (
613 UINT32 ExTokenNumber
,
614 CONST EFI_GUID
*Guid
, OPTIONAL
620 CALLBACK_FN_ENTRY
*FnTableEntry
;
621 LIST_ENTRY
*ListHead
;
622 LIST_ENTRY
*ListNode
;
625 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
626 // We have to decrement TokenNumber by 1 to make it usable
627 // as the array index.
631 ListHead
= &mCallbackFnTable
[TokenNumber
];
632 ListNode
= GetFirstNode (ListHead
);
634 while (ListNode
!= ListHead
) {
635 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
637 FnTableEntry
->CallbackFn(Guid
,
638 (Guid
== NULL
) ? TokenNumber
: ExTokenNumber
,
642 ListNode
= GetNextNode (ListHead
, ListNode
);
650 Wrapper function for setting non-pointer type value for a PCD entry.
652 @param TokenNumber Pcd token number autogenerated by build tools.
653 @param Data Value want to be set for PCD entry
654 @param Size Size of value.
656 @return status of SetWorker.
661 IN UINTN TokenNumber
,
666 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
671 Set value for an PCD entry
673 @param TokenNumber Pcd token number autogenerated by build tools.
674 @param Data Value want to be set for PCD entry
675 @param Size Size of value.
676 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
677 If False, the type of PCD entry's value is not Pointer.
679 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
680 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
681 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
682 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
683 range of UINT8, UINT16, UINT32, UINT64
684 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
688 IN UINTN TokenNumber
,
694 UINT32
*LocalTokenNumberTable
;
696 UINT32 LocalTokenNumber
;
701 UINTN VariableOffset
;
703 VARIABLE_HEAD
*VariableHead
;
708 UINTN TmpTokenNumber
;
711 // Aquire lock to prevent reentrance from TPL_CALLBACK level
713 EfiAcquireLock (&mPcdDatabaseLock
);
716 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
717 // We have to decrement TokenNumber by 1 to make it usable
718 // as the array index.
722 TmpTokenNumber
= TokenNumber
;
725 // EBC compiler is very choosy. It may report warning about comparison
726 // between UINTN and 0 . So we add 1 in each size of the
729 ASSERT (TokenNumber
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1);
731 if ((!PtrType
) && (*Size
!= DxePcdGetSize (TokenNumber
+ 1))) {
732 return EFI_INVALID_PARAMETER
;
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 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1) ? TRUE
: FALSE
);
742 LocalTokenNumberTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
:
743 mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
746 // EBC compiler is very choosy. It may report warning about comparison
747 // between UINTN and 0 . So we add 1 in each size of the
750 if ((TokenNumber
+ 1 < PEI_NEX_TOKEN_NUMBER
+ 1) ||
751 (TokenNumber
+ 1 >= PEI_LOCAL_TOKEN_NUMBER
+ 1 || TokenNumber
+ 1 < (PEI_LOCAL_TOKEN_NUMBER
+ DXE_NEX_TOKEN_NUMBER
+ 1))) {
752 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
755 TokenNumber
= IsPeiDb
? TokenNumber
756 : TokenNumber
- PEI_LOCAL_TOKEN_NUMBER
;
758 LocalTokenNumber
= LocalTokenNumberTable
[TokenNumber
];
760 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
762 GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
766 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
, IsPeiDb
);
769 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
771 PcdDb
= IsPeiDb
? ((UINT8
*) &mPcdDatabase
->PeiDb
) : ((UINT8
*) &mPcdDatabase
->DxeDb
);
774 StringTable
= (UINT8
*) (&mPcdDatabase
->PeiDb
.Init
.StringTable
[0]);
776 StringTable
= (UINT8
*) (&mPcdDatabase
->DxeDb
.Init
.StringTable
[0]);
780 InternalData
= PcdDb
+ Offset
;
782 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
785 Status
= EFI_INVALID_PARAMETER
;
788 case PCD_TYPE_STRING
:
789 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
790 CopyMem (StringTable
+ *((UINT16
*)InternalData
), Data
, *Size
);
791 Status
= EFI_SUCCESS
;
793 Status
= EFI_INVALID_PARAMETER
;
799 if (!SetPtrTypeSize (TmpTokenNumber
, Size
)) {
800 Status
= EFI_INVALID_PARAMETER
;
806 GuidTable
= (EFI_GUID
*) (&mPcdDatabase
->PeiDb
.Init
.GuidTable
[0]);
808 GuidTable
= (EFI_GUID
*) (&mPcdDatabase
->DxeDb
.Init
.GuidTable
[0]);
811 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
813 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
814 Name
= (UINT16
*) (StringTable
+ VariableHead
->StringIndex
);
815 VariableOffset
= VariableHead
->Offset
;
817 Status
= SetHiiVariable (Guid
, Name
, Data
, *Size
, VariableOffset
);
819 if (EFI_NOT_FOUND
== Status
) {
820 CopyMem (PcdDb
+ VariableHead
->DefaultValueOffset
, Data
, *Size
);
821 Status
= EFI_SUCCESS
;
827 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
828 CopyMem (InternalData
, Data
, *Size
);
829 Status
= EFI_SUCCESS
;
831 Status
= EFI_INVALID_PARAMETER
;
836 Status
= EFI_SUCCESS
;
839 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
843 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
847 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
851 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
856 Status
= EFI_NOT_FOUND
;
863 Status
= EFI_NOT_FOUND
;
867 EfiReleaseLock (&mPcdDatabaseLock
);
873 Wrapper function for get PCD value for dynamic-ex PCD.
875 @param Guid Token space guid for dynamic-ex PCD.
876 @param ExTokenNumber Token number for dynamic-ex PCD.
877 @param GetSize The size of dynamic-ex PCD value.
879 @return PCD entry in PCD database.
884 IN CONST EFI_GUID
*Guid
,
885 IN UINTN ExTokenNumber
,
889 return GetWorker(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
), GetSize
);
893 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
895 @param ExTokenNumber Token number for dynamic-ex PCD.
896 @param Guid Token space guid for dynamic-ex PCD.
897 @param Data Value want to be set.
898 @param SetSize The size of value.
900 @return status of ExSetWorker().
905 IN UINTN ExTokenNumber
,
906 IN CONST EFI_GUID
*Guid
,
911 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &SetSize
, FALSE
);
915 Set value for a dynamic PCD entry.
917 This routine find the local token number according to dynamic-ex PCD's token
918 space guid and token number firstly, and invoke callback function if this PCD
919 entry registered callback function. Finally, invoken general SetWorker to set
922 @param ExTokenNumber Dynamic-ex PCD token number.
923 @param Guid Token space guid for dynamic-ex PCD.
924 @param Data PCD value want to be set
925 @param SetSize Size of value.
926 @param PtrType If TRUE, this PCD entry is pointer type.
927 If FALSE, this PCD entry is not pointer type.
929 @return status of SetWorker().
934 IN UINTN ExTokenNumber
,
935 IN CONST EFI_GUID
*Guid
,
937 IN OUT UINTN
*SetSize
,
943 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
);
945 InvokeCallbackOnSet ((UINT32
) ExTokenNumber
, Guid
, TokenNumber
, Data
, *SetSize
);
947 return SetWorker (TokenNumber
, Data
, SetSize
, PtrType
);
952 Set value for HII-type PCD.
954 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
955 HII-type PCD is to visit this variable.
957 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
958 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
959 @param Data Value want to be set.
960 @param DataSize Size of value
961 @param Offset Value offset of HII-type PCD in variable.
963 @return status of GetVariable()/SetVariable().
968 IN EFI_GUID
*VariableGuid
,
969 IN UINT16
*VariableName
,
985 // Try to get original variable size information.
987 Status
= gRT
->GetVariable (
988 (UINT16
*)VariableName
,
995 if (Status
== EFI_BUFFER_TOO_SMALL
) {
997 // Patch new PCD's value to offset in given HII variable.
999 if (Size
>= (DataSize
+ Offset
)) {
1002 SetSize
= DataSize
+ Offset
;
1004 Buffer
= AllocatePool (SetSize
);
1005 ASSERT (Buffer
!= NULL
);
1007 Status
= gRT
->GetVariable (
1015 ASSERT_EFI_ERROR (Status
);
1017 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1019 Status
= gRT
->SetVariable (
1029 } else if (Status
== EFI_NOT_FOUND
) {
1031 // If variable does not exist, a new variable need to be created.
1034 Size
= Offset
+ DataSize
;
1036 Buffer
= AllocateZeroPool (Size
);
1037 ASSERT (Buffer
!= NULL
);
1039 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1041 Status
= gRT
->SetVariable (
1044 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1054 // If we drop to here, the value is failed to be written in to variable area
1055 // So, we will save the data in the PCD Database's volatile area.
1061 Get local token number according to dynamic-ex PCD's {token space guid:token number}
1063 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1064 in DEC file. PCD database maintain a mapping table that translate pair of {token
1065 space guid: token number} to local token number.
1067 @param Guid Token space guid for dynamic-ex PCD entry.
1068 @param ExTokenNumber Dynamic-ex PCD token number.
1070 @return local token number for dynamic-ex PCD.
1074 GetExPcdTokenNumber (
1075 IN CONST EFI_GUID
*Guid
,
1076 IN UINT32 ExTokenNumber
1080 DYNAMICEX_MAPPING
*ExMap
;
1081 EFI_GUID
*GuidTable
;
1082 EFI_GUID
*MatchGuid
;
1085 if (!PEI_DATABASE_EMPTY
) {
1086 ExMap
= mPcdDatabase
->PeiDb
.Init
.ExMapTable
;
1087 GuidTable
= mPcdDatabase
->PeiDb
.Init
.GuidTable
;
1089 MatchGuid
= ScanGuid (GuidTable
, sizeof(mPcdDatabase
->PeiDb
.Init
.GuidTable
), Guid
);
1091 if (MatchGuid
!= NULL
) {
1093 MatchGuidIdx
= MatchGuid
- GuidTable
;
1095 for (Index
= 0; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
1096 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1097 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1098 return ExMap
[Index
].LocalTokenNumber
;
1104 ExMap
= mPcdDatabase
->DxeDb
.Init
.ExMapTable
;
1105 GuidTable
= mPcdDatabase
->DxeDb
.Init
.GuidTable
;
1107 MatchGuid
= ScanGuid (GuidTable
, sizeof(mPcdDatabase
->DxeDb
.Init
.GuidTable
), Guid
);
1109 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1110 // error in the BUILD system.
1112 ASSERT (MatchGuid
!= NULL
);
1114 MatchGuidIdx
= MatchGuid
- GuidTable
;
1116 for (Index
= 0; Index
< DXE_EXMAPPING_TABLE_SIZE
; Index
++) {
1117 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1118 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1119 return ExMap
[Index
].LocalTokenNumber
;
1129 Get SKU ID table from PCD database.
1131 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1132 @param IsPeiPcd If TRUE,
1134 @return Pointer to SKU ID array table
1139 IN UINTN LocalTokenNumberTableIdx
,
1144 UINTN LocalTokenNumber
;
1148 LocalTokenNumber
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1149 Database
= (UINT8
*) &mPcdDatabase
->PeiDb
;
1151 LocalTokenNumber
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
- PEI_LOCAL_TOKEN_NUMBER
];
1152 Database
= (UINT8
*) &mPcdDatabase
->DxeDb
;
1155 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1157 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1159 return (SKU_ID
*) (Database
+ SkuHead
->SkuIdTableOffset
);
1164 Wrapper function of getting index of PCD entry in size table.
1166 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1167 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1168 If FALSE, the pcd entry is initialized in DXE phase.
1170 @return index of PCD entry in size table.
1174 IN UINTN LocalTokenNumberTableIdx
,
1178 UINT32
*LocalTokenNumberTable
;
1179 UINTN LocalTokenNumber
;
1185 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1187 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1192 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
1193 LocalTokenNumber
= LocalTokenNumberTable
[Index
];
1195 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1197 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1200 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1202 // We have only one entry for VPD enabled PCD entry:
1204 // We consider current size is equal to MAX size.
1208 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1210 // We have only two entry for Non-Sku enabled PCD entry:
1217 // We have these entry for SKU enabled PCD entry
1219 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1221 SkuIdTable
= GetSkuIdArray (Index
, IsPeiDb
);
1222 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1229 return SizeTableIdx
;
1233 Get size of POINTER type PCD value.
1235 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1236 @param MaxSize Maxmium size of POINTER type PCD value.
1238 @return size of POINTER type PCD value.
1243 IN UINTN LocalTokenNumberTableIdx
,
1248 UINTN LocalTokenNumber
;
1250 SIZE_INFO
*SizeTable
;
1253 UINT32
*LocalTokenNumberTable
;
1255 // EBC compiler is very choosy. It may report warning about comparison
1256 // between UINTN and 0 . So we add 1 in each size of the
1258 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
1262 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1263 SizeTable
= mPcdDatabase
->PeiDb
.Init
.SizeTable
;
1265 LocalTokenNumberTableIdx
-= PEI_LOCAL_TOKEN_NUMBER
;
1266 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1267 SizeTable
= mPcdDatabase
->DxeDb
.Init
.SizeTable
;
1270 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1272 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1274 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1276 *MaxSize
= SizeTable
[SizeTableIdx
];
1278 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1281 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1283 // We have only one entry for VPD enabled PCD entry:
1285 // We consider current size is equal to MAX size.
1289 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1291 // We have only two entry for Non-Sku enabled PCD entry:
1295 return SizeTable
[SizeTableIdx
+ 1];
1298 // We have these entry for SKU enabled PCD entry
1300 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1302 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1303 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1304 if (SkuIdTable
[1 + Index
] == mPcdDatabase
->PeiDb
.Init
.SystemSkuId
) {
1305 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1308 return SizeTable
[SizeTableIdx
+ 1];
1314 Set size of POINTER type PCD value. The size should not exceed the maximum size
1317 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1318 @param CurrentSize Size of POINTER type PCD value.
1320 @retval TRUE Success to set size of PCD value.
1321 @retval FALSE Fail to set size of PCD value.
1325 IN UINTN LocalTokenNumberTableIdx
,
1326 IN OUT UINTN
*CurrentSize
1330 UINTN LocalTokenNumber
;
1332 SIZE_INFO
*SizeTable
;
1336 UINT32
*LocalTokenNumberTable
;
1339 // EBC compiler is very choosy. It may report warning about comparison
1340 // between UINTN and 0 . So we add 1 in each size of the
1343 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
1346 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1347 SizeTable
= mPcdDatabase
->PeiDb
.Init
.SizeTable
;
1349 LocalTokenNumberTableIdx
-= PEI_LOCAL_TOKEN_NUMBER
;
1350 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1351 SizeTable
= mPcdDatabase
->DxeDb
.Init
.SizeTable
;
1354 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1356 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1358 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1360 MaxSize
= SizeTable
[SizeTableIdx
];
1362 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1365 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1367 // We shouldn't come here as we don't support SET for VPD
1372 if ((*CurrentSize
> MaxSize
) ||
1373 (*CurrentSize
== MAX_ADDRESS
)) {
1374 *CurrentSize
= MaxSize
;
1378 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1380 // We have only two entry for Non-Sku enabled PCD entry:
1384 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1388 // We have these entry for SKU enabled PCD entry
1390 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1392 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1393 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1394 if (SkuIdTable
[1 + Index
] == mPcdDatabase
->PeiDb
.Init
.SystemSkuId
) {
1395 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1399 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;