diff options
author | Bob C Feng <bob.c.feng@intel.com> | 2013-11-18 07:45:49 +0000 |
---|---|---|
committer | lzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524> | 2013-11-18 07:45:49 +0000 |
commit | 419db80bef66edff583a0a5f406e801d70f11344 (patch) | |
tree | 2d3e4e5b918200570bd6ec4b0eccc874b7447410 /MdeModulePkg/Universal/PCD/Pei/Service.c | |
parent | e8a47801a1dfdb148b1bfcd5bdc8ebc3bf51f92d (diff) | |
download | edk2-platforms-419db80bef66edff583a0a5f406e801d70f11344.tar.xz |
MdePkg and MdeModulePkg Pcd: Implement PCD Driver for External PCD Database and SKU enable Feature.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Bob C Feng <bob.c.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14857 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Universal/PCD/Pei/Service.c')
-rw-r--r-- | MdeModulePkg/Universal/PCD/Pei/Service.c | 193 |
1 files changed, 138 insertions, 55 deletions
diff --git a/MdeModulePkg/Universal/PCD/Pei/Service.c b/MdeModulePkg/Universal/PCD/Pei/Service.c index e5d5f0c208..47e87d3bcd 100644 --- a/MdeModulePkg/Universal/PCD/Pei/Service.c +++ b/MdeModulePkg/Universal/PCD/Pei/Service.c @@ -2,7 +2,7 @@ The driver internal functions are implmented here.
They build Pei PCD database, and provide access service to PCD database.
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -43,25 +43,30 @@ PeiRegisterCallBackWorker ( PCD_PPI_CALLBACK Compare;
PCD_PPI_CALLBACK Assign;
UINT32 LocalTokenNumber;
+ UINT32 LocalTokenCount;
+ UINTN PeiNexTokenNumber;
UINTN TokenNumber;
UINTN Idx;
+ PEI_PCD_DATABASE *PeiPcdDb;
+
+ PeiPcdDb = GetPcdDatabase();
+ LocalTokenCount = PeiPcdDb->LocalTokenCount;
+ PeiNexTokenNumber = PeiPcdDb->LocalTokenCount - PeiPcdDb->ExTokenCount;
if (Guid == NULL) {
TokenNumber = ExTokenNumber;
-
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index.
//
TokenNumber--;
- ASSERT (TokenNumber + 1 < PEI_NEX_TOKEN_NUMBER + 1);
+ ASSERT (TokenNumber + 1 < (PeiNexTokenNumber + 1));
} else {
TokenNumber = GetExPcdTokenNumber (Guid, ExTokenNumber);
if (TokenNumber == PCD_INVALID_TOKEN_NUMBER) {
return EFI_NOT_FOUND;
}
-
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
@@ -71,11 +76,11 @@ PeiRegisterCallBackWorker ( // EBC compiler is very choosy. It may report warning about comparison
// between UINTN and 0 . So we add 1 in each size of the
// comparison.
- ASSERT (TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);
+ ASSERT ((TokenNumber + 1) < (LocalTokenCount + 1));
}
- LocalTokenNumber = GetPcdDatabase()->Init.LocalTokenNumberTable[TokenNumber];
+ LocalTokenNumber = *((UINT32 *)((UINT8 *)PeiPcdDb + PeiPcdDb->LocalTokenNumberTableOffset) + TokenNumber);
//
// We don't support SET for HII and VPD type PCD entry in PEI phase.
@@ -105,29 +110,74 @@ PeiRegisterCallBackWorker ( }
+
+/**
+ Find the Pcd database.
+
+ @param FileHandle Handle of the file the external PCD database binary located.
+
+ @retval The base address of external PCD database binary.
+ @retval NULL Return NULL if not find.
+**/
+VOID *
+LocateExPcdBinary (
+ IN EFI_PEI_FILE_HANDLE FileHandle
+ )
+{
+ EFI_STATUS Status;
+ VOID *PcdDb;
+
+ PcdDb = NULL;
+
+ ASSERT (FileHandle != NULL);
+
+ Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, FileHandle, &PcdDb);
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Check the first bytes (Header Signature Guid) and build version.
+ //
+ if (!CompareGuid (PcdDb, &gPcdDataBaseSignatureGuid) ||
+ (((PEI_PCD_DATABASE *) PcdDb)->BuildVersion != PCD_SERVICE_PEIM_VERSION)) {
+ ASSERT (FALSE);
+ }
+ return PcdDb;
+}
+
+
/**
The function builds the PCD database.
+
+ @param FileHandle Handle of the file the external PCD database binary located.
+
**/
VOID
BuildPcdDatabase (
- VOID
+ IN EFI_PEI_FILE_HANDLE FileHandle
)
{
- PEI_PCD_DATABASE *Database;
- VOID *CallbackFnTable;
- UINTN SizeOfCallbackFnTable;
-
- Database = BuildGuidHob (&gPcdDataBaseHobGuid, sizeof (PEI_PCD_DATABASE));
+ PEI_PCD_DATABASE *Database;
+ PEI_PCD_DATABASE *PeiPcdDbBinary;
+ VOID *CallbackFnTable;
+ UINTN SizeOfCallbackFnTable;
+
+ //
+ // Locate the external PCD database binary for one section of current FFS
+ //
+ PeiPcdDbBinary = LocateExPcdBinary (FileHandle);
- ZeroMem (Database, sizeof (PEI_PCD_DATABASE));
+ ASSERT(PeiPcdDbBinary != NULL);
+
+ Database = BuildGuidHob (&gPcdDataBaseHobGuid, PeiPcdDbBinary->Length + PeiPcdDbBinary->UninitDataBaseSize);
+
+ ZeroMem (Database, PeiPcdDbBinary->Length + PeiPcdDbBinary->UninitDataBaseSize);
//
- // gPEIPcdDbInit is smaller than PEI_PCD_DATABASE
+ // PeiPcdDbBinary is smaller than Database
//
-
- CopyMem (&Database->Init, &gPEIPcdDbInit, sizeof (gPEIPcdDbInit));
+ CopyMem (Database, PeiPcdDbBinary, PeiPcdDbBinary->Length);
- SizeOfCallbackFnTable = PEI_LOCAL_TOKEN_NUMBER * sizeof (PCD_PPI_CALLBACK) * PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry);
+ SizeOfCallbackFnTable = Database->LocalTokenCount * sizeof (PCD_PPI_CALLBACK) * PcdGet32 (PcdMaxPeiPcdCallBackNumberPerPcdEntry);
CallbackFnTable = BuildGuidHob (&gEfiCallerIdGuid, SizeOfCallbackFnTable);
@@ -215,6 +265,7 @@ GetSkuEnabledTokenNumber ( SKU_ID *SkuIdTable;
INTN Index;
UINT8 *Value;
+ BOOLEAN FoundSku;
PeiPcdDb = GetPcdDatabase ();
@@ -223,13 +274,30 @@ GetSkuEnabledTokenNumber ( SkuHead = (SKU_HEAD *) ((UINT8 *)PeiPcdDb + (LocalTokenNumber & PCD_DATABASE_OFFSET_MASK));
Value = (UINT8 *) ((UINT8 *)PeiPcdDb + (SkuHead->SkuDataStartOffset));
SkuIdTable = (SKU_ID *) ((UINT8 *)PeiPcdDb + (SkuHead->SkuIdTableOffset));
-
+
+ //
+ // Find the current system's SKU ID entry in SKU ID table.
+ //
+ FoundSku = FALSE;
for (Index = 0; Index < SkuIdTable[0]; Index++) {
- if (PeiPcdDb->Init.SystemSkuId == SkuIdTable[Index + 1]) {
+ if (PeiPcdDb->SystemSkuId == SkuIdTable[Index + 1]) {
+ FoundSku = TRUE;
break;
}
}
+ //
+ // Find the default SKU ID entry in SKU ID table.
+ //
+ if(!FoundSku) {
+ for (Index = 0; Index < SkuIdTable[0]; Index++) {
+ if (0 == SkuIdTable[Index + 1]) {
+ break;
+ }
+ }
+ }
+ ASSERT (Index < SkuIdTable[0]);
+
switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
Value = (UINT8 *) &(((VPD_HEAD *) Value)[Index]);
@@ -238,14 +306,18 @@ GetSkuEnabledTokenNumber ( case PCD_TYPE_HII:
Value = (UINT8 *) &(((VARIABLE_HEAD *) Value)[Index]);
return (UINT32) ((Value - (UINT8 *) PeiPcdDb) | PCD_TYPE_HII);
-
+
+ case PCD_TYPE_HII|PCD_TYPE_STRING:
+ Value = (UINT8 *) &(((VARIABLE_HEAD *) Value)[Index]);
+ return (UINT32) ((Value - (UINT8 *) PeiPcdDb) | PCD_TYPE_HII | PCD_TYPE_STRING);
+
case PCD_TYPE_STRING:
Value = (UINT8 *) &(((STRING_HEAD *) Value)[Index]);
return (UINT32) ((Value - (UINT8 *) PeiPcdDb) | PCD_TYPE_STRING);
case PCD_TYPE_DATA:
Value += Size * Index;
- return (UINT32) (Value - (UINT8 *) PeiPcdDb);
+ return (UINT32) ((Value - (UINT8 *) PeiPcdDb) | PCD_TYPE_DATA);
default:
ASSERT (FALSE);
@@ -281,6 +353,8 @@ InvokeCallbackOnSet ( EFI_HOB_GUID_TYPE *GuidHob;
PCD_PPI_CALLBACK *CallbackTable;
UINTN Idx;
+ PEI_PCD_DATABASE *PeiPcdDb;
+ UINT32 LocalTokenCount;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
@@ -288,12 +362,15 @@ InvokeCallbackOnSet ( // as the array index.
//
TokenNumber--;
-
+
+ PeiPcdDb = GetPcdDatabase ();
+ LocalTokenCount = PeiPcdDb->LocalTokenCount;
+
if (Guid == NULL) {
// EBC compiler is very choosy. It may report warning about comparison
// between UINTN and 0 . So we add 1 in each size of the
// comparison.
- ASSERT (TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);
+ ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));
}
GuidHob = GetFirstGuidHob (&gEfiCallerIdGuid);
@@ -359,11 +436,13 @@ SetWorker ( )
{
UINT32 LocalTokenNumber;
+ UINTN PeiNexTokenNumber;
PEI_PCD_DATABASE *PeiPcdDb;
STRING_HEAD StringTableIdx;
UINTN Offset;
VOID *InternalData;
UINTN MaxSize;
+ UINT32 LocalTokenCount;
if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {
return EFI_UNSUPPORTED;
@@ -375,15 +454,15 @@ SetWorker ( // as the array index.
//
TokenNumber--;
+ PeiPcdDb = GetPcdDatabase ();
+ LocalTokenCount = PeiPcdDb->LocalTokenCount;
// EBC compiler is very choosy. It may report warning about comparison
// between UINTN and 0 . So we add 1 in each size of the
// comparison.
- ASSERT (TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);
-
- PeiPcdDb = GetPcdDatabase ();
+ ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));
- LocalTokenNumber = PeiPcdDb->Init.LocalTokenNumberTable[TokenNumber];
+ LocalTokenNumber = *((UINT32 *)((UINT8 *)PeiPcdDb + PeiPcdDb->LocalTokenNumberTableOffset) + TokenNumber);
if (PtrType) {
//
@@ -405,7 +484,8 @@ SetWorker ( // For Dynamic EX PCD entry, we have invoked the callback function for Dynamic EX
// type PCD entry in ExSetWorker.
//
- if (TokenNumber + 1 < PEI_NEX_TOKEN_NUMBER + 1) {
+ PeiNexTokenNumber = PeiPcdDb->LocalTokenCount - PeiPcdDb->ExTokenCount;
+ if (TokenNumber + 1 < PeiNexTokenNumber + 1) {
InvokeCallbackOnSet (0, NULL, TokenNumber + 1, Data, *Size);
}
@@ -433,7 +513,7 @@ SetWorker ( case PCD_TYPE_STRING:
if (SetPtrTypeSize (TokenNumber, Size, PeiPcdDb)) {
StringTableIdx = *((STRING_HEAD *)InternalData);
- CopyMem (&PeiPcdDb->Init.StringTable[StringTableIdx], Data, *Size);
+ CopyMem ((UINT8 *)PeiPcdDb + PeiPcdDb->StringTableOffset + StringTableIdx, Data, *Size);
return EFI_SUCCESS;
} else {
return EFI_INVALID_PARAMETER;
@@ -503,7 +583,7 @@ ExSetValueWorker ( }
/**
- Set value for a dynamic PCD entry.
+ Set value for a dynamic-ex 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
@@ -598,6 +678,7 @@ GetWorker ( PEI_PCD_DATABASE *PeiPcdDb;
UINT32 LocalTokenNumber;
UINTN MaxSize;
+ UINT32 LocalTokenCount;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
@@ -606,16 +687,17 @@ GetWorker ( //
TokenNumber--;
+ PeiPcdDb = GetPcdDatabase ();
+ LocalTokenCount = PeiPcdDb->LocalTokenCount;
+
// EBC compiler is very choosy. It may report warning about comparison
// between UINTN and 0 . So we add 1 in each size of the
// comparison.
- ASSERT (TokenNumber + 1 < PEI_LOCAL_TOKEN_NUMBER + 1);
+ ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));
ASSERT ((GetSize == PeiPcdGetSize(TokenNumber + 1)) || (GetSize == 0));
- PeiPcdDb = GetPcdDatabase ();
-
- LocalTokenNumber = PeiPcdDb->Init.LocalTokenNumberTable[TokenNumber];
+ LocalTokenNumber = *((UINT32 *)((UINT8 *)PeiPcdDb + PeiPcdDb->LocalTokenNumberTableOffset) + TokenNumber);
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
if (GetSize == 0) {
@@ -627,8 +709,8 @@ GetWorker ( }
Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;
- StringTable = PeiPcdDb->Init.StringTable;
-
+ StringTable = (UINT8 *)PeiPcdDb + PeiPcdDb->StringTableOffset;
+
switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
{
@@ -642,7 +724,7 @@ GetWorker ( {
VariableHead = (VARIABLE_HEAD *) ((UINT8 *)PeiPcdDb + Offset);
- Guid = &(PeiPcdDb->Init.GuidTable[VariableHead->GuidTableIndex]);
+ Guid = (EFI_GUID *) ((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + VariableHead->GuidTableIndex;
Name = (UINT16*)&StringTable[VariableHead->StringIndex];
Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
@@ -681,16 +763,16 @@ GetWorker ( }
/**
- Get local token number according to dynamic-ex PCD's {token space guid:token number}
+ Get 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.
+ space guid: token number} to Token Number.
@param Guid Token space guid for dynamic-ex PCD entry.
- @param ExTokenNumber EDES_TODO: Add parameter description
+ @param ExTokenNumber Dynamic-ex PCD token number.
- @return local token number for dynamic-ex PCD.
+ @return Token Number for dynamic-ex PCD.
**/
UINTN
@@ -707,11 +789,11 @@ GetExPcdTokenNumber ( PEI_PCD_DATABASE *PeiPcdDb;
PeiPcdDb = GetPcdDatabase();
-
- ExMap = PeiPcdDb->Init.ExMapTable;
- GuidTable = PeiPcdDb->Init.GuidTable;
- MatchGuid = ScanGuid (GuidTable, sizeof(PeiPcdDb->Init.GuidTable), Guid);
+ ExMap = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);
+ GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);
+
+ MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid);
//
// We need to ASSERT here. If GUID can't be found in GuidTable, this is a
// error in the BUILD system.
@@ -720,10 +802,10 @@ GetExPcdTokenNumber ( MatchGuidIdx = MatchGuid - GuidTable;
- for (Index = 0; Index < PEI_EXMAPPING_TABLE_SIZE; Index++) {
+ for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {
if ((ExTokenNumber == ExMap[Index].ExTokenNumber) &&
(MatchGuidIdx == ExMap[Index].ExGuidIndex)) {
- return ExMap[Index].LocalTokenNumber;
+ return ExMap[Index].TokenNumber;
}
}
@@ -750,7 +832,7 @@ GetPcdDatabase ( }
/**
- Get SKU ID tabble from PCD database.
+ Get SKU ID table from PCD database.
@param LocalTokenNumberTableIdx Index of local token number in token number table.
@param Database PCD database.
@@ -767,7 +849,7 @@ GetSkuIdArray ( SKU_HEAD *SkuHead;
UINTN LocalTokenNumber;
- LocalTokenNumber = Database->Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];
+ LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);
ASSERT ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) != 0);
@@ -793,14 +875,14 @@ GetSizeTableIndex ( )
{
UINTN Index;
- UINTN SizeTableIdx;
+ UINTN SizeTableIdx;
UINTN LocalTokenNumber;
SKU_ID *SkuIdTable;
SizeTableIdx = 0;
- for (Index=0; Index<LocalTokenNumberTableIdx; Index++) {
- LocalTokenNumber = Database->Init.LocalTokenNumberTable[Index];
+ for (Index = 0; Index < LocalTokenNumberTableIdx; Index++) {
+ LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + Index);
if ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER) {
//
@@ -809,11 +891,12 @@ GetSizeTableIndex ( //
if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {
//
- // We have only one entry for VPD enabled PCD entry:
+ // We have only two entry for VPD enabled PCD entry:
// 1) MAX Size.
- // We consider current size is equal to MAX size.
+ // 2) Current Size
+ // Current size is equal to MAX size.
//
- SizeTableIdx++;
+ SizeTableIdx += 2;
} else {
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
//
|