xref: /rk3399_ARM-atf/include/drivers/scmi-msg.h (revision ca9d6edc892165c38f1b2710b537c10d4a57062d)
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
257ece6597SMichal 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.
116*ca9d6edcSXiaoDong Huang  * @start_idx: Start index of rates array
117b4734308SPeng Fan  * Return an SCMI compliant error code
118b4734308SPeng Fan  */
119b4734308SPeng Fan int32_t plat_scmi_clock_rates_array(unsigned int agent_id, unsigned int scmi_id,
120*ca9d6edcSXiaoDong Huang 				    unsigned long *rates, size_t *nb_elts,
121*ca9d6edcSXiaoDong Huang 				    uint32_t start_idx);
122b4734308SPeng Fan 
123b4734308SPeng Fan /*
124b4734308SPeng Fan  * Get clock possible rate as range with regular steps in Hertz
125b4734308SPeng Fan  *
126b4734308SPeng Fan  * @agent_id: SCMI agent ID
127b4734308SPeng Fan  * @scmi_id: SCMI clock ID
128b4734308SPeng Fan  * @min_max_step: 3 cell array for min, max and step rate data
129b4734308SPeng Fan  * Return an SCMI compliant error code
130b4734308SPeng Fan  */
131b4734308SPeng Fan int32_t plat_scmi_clock_rates_by_step(unsigned int agent_id,
132b4734308SPeng Fan 				      unsigned int scmi_id,
133b4734308SPeng Fan 				      unsigned long *min_max_step);
134b4734308SPeng Fan 
135b4734308SPeng Fan /*
136b4734308SPeng Fan  * Get clock rate in Hertz
137b4734308SPeng Fan  * @agent_id: SCMI agent ID
138b4734308SPeng Fan  * @scmi_id: SCMI clock ID
139b4734308SPeng Fan  * Return clock rate or 0 if not supported
140b4734308SPeng Fan  */
141b4734308SPeng Fan unsigned long plat_scmi_clock_get_rate(unsigned int agent_id,
142b4734308SPeng Fan 				       unsigned int scmi_id);
143b4734308SPeng Fan 
144b4734308SPeng Fan /*
145b4734308SPeng Fan  * Set clock rate in Hertz
146b4734308SPeng Fan  * @agent_id: SCMI agent ID
147b4734308SPeng Fan  * @scmi_id: SCMI clock ID
148b4734308SPeng Fan  * @rate: Target clock frequency in Hertz
149b4734308SPeng Fan  * Return a compliant SCMI error code
150b4734308SPeng Fan  */
151b4734308SPeng Fan int32_t plat_scmi_clock_set_rate(unsigned int agent_id, unsigned int scmi_id,
152b4734308SPeng Fan 				 unsigned long rate);
153b4734308SPeng Fan 
154b4734308SPeng Fan /*
155b4734308SPeng Fan  * Get clock state (enabled or disabled)
156b4734308SPeng Fan  * @agent_id: SCMI agent ID
157b4734308SPeng Fan  * @scmi_id: SCMI clock ID
158b4734308SPeng Fan  * Return 1 if clock is enabled, 0 if disables, or a negative SCMI error code
159b4734308SPeng Fan  */
160b4734308SPeng Fan int32_t plat_scmi_clock_get_state(unsigned int agent_id, unsigned int scmi_id);
161b4734308SPeng Fan 
162b4734308SPeng Fan /*
163b4734308SPeng Fan  * Get clock state (enabled or disabled)
164b4734308SPeng Fan  * @agent_id: SCMI agent ID
165b4734308SPeng Fan  * @scmi_id: SCMI clock ID
166b4734308SPeng Fan  * @enable_not_disable: Enable clock if true, disable clock otherwise
167b4734308SPeng Fan  * Return a compliant SCMI error code
168b4734308SPeng Fan  */
169b4734308SPeng Fan int32_t plat_scmi_clock_set_state(unsigned int agent_id, unsigned int scmi_id,
170b4734308SPeng Fan 				  bool enable_not_disable);
171b4734308SPeng Fan 
172b4734308SPeng Fan /* Handlers for SCMI Reset Domain protocol services */
173b4734308SPeng Fan 
174b4734308SPeng Fan /*
175b4734308SPeng Fan  * Return number of reset domains for the agent
176b4734308SPeng Fan  * @agent_id: SCMI agent ID
177b4734308SPeng Fan  * Return number of reset domains
178b4734308SPeng Fan  */
179b4734308SPeng Fan size_t plat_scmi_rstd_count(unsigned int agent_id);
180b4734308SPeng Fan 
181b4734308SPeng Fan /*
182b4734308SPeng Fan  * Get reset domain string ID (aka name)
183b4734308SPeng Fan  * @agent_id: SCMI agent ID
184b4734308SPeng Fan  * @scmi_id: SCMI reset domain ID
185b4734308SPeng Fan  * Return pointer to name or NULL
186b4734308SPeng Fan  */
187b4734308SPeng Fan const char *plat_scmi_rstd_get_name(unsigned int agent_id, unsigned int scmi_id);
188b4734308SPeng Fan 
189b4734308SPeng Fan /*
190b4734308SPeng Fan  * Perform a reset cycle on a target reset domain
191b4734308SPeng Fan  * @agent_id: SCMI agent ID
192b4734308SPeng Fan  * @scmi_id: SCMI reset domain ID
193b4734308SPeng Fan  * @state: Target reset state (see SCMI specification, 0 means context loss)
194b4734308SPeng Fan  * Return a compliant SCMI error code
195b4734308SPeng Fan  */
196b4734308SPeng Fan int32_t plat_scmi_rstd_autonomous(unsigned int agent_id, unsigned int scmi_id,
197b4734308SPeng Fan 				  unsigned int state);
198b4734308SPeng Fan 
199b4734308SPeng Fan /*
200b4734308SPeng Fan  * Assert or deassert target reset domain
201b4734308SPeng Fan  * @agent_id: SCMI agent ID
202b4734308SPeng Fan  * @scmi_id: SCMI reset domain ID
203b4734308SPeng Fan  * @assert_not_deassert: Assert domain if true, otherwise deassert domain
204b4734308SPeng Fan  * Return a compliant SCMI error code
205b4734308SPeng Fan  */
206b4734308SPeng Fan int32_t plat_scmi_rstd_set_state(unsigned int agent_id, unsigned int scmi_id,
207b4734308SPeng Fan 				 bool assert_not_deassert);
208b4734308SPeng Fan 
209b4734308SPeng Fan #endif /* SCMI_MSG_H */
210