Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, Arm Limited. All rights reserved. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 8 | #include <errno.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 9 | #include <debug.h> |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 10 | |
| 11 | #include <cactus_platform_def.h> |
| 12 | #include <cactus_test_cmds.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 13 | #include <drivers/arm/pl011.h> |
| 14 | #include <drivers/console.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 15 | #include <lib/aarch64/arch_helpers.h> |
| 16 | #include <lib/xlat_tables/xlat_mmu_helpers.h> |
| 17 | #include <lib/xlat_tables/xlat_tables_v2.h> |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 18 | #include <plat_arm.h> |
| 19 | #include <plat/common/platform.h> |
| 20 | #include <platform_def.h> |
J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 21 | #include <sp_helpers.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 22 | #include <std_svc.h> |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 23 | |
Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 24 | #include "cactus_def.h" |
| 25 | #include "cactus_tests.h" |
| 26 | #include "cactus.h" |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 27 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 28 | /* Host machine information injected by the build system in the ELF file. */ |
| 29 | extern const char build_message[]; |
| 30 | extern const char version_string[]; |
| 31 | |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 32 | /* Memory section to be used for memory share operations */ |
| 33 | static __aligned(PAGE_SIZE) uint8_t share_page[PAGE_SIZE]; |
| 34 | |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 35 | /* |
| 36 | * |
| 37 | * Message loop function |
| 38 | * Notice we cannot use regular print functions because this serves to both |
| 39 | * "primary" and "secondary" VMs. Secondary VM cannot access UART directly |
| 40 | * but rather through Hafnium print hypercall. |
| 41 | * |
| 42 | */ |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 43 | static void __dead2 message_loop(ffa_vm_id_t vm_id, struct mailbox_buffers *mb) |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 44 | { |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 45 | smc_ret_values ffa_ret; |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 46 | uint32_t sp_response; |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 47 | ffa_vm_id_t source; |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 48 | ffa_vm_id_t destination; |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 49 | uint64_t cactus_cmd; |
| 50 | |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 51 | /* |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 52 | * This initial wait call is necessary to inform SPMD that |
| 53 | * SP initialization has completed. It blocks until receiving |
| 54 | * a direct message request. |
| 55 | */ |
| 56 | |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 57 | ffa_ret = ffa_msg_wait(); |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 58 | |
| 59 | for (;;) { |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 60 | VERBOSE("Woke up with func id: %x\n", ffa_func_id(ffa_ret)); |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 61 | |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 62 | if (ffa_func_id(ffa_ret) == FFA_ERROR) { |
| 63 | ERROR("Error: %x\n", ffa_error_code(ffa_ret)); |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 64 | break; |
| 65 | } |
| 66 | |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 67 | if (ffa_func_id(ffa_ret) != FFA_MSG_SEND_DIRECT_REQ_SMC32 && |
| 68 | ffa_func_id(ffa_ret) != FFA_MSG_SEND_DIRECT_REQ_SMC64) { |
| 69 | ERROR("%s(%u) unknown func id 0x%x\n", |
| 70 | __func__, vm_id, ffa_func_id(ffa_ret)); |
Olivier Deprez | 73d81cf | 2020-09-15 16:57:00 +0200 | [diff] [blame] | 71 | break; |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 72 | } |
| 73 | |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 74 | destination = ffa_dir_msg_dest(ffa_ret); |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 75 | |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 76 | source = ffa_dir_msg_source(ffa_ret); |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 77 | |
| 78 | if (destination != vm_id) { |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 79 | ERROR("%s(%u) invalid vm id 0x%x\n", |
| 80 | __func__, vm_id, destination); |
Olivier Deprez | 73d81cf | 2020-09-15 16:57:00 +0200 | [diff] [blame] | 81 | break; |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 82 | } |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 83 | |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 84 | PRINT_CMD(ffa_ret); |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 85 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 86 | cactus_cmd = cactus_get_cmd(ffa_ret); |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 87 | |
| 88 | switch (cactus_cmd) { |
J-Alves | b9085f8 | 2020-12-07 10:57:28 +0000 | [diff] [blame] | 89 | case CACTUS_MEM_SEND_CMD: |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 90 | ffa_memory_management_test( |
| 91 | mb, vm_id, source, |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 92 | cactus_req_mem_send_get_mem_func( |
| 93 | ffa_ret), |
| 94 | cactus_mem_send_get_handle(ffa_ret)); |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * If execution gets to this point means all operations |
| 98 | * with memory retrieval went well, as such replying |
| 99 | */ |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 100 | ffa_ret = cactus_success_resp(vm_id, source); |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 101 | break; |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 102 | case CACTUS_REQ_MEM_SEND_CMD: |
| 103 | { |
| 104 | uint32_t mem_func = |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 105 | cactus_req_mem_send_get_mem_func(ffa_ret); |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 106 | ffa_vm_id_t receiver = |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 107 | cactus_req_mem_send_get_receiver(ffa_ret); |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 108 | ffa_memory_handle_t handle; |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 109 | |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 110 | VERBOSE("%x requested to send memory to %x (func: %x)\n", |
| 111 | source, receiver, mem_func); |
| 112 | |
| 113 | const struct ffa_memory_region_constituent |
| 114 | constituents[] = { |
| 115 | {(void *)share_page, 1, 0} |
| 116 | }; |
| 117 | |
| 118 | const uint32_t constituents_count = ( |
| 119 | sizeof(constituents) / |
| 120 | sizeof(constituents[0]) |
| 121 | ); |
| 122 | |
| 123 | handle = ffa_memory_init_and_send( |
| 124 | (struct ffa_memory_region *)mb->send, PAGE_SIZE, |
| 125 | vm_id, receiver, constituents, |
| 126 | constituents_count, mem_func); |
| 127 | |
| 128 | /* |
| 129 | * If returned an invalid handle, we should break the |
| 130 | * test. |
| 131 | */ |
| 132 | expect(handle != FFA_MEMORY_HANDLE_INVALID, true); |
| 133 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 134 | ffa_ret = cactus_mem_send_cmd(vm_id, receiver, mem_func, |
| 135 | handle); |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 136 | |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 137 | if (ffa_func_id(ffa_ret) != |
| 138 | FFA_MSG_SEND_DIRECT_RESP_SMC32) { |
| 139 | ERROR("Failed to send message. error: %x\n", |
| 140 | ffa_error_code(ffa_ret)); |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 141 | ffa_ret = cactus_error_resp(vm_id, source); |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 142 | break; |
| 143 | } |
| 144 | |
| 145 | /* If anything went bad on the receiver's end. */ |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 146 | if (cactus_get_response(ffa_ret) == CACTUS_ERROR) { |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 147 | ERROR("Received error from receiver!\n"); |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 148 | ffa_ret = cactus_error_resp(vm_id, source); |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 149 | break; |
| 150 | } |
| 151 | |
| 152 | if (mem_func != FFA_MEM_DONATE_SMC32) { |
| 153 | /* |
| 154 | * Do a memory reclaim only if the mem_func |
| 155 | * regards to memory share or lend operations, |
| 156 | * as with a donate the owner is permanently |
| 157 | * given up access to the memory region. |
| 158 | */ |
| 159 | if (ffa_mem_reclaim(handle, 0) |
| 160 | .ret0 == FFA_ERROR) { |
| 161 | ERROR("Failed to reclaim memory!\n"); |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 162 | ffa_ret = cactus_error_resp(vm_id, |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 163 | source); |
| 164 | break; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Read Content that has been written to memory |
| 169 | * to validate access to memory segment has been |
| 170 | * reestablished, and receiver made use of |
| 171 | * memory region. |
| 172 | */ |
| 173 | #if (LOG_LEVEL >= LOG_LEVEL_VERBOSE) |
| 174 | uint32_t *ptr = |
| 175 | (uint32_t *)constituents |
| 176 | ->address; |
| 177 | VERBOSE("Memory contents after receiver" |
| 178 | " SP's use:\n"); |
| 179 | for (unsigned int i = 0U; i < 5U; i++) |
| 180 | VERBOSE(" %u: %x\n", i, |
| 181 | ptr[i]); |
| 182 | #endif |
| 183 | } |
| 184 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 185 | ffa_ret = cactus_success_resp(vm_id, source); |
| 186 | break; |
J-Alves | d8edeed | 2020-11-18 10:48:12 +0000 | [diff] [blame] | 187 | } |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 188 | case CACTUS_ECHO_CMD: |
| 189 | { |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 190 | uint64_t echo_val = cactus_echo_get_val(ffa_ret); |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 191 | |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 192 | VERBOSE("Received echo at %x, value %llx from %x.\n", |
| 193 | destination, echo_val, source); |
| 194 | ffa_ret = cactus_response(destination, source, echo_val); |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 195 | break; |
| 196 | } |
| 197 | case CACTUS_REQ_ECHO_CMD: |
| 198 | { |
| 199 | ffa_vm_id_t echo_dest = |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 200 | cactus_req_echo_get_echo_dest(ffa_ret); |
| 201 | uint64_t echo_val = cactus_echo_get_val(ffa_ret); |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 202 | bool success = true; |
| 203 | |
| 204 | VERBOSE("%x requested to send echo to %x, value %llx\n", |
| 205 | source, echo_dest, echo_val); |
| 206 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 207 | ffa_ret = cactus_echo_send_cmd(vm_id, echo_dest, |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 208 | echo_val); |
| 209 | |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 210 | if (ffa_func_id(ffa_ret) != |
| 211 | FFA_MSG_SEND_DIRECT_RESP_SMC32) { |
| 212 | ERROR("Failed to send message. error: %x\n", |
| 213 | ffa_error_code(ffa_ret)); |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 214 | success = false; |
| 215 | } |
| 216 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 217 | if (cactus_get_response(ffa_ret) != echo_val) { |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 218 | ERROR("Echo Failed!\n"); |
| 219 | success = false; |
| 220 | } |
| 221 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 222 | ffa_ret = success ? cactus_success_resp(vm_id, source) : |
| 223 | cactus_error_resp(vm_id, source); |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 224 | break; |
| 225 | } |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 226 | case CACTUS_DEADLOCK_CMD: |
| 227 | case CACTUS_REQ_DEADLOCK_CMD: |
| 228 | { |
| 229 | ffa_vm_id_t deadlock_dest = |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 230 | cactus_deadlock_get_next_dest(ffa_ret); |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 231 | ffa_vm_id_t deadlock_next_dest = source; |
| 232 | |
| 233 | if (cactus_cmd == CACTUS_DEADLOCK_CMD) { |
| 234 | VERBOSE("%x is creating deadlock. next: %x\n", |
| 235 | source, deadlock_dest); |
| 236 | } else if (cactus_cmd == CACTUS_REQ_DEADLOCK_CMD) { |
| 237 | VERBOSE( |
| 238 | "%x requested deadlock with %x and %x\n", |
| 239 | source, deadlock_dest, deadlock_next_dest); |
| 240 | |
| 241 | deadlock_next_dest = |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 242 | cactus_deadlock_get_next_dest2(ffa_ret); |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 243 | } |
| 244 | |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 245 | ffa_ret = cactus_deadlock_send_cmd(vm_id, deadlock_dest, |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 246 | deadlock_next_dest); |
| 247 | |
| 248 | /* |
| 249 | * Should be true for the last partition to attempt |
| 250 | * an FF-A direct message, to the first partition. |
| 251 | */ |
| 252 | bool is_deadlock_detected = |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 253 | (ffa_func_id(ffa_ret) == FFA_ERROR) && |
| 254 | (ffa_error_code(ffa_ret) == FFA_ERROR_BUSY); |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 255 | |
| 256 | /* |
| 257 | * Should be true after the deadlock has been detected |
| 258 | * and after the first response has been sent down the |
| 259 | * request chain. |
| 260 | */ |
| 261 | bool is_returning_from_deadlock = |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 262 | (ffa_func_id(ffa_ret) == |
| 263 | FFA_MSG_SEND_DIRECT_RESP_SMC32) |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 264 | && |
| 265 | (cactus_get_response(ffa_ret) == CACTUS_SUCCESS); |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 266 | |
| 267 | if (is_deadlock_detected) { |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 268 | NOTICE("Attempting dealock but got error %x\n", |
| 269 | ffa_error_code(ffa_ret)); |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | if (is_deadlock_detected || |
| 273 | is_returning_from_deadlock) { |
| 274 | /* |
| 275 | * This is not the partition, that would have |
| 276 | * created the deadlock. As such, reply back |
| 277 | * to the partitions. |
| 278 | */ |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 279 | ffa_ret = cactus_success_resp(vm_id, source); |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 280 | break; |
| 281 | } |
| 282 | |
| 283 | /* Shouldn't get to this point */ |
| 284 | ERROR("Deadlock test went wrong!\n"); |
J-Alves | 5339201 | 2020-11-18 14:51:57 +0000 | [diff] [blame] | 285 | ffa_ret = cactus_error_resp(vm_id, source); |
J-Alves | 1d203f1 | 2020-11-11 11:38:49 +0000 | [diff] [blame] | 286 | break; |
| 287 | } |
Olivier Deprez | 881b199 | 2020-12-01 15:34:34 +0100 | [diff] [blame] | 288 | case CACTUS_REQ_SIMD_FILL_CMD: |
| 289 | fill_simd_vectors(); |
| 290 | ffa_ret = cactus_success_resp(vm_id, source); |
| 291 | break; |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 292 | default: |
| 293 | /* |
| 294 | * Currently direct message test is handled here. |
| 295 | * TODO: create a case within the switch case |
| 296 | * For the sake of testing, add the vm id to the |
| 297 | * received message. |
| 298 | */ |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 299 | sp_response = ffa_ret.ret3 | vm_id; |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 300 | VERBOSE("Replying with direct message response: %x\n", sp_response); |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 301 | ffa_ret = ffa_msg_send_direct_resp(vm_id, |
| 302 | HYP_ID, |
| 303 | sp_response); |
| 304 | |
| 305 | break; |
| 306 | } |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 307 | } |
Olivier Deprez | 73d81cf | 2020-09-15 16:57:00 +0200 | [diff] [blame] | 308 | |
| 309 | panic(); |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static const mmap_region_t cactus_mmap[] __attribute__((used)) = { |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 313 | /* PLAT_ARM_DEVICE0 area includes UART2 necessary to console */ |
| 314 | MAP_REGION_FLAT(PLAT_ARM_DEVICE0_BASE, PLAT_ARM_DEVICE0_SIZE, |
| 315 | MT_DEVICE | MT_RW), |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 316 | {0} |
| 317 | }; |
| 318 | |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 319 | static void cactus_print_memory_layout(unsigned int vm_id) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 320 | { |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 321 | INFO("Secure Partition memory layout:\n"); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 322 | |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 323 | INFO(" Text region : %p - %p\n", |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 324 | (void *)CACTUS_TEXT_START, (void *)CACTUS_TEXT_END); |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 325 | |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 326 | INFO(" Read-only data region : %p - %p\n", |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 327 | (void *)CACTUS_RODATA_START, (void *)CACTUS_RODATA_END); |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 328 | |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 329 | INFO(" Data region : %p - %p\n", |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 330 | (void *)CACTUS_DATA_START, (void *)CACTUS_DATA_END); |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 331 | |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 332 | INFO(" BSS region : %p - %p\n", |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 333 | (void *)CACTUS_BSS_START, (void *)CACTUS_BSS_END); |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 334 | |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 335 | INFO(" RX : %p - %p\n", |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 336 | (void *)get_sp_rx_start(vm_id), |
| 337 | (void *)get_sp_rx_end(vm_id)); |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 338 | |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 339 | INFO(" TX : %p - %p\n", |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 340 | (void *)get_sp_tx_start(vm_id), |
| 341 | (void *)get_sp_tx_end(vm_id)); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 344 | static void cactus_plat_configure_mmu(unsigned int vm_id) |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 345 | { |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 346 | mmap_add_region(CACTUS_TEXT_START, |
| 347 | CACTUS_TEXT_START, |
| 348 | CACTUS_TEXT_END - CACTUS_TEXT_START, |
| 349 | MT_CODE); |
| 350 | mmap_add_region(CACTUS_RODATA_START, |
| 351 | CACTUS_RODATA_START, |
| 352 | CACTUS_RODATA_END - CACTUS_RODATA_START, |
| 353 | MT_RO_DATA); |
| 354 | mmap_add_region(CACTUS_DATA_START, |
| 355 | CACTUS_DATA_START, |
| 356 | CACTUS_DATA_END - CACTUS_DATA_START, |
| 357 | MT_RW_DATA); |
| 358 | mmap_add_region(CACTUS_BSS_START, |
| 359 | CACTUS_BSS_START, |
| 360 | CACTUS_BSS_END - CACTUS_BSS_START, |
| 361 | MT_RW_DATA); |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 362 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 363 | mmap_add_region(get_sp_rx_start(vm_id), |
| 364 | get_sp_rx_start(vm_id), |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 365 | (CACTUS_RX_TX_SIZE / 2), |
| 366 | MT_RO_DATA); |
| 367 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 368 | mmap_add_region(get_sp_tx_start(vm_id), |
| 369 | get_sp_tx_start(vm_id), |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 370 | (CACTUS_RX_TX_SIZE / 2), |
| 371 | MT_RW_DATA); |
| 372 | |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 373 | mmap_add(cactus_mmap); |
| 374 | init_xlat_tables(); |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 375 | } |
| 376 | |
Olivier Deprez | 458d553 | 2020-06-09 17:56:20 +0200 | [diff] [blame] | 377 | int tftf_irq_handler_dispatcher(void) |
| 378 | { |
| 379 | ERROR("%s\n", __func__); |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 384 | void __dead2 cactus_main(void) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 385 | { |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 386 | assert(IS_IN_EL1() != 0); |
| 387 | |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 388 | struct mailbox_buffers mb; |
J-Alves | da6ac32 | 2020-11-09 15:45:30 +0000 | [diff] [blame] | 389 | |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 390 | /* Clear BSS */ |
| 391 | memset((void *)CACTUS_BSS_START, |
| 392 | 0, CACTUS_BSS_END - CACTUS_BSS_START); |
| 393 | |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 394 | /* Get current FFA id */ |
| 395 | smc_ret_values ffa_id_ret = ffa_id_get(); |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 396 | if (ffa_func_id(ffa_id_ret) != FFA_SUCCESS_SMC32) { |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 397 | ERROR("FFA_ID_GET failed.\n"); |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 398 | panic(); |
| 399 | } |
| 400 | |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 401 | ffa_vm_id_t ffa_id = ffa_id_ret.ret2 & 0xffff; |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 402 | mb.send = (void *) get_sp_tx_start(ffa_id); |
| 403 | mb.recv = (void *) get_sp_rx_start(ffa_id); |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 404 | |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 405 | /* Configure and enable Stage-1 MMU, enable D-Cache */ |
| 406 | cactus_plat_configure_mmu(ffa_id); |
| 407 | enable_mmu_el1(0); |
| 408 | |
J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 409 | if (ffa_id == SPM_VM_ID_FIRST) { |
Arunachalam Ganapathy | 51be1fe | 2020-09-22 13:25:21 +0100 | [diff] [blame] | 410 | console_init(CACTUS_PL011_UART_BASE, |
| 411 | CACTUS_PL011_UART_CLK_IN_HZ, |
| 412 | PL011_BAUDRATE); |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 413 | |
| 414 | set_putc_impl(PL011_AS_STDOUT); |
| 415 | |
| 416 | NOTICE("Booting Primary Cactus Secure Partition\n%s\n%s\n", |
| 417 | build_message, version_string); |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 418 | } else { |
J-Alves | 83ede9b | 2020-11-02 17:37:19 +0000 | [diff] [blame] | 419 | smc_ret_values ret; |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 420 | set_putc_impl(HVC_CALL_AS_STDOUT); |
| 421 | |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 422 | NOTICE("Booting Secondary Cactus Secure Partition (ID: %x)\n%s\n%s\n", |
Ruari Phipps | bd0a7e4 | 2020-07-17 16:42:21 +0100 | [diff] [blame] | 423 | ffa_id, build_message, version_string); |
| 424 | |
Olivier Deprez | 0be4abe | 2020-08-04 11:26:13 +0200 | [diff] [blame] | 425 | if (ffa_id == (SPM_VM_ID_FIRST + 2)) { |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 426 | VERBOSE("Mapping RXTX Region\n"); |
J-Alves | 83ede9b | 2020-11-02 17:37:19 +0000 | [diff] [blame] | 427 | CONFIGURE_AND_MAP_MAILBOX(mb, PAGE_SIZE, ret); |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 428 | if (ffa_func_id(ret) != FFA_SUCCESS_SMC32) { |
J-Alves | 83ede9b | 2020-11-02 17:37:19 +0000 | [diff] [blame] | 429 | ERROR( |
J-Alves | 6cb21d9 | 2021-01-07 15:18:12 +0000 | [diff] [blame^] | 430 | "Failed to map RXTX buffers. Error: %x\n", |
| 431 | ffa_error_code(ret)); |
Ruari Phipps | bd0a7e4 | 2020-07-17 16:42:21 +0100 | [diff] [blame] | 432 | panic(); |
| 433 | } |
Ruari Phipps | bd0a7e4 | 2020-07-17 16:42:21 +0100 | [diff] [blame] | 434 | } |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 435 | } |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 436 | |
Olivier Deprez | aed7f08 | 2020-11-04 15:11:59 +0100 | [diff] [blame] | 437 | INFO("FF-A id: %x\n", ffa_id); |
Manish Pandey | 26c6f81 | 2020-04-30 11:43:00 +0100 | [diff] [blame] | 438 | cactus_print_memory_layout(ffa_id); |
| 439 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 440 | /* Invoking Tests */ |
Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 441 | ffa_tests(&mb); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 442 | |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 443 | /* End up to message loop */ |
J-Alves | 63cdaa7 | 2020-10-08 17:22:45 +0100 | [diff] [blame] | 444 | message_loop(ffa_id, &mb); |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 445 | |
Olivier Deprez | afcdb7c | 2019-11-29 14:21:48 +0100 | [diff] [blame] | 446 | /* Not reached */ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 447 | } |