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