xref: /optee_os/core/include/drivers/scmi-msg.h (revision a7a9e3ba71dd908aafdc4c5ed9b29b15faa9692d)
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 <compiler.h>
11 #include <kernel/panic.h>
12 #include <mm/core_memprot.h>
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 /* Minimum size expected for SMT based shared memory message buffers */
18 #define SMT_BUF_SLOT_SIZE	128
19 
20 /* A channel abstract a communication path between agent and server */
21 struct scmi_msg_channel;
22 
23 /*
24  * struct scmi_msg_channel - Shared memory buffer for a agent-to-server channel
25  *
26  * @shm_addr: Address of the shared memory for the SCMI channel
27  * @shm_size: Byte size of the shared memory for the SCMI channel
28  * @busy: True when channel is busy, flase when channel is free
29  * @threaded: True is executed in a threaded context, false otherwise
30  * @agent_name: Optional agent name, SCMI protocol exposes 16 bytes max
31  */
32 struct scmi_msg_channel {
33 	struct io_pa_va shm_addr;
34 	size_t shm_size;
35 	bool busy;
36 	bool threaded;
37 	const char *agent_name;
38 };
39 
40 /* Platform callback functions */
41 
42 /*
43  * Return the SCMI channel related to an agent
44  * @agent_id: SCMI agent ID
45  * Return a pointer to channel on success, NULL otherwise
46  */
47 struct scmi_msg_channel *plat_scmi_get_channel(unsigned int agent_id);
48 
49 /*
50  * Return how many SCMI protocols supported by the platform
51  * According to the SCMI specification, this function does not target
52  * a specific agent ID and shall return all platform known capabilities.
53  */
54 size_t plat_scmi_protocol_count(void);
55 
56 /*
57  * Get the count and list of SCMI protocols (but base) supported for an agent
58  *
59  * @agent_id: SCMI agent ID
60  * Return a pointer to a null terminated array supported protocol IDs.
61  */
62 const uint8_t *plat_scmi_protocol_list(unsigned int agent_id);
63 
64 /* Get the name of the SCMI vendor for the platform */
65 const char *plat_scmi_vendor_name(void);
66 
67 /* Get the name of the SCMI sub-vendor for the platform */
68 const char *plat_scmi_sub_vendor_name(void);
69 
70 /* Handlers for SCMI Clock protocol services */
71 
72 /*
73  * Return number of clock controllers for an agent
74  * @agent_id: SCMI agent ID
75  * Return number of clock controllers
76  */
77 size_t plat_scmi_clock_count(unsigned int agent_id);
78 
79 /*
80  * Get clock controller string ID (aka name)
81  * @agent_id: SCMI agent ID
82  * @scmi_id: SCMI clock ID
83  * Return pointer to name or NULL
84  */
85 const char *plat_scmi_clock_get_name(unsigned int agent_id,
86 				     unsigned int scmi_id);
87 
88 /*
89  * Get clock possible rate as an array of frequencies in Hertz.
90  *
91  * @agent_id: SCMI agent ID
92  * @scmi_id: SCMI clock ID
93  * @rates: If NULL, function returns, else output rates array
94  * @nb_elts: Array size of @rates.
95  * Return an SCMI compliant error code
96  */
97 int32_t plat_scmi_clock_rates_array(unsigned int agent_id, unsigned int scmi_id,
98 				    unsigned long *rates, size_t *nb_elts);
99 
100 /*
101  * Get clock possible rate as range with regular steps in Hertz
102  *
103  * @agent_id: SCMI agent ID
104  * @scmi_id: SCMI clock ID
105  * @min_max_step: 3 cell array for min, max and step rate data
106  * Return an SCMI compliant error code
107  */
108 int32_t plat_scmi_clock_rates_by_step(unsigned int agent_id,
109 				      unsigned int scmi_id,
110 				      unsigned long *min_max_step);
111 
112 /*
113  * Get clock rate in Hertz
114  * @agent_id: SCMI agent ID
115  * @scmi_id: SCMI clock ID
116  * Return clock rate or 0 if not supported
117  */
118 unsigned long plat_scmi_clock_get_rate(unsigned int agent_id,
119 				       unsigned int scmi_id);
120 
121 /*
122  * Set clock rate in Hertz
123  * @agent_id: SCMI agent ID
124  * @scmi_id: SCMI clock ID
125  * @rate: Target clock frequency in Hertz
126  * Return a compliant SCMI error code
127  */
128 int32_t plat_scmi_clock_set_rate(unsigned int agent_id, unsigned int scmi_id,
129 				 unsigned long rate);
130 
131 /*
132  * Get clock state (enabled or disabled)
133  * @agent_id: SCMI agent ID
134  * @scmi_id: SCMI clock ID
135  * Return 1 if clock is enabled, 0 if disables, or a negative SCMI error code
136  */
137 int32_t plat_scmi_clock_get_state(unsigned int agent_id, unsigned int scmi_id);
138 
139 /*
140  * Get clock state (enabled or disabled)
141  * @agent_id: SCMI agent ID
142  * @scmi_id: SCMI clock ID
143  * @enable_not_disable: Enable clock if true, disable clock otherwise
144  * Return a compliant SCMI error code
145  */
146 int32_t plat_scmi_clock_set_state(unsigned int agent_id, unsigned int scmi_id,
147 				  bool enable_not_disable);
148 #endif /* SCMI_MSG_H */
149