]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.c
Add security package to repository.
[mirror_edk2.git] / SecurityPkg / Tcg / MemoryOverwriteControl / TcgMor.c
diff --git a/SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.c b/SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.c
new file mode 100644 (file)
index 0000000..ce53112
--- /dev/null
@@ -0,0 +1,82 @@
+/** @file\r
+  TCG MOR (Memory Overwrite Request) Control Driver.\r
+\r
+  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
+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
+\r
+**/\r
+\r
+#include "TcgMor.h"\r
+\r
+/**\r
+  Entry Point for TCG MOR Control driver.\r
+\r
+  @param[in] ImageHandle  Image handle of this driver.\r
+  @param[in] SystemTable  A Pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCEESS     \r
+  @return Others          Some error occurs.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MorDriverEntryPoint (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       MorControl;\r
+  UINTN       DataSize;\r
+\r
+  ///\r
+  /// The firmware is required to create the MemoryOverwriteRequestControl UEFI variable.\r
+  ///\r
+\r
+  DataSize = sizeof (MorControl);\r
+  Status = gRT->GetVariable (\r
+                  MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
+                  &gEfiMemoryOverwriteControlDataGuid, \r
+                  NULL, \r
+                  &DataSize, \r
+                  &MorControl\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Set default value to 0\r
+    //\r
+    MorControl = 0;\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
+    //\r
+    DEBUG ((EFI_D_INFO, "TcgMor: Clear MorClearMemory bit\n"));\r
+    MorControl &= 0xFE;\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
+\r