From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.107.8.71; helo=eur04-vi1-obe.outbound.protection.outlook.com; envelope-from=achin.gupta@arm.com; receiver=edk2-devel@lists.01.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80071.outbound.protection.outlook.com [40.107.8.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 63720209859B7 for ; Thu, 19 Jul 2018 12:03:29 -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=8dppCNckK7kB4TqkmUrNfa4GJGZYuCZDV1wGNKBo/Zk=; b=kTSsPZI/fPeBwr3IyYM9RPlP/0BFyMXIt4aaucNfFHlcNuGJj2G0Ioaf44mK1TzXa3VzdIqKUWKCWeng+jO6Jz5Uo0lMm4QaDM2b4LqDzUWqaaevu7Ns9/8lsN2PRFOR4I/ua5vW1hO0Os13v6qe0ug0ghZYsEYo18Am5q4NVsc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Achin.Gupta@arm.com; Received: from e104320-lin (217.140.96.140) by DB7PR08MB2985.eurprd08.prod.outlook.com (2603:10a6:5:1c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.952.18; Thu, 19 Jul 2018 19:03:25 +0000 Date: Thu, 19 Jul 2018 20:05:03 +0100 From: Achin Gupta To: Sughosh Ganu Cc: edk2-devel@lists.01.org, Jiewen Yao , Supreeth Venkatesh , nd@arm.com Message-ID: <20180719190503.GD11021@e104320-lin> References: <1531494330-1280-1-git-send-email-sughosh.ganu@arm.com> <1531494330-1280-10-git-send-email-sughosh.ganu@arm.com> MIME-Version: 1.0 In-Reply-To: <1531494330-1280-10-git-send-email-sughosh.ganu@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: VI1PR0502CA0013.eurprd05.prod.outlook.com (2603:10a6:803:1::26) To DB7PR08MB2985.eurprd08.prod.outlook.com (2603:10a6:5:1c::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 70dc29e3-0e00-4b42-d6d6-08d5edaa4e67 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:DB7PR08MB2985; X-Microsoft-Exchange-Diagnostics: 1; DB7PR08MB2985; 3:s2G1Ta2VzqT3NOaQepwyUTsK3KquxFmfhPvqiiuT5sRnOboA7RQWRArITWt8iWfBuGCgVz9z6yiVG67YbX6j6agnIUmGmStSwc3GzHzvnTX09+CcCM+H6jrSAMpmgvlWbp3663sgFupl4wuJIAZSWdmKqHvm5M/XasHb/dezST0r5g6Foi8Aw/KumCr6RPGWVw1wnLyzxp4aSKUdVJ9uBlZh6AemZXyrY2CT3EmULCfhXeugfi1Z5If9TTJon8Sn; 25:5ZPDy9n1xlNUc9I8zcw1SyMfwCBj42ZUw1NazcFxG9Aw9qNkpLOAMW6kKkn6RkWFEiS3PEl9kkIw3hUAMNs9Rf88PCZhPKyP0Q9Gw7M15Gtw/XdRYWMpNATCRAQDJk0hfNmdmx6uSjO2Bv5kC6lgsefvHuhdHeScZZZvenBurRJbL5v9TiWNwh7lz7aOX8vYG9fzZriSY+3fhojYnwdbjjw6SZAOZOWogZiGxal+OMvFld3UmlrcY0ycMsBM850l0yEu2IrdXV5ZKYreBKQDnmplK7eIkkIJ34tGLbeZaF35GWO066WvyZnlWzpt90IvCh3x49Tptj49YMZouQg0xg==; 31:LtF93Hd9rZvQDoVODzrz01T9OjoEkPfVVXUzRK+YUb2PtH04t+TzwjuVIpOOieoorY4kijT7Jr8qKYdrXnH29fKynb0Uvb5TSkwoTyBxXovRmTdp/WWjZVHscS3GsB5iIMxlglyN1UP5jfo96Qukq1rPSt1Yu9YPL3/zlLFhFBCNJFIL8djWs+pUCZwh7LSpWKgUSXnnW0qbGdKu79yTOSOsaRcM5F4cvWZ++J3L3JE= X-MS-TrafficTypeDiagnostic: DB7PR08MB2985: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; DB7PR08MB2985; 20:T1+Trp8TGQ6B4LPZPEBAwfucu0Qgc7LDyPBEgdFMEEPMw7QrA/vrSu7cpWTPM9CGqQ302bUPR88b82p0876H+J/pIegmgFLKbTY5C1ugqeRILEMPWd0bfybi4xV/tg1uiC020EDH2dbq1KKH59s/ihVtu1+THcPZizgHBXmR/Cs=; 4:qq2f0rrsblidA019vDk2NOrihOh+xbzC3GdECndjdZY3VqapAn0VbYXBSCuBk1LGdf+iwqpOa6p2cjXARbhr2eO8b2v+cX9RV868Hk8k32d5/htEj63WpmVtm0ATM5kKKPZluxKrj5eGG3729CU4+rAQggsdeRGk9456mhS3ePpyh5B2IJGFZmq2Q96KkDdpu2EYr0DgHZGglPHmu5Tg85Iev+ZzV/+t71EvUO/QcKtxpZPPoI5sUbYvS5L7HfeNGpdrHpKiTBKWPzQisdM4rxXTTQnDB7pa4ph84RtaOk3lPnm2yj6ZZuq/MFGqg4fX X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231311)(944501410)(52105095)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:DB7PR08MB2985; BCL:0; PCL:0; RULEID:; SRVR:DB7PR08MB2985; X-Forefront-PRVS: 0738AF4208 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6029001)(39860400002)(366004)(346002)(396003)(136003)(376002)(189003)(199004)(3846002)(229853002)(8676002)(33656002)(6496006)(305945005)(19627235002)(6666003)(7736002)(23726003)(52116002)(2906002)(81156014)(47776003)(68736007)(66066001)(76176011)(6116002)(6636002)(8936002)(446003)(11346002)(33896004)(81166006)(1076002)(478600001)(58126008)(6862004)(5660300001)(6246003)(26005)(9686003)(97736004)(50466002)(966005)(6306002)(54906003)(386003)(14444005)(16799955002)(53376002)(486006)(4326008)(15188155005)(105586002)(106356001)(86362001)(33716001)(44832011)(72206003)(16526019)(16586007)(476003)(316002)(53936002)(956004)(25786009)(55016002)(18370500001)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR08MB2985; H:e104320-lin; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB7PR08MB2985; 23:TOV7D6Gj8FzWBheNPKGoHVyaPcAS7D074UzR44EIh?= =?us-ascii?Q?1bBlZ1oH1t1qVesS0ZpSToqcjQd1DGMdb15ceiDxIbvjsglQXHi7rcNC00t7?= =?us-ascii?Q?2ScN4dbp7hwfB85KdXY2c1IIAEdDfRstaDVqJzcDMWtiJRtdXZiKyKDx5r48?= =?us-ascii?Q?UNxWjlB7xMkupEhbAXDkMayUHwlpiIb5B9xeIld7w3+U7rCP8R3MPVxyzPOl?= =?us-ascii?Q?BjFFjh+it1T+qxS3iKdVKSOUjMssVYJySLOGO50NLDJ6qc1elnxV3Kg/Z5OO?= =?us-ascii?Q?B8MqOnEyI/YbDBsFBqbtk1wkPVAibLgOQjwx5sXuw52ioYGj3IvksxMt1u96?= =?us-ascii?Q?se3VDHF4tn9X1J55hvwxDheankNYm6pi6TkuMwsMNUiNvlCBNa9eEn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ulKonbu6ofASGDM/SLnaySoMuxiqMchYmVolKtB2Fz0BimrRVieHwEoHSDKRiYBdypbGvWURMhy+EELX+79jcLdhuaKwb66rkuUVjHuQy2wA5autSLSf5QW8qOZdeVGYfqWWn25P45iy5TNsl2VXDTwsgezaxA==; 5:+B+F7JZkMmFBX7wfHL5vRwRvb8y0MeBvzIlTfFPmCCC1QcQlv2qD8VENyKatg4QIR3RrS57Jcb+1LgkVrPUhmlBkg12EzGrBN8ZCiSkZl5cDULFU5zukrdCpEl0NCJjP9YU5z1iyWwZD35y8Wm50vOnDwYG2z/mR3+lni8dptv8=; 24:P0h9X99bnWaqjPfnPki9f1uXdYU1TA08roW2LViIZOuQBlXpnQooP+FPVFUy04nY/fEFD3ROSdn1elmAZXt4kYC3iUFL8xKJZv4nkGO6NeM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB7PR08MB2985; 7:DUzojSVGqD5vsVFiWx0lgvcMPqUo8QrwU/BYayiXa68+lF1PW0a4c8MhSaM3sH8T2ydzkPdr3Eg91IB4RbIuR2jZPScgisw/HAuTkp/bCrNtQUQ/E16YbUJ5bQk/Axj2bIAZHM0Bna3YyYyNKJDmLFURBky0z0Qhd8zgf9M0JCrc2ylKFHstSxWDoPf1o22bghDG13sWeUikAm8TlZPdVqfq9yD6PWfBMk/ZAFnWOkLTA6ZdyZSy+QzGDOyjV7E0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2018 19:03:25.3444 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 70dc29e3-0e00-4b42-d6d6-08d5edaa4e67 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB2985 Subject: Re: [PATCH v2 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: Thu, 19 Jul 2018 19:03:30 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Thanks Sughosh. Reviewed-by: Achin Gupta On Fri, Jul 13, 2018 at 08:35:29PM +0530, Sughosh Ganu wrote: > From: Supreeth Venkatesh > > 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: Sughosh Ganu > Signed-off-by: Achin Gupta > Signed-off-by: Supreeth Venkatesh > --- > .../Drivers/StandaloneMmCpu/AArch64/EventHandle.c | 220 +++++++++++++++++++ > .../StandaloneMmCpu/AArch64/StandaloneMmCpu.c | 232 +++++++++++++++++++++ > .../StandaloneMmCpu/AArch64/StandaloneMmCpu.h | 64 ++++++ > .../StandaloneMmCpu/AArch64/StandaloneMmCpu.inf | 59 ++++++ > StandaloneMmPkg/Include/Guid/MpInformation.h | 41 ++++ > 5 files changed, 616 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 000000000000..2814577b3fcc > --- /dev/null > +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c > @@ -0,0 +1,220 @@ > +/** @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; > + } > + > + // Perform parameter validation of NsCommBufferAddr > + if (NsCommBufferAddr && (NsCommBufferAddr < mNsCommBuffer.PhysicalStart)) > + return EFI_ACCESS_DENIED; > + > + 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); > + > + // 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 > + ); > + > + 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 > + ) > +{ > + // 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 > + ); > + > + 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 000000000000..85a9c108aea4 > --- /dev/null > +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.c > @@ -0,0 +1,232 @@ > +/** @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 > + ) > +{ > + 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 > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // register the root MMI handler > + Status = mMmst->MmiHandlerRegister ( > + PiMmCpuTpFwRootMmiHandler, > + NULL, > + &DispatchHandle > + ); > + 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 > + ); > + 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 > + ); > + 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 > + ); > + 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 > + ); > + 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 > + ); > + 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 000000000000..7b38b65e1242 > --- /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 000000000000..9e6bbabdb103 > --- /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 000000000000..c88ff4afaba9 > --- /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 >