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