[RFC PATCH v1 29/38] coco: guest: arm64: Add support for collecting interface reports

Aneesh Kumar K.V (Arm)
2025-07-28T13:55:29Z

Support collecting interface reports using RSI calls.

Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
arch/arm64/include/asm/rsi_cmds.h | 14 ++++++++++
arch/arm64/include/asm/rsi_smc.h | 2 ++
drivers/virt/coco/arm-cca-guest/rsi-da.c | 34 ++++++++++++++++++++++++
3 files changed, 50 insertions(+)

diff --git a/arch/arm64/include/asm/rsi_cmds.h b/arch/arm64/include/asm/rsi_cmds.h
index b9c4b8ff5631..1d76f7d37cb6 100644
--- a/arch/arm64/include/asm/rsi_cmds.h
+++ b/arch/arm64/include/asm/rsi_cmds.h
@@ -205,4 +205,18 @@ static inline unsigned long rsi_rdev_continue(unsigned long vdev_id, unsigned lo
return res.a0;
}

+static inline unsigned long __rsi_rdev_get_interface_report(unsigned long vdev_id,
+ unsigned long inst_id,
+ unsigned long version_max,
+ unsigned long *version)
+{
+ struct arm_smccc_res res;
+
+ arm_smccc_1_1_invoke(SMC_RSI_RDEV_GET_INTERFACE_REPORT,
+ vdev_id, inst_id, version_max, &res);
+
+ *version = res.a1;
+ return res.a0;
+}
+
#endif /* __ASM_RSI_CMDS_H */
diff --git a/arch/arm64/include/asm/rsi_smc.h b/arch/arm64/include/asm/rsi_smc.h
index 44b583ab6d67..6afcccee2ae7 100644
--- a/arch/arm64/include/asm/rsi_smc.h
+++ b/arch/arm64/include/asm/rsi_smc.h
@@ -194,6 +194,8 @@ struct realm_config {
#define SMC_RSI_RDEV_GET_INSTANCE_ID SMC_RSI_FID(0x19c)
#define SMC_RSI_RDEV_CONTINUE SMC_RSI_FID(0x1a4)

+#define SMC_RSI_RDEV_GET_INTERFACE_REPORT SMC_RSI_FID(0x1a6)
+
#define SMC_RSI_RDEV_LOCK SMC_RSI_FID(0x1a9)

#endif /* __ASM_RSI_SMC_H_ */
diff --git a/drivers/virt/coco/arm-cca-guest/rsi-da.c b/drivers/virt/coco/arm-cca-guest/rsi-da.c
index 097cf52ee199..28ec946df1e2 100644
--- a/drivers/virt/coco/arm-cca-guest/rsi-da.c
+++ b/drivers/virt/coco/arm-cca-guest/rsi-da.c
@@ -29,9 +29,31 @@ static inline unsigned long rsi_rdev_lock(struct pci_dev *pdev,
return RSI_SUCCESS;
}

+static inline unsigned long
+rsi_rdev_get_interface_report(struct pci_dev *pdev, unsigned long vdev_id,
+ unsigned long inst_id, unsigned long version_max,
+ unsigned long *version)
+{
+ unsigned long ret;
+
+ ret = __rsi_rdev_get_interface_report(vdev_id, inst_id, version_max, version);
+ if (ret != RSI_SUCCESS)
+ return ret;
+
+ do {
+ ret = rsi_rdev_continue(vdev_id, inst_id);
+ } while (ret == RSI_INCOMPLETE);
+ if (ret != RSI_SUCCESS) {
+ pci_err(pdev, "failed to communicate with the device (%lu)\n", ret);
+ return ret;
+ }
+ return RSI_SUCCESS;
+}
+
int rsi_device_lock(struct pci_dev *pdev)
{
unsigned long ret;
+ unsigned long tdisp_version;
struct cca_guest_dsc *dsm = to_cca_guest_dsc(pdev);
int vdev_id = (pci_domain_nr(pdev->bus) << 16) |
PCI_DEVID(pdev->bus->number, pdev->devfn);
@@ -48,5 +70,17 @@ int rsi_device_lock(struct pci_dev *pdev)
return -EIO;
}

+ ret = rsi_rdev_get_interface_report(pdev, vdev_id, dsm->instance_id,
+ PCI_TDISP_MESSAGE_VERSION_10, &tdisp_version);
+ if (ret != RSI_SUCCESS) {
+ pci_err(pdev, "failed to get interface report (%lu)\n", ret);
+ return -EIO;
+ }
+
+ if (tdisp_version != PCI_TDISP_MESSAGE_VERSION_10) {
+ pci_err(pdev, "unknown TDISP version (%lu)\n", tdisp_version);
+ return -EOPNOTSUPP;
+ }
+
return ret;
}
--
2.43.0