[PATCH 1/3] arm64: rsi: Add helpers for Arm CCA measurement register operations

Sami Mujawar
2026-04-13T08:52:50Z

Add static inline helper functions to support reading the Realm
Initial Measurement (RIM) and reading/extending the Realm
Extensible Measurement (REM) registers.

The indices of the Arm CCA measurement registers, as defined by
the Realm Management Monitor specification, are as follows:
Index Register
0 RIM
1 - 4 REM[0 - 3]

The rsi_measurement_extend() function allows extending REM[0–3]
registers with a caller-provided digest (up to 64 bytes).
Index 0 (RIM) is read-only and cannot be extended.

The rsi_measurement_read() function allows reading measurement
values from RIM (index 0) or REM[0–3] (indices 1–4). The returned
digest is expected to be 64 bytes.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
arch/arm64/include/asm/rsi_cmds.h | 105 +++++++++++++++++++++++++++++-
1 file changed, 104 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/rsi_cmds.h b/arch/arm64/include/asm/rsi_cmds.h
index 2c8763876dfb..cfd9bff88147 100644
--- a/arch/arm64/include/asm/rsi_cmds.h
+++ b/arch/arm64/include/asm/rsi_cmds.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
- * Copyright (C) 2023 ARM Ltd.
+ * Copyright (C) 2023 - 2025 ARM Ltd.
*/

#ifndef __ASM_RSI_CMDS_H
@@ -15,6 +15,26 @@
#define RSI_GRANULE_SHIFT 12
#define RSI_GRANULE_SIZE (_AC(1, UL) << RSI_GRANULE_SHIFT)

+/*
+ * Maximum measurement data size in bytes.
+ * According to the RMM Specification, the width of the RmmRealmMeasurement type
+ * is 512 bits.
+ */
+#define RSI_MAX_MEASUREMENT_DATA_SIZE_BYTES 64
+
+/*
+ * Indices for the Realm Initial Measurement register (RIM) and the Realm
+ * Extensible Measurement registers (REMs).
+ * According to the RMM Specification, Realm 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 RSI_INDEX_RIM 0
+#define RSI_INDEX_REM0 1
+#define RSI_INDEX_REM1 2
+#define RSI_INDEX_REM2 3
+#define RSI_INDEX_REM3 4
+
enum ripas {
RSI_RIPAS_EMPTY = 0,
RSI_RIPAS_RAM = 1,
@@ -159,4 +179,87 @@ static inline unsigned long rsi_attestation_token_continue(phys_addr_t granule,
return res.a0;
}

+/**
+ * rsi_measurement_extend - Extend the measurement value to the Realm Extensible
+ * Measurement (REM).
+ *
+ * @idx: Index of the REM register.
+ * Where:
+ * Index Register
+ * 1 - 4 REM[0-3]
+ * @digest: The digest data to be extended.
+ * @digest_size: Size of the digest data in bytes.
+ *
+ * Returns:
+ * On success, returns RSI_SUCCESS.
+ * Otherwise, -EINVAL
+ */
+static inline unsigned long rsi_measurement_extend(u32 idx,
+ const u8 *digest,
+ unsigned long digest_size)
+{
+ struct arm_smccc_1_2_regs regs = { 0 };
+
+ /*
+ * Index 0 is for RIM (which is Read Only), while
+ * REM[0-3] are indexed from 1 - 4.
+ * The digest size can be at the most 64 bytes.
+ */
+ if (!digest || idx < RSI_INDEX_REM0 || idx > RSI_INDEX_REM3 ||
+ digest_size == 0 || digest_size > RSI_MAX_MEASUREMENT_DATA_SIZE_BYTES)
+ return -EINVAL;
+
+ regs.a0 = SMC_RSI_MEASUREMENT_EXTEND;
+ regs.a1 = idx;
+ regs.a2 = digest_size;
+ memcpy(&regs.a3, digest, digest_size);
+ arm_smccc_1_2_smc(&regs, &regs);
+
+ if (regs.a0 != RSI_SUCCESS)
+ return -EINVAL;
+
+ return regs.a0;
+}
+
+/**
+ * rsi_measurement_read - Read the measurement value from the Realm Initial
+ * Measurement (RIM) or the Realm Extensible Measurement (REM) register.
+ *
+ * @idx: Index of the RIM or REM register.
+ * Where:
+ * Index Register
+ * 0 RIM
+ * 1 - 4 REM[0-3]
+ * @digest: The digest data to be returned.
+ * @digest_size: Size of the digest data buffer in bytes.
+ *
+ * Returns:
+ * On success, returns RSI_SUCCESS.
+ * Otherwise, -EINVAL
+ */
+static inline unsigned long rsi_measurement_read(u32 idx,
+ u8 *digest,
+ unsigned long digest_size)
+{
+ struct arm_smccc_1_2_regs regs = { 0 };
+
+ /*
+ * The digest size can be at the most 64 bytes, if less then 64 bytes
+ * it is zero padded.
+ */
+ if (!digest || idx > RSI_INDEX_REM3 ||
+ digest_size == 0 || digest_size > RSI_MAX_MEASUREMENT_DATA_SIZE_BYTES)
+ return -EINVAL;
+
+ regs.a0 = SMC_RSI_MEASUREMENT_READ;
+ regs.a1 = idx;
+ arm_smccc_1_2_smc(&regs, &regs);
+
+ if (regs.a0 != RSI_SUCCESS)
+ return -EINVAL;
+
+ memcpy(digest, &regs.a1, digest_size);
+ return regs.a0;
+}
+
#endif /* __ASM_RSI_CMDS_H */
--
SAMI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}