blob: 2c1623ac745c95f96c5d83d3848813b5624049e7 [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001From e67cd78142984c7c4120f15ef14e1e026746af5a Mon Sep 17 00:00:00 2001
2From: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
3Date: Thu, 3 Feb 2022 11:19:38 +0000
4Subject: [PATCH 30/32] ANDROID: trusty-ffa: Enable FFA transport for both
5 memory and message ops
6
7Adds new API version TRUSTY_API_VERSION_FFA and sets this as current
8API version.
9
10If Trusty on the secure side supports receipt of FFA direct request,
11then trusty core uses FFA calls for messages and memory operations.
12
13Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
14Change-Id: I4a8b060f906a96935a7df10713026fb543e2b9a7
15Upstream-Status: Pending [Not submitted to upstream yet]
16---
17 drivers/trusty/trusty-ffa.c | 58 +++++++++++++++++++++++++++++++++++
18 drivers/trusty/trusty.c | 3 ++
19 include/linux/trusty/smcall.h | 3 +-
20 3 files changed, 63 insertions(+), 1 deletion(-)
21
22diff --git a/drivers/trusty/trusty-ffa.c b/drivers/trusty/trusty-ffa.c
23index 0655b3887b52..543f5a0d31cb 100644
24--- a/drivers/trusty/trusty-ffa.c
25+++ b/drivers/trusty/trusty-ffa.c
26@@ -15,6 +15,36 @@
27 #include "trusty-ffa.h"
28 #include "trusty-private.h"
29
30+/* partition property: Supports receipt of direct requests */
31+#define FFA_PARTITION_DIRECT_REQ_RECV BIT(0)
32+
33+/* string representation of trusty UUID used for partition info get call */
34+static const char *trusty_uuid = "40ee25f0-a2bc-304c-8c4c-a173c57d8af1";
35+
36+static u32 trusty_ffa_send_direct_msg(struct device *dev, unsigned long fid,
37+ unsigned long a0, unsigned long a1,
38+ unsigned long a2)
39+{
40+ struct trusty_state *s = platform_get_drvdata(to_platform_device(dev));
41+ struct ffa_send_direct_data ffa_msg;
42+ struct ffa_device *ffa_dev;
43+ int ret;
44+
45+ ffa_dev = to_ffa_dev(s->ffa->dev);
46+
47+ ffa_msg.data0 = fid;
48+ ffa_msg.data1 = a0;
49+ ffa_msg.data2 = a1;
50+ ffa_msg.data3 = a2;
51+ ffa_msg.data4 = 0;
52+
53+ ret = s->ffa->ops->sync_send_receive(ffa_dev, &ffa_msg);
54+ if (!ret)
55+ return ffa_msg.data0;
56+
57+ return ret;
58+}
59+
60 static int __trusty_ffa_share_memory(struct device *dev, u64 *id,
61 struct scatterlist *sglist,
62 unsigned int nents, pgprot_t pgprot,
63@@ -114,6 +144,11 @@ static int trusty_ffa_reclaim_memory(struct device *dev, u64 id,
64 return 0;
65 }
66
67+static const struct trusty_msg_ops trusty_ffa_msg_ops = {
68+ .desc = &trusty_ffa_transport,
69+ .send_direct_msg = &trusty_ffa_send_direct_msg,
70+};
71+
72 static const struct trusty_mem_ops trusty_ffa_mem_ops = {
73 .desc = &trusty_ffa_transport,
74 .trusty_share_memory = &trusty_ffa_share_memory,
75@@ -181,6 +216,7 @@ static int trusty_ffa_transport_setup(struct device *dev)
76 struct trusty_state *s = platform_get_drvdata(to_platform_device(dev));
77 struct trusty_ffa_state *ffa_state;
78 struct ffa_device *ffa_dev;
79+ struct ffa_partition_info pinfo = { 0 };
80
81 /* ffa transport not required for lower api versions */
82 if (s->api_version != 0 && s->api_version < TRUSTY_API_VERSION_MEM_OBJ) {
83@@ -208,6 +244,28 @@ static int trusty_ffa_transport_setup(struct device *dev)
84 return 0;
85 }
86
87+ /* check if Trusty partition can support receipt of direct requests. */
88+ rc = ffa_state->ops->partition_info_get(trusty_uuid, &pinfo);
89+ if (rc || !(pinfo.properties & FFA_PARTITION_DIRECT_REQ_RECV)) {
90+ dev_err(ffa_state->dev, "trusty_ffa_pinfo: ret: 0x%x, prop: 0x%x\n",
91+ rc, pinfo.properties);
92+ return -EINVAL;
93+ }
94+
95+ /* query and check Trusty API version */
96+ s->ffa = ffa_state;
97+ rc = trusty_init_api_version(s, dev, trusty_ffa_send_direct_msg);
98+ if (rc) {
99+ s->ffa = NULL;
100+ return -EINVAL;
101+ }
102+
103+ if (s->api_version == TRUSTY_API_VERSION_FFA) {
104+ s->msg_ops = &trusty_ffa_msg_ops;
105+ s->mem_ops = &trusty_ffa_mem_ops;
106+ return 0;
107+ }
108+
109 return -EINVAL;
110 }
111
112diff --git a/drivers/trusty/trusty.c b/drivers/trusty/trusty.c
113index f91c255c9897..66273873f169 100644
114--- a/drivers/trusty/trusty.c
115+++ b/drivers/trusty/trusty.c
116@@ -679,6 +679,9 @@ static int trusty_remove(struct platform_device *pdev)
117 * trusty_smc_transport used for messaging.
118 * trusty_ffa_transport used for memory sharing.
119 *
120+ * For Trusty API version > TRUSTY_API_VERSION_MEM_OBJ:
121+ * trusty_ffa_transport used for messaging and memory sharing operations.
122+ *
123 */
124 static const trusty_transports_t trusty_transports[] = {
125 &trusty_smc_transport,
126diff --git a/include/linux/trusty/smcall.h b/include/linux/trusty/smcall.h
127index aea3f6068593..17b3d1c2c4f6 100644
128--- a/include/linux/trusty/smcall.h
129+++ b/include/linux/trusty/smcall.h
130@@ -109,7 +109,8 @@
131 #define TRUSTY_API_VERSION_SMP_NOP (3)
132 #define TRUSTY_API_VERSION_PHYS_MEM_OBJ (4)
133 #define TRUSTY_API_VERSION_MEM_OBJ (5)
134-#define TRUSTY_API_VERSION_CURRENT (5)
135+#define TRUSTY_API_VERSION_FFA (6)
136+#define TRUSTY_API_VERSION_CURRENT (6)
137 #define SMC_FC_API_VERSION SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 11)
138
139 /* TRUSTED_OS entity calls */
140--
1412.30.2
142