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