2 Help functions used by PCD DXE driver.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
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
);
125 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
128 GuidTable
= (EFI_GUID
*) (&mPcdDatabase
->PeiDb
.Init
.GuidTable
[0]);
130 GuidTable
= (EFI_GUID
*) (&mPcdDatabase
->DxeDb
.Init
.GuidTable
[0]);
133 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
134 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
135 Name
= (UINT16
*)(StringTable
+ VariableHead
->StringIndex
);
137 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
139 // If a HII type PCD's datum type is VOID*, the DefaultValueOffset is the index of
140 // string array in string table.
142 StringTableIdx
= *(UINT16
*)((UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
);
143 VaraiableDefaultBuffer
= (VOID
*) (StringTable
+ StringTableIdx
);
144 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
145 if (Status
== EFI_SUCCESS
) {
148 // It is a pointer type. So get the MaxSize reserved for
151 GetPtrTypeSize (TmpTokenNumber
, &GetSize
);
153 CopyMem (VaraiableDefaultBuffer
, Data
+ VariableHead
->Offset
, GetSize
);
156 RetPtr
= (VOID
*) VaraiableDefaultBuffer
;
158 VaraiableDefaultBuffer
= (UINT8
*) PcdDb
+ VariableHead
->DefaultValueOffset
;
160 Status
= GetHiiVariable (Guid
, Name
, &Data
, &DataSize
);
161 if (Status
== EFI_SUCCESS
) {
164 // It is a pointer type. So get the MaxSize reserved for
167 GetPtrTypeSize (TmpTokenNumber
, &GetSize
);
169 CopyMem (VaraiableDefaultBuffer
, Data
+ VariableHead
->Offset
, GetSize
);
173 // If the operation is successful, we copy the data
174 // to the default value buffer in the PCD Database.
175 // So that we can free the Data allocated in GetHiiVariable.
178 // If the operation is not successful,
179 // Return 1) either the default value specified by Platform Integrator
180 // 2) Or the value Set by a PCD set operation.
182 RetPtr
= (VOID
*) VaraiableDefaultBuffer
;
186 case PCD_TYPE_STRING
:
187 StringTableIdx
= *(UINT16
*)((UINT8
*) PcdDb
+ Offset
);
188 RetPtr
= (VOID
*) (StringTable
+ StringTableIdx
);
192 RetPtr
= (VOID
*) ((UINT8
*) PcdDb
+ Offset
);
201 EfiReleaseLock (&mPcdDatabaseLock
);
208 Register the callback function for a PCD entry.
210 This routine will register a callback function to a PCD entry by given token number
211 and token space guid.
213 @param TokenNumber PCD token's number, it is autogened by build tools.
214 @param Guid PCD token space's guid,
215 if not NULL, this PCD is dynamicEx type PCD.
216 @param CallBackFunction Callback function pointer
218 @return EFI_SUCCESS Always success for registering callback function.
222 DxeRegisterCallBackWorker (
223 IN UINTN TokenNumber
,
224 IN CONST EFI_GUID
*Guid
, OPTIONAL
225 IN PCD_PROTOCOL_CALLBACK CallBackFunction
228 CALLBACK_FN_ENTRY
*FnTableEntry
;
229 LIST_ENTRY
*ListHead
;
230 LIST_ENTRY
*ListNode
;
233 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
237 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
238 // We have to decrement TokenNumber by 1 to make it usable
239 // as the array index of mCallbackFnTable[].
241 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
242 ListNode
= GetFirstNode (ListHead
);
244 while (ListNode
!= ListHead
) {
245 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
247 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
249 // We only allow a Callback function to be register once
250 // for a TokenNumber. So just return EFI_SUCCESS
254 ListNode
= GetNextNode (ListHead
, ListNode
);
257 FnTableEntry
= AllocatePool (sizeof(CALLBACK_FN_ENTRY
));
258 ASSERT (FnTableEntry
!= NULL
);
260 FnTableEntry
->CallbackFn
= CallBackFunction
;
261 InsertTailList (ListHead
, &FnTableEntry
->Node
);
267 UnRegister the callback function for a PCD entry.
269 This routine will unregister a callback function to a PCD entry by given token number
270 and token space guid.
272 @param TokenNumber PCD token's number, it is autogened by build tools.
273 @param Guid PCD token space's guid.
274 if not NULL, this PCD is dynamicEx type PCD.
275 @param CallBackFunction Callback function pointer
277 @retval EFI_SUCCESS Callback function is success to be unregister.
278 @retval EFI_INVALID_PARAMETER Can not find the PCD entry by given token number.
281 DxeUnRegisterCallBackWorker (
282 IN UINTN TokenNumber
,
283 IN CONST EFI_GUID
*Guid
, OPTIONAL
284 IN PCD_PROTOCOL_CALLBACK CallBackFunction
287 CALLBACK_FN_ENTRY
*FnTableEntry
;
288 LIST_ENTRY
*ListHead
;
289 LIST_ENTRY
*ListNode
;
292 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) TokenNumber
);
296 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
297 // We have to decrement TokenNumber by 1 to make it usable
298 // as the array index of mCallbackFnTable[].
300 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
301 ListNode
= GetFirstNode (ListHead
);
303 while (ListNode
!= ListHead
) {
304 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE(ListNode
, CALLBACK_FN_ENTRY
, Node
);
306 if (FnTableEntry
->CallbackFn
== CallBackFunction
) {
308 // We only allow a Callback function to be register once
309 // for a TokenNumber. So we can safely remove the Node from
310 // the Link List and return EFI_SUCCESS.
312 RemoveEntryList (ListNode
);
313 FreePool (FnTableEntry
);
317 ListNode
= GetNextNode (ListHead
, ListNode
);
320 return EFI_INVALID_PARAMETER
;
324 Get next token number in given token space.
326 This routine is used for dynamicEx type PCD. It will firstly scan token space
327 table to get token space according to given token space guid. Then scan given
328 token number in found token space, if found, then return next token number in
331 @param Guid Token space guid. Next token number will be scaned in
333 @param TokenNumber Token number.
334 If PCD_INVALID_TOKEN_NUMBER, return first token number in
336 If not PCD_INVALID_TOKEN_NUMBER, return next token number
337 in token space table.
338 @param GuidTable Token space guid table. It will be used for scan token space
339 by given token space guid.
340 @param SizeOfGuidTable The size of guid table.
341 @param ExMapTable DynamicEx token number mapping table.
342 @param SizeOfExMapTable The size of dynamicEx token number mapping table.
344 @retval EFI_NOT_FOUND Can not given token space or token number.
345 @retval EFI_SUCCESS Success to get next token number.
349 ExGetNextTokeNumber (
350 IN CONST EFI_GUID
*Guid
,
351 IN OUT UINTN
*TokenNumber
,
352 IN EFI_GUID
*GuidTable
,
353 IN UINTN SizeOfGuidTable
,
354 IN DYNAMICEX_MAPPING
*ExMapTable
,
355 IN UINTN SizeOfExMapTable
364 // Scan token space guid
366 MatchGuid
= ScanGuid (GuidTable
, SizeOfGuidTable
, Guid
);
367 if (MatchGuid
== NULL
) {
368 return EFI_NOT_FOUND
;
372 // Find the token space table in dynamicEx mapping table.
375 GuidTableIdx
= MatchGuid
- GuidTable
;
376 for (Index
= 0; Index
< SizeOfExMapTable
; Index
++) {
377 if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
385 // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first
386 // token number in found token space.
388 if (*TokenNumber
== PCD_INVALID_TOKEN_NUMBER
) {
389 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
393 for ( ; Index
< SizeOfExMapTable
; Index
++) {
394 if (ExMapTable
[Index
].ExTokenNumber
== *TokenNumber
) {
396 if (Index
== SizeOfExMapTable
) {
398 // Exceed the length of ExMap Table
400 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
402 } else if (ExMapTable
[Index
].ExGuidIndex
== GuidTableIdx
) {
404 // Found the next match
406 *TokenNumber
= ExMapTable
[Index
].ExTokenNumber
;
410 // Guid has been changed. It is the next Token Space Guid.
411 // We should flag no more TokenNumber.
413 *TokenNumber
= PCD_INVALID_TOKEN_NUMBER
;
420 return EFI_NOT_FOUND
;
425 Initialize the PCD database in DXE phase.
427 PCD database in DXE phase also contains PCD database in PEI phase which is copied
432 BuildPcdDxeDataBase (
436 PEI_PCD_DATABASE
*PeiDatabase
;
437 EFI_HOB_GUID_TYPE
*GuidHob
;
440 mPcdDatabase
= AllocateZeroPool (sizeof(PCD_DATABASE
));
441 ASSERT (mPcdDatabase
!= NULL
);
443 GuidHob
= GetFirstGuidHob (&gPcdDataBaseHobGuid
);
444 if (GuidHob
!= NULL
) {
447 // We will copy over the PEI phase's PCD Database.
449 // If no PEIMs use dynamic Pcd Entry, the Pcd Service PEIM
450 // should not be included at all. So the GuidHob could
451 // be NULL. If it is NULL, we just copy over the DXE Default
452 // Value to PCD Database.
455 PeiDatabase
= (PEI_PCD_DATABASE
*) GET_GUID_HOB_DATA (GuidHob
);
457 // Copy PCD Entries refereneced in PEI phase to PCD DATABASE
459 CopyMem (&mPcdDatabase
->PeiDb
, PeiDatabase
, sizeof (PEI_PCD_DATABASE
));
463 // Copy PCD Entries with default value to PCD DATABASE
465 CopyMem (&mPcdDatabase
->DxeDb
.Init
, &gDXEPcdDbInit
, sizeof(DXE_PCD_DATABASE_INIT
));
469 // Initialized the Callback Function Table
472 mCallbackFnTable
= AllocateZeroPool (PCD_TOTAL_TOKEN_NUMBER
* sizeof (LIST_ENTRY
));
473 ASSERT(mCallbackFnTable
!= NULL
);
475 // EBC compiler is very choosy. It may report warning about comparison
476 // between UINTN and 0 . So we add 1 in each size of the
478 for (Index
= 0; Index
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1; Index
++) {
479 InitializeListHead (&mCallbackFnTable
[Index
]);
484 Get Variable which contains HII type PCD entry.
486 @param VariableGuid Variable's guid
487 @param VariableName Variable's unicode name string
488 @param VariableData Variable's data pointer,
489 @param VariableSize Variable's size.
491 @return the status of gRT->GetVariable
495 IN EFI_GUID
*VariableGuid
,
496 IN UINT16
*VariableName
,
497 OUT UINT8
**VariableData
,
498 OUT UINTN
*VariableSize
509 // Firstly get the real size of HII variable
511 Status
= gRT
->GetVariable (
512 (UINT16
*)VariableName
,
520 // Allocate buffer to hold whole variable data according to variable size.
522 if (Status
== EFI_BUFFER_TOO_SMALL
) {
523 Buffer
= (UINT8
*) AllocatePool (Size
);
525 ASSERT (Buffer
!= NULL
);
527 Status
= gRT
->GetVariable (
535 ASSERT (Status
== EFI_SUCCESS
);
536 *VariableData
= Buffer
;
537 *VariableSize
= Size
;
544 Find the local token number according to system SKU ID.
546 @param LocalTokenNumber PCD token number
547 @param Size The size of PCD entry.
548 @param IsPeiDb If TRUE, the PCD entry is initialized in PEI phase.
549 If False, the PCD entry is initialized in DXE phase.
551 @return Token number according to system SKU ID.
555 GetSkuEnabledTokenNumber (
556 UINT32 LocalTokenNumber
,
565 SKU_ID
*PhaseSkuIdTable
;
568 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0);
570 PcdDb
= IsPeiDb
? (UINT8
*) &mPcdDatabase
->PeiDb
: (UINT8
*) &mPcdDatabase
->DxeDb
;
572 SkuHead
= (SKU_HEAD
*) (PcdDb
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
573 Value
= (UINT8
*) (PcdDb
+ SkuHead
->SkuDataStartOffset
);
575 PhaseSkuIdTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.SkuIdTable
:
576 mPcdDatabase
->DxeDb
.Init
.SkuIdTable
;
578 SkuIdTable
= &PhaseSkuIdTable
[SkuHead
->SkuIdTableOffset
];
581 // Find the current system's SKU ID entry in SKU ID table.
583 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
584 if (mPcdDatabase
->PeiDb
.Init
.SystemSkuId
== SkuIdTable
[Index
+ 1]) {
588 ASSERT (Index
< SkuIdTable
[0]);
590 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
592 Value
= (UINT8
*) &(((VPD_HEAD
*) Value
)[Index
]);
593 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_VPD
);
596 Value
= (UINT8
*) &(((VARIABLE_HEAD
*) Value
)[Index
]);
597 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_HII
);
599 case PCD_TYPE_STRING
:
600 Value
= (UINT8
*) &(((STRING_HEAD
*) Value
)[Index
]);
601 return (UINT32
) ((Value
- PcdDb
) | PCD_TYPE_STRING
);
604 Value
+= Size
* Index
;
605 return (UINT32
) (Value
- PcdDb
);
618 Invoke the callback function when dynamic PCD entry was set, if this PCD entry
619 has registered callback function.
621 @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
623 @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
625 @param TokenNumber PCD token number generated by build tools.
626 @param Data Value want to be set for this PCD entry
627 @param Size The size of value
631 InvokeCallbackOnSet (
632 UINT32 ExTokenNumber
,
633 CONST EFI_GUID
*Guid
, OPTIONAL
639 CALLBACK_FN_ENTRY
*FnTableEntry
;
640 LIST_ENTRY
*ListHead
;
641 LIST_ENTRY
*ListNode
;
644 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
645 // We have to decrement TokenNumber by 1 to make it usable
646 // as the array index of mCallbackFnTable[].
648 ListHead
= &mCallbackFnTable
[TokenNumber
- 1];
649 ListNode
= GetFirstNode (ListHead
);
651 while (ListNode
!= ListHead
) {
652 FnTableEntry
= CR_FNENTRY_FROM_LISTNODE (ListNode
, CALLBACK_FN_ENTRY
, Node
);
654 FnTableEntry
->CallbackFn(Guid
,
655 (Guid
== NULL
) ? TokenNumber
: ExTokenNumber
,
659 ListNode
= GetNextNode (ListHead
, ListNode
);
667 Wrapper function for setting non-pointer type value for a PCD entry.
669 @param TokenNumber Pcd token number autogenerated by build tools.
670 @param Data Value want to be set for PCD entry
671 @param Size Size of value.
673 @return status of SetWorker.
678 IN UINTN TokenNumber
,
683 return SetWorker (TokenNumber
, Data
, &Size
, FALSE
);
688 Set value for an PCD entry
690 @param TokenNumber Pcd token number autogenerated by build tools.
691 @param Data Value want to be set for PCD entry
692 @param Size Size of value.
693 @param PtrType If TRUE, the type of PCD entry's value is Pointer.
694 If False, the type of PCD entry's value is not Pointer.
696 @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
697 @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
698 @retval EFI_INVALID_PARAMETER If Size of non-Ptr type PCD does not match the size information in PCD database.
699 @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
700 range of UINT8, UINT16, UINT32, UINT64
701 @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
705 IN UINTN TokenNumber
,
711 UINT32
*LocalTokenNumberTable
;
713 UINT32 LocalTokenNumber
;
718 UINTN VariableOffset
;
720 VARIABLE_HEAD
*VariableHead
;
725 UINTN TmpTokenNumber
;
728 // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
729 // We have to decrement TokenNumber by 1 to make it usable
730 // as the array index.
734 TmpTokenNumber
= TokenNumber
;
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 ASSERT (TokenNumber
+ 1 < PCD_TOTAL_TOKEN_NUMBER
+ 1);
745 // Get MaxSize first, then check new size with max buffer size.
747 GetPtrTypeSize (TokenNumber
, &MaxSize
);
748 if (*Size
> MaxSize
) {
749 return EFI_INVALID_PARAMETER
;
752 if (*Size
!= DxePcdGetSize (TokenNumber
+ 1)) {
753 return EFI_INVALID_PARAMETER
;
758 // EBC compiler is very choosy. It may report warning about comparison
759 // between UINTN and 0 . So we add 1 in each size of the
762 if ((TokenNumber
+ 1 < PEI_NEX_TOKEN_NUMBER
+ 1) ||
763 (TokenNumber
+ 1 >= PEI_LOCAL_TOKEN_NUMBER
+ 1 || TokenNumber
+ 1 < (PEI_LOCAL_TOKEN_NUMBER
+ DXE_NEX_TOKEN_NUMBER
+ 1))) {
764 InvokeCallbackOnSet (0, NULL
, TokenNumber
+ 1, Data
, *Size
);
768 // Aquire lock to prevent reentrance from TPL_CALLBACK level
770 EfiAcquireLock (&mPcdDatabaseLock
);
773 // EBC compiler is very choosy. It may report warning about comparison
774 // between UINTN and 0 . So we add 1 in each size of the
777 IsPeiDb
= (BOOLEAN
) ((TokenNumber
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1) ? TRUE
: FALSE
);
779 LocalTokenNumberTable
= IsPeiDb
? mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
:
780 mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
782 TokenNumber
= IsPeiDb
? TokenNumber
783 : TokenNumber
- PEI_LOCAL_TOKEN_NUMBER
;
785 LocalTokenNumber
= LocalTokenNumberTable
[TokenNumber
];
787 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == PCD_TYPE_SKU_ENABLED
) {
789 GetPtrTypeSize (TmpTokenNumber
, &MaxSize
);
793 LocalTokenNumber
= GetSkuEnabledTokenNumber (LocalTokenNumber
& ~PCD_TYPE_SKU_ENABLED
, MaxSize
, IsPeiDb
);
796 Offset
= LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
;
798 PcdDb
= IsPeiDb
? ((UINT8
*) &mPcdDatabase
->PeiDb
) : ((UINT8
*) &mPcdDatabase
->DxeDb
);
801 StringTable
= (UINT8
*) (&mPcdDatabase
->PeiDb
.Init
.StringTable
[0]);
803 StringTable
= (UINT8
*) (&mPcdDatabase
->DxeDb
.Init
.StringTable
[0]);
807 InternalData
= PcdDb
+ Offset
;
809 switch (LocalTokenNumber
& PCD_TYPE_ALL_SET
) {
812 Status
= EFI_INVALID_PARAMETER
;
815 case PCD_TYPE_STRING
:
816 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
817 CopyMem (StringTable
+ *((UINT16
*)InternalData
), Data
, *Size
);
818 Status
= EFI_SUCCESS
;
820 Status
= EFI_INVALID_PARAMETER
;
824 case PCD_TYPE_HII
|PCD_TYPE_STRING
:
827 if (!SetPtrTypeSize (TmpTokenNumber
, Size
)) {
828 Status
= EFI_INVALID_PARAMETER
;
834 GuidTable
= (EFI_GUID
*) (&mPcdDatabase
->PeiDb
.Init
.GuidTable
[0]);
836 GuidTable
= (EFI_GUID
*) (&mPcdDatabase
->DxeDb
.Init
.GuidTable
[0]);
839 VariableHead
= (VARIABLE_HEAD
*) (PcdDb
+ Offset
);
841 Guid
= GuidTable
+ VariableHead
->GuidTableIndex
;
842 Name
= (UINT16
*) (StringTable
+ VariableHead
->StringIndex
);
843 VariableOffset
= VariableHead
->Offset
;
844 Status
= SetHiiVariable (Guid
, Name
, Data
, *Size
, VariableOffset
);
846 if (EFI_NOT_FOUND
== Status
) {
847 if ((LocalTokenNumber
& PCD_TYPE_ALL_SET
) == (PCD_TYPE_HII
|PCD_TYPE_STRING
)) {
849 StringTable
+ *(UINT16
*)(PcdDb
+ VariableHead
->DefaultValueOffset
),
854 CopyMem (PcdDb
+ VariableHead
->DefaultValueOffset
, Data
, *Size
);
856 Status
= EFI_SUCCESS
;
862 if (SetPtrTypeSize (TmpTokenNumber
, Size
)) {
863 CopyMem (InternalData
, Data
, *Size
);
864 Status
= EFI_SUCCESS
;
866 Status
= EFI_INVALID_PARAMETER
;
871 Status
= EFI_SUCCESS
;
874 *((UINT8
*) InternalData
) = *((UINT8
*) Data
);
878 *((UINT16
*) InternalData
) = *((UINT16
*) Data
);
882 *((UINT32
*) InternalData
) = *((UINT32
*) Data
);
886 *((UINT64
*) InternalData
) = *((UINT64
*) Data
);
891 Status
= EFI_NOT_FOUND
;
898 Status
= EFI_NOT_FOUND
;
902 EfiReleaseLock (&mPcdDatabaseLock
);
908 Wrapper function for get PCD value for dynamic-ex PCD.
910 @param Guid Token space guid for dynamic-ex PCD.
911 @param ExTokenNumber Token number for dynamic-ex PCD.
912 @param GetSize The size of dynamic-ex PCD value.
914 @return PCD entry in PCD database.
919 IN CONST EFI_GUID
*Guid
,
920 IN UINTN ExTokenNumber
,
924 return GetWorker(GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
), GetSize
);
928 Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
930 @param ExTokenNumber Token number for dynamic-ex PCD.
931 @param Guid Token space guid for dynamic-ex PCD.
932 @param Data Value want to be set.
933 @param SetSize The size of value.
935 @return status of ExSetWorker().
940 IN UINTN ExTokenNumber
,
941 IN CONST EFI_GUID
*Guid
,
946 return ExSetWorker (ExTokenNumber
, Guid
, Data
, &SetSize
, FALSE
);
950 Set value for a dynamic PCD entry.
952 This routine find the local token number according to dynamic-ex PCD's token
953 space guid and token number firstly, and invoke callback function if this PCD
954 entry registered callback function. Finally, invoken general SetWorker to set
957 @param ExTokenNumber Dynamic-ex PCD token number.
958 @param Guid Token space guid for dynamic-ex PCD.
959 @param Data PCD value want to be set
960 @param SetSize Size of value.
961 @param PtrType If TRUE, this PCD entry is pointer type.
962 If FALSE, this PCD entry is not pointer type.
964 @return status of SetWorker().
969 IN UINTN ExTokenNumber
,
970 IN CONST EFI_GUID
*Guid
,
972 IN OUT UINTN
*SetSize
,
978 TokenNumber
= GetExPcdTokenNumber (Guid
, (UINT32
) ExTokenNumber
);
980 InvokeCallbackOnSet ((UINT32
) ExTokenNumber
, Guid
, TokenNumber
, Data
, *SetSize
);
982 return SetWorker (TokenNumber
, Data
, SetSize
, PtrType
);
987 Set value for HII-type PCD.
989 A HII-type PCD's value is stored in a variable. Setting/Getting the value of
990 HII-type PCD is to visit this variable.
992 @param VariableGuid Guid of variable which stored value of a HII-type PCD.
993 @param VariableName Unicode name of variable which stored value of a HII-type PCD.
994 @param Data Value want to be set.
995 @param DataSize Size of value
996 @param Offset Value offset of HII-type PCD in variable.
998 @return status of GetVariable()/SetVariable().
1003 IN EFI_GUID
*VariableGuid
,
1004 IN UINT16
*VariableName
,
1005 IN CONST VOID
*Data
,
1020 // Try to get original variable size information.
1022 Status
= gRT
->GetVariable (
1023 (UINT16
*)VariableName
,
1030 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1032 // Patch new PCD's value to offset in given HII variable.
1034 if (Size
>= (DataSize
+ Offset
)) {
1037 SetSize
= DataSize
+ Offset
;
1039 Buffer
= AllocatePool (SetSize
);
1040 ASSERT (Buffer
!= NULL
);
1042 Status
= gRT
->GetVariable (
1050 ASSERT_EFI_ERROR (Status
);
1052 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1054 Status
= gRT
->SetVariable (
1064 } else if (Status
== EFI_NOT_FOUND
) {
1066 // If variable does not exist, a new variable need to be created.
1069 Size
= Offset
+ DataSize
;
1071 Buffer
= AllocateZeroPool (Size
);
1072 ASSERT (Buffer
!= NULL
);
1074 CopyMem ((UINT8
*)Buffer
+ Offset
, Data
, DataSize
);
1076 Status
= gRT
->SetVariable (
1079 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1089 // If we drop to here, the value is failed to be written in to variable area
1090 // So, we will save the data in the PCD Database's volatile area.
1096 Get local token number according to dynamic-ex PCD's {token space guid:token number}
1098 A dynamic-ex type PCD, developer must provide pair of token space guid: token number
1099 in DEC file. PCD database maintain a mapping table that translate pair of {token
1100 space guid: token number} to local token number.
1102 @param Guid Token space guid for dynamic-ex PCD entry.
1103 @param ExTokenNumber Dynamic-ex PCD token number.
1105 @return local token number for dynamic-ex PCD.
1109 GetExPcdTokenNumber (
1110 IN CONST EFI_GUID
*Guid
,
1111 IN UINT32 ExTokenNumber
1115 DYNAMICEX_MAPPING
*ExMap
;
1116 EFI_GUID
*GuidTable
;
1117 EFI_GUID
*MatchGuid
;
1120 if (!PEI_DATABASE_EMPTY
) {
1121 ExMap
= mPcdDatabase
->PeiDb
.Init
.ExMapTable
;
1122 GuidTable
= mPcdDatabase
->PeiDb
.Init
.GuidTable
;
1124 MatchGuid
= ScanGuid (GuidTable
, sizeof(mPcdDatabase
->PeiDb
.Init
.GuidTable
), Guid
);
1126 if (MatchGuid
!= NULL
) {
1128 MatchGuidIdx
= MatchGuid
- GuidTable
;
1130 for (Index
= 0; Index
< PEI_EXMAPPING_TABLE_SIZE
; Index
++) {
1131 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1132 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1133 return ExMap
[Index
].LocalTokenNumber
;
1139 ExMap
= mPcdDatabase
->DxeDb
.Init
.ExMapTable
;
1140 GuidTable
= mPcdDatabase
->DxeDb
.Init
.GuidTable
;
1142 MatchGuid
= ScanGuid (GuidTable
, sizeof(mPcdDatabase
->DxeDb
.Init
.GuidTable
), Guid
);
1144 // We need to ASSERT here. If GUID can't be found in GuidTable, this is a
1145 // error in the BUILD system.
1147 ASSERT (MatchGuid
!= NULL
);
1149 MatchGuidIdx
= MatchGuid
- GuidTable
;
1151 for (Index
= 0; Index
< DXE_EXMAPPING_TABLE_SIZE
; Index
++) {
1152 if ((ExTokenNumber
== ExMap
[Index
].ExTokenNumber
) &&
1153 (MatchGuidIdx
== ExMap
[Index
].ExGuidIndex
)) {
1154 return ExMap
[Index
].LocalTokenNumber
;
1164 Get SKU ID table from PCD database.
1166 @param LocalTokenNumberTableIdx Index of local token number in token number table.
1167 @param IsPeiPcd If TRUE,
1169 @return Pointer to SKU ID array table
1174 IN UINTN LocalTokenNumberTableIdx
,
1179 UINTN LocalTokenNumber
;
1183 LocalTokenNumber
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1184 Database
= (UINT8
*) &mPcdDatabase
->PeiDb
;
1186 LocalTokenNumber
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
[LocalTokenNumberTableIdx
- PEI_LOCAL_TOKEN_NUMBER
];
1187 Database
= (UINT8
*) &mPcdDatabase
->DxeDb
;
1190 ASSERT ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) != 0);
1192 SkuHead
= (SKU_HEAD
*) ((UINT8
*)Database
+ (LocalTokenNumber
& PCD_DATABASE_OFFSET_MASK
));
1194 return (SKU_ID
*) (Database
+ SkuHead
->SkuIdTableOffset
);
1199 Wrapper function of getting index of PCD entry in size table.
1201 @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
1202 @param IsPeiDb If TRUE, the pcd entry is initialized in PEI phase,
1203 If FALSE, the pcd entry is initialized in DXE phase.
1205 @return index of PCD entry in size table.
1209 IN UINTN LocalTokenNumberTableIdx
,
1213 UINT32
*LocalTokenNumberTable
;
1214 UINTN LocalTokenNumber
;
1220 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1222 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1227 for (Index
= 0; Index
< LocalTokenNumberTableIdx
; Index
++) {
1228 LocalTokenNumber
= LocalTokenNumberTable
[Index
];
1230 if ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
) {
1232 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1235 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1237 // We have only one entry for VPD enabled PCD entry:
1239 // We consider current size is equal to MAX size.
1243 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1245 // We have only two entry for Non-Sku enabled PCD entry:
1252 // We have these entry for SKU enabled PCD entry
1254 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1256 SkuIdTable
= GetSkuIdArray (Index
, IsPeiDb
);
1257 SizeTableIdx
+= (UINTN
)*SkuIdTable
+ 1;
1264 return SizeTableIdx
;
1268 Get size of POINTER type PCD value.
1270 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1271 @param MaxSize Maxmium size of POINTER type PCD value.
1273 @return size of POINTER type PCD value.
1278 IN UINTN LocalTokenNumberTableIdx
,
1283 UINTN LocalTokenNumber
;
1285 SIZE_INFO
*SizeTable
;
1288 UINT32
*LocalTokenNumberTable
;
1290 // EBC compiler is very choosy. It may report warning about comparison
1291 // between UINTN and 0 . So we add 1 in each size of the
1293 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
1297 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1298 SizeTable
= mPcdDatabase
->PeiDb
.Init
.SizeTable
;
1300 LocalTokenNumberTableIdx
-= PEI_LOCAL_TOKEN_NUMBER
;
1301 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1302 SizeTable
= mPcdDatabase
->DxeDb
.Init
.SizeTable
;
1305 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1307 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1309 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1311 *MaxSize
= SizeTable
[SizeTableIdx
];
1313 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1316 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1318 // We have only one entry for VPD enabled PCD entry:
1320 // We consider current size is equal to MAX size.
1324 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1326 // We have only two entry for Non-Sku enabled PCD entry:
1330 return SizeTable
[SizeTableIdx
+ 1];
1333 // We have these entry for SKU enabled PCD entry
1335 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1337 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1338 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1339 if (SkuIdTable
[1 + Index
] == mPcdDatabase
->PeiDb
.Init
.SystemSkuId
) {
1340 return SizeTable
[SizeTableIdx
+ 1 + Index
];
1343 return SizeTable
[SizeTableIdx
+ 1];
1349 Set size of POINTER type PCD value. The size should not exceed the maximum size
1352 @param LocalTokenNumberTableIdx Index of local token number in local token number table.
1353 @param CurrentSize Size of POINTER type PCD value.
1355 @retval TRUE Success to set size of PCD value.
1356 @retval FALSE Fail to set size of PCD value.
1360 IN UINTN LocalTokenNumberTableIdx
,
1361 IN OUT UINTN
*CurrentSize
1365 UINTN LocalTokenNumber
;
1367 SIZE_INFO
*SizeTable
;
1371 UINT32
*LocalTokenNumberTable
;
1374 // EBC compiler is very choosy. It may report warning about comparison
1375 // between UINTN and 0 . So we add 1 in each size of the
1378 IsPeiDb
= (BOOLEAN
) (LocalTokenNumberTableIdx
+ 1 < PEI_LOCAL_TOKEN_NUMBER
+ 1);
1381 LocalTokenNumberTable
= mPcdDatabase
->PeiDb
.Init
.LocalTokenNumberTable
;
1382 SizeTable
= mPcdDatabase
->PeiDb
.Init
.SizeTable
;
1384 LocalTokenNumberTableIdx
-= PEI_LOCAL_TOKEN_NUMBER
;
1385 LocalTokenNumberTable
= mPcdDatabase
->DxeDb
.Init
.LocalTokenNumberTable
;
1386 SizeTable
= mPcdDatabase
->DxeDb
.Init
.SizeTable
;
1389 LocalTokenNumber
= LocalTokenNumberTable
[LocalTokenNumberTableIdx
];
1391 ASSERT ((LocalTokenNumber
& PCD_DATUM_TYPE_ALL_SET
) == PCD_DATUM_TYPE_POINTER
);
1393 SizeTableIdx
= GetSizeTableIndex (LocalTokenNumberTableIdx
, IsPeiDb
);
1395 MaxSize
= SizeTable
[SizeTableIdx
];
1397 // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
1400 if ((LocalTokenNumber
& PCD_TYPE_VPD
) != 0) {
1402 // We shouldn't come here as we don't support SET for VPD
1407 if ((*CurrentSize
> MaxSize
) ||
1408 (*CurrentSize
== MAX_ADDRESS
)) {
1409 *CurrentSize
= MaxSize
;
1413 if ((LocalTokenNumber
& PCD_TYPE_SKU_ENABLED
) == 0) {
1415 // We have only two entry for Non-Sku enabled PCD entry:
1419 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;
1423 // We have these entry for SKU enabled PCD entry
1425 // 2) Current Size for each SKU_ID (It is equal to MaxSku).
1427 SkuIdTable
= GetSkuIdArray (LocalTokenNumberTableIdx
, IsPeiDb
);
1428 for (Index
= 0; Index
< SkuIdTable
[0]; Index
++) {
1429 if (SkuIdTable
[1 + Index
] == mPcdDatabase
->PeiDb
.Init
.SystemSkuId
) {
1430 SizeTable
[SizeTableIdx
+ 1 + Index
] = (SIZE_INFO
) *CurrentSize
;
1434 SizeTable
[SizeTableIdx
+ 1] = (SIZE_INFO
) *CurrentSize
;