Patrick Williams | 975a06f | 2022-10-21 14:42:47 -0500 | [diff] [blame] | 1 | From 6cb8e5f83d53357fbc6e58c2c5c5a3450654f9e6 Mon Sep 17 00:00:00 2001 |
| 2 | From: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> |
| 3 | Date: Wed, 19 Oct 2022 17:51:10 +0100 |
| 4 | Subject: [PATCH] arm_ffa: add support for 32-bit direct messaging |
| 5 | |
| 6 | add 32-bit mode for FFA_MSG_SEND_DIRECT_REQ and FFA_MSG_SEND_DIRECT_RESP |
| 7 | |
| 8 | Tested-by: Mohamed Omar Asaker <mohamed.omarasaker@arm.com> |
| 9 | Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> |
| 10 | Upstream-Status: Pending [Not submitted to upstream yet] |
| 11 | --- |
| 12 | cmd/armffa.c | 2 +- |
| 13 | drivers/firmware/arm-ffa/core.c | 17 ++++++++++++++--- |
| 14 | drivers/firmware/arm-ffa/sandbox.c | 2 +- |
| 15 | include/arm_ffa.h | 2 +- |
| 16 | lib/efi_loader/efi_capsule.c | 2 +- |
| 17 | lib/efi_loader/efi_setup.c | 2 +- |
| 18 | lib/efi_loader/efi_variable_tee.c | 2 +- |
| 19 | test/dm/ffa.c | 6 +++--- |
| 20 | 8 files changed, 23 insertions(+), 12 deletions(-) |
| 21 | |
| 22 | diff --git a/cmd/armffa.c b/cmd/armffa.c |
| 23 | index 9b56e8a830..9842b99181 100644 |
| 24 | --- a/cmd/armffa.c |
| 25 | +++ b/cmd/armffa.c |
| 26 | @@ -129,7 +129,7 @@ int do_ffa_msg_send_direct_req(struct cmd_tbl *cmdtp, int flag, int argc, |
| 27 | return -EINVAL; |
| 28 | } |
| 29 | |
| 30 | - ret = ffa_bus_ops_get()->sync_send_receive(part_id, &msg); |
| 31 | + ret = ffa_bus_ops_get()->sync_send_receive(part_id, &msg, 1); |
| 32 | if (ret == 0) { |
| 33 | u8 cnt; |
| 34 | |
| 35 | diff --git a/drivers/firmware/arm-ffa/core.c b/drivers/firmware/arm-ffa/core.c |
| 36 | index caba10caae..ba1ba59937 100644 |
| 37 | --- a/drivers/firmware/arm-ffa/core.c |
| 38 | +++ b/drivers/firmware/arm-ffa/core.c |
| 39 | @@ -1032,6 +1032,7 @@ static int ffa_cache_partitions_info(void) |
| 40 | * ffa_msg_send_direct_req - FFA_MSG_SEND_DIRECT_{REQ,RESP} handler function |
| 41 | * @dst_part_id: destination partition ID |
| 42 | * @msg: pointer to the message data preallocated by the client (in/out) |
| 43 | + * @is_smc64: select 64-bit or 32-bit FF-A ABI |
| 44 | * |
| 45 | * This is the runtime function that implements FFA_MSG_SEND_DIRECT_{REQ,RESP} |
| 46 | * FF-A functions. |
| 47 | @@ -1048,10 +1049,12 @@ static int ffa_cache_partitions_info(void) |
| 48 | * |
| 49 | * 0 on success. Otherwise, failure |
| 50 | */ |
| 51 | -static int __ffa_runtime ffa_msg_send_direct_req(u16 dst_part_id, struct ffa_send_direct_data *msg) |
| 52 | +static int __ffa_runtime ffa_msg_send_direct_req(u16 dst_part_id, struct ffa_send_direct_data *msg, |
| 53 | + u8 is_smc64) |
| 54 | { |
| 55 | ffa_value_t res = {0}; |
| 56 | int ffa_errno; |
| 57 | + u64 req_mode, resp_mode; |
| 58 | |
| 59 | if (!ffa_priv_data || !ffa_priv_data->invoke_ffa_fn) |
| 60 | return -EINVAL; |
| 61 | @@ -1060,8 +1063,16 @@ static int __ffa_runtime ffa_msg_send_direct_req(u16 dst_part_id, struct ffa_sen |
| 62 | if (!ffa_priv_data->partitions.count || !ffa_priv_data->partitions.descs) |
| 63 | return -ENODEV; |
| 64 | |
| 65 | + if(is_smc64) { |
| 66 | + req_mode = FFA_SMC_64(FFA_MSG_SEND_DIRECT_REQ); |
| 67 | + resp_mode = FFA_SMC_64(FFA_MSG_SEND_DIRECT_RESP); |
| 68 | + } else { |
| 69 | + req_mode = FFA_SMC_32(FFA_MSG_SEND_DIRECT_REQ); |
| 70 | + resp_mode = FFA_SMC_32(FFA_MSG_SEND_DIRECT_RESP); |
| 71 | + } |
| 72 | + |
| 73 | ffa_priv_data->invoke_ffa_fn((ffa_value_t){ |
| 74 | - .a0 = FFA_SMC_64(FFA_MSG_SEND_DIRECT_REQ), |
| 75 | + .a0 = req_mode, |
| 76 | .a1 = PREP_SELF_ENDPOINT_ID(ffa_priv_data->id) | |
| 77 | PREP_PART_ENDPOINT_ID(dst_part_id), |
| 78 | .a2 = 0, |
| 79 | @@ -1083,7 +1094,7 @@ static int __ffa_runtime ffa_msg_send_direct_req(u16 dst_part_id, struct ffa_sen |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | - if (res.a0 == FFA_SMC_64(FFA_MSG_SEND_DIRECT_RESP)) { |
| 84 | + if (res.a0 == resp_mode){ |
| 85 | /* |
| 86 | * Message sent with response |
| 87 | * extract the return data |
| 88 | diff --git a/drivers/firmware/arm-ffa/sandbox.c b/drivers/firmware/arm-ffa/sandbox.c |
| 89 | index 16e1fdc809..8e8549441d 100644 |
| 90 | --- a/drivers/firmware/arm-ffa/sandbox.c |
| 91 | +++ b/drivers/firmware/arm-ffa/sandbox.c |
| 92 | @@ -430,7 +430,7 @@ static int sandbox_ffa_sp_valid(u16 part_id) |
| 93 | * @{a0-a7} , res: The SMC call arguments and return structure. |
| 94 | * |
| 95 | * This is the function that emulates FFA_MSG_SEND_DIRECT_{REQ,RESP} |
| 96 | - * FF-A functions. |
| 97 | + * FF-A functions. Only SMC 64-bit is supported in Sandbox. |
| 98 | * |
| 99 | * Emulating interrupts is not supported. So, FFA_RUN and FFA_INTERRUPT are not supported. |
| 100 | * In case of success FFA_MSG_SEND_DIRECT_RESP is returned with default pattern data (0xff). |
| 101 | diff --git a/include/arm_ffa.h b/include/arm_ffa.h |
| 102 | index 665413a0c5..4a7c59ff28 100644 |
| 103 | --- a/include/arm_ffa.h |
| 104 | +++ b/include/arm_ffa.h |
| 105 | @@ -97,7 +97,7 @@ struct __packed ffa_send_direct_data { |
| 106 | struct ffa_bus_ops { |
| 107 | int (*partition_info_get)(const char *uuid_str, |
| 108 | u32 *parts_size, struct ffa_partition_info *buffer); |
| 109 | - int (*sync_send_receive)(u16 dst_part_id, struct ffa_send_direct_data *msg); |
| 110 | + int (*sync_send_receive)(u16 dst_part_id, struct ffa_send_direct_data *msg, u8 is_smc64); |
| 111 | int (*rxtx_unmap)(void); |
| 112 | }; |
| 113 | |
| 114 | diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c |
| 115 | index 65e2fc8296..c479c53d04 100644 |
| 116 | --- a/lib/efi_loader/efi_capsule.c |
| 117 | +++ b/lib/efi_loader/efi_capsule.c |
| 118 | @@ -591,7 +591,7 @@ static int __efi_runtime efi_corstone1000_buffer_ready_event(u32 capsule_image_s |
| 119 | msg.data1 = PREP_SEPROXY_SVC_ID(CORSTONE1000_SEPROXY_UPDATE_SVC_ID) | |
| 120 | PREP_SEPROXY_EVT(CORSTONE1000_BUFFER_READY_EVT); /* w4 */ |
| 121 | |
| 122 | - return ffa_bus_ops_get()->sync_send_receive(CORSTONE1000_SEPROXY_PART_ID, &msg); |
| 123 | + return ffa_bus_ops_get()->sync_send_receive(CORSTONE1000_SEPROXY_PART_ID, &msg, 0); |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c |
| 128 | index 6ccda175ff..416af8d663 100644 |
| 129 | --- a/lib/efi_loader/efi_setup.c |
| 130 | +++ b/lib/efi_loader/efi_setup.c |
| 131 | @@ -153,7 +153,7 @@ static int efi_corstone1000_uboot_efi_started_event(void) |
| 132 | msg.data1 = PREP_SEPROXY_SVC_ID(CORSTONE1000_SEPROXY_UPDATE_SVC_ID) | |
| 133 | PREP_SEPROXY_EVT(CORSTONE1000_UBOOT_EFI_STARTED_EVT); /* w4 */ |
| 134 | |
| 135 | - return ffa_bus_ops_get()->sync_send_receive(CORSTONE1000_SEPROXY_PART_ID, &msg); |
| 136 | + return ffa_bus_ops_get()->sync_send_receive(CORSTONE1000_SEPROXY_PART_ID, &msg, 0); |
| 137 | } |
| 138 | #endif |
| 139 | |
| 140 | diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c |
| 141 | index 7d9d577281..05f3c02911 100644 |
| 142 | --- a/lib/efi_loader/efi_variable_tee.c |
| 143 | +++ b/lib/efi_loader/efi_variable_tee.c |
| 144 | @@ -201,7 +201,7 @@ static int __efi_runtime ffa_notify_mm_sp(void) |
| 145 | |
| 146 | msg.data0 = FFA_SHARED_MM_BUFFER_OFFSET; /* x3 */ |
| 147 | |
| 148 | - ret = ffa_bus_ops_get()->sync_send_receive(mm_sp_id, &msg); |
| 149 | + ret = ffa_bus_ops_get()->sync_send_receive(mm_sp_id, &msg, 1); |
| 150 | if (ret != 0) |
| 151 | return ret; |
| 152 | |
| 153 | diff --git a/test/dm/ffa.c b/test/dm/ffa.c |
| 154 | index 052d5fc3f4..14b19cf71e 100644 |
| 155 | --- a/test/dm/ffa.c |
| 156 | +++ b/test/dm/ffa.c |
| 157 | @@ -170,7 +170,7 @@ static int test_ffa_msg_send_direct_req(u16 part_id, struct unit_test_state *ut |
| 158 | struct ffa_send_direct_data msg = {0}; |
| 159 | u8 cnt; |
| 160 | |
| 161 | - ut_assertok(ffa_bus_ops_get()->sync_send_receive(part_id, &msg)); |
| 162 | + ut_assertok(ffa_bus_ops_get()->sync_send_receive(part_id, &msg, 1)); |
| 163 | |
| 164 | for (cnt = 0; cnt < sizeof(struct ffa_send_direct_data) / sizeof(u64); cnt++) |
| 165 | ut_assertok(((u64 *)&msg)[cnt] != 0xffffffffffffffff); |
| 166 | @@ -380,12 +380,12 @@ static int dm_test_ffa_nack(struct unit_test_state *uts) |
| 167 | ut_assertok(count != SANDBOX_SP_COUNT_PER_VALID_SERVICE); |
| 168 | |
| 169 | /* send data to an invalid partition */ |
| 170 | - ret = ffa_bus_ops_get()->sync_send_receive(part_id, &msg); |
| 171 | + ret = ffa_bus_ops_get()->sync_send_receive(part_id, &msg, 1); |
| 172 | ut_assertok(ret != -EINVAL); |
| 173 | |
| 174 | /* send data to a valid partition */ |
| 175 | part_id = prvdata->partitions.descs[0].info.id; |
| 176 | - ret = ffa_bus_ops_get()->sync_send_receive(part_id, &msg); |
| 177 | + ret = ffa_bus_ops_get()->sync_send_receive(part_id, &msg, 1); |
| 178 | ut_assertok(ret != 0); |
| 179 | |
| 180 | return CMD_RET_SUCCESS; |
| 181 | -- |
| 182 | 2.17.1 |