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 7ae8c8068SEtienne Carriere #ifndef SCMI_MSG_H 8ae8c8068SEtienne Carriere #define 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 */ 18ae8c8068SEtienne Carriere #define SMT_BUF_SLOT_SIZE 128 19ae8c8068SEtienne Carriere 20c22983c9SEtienne Carriere /* Standard values for SCMI voltage domain protocol configuration state */ 21c22983c9SEtienne Carriere #define SCMI_VOLTAGE_DOMAIN_CONFIG_ARCH_ON 0x7 22c22983c9SEtienne Carriere #define SCMI_VOLTAGE_DOMAIN_CONFIG_ARCH_OFF 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 42*9ed56ecdSEtienne 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 * 48a58c4d70SEtienne Carriere * @chan: Pointer to the channel shared memory to be initialized 49a58c4d70SEtienne Carriere */ 50*9ed56ecdSEtienne Carriere void scmi_smt_init_agent_channel(struct scmi_msg_channel *channel); 51*9ed56ecdSEtienne Carriere #else 52*9ed56ecdSEtienne Carriere static inline 53*9ed56ecdSEtienne Carriere void scmi_smt_init_agent_channel(struct scmi_msg_channel *channel __unused) 54*9ed56ecdSEtienne Carriere { 55*9ed56ecdSEtienne Carriere panic(); 56*9ed56ecdSEtienne Carriere } 57*9ed56ecdSEtienne Carriere #endif 58a58c4d70SEtienne Carriere 59*9ed56ecdSEtienne Carriere #ifdef CFG_SCMI_MSG_SMT_FASTCALL_ENTRY 60a58c4d70SEtienne Carriere /* 61064bf8dcSEtienne Carriere * Process SMT formatted message in a fastcall SMC execution context. 62a58c4d70SEtienne Carriere * Called by platform on SMC entry. When returning, output message is 63a58c4d70SEtienne Carriere * available in shared memory for agent to read the response. 64a58c4d70SEtienne Carriere * This function depends on CFG_SCMI_MSG_SMT_FASTCALL_ENTRY. 65a58c4d70SEtienne Carriere * 66659a1f88SEtienne Carriere * @channel_id: SCMI channel ID the SMT belongs to 67a58c4d70SEtienne Carriere */ 68659a1f88SEtienne Carriere void scmi_smt_fastcall_smc_entry(unsigned int channel_id); 69*9ed56ecdSEtienne Carriere #else 70*9ed56ecdSEtienne Carriere static inline void scmi_smt_fastcall_smc_entry(unsigned int channel_id __unused) 71*9ed56ecdSEtienne Carriere { 72*9ed56ecdSEtienne Carriere } 73*9ed56ecdSEtienne Carriere #endif 74a58c4d70SEtienne Carriere 75*9ed56ecdSEtienne Carriere #ifdef CFG_SCMI_MSG_SMT_INTERRUPT_ENTRY 76a58c4d70SEtienne Carriere /* 77a58c4d70SEtienne Carriere * Process SMT formatted message in a secure interrupt execution context. 78a58c4d70SEtienne Carriere * Called by platform interrupt handler. When returning, output message is 79a58c4d70SEtienne Carriere * available in shared memory for agent to read the response. 80a58c4d70SEtienne Carriere * This function depends on CFG_SCMI_MSG_SMT_INTERRUPT_ENTRY. 81a58c4d70SEtienne Carriere * 82659a1f88SEtienne Carriere * @channel_id: SCMI channel ID the SMT belongs to 83a58c4d70SEtienne Carriere */ 84659a1f88SEtienne Carriere void scmi_smt_interrupt_entry(unsigned int channel_id); 85*9ed56ecdSEtienne Carriere #else 86*9ed56ecdSEtienne Carriere static inline void scmi_smt_interrupt_entry(unsigned int channel_id __unused) 87*9ed56ecdSEtienne Carriere { 88*9ed56ecdSEtienne Carriere } 89*9ed56ecdSEtienne Carriere #endif 90a58c4d70SEtienne Carriere 91*9ed56ecdSEtienne Carriere #ifdef CFG_SCMI_MSG_SMT_THREAD_ENTRY 92a58c4d70SEtienne Carriere /* 93a58c4d70SEtienne Carriere * Process SMT formatted message in a TEE thread execution context. 94a58c4d70SEtienne Carriere * When returning, output message is available in shared memory for 95a58c4d70SEtienne Carriere * agent to read the response. 96a58c4d70SEtienne Carriere * This function depends on CFG_SCMI_MSG_SMT_THREAD_ENTRY. 97a58c4d70SEtienne Carriere * 98659a1f88SEtienne Carriere * @channel_id: SCMI channel ID the SMT belongs to 99a58c4d70SEtienne Carriere */ 100659a1f88SEtienne Carriere void scmi_smt_threaded_entry(unsigned int channel_id); 101*9ed56ecdSEtienne Carriere #else 102*9ed56ecdSEtienne Carriere static inline void scmi_smt_threaded_entry(unsigned int channel_id __unused) 103*9ed56ecdSEtienne Carriere { 104*9ed56ecdSEtienne Carriere } 105*9ed56ecdSEtienne Carriere #endif 106a58c4d70SEtienne Carriere 107ae8c8068SEtienne Carriere /* Platform callback functions */ 108ae8c8068SEtienne Carriere 109ae8c8068SEtienne Carriere /* 110ae8c8068SEtienne Carriere * Return the SCMI channel related to an agent 111659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 112ae8c8068SEtienne Carriere * Return a pointer to channel on success, NULL otherwise 113ae8c8068SEtienne Carriere */ 114659a1f88SEtienne Carriere struct scmi_msg_channel *plat_scmi_get_channel(unsigned int channel_id); 115ae8c8068SEtienne Carriere 116ae8c8068SEtienne Carriere /* 117ae8c8068SEtienne Carriere * Return how many SCMI protocols supported by the platform 118ae8c8068SEtienne Carriere * According to the SCMI specification, this function does not target 119659a1f88SEtienne Carriere * a specific channel ID and shall return all platform known capabilities. 120ae8c8068SEtienne Carriere */ 121ae8c8068SEtienne Carriere size_t plat_scmi_protocol_count(void); 122ae8c8068SEtienne Carriere 123ae8c8068SEtienne Carriere /* 124ae8c8068SEtienne Carriere * Get the count and list of SCMI protocols (but base) supported for an agent 125ae8c8068SEtienne Carriere * 126659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 127ae8c8068SEtienne Carriere * Return a pointer to a null terminated array supported protocol IDs. 128ae8c8068SEtienne Carriere */ 129659a1f88SEtienne Carriere const uint8_t *plat_scmi_protocol_list(unsigned int channel_id); 130ae8c8068SEtienne Carriere 131ae8c8068SEtienne Carriere /* Get the name of the SCMI vendor for the platform */ 132ae8c8068SEtienne Carriere const char *plat_scmi_vendor_name(void); 133ae8c8068SEtienne Carriere 134ae8c8068SEtienne Carriere /* Get the name of the SCMI sub-vendor for the platform */ 135ae8c8068SEtienne Carriere const char *plat_scmi_sub_vendor_name(void); 136ae8c8068SEtienne Carriere 137a7a9e3baSEtienne Carriere /* Handlers for SCMI Clock protocol services */ 138a7a9e3baSEtienne Carriere 139a7a9e3baSEtienne Carriere /* 140a7a9e3baSEtienne Carriere * Return number of clock controllers for an agent 141659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 142a7a9e3baSEtienne Carriere * Return number of clock controllers 143a7a9e3baSEtienne Carriere */ 144659a1f88SEtienne Carriere size_t plat_scmi_clock_count(unsigned int channel_id); 145a7a9e3baSEtienne Carriere 146a7a9e3baSEtienne Carriere /* 147a7a9e3baSEtienne Carriere * Get clock controller string ID (aka name) 148659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 149a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID 150a7a9e3baSEtienne Carriere * Return pointer to name or NULL 151a7a9e3baSEtienne Carriere */ 152659a1f88SEtienne Carriere const char *plat_scmi_clock_get_name(unsigned int channel_id, 153a7a9e3baSEtienne Carriere unsigned int scmi_id); 154a7a9e3baSEtienne Carriere 155a7a9e3baSEtienne Carriere /* 156a7a9e3baSEtienne Carriere * Get clock possible rate as an array of frequencies in Hertz. 157a7a9e3baSEtienne Carriere * 158659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 159a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID 160d9be1b35SEtienne Carriere * @start_index: Requested start index for the exposed rates array 161ec8c2914SEtienne Carriere * @rates: If NULL, function returns, else output rates array 162a7a9e3baSEtienne Carriere * @nb_elts: Array size of @rates. 163a7a9e3baSEtienne Carriere * Return an SCMI compliant error code 164a7a9e3baSEtienne Carriere */ 165659a1f88SEtienne Carriere int32_t plat_scmi_clock_rates_array(unsigned int channel_id, 166659a1f88SEtienne Carriere unsigned int scmi_id, size_t start_index, 167659a1f88SEtienne Carriere unsigned long *rates, size_t *nb_elts); 168a7a9e3baSEtienne Carriere 169a7a9e3baSEtienne Carriere /* 170a7a9e3baSEtienne Carriere * Get clock possible rate as range with regular steps in Hertz 171a7a9e3baSEtienne Carriere * 172659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 173a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID 174a7a9e3baSEtienne Carriere * @min_max_step: 3 cell array for min, max and step rate data 175a7a9e3baSEtienne Carriere * Return an SCMI compliant error code 176a7a9e3baSEtienne Carriere */ 177659a1f88SEtienne Carriere int32_t plat_scmi_clock_rates_by_step(unsigned int channel_id, 178a7a9e3baSEtienne Carriere unsigned int scmi_id, 179a7a9e3baSEtienne Carriere unsigned long *min_max_step); 180a7a9e3baSEtienne Carriere 181a7a9e3baSEtienne Carriere /* 182a7a9e3baSEtienne Carriere * Get clock rate in Hertz 183659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 184a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID 185a7a9e3baSEtienne Carriere * Return clock rate or 0 if not supported 186a7a9e3baSEtienne Carriere */ 187659a1f88SEtienne Carriere unsigned long plat_scmi_clock_get_rate(unsigned int channel_id, 188a7a9e3baSEtienne Carriere unsigned int scmi_id); 189a7a9e3baSEtienne Carriere 190a7a9e3baSEtienne Carriere /* 191a7a9e3baSEtienne Carriere * Set clock rate in Hertz 192659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 193a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID 194a7a9e3baSEtienne Carriere * @rate: Target clock frequency in Hertz 195a7a9e3baSEtienne Carriere * Return a compliant SCMI error code 196a7a9e3baSEtienne Carriere */ 197659a1f88SEtienne Carriere int32_t plat_scmi_clock_set_rate(unsigned int channel_id, unsigned int scmi_id, 198a7a9e3baSEtienne Carriere unsigned long rate); 199a7a9e3baSEtienne Carriere 200a7a9e3baSEtienne Carriere /* 201a7a9e3baSEtienne Carriere * Get clock state (enabled or disabled) 202659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 203a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID 204a7a9e3baSEtienne Carriere * Return 1 if clock is enabled, 0 if disables, or a negative SCMI error code 205a7a9e3baSEtienne Carriere */ 206659a1f88SEtienne Carriere int32_t plat_scmi_clock_get_state(unsigned int channel_id, 207659a1f88SEtienne Carriere unsigned int scmi_id); 208a7a9e3baSEtienne Carriere 209a7a9e3baSEtienne Carriere /* 210a7a9e3baSEtienne Carriere * Get clock state (enabled or disabled) 211659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 212a7a9e3baSEtienne Carriere * @scmi_id: SCMI clock ID 213a7a9e3baSEtienne Carriere * @enable_not_disable: Enable clock if true, disable clock otherwise 214a7a9e3baSEtienne Carriere * Return a compliant SCMI error code 215a7a9e3baSEtienne Carriere */ 216659a1f88SEtienne Carriere int32_t plat_scmi_clock_set_state(unsigned int channel_id, unsigned int scmi_id, 217a7a9e3baSEtienne Carriere bool enable_not_disable); 21856a1f10eSEtienne Carriere 21956a1f10eSEtienne Carriere /* Handlers for SCMI Reset Domain protocol services */ 22056a1f10eSEtienne Carriere 22156a1f10eSEtienne Carriere /* 22256a1f10eSEtienne Carriere * Return number of reset domains for the agent 223659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 22456a1f10eSEtienne Carriere * Return number of reset domains 22556a1f10eSEtienne Carriere */ 226659a1f88SEtienne Carriere size_t plat_scmi_rd_count(unsigned int channel_id); 22756a1f10eSEtienne Carriere 22856a1f10eSEtienne Carriere /* 22956a1f10eSEtienne Carriere * Get reset domain string ID (aka name) 230659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 23156a1f10eSEtienne Carriere * @scmi_id: SCMI reset domain ID 23256a1f10eSEtienne Carriere * Return pointer to name or NULL 23356a1f10eSEtienne Carriere */ 234659a1f88SEtienne Carriere const char *plat_scmi_rd_get_name(unsigned int channel_id, 235659a1f88SEtienne Carriere unsigned int scmi_id); 23656a1f10eSEtienne Carriere 23756a1f10eSEtienne Carriere /* 23856a1f10eSEtienne Carriere * Perform a reset cycle on a target reset domain 239659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 24056a1f10eSEtienne Carriere * @scmi_id: SCMI reset domain ID 24156a1f10eSEtienne Carriere * @state: Target reset state (see SCMI specification, 0 means context loss) 24256a1f10eSEtienne Carriere * Return a compliant SCMI error code 24356a1f10eSEtienne Carriere */ 244659a1f88SEtienne Carriere int32_t plat_scmi_rd_autonomous(unsigned int channel_id, unsigned int scmi_id, 24556a1f10eSEtienne Carriere unsigned int state); 24656a1f10eSEtienne Carriere 24756a1f10eSEtienne Carriere /* 24856a1f10eSEtienne Carriere * Assert or deassert target reset domain 249659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 25056a1f10eSEtienne Carriere * @scmi_id: SCMI reset domain ID 25156a1f10eSEtienne Carriere * @assert_not_deassert: Assert domain if true, otherwise deassert domain 25256a1f10eSEtienne Carriere * Return a compliant SCMI error code 25356a1f10eSEtienne Carriere */ 254659a1f88SEtienne Carriere int32_t plat_scmi_rd_set_state(unsigned int channel_id, unsigned int scmi_id, 25556a1f10eSEtienne Carriere bool assert_not_deassert); 25656a1f10eSEtienne Carriere 257006d89b8SEtienne Carriere /* Handlers for SCMI Voltage Domain protocol services */ 258006d89b8SEtienne Carriere 259006d89b8SEtienne Carriere /* 260006d89b8SEtienne Carriere * Return number of voltage domain for an agent 261659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 262006d89b8SEtienne Carriere * Return number of voltage domains 263006d89b8SEtienne Carriere */ 264659a1f88SEtienne Carriere size_t plat_scmi_voltd_count(unsigned int channel_id); 265006d89b8SEtienne Carriere 266006d89b8SEtienne Carriere /* 267006d89b8SEtienne Carriere * Get clock controller string ID (aka name) 268659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 269006d89b8SEtienne Carriere * @scmi_id: SCMI voltage domain ID 270006d89b8SEtienne Carriere * Return pointer to name or NULL 271006d89b8SEtienne Carriere */ 272659a1f88SEtienne Carriere const char *plat_scmi_voltd_get_name(unsigned int channel_id, 273006d89b8SEtienne Carriere unsigned int scmi_id); 274006d89b8SEtienne Carriere 275006d89b8SEtienne Carriere /* 276006d89b8SEtienne Carriere * Get voltage domain possible levels as an array of voltages in microvolt. 277006d89b8SEtienne Carriere * 278659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 279006d89b8SEtienne Carriere * @scmi_id: SCMI voltage domain ID 280006d89b8SEtienne Carriere * @start_index: Level index to start from. 281ec8c2914SEtienne Carriere * @levels: If NULL, function returns, else output rates array 282006d89b8SEtienne Carriere * @nb_elts: Array size of @levels. 283006d89b8SEtienne Carriere * Return an SCMI compliant error code 284006d89b8SEtienne Carriere */ 285659a1f88SEtienne Carriere int32_t plat_scmi_voltd_levels_array(unsigned int channel_id, 286006d89b8SEtienne Carriere unsigned int scmi_id, size_t start_index, 287006d89b8SEtienne Carriere long *levels, size_t *nb_elts); 288006d89b8SEtienne Carriere 289006d89b8SEtienne Carriere /* 290006d89b8SEtienne Carriere * Get voltage domain possible levels as range with regular steps in microvolt 291006d89b8SEtienne Carriere * 292659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 293006d89b8SEtienne Carriere * @scmi_id: SCMI voltage domain ID 294006d89b8SEtienne Carriere * @min_max_step: 3 cell array for min, max and step voltage data 295006d89b8SEtienne Carriere * Return an SCMI compliant error code 296006d89b8SEtienne Carriere */ 297659a1f88SEtienne Carriere int32_t plat_scmi_voltd_levels_by_step(unsigned int channel_id, 298006d89b8SEtienne Carriere unsigned int scmi_id, 299006d89b8SEtienne Carriere long *min_max_step); 300006d89b8SEtienne Carriere 301006d89b8SEtienne Carriere /* 302006d89b8SEtienne Carriere * Get current voltage domain level in microvolt 303659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 304006d89b8SEtienne Carriere * @scmi_id: SCMI voltage domain ID 305006d89b8SEtienne Carriere * Return clock rate or 0 if not supported 306006d89b8SEtienne Carriere */ 307659a1f88SEtienne Carriere long plat_scmi_voltd_get_level(unsigned int channel_id, unsigned int scmi_id); 308006d89b8SEtienne Carriere 309006d89b8SEtienne Carriere /* 310006d89b8SEtienne Carriere * Set voltage domain level voltage domain 311659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 312006d89b8SEtienne Carriere * @scmi_id: SCMI clock ID 313006d89b8SEtienne Carriere * @level: Target voltage domain level in microvolt 314006d89b8SEtienne Carriere * Return a compliant SCMI error code 315006d89b8SEtienne Carriere */ 316659a1f88SEtienne Carriere int32_t plat_scmi_voltd_set_level(unsigned int channel_id, unsigned int scmi_id, 317006d89b8SEtienne Carriere long level); 318006d89b8SEtienne Carriere 319006d89b8SEtienne Carriere /* 320006d89b8SEtienne Carriere * Get voltage domain state configuration (enabled or disabled) 321659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 322006d89b8SEtienne Carriere * @scmi_id: SCMI voltage domain ID 323ec8c2914SEtienne Carriere * @config: output state configuration value SCMI_VOLTAGE_DOMAIN_CONFIG_* 324006d89b8SEtienne Carriere * Return a compliant SCMI error code 325006d89b8SEtienne Carriere */ 326659a1f88SEtienne Carriere int32_t plat_scmi_voltd_get_config(unsigned int channel_id, 327659a1f88SEtienne Carriere unsigned int scmi_id, uint32_t *config); 328006d89b8SEtienne Carriere 329006d89b8SEtienne Carriere /* 330006d89b8SEtienne Carriere * Get voltage domain state configuration (enabled or disabled) 331659a1f88SEtienne Carriere * @channel_id: SCMI channel ID 332ec8c2914SEtienne Carriere * @scmi_id: SCMI voltage domain ID 333ec8c2914SEtienne Carriere * @config: Target state configuration value SCMI_VOLTAGE_DOMAIN_CONFIG_* 334006d89b8SEtienne Carriere * Return a compliant SCMI error code 335006d89b8SEtienne Carriere */ 336659a1f88SEtienne Carriere int32_t plat_scmi_voltd_set_config(unsigned int channel_id, 337659a1f88SEtienne Carriere unsigned int scmi_id, uint32_t config); 338006d89b8SEtienne Carriere 339ae8c8068SEtienne Carriere #endif /* SCMI_MSG_H */ 340