MdeModulePkg PCD: Enable Firmware to retrieve the default setting

https://bugzilla.tianocore.org/show_bug.cgi?id=611
Update PCD driver to retrieve the default setting and set the initial
EFI variable when PcdSetNvStoreDefaultId is set.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
This commit is contained in:
Liming Gao 2017-12-22 12:42:00 +08:00
parent 8ddbd22716
commit 219247e164
3 changed files with 111 additions and 1 deletions

View File

@ -129,6 +129,105 @@ EFI_PEI_PPI_DESCRIPTOR mPpiList2[] = {
}
};
/**
Callback on SET PcdSetNvStoreDefaultId
Once PcdSetNvStoreDefaultId is set, the default NV storage will be found from
PcdNvStoreDefaultValueBuffer, and built into VariableHob.
@param[in] CallBackGuid The PCD token GUID being set.
@param[in] CallBackToken The PCD token number being set.
@param[in, out] TokenData A pointer to the token data being set.
@param[in] TokenDataSize The size, in bytes, of the data being set.
**/
VOID
EFIAPI
PcdSetNvStoreDefaultIdCallBack (
IN CONST EFI_GUID *CallBackGuid, OPTIONAL
IN UINTN CallBackToken,
IN OUT VOID *TokenData,
IN UINTN TokenDataSize
)
{
EFI_STATUS Status;
UINT16 DefaultId;
SKU_ID SkuId;
UINTN FullSize;
UINTN Index;
UINT8 *DataBuffer;
UINT8 *VarStoreHobData;
UINT8 *BufferEnd;
BOOLEAN IsFound;
VARIABLE_STORE_HEADER *NvStoreBuffer;
PCD_DEFAULT_DATA *DataHeader;
PCD_DEFAULT_INFO *DefaultInfo;
PCD_DATA_DELTA *DeltaData;
DefaultId = *(UINT16 *) TokenData;
SkuId = GetPcdDatabase()->SystemSkuId;
IsFound = FALSE;
if (PeiPcdGetSizeEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer)) > sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {
DataBuffer = (UINT8 *) PeiPcdGetPtrEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer));
FullSize = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER *) DataBuffer)->Length;
DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER));
//
// The first section data includes NV storage default setting.
//
NvStoreBuffer = (VARIABLE_STORE_HEADER *) ((UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize);
VarStoreHobData = (UINT8 *) BuildGuidHob (&NvStoreBuffer->Signature, NvStoreBuffer->Size);
ASSERT (VarStoreHobData != NULL);
CopyMem (VarStoreHobData, NvStoreBuffer, NvStoreBuffer->Size);
//
// Find the matched SkuId and DefaultId in the first section
//
DefaultInfo = &(DataHeader->DefaultInfo[0]);
BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;
while ((UINT8 *) DefaultInfo < BufferEnd) {
if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == SkuId) {
IsFound = TRUE;
break;
}
DefaultInfo ++;
}
//
// Find the matched SkuId and DefaultId in the remaining section
//
Index = sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER) + ((DataHeader->DataSize + 7) & (~7));
DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);
while (!IsFound && Index < FullSize && DataHeader->DataSize != 0xFFFFFFFF) {
DefaultInfo = &(DataHeader->DefaultInfo[0]);
BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;
while ((UINT8 *) DefaultInfo < BufferEnd) {
if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == SkuId) {
IsFound = TRUE;
break;
}
DefaultInfo ++;
}
if (IsFound) {
DeltaData = (PCD_DATA_DELTA *) BufferEnd;
BufferEnd = (UINT8 *) DataHeader + DataHeader->DataSize;
while ((UINT8 *) DeltaData < BufferEnd) {
*(VarStoreHobData + DeltaData->Offset) = (UINT8) DeltaData->Value;
DeltaData ++;
}
break;
}
Index = (Index + DataHeader->DataSize + 7) & (~7) ;
DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);
}
}
Status = PcdUnRegisterCallBackOnSet (
&gEfiMdeModulePkgTokenSpaceGuid,
PcdToken(PcdSetNvStoreDefaultId),
PcdSetNvStoreDefaultIdCallBack
);
ASSERT_EFI_ERROR (Status);
}
/**
Main entry for PCD PEIM driver.
@ -163,6 +262,13 @@ PcdPeimInit (
Status = PeiServicesInstallPpi (&mPpiList2[0]);
ASSERT_EFI_ERROR (Status);
Status = PeiRegisterCallBackOnSet (
&gEfiMdeModulePkgTokenSpaceGuid,
PcdToken(PcdSetNvStoreDefaultId),
PcdSetNvStoreDefaultIdCallBack
);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@ -330,6 +330,7 @@
## SOMETIMES_CONSUMES ## HOB
gPcdDataBaseHobGuid
gPcdDataBaseSignatureGuid ## CONSUMES ## GUID # PCD database signature GUID.
gEfiMdeModulePkgTokenSpaceGuid ## SOMETIMES_CONSUMES ## GUID
[Ppis]
gEfiPeiReadOnlyVariable2PpiGuid ## SOMETIMES_CONSUMES
@ -344,6 +345,8 @@
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPcdCallBackNumberPerPcdEntry ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNvStoreDefaultId ## CONSUMES
[Depex]
TRUE

View File

@ -23,6 +23,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Ppi/PiPcdInfo.h>
#include <Guid/PcdDataBaseHobGuid.h>
#include <Guid/PcdDataBaseSignatureGuid.h>
#include <Guid/VariableFormat.h>
#include <Library/DebugLib.h>
#include <Library/PeimEntryPoint.h>
#include <Library/BaseLib.h>
@ -36,7 +37,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
// Please make sure the PCD Serivce PEIM Version is consistent with
// the version of the generated PEIM PCD Database by build tool.
//
#define PCD_SERVICE_PEIM_VERSION 6
#define PCD_SERVICE_PEIM_VERSION 7
//
// PCD_PEI_SERVICE_DRIVER_VERSION is defined in Autogen.h.