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