Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
| 2 | /* |
Imre Kis | 9757f6b | 2022-07-26 17:19:46 +0200 | [diff] [blame] | 3 | * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved. |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 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 | |
| 17 | uint16_t own_id = 0; /* !!Needs refactoring as parameter to ffarpc_caller_init */ |
| 18 | |
| 19 | |
| 20 | static int sp_init(uint16_t *own_sp_id); |
| 21 | |
| 22 | void __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); |
Imre Kis | d92645c | 2022-06-28 17:26:53 +0200 | [diff] [blame^] | 36 | ffa_call_ep_init(&ffarpc_call_ep, rpc_iface, own_id); |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 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 | |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 60 | sp_msg_send_direct_resp(&resp_msg, &req_msg); |
| 61 | } |
| 62 | |
| 63 | fatal_error: |
| 64 | /* SP is not viable */ |
| 65 | EMSG("SE proxy 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 | } |