julhal01 | 3ec4c32 | 2021-02-05 17:30:49 +0000 | [diff] [blame^] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
| 2 | /* |
| 3 | * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #include <rpc/ffarpc/caller/sp/ffarpc_caller.h> |
| 7 | #include <rpc/ffarpc/endpoint/ffarpc_call_ep.h> |
| 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 <ffa_api.h> |
| 12 | #include <sp_api.h> |
| 13 | #include <sp_rxtx.h> |
| 14 | #include <trace.h> |
| 15 | #include "env_test_config.h" |
| 16 | |
| 17 | |
| 18 | uint16_t own_id = 0; /* !!Needs refactoring as parameter to ffarpc_caller_init */ |
| 19 | |
| 20 | |
| 21 | static int sp_init(uint16_t *own_sp_id); |
| 22 | |
| 23 | void __noreturn sp_main(struct ffa_init_info *init_info) |
| 24 | { |
| 25 | struct test_runner_provider test_runner_provider; |
| 26 | struct ffa_call_ep ffarpc_call_ep; |
| 27 | struct rpc_interface *test_runner_iface; |
| 28 | struct ffarpc_caller ffarpc_caller; |
| 29 | struct ffa_direct_msg req_msg; |
| 30 | |
| 31 | /* Boot */ |
| 32 | (void) init_info; |
| 33 | |
| 34 | if (sp_init(&own_id) != 0) goto fatal_error; |
| 35 | |
| 36 | load_sp_config(init_info); |
| 37 | |
| 38 | /* Initialize the test_runner service */ |
| 39 | test_runner_iface = test_runner_provider_init(&test_runner_provider); |
| 40 | |
| 41 | test_runner_provider_register_serializer(&test_runner_provider, |
| 42 | TS_RPC_ENCODING_PACKED_C, packedc_test_runner_provider_serializer_instance()); |
| 43 | |
| 44 | ffa_call_ep_init(&ffarpc_call_ep, test_runner_iface); |
| 45 | |
| 46 | /* End of boot phase */ |
| 47 | ffa_msg_wait(&req_msg); |
| 48 | |
| 49 | while (1) { |
| 50 | if (req_msg.function_id == FFA_MSG_SEND_DIRECT_REQ_32) { |
| 51 | |
| 52 | struct ffa_direct_msg resp_msg; |
| 53 | |
| 54 | ffa_call_ep_receive(&ffarpc_call_ep, &req_msg, &resp_msg); |
| 55 | |
| 56 | ffa_msg_send_direct_resp(req_msg.destination_id, |
| 57 | req_msg.source_id, resp_msg.args[0], resp_msg.args[1], |
| 58 | resp_msg.args[2], resp_msg.args[3], resp_msg.args[4], |
| 59 | &req_msg); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | fatal_error: |
| 64 | /* SP is not viable */ |
| 65 | EMSG("environment-test SP error"); |
| 66 | while (1) {} |
| 67 | } |
| 68 | |
| 69 | void sp_interrupt_handler(uint32_t interrupt_id) |
| 70 | { |
| 71 | (void)interrupt_id; |
| 72 | } |
| 73 | |
| 74 | static int sp_init(uint16_t *own_sp_id) |
| 75 | { |
| 76 | int status = -1; |
| 77 | ffa_result ffa_res; |
| 78 | sp_result sp_res; |
| 79 | static uint8_t tx_buffer[4096] __aligned(4096); |
| 80 | static uint8_t rx_buffer[4096] __aligned(4096); |
| 81 | |
| 82 | sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer)); |
| 83 | if (sp_res == SP_RESULT_OK) { |
| 84 | ffa_res = ffa_id_get(own_sp_id); |
| 85 | if (ffa_res == FFA_OK) { |
| 86 | status = 0; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | return status; |
| 91 | } |