blob: a7bc06004eb38e4a27677fbb1f0cc6b8b4798a60 [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001From 804ef860d9757cbe31b606fd5ec68cc5454c88f8 Mon Sep 17 00:00:00 2001
2From: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
3Date: Tue, 18 Jan 2022 18:27:09 +0000
4Subject: [PATCH 24/32] ANDROID: trusty: Rename transfer memory function to
5 lend memory
6
7Renaming trusty_transfer_memory to trusty_lend_memory allows Trusty
8to export memory operation like share, lend, reclaim and use common
9code for memory share and lend operations.
10
11Define TRUSTY_DEFAULT_MEM_OBJ_TAG as 0 and use that in existing calls.
12
13Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
14Change-Id: Ie165a609cc4398bb916967595d0b748d54d75faf
15Upstream-Status: Pending [Not submitted to upstream yet]
16---
17 drivers/trusty/trusty-ipc.c | 14 ++++++++----
18 drivers/trusty/trusty-test.c | 3 ++-
19 drivers/trusty/trusty-virtio.c | 3 ++-
20 drivers/trusty/trusty.c | 41 ++++++++++++++++++++++------------
21 include/linux/trusty/trusty.h | 11 ++++-----
22 5 files changed, 47 insertions(+), 25 deletions(-)
23
24diff --git a/drivers/trusty/trusty-ipc.c b/drivers/trusty/trusty-ipc.c
25index 82d6ddeb41f4..0a27af2063a7 100644
26--- a/drivers/trusty/trusty-ipc.c
27+++ b/drivers/trusty/trusty-ipc.c
28@@ -1233,10 +1233,16 @@ static int dn_share_fd(struct tipc_dn_chan *dn, int fd,
29 goto cleanup_handle;
30 }
31
32- ret = trusty_transfer_memory(tipc_shared_handle_dev(shared_handle),
33- &mem_id, shared_handle->sgt->sgl,
34- shared_handle->sgt->orig_nents, prot, tag,
35- lend);
36+ if (lend)
37+ ret = trusty_lend_memory(tipc_shared_handle_dev(shared_handle),
38+ &mem_id, shared_handle->sgt->sgl,
39+ shared_handle->sgt->orig_nents, prot,
40+ tag);
41+ else
42+ ret = trusty_share_memory(tipc_shared_handle_dev(shared_handle),
43+ &mem_id, shared_handle->sgt->sgl,
44+ shared_handle->sgt->orig_nents, prot,
45+ tag);
46
47 if (ret < 0) {
48 dev_dbg(dev, "Transferring memory failed: %d\n", ret);
49diff --git a/drivers/trusty/trusty-test.c b/drivers/trusty/trusty-test.c
50index 844868981fa5..c25fc0f2fcf0 100644
51--- a/drivers/trusty/trusty-test.c
52+++ b/drivers/trusty/trusty-test.c
53@@ -138,7 +138,8 @@ static int trusty_test_share_objs(struct trusty_test_state *s,
54 t1 = ktime_get();
55 tmpret = trusty_share_memory(s->trusty_dev, &obj->mem_id,
56 obj->sgt.sgl, obj->sgt.nents,
57- PAGE_KERNEL);
58+ PAGE_KERNEL,
59+ TRUSTY_DEFAULT_MEM_OBJ_TAG);
60 t2 = ktime_get();
61 if (tmpret) {
62 ret = tmpret;
63diff --git a/drivers/trusty/trusty-virtio.c b/drivers/trusty/trusty-virtio.c
64index fea59cd2e218..365e7c04bcf4 100644
65--- a/drivers/trusty/trusty-virtio.c
66+++ b/drivers/trusty/trusty-virtio.c
67@@ -626,7 +626,8 @@ static int trusty_virtio_add_devices(struct trusty_ctx *tctx)
68
69 sg_init_one(&tctx->shared_sg, descr_va, descr_buf_sz);
70 ret = trusty_share_memory(tctx->dev->parent, &descr_id,
71- &tctx->shared_sg, 1, PAGE_KERNEL);
72+ &tctx->shared_sg, 1, PAGE_KERNEL,
73+ TRUSTY_DEFAULT_MEM_OBJ_TAG);
74 if (ret) {
75 dev_err(tctx->dev, "trusty_share_memory failed: %d\n", ret);
76 goto err_share_memory;
77diff --git a/drivers/trusty/trusty.c b/drivers/trusty/trusty.c
78index 2dec75398f69..6bd30bc1bbc9 100644
79--- a/drivers/trusty/trusty.c
80+++ b/drivers/trusty/trusty.c
81@@ -222,18 +222,9 @@ s32 trusty_std_call32(struct device *dev, u32 smcnr, u32 a0, u32 a1, u32 a2)
82 }
83 EXPORT_SYMBOL(trusty_std_call32);
84
85-int trusty_share_memory(struct device *dev, u64 *id,
86- struct scatterlist *sglist, unsigned int nents,
87- pgprot_t pgprot)
88-{
89- return trusty_transfer_memory(dev, id, sglist, nents, pgprot, 0,
90- false);
91-}
92-EXPORT_SYMBOL(trusty_share_memory);
93-
94-int trusty_transfer_memory(struct device *dev, u64 *id,
95- struct scatterlist *sglist, unsigned int nents,
96- pgprot_t pgprot, u64 tag, bool lend)
97+static int __trusty_share_memory(struct device *dev, u64 *id,
98+ struct scatterlist *sglist, unsigned int nents,
99+ pgprot_t pgprot, u64 tag, bool mem_share)
100 {
101 struct trusty_state *s = platform_get_drvdata(to_platform_device(dev));
102 int ret;
103@@ -253,6 +244,12 @@ int trusty_transfer_memory(struct device *dev, u64 *id,
104 return -EOPNOTSUPP;
105 }
106
107+ if (mem_share == false && s->api_version < TRUSTY_API_VERSION_MEM_OBJ) {
108+ dev_err(s->dev, "%s: old trusty version does not support lending memory objects\n",
109+ __func__);
110+ return -EOPNOTSUPP;
111+ }
112+
113 count = dma_map_sg(dev, sglist, nents, DMA_BIDIRECTIONAL);
114 if (count != nents) {
115 dev_err(s->dev, "failed to dma map sg_table\n");
116@@ -271,7 +268,22 @@ int trusty_transfer_memory(struct device *dev, u64 *id,
117 *id = pg_inf.compat_attr;
118 return 0;
119 }
120-EXPORT_SYMBOL(trusty_transfer_memory);
121+
122+int trusty_share_memory(struct device *dev, u64 *id,
123+ struct scatterlist *sglist, unsigned int nents,
124+ pgprot_t pgprot, u64 tag)
125+{
126+ return __trusty_share_memory(dev, id, sglist, nents, pgprot, tag, true);
127+}
128+EXPORT_SYMBOL(trusty_share_memory);
129+
130+int trusty_lend_memory(struct device *dev, u64 *id,
131+ struct scatterlist *sglist, unsigned int nents,
132+ pgprot_t pgprot, u64 tag)
133+{
134+ return __trusty_share_memory(dev, id, sglist, nents, pgprot, tag, false);
135+}
136+EXPORT_SYMBOL(trusty_lend_memory);
137
138 /*
139 * trusty_share_memory_compat - trusty_share_memory wrapper for old apis
140@@ -287,7 +299,8 @@ int trusty_share_memory_compat(struct device *dev, u64 *id,
141 int ret;
142 struct trusty_state *s = platform_get_drvdata(to_platform_device(dev));
143
144- ret = trusty_share_memory(dev, id, sglist, nents, pgprot);
145+ ret = trusty_share_memory(dev, id, sglist, nents, pgprot,
146+ TRUSTY_DEFAULT_MEM_OBJ_TAG);
147 if (!ret && s->api_version < TRUSTY_API_VERSION_PHYS_MEM_OBJ)
148 *id &= 0x0000FFFFFFFFF000ull;
149
150diff --git a/include/linux/trusty/trusty.h b/include/linux/trusty/trusty.h
151index 272d96c1c696..27f635f2d12d 100644
152--- a/include/linux/trusty/trusty.h
153+++ b/include/linux/trusty/trusty.h
154@@ -11,6 +11,7 @@
155 #include <linux/device.h>
156 #include <linux/pagemap.h>
157
158+#define TRUSTY_DEFAULT_MEM_OBJ_TAG (0)
159
160 #if IS_ENABLED(CONFIG_TRUSTY)
161 s32 trusty_std_call32(struct device *dev, u32 smcnr, u32 a0, u32 a1, u32 a2);
162@@ -62,13 +63,13 @@ struct scatterlist;
163 typedef u64 trusty_shared_mem_id_t;
164 int trusty_share_memory(struct device *dev, trusty_shared_mem_id_t *id,
165 struct scatterlist *sglist, unsigned int nents,
166- pgprot_t pgprot);
167+ pgprot_t pgprot, u64 tag);
168 int trusty_share_memory_compat(struct device *dev, trusty_shared_mem_id_t *id,
169 struct scatterlist *sglist, unsigned int nents,
170 pgprot_t pgprot);
171-int trusty_transfer_memory(struct device *dev, u64 *id,
172- struct scatterlist *sglist, unsigned int nents,
173- pgprot_t pgprot, u64 tag, bool lend);
174+int trusty_lend_memory(struct device *dev, u64 *id,
175+ struct scatterlist *sglist, unsigned int nents,
176+ pgprot_t pgprot, u64 tag);
177 int trusty_reclaim_memory(struct device *dev, trusty_shared_mem_id_t id,
178 struct scatterlist *sglist, unsigned int nents);
179
180@@ -78,7 +79,7 @@ u64 trusty_dma_buf_get_ffa_tag(struct dma_buf *dma_buf);
181 #else
182 static inline u64 trusty_dma_buf_get_ffa_tag(struct dma_buf *dma_buf)
183 {
184- return 0;
185+ return TRUSTY_DEFAULT_MEM_OBJ_TAG;
186 }
187 #endif
188
189--
1902.30.2
191