blob: 155e948637a3ccdf9d25e6d26e2faa84fb675b16 [file] [log] [blame]
Julian Hall527ddd52021-06-28 11:57:17 +01001// SPDX-License-Identifier: BSD-3-Clause
2/*
Imre Kis9757f6b2022-07-26 17:19:46 +02003 * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
Julian Hall527ddd52021-06-28 11:57:17 +01004 */
5
Imre Kis16f07142023-07-05 18:15:07 +02006#include "components/rpc/common/endpoint/rpc_service_interface.h"
7#include "components/rpc/ts_rpc/endpoint/sp/ts_rpc_endpoint_sp.h"
Imre Kis6bf3de32022-07-05 16:43:55 +02008#include "config/ramstore/config_ramstore.h"
9#include "config/loader/sp/sp_config_loader.h"
10#include "sp_api.h"
11#include "sp_discovery.h"
12#include "sp_rxtx.h"
13#include "trace.h"
Julian Hall3d0ec042022-09-06 13:26:14 +010014#include "deployments/se-proxy/infra/service_proxy_factory.h"
15#include "deployments/se-proxy/se_proxy_interfaces.h"
Julian Hall527ddd52021-06-28 11:57:17 +010016
Imre Kis6bf3de32022-07-05 16:43:55 +020017static bool sp_init(uint16_t *own_sp_id);
Julian Hall527ddd52021-06-28 11:57:17 +010018
Balint Dobszay4f9d8e32023-04-13 13:55:08 +020019void __noreturn sp_main(union ffa_boot_info *boot_info)
Julian Hall527ddd52021-06-28 11:57:17 +010020{
Imre Kis16f07142023-07-05 18:15:07 +020021 struct ts_rpc_endpoint_sp rpc_endpoint = { 0 };
Imre Kis6bf3de32022-07-05 16:43:55 +020022 struct sp_msg req_msg = { 0 };
23 struct sp_msg resp_msg = { 0 };
Imre Kis16f07142023-07-05 18:15:07 +020024 struct rpc_service_interface *rpc_iface = NULL;
Imre Kisf6562652022-07-04 15:33:13 +020025 uint16_t own_id = 0;
Imre Kis6bf3de32022-07-05 16:43:55 +020026 sp_result result = SP_RESULT_INTERNAL_ERROR;
Imre Kis16f07142023-07-05 18:15:07 +020027 rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
Julian Hall527ddd52021-06-28 11:57:17 +010028
29 /* Boot phase */
Imre Kis6bf3de32022-07-05 16:43:55 +020030 if (!sp_init(&own_id)) {
31 EMSG("Failed to init SP");
32 goto fatal_error;
33 }
Julian Hall527ddd52021-06-28 11:57:17 +010034
35 config_ramstore_init();
Imre Kis6bf3de32022-07-05 16:43:55 +020036
Balint Dobszay4f9d8e32023-04-13 13:55:08 +020037 if (!sp_config_load(boot_info)) {
Imre Kis6bf3de32022-07-05 16:43:55 +020038 EMSG("Failed to load SP config");
39 goto fatal_error;
40 }
Julian Hall527ddd52021-06-28 11:57:17 +010041
Imre Kis16f07142023-07-05 18:15:07 +020042 rpc_status = ts_rpc_endpoint_sp_init(&rpc_endpoint, 4, 16);
43 if (rpc_status != RPC_SUCCESS) {
44 EMSG("Failed to initialize RPC endpoint: %d", rpc_status);
Imre Kis6bf3de32022-07-05 16:43:55 +020045 goto fatal_error;
46 }
47
Julian Hall527ddd52021-06-28 11:57:17 +010048 /* Create service proxies */
49 rpc_iface = its_proxy_create();
Imre Kis6bf3de32022-07-05 16:43:55 +020050 if (!rpc_iface) {
51 EMSG("Failed to create ITS proxy");
52 goto fatal_error;
53 }
54
Imre Kis16f07142023-07-05 18:15:07 +020055 rpc_status = ts_rpc_endpoint_sp_add_service(&rpc_endpoint, rpc_iface);
56 if (rpc_status != RPC_SUCCESS) {
57 EMSG("Failed to add service to RPC endpoint: %d", rpc_status);
58 goto fatal_error;
59 }
Julian Hall527ddd52021-06-28 11:57:17 +010060
61 rpc_iface = ps_proxy_create();
Imre Kis6bf3de32022-07-05 16:43:55 +020062 if (!rpc_iface) {
63 EMSG("Failed to create PS proxy");
64 goto fatal_error;
65 }
Imre Kis16f07142023-07-05 18:15:07 +020066
67 rpc_status = ts_rpc_endpoint_sp_add_service(&rpc_endpoint, rpc_iface);
68 if (rpc_status != RPC_SUCCESS) {
69 EMSG("Failed to add service to RPC endpoint: %d", rpc_status);
70 goto fatal_error;
71 }
Julian Hall527ddd52021-06-28 11:57:17 +010072
73 rpc_iface = crypto_proxy_create();
Imre Kis6bf3de32022-07-05 16:43:55 +020074 if (!rpc_iface) {
75 EMSG("Failed to create Crypto proxy");
76 goto fatal_error;
77 }
Imre Kis16f07142023-07-05 18:15:07 +020078
79 rpc_status = ts_rpc_endpoint_sp_add_service(&rpc_endpoint, rpc_iface);
80 if (rpc_status != RPC_SUCCESS) {
81 EMSG("Failed to add service to RPC endpoint: %d", rpc_status);
82 goto fatal_error;
83 }
Julian Hall527ddd52021-06-28 11:57:17 +010084
85 rpc_iface = attest_proxy_create();
Imre Kis6bf3de32022-07-05 16:43:55 +020086 if (!rpc_iface) {
87 EMSG("Failed to create Attestation proxy");
88 goto fatal_error;
89 }
Imre Kis16f07142023-07-05 18:15:07 +020090
91 rpc_status = ts_rpc_endpoint_sp_add_service(&rpc_endpoint, rpc_iface);
92 if (rpc_status != RPC_SUCCESS) {
93 EMSG("Failed to add service to RPC endpoint: %d", rpc_status);
94 goto fatal_error;
95 }
Julian Hall527ddd52021-06-28 11:57:17 +010096
97 /* End of boot phase */
Imre Kis6bf3de32022-07-05 16:43:55 +020098 result = sp_msg_wait(&req_msg);
99 if (result != SP_RESULT_OK) {
100 EMSG("Failed to send message wait %d", result);
101 goto fatal_error;
102 }
Julian Hall527ddd52021-06-28 11:57:17 +0100103
104 while (1) {
Imre Kis16f07142023-07-05 18:15:07 +0200105 ts_rpc_endpoint_sp_receive(&rpc_endpoint, &req_msg, &resp_msg);
Julian Hall527ddd52021-06-28 11:57:17 +0100106
Imre Kis6bf3de32022-07-05 16:43:55 +0200107 result = sp_msg_send_direct_resp(&resp_msg, &req_msg);
108 if (result != SP_RESULT_OK) {
109 EMSG("Failed to send direct response %d", result);
110 result = sp_msg_wait(&req_msg);
111 if (result != SP_RESULT_OK) {
112 EMSG("Failed to send message wait %d", result);
113 goto fatal_error;
114 }
115 }
Julian Hall527ddd52021-06-28 11:57:17 +0100116 }
117
118fatal_error:
119 /* SP is not viable */
120 EMSG("SE proxy SP error");
121 while (1) {}
122}
123
124void sp_interrupt_handler(uint32_t interrupt_id)
125{
126 (void)interrupt_id;
127}
128
Imre Kis6bf3de32022-07-05 16:43:55 +0200129static bool sp_init(uint16_t *own_id)
Julian Hall527ddd52021-06-28 11:57:17 +0100130{
Imre Kis6bf3de32022-07-05 16:43:55 +0200131 sp_result sp_res = SP_RESULT_INTERNAL_ERROR;
Julian Hall527ddd52021-06-28 11:57:17 +0100132 static uint8_t tx_buffer[4096] __aligned(4096);
133 static uint8_t rx_buffer[4096] __aligned(4096);
134
135 sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
Imre Kis6bf3de32022-07-05 16:43:55 +0200136 if (sp_res != SP_RESULT_OK) {
137 EMSG("Failed to map RXTX buffers: %d", sp_res);
138 return false;
Julian Hall527ddd52021-06-28 11:57:17 +0100139 }
140
Imre Kis6bf3de32022-07-05 16:43:55 +0200141 sp_res = sp_discovery_own_id_get(own_id);
142 if (sp_res != SP_RESULT_OK) {
143 EMSG("Failed to query own ID: %d", sp_res);
144 return false;
145 }
146
147 return true;
Julian Hall527ddd52021-06-28 11:57:17 +0100148}