xref: /optee_os/core/arch/arm/plat-sam/scmi_server.c (revision 1e91da09a385c33be0709a3f457398d6c4783e9d)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2019, STMicroelectronics
4  * Copyright (c) 2021, Microchip
5  */
6 
7 #include <confine_array_index.h>
8 #include <drivers/scmi-msg.h>
9 #include <drivers/scmi.h>
10 #include <initcall.h>
11 #include <tee_api_defines.h>
12 
13 static_assert(SMT_BUF_SLOT_SIZE <= CFG_SCMI_SHMEM_SIZE);
14 
15 register_phys_mem(MEM_AREA_IO_NSEC, CFG_SCMI_SHMEM_START, CFG_SCMI_SHMEM_SIZE);
16 
17 struct channel_resources {
18 	struct scmi_msg_channel *channel;
19 };
20 
21 static const struct channel_resources scmi_channel[] = {
22 	[0] = {
23 		.channel = &(struct scmi_msg_channel){
24 			.shm_addr = { .pa = CFG_SCMI_SHMEM_START },
25 			.shm_size = SMT_BUF_SLOT_SIZE,
26 		},
27 	},
28 };
29 
30 static const struct channel_resources *find_resource(unsigned int channel_id)
31 {
32 	assert(channel_id < ARRAY_SIZE(scmi_channel));
33 
34 	return scmi_channel + channel_id;
35 }
36 
37 struct scmi_msg_channel *plat_scmi_get_channel(unsigned int channel_id)
38 {
39 	const size_t max_id = ARRAY_SIZE(scmi_channel);
40 	unsigned int confined_id = confine_array_index(channel_id, max_id);
41 
42 	if (channel_id >= max_id)
43 		return NULL;
44 
45 	return find_resource(confined_id)->channel;
46 }
47 
48 static const char vendor[] = "Microchip";
49 static const char sub_vendor[] = "";
50 
51 const char *plat_scmi_vendor_name(void)
52 {
53 	return vendor;
54 }
55 
56 const char *plat_scmi_sub_vendor_name(void)
57 {
58 	return sub_vendor;
59 }
60 
61 /* Currently supporting only SCMI Base protocol */
62 static const uint8_t plat_protocol_list[] = {
63 	SCMI_PROTOCOL_ID_CLOCK,
64 	0 /* Null termination */
65 };
66 
67 size_t plat_scmi_protocol_count(void)
68 {
69 	return ARRAY_SIZE(plat_protocol_list) - 1;
70 }
71 
72 const uint8_t *plat_scmi_protocol_list(unsigned int channel_id __unused)
73 {
74 	return plat_protocol_list;
75 }
76 
77 /*
78  * Initialize platform SCMI resources
79  */
80 static TEE_Result sam_init_scmi_server(void)
81 {
82 	size_t i = 0;
83 
84 	for (i = 0; i < ARRAY_SIZE(scmi_channel); i++) {
85 		const struct channel_resources *res = scmi_channel + i;
86 		struct scmi_msg_channel *chan = res->channel;
87 
88 		/* Enforce non-secure shm mapped as device memory */
89 		chan->shm_addr.va = (vaddr_t)phys_to_virt(chan->shm_addr.pa,
90 							  MEM_AREA_IO_NSEC, 1);
91 		assert(chan->shm_addr.va);
92 
93 		scmi_smt_init_agent_channel(chan);
94 	}
95 
96 	return TEE_SUCCESS;
97 }
98 
99 driver_init_late(sam_init_scmi_server);
100