1 /*
2 * Arm SCP/MCP Software
3 * Copyright (c) 2022-2023, Linaro Limited and Contributors. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #include <fwk_arch.h>
9 #include <fwk_core.h>
10 #include <fwk_id.h>
11 #include <fwk_log.h>
12 #include <fwk_noreturn.h>
13 #include <fwk_status.h>
14 #include <internal/fwk_context.h>
15
16 #include <stddef.h>
17 #include <stdint.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <malloc.h>
21
22 #include <mod_optee_mbx.h>
23
24 #include <arch_interrupt.h>
25 #include <arch_main.h>
26
27 static const struct fwk_arch_init_driver scmi_init_driver = {
28 .interrupt = arch_interrupt_init,
29 };
30
scmi_arch_init(void)31 int scmi_arch_init(void)
32 {
33 int status;
34
35 status = fwk_arch_init(&scmi_init_driver);
36
37 fwk_log_flush();
38
39 return status;
40 }
41
scmi_arch_deinit(void)42 int scmi_arch_deinit(void)
43 {
44 return fwk_arch_deinit();
45 }
46
scmi_get_devices_count(void)47 int scmi_get_devices_count(void)
48 {
49 return optee_mbx_get_devices_count();
50 }
51
scmi_get_device(unsigned int id)52 int scmi_get_device(unsigned int id)
53 {
54 fwk_id_t device_id;
55
56 device_id = optee_mbx_get_device(id);
57
58 if (fwk_id_is_type(device_id, FWK_ID_TYPE_NONE)) {
59 return -1;
60 }
61
62 return (int)device_id.value;
63 }
64
scmi_process_mbx_smt(unsigned int fwk_id)65 void scmi_process_mbx_smt(unsigned int fwk_id)
66 {
67 #ifdef BUILD_HAS_MOD_OPTEE_SMT
68 fwk_id_t device_id;
69
70 device_id.value = fwk_id;
71
72 optee_mbx_signal_smt_message(device_id);
73
74 fwk_process_event_queue();
75
76 fwk_log_flush();
77 #endif
78 }
79
scmi_process_mbx_msg(unsigned int fwk_id,void * in_buf,size_t in_size,void * out_buf,size_t * out_size)80 void scmi_process_mbx_msg(unsigned int fwk_id, void *in_buf, size_t in_size,
81 void *out_buf, size_t *out_size)
82 {
83 #ifdef BUILD_HAS_MOD_MSG_SMT
84 fwk_id_t device_id;
85
86 device_id.value = fwk_id;
87
88 optee_mbx_signal_msg_message(device_id, in_buf, in_size, out_buf, out_size);
89
90 fwk_process_event_queue();
91
92 fwk_log_flush();
93 #endif
94 }
95