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 <stdbool.h> 11 #include <stddef.h> 12 #include <stdint.h> 13 14 /* Minimum size expected for SMT based shared memory message buffers */ 15 #define SMT_BUF_SLOT_SIZE 128U 16 17 /* A channel abstract a communication path between agent and server */ 18 struct scmi_msg_channel; 19 20 /* 21 * struct scmi_msg_channel - Shared memory buffer for a agent-to-server channel 22 * 23 * @shm_addr: Address of the shared memory for the SCMI channel 24 * @shm_size: Byte size of the shared memory for the SCMI channel 25 * @busy: True when channel is busy, false when channel is free 26 * @agent_name: Agent name, SCMI protocol exposes 16 bytes max, or NULL 27 */ 28 struct scmi_msg_channel { 29 uintptr_t shm_addr; 30 size_t shm_size; 31 bool busy; 32 const char *agent_name; 33 }; 34 35 /* 36 * Initialize SMT memory buffer, called by platform at init for each 37 * agent channel using the SMT header format. 38 * 39 * @chan: Pointer to the channel shared memory to be initialized 40 */ 41 void scmi_smt_init_agent_channel(struct scmi_msg_channel *chan); 42 43 /* 44 * Process SMT formatted message in a fastcall SMC execution context. 45 * Called by platform on SMC entry. When returning, output message is 46 * available in shared memory for agent to read the response. 47 * 48 * @agent_id: SCMI agent ID the SMT belongs to 49 */ 50 void scmi_smt_fastcall_smc_entry(unsigned int agent_id); 51 52 /* 53 * Process SMT formatted message in a secure interrupt execution context. 54 * Called by platform interrupt handler. When returning, output message is 55 * available in shared memory for agent to read the response. 56 * 57 * @agent_id: SCMI agent ID the SMT belongs to 58 */ 59 void scmi_smt_interrupt_entry(unsigned int agent_id); 60 61 /* Platform callback functions */ 62 63 /* 64 * Return the SCMI channel related to an agent 65 * @agent_id: SCMI agent ID 66 * Return a pointer to channel on success, NULL otherwise 67 */ 68 struct scmi_msg_channel *plat_scmi_get_channel(unsigned int agent_id); 69 70 /* 71 * Return how many SCMI protocols supported by the platform 72 * According to the SCMI specification, this function does not target 73 * a specific agent ID and shall return all platform known capabilities. 74 */ 75 size_t plat_scmi_protocol_count(void); 76 77 /* 78 * Get the count and list of SCMI protocols (but base) supported for an agent 79 * 80 * @agent_id: SCMI agent ID 81 * Return a pointer to a null terminated array supported protocol IDs. 82 */ 83 const uint8_t *plat_scmi_protocol_list(unsigned int agent_id); 84 85 /* Get the name of the SCMI vendor for the platform */ 86 const char *plat_scmi_vendor_name(void); 87 88 /* Get the name of the SCMI sub-vendor for the platform */ 89 const char *plat_scmi_sub_vendor_name(void); 90 91 /* Handlers for SCMI Clock protocol services */ 92 93 /* 94 * Return number of clock controllers for an agent 95 * @agent_id: SCMI agent ID 96 * Return number of clock controllers 97 */ 98 size_t plat_scmi_clock_count(unsigned int agent_id); 99 100 /* 101 * Get clock controller string ID (aka name) 102 * @agent_id: SCMI agent ID 103 * @scmi_id: SCMI clock ID 104 * Return pointer to name or NULL 105 */ 106 const char *plat_scmi_clock_get_name(unsigned int agent_id, 107 unsigned int scmi_id); 108 109 /* 110 * Get clock enable delay in microseconds 111 * @agent_id: SCMI agent ID 112 * @scmi_id: SCMI clock ID 113 * Return delay or zero if not supported 114 */ 115 uint32_t plat_scmi_clock_get_enable_delay(unsigned int agent_id, 116 unsigned int scmi_id); 117 118 /* 119 * Get clock possible rate as an array of frequencies in Hertz. 120 * 121 * @agent_id: SCMI agent ID 122 * @scmi_id: SCMI clock ID 123 * @rates: If NULL, function returns, else output rates array 124 * @nb_elts: Array size of @rates. 125 * @start_idx: Start index of rates array 126 * Return an SCMI compliant error code 127 */ 128 int32_t plat_scmi_clock_rates_array(unsigned int agent_id, unsigned int scmi_id, 129 unsigned long *rates, size_t *nb_elts, 130 uint32_t start_idx); 131 132 /* 133 * Get clock possible rate as range with regular steps in Hertz 134 * 135 * @agent_id: SCMI agent ID 136 * @scmi_id: SCMI clock ID 137 * @min_max_step: 3 cell array for min, max and step rate data 138 * Return an SCMI compliant error code 139 */ 140 int32_t plat_scmi_clock_rates_by_step(unsigned int agent_id, 141 unsigned int scmi_id, 142 unsigned long *min_max_step); 143 /* 144 * Get clock possible parents as an array of parent ids 145 * @agent_id: SCMI agent ID 146 * @scmi_id: SCMI clock ID 147 * @plat_possible_parents: If NULL, function returns, 148 * else output possible parents array 149 * @nb_elts: Array size of @plat_possible_parents 150 * @skip_parents: Number of parents to skip for 2nd iteration onwards 151 * Return an SCMI compliant error code 152 */ 153 int32_t plat_scmi_clock_get_possible_parents(unsigned int agent_id, 154 unsigned int scmi_id, 155 unsigned int *plat_possible_parents, 156 size_t *nb_elts, 157 unsigned int skip_parents); 158 /* 159 * Get clock parent 160 * @agent_id: SCMI agent ID 161 * @scmi_id: SCMI clock ID 162 * @parent_id: Target parent id 163 * Return a compliant SCMI error code 164 */ 165 int32_t plat_scmi_clock_get_parent(unsigned int agent_id, 166 unsigned int scmi_id, 167 unsigned int *parent_id); 168 /* 169 * Set clock parent 170 * @agent_id: SCMI agent ID 171 * @scmi_id: SCMI clock ID 172 * @parent_id: Target parent id 173 * Return a compliant SCMI error code 174 */ 175 int32_t plat_scmi_clock_set_parent(unsigned int agent_id, 176 unsigned int scmi_id, 177 unsigned int parent_id); 178 179 /* 180 * Get clock rate in Hertz 181 * @agent_id: SCMI agent ID 182 * @scmi_id: SCMI clock ID 183 * Return clock rate or 0 if not supported 184 */ 185 unsigned long plat_scmi_clock_get_rate(unsigned int agent_id, 186 unsigned int scmi_id); 187 188 /* 189 * Set clock rate in Hertz 190 * @agent_id: SCMI agent ID 191 * @scmi_id: SCMI clock ID 192 * @rate: Target clock frequency in Hertz 193 * Return a compliant SCMI error code 194 */ 195 int32_t plat_scmi_clock_set_rate(unsigned int agent_id, unsigned int scmi_id, 196 unsigned long rate); 197 198 /* 199 * Get clock state (enabled or disabled) 200 * @agent_id: SCMI agent ID 201 * @scmi_id: SCMI clock ID 202 * Return 1 if clock is enabled, 0 if disables, or a negative SCMI error code 203 */ 204 int32_t plat_scmi_clock_get_state(unsigned int agent_id, unsigned int scmi_id); 205 206 /* 207 * Get clock state (enabled or disabled) 208 * @agent_id: SCMI agent ID 209 * @scmi_id: SCMI clock ID 210 * @enable_not_disable: Enable clock if true, disable clock otherwise 211 * Return a compliant SCMI error code 212 */ 213 int32_t plat_scmi_clock_set_state(unsigned int agent_id, unsigned int scmi_id, 214 bool enable_not_disable); 215 216 /* 217 * Get clock extended config 218 * @agent_id: SCMI agent ID 219 * @scmi_id: SCMI clock ID 220 * @extended_config_type: Type of Extended config value 221 * @extended_config_val: Value corresponding to extended configuration type 222 * Return a compliant SCMI error code 223 */ 224 int32_t plat_scmi_clock_get_extended_config(unsigned int agent_id, 225 unsigned int scmi_id, 226 unsigned char extended_config_type, 227 unsigned int *extended_config_val); 228 229 /* 230 * Set clock extended config 231 * @agent_id: SCMI agent ID 232 * @scmi_id: SCMI clock ID 233 * @extended_config_type: Type of Extended config value 234 * @extended_config_val: Value corresponding to extended configuration type 235 * Return a compliant SCMI error code 236 */ 237 int32_t plat_scmi_clock_set_extended_config(unsigned int agent_id, 238 unsigned int scmi_id, 239 unsigned char extended_config_type, 240 unsigned int extended_config_val); 241 242 /* Handlers for SCMI Reset Domain protocol services */ 243 244 /* 245 * Return number of reset domains for the agent 246 * @agent_id: SCMI agent ID 247 * Return number of reset domains 248 */ 249 size_t plat_scmi_rstd_count(unsigned int agent_id); 250 251 /* 252 * Get reset domain string ID (aka name) 253 * @agent_id: SCMI agent ID 254 * @scmi_id: SCMI reset domain ID 255 * Return pointer to name or NULL 256 */ 257 const char *plat_scmi_rstd_get_name(unsigned int agent_id, unsigned int scmi_id); 258 259 /* 260 * Perform a reset cycle on a target reset domain 261 * @agent_id: SCMI agent ID 262 * @scmi_id: SCMI reset domain ID 263 * @state: Target reset state (see SCMI specification, 0 means context loss) 264 * Return a compliant SCMI error code 265 */ 266 int32_t plat_scmi_rstd_autonomous(unsigned int agent_id, unsigned int scmi_id, 267 unsigned int state); 268 269 /* 270 * Assert or deassert target reset domain 271 * @agent_id: SCMI agent ID 272 * @scmi_id: SCMI reset domain ID 273 * @assert_not_deassert: Assert domain if true, otherwise deassert domain 274 * Return a compliant SCMI error code 275 */ 276 int32_t plat_scmi_rstd_set_state(unsigned int agent_id, unsigned int scmi_id, 277 bool assert_not_deassert); 278 279 #endif /* SCMI_MSG_H */ 280