[PATCH RFC 3/5] optee: riscv: enable persistent shared argument cache
From: Amirreza Zarrabi
Date: Sat Sep 12 2026 - 06:17:50 EST
Use the OP-TEE shared argument cache when secure world advertises
OPTEE_ABI_SEC_CAP_ARG_OFFSET.
In this mode the argument structure can reside at an offset within an
already registered parcel-backed shared-memory buffer, allowing the same
buffer to be reused across calls instead of creating and reclaiming a
parcel for each call.
Signed-off-by: Amirreza Zarrabi <amirreza.zarrabi@xxxxxxxxxxxxxxxx>
---
drivers/tee/optee/optee_riscv.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/tee/optee/optee_riscv.c b/drivers/tee/optee/optee_riscv.c
index 36115326486d..72c9eb85f4fe 100644
--- a/drivers/tee/optee/optee_riscv.c
+++ b/drivers/tee/optee/optee_riscv.c
@@ -1149,6 +1149,7 @@ static int optee_riscv_probe(struct platform_device *pdev)
struct tee_device *teedev;
struct tee_context *ctx;
struct mbox_client *client;
+ u32 arg_cache_flags = 0;
struct optee *optee;
u32 sec_caps;
unsigned int nr_cpus;
@@ -1219,6 +1220,15 @@ static int optee_riscv_probe(struct platform_device *pdev)
goto err_free_channels;
}
+ /*
+ * If OP-TEE can read the argument struct from an offset into a shared
+ * memory buffer, cache and reuse one buffer across calls instead of
+ * creating a fresh parcel per call. This is the persistent pool that
+ * matches the FF-A OPTEE_FFA_SEC_CAP_ARG_OFFSET path.
+ */
+ if (sec_caps & OPTEE_ABI_SEC_CAP_ARG_OFFSET)
+ arg_cache_flags |= OPTEE_SHM_ARG_SHARED;
+
pool = optee_riscv_shm_pool_alloc_pages();
if (IS_ERR(pool)) {
rc = PTR_ERR(pool);
@@ -1266,7 +1276,7 @@ static int optee_riscv_probe(struct platform_device *pdev)
atomic_set(&optee->riscv.next_nonce, 0);
optee_cq_init(&optee->call_queue, 0);
optee_supp_init(&optee->supp);
- optee_shm_arg_cache_init(optee, 0);
+ optee_shm_arg_cache_init(optee, arg_cache_flags);
mutex_init(&optee->rpmb_dev_mutex);
platform_set_drvdata(pdev, optee);
--
2.34.1