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