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