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.109]) by mx.groups.io with SMTP id smtpd.web08.10065.1631721560246865362 for ; Wed, 15 Sep 2021 08:59:20 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@os.amperecomputing.com header.s=selector2 header.b=lCnBbWV7; spf=pass (domain: os.amperecomputing.com, ip: 40.107.101.109, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T3odyhXpRhZKVcgZ4wrhn/HICOkmmotLlqrOrENr2TM+kgEZC8fWExR+SKwVcb2YIdQaCZId4AX1UZt3z3aRgl4q0GbjmztXHIGUg1qLi6ZkClCCkQTelbvAx4EiMhK0NyEji0y9J/RX4CBJJFw9U4noD3ihQfTNpCtpR2htRL6WpVqI1qr3cSauKT52lWenrkI9P8mfVKAtm+OywVALNgjGjgQ6kBoZOR3T+Zm3jFa/U58Uudx0AQmfqCjzP9Q9b7HWGm95o/khrrMzDb4wa5/zfUUeUzZdn9KAKfWMH52qoFQf/K5vvKCj3WcQipVjsVX8AG7+5oyA8R3KSDEw1Q== 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; bh=xo0MIZytkoONbKv73KiVLILRL7WQPMNSQLZSPkh8OgA=; b=ndB8q3xE9Mo6F9inkvAi1XFWhLk1tGkyfk3SfoUGS7LvnGbt/lCjgfaLbU59BWySrYOHRmhU6CbqkTmK46AuLfSvIJCRqlzj5vDQbshWS7zV4zUJAZTGoZLiFz1Pzf2cmJZ/mb8aAuinMNqCMYSKFbXU5JHd/5T/pFC8YhjsxH7MFrkqFqGI/NaC5Utu+QOwA4HfWv70FEzlxyd4emwTpur8G1/qhL7b99GPpB8DTDH3n4ipqwvmETBHL8ICc35VnBadXycB4M8ypa/HSV9V6hDqqN3dy6p02vZPt6xdXxH3J7nwsrmkV37D5v+ZnnEUTMw2AnRX68LjtuIjCFRMwQ== 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=xo0MIZytkoONbKv73KiVLILRL7WQPMNSQLZSPkh8OgA=; b=lCnBbWV7W+iBgbBrcmAU0vhFWXmPV9+9/YzxZmRQW7rtnA4IpUYu86p57IrBDS4kKf4REe6so383/eCe+kd4opOAeWKKXVF6byFtWiVav7o+wl0/QAmBCf4kozkGID4fIJHnymzW7JhxVA8Mzscj6Qw/6cn8mtnH26x4FvcadzQ= 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 DM6PR01MB5513.prod.exchangelabs.com (2603:10b6:5:151::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Wed, 15 Sep 2021 15:59:18 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::8eb:704f:2ba7:9bc3]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::8eb:704f:2ba7:9bc3%4]) with mapi id 15.20.4523.014; Wed, 15 Sep 2021 15:59:18 +0000 From: "Nhi Pham" To: devel@edk2.groups.io CC: patches@amperecomputing.com, nhi@os.amperecomputing.com, vunguyen@os.amperecomputing.com, Thang Nguyen , Chuong Tran , Phong Vo , Leif Lindholm , Michael D Kinney , Ard Biesheuvel , Nate DeSimone Subject: [PATCH v3 02/28] AmpereAltraPkg: Add MmCommunication modules Date: Wed, 15 Sep 2021 22:55:01 +0700 Message-ID: <20210915155527.8176-3-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210915155527.8176-1-nhi@os.amperecomputing.com> References: <20210915155527.8176-1-nhi@os.amperecomputing.com> X-ClientProxiedBy: HK2PR0302CA0012.apcprd03.prod.outlook.com (2603:1096:202::22) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 Received: from sw004.amperecomputing.com (118.69.219.201) by HK2PR0302CA0012.apcprd03.prod.outlook.com (2603:1096:202::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.5 via Frontend Transport; Wed, 15 Sep 2021 15:59:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fed39019-f2cb-49de-fc43-08d97861c5e9 X-MS-TrafficTypeDiagnostic: DM6PR01MB5513: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VF4Y4TqBF96RGe6A3S+xE1reDSfYot73Hy+Hw06jGvNgLfBWclncL0FxD1wDLsAqALDMLrNXc+jOHFM1FuN4+t5+uuhpAFzRlhkGyXBRXlH3p4iX7ha/WTJr41PmfrSi1zNK402Y/ShV9u/iN0l6b1MKHOt4pFOuR/54Mf8bOat+3L07tIT2DDsTQ71KP3A4drtwItz/oT9vLDRzMl9NjxXOfdhxDSTzq0ytSWb0jZmGFl1/L7/otx0ItuX2q5FbqNyvzDOHYNLisqKQb8knQGt6GWBURUK8DWzh5BWF8BUdNKnNke6HRdjpxrRespZoQBnFmaZjV24KGWNfQjVg1fKMp9Yac+tBqG6EI1xUpTG7NIEUoTXOLsnSGrhkgbl3ajU93jsaYRKKwv5aSeOuPgqq+oc152qgrnAsjhdacSjl4jYIkvkKLXzNHrxPB0Q9PntcoaDyIM965WtfCXSGx/PPgVEmqbq7tVgtMhLsPpE7iqAHhyynVV6Wyx+SWViti+EI8WPWpMDJzFaaH7y8ngc3/N6PZoO2eJv2/hxAMLgOdcKwQ3qPyH1wtcehWniwT6nceW2Ct+9VbkHd5mqTRa+kYd/qDAgJTg24/svUClJC8C+mvZXgvbcQdlUknqKot5JS3aIWlqL27paBtwFTPI5Yftlqn6ysXf+PollfX8z7MuSErnOz/Gy1snZm0IQ9WxtzQltzGjgegkBq8zbMXQ== 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)(376002)(136003)(366004)(396003)(39850400004)(346002)(316002)(30864003)(1076003)(5660300002)(83380400001)(54906003)(6506007)(6666004)(4326008)(8676002)(186003)(956004)(6512007)(86362001)(38100700002)(19627235002)(6486002)(38350700002)(478600001)(66946007)(66476007)(66556008)(2616005)(26005)(6916009)(8936002)(52116002)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Gv+FvrJY6qgWg57AhQIlLb2PO1r9f+LxCdh/s2lu4SaIg7S6gM1S+vchVkuC?= =?us-ascii?Q?xyWRtto2yWTPLjzuHJaD0KFpJEOvU2rtmPm/wsabgsO1WLXR9JjGlZaJXTfJ?= =?us-ascii?Q?paNqS8dTfwOZTJMR+8tXxZLrFNn2UfW+zhWyJ/s8yggqBSjhLCtgZtN0ftv3?= =?us-ascii?Q?0WaQZSEBTzttzUOKj2WVokye+EaWW1uxLFOff7ITMw80nyRC3AiTH+uowNxY?= =?us-ascii?Q?JTmJv7AA4m3BI8DliMrgfL1LEbZZt4sPHcTe0mtJ17+fj9xPEQMOFam3OhuR?= =?us-ascii?Q?C9EiaKi4hJhIGj7feUXh1g86dln4VC0voAYNElN6hGL469ga/TlrSWDFQNMJ?= =?us-ascii?Q?XJCmApWY78mIUWbbnusgY8i1LDgSoSHxQ10by1sVDzyTwlOP3jqrTTPdzZEY?= =?us-ascii?Q?erT5fLToIozXMHDynL7Ni5LCkVLxjymU1nAT/veHN2aJjfcn8RpcPQHx0tNH?= =?us-ascii?Q?L1TfEbujYCCEMdlmj9WshX1nIvuSrE8wHdJwqsFRLox5Co9yKHyGs7fxgi01?= =?us-ascii?Q?JcmSkAExF1dQSl2Fnh4Y2e71tE35e2leinwec+OjOihjUM6DJy3Yi8qrshgw?= =?us-ascii?Q?wPzuZP47xEDmBzUKs2Dr7+AawkNRqOKUSMA94kqrOWpA78D4O1w6kBVWv/D4?= =?us-ascii?Q?NQmWOk0ZRMtXZZJBaQ3o3kMV4dV3D6+2CMhGvnVHPwZ2SXiToAeInLpXp5MA?= =?us-ascii?Q?xT7xJHaesso5wSvFE46CCvafiKOkOhw8Av10M4Yn33JST5PQtxRXQMWVvSes?= =?us-ascii?Q?xhDGu6TTW5h44GOOzdCT41vmNQ5Y3kppu8z5k5WfOMxSFGGB0pv/0FmwG8zM?= =?us-ascii?Q?Ty+wOHAGXxDyeeZY5J4MTvcYLVOcGShNfikZHXIyATRkw5B6FT8vT57nqn1I?= =?us-ascii?Q?BGPfjV6P/GOmQQlvv9oxdSm81QpfBaJreBnOT7O30N0cE2sMlpBGJxk+bh0z?= =?us-ascii?Q?cjGIvLz7cYue0wuQvZbb0yt1dajUuwx2Rb5hl500BSRBocGqBJQim9xCsW0e?= =?us-ascii?Q?8kxIAx4WHOZHa/l2gsDfkex+IlK8kGNoWP76+uvfkJTgMpB//S3ugfiph7in?= =?us-ascii?Q?X/jBQ8IGCf5MvyDpJgAPaayI87ED7f3Fh5amjGLWd+Z1zcZoPQI36JEiV4Y0?= =?us-ascii?Q?e0dwgzQzr6F+/fWzhEXFu4Q4tG7YKnEw6ycZ58t4ZU1cy/UuVmt00g8sgoZ0?= =?us-ascii?Q?rZv2UM3kVE6GGeJwGQW+yqCk4xb1/jskCaxZ3JdWrRw7v3Pwj2pnZnuQKP2z?= =?us-ascii?Q?8EULBse7mtW8jud1R2QD7jc5EzsgsY+na4226LAFNotmeDlWT2BZB6xiyuwu?= =?us-ascii?Q?TF6moQTaVjhopZfmH44qOxWH?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: fed39019-f2cb-49de-fc43-08d97861c5e9 X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2021 15:59:18.2159 (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: XS3Gf2teRvfnp/Mxfg1atUqm1bhflqBv41tpRm3QUE0kmCOglc5EDttZ1f6j8T7FiIYFMit9LmMgN2JT5LUb4k96kdiYzibRDGlcltSG7dc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5513 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 Reviewed-by: Leif Lindholm --- 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 770b4a12bc0b..7dadf15b7825 100644 --- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc +++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc @@ -525,6 +525,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 @@ -573,6 +574,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 100644 --- 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 100644 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