summaryrefslogtreecommitdiff
path: root/meta-arm/meta-arm-bsp/recipes-kernel/linux/linux-arm64-ack-5.15/tc/0029-ANDROID-trusty-Rename-transfer-memory-function-to-le.patch
blob: 8f061f75909b4defe01b7ab2543b758ee23c20f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
From 162daf58abe2d00b9279fce143595b6ff546f803 Mon Sep 17 00:00:00 2001
From: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
Date: Tue, 18 Jan 2022 18:27:09 +0000
Subject: [PATCH 29/40] ANDROID: trusty: Rename transfer memory function to
 lend memory

Renaming trusty_transfer_memory to trusty_lend_memory allows Trusty
to export memory operation like share, lend, reclaim and use common
code for memory share and lend operations.

Define TRUSTY_DEFAULT_MEM_OBJ_TAG as 0 and use that in existing calls.

Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
Change-Id: Ie165a609cc4398bb916967595d0b748d54d75faf
Upstream-Status: Pending [Not submitted to upstream yet]
Signed-off-by: Rupinderjit Singh <rupinderjit.singh@arm.com
---
 drivers/trusty/trusty-ipc.c    | 14 ++++++++----
 drivers/trusty/trusty-test.c   |  3 ++-
 drivers/trusty/trusty-virtio.c |  3 ++-
 drivers/trusty/trusty.c        | 41 ++++++++++++++++++++++------------
 include/linux/trusty/trusty.h  | 11 ++++-----
 5 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/drivers/trusty/trusty-ipc.c b/drivers/trusty/trusty-ipc.c
index 82d6ddeb41f4..0a27af2063a7 100644
--- a/drivers/trusty/trusty-ipc.c
+++ b/drivers/trusty/trusty-ipc.c
@@ -1233,10 +1233,16 @@ static int dn_share_fd(struct tipc_dn_chan *dn, int fd,
 		goto cleanup_handle;
 	}
 
