blob: 3df4c1adbcf008afd775fa1aee1706eca3bd8613 [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;
31 struct ffa_direct_msg req_msg;
32
33 /* Boot */
34 (void) init_info;
35
36 if (sp_init(&own_id) != 0) goto fatal_error;
37
julhal0137e1aea2021-02-09 15:22:20 +000038 config_ramstore_init();
39 sp_config_load(init_info);
julhal013ec4c322021-02-05 17:30:49 +000040
41 /* Initialize the test_runner service */
42 test_runner_iface = test_runner_provider_init(&test_runner_provider);
43
44 test_runner_provider_register_serializer(&test_runner_provider,
45 TS_RPC_ENCODING_PACKED_C, packedc_test_runner_provider_serializer_instance());
46
julhal0137e1aea2021-02-09 15:22:20 +000047 env_test_register_tests(&test_runner_provider);
48
julhal013ec4c322021-02-05 17:30:49 +000049 ffa_call_ep_init(&ffarpc_call_ep, test_runner_iface);
50
51 /* End of boot phase */
52 ffa_msg_wait(&req_msg);
53
54 while (1) {
55 if (req_msg.function_id == FFA_MSG_SEND_DIRECT_REQ_32) {
56
57 struct ffa_direct_msg resp_msg;
58
59 ffa_call_ep_receive(&ffarpc_call_ep, &req_msg, &resp_msg);
60
61 ffa_msg_send_direct_resp(req_msg.destination_id,
62 req_msg.source_id, resp_msg.args[0], resp_msg.args[1],
63 resp_msg.args[2], resp_msg.args[3], resp_msg.args[4],
64 &req_msg);
65 }
66 }
67
68fatal_error:
69 /* SP is not viable */
70 EMSG("environment-test SP error");
71 while (1) {}
72}
73
74void sp_interrupt_handler(uint32_t interrupt_id)
75{
76 (void)interrupt_id;
77}
78
79static int sp_init(uint16_t *own_sp_id)
80{
81 int status = -1;
82 ffa_result ffa_res;
83 sp_result sp_res;
84 static uint8_t tx_buffer[4096] __aligned(4096);
85 static uint8_t rx_buffer[4096] __aligned(4096);
86
87 sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
88 if (sp_res == SP_RESULT_OK) {
89 ffa_res = ffa_id_get(own_sp_id);
90 if (ffa_res == FFA_OK) {
91 status = 0;
92 }
93 }
94
95 return status;
96}