From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a01:111:f400:fe07::603; helo=eur02-am5-obe.outbound.protection.outlook.com; envelope-from=achin.gupta@arm.com; receiver=edk2-devel@lists.01.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02on0603.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe07::603]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F2419209605DE for ; Mon, 9 Jul 2018 08:46:05 -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:X-MS-Exchange-SenderADCheck; bh=YgpK9KZQ0hu307hgc194XGjG8TASe8Yt2JA8p9ME2ho=; b=oqimOTbWeTeimBQzzEeEyCrULq0Py6dnUp+hCQLHivjmrAPn3t7ARaLbUTMi42KpEga1xOJh0VwTK8Cfnbi+QJvSnYmRXO2wK/UkFySyy1Ho2C97v6lD/9HWteL3CLd1hcyqJaVaf3x9i0agUVLhaMnHQueZqapgaKR+b/BiaVQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Achin.Gupta@arm.com; Received: from e104320-lin (217.140.96.140) by DB7PR08MB2988.eurprd08.prod.outlook.com (2603:10a6:5:1c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.930.21; Mon, 9 Jul 2018 15:46:02 +0000 Date: Mon, 9 Jul 2018 16:47:40 +0100 From: Achin Gupta To: sughosh.ganu@arm.com Cc: edk2-devel@lists.01.org, Jiewen Yao , nd@arm.com, Supreeth Venkatesh Message-ID: <20180709154739.GB11021@e104320-lin> References: <1530610972-9659-1-git-send-email-supreeth.venkatesh@arm.com> MIME-Version: 1.0 In-Reply-To: <1530610972-9659-1-git-send-email-supreeth.venkatesh@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: AM5PR0202CA0006.eurprd02.prod.outlook.com (2603:10a6:203:69::16) To DB7PR08MB2988.eurprd08.prod.outlook.com (2603:10a6:5:1c::26) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7164001a-46c1-402a-01a4-08d5e5b31315 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:DB7PR08MB2988; X-Microsoft-Exchange-Diagnostics: 1; DB7PR08MB2988; 3:9LrxfJOrEyCqXG+MXFAlmXVKKfCA8H+Sm7riQAaY5MNJgkCYo6G5Bd+ImW5WdSPkGoNfVkZhlZWSYXniQ0BpNmcxPAgG1Oy/SDitPjoENf8mzb/L4Iv3I/W8ipfPPQCH3MRcMVJRny/QI3f8qX0IH7nyHnRAAt1yg9+V/rDK89ufhE40v7nvySu4qAKWP+FmzqcCPH2qFNIYXwNzAAhIgfXYJPla5D2xFTu3Fq8FCMi3jBXkYQ04573cEDP9X8ie; 25:Ydw5r9dsA1740zlVq11jjI+o3w6bC9rzUzyDky0DDti3oV8pSFxNsidPMt5dPB1alQcczmRhPWYHfKRVSgJE5HNg0LN5rPn4H1ZJGzmcJRnp9vPCWGmSDKi5+j7hsPCALxqK4Id9RMEENgj1i4japClt2Gb4kvOEkVjWG5GGEiKWHVgY4r1JMhihmpPA82mOQ3o7QoCBNzrIh7+0msf1kxe8uOBGg1jONdW76Z24N2dyQ0oigq2vEopglDu7wA2NEdcjFQZPUbA6a2h0zCgHTtjk3feurtYJ9vJwdNd5gsi0WHvvuKfeGOiperL26wwWQskSz4zVIMsNmALlTW7/YA==; 31:2Q2Kmj+aDrARLTDuUFnhncPk8W0gLVjH4UCdil+RUENMYP8H7r7yzHIzTuxeWNNSCe1/rQvGituwauD5JOLllVb/TNErGtTY21iWwaHcKiIJI+JnHO1K0IruGwA10tSQBhL29kPF7780B5OzVTAR0YVGR22TkrIHR+Wld8bHZrD1x/MZRDEzuVU6zPUfEEqVJSZN68eUc6hShNFVb0C3aZSkqw167blWTvDSO45QNLw= X-MS-TrafficTypeDiagnostic: DB7PR08MB2988: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; DB7PR08MB2988; 20:DvrfrY4s+bP/H+HwpEIkw49zW7qNnUXxgPlZoLSrBvMiucYan46iwUUwa1d190WVSui4xJ8zt6lNDezBHwJyRQ3vA/B6vPWrQmXsC03ri9iVTUg/MK7Dw/j3z8ixMfeCAV3j7FcEOAMpJaqMmiBFo8IOI05KMMWzPDmmkha8sU4=; 4:P/7ad1EdYj0xjypUHwzALGWN9knTNuEzgEZEoITFzy5edmAF1qivQ9JqfDBfMu2XdETTaiNBWeN+1ReQ/vqEtxY+Xm2n4wOafTHkaCgI1dGvHVNW1ewKfA5HI+GCF6SHHCxTFpnxlspcJM+x6SAXrU9qVA9vN+5s0kRyFyAGo52ZH+iV1ncCoiscVhBrbj+bMcNnvEDFfbcZ1S4Wbp7WVUn4eBsEksWxqMAdVMOs+BfTIliPOoU2ypNSHsl9yL470b6i5Ypr2ng3KNd4jZPlwPohJ/YMuC7qGA61TsYwGQ3oQUoZBoAmEUcCOMvk/rJ1BN8u3ypgQxVjYCXKfzAi4JI+0fLqC3BRrwINcZgS+Vb8/KgsQTjRMFlBibJC9ydo X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(166708455590820)(228905959029699); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231311)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:DB7PR08MB2988; BCL:0; PCL:0; RULEID:; SRVR:DB7PR08MB2988; X-Forefront-PRVS: 07283408BE X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6029001)(366004)(39860400002)(396003)(136003)(376002)(346002)(199004)(189003)(54906003)(7736002)(66066001)(47776003)(97736004)(106356001)(105586002)(81166006)(81156014)(8676002)(33656002)(8936002)(229853002)(55016002)(50466002)(2361001)(2351001)(1076002)(44832011)(6496006)(6306002)(966005)(478600001)(72206003)(4326008)(25786009)(15188155005)(53376002)(11346002)(6246003)(2906002)(446003)(486006)(26005)(52116002)(86362001)(386003)(34206002)(16526019)(33896004)(76176011)(33716001)(58126008)(3846002)(6116002)(316002)(16799955002)(6666003)(14444005)(16586007)(5660300001)(956004)(9686003)(68736007)(53936002)(476003)(23726003)(305945005)(6636002)(18370500001)(107986001)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR08MB2988; H:e104320-lin; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB7PR08MB2988; 23:LKxzPJm/+mvB0eWGVUn3A7T7DdlF36wT1MCdnZQ6B?= =?us-ascii?Q?1PaERtOp9eAZXULoai2Wj5b2PkeVf8zwxmKdTSHqhrgxXn+dY2XR35phglkO?= =?us-ascii?Q?aOCW+HRWWtmVtYSs3jxNVymjWLkWSjv5Cgmeg8hlJKlO3DD/msuigsAp1I64?= =?us-ascii?Q?enfBtYJDqbEpZt5UL4oNqAI+DLw6JL3cpo7A8GcMsCWIY4C5v75lB2WErmF9?= =?us-ascii?Q?nOq1MUYnvvkQS/KYu5F+LvZIT7QjL8yku6CDQIdc7DOa4WtIdHs2LBw5ML95?= =?us-ascii?Q?ygQB6wACmZdQW9LncGIiORGbgqbIJdIG/ORdR41JtP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su3PxvQ4jr30bqoYtCf7Xo/44ZweOhZ5n2+2fVU+ZWaPeLn1kVbKBwEfwRhJdYnWelHmEkI91IlwduItWX33gP90H9xLUsKOAAtzcmYSGrJhl0k6UrEAFns/4SfL62qrJMEPC7ZpLdvT4bt8eUNhFRAdCiSN5l/IjvPFEC7vkfAal8PDGUCq2VIfbAPxndjBm8e/Y17o6IuC4N08hz3XKtCzvtLn9Z5Tcj96iqHilO8kP5TLuk+d24nDj4FSeUN6IuSkinPgFl169+0bAh2C6uilHqAWXeTpgnmQU10pWjVUJz5/YV7Mg==; 5:Ytfg0eUJsEHNQKgrGG3FN4bUbqI340tTcqxc+IVOVDh2xhfxLlgNVN6UEQIC1M5UbR8LEmZxi079cGnvZm4Na7D6Z8FMx5BOnakzxUUwFZ2fzCRjFe9pzXFspyBBbYDD7ivWiFMTqP26e5SsbnV87ynnf3+zQkqItfEr3xHxdUg=; 24:kL5dRjM2t0nLPa1IEvVIUTET1YuVzxv/Eoo+92/K88nfYVNjhJwPfqb9489+QdoAeVsEuEWY8dXTBeweYnvd9z8eJUiQk16R626DPgk5fbM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB7PR08MB2988; 7:33GVeo8Dih2dXkdas0Sp3yadsT45yw6AUdtmpjWoSBIVlJJQAaolUBlELGOT1DxY1XmeqaFyRAJ+IrVpXGPM8pqp/yoOWdffRd3oC0H6h0ovT59utECwiIjH/G24EAeMIQCITYgflXuwE4Y9HS8w0Oe2TL1neHfsGhlIIrKQJrPX7F1bOgmWkspdSl9wg58cYUCxBUvyUpbvt/4pN8+mjUR6JMINfRHVdD401bYWgvZU5c88g80Eynt4Xaf08h2A X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2018 15:46:02.2031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7164001a-46c1-402a-01a4-08d5e5b31315 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB2988 Subject: Re: [PATCH 09/10] StandaloneMmPkg: Add CPU driver suitable for ARM Platforms. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jul 2018 15:46:06 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi Sughosh, CIL. On Tue, Jul 03, 2018 at 03:12:52PM +0530, Supreeth Venkatesh wrote: > This patch adds a simple CPU driver that exports the > EFI_MM_CONFIGURATION_PROTOCOL to allow registration of the Standalone > MM Foundation entry point. It preserves the existing notification > mechanism for the configuration protocol. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Achin Gupta > Signed-off-by: Supreeth Venkatesh > Cc: Jiewen Yao > Cc: Achin Gupta > --- > .../Drivers/StandaloneMmCpu/AArch64/EventHandle.c | 208 +++++++++++++++++++ > .../StandaloneMmCpu/AArch64/StandaloneMmCpu.c | 219 +++++++++++++++++++++ > .../StandaloneMmCpu/AArch64/StandaloneMmCpu.h | 64 ++++++ > .../StandaloneMmCpu/AArch64/StandaloneMmCpu.inf | 59 ++++++ > StandaloneMmPkg/Include/Guid/MpInformation.h | 41 ++++ > 5 files changed, 591 insertions(+) > create mode 100644 StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c > create mode 100644 StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c > create mode 100644 StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.h > create mode 100644 StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.inf > create mode 100644 StandaloneMmPkg/Include/Guid/MpInformation.h > > diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c > new file mode 100644 > index 0000000..5f39216 > --- /dev/null > +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c > @@ -0,0 +1,208 @@ > +/** @file > + > + Copyright (c) 2016 HP Development Company, L.P. > + Copyright (c) 2016 - 2018, 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 // for EFI_SYSTEM_CONTEXT > + > +#include > +#include > + > +#include > + > +#include "StandaloneMmCpu.h" > + > +EFI_STATUS > +EFIAPI > +MmFoundationEntryRegister( > + IN CONST EFI_MM_CONFIGURATION_PROTOCOL *This, > + IN EFI_MM_ENTRY_POINT MmEntryPoint > + ); > + > +// > +// On ARM platforms every event is expected to have a GUID associated with > +// it. It will be used by the MM Entry point to find the handler for the > +// event. It will either be populated in a EFI_MM_COMMUNICATE_HEADER by the > +// caller of the event (e.g. MM_COMMUNICATE SMC) or by the CPU driver > +// (e.g. during an asynchronous event). In either case, this context is > +// maintained in an array which has an entry for each CPU. The pointer to this > +// array is held in PerCpuGuidedEventContext. Memory is allocated once the > +// number of CPUs in the system are made known through the > +// MP_INFORMATION_HOB_DATA. > +// > +EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = NULL; > + > +// Descriptor with whereabouts of memory used for communication with the normal world > +EFI_MMRAM_DESCRIPTOR mNsCommBuffer; > + > +MP_INFORMATION_HOB_DATA *mMpInformationHobData; > + > +EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = { > + 0, > + MmFoundationEntryRegister > +}; > + > +static EFI_MM_ENTRY_POINT mMmEntryPoint = NULL; > + > +EFI_STATUS > +PiMmStandloneArmTfCpuDriverEntry ( > + IN UINTN EventId, > + IN UINTN CpuNumber, > + IN UINTN NsCommBufferAddr > + ) > +{ > + EFI_MM_COMMUNICATE_HEADER *GuidedEventContext = NULL; > + EFI_MM_ENTRY_CONTEXT MmEntryPointContext = {0}; > + EFI_STATUS Status; > + UINTN NsCommBufferSize; > + > + DEBUG ((DEBUG_INFO, "Received event - 0x%x on cpu %d\n", EventId, CpuNumber)); > + > + Status = EFI_SUCCESS; > + // > + // ARM TF passes SMC FID of the MM_COMMUNICATE interface as the Event ID upon > + // receipt of a synchronous MM request. Use the Event ID to distinguish > + // between synchronous and asynchronous events. > + // > + if (ARM_SMC_ID_MM_COMMUNICATE_AARCH64 != EventId) { > + DEBUG ((DEBUG_INFO, "UnRecognized Event - 0x%x\n", EventId)); > + return EFI_INVALID_PARAMETER; > + } else { Since the 'if' checks and error condition and returns, there is no need for the 'else'. > + // Perform parameter validation of NsCommBufferAddr > + > + if (NsCommBufferAddr && (NsCommBufferAddr < mNsCommBuffer.PhysicalStart)) > + return EFI_ACCESS_DENIED; Had left a comment in the previous version which I did not quite bottom out with Supreeth. Here goes again! This check is not enough before the NsCommBufferAddr is dereferenced in the next statement. There must be a check to ensure that NsCommBufferAddr points to enough memory to hold a EFI_MM_COMMUNICATE_HEADER. If NsCommBufferAddr = mNsCommBuffer.PhysicalStart - 1, then we are screwed. Suggest in addition to the above: if (NsCommBufferAddr + sizeof(EFI_MM_COMMUNICATE_HEADER) >= mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) return EFI_INVALID_PARAMETER; > + > + // Find out the size of the buffer passed > + NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) NsCommBufferAddr)->MessageLength + > + sizeof(((EFI_MM_COMMUNICATE_HEADER *)NsCommBufferAddr)->MessageLength) + > + sizeof(((EFI_MM_COMMUNICATE_HEADER *)NsCommBufferAddr)->HeaderGuid); Again something from previous version. This assignment is more complicated that it should be. Can it be changed to: ((EFI_MM_COMMUNICATE_HEADER *) NsCommBufferAddr)->MessageLength + sizeof(EFI_MM_COMMUNICATE_HEADER) > + > + // perform bounds check. > + if (NsCommBufferAddr + NsCommBufferSize >= > + mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) > + return EFI_ACCESS_DENIED; > + > + > + // Now that the secure world can see the normal world buffer, allocate > + // memory to copy the communication buffer to the secure world. > + Status = mMmst->MmAllocatePool(EfiRuntimeServicesData, NsCommBufferSize, (VOID **) &GuidedEventContext); Please split this statement accross multiple lines. > + if (Status != EFI_SUCCESS) { > + DEBUG ((DEBUG_INFO, "Mem alloc failed - 0x%x\n", EventId)); > + return EFI_OUT_OF_RESOURCES; > + } > + > + // X1 contains the VA of the normal world memory accessible from > + // S-EL0 > + CopyMem(GuidedEventContext, (CONST VOID *) NsCommBufferAddr, NsCommBufferSize); > + } > + > + // Stash the pointer to the allocated Event Context for this CPU > + PerCpuGuidedEventContext[CpuNumber] = GuidedEventContext; > + > + MmEntryPointContext.CurrentlyExecutingCpu = CpuNumber; > + MmEntryPointContext.NumberOfCpus = mMpInformationHobData->NumberOfProcessors; > + > + // Populate the MM system table with MP and state information > + mMmst->CurrentlyExecutingCpu = CpuNumber; > + mMmst->NumberOfCpus = mMpInformationHobData->NumberOfProcessors; > + mMmst->CpuSaveStateSize = 0; > + mMmst->CpuSaveState = NULL; > + > + if (mMmEntryPoint == NULL) { > + DEBUG ((DEBUG_INFO, "Mm Entry point Not Found\n")); > + return EFI_UNSUPPORTED; > + } > + > + mMmEntryPoint(&MmEntryPointContext); > + // Free the memory allocation done earlier and reset the per-cpu context > + ASSERT (GuidedEventContext); > + CopyMem ((VOID *)NsCommBufferAddr, (CONST VOID *) GuidedEventContext, NsCommBufferSize); > + Status = mMmst->MmFreePool((VOID *) GuidedEventContext); > + if (Status != EFI_SUCCESS) { > + return EFI_OUT_OF_RESOURCES; > + } > + PerCpuGuidedEventContext[CpuNumber] = NULL; > + > + return Status; > +} > + > +EFI_STATUS > +EFIAPI > +MmFoundationEntryRegister( > + IN CONST EFI_MM_CONFIGURATION_PROTOCOL *This, > + IN EFI_MM_ENTRY_POINT MmEntryPoint > + ) { Opening '{' on its own line. > + // store the entry point in a global > + mMmEntryPoint = MmEntryPoint; > + return EFI_SUCCESS; > +} > + > +/** > + This function is the main entry point for an MM handler dispatch > + or communicate-based callback. > + > + @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister(). > + @param Context Points to an optional handler context which was specified when the handler was registered. > + @param CommBuffer A pointer to a collection of data in memory that will > + be conveyed from a non-MM environment into an MM environment. > + @param CommBufferSize The size of the CommBuffer. > + > + @return Status Code > + > +**/ > +EFI_STATUS > +EFIAPI > +PiMmCpuTpFwRootMmiHandler ( > + IN EFI_HANDLE DispatchHandle, > + IN CONST VOID *Context, OPTIONAL > + IN OUT VOID *CommBuffer, OPTIONAL > + IN OUT UINTN *CommBufferSize OPTIONAL > + ) > +{ > + EFI_STATUS Status; > + UINTN CpuNumber; > + > + ASSERT (Context == NULL); > + ASSERT (CommBuffer == NULL); > + ASSERT (CommBufferSize == NULL); > + > + CpuNumber = mMmst->CurrentlyExecutingCpu; > + if (!PerCpuGuidedEventContext[CpuNumber]) > + return EFI_NOT_FOUND; > + > + DEBUG ((DEBUG_INFO, "CommBuffer - 0x%x, CommBufferSize - 0x%x\n", > + PerCpuGuidedEventContext[CpuNumber], > + PerCpuGuidedEventContext[CpuNumber]->MessageLength)); > + > + Status = mMmst->MmiManage(&PerCpuGuidedEventContext[CpuNumber]->HeaderGuid, > + NULL, > + PerCpuGuidedEventContext[CpuNumber]->Data, > + &PerCpuGuidedEventContext[CpuNumber]->MessageLength); closing ')' on its own line. > + > + if (Status != EFI_SUCCESS) { > + DEBUG ((DEBUG_WARN, "Unable to manage Guided Event - %d\n", Status)); > + } > + > + return Status; > +} > diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c > new file mode 100644 > index 0000000..fd4bbdc > --- /dev/null > +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c > @@ -0,0 +1,219 @@ > +/** @file > + > + Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
> + Copyright (c) 2016 HP Development Company, L.P. > + Copyright (c) 2016 - 2018, 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 // for EFI_SYSTEM_CONTEXT > + > +#include > +#include > + > + > +#include "StandaloneMmCpu.h" > + > +// GUID to identify HOB with whereabouts of communication buffer with Normal > +// World > +extern EFI_GUID gEfiStandaloneMmNonSecureBufferGuid; > + > +// GUID to identify HOB where the entry point of this CPU driver will be > +// populated to allow the entry point driver to invoke it upon receipt of an > +// event > +extern EFI_GUID gEfiArmTfCpuDriverEpDescriptorGuid; > + > +// > +// Private copy of the MM system table for future use > +// > +EFI_MM_SYSTEM_TABLE *mMmst = NULL; > + > +// > +// Globals used to initialize the protocol > +// > +static EFI_HANDLE mMmCpuHandle = NULL; > + > +EFI_STATUS > +GetGuidedHobData ( > + IN VOID *HobList, > + IN CONST EFI_GUID *HobGuid, > + OUT VOID **HobData) Closing ')' on its own line. > +{ > + EFI_HOB_GUID_TYPE *Hob; > + > + if (!HobList || !HobGuid || !HobData) > + return EFI_INVALID_PARAMETER; > + > + Hob = GetNextGuidHob (HobGuid, HobList); > + if (!Hob) > + return EFI_NOT_FOUND; > + > + *HobData = GET_GUID_HOB_DATA (Hob); > + if (!HobData) > + return EFI_NOT_FOUND; > + > + return EFI_SUCCESS; > +} > + > +EFI_STATUS > +StandloneMmCpuInitialize ( > + IN EFI_HANDLE ImageHandle, // not actual imagehandle > + IN EFI_MM_SYSTEM_TABLE *SystemTable // not actual systemtable > + ) > +{ > + ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc; > + EFI_CONFIGURATION_TABLE *ConfigurationTable; > + MP_INFORMATION_HOB_DATA *MpInformationHobData; > + EFI_MMRAM_DESCRIPTOR *NsCommBufMmramRange; > + EFI_STATUS Status; > + EFI_HANDLE DispatchHandle; > + UINT32 MpInfoSize; > + UINTN Index; > + UINTN ArraySize; > + VOID *HobStart; > + > + ASSERT (SystemTable != NULL); > + mMmst = SystemTable; > + > + // publish the MM config protocol so the MM core can register its entry point > + Status = mMmst->MmInstallProtocolInterface (&mMmCpuHandle, > + &gEfiMmConfigurationProtocolGuid, > + EFI_NATIVE_INTERFACE, > + &mMmConfig); Closing ')' on its own line. Also the indentation of function parameters needs to be changed. See 5.2.2.4 in EDK2 coding guide. Another example in [1]. [1] https://github.com/tianocore/edk2/blob/master/MdePkg/Library/SmmMemLib/SmmMemLib.c#L363 > + if (EFI_ERROR(Status)) { > + return Status; > + } > + > + // register the root MMI handler > + Status = mMmst->MmiHandlerRegister (PiMmCpuTpFwRootMmiHandler, > + NULL, > + &DispatchHandle); Ditto as previous comment. > + if (EFI_ERROR(Status)) { > + return Status; > + } > + > + // Retrieve the Hoblist from the MMST to extract the details of the NS > + // communication buffer that has been reserved by S-EL1/EL3 > + ConfigurationTable = mMmst->MmConfigurationTable; > + for (Index = 0; Index < mMmst->NumberOfTableEntries; Index++) { > + if (CompareGuid (&gEfiHobListGuid, &(ConfigurationTable[Index].VendorGuid))) { > + break; > + } > + } > + > + // Bail out if the Hoblist could not be found > + if (Index >= mMmst->NumberOfTableEntries) { > + DEBUG ((DEBUG_INFO, "Hoblist not found - 0x%x\n", Index)); > + return EFI_OUT_OF_RESOURCES; > + } > + > + HobStart = ConfigurationTable[Index].VendorTable; > + > + // > + // Locate the HOB with the buffer to populate the entry point of this driver > + // > + Status = GetGuidedHobData ( > + HobStart, > + &gEfiArmTfCpuDriverEpDescriptorGuid, > + (VOID **) &CpuDriverEntryPointDesc); Ditto as previous comment. > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_INFO, "ArmTfCpuDriverEpDesc HOB data extraction failed - 0x%x\n", Status)); > + return Status; > + } > + > + // Share the entry point of the CPU driver > + DEBUG ((DEBUG_INFO, "Sharing Cpu Driver EP *0x%lx = 0x%lx\n", > + (UINT64) CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr, > + (UINT64) PiMmStandloneArmTfCpuDriverEntry)); > + *(CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr) = PiMmStandloneArmTfCpuDriverEntry; > + > + // Find the descriptor that contains the whereabouts of the buffer for > + // communication with the Normal world. > + Status = GetGuidedHobData ( > + HobStart, > + &gEfiStandaloneMmNonSecureBufferGuid, > + (VOID **) &NsCommBufMmramRange); Ditto as previous comment. > + if (EFI_ERROR(Status)) { > + DEBUG ((DEBUG_INFO, "NsCommBufMmramRange HOB data extraction failed - 0x%x\n", Status)); > + return Status; > + } > + > + DEBUG ((DEBUG_INFO, "mNsCommBuffer.PhysicalStart - 0x%lx\n", (UINT64) NsCommBufMmramRange->PhysicalStart)); > + DEBUG ((DEBUG_INFO, "mNsCommBuffer.PhysicalSize - 0x%lx\n", (UINT64) NsCommBufMmramRange->PhysicalSize)); > + > + CopyMem (&mNsCommBuffer, NsCommBufMmramRange, sizeof(EFI_MMRAM_DESCRIPTOR)); > + DEBUG ((DEBUG_INFO, "mNsCommBuffer: 0x%016lx - 0x%lx\n", mNsCommBuffer.CpuStart, mNsCommBuffer.PhysicalSize)); > + > + // > + // Extract the MP information from the Hoblist > + // > + Status = GetGuidedHobData (HobStart, > + &gMpInformationHobGuid, > + (VOID **) &MpInformationHobData); Ditto as previous comment. > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_INFO, "MpInformationHob extraction failed - 0x%x\n", Status)); > + return Status; > + } > + > + // > + // Allocate memory for the MP information and copy over the MP information > + // passed by Trusted Firmware. Use the number of processors passed in the HOB > + // to copy the processor information > + // > + MpInfoSize = sizeof (MP_INFORMATION_HOB_DATA) + > + (sizeof (EFI_PROCESSOR_INFORMATION) * > + MpInformationHobData->NumberOfProcessors); > + Status = mMmst->MmAllocatePool (EfiRuntimeServicesData, > + MpInfoSize, > + (void **) &mMpInformationHobData); Ditto as previous comment. > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_INFO, "mMpInformationHobData mem alloc failed - 0x%x\n", Status)); > + return Status; > + } > + > + CopyMem (mMpInformationHobData, MpInformationHobData, MpInfoSize); > + > + // Print MP information > + DEBUG ((DEBUG_INFO, "mMpInformationHobData: 0x%016lx - 0x%lx\n", > + mMpInformationHobData->NumberOfProcessors, > + mMpInformationHobData->NumberOfEnabledProcessors)); > + for (Index = 0; Index < mMpInformationHobData->NumberOfProcessors; Index++) { > + DEBUG ((DEBUG_INFO, "mMpInformationHobData[0x%lx]: %d, %d, %d\n", > + mMpInformationHobData->ProcessorInfoBuffer[Index].ProcessorId, > + mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Package, > + mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Core, > + mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Thread)); > + } > + > + // > + // Allocate memory for a table to hold pointers to a > + // EFI_MM_COMMUNICATE_HEADER for each CPU > + // > + ArraySize = sizeof (EFI_MM_COMMUNICATE_HEADER *) * > + mMpInformationHobData->NumberOfEnabledProcessors; > + Status = mMmst->MmAllocatePool (EfiRuntimeServicesData, > + ArraySize, > + (VOID **) &PerCpuGuidedEventContext); Ditto as previous comment. cheers, Achin > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_INFO, "PerCpuGuidedEventContext mem alloc failed - 0x%x\n", Status)); > + return Status; > + } > + return Status; > +} > diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.h b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.h > new file mode 100644 > index 0000000..7b38b65 > --- /dev/null > +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.h > @@ -0,0 +1,64 @@ > +/** @file > + Private header with declarations and definitions specific to the MM Standalone > + CPU driver > + > + Copyright (c) 2017 - 2018, 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. > + > +**/ > + > +#ifndef _ARM_TF_CPU_DRIVER_H_ > +#define _ARM_TF_CPU_DRIVER_H_ > + > +#include > +#include > +#include > +#include > + > +// > +// CPU driver initialization specific declarations > +// > +extern EFI_MM_SYSTEM_TABLE *mMmst; > + > +// > +// CPU State Save protocol specific declarations > +// > +extern EFI_MM_CPU_PROTOCOL mMmCpuState; > + > +// > +// MM event handling specific declarations > +// > +extern EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext; > +extern EFI_MMRAM_DESCRIPTOR mNsCommBuffer; > +extern MP_INFORMATION_HOB_DATA *mMpInformationHobData; > +extern EFI_MM_CONFIGURATION_PROTOCOL mMmConfig; > + > +EFI_STATUS > +PiMmStandloneArmTfCpuDriverEntry ( > + IN UINTN EventId, > + IN UINTN CpuNumber, > + IN UINTN NsCommBufferAddr > + ); > + > +EFI_STATUS > +EFIAPI > +PiMmCpuTpFwRootMmiHandler ( > + IN EFI_HANDLE DispatchHandle, > + IN CONST VOID *Context, OPTIONAL > + IN OUT VOID *CommBuffer, OPTIONAL > + IN OUT UINTN *CommBufferSize OPTIONAL > + ); > + > +EFI_STATUS _PiMmStandloneArmTfCpuDriverEntry ( > + IN UINTN EventId, > + IN UINTN CpuNumber, > + IN UINTN NsCommBufferAddr > + ); > + > +#endif > diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.inf b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.inf > new file mode 100644 > index 0000000..9e6bbab > --- /dev/null > +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.inf > @@ -0,0 +1,59 @@ > +#/** @file > +# > +# Standalone MM CPU driver for ARM Standard Platforms > +# > +# Copyright (c) 2009, Apple Inc. All rights reserved.
> +# Copyright (c) 2016 HP Development Company, L.P. > +# Copyright (c) 2017 - 2018, 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. > +# > +#**/ > + > +[Defines] > + INF_VERSION = 0x0001001A > + BASE_NAME = StandloneMmCpu > + FILE_GUID = 58F7A62B-6280-42A7-BC38-10535A64A92C > + MODULE_TYPE = MM_STANDALONE > + VERSION_STRING = 1.0 > + PI_SPECIFICATION_VERSION = 0x00010032 > + ENTRY_POINT = StandloneMmCpuInitialize > + > +[Sources] > + StandaloneMmCpu.c > + EventHandle.c > + > +[Packages] > + ArmPkg/ArmPkg.dec > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + StandaloneMmPkg/StandaloneMmPkg.dec > + > +[LibraryClasses] > + ArmLib > + ArmSvcLib > + BaseMemoryLib > + DebugLib > + HobLib > + StandaloneMmDriverEntryPoint > + > +[Protocols] > + gEfiMmConfigurationProtocolGuid # PROTOCOL ALWAYS_PRODUCED > + gEfiMmCpuProtocolGuid # PROTOCOL ALWAYS_PRODUCED > + > +[Guids] > + gEfiHobListGuid > + gEfiMmPeiMmramMemoryReserveGuid > + gZeroGuid > + gMpInformationHobGuid > + gEfiStandaloneMmNonSecureBufferGuid > + gEfiArmTfCpuDriverEpDescriptorGuid > + > +[Depex] > + TRUE > diff --git a/StandaloneMmPkg/Include/Guid/MpInformation.h b/StandaloneMmPkg/Include/Guid/MpInformation.h > new file mode 100644 > index 0000000..c88ff4a > --- /dev/null > +++ b/StandaloneMmPkg/Include/Guid/MpInformation.h > @@ -0,0 +1,41 @@ > +/** @file > + EFI MP information protocol provides a lightweight MP_SERVICES_PROTOCOL. > + > + MP information protocol only provides static information of MP processor. > + > + Copyright (c) 2009, Intel Corporation. All rights reserved.
> + Copyright (c) 2016 - 2018, 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. > + > +**/ > + > +#ifndef _MP_INFORMATION_H_ > +#define _MP_INFORMATION_H_ > + > +#include > +#include > +#include > + > +#define MP_INFORMATION_GUID \ > + { \ > + 0xba33f15d, 0x4000, 0x45c1, {0x8e, 0x88, 0xf9, 0x16, 0x92, 0xd4, 0x57, 0xe3} \ > + } > + > +#pragma pack(1) > +typedef struct { > + UINT64 NumberOfProcessors; > + UINT64 NumberOfEnabledProcessors; > + EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer[]; > +} MP_INFORMATION_HOB_DATA; > +#pragma pack() > + > +extern EFI_GUID gMpInformationHobGuid; > + > +#endif > -- > 2.7.4 >