+/** @file\r
+\r
+ Parts of the SMM/MM implementation that are specific to traditional MM\r
+\r
+Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2018, Linaro, Ltd. 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 <Library/UefiBootServicesTableLib.h>\r
+#include <Library/SmmMemLib.h>\r
+#include "Variable.h"\r
+\r
+/**\r
+ This function checks if the buffer is valid per processor architecture and\r
+ does not overlap with SMRAM.\r
+\r
+ @param Buffer The buffer start address to be checked.\r
+ @param Length The buffer length to be checked.\r
+\r
+ @retval TRUE This buffer is valid per processor architecture and does not\r
+ overlap with SMRAM.\r
+ @retval FALSE This buffer is not valid per processor architecture or overlaps\r
+ with SMRAM.\r
+**/\r
+BOOLEAN\r
+VariableSmmIsBufferOutsideSmmValid (\r
+ IN EFI_PHYSICAL_ADDRESS Buffer,\r
+ IN UINT64 Length\r
+ )\r
+{\r
+ return SmmIsBufferOutsideSmmValid (Buffer, Length);\r
+}\r
+\r
+/**\r
+ Notify the system that the SMM variable driver is ready\r
+**/\r
+VOID\r
+VariableNotifySmmReady (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HANDLE Handle;\r
+\r
+ Handle = NULL;\r
+ Status = gBS->InstallProtocolInterface (\r
+ &Handle,\r
+ &gEfiSmmVariableProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+ Notify the system that the SMM variable write driver is ready\r
+**/\r
+VOID\r
+VariableNotifySmmWriteReady (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HANDLE Handle;\r
+\r
+ Handle = NULL;\r
+ Status = gBS->InstallProtocolInterface (\r
+ &Handle,\r
+ &gSmmVariableWriteGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+ Variable service MM driver entry point\r
+\r
+ @param[in] ImageHandle A handle for the image that is initializing this\r
+ driver\r
+ @param[in] SystemTable A pointer to the EFI system table\r
+\r
+ @retval EFI_SUCCESS Variable service successfully initialized.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VariableServiceInitialize (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ return MmVariableServiceInitialize ();\r
+}\r
+\r
+/**\r
+ Whether the TCG or TCG2 protocols are installed in the UEFI protocol database.\r
+ This information is used by the MorLock code to infer whether an existing\r
+ MOR variable is legitimate or not.\r
+\r
+ @retval TRUE Either the TCG or TCG2 protocol is installed in the UEFI\r
+ protocol database\r
+ @retval FALSE Neither the TCG nor the TCG2 protocol is installed in the UEFI\r
+ protocol database\r
+**/\r
+BOOLEAN\r
+VariableHaveTcgProtocols (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ VOID *Interface;\r
+\r
+ Status = gBS->LocateProtocol (\r
+ &gEfiTcg2ProtocolGuid,\r
+ NULL, // Registration\r
+ &Interface\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ return TRUE;\r
+ }\r
+\r
+ Status = gBS->LocateProtocol (\r
+ &gEfiTcgProtocolGuid,\r
+ NULL, // Registration\r
+ &Interface\r
+ );\r
+ return !EFI_ERROR (Status);\r
+}\r