diff options
Diffstat (limited to 'MdeModulePkg/Universal/PCD/Pei/Service.c')
-rw-r--r-- | MdeModulePkg/Universal/PCD/Pei/Service.c | 186 |
1 files changed, 141 insertions, 45 deletions
diff --git a/MdeModulePkg/Universal/PCD/Pei/Service.c b/MdeModulePkg/Universal/PCD/Pei/Service.c index 16a5cc8489..fddab6be58 100644 --- a/MdeModulePkg/Universal/PCD/Pei/Service.c +++ b/MdeModulePkg/Universal/PCD/Pei/Service.c @@ -21,7 +21,7 @@ Module Name: Service.c The function registers the CallBackOnSet fucntion
according to TokenNumber and EFI_GUID space.
- @param TokenNumber The token number.
+ @param ExTokenNumber The token number.
@param Guid The GUID space.
@param CallBackFunction The Callback function to be registered.
@param Register To register or unregister the callback function.
@@ -30,7 +30,7 @@ Module Name: Service.c @retval EFI_NOT_FOUND If the PCD Entry is not found according to Token Number and GUID space.
@retval EFI_OUT_OF_RESOURCES If the callback function can't be registered because there is not free
slot left in the CallbackFnTable.
---*/
+**/
EFI_STATUS
PeiRegisterCallBackWorker (
IN UINTN ExTokenNumber,
@@ -103,16 +103,9 @@ PeiRegisterCallBackWorker ( }
-
-
-
/**
The function builds the PCD database.
-
- @param VOID
-
- @retval VOID
---*/
+**/
VOID
BuildPcdDatabase (
VOID
@@ -137,12 +130,8 @@ BuildPcdDatabase ( CallbackFnTable = BuildGuidHob (&gPcdPeiCallbackFnTableHobGuid, SizeOfCallbackFnTable);
ZeroMem (CallbackFnTable, SizeOfCallbackFnTable);
-
- return;
}
-
-
/**
The function is provided by PCD PEIM and PCD DXE driver to
do the work of reading a HII variable from variable service.
@@ -154,8 +143,7 @@ BuildPcdDatabase ( @retval EFI_SUCCESS Operation successful.
@retval EFI_NOT_FOUND Variablel not found.
---*/
-STATIC
+**/
EFI_STATUS
GetHiiVariable (
IN CONST EFI_GUID *VariableGuid,
@@ -201,13 +189,20 @@ GetHiiVariable ( *VariableData = Buffer;
return EFI_SUCCESS;
- } else {
- return EFI_NOT_FOUND;
- }
+ }
+ return EFI_NOT_FOUND;
}
-STATIC
+/**
+ Find the local token number according to system SKU ID.
+
+ @param LocalTokenNumber PCD token number
+ @param Size The size of PCD entry.
+
+ @return Token number according to system SKU ID.
+
+**/
UINT32
GetSkuEnabledTokenNumber (
UINT32 LocalTokenNumber,
@@ -217,7 +212,7 @@ GetSkuEnabledTokenNumber ( PEI_PCD_DATABASE *PeiPcdDb;
SKU_HEAD *SkuHead;
SKU_ID *SkuIdTable;
- INTN i;
+ INTN Index;
UINT8 *Value;
PeiPcdDb = GetPcdDatabase ();
@@ -228,27 +223,27 @@ GetSkuEnabledTokenNumber ( Value = (UINT8 *) ((UINT8 *)PeiPcdDb + (SkuHead->SkuDataStartOffset));
SkuIdTable = (SKU_ID *) ((UINT8 *)PeiPcdDb + (SkuHead->SkuIdTableOffset));
- for (i = 0; i < SkuIdTable[0]; i++) {
- if (PeiPcdDb->Init.SystemSkuId == SkuIdTable[i + 1]) {
+ for (Index = 0; Index < SkuIdTable[0]; Index++) {
+ if (PeiPcdDb->Init.SystemSkuId == SkuIdTable[Index + 1]) {
break;
}
}
switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
- Value = (UINT8 *) &(((VPD_HEAD *) Value)[i]);
+ Value = (UINT8 *) &(((VPD_HEAD *) Value)[Index]);
return (UINT32) ((Value - (UINT8 *) PeiPcdDb) | PCD_TYPE_VPD);
case PCD_TYPE_HII:
- Value = (UINT8 *) &(((VARIABLE_HEAD *) Value)[i]);
+ Value = (UINT8 *) &(((VARIABLE_HEAD *) Value)[Index]);
return (UINT32) ((Value - (UINT8 *) PeiPcdDb) | PCD_TYPE_HII);
case PCD_TYPE_STRING:
- Value = (UINT8 *) &(((STRING_HEAD *) Value)[i]);
+ Value = (UINT8 *) &(((STRING_HEAD *) Value)[Index]);
return (UINT32) ((Value - (UINT8 *) PeiPcdDb) | PCD_TYPE_STRING);
case PCD_TYPE_DATA:
- Value += Size * i;
+ Value += Size * Index;
return (UINT32) (Value - (UINT8 *) PeiPcdDb);
default:
@@ -258,12 +253,21 @@ GetSkuEnabledTokenNumber ( ASSERT (FALSE);
return 0;
-
}
+/**
+ Invoke the callback function when dynamic PCD entry was set, if this PCD entry
+ has registered callback function.
+ @param ExTokenNumber DynamicEx PCD's token number, if this PCD entry is dyanmicEx
+ type PCD.
+ @param Guid DynamicEx PCD's guid, if this PCD entry is dynamicEx type
+ PCD.
+ @param TokenNumber PCD token number generated by build tools.
+ @param Data Value want to be set for this PCD entry
+ @param Size The size of value
-STATIC
+**/
VOID
InvokeCallbackOnSet (
UINTN ExTokenNumber,
@@ -307,11 +311,18 @@ InvokeCallbackOnSet ( );
}
}
-
}
+/**
+ Wrapper function for setting non-pointer type value for a PCD entry.
+
+ @param TokenNumber Pcd token number autogenerated by build tools.
+ @param Data Value want to be set for PCD entry
+ @param Size Size of value.
+ @return status of SetWorker.
+**/
EFI_STATUS
SetValueWorker (
IN UINTN TokenNumber,
@@ -322,12 +333,25 @@ SetValueWorker ( return SetWorker (TokenNumber, Data, &Size, FALSE);
}
-
-
+/**
+ Set value for an PCD entry
+
+ @param TokenNumber Pcd token number autogenerated by build tools.
+ @param Data Value want to be set for PCD entry
+ @param Size Size of value.
+ @param PtrType If TRUE, the type of PCD entry's value is Pointer.
+ If False, the type of PCD entry's value is not Pointer.
+
+ @retval EFI_INVALID_PARAMETER If this PCD type is VPD, VPD PCD can not be set.
+ @retval EFI_INVALID_PARAMETER If Size can not be set to size table.
+ @retval EFI_NOT_FOUND If value type of PCD entry is intergrate, but not in
+ range of UINT8, UINT16, UINT32, UINT64
+ @retval EFI_NOT_FOUND Can not find the PCD type according to token number.
+**/
EFI_STATUS
SetWorker (
IN UINTN TokenNumber,
- IN OUT VOID *Data,
+ IN VOID *Data,
IN OUT UINTN *Size,
IN BOOLEAN PtrType
)
@@ -442,8 +466,17 @@ SetWorker ( }
+/**
+ Wrapper function for set PCD value for non-Pointer type dynamic-ex PCD.
+ @param ExTokenNumber Token number for dynamic-ex PCD.
+ @param Guid Token space guid for dynamic-ex PCD.
+ @param Data Value want to be set.
+ @param SetSize The size of value.
+ @return status of ExSetWorker().
+
+**/
EFI_STATUS
ExSetValueWorker (
IN UINTN ExTokenNumber,
@@ -455,8 +488,24 @@ ExSetValueWorker ( return ExSetWorker (ExTokenNumber, Guid, Data, &Size, FALSE);
}
+/**
+ Set value for a dynamic PCD entry.
+
+ This routine find the local token number according to dynamic-ex PCD's token
+ space guid and token number firstly, and invoke callback function if this PCD
+ entry registered callback function. Finally, invoken general SetWorker to set
+ PCD value.
+
+ @param ExTokenNumber Dynamic-ex PCD token number.
+ @param Guid Token space guid for dynamic-ex PCD.
+ @param Data PCD value want to be set
+ @param SetSize Size of value.
+ @param PtrType If TRUE, this PCD entry is pointer type.
+ If FALSE, this PCD entry is not pointer type.
+ @return status of SetWorker().
+**/
EFI_STATUS
ExSetWorker (
IN UINTN ExTokenNumber,
@@ -480,9 +529,16 @@ ExSetWorker ( }
+/**
+ Wrapper function for get PCD value for dynamic-ex PCD.
+ @param Guid Token space guid for dynamic-ex PCD.
+ @param ExTokenNumber Token number for dyanmic-ex PCD.
+ @param GetSize The size of dynamic-ex PCD value.
+ @return PCD entry in PCD database.
+**/
VOID *
ExGetWorker (
IN CONST EFI_GUID *Guid,
@@ -498,13 +554,24 @@ ExGetWorker ( return GetWorker (GetExPcdTokenNumber (Guid, ExTokenNumber), GetSize);
}
+/**
+ Get the PCD entry pointer in PCD database.
+
+ This routine will visit PCD database to find the PCD entry according to given
+ token number. The given token number is autogened by build tools and it will be
+ translated to local token number. Local token number contains PCD's type and
+ offset of PCD entry in PCD database.
+ @param TokenNumber Token's number, it is autogened by build tools
+ @param GetSize The size of token's value
+ @return PCD entry pointer in PCD database
+**/
VOID *
GetWorker (
- UINTN TokenNumber,
- UINTN GetSize
+ IN UINTN TokenNumber,
+ IN UINTN GetSize
)
{
UINT32 Offset;
@@ -596,15 +663,26 @@ GetWorker ( }
+/**
+ Get local token number according to dynamic-ex PCD's {token space guid:token number}
+
+ A dynamic-ex type PCD, developer must provide pair of token space guid: token number
+ in DEC file. PCD database maintain a mapping table that translate pair of {token
+ space guid: token number} to local token number.
+
+ @param Guid Token space guid for dynamic-ex PCD entry.
+ @param ExTokenNumber EDES_TODO: Add parameter description
+ @return local token number for dynamic-ex PCD.
+**/
UINTN
GetExPcdTokenNumber (
IN CONST EFI_GUID *Guid,
IN UINTN ExTokenNumber
)
{
- UINT32 i;
+ UINT32 Index;
DYNAMICEX_MAPPING *ExMap;
EFI_GUID *GuidTable;
EFI_GUID *MatchGuid;
@@ -625,10 +703,10 @@ GetExPcdTokenNumber ( MatchGuidIdx = MatchGuid - GuidTable;
- for (i = 0; i < PEI_EXMAPPING_TABLE_SIZE; i++) {
- if ((ExTokenNumber == ExMap[i].ExTokenNumber) &&
- (MatchGuidIdx == ExMap[i].ExGuidIndex)) {
- return ExMap[i].LocalTokenNumber;
+ for (Index = 0; Index < PEI_EXMAPPING_TABLE_SIZE; Index++) {
+ if ((ExTokenNumber == ExMap[Index].ExTokenNumber) &&
+ (MatchGuidIdx == ExMap[Index].ExGuidIndex)) {
+ return ExMap[Index].LocalTokenNumber;
}
}
@@ -637,8 +715,12 @@ GetExPcdTokenNumber ( return 0;
}
+/**
+ Get PCD database from GUID HOB in PEI phase.
+ @return Pointer to PCD database.
+**/
PEI_PCD_DATABASE *
GetPcdDatabase (
VOID
@@ -652,8 +734,15 @@ GetPcdDatabase ( return (PEI_PCD_DATABASE *) GET_GUID_HOB_DATA (GuidHob);
}
+/**
+ Get SKU ID tabble from PCD database.
+
+ @param LocalTokenNumberTableIdx Index of local token number in token number table.
+ @param Database PCD database.
+ @return Pointer to SKU ID array table
+**/
SKU_ID *
GetSkuIdArray (
IN UINTN LocalTokenNumberTableIdx,
@@ -673,30 +762,37 @@ GetSkuIdArray ( }
+/**
+ Get index of PCD entry in size table.
+
+ @param LocalTokenNumberTableIdx Index of this PCD in local token number table.
+ @param Database Pointer to PCD database in PEI phase.
+ @return index of PCD entry in size table.
+**/
UINTN
GetSizeTableIndex (
IN UINTN LocalTokenNumberTableIdx,
IN PEI_PCD_DATABASE *Database
)
{
- UINTN i;
+ UINTN Index;
UINTN SizeTableIdx;
UINTN LocalTokenNumber;
SKU_ID *SkuIdTable;
SizeTableIdx = 0;
- for (i=0; i<LocalTokenNumberTableIdx; i++) {
- LocalTokenNumber = Database->Init.LocalTokenNumberTable[i];
+ for (Index=0; Index<LocalTokenNumberTableIdx; Index++) {
+ LocalTokenNumber = Database->Init.LocalTokenNumberTable[Index];
if ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER) {
//
// SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
// PCD entry.
//
- if (LocalTokenNumber & PCD_TYPE_VPD) {
+ if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
//
// We have only one entry for VPD enabled PCD entry:
// 1) MAX Size.
@@ -717,7 +813,7 @@ GetSizeTableIndex ( // 1) MAX SIZE
// 2) Current Size for each SKU_ID (It is equal to MaxSku).
//
- SkuIdTable = GetSkuIdArray (i, Database);
+ SkuIdTable = GetSkuIdArray (Index, Database);
SizeTableIdx += (UINTN)*SkuIdTable + 1;
}
}
|