xref: /rk3399_ARM-atf/plat/arm/board/tc/tc_sfcp.c (revision a8dc2595ab7e10dac8285d2c0b6da7ebbcd0edb0)
1 /*
2  * Copyright (c) 2026, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include <assert.h>
9 
10 #include "mhu_v3_x.h"
11 #include <sfcp_platform.h>
12 
13 #include <platform_def.h>
14 
15 /* These must be kept up to data with the routing table
16  * definition in RSE as the node IDs are global
17  */
18 #define AP_MONITOR_NODE_ID (2)
19 
20 static struct mhu_v3_x_dev_t mhu_rse_ap_snd_dev = { PLAT_RSE_AP_SND_MHU_BASE,
21 						    MHU_V3_X_PBX_FRAME };
22 static struct mhu_v3_x_dev_t mhu_rse_ap_recv_dev = { PLAT_RSE_AP_RCV_MHU_BASE,
23 						     MHU_V3_X_MBX_FRAME };
24 
25 static struct sfcp_platform_device_t sender_devices[] = {
26 	/* Link ID 0 is reserved */
27 	[0] = { 0 },
28 	[1] = { &mhu_rse_ap_snd_dev, SFCP_PLATFORM_DEVICE_TYPE_MHUV3 },
29 };
30 
31 struct sfcp_platform_device_t
32 sfcp_platform_get_send_device(sfcp_link_id_t link_id)
33 {
34 	assert(link_id < ARRAY_SIZE(sender_devices));
35 
36 	return sender_devices[link_id];
37 }
38 
39 static struct sfcp_platform_device_t receiver_devices[] = {
40 	/* Link ID 0 is reserved */
41 	[0] = { 0 },
42 	[1] = { &mhu_rse_ap_recv_dev, SFCP_PLATFORM_DEVICE_TYPE_MHUV3 },
43 };
44 
45 struct sfcp_platform_device_t
46 sfcp_platform_get_receive_device(sfcp_link_id_t link_id)
47 {
48 	assert(link_id < ARRAY_SIZE(receiver_devices));
49 
50 	return receiver_devices[link_id];
51 }
52 
53 sfcp_link_id_t
54 sfcp_platform_get_receive_link_id(struct sfcp_platform_device_t device)
55 {
56 	for (uint8_t i = 1; i < ARRAY_SIZE(receiver_devices); i++) {
57 		if ((receiver_devices[i].type == device.type) &&
58 		    (receiver_devices[i].device == device.device)) {
59 			return i;
60 		}
61 	}
62 
63 	return 0;
64 }
65 
66 sfcp_node_id_t sfcp_platform_get_my_node_id(void)
67 {
68 	return AP_MONITOR_NODE_ID;
69 }
70 
71 /* Currently only link defined is to RSE. All other links are
72  * defined as 0 (invalid link ID) as SFCP is currently only
73  * used for communication with the RSE.
74  *
75  * TODO: Once SFCP has been adopted by other components
76  * update this table to add link IDs for communication
77  * with other nodes
78  */
79 static const uint8_t ap_monitor_routing_tables[] = {
80 	[0] = 1,
81 	[1] = 0,
82 	[2] = 0,
83 	[3] = 0,
84 };
85 
86 void sfcp_platform_get_routing_tables(const uint8_t **routing_tables,
87 				      size_t *routing_tables_size)
88 {
89 	assert(routing_tables != NULL);
90 	assert(routing_tables_size != NULL);
91 
92 	*routing_tables = ap_monitor_routing_tables;
93 	*routing_tables_size = ARRAY_SIZE(ap_monitor_routing_tables);
94 }
95