xref: /optee_os/core/include/drivers/scmi-msg.h (revision 5b25c76ac40f830867e3d60800120ffd7874e8dc)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*
3  * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
4  * Copyright (c) 2019, Linaro Limited
5  */
6 
7 #ifndef SCMI_MSG_H
8 #define SCMI_MSG_H
9 
10 #include <compiler.h>
11 #include <kernel/panic.h>
12 #include <mm/core_memprot.h>
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 /* Minimum size expected for SMT based shared memory message buffers */
18 #define SMT_BUF_SLOT_SIZE	128
19 
20 /* A channel abstract a communication path between agent and server */
21 struct scmi_msg_channel;
22 
23 /*
24  * struct scmi_msg_channel - Shared memory buffer for a agent-to-server channel
25  *
26  * @shm_addr: Address of the shared memory for the SCMI channel
27  * @shm_size: Byte size of the shared memory for the SCMI channel
28  * @busy: True when channel is busy, flase when channel is free
29  * @threaded: True is executed in a threaded context, false otherwise
30  * @agent_name: Optional agent name, SCMI protocol exposes 16 bytes max
31  */
32 struct scmi_msg_channel {
33 	struct io_pa_va shm_addr;
34 	size_t shm_size;
35 	bool busy;
36 	bool threaded;
37 	const char *agent_name;
38 };
39 
40 /*
41  * Initialize SMT memory buffer, called by platform at init for each
42  * agent channel using the SMT header format.
43  * This function depends on CFG_SCMI_MSG_SMT.
44  *
45  * @chan: Pointer to the channel shared memory to be initialized
46  */
47 void scmi_smt_init_agent_channel(struct scmi_msg_channel *chan);
48 
49 /*
50  * Process SMT formatted message in a fastcall SMC cexecution ontext.
51  * Called by platform on SMC entry. When returning, output message is
52  * available in shared memory for agent to read the response.
53  * This function depends on CFG_SCMI_MSG_SMT_FASTCALL_ENTRY.
54  *
55  * @agent_id: SCMI agent ID the SMT belongs to
56  */
57 void scmi_smt_fastcall_smc_entry(unsigned int agent_id);
58 
59 /*
60  * Process SMT formatted message in a secure interrupt execution context.
61  * Called by platform interrupt handler. When returning, output message is
62  * available in shared memory for agent to read the response.
63  * This function depends on CFG_SCMI_MSG_SMT_INTERRUPT_ENTRY.
64  *
65  * @agent_id: SCMI agent ID the SMT belongs to
66  */
67 void scmi_smt_interrupt_entry(unsigned int agent_id);
68 
69 /*
70  * Process SMT formatted message in a TEE thread execution context.
71  * When returning, output message is available in shared memory for
72  * agent to read the response.
73  * This function depends on CFG_SCMI_MSG_SMT_THREAD_ENTRY.
74  *
75  * @agent_id: SCMI agent ID the SMT belongs to
76  */
77 void scmi_smt_threaded_entry(unsigned int agent_id);
78 
79 /* Platform callback functions */
80 
81 /*
82  * Return the SCMI channel related to an agent
83  * @agent_id: SCMI agent ID
84  * Return a pointer to channel on success, NULL otherwise
85  */
86 struct scmi_msg_channel *plat_scmi_get_channel(unsigned int agent_id);
87 
88 /*
89  * Return how many SCMI protocols supported by the platform
90  * According to the SCMI specification, this function does not target
91  * a specific agent ID and shall return all platform known capabilities.
92  */
93 size_t plat_scmi_protocol_count(void);
94 
95 /*
96  * Get the count and list of SCMI protocols (but base) supported for an agent
97  *
98  * @agent_id: SCMI agent ID
99  * Return a pointer to a null terminated array supported protocol IDs.
100  */
101 const uint8_t *plat_scmi_protocol_list(unsigned int agent_id);
102 
103 /* Get the name of the SCMI vendor for the platform */
104 const char *plat_scmi_vendor_name(void);
105 
106 /* Get the name of the SCMI sub-vendor for the platform */
107 const char *plat_scmi_sub_vendor_name(void);
108 
109 /* Handlers for SCMI Clock protocol services */
110 
111 /*
112  * Return number of clock controllers for an agent
113  * @agent_id: SCMI agent ID
114  * Return number of clock controllers
115  */
116 size_t plat_scmi_clock_count(unsigned int agent_id);
117 
118 /*
119  * Get clock controller string ID (aka name)
120  * @agent_id: SCMI agent ID
121  * @scmi_id: SCMI clock ID
122  * Return pointer to name or NULL
123  */
124 const char *plat_scmi_clock_get_name(unsigned int agent_id,
125 				     unsigned int scmi_id);
126 
127 /*
128  * Get clock possible rate as an array of frequencies in Hertz.
129  *
130  * @agent_id: SCMI agent ID
131  * @scmi_id: SCMI clock ID
132  * @rates: If NULL, function returns, else output rates array
133  * @nb_elts: Array size of @rates.
134  * Return an SCMI compliant error code
135  */
136 int32_t plat_scmi_clock_rates_array(unsigned int agent_id, unsigned int scmi_id,
137 				    unsigned long *rates, size_t *nb_elts);
138 
139 /*
140  * Get clock possible rate as range with regular steps in Hertz
141  *
142  * @agent_id: SCMI agent ID
143  * @scmi_id: SCMI clock ID
144  * @min_max_step: 3 cell array for min, max and step rate data
145  * Return an SCMI compliant error code
146  */
147 int32_t plat_scmi_clock_rates_by_step(unsigned int agent_id,
148 				      unsigned int scmi_id,
149 				      unsigned long *min_max_step);
150 
151 /*
152  * Get clock rate in Hertz
153  * @agent_id: SCMI agent ID
154  * @scmi_id: SCMI clock ID
155  * Return clock rate or 0 if not supported
156  */
157 unsigned long plat_scmi_clock_get_rate(unsigned int agent_id,
158 				       unsigned int scmi_id);
159 
160 /*
161  * Set clock rate in Hertz
162  * @agent_id: SCMI agent ID
163  * @scmi_id: SCMI clock ID
164  * @rate: Target clock frequency in Hertz
165  * Return a compliant SCMI error code
166  */
167 int32_t plat_scmi_clock_set_rate(unsigned int agent_id, unsigned int scmi_id,
168 				 unsigned long rate);
169 
170 /*
171  * Get clock state (enabled or disabled)
172  * @agent_id: SCMI agent ID
173  * @scmi_id: SCMI clock ID
174  * Return 1 if clock is enabled, 0 if disables, or a negative SCMI error code
175  */
176 int32_t plat_scmi_clock_get_state(unsigned int agent_id, unsigned int scmi_id);
177 
178 /*
179  * Get clock state (enabled or disabled)
180  * @agent_id: SCMI agent ID
181  * @scmi_id: SCMI clock ID
182  * @enable_not_disable: Enable clock if true, disable clock otherwise
183  * Return a compliant SCMI error code
184  */
185 int32_t plat_scmi_clock_set_state(unsigned int agent_id, unsigned int scmi_id,
186 				  bool enable_not_disable);
187 
188 /* Handlers for SCMI Reset Domain protocol services */
189 
190 /*
191  * Return number of reset domains for the agent
192  * @agent_id: SCMI agent ID
193  * Return number of reset domains
194  */
195 size_t plat_scmi_rd_count(unsigned int agent_id);
196 
197 /*
198  * Get reset domain string ID (aka name)
199  * @agent_id: SCMI agent ID
200  * @scmi_id: SCMI reset domain ID
201  * Return pointer to name or NULL
202  */
203 const char *plat_scmi_rd_get_name(unsigned int agent_id, unsigned int scmi_id);
204 
205 /*
206  * Perform a reset cycle on a target reset domain
207  * @agent_id: SCMI agent ID
208  * @scmi_id: SCMI reset domain ID
209  * @state: Target reset state (see SCMI specification, 0 means context loss)
210  * Return a compliant SCMI error code
211  */
212 int32_t plat_scmi_rd_autonomous(unsigned int agent_id, unsigned int scmi_id,
213 				unsigned int state);
214 
215 /*
216  * Assert or deassert target reset domain
217  * @agent_id: SCMI agent ID
218  * @scmi_id: SCMI reset domain ID
219  * @assert_not_deassert: Assert domain if true, otherwise deassert domain
220  * Return a compliant SCMI error code
221  */
222 int32_t plat_scmi_rd_set_state(unsigned int agent_id, unsigned int scmi_id,
223 			       bool assert_not_deassert);
224 
225 #endif /* SCMI_MSG_H */
226