From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail03.groups.io (mail03.groups.io [45.79.227.220]) by spool.mail.gandi.net (Postfix) with ESMTPS id AC3E07803CC for ; Fri, 12 Apr 2024 14:33:55 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=jimvGfL2i/8tc8Olna2wtkj4KSetf3G1iVe+9idkNZw=; c=relaxed/simple; d=groups.io; h=Received-SPF:Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:NoDisclaimer:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20240206; t=1712932434; v=1; b=ttxSAglerW19Ua3PVvsH3RcvcNuAiJWDkVMRrfsOtx5Fju2soCt8ej7reYOuVs+DjEaaZK5l myfz+wJRqcPwqtuHQz+XMb8vWxFYBvCZpl9+aUxusxHDC6fyJC4AWva42rcPm69oBJxm8D+50NR QbrVAmm7BK11LwwfOiuB0NyJLWgIlxGhCaRbiBP6Zgu17vtTcBZpopApSdal8ghTIWkLXLa7NGo v6jA+myJSY0/BxWiGCPjbUtZZzvgj4CnGSwAoQqBYt3EvXOtTPUebI9JxFSdlvKtBvzt2jNGODy LhZPoXnW+6HJzh+zmL8ol/8nnRUHLlTnkT/rWcihJA1iA== X-Received: by 127.0.0.2 with SMTP id srhjYY7687511xCKiF8XEX3o; Fri, 12 Apr 2024 07:33:54 -0700 X-Received: from EUR05-VI1-obe.outbound.protection.outlook.com (EUR05-VI1-obe.outbound.protection.outlook.com [40.107.21.54]) by mx.groups.io with SMTP id smtpd.web10.48534.1712932430758429062 for ; Fri, 12 Apr 2024 07:33:51 -0700 X-Received: from DBBPR09CA0010.eurprd09.prod.outlook.com (2603:10a6:10:c0::22) by DBBPR08MB10842.eurprd08.prod.outlook.com (2603:10a6:10:533::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Fri, 12 Apr 2024 14:33:47 +0000 X-Received: from DU2PEPF00028D11.eurprd03.prod.outlook.com (2603:10a6:10:c0:cafe::dc) by DBBPR09CA0010.outlook.office365.com (2603:10a6:10:c0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.22 via Frontend Transport; Fri, 12 Apr 2024 14:33:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C X-Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DU2PEPF00028D11.mail.protection.outlook.com (10.167.242.25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Fri, 12 Apr 2024 14:33:47 +0000 X-Received: ("Tessian outbound 01a47eb2eb85:v313"); Fri, 12 Apr 2024 14:33:47 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c0aadf410401c094 X-CR-MTA-TID: 64aa7808 X-Received: from bb06c000acda.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3D575E6E-625C-4E8F-AC03-F5996A02B011.1; Fri, 12 Apr 2024 14:33:41 +0000 X-Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id bb06c000acda.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 12 Apr 2024 14:33:41 +0000 X-Received: from DUZPR01CA0001.eurprd01.prod.exchangelabs.com (2603:10a6:10:3c3::10) by DBBPR08MB5899.eurprd08.prod.outlook.com (2603:10a6:10:208::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.55; Fri, 12 Apr 2024 14:33:37 +0000 X-Received: from DU2PEPF00028D01.eurprd03.prod.outlook.com (2603:10a6:10:3c3:cafe::e2) by DUZPR01CA0001.outlook.office365.com (2603:10a6:10:3c3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.26 via Frontend Transport; Fri, 12 Apr 2024 14:33:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C X-Received: from nebula.arm.com (40.67.248.234) by DU2PEPF00028D01.mail.protection.outlook.com (10.167.242.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7452.22 via Frontend Transport; Fri, 12 Apr 2024 14:33:36 +0000 X-Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 12 Apr 2024 14:33:35 +0000 X-Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 12 Apr 2024 14:33:34 +0000 X-Received: from E114225.Arm.com (10.1.196.56) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Fri, 12 Apr 2024 14:33:34 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , Subject: [edk2-devel] [PATCH v2 20/45] ArmVirtPkg: Introduce ArmVirtMonitorLib library Date: Fri, 12 Apr 2024 15:32:57 +0100 Message-ID: <20240412143322.5244-21-sami.mujawar@arm.com> In-Reply-To: <20240412143322.5244-1-sami.mujawar@arm.com> References: <20240412143322.5244-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DU2PEPF00028D01:EE_|DBBPR08MB5899:EE_|DU2PEPF00028D11:EE_|DBBPR08MB10842:EE_ X-MS-Office365-Filtering-Correlation-Id: 83a29958-0475-4ed1-8aca-08dc5afd9033 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: mEoGHgtaeJD2c9SqLHUSriEnplqQZT/FzZRubtC/FB6RXCMaSTrIH13AXAv3HvtJNVI4ySNkSCn80OEmDzeExQZdKAodPkI7VcPanIJg8TcxtHkmtSBg66GkzHbKs9PyMuTu0sQ4/4xAIWqHs0h97Um3tqH7hSf9uE4JFY2/uZuvlgBhWfAiknjoLTaOwookwiSFJlkZMxphmKaPsIxSceBbZlbJUn4+QxrBVxhtrergVJKooGWiUxnGH6EzX9WDOQG2tsHUDbeygM8NBYQ/3CDf2rq7MsknC8G/oa3QsptOzpjY/pw6BJAShwsfW+4SP4W8ENmGx9H+TOg8RsD35VJuV/JUv9i8OzaLYlxKq+8ax0C3/+UML/mR1JJeKwjBW/vBRSQIM3B8a0Jy5yBfq2t6XIBbP9AAex9JwqkNlS8d+xIcK0czv3tbJd0gVrwcS6C20mUd3BAeyi+8U63ndHGxtxaetCyavbqt9cECO84kFAdF9r7Zql+UrOkV1UQEIPu15wRqQHixMvN6QCnqYnMwKk973wdYdo+6ximMypKvUddvatNCMx/rc+fntRYjB3niVk0Cpr98gEKpWQwrZioWNgyJeyk7wYSs7Fm3yq72tiUrJtLbwdQM9a3tvwmbIGlECKBs9hpRb3GDSn6m5f5+x/iOGDTtCOtnZ2plam7ljE0ZYMRlorKO7B/3wikaWMJAwl6Drm082ZpFoVQh47cHy+zgfcHhYlxPQJSpz/Gt3hIFFndpLAoWIyfgIVZe X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(376005)(82310400014)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB5899 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DU2PEPF00028D11.eurprd03.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: daa89be7-c8f9-4640-db15-08dc5afd8a16 X-Microsoft-Antispam-Message-Info: XvSMFfaeDiihon9MvCGCefMlsjemOMJ/hlBkoDa0RUDavunu0r2YOE5DYop6C/ll/P0Hx5KpkikrZ/p21AFxH5PgwwDkSfxlt07HAKUX3r4CWQcp/b2PHxi1KTUHHa/UsuUNHm6DuzwP+2BUKwSiqo+gxqJ6VWkDWp4D3atqREoE+7aSISpQTkVsQeCZ8KPDxmtKoQ5GTY9qP7PWtICse75uZAr3EKlEZJ1TLyzjy4Wac5L9q52ZOJKE7wfHC1XBaKotlcnhu+VE/7u60cyJr5LY8EuzrKcpM83t8mhDs1wZz1wFaYX9/C+2E/4bTY4GvB0zbhTtt6ZnMVKZ8oIQ2qg2PuI44sCQn3s2yePWTtYtmWcoseKQ6gScSjMyDbp0qkI1Ikfs/4RJHVroi/nfbSwihnO2/iuor+zphNvJunrjIHJRVHwNuEjxFNAKYsydBfCF2B3gmeq0OsdAiKJ9kvl86srMPrF25/MhwsGR9wVlVjXg8czduWde9QmR4kBvWZj2+D1AQ2uSI1rj7owdv6G5bEg8mA9Yi5+9qyknZHNs2pmUbB9vsQM95arknne/Ne4gguTceb6TpMmPxp57gglaAEyfg9cVivFmpY52OkxhFCzq5WVL2zIIxVbLNJTCG9NDWkTn83WETMezuW/O62cweL3Qvy/NwdIM88vXhCgoKnAhck1DCfzzIbLCQRldueM9b1pW4GJZ1cQzKVbEtuU4XCcwThQwIHo2snJ/cootocV5ZlFeMvYK1w5bJIUN X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2024 14:33:47.2134 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 83a29958-0475-4ed1-8aca-08dc5afd9033 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D11.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB10842 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Fri, 12 Apr 2024 07:33:51 -0700 Resent-From: sami.mujawar@arm.com Reply-To: devel@edk2.groups.io,sami.mujawar@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Ay05f3DYTQ7PlqAom5FUSFgOx7686176AA= Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=ttxSAgle; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.227.220 as permitted sender) smtp.mailfrom=bounce@groups.io ArmMonitorLib provides an abstraction for invoking monitor calls using a SMC or HVC conduit based on the value configured in the PCD PcdMonitorConduitHvc. The monitor call conduit is fixed for a platform firmware in most scenarios. For a normal virtual machine guest firmware, the default conduit is HVC. However, for Arm CCA the Realm code must use SMC as the conduit. To have a common code base for Guest/Virtual firmware to be used by both normal VMs and Realm VMs, the firmware must dynamically detect the conduit to be used. Some VMMs like kvmtool setup the PSCI conduit to be used in the device tree it hands off to the firmware. Therefore, introduce an ArmVirt instance of ArmMontorLib that parses this device tree to read the PSCI conduit value and issues monitor calls using the appropriate conduit. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Gerd Hoffmann Signed-off-by: Sami Mujawar --- ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.c | 119 ++++++++++++++++++++ ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.inf | 37 ++++++ 2 files changed, 156 insertions(+) diff --git a/ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.c b/ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.c new file mode 100644 index 0000000000000000000000000000000000000000..a13bec36b3537a2348e7883c29c5beb6e55dc64b --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.c @@ -0,0 +1,119 @@ +/** @file + Arm Monitor Library. + + Copyright (c) 2022 - 2023, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +/** + An enum representing the PSCI conduits for issuing monitor calls. +*/ +typedef enum PsciConduit { + PsciConduitHvc, // < HVC conduit + PsciConduitSmc, // < SMC conduit + PsciConduitMax +} PSCI_CONDUIT; + +/** + A variable that stores the PSCI conduit to be used. +*/ +STATIC PSCI_CONDUIT mArmPsciConduit = PsciConduitMax; + +/** Monitor call. + + An HyperVisor Call (HVC) or System Monitor Call (SMC) will be issued + depending on the conduit. The library constructor for ArmVirtMonitorLib + determines the conduit by parsing the Device Tree handed off by the VMM + and initialising mArmPsciConduit. + + @param [in,out] Args Arguments for the HVC/SMC. +**/ +VOID +EFIAPI +ArmMonitorCall ( + IN OUT ARM_MONITOR_ARGS *Args + ) +{ + switch (mArmPsciConduit) { + case PsciConduitHvc: + ArmCallHvc ((ARM_HVC_ARGS *)Args); + break; + case PsciConduitSmc: + ArmCallSmc ((ARM_SMC_ARGS *)Args); + break; + default: + ASSERT (0); + CpuDeadLoop (); + } +} + +/** Constructor for ArmVirtMonitorLib. + + The library constructor for ArmVirtMonitorLib determines the conduit + by parsing the Device Tree handed off by the VMM and initialising + mArmPsciConduit, which can then be used to select the appropriate + conduit for invoking the monitor call. + + @retval RETURN_SUCCESS The constructor always returns RETURN_SUCCESS. + @retval RETURN_NOT_FOUND An entry for the PSCI conduit was not found in + the platform device tree. +**/ +RETURN_STATUS +EFIAPI +ArmVirtMonitorLibConstructor ( + VOID + ) +{ + RETURN_STATUS Status; + FDT_CLIENT_PROTOCOL *FdtClient; + CONST VOID *Prop; + + Status = gBS->LocateProtocol ( + &gFdtClientProtocolGuid, + NULL, + (VOID **)&FdtClient + ); + if (RETURN_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = FdtClient->FindCompatibleNodeProperty ( + FdtClient, + "arm,psci-0.2", + "method", + &Prop, + NULL + ); + if (RETURN_ERROR (Status)) { + return Status; + } + + if (AsciiStrnCmp (Prop, "hvc", 3) == 0) { + mArmPsciConduit = PsciConduitHvc; + } else if (AsciiStrnCmp (Prop, "smc", 3) == 0) { + mArmPsciConduit = PsciConduitSmc; + } else { + DEBUG (( + DEBUG_ERROR, + "%a: Unknown PSCI method \"%a\"\n", + __func__, + Prop + )); + return RETURN_NOT_FOUND; + } + + return RETURN_SUCCESS; +} diff --git a/ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.inf b/ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.inf new file mode 100644 index 0000000000000000000000000000000000000000..d90f92d5faff96de9cd0433c1de18b0168b42592 --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtMonitorLib/ArmVirtMonitorLib.inf @@ -0,0 +1,37 @@ +## @file +# Arm Virt Monitor Library +# +# Copyright (c) 2022 - 2023, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 1.29 + BASE_NAME = ArmVirtMonitorLib + FILE_GUID = 3E464134-890D-4C3F-A559-D0FE2803E332 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmMonitorLib|DXE_DRIVER DXE_RUNTIME_DRIVER + CONSTRUCTOR = ArmVirtMonitorLibConstructor + +[Sources] + ArmVirtMonitorLib.c + +[Packages] + ArmPkg/ArmPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmHvcLib + ArmSmcLib + DebugLib + UefiBootServicesTableLib + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Depex] + gFdtClientProtocolGuid + -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117678): https://edk2.groups.io/g/devel/message/117678 Mute This Topic: https://groups.io/mt/105483416/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-