]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/RuntimeDxe/TcgMorLockSmm.c
MdeModulePkg/Variable/RuntimeDxe: delay MorLock creation until EndOfDxe
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / TcgMorLockSmm.c
index 3b2d555d2e45a200fd9faccaa99e943c50b4a212..faeaabb224afc6fa9214fdc34191e94fce2ee864 100644 (file)
@@ -45,6 +45,7 @@ typedef enum {
   MorLockStateLocked = 1,\r
 } MOR_LOCK_STATE;\r
 \r
+BOOLEAN         mMorLockInitializationRequired = FALSE;\r
 UINT8           mMorLockKey[MOR_LOCK_V2_KEY_SIZE];\r
 BOOLEAN         mMorLockKeyEmpty = TRUE;\r
 BOOLEAN         mMorLockPassThru = FALSE;\r
@@ -392,10 +393,8 @@ MorLockInit (
   VOID\r
   )\r
 {\r
-  //\r
-  // Set variable to report capability to OS\r
-  //\r
-  return SetMorLockVariable (0);\r
+  mMorLockInitializationRequired = TRUE;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -408,7 +407,61 @@ MorLockInitAtEndOfDxe (
   VOID\r
   )\r
 {\r
+  UINTN      MorSize;\r
+  EFI_STATUS MorStatus;\r
+\r
+  if (!mMorLockInitializationRequired) {\r
+    //\r
+    // The EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL has never been installed, thus\r
+    // the variable write service is unavailable. This should never happen.\r
+    //\r
+    ASSERT (FALSE);\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Check if the MOR variable exists.\r
+  //\r
+  MorSize = 0;\r
+  MorStatus = VariableServiceGetVariable (\r
+                MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,\r
+                &gEfiMemoryOverwriteControlDataGuid,\r
+                NULL,                                   // Attributes\r
+                &MorSize,\r
+                NULL                                    // Data\r
+                );\r
   //\r
-  // Do nothing.\r
+  // We provided a zero-sized buffer, so the above call can never succeed.\r
   //\r
+  ASSERT (EFI_ERROR (MorStatus));\r
+\r
+  if (MorStatus == EFI_BUFFER_TOO_SMALL) {\r
+    //\r
+    // The MOR variable exists; set the MOR Control Lock variable to report the\r
+    // capability to the OS.\r
+    //\r
+    SetMorLockVariable (0);\r
+    return;\r
+  }\r
+\r
+  //\r
+  // The platform does not support the MOR variable. Delete the MOR Control\r
+  // Lock variable (should it exists for some reason) and prevent other modules\r
+  // from creating it.\r
+  //\r
+  mMorLockPassThru = TRUE;\r
+  VariableServiceSetVariable (\r
+    MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,\r
+    &gEfiMemoryOverwriteRequestControlLockGuid,\r
+    0,                                          // Attributes\r
+    0,                                          // DataSize\r
+    NULL                                        // Data\r
+    );\r
+  mMorLockPassThru = FALSE;\r
+\r
+  VariableLockRequestToLock (\r
+    NULL,                                       // This\r
+    MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,\r
+    &gEfiMemoryOverwriteRequestControlLockGuid\r
+    );\r
 }\r