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