]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Reclaim occurs as late as possible before OS boot for keep enough space used by OS
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 17 Jan 2008 09:59:51 +0000 (09:59 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 17 Jan 2008 09:59:51 +0000 (09:59 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4574 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c

index 2da9edf28748500d8f0c7c03903f377169ef21f0..019f0a806df22461b8cbc733a02fc3bec5d316e7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI Runtime Variable services.\r
   \r
-  Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
+  Copyright (c) 2006 - 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
@@ -15,9 +15,7 @@
 \r
 #include "Variable.h"\r
 \r
-\r
-VARIABLE_MODULE_GLOBAL  mRuntimeData;\r
-VARIABLE_MODULE_GLOBAL  *mVariableModuleGlobal = &mRuntimeData;\r
+VARIABLE_MODULE_GLOBAL  *mVariableModuleGlobal;\r
 EFI_EVENT   mVirtualAddressChangeEvent = NULL;\r
 EFI_HANDLE  mHandle = NULL;\r
 \r
@@ -1705,6 +1703,32 @@ RuntimeServiceQueryVariableInfo (
   return EFI_SUCCESS;\r
 }\r
 \r
+VOID\r
+EFIAPI\r
+ReclaimForOS(\r
+  EFI_EVENT  Event,\r
+  VOID       *Context\r
+  )\r
+{\r
+  UINT32                          VarSize;\r
+  EFI_STATUS                      Status;\r
+\r
+  VarSize = ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase))->Size;\r
+  Status  = EFI_SUCCESS; \r
+\r
+  //\r
+  // Check if the free area is blow a threshold\r
+  //\r
+  if ((VarSize - mVariableModuleGlobal->NonVolatileLastVariableOffset) < VARIABLE_RECLAIM_THRESHOLD) {\r
+    Status = Reclaim (\r
+              mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,\r
+              &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
+              FALSE\r
+              );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+}\r
+\r
 EFI_STATUS\r
 VariableCommonInitialize (\r
   IN EFI_HANDLE         ImageHandle,\r
@@ -1746,7 +1770,16 @@ Returns:
   UINT8                           Data;\r
   UINT64                          VariableStoreBase;\r
   UINT64                          VariableStoreLength;\r
+  EFI_EVENT                       ReadyToBootEvent;\r
 \r
+  Status = EFI_SUCCESS;\r
+  //\r
+  // Allocate runtime memory for variable driver global structure.\r
+  //\r
+  mVariableModuleGlobal = AllocateRuntimePool (sizeof (VARIABLE_MODULE_GLOBAL));\r
+  if (mVariableModuleGlobal == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
 \r
   EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock, TPL_NOTIFY);\r
   mVariableModuleGlobal->VariableGlobal.ReentrantState = 0;\r
@@ -1793,9 +1826,7 @@ Returns:
 \r
   Status      = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (mVariableModuleGlobal);\r
-    FreePool (VolatileVariableStore);\r
-    return EFI_UNSUPPORTED;\r
+    goto Done;\r
   }\r
 \r
   Status = gDS->SetMemorySpaceAttributes (\r
@@ -1804,9 +1835,7 @@ Returns:
                   GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (mVariableModuleGlobal);\r
-    FreePool (VolatileVariableStore);\r
-    return EFI_UNSUPPORTED;\r
+    goto Done;\r
   }\r
   //\r
   // Get address of non volatile variable store base\r
@@ -1854,7 +1883,7 @@ Returns:
       ASSERT(VariableStoreHeader->Size == VariableStoreLength);\r
 \r
       if (EFI_ERROR (Status)) {\r
-        return Status;\r
+        goto Done;\r
       }\r
     }\r
 \r
@@ -1871,23 +1900,6 @@ Returns:
 \r
     mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) CurrPtr;\r
 \r
-    //\r
-    // Check if the free area is blow a threshold\r
-    //\r
-    if ((((VARIABLE_STORE_HEADER *)((UINTN) CurrPtr))->Size - mVariableModuleGlobal->NonVolatileLastVariableOffset) < VARIABLE_RECLAIM_THRESHOLD) {\r
-      Status = Reclaim (\r
-                mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,\r
-                &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
-                FALSE\r
-                );\r
-    }\r
-\r
-    if (EFI_ERROR (Status)) {\r
-      FreePool (mVariableModuleGlobal);\r
-      FreePool (VolatileVariableStore);\r
-      return Status;\r
-    }\r
-\r
     //\r
     // Check if the free area is really free.\r
     //\r
@@ -1902,11 +1914,27 @@ Returns:
                   &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
                   FALSE\r
                   );\r
+\r
+        if (EFI_ERROR (Status)) {\r
+          goto Done;\r
+        }\r
+\r
         break;\r
       }\r
     }\r
+\r
+    //\r
+    // Register the event handling function to reclaim variable for OS usage.\r
+    //\r
+    Status = EfiCreateEventReadyToBootEx (\r
+               TPL_NOTIFY, \r
+               ReclaimForOS, \r
+               NULL, \r
+               &ReadyToBootEvent\r
+               );\r
   }\r
 \r
+Done:\r
   if (EFI_ERROR (Status)) {\r
     FreePool (mVariableModuleGlobal);\r
     FreePool (VolatileVariableStore);\r
@@ -1915,9 +1943,6 @@ Returns:
   return Status;\r
 }\r
 \r
-\r
-\r
-\r
 VOID\r
 EFIAPI\r
 VariableClassAddressChangeEvent (\r