]> git.proxmox.com Git - mirror_edk2.git/commitdiff
refine VariablePei driver to unify the algorithm of access VariableIndexTable among...
authoreric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 23 Jun 2009 08:30:04 +0000 (08:30 +0000)
committereric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 23 Jun 2009 08:30:04 +0000 (08:30 +0000)
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

MdeModulePkg/Universal/Variable/Pei/Ipf/VariableWorker.c [deleted file]
MdeModulePkg/Universal/Variable/Pei/Variable.c
MdeModulePkg/Universal/Variable/Pei/Variable.h
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
MdeModulePkg/Universal/Variable/Pei/VariableWorker.c [deleted file]

diff --git a/MdeModulePkg/Universal/Variable/Pei/Ipf/VariableWorker.c b/MdeModulePkg/Universal/Variable/Pei/Ipf/VariableWorker.c
deleted file mode 100644 (file)
index 17f152a..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/** @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
index 39998f5f67126757babbbe4fa9d52d6b6850db99..4716eac9ec86746ca8b9d64887c197ab9fe78793 100644 (file)
@@ -366,10 +366,13 @@ FindVariable (
   EFI_HOB_GUID_TYPE       *GuidHob;\r
   VARIABLE_STORE_HEADER   *VariableStoreHeader;\r
   VARIABLE_HEADER         *Variable;\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
   VARIABLE_HEADER         *MaxIndex;\r
   VARIABLE_INDEX_TABLE    *IndexTable;\r
   UINT32                  Count;\r
+  UINT32                  Offset;\r
   UINT8                   *VariableBase;\r
   UINT8                   *VariableBase;\r
+  BOOLEAN                 StopRecord;\r
 \r
   if (VariableName[0] != 0 && VendorGuid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
 \r
   if (VariableName[0] != 0 && VendorGuid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -378,9 +381,16 @@ FindVariable (
   // No Variable Address equals zero, so 0 as initial value is safe.\r
   //\r
   MaxIndex = 0;\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
   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 = BuildGuidHob (&mEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));\r
     IndexTable->Length      = 0;\r
     IndexTable->StartPtr    = NULL;\r
@@ -388,9 +398,13 @@ FindVariable (
     IndexTable->GoneThrough = 0;\r
   } else {\r
     IndexTable = GET_GUID_HOB_DATA (GuidHob);\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 (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
         PtrTrack->StartPtr  = IndexTable->StartPtr;\r
         PtrTrack->EndPtr    = IndexTable->EndPtr;\r
@@ -407,7 +421,8 @@ FindVariable (
   // If not found in HOB, then let's start from the MaxIndex we've found.\r
   //\r
   if (MaxIndex != NULL) {\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
   } else {\r
     if ((IndexTable->StartPtr != NULL) || (IndexTable->EndPtr != NULL)) {\r
       Variable = IndexTable->StartPtr;\r
@@ -435,6 +450,8 @@ FindVariable (
       //\r
       Variable = IndexTable->StartPtr;\r
     }\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
   //\r
   // Find the variable by walk through non-volatile variable store\r
@@ -447,8 +464,23 @@ FindVariable (
       //\r
       // Record Variable in VariableIndex HOB\r
       //\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
       if (CompareWithValidVariable (Variable, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {\r
         return EFI_SUCCESS;\r
       }\r
index 7cee1f08b55fbfca0f0ac7b52efc38cb11945f93..d7f62017651291a8bc5a44109c9c6eb8009de9d8 100644 (file)
@@ -41,11 +41,18 @@ typedef struct {
 #define EFI_VARIABLE_INDEX_TABLE_GUID \\r
   { 0x8cfdb8c8, 0xd6b2, 0x40f3, { 0x8e, 0x97, 0x02, 0x30, 0x7c, 0xc9, 0x8b, 0x7c } }\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
 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
   UINT16          Index[VARIABLE_INDEX_TABLE_VOLUME];\r
 } VARIABLE_INDEX_TABLE;\r
 \r
@@ -146,34 +153,4 @@ PeiGetNextVariableName (
   IN OUT EFI_GUID                           *VariableGuid\r
   );\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
 #endif\r
index 2e5580bde658d9382b181ae4f7e000d93b89797e..b406f8aa6f09b9c14805cb0313f0e881f41feeac 100644 (file)
   Variable.c\r
   Variable.h\r
 \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
 [Packages]\r
   MdePkg/MdePkg.dec\r
   MdeModulePkg/MdeModulePkg.dec\r
diff --git a/MdeModulePkg/Universal/Variable/Pei/VariableWorker.c b/MdeModulePkg/Universal/Variable/Pei/VariableWorker.c
deleted file mode 100644 (file)
index a99bfa8..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/** @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