summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Universal/Variable/Pei/Variable.c
diff options
context:
space:
mode:
authoreric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>2009-06-23 08:30:04 +0000
committereric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>2009-06-23 08:30:04 +0000
commit841014ba97539efa5f69c5ffd874ffc55e426023 (patch)
treedce1c5ab71c4298479dab40d944417ac78474fd3 /MdeModulePkg/Universal/Variable/Pei/Variable.c
parent48a9ea7b1bf6d6dfbcc98aa90eb71d476a838cbd (diff)
downloadedk2-platforms-841014ba97539efa5f69c5ffd874ffc55e426023.tar.xz
refine VariablePei driver to unify the algorithm of access VariableIndexTable among various archs.
1. record the distance of two neighboring VAR_ADDED type variables rather than the offset of each variable. As the field recording this info is UINT16 width, the latter causes in IA32/X64 platform, it can only cache those variables from offset 0 to offset 2^16; in IPF platform, from offset 0 to offset 2^18(extend the scope by left-shift the offset two bits). when taking the former algorithm, the max range of caching variable is from offset 0 to offset 122*(2^16) git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8625 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Universal/Variable/Pei/Variable.c')
-rw-r--r--MdeModulePkg/Universal/Variable/Pei/Variable.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c
index 39998f5f67..4716eac9ec 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.c
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c
@@ -366,10 +366,13 @@ FindVariable (
EFI_HOB_GUID_TYPE *GuidHob;
VARIABLE_STORE_HEADER *VariableStoreHeader;
VARIABLE_HEADER *Variable;
+ VARIABLE_HEADER *LastVariable;
VARIABLE_HEADER *MaxIndex;
VARIABLE_INDEX_TABLE *IndexTable;
UINT32 Count;
+ UINT32 Offset;
UINT8 *VariableBase;
+ BOOLEAN StopRecord;
if (VariableName[0] != 0 && VendorGuid == NULL) {
return EFI_INVALID_PARAMETER;
@@ -378,9 +381,16 @@ FindVariable (
// No Variable Address equals zero, so 0 as initial value is safe.
//
MaxIndex = 0;
+ StopRecord = FALSE;
GuidHob = GetFirstGuidHob (&mEfiVariableIndexTableGuid);
if (GuidHob == NULL) {
+ //
+ // If it's the first time to access variable region in flash, create a guid hob to record
+ // VAR_ADDED type variable info.
+ // Note that as the resource of PEI phase is limited, only store the number of
+ // VARIABLE_INDEX_TABLE_VOLUME of VAR_ADDED type variables to reduce access time.
+ //
IndexTable = BuildGuidHob (&mEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));
IndexTable->Length = 0;
IndexTable->StartPtr = NULL;
@@ -388,9 +398,13 @@ FindVariable (
IndexTable->GoneThrough = 0;
} else {
IndexTable = GET_GUID_HOB_DATA (GuidHob);
- for (Count = 0; Count < IndexTable->Length; Count++) {
- MaxIndex = GetVariableByIndex (IndexTable, Count);
-
+ for (Offset = 0, Count = 0; Count < IndexTable->Length; Count++) {
+ //
+ // traverse the variable info list to look for varible.
+ // The IndexTable->Index[Count] records the distance of two neighbouring VAR_ADDED type variables.
+ //
+ Offset += IndexTable->Index[Count];
+ MaxIndex = (VARIABLE_HEADER *)((CHAR8 *)(IndexTable->StartPtr) + Offset);
if (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
PtrTrack->StartPtr = IndexTable->StartPtr;
PtrTrack->EndPtr = IndexTable->EndPtr;
@@ -407,7 +421,8 @@ FindVariable (
// If not found in HOB, then let's start from the MaxIndex we've found.
//
if (MaxIndex != NULL) {
- Variable = GetNextVariablePtr (MaxIndex);
+ Variable = GetNextVariablePtr (MaxIndex);
+ LastVariable = MaxIndex;
} else {
if ((IndexTable->StartPtr != NULL) || (IndexTable->EndPtr != NULL)) {
Variable = IndexTable->StartPtr;
@@ -435,6 +450,8 @@ FindVariable (
//
Variable = IndexTable->StartPtr;
}
+
+ LastVariable = IndexTable->StartPtr;
}
//
// Find the variable by walk through non-volatile variable store
@@ -447,8 +464,23 @@ FindVariable (
//
// Record Variable in VariableIndex HOB
//
- VariableIndexTableUpdate (IndexTable, Variable);
-
+ if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME && StopRecord != TRUE) {
+ Offset = (UINT32)((UINTN)Variable - (UINTN)LastVariable);
+ //
+ // The distance of two neighbouring VAR_ADDED variable is larger than 2^16,
+ // which is beyond the allowable scope(UINT16) of record. In such case, need not to
+ // record the subsequent VAR_ADDED type variables again.
+ //
+ if ((Offset & 0xFFFF0000UL) != 0) {
+ StopRecord = TRUE;
+ }
+
+ if (StopRecord != TRUE) {
+ IndexTable->Index[IndexTable->Length++] = (UINT16) Offset;
+ }
+ LastVariable = Variable;
+ }
+
if (CompareWithValidVariable (Variable, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
return EFI_SUCCESS;
}