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.44; helo=eur04-vi1-obe.outbound.protection.outlook.com; envelope-from=supreeth.venkatesh@arm.com; receiver=edk2-devel@lists.01.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80044.outbound.protection.outlook.com [40.107.8.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9BDD521BADAB3 for ; Mon, 23 Jul 2018 12:28:03 -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=/VPfeiCy0rOygiDEylv+6righbxFrikG3XQ3pPcJdkk=; b=Fjpdm0ThRzj+Hkfe6euSwOSIWPurAkv5LaBwym6MO+kLpPgVQy49Q3ZBDVueTIyo8hn/zodaEFjlbIRYAYi3JkXZkG+OlDIpfLUHfrLDnqHBvO5Rrc781N6aAOYSh+AYPaeaeqF9DGMlbVZcO6Dy9pGdCP4Uz7/WwB/KFl9czdM= Received: from AM4PR0802MB2306.eurprd08.prod.outlook.com (10.172.218.15) by AM4PR0802MB2353.eurprd08.prod.outlook.com (10.172.218.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.973.16; Mon, 23 Jul 2018 19:28:00 +0000 Received: from AM4PR0802MB2306.eurprd08.prod.outlook.com ([fe80::1c37:b0e3:ce14:9eb1]) by AM4PR0802MB2306.eurprd08.prod.outlook.com ([fe80::1c37:b0e3:ce14:9eb1%7]) with mapi id 15.20.0973.022; Mon, 23 Jul 2018 19:27:59 +0000 From: Supreeth Venkatesh To: Achin Gupta , Sughosh Ganu CC: "edk2-devel@lists.01.org" , Jiewen Yao , nd Thread-Topic: [PATCH v2 09/10] StandaloneMmPkg: Add CPU driver suitable for ARM Platforms. Thread-Index: AQHUGrsK3pHWfdTyCkaGe6zNAOIlOKSW8VWAgAZNYJA= Date: Mon, 23 Jul 2018 19:27:59 +0000 Message-ID: References: <1531494330-1280-1-git-send-email-sughosh.ganu@arm.com> <1531494330-1280-10-git-send-email-sughosh.ganu@arm.com> <20180719190503.GD11021@e104320-lin> In-Reply-To: <20180719190503.GD11021@e104320-lin> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Supreeth.Venkatesh@arm.com; x-originating-ip: [217.140.111.135] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR0802MB2353; 6:pApXC7GUe3tfh8O58DzY51Hutf8ovU7Ixs3zj6Gk+z0ZEM5wrZxNMH/t/QGL581DvW+0PFHoPnTy8kJyIFrC/noq9AReQNakJGuH3IcBB4paanZpKrJyMuWvcvs1Vu4WXf2L1MexuVs51+80sM959VMyCQ2X4wafhm8vIaOT0omDfMU1rAHq25J039o8vRw3Ivro2ZthSH+KEtDVxMTV3WP15BKV24yGn7oNcsfM3NmkBBBN+EjLOXjphhZbp2/yuxxFJzs2sXnWnaJPY5GgW1x4nqBl7En7/A7/EVp2pM6k7Dons9s11/fLajPr/xEw0Jop0zUTRUsiMqyNvkRn1p25KcokDv5KHs8S1NYHUl8LjIO9ANYDV9KsIF+RBB8xJ35A1Te3tvUr3t/d6NNOJ5CSWVPXCNaI9DbjUFNqU9BHQblMfjlQ6ulXXETT9F1+777LTGW62046cOWysYMPfA==; 5:QJMZoO4pX2wfwba8Kt2S2a0p1CZpVugFco6k3v4lbSLiIAizC8hKNXI5CyJWI76dn0iqwr8aTI86qnI3qoPiOlSDCZcnVXvxBzdwvDpUVtfD3Xecnjfb9SNdI4uYLjIg9bbeCskxE1ndY6oV2yLn/p7GNXmoQNs0LPaRewakO+E=; 7:Wr4upIpARCFUMXHOtjB/ACjzMN2JsxWbByhn0AaPcJmbmrrFFrpp/gH4366ymt2hCs8A/ssjtM+RucS8YKe0P0x+1Kbxa31723YCJBIV4UAZCYLQfecuz1vv/On5se9al06VrH2UpL5+mkQNStKWXb6MEdLNgRgp5E6VTgWA+0i9a5m4lZxiAaAjsKtOUvR8BezOEe9jDoDhZ7V3x5N5uhoyWIriddF/yZMrP78UcVbvTAc5eoieNZwcmOvz3Spv x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-ms-office365-filtering-correlation-id: 92e21f1d-6c13-4e48-b3c6-08d5f0d266b6 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600073)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM4PR0802MB2353; x-ms-traffictypediagnostic: AM4PR0802MB2353: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(223705240517415)(162533806227266)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231311)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:AM4PR0802MB2353; BCL:0; PCL:0; RULEID:; SRVR:AM4PR0802MB2353; x-forefront-prvs: 0742443479 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6029001)(39860400002)(346002)(396003)(376002)(136003)(366004)(189003)(199004)(40434004)(13464003)(3846002)(7696005)(68736007)(4326008)(2906002)(76176011)(6436002)(53946003)(53936002)(8676002)(25786009)(9686003)(55016002)(6306002)(229853002)(5660300001)(2900100001)(54906003)(6116002)(53376002)(86362001)(6636002)(6246003)(966005)(72206003)(486006)(5250100002)(14454004)(97736004)(8936002)(33656002)(7736002)(74316002)(305945005)(81166006)(81156014)(19627235002)(11346002)(478600001)(66066001)(476003)(446003)(102836004)(99286004)(256004)(14444005)(6506007)(15188155005)(26005)(110136005)(316002)(53546011)(106356001)(16799955002)(5024004)(105586002)(579004)(559001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR0802MB2353; H:AM4PR0802MB2306.eurprd08.prod.outlook.com; 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-antispam-message-info: YBLsTV+yEC1+L20QDGGUeHm+W+/v3B2Rga9Pr3vfzDHo1nRbSlPwl3LEOPc/Rk1CDB7HdQEMHBOVCwcG3yyasodbnq5W5H7a+8WvaPlPnZDCmPdaAb7Hrx7+9T6XOPosPMcI1wedOW5+inRYYFnmafuAJv8LdNjqQtdSqdDxWhdKnQJ5B2UpRC/cLYzq3rHA+n2z2S3b/r5NsVb4KkULm+ZXKTuQXfmFqxIuQDxz8QVG2PP0e7q61L3YLGIlALPq+qycaiGk+OBEjomi2AcjFeOTD9uSuoamocAhKJddurGrNAGfOVZPK0iBODaObjBB+DzncIvh7Qc6c872jkYcktOzFx5deDkjzuw5NrSDdbo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 92e21f1d-6c13-4e48-b3c6-08d5f0d266b6 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jul 2018 19:27:59.8591 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0802MB2353 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: Mon, 23 Jul 2018 19:28:05 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Sughosh, My response inline. Thanks, Supreeth -----Original Message----- From: Achin Gupta Sent: Thursday, July 19, 2018 2:05 PM To: Sughosh Ganu Cc: edk2-devel@lists.01.org; Jiewen Yao ; Supreeth Ve= nkatesh ; nd Subject: Re: [PATCH v2 09/10] StandaloneMmPkg: Add CPU driver suitable for = ARM Platforms. 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 EXPRE= SS 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_INF= ORMATION_HOB_DATA. > +// > +EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext =3D 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 =3D { > + 0, > + MmFoundationEntryRegister > +}; > + > +STATIC EFI_MM_ENTRY_POINT mMmEntryPoint =3D NULL; > + > +EFI_STATUS > +PiMmStandloneArmTfCpuDriverEntry ( > + IN UINTN EventId, > + IN UINTN CpuNumber, > + IN UINTN NsCommBufferAddr > + ) > +{ > + EFI_MM_COMMUNICATE_HEADER *GuidedEventContext =3D NULL; > + EFI_MM_ENTRY_CONTEXT MmEntryPointContext =3D {0}; > + EFI_STATUS Status; > + UINTN NsCommBufferSize; > + > + DEBUG ((DEBUG_INFO, "Received event - 0x%x on cpu %d\n", EventId, > + CpuNumber)); > + > + Status =3D 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 !=3D 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)) >=3D > + (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) > + return EFI_INVALID_PARAMETER; > + > + // Find out the size of the buffer passed NsCommBufferSize =3D > + ((EFI_MM_COMMUNICATE_HEADER *) NsCommBufferAddr)->MessageLength + > + sizeof (EFI_MM_COMMUNICATE_HEADER); [Supreeth] This is incorrect. The size of above one and size of the below o= ne differ by 1 and will cause issues later. NsCommBufferSize =3D ((EFI_MM_COMMUNICATE_HEADER *) NsCommBufferAddr)->Mess= ageLength + + sizeof(((EFI_MM_COMMUNICATE_HEADER= *)NsCommBufferAddr)->MessageLength) + + sizeof(((EFI_MM_COMMUNICATE_HEADER>= + *)NsCommBufferAddr)->HeaderGuid); The statements will return different values because sizeof(EFI_MM_COMMUNICA= TE_HEADER) will include UINT8 Data[1] which is a pointer to actual data. > + > + // perform bounds check. > + if (NsCommBufferAddr + NsCommBufferSize >=3D > + 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 worl= d. > + Status =3D mMmst->MmAllocatePool ( > + EfiRuntimeServicesData, > + NsCommBufferSize, > + (VOID **) &GuidedEventContext > + ); > + > + if (Status !=3D 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] =3D GuidedEventContext; > + > + MmEntryPointContext.CurrentlyExecutingCpu =3D CpuNumber; > + MmEntryPointContext.NumberOfCpus =3D > + mMpInformationHobData->NumberOfProcessors; > + > + // Populate the MM system table with MP and state information > + mMmst->CurrentlyExecutingCpu =3D CpuNumber; mMmst->NumberOfCpus =3D > + mMpInformationHobData->NumberOfProcessors; > + mMmst->CpuSaveStateSize =3D 0; > + mMmst->CpuSaveState =3D NULL; > + > + if (mMmEntryPoint =3D=3D 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 =3D mMmst->MmFreePool ((VOID *) GuidedEventContext); if > + (Status !=3D EFI_SUCCESS) { > + return EFI_OUT_OF_RESOURCES; > + } > + PerCpuGuidedEventContext[CpuNumber] =3D 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 =3D 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 wa= s specified when the handler was registered. > + @param CommBuffer A pointer to a collection of data in memory th= at 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 =3D=3D NULL); > + ASSERT (CommBuffer =3D=3D NULL); > + ASSERT (CommBufferSize =3D=3D NULL); > + > + CpuNumber =3D 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 =3D mMmst->MmiManage ( > + &PerCpuGuidedEventContext[CpuNumber]->HeaderGuid, > + NULL, > + PerCpuGuidedEventContext[CpuNumber]->Data, > + &PerCpuGuidedEventContext[CpuNumber]->MessageLength > + ); > + > + if (Status !=3D 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 EXPRE= SS 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 =3D NULL; > + > +// > +// Globals used to initialize the protocol // > +STATIC EFI_HANDLE mMmCpuHandle =3D 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 =3D GetNextGuidHob (HobGuid, HobList); if (!Hob) > + return EFI_NOT_FOUND; > + > + *HobData =3D 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 !=3D NULL); > + mMmst =3D SystemTable; > + > + // publish the MM config protocol so the MM core can register its > + entry point Status =3D mMmst->MmInstallProtocolInterface ( > + &mMmCpuHandle, > + &gEfiMmConfigurationProtocolGuid, > + EFI_NATIVE_INTERFACE, > + &mMmConfig > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // register the root MMI handler > + Status =3D 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 =3D mMmst->MmConfigurationTable; for (Index =3D 0; > + Index < mMmst->NumberOfTableEntries; Index++) { > + if (CompareGuid (&gEfiHobListGuid, &(ConfigurationTable[Index].Vendo= rGuid))) { > + break; > + } > + } > + > + // Bail out if the Hoblist could not be found if (Index >=3D > + mMmst->NumberOfTableEntries) { > + DEBUG ((DEBUG_INFO, "Hoblist not found - 0x%x\n", Index)); > + return EFI_OUT_OF_RESOURCES; > + } > + > + HobStart =3D ConfigurationTable[Index].VendorTable; > + > + // > + // Locate the HOB with the buffer to populate the entry point of > + this driver // Status =3D 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 =3D 0x%lx\n", > + (UINT64) CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr, > + (UINT64) PiMmStandloneArmTfCpuDriverEntry)); > + *(CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr) =3D > + PiMmStandloneArmTfCpuDriverEntry; > + > + // Find the descriptor that contains the whereabouts of the buffer > + for // communication with the Normal world. > + Status =3D 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 =3D > + GetGuidedHobData ( > + HobStart, > + &gMpInformationHobGuid, > + (VOID **) &MpInformationHobData > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_INFO, "MpInformationHob extraction failed - 0x%x\n", S= tatus)); > + 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 =3D sizeof (MP_INFORMATION_HOB_DATA) + > + (sizeof (EFI_PROCESSOR_INFORMATION) * > + MpInformationHobData->NumberOfProcessors); > + Status =3D 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 =3D 0; Index < mMpInformationHobData->NumberOfProcessors; I= ndex++) { > + DEBUG ((DEBUG_INFO, "mMpInformationHobData[0x%lx]: %d, %d, %d\n", > + mMpInformationHobData->ProcessorInfoBuffer[Index].ProcessorI= d, > + mMpInformationHobData->ProcessorInfoBuffer[Index].Location.P= ackage, > + mMpInformationHobData->ProcessorInfoBuffer[Index].Location.C= ore, > + > + mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Thread)); > + } > + > + // > + // Allocate memory for a table to hold pointers to a > + // EFI_MM_COMMUNICATE_HEADER for each CPU > + // > + ArraySize =3D sizeof (EFI_MM_COMMUNICATE_HEADER *) * > + mMpInformationHobData->NumberOfEnabledProcessors; > + Status =3D 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 EXPRE= SS 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 EXPR= ESS OR IMPLIED. > +# > +#**/ > + > +[Defines] > + INF_VERSION =3D 0x0001001A > + BASE_NAME =3D StandloneMmCpu > + FILE_GUID =3D 58F7A62B-6280-42A7-BC38-10535A64A92= C > + MODULE_TYPE =3D MM_STANDALONE > + VERSION_STRING =3D 1.0 > + PI_SPECIFICATION_VERSION =3D 0x00010032 > + ENTRY_POINT =3D 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 ALWA= YS_PRODUCED > + gEfiMmCpuProtocolGuid # PROTOCOL ALWA= YS_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_PROTOCO= L. > + > + MP information protocol only provides static information of MP process= or. > + > + 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 EXPRE= SS 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 > IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in = any medium. Thank you.