[PATCH 7/8] arm_ffa: sandbox: Add FFA_MEM_RECLAIM emulation

abdellatif.elkhlifi
2024-11-01T14:21:56Z

Add FFA_MEM_RECLAIM support to the FF-A emulator

Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
---
drivers/firmware/arm-ffa/ffa-emul-uclass.c | 43 ++++++++++++++++++++++
drivers/firmware/arm-ffa/sandbox_ffa.c | 1 +
2 files changed, 44 insertions(+)

diff --git a/drivers/firmware/arm-ffa/ffa-emul-uclass.c b/drivers/firmware/arm-ffa/ffa-emul-uclass.c
index a859d2e26cc..b628e2c5c63 100644
--- a/drivers/firmware/arm-ffa/ffa-emul-uclass.c
+++ b/drivers/firmware/arm-ffa/ffa-emul-uclass.c
@@ -604,6 +604,46 @@ feedback:
return ret;
}

+/**
+ * sandbox_ffa_memory_reclaim() - Emulated FFA_MEM_RECLAIM handler
+ * @emul: The sandbox FF-A emulator device
+ * @pargs: The SMC call input arguments a0-a7
+ * @res: The SMC return data
+ *
+ * Emulate FFA_MEM_RECLAIM FF-A function.
+ *
+ * Return:
+ *
+ * 0 on success. Otherwise, failure
+ */
+static int sandbox_ffa_memory_reclaim(struct udevice *emul, ffa_value_t *pargs,
+ ffa_value_t *res)
+{
+ int ret;
+
+ if (pargs->a1 != SANDBOX_MEM_HANDLE ||
+ pargs->a2 != SANDBOX_MEM_HANDLE) {
+ res->a0 = FFA_SMC_32(FFA_ERROR);
+ res->a2 = -INVALID_PARAMETERS;
+ ret = ffa_to_std_errmap[INVALID_PARAMETERS];
+ goto feedback;
+ }
+
+ res->a0 = FFA_SMC_32(FFA_SUCCESS);
+ res->a2 = 0;
+ ret = 0;
+
+feedback:
+
+ res->a1 = 0;
+ res->a3 = 0;
+
+ /* x4-x7 MBZ */
+ memset(FFA_X4X7_MBZ_REG_START, 0, FFA_X4X7_MBZ_CNT * sizeof(ulong));
+
+ return ret;
+}
+
/**
* sandbox_query_ffa_emul_state() - Inspect the FF-A ABIs
* @queried_func_id: The FF-A function to be queried
@@ -697,6 +737,9 @@ void sandbox_arm_ffa_smccc_smc(ffa_value_t *args, ffa_value_t *res)
case FFA_SMC_32(FFA_MEM_SHARE):
ret = sandbox_ffa_memory_share(emul, args, res);
break;
+ case FFA_SMC_32(FFA_MEM_RECLAIM):
+ ret = sandbox_ffa_memory_reclaim(emul, args, res);
+ break;
default:
log_err("Undefined FF-A interface (%lx)\n",
args->a0);
diff --git a/drivers/firmware/arm-ffa/sandbox_ffa.c b/drivers/firmware/arm-ffa/sandbox_ffa.c
index a81455ce5ff..8af9c8ac005 100644
--- a/drivers/firmware/arm-ffa/sandbox_ffa.c
+++ b/drivers/firmware/arm-ffa/sandbox_ffa.c
@@ -92,6 +92,7 @@ static const struct ffa_bus_ops sandbox_ffa_ops = {
.sync_send_receive = ffa_msg_send_direct_req_hdlr,
.rxtx_unmap = ffa_unmap_rxtx_buffers_hdlr,
.memory_share = ffa_memory_share_hdlr,
+ .memory_reclaim = ffa_memory_reclaim_hdlr,
};

static const struct udevice_id sandbox_ffa_id[] = {
--
2.25.1