]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
MdeModulePkg: Refine description a little for PcdEmuVariableNvStoreReserved
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableDxe.c
index f7185df3a7eb5bf06e0ffd9a5010bb8a6fd7efe8..521cb4ed24907c0bc58d64849689223aa5e3e7d8 100644 (file)
@@ -17,13 +17,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "Variable.h"\r
 \r
-extern VARIABLE_STORE_HEADER        *mNvVariableCache;\r
-extern EFI_FIRMWARE_VOLUME_HEADER   *mNvFvHeaderCache;\r
-extern VARIABLE_INFO_ENTRY          *gVariableInfo;\r
 EFI_HANDLE                          mHandle                    = NULL;\r
 EFI_EVENT                           mVirtualAddressChangeEvent = NULL;\r
 EFI_EVENT                           mFtwRegistration           = NULL;\r
-extern BOOLEAN                      mEndOfDxe;\r
 VOID                                ***mVarCheckAddressPointer = NULL;\r
 UINTN                               mVarCheckAddressPointerCount = 0;\r
 EDKII_VARIABLE_LOCK_PROTOCOL        mVariableLock              = { VariableLockRequestToLock };\r
@@ -345,6 +341,40 @@ OnEndOfDxe (
   gBS->CloseEvent (Event);\r
 }\r
 \r
+/**\r
+  Initializes variable write service for DXE.\r
+\r
+**/\r
+VOID\r
+VariableWriteServiceInitializeDxe (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  Status = VariableWriteServiceInitialize ();\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "Variable write service initialization failed. Status = %r\n", Status));\r
+  }\r
+\r
+  //\r
+  // Some Secure Boot Policy Var (SecureBoot, etc) updates following other\r
+  // Secure Boot Policy Variable change. Record their initial value.\r
+  //\r
+  RecordSecureBootPolicyVarData();\r
+\r
+  //\r
+  // Install the Variable Write Architectural protocol.\r
+  //\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &mHandle,\r
+                  &gEfiVariableWriteArchProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
 /**\r
   Fault Tolerant Write protocol notification event handler.\r
 \r
@@ -386,13 +416,17 @@ FtwNotificationEvent (
     ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
   }\r
 \r
+  NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;\r
+  VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;\r
+\r
+  //\r
+  // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.\r
+  //\r
+  mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;\r
+\r
   //\r
   // Find the proper FVB protocol for variable.\r
   //\r
-  NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64);\r
-  if (NvStorageVariableBase == 0) {\r
-    NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);\r
-  }\r
   Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);\r
   if (EFI_ERROR (Status)) {\r
     return ;\r
@@ -402,7 +436,6 @@ FtwNotificationEvent (
   //\r
   // Mark the variable storage region of the FLASH as RUNTIME.\r
   //\r
-  VariableStoreBase   = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;\r
   VariableStoreLength = mNvVariableCache->Size;\r
   BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);\r
   Length      = VariableStoreLength + (VariableStoreBase - BaseAddress);\r
@@ -424,27 +457,10 @@ FtwNotificationEvent (
     }\r
   }\r
 \r
-  Status = VariableWriteServiceInitialize ();\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((DEBUG_ERROR, "Variable write service initialization failed. Status = %r\n", Status));\r
-  }\r
-\r
   //\r
-  // Some Secure Boot Policy Var (SecureBoot, etc) updates following other\r
-  // Secure Boot Policy Variable change. Record their initial value.\r
-  //\r
-  RecordSecureBootPolicyVarData();\r
-\r
+  // Initializes variable write service after FTW was ready.\r
   //\r
-  // Install the Variable Write Architectural protocol.\r
-  //\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &mHandle,\r
-                  &gEfiVariableWriteArchProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  NULL\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  VariableWriteServiceInitializeDxe ();\r
 \r
   //\r
   // Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.\r