From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.107.4.79; helo=eur03-db5-obe.outbound.protection.outlook.com; envelope-from=achin.gupta@arm.com; receiver=edk2-devel@lists.01.org Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40079.outbound.protection.outlook.com [40.107.4.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 602F72034A7B3 for ; Thu, 26 Oct 2017 03:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=GMwhWThLLz/kIckDaQLxhm69pKAhAJ9DqDQYXmQFolg=; b=daZQ6ABuA61m8ILNa4L+UXHWS0h462fOTGyk6CHRkUDXBq4h5ksBgF3HEmdRBqvikhewJ1cGCIPiU9gTfSrU61i8rNFkRIbEA58AKz2q8ua6Lhd4JjKxj/VBk9vdK7f1sBSNxNVFlDcMGb3llob3F1Vl+cl5cvO58Ji6rdWfxpM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Achin.Gupta@arm.com; Received: from e104320-lin (217.140.96.140) by HE1PR08MB2699.eurprd08.prod.outlook.com (2603:10a6:7:2b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.156.4; Thu, 26 Oct 2017 10:13:04 +0000 Date: Thu, 26 Oct 2017 11:13:49 +0100 From: Achin Gupta To: Supreeth Venkatesh Cc: edk2-devel@lists.01.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, nd@arm.com Message-ID: <20171026101349.GY25095@e104320-lin> References: <20171025163258.47961-1-supreeth.venkatesh@arm.com> <20171025163258.47961-3-supreeth.venkatesh@arm.com> MIME-Version: 1.0 In-Reply-To: <20171025163258.47961-3-supreeth.venkatesh@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: AM5P190CA0007.EURP190.PROD.OUTLOOK.COM (2603:10a6:206:14::20) To HE1PR08MB2699.eurprd08.prod.outlook.com (2603:10a6:7:2b::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 413e96a5-632e-4164-d41e-08d51c5a25e3 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(4534020)(4602075)(4627075)(201703031133081)(201702281549075)(2017052603199); SRVR:HE1PR08MB2699; X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB2699; 3:EIv5B6sRWCut7iabAMQAi3BHc3aigM+DJ+Ck7jqFKOm+1Uukv/UfTFRBXyZy09Ydazr4nctTiyDJ9jUDV219MFY3/HypSlCgPdRRxWvTr9UAGz3A6qNgtae2U+nYA9xZtD5qf2ySyA4++vTg6OOI17mI7guDBqjQKI0hZMQ/jv9QJltdOSUwteEo7ugUAluBWipAKPqdrKK0cefsro7NVNUko5DTlXWgwhbhJL0b1K4YlswO6Wr4oP7rT5zMqpgu; 25:ekFteK20z7gxzes0spgdJ2P/p3xe9OXOCLN/7Bngq5MLdl1Mw7xMKC3JifglI0yxScrW7qWHUTI8A4PKgXRz4VAtXwOpcC7pAaO7yHS7iVXAjBSsRfsA4LSHqoephRAT/qLCh/7MM8g7T2DJtdNA15HHXuh7iddM+2+lPjQGJ6LjUXr61xYT0TgCtghR99HXmduWd9UswS5ksgZVbrqpZLFWAIT+NDGAjixy9oT5t6SYSmnIbbeMuW8gHNP0dpQJn3MZdbuN7I31DN7CgoUSXrMkkxfIp94cPn7XzB2uZMVRPQjjeJkscallG8agPMkND2AuEry3HQ/PdlMexIZM4sS/ELP+N4DX0jyqyvNuVAQ=; 31:p0YI8P4mCtiFxWc/PfbBCuRfxYnjfgqf4LU5UlIK6/gf5kEXMqko0zroCj1OU3XRMxPH6LQSmxO+jyNWat60O4N9GU3tRN5DJJ6M7+Qs5VxXtAp6pXJlD6TPVLsxVrRBd16a3zIswit1dbO3jJVUdvfSCFg3P9jOkv/unIW78dzhOPnI03jUZNiiC6GGyOx35Hd3mlyRfhxiOuEeqwfD1MT+1eldqtBWazRai5LFtPA= X-MS-TrafficTypeDiagnostic: HE1PR08MB2699: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB2699; 20:xjqNKuR6IYcXGEPN1A0OWoQWP54qg4/ljsPG23g5y5lkTebuX91+u+9XnPDJ1FpWxC3+A38sxsOU0MD+hjLyPzGnwrEuTtWnxGwA+WY5mH0xZlrj74WTNUGPWfiSXjy7QSexqxlP7bvwDrKFx9H9c9veP/cgABpO1JbqHbEyETY=; 4:/SIAawyDG9iUVqeiQEqB1U5Pw3eBYXd9HQoj+Bs96EMsiBw8m8+wTpkU566iIa41xeho6uM5O3+oYTcxs+RnSbmO85MRiokqQIyngANrYf712OOR2a2KKslp+7d2LyQL1CeuYXHtFIEoJgic0qRcQ7PIQosZ1kM7cez2rN1ZSwzFZXq6fniFfTkMYCEMljfq1GmwxboWwsit5wIYASTlK0lNFcP8lrLM/lGMkfPScLQR6xSy4E2TbccI8aWgTgegIaR/gGPEcBkw+2YKZyRCfjg6RNYlnvrJw/8O4ZOFzHSIvh49NZ7gZCE6o+w6B3yiwqvc6z2tCog+39bIVEzNAA== X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(17755550239193); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231020)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123560025)(20161123562025)(20161123555025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR08MB2699; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR08MB2699; X-Forefront-PRVS: 04724A515E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(376002)(346002)(189002)(199003)(24454002)(9686003)(6246003)(8936002)(54356999)(4326008)(101416001)(105586002)(76176999)(229853002)(7736002)(23726003)(97736004)(81166006)(16799955002)(305945005)(6496005)(106356001)(15188155005)(8676002)(81156014)(3846002)(68736007)(53376002)(33656002)(6116002)(189998001)(72206003)(83506002)(50466002)(5660300001)(55016002)(50986999)(25786009)(33716001)(1076002)(316002)(966005)(53936002)(478600001)(16526018)(6306002)(66066001)(6862004)(16586007)(6666003)(47776003)(6636002)(86362001)(2906002)(58126008)(2950100002)(18370500001)(107986001)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR08MB2699; H:e104320-lin; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR08MB2699; 23:PklamYaT6xiFamFuT7RctbZr1B43JvjdZIWUEM1gp?= =?us-ascii?Q?LdYYWw8wl+eFdYaqukZzZxY5BId/+BJbuHwaLPY585LSLWMdd1TmWnFmS/8X?= =?us-ascii?Q?eYH33k4opiHpz+6dpOHMOnrWZXUf0v+MQUbLKbHLrzXPHKQsExTgd0kUDgqx?= =?us-ascii?Q?9LevLcW0vlH2aosGxE/Ks77lUmEbn5p3J58Tun5FaVWQVNCgcb8E5vGWgJQd?= =?us-ascii?Q?ZYUma8DYGHVdSQQ2q3ucdoLDlygcu8qufZmhDUykvrQGNE+dxrQNrXBINdt+?= =?us-ascii?Q?SC71UxB8HBouX91PqEN3RKA6yMHzzCIhSV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AyWR66x1Qt/0Q4CfOYjyATMbt9vIPYk2yHZmfn/+mQvyYIzIjSR+3E7MvlxwyUbiAd/eLm+UqZFRXnbBbGWuLs3Og/CHBCpGoI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2017 10:13:04.7521 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 413e96a5-632e-4164-d41e-08d51c5a25e3 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB2699 Subject: Re: [PATCH v2 2/3] ArmPkg/Drivers: Add EFI_MM_COMMUNICATION_PROTOCOL DXE driver. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Oct 2017 10:09:23 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi Supreeth, some CIL, On Wed, Oct 25, 2017 at 05:32:57PM +0100, Supreeth Venkatesh wrote: > PI v1.5 Specification Volume 4 defines Management Mode Core Interface > and defines EFI_MM_COMMUNICATION_PROTOCOL. This protocol provides a > means of communicating between drivers outside of MM and MMI > handlers inside of MM. > > This patch implements the EFI_MM_COMMUNICATION_PROTOCOL DXE runtime > driver for AARCH64 platforms. It uses SMCs allocated from the standard > SMC range defined in > http://infocenter.arm.com/help/topic/com.arm.doc.den0060a/DEN0060A_ARM_MM_Interface_Specification.pdf > to communicate with the standalone MM environment in the secure world. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Achin Gupta > Signed-off-by: Supreeth Venkatesh > --- > .../Drivers/MmCommunicationDxe/MmCommunication.c | 339 +++++++++++++++++++++ > 1 file changed, 339 insertions(+) > create mode 100644 ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c > > diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c > new file mode 100644 > index 0000000000..ecf70e666c > --- /dev/null > +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c > @@ -0,0 +1,339 @@ > +/** @file > + > + Copyright (c) 2016-2017, ARM Limited. All rights reserved. > + > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the BSD License > + which accompanies this distribution. The full text of the license may be found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > + > +#include > + > +/** > + Communicates with a registered handler. > + > + This function provides an interface to send and receive messages to the > + Standalone MM environment on behalf of UEFI services. This function is part > + of the MM Communication Protocol that may be called in physical mode prior to > + SetVirtualAddressMap() and in virtual mode after SetVirtualAddressMap(). > + > + @param[in] This The EFI_MM_COMMUNICATION_PROTOCOL instance. > + @param[in, out] CommBuffer A pointer to the buffer to convey into MMRAM. > + @param[in, out] CommSize The size of the data buffer being passed in.On exit, the size of data > + being returned. Zero if the handler does not wish to reply with any data. > + > + @retval EFI_SUCCESS The message was successfully posted. > + @retval EFI_INVALID_PARAMETER The CommBuffer was NULL. > + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM implementation. If this error is > + returned, the MessageLength field in the CommBuffer header or the integer > + pointed by CommSize are updated to reflect the maximum payload size the > + implementation can accommodate. > + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommSize parameter, if not omitted, > + are in address range that cannot be accessed by the MM environment > +**/ > +EFI_STATUS > +EFIAPI > +MmCommunicationCommunicate ( > + IN CONST EFI_MM_COMMUNICATION_PROTOCOL *This, > + IN OUT VOID *CommBuffer, > + IN OUT UINTN *CommSize OPTIONAL > + ); > + > +// > +// Address, Length of the pre-allocated buffer for communication with the secure > +// world. > +// > +STATIC ARM_MEMORY_REGION_DESCRIPTOR mNsCommBuffMemRegion; > + > +// Notification event when virtual address map is set. > +STATIC EFI_EVENT mSetVirtualAddressMapEvent; > + > +// > +// Handle to install the MM Communication Protocol > +// > +STATIC EFI_HANDLE mMmCommunicateHandle; > + > +// > +// MM Communication Protocol instance > +// > +EFI_MM_COMMUNICATION_PROTOCOL mMmCommunication = { > + MmCommunicationCommunicate > +}; > + > +/** > + Communicates with a registered handler. > + > + This function provides an interface to send and receive messages to the > + Standalone MM environment on behalf of UEFI services. This function is part > + of the MM Communication Protocol that may be called in physical mode prior to > + SetVirtualAddressMap() and in virtual mode after SetVirtualAddressMap(). > + > + @param[in] This The EFI_MM_COMMUNICATION_PROTOCOL instance. > + @param[in, out] CommBuffer A pointer to the buffer to convey into SMRAM. > + @param[in, out] CommSize The size of the data buffer being passed in.On exit, the size of data > + being returned. Zero if the handler does not wish to reply with any data. > + > + @retval EFI_SUCCESS The message was successfully posted. > + @retval EFI_INVALID_PARAMETER The CommBuffer was NULL. > + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM implementation. If this error is > + returned, the MessageLength field in the CommBuffer header or the integer > + pointed by CommSize are updated to reflect the maximum payload size the > + implementation can accommodate. > + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommSize parameter, if not omitted, > + are in address range that cannot be accessed by the MM environment > +**/ > +EFI_STATUS > +EFIAPI > +MmCommunicationCommunicate ( > + IN CONST EFI_MM_COMMUNICATION_PROTOCOL *This, > + IN OUT VOID *CommBuffer, > + IN OUT UINTN *CommSize > + ) > +{ > + EFI_MM_COMMUNICATE_HEADER *CommunicateHeader; > + ARM_SMC_ARGS CommunicateSmcArgs; > + EFI_STATUS Status; > + UINTN BufferSize; > + > + CommunicateHeader = CommBuffer; > + Status = EFI_SUCCESS; > + BufferSize = 0; > + > + ZeroMem (&CommunicateSmcArgs, sizeof (ARM_SMC_ARGS)); > + > + // > + // Check parameters > + // > + if (CommBuffer == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + // If the length of the CommBuffer is 0 then return the expected length. > + if (CommSize) { > + if (*CommSize == 0) { > + *CommSize = mNsCommBuffMemRegion.Length; > + return EFI_BAD_BUFFER_SIZE; > + } > + // > + // CommSize must hold HeaderGuid and MessageLength > + // > + if (*CommSize < sizeof (EFI_MM_COMMUNICATE_HEADER)) { > + return EFI_INVALID_PARAMETER; > + } > + BufferSize = *CommSize; > + } else { > + BufferSize = CommunicateHeader->MessageLength + > + sizeof (CommunicateHeader->HeaderGuid) + > + sizeof (CommunicateHeader->MessageLength); > + } > + > + // > + // If the buffer size is 0 or greater than what can be tolerated by the MM > + // environment then return the expected size. > + // > + if ((BufferSize == 0) || > + (BufferSize > mNsCommBuffMemRegion.Length)) { > + CommunicateHeader->MessageLength = mNsCommBuffMemRegion.Length - > + sizeof (CommunicateHeader->HeaderGuid) - > + sizeof (CommunicateHeader->MessageLength); > + return EFI_BAD_BUFFER_SIZE; > + } > + > + // SMC Function ID > + CommunicateSmcArgs.Arg0 = ARM_SMC_ID_MM_COMMUNICATE_AARCH64; > + > + // Reserved for Future. Must be Zero. > + CommunicateSmcArgs.Arg1 = 0; > + > + if (mNsCommBuffMemRegion.VirtualBase) { > + CopyMem ((VOID *)mNsCommBuffMemRegion.VirtualBase, CommBuffer, BufferSize); > + } Should the else condition not assert as VirtualBase should always be non-zero? > + > + // For the SMC64 version, this parameter is a 64-bit Physical Address (PA) > + // or Intermediate Physical Address (IPA). > + // For the SMC32 version, this parameter is a 32-bit PA or IPA. > + CommunicateSmcArgs.Arg2 = (UINTN)mNsCommBuffMemRegion.PhysicalBase; > + > + // comm_size_address is a PA or an IPA that holds the size of the > + // communication buffer being passed in. This parameter is optional > + // and can be omitted by passing a zero. > + // ARM does not recommend using it since this might require the > + // implementation to create a separate memory mapping for the parameter. > + // ARM recommends storing the buffer size in the buffer itself. > + CommunicateSmcArgs.Arg3 = 0; If CommSize has been used then the spec. does not say if CommunicateHeader->MessageLength must match it. IMH, we should update the latter with the former to prevent a situation where neither indicates the size of the buffer. > + > + // Call the Standalone MM environment. > + ArmCallSmc (&CommunicateSmcArgs); > + > + Status = CommunicateSmcArgs.Arg0; > + switch (Status) { > + case ARM_SMC_MM_RET_SUCCESS: > + // On exit, the size of data being returned is inferred from > + // CommSize or MessageLength + Header. > + CopyMem (CommBuffer, (const VOID *)mNsCommBuffMemRegion.VirtualBase, BufferSize); > + break; > + > + case ARM_SMC_MM_RET_NOT_SUPPORTED: Can we treat this as a spurious error below and assert? > + case ARM_SMC_MM_RET_INVALID_PARAMS: > + Status = EFI_INVALID_PARAMETER; > + break; > + > + case ARM_SMC_MM_RET_DENIED: > + Status = EFI_ACCESS_DENIED; > + break; > + > + case ARM_SMC_MM_RET_NO_MEMORY: > + // Unexpected error since the CommSize was checked for zero length > + // prior to issuing the SMC A better explanation might be: Since this driver relies on a buffer pre-allocated by the secure world this error code should never be returned. Also, to handle this case there should be an assertion here? > + default: > + Status = EFI_ACCESS_DENIED; > + ASSERT (0); Can we print an error string here since the secure world has just returned an unknown error code. > + } > + > + return Status; > +} > + > +/** > + Notification callback on SetVirtualAddressMap event. > + > + This function notifies the MM communication protocol interface on > + SetVirtualAddressMap event and converts pointers used in this driver > + from physical to virtual address. > + > + @param Event SetVirtualAddressMap event. > + @param Context A context when the SetVirtualAddressMap triggered. > + > + @retval EFI_SUCCESS The function executed successfully. > + @retval Other Some error occurred when executing this function. > + > +**/ > +STATIC > +VOID > +EFIAPI > +NotifySetVirtualAddressMap ( > + IN EFI_EVENT Event, > + IN VOID *Context > + ) > +{ > + EFI_STATUS Status; > + > + Status = gRT->ConvertPointer (EFI_OPTIONAL_PTR, > + (VOID **)&mNsCommBuffMemRegion.VirtualBase > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "NotifySetVirtualAddressMap(): Unable to convert MM runtime pointer. Status:0x%x\n", Status)); > + } > + > +} > + > +/** > + The Entry Point for MM Communication > + > + This function installs the MM communication protocol interface and finds out > + what type of buffer management will be required prior to invoking the > + communication SMC. > + > + @param ImageHandle The firmware allocated handle for the EFI image. > + @param SystemTable A pointer to the EFI System Table. > + > + @retval EFI_SUCCESS The entry point is executed successfully. > + @retval Other Some error occurred when executing this entry point. > + > +**/ > +EFI_STATUS > +EFIAPI > +MmCommunicationInitialize ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + Forgot to mention this earlier but we should first invoke MM_VERSION to ensure the driver is dealing with the right interface and possibly print this. > + mNsCommBuffMemRegion.PhysicalBase = 0; > + mNsCommBuffMemRegion.VirtualBase = 0; > + mNsCommBuffMemRegion.Length = 0; > + > + mNsCommBuffMemRegion.PhysicalBase = PcdGet64 (PcdMmBufferBase); > + // During boot , Virtual and Physical are same > + mNsCommBuffMemRegion.VirtualBase = mNsCommBuffMemRegion.PhysicalBase; > + mNsCommBuffMemRegion.Length = PcdGet64 (PcdMmBufferSize); > + > + if (mNsCommBuffMemRegion.PhysicalBase == 0) { > + DEBUG ((DEBUG_ERROR, "MmCommunicateInitialize: Invalid MM Buffer Base Address.\n")); > + return EFI_INVALID_PARAMETER; > + } > + > + if (mNsCommBuffMemRegion.Length == 0) { > + DEBUG ((DEBUG_ERROR, "MmCommunicateInitialize: Maximum Buffer Size is zero.\n")); > + return EFI_INVALID_PARAMETER; > + } > + > + Status = gDS->AddMemorySpace (EfiGcdMemoryTypeSystemMemory, > + mNsCommBuffMemRegion.PhysicalBase, > + mNsCommBuffMemRegion.Length, > + EFI_MEMORY_WB | > + EFI_MEMORY_XP | EFI_MEMORY_XP is not used on AArch64? cheers, Achin > + EFI_MEMORY_RUNTIME); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "MmCommunicateInitialize: Failed to add MM-NS Buffer Memory Space\n")); > + return EFI_INVALID_PARAMETER; > + } > + > + Status = gDS->SetMemorySpaceAttributes(mNsCommBuffMemRegion.PhysicalBase, > + mNsCommBuffMemRegion.Length, > + EFI_MEMORY_WB | EFI_MEMORY_XP); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "MmCommunicateInitialize: Failed to set MM-NS Buffer Memory attributes\n")); > + return EFI_INVALID_PARAMETER; > + } > + > + Status = gBS->AllocatePages (AllocateAddress, > + EfiRuntimeServicesData, > + EFI_SIZE_TO_PAGES (mNsCommBuffMemRegion.Length), > + &mNsCommBuffMemRegion.PhysicalBase); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "MmCommunicateInitialize: Failed to allocate MM-NS Buffer Memory Space\n")); > + return EFI_INVALID_PARAMETER; > + } > + > + // Install the communication protocol > + Status = gBS->InstallProtocolInterface (&mMmCommunicateHandle, > + &gEfiMmCommunicationProtocolGuid, > + EFI_NATIVE_INTERFACE, > + &mMmCommunication); > + if (EFI_ERROR(Status)) { > + DEBUG ((DEBUG_ERROR, "MmCommunicationInitialize: Failed to install MM communication protocol\n")); > + return EFI_INVALID_PARAMETER; > + } > + > + // Register notification callback when virtual address is associated > + // with the physical address. > + // Create a Set Virtual Address Map event. > + // > + Status = gBS->CreateEvent (EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, // Type > + TPL_NOTIFY, // NotifyTpl > + NotifySetVirtualAddressMap, // NotifyFunction > + NULL, // NotifyContext > + &mSetVirtualAddressMapEvent // Event > + ); > + ASSERT_EFI_ERROR (Status); > + > + return Status; > +} > -- > 2.14.1 >