]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
MdeModulePkg Variable: Merge from Auth Variable driver in SecurityPkg
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableDxe.c
index c5cef3194492ed73298e96e89cd66e0973f4c5b9..a95846a934e84681d81246c09dca909d8702007d 100644 (file)
@@ -1,17 +1,16 @@
 /** @file\r
-\r
   Implement all four UEFI Runtime Variable services for the nonvolatile\r
   and volatile storage space and install variable architecture protocol.\r
-  \r
+\r
 Copyright (C) 2013, Red Hat, Inc.\r
 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
-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
+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
+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
@@ -34,7 +33,7 @@ EDKII_VAR_CHECK_PROTOCOL       mVarCheck                  = { VarCheckRegisterSe
 \r
 /**\r
   Return TRUE if ExitBootServices () has been called.\r
-  \r
+\r
   @retval TRUE If ExitBootServices () has been called.\r
 **/\r
 BOOLEAN\r
@@ -49,8 +48,8 @@ AtRuntime (
 /**\r
   Initializes a basic mutual exclusion lock.\r
 \r
-  This function initializes a basic mutual exclusion lock to the released state \r
-  and returns the lock.  Each lock provides mutual exclusion access at its task \r
+  This function initializes a basic mutual exclusion lock to the released state\r
+  and returns the lock.  Each lock provides mutual exclusion access at its task\r
   priority level.  Since there is no preemption or multiprocessor support in EFI,\r
   acquiring the lock only consists of raising to the locks TPL.\r
   If Lock is NULL, then ASSERT().\r
@@ -141,7 +140,7 @@ GetFtwProtocol (
                   &gEfiFaultTolerantWriteProtocolGuid,\r
                   NULL,\r
                   FtwProtocol\r
-                  );                    \r
+                  );\r
   return Status;\r
 }\r
 \r
@@ -155,7 +154,7 @@ GetFtwProtocol (
   @retval EFI_SUCCESS           The interface information for the specified protocol was returned.\r
   @retval EFI_UNSUPPORTED       The device does not support the FVB protocol.\r
   @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 GetFvbByHandle (\r
@@ -176,7 +175,7 @@ GetFvbByHandle (
 \r
 /**\r
   Function returns an array of handles that support the FVB protocol\r
-  in a buffer allocated from pool. \r
+  in a buffer allocated from pool.\r
 \r
   @param[out]  NumberHandles    The number of handles returned in Buffer.\r
   @param[out]  Buffer           A pointer to the buffer to return the requested\r
@@ -187,7 +186,7 @@ GetFvbByHandle (
   @retval EFI_NOT_FOUND         No FVB handle was found.\r
   @retval EFI_OUT_OF_RESOURCES  There is not enough pool memory to store the matching results.\r
   @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 GetFvbCountAndBuffer (\r
@@ -246,7 +245,7 @@ VariableClassAddressChangeEvent (
   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);\r
   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.HobVariableBase);\r
   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r
-  EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);  \r
+  EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);\r
   EfiConvertPointer (0x0, (VOID **) &mHandlerTable);\r
   for (Index = 0; Index < mNumberOfHandler; Index++) {\r
     EfiConvertPointer (0x0, (VOID **) &mHandlerTable[Index]);\r
@@ -257,6 +256,12 @@ VariableClassAddressChangeEvent (
 \r
   Status = EfiConvertList (0x0, &mVarCheckVariableList);\r
   ASSERT_EFI_ERROR (Status);\r
+\r
+  if (mContextOut.AddressPointer != NULL) {\r
+    for (Index = 0; Index < mContextOut.AddressPointerCount; Index++) {\r
+      EfiConvertPointer (0x0, (VOID **) &mContextOut.AddressPointer[Index]);\r
+    }\r
+  }\r
 }\r
 \r
 \r
@@ -288,8 +293,14 @@ OnReadyToBoot (
   InitializeVariableQuota ();\r
   ReclaimForOS ();\r
   if (FeaturePcdGet (PcdVariableCollectStatistics)) {\r
-    gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);\r
+    if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {\r
+      gBS->InstallConfigurationTable (&gEfiAuthenticatedVariableGuid, gVariableInfo);\r
+    } else {\r
+      gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);\r
+    }\r
   }\r
+\r
+  gBS->CloseEvent (Event);\r
 }\r
 \r
 /**\r
@@ -316,17 +327,19 @@ OnEndOfDxe (
   if (PcdGetBool (PcdReclaimVariableSpaceAtEndOfDxe)) {\r
     ReclaimForOS ();\r
   }\r
+\r
+  gBS->CloseEvent (Event);\r
 }\r
 \r
 /**\r
   Fault Tolerant Write protocol notification event handler.\r
 \r
-  Non-Volatile variable write may needs FTW protocol to reclaim when \r
+  Non-Volatile variable write may needs FTW protocol to reclaim when\r
   writting variable.\r
 \r
   @param[in] Event    Event whose notification function is being invoked.\r
   @param[in] Context  Pointer to the notification function's context.\r
-  \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -394,21 +407,23 @@ FtwNotificationEvent (
       DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));\r
     }\r
   }\r
-  \r
+\r
   Status = VariableWriteServiceInitialize ();\r
-  ASSERT_EFI_ERROR (Status);\r
\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "Variable write service initialization failed. Status = %r\n", Status));\r
+  }\r
+\r
   //\r
   // Install the Variable Write Architectural protocol.\r
   //\r
   Status = gBS->InstallProtocolInterface (\r
                   &mHandle,\r
-                  &gEfiVariableWriteArchProtocolGuid, \r
+                  &gEfiVariableWriteArchProtocolGuid,\r
                   EFI_NATIVE_INTERFACE,\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
   //\r
   // Close the notify event to avoid install gEfiVariableWriteArchProtocolGuid again.\r
   //\r
@@ -419,13 +434,13 @@ FtwNotificationEvent (
 \r
 /**\r
   Variable Driver main entry point. The Variable driver places the 4 EFI\r
-  runtime services in the EFI System Table and installs arch protocols \r
-  for variable read and write services being availible. It also registers\r
+  runtime services in the EFI System Table and installs arch protocols\r
+  for variable read and write services being available. It also registers\r
   a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
 \r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
   @param[in] SystemTable    A pointer to the EFI System Table.\r
-  \r
+\r
   @retval EFI_SUCCESS       Variable service successfully initialized.\r
 \r
 **/\r
@@ -463,13 +478,13 @@ VariableServiceInitialize (
   SystemTable->RuntimeServices->GetNextVariableName = VariableServiceGetNextVariableName;\r
   SystemTable->RuntimeServices->SetVariable         = VariableServiceSetVariable;\r
   SystemTable->RuntimeServices->QueryVariableInfo   = VariableServiceQueryVariableInfo;\r
-    \r
+\r
   //\r
   // Now install the Variable Runtime Architectural protocol on a new handle.\r
   //\r
   Status = gBS->InstallProtocolInterface (\r
                   &mHandle,\r
-                  &gEfiVariableArchProtocolGuid, \r
+                  &gEfiVariableArchProtocolGuid,\r
                   EFI_NATIVE_INTERFACE,\r
                   NULL\r
                   );\r
@@ -477,7 +492,7 @@ VariableServiceInitialize (
 \r
   //\r
   // Register FtwNotificationEvent () notify function.\r
-  // \r
+  //\r
   EfiCreateProtocolNotifyEvent (\r
     &gEfiFaultTolerantWriteProtocolGuid,\r
     TPL_CALLBACK,\r
@@ -500,9 +515,9 @@ VariableServiceInitialize (
   // Register the event handling function to reclaim variable for OS usage.\r
   //\r
   Status = EfiCreateEventReadyToBootEx (\r
-             TPL_NOTIFY, \r
-             OnReadyToBoot, \r
-             NULL, \r
+             TPL_NOTIFY,\r
+             OnReadyToBoot,\r
+             NULL,\r
              &ReadyToBootEvent\r
              );\r
   ASSERT_EFI_ERROR (Status);\r