From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (EUR05-VI1-obe.outbound.protection.outlook.com [40.107.21.71]) by mx.groups.io with SMTP id smtpd.web11.83445.1682438690987342709 for ; Tue, 25 Apr 2023 09:04:51 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=uCiRVh2x; spf=pass (domain: arm.com, ip: 40.107.21.71, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JpiKmZanIgN70LV/20XCSdKvWVFmSmmo1DWTDgU+6Rs=; b=uCiRVh2xfhdWA9DloNCm0KNcsOoBP9aGzXc1d5xtjtsJRcsFFUC9XgGDV1lR4n4iSpDLlJI1SOYWyMYnOzC/ckA+qtDTjZ4lpVtwC+GNEmrPmFM/MsIxu8Cv2n2iPmH2swQVWoyz5NNNHlCV2u5Or4M7fODjMN61TayIGrR1dBM= Received: from AS9PR06CA0142.eurprd06.prod.outlook.com (2603:10a6:20b:467::35) by AS1PR08MB7612.eurprd08.prod.outlook.com (2603:10a6:20b:477::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.33; Tue, 25 Apr 2023 16:04:47 +0000 Received: from AM7EUR03FT050.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:467:cafe::b8) by AS9PR06CA0142.outlook.office365.com (2603:10a6:20b:467::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.33 via Frontend Transport; Tue, 25 Apr 2023 16:04: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 Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT050.mail.protection.outlook.com (100.127.141.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.21 via Frontend Transport; Tue, 25 Apr 2023 16:04:46 +0000 Received: ("Tessian outbound 8b05220b4215:v136"); Tue, 25 Apr 2023 16:04:46 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 65822af2f738dae3 X-CR-MTA-TID: 64aa7808 Received: from db44ddda7f40.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 1CCF64AE-8030-48EC-9703-34168ED6B4E8.1; Tue, 25 Apr 2023 16:04:39 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id db44ddda7f40.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 25 Apr 2023 16:04:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B4wdy68Ir3+Wfd/KEvmpLvoATGwNbZ7+YdEkFqcrAE7+IHJylhuQNQ1u0Lw/LC5w0Te/H5hnxZMug8NsokjTy3++px4vTeeuHoaLXmkLrMQm5yGWuhvOG7oSjPHwsPicZKj9rC6tU/8FA/JYNVtQ+Ng0X2SXFMh3BqXHS0KMRVLlHyxBJTPSd24FH8HxHCXJ8BMpaEk8cDK1SM+nMK3lze71Z5F5QSTx9YYO+3FUFfnQ7UsO4BxvPYj7NCsquxwyqZDdYc9Pu/rKc2GTNuZ4W8MQsKhdTjM/YNpYxp/VY0qFCimVIcA/h3/x8nKCd/vWicq0ctJ2vwTuoUTn1mM3pQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JpiKmZanIgN70LV/20XCSdKvWVFmSmmo1DWTDgU+6Rs=; b=LovDbjd5wZQuRjil5icxSgCGO5gmBtS2b4hgXAfpW1zvHdYB1UKcCPv8za4d45qyBoji0Z31N/GPWdn9jQ24HxwvPUvLxMjwYbJgIcEV1dQqUSZJz6vLpcERA25mQh+gkdGBek1uC1VThwrmlf06SLAYcj/jbsrntEZW3gQFD2Eea/eKup58925Jpy6fswrC2ZrlGjq/E8yExx5OkSvWPRycfBfkVz60VLRVzUIaCOn1hqOku5SijxhujrQSrGmeFTLriDWFCdU4uelkHmkKTvZENo8SHaeOBM+pRgjijyE3g4wsQ/yMeIUQjeB1D1+IMZpZkQXGPPKPJESVbiPF+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JpiKmZanIgN70LV/20XCSdKvWVFmSmmo1DWTDgU+6Rs=; b=uCiRVh2xfhdWA9DloNCm0KNcsOoBP9aGzXc1d5xtjtsJRcsFFUC9XgGDV1lR4n4iSpDLlJI1SOYWyMYnOzC/ckA+qtDTjZ4lpVtwC+GNEmrPmFM/MsIxu8Cv2n2iPmH2swQVWoyz5NNNHlCV2u5Or4M7fODjMN61TayIGrR1dBM= Received: from DB3PR08CA0030.eurprd08.prod.outlook.com (2603:10a6:8::43) by DBAPR08MB5606.eurprd08.prod.outlook.com (2603:10a6:10:1a7::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.34; Tue, 25 Apr 2023 16:04:37 +0000 Received: from DBAEUR03FT017.eop-EUR03.prod.protection.outlook.com (2603:10a6:8:0:cafe::9d) by DB3PR08CA0030.outlook.office365.com (2603:10a6:8::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.34 via Frontend Transport; Tue, 25 Apr 2023 16:04: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 Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT017.mail.protection.outlook.com (100.127.142.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6340.20 via Frontend Transport; Tue, 25 Apr 2023 16:04:37 +0000 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.23; Tue, 25 Apr 2023 16:04:36 +0000 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.23; Tue, 25 Apr 2023 16:04:35 +0000 Received: from E114225.Arm.com (10.1.196.36) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2507.23 via Frontend Transport; Tue, 25 Apr 2023 16:04:35 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , , , Subject: [RFC PATCH v1 06/30] ArmVirtPkg: Add Arm CCA Realm Service Interface Library Date: Tue, 25 Apr 2023 17:04:04 +0100 Message-ID: <20230425160428.27980-7-sami.mujawar@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20230425160428.27980-1-sami.mujawar@arm.com> References: <20230425160428.27980-1-sami.mujawar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DBAEUR03FT017:EE_|DBAPR08MB5606:EE_|AM7EUR03FT050:EE_|AS1PR08MB7612:EE_ X-MS-Office365-Filtering-Correlation-Id: f1416ec7-711d-4c48-7682-08db45a6ca9b 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: YyWmgLY3yvBS53RZ9Jh5WThF1Uheg3pNOjhkntTemCv82hI5o74t+gyzHw6yWcGks5HkY55A++bgc4FIlRi1YGEEcJfkzWBeYD9JAhVQa4mxckvcw5bX5SOo010z2UsTKkw9iRB0Hq7ft4rWjJH7ND97y9wdOW5hAAsWw58hc+HCJsfUFLdXAXqu+v4F5uzOSo6YLFPq1FpC9V3BGPrFWN0HLLVrZSRsjyCvkv/LEKCIX1v52tRXSdqWwhytbvYveupzQDZCrzYIcNtLrm2yGP69LfkbRP1ykYOMyo0TMVkiU24I5d3PF0KdKN7/yepnZrvlYb2QTroe37XKIedQNPjtc5stfOpNOLmx1/CpzM5LR3lyBkqCGttri0Xq/ZvxNiKKAC0GeK/Y+xPvQtOS1RNadf8EL6Zisl3IXLe1/TOd+nfTRV6U5NENSSdt5kXpwEV8wtAfnMuPV38e0QudTxbkL46Rqc6F6xkrKmSok8WRR9rFYa0t+KATSJeixeL6Z/3V1V9LxPcV/i4rTPYZHJYUz9bYpgjhidZS7D2iHU1hXpTsugeVBuQzthe3b0EgJdKnEKN7DYTBW4voLN+Qti9jSpZqJsDRaOBuP2zviTD4cW6KutsjJJmNjRjF8CtD+ns8hhpyzAjUgy1bH6LtBVQaXKtVRaHbD/kaJy/mboHO0WRfAaVbBc9WmZS8+ilzsv6OzdcsxHFmRw6tbDCd9I3NC6nkC1//ddKiHMJczlM= 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:(13230028)(4636009)(39850400004)(136003)(396003)(376002)(346002)(451199021)(46966006)(36840700001)(36756003)(54906003)(34070700002)(82310400005)(86362001)(478600001)(41300700001)(81166007)(8936002)(8676002)(44832011)(2906002)(6916009)(40480700001)(4326008)(316002)(356005)(82740400003)(70586007)(70206006)(5660300002)(186003)(1076003)(26005)(336012)(426003)(83380400001)(47076005)(2616005)(36860700001)(7696005)(6666004)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5606 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT050.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: fea7935d-3c56-4c29-a5ee-08db45a6c4fa X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nBcpH5ZtGF9WHbGne4xyINm/tr3x/2TBlewdGP7Kmp//WCTRFAZ8pz9O0UJohcL4x6rP3anMaYbu0EHthqlpi3Ik9Qd1Ygii7MdGMSpsvG7Ny8qGyun91LIDAryEz42diPY4wHpS8dPFoZdgZJQraCch1FMejOmV2D/GZ7w4chShjzfNTUVL1SMFiESW+YEE8X2nTMV3j2ohU8zIVbumLbICX0QeXthz4cKfyY6GVcFJPsCN60i4I6se0cKUtJjx65zDEddv9U7tdLR52wZ/mBQOqLiUASxJukB52qNRERTfWGpbh14BqwjAm8xM4WyyYL/v+Vauit9hHrGq9hFXFC6A7FAmLeko6vcFURAA7ZPmEC0+3E6txOvAzPZWWouoykSgzYYuPx7g6Z3zFNCtE6nN1fxqH5sxhoVei+fGHb4lV8jy2n7W5+VQDU+UKf1zeCJrjJsU3QHKfPSDRj2NAf+VH3/oG4Ka39jZg/tveEXZwd2SS2glFLjAP0cRYJXKtW+c/3VSGFixMciopLWDPZuboYfBaGCTWlUUosJcfR2wsI58b46yb/LY0YLNZE4eegcGwCF+zMHVqx3VMTtoscKbIZmw6b9P0uXsbOBSYZhWDVS3fuHd7i7MudO31UJsAMtJzArhvi5ok789k6R03RcEY+XlqSK0YCIHcB4+om9t5C1Ej/QtoaWZJCvWcF2U1YzhC4XUyeRjX7jVHlwVm5LjoDf06kwwOPuX5ttgVcY= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230028)(4636009)(136003)(396003)(39860400002)(346002)(376002)(451199021)(36840700001)(40470700004)(46966006)(2906002)(70206006)(70586007)(6916009)(4326008)(316002)(44832011)(5660300002)(8936002)(8676002)(41300700001)(82310400005)(36756003)(86362001)(40460700003)(40480700001)(186003)(26005)(1076003)(81166007)(478600001)(36860700001)(6666004)(7696005)(34070700002)(83380400001)(2616005)(47076005)(336012)(426003)(54906003)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2023 16:04:46.8349 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f1416ec7-711d-4c48-7682-08db45a6ca9b 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: AM7EUR03FT050.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR08MB7612 Content-Type: text/plain The Realm Management Monitor (RMM) is a software component which forms part of a system which implements the Arm Confidential Compute Architecture (CCA) and is responsible for management of Realms. The RMM specification defines a Realm Service Interface (RSI) that the Guest can use to request services from the RMM. Therefore, add a library that implements the RSI interfaces to: - query the RSI version - get the Realm configuration. Signed-off-by: Sami Mujawar --- ArmVirtPkg/ArmVirtPkg.dec | 1 + ArmVirtPkg/Include/Library/ArmCcaRsiLib.h | 72 ++++++++++ ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h | 40 ++++++ ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c | 145 ++++++++++++++++++++ ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.inf | 29 ++++ 5 files changed, 287 insertions(+) diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec index 4645c91a83756603141717baadd9f3e9b482cdb2..0bc7d697428636d42ffb27e8e92fca947665a79e 100644 --- a/ArmVirtPkg/ArmVirtPkg.dec +++ b/ArmVirtPkg/ArmVirtPkg.dec @@ -26,6 +26,7 @@ [Includes.common] Include # Root include for the package [LibraryClasses] + ArmCcaRsiLib|Include/Library/ArmCcaRsiLib.h ArmVirtMemInfoLib|Include/Library/ArmVirtMemInfoLib.h [Guids.common] diff --git a/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h b/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h new file mode 100644 index 0000000000000000000000000000000000000000..ab70240b3ab2979996f20190ddf669b53183556b --- /dev/null +++ b/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h @@ -0,0 +1,72 @@ +/** @file + Library that implements the Arm CCA Realm Service Interface calls. + + Copyright (c) 2022 - 2023, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + - Rsi or RSI - Realm Service Interface + - IPA - Intermediate Physical Address + + @par Reference(s): + - Realm Management Monitor (RMM) Specification, version A-bet0 + (https://developer.arm.com/documentation/den0137/) +**/ + +#ifndef ARM_CCA_RSI_LIB_ +#define ARM_CCA_RSI_LIB_ + +#include + +/** + A macro defining the size of a Realm Granule. + See Section A2.2, RMM Specification, version A-bet0 + DNBXXX A Granule is a unit of physical memory whose size is 4KB. +*/ +#define REALM_GRANULE_SIZE SIZE_4KB + +/** A structure describing the Realm Configuration. + See Section B4.4.4 RsiRealmConfig type, RMM Specification, version A-bet0 + The width of the RsiRealmConfig structure is 4096 (0x1000) bytes. +*/ +typedef struct RealmConfig { + // Width of IPA in bits. + UINT64 IpaWidth; + // Unused bits of the RsiRealmConfig structure should be zero. + UINT8 Reserved[SIZE_4KB - sizeof (UINT64)]; +} REALM_CONFIG; + +/** + Read the Realm Configuration. + + @param [out] Config Pointer to the address of the buffer to retrieve + the Realm configuration. + + Note: The buffer to retrieve the Realm configuration must be aligned to the + Realm granule size. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiGetRealmConfig ( + IN REALM_CONFIG *Config + ); + +/** + Get the version of the RSI implementation. + + @param [out] Major The major version of the RSI implementation. + @param [out] Minor The minor version of the RSI implementation. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. + */ +RETURN_STATUS +EFIAPI +RsiGetVersion ( + OUT UINT16 *CONST Major, + OUT UINT16 *CONST Minor + ); + +#endif // ARM_CCA_RSI_LIB_ diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h new file mode 100644 index 0000000000000000000000000000000000000000..90e9dbb609679c82cd8e8ee8081428fd97021f97 --- /dev/null +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h @@ -0,0 +1,40 @@ +/** @file + Definitions for Arm CCA Realm Service Interface. + + Copyright (c) 2022 - 2023, ARM Ltd. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Rsi or RSI - Realm Service Interface + - IPA - Intermediate Physical Address + + @par Reference(s): + - Realm Management Monitor (RMM) Specification, version A-bet0 + (https://developer.arm.com/documentation/den0137/) +**/ + +#ifndef ARM_CCA_RSI_H_ +#define ARM_CCA_RSI_H_ + +// FIDs for Realm Service Interface calls. +#define FID_RSI_REALM_CONFIG 0xC4000196 +#define FID_RSI_VERSION 0xC4000190 + +/** RSI Command Return codes + See Section B4.4.1, RMM Specification, version A-bet0. + The width of the RsiCommandReturnCode enumeration is 64 bits. +*/ +#define RSI_SUCCESS 0ULL +#define RSI_ERROR_INPUT 1ULL +#define RSI_ERROR_STATE 2ULL +#define RSI_INCOMPLETE 3ULL + +/** RSI interface Version + See Section B4.4.3, RMM Specification, version A-bet0. + The width of the RsiInterfaceVersion fieldset is 64 bits. +*/ +#define RSI_VER_MINOR_MASK 0x00FFULL +#define RSI_VER_MAJOR_MASK 0x7F00ULL +#define RSI_VER_MAJOR_SHIFT 16 + +#endif // ARM_CCA_RSI_H_ diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c new file mode 100644 index 0000000000000000000000000000000000000000..42b99fb7a71c8b38512a2f7472f9bc8a034fe1e9 --- /dev/null +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c @@ -0,0 +1,145 @@ +/** @file + Library that implements the Arm CCA Realm Service Interface calls. + + Copyright (c) 2022 - 2023, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Glossary: + - Rsi or RSI - Realm Service Interface + - IPA - Intermediate Physical Address + + @par Reference(s): + - Realm Management Monitor (RMM) Specification, version A-bet0 + (https://developer.arm.com/documentation/den0137/) + +**/ +#include + +#include +#include +#include +#include +#include +#include "ArmCcaRsi.h" + +/** + Convert the RSI status code to EFI Status code. + + @param [in] RsiCommandReturnCode RSI status code. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. + @retval RETURN_ABORTED The operation was aborted as the state + of the Realm or REC does not match the + state expected by the command. + @retval RETURN_NOT_READY The operation requested by the command + is not complete. + **/ +STATIC +RETURN_STATUS +RsiCmdStatusToEfiStatus ( + IN UINT64 RsiCommandReturnCode + ) +{ + switch (RsiCommandReturnCode) { + case RSI_SUCCESS: + return RETURN_SUCCESS; + case RSI_ERROR_INPUT: + return RETURN_INVALID_PARAMETER; + case RSI_ERROR_STATE: + return RETURN_ABORTED; + case RSI_INCOMPLETE: + return RETURN_NOT_READY; + default: + // Unknown error code. + ASSERT (0); + break; + } // switch + + return RETURN_ABORTED; +} + +/** + Check if the address is aligned to the size of the Realm granule. + + @param [in] Address Address to check granule alignment. + + @retval TRUE Address is aligned to the Realm granule size. + @retval FALSE Address is not aligned to the Realm granule size. +**/ +STATIC +BOOLEAN +EFIAPI +AddrIsGranuleAligned ( + IN UINT64 *Address + ) +{ + if (((UINT64)Address & (REALM_GRANULE_SIZE - 1)) != 0) { + return FALSE; + } + + return TRUE; +} + +/** + Read the Realm Configuration. + + @param [out] Config Pointer to the address of the buffer to retrieve + the Realm configuration. + + Note: The buffer to retrieve the Realm configuration must be aligned to the + Realm granule size. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiGetRealmConfig ( + OUT REALM_CONFIG *Config + ) +{ + ARM_SMC_ARGS SmcCmd; + + if ((Config == NULL) || (!AddrIsGranuleAligned ((UINT64 *)Config))) { + return RETURN_INVALID_PARAMETER; + } + + ZeroMem (&SmcCmd, sizeof (SmcCmd)); + SmcCmd.Arg0 = FID_RSI_REALM_CONFIG; + SmcCmd.Arg1 = (UINTN)Config; + + ArmCallSmc (&SmcCmd); + return RsiCmdStatusToEfiStatus (SmcCmd.Arg0); +} + +/** + Get the version of the RSI implementation. + + @param [out] Major The major version of the RSI implementation. + @param [out] Minor The minor version of the RSI implementation. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. + */ +RETURN_STATUS +EFIAPI +RsiGetVersion ( + OUT UINT16 *CONST Major, + OUT UINT16 *CONST Minor + ) +{ + ARM_SMC_ARGS SmcCmd; + + if ((Major == NULL) || (Minor == NULL)) { + return EFI_INVALID_PARAMETER; + } + + ZeroMem (&SmcCmd, sizeof (SmcCmd)); + SmcCmd.Arg0 = FID_RSI_VERSION; + + ArmCallSmc (&SmcCmd); + *Minor = SmcCmd.Arg0 & RSI_VER_MINOR_MASK; + *Major = (SmcCmd.Arg0 & RSI_VER_MAJOR_MASK) >> RSI_VER_MAJOR_SHIFT; + return RETURN_SUCCESS; +} diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.inf b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.inf new file mode 100644 index 0000000000000000000000000000000000000000..1e2b72f312587f822dfca1b26b1910f75d4ec7b6 --- /dev/null +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.inf @@ -0,0 +1,29 @@ +## @file +# Library that implements the Arm CCA Realm Service Interface calls. +# +# Copyright (c) 2022 - 2023, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = ArmCcaRsiLib + FILE_GUID = 5EF34A0A-28B5-4E57-A999-CC1528FC629A + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmCcaRsiLib + +[Sources] + ArmCcaRsiLib.c + ArmCcaRsi.h + +[Packages] + ArmPkg/ArmPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmLib + ArmSmcLib -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'