From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.80]) by mx.groups.io with SMTP id smtpd.web11.83448.1682438696776121751 for ; Tue, 25 Apr 2023 09:04:57 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=1Dvo/VHk; spf=pass (domain: arm.com, ip: 40.107.7.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=B009P1u/LlyCTYTNiOhGXTYedXP9PGH4DpFgK9FG1hQ=; b=1Dvo/VHkc355L3kZUykLLRM8TcKKp603BI8igPWLcB/YiCC3enPI/Z9+iOjr/hPTY2vo41K4NOUChGSDwVYDKsCx2moFE/gTJGx8QaZQXgxBF+ZWEUz+OLp7mR8jegyReuEMWY6YQ23HZYHjZh7FOLeRFANDllyrSrYn05gcKBw= Received: from DB6PR0402CA0014.eurprd04.prod.outlook.com (2603:10a6:4:91::24) by PAVPR08MB9794.eurprd08.prod.outlook.com (2603:10a6:102:31e::17) 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:51 +0000 Received: from DBAEUR03FT040.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:91:cafe::71) by DB6PR0402CA0014.outlook.office365.com (2603:10a6:4:91::24) 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:51 +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 DBAEUR03FT040.mail.protection.outlook.com (100.127.142.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.20 via Frontend Transport; Tue, 25 Apr 2023 16:04:51 +0000 Received: ("Tessian outbound 8b05220b4215:v136"); Tue, 25 Apr 2023 16:04:51 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: a040f625eff439e2 X-CR-MTA-TID: 64aa7808 Received: from f8c9dccc31ad.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4A9AA680-DA2B-4C77-82E5-EEE2895E4F8A.1; Tue, 25 Apr 2023 16:04:44 +0000 Received: from EUR02-AM0-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f8c9dccc31ad.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 25 Apr 2023 16:04:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UhyPZzJa2pN7CYJdqHdabKOfvunNoSx3JLa/aTSh+qlJgWydbcNZDr5Yz19M7vVeyWmzPsHxeTBQzUoIlyIVnMcBq6EVFP26JjEfenzOkW/Eyo/M6WCvtutWUOjjRnioJJvgHrvoBpPXHS3hwrszCbvM6MWJNHzI/OrGzFqGGJHDkILkx9qvtDQntWa5rBcLH/cz+LB05RwJxI28a3cniRX2/ZUQWY/cok6ppV7HPceahmhb9QnBSbKEuz2ZPf2zwqItgjT/EK5e42ybBjQpJ5M9bIgDMfJ+Qo8Gv/a/xZ96j6C/7wKzProukEgayvCGwZGn1vO++zVCoiKQaph8Pg== 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=B009P1u/LlyCTYTNiOhGXTYedXP9PGH4DpFgK9FG1hQ=; b=imz5Cj1wC/+ICJOKcZVjrb6zG/PrytDue8aB8sLBJ/wJaFMt+/Kb2OaPASuaJ8bwsKGL64f1kHUqvtvIBbDgX2Z9zsfHfjALqAOu2Thze86nVn6C7FGlq1h8ocbtP+SLUqfrmLMz6AsAKBF3bjMtBXTPMrE3LLDwNA3VPIxXbVtNQcZjH8Ozd4oCSU0aX22Ik5FuJp+Wdp/5KY5MiZKqKv3JFIXhQQ9gjZCRexijjzH2TYAPQtC9Smhpel4AUmYNp7OjZLEfHC7bfJcCDt/40gxd9+tj6mZ5KkNgAC/clZmLVd6tDlEfVwNzazURjf4ziI0JsF0uaeu0FIjfQ3QX2w== 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=B009P1u/LlyCTYTNiOhGXTYedXP9PGH4DpFgK9FG1hQ=; b=1Dvo/VHkc355L3kZUykLLRM8TcKKp603BI8igPWLcB/YiCC3enPI/Z9+iOjr/hPTY2vo41K4NOUChGSDwVYDKsCx2moFE/gTJGx8QaZQXgxBF+ZWEUz+OLp7mR8jegyReuEMWY6YQ23HZYHjZh7FOLeRFANDllyrSrYn05gcKBw= Received: from DB7PR05CA0043.eurprd05.prod.outlook.com (2603:10a6:10:2e::20) by PR3PR08MB5577.eurprd08.prod.outlook.com (2603:10a6:102:81::23) 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:41 +0000 Received: from DBAEUR03FT010.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:2e:cafe::52) by DB7PR05CA0043.outlook.office365.com (2603:10a6:10:2e::20) 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:41 +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 DBAEUR03FT010.mail.protection.outlook.com (100.127.142.78) 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:41 +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:39 +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:39 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , , , Subject: [RFC PATCH v1 09/30] ArmVirtPkg: ArmCcaRsiLib: Add interfaces to get/extend REMs Date: Tue, 25 Apr 2023 17:04:07 +0100 Message-ID: <20230425160428.27980-10-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: DBAEUR03FT010:EE_|PR3PR08MB5577:EE_|DBAEUR03FT040:EE_|PAVPR08MB9794:EE_ X-MS-Office365-Filtering-Correlation-Id: 563767d1-b425-4a90-6b80-08db45a6cd98 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: s2Qs9PsjaZnxUTgQF/Bv5tWb0YeubEhoamYaUpp+wrxKQPWdvN08DavqXW4L+OilHFVzzwHnIlzDONa6diApksarxDjjmRr0/NpOIKw0nZcRwGDTe5Vx9e5SKF8ncnWFhafNSePq78hArd8NoRB7GfHKkaTDCjJgzXJfJDBgKO8NxJP6fEglAqhNxFFS7rZ4xH9lZzU1phffMVl2FUpcwDFCyTe7R4wBs1d3drre+Bh7TU86UYXZ5xWtabRYo84cA3neGjyt9BfCV7RA4J53Jtb5HVk7c7YzW74VXQ/Xq4/gStmWA/kSPVVu1+pXKwTvhlCVzhoA8xjsOWpy+vhTmovyz+2YrNzANo8MsWNLd4J0qVNOfrPGakZhDgI2fiul23u3hOgD0u8sqI5RoUbAYu0pFmCRnq17XCfvnc6gFydG67cz7PbEnNTRW98Q9wO/trT/Sv46pIN4/OSJQ2/p6Xxns2EhrNU+cV2n6TUjt7fPpqkyGv368WnATNuv70Ja1sDCxSOoOH2JCpRpTmcoVMV7GvqhNYyIGtvgML8qHYV3oUvJP/Mvf0raz54npUqu87+6q/Nb/SU2ls7kmayF9i+q80GBN+oVwTJvn9OhGWqxSlzlsx8uYt10IH2TEUrwpvCs0K9KpLFKab778REWkBgy8NWpzuVQkKnngYVsvLRSRdjH4bVueteDlnsUyaPi4xcs8qVk7OASA9iJz7XMPXjiRpppG899z1ObTSR/37Q= 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)(376002)(346002)(39860400002)(136003)(396003)(451199021)(46966006)(36840700001)(478600001)(54906003)(86362001)(36756003)(34070700002)(186003)(26005)(82310400005)(1076003)(40480700001)(4326008)(6916009)(316002)(6666004)(82740400003)(44832011)(83380400001)(70206006)(70586007)(36860700001)(2906002)(8676002)(336012)(426003)(356005)(81166007)(41300700001)(7696005)(5660300002)(8936002)(47076005)(2616005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5577 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT040.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: ab1be8eb-2f7d-403d-c723-08db45a6c737 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 75rUFzl15WWjI0W8oVbx1OaYbY5hT0pYkmGi2sHQr2drHCph1qtW+dN4NlpUEVnGf5gJkS483cuGCsZk65r+lNqxXn9rFp4mi03BUPJpQL5pZK9FrVGiCTxoyAK2qgVn8MLKptGOAzNBtzatcthbW7bVORkudcrkVvpTDjB/YXvJZCis9HVc2sYAIwn8YNIWkCikeWteLFHcyW8qC42fUlzu5MPNq/dMU4xrZcjdFtBB0oiYW9UVwS1BMJfQsEEHAGH8xLstpPcsY3Y4aJWFtIa4ZQR7FWxbW1lnpwuVuJzh6Fvc2pl2MOpIRnrh5wtV3DD2AOeTo4ono0lxYS8ce9uv+zSxiDoHpWb/f1+COQHMORe7sMZqLu9K8Ee2WAs5HPpX+nDamtFB+3mhn19HGWrcB5HG3ooq/vcq2VdxvyNfurCES/X2m62D8oLHezaTiqydLnNbkrvfpxDkxtewERfrqC1j9uJwJWM497WHxkspOf4dK2uG9/7wWQ4A2v4CZR4vNUzvo9oCW21cNbXCKZkkQLElOdVmST3y82SMBxUlJYLG9+mgE7yekEKP6WDe4dwYEzfneaL4zNFq3hjgVClDRodhc1tTQDmxVdN/uq8bNyr9VrcFneCZS/y4gUTFq5lV32mUR17duG+M1kfdXu1A2P5/TqiF53v48ZlRto/glvd0WVxTw6KysOZvDy89M9b9BWR2ovlrsP02/I7nEEzp2eWVSOxITLsKa66cyi4= 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)(376002)(346002)(396003)(136003)(39860400002)(451199021)(40470700004)(36840700001)(46966006)(36756003)(8676002)(8936002)(54906003)(40460700003)(34070700002)(478600001)(70586007)(6916009)(4326008)(70206006)(40480700001)(81166007)(44832011)(316002)(41300700001)(82740400003)(2906002)(5660300002)(2616005)(86362001)(36860700001)(186003)(336012)(426003)(26005)(1076003)(7696005)(6666004)(83380400001)(47076005)(82310400005);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2023 16:04:51.9106 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 563767d1-b425-4a90-6b80-08db45a6cd98 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: DBAEUR03FT040.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9794 Content-Type: text/plain The Section A2.1.3 Realm attributes, RMM Specification, version A-bet0 introduces the concept of REMs as described below: DGRFCS - A Realm Extensible Measurement (REM) is a measurement value which can be extended during the lifetime of a Realm. IFMPYL - Attributes of a Realm include an array of measurement values. The first entry in this array is a RIM. The remaining entries in this array are REMs. The Realm Service Interface commands defined in section B4.3.7 RSI_MEASUREMENT_READ and B4.3.6 RSI_MEASUREMENT_EXTEND specify the interfaces to read and extend measurements to REMs. Therefore, update ArmCcaRsiLib to add interfaces to get and extend REMs. Signed-off-by: Sami Mujawar --- ArmVirtPkg/Include/Library/ArmCcaRsiLib.h | 53 ++++++++++++ ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h | 2 + ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c | 91 ++++++++++++++++++++ 3 files changed, 146 insertions(+) diff --git a/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h b/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h index fe176d83c4b11d3f7bb35c97ec8ef00a4f47f981..51527071ab87aa82efa9ddc3064bb88803d5ba13 100644 --- a/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h +++ b/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h @@ -7,6 +7,8 @@ - Rsi or RSI - Realm Service Interface - IPA - Intermediate Physical Address - RIPAS - Realm IPA state + - RIM - Realm Initial Measurement + - REM - Realm Extensible Measurement @par Reference(s): - Realm Management Monitor (RMM) Specification, version A-bet0 @@ -44,6 +46,21 @@ */ #define MIN_CHALLENGE_DATA_SIZE_BITS 256 +/* Maximum measurement data size in bytes. + See Section C1.11 RmmRealmMeasurement type, RMM Specification, version A-bet0 + The width of the RmmRealmMeasurement type is 512 bits. +*/ +#define MAX_MEASUREMENT_DATA_SIZE_BYTES 64 + +/* Minimum and Maximum indices for REMs + See Section A2.1.3 Realm attributes, RMM Specification, version A-bet0 + IFMPYL - Attributes of a Realm include an array of measurement values. The + first entry in this array is a RIM. The remaining entries in this array are + REMs. +*/ +#define MIN_REM_INDEX 1 +#define MAX_REM_INDEX 4 + /** An enum describing the RSI RIPAS. See Section A5.2.2 Realm IPA state, RMM Specification, version A-bet0 */ @@ -127,6 +144,42 @@ RsiSetIpaState ( IN RIPAS State ); +/** + Extends a measurement to a REM. + + @param [in] MeasurementIndex Index of the REM. + @param [in] Measurement Pointer to the measurement buffer. + @param [in] MeasurementSize Size of the measurement data. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiExtendMeasurement ( + IN UINTN MeasurementIndex, + IN CONST UINT8 *CONST Measurement, + IN UINTN MeasurementSize + ); + +/** + Read the measurement value from a REM. + + @param [in] MeasurementIndex Index of the REM. + @param [out] MeasurementBuffer Pointer to store the measurement data. + @param [in] MeasurementBufferSize Size of the measurement buffer. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiReadMeasurement ( + IN UINTN MeasurementIndex, + OUT UINT8 *CONST MeasurementBuffer, + IN UINTN MeasurementBufferSize + ); + /** Read the Realm Configuration. diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h index 325234d06695befc840dcf37e951130dfe0550c3..6f0ee3061ade5a4a99b717a52d5a241e0e446270 100644 --- a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h @@ -22,6 +22,8 @@ #define FID_RSI_ATTESTATION_TOKEN_INIT 0xC4000194 #define FID_RSI_IPA_STATE_GET 0xC4000198 #define FID_RSI_IPA_STATE_SET 0xC4000197 +#define FID_RSI_MEASUREMENT_EXTEND 0xC4000193 +#define FID_RSI_MEASUREMENT_READ 0xC4000192 #define FID_RSI_REALM_CONFIG 0xC4000196 #define FID_RSI_VERSION 0xC4000190 diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c index 01ecee3a6798c0e5cefd9fb4f48788d3063c94cd..fd29fc61caf880bcaf96d982f3a4d973e7ebb70f 100644 --- a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c @@ -8,6 +8,7 @@ - Rsi or RSI - Realm Service Interface - IPA - Intermediate Physical Address - RIPAS - Realm IPA state + - REM - Realm Extensible Measurement @par Reference(s): - Realm Management Monitor (RMM) Specification, version A-bet0 @@ -366,6 +367,96 @@ RsiSetIpaState ( return Status; } +/** + Extends a measurement to a REM. + + @param [in] MeasurementIndex Index of the REM. + @param [in] Measurement Pointer to the measurement buffer. + @param [in] MeasurementSize Size of the measurement data. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiExtendMeasurement ( + IN UINTN MeasurementIndex, + IN CONST UINT8 *CONST Measurement, + IN UINTN MeasurementSize + ) +{ + ARM_SMC_ARGS SmcCmd; + UINT64 *Data64; + + if ((MeasurementIndex < MIN_REM_INDEX) || + (MeasurementIndex > MAX_REM_INDEX) || + (Measurement == NULL) || + (MeasurementSize == 0) || + (MeasurementSize > MAX_MEASUREMENT_DATA_SIZE_BYTES)) + { + return RETURN_INVALID_PARAMETER; + } + + ZeroMem (&SmcCmd, sizeof (SmcCmd)); + + SmcCmd.Arg0 = FID_RSI_MEASUREMENT_EXTEND; + SmcCmd.Arg1 = MeasurementIndex; + SmcCmd.Arg2 = MeasurementSize; + + Data64 = &SmcCmd.Arg3; + CopyMem (Data64, Measurement, MeasurementSize); + + ArmCallSmc (&SmcCmd); + return RsiCmdStatusToEfiStatus (SmcCmd.Arg0); +} + +/** + Read the measurement value from a REM. + + @param [in] MeasurementIndex Index of the REM. + @param [out] MeasurementBuffer Pointer to store the measurement data. + @param [in] MeasurementBufferSize Size of the measurement buffer. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiReadMeasurement ( + IN UINTN MeasurementIndex, + OUT UINT8 *CONST MeasurementBuffer, + IN UINTN MeasurementBufferSize + ) +{ + RETURN_STATUS Status; + ARM_SMC_ARGS SmcCmd; + UINT64 *Data64; + + if ((MeasurementIndex < MIN_REM_INDEX) || + (MeasurementIndex > MAX_REM_INDEX) || + (MeasurementBuffer == NULL)) + { + return RETURN_INVALID_PARAMETER; + } + + if (MeasurementBufferSize < MAX_MEASUREMENT_DATA_SIZE_BYTES) { + return RETURN_BUFFER_TOO_SMALL; + } + + ZeroMem (&SmcCmd, sizeof (SmcCmd)); + SmcCmd.Arg0 = FID_RSI_MEASUREMENT_READ; + SmcCmd.Arg1 = MeasurementIndex; + + ArmCallSmc (&SmcCmd); + Status = RsiCmdStatusToEfiStatus (SmcCmd.Arg0); + if (!RETURN_ERROR (Status)) { + Data64 = &SmcCmd.Arg1; + CopyMem (MeasurementBuffer, Data64, MAX_MEASUREMENT_DATA_SIZE_BYTES); + } + + return Status; +} + /** Read the Realm Configuration. -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'