-	ret = trusty_transfer_memory(tipc_shared_handle_dev(shared_handle),
-				     &mem_id, shared_handle->sgt->sgl,
-				     shared_handle->sgt->orig_nents, prot, tag,
-				     lend);
+	if (lend)
+		ret = trusty_lend_memory(tipc_shared_handle_dev(shared_handle),
+					 &mem_id, shared_handle->sgt->sgl,
+					 shared_handle->sgt->orig_nents, prot,
+					 tag);
+	else
+		ret = trusty_share_memory(tipc_shared_handle_dev(shared_handle),
+					  &mem_id, shared_handle->sgt->sgl,
+					  shared_handle->sgt->orig_nents, prot,
+					  tag);
 
 	if (ret < 0) {
 		dev_dbg(dev, "Transferring memory failed: %d\n", ret);
diff --git a/drivers/trusty/trusty-test.c b/drivers/trusty/trusty-test.c
index 844868981fa5..c25fc0f2fcf0 100644
--- a/drivers/trusty/trusty-test.c
+++ b/drivers/trusty/trusty-test.c
@@ -138,7 +138,8 @@ static int trusty_test_share_objs(struct trusty_test_state *s,
 		t1 = ktime_get();
 		tmpret = trusty_share_memory(s->trusty_dev, &obj->mem_id,
 					     obj->sgt.sgl, obj->sgt.nents,
-					     PAGE_KERNEL);
+					     PAGE_KERNEL,
+					     TRUSTY_DEFAULT_MEM_OBJ_TAG);
 		t2 = ktime_get();
 		if (tmpret) {
 			ret = tmpret;
diff --git a/drivers/trusty/trusty-virtio.c b/drivers/trusty/trusty-virtio.c
index fea59cd2e218..365e7c04bcf4 100644
--- a/drivers/trusty/trusty-virtio.c
+++ b/drivers/trusty/trusty-virtio.c
@@ -626,7 +626,8 @@ static int trusty_virtio_add_devices(struct trusty_ctx *tctx)
 
 	sg_init_one(&tctx->shared_sg, descr_va, descr_buf_sz);
 	ret = trusty_share_memory(tctx->dev->parent, &descr_id,
-				  &tctx->shared_sg, 1, PAGE_KERNEL);
+				  &tctx->shared_sg, 1, PAGE_KERNEL,
+				  TRUSTY_DEFAULT_MEM_OBJ_TAG);
 	if (ret) {
 		dev_err(tctx->dev, "trusty_share_memory failed: %d\n", ret);
 		goto err_share_memory;
diff --git a/drivers/trusty/trusty.c b/drivers/trusty/trusty.c
index 2dec75398f69..6bd30bc1bbc9 100644
--- a/drivers/trusty/trusty.c
+++ b/drivers/trusty/trusty.c
@@ -222,18 +222,9 @@ s32 trusty_std_call32(struct device *dev, u32 smcnr, u32 a0, u32 a1, u32 a2)
 }
 EXPORT_SYMBOL(trusty_std_call32);
 
-int trusty_share_memory(struct device *dev, u64 *id,
-			struct scatterlist *sglist, unsigned int nents,
-			pgprot_t pgprot)
-{
-	return trusty_transfer_memory(dev, id, sglist, nents, pgprot, 0,
-				      false);
-}
-EXPORT_SYMBOL(trusty_share_memory);
-
-int trusty_transfer_memory(struct device *dev, u64 *id,
-			   struct scatterlist *sglist, unsigned int nents,
-			   pgprot_t pgprot, u64 tag, bool lend)
+static int __trusty_share_memory(struct device *dev, u64 *id,
+				 struct scatterlist *sglist, unsigned int nents,
+				 pgprot_t pgprot, u64 tag, bool mem_share)
 {
 	struct trusty_state *s = platform_get_drvdata(to_platform_device(dev));
 	int ret;
@@ -253,6 +244,12 @@ int trusty_transfer_memory(struct device *dev, u64 *id,
 		return -EOPNOTSUPP;
 	}
 
+	if (mem_share == false && s->api_version < TRUSTY_API_VERSION_MEM_OBJ) {
+		dev_err(s->dev, "%s: old trusty version does not support lending memory objects\n",
+			__func__);
+		return -EOPNOTSUPP;
+	}
+
 	count = dma_map_sg(dev, sglist, nents, DMA_BIDIRECTIONAL);
 	if (count != nents) {
 		dev_err(s->dev, "failed to dma map sg_table\n");
@@ -271,7 +268,22 @@ int trusty_transfer_memory(struct device *dev, u64 *id,
 	*id = pg_inf.compat_attr;
 	return 0;
 }
-EXPORT_SYMBOL(trusty_transfer_memory);
+
+int trusty_share_memory(struct device *dev, u64 *id,
+			struct scatterlist *sglist, unsigned int nents,
+			pgprot_t pgprot, u64 tag)
+{
+	return __trusty_share_memory(dev, id, sglist, nents, pgprot, tag, true);
+}
+EXPORT_SYMBOL(trusty_share_memory);
+
+int trusty_lend_memory(struct device *dev, u64 *id,
+		       struct scatterlist *sglist, unsigned int nents,
+		       pgprot_t pgprot, u64 tag)
+{
+	return __trusty_share_memory(dev, id, sglist, nents, pgprot, tag, false);
+}
+EXPORT_SYMBOL(trusty_lend_memory);
 
 /*
  * trusty_share_memory_compat - trusty_share_memory wrapper for old apis
@@ -287,7 +299,8 @@ int trusty_share_memory_compat(struct device *dev, u64 *id,
 	int ret;
 	struct trusty_state *s = platform_get_drvdata(to_platform_device(dev));
 
-	ret = trusty_share_memory(dev, id, sglist, nents, pgprot);
+	ret = trusty_share_memory(dev, id, sglist, nents, pgprot,
+				  TRUSTY_DEFAULT_MEM_OBJ_TAG);
 	if (!ret && s->api_version < TRUSTY_API_VERSION_PHYS_MEM_OBJ)
 		*id &= 0x0000FFFFFFFFF000ull;
 
diff --git a/include/linux/trusty/trusty.h b/include/linux/trusty/trusty.h
index 272d96c1c696..27f635f2d12d 100644
--- a/include/linux/trusty/trusty.h
+++ b/include/linux/trusty/trusty.h
@@ -11,6 +11,7 @@
 #include <linux/device.h>
 #include <linux/pagemap.h>
 
+#define TRUSTY_DEFAULT_MEM_OBJ_TAG	(0)
 
 #if IS_ENABLED(CONFIG_TRUSTY)
 s32 trusty_std_call32(struct device *dev, u32 smcnr, u32 a0, u32 a1, u32 a2);
@@ -62,13 +63,13 @@ struct scatterlist;
 typedef u64 trusty_shared_mem_id_t;
 int trusty_share_memory(struct device *dev, trusty_shared_mem_id_t *id,
 			struct scatterlist *sglist, unsigned int nents,
-			pgprot_t pgprot);
+			pgprot_t pgprot, u64 tag);
 int trusty_share_memory_compat(struct device *dev, trusty_shared_mem_id_t *id,
 			       struct scatterlist *sglist, unsigned int nents,
 			       pgprot_t pgprot);
-int trusty_transfer_memory(struct device *dev, u64 *id,
-			   struct scatterlist *sglist, unsigned int nents,
-			   pgprot_t pgprot, u64 tag, bool lend);
+int trusty_lend_memory(struct device *dev, u64 *id,
+		       struct scatterlist *sglist, unsigned int nents,
+		       pgprot_t pgprot, u64 tag);
 int trusty_reclaim_memory(struct device *dev, trusty_shared_mem_id_t id,
 			  struct scatterlist *sglist, unsigned int nents);
 
@@ -78,7 +79,7 @@ u64 trusty_dma_buf_get_ffa_tag(struct dma_buf *dma_buf);
 #else
 static inline u64 trusty_dma_buf_get_ffa_tag(struct dma_buf *dma_buf)
 {
-	return 0;
+	return TRUSTY_DEFAULT_MEM_OBJ_TAG;
 }
 #endif
 
-- 
2.34.1