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 | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 6 | #include "rpc/ffarpc/endpoint/ffarpc_call_ep.h" |
| 7 | #include "service/test_runner/provider/test_runner_provider.h" |
| 8 | #include "service/test_runner/provider/serializer/packed-c/packedc_test_runner_provider_serializer.h" |
| 9 | #include "protocols/rpc/common/packed-c/status.h" |
| 10 | #include "config/ramstore/config_ramstore.h" |
| 11 | #include "config/loader/sp/sp_config_loader.h" |
| 12 | #include "ffa_api.h" |
| 13 | #include "sp_api.h" |
| 14 | #include "sp_discovery.h" |
| 15 | #include "sp_rxtx.h" |
| 16 | #include "trace.h" |
Julian Hall | 2feec56 | 2022-09-07 09:22:45 +0100 | [diff] [blame] | 17 | #include "deployments/env-test/suites/registration/env_test_register.h" |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 18 | |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 19 | static bool sp_init(uint16_t *own_sp_id); |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 20 | |
| 21 | void __noreturn sp_main(struct ffa_init_info *init_info) |
| 22 | { |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 23 | struct test_runner_provider test_runner_provider = { 0 }; |
| 24 | struct ffa_call_ep ffarpc_call_ep = { 0 }; |
| 25 | struct rpc_interface *test_runner_iface = NULL; |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 26 | struct sp_msg req_msg = { 0 }; |
| 27 | struct sp_msg resp_msg = { 0 }; |
Imre Kis | f656265 | 2022-07-04 15:33:13 +0200 | [diff] [blame] | 28 | uint16_t own_id = 0; |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 29 | sp_result result = SP_RESULT_INTERNAL_ERROR; |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 30 | |
| 31 | /* Boot */ |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 32 | if (!sp_init(&own_id)) { |
| 33 | EMSG("Failed to init SP"); |
| 34 | goto fatal_error; |
| 35 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 36 | |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 37 | config_ramstore_init(); |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 38 | |
| 39 | if (!sp_config_load(init_info)) { |
| 40 | EMSG("Failed to load SP config"); |
| 41 | goto fatal_error; |
| 42 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 43 | |
| 44 | /* Initialize the test_runner service */ |
| 45 | test_runner_iface = test_runner_provider_init(&test_runner_provider); |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 46 | if (!test_runner_iface) { |
| 47 | EMSG("Failed to initialize test runner provider"); |
| 48 | goto fatal_error; |
| 49 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 50 | |
| 51 | test_runner_provider_register_serializer(&test_runner_provider, |
Julian Hall | 7048d30 | 2021-06-03 16:07:28 +0100 | [diff] [blame] | 52 | TS_RPC_ENCODING_PACKED_C, packedc_test_runner_provider_serializer_instance()); |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 53 | |
julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 54 | env_test_register_tests(&test_runner_provider); |
| 55 | |
Imre Kis | d92645c | 2022-06-28 17:26:53 +0200 | [diff] [blame] | 56 | ffa_call_ep_init(&ffarpc_call_ep, test_runner_iface, own_id); |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 57 | |
| 58 | /* End of boot phase */ |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 59 | result = sp_msg_wait(&req_msg); |
| 60 | if (result != SP_RESULT_OK) { |
| 61 | EMSG("Failed to send message wait %d", result); |
| 62 | goto fatal_error; |
| 63 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 64 | |
| 65 | while (1) { |
Julian Hall | 22c47a9 | 2021-07-09 14:49:16 +0100 | [diff] [blame] | 66 | ffa_call_ep_receive(&ffarpc_call_ep, &req_msg, &resp_msg); |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 67 | |
Julian Hall | 22c47a9 | 2021-07-09 14:49:16 +0100 | [diff] [blame] | 68 | resp_msg.source_id = req_msg.destination_id; |
| 69 | resp_msg.destination_id = req_msg.source_id; |
| 70 | |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 71 | result = sp_msg_send_direct_resp(&resp_msg, &req_msg); |
| 72 | if (result != SP_RESULT_OK) { |
| 73 | EMSG("Failed to send direct response %d", result); |
| 74 | result = sp_msg_wait(&req_msg); |
| 75 | if (result != SP_RESULT_OK) { |
| 76 | EMSG("Failed to send message wait %d", result); |
| 77 | goto fatal_error; |
| 78 | } |
| 79 | } |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | fatal_error: |
| 83 | /* SP is not viable */ |
| 84 | EMSG("environment-test SP error"); |
| 85 | while (1) {} |
| 86 | } |
| 87 | |
| 88 | void sp_interrupt_handler(uint32_t interrupt_id) |
| 89 | { |
| 90 | (void)interrupt_id; |
| 91 | } |
| 92 | |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 93 | static bool sp_init(uint16_t *own_id) |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 94 | { |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 95 | sp_result sp_res = SP_RESULT_INTERNAL_ERROR; |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 96 | static uint8_t tx_buffer[4096] __aligned(4096); |
| 97 | static uint8_t rx_buffer[4096] __aligned(4096); |
| 98 | |
| 99 | 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] | 100 | if (sp_res != SP_RESULT_OK) { |
| 101 | EMSG("Failed to map RXTX buffers: %d", sp_res); |
| 102 | return false; |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Imre Kis | 2453136 | 2022-07-05 16:43:28 +0200 | [diff] [blame] | 105 | sp_res = sp_discovery_own_id_get(own_id); |
| 106 | if (sp_res != SP_RESULT_OK) { |
| 107 | EMSG("Failed to query own ID: %d", sp_res); |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | return true; |
julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame] | 112 | } |