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
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
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