]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EMU Variable: Add support for pre-reserved NV variable store.
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 7 Sep 2009 20:18:14 +0000 (20:18 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 7 Sep 2009 20:18:14 +0000 (20:18 +0000)
Add PcdEmuVariableNvStoreReserved which allows a platform to declare a
memory address for the EMU Variable driver to use for the NV variable
store.  The EMU Variable driver will look to see if the contents of
this memory range appear to be a valid variable store, and if so
the EMU driver will use the variables.

If a platform can preserve a memory range across system resets, this
feature can allow the EMU Variable driver's NV variable store to be
preserved across a system reset.

In the default case this PCD will be set as a fixed PCD with a value
of 0.  In this case this new feature should have minimal impact on
the EMU Variable driver.  (Perhaps a slight increase in code size,
but no functional difference is expected.)

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9240 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c
MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf

index 83c85348584bbc853c6bc0f2d8b49e2a1df2b342..7a167ac61959201cd5c8ffced1c2873fa8bb9f99 100644 (file)
   #  This PCD is a sample to explain String typed PCD usage.\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdHelloWorldPrintString|L"UEFI Hello World!\n"|VOID*|0x40000004\r
 \r
+  ## This PCD defines a reserved memory range for the EMU Variable driver's NV Variable Store\r
+  #  The range is valid if non-zero.  The memory range size must be PcdVariableStoreSize.\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0|UINT64|0x40000008\r
+\r
 [PcdsFixedAtBuild,PcdsPatchableInModule,PcdsDynamic]\r
   ## This PCD defines the times to print hello world string.\r
   #  This PCD is a sample to explain FixedAtBuild UINT32 PCD usage.\r
index d2f4d6723b770bd9bf7b166284eed53e68751247..fd0228d564bc971933ad493815e0c075ff9407bc 100644 (file)
@@ -160,18 +160,21 @@ GetVariableDataPtr (
 }\r
 \r
 /**\r
-  Gets pointer to header of the next variable.\r
+  Gets pointer to header of the next potential variable.\r
 \r
-  This function gets the pointer to the next variable header according\r
-  to the input point to the variable header.\r
+  This function gets the pointer to the next potential variable header\r
+  according to the input point to the variable header.  The return value\r
+  is not a valid variable if the input variable was the last variable\r
+  in the variabl store.\r
 \r
   @param  Variable      Pointer to header of the next variable\r
 \r
   @return Pointer to next variable header.\r
+  @retval NULL  Input was not a valid variable header.\r
 \r
 **/\r
 VARIABLE_HEADER *\r
-GetNextVariablePtr (\r
+GetNextPotentialVariablePtr (\r
   IN  VARIABLE_HEADER   *Variable\r
   )\r
 {\r
@@ -185,13 +188,67 @@ GetNextVariablePtr (
   //\r
   VarHeader = (VARIABLE_HEADER *) (GetVariableDataPtr (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize));\r
 \r
-  if (VarHeader->StartId != VARIABLE_DATA) {\r
+  return VarHeader;\r
+}\r
+\r
+/**\r
+  Gets pointer to header of the next variable.\r
+\r
+  This function gets the pointer to the next variable header according\r
+  to the input point to the variable header.\r
+\r
+  @param  Variable      Pointer to header of the next variable\r
+\r
+  @return Pointer to next variable header.\r
+\r
+**/\r
+VARIABLE_HEADER *\r
+GetNextVariablePtr (\r
+  IN  VARIABLE_HEADER   *Variable\r
+  )\r
+{\r
+  VARIABLE_HEADER *VarHeader;\r
+\r
+  VarHeader = GetNextPotentialVariablePtr (Variable);\r
+\r
+  if ((VarHeader == NULL) || (VarHeader->StartId != VARIABLE_DATA)) {\r
     return NULL;\r
   }\r
 \r
   return VarHeader;\r
 }\r
 \r
+/**\r
+  Updates LastVariableOffset variable for the given variable store.\r
+\r
+  LastVariableOffset points to the offset to use for the next variable\r
+  when updating the variable store.\r
+\r
+  @param[in]   VariableStore       Pointer to the start of the variable store\r
+  @param[out]  LastVariableOffset  Offset to put the next new variable in\r
+\r
+**/\r
+VOID\r
+InitializeLocationForLastVariableOffset (\r
+  IN  VARIABLE_STORE_HEADER *VariableStore,\r
+  OUT UINTN                 *LastVariableOffset\r
+  )\r
+{\r
+  VARIABLE_HEADER *VarHeader;\r
+\r
+  *LastVariableOffset       = sizeof (VARIABLE_STORE_HEADER);\r
+  VarHeader = (VARIABLE_HEADER*) ((UINT8*)VariableStore + *LastVariableOffset);\r
+  while (VarHeader->StartId == VARIABLE_DATA) {\r
+    VarHeader = GetNextPotentialVariablePtr (VarHeader);\r
+\r
+    if (VarHeader != NULL) {\r
+      *LastVariableOffset = (UINTN) VarHeader - (UINTN) VariableStore;\r
+    } else {\r
+      return;\r
+    }\r
+  }\r
+}\r
+\r
 /**\r
   Gets pointer to the end of the variable storage area.\r
 \r
@@ -1307,11 +1364,23 @@ EmuQueryVariableInfo (
 **/\r
 EFI_STATUS\r
 InitializeVariableStore (\r
-  OUT EFI_PHYSICAL_ADDRESS  *VariableBase,\r
-  OUT UINTN                 *LastVariableOffset\r
+  IN  BOOLEAN               VolatileStore\r
   )\r
 {\r
   VARIABLE_STORE_HEADER *VariableStore;\r
+  BOOLEAN               FullyInitializeStore;\r
+  EFI_PHYSICAL_ADDRESS  *VariableBase;\r
+  UINTN                 *LastVariableOffset;\r
+\r
+  FullyInitializeStore = TRUE;\r
+\r
+  if (VolatileStore) {\r
+    VariableBase = &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase;\r
+    LastVariableOffset = &mVariableModuleGlobal->VolatileLastVariableOffset;\r
+  } else {\r
+    VariableBase = &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase;\r
+    LastVariableOffset = &mVariableModuleGlobal->NonVolatileLastVariableOffset;\r
+  }\r
 \r
   //\r
   // Note that in EdkII variable driver implementation, Hardware Error Record type variable\r
@@ -1322,22 +1391,48 @@ InitializeVariableStore (
   ASSERT (FixedPcdGet32(PcdHwErrStorageSize) <= FixedPcdGet32(PcdVariableStoreSize));\r
 \r
   //\r
-  // Allocate memory for volatile variable store\r
+  // Allocate memory for variable store.\r
   //\r
-  VariableStore = (VARIABLE_STORE_HEADER *) AllocateRuntimePool (\r
-                                              FixedPcdGet32(PcdVariableStoreSize)\r
-                                              );\r
+  if (VolatileStore || (PcdGet64 (PcdEmuVariableNvStoreReserved) == 0)) {\r
+    VariableStore = (VARIABLE_STORE_HEADER *) AllocateRuntimePool (\r
+                                                FixedPcdGet32(PcdVariableStoreSize)\r
+                                                );\r
+  } else {\r
+    //\r
+    // A memory location has been reserved for the NV variable store.  Certain\r
+    // platforms may be able to preserve a memory range across system resets,\r
+    // thereby providing better NV variable emulation.\r
+    //\r
+    VariableStore =\r
+      (VARIABLE_STORE_HEADER *)(VOID*)(UINTN)\r
+        PcdGet64 (PcdEmuVariableNvStoreReserved);\r
+    if (\r
+         (VariableStore->Size == FixedPcdGet32(PcdVariableStoreSize)) &&\r
+         (VariableStore->Format == VARIABLE_STORE_FORMATTED) &&\r
+         (VariableStore->State == VARIABLE_STORE_HEALTHY)\r
+       ) {\r
+      DEBUG((\r
+        EFI_D_INFO,\r
+        "Variable Store reserved at %p appears to be valid\n",\r
+        VariableStore\r
+        ));\r
+      FullyInitializeStore = FALSE;\r
+    }\r
+  }\r
+\r
   if (NULL == VariableStore) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  SetMem (VariableStore, FixedPcdGet32(PcdVariableStoreSize), 0xff);\r
+  if (FullyInitializeStore) {\r
+    SetMem (VariableStore, FixedPcdGet32(PcdVariableStoreSize), 0xff);\r
+  }\r
 \r
   //\r
   // Variable Specific Data\r
   //\r
   *VariableBase             = (EFI_PHYSICAL_ADDRESS) (UINTN) VariableStore;\r
-  *LastVariableOffset       = sizeof (VARIABLE_STORE_HEADER);\r
+  InitializeLocationForLastVariableOffset (VariableStore, LastVariableOffset);\r
 \r
   CopyGuid (&VariableStore->Signature, &gEfiVariableGuid);\r
   VariableStore->Size       = FixedPcdGet32(PcdVariableStoreSize);\r
@@ -1386,11 +1481,7 @@ VariableCommonInitialize (
   //\r
   // Intialize volatile variable store\r
   //\r
-  Status = InitializeVariableStore (\r
-            &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase,\r
-            &mVariableModuleGlobal->VolatileLastVariableOffset\r
-            );\r
-\r
+  Status = InitializeVariableStore (TRUE);\r
   if (EFI_ERROR (Status)) {\r
     FreePool(mVariableModuleGlobal);\r
     return Status;\r
@@ -1398,10 +1489,7 @@ VariableCommonInitialize (
   //\r
   // Intialize non volatile variable store\r
   //\r
-  Status = InitializeVariableStore (\r
-            &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase,\r
-            &mVariableModuleGlobal->NonVolatileLastVariableOffset\r
-            );\r
+  Status = InitializeVariableStore (FALSE);\r
 \r
   return Status;\r
 }\r
index 4f7d06b3e688cdc17e9eb4a7c9ffd7feffd01f61..ffd92c66ad98bcce1dd4f94de0a059d8e722bdad 100644 (file)
@@ -60,6 +60,7 @@
   gEfiVariableGuid\r
 \r
 [Pcd.common]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize\r