From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.80]) by mx.groups.io with SMTP id smtpd.web10.83962.1682438694691617593 for ; Tue, 25 Apr 2023 09:04:55 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=iy3z45Vt; spf=pass (domain: arm.com, ip: 40.107.22.80, 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=sdgl81LEDTHHrd63wk5/yLnJtSJVvnfqgcSdkEnEkPw=; b=iy3z45VtCIVvtmWu0OHK3rHqxgxgaKQIue7l5k/ChiY0rSUFd5wSUwtq/LsJYiyoXpOxJ6/rYcIT7SaNGfiHDUy6P5MHAWpOxOo7TZ6OW1pGf3rS0SKhaE+YfSU0M94jwKyoR8OJkmcqNU3Wp/uLbm68+v4uBJYSR/OCGkI6Qew= Received: from AS9PR0301CA0022.eurprd03.prod.outlook.com (2603:10a6:20b:468::18) by AM9PR08MB6676.eurprd08.prod.outlook.com (2603:10a6:20b:2ff::21) 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:47 +0000 Received: from AM7EUR03FT014.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:468:cafe::28) by AS9PR0301CA0022.outlook.office365.com (2603:10a6:20b:468::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.54 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 AM7EUR03FT014.mail.protection.outlook.com (100.127.140.163) 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:47 +0000 Received: ("Tessian outbound 3a01b65b5aad:v136"); Tue, 25 Apr 2023 16:04:47 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 1ae188d6bdfd72db X-CR-MTA-TID: 64aa7808 Received: from cb4b7a39bab1.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id CB9FC1E5-C047-4DC3-9AA9-C1D508A253A8.1; Tue, 25 Apr 2023 16:04:40 +0000 Received: from EUR03-AM7-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id cb4b7a39bab1.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 25 Apr 2023 16:04:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jj2/I5dIfVc2N59Fr7weJ9EnYpl3dSfnrmHi3zfRHCQZQDEP8XfJ1jidkfj7RfisJgeRuGUtl6mSWLzkntBNYFTBbXjE56gdkwq44GZGesgfMV6Ay6YNA4ZEgMIJBNHOZE4UwEwF/mj+We/r6n03WHxyOCjzwlYH90Ce73aGMiRaJy+fE3bHTyobOm7FAqQo1IoBPt7z++OE5zfHfpU0xx0ob5pVd6MAY3ToGjhSq1gagZdllxAtfnnzFheAQxwX2MweYhtDXZDy4PP8NRVTW4nT5bDiLtQNRW2OhWu59eElrAuRkjVJYdaNhvF4fuXBmDltfNVlah1oO+ZM9Pftfw== 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=sdgl81LEDTHHrd63wk5/yLnJtSJVvnfqgcSdkEnEkPw=; b=IML1HYXmcK6Tv6r0vgGWhkGIOm2oagPXCCv0MicxGffW1WDpG/YO5a0/fhs33aFbFRNq9fus+bOsI6ZA6mcEKrbM7raENOexQrLRPu3hZFoHj/cz82JJotTUjDd+ETS0nE8+tkJ0365OW2vUYCV0rvhUJnrOWVEJTR1NADY/FLCPaynXjAoNgxgsvsKgJoelwr9ZcbHdKUEx1N1dhnZ6Mvcihq08n5dNNF/VWbe2Yz8bHXQ8409yPl4OyB+inZjkTZwWnEuWQTKRMeB5J4NINl7I8ZrBa4ANgiWJyCx0iPJRkY9ldXzQ8GbgtgiMcAl/MIUmnuSKRrHuKxSXmZPwGg== 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=sdgl81LEDTHHrd63wk5/yLnJtSJVvnfqgcSdkEnEkPw=; b=iy3z45VtCIVvtmWu0OHK3rHqxgxgaKQIue7l5k/ChiY0rSUFd5wSUwtq/LsJYiyoXpOxJ6/rYcIT7SaNGfiHDUy6P5MHAWpOxOo7TZ6OW1pGf3rS0SKhaE+YfSU0M94jwKyoR8OJkmcqNU3Wp/uLbm68+v4uBJYSR/OCGkI6Qew= Received: from DU2PR04CA0269.eurprd04.prod.outlook.com (2603:10a6:10:28e::34) by AS8PR08MB10170.eurprd08.prod.outlook.com (2603:10a6:20b:63f::12) 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:38 +0000 Received: from DBAEUR03FT055.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:28e:cafe::e0) by DU2PR04CA0269.outlook.office365.com (2603:10a6:10:28e::34) 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:38 +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 DBAEUR03FT055.mail.protection.outlook.com (100.127.142.171) 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:38 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) 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:37 +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:36 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , , , Subject: [RFC PATCH v1 07/30] ArmVirtPkg: ArmCcaRsiLib: Add interfaces to manage the Realm IPA state Date: Tue, 25 Apr 2023 17:04:05 +0100 Message-ID: <20230425160428.27980-8-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: DBAEUR03FT055:EE_|AS8PR08MB10170:EE_|AM7EUR03FT014:EE_|AM9PR08MB6676:EE_ X-MS-Office365-Filtering-Correlation-Id: b2e972f1-2f26-4e37-e60f-08db45a6cb05 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: mMwH5MgCcQ+kvW71y9QASI6AK+xi7bhpxepx/+qV4s+FITqJcp+TgUEORns+We75IqkZnazXq1ZHhFBwhGRA6YRw2UVi2Xm+MYWKB/diezb1mDt49jnyFI96VwlHW4qFu30QcUzmhdBbf+nsEm+c0IPHIbhHhWSMUhIgn5pVl6PKKwh6RoGJFED9qGwN20rB1Fz8pV3Ye3RheimskRYYESTr9IqbnuibHNK0jd32OxBmlg5+Qv2dT6NG8sTPPXvz8DPE6BAGE+UwaUCuQUi/MlyN6QXMKiuVhHPR6GtK6rlrpzLfI/7WZYMJNORX5kuz6mvHiw59/IgH4uTg1btVSBeJa7lysgTCBWJfZQsXdtFTFvtfVFPaos7h59VaszRuh2DpFc/gPwdnV6eWPUpVrupimI3sNYWUZEQ6nj+BMlbS+sl9VMUbmiUMa9RQhgAfVn4g5JZcZKwfieggKECi/AiEtDF2BGqVtfriLHDKpFcHfjAEx5j1Sj96PjzpdTXngTEKfukqyknZNV4z9wU7syPGnW7Tvn2cP7JMKj2idLaNYL0QWNSaR39e9um5rHwjiXn1/UNNqs2A52GG31vj0REDH8Rq5fp41k7b2ZSHAKZ5R4Avbgg2OIINFRXoiHLZ4SsBplQe3wBjZZERgarOFCP12mu2305+fjgY9xc4gir5Yoh+nX/MKj1jIZ52FlzORi7AYhKAZi5j+lavxPJvD7sQRKm7L7uwN8Dz66FGTNk= 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)(396003)(39860400002)(376002)(136003)(346002)(451199021)(36840700001)(46966006)(1076003)(26005)(40480700001)(426003)(336012)(2616005)(36756003)(34070700002)(83380400001)(36860700001)(47076005)(186003)(82740400003)(356005)(81166007)(70206006)(86362001)(70586007)(478600001)(6916009)(8676002)(8936002)(54906003)(44832011)(5660300002)(7696005)(41300700001)(2906002)(82310400005)(4326008)(6666004)(316002)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB10170 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT014.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 1ff1f0a5-9772-46b8-c4a3-08db45a6c584 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pohMm1rXWVGpANXa4zAmxkNkZiwn9+5hP/+Xm7AkL++myFVfg9R5myzM1m7SgmotKic0gDO7xSWIUFjrOCfLwRoIgPOlP4G2TxM6OZSq+ZMd5+evPt6/6y3umPL9clmE+iU1JjKNE9bJor90Bw5LFnwBmbadhNot5etMBvqsKBgilXYpf1nmD7ThWazDoBh1ny537L29URrJD3UQi4rN2T/ALlMWeJIHoNmD1y9vrUEKauQ6Ui0/bcspshng9udOQbyihXfuAwb7UJHK8C3bFANSldO/WbPEyA9DhtETZCGBJw2bhpUzkNWCEnAQGTfO3EXRlmQZBjSxWkfA8DTx4jQF5hIXgPSetTAs2U6PN7mRUTqPsyXv+oF3gbFtnlPdb0cWV3mwAfyOtfzEVqxipcD1I4E1cp0rP4YzatanC8pjrezbP4Wmva7f/k66HTE7DD4wTw3/mrwzmcPtlk0c10lhc8MC92gSr3N3zsy8VYH70pMvhsB/lX4aiG/8BEq6ezQvhbMHcIS7jFwp1KfZlol1z66OBH/q8y6S42yAC+YfpAmiEx9VKfGmKb57LIWfEDmwCQEJuUCvzmXbvEIZ4/7YxaP6Sm7k+O2nkMP6rTSOxNmgq8lfCFvxFCWblDyryGN9LPLMLgwbYUb1GUGrz9Ty/WjD3hpHzFmZdz8HVfY82M/X999W2jA2w0Lwg+m+82Q24UjUdEixsSBZX2DCjIy1HupJArfNCRK8VHJg8hQ= 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)(396003)(39860400002)(136003)(346002)(376002)(451199021)(46966006)(36840700001)(40470700004)(34070700002)(6666004)(6916009)(2616005)(316002)(82310400005)(4326008)(70586007)(70206006)(36860700001)(478600001)(426003)(336012)(47076005)(83380400001)(2906002)(8676002)(86362001)(8936002)(5660300002)(7696005)(186003)(82740400003)(54906003)(41300700001)(1076003)(26005)(40460700003)(81166007)(40480700001)(44832011)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2023 16:04:47.5325 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2e972f1-2f26-4e37-e60f-08db45a6cb05 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: AM7EUR03FT014.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6676 Content-Type: text/plain The IPA space of a Realm is divided into two halves: Protected IPA space and Unprotected IPA space. Software in a Realm should treat the most significant bit of an IPA as a protection attribute. A Protected IPA is an address in the lower half of a Realm's IPA space. An Unprotected IPA is an address in the upper half of a Realm's IPA space. A Protected IPA has an associated Realm IPA state (RIPAS). The RIPAS values are: * EMPTY - Unused address * RAM - Private code or data owned by the Realm. Software in the Realm needs to share memory with the host to communicate with the outside world, e.g. network, disk image, etc. To share memory, the software in the Realm first transitions the RIPAS of memory region it wants to share with the host from RAM to EMPTY. The Realm software can then access the shared memory region using the Unprotected IPA address. The RMM specification defines the following Realm Service Interfaces for managing the IPA state: * RSI_IPA_STATE_GET * RSI_IPA_STATE_SET Therefore, update the ArmCcaRsiLib to add interfaces to get and set the IPA state of Realm memory pages. Signed-off-by: Sami Mujawar --- ArmVirtPkg/Include/Library/ArmCcaRsiLib.h | 50 +++++++++++ ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h | 7 +- ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c | 92 ++++++++++++++++++++ 3 files changed, 147 insertions(+), 2 deletions(-) diff --git a/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h b/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h index ab70240b3ab2979996f20190ddf669b53183556b..ae798a2feb9c3c417f06b7c2dfdb49479731df52 100644 --- a/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h +++ b/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h @@ -6,6 +6,7 @@ - Rsi or RSI - Realm Service Interface - IPA - Intermediate Physical Address + - RIPAS - Realm IPA state @par Reference(s): - Realm Management Monitor (RMM) Specification, version A-bet0 @@ -24,6 +25,21 @@ */ #define REALM_GRANULE_SIZE SIZE_4KB +/** + A macro defining the mask for the RSI RIPAS type. + See Section B4.4.5 RsiRipas type, RMM Specification, version A-bet0. +*/ +#define RIPAS_TYPE_MASK 0xFF + +/** An enum describing the RSI RIPAS. + See Section A5.2.2 Realm IPA state, RMM Specification, version A-bet0 +*/ +typedef enum Ripas { + RIPAS_EMPTY, ///< Unused IPA location. + RIPAS_RAM, ///< Private code or data owned by the Realm. + RIPAS_MAX ///< A valid RIPAS type value is less than RIPAS_MAX. +} RIPAS; + /** 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. @@ -35,6 +51,40 @@ typedef struct RealmConfig { UINT8 Reserved[SIZE_4KB - sizeof (UINT64)]; } REALM_CONFIG; +/** + Returns the IPA state for the page pointed by the address. + + @param [in] Address Address to retrive IPA state. + @param [out] State The RIPAS state for the address specified. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiGetIpaState ( + IN UINT64 *Address, + OUT RIPAS *State + ); + +/** + Sets the IPA state for the pages pointed by the memory range. + + @param [in] Address Address to the start of the memory range. + @param [in] Size Length of the memory range. + @param [in] State The RIPAS state to be configured. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiSetIpaState ( + IN UINT64 *Address, + IN UINT64 Size, + IN RIPAS State + ); + /** Read the Realm Configuration. diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h index 90e9dbb609679c82cd8e8ee8081428fd97021f97..9cc12bc5a70b457367077d0b26011c3b91fa63c9 100644 --- a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h @@ -7,6 +7,7 @@ @par Glossary: - Rsi or RSI - Realm Service Interface - IPA - Intermediate Physical Address + - RIPAS - Realm IPA state @par Reference(s): - Realm Management Monitor (RMM) Specification, version A-bet0 @@ -17,8 +18,10 @@ #define ARM_CCA_RSI_H_ // FIDs for Realm Service Interface calls. -#define FID_RSI_REALM_CONFIG 0xC4000196 -#define FID_RSI_VERSION 0xC4000190 +#define FID_RSI_IPA_STATE_GET 0xC4000198 +#define FID_RSI_IPA_STATE_SET 0xC4000197 +#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. diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c index 42b99fb7a71c8b38512a2f7472f9bc8a034fe1e9..546df9a94cb86533b37fef7e42fdaf7b8563052d 100644 --- a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c @@ -7,6 +7,7 @@ @par Glossary: - Rsi or RSI - Realm Service Interface - IPA - Intermediate Physical Address + - RIPAS - Realm IPA state @par Reference(s): - Realm Management Monitor (RMM) Specification, version A-bet0 @@ -81,6 +82,97 @@ AddrIsGranuleAligned ( return TRUE; } +/** + Returns the IPA state for the page pointed by the address. + + @param [in] Address Address to retrive IPA state. + @param [out] State The RIPAS state for the address specified. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiGetIpaState ( + IN UINT64 *Address, + OUT RIPAS *State + ) +{ + RETURN_STATUS Status; + ARM_SMC_ARGS SmcCmd; + + if ((State == NULL) || (!AddrIsGranuleAligned (Address))) { + return RETURN_INVALID_PARAMETER; + } + + ZeroMem (&SmcCmd, sizeof (SmcCmd)); + SmcCmd.Arg0 = FID_RSI_IPA_STATE_GET; + SmcCmd.Arg1 = (UINTN)Address; + + ArmCallSmc (&SmcCmd); + Status = RsiCmdStatusToEfiStatus (SmcCmd.Arg0); + if (!RETURN_ERROR (Status)) { + *State = (RIPAS)(SmcCmd.Arg1 & RIPAS_TYPE_MASK); + } + + return Status; +} + +/** + Sets the IPA state for the pages pointed by the memory range. + + @param [in] Address Address to the start of the memory range. + @param [in] Size Length of the memory range. + @param [in] State The RIPAS state to be configured. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiSetIpaState ( + IN UINT64 *Address, + IN UINT64 Size, + IN RIPAS State + ) +{ + RETURN_STATUS Status; + UINT64 *BaseAddress; + UINT64 *EndAddress; + ARM_SMC_ARGS SmcCmd; + + if ((Size == 0) || + ((Size & (REALM_GRANULE_SIZE - 1)) != 0) || + (!AddrIsGranuleAligned (Address))) + { + return RETURN_INVALID_PARAMETER; + } + + BaseAddress = Address; + // Divide Size by 8 for the pointer arithmetic + // to work, as we are adding to UINT64*. + EndAddress = Address + (Size >> 3); + + while (Size > 0) { + ZeroMem (&SmcCmd, sizeof (SmcCmd)); + SmcCmd.Arg0 = FID_RSI_IPA_STATE_SET; + SmcCmd.Arg1 = (UINTN)BaseAddress; + SmcCmd.Arg2 = (UINTN)Size; + SmcCmd.Arg3 = (UINTN)State; + + ArmCallSmc (&SmcCmd); + Status = RsiCmdStatusToEfiStatus (SmcCmd.Arg0); + if (RETURN_ERROR (Status)) { + break; + } + + BaseAddress = (UINT64 *)SmcCmd.Arg1; + Size = EndAddress - BaseAddress; + } // while + + return Status; +} + /** Read the Realm Configuration. -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'