blob: 6f138850b4a3f15eb1e596ab513250a9ed9d1458 [file] [log] [blame]
Julian Hallead5b622021-11-23 17:31:07 +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 <deployments/smm-gateway/smm_gateway.h>
8#include <config/ramstore/config_ramstore.h>
Imre Kisee70c1a2021-10-27 20:41:01 +02009#include "config/interface/config_store.h"
Julian Hallead5b622021-11-23 17:31:07 +010010#include <config/loader/sp/sp_config_loader.h>
Imre Kisee70c1a2021-10-27 20:41:01 +020011#include "components/rpc/mm_communicate/endpoint/sp/mm_communicate_call_ep.h"
12#include "components/service/smm_variable/frontend/mm_communicate/smm_variable_mm_service.h"
13#include "platform/interface/memory_region.h"
Julian Hallead5b622021-11-23 17:31:07 +010014#include <ffa_api.h>
15#include <sp_api.h>
16#include <sp_messaging.h>
17#include <sp_rxtx.h>
18#include <trace.h>
19
Imre Kisee70c1a2021-10-27 20:41:01 +020020#define CONFIG_NAME_MM_COMM_BUFFER_REGION "mm-comm-buffer"
Julian Hallead5b622021-11-23 17:31:07 +010021
22uint16_t own_id = 0; /* !!Needs refactoring as parameter to ffarpc_caller_init */
23
Julian Hallead5b622021-11-23 17:31:07 +010024static int sp_init(uint16_t *own_sp_id);
25
26void __noreturn sp_main(struct ffa_init_info *init_info)
27{
Imre Kisee70c1a2021-10-27 20:41:01 +020028 struct memory_region mm_comm_buffer_region = { 0 };
29 struct rpc_interface *gateway_iface = NULL;
30 struct smm_variable_mm_service smm_var_service = { 0 };
31 struct mm_service_interface *smm_var_service_interface = NULL;
32 struct mm_communicate_ep mm_communicate_call_ep = { 0 };
33 struct ffa_direct_msg req_msg = { 0 };
34 struct ffa_direct_msg resp_msg = { 0 };
35
36 static const EFI_GUID smm_variable_guid = SMM_VARIABLE_GUID;
Julian Hallead5b622021-11-23 17:31:07 +010037
38 /* Boot phase */
39 if (sp_init(&own_id) != 0) goto fatal_error;
40
41 /* Load any dynamic configuration */
42 config_ramstore_init();
43 sp_config_load(init_info);
44
Imre Kisee70c1a2021-10-27 20:41:01 +020045 if (!config_store_query(CONFIG_CLASSIFIER_MEMORY_REGION, CONFIG_NAME_MM_COMM_BUFFER_REGION,
46 0, &mm_comm_buffer_region, sizeof(mm_comm_buffer_region))) {
47 EMSG(CONFIG_NAME_MM_COMM_BUFFER_REGION " is not set in SP configuration");
48 goto fatal_error;
49 }
50
Julian Hallead5b622021-11-23 17:31:07 +010051 /* Initialize service layer and associate with RPC endpoint */
Imre Kisee70c1a2021-10-27 20:41:01 +020052 gateway_iface = smm_gateway_create(own_id);
53
54 /* Initialize SMM variable MM service */
55 smm_var_service_interface = smm_variable_mm_service_init(&smm_var_service, gateway_iface);
56
57 /* Initialize MM communication layer */
58 if (!mm_communicate_call_ep_init(&mm_communicate_call_ep,
59 (void *)mm_comm_buffer_region.base_addr,
60 mm_comm_buffer_region.region_size))
61 goto fatal_error;
62
63 /* Attach SMM variable service to MM communication layer */
64 mm_communicate_call_ep_attach_service(&mm_communicate_call_ep, &smm_variable_guid,
65 smm_var_service_interface);
Julian Hallead5b622021-11-23 17:31:07 +010066
67 /* End of boot phase */
Imre Kisee70c1a2021-10-27 20:41:01 +020068 ffa_msg_wait(&req_msg);
Julian Hallead5b622021-11-23 17:31:07 +010069
70 while (1) {
Imre Kisee70c1a2021-10-27 20:41:01 +020071 mm_communicate_call_ep_receive(&mm_communicate_call_ep, &req_msg, &resp_msg);
Julian Hallead5b622021-11-23 17:31:07 +010072
Imre Kisee70c1a2021-10-27 20:41:01 +020073 ffa_msg_send_direct_resp(req_msg.destination_id,
74 req_msg.source_id, resp_msg.args[0],
75 resp_msg.args[1], resp_msg.args[2],
76 resp_msg.args[3], resp_msg.args[4],
77 &req_msg);
Julian Hallead5b622021-11-23 17:31:07 +010078 }
79
80fatal_error:
81 /* SP is not viable */
82 EMSG("SMM gateway SP error");
83 while (1) {}
84}
85
86void sp_interrupt_handler(uint32_t interrupt_id)
87{
88 (void)interrupt_id;
89}
90
91static int sp_init(uint16_t *own_sp_id)
92{
93 int status = -1;
94 ffa_result ffa_res;
95 sp_result sp_res;
96 static uint8_t tx_buffer[4096] __aligned(4096);
97 static uint8_t rx_buffer[4096] __aligned(4096);
98
99 sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
100 if (sp_res == SP_RESULT_OK) {
101 ffa_res = ffa_id_get(own_sp_id);
102 if (ffa_res == FFA_OK) {
103 status = 0;
104 }
105 }
106
107 return status;
108}