julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
| 2 | /* |
Imre Kis | d92645c | 2022-06-28 17:26:53 +0200 | [diff] [blame] | 3 | * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved. |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Imre Kis | 4fe0c10 | 2023-07-05 18:14:21 +0200 | [diff] [blame] | 6 | #include "components/rpc/common/endpoint/rpc_service_interface.h" |
| 7 | #include "components/rpc/ts_rpc/endpoint/sp/ts_rpc_endpoint_sp.h" |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 8 | #include "service/test_runner/provider/test_runner_provider.h" |
| 9 | #include "service/test_runner/provider/serializer/packed-c/packedc_test_runner_provider_serializer.h" |
| 10 | #include "protocols/rpc/common/packed-c/status.h" |
| 11 | #include "config/ramstore/config_ramstore.h" |
| 12 | #include "config/loader/sp/sp_config_loader.h" |
| 13 | #include "ffa_api.h" |
| 14 | #include "sp_api.h" |
| 15 | #include "sp_discovery.h" |
| 16 | #include "sp_rxtx.h" |
| 17 | #include "trace.h" |
Julian Hall | 2feec56 | 2022-09-07 09:22:45 +0100 | [diff] [blame] | 18 | #include "deployments/env-test/suites/registration/env_test_register.h" |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 19 | |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 20 | static bool sp_init(uint16_t *own_sp_id); |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 21 | |
Balint Dobszay | 4f9d8e3 | 2023-04-13 13:55:08 +0200 | [diff] [blame] | 22 | void __noreturn sp_main(union ffa_boot_info *boot_info) |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 23 | { |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 24 | struct test_runner_provider test_runner_provider = { 0 }; |
Imre Kis | 4fe0c10 | 2023-07-05 18:14:21 +0200 | [diff] [blame] | 25 | struct ts_rpc_endpoint_sp rpc_endpoint = { 0 }; |
| 26 | struct rpc_service_interface *test_runner_iface = NULL; |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 27 | struct sp_msg req_msg = { 0 }; |
| 28 | struct sp_msg resp_msg = { 0 }; |
Imre Kis | f656265 | 2022-07-04 15:33:13 +0200 | [diff] [blame] | 29 | uint16_t own_id = 0; |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 30 | sp_result result = SP_RESULT_INTERNAL_ERROR; |
Imre Kis | 4fe0c10 | 2023-07-05 18:14:21 +0200 | [diff] [blame] | 31 | rpc_status_t rpc_status = RPC_ERROR_INTERNAL; |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 32 | |
| 33 | /* Boot */ |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 34 | if (!sp_init(&own_id)) { |
| 35 | EMSG("Failed to init SP"); |
| 36 | goto fatal_error; |
| 37 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 38 | |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 39 | config_ramstore_init(); |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 40 | |
Balint Dobszay | 4f9d8e3 | 2023-04-13 13:55:08 +0200 | [diff] [blame] | 41 | if (!sp_config_load(boot_info)) { |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 42 | EMSG("Failed to load SP config"); |
| 43 | goto fatal_error; |
| 44 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 45 | |
| 46 | /* Initialize the test_runner service */ |
| 47 | test_runner_iface = test_runner_provider_init(&test_runner_provider); |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 48 | if (!test_runner_iface) { |
| 49 | EMSG("Failed to initialize test runner provider"); |
| 50 | goto fatal_error; |
| 51 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 52 | |
| 53 | test_runner_provider_register_serializer(&test_runner_provider, |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame] | 54 | TS_RPC_ENCODING_PACKED_C, packedc_test_runner_provider_serializer_instance()); |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 55 | |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 56 | env_test_register_tests(&test_runner_provider); |
| 57 | |
Imre Kis | 4fe0c10 | 2023-07-05 18:14:21 +0200 | [diff] [blame] | 58 | rpc_status = ts_rpc_endpoint_sp_init(&rpc_endpoint, 1, 16); |
| 59 | if (rpc_status != RPC_SUCCESS) { |
| 60 | EMSG("Failed to initialize RPC endpoint: %d", rpc_status); |
| 61 | goto fatal_error; |
| 62 | } |
| 63 | |
| 64 | rpc_status = ts_rpc_endpoint_sp_add_service(&rpc_endpoint, test_runner_iface); |
| 65 | if (rpc_status != RPC_SUCCESS) { |
| 66 | EMSG("Failed to add service to RPC endpoint: %d", rpc_status); |
| 67 | goto fatal_error; |
| 68 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 69 | |
| 70 | /* End of boot phase */ |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 71 | result = sp_msg_wait(&req_msg); |
| 72 | if (result != SP_RESULT_OK) { |
| 73 | EMSG("Failed to send message wait %d", result); |
| 74 | goto fatal_error; |
| 75 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 76 | |
| 77 | while (1) { |
Imre Kis | 4fe0c10 | 2023-07-05 18:14:21 +0200 | [diff] [blame] | 78 | ts_rpc_endpoint_sp_receive(&rpc_endpoint, &req_msg, &resp_msg); |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 79 | |
Julian Hall | 22c47a9 | 2021-07-09 14:49:16 +0100 | [diff] [blame] | 80 | resp_msg.source_id = req_msg.destination_id; |
| 81 | resp_msg.destination_id = req_msg.source_id; |
| 82 | |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 83 | result = sp_msg_send_direct_resp(&resp_msg, &req_msg); |
| 84 | if (result != SP_RESULT_OK) { |
| 85 | EMSG("Failed to send direct response %d", result); |
| 86 | result = sp_msg_wait(&req_msg); |
| 87 | if (result != SP_RESULT_OK) { |
| 88 | EMSG("Failed to send message wait %d", result); |
| 89 | goto fatal_error; |
| 90 | } |
| 91 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | fatal_error: |
| 95 | /* SP is not viable */ |
| 96 | EMSG("environment-test SP error"); |
| 97 | while (1) {} |
| 98 | } |
| 99 | |
| 100 | void sp_interrupt_handler(uint32_t interrupt_id) |
| 101 | { |
| 102 | (void)interrupt_id; |
| 103 | } |
| 104 | |
Balint Dobszay | ac721da | 2024-07-02 16:33:59 +0200 | [diff] [blame] | 105 | ffa_result ffa_vm_created_handler(uint16_t vm_id, uint64_t handle) |
| 106 | { |
| 107 | (void)vm_id; |
| 108 | (void)handle; |
| 109 | |
| 110 | return FFA_OK; |
| 111 | } |
| 112 | |
| 113 | ffa_result ffa_vm_destroyed_handler(uint16_t vm_id, uint64_t handle) |
| 114 | { |
| 115 | (void)vm_id; |
| 116 | (void)handle; |
| 117 | |
| 118 | return FFA_OK; |
| 119 | } |
| 120 | |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 121 | static bool sp_init(uint16_t *own_id) |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 122 | { |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 123 | sp_result sp_res = SP_RESULT_INTERNAL_ERROR; |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 124 | static uint8_t tx_buffer[4096] __aligned(4096); |
| 125 | static uint8_t rx_buffer[4096] __aligned(4096); |
| 126 | |
| 127 | sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer)); |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 128 | if (sp_res != SP_RESULT_OK) { |
| 129 | EMSG("Failed to map RXTX buffers: %d", sp_res); |
| 130 | return false; |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 133 | sp_res = sp_discovery_own_id_get(own_id); |
| 134 | if (sp_res != SP_RESULT_OK) { |
| 135 | EMSG("Failed to query own ID: %d", sp_res); |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | return true; |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 140 | } |