From 1de04b4f83050f9a8f6c3eedce27f841591972f3 Mon Sep 17 00:00:00 2001 From: qwang12 Date: Thu, 6 Jul 2006 06:10:20 +0000 Subject: [PATCH] Add in support for MaxSize and CurrentSize for PCD entry. Change the behavior for PcdSET for Variable_Enabled Pcd entry. If a Variable does not exist, we will only save the value to a volatile space. We save it to variable ONLY when the variable exist. Fix a few bugs in Pcd Build tool when generated Pcd database for Pcd entry with Unicode String type. Support PcdSet to return MaxSize if the input SizeOfBuffer is greater than the Max Size declared in FPD file. Add SetValueWorker and GetValueWoker for each PcdSET and PcdGET function to reduce code size. Sync function prototype definition for PCD_PPI_SET_POINTER, PCD_PPI_SET_EX_POINTER, PCD_PROTOCOL_SET_POINTER and PCD_PROTOCOL_SET_EX_POINTER with PCD arch spec 0.52. Add ASSERTION in LibPcdSetPtr. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@789 6f19259b-4bc3-4df7-8a09-765794883524 --- EdkModulePkg/Universal/PCD/Dxe/Pcd.c | 107 ++-- EdkModulePkg/Universal/PCD/Dxe/Service.c | 460 +++++++++++++++--- EdkModulePkg/Universal/PCD/Dxe/Service.h | 76 ++- EdkModulePkg/Universal/PCD/Pei/Pcd.c | 103 ++-- EdkModulePkg/Universal/PCD/Pei/Service.c | 322 ++++++++++-- EdkModulePkg/Universal/PCD/Pei/Service.h | 83 +++- MdePkg/Include/Ppi/Pcd.h | 14 +- MdePkg/Include/Protocol/Pcd.h | 16 +- MdePkg/Library/BasePcdLibNull/PcdLib.c | 2 + MdePkg/Library/DxePcdLib/DxePcdLib.c | 24 +- MdePkg/Library/PeiPcdLib/PeiPcdLib.c | 23 +- .../Pcd/PcdDatabaseCommonDefinitions.sample | 39 +- .../build/pcd/action/CollectPCDAction.java | 99 +++- .../org/tianocore/build/pcd/entity/Token.java | 73 ++- 14 files changed, 1091 insertions(+), 350 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 { + Status = EfiSetVariable ( + VariableName, + VariableGuid, + Attribute, + Size, + Buffer + ); - 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); - - } - - 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; iPeiDb.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 -SetWorker ( - IN UINTN TokenNumber, - IN VOID *Data, - IN UINTN Size, - IN BOOLEAN PtrType +SetValueWorker ( + IN UINTN TokenNumber, + IN VOID *Data, + IN UINTN Size ) ; +EFI_STATUS +SetWorker ( + 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; iInit.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 -SetWorker ( - IN UINTN TokenNumber, - IN VOID *Data, - IN UINTN Size, - IN BOOLEAN PtrType +SetValueWorker ( + IN UINTN TokenNumber, + 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 +SetWorker ( + 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 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 ) ; diff --git a/MdePkg/Include/Ppi/Pcd.h b/MdePkg/Include/Ppi/Pcd.h index a67e79c01c..2050d659de 100644 --- a/MdePkg/Include/Ppi/Pcd.h +++ b/MdePkg/Include/Ppi/Pcd.h @@ -152,9 +152,9 @@ EFI_STATUS typedef EFI_STATUS (EFIAPI *PCD_PPI_SET_POINTER) ( - IN UINTN TokenNumber, - IN UINTN SizeOfBuffer, - IN VOID *Buffer + IN UINTN TokenNumber, + IN OUT UINTN *SizeOfBuffer, + IN VOID *Buffer ); typedef @@ -199,10 +199,10 @@ EFI_STATUS typedef EFI_STATUS (EFIAPI *PCD_PPI_SET_EX_POINTER) ( - 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 ); typedef diff --git a/MdePkg/Include/Protocol/Pcd.h b/MdePkg/Include/Protocol/Pcd.h index 8869ad2be1..4127f73488 100644 --- a/MdePkg/Include/Protocol/Pcd.h +++ b/MdePkg/Include/Protocol/Pcd.h @@ -152,9 +152,9 @@ EFI_STATUS typedef EFI_STATUS (EFIAPI *PCD_PROTOCOL_SET_POINTER) ( - IN UINTN TokenNumber, - IN UINTN SizeOfBuffer, - IN VOID *Buffer + IN UINTN TokenNumber, + IN OUT UINTN *SizeOfBuffer, + IN VOID *Buffer ); typedef @@ -199,10 +199,10 @@ EFI_STATUS typedef EFI_STATUS (EFIAPI *PCD_PROTOCOL_SET_EX_POINTER) ( - 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 ); typedef @@ -228,7 +228,7 @@ typedef VOID (EFIAPI *PCD_PROTOCOL_CALLBACK) ( IN CONST EFI_GUID *CallBackGuid, OPTIONAL - IN UINTN CallBackToken, + IN UINTN CallBackToken, IN OUT VOID *TokenData, IN UINTN TokenDataSize ); diff --git a/MdePkg/Library/BasePcdLibNull/PcdLib.c b/MdePkg/Library/BasePcdLibNull/PcdLib.c index e58965cc68..ab6f711a00 100644 --- a/MdePkg/Library/BasePcdLibNull/PcdLib.c +++ b/MdePkg/Library/BasePcdLibNull/PcdLib.c @@ -463,6 +463,8 @@ LibPcdSetPtr ( IN VOID *Buffer ) { + ASSERT (SizeOfBuffer != NULL); + if (*SizeOfBuffer > 0) { ASSERT (Buffer != NULL); } diff --git a/MdePkg/Library/DxePcdLib/DxePcdLib.c b/MdePkg/Library/DxePcdLib/DxePcdLib.c index f0b0cbd8f6..2747df35c0 100644 --- a/MdePkg/Library/DxePcdLib/DxePcdLib.c +++ b/MdePkg/Library/DxePcdLib/DxePcdLib.c @@ -514,23 +514,19 @@ LibPcdSetPtr ( ) { EFI_STATUS Status; - UINTN Size; + + ASSERT (SizeOfBuffer != NULL); if (*SizeOfBuffer > 0) { ASSERT (Buffer != NULL); } - Size = LibPcdGetSize (TokenNumber); - - if (*SizeOfBuffer > Size) { - *SizeOfBuffer = Size; + Status = mPcd->SetPtr (TokenNumber, SizeOfBuffer, Buffer); + + if (EFI_ERROR (Status)) { return NULL; } - Status = mPcd->SetPtr (TokenNumber, *SizeOfBuffer, Buffer); - - ASSERT_EFI_ERROR (Status); - return Buffer; } @@ -728,7 +724,6 @@ LibPcdSetExPtr ( ) { EFI_STATUS Status; - UINTN Size; ASSERT (Guid != NULL); @@ -738,17 +733,12 @@ LibPcdSetExPtr ( ASSERT (Buffer != NULL); } + Status = mPcd->SetPtrEx (Guid, TokenNumber, SizeOfBuffer, Buffer); - Size = LibPcdGetExSize (Guid, TokenNumber); - if (*SizeOfBuffer > Size) { - *SizeOfBuffer = Size; + if (EFI_ERROR (Status)) { return NULL; } - Status = mPcd->SetPtrEx (Guid, TokenNumber, *SizeOfBuffer, Buffer); - - ASSERT_EFI_ERROR (Status); - return Buffer; } diff --git a/MdePkg/Library/PeiPcdLib/PeiPcdLib.c b/MdePkg/Library/PeiPcdLib/PeiPcdLib.c index bee5386097..b8a53185bd 100644 --- a/MdePkg/Library/PeiPcdLib/PeiPcdLib.c +++ b/MdePkg/Library/PeiPcdLib/PeiPcdLib.c @@ -586,7 +586,6 @@ LibPcdSetPtr ( { EFI_STATUS Status; PCD_PPI *PcdPpi; - UINTN Size; ASSERT (SizeOfBuffer != NULL); @@ -596,17 +595,12 @@ LibPcdSetPtr ( PcdPpi = GetPcdPpiPtr (); - Size = LibPcdGetSize (TokenNumber); - - if (*SizeOfBuffer > Size) { - *SizeOfBuffer = Size; + Status = PcdPpi->SetPtr (TokenNumber, SizeOfBuffer, Buffer); + + if (EFI_ERROR (Status)) { return NULL; } - Status = PcdPpi->SetPtr (TokenNumber, *SizeOfBuffer, Buffer); - - ASSERT_EFI_ERROR (Status); - return Buffer; } @@ -817,7 +811,6 @@ LibPcdSetExPtr ( { EFI_STATUS Status; PCD_PPI *PcdPpi; - UINTN Size; if (*SizeOfBuffer > 0) { ASSERT (Buffer != NULL); @@ -825,16 +818,12 @@ LibPcdSetExPtr ( PcdPpi = GetPcdPpiPtr (); - Size = LibPcdGetExSize (Guid, TokenNumber); - if (*SizeOfBuffer > Size) { - *SizeOfBuffer = Size; + Status = PcdPpi->SetPtrEx (Guid, TokenNumber, SizeOfBuffer, Buffer); + + if (EFI_ERROR (Status)) { return NULL; } - Status = PcdPpi->SetPtrEx (Guid, TokenNumber, *SizeOfBuffer, Buffer); - - ASSERT_EFI_ERROR (Status); - return Buffer; } diff --git a/Tools/Conf/Pcd/PcdDatabaseCommonDefinitions.sample b/Tools/Conf/Pcd/PcdDatabaseCommonDefinitions.sample index 7bdb28293c..7df1a5a6f4 100644 --- a/Tools/Conf/Pcd/PcdDatabaseCommonDefinitions.sample +++ b/Tools/Conf/Pcd/PcdDatabaseCommonDefinitions.sample @@ -7,17 +7,32 @@ // typedef UINT8 SKU_ID; -#define PCD_TYPE_SHIFT 24 +#define PCD_TYPE_SHIFT 28 + +#define PCD_TYPE_DATA (0x0 << PCD_TYPE_SHIFT) +#define PCD_TYPE_HII (0x8 << PCD_TYPE_SHIFT) +#define PCD_TYPE_VPD (0x4 << PCD_TYPE_SHIFT) +#define PCD_TYPE_SKU_ENABLED (0x2 << PCD_TYPE_SHIFT) +#define PCD_TYPE_STRING (0x1 << PCD_TYPE_SHIFT) + +#define PCD_TYPE_ALL_SET (PCD_TYPE_DATA | PCD_TYPE_HII | PCD_TYPE_VPD | PCD_TYPE_SKU_ENABLED | PCD_TYPE_STRING) + +#define PCD_DATUM_TYPE_SHIFT 24 + +#define PCD_DATUM_TYPE_POINTER (0x0 << PCD_DATUM_TYPE_SHIFT) +#define PCD_DATUM_TYPE_UINT8 (0x1 << PCD_DATUM_TYPE_SHIFT) +#define PCD_DATUM_TYPE_UINT16 (0x2 << PCD_DATUM_TYPE_SHIFT) +#define PCD_DATUM_TYPE_UINT32 (0x4 << PCD_DATUM_TYPE_SHIFT) +#define PCD_DATUM_TYPE_UINT64 (0x8 << PCD_DATUM_TYPE_SHIFT) + +#define PCD_DATUM_TYPE_ALL_SET (PCD_DATUM_TYPE_POINTER | \ + PCD_DATUM_TYPE_UINT8 | \ + PCD_DATUM_TYPE_UINT16 | \ + PCD_DATUM_TYPE_UINT32 | \ + PCD_DATUM_TYPE_UINT64) -#define PCD_TYPE_DATA (0x00 << PCD_TYPE_SHIFT) -#define PCD_TYPE_HII (0x80 << PCD_TYPE_SHIFT) -#define PCD_TYPE_VPD (0x40 << PCD_TYPE_SHIFT) -#define PCD_TYPE_SKU_ENABLED (0x20 << PCD_TYPE_SHIFT) -#define PCD_TYPE_STRING (0x10 << PCD_TYPE_SHIFT) - - -#define PCD_DATABASE_OFFSET_MASK (~(PCD_TYPE_HII | PCD_TYPE_VPD | PCD_TYPE_SKU_ENABLED | PCD_TYPE_STRING)) +#define PCD_DATABASE_OFFSET_MASK (~(PCD_TYPE_ALL_SET | PCD_DATUM_TYPE_ALL_SET)) typedef struct { UINT32 ExTokenNumber; @@ -46,11 +61,7 @@ typedef struct { typedef UINT16 STRING_HEAD; -typedef struct { - UINT32 LocalTokenNumber; - UINT16 TokenNumber; - UINT16 Size; -} SIZEINFO; +typedef UINT16 SIZE_INFO; #define offsetof(s,m) (UINT32) (UINTN) &(((s *)0)->m) diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java index 3a781c8001..396a1af442 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java @@ -229,16 +229,24 @@ class StringTable { **/ class SizeTable { - private ArrayList al; + private ArrayList> al; private ArrayList alComments; - private String phase; private int len; + private String phase; public SizeTable (String phase) { - this.phase = phase; - al = new ArrayList(); + al = new ArrayList>(); alComments = new ArrayList(); len = 0; + this.phase = phase; + } + + public String getSizeMacro () { + return String.format(PcdDatabase.SizeTableSizeMacro, phase, getSize()); + } + + private int getSize() { + return len == 0 ? 1 : len; } public void genCode (ArrayList declaList, HashMap instTable, String phase) { @@ -262,6 +270,7 @@ class SizeTable { } private ArrayList getInstantiation () { + final String comma = ","; ArrayList Output = new ArrayList(); Output.add("/* SizeTable */"); @@ -270,14 +279,23 @@ class SizeTable { Output.add("\t0"); } else { for (int index = 0; index < al.size(); index++) { - Integer n = al.get(index); - String str = "\t" + n.toString(); - - if (index != (al.size() - 1)) { - str += ","; + ArrayList ial = al.get(index); + + String str = "\t"; + + for (int index2 = 0; index2 < ial.size(); index2++) { + str += " " + ial.get(index2).toString(); + if (index2 != ial.size() - 1) { + str += comma; + } } str += " /* " + alComments.get(index) + " */"; + + if (index != (al.size() - 1)) { + str += comma; + } + Output.add(str); } @@ -287,20 +305,25 @@ class SizeTable { return Output; } - public int add (Token token) { - int index = len; + public void add (Token token) { - len++; - al.add(token.datumSize); + // + // We only have size information for POINTER type PCD entry. + // + if (token.datumType != Token.DATUM_TYPE.POINTER) { + return; + } + + ArrayList ial = token.getPointerTypeSize(); + + len+= ial.size(); + + al.add(ial); alComments.add(token.getPrimaryKeyString()); - return index; + return; } - public int getTableLen () { - return al.size() == 0 ? 1 : al.size(); - } - } /** @@ -344,7 +367,7 @@ class GuidTable { cCode += String.format(PcdDatabase.GuidTableDeclaration, phase); decl = new CStructTypeDeclaration ( name, - 8, + 4, cCode, true ); @@ -674,6 +697,25 @@ class LocalTokenNumberTable { str += " | PCD_TYPE_VPD"; } + switch (token.datumType) { + case UINT8: + case BOOLEAN: + str += " | PCD_DATUM_TYPE_UINT8"; + break; + case UINT16: + str += " | PCD_DATUM_TYPE_UINT16"; + break; + case UINT32: + str += " | PCD_DATUM_TYPE_UINT32"; + break; + case UINT64: + str += " | PCD_DATUM_TYPE_UINT64"; + break; + case POINTER: + str += " | PCD_DATUM_TYPE_POINTER"; + break; + } + al.add(str); alComment.add(token.getPrimaryKeyString()); @@ -851,7 +893,7 @@ class PcdDatabase { public final static String GuidTableDeclaration = "EFI_GUID GuidTable[%s_GUID_TABLE_SIZE];\r\n"; public final static String LocalTokenNumberTableDeclaration = "UINT32 LocalTokenNumberTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n"; public final static String StringTableDeclaration = "UINT16 StringTable[%s_STRING_TABLE_SIZE];\r\n"; - public final static String SizeTableDeclaration = "UINT16 SizeTable[%s_LOCAL_TOKEN_NUMBER_TABLE_SIZE];\r\n"; + public final static String SizeTableDeclaration = "SIZE_INFO SizeTable[%s_SIZE_TABLE_SIZE];\r\n"; public final static String SkuIdTableDeclaration = "UINT8 SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n"; @@ -860,6 +902,7 @@ class PcdDatabase { public final static String GuidTableSizeMacro = "#define %s_GUID_TABLE_SIZE %d\r\n"; public final static String LocalTokenNumberTableSizeMacro = "#define %s_LOCAL_TOKEN_NUMBER_TABLE_SIZE %d\r\n"; public final static String LocalTokenNumberSizeMacro = "#define %s_LOCAL_TOKEN_NUMBER %d\r\n"; + public final static String SizeTableSizeMacro = "#define %s_SIZE_TABLE_SIZE %d\r\n"; public final static String StringTableSizeMacro = "#define %s_STRING_TABLE_SIZE %d\r\n"; public final static String SkuIdTableSizeMacro = "#define %s_SKUID_TABLE_SIZE %d\r\n"; @@ -1144,6 +1187,7 @@ class PcdDatabase { macroStr += skuIdTable.getSizeMacro(); macroStr += localTokenNumberTable.getSizeMacro(); macroStr += exMapTable.getSizeMacro(); + macroStr += sizeTable.getSizeMacro(); // // Generate existance info Macro for all Tables @@ -1311,6 +1355,9 @@ class PcdDatabase { } } + // + // privateGlobalName and privateGlobalCCode is used to pass output to caller of getCDeclarationString + // private void getCDeclarationString(Token t) throws EntityException { @@ -1321,7 +1368,7 @@ class PcdDatabase { } String type = getCType(t); - if ((t.datumType == Token.DATUM_TYPE.POINTER) && (!t.isHiiEnable())) { + if ((t.datumType == Token.DATUM_TYPE.POINTER) && (!t.isHiiEnable()) && (!t.isUnicodeStringType())) { int bufferSize; if (t.isASCIIStringType()) { // @@ -3007,14 +3054,16 @@ public class CollectPCDAction { **/ public static void main(String argv[]) throws EntityException { CollectPCDAction ca = new CollectPCDAction(); - ca.setWorkspacePath("m:/tianocore/edk2"); - ca.setFPDFilePath("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd"); + String projectDir = "x:/edk2"; + ca.setWorkspacePath(projectDir); + ca.setFPDFilePath(projectDir + "/EdkNt32Pkg/Nt32.fpd"); ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL); GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db", - "m:/tianocore/edk2", + projectDir, "tools_def.txt"); + System.out.println("After initInfo!"); FpdParserTask fpt = new FpdParserTask(); - fpt.parseFpdFile(new File("m:/tianocore/edk2/EdkNt32Pkg/Nt32.fpd")); + fpt.parseFpdFile(new File(projectDir + "/EdkNt32Pkg/Nt32.fpd")); ca.execute(); } } diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java index 1ffad91183..94266cda36 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java @@ -574,7 +574,78 @@ public class Token { public int getSkuIdCount () { return this.skuData.size(); } - + + private void getCurrentSizeFromDefaultValue (String str, ArrayList al) { + if (isValidNullValue(str)) { + al.add(new Integer(0)); + } else { + // + // isValidNullValue has already make sure that str here + // always contain a valid default value of the following 3 + // cases: + // 1) "Hello world" //Assci string + // 2) L"Hello" //Unicode string + // 3) {0x01, 0x02, 0x03} //Byte stream + // + if (str.startsWith("\"")) { + al.add(new Integer(str.length() - 2)); + } else if (str.startsWith("L\"")){ + // + // Unicode is 2 bytes each. + // + al.add(new Integer((str.length() - 3) * 2)); + } else if (str.startsWith("{")) { + // + // We count the number of "," in the string. + // The number of byte is one plus the number of + // comma. + // + String str2 = str; + + int cnt = 0; + int pos = 0; + pos = str2.indexOf(",", 0); + while (pos != -1) { + cnt++; + pos++; + pos = str2.indexOf(",", pos); + } + cnt++; + al.add(new Integer(cnt)); + } + } + } + // + // This method can be used to get the MAX and current size + // for pointer type dynamic(ex) PCD entry + // + public ArrayList getPointerTypeSize () { + ArrayList al = new ArrayList(); + + // + // For VPD_enabled and HII_enabled, we can only return the MAX size. + // For the default DATA type dynamic PCD entry, we will return + // the MAX size and current size for each SKU_ID. + // + al.add(new Integer(this.datumSize)); + + if (!this.isVpdEnable()) { + int idx; + if (this.isHiiEnable()){ + for (idx = 0; idx < this.skuData.size(); idx++) { + String str = this.skuData.get(idx).value.hiiDefaultValue; + getCurrentSizeFromDefaultValue(str, al); + } + } else { + for (idx = 0; idx < this.skuData.size(); idx++) { + String str = this.skuData.get(idx).value.value; + getCurrentSizeFromDefaultValue(str, al); + } + } + } + + return al; + } /** Get default value for a token, For HII type, HiiDefaultValue of default