1) remove some dead code from WinNtBusDriver.c

2) change PCD_INVALID_TOKEN_NUMBER to 0 as stipulated in MWG spec and PCD spec.
3) support returning a Default Value when a read failure by variable service for PCD entry with Variable Enabled.
4) Remove a lot of unreferenced JAVA import from CollectPCDAction.java, PCDAutoGenAction.java, MemoryDatabaseManager.java, Token.java and UsageInstance.java.
5) Opimized to merge elements in all tables in PCD database for make the code compact.
6) Did a tighter check on how dynamic PCD entry is referenced in each module.
7) Update the PCD driver/PEIM and PCD database generation verion to 2.



git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@605 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12 2006-06-23 04:30:23 +00:00
parent 90f7b6a81b
commit 58f1099f3d
16 changed files with 945 additions and 201 deletions

View File

@ -183,7 +183,13 @@ DxePcdGetSize (
)
{
UINT16 * SizeTable;
//
// 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--;
SizeTable = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? mPcdDatabase->PeiDb.Init.SizeTable :
mPcdDatabase->DxeDb.Init.SizeTable;
@ -493,7 +499,7 @@ DxeUnRegisterCallBackOnSet (
{
ASSERT (CallBackFunction != NULL);
return DxeRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);
return DxeUnRegisterCallBackWorker (TokenNumber, Guid, CallBackFunction);
}

View File

@ -50,10 +50,16 @@ GetWorker (
UINT16 StringTableIdx;
UINT32 LocalTokenNumber;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index.
//
TokenNumber--;
ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);
Size = DxePcdGetSize (TokenNumber);
Size = DxePcdGetSize (TokenNumber + 1);
ASSERT (GetSize == Size || GetSize == 0);
@ -100,11 +106,10 @@ GetWorker (
return (UINT8 *) Data + VariableHead->Offset;
} else {
//
// BugBug: Need to support default value. The current implementation
// will return a memory buffer with ALL ZERO.
//
return AllocateZeroPool (Size);
}
// Return the default value specified by Platform Integrator
//
return (VOID *) ((UINT8 *) PcdDb + VariableHead->DefaultValueOffset);
}
case PCD_TYPE_STRING:
StringTableIdx = (UINT16) *((UINT8 *) PcdDb + Offset);
@ -143,6 +148,13 @@ DxeRegisterCallBackWorker (
TokenNumber = GetExPcdTokenNumber (Guid, (UINT32) TokenNumber);
}
//
// 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--;
ListHead = &mCallbackFnTable[TokenNumber];
ListNode = GetFirstNode (ListHead);
@ -186,6 +198,13 @@ DxeUnRegisterCallBackWorker (
TokenNumber = GetExPcdTokenNumber (Guid, (UINT32) TokenNumber);
}
//
// 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--;
ListHead = &mCallbackFnTable[TokenNumber];
ListNode = GetFirstNode (ListHead);
@ -342,13 +361,17 @@ GetHiiVariable (
EFI_STATUS Status;
VOID *Buffer;
Size = 0;
Buffer = NULL;
Status = EfiGetVariable (
(UINT16 *)VariableName,
VariableGuid,
NULL,
&Size,
NULL
Buffer
);
if (Status == EFI_BUFFER_TOO_SMALL) {
Buffer = AllocatePool (Size);
@ -366,6 +389,9 @@ GetHiiVariable (
ASSERT (Status == EFI_SUCCESS);
}
*VariableData = Buffer;
*VariableSize = Size;
return Status;
}
@ -444,6 +470,13 @@ InvokeCallbackOnSet (
LIST_ENTRY *ListHead;
LIST_ENTRY *ListNode;
//
// 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--;
ListHead = &mCallbackFnTable[TokenNumber];
ListNode = GetFirstNode (ListHead);
@ -485,13 +518,19 @@ SetWorker (
UINTN Offset;
UINT8 *PcdDb;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index.
//
TokenNumber--;
ASSERT (TokenNumber < PCD_TOTAL_TOKEN_NUMBER);
if (PtrType) {
ASSERT (Size <= DxePcdGetSize (TokenNumber));
ASSERT (Size <= DxePcdGetSize (TokenNumber + 1));
} else {
ASSERT (Size == DxePcdGetSize (TokenNumber));
ASSERT (Size == DxePcdGetSize (TokenNumber + 1));
}
IsPeiDb = (TokenNumber < PEI_LOCAL_TOKEN_NUMBER) ? TRUE : FALSE;
@ -501,7 +540,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, Data, Size);
InvokeCallbackOnSet (0, NULL, TokenNumber + 1, Data, Size);
}
TokenNumber = IsPeiDb ? TokenNumber

View File

@ -22,7 +22,7 @@ Module Name: Service.h
// Please make sure the PCD Serivce PEIM Version is consistent with
// the version of PCD Database generation tool
//
#define PCD_DXE_SERVICE_DRIVER_VERSION 1
#define PCD_DXE_SERVICE_DRIVER_VERSION 2
//
// PCD_DXE_DATABASE_GENTOOL_VERSION is defined in Autogen.h

View File

@ -169,6 +169,13 @@ PeiPcdGetSize (
IN UINTN TokenNumber
)
{
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index.
//
TokenNumber--;
ASSERT (TokenNumber < PEI_LOCAL_TOKEN_NUMBER);
return GetPcdDatabase()->Init.SizeTable[TokenNumber];
@ -559,10 +566,10 @@ PeiPcdGetNextToken (
return EFI_SUCCESS;
}
EFI_GUID *
EFI_STATUS
EFIAPI
PeiPcdGetNextTokenSpaceGuid (
IN CONST EFI_GUID *Guid
IN OUT CONST EFI_GUID **Guid
)
{
UINTN GuidTableIdx;
@ -572,9 +579,17 @@ PeiPcdGetNextTokenSpaceGuid (
UINTN i;
BOOLEAN Found;
if (PEI_EXMAP_TABLE_EMPTY) {
return NULL;
}
if (*Guid == NULL) {
if (PEI_EXMAP_TABLE_EMPTY) {
return EFI_SUCCESS;
} else {
//
// return the first Token Space Guid.
//
*Guid = &PeiPcdDb->Init.GuidTable[ExMapTable[0].ExGuidIndex];
return EFI_SUCCESS;
}
}
//
// Assume PCD Database AutoGen tool is sorting the ExMap based on the following order
@ -583,10 +598,10 @@ PeiPcdGetNextTokenSpaceGuid (
//
PeiPcdDb = GetPcdDatabase ();
MatchGuid = ScanGuid (PeiPcdDb->Init.GuidTable, sizeof(PeiPcdDb->Init.GuidTable), Guid);
MatchGuid = ScanGuid (PeiPcdDb->Init.GuidTable, sizeof(PeiPcdDb->Init.GuidTable), *Guid);
if (MatchGuid == NULL) {
return NULL;
return EFI_NOT_FOUND;
}
GuidTableIdx = MatchGuid - PeiPcdDb->Init.GuidTable;
@ -604,16 +619,13 @@ PeiPcdGetNextTokenSpaceGuid (
if (Found) {
for ( ; i < PEI_EXMAPPING_TABLE_SIZE; i++ ) {
if (ExMapTable[i].ExGuidIndex != GuidTableIdx ) {
if (i < PEI_EXMAPPING_TABLE_SIZE) {
return &PeiPcdDb->Init.GuidTable[ExMapTable[i].ExGuidIndex];
} else {
return NULL;
}
*Guid = &PeiPcdDb->Init.GuidTable[ExMapTable[i].ExGuidIndex];
return EFI_SUCCESS;
}
}
}
return NULL;
return EFI_NOT_FOUND;
}

View File

@ -46,12 +46,27 @@ PeiRegisterCallBackWorker (
if (Guid == NULL) {
TokenNumber = ExTokenNumber;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index.
//
TokenNumber--;
ASSERT (TokenNumber < PEI_NEX_TOKEN_NUMBER);
} else {
TokenNumber = GetExPcdTokenNumber (Guid, ExTokenNumber);
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index.
//
TokenNumber--;
ASSERT (TokenNumber < PEI_LOCAL_TOKEN_NUMBER);
}
LocalTokenNumber = GetPcdDatabase()->Init.LocalTokenNumberTable[TokenNumber];
ASSERT ((LocalTokenNumber & PCD_TYPE_HII) == 0);
@ -248,6 +263,13 @@ InvokeCallbackOnSet (
PCD_PPI_CALLBACK *CallbackTable;
UINTN Idx;
//
// 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--;
if (Guid == NULL)
ASSERT (TokenNumber < PEI_LOCAL_TOKEN_NUMBER);
@ -287,6 +309,13 @@ SetWorker (
UINTN Offset;
VOID *InternalData;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index.
//
TokenNumber--;
ASSERT (TokenNumber < PEI_LOCAL_TOKEN_NUMBER);
PeiPcdDb = GetPcdDatabase ();
@ -305,7 +334,7 @@ SetWorker (
// type PCD entry in ExSetWorker.
//
if (TokenNumber < PEI_NEX_TOKEN_NUMBER) {
InvokeCallbackOnSet (0, NULL, TokenNumber, Data, Size);
InvokeCallbackOnSet (0, NULL, TokenNumber + 1, Data, Size);
}
if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == PCD_TYPE_SKU_ENABLED) {
@ -425,9 +454,16 @@ GetWorker (
UINT32 LocalTokenNumber;
UINTN Size;
//
// TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.
// We have to decrement TokenNumber by 1 to make it usable
// as the array index.
//
TokenNumber--;
ASSERT (TokenNumber < PEI_LOCAL_TOKEN_NUMBER);
Size = PeiPcdGetSize(TokenNumber);
Size = PeiPcdGetSize(TokenNumber + 1);
ASSERT (GetSize == Size || GetSize == 0);
@ -464,16 +500,14 @@ GetWorker (
return (VOID *) ((UINT8 *) Data + VariableHead->Offset);
} else {
//
// BugBug: Need to support default value. The current implementation
// will return a memory buffer with ALL ZERO.
//
return AllocateZeroPool (Size);
// Return the default value specified by Platform Integrator
//
return (VOID *) ((UINT8 *) PeiPcdDb + VariableHead->DefaultValueOffset);
}
}
case PCD_TYPE_DATA:
return (VOID *) ((UINT8 *)PeiPcdDb + Offset);
break;
case PCD_TYPE_STRING:
StringTableIdx = (UINT16) *((UINT8 *) PeiPcdDb + Offset);

View File

@ -22,7 +22,7 @@ Module Name: Service.h
// Please make sure the PCD Serivce PEIM Version is consistent with
// the version of PCD Database generation tool
//
#define PCD_PEI_SERVICE_DRIVER_VERSION 1
#define PCD_PEI_SERVICE_DRIVER_VERSION 2
//
// PCD_PEI_DATABASE_GENTOOL_VERSION is defined in Autogen.h

View File

@ -317,26 +317,6 @@ Returns:
CHAR16 *PcdTempStr;
UINTN TempStrSize;
//
// Test Feature Set and Binary Patchable Case
//
if (FeaturePcdGet (PcdWinNtFeatureFlag1)) {
TempStrSize = PatchPcdGet32(PcdWinNtBinaryPatch1) + PatchPcdGet32(PcdWinNtBinaryPatch2);
}
if (0) {
//
// Test Dynamic and DynamicEx
// (Please add PcdWinNtConsole in "WinNtBusDriver.inf" before enable this code!!!)
//
PcdTempStr = PcdGetPtr (PcdWinNtConsole);
}
//
// Test Dynamic Set and Dynamic Set Ex
//
PcdSet32 (PcdWinNtDynamicUINT32, 2006);
Status = EFI_UNSUPPORTED;
//

View File

@ -18,7 +18,7 @@ Module Name: PcdLib.h
#ifndef __PCD_LIB_H__
#define __PCD_LIB_H__
#define PCD_INVALID_TOKEN_NUMBER ((UINTN) -1)
#define PCD_INVALID_TOKEN_NUMBER ((UINTN) 0)
#define PcdToken(TokenName) _PCD_TOKEN_##TokenName

View File

@ -22,7 +22,7 @@ extern EFI_GUID gPcdPpiGuid;
#define PCD_PPI_GUID \
{ 0x6e81c58, 0x4ad7, 0x44bc, { 0x83, 0x90, 0xf1, 0x2, 0x65, 0xf7, 0x24, 0x80 } }
#define PCD_INVALID_TOKEN_NUMBER ((UINTN) -1)
#define PCD_INVALID_TOKEN_NUMBER ((UINTN) 0)
typedef
VOID

View File

@ -22,7 +22,7 @@ extern EFI_GUID gPcdProtocolGuid;
#define PCD_PROTOCOL_GUID \
{ 0x11b34006, 0xd85b, 0x4d0a, { 0xa2, 0x90, 0xd5, 0xa5, 0x71, 0x31, 0xe, 0xf7 } }
#define PCD_INVALID_TOKEN_NUMBER ((UINTN) -1)
#define PCD_INVALID_TOKEN_NUMBER ((UINTN) 0)
typedef
VOID

View File

@ -33,9 +33,10 @@ typedef struct {
typedef struct {
UINT16 GuidTableIndex; // Offset in Guid Table in units of GUID.
UINT16 StringIndex; // Offset in String Table in units of UINT16.
UINT16 Offset; // Offset in Variable
UINT16 GuidTableIndex; // Offset in Guid Table in units of GUID.
UINT16 StringIndex; // Offset in String Table in units of UINT16.
UINT16 Offset; // Offset in Variable
UINT16 DefaultValueOffset; // Offset of the Default Value
} VARIABLE_HEAD ;
@ -43,6 +44,8 @@ typedef struct {
UINT32 Offset;
} VPD_HEAD;
typedef UINT16 STRING_HEAD;
typedef struct {
UINT32 LocalTokenNumber;
UINT16 TokenNumber;

View File

@ -19,15 +19,11 @@ package org.tianocore.build.pcd.action;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.xmlbeans.XmlObject;
import org.tianocore.build.global.GlobalData;
import org.tianocore.build.global.SurfaceAreaQuery;
import org.tianocore.build.pcd.entity.MemoryDatabaseManager;
import org.tianocore.build.pcd.entity.Token;
import org.tianocore.build.pcd.entity.UsageInstance;
@ -398,7 +394,7 @@ public class PCDAutoGenAction extends BuildAction {
**/
public static void main(String argv[]) {
String WorkSpace = "M:/tianocore/edk2";
String WorkSpace = "X:/edk2";
String logFilePath = WorkSpace + "/EdkNt32Pkg/Nt32.fpd";
String[] nameArray = null;
@ -421,13 +417,13 @@ public class PCDAutoGenAction extends BuildAction {
//
// Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c
//
PCDAutoGenAction autogenAction = new PCDAutoGenAction("MonoStatusCode",
PCDAutoGenAction autogenAction = new PCDAutoGenAction("PcdPeim",
null,
null,
null,
"IA32",
null,
false,
true,
nameArray);
autogenAction.execute();

View File

@ -15,20 +15,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.build.pcd.entity;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.tianocore.build.pcd.action.ActionMessage;
import org.tianocore.build.pcd.exception.EntityException;
/** Database hold all PCD information comes from SPD, MSA, FPD file in memory.
**/
@ -141,7 +134,6 @@ public class MemoryDatabaseManager {
private ArrayList getDynamicRecordArray() {
Token[] tokenArray = getRecordArray();
int index = 0;
int count = 0;
ArrayList<Token> al = new ArrayList<Token>();
for (index = 0; index < tokenArray.length; index++) {
@ -159,8 +151,10 @@ public class MemoryDatabaseManager {
The output array is sorted based on descending order of the size of alignment for each feilds.
@return the token record array contained all PCD token referenced in PEI phase.
* @throws EntityException
**/
public void getTwoPhaseDynamicRecordArray(ArrayList<Token> pei, ArrayList<Token> dxe) {
public void getTwoPhaseDynamicRecordArray(ArrayList<Token> pei, ArrayList<Token> dxe)
throws EntityException {
int usageInstanceIndex = 0;
int index = 0;
ArrayList tokenArrayList = getDynamicRecordArray();
@ -185,10 +179,30 @@ public class MemoryDatabaseManager {
}
}
// If no PEI components reference the PCD entry, we insert it to DXE list
//
// If no PEI components reference the PCD entry,
// we check if it is referenced in DXE driver.
//
if (!found) {
dxe.add(token);
if (token.consumers != null) {
usageInstanceArray = token.consumers.entrySet().toArray();
for (usageInstanceIndex = 0; usageInstanceIndex < token.consumers.size(); usageInstanceIndex ++) {
usageInstance =(UsageInstance) (((Map.Entry)usageInstanceArray[usageInstanceIndex]).getValue());
if (usageInstance.isDxePhaseComponent()) {
dxe.add(token);
found = true;
break;
}
}
}
if (!found) {
//
// We only support Dynamice(EX) type for PEI and DXE phase.
// If it is not referenced in either PEI or DXE, throw exception now.
//
throw new EntityException("Dynamic(EX) PCD Entries are referenced in module that is not in PEI phase nor in DXE phase.");
}
}
}

View File

@ -22,7 +22,6 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.tianocore.build.pcd.action.ActionMessage;
import org.tianocore.build.pcd.exception.EntityException;
/** This class is to descript a PCD token object. The information of a token mainly
@ -164,6 +163,17 @@ public class Token {
return false;
}
public boolean isDynamicEx() {
for (int i = 0; i < supportedPcdType.size(); i++) {
if (supportedPcdType.get(i) == PCD_TYPE.DYNAMIC_EX) {
return true;
}
}
return false;
}
/**
Use "TokencName + "-" + SpaceTokenName" as primary key when adding token into database
@ -194,6 +204,20 @@ public class Token {
}
return false;
}
public boolean isHiiEnable() {
if (getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {
return true;
}
return false;
}
public boolean isVpdEnable() {
if (getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {
return true;
}
return false;
}
/**
Get the token primary key in token database.
@ -471,6 +495,7 @@ public class Token {
@return string of datum type.
**/
public static String getAutogendatumTypeString(DATUM_TYPE datumType) {
switch (datumType) {
case UINT8:
@ -545,6 +570,11 @@ public class Token {
return null;
}
public int getSkuIdCount () {
return this.skuData.size();
}
/**
Get default value for a token, For HII type, HiiDefaultValue of default
@ -576,13 +606,17 @@ public class Token {
boolean isInteger = true;
DynamicTokenValue dynamicValue = null;
if (isSkuEnable()) {
return true;
}
if (this.isDynamicPCD) {
dynamicValue = getDefaultSku();
switch (dynamicValue.type) {
case HII_TYPE:
return !isValidNullValue(dynamicValue.hiiDefaultValue);
return true;
case VPD_TYPE:
return false;
return true;
case DEFAULT_TYPE:
return !isValidNullValue(dynamicValue.value);
}

View File

@ -20,8 +20,6 @@ package org.tianocore.build.pcd.entity;
import java.util.UUID;
import org.tianocore.ModuleTypeDef;
import org.tianocore.build.autogen.CommonDefinition;
import org.tianocore.build.pcd.action.ActionMessage;
import org.tianocore.build.pcd.exception.EntityException;
/**
@ -186,6 +184,23 @@ public class UsageInstance {
}
return false;
}
public boolean isDxePhaseComponent() {
//
// BugBug: May need confirmation on which type of module can
// make use of Dynamic(EX) PCD entry.
//
if ((moduleType == ModuleTypeDef.DXE_DRIVER) ||
(moduleType == ModuleTypeDef.DXE_RUNTIME_DRIVER) ||
(moduleType == ModuleTypeDef.DXE_SAL_DRIVER) ||
(moduleType == ModuleTypeDef.DXE_SMM_DRIVER) ||
(moduleType == ModuleTypeDef.UEFI_DRIVER) ||
(moduleType == ModuleTypeDef.UEFI_APPLICATION)
) {
return true;
}
return false;
}
/**
Generate autogen string for header file and C code file.