+++ /dev/null
-/** @file\r
-\r
- Variable worker functions specific for IPF arch.\r
-\r
- Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "Variable.h"\r
-\r
-\r
-/**\r
- Get one variable by the index count.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Count The index count of variable in index table.\r
-\r
- @return The pointer to variable header indexed by count.\r
-\r
-**/\r
-VARIABLE_HEADER *\r
-GetVariableByIndex (\r
- IN VARIABLE_INDEX_TABLE *IndexTable,\r
- IN UINT32 Count\r
- )\r
-{\r
- return (VARIABLE_HEADER *) (UINTN) ((((UINT32)IndexTable->Index[Count]) << 2) + ((UINT32)(UINTN)IndexTable->StartPtr & 0xFFFC0000) );\r
-}\r
-\r
-/**\r
- Record Variable in VariableIndex HOB.\r
-\r
- Record Variable in VariableIndex HOB and update the length of variable index table.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Variable The pointer to the variable that will be recorded.\r
-\r
-**/\r
-VOID\r
-VariableIndexTableUpdate (\r
- IN OUT VARIABLE_INDEX_TABLE *IndexTable,\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-{\r
- if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) {\r
- IndexTable->Index[IndexTable->Length++] = (UINT16) (((UINT32)(UINTN) Variable) >> 2);\r
- }\r
-\r
- return;\r
-}\r
-\r
EFI_HOB_GUID_TYPE *GuidHob;\r
VARIABLE_STORE_HEADER *VariableStoreHeader;\r
VARIABLE_HEADER *Variable;\r
+ VARIABLE_HEADER *LastVariable;\r
VARIABLE_HEADER *MaxIndex;\r
VARIABLE_INDEX_TABLE *IndexTable;\r
UINT32 Count;\r
+ UINT32 Offset;\r
UINT8 *VariableBase;\r
+ BOOLEAN StopRecord;\r
\r
if (VariableName[0] != 0 && VendorGuid == NULL) {\r
return EFI_INVALID_PARAMETER;\r
// No Variable Address equals zero, so 0 as initial value is safe.\r
//\r
MaxIndex = 0;\r
+ StopRecord = FALSE;\r
\r
GuidHob = GetFirstGuidHob (&mEfiVariableIndexTableGuid);\r
if (GuidHob == NULL) {\r
+ //\r
+ // If it's the first time to access variable region in flash, create a guid hob to record\r
+ // VAR_ADDED type variable info.\r
+ // Note that as the resource of PEI phase is limited, only store the number of \r
+ // VARIABLE_INDEX_TABLE_VOLUME of VAR_ADDED type variables to reduce access time.\r
+ //\r
IndexTable = BuildGuidHob (&mEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));\r
IndexTable->Length = 0;\r
IndexTable->StartPtr = NULL;\r
IndexTable->GoneThrough = 0;\r
} else {\r
IndexTable = GET_GUID_HOB_DATA (GuidHob);\r
- for (Count = 0; Count < IndexTable->Length; Count++) {\r
- MaxIndex = GetVariableByIndex (IndexTable, Count);\r
-\r
+ for (Offset = 0, Count = 0; Count < IndexTable->Length; Count++) {\r
+ //\r
+ // traverse the variable info list to look for varible.\r
+ // The IndexTable->Index[Count] records the distance of two neighbouring VAR_ADDED type variables.\r
+ //\r
+ Offset += IndexTable->Index[Count];\r
+ MaxIndex = (VARIABLE_HEADER *)((CHAR8 *)(IndexTable->StartPtr) + Offset);\r
if (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
PtrTrack->StartPtr = IndexTable->StartPtr;\r
PtrTrack->EndPtr = IndexTable->EndPtr;\r
// If not found in HOB, then let's start from the MaxIndex we've found.\r
//\r
if (MaxIndex != NULL) {\r
- Variable = GetNextVariablePtr (MaxIndex);\r
+ Variable = GetNextVariablePtr (MaxIndex);\r
+ LastVariable = MaxIndex;\r
} else {\r
if ((IndexTable->StartPtr != NULL) || (IndexTable->EndPtr != NULL)) {\r
Variable = IndexTable->StartPtr;\r
//\r
Variable = IndexTable->StartPtr;\r
}\r
+\r
+ LastVariable = IndexTable->StartPtr;\r
}\r
//\r
// Find the variable by walk through non-volatile variable store\r
//\r
// Record Variable in VariableIndex HOB\r
//\r
- VariableIndexTableUpdate (IndexTable, Variable);\r
- \r
+ if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME && StopRecord != TRUE) {\r
+ Offset = (UINT32)((UINTN)Variable - (UINTN)LastVariable);\r
+ //\r
+ // The distance of two neighbouring VAR_ADDED variable is larger than 2^16, \r
+ // which is beyond the allowable scope(UINT16) of record. In such case, need not to\r
+ // record the subsequent VAR_ADDED type variables again.\r
+ //\r
+ if ((Offset & 0xFFFF0000UL) != 0) {\r
+ StopRecord = TRUE;\r
+ }\r
+\r
+ if (StopRecord != TRUE) {\r
+ IndexTable->Index[IndexTable->Length++] = (UINT16) Offset;\r
+ }\r
+ LastVariable = Variable;\r
+ }\r
+\r
if (CompareWithValidVariable (Variable, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
return EFI_SUCCESS;\r
}\r
#define EFI_VARIABLE_INDEX_TABLE_GUID \\r
{ 0x8cfdb8c8, 0xd6b2, 0x40f3, { 0x8e, 0x97, 0x02, 0x30, 0x7c, 0xc9, 0x8b, 0x7c } }\r
\r
+///\r
+/// Use this data structure to store variable-related info, which can decrease\r
+/// the cost of access to NV.\r
+///\r
typedef struct {\r
UINT16 Length;\r
UINT16 GoneThrough;\r
VARIABLE_HEADER *EndPtr;\r
VARIABLE_HEADER *StartPtr;\r
+ ///\r
+ /// This field is used to store the distance of two neighbouring VAR_ADDED type variables.\r
+ /// The meaning of the field is implement-dependent.\r
UINT16 Index[VARIABLE_INDEX_TABLE_VOLUME];\r
} VARIABLE_INDEX_TABLE;\r
\r
IN OUT EFI_GUID *VariableGuid\r
);\r
\r
-/**\r
- Get one variable by the index count.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Count The index count of variable in index table.\r
-\r
- @return The pointer to variable header indexed by count.\r
-\r
-**/\r
-VARIABLE_HEADER *\r
-GetVariableByIndex (\r
- IN VARIABLE_INDEX_TABLE *IndexTable,\r
- IN UINT32 Count\r
- );\r
-\r
-/**\r
- Record Variable in VariableIndex HOB.\r
-\r
- Record Variable in VariableIndex HOB and update the length of variable index table.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Variable The pointer to the variable that will be recorded.\r
-\r
-**/\r
-VOID\r
-VariableIndexTableUpdate (\r
- IN OUT VARIABLE_INDEX_TABLE *IndexTable,\r
- IN VARIABLE_HEADER *Variable\r
- );\r
-\r
#endif\r
Variable.c\r
Variable.h\r
\r
-[Sources.Ia32]\r
- VariableWorker.c\r
-\r
-[Sources.X64]\r
- VariableWorker.c\r
-\r
-[Sources.IPF]\r
- Ipf/VariableWorker.c\r
-\r
-[Sources.EBC]\r
- VariableWorker.c\r
-\r
[Packages]\r
MdePkg/MdePkg.dec\r
MdeModulePkg/MdeModulePkg.dec\r
+++ /dev/null
-/** @file\r
-\r
- Variable worker functions specific for IA32, X64 and EBC.\r
-\r
-Copyright (c) 2007 - 2008, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "Variable.h"\r
-\r
-/**\r
- Get one variable by the index count.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Count The index count of variable in index table.\r
-\r
- @return The pointer to variable header indexed by count.\r
-\r
-**/\r
-VARIABLE_HEADER *\r
-GetVariableByIndex (\r
- IN VARIABLE_INDEX_TABLE *IndexTable,\r
- IN UINT32 Count\r
- )\r
-{\r
- return (VARIABLE_HEADER *) (UINTN) (IndexTable->Index[Count] + ((UINTN) IndexTable->StartPtr & 0xFFFF0000));\r
-}\r
-\r
-/**\r
- Record Variable in VariableIndex HOB.\r
-\r
- Record Variable in VariableIndex HOB and update the length of variable index table.\r
-\r
- @param IndexTable The pointer to variable index table.\r
- @param Variable The pointer to the variable that will be recorded.\r
-\r
-**/\r
-VOID\r
-VariableIndexTableUpdate (\r
- IN OUT VARIABLE_INDEX_TABLE *IndexTable,\r
- IN VARIABLE_HEADER *Variable\r
- )\r
-{\r
- if (IndexTable->Length < VARIABLE_INDEX_TABLE_VOLUME) {\r
- IndexTable->Index[IndexTable->Length++] = (UINT16) (UINTN) Variable;\r
- }\r
-\r
- return;\r
-}\r
-\r