blob: 3062877f94ec20db7002d289ffb7e383a29c525a [file] [log] [blame]
Julian Hallead5b622021-11-23 17:31:07 +01001// SPDX-License-Identifier: BSD-3-Clause
2/*
Imre Kisd0ed5c22021-12-15 17:05:47 +01003 * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
Julian Hallead5b622021-11-23 17:31:07 +01004 */
5
6#include <rpc/ffarpc/endpoint/ffarpc_call_ep.h>
Imre Kisd0ed5c22021-12-15 17:05:47 +01007#include "smm_gateway.h"
Julian Hallead5b622021-11-23 17:31:07 +01008#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"
Imre Kise700cb12022-07-20 15:19:17 +020014#include "protocols/common/mm/mm_smc.h"
Julian Hallead5b622021-11-23 17:31:07 +010015#include <ffa_api.h>
16#include <sp_api.h>
17#include <sp_messaging.h>
18#include <sp_rxtx.h>
19#include <trace.h>
20
Imre Kisee70c1a2021-10-27 20:41:01 +020021#define CONFIG_NAME_MM_COMM_BUFFER_REGION "mm-comm-buffer"
Julian Hallead5b622021-11-23 17:31:07 +010022
23uint16_t own_id = 0; /* !!Needs refactoring as parameter to ffarpc_caller_init */
24
Julian Hallead5b622021-11-23 17:31:07 +010025static int sp_init(uint16_t *own_sp_id);
26
27void __noreturn sp_main(struct ffa_init_info *init_info)
28{
Imre Kisee70c1a2021-10-27 20:41:01 +020029 struct memory_region mm_comm_buffer_region = { 0 };
30 struct rpc_interface *gateway_iface = NULL;
31 struct smm_variable_mm_service smm_var_service = { 0 };
32 struct mm_service_interface *smm_var_service_interface = NULL;
33 struct mm_communicate_ep mm_communicate_call_ep = { 0 };
34 struct ffa_direct_msg req_msg = { 0 };
35 struct ffa_direct_msg resp_msg = { 0 };
36
37 static const EFI_GUID smm_variable_guid = SMM_VARIABLE_GUID;
Julian Hallead5b622021-11-23 17:31:07 +010038
39 /* Boot phase */
40 if (sp_init(&own_id) != 0) goto fatal_error;
41
42 /* Load any dynamic configuration */
43 config_ramstore_init();
44 sp_config_load(init_info);
45
Imre Kisee70c1a2021-10-27 20:41:01 +020046 if (!config_store_query(CONFIG_CLASSIFIER_MEMORY_REGION, CONFIG_NAME_MM_COMM_BUFFER_REGION,
47 0, &mm_comm_buffer_region, sizeof(mm_comm_buffer_region))) {
48 EMSG(CONFIG_NAME_MM_COMM_BUFFER_REGION " is not set in SP configuration");
49 goto fatal_error;
50 }
51
Julian Hallead5b622021-11-23 17:31:07 +010052 /* Initialize service layer and associate with RPC endpoint */
Imre Kisee70c1a2021-10-27 20:41:01 +020053 gateway_iface = smm_gateway_create(own_id);
54
55 /* Initialize SMM variable MM service */
56 smm_var_service_interface = smm_variable_mm_service_init(&smm_var_service, gateway_iface);
57
58 /* Initialize MM communication layer */
59 if (!mm_communicate_call_ep_init(&mm_communicate_call_ep,
60 (void *)mm_comm_buffer_region.base_addr,
61 mm_comm_buffer_region.region_size))
62 goto fatal_error;
63
64 /* Attach SMM variable service to MM communication layer */
65 mm_communicate_call_ep_attach_service(&mm_communicate_call_ep, &smm_variable_guid,
66 smm_var_service_interface);
Julian Hallead5b622021-11-23 17:31:07 +010067
68 /* End of boot phase */
Imre Kisee70c1a2021-10-27 20:41:01 +020069 ffa_msg_wait(&req_msg);
Julian Hallead5b622021-11-23 17:31:07 +010070
71 while (1) {
Imre Kise700cb12022-07-20 15:19:17 +020072 if (FFA_IS_32_BIT_FUNC(req_msg.function_id)) {
73 EMSG("MM communicate over 32 bit FF-A messages is not supported");
74 ffa_msg_send_direct_resp_32(req_msg.destination_id, req_msg.source_id,
75 MM_RETURN_CODE_NOT_SUPPORTED, 0, 0, 0, 0,
76 &req_msg);
77 continue;
78 }
79
Imre Kisee70c1a2021-10-27 20:41:01 +020080 mm_communicate_call_ep_receive(&mm_communicate_call_ep, &req_msg, &resp_msg);
Julian Hallead5b622021-11-23 17:31:07 +010081
Imre Kise700cb12022-07-20 15:19:17 +020082 ffa_msg_send_direct_resp_64(req_msg.destination_id,
83 req_msg.source_id, resp_msg.args.args64[0],
84 resp_msg.args.args64[1], resp_msg.args.args64[2],
85 resp_msg.args.args64[3], resp_msg.args.args64[4],
Imre Kisee70c1a2021-10-27 20:41:01 +020086 &req_msg);
Julian Hallead5b622021-11-23 17:31:07 +010087 }
88
89fatal_error:
90 /* SP is not viable */
91 EMSG("SMM gateway SP error");
92 while (1) {}
93}
94
95void sp_interrupt_handler(uint32_t interrupt_id)
96{
97 (void)interrupt_id;
98}
99
100static int sp_init(uint16_t *own_sp_id)
101{
102 int status = -1;
103 ffa_result ffa_res;
104 sp_result sp_res;
105 static uint8_t tx_buffer[4096] __aligned(4096);
106 static uint8_t rx_buffer[4096] __aligned(4096);
107
108 sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
109 if (sp_res == SP_RESULT_OK) {
110 ffa_res = ffa_id_get(own_sp_id);
111 if (ffa_res == FFA_OK) {
112 status = 0;
113 }
114 }
115
116 return status;
117}