1ae8c8068SEtienne Carriere /* SPDX-License-Identifier: BSD-3-Clause */
2ae8c8068SEtienne Carriere /*
3ae8c8068SEtienne Carriere * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
4659a1f88SEtienne Carriere * Copyright (c) 2019-2021, Linaro Limited
5ae8c8068SEtienne Carriere */
6ae8c8068SEtienne Carriere
7fbe66cf8SEtienne Carriere #ifndef __DRIVERS_SCMI_MSG_H
8fbe66cf8SEtienne Carriere #define __DRIVERS_SCMI_MSG_H
9ae8c8068SEtienne Carriere
10ae8c8068SEtienne Carriere #include <compiler.h>
11ae8c8068SEtienne Carriere #include <kernel/panic.h>
12ae8c8068SEtienne Carriere #include <mm/core_memprot.h>
13ae8c8068SEtienne Carriere #include <stdbool.h>
14ae8c8068SEtienne Carriere #include <stddef.h>
15ae8c8068SEtienne Carriere #include <stdint.h>
16ae8c8068SEtienne Carriere
17ae8c8068SEtienne Carriere /* Minimum size expected for SMT based shared memory message buffers */
18b4bfc9a9SJens Wiklander #define SMT_BUF_SLOT_SIZE U(128)
19ae8c8068SEtienne Carriere
20c22983c9SEtienne Carriere /* Standard values for SCMI voltage domain protocol configuration state */
21b4bfc9a9SJens Wiklander #define SCMI_VOLTAGE_DOMAIN_CONFIG_ARCH_ON U(0x7)
22b4bfc9a9SJens Wiklander #define SCMI_VOLTAGE_DOMAIN_CONFIG_ARCH_OFF U(0)
23c22983c9SEtienne Carriere
24ae8c8068SEtienne Carriere /* A channel abstract a communication path between agent and server */
25ae8c8068SEtienne Carriere struct scmi_msg_channel;
26ae8c8068SEtienne Carriere
27ae8c8068SEtienne Carriere /*
28ae8c8068SEtienne Carriere * struct scmi_msg_channel - Shared memory buffer for a agent-to-server channel
29ae8c8068SEtienne Carriere *
30ae8c8068SEtienne Carriere * @shm_addr: Address of the shared memory for the SCMI channel
31ae8c8068SEtienne Carriere * @shm_size: Byte size of the shared memory for the SCMI channel
32ae8c8068SEtienne Carriere * @busy: True when channel is busy, flase when channel is free
33ae8c8068SEtienne Carriere * @threaded: True is executed in a threaded context, false otherwise
34ae8c8068SEtienne Carriere */
35ae8c8068SEtienne Carriere struct scmi_msg_channel {
36ae8c8068SEtienne Carriere struct io_pa_va shm_addr;
37ae8c8068SEtienne Carriere size_t shm_size;
38ae8c8068SEtienne Carriere bool busy;
39ae8c8068SEtienne Carriere bool threaded;
40ae8c8068SEtienne Carriere };
41ae8c8068SEtienne Carriere
429ed56ecdSEtienne Carriere #ifdef CFG_SCMI_MSG_SMT
43a58c4d70SEtienne Carriere /*
44a58c4d70SEtienne Carriere * Initialize SMT memory buffer, called by platform at init for each
45a58c4d70SEtienne Carriere * agent channel using the SMT header format.
46a58c4d70SEtienne Carriere * This function depends on CFG_SCMI_MSG_SMT.
47a58c4d70SEtienne Carriere *
480c43202eSEtienne Carriere * @channel: Pointer to the channel shared memory to be initialized
49a58c4d70SEtienne Carriere */
509ed56ecdSEtienne Carriere void scmi_smt_init_agent_channel(struct scmi_msg_channel *channel);
5148f04743SEtienne Carriere
5248f04743SEtienne Carriere /*
5348f04743SEtienne Carriere * Set SMT shared buffer location
5448f04743SEtienne Carriere *
5548f04743SEtienne Carriere * @channel: SCMI channel reference
5648f04743SEtienne Carriere * @base: virtual address of the shared buffer or NULL to clear the reference
5748f04743SEtienne Carriere */
5848f04743SEtienne Carriere void scmi_smt_set_shared_buffer(struct scmi_msg_channel *channel, void *base);
599ed56ecdSEtienne Carriere #else
609ed56ecdSEtienne Carriere static inline
scmi_smt_init_agent_channel(struct scmi_msg_channel * channel __unused)619ed56ecdSEtienne Carriere void scmi_smt_init_agent_channel(struct scmi_msg_channel *channel __unused)
629ed56ecdSEtienne Carriere {
639ed56ecdSEtienne Carriere panic();
649ed56ecdSEtienne Carriere }
6548f04743SEtienne Carriere
6648f04743SEtienne Carriere static inline
scmi_smt_set_shared_buffer(struct scmi_msg_channel * channel __unused,void * base __unused)6748f04743SEtienne Carriere void scmi_smt_set_shared_buffer(struct scmi_msg_channel *channel __unused,
6848f04743SEtienne Carriere void *base __unused)
6948f04743SEtienne Carriere {
7048f04743SEtienne Carriere }
7148f04743SEtienne Carriere #endif /* CFG_SCMI_MSG_SMT */
72a58c4d70SEtienne Carriere
739ed56ecdSEtienne Carriere #ifdef CFG_SCMI_MSG_SMT_FASTCALL_ENTRY
74a58c4d70SEtienne Carriere /*
75064bf8dcSEtienne Carriere * Process SMT formatted message in a fastcall SMC execution context.
76a58c4d70SEtienne Carriere * Called by platform on SMC entry. When returning, output message is
77a58c4d70SEtienne Carriere * available in shared memory for agent to read the response.
78a58c4d70SEtienne Carriere * This function depends on CFG_SCMI_MSG_SMT_FASTCALL_ENTRY.
79a58c4d70SEtienne Carriere *
80659a1f88SEtienne Carriere * @channel_id: SCMI channel ID the SMT belongs to
81a58c4d70SEtienne Carriere */
82659a1f88SEtienne Carriere void scmi_smt_fastcall_smc_entry(unsigned int channel_id);
839ed56ecdSEtienne Carriere #else
scmi_smt_fastcall_smc_entry(unsigned int channel_id __unused)849ed56ecdSEtienne Carriere static inline void scmi_smt_fastcall_smc_entry(unsigned int channel_id __unused)
859ed56ecdSEtienne Carriere {
869ed56ecdSEtienne Carriere }
879ed56ecdSEtienne Carriere #endif
88a58c4d70SEtienne Carriere
899ed56ecdSEtienne Carriere #ifdef CFG_SCMI_MSG_SMT_INTERRUPT_ENTRY
90a58c4d70SEtienne Carriere /*
91a58c4d70SEtienne Carriere * Process SMT formatted message in a secure interrupt execution context.
92a58c4d70SEtienne Carriere * Called by platform interrupt handler. When returning, output message is
93a58c4d70SEtienne Carriere * available in shared memory for agent to read the response.
94a58c4d70SEtienne Carriere * This function depends on CFG_SCMI_MSG_SMT_INTERRUPT_ENTRY.
95a58c4d70SEtienne Carriere *
96659a1f88SEtienne Carriere * @channel_id: SCMI channel ID the SMT belongs to
97a58c4d70SEtienne Carriere */
98659a1f88SEtienne Carriere void scmi_smt_interrupt_entry(unsigned int channel_id);
999ed56ecdSEtienne Carriere #else
scmi_smt_interrupt_entry(unsigned int channel_id __unused)1009ed56ecdSEtienne Carriere static inline void scmi_smt_interrupt_entry(unsigned int channel_id __unused)
1019ed56ecdSEtienne Carriere {
1029ed56ecdSEtienne Carriere }
1039ed56ecdSEtienne Carriere #endif
104a58c4d70SEtienne Carriere
1059ed56ecdSEtienne Carriere #ifdef CFG_SCMI_MSG_SMT_THREAD_ENTRY
106a58c4d70SEtienne Carriere /*
107a58c4d70SEtienne Carriere * Process SMT formatted message in a TEE thread execution context.
108a58c4d70SEtienne Carriere * When returning, output message is available in shared memory for
109a58c4d70SEtienne Carriere * agent to read the response.
110a58c4d70SEtienne Carriere * This function depends on CFG_SCMI_MSG_SMT_THREAD_ENTRY.
111a58c4d70SEtienne Carriere *
112659a1f88SEtienne Carriere * @channel_id: SCMI channel ID the SMT belongs to
113a58c4d70SEtienne Carriere */
114659a1f88SEtienne Carriere void scmi_smt_threaded_entry(unsigned int channel_id);
1159ed56ecdSEtienne Carriere #else
scmi_smt_threaded_entry(unsigned int channel_id __unused)1169ed56ecdSEtienne Carriere static inline void scmi_smt_threaded_entry(unsigned int channel_id __unused)
1179ed56ecdSEtienne Carriere {
1189ed56ecdSEtienne Carriere }
1199ed56ecdSEtienne Carriere #endif
120a58c4d70SEtienne Carriere
121916cc52aSEtienne Carriere #ifdef CFG_SCMI_MSG_SHM_MSG
122916cc52aSEtienne Carriere /*
123916cc52aSEtienne Carriere * Process MSG formatted message in a TEE thread execution context.
124916cc52aSEtienne Carriere * When returning, output message is available in shared memory for
125916cc52aSEtienne Carriere * agent to read the response.
126916cc52aSEtienne Carriere * This function depends on CFG_SCMI_MSG_MSG_THREAD_ENTRY.
127916cc52aSEtienne Carriere *
128916cc52aSEtienne Carriere * @channel_id: SCMI channel ID
129916cc52aSEtienne Carriere * @in_buf: Shared buffer storing input SCMI message
130916cc52aSEtienne Carriere * @in_size: Byte size of @in_buf, including MSG header and message payload
131916cc52aSEtienne Carriere * @out_buf: Shared buffer storing input SCMI message
132916cc52aSEtienne Carriere * @out_size: [in] @out_buf max byte size
133916cc52aSEtienne Carriere * [out] @out_buf output byte size (MSG header and message payload)
134916cc52aSEtienne Carriere */
135916cc52aSEtienne Carriere TEE_Result scmi_msg_threaded_entry(unsigned int channel_id,
136916cc52aSEtienne Carriere void *in_buf, size_t in_size,
137916cc52aSEtienne Carriere void *out_buf, size_t *out_size);
138916cc52aSEtienne Carriere #else
scmi_msg_threaded_entry(unsigned int chan_id __unused,void * in_buf __unused,size_t in_size __unused,void * out_buf __unused,size_t * out_size __unused)139916cc52aSEtienne Carriere static inline TEE_Result scmi_msg_threaded_entry(unsigned int chan_id __unused,
140916cc52aSEtienne Carriere void *in_buf __unused,
141916cc52aSEtienne Carriere size_t in_size __unused,
142916cc52aSEtienne Carriere void *out_buf __unused,
143916cc52aSEtienne Carriere size_t *out_size __unused)
144916cc52aSEtienne Carriere {
145916cc52aSEtienne Carriere return TEE_ERROR_NOT_SUPPORTED;
146916cc52aSEtienne Carriere }
147916cc52aSEtienne Carriere #endif
148916cc52aSEtienne Carriere
149e80130f6SClément Léger struct clk;
150e80130f6SClément Léger
151e80130f6SClément Léger #ifdef CFG_SCMI_MSG_USE_CLK
152e80130f6SClément Léger /*
153e80130f6SClément Léger * Expose a clock through SCMI
154e80130f6SClément Léger * @clk: Clock to be exposed
155e80130f6SClément Léger * @channel_id: SCMI server channel exposing the clock
156e80130f6SClément Léger * @scmi_id: SCMI ID of the clock within the channel
157e80130f6SClément Léger */
158e80130f6SClément Léger TEE_Result scmi_clk_add(struct clk *clk, unsigned int channel_id,
159e80130f6SClément Léger unsigned int scmi_id);
160e80130f6SClément Léger #else
scmi_clk_add(struct clk * clk __unused,unsigned int channel_id __unused,unsigned int scmi_id __unused)161e80130f6SClément Léger static inline TEE_Result scmi_clk_add(struct clk *clk __unused,
162e80130f6SClément Léger unsigned int channel_id __unused,
163e80130f6SClément Léger unsigned int scmi_id __unused)
164e80130f6SClément Léger {
165e80130f6SClément Léger return TEE_ERROR_NOT_SUPPORTED;
166e80130f6SClément Léger }
167e80130f6SClément Léger #endif
168e80130f6SClément Léger
169ae8c8068SEtienne Carriere /* Platform callback functions */
170ae8c8068SEtienne Carriere
171ae8c8068SEtienne Carriere /*
172ae8c8068SEtienne Carriere * Return the SCMI channel related to an agent
173659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
174ae8c8068SEtienne Carriere * Return a pointer to channel on success, NULL otherwise
175ae8c8068SEtienne Carriere */
176659a1f88SEtienne Carriere struct scmi_msg_channel *plat_scmi_get_channel(unsigned int channel_id);
177ae8c8068SEtienne Carriere
1783e530666SEtienne Carriere /* Scmi-msg uses the channel ID as handle. Must channel_id is valid */
scmi_smt_channel_handle(unsigned int channel_id)1793e530666SEtienne Carriere static inline unsigned int scmi_smt_channel_handle(unsigned int channel_id)
1803e530666SEtienne Carriere {
1813e530666SEtienne Carriere assert(plat_scmi_get_channel(channel_id));
1823e530666SEtienne Carriere
1833e530666SEtienne Carriere return channel_id;
1843e530666SEtienne Carriere }
1853e530666SEtienne Carriere
186ae8c8068SEtienne Carriere /*
187ae8c8068SEtienne Carriere * Return how many SCMI protocols supported by the platform
188ae8c8068SEtienne Carriere * According to the SCMI specification, this function does not target
189659a1f88SEtienne Carriere * a specific channel ID and shall return all platform known capabilities.
190ae8c8068SEtienne Carriere */
191ae8c8068SEtienne Carriere size_t plat_scmi_protocol_count(void);
192ae8c8068SEtienne Carriere
193ae8c8068SEtienne Carriere /*
194ae8c8068SEtienne Carriere * Get the count and list of SCMI protocols (but base) supported for an agent
195ae8c8068SEtienne Carriere *
196659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
197ae8c8068SEtienne Carriere * Return a pointer to a null terminated array supported protocol IDs.
198ae8c8068SEtienne Carriere */
199659a1f88SEtienne Carriere const uint8_t *plat_scmi_protocol_list(unsigned int channel_id);
200ae8c8068SEtienne Carriere
201ae8c8068SEtienne Carriere /* Get the name of the SCMI vendor for the platform */
202ae8c8068SEtienne Carriere const char *plat_scmi_vendor_name(void);
203ae8c8068SEtienne Carriere
204ae8c8068SEtienne Carriere /* Get the name of the SCMI sub-vendor for the platform */
205ae8c8068SEtienne Carriere const char *plat_scmi_sub_vendor_name(void);
206ae8c8068SEtienne Carriere
207a7a9e3baSEtienne Carriere /* Handlers for SCMI Clock protocol services */
208a7a9e3baSEtienne Carriere
209a7a9e3baSEtienne Carriere /*
210a7a9e3baSEtienne Carriere * Return number of clock controllers for an agent
211659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
212a7a9e3baSEtienne Carriere * Return number of clock controllers
213a7a9e3baSEtienne Carriere */
214659a1f88SEtienne Carriere size_t plat_scmi_clock_count(unsigned int channel_id);
215a7a9e3baSEtienne Carriere
216a7a9e3baSEtienne Carriere /*
217a7a9e3baSEtienne Carriere * Get clock controller string ID (aka name)
218659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
219a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID
220a7a9e3baSEtienne Carriere * Return pointer to name or NULL
221a7a9e3baSEtienne Carriere */
222659a1f88SEtienne Carriere const char *plat_scmi_clock_get_name(unsigned int channel_id,
223a7a9e3baSEtienne Carriere unsigned int scmi_id);
224a7a9e3baSEtienne Carriere
225a7a9e3baSEtienne Carriere /*
226a7a9e3baSEtienne Carriere * Get clock possible rate as an array of frequencies in Hertz.
227a7a9e3baSEtienne Carriere *
228659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
229a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID
230d9be1b35SEtienne Carriere * @start_index: Requested start index for the exposed rates array
2310c43202eSEtienne Carriere * @rates: Output rates array or NULL if only querying @nb_elts
2320c43202eSEtienne Carriere * @nb_elts: [in] Array size of @rates, [out] Number of rates loaded in @rates
233a7a9e3baSEtienne Carriere * Return an SCMI compliant error code
234a7a9e3baSEtienne Carriere */
235659a1f88SEtienne Carriere int32_t plat_scmi_clock_rates_array(unsigned int channel_id,
236659a1f88SEtienne Carriere unsigned int scmi_id, size_t start_index,
237659a1f88SEtienne Carriere unsigned long *rates, size_t *nb_elts);
238a7a9e3baSEtienne Carriere
239a7a9e3baSEtienne Carriere /*
240a7a9e3baSEtienne Carriere * Get clock possible rate as range with regular steps in Hertz
241a7a9e3baSEtienne Carriere *
242659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
243a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID
244a7a9e3baSEtienne Carriere * @min_max_step: 3 cell array for min, max and step rate data
245a7a9e3baSEtienne Carriere * Return an SCMI compliant error code
246a7a9e3baSEtienne Carriere */
247659a1f88SEtienne Carriere int32_t plat_scmi_clock_rates_by_step(unsigned int channel_id,
248a7a9e3baSEtienne Carriere unsigned int scmi_id,
249a7a9e3baSEtienne Carriere unsigned long *min_max_step);
250a7a9e3baSEtienne Carriere
251a7a9e3baSEtienne Carriere /*
252a7a9e3baSEtienne Carriere * Get clock rate in Hertz
253659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
254a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID
255a7a9e3baSEtienne Carriere * Return clock rate or 0 if not supported
256a7a9e3baSEtienne Carriere */
257659a1f88SEtienne Carriere unsigned long plat_scmi_clock_get_rate(unsigned int channel_id,
258a7a9e3baSEtienne Carriere unsigned int scmi_id);
259a7a9e3baSEtienne Carriere
260a7a9e3baSEtienne Carriere /*
261a7a9e3baSEtienne Carriere * Set clock rate in Hertz
262659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
263a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID
264a7a9e3baSEtienne Carriere * @rate: Target clock frequency in Hertz
265a7a9e3baSEtienne Carriere * Return a compliant SCMI error code
266a7a9e3baSEtienne Carriere */
267659a1f88SEtienne Carriere int32_t plat_scmi_clock_set_rate(unsigned int channel_id, unsigned int scmi_id,
268a7a9e3baSEtienne Carriere unsigned long rate);
269a7a9e3baSEtienne Carriere
270a7a9e3baSEtienne Carriere /*
271a7a9e3baSEtienne Carriere * Get clock state (enabled or disabled)
272659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
273a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID
274a7a9e3baSEtienne Carriere * Return 1 if clock is enabled, 0 if disables, or a negative SCMI error code
275a7a9e3baSEtienne Carriere */
276659a1f88SEtienne Carriere int32_t plat_scmi_clock_get_state(unsigned int channel_id,
277659a1f88SEtienne Carriere unsigned int scmi_id);
278a7a9e3baSEtienne Carriere
279a7a9e3baSEtienne Carriere /*
280a7a9e3baSEtienne Carriere * Get clock state (enabled or disabled)
281659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
282a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID
283a7a9e3baSEtienne Carriere * @enable_not_disable: Enable clock if true, disable clock otherwise
284a7a9e3baSEtienne Carriere * Return a compliant SCMI error code
285a7a9e3baSEtienne Carriere */
286659a1f88SEtienne Carriere int32_t plat_scmi_clock_set_state(unsigned int channel_id, unsigned int scmi_id,
287a7a9e3baSEtienne Carriere bool enable_not_disable);
28856a1f10eSEtienne Carriere
28956a1f10eSEtienne Carriere /* Handlers for SCMI Reset Domain protocol services */
29056a1f10eSEtienne Carriere
29156a1f10eSEtienne Carriere /*
29256a1f10eSEtienne Carriere * Return number of reset domains for the agent
293659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
29456a1f10eSEtienne Carriere * Return number of reset domains
29556a1f10eSEtienne Carriere */
296659a1f88SEtienne Carriere size_t plat_scmi_rd_count(unsigned int channel_id);
29756a1f10eSEtienne Carriere
29856a1f10eSEtienne Carriere /*
29956a1f10eSEtienne Carriere * Get reset domain string ID (aka name)
300659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
30156a1f10eSEtienne Carriere * @scmi_id: SCMI reset domain ID
30256a1f10eSEtienne Carriere * Return pointer to name or NULL
30356a1f10eSEtienne Carriere */
304659a1f88SEtienne Carriere const char *plat_scmi_rd_get_name(unsigned int channel_id,
305659a1f88SEtienne Carriere unsigned int scmi_id);
30656a1f10eSEtienne Carriere
30756a1f10eSEtienne Carriere /*
30856a1f10eSEtienne Carriere * Perform a reset cycle on a target reset domain
309659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
31056a1f10eSEtienne Carriere * @scmi_id: SCMI reset domain ID
31156a1f10eSEtienne Carriere * @state: Target reset state (see SCMI specification, 0 means context loss)
31256a1f10eSEtienne Carriere * Return a compliant SCMI error code
31356a1f10eSEtienne Carriere */
314659a1f88SEtienne Carriere int32_t plat_scmi_rd_autonomous(unsigned int channel_id, unsigned int scmi_id,
31556a1f10eSEtienne Carriere unsigned int state);
31656a1f10eSEtienne Carriere
31756a1f10eSEtienne Carriere /*
31856a1f10eSEtienne Carriere * Assert or deassert target reset domain
319659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
32056a1f10eSEtienne Carriere * @scmi_id: SCMI reset domain ID
32156a1f10eSEtienne Carriere * @assert_not_deassert: Assert domain if true, otherwise deassert domain
32256a1f10eSEtienne Carriere * Return a compliant SCMI error code
32356a1f10eSEtienne Carriere */
324659a1f88SEtienne Carriere int32_t plat_scmi_rd_set_state(unsigned int channel_id, unsigned int scmi_id,
32556a1f10eSEtienne Carriere bool assert_not_deassert);
32656a1f10eSEtienne Carriere
327006d89b8SEtienne Carriere /* Handlers for SCMI Voltage Domain protocol services */
328006d89b8SEtienne Carriere
329006d89b8SEtienne Carriere /*
330006d89b8SEtienne Carriere * Return number of voltage domain for an agent
331659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
332006d89b8SEtienne Carriere * Return number of voltage domains
333006d89b8SEtienne Carriere */
334659a1f88SEtienne Carriere size_t plat_scmi_voltd_count(unsigned int channel_id);
335006d89b8SEtienne Carriere
336006d89b8SEtienne Carriere /*
337a286b03fSEtienne Carriere * Get voltage domain string ID (aka name)
338659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
339006d89b8SEtienne Carriere * @scmi_id: SCMI voltage domain ID
340006d89b8SEtienne Carriere * Return pointer to name or NULL
341006d89b8SEtienne Carriere */
342659a1f88SEtienne Carriere const char *plat_scmi_voltd_get_name(unsigned int channel_id,
343006d89b8SEtienne Carriere unsigned int scmi_id);
344006d89b8SEtienne Carriere
345006d89b8SEtienne Carriere /*
346006d89b8SEtienne Carriere * Get voltage domain possible levels as an array of voltages in microvolt.
347006d89b8SEtienne Carriere *
348659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
349006d89b8SEtienne Carriere * @scmi_id: SCMI voltage domain ID
350006d89b8SEtienne Carriere * @start_index: Level index to start from.
351ec8c2914SEtienne Carriere * @levels: If NULL, function returns, else output rates array
352006d89b8SEtienne Carriere * @nb_elts: Array size of @levels.
353006d89b8SEtienne Carriere * Return an SCMI compliant error code
354006d89b8SEtienne Carriere */
355659a1f88SEtienne Carriere int32_t plat_scmi_voltd_levels_array(unsigned int channel_id,
356006d89b8SEtienne Carriere unsigned int scmi_id, size_t start_index,
357006d89b8SEtienne Carriere long *levels, size_t *nb_elts);
358006d89b8SEtienne Carriere
359006d89b8SEtienne Carriere /*
360006d89b8SEtienne Carriere * Get voltage domain possible levels as range with regular steps in microvolt
361006d89b8SEtienne Carriere *
362659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
363006d89b8SEtienne Carriere * @scmi_id: SCMI voltage domain ID
364006d89b8SEtienne Carriere * @min_max_step: 3 cell array for min, max and step voltage data
365006d89b8SEtienne Carriere * Return an SCMI compliant error code
366006d89b8SEtienne Carriere */
367659a1f88SEtienne Carriere int32_t plat_scmi_voltd_levels_by_step(unsigned int channel_id,
368006d89b8SEtienne Carriere unsigned int scmi_id,
369006d89b8SEtienne Carriere long *min_max_step);
370006d89b8SEtienne Carriere
371006d89b8SEtienne Carriere /*
372006d89b8SEtienne Carriere * Get current voltage domain level in microvolt
373659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
374006d89b8SEtienne Carriere * @scmi_id: SCMI voltage domain ID
3754afbdbddSAnton Eliasson * @level: Out parameter for the current voltage level
3764afbdbddSAnton Eliasson * Return an SCMI compliant error code
377006d89b8SEtienne Carriere */
3784afbdbddSAnton Eliasson int32_t plat_scmi_voltd_get_level(unsigned int channel_id, unsigned int scmi_id,
3794afbdbddSAnton Eliasson long *level);
380006d89b8SEtienne Carriere
381006d89b8SEtienne Carriere /*
382006d89b8SEtienne Carriere * Set voltage domain level voltage domain
383659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
384a286b03fSEtienne Carriere * @scmi_id: SCMI voltage domain ID
385006d89b8SEtienne Carriere * @level: Target voltage domain level in microvolt
386006d89b8SEtienne Carriere * Return a compliant SCMI error code
387006d89b8SEtienne Carriere */
388659a1f88SEtienne Carriere int32_t plat_scmi_voltd_set_level(unsigned int channel_id, unsigned int scmi_id,
389006d89b8SEtienne Carriere long level);
390006d89b8SEtienne Carriere
391006d89b8SEtienne Carriere /*
392006d89b8SEtienne Carriere * Get voltage domain state configuration (enabled or disabled)
393659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
394006d89b8SEtienne Carriere * @scmi_id: SCMI voltage domain ID
395ec8c2914SEtienne Carriere * @config: output state configuration value SCMI_VOLTAGE_DOMAIN_CONFIG_*
396006d89b8SEtienne Carriere * Return a compliant SCMI error code
397006d89b8SEtienne Carriere */
398659a1f88SEtienne Carriere int32_t plat_scmi_voltd_get_config(unsigned int channel_id,
399659a1f88SEtienne Carriere unsigned int scmi_id, uint32_t *config);
400006d89b8SEtienne Carriere
401006d89b8SEtienne Carriere /*
402006d89b8SEtienne Carriere * Get voltage domain state configuration (enabled or disabled)
403659a1f88SEtienne Carriere * @channel_id: SCMI channel ID
404ec8c2914SEtienne Carriere * @scmi_id: SCMI voltage domain ID
405ec8c2914SEtienne Carriere * @config: Target state configuration value SCMI_VOLTAGE_DOMAIN_CONFIG_*
406006d89b8SEtienne Carriere * Return a compliant SCMI error code
407006d89b8SEtienne Carriere */
408659a1f88SEtienne Carriere int32_t plat_scmi_voltd_set_config(unsigned int channel_id,
409659a1f88SEtienne Carriere unsigned int scmi_id, uint32_t config);
410006d89b8SEtienne Carriere
411*f1cec17aSPascal Paillet /* Handlers for SCMI Performance Domain Management protocol services */
412*f1cec17aSPascal Paillet
413*f1cec17aSPascal Paillet /*
414*f1cec17aSPascal Paillet * Return number of performance domains for the channel
415*f1cec17aSPascal Paillet * @channel_id: SCMI channel ID
416*f1cec17aSPascal Paillet * Return number of performance domains for the channel
417*f1cec17aSPascal Paillet */
418*f1cec17aSPascal Paillet size_t plat_scmi_perf_count(unsigned int channel_id);
419*f1cec17aSPascal Paillet
420*f1cec17aSPascal Paillet /*
421*f1cec17aSPascal Paillet * Return statistics on performance domains for the channel
422*f1cec17aSPascal Paillet * @channel_id: SCMI channel ID
423*f1cec17aSPascal Paillet * @stats_len: Output byte size of the statistics buffer or zero
424*f1cec17aSPascal Paillet * Return pointer to SCMI server statistics buffer for the channel or NULL
425*f1cec17aSPascal Paillet */
426*f1cec17aSPascal Paillet void *plat_scmi_perf_statistics_buf(unsigned int channel_id, size_t *stats_len);
427*f1cec17aSPascal Paillet
428*f1cec17aSPascal Paillet /*
429*f1cec17aSPascal Paillet * Get performance domain string ID (aka name)
430*f1cec17aSPascal Paillet * @channel_id: SCMI channel ID
431*f1cec17aSPascal Paillet * @domain_id: SCMI performance domain ID
432*f1cec17aSPascal Paillet * Return pointer to name or NULL
433*f1cec17aSPascal Paillet */
434*f1cec17aSPascal Paillet const char *plat_scmi_perf_domain_name(unsigned int channel_id,
435*f1cec17aSPascal Paillet unsigned int domain_id);
436*f1cec17aSPascal Paillet
437*f1cec17aSPascal Paillet /*
438*f1cec17aSPascal Paillet * Get performance domain sustained frequency
439*f1cec17aSPascal Paillet * @channel_id: SCMI channel ID
440*f1cec17aSPascal Paillet * @domain_id: SCMI performance domain ID
441*f1cec17aSPascal Paillet * @freq: Frequency value in KHz
442*f1cec17aSPascal Paillet * Return an SCMI compliant error code
443*f1cec17aSPascal Paillet */
444*f1cec17aSPascal Paillet int32_t plat_scmi_perf_sustained_freq(unsigned int channel_id,
445*f1cec17aSPascal Paillet unsigned int domain_id,
446*f1cec17aSPascal Paillet unsigned int *freq);
447*f1cec17aSPascal Paillet
448*f1cec17aSPascal Paillet /*
449*f1cec17aSPascal Paillet * Get performance domain possible levels as an array of unsigned int
450*f1cec17aSPascal Paillet *
451*f1cec17aSPascal Paillet * @channel_id: SCMI channel ID
452*f1cec17aSPascal Paillet * @domain_id: SCMI performance domain ID
453*f1cec17aSPascal Paillet * @start_index: Level index to start from
454*f1cec17aSPascal Paillet * @elt: Array where to store levels or NULL if querying only @nb_elts
455*f1cec17aSPascal Paillet * @nb_elts: [in] @elt array size, [out] number of levels
456*f1cec17aSPascal Paillet *
457*f1cec17aSPascal Paillet * When @elt is NULL, @nb_elt output value gives full number of levels
458*f1cec17aSPascal Paillet * remaining starting from @start_index. When @elt is not NULL,
459*f1cec17aSPascal Paillet * @nb_elt output value gives the number of levels stored in @elt.
460*f1cec17aSPascal Paillet * Return an SCMI compliant error code
461*f1cec17aSPascal Paillet */
462*f1cec17aSPascal Paillet int32_t plat_scmi_perf_levels_array(unsigned int channel_id,
463*f1cec17aSPascal Paillet unsigned int domain_id, size_t start_index,
464*f1cec17aSPascal Paillet unsigned int *elt, size_t *nb_elts);
465*f1cec17aSPascal Paillet
466*f1cec17aSPascal Paillet /*
467*f1cec17aSPascal Paillet * Get latency is microseconds for transition to target performance level.
468*f1cec17aSPascal Paillet * A default (weak) implementation outputs a latency value of 1 microsecond.
469*f1cec17aSPascal Paillet *
470*f1cec17aSPascal Paillet * @channel_id: SCMI channel ID
471*f1cec17aSPascal Paillet * @domain_id: SCMI performance domain ID
472*f1cec17aSPascal Paillet * @level: Target performance level
473*f1cec17aSPascal Paillet * @latency: Output latency value (microsecond) for the target level
474*f1cec17aSPascal Paillet * Return a compliant SCMI error code
475*f1cec17aSPascal Paillet */
476*f1cec17aSPascal Paillet int32_t plat_scmi_perf_level_latency(unsigned int channel_id,
477*f1cec17aSPascal Paillet unsigned int domain_id,
478*f1cec17aSPascal Paillet unsigned int level,
479*f1cec17aSPascal Paillet unsigned int *latency);
480*f1cec17aSPascal Paillet
481*f1cec17aSPascal Paillet /*
482*f1cec17aSPascal Paillet * Get power cost value related to target performance level.
483*f1cec17aSPascal Paillet * A default (weak) implementation outputs a power cost of 0.
484*f1cec17aSPascal Paillet *
485*f1cec17aSPascal Paillet * @channel_id: SCMI channel ID
486*f1cec17aSPascal Paillet * @domain_id: SCMI performance domain ID
487*f1cec17aSPascal Paillet * @level: Target performance level
488*f1cec17aSPascal Paillet * @power_cost: Output power cost for the performance level
489*f1cec17aSPascal Paillet * Return a compliant SCMI error code
490*f1cec17aSPascal Paillet */
491*f1cec17aSPascal Paillet int32_t plat_scmi_perf_level_power_cost(unsigned int channel_id,
492*f1cec17aSPascal Paillet unsigned int domain_id,
493*f1cec17aSPascal Paillet unsigned int level,
494*f1cec17aSPascal Paillet unsigned int *power_cost);
495*f1cec17aSPascal Paillet
496*f1cec17aSPascal Paillet /*
497*f1cec17aSPascal Paillet * Get current performance level of the domain
498*f1cec17aSPascal Paillet * @channel_id: SCMI channel ID
499*f1cec17aSPascal Paillet * @domain_id: SCMI performance domain ID
500*f1cec17aSPascal Paillet * @level: Output performance level
501*f1cec17aSPascal Paillet * Return a compliant SCMI error code
502*f1cec17aSPascal Paillet */
503*f1cec17aSPascal Paillet int32_t plat_scmi_perf_level_get(unsigned int channel_id,
504*f1cec17aSPascal Paillet unsigned int domain_id, unsigned int *level);
505*f1cec17aSPascal Paillet
506*f1cec17aSPascal Paillet /*
507*f1cec17aSPascal Paillet * Request change of performance level for the domain
508*f1cec17aSPascal Paillet * @channel_id: SCMI channel ID
509*f1cec17aSPascal Paillet * @domain_id: SCMI performance domain ID
510*f1cec17aSPascal Paillet * @level: Target performance level
511*f1cec17aSPascal Paillet * Return a compliant SCMI error code
512*f1cec17aSPascal Paillet */
513*f1cec17aSPascal Paillet int32_t plat_scmi_perf_level_set(unsigned int channel_id,
514*f1cec17aSPascal Paillet unsigned int domain_id, unsigned int level);
515fbe66cf8SEtienne Carriere #endif /* __DRIVERS_SCMI_MSG_H */
516