From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (NAM04-MW2-obe.outbound.protection.outlook.com [40.107.101.137]) by mx.groups.io with SMTP id smtpd.web12.5455.1622023878748734819 for ; Wed, 26 May 2021 03:11:18 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@os.amperecomputing.com header.s=selector2 header.b=DkcrOuBt; spf=pass (domain: os.amperecomputing.com, ip: 40.107.101.137, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cFvhMRmIyEbpOpJUTuKxXje2Lf8Lmv+arFeVXac6gMq5aVScnYwi+xqlZYJrFvhdyino22bGQ3moOnWYrfJAO11raXIKZcjirFksnP5c0bFbfxNH/M5jeejTygmfw44WWCXINftvarbPs+az+fh4Kg68rtkhunoVvgrjkfbm01cg2jb2OuIczx5MXjF/lknX9ynPAY05iUKFciA98utZfC8zPFRgPshMinPTZMZ1Ba6VS+CR5xrCZYRzp76JPr9gLwFrhiOvGzeIMYBP/BS7UddUow+PIskYTGoX0LJw1QZeGis+GWKazfWgVQ7Vetkk/ohzw71pqJ45lz8OwLmQdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hJfNCUnN6UspZTG3hyHqATkig0NfWKyhRFJnUA2Vb3o=; b=eNr2xkJbkAlpjPgybN1Nt0D8FQ+6TGKfcBKzuXp3Ik9nmXXqFb8DtDMPIBbpGC9vy3xtLLaImZKmGTyI9laPtCbj9Jr3oiuW8im6+8vFM+IgcuvKl4lG6Ovte5nugiAuZxJickKks5vSQQqTZyfUvuccnaEgKkePQKpGfGx/LlchmowWWlLLwOatb0QNlr7yk476XcZK7DVDAbXyRu/8Bsgzwuf5YIRv6ljjHSSn6eq4Ifv95gY4kLz8om0MMBK3RhhknS0O2keVwdZPHlYfjO4vEzcBuR4IF/PjXpreLe8MByeUJR2vtv+kqA1COVl3+T6yZVnXjfZYOHGmrOmtAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hJfNCUnN6UspZTG3hyHqATkig0NfWKyhRFJnUA2Vb3o=; b=DkcrOuBtzUEQupQ1PyecR5+F+xfN/AjxMKSTogVQr5w0eiaAWDsKFbtSowqM1kZAxY005lzqcBkUmbPlMohtfHhlj9lNmIS6FH5rdzT4AwVBbZVhjjCdiKtD0TVgXOtoWY1TjzDl3w5nbji+gCOACf/KYo4NcIxhdzy7QieQgmU= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) by DM8PR01MB6808.prod.exchangelabs.com (2603:10b6:8:23::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21; Wed, 26 May 2021 10:11:17 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::60d2:86dd:1f1c:51dd]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::60d2:86dd:1f1c:51dd%7]) with mapi id 15.20.4173.020; Wed, 26 May 2021 10:11:17 +0000 From: "Nhi Pham" To: devel@edk2.groups.io CC: Vu Nguyen , Thang Nguyen , Chuong Tran , Phong Vo , Leif Lindholm , Michael D Kinney , Ard Biesheuvel , Nate DeSimone Subject: [edk2-platforms][PATCH v2 02/32] AmpereAltraPkg: Add MmCommunication modules Date: Wed, 26 May 2021 17:06:54 +0700 Message-ID: <20210526100724.5359-4-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210526100724.5359-1-nhi@os.amperecomputing.com> References: <20210526100724.5359-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HKAPR04CA0008.apcprd04.prod.outlook.com (2603:1096:203:d0::18) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (118.69.219.201) by HKAPR04CA0008.apcprd04.prod.outlook.com (2603:1096:203:d0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Wed, 26 May 2021 10:11:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d1383a3e-a83e-4d99-6869-08d9202e99bd X-MS-TrafficTypeDiagnostic: DM8PR01MB6808: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Yts4xLkB84YsJCSDor0bCa9y3f2veUuii0pvzbIXVrP7pjOA2oW84oeUpaAGMTlj4QJ9kl5B6uKvsUkCwuvAsoZNIA9KUHcfiEMqmM9vcvxaT/hgi3la1L9OK+ffabprJu6Bh/FSlBum/4Tn4fN7PDtHY3nGbFUG5Xq/TclhYjxInDskRdd5d9UlXQKNH74+RUUUzj7Ou3PtUDt7R9myvObhd6yp+HEACitzEtaXKX8nZh5fTi66/yMHxOfEtq969X8d0h7siEUMuJArJ1YjVq1FJazPW4+665k79EDIFyeOHBs6D5SOEDolcxoZxYB4nbUO2mOYrg+5OA50nOqVER+Vwjp7lLnwSK/K1RRjvMTNOqEr4tjUwHB7DdHHo9K+Q9lLccIiNHdvAnpaYoy+uz6jUjU0+4D6WvdoA6Wdrrf3p4YQn1b2S7CJgkTq0CIGHfZ28rZkKRlaMuwBSX2Uh3+DQk89EQosNMwc0r/vTkD5BMYCTnRyFhjtiY/FZL4P+K0m5alEg5lcQBkIRhyO5Dj7HTXkua8uya0uwneRACiojU9pofTvIR6vUroNRhXftxbtnzoHxnuhqPQQwRvTow0cg0m550ZcWbTXFo7RtvJb3Bgx1tMenuG3oW/gTQInKypyUS+xDgw94PNC8nLR5IYiJyN4NJg279nHwU8jKKb43Ee5E5K2fPcrevhDIuFf X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR01MB5849.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(6029001)(4636009)(366004)(396003)(346002)(136003)(376002)(39850400004)(6666004)(4326008)(8676002)(52116002)(8936002)(1076003)(86362001)(66476007)(66946007)(66556008)(19627235002)(54906003)(186003)(6486002)(6916009)(6506007)(2906002)(6512007)(2616005)(316002)(478600001)(956004)(26005)(30864003)(38100700002)(38350700002)(5660300002)(16526019)(83380400001)(69590400013);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?mxB3TOWBsVQvfL2eDEqZr3yZZoUGChAf+mHj/GmAHstfsUcN6ju1M4ySFC3g?= =?us-ascii?Q?wpoO56GiVhQu4fajI7wN4MpPyhjpNFioSwsmrMbX3vBxNd1qLXRxOzeLtxdq?= =?us-ascii?Q?vHSqr2v698YcqMVIc6ccSh9uDB1bIT0Ato2MIuIo90nid4sQPK85EmyJJ1Sk?= =?us-ascii?Q?XXWZMjqidaLOlZ32M3m9de14cbai2m69H2OZbUtzjPDb92keKwzxPac71X8Z?= =?us-ascii?Q?gL+nLD7Rah2hnTUgmg2OINNLIXOUvdD+rgkuZnBXGH20DH/bNWWiTxteZ2Fm?= =?us-ascii?Q?puKfYxEkQbv3RIrNB9cdcCi9rNdhgWf9k2mlXgRgxJWvJo1wKSJk1rt3WeBF?= =?us-ascii?Q?LV6Mg7zNpEfK9UPZpli4t7hiorYsOX1mh5feiUTA+AQ2b6j/SqWpqt+saJCM?= =?us-ascii?Q?q5/zSFcjQRkpzzigfS0VcXUY9zoorYtHAQt+XpjWLtgasuDOInXBQa4TO5rc?= =?us-ascii?Q?sUlxq8gfKbRL9Fq24JOwnm58xGPkAh3QjEEO+2yWiUrolN8KJOtQm7HQrz7Q?= =?us-ascii?Q?aTFCoqZcY6zW76Gx4hqCDp28uU0BJK7RVhDcZYZiEYHlGTShvq/iMP+r4vcP?= =?us-ascii?Q?3dUA07PwiMIbR+myUPUA5rWylgs5ZV4Q0FR+1AGMQTDCcdFq+rifV+nOauzC?= =?us-ascii?Q?qqTVG5NtcOvjGVGxFj81/8b0Hk3kzdwUpqUxOj3HpLn8V2LZZWippT1zN0Qc?= =?us-ascii?Q?VlR92rXzJhDyuBZOVIFkRZx/I35sgm+5q0R7qdFAmbElgGije46P7qEmVNXY?= =?us-ascii?Q?6F27CPB+v/ddcUSiogUEpQiwQYJ9MshyYpXlAJoPu/kxo+OhDgrreOB0llYE?= =?us-ascii?Q?Ki6TDm+5BHUTE3xVmyt4vIRj0UaQT2gf8iPV2kLej4NjmSd8C/zV2ZGB5hIe?= =?us-ascii?Q?mghX5pcfll5BjiSo3Z1Y25Spcg4pCbqY79oQAX7da+tDCBDV+kcXIAyCQ3LE?= =?us-ascii?Q?kWG8BHPkYljM90Ms9re2VJtV4c7UonWjA/YE+IOCT+eqGzuEDivmVi7Op3Bm?= =?us-ascii?Q?HdierNNc78KYqemjX3Syb+Ga9nusfet7ybUYF6Ymn75p3I+Mqy7E0Sg4tAhv?= =?us-ascii?Q?XoJyZsSq1kzfdG2RXE3JiGRMT5tVNHgjwNGNid61HhLIbbQuzYfnSGvNG4nn?= =?us-ascii?Q?k8cF6qOIub1I/lDFDF91gg9EYOlGBsBsqo28DJ8vZNiVzos5OLUUatSZxmIj?= =?us-ascii?Q?vZwnoaH+LyPf9Ftb2MdcF4skMABNpy/+jplNjHEBnVMrtCh/3SFSfAcfqoZu?= =?us-ascii?Q?XxdCEFaDIVPDSkLtrdij3chwuCvnBJydwJpjG3uqyAfVg1fInX86UrLNh4Cv?= =?us-ascii?Q?N0Lfq0F35QhoS39ilBtf9bqt?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1383a3e-a83e-4d99-6869-08d9202e99bd X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2021 10:11:17.2865 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eYiwETQOxRaVtDssfIYQAo77Tnh2mkVSSNQxvQlrA8VpLUBwuDujIdAGTOX4+c1seIdF+rSYbZlmB8xgiO7ON9+rZVZ9HtWjROiwykYuP9I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR01MB6808 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Vu Nguyen The MmCommunicationDxe module is derived from ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf. The MmCommunication PEI and DXE modules implement the MM Communication protocol (EFI_MM_COMMUNICATION_PROTOCOL) as defined in the PI 1.5 specification for the interface between UEFI and MM services in the secure world. Cc: Thang Nguyen Cc: Chuong Tran Cc: Phong Vo Cc: Leif Lindholm Cc: Michael D Kinney Cc: Ard Biesheuvel Cc: Nate DeSimone Signed-off-by: Vu Nguyen --- Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec = | 3 + Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc = | 2 + Platform/Ampere/JadePkg/Jade.fdf = | 3 + Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCommunication.i= nf | 57 +++ Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPei/MmCommunicationPe= i.inf | 34 ++ Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCommunicate.h = | 22 + Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCommunication.c= | 454 ++++++++++++++++++++ Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPei/MmCommunicationPe= i.c | 37 ++ 8 files changed, 612 insertions(+) diff --git a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec b/Silicon/Amp= ere/AmpereAltraPkg/AmpereAltraPkg.dec index f0a5bd04ec22..73097afaf841 100644 --- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec +++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec @@ -38,5 +38,8 @@ [Guids] ## NVParam MM GUID gNVParamMmGuid =3D { 0xE4AC5024, 0x29BE, 0x4ADC, { 0x93, 0= x36, 0x87, 0xB5, 0xA0, 0x76, 0x23, 0x2D } } =20 + ## SPI NOR Proxy MM GUID + gSpiNorMmGuid =3D { 0xC8D76438, 0x4D3C, 0x4BEA, { 0xBF, 0= x86, 0x92, 0x6B, 0x83, 0x07, 0xA2, 0x39 } } + ## Include/Guid/PlatformInfoHobGuid.h gPlatformHobGuid =3D { 0x7f73e372, 0x7183, 0x4022, { 0xb3, 0= x76, 0x78, 0x30, 0x32, 0x6d, 0x79, 0xb4 } } diff --git a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc b/Silicon= /Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc index af66c27822a3..0332473b59b0 100755 --- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc +++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc @@ -517,6 +517,7 @@ [Components.common] ArmPlatformPkg/PlatformPei/PlatformPeim.inf Silicon/Ampere/AmpereAltraPkg/Drivers/ATFHobPei/ATFHobPeim.inf Silicon/Ampere/AmpereAltraPkg/Drivers/MemoryInitPeim/MemoryInitPeim.inf + Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPei/MmCommunication= Pei.inf ArmPkg/Drivers/CpuPei/CpuPei.inf UefiCpuPkg/CpuIoPei/CpuIoPei.inf MdeModulePkg/Universal/Variable/Pei/VariablePei.inf @@ -565,6 +566,7 @@ [Components.common] EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf + Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCommunication= .inf =20 # # Environment Variables Protocol diff --git a/Platform/Ampere/JadePkg/Jade.fdf b/Platform/Ampere/JadePkg/Jad= e.fdf index 8ed6df381aed..905289844378 100755 --- a/Platform/Ampere/JadePkg/Jade.fdf +++ b/Platform/Ampere/JadePkg/Jade.fdf @@ -101,6 +101,7 @@ [FV.FVMAIN_COMPACT] INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf INF Silicon/Ampere/AmpereAltraPkg/Drivers/ATFHobPei/ATFHobPeim.inf INF Silicon/Ampere/AmpereAltraPkg/Drivers/MemoryInitPeim/MemoryInitPeim.= inf + INF Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPei/MmCommunica= tionPei.inf INF ArmPkg/Drivers/CpuPei/CpuPei.inf INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf @@ -141,6 +142,7 @@ [FV.FvMain] INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatu= sCodeRouterRuntimeDxe.inf INF MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandle= rRuntimeDxe.inf + INF Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCommunica= tion.inf } =20 INF MdeModulePkg/Core/Dxe/DxeMain.inf @@ -163,6 +165,7 @@ [FV.FvMain] INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf + INF Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCommunica= tion.inf =20 # # Environment Variables Protocol diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCom= munication.inf b/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/M= mCommunication.inf new file mode 100644 index 000000000000..3efff142944f --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCommunicat= ion.inf @@ -0,0 +1,57 @@ +#/** @file +# +# This module implements the MM Communication Protocol (EFI_MM_COMMUNICAT= ION_PROTOCOL) +# as defined in the PI 1.5 specification. +# +# Copyright (c) 2016 - 2018, ARM Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D ArmMmCommunication + FILE_GUID =3D 09EE81D3-F15E-43F4-85B4-CB9873DA5D6B + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D MmCommunicationInitialize + +# +# The following is for reference only and not required by +# build tools +# +# VALID_ARCHITECTURES =3D AARCH64 +# + +[Sources.AARCH64] + MmCommunicate.h + MmCommunication.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmLib + ArmSmcLib + BaseMemoryLib + DebugLib + DxeServicesTableLib + HobLib + UefiDriverEntryPoint + +[Protocols] + gEfiMmCommunicationProtocolGuid ## PRODUCES + +[Guids] + gEfiEndOfDxeEventGroupGuid + gEfiEventExitBootServicesGuid + gEfiEventReadyToBootGuid + +[Pcd.common] + gArmTokenSpaceGuid.PcdMmBufferBase + gArmTokenSpaceGuid.PcdMmBufferSize + +[Depex] + gEfiCpuArchProtocolGuid diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPei/MmCom= municationPei.inf b/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPe= i/MmCommunicationPei.inf new file mode 100755 index 000000000000..3a985840a0a0 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPei/MmCommunicat= ionPei.inf @@ -0,0 +1,34 @@ +## @file +# +# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D MmCommunicationPei + FILE_GUID =3D B5AE0F80-DF81-11EA-8B6E-0800200C9A66 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D MmCommunicationPeiEntryPoint + +[Sources] + MmCommunicationPei.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + HobLib + PcdLib + PeimEntryPoint + +[Pcd] + gArmTokenSpaceGuid.PcdMmBufferBase + gArmTokenSpaceGuid.PcdMmBufferSize + +[Depex] + TRUE diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCom= municate.h b/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCom= municate.h new file mode 100644 index 000000000000..804ba58afb72 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCommunicat= e.h @@ -0,0 +1,22 @@ +/** @file + + Copyright (c) 2016-2018, ARM Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MM_COMMUNICATE_H_ +#define MM_COMMUNICATE_H_ + +#define MM_MAJOR_VER_MASK 0xEFFF0000 +#define MM_MINOR_VER_MASK 0x0000FFFF +#define MM_MAJOR_VER_SHIFT 16 + +#define MM_MAJOR_VER(x) (((x) & MM_MAJOR_VER_MASK) >> MM_MAJOR_VER_SHIFT) +#define MM_MINOR_VER(x) ((x) & MM_MINOR_VER_MASK) + +#define MM_CALLER_MAJOR_VER 0x1UL +#define MM_CALLER_MINOR_VER 0x0 + +#endif /* MM_COMMUNICATE_H_ */ diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCom= munication.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmC= ommunication.c new file mode 100644 index 000000000000..271fc755548f --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationDxe/MmCommunicat= ion.c @@ -0,0 +1,454 @@ +/** @file + + Copyright (c) 2020, Ampere Computing LLC + Copyright (c) 2016-2018, ARM Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "MmCommunicate.h" + +#define MM_EARLY_MEM_ALLOCATE 1 + +// +// 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; + +/** + 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 pri= or 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. This is optional. + + @retval EFI_SUCCESS The message was successfully posted. + @retval EFI_INVALID_PARAMETER The CommBuffer was NULL. + @retval EFI_BAD_BUFFER_SIZE The buffer size is incorrect 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 r= eflect + the maximum payload size the + implementation can accommodate. + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter + or CommSize parameter, if not omitte= d, + are in address range that cannot be + accessed by the MM environment +**/ +STATIC +EFI_STATUS +EFIAPI +MmCommunicationCommunicate ( + IN CONST EFI_MM_COMMUNICATION_PROTOCOL *This, + IN OUT VOID *CommBuffer, + IN OUT UINTN *CommSize OPTIONAL + ) +{ + EFI_MM_COMMUNICATE_HEADER *CommunicateHeader; + ARM_SMC_ARGS CommunicateSmcArgs; + EFI_STATUS Status; + UINTN BufferSize; + + Status =3D EFI_ACCESS_DENIED; + BufferSize =3D 0; + + ZeroMem (&CommunicateSmcArgs, sizeof (ARM_SMC_ARGS)); + + // + // Check parameters + // + if (CommBuffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + CommunicateHeader =3D CommBuffer; + // CommBuffer is a mandatory parameter. Hence, rely on + // MessageLength + Header to ascertain the + // total size of the communication payload rather than + // relying on optional CommSize parameter + BufferSize =3D CommunicateHeader->MessageLength + + sizeof (CommunicateHeader->HeaderGuid) + + sizeof (CommunicateHeader->MessageLength); + + // If the length of the CommBuffer is 0 then return the expected length. + if (CommSize !=3D NULL) { + // This case can be used by the consumer of this driver to find out th= e + // max size that can be used for allocating CommBuffer. + if ((*CommSize =3D=3D 0) || + (*CommSize > mNsCommBuffMemRegion.Length)) + { + *CommSize =3D mNsCommBuffMemRegion.Length; + return EFI_BAD_BUFFER_SIZE; + } + // + // CommSize must match MessageLength + sizeof (EFI_MM_COMMUNICATE_HEAD= ER); + // + if (*CommSize !=3D BufferSize) { + return EFI_INVALID_PARAMETER; + } + } + + // + // If the buffer size is 0 or greater than what can be tolerated by the = MM + // environment then return the expected size. + // + if ((BufferSize =3D=3D 0) || + (BufferSize > mNsCommBuffMemRegion.Length)) + { + CommunicateHeader->MessageLength =3D mNsCommBuffMemRegion.Length - + sizeof (CommunicateHeader->HeaderGu= id) - + sizeof (CommunicateHeader->MessageL= ength); + return EFI_BAD_BUFFER_SIZE; + } + + // SMC Function ID + CommunicateSmcArgs.Arg0 =3D ARM_SMC_ID_MM_COMMUNICATE_AARCH64; + + // Cookie + CommunicateSmcArgs.Arg1 =3D 0; + + // Copy Communication Payload + CopyMem ((VOID *)mNsCommBuffMemRegion.VirtualBase, CommBuffer, BufferSiz= e); + + // comm_buffer_address (64-bit physical address) + CommunicateSmcArgs.Arg2 =3D (UINTN)mNsCommBuffMemRegion.PhysicalBase; + + // comm_size_address (not used, indicated by setting to zero) + CommunicateSmcArgs.Arg3 =3D 0; + + // Call the Standalone MM environment. + ArmCallSmc (&CommunicateSmcArgs); + + switch (CommunicateSmcArgs.Arg0) { + case ARM_SMC_MM_RET_SUCCESS: + ZeroMem (CommBuffer, BufferSize); + // On successful return, the size of data being returned is inferred f= rom + // MessageLength + Header. + CommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER *)mNsCommBuffMemRegio= n.VirtualBase; + BufferSize =3D CommunicateHeader->MessageLength + + sizeof (CommunicateHeader->HeaderGuid) + + sizeof (CommunicateHeader->MessageLength); + + CopyMem ( + CommBuffer, + (VOID *)mNsCommBuffMemRegion.VirtualBase, + BufferSize + ); + Status =3D EFI_SUCCESS; + break; + + case ARM_SMC_MM_RET_INVALID_PARAMS: + Status =3D EFI_INVALID_PARAMETER; + break; + + case ARM_SMC_MM_RET_DENIED: + Status =3D 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 + Status =3D EFI_OUT_OF_RESOURCES; + ASSERT (0); + break; + + default: + Status =3D EFI_ACCESS_DENIED; + ASSERT (0); + } + + return Status; +} + +// +// MM Communication Protocol instance +// +EFI_MM_COMMUNICATION_PROTOCOL mMmCommunication =3D { + MmCommunicationCommunicate +}; + +/** + 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 =3D gRT->ConvertPointer ( + EFI_OPTIONAL_PTR, + (VOID **)&mNsCommBuffMemRegion.VirtualBase + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Unable to convert MM runtime pointer. Status:0x%r\n", + __FUNCTION__, + Status + )); + } + +} + +STATIC +EFI_STATUS +GetMmCompatibility () +{ + EFI_STATUS Status; + UINT32 MmVersion; + ARM_SMC_ARGS MmVersionArgs; + + // MM_VERSION uses SMC32 calling conventions + MmVersionArgs.Arg0 =3D ARM_SMC_ID_MM_VERSION_AARCH32; + + ArmCallSmc (&MmVersionArgs); + + MmVersion =3D MmVersionArgs.Arg0; + + if ((MM_MAJOR_VER (MmVersion) =3D=3D MM_CALLER_MAJOR_VER) && + (MM_MINOR_VER (MmVersion) >=3D MM_CALLER_MINOR_VER)) + { + DEBUG (( + DEBUG_INFO, + "MM Version: Major=3D0x%x, Minor=3D0x%x\n", + MM_MAJOR_VER (MmVersion), + MM_MINOR_VER (MmVersion) + )); + Status =3D EFI_SUCCESS; + } else { + DEBUG (( + DEBUG_ERROR, + "Incompatible MM Versions.\n Current Version: Major=3D0x%x, " + "Minor=3D0x%x.\n Expected: Major=3D0x%x, Minor>=3D0x%x.\n", + MM_MAJOR_VER (MmVersion), + MM_MINOR_VER (MmVersion), + MM_CALLER_MAJOR_VER, + MM_CALLER_MINOR_VER + )); + Status =3D EFI_UNSUPPORTED; + } + + return Status; +} + +STATIC EFI_GUID *CONST mGuidedEventGuid[] =3D { + &gEfiEndOfDxeEventGroupGuid, + &gEfiEventExitBootServicesGuid, + &gEfiEventReadyToBootGuid, +}; + +STATIC EFI_EVENT mGuidedEvent[ARRAY_SIZE (mGuidedEventGuid)]; + +/** + Event notification that is fired when GUIDed Event Group is signaled. + + @param Event The Event that is being processed, not use= d. + @param Context Event Context, not used. + +**/ +STATIC +VOID +EFIAPI +MmGuidedEventNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_MM_COMMUNICATE_HEADER Header; + UINTN Size; + + // + // Use Guid to initialize EFI_SMM_COMMUNICATE_HEADER structure + // + CopyGuid (&Header.HeaderGuid, Context); + Header.MessageLength =3D 1; + Header.Data[0] =3D 0; + + Size =3D sizeof (Header); + MmCommunicationCommunicate (&mMmCommunication, &Header, &Size); +} + +/** + 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 poi= nt. + +**/ +EFI_STATUS +EFIAPI +MmCommunicationInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + UINTN Index; + + // Check if we can make the MM call + Status =3D GetMmCompatibility (); + if (EFI_ERROR (Status)) { + goto ReturnErrorStatus; + } + + mNsCommBuffMemRegion.PhysicalBase =3D PcdGet64 (PcdMmBufferBase); + // During boot, virtual and physical are same + mNsCommBuffMemRegion.VirtualBase =3D mNsCommBuffMemRegion.PhysicalBase; + mNsCommBuffMemRegion.Length =3D PcdGet64 (PcdMmBufferSize); + + ASSERT (mNsCommBuffMemRegion.PhysicalBase !=3D 0); + + ASSERT (mNsCommBuffMemRegion.Length !=3D 0); + +#if !defined(MM_EARLY_MEM_ALLOCATE) + Status =3D gDS->AddMemorySpace ( + EfiGcdMemoryTypeReserved, + mNsCommBuffMemRegion.PhysicalBase, + mNsCommBuffMemRegion.Length, + EFI_MEMORY_WB | + EFI_MEMORY_XP | + EFI_MEMORY_RUNTIME + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to add MM-NS Buffer Memory Space\n", + __FUNCTION__ + )); + goto ReturnErrorStatus; + } + + Status =3D gDS->SetMemorySpaceAttributes ( + mNsCommBuffMemRegion.PhysicalBase, + mNsCommBuffMemRegion.Length, + EFI_MEMORY_WB | EFI_MEMORY_XP | EFI_MEMORY_RUNTIME + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to set MM-NS Buffer Memory attributes\n", + __FUNCTION__ + )); + goto CleanAddedMemorySpace; + } +#endif + + // Install the communication protocol + Status =3D gBS->InstallProtocolInterface ( + &mMmCommunicateHandle, + &gEfiMmCommunicationProtocolGuid, + EFI_NATIVE_INTERFACE, + &mMmCommunication + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to install MM communication protocol\n", + __FUNCTION__ + )); + goto CleanAddedMemorySpace; + } + + // Register notification callback when virtual address is associated + // with the physical address. + // Create a Set Virtual Address Map event. + Status =3D gBS->CreateEvent ( + EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, + TPL_NOTIFY, + NotifySetVirtualAddressMap, + NULL, + &mSetVirtualAddressMapEvent + ); + ASSERT_EFI_ERROR (Status); + + for (Index =3D 0; Index < ARRAY_SIZE (mGuidedEventGuid); Index++) { + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + MmGuidedEventNotify, + mGuidedEventGuid[Index], + mGuidedEventGuid[Index], + &mGuidedEvent[Index] + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + while (Index-- > 0) { + gBS->CloseEvent (mGuidedEvent[Index]); + } + goto UninstallProtocol; + } + } + return EFI_SUCCESS; + +UninstallProtocol: + gBS->UninstallProtocolInterface ( + mMmCommunicateHandle, + &gEfiMmCommunicationProtocolGuid, + &mMmCommunication + ); + +CleanAddedMemorySpace: +#if !defined(MM_EARLY_MEM_ALLOCATE) + gDS->RemoveMemorySpace ( + mNsCommBuffMemRegion.PhysicalBase, + mNsCommBuffMemRegion.Length + ); +#endif + +ReturnErrorStatus: + return EFI_INVALID_PARAMETER; +} diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPei/MmCom= municationPei.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPei/= MmCommunicationPei.c new file mode 100644 index 000000000000..d3925015612f --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPei/MmCommunicat= ionPei.c @@ -0,0 +1,37 @@ +/** @file + + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include +#include + +/** + Entry point function for the PEIM + + @param FileHandle Handle of the file being invoked. + @param PeiServices Describes the list of possible PEI Services. + + @return EFI_SUCCESS If we installed our PPI + +**/ +EFI_STATUS +EFIAPI +MmCommunicationPeiEntryPoint ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_PHYSICAL_ADDRESS MmBufferBase =3D PcdGet64 (PcdMmBufferBase); + UINT64 MmBufferSize =3D PcdGet64 (PcdMmBufferSize); + + BuildMemoryAllocationHob (MmBufferBase, MmBufferSize, EfiRuntimeServices= Data); + + return EFI_SUCCESS; +} --=20 2.17.1