blob: ef90d9eee4f0b5e20724b2ce2619b8e4af08b2fe [file] [log] [blame]
Julian Hall527ddd52021-06-28 11:57:17 +01001// SPDX-License-Identifier: BSD-3-Clause
2/*
3 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
4 */
5
6#include <rpc/ffarpc/endpoint/ffarpc_call_ep.h>
7#include <rpc/common/demux/rpc_demux.h>
8#include <config/ramstore/config_ramstore.h>
9#include <config/loader/sp/sp_config_loader.h>
10#include <ffa_api.h>
11#include <sp_api.h>
12#include <sp_rxtx.h>
13#include <trace.h>
14#include "service_proxy_factory.h"
15#include "../se_proxy_interfaces.h"
16
17uint16_t own_id = 0; /* !!Needs refactoring as parameter to ffarpc_caller_init */
18
19
20static int sp_init(uint16_t *own_sp_id);
21
22void __noreturn sp_main(struct ffa_init_info *init_info)
23{
24 struct ffa_call_ep ffarpc_call_ep;
25 struct sp_msg req_msg;
26 struct rpc_demux rpc_demux;
27 struct rpc_interface *rpc_iface;
28
29 /* Boot phase */
30 if (sp_init(&own_id) != 0) goto fatal_error;
31
32 config_ramstore_init();
33 sp_config_load(init_info);
34
35 rpc_iface = rpc_demux_init(&rpc_demux);
36 ffa_call_ep_init(&ffarpc_call_ep, rpc_iface);
37
38 /* Create service proxies */
39 rpc_iface = its_proxy_create();
40 rpc_demux_attach(&rpc_demux, SE_PROXY_INTERFACE_ID_ITS, rpc_iface);
41
42 rpc_iface = ps_proxy_create();
43 rpc_demux_attach(&rpc_demux, SE_PROXY_INTERFACE_ID_PS, rpc_iface);
44
45 rpc_iface = crypto_proxy_create();
46 rpc_demux_attach(&rpc_demux, SE_PROXY_INTERFACE_ID_CRYPTO, rpc_iface);
47
48 rpc_iface = attest_proxy_create();
49 rpc_demux_attach(&rpc_demux, SE_PROXY_INTERFACE_ID_ATTEST, rpc_iface);
50
51 /* End of boot phase */
52 sp_msg_wait(&req_msg);
53
54 while (1) {
55
56 struct sp_msg resp_msg;
57
58 ffa_call_ep_receive(&ffarpc_call_ep, &req_msg, &resp_msg);
59
60 resp_msg.source_id = req_msg.destination_id;
61 resp_msg.destination_id = req_msg.source_id;
62
63 sp_msg_send_direct_resp(&resp_msg, &req_msg);
64 }
65
66fatal_error:
67 /* SP is not viable */
68 EMSG("SE proxy SP error");
69 while (1) {}
70}
71
72void sp_interrupt_handler(uint32_t interrupt_id)
73{
74 (void)interrupt_id;
75}
76
77static int sp_init(uint16_t *own_sp_id)
78{
79 int status = -1;
80 ffa_result ffa_res;
81 sp_result sp_res;
82 static uint8_t tx_buffer[4096] __aligned(4096);
83 static uint8_t rx_buffer[4096] __aligned(4096);
84
85 sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
86 if (sp_res == SP_RESULT_OK) {
87 ffa_res = ffa_id_get(own_sp_id);
88 if (ffa_res == FFA_OK) {
89 status = 0;
90 }
91 }
92
93 return status;
94}