]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.c
Add Tper Reset Logic by using MOR bit.
[mirror_edk2.git] / SecurityPkg / Tcg / MemoryOverwriteControl / TcgMor.c
index ce53112dc57070f11c3bc949a145713d551a1863..def965f13853cf1acdc84998307f5ab1294c5899 100644 (file)
@@ -4,7 +4,7 @@
   This driver initilize MemoryOverwriteRequestControl variable. It \r
   will clear MOR_CLEAR_MEMORY_BIT bit if it is set.\r
 \r
-Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2012, 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
@@ -17,6 +17,50 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "TcgMor.h"\r
 \r
+UINT8    mMorControl;\r
+\r
+/**\r
+  Ready to Boot Event notification handler.\r
+\r
+  Sequence of OS boot events is measured in this event notification handler.\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
+VOID\r
+EFIAPI\r
+OnReadyToBoot (\r
+  IN      EFI_EVENT                 Event,\r
+  IN      VOID                      *Context\r
+  )\r
+{\r
+  UINTN       DataSize;\r
+  \r
+  if (MOR_CLEAR_MEMORY_VALUE (mMorControl) == 0x0) {\r
+    //\r
+    // MorControl is expected, directly return to avoid unnecessary variable operation\r
+    //\r
+    return ;\r
+  }\r
+  //\r
+  // Clear MOR_CLEAR_MEMORY_BIT\r
+  //\r
+  DEBUG ((EFI_D_INFO, "TcgMor: Clear MorClearMemory bit\n"));\r
+  mMorControl &= 0xFE;  \r
+\r
+  DataSize = sizeof (mMorControl);\r
+  gRT->SetVariable (\r
+         MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
+         &gEfiMemoryOverwriteControlDataGuid, \r
+         EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+         DataSize, \r
+         &mMorControl\r
+         );\r
+\r
+}\r
+\r
+\r
 /**\r
   Entry Point for TCG MOR Control driver.\r
 \r
@@ -34,48 +78,49 @@ MorDriverEntryPoint (
   )\r
 {\r
   EFI_STATUS  Status;\r
-  UINT8       MorControl;\r
   UINTN       DataSize;\r
+  EFI_EVENT   Event;\r
 \r
   ///\r
   /// The firmware is required to create the MemoryOverwriteRequestControl UEFI variable.\r
   ///\r
 \r
-  DataSize = sizeof (MorControl);\r
+  DataSize = sizeof (mMorControl);\r
   Status = gRT->GetVariable (\r
                   MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
                   &gEfiMemoryOverwriteControlDataGuid, \r
                   NULL, \r
                   &DataSize, \r
-                  &MorControl\r
+                  &mMorControl\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     //\r
     // Set default value to 0\r
     //\r
-    MorControl = 0;\r
+    mMorControl = 0;\r
+    DEBUG ((EFI_D_INFO, "TcgMor: Create gEfiMemoryOverwriteControlDataGuid!\n"));\r
+    Status = gRT->SetVariable (\r
+                    MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
+                    &gEfiMemoryOverwriteControlDataGuid, \r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                    DataSize, \r
+                    &mMorControl\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
   } else {\r
-    if (MOR_CLEAR_MEMORY_VALUE (MorControl) == 0x0) {\r
-      //\r
-      // MorControl is expected, directly return to avoid unnecessary variable operation\r
-      //\r
-      return EFI_SUCCESS;\r
-    }\r
     //\r
-    // Clear MOR_CLEAR_MEMORY_BIT\r
+    // Create a Ready To Boot Event and Clear the MorControl bit in the call back function.\r
     //\r
-    DEBUG ((EFI_D_INFO, "TcgMor: Clear MorClearMemory bit\n"));\r
-    MorControl &= 0xFE;\r
-  }\r
+    DEBUG ((EFI_D_INFO, "TcgMor: Create ReadyToBoot Event for MorControl Bit cleanning!\n"));\r
+    Status = EfiCreateEventReadyToBootEx (\r
+               TPL_CALLBACK,\r
+               OnReadyToBoot,\r
+               NULL,\r
+               &Event\r
+               );\r
+  }    \r
   \r
-  Status = gRT->SetVariable (\r
-                  MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
-                  &gEfiMemoryOverwriteControlDataGuid, \r
-                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                  DataSize, \r
-                  &MorControl\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
   return Status;\r
 }\r
 \r