diff options
Diffstat (limited to 'EdkModulePkg/Universal/PCD')
-rw-r--r-- | EdkModulePkg/Universal/PCD/Dxe/Pcd.c | 107 | ||||
-rw-r--r-- | EdkModulePkg/Universal/PCD/Dxe/Service.c | 460 | ||||
-rw-r--r-- | EdkModulePkg/Universal/PCD/Dxe/Service.h | 74 | ||||
-rw-r--r-- | EdkModulePkg/Universal/PCD/Pei/Pcd.c | 103 | ||||
-rw-r--r-- | EdkModulePkg/Universal/PCD/Pei/Service.c | 322 | ||||
-rw-r--r-- | EdkModulePkg/Universal/PCD/Pei/Service.h | 79 |
6 files changed, 887 insertions, 258 deletions
diff --git a/EdkModulePkg/Universal/PCD/Dxe/Pcd.c b/EdkModulePkg/Universal/PCD/Dxe/Pcd.c index 26bb7d807e..3e35363a3b 100644 --- a/EdkModulePkg/Universal/PCD/Dxe/Pcd.c +++ b/EdkModulePkg/Universal/PCD/Dxe/Pcd.c @@ -182,21 +182,44 @@ DxePcdGetSize ( IN UINTN TokenNumber
)
{
- UINT16 * SizeTable;
+ UINTN Size;
+ UINT32 *LocalTokenNumberTable;
+ BOOLEAN IsPeiDb;
+ UINTN MaxSize;
+ UINTN TmpTokenNumber;
//
// 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--;
+
+ //
+ // Backup the TokenNumber passed in as GetPtrTypeSize need the original TokenNumber
+ //
+ TmpTokenNumber = TokenNumber;
+
+ ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);
+
+ IsPeiDb = (BOOLEAN) (TokenNumber < PEI_LOCAL_TOKEN_NUMBER);
- SizeTable = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? mPcdDatabase->PeiDb.Init.SizeTable :
- mPcdDatabase->DxeDb.Init.SizeTable;
+ TokenNumber = IsPeiDb ? TokenNumber :
+ (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);
+ LocalTokenNumberTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.LocalTokenNumberTable
+ : mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
- TokenNumber = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TokenNumber : (TokenNumber - PEI_LOCAL_TOKEN_NUMBER);
+ Size = (LocalTokenNumberTable[TokenNumber] & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;
+
+ if (Size == 0) {
+ //
+ // For pointer type, we need to scan the SIZE_TABLE to get the current size.
+ //
+ return GetPtrTypeSize (TmpTokenNumber, &MaxSize);
+ } else {
+ return Size;
+ }
- return SizeTable[TokenNumber];
}
@@ -256,7 +279,7 @@ DxePcdGetPtrEx ( IN UINTN ExTokenNumber
)
{
- return ExGetWorker (Guid, ExTokenNumber, 0);
+ return ExGetWorker (Guid, ExTokenNumber, 0);
}
@@ -292,7 +315,7 @@ DxePcdSet8 ( IN UINT8 Value
)
{
- return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
+ return SetValueWorker (TokenNumber, &Value, sizeof (Value));
}
@@ -304,7 +327,7 @@ DxePcdSet16 ( IN UINT16 Value
)
{
- return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
+ return SetValueWorker (TokenNumber, &Value, sizeof (Value));
}
@@ -316,7 +339,7 @@ DxePcdSet32 ( IN UINT32 Value
)
{
- return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
+ return SetValueWorker (TokenNumber, &Value, sizeof (Value));
}
@@ -328,7 +351,7 @@ DxePcdSet64 ( IN UINT64 Value
)
{
- return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
+ return SetValueWorker (TokenNumber, &Value, sizeof (Value));
}
@@ -336,9 +359,9 @@ DxePcdSet64 ( EFI_STATUS
EFIAPI
DxePcdSetPtr (
- IN UINTN TokenNumber,
- IN UINTN SizeOfBuffer,
- IN VOID *Buffer
+ IN UINTN TokenNumber,
+ IN OUT UINTN *SizeOfBuffer,
+ IN VOID *Buffer
)
{
return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);
@@ -353,7 +376,7 @@ DxePcdSetBool ( IN BOOLEAN Value
)
{
- return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
+ return SetValueWorker (TokenNumber, &Value, sizeof (Value));
}
@@ -366,13 +389,7 @@ DxePcdSet8Ex ( IN UINT8 Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- &Value,
- sizeof (Value),
- FALSE
- );
+ return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
}
@@ -385,13 +402,7 @@ DxePcdSet16Ex ( IN UINT16 Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- &Value,
- sizeof (Value),
- FALSE
- );
+ return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
}
@@ -404,13 +415,7 @@ DxePcdSet32Ex ( IN UINT32 Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- &Value,
- sizeof (Value),
- FALSE
- );
+ return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
}
@@ -423,13 +428,7 @@ DxePcdSet64Ex ( IN UINT64 Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- &Value,
- sizeof (Value),
- FALSE
- );
+ return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
}
@@ -437,19 +436,13 @@ DxePcdSet64Ex ( EFI_STATUS
EFIAPI
DxePcdSetPtrEx (
- IN CONST EFI_GUID *Guid,
- IN UINTN ExTokenNumber,
- IN UINTN SizeOfBuffer,
- IN VOID *Buffer
+ IN CONST EFI_GUID *Guid,
+ IN UINTN ExTokenNumber,
+ IN OUT UINTN *SizeOfBuffer,
+ IN VOID *Buffer
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- Buffer,
- SizeOfBuffer,
- TRUE
- );
+ return ExSetWorker(ExTokenNumber, Guid, Buffer, SizeOfBuffer, TRUE);
}
@@ -462,13 +455,7 @@ DxePcdSetBoolEx ( IN BOOLEAN Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- &Value,
- sizeof (Value),
- TRUE
- );
+ return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
}
diff --git a/EdkModulePkg/Universal/PCD/Dxe/Service.c b/EdkModulePkg/Universal/PCD/Dxe/Service.c index 771c4db54d..f175b14db2 100644 --- a/EdkModulePkg/Universal/PCD/Dxe/Service.c +++ b/EdkModulePkg/Universal/PCD/Dxe/Service.c @@ -35,20 +35,22 @@ GetWorker ( UINT32 *LocalTokenNumberTable;
UINT16 *SizeTable;
BOOLEAN IsPeiDb;
- UINTN Size;
UINT32 Offset;
EFI_GUID *GuidTable;
UINT16 *StringTable;
EFI_GUID *Guid;
UINT16 *Name;
VARIABLE_HEAD *VariableHead;
+ UINT8 *VaraiableDefaultBuffer;
EFI_STATUS Status;
UINTN DataSize;
- VOID *Data;
+ UINT8 *Data;
VPD_HEAD *VpdHead;
UINT8 *PcdDb;
UINT16 StringTableIdx;
UINT32 LocalTokenNumber;
+ UINTN MaxSize;
+ UINTN TmpTokenNumber;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
@@ -56,11 +58,12 @@ GetWorker ( // as the array index.
//
TokenNumber--;
+
+ TmpTokenNumber = TokenNumber;
ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);
- Size = DxePcdGetSize (TokenNumber + 1);
- ASSERT (GetSize == Size || GetSize == 0);
+ ASSERT ((GetSize == DxePcdGetSize (TokenNumber + 1)) || (GetSize == 0));
IsPeiDb = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TRUE : FALSE;
@@ -77,7 +80,12 @@ GetWorker ( LocalTokenNumber = LocalTokenNumberTable[TokenNumber];
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
- LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, Size, IsPeiDb);
+ if (GetSize == 0) {
+ GetPtrTypeSize (TmpTokenNumber, &MaxSize);
+ } else {
+ MaxSize = GetSize;
+ }
+ LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, MaxSize, IsPeiDb);
}
PcdDb = IsPeiDb ? ((UINT8 *) &mPcdDatabase->PeiDb) : ((UINT8 *) &mPcdDatabase->DxeDb);
@@ -86,7 +94,7 @@ GetWorker ( Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;
- switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {
+ switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
VpdHead = (VPD_HEAD *) ((UINT8 *) PcdDb + Offset);
return (VOID *) (UINTN) (FixedPcdGet32(PcdVpdBaseAddress) + VpdHead->Offset);
@@ -99,16 +107,31 @@ GetWorker ( Guid = &(GuidTable[VariableHead->GuidTableIndex]);
Name = &(StringTable[VariableHead->StringIndex]);
+ VaraiableDefaultBuffer = (UINT8 *) PcdDb + VariableHead->DefaultValueOffset;
Status = GetHiiVariable (Guid, Name, &Data, &DataSize);
if (Status == EFI_SUCCESS) {
- return (UINT8 *) Data + VariableHead->Offset;
- } else {
- //
- // Return the default value specified by Platform Integrator
- //
- return (VOID *) ((UINT8 *) PcdDb + VariableHead->DefaultValueOffset);
- }
+ if (GetSize == 0) {
+ //
+ // It is a pointer type. So get the MaxSize reserved for
+ // this PCD entry.
+ //
+ GetPtrTypeSize (TokenNumber, &GetSize);
+ }
+ CopyMem (VaraiableDefaultBuffer, Data + VariableHead->Offset, GetSize);
+ FreePool (Data);
+ }
+ //
+ // If the operation is successful, we copy the data
+ // to the default value buffer in the PCD Database.
+ // So that we can free the Data allocated in GetHiiVariable.
+ //
+ //
+ // If the operation is not successful,
+ // Return 1) either the default value specified by Platform Integrator
+ // 2) Or the value Set by a PCD set operation.
+ //
+ return (VOID *) VaraiableDefaultBuffer;
case PCD_TYPE_STRING:
StringTableIdx = (UINT16) *((UINT8 *) PcdDb + Offset);
@@ -352,7 +375,7 @@ EFI_STATUS GetHiiVariable (
IN EFI_GUID *VariableGuid,
IN UINT16 *VariableName,
- OUT VOID ** VariableData,
+ OUT VOID **VariableData,
OUT UINTN *VariableSize
)
{
@@ -372,7 +395,6 @@ GetHiiVariable ( );
if (Status == EFI_BUFFER_TOO_SMALL) {
-
Buffer = AllocatePool (Size);
ASSERT (Buffer != NULL);
@@ -386,13 +408,11 @@ GetHiiVariable ( );
ASSERT (Status == EFI_SUCCESS);
+ *VariableData = Buffer;
+ *VariableSize = Size;
}
- *VariableData = Buffer;
- *VariableSize = Size;
-
return Status;
-
}
@@ -429,7 +449,7 @@ GetSkuEnabledTokenNumber ( }
ASSERT (i < SkuIdTable[0]);
- switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {
+ switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
Value = (UINT8 *) &(((VPD_HEAD *) Value)[i]);
return (UINT32) ((Value - PcdDb) | PCD_TYPE_VPD);
@@ -437,11 +457,15 @@ GetSkuEnabledTokenNumber ( case PCD_TYPE_HII:
Value = (UINT8 *) &(((VARIABLE_HEAD *) Value)[i]);
return (UINT32) ((Value - PcdDb) | PCD_TYPE_HII);
+
+ case PCD_TYPE_STRING:
+ Value = (UINT8 *) &(((STRING_HEAD *) Value)[i]);
+ return (UINT32) ((Value - PcdDb) | PCD_TYPE_STRING);
case PCD_TYPE_DATA:
Value += Size * i;
return (UINT32) (Value - PcdDb);
-
+
default:
ASSERT (FALSE);
}
@@ -494,14 +518,23 @@ InvokeCallbackOnSet ( }
+EFI_STATUS
+SetValueWorker (
+ IN UINTN TokenNumber,
+ IN VOID *Data,
+ IN UINTN Size
+ )
+{
+ return SetWorker (TokenNumber, Data, &Size, FALSE);
+}
EFI_STATUS
SetWorker (
- UINTN TokenNumber,
- VOID *Data,
- UINTN Size,
- BOOLEAN PtrType
+ IN UINTN TokenNumber,
+ IN VOID *Data,
+ IN OUT UINTN *Size,
+ IN BOOLEAN PtrType
)
{
UINT32 *LocalTokenNumberTable;
@@ -516,6 +549,9 @@ SetWorker ( VARIABLE_HEAD *VariableHead;
UINTN Offset;
UINT8 *PcdDb;
+ EFI_STATUS Status;
+ UINTN MaxSize;
+ UINTN TmpTokenNumber;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
@@ -523,13 +559,13 @@ SetWorker ( // as the array index.
//
TokenNumber--;
+
+ TmpTokenNumber = TokenNumber;
ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);
- if (PtrType) {
- ASSERT (Size <= DxePcdGetSize (TokenNumber + 1));
- } else {
- ASSERT (Size == DxePcdGetSize (TokenNumber + 1));
+ if (!PtrType) {
+ ASSERT (*Size == DxePcdGetSize (TokenNumber + 1));
}
IsPeiDb = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TRUE : FALSE;
@@ -539,7 +575,7 @@ SetWorker ( if ((TokenNumber < PEI_NEX_TOKEN_NUMBER) ||
(TokenNumber >= PEI_LOCAL_TOKEN_NUMBER || TokenNumber < (PEI_LOCAL_TOKEN_NUMBER + DXE_NEX_TOKEN_NUMBER))) {
- InvokeCallbackOnSet (0, NULL, TokenNumber + 1, Data, Size);
+ InvokeCallbackOnSet (0, NULL, TokenNumber + 1, Data, *Size);
}
TokenNumber = IsPeiDb ? TokenNumber
@@ -548,7 +584,12 @@ SetWorker ( LocalTokenNumber = LocalTokenNumberTable[TokenNumber];
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
- LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, Size, IsPeiDb);
+ if (PtrType) {
+ GetPtrTypeSize (TmpTokenNumber, &MaxSize);
+ } else {
+ MaxSize = *Size;
+ }
+ LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, MaxSize, IsPeiDb);
}
Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;
@@ -560,19 +601,26 @@ SetWorker ( InternalData = PcdDb + Offset;
- switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {
+ switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
ASSERT (FALSE);
return EFI_INVALID_PARAMETER;
case PCD_TYPE_STRING:
- CopyMem (&StringTable[*((UINT16 *)InternalData)], Data, Size);
- return EFI_SUCCESS;
+ if (SetPtrTypeSize (TokenNumber, Size)) {
+ CopyMem (&StringTable[*((UINT16 *)InternalData)], Data, *Size);
+ return EFI_SUCCESS;
+ } else {
+ return EFI_INVALID_PARAMETER;
+ }
case PCD_TYPE_HII:
- //
- // Bug Bug: Please implement this
- //
+ if (PtrType) {
+ if (!SetPtrTypeSize (TokenNumber, Size)) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
GuidTable = IsPeiDb ? mPcdDatabase->PeiDb.Init.GuidTable :
mPcdDatabase->DxeDb.Init.GuidTable;
@@ -582,15 +630,30 @@ SetWorker ( Name = &(StringTable[VariableHead->StringIndex]);
VariableOffset = VariableHead->Offset;
- return SetHiiVariable (Guid, Name, Data, Size, VariableOffset);
+ Status = SetHiiVariable (Guid, Name, Data, *Size, VariableOffset);
+
+ if (EFI_NOT_FOUND == Status) {
+ CopyMem (PcdDb + VariableHead->DefaultValueOffset, Data, *Size);
+ return EFI_SUCCESS;
+ } else {
+ return Status;
+ }
+
+ //
+ // Bug Bug: Please implement this
+ //
case PCD_TYPE_DATA:
if (PtrType) {
- CopyMem (InternalData, Data, Size);
- return EFI_SUCCESS;
+ if (SetPtrTypeSize (TokenNumber, Size)) {
+ CopyMem (InternalData, Data, *Size);
+ return EFI_SUCCESS;
+ } else {
+ return EFI_INVALID_PARAMETER;
+ }
}
- switch (Size) {
+ switch (*Size) {
case sizeof(UINT8):
*((UINT8 *) InternalData) = *((UINT8 *) Data);
return EFI_SUCCESS;
@@ -638,26 +701,35 @@ ExGetWorker ( +EFI_STATUS
+ExSetValueWorker (
+ IN UINTN ExTokenNumber,
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN UINTN SetSize
+ )
+{
+ return ExSetWorker (ExTokenNumber, Guid, Data, &SetSize, FALSE);
+}
+
EFI_STATUS
ExSetWorker (
- IN UINTN ExTokenNumber,
- IN CONST EFI_GUID *Guid,
- VOID *Data,
- UINTN SetSize,
- BOOLEAN PtrType
+ IN UINTN ExTokenNumber,
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN OUT UINTN *SetSize,
+ IN BOOLEAN PtrType
)
{
UINTN TokenNumber;
TokenNumber = GetExPcdTokenNumber (Guid, (UINT32) ExTokenNumber);
- InvokeCallbackOnSet ((UINT32) ExTokenNumber, Guid, TokenNumber, Data, SetSize);
+ InvokeCallbackOnSet ((UINT32) ExTokenNumber, Guid, TokenNumber, Data, *SetSize);
- SetWorker (TokenNumber, Data, SetSize, PtrType);
+ return SetWorker (TokenNumber, Data, SetSize, PtrType);
- return EFI_SUCCESS;
-
}
@@ -705,24 +777,25 @@ SetHiiVariable ( CopyMem ((UINT8 *)Buffer + Offset, Data, DataSize);
- } else {
-
- Attribute = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
- Size = DataSize + Offset;
- Buffer = AllocateZeroPool (Size);
- ASSERT (Buffer != NULL);
- CopyMem ((UINT8 *)Buffer + Offset, Data, DataSize);
-
- }
+ Status = EfiSetVariable (
+ VariableName,
+ VariableGuid,
+ Attribute,
+ Size,
+ Buffer
+ );
- return EfiSetVariable (
- VariableName,
- VariableGuid,
- Attribute,
- Size,
- Buffer
- );
+ FreePool (Buffer);
+ return Status;
+ }
+
+ //
+ // If we drop to here, we don't have a Variable entry in
+ // the variable service yet. So, we will save the data
+ // in the PCD Database's volatile area.
+ //
+ return Status;
}
@@ -785,3 +858,258 @@ GetExPcdTokenNumber ( return 0;
}
+
+
+SKU_ID *
+GetSkuIdArray (
+ IN UINTN LocalTokenNumberTableIdx,
+ IN BOOLEAN IsPeiPcd
+ )
+{
+ SKU_HEAD *SkuHead;
+ UINTN LocalTokenNumber;
+ UINT8 *Database;
+
+ if (IsPeiPcd) {
+ LocalTokenNumber = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];
+ Database = (UINT8 *) &mPcdDatabase->PeiDb;
+ } else {
+ LocalTokenNumber = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable[LocalTokenNumberTableIdx - PEI_LOCAL_TOKEN_NUMBER];
+ Database = (UINT8 *) &mPcdDatabase->DxeDb;
+ }
+
+ ASSERT ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) != 0);
+
+ SkuHead = (SKU_HEAD *) ((UINT8 *)Database + (LocalTokenNumber & PCD_DATABASE_OFFSET_MASK));
+
+ return (SKU_ID *) (Database + SkuHead->SkuIdTableOffset);
+
+}
+
+
+
+UINTN
+GetSizeTableIndexA (
+ IN UINTN LocalTokenNumberTableIdx,
+ IN UINT32 *LocalTokenNumberTable,
+ IN BOOLEAN IsPeiDb
+ )
+{
+ UINTN i;
+ UINTN SizeTableIdx;
+ UINTN LocalTokenNumber;
+ SKU_ID *SkuIdTable;
+
+ SizeTableIdx = 0;
+
+ for (i=0; i<LocalTokenNumberTableIdx; i++) {
+ LocalTokenNumber = LocalTokenNumberTable[i];
+
+ 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) {
+ //
+ // We have only one entry for VPD enabled PCD entry:
+ // 1) MAX Size.
+ // We consider current size is equal to MAX size.
+ //
+ SizeTableIdx++;
+ } else {
+ if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
+ //
+ // We have only two entry for Non-Sku enabled PCD entry:
+ // 1) MAX SIZE
+ // 2) Current Size
+ //
+ SizeTableIdx += 2;
+ } else {
+ //
+ // We have these entry for SKU enabled PCD entry
+ // 1) MAX SIZE
+ // 2) Current Size for each SKU_ID (It is equal to MaxSku).
+ //
+ SkuIdTable = GetSkuIdArray (i, IsPeiDb);
+ SizeTableIdx += (UINTN)*SkuIdTable + 1;
+ }
+ }
+ }
+
+ }
+
+ return SizeTableIdx;
+}
+
+
+
+
+UINTN
+GetSizeTableIndex (
+ IN UINTN LocalTokenNumberTableIdx,
+ IN BOOLEAN IsPeiDb
+ )
+{
+ UINT32 *LocalTokenNumberTable;
+
+ if (IsPeiDb) {
+ LocalTokenNumberTable = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable;
+ } else {
+ LocalTokenNumberTable = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
+ }
+ return GetSizeTableIndexA (LocalTokenNumberTableIdx,
+ LocalTokenNumberTable,
+ IsPeiDb);
+}
+
+
+
+UINTN
+GetPtrTypeSize (
+ IN UINTN LocalTokenNumberTableIdx,
+ OUT UINTN *MaxSize
+ )
+{
+ INTN SizeTableIdx;
+ UINTN LocalTokenNumber;
+ SKU_ID *SkuIdTable;
+ SIZE_INFO *SizeTable;
+ UINTN i;
+ BOOLEAN IsPeiDb;
+ UINT32 *LocalTokenNumberTable;
+
+ IsPeiDb = (BOOLEAN) (LocalTokenNumberTableIdx < PEI_LOCAL_TOKEN_NUMBER);
+
+
+ if (IsPeiDb) {
+ LocalTokenNumberTable = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable;
+ SizeTable = mPcdDatabase->PeiDb.Init.SizeTable;
+ } else {
+ LocalTokenNumberTableIdx -= PEI_LOCAL_TOKEN_NUMBER;
+ LocalTokenNumberTable = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
+ SizeTable = mPcdDatabase->DxeDb.Init.SizeTable;
+ }
+
+ LocalTokenNumber = LocalTokenNumberTable[LocalTokenNumberTableIdx];
+
+ ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
+
+ SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, IsPeiDb);
+
+ *MaxSize = SizeTable[SizeTableIdx];
+ //
+ // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
+ // PCD entry.
+ //
+ if (LocalTokenNumber & PCD_TYPE_VPD) {
+ //
+ // We have only one entry for VPD enabled PCD entry:
+ // 1) MAX Size.
+ // We consider current size is equal to MAX size.
+ //
+ return *MaxSize;
+ } else {
+ if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
+ //
+ // We have only two entry for Non-Sku enabled PCD entry:
+ // 1) MAX SIZE
+ // 2) Current Size
+ //
+ return SizeTable[SizeTableIdx + 1];
+ } else {
+ //
+ // We have these entry for SKU enabled PCD entry
+ // 1) MAX SIZE
+ // 2) Current Size for each SKU_ID (It is equal to MaxSku).
+ //
+ SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, IsPeiDb);
+ for (i = 0; i < SkuIdTable[0]; i++) {
+ if (SkuIdTable[1 + i] == mPcdDatabase->PeiDb.Init.SystemSkuId) {
+ return SizeTable[SizeTableIdx + 1 + i];
+ }
+ }
+ return SizeTable[SizeTableIdx + 1];
+ }
+ }
+}
+
+
+
+BOOLEAN
+SetPtrTypeSize (
+ IN UINTN LocalTokenNumberTableIdx,
+ IN OUT UINTN *CurrentSize
+ )
+{
+ INTN SizeTableIdx;
+ UINTN LocalTokenNumber;
+ SKU_ID *SkuIdTable;
+ SIZE_INFO *SizeTable;
+ UINTN i;
+ UINTN MaxSize;
+ BOOLEAN IsPeiDb;
+ UINT32 *LocalTokenNumberTable;
+
+ IsPeiDb = (BOOLEAN) (LocalTokenNumberTableIdx < PEI_LOCAL_TOKEN_NUMBER);
+
+ if (IsPeiDb) {
+ LocalTokenNumberTable = mPcdDatabase->PeiDb.Init.LocalTokenNumberTable;
+ SizeTable = mPcdDatabase->PeiDb.Init.SizeTable;
+ } else {
+ LocalTokenNumberTableIdx -= PEI_LOCAL_TOKEN_NUMBER;
+ LocalTokenNumberTable = mPcdDatabase->DxeDb.Init.LocalTokenNumberTable;
+ SizeTable = mPcdDatabase->DxeDb.Init.SizeTable;
+ }
+
+ LocalTokenNumber = LocalTokenNumberTable[LocalTokenNumberTableIdx];
+
+ ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
+
+ SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, IsPeiDb);
+
+ MaxSize = SizeTable[SizeTableIdx];
+ //
+ // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
+ // PCD entry.
+ //
+ if (LocalTokenNumber & PCD_TYPE_VPD) {
+ //
+ // We shouldn't come here as we don't support SET for VPD
+ //
+ ASSERT (FALSE);
+ return FALSE;
+ } else {
+ if ((*CurrentSize > MaxSize) ||
+ (*CurrentSize == MAX_ADDRESS)) {
+ *CurrentSize = MaxSize;
+ return FALSE;
+ }
+
+ if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
+ //
+ // We have only two entry for Non-Sku enabled PCD entry:
+ // 1) MAX SIZE
+ // 2) Current Size
+ //
+ SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
+ return TRUE;
+ } else {
+ //
+ // We have these entry for SKU enabled PCD entry
+ // 1) MAX SIZE
+ // 2) Current Size for each SKU_ID (It is equal to MaxSku).
+ //
+ SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, IsPeiDb);
+ for (i = 0; i < SkuIdTable[0]; i++) {
+ if (SkuIdTable[1 + i] == mPcdDatabase->PeiDb.Init.SystemSkuId) {
+ SizeTable[SizeTableIdx + 1 + i] = (SIZE_INFO) *CurrentSize;
+ return TRUE;
+ }
+ }
+ SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
+ return TRUE;
+ }
+ }
+}
+
diff --git a/EdkModulePkg/Universal/PCD/Dxe/Service.h b/EdkModulePkg/Universal/PCD/Dxe/Service.h index c8bec08539..7628900596 100644 --- a/EdkModulePkg/Universal/PCD/Dxe/Service.h +++ b/EdkModulePkg/Universal/PCD/Dxe/Service.h @@ -45,29 +45,49 @@ typedef struct { //
EFI_STATUS
+SetValueWorker (
+ IN UINTN TokenNumber,
+ IN VOID *Data,
+ IN UINTN Size
+ )
+;
+
+EFI_STATUS
SetWorker (
- IN UINTN TokenNumber,
- IN VOID *Data,
- IN UINTN Size,
- IN BOOLEAN PtrType
+ IN UINTN TokenNumber,
+ IN VOID *Data,
+ IN OUT UINTN *Size,
+ IN BOOLEAN PtrType
+ )
+;
+
+
+EFI_STATUS
+ExSetValueWorker (
+ IN UINTN ExTokenNumber,
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN UINTN SetSize
)
;
+
+
EFI_STATUS
ExSetWorker (
- IN UINTN ExTokenNumber,
- IN CONST EFI_GUID *Guid,
- VOID *Data,
- UINTN Size,
- BOOLEAN PtrType
+ IN UINTN ExTokenNumber,
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN OUT UINTN *Size,
+ IN BOOLEAN PtrType
)
;
VOID *
GetWorker (
- UINTN TokenNumber,
- UINTN GetSize
+ IN UINTN TokenNumber,
+ IN UINTN GetSize
)
;
@@ -132,6 +152,24 @@ GetExPcdTokenNumber ( IN UINT32 ExTokenNumber
)
;
+
+
+UINTN
+GetPtrTypeSize (
+ IN UINTN LocalTokenNumberTableIdx,
+ OUT UINTN *MaxSize
+ )
+;
+
+
+
+BOOLEAN
+SetPtrTypeSize (
+ IN UINTN LocalTokenNumberTableIdx,
+ IN OUT UINTN *CurrentSize
+ )
+;
+
//
// Protocol Interface function declaration.
//
@@ -303,9 +341,9 @@ DxePcdSet64 ( EFI_STATUS
EFIAPI
DxePcdSetPtr (
- IN UINTN TokenNumber,
- IN UINTN SizeOfBuffer,
- IN VOID *Buffer
+ IN UINTN TokenNumber,
+ IN UINTN *SizeOfBuffer,
+ IN VOID *Buffer
)
;
@@ -362,10 +400,10 @@ DxePcdSet64Ex ( EFI_STATUS
EFIAPI
DxePcdSetPtrEx (
- IN CONST EFI_GUID *Guid,
- IN UINTN TokenNumber,
- IN UINTN SizeOfBuffer,
- IN VOID *Buffer
+ IN CONST EFI_GUID *Guid,
+ IN UINTN TokenNumber,
+ IN OUT UINTN *SizeOfBuffer,
+ IN VOID *Buffer
)
;
diff --git a/EdkModulePkg/Universal/PCD/Pei/Pcd.c b/EdkModulePkg/Universal/PCD/Pei/Pcd.c index dfcb56981e..a2b5701f13 100644 --- a/EdkModulePkg/Universal/PCD/Pei/Pcd.c +++ b/EdkModulePkg/Universal/PCD/Pei/Pcd.c @@ -170,6 +170,11 @@ PeiPcdGetSize ( IN UINTN TokenNumber
)
{
+ PEI_PCD_DATABASE *PeiPcdDb;
+ UINTN Size;
+ UINTN MaxSize;
+
+ PeiPcdDb = GetPcdDatabase ();
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
@@ -179,7 +184,17 @@ PeiPcdGetSize ( ASSERT (TokenNumber < PEI_LOCAL_TOKEN_NUMBER);
- return GetPcdDatabase()->Init.SizeTable[TokenNumber];
+ Size = (PeiPcdDb->Init.LocalTokenNumberTable[TokenNumber] & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;
+
+ if (Size == 0) {
+ //
+ // For pointer type, we need to scan the SIZE_TABLE to get the current size.
+ //
+ return GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);
+ } else {
+ return Size;
+ }
+
}
@@ -272,10 +287,10 @@ EFI_STATUS EFIAPI
PeiPcdSet8 (
IN UINTN TokenNumber,
- IN UINT8 Value
+ IN UINT8 Value
)
{
- return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
+ return SetValueWorker (TokenNumber, &Value, sizeof (Value));
}
@@ -283,11 +298,11 @@ PeiPcdSet8 ( EFI_STATUS
EFIAPI
PeiPcdSet16 (
- IN UINTN TokenNumber,
- IN UINT16 Value
+ IN UINTN TokenNumber,
+ IN UINT16 Value
)
{
- return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
+ return SetValueWorker (TokenNumber, &Value, sizeof (Value));
}
@@ -295,11 +310,11 @@ PeiPcdSet16 ( EFI_STATUS
EFIAPI
PeiPcdSet32 (
- IN UINTN TokenNumber,
- IN UINT32 Value
+ IN UINTN TokenNumber,
+ IN UINT32 Value
)
{
- return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
+ return SetValueWorker (TokenNumber, &Value, sizeof (Value));
}
@@ -307,20 +322,20 @@ PeiPcdSet32 ( EFI_STATUS
EFIAPI
PeiPcdSet64 (
- IN UINTN TokenNumber,
- IN UINT64 Value
+ IN UINTN TokenNumber,
+ IN UINT64 Value
)
{
- return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
+ return SetValueWorker (TokenNumber, &Value, sizeof (Value));
}
EFI_STATUS
EFIAPI
PeiPcdSetPtr (
- IN UINTN TokenNumber,
- IN UINTN SizeOfBuffer,
- IN VOID *Buffer
+ IN UINTN TokenNumber,
+ IN OUT UINTN *SizeOfBuffer,
+ IN VOID *Buffer
)
{
return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);
@@ -331,11 +346,11 @@ PeiPcdSetPtr ( EFI_STATUS
EFIAPI
PeiPcdSetBool (
- IN UINTN TokenNumber,
- IN BOOLEAN Value
+ IN UINTN TokenNumber,
+ IN BOOLEAN Value
)
{
- return SetWorker (TokenNumber, &Value, sizeof (Value), FALSE);
+ return SetValueWorker (TokenNumber, &Value, sizeof (Value));
}
@@ -348,13 +363,7 @@ PeiPcdSet8Ex ( IN UINT8 Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- &Value,
- sizeof (Value),
- FALSE
- );
+ return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
}
@@ -367,13 +376,7 @@ PeiPcdSet16Ex ( IN UINT16 Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- &Value,
- sizeof (Value),
- FALSE
- );
+ return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
}
@@ -386,13 +389,7 @@ PeiPcdSet32Ex ( IN UINT32 Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- &Value,
- sizeof (Value),
- FALSE
- );
+ return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
}
@@ -405,13 +402,7 @@ PeiPcdSet64Ex ( IN UINT64 Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- &Value,
- sizeof (Value),
- FALSE
- );
+ return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
}
@@ -421,17 +412,11 @@ EFIAPI PeiPcdSetPtrEx (
IN CONST EFI_GUID *Guid,
IN UINTN ExTokenNumber,
- IN UINTN SizeOfBuffer,
+ IN UINTN *SizeOfBuffer,
IN VOID *Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- Value,
- SizeOfBuffer,
- TRUE
- );
+ return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);
}
@@ -444,13 +429,7 @@ PeiPcdSetBoolEx ( IN BOOLEAN Value
)
{
- return ExSetWorker(
- ExTokenNumber,
- Guid,
- &Value,
- sizeof (Value),
- FALSE
- );
+ return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));
}
@@ -567,6 +546,8 @@ PeiPcdGetNextToken ( return EFI_SUCCESS;
}
+
+
EFI_STATUS
EFIAPI
PeiPcdGetNextTokenSpace (
diff --git a/EdkModulePkg/Universal/PCD/Pei/Service.c b/EdkModulePkg/Universal/PCD/Pei/Service.c index a85d1d1786..0004bc6c76 100644 --- a/EdkModulePkg/Universal/PCD/Pei/Service.c +++ b/EdkModulePkg/Universal/PCD/Pei/Service.c @@ -68,6 +68,10 @@ PeiRegisterCallBackWorker ( LocalTokenNumber = GetPcdDatabase()->Init.LocalTokenNumberTable[TokenNumber];
+ //
+ // We don't support SET for HII and VPD type PCD entry in PEI phase.
+ // So we will assert if any register callback for such PCD entry.
+ //
ASSERT ((LocalTokenNumber & PCD_TYPE_HII) == 0);
ASSERT ((LocalTokenNumber & PCD_TYPE_VPD) == 0);
@@ -223,19 +227,23 @@ GetSkuEnabledTokenNumber ( }
}
- switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {
+ switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
- Value += sizeof(VPD_HEAD) * i;
+ Value = (UINT8 *) &(((VPD_HEAD *) Value)[i]);
return ((Value - (UINT8 *) PeiPcdDb) | PCD_TYPE_VPD);
case PCD_TYPE_HII:
- Value += sizeof(VARIABLE_HEAD) * i;
+ Value = (UINT8 *) &(((VARIABLE_HEAD *) Value)[i]);
return ((Value - (UINT8 *) PeiPcdDb) | PCD_TYPE_HII);
+ case PCD_TYPE_STRING:
+ Value = (UINT8 *) &(((STRING_HEAD *) Value)[i]);
+ return ((Value - (UINT8 *) PeiPcdDb) | PCD_TYPE_STRING);
+
case PCD_TYPE_DATA:
Value += Size * i;
return (Value - (UINT8 *) PeiPcdDb);
-
+
default:
ASSERT (FALSE);
}
@@ -293,13 +301,24 @@ InvokeCallbackOnSet ( +EFI_STATUS
+SetValueWorker (
+ IN UINTN TokenNumber,
+ IN VOID *Data,
+ IN UINTN Size
+ )
+{
+ return SetWorker (TokenNumber, Data, &Size, FALSE);
+}
+
+
EFI_STATUS
SetWorker (
- UINTN TokenNumber,
- VOID *Data,
- UINTN Size,
- BOOLEAN PtrType
+ IN UINTN TokenNumber,
+ IN OUT VOID *Data,
+ IN OUT UINTN *Size,
+ IN BOOLEAN PtrType
)
{
UINT32 LocalTokenNumber;
@@ -307,6 +326,7 @@ SetWorker ( UINT16 StringTableIdx;
UINTN Offset;
VOID *InternalData;
+ UINTN MaxSize;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
@@ -321,10 +341,8 @@ SetWorker ( LocalTokenNumber = PeiPcdDb->Init.LocalTokenNumberTable[TokenNumber];
- if (PtrType) {
- ASSERT (PeiPcdDb->Init.SizeTable[TokenNumber] >= Size);
- } else {
- ASSERT (PeiPcdDb->Init.SizeTable[TokenNumber] == Size);
+ if (!PtrType) {
+ ASSERT (PeiPcdGetSize(TokenNumber + 1) == *Size);
}
//
@@ -333,17 +351,22 @@ SetWorker ( // type PCD entry in ExSetWorker.
//
if (TokenNumber < PEI_NEX_TOKEN_NUMBER) {
- InvokeCallbackOnSet (0, NULL, TokenNumber + 1, Data, Size);
+ InvokeCallbackOnSet (0, NULL, TokenNumber + 1, Data, *Size);
}
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
- LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, Size);
+ if (PtrType) {
+ MaxSize = GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);
+ } else {
+ MaxSize = *Size;
+ }
+ LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, MaxSize);
}
Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;
InternalData = (VOID *) ((UINT8 *) PeiPcdDb + Offset);
- switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {
+ switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
case PCD_TYPE_HII:
{
@@ -352,19 +375,26 @@ SetWorker ( }
case PCD_TYPE_STRING:
- StringTableIdx = *((UINT16 *)InternalData);
- CopyMem (&PeiPcdDb->Init.StringTable[StringTableIdx], Data, Size);
- return EFI_SUCCESS;
+ if (SetPtrTypeSize (TokenNumber, Size, PeiPcdDb)) {
+ StringTableIdx = *((UINT16 *)InternalData);
+ CopyMem (&PeiPcdDb->Init.StringTable[StringTableIdx], Data, *Size);
+ return EFI_SUCCESS;
+ } else {
+ return EFI_INVALID_PARAMETER;
+ }
case PCD_TYPE_DATA:
{
-
if (PtrType) {
- CopyMem (InternalData, Data, Size);
- return EFI_SUCCESS;
+ if (SetPtrTypeSize (TokenNumber, Size, PeiPcdDb)) {
+ CopyMem (InternalData, Data, *Size);
+ return EFI_SUCCESS;
+ } else {
+ return EFI_INVALID_PARAMETER;
+ }
}
- switch (Size) {
+ switch (*Size) {
case sizeof(UINT8):
*((UINT8 *) InternalData) = *((UINT8 *) Data);
return EFI_SUCCESS;
@@ -396,26 +426,36 @@ SetWorker ( +EFI_STATUS
+ExSetValueWorker (
+ IN UINTN ExTokenNumber,
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN UINTN Size
+ )
+{
+ return ExSetWorker (ExTokenNumber, Guid, Data, &Size, FALSE);
+}
+
+
EFI_STATUS
ExSetWorker (
- IN UINTN ExTokenNumber,
- IN CONST EFI_GUID *Guid,
- VOID *Data,
- UINTN Size,
- BOOLEAN PtrType
+ IN UINTN ExTokenNumber,
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN OUT UINTN *Size,
+ IN BOOLEAN PtrType
)
{
UINTN TokenNumber;
TokenNumber = GetExPcdTokenNumber (Guid, ExTokenNumber);
- InvokeCallbackOnSet (ExTokenNumber, Guid, TokenNumber, Data, Size);
+ InvokeCallbackOnSet (ExTokenNumber, Guid, TokenNumber, Data, *Size);
- SetWorker (TokenNumber, Data, Size, PtrType);
+ return SetWorker (TokenNumber, Data, Size, PtrType);
- return EFI_SUCCESS;
-
}
@@ -451,7 +491,7 @@ GetWorker ( UINT16 StringTableIdx;
PEI_PCD_DATABASE *PeiPcdDb;
UINT32 LocalTokenNumber;
- UINTN Size;
+ UINTN MaxSize;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
@@ -462,22 +502,25 @@ GetWorker ( ASSERT (TokenNumber < PEI_LOCAL_TOKEN_NUMBER);
- Size = PeiPcdGetSize(TokenNumber + 1);
-
- ASSERT (GetSize == Size || GetSize == 0);
+ ASSERT ((GetSize == PeiPcdGetSize(TokenNumber + 1)) || (GetSize == 0));
PeiPcdDb = GetPcdDatabase ();
LocalTokenNumber = PeiPcdDb->Init.LocalTokenNumberTable[TokenNumber];
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
- LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, Size);
+ if (GetSize == 0) {
+ MaxSize = GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);
+ } else {
+ MaxSize = GetSize;
+ }
+ LocalTokenNumber = GetSkuEnabledTokenNumber (LocalTokenNumber & ~PCD_TYPE_SKU_ENABLED, MaxSize);
}
Offset = LocalTokenNumber & PCD_DATABASE_OFFSET_MASK;
StringTable = PeiPcdDb->Init.StringTable;
- switch (LocalTokenNumber & ~PCD_DATABASE_OFFSET_MASK) {
+ switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
case PCD_TYPE_VPD:
{
VPD_HEAD *VpdHead;
@@ -578,3 +621,208 @@ GetPcdDatabase ( return (PEI_PCD_DATABASE *) GET_GUID_HOB_DATA (GuidHob);
}
+
+SKU_ID *
+GetSkuIdArray (
+ IN UINTN LocalTokenNumberTableIdx,
+ IN PEI_PCD_DATABASE *Database
+ )
+{
+ SKU_HEAD *SkuHead;
+ UINTN LocalTokenNumber;
+
+ LocalTokenNumber = Database->Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];
+
+ ASSERT ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) != 0);
+
+ SkuHead = (SKU_HEAD *) ((UINT8 *)Database + (LocalTokenNumber & PCD_DATABASE_OFFSET_MASK));
+
+ return (SKU_ID *) ((UINT8 *)Database + SkuHead->SkuIdTableOffset);
+
+}
+
+
+
+UINTN
+GetSizeTableIndex (
+ IN UINTN LocalTokenNumberTableIdx,
+ IN PEI_PCD_DATABASE *Database
+ )
+{
+ UINTN i;
+ UINTN SizeTableIdx;
+ UINTN LocalTokenNumber;
+ SKU_ID *SkuIdTable;
+
+ SizeTableIdx = 0;
+
+ for (i=0; i<LocalTokenNumberTableIdx; i++) {
+ LocalTokenNumber = Database->Init.LocalTokenNumberTable[i];
+
+ 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) {
+ //
+ // We have only one entry for VPD enabled PCD entry:
+ // 1) MAX Size.
+ // We consider current size is equal to MAX size.
+ //
+ SizeTableIdx++;
+ } else {
+ if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
+ //
+ // We have only two entry for Non-Sku enabled PCD entry:
+ // 1) MAX SIZE
+ // 2) Current Size
+ //
+ SizeTableIdx += 2;
+ } else {
+ //
+ // We have these entry for SKU enabled PCD entry
+ // 1) MAX SIZE
+ // 2) Current Size for each SKU_ID (It is equal to MaxSku).
+ //
+ SkuIdTable = GetSkuIdArray (i, Database);
+ SizeTableIdx += (UINTN)*SkuIdTable + 1;
+ }
+ }
+ }
+
+ }
+
+ return SizeTableIdx;
+}
+
+
+
+
+UINTN
+GetPtrTypeSize (
+ IN UINTN LocalTokenNumberTableIdx,
+ OUT UINTN *MaxSize,
+ IN PEI_PCD_DATABASE *Database
+ )
+{
+ INTN SizeTableIdx;
+ UINTN LocalTokenNumber;
+ SKU_ID *SkuIdTable;
+ SIZE_INFO *SizeTable;
+ UINTN i;
+
+ SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);
+
+ LocalTokenNumber = Database->Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];
+
+ ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
+
+ SizeTable = Database->Init.SizeTable;
+
+ *MaxSize = SizeTable[SizeTableIdx];
+ //
+ // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
+ // PCD entry.
+ //
+ if (LocalTokenNumber & PCD_TYPE_VPD) {
+ //
+ // We have only one entry for VPD enabled PCD entry:
+ // 1) MAX Size.
+ // We consider current size is equal to MAX size.
+ //
+ return *MaxSize;
+ } else {
+ if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
+ //
+ // We have only two entry for Non-Sku enabled PCD entry:
+ // 1) MAX SIZE
+ // 2) Current Size
+ //
+ return SizeTable[SizeTableIdx + 1];
+ } else {
+ //
+ // We have these entry for SKU enabled PCD entry
+ // 1) MAX SIZE
+ // 2) Current Size for each SKU_ID (It is equal to MaxSku).
+ //
+ SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);
+ for (i = 0; i < SkuIdTable[0]; i++) {
+ if (SkuIdTable[1 + i] == Database->Init.SystemSkuId) {
+ return SizeTable[SizeTableIdx + 1 + i];
+ }
+ }
+ return SizeTable[SizeTableIdx + 1];
+ }
+ }
+}
+
+
+
+BOOLEAN
+SetPtrTypeSize (
+ IN UINTN LocalTokenNumberTableIdx,
+ IN OUT UINTN *CurrentSize,
+ IN PEI_PCD_DATABASE *Database
+ )
+{
+ INTN SizeTableIdx;
+ UINTN LocalTokenNumber;
+ SKU_ID *SkuIdTable;
+ SIZE_INFO *SizeTable;
+ UINTN i;
+ UINTN MaxSize;
+
+ SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);
+
+ LocalTokenNumber = Database->Init.LocalTokenNumberTable[LocalTokenNumberTableIdx];
+
+ ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);
+
+ SizeTable = Database->Init.SizeTable;
+
+ MaxSize = SizeTable[SizeTableIdx];
+ //
+ // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type
+ // PCD entry.
+ //
+ if (LocalTokenNumber & PCD_TYPE_VPD) {
+ //
+ // We shouldn't come here as we don't support SET for VPD
+ //
+ ASSERT (FALSE);
+ return FALSE;
+ } else {
+ if ((*CurrentSize > MaxSize) ||
+ (*CurrentSize == MAX_ADDRESS)) {
+ *CurrentSize = MaxSize;
+ return FALSE;
+ }
+
+ if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {
+ //
+ // We have only two entry for Non-Sku enabled PCD entry:
+ // 1) MAX SIZE
+ // 2) Current Size
+ //
+ SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
+ return TRUE;
+ } else {
+ //
+ // We have these entry for SKU enabled PCD entry
+ // 1) MAX SIZE
+ // 2) Current Size for each SKU_ID (It is equal to MaxSku).
+ //
+ SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);
+ for (i = 0; i < SkuIdTable[0]; i++) {
+ if (SkuIdTable[1 + i] == Database->Init.SystemSkuId) {
+ SizeTable[SizeTableIdx + 1 + i] = (SIZE_INFO) *CurrentSize;
+ return TRUE;
+ }
+ }
+ SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;
+ return TRUE;
+ }
+ }
+
+}
diff --git a/EdkModulePkg/Universal/PCD/Pei/Service.h b/EdkModulePkg/Universal/PCD/Pei/Service.h index d3e7139ff4..4dbf7610ba 100644 --- a/EdkModulePkg/Universal/PCD/Pei/Service.h +++ b/EdkModulePkg/Universal/PCD/Pei/Service.h @@ -40,25 +40,49 @@ GetPcdDatabase ( )
;
+
+EFI_STATUS
+SetValueWorker (
+ IN UINTN TokenNumber,
+ IN VOID *Data,
+ IN UINTN Size
+ )
+;
+
+
EFI_STATUS
SetWorker (
- IN UINTN TokenNumber,
- IN VOID *Data,
- IN UINTN Size,
- IN BOOLEAN PtrType
+ IN UINTN TokenNumber,
+ IN VOID *Data,
+ IN OUT UINTN *Size,
+ IN BOOLEAN PtrType
)
;
+
+EFI_STATUS
+ExSetValueWorker (
+ IN UINTN ExTokenNumber,
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN UINTN Size
+ )
+;
+
+
+
EFI_STATUS
ExSetWorker (
- IN UINTN ExTokenNumber,
- IN CONST EFI_GUID *Guid,
- IN VOID *Data,
- IN UINTN Size,
- IN BOOLEAN PtrType
+ IN UINTN ExTokenNumber,
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN OUT UINTN *Size,
+ IN BOOLEAN PtrType
)
;
+
+
VOID *
GetWorker (
IN UINTN TokenNumber,
@@ -66,6 +90,8 @@ GetWorker ( )
;
+
+
VOID *
ExGetWorker (
IN CONST EFI_GUID *Guid,
@@ -109,6 +135,27 @@ BuildPcdDatabase ( ;
+
+
+UINTN
+GetPtrTypeSize (
+ IN UINTN LocalTokenNumberTableIdx,
+ OUT UINTN *MaxSize,
+ IN PEI_PCD_DATABASE *Database
+ )
+;
+
+
+
+BOOLEAN
+SetPtrTypeSize (
+ IN UINTN LocalTokenNumberTableIdx,
+ IN OUT UINTN *CurrentSize,
+ IN PEI_PCD_DATABASE *Database
+ )
+;
+
+
//
// PPI Interface Implementation Declaration.
//
@@ -276,9 +323,9 @@ PeiPcdSet64 ( EFI_STATUS
EFIAPI
PeiPcdSetPtr (
- IN UINTN TokenNumber,
- IN UINTN SizeOfBuffer,
- IN VOID *Buffer
+ IN UINTN TokenNumber,
+ IN OUT UINTN *SizeOfBuffer,
+ IN VOID *Buffer
)
;
@@ -334,10 +381,10 @@ PeiPcdSet64Ex ( EFI_STATUS
EFIAPI
PeiPcdSetPtrEx (
- IN CONST EFI_GUID *Guid,
- IN UINTN TokenNumber,
- IN UINTN SizeOfBuffer,
- IN VOID *Buffer
+ IN CONST EFI_GUID *Guid,
+ IN UINTN TokenNumber,
+ IN OUT UINTN *SizeOfBuffer,
+ IN VOID *Buffer
)
;
|