blob: 78c439fc19a869129b84773b2c6e2cdc344eb115 [file] [log] [blame]
julhal013ec4c322021-02-05 17:30:49 +00001// 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>
julhal0137e1aea2021-02-09 15:22:20 +000011#include <config/ramstore/config_ramstore.h>
12#include <config/loader/sp/sp_config_loader.h>
julhal013ec4c322021-02-05 17:30:49 +000013#include <ffa_api.h>
14#include <sp_api.h>
15#include <sp_rxtx.h>
16#include <trace.h>
julhal0137e1aea2021-02-09 15:22:20 +000017#include "env_test_tests.h"
julhal013ec4c322021-02-05 17:30:49 +000018
19
20uint16_t own_id = 0; /* !!Needs refactoring as parameter to ffarpc_caller_init */
21
22
23static int sp_init(uint16_t *own_sp_id);
24
25void __noreturn sp_main(struct ffa_init_info *init_info)
26{
27 struct test_runner_provider test_runner_provider;
28 struct ffa_call_ep ffarpc_call_ep;
29 struct rpc_interface *test_runner_iface;
30 struct ffarpc_caller ffarpc_caller;
Julian Hall22c47a92021-07-09 14:49:16 +010031 struct sp_msg req_msg;
julhal013ec4c322021-02-05 17:30:49 +000032
33 /* Boot */
julhal013ec4c322021-02-05 17:30:49 +000034 if (sp_init(&own_id) != 0) goto fatal_error;
35
julhal0137e1aea2021-02-09 15:22:20 +000036 config_ramstore_init();
37 sp_config_load(init_info);
julhal013ec4c322021-02-05 17:30:49 +000038
39 /* Initialize the test_runner service */
40 test_runner_iface = test_runner_provider_init(&test_runner_provider);
41
42 test_runner_provider_register_serializer(&test_runner_provider,
Julian Hall7048d302021-06-03 16:07:28 +010043 TS_RPC_ENCODING_PACKED_C, packedc_test_runner_provider_serializer_instance());
julhal013ec4c322021-02-05 17:30:49 +000044
julhal0137e1aea2021-02-09 15:22:20 +000045 env_test_register_tests(&test_runner_provider);
46
julhal013ec4c322021-02-05 17:30:49 +000047 ffa_call_ep_init(&ffarpc_call_ep, test_runner_iface);
48
49 /* End of boot phase */
Julian Hall22c47a92021-07-09 14:49:16 +010050 sp_msg_wait(&req_msg);
julhal013ec4c322021-02-05 17:30:49 +000051
52 while (1) {
julhal013ec4c322021-02-05 17:30:49 +000053
Julian Hall22c47a92021-07-09 14:49:16 +010054 struct sp_msg resp_msg;
julhal013ec4c322021-02-05 17:30:49 +000055
Julian Hall22c47a92021-07-09 14:49:16 +010056 ffa_call_ep_receive(&ffarpc_call_ep, &req_msg, &resp_msg);
julhal013ec4c322021-02-05 17:30:49 +000057
Julian Hall22c47a92021-07-09 14:49:16 +010058 resp_msg.source_id = req_msg.destination_id;
59 resp_msg.destination_id = req_msg.source_id;
60
61 sp_msg_send_direct_resp(&resp_msg, &req_msg);
julhal013ec4c322021-02-05 17:30:49 +000062 }
63
64fatal_error:
65 /* SP is not viable */
66 EMSG("environment-test SP error");
67 while (1) {}
68}
69
70void sp_interrupt_handler(uint32_t interrupt_id)
71{
72 (void)interrupt_id;
73}
74
75static int sp_init(uint16_t *own_sp_id)
76{
77 int status = -1;
78 ffa_result ffa_res;
79 sp_result sp_res;
80 static uint8_t tx_buffer[4096] __aligned(4096);
81 static uint8_t rx_buffer[4096] __aligned(4096);
82
83 sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
84 if (sp_res == SP_RESULT_OK) {
85 ffa_res = ffa_id_get(own_sp_id);
86 if (ffa_res == FFA_OK) {
87 status = 0;
88 }
89 }
90
91 return status;
92}