Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 1 | /* |
Roberto Vargas | 2b36b15 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <assert.h> |
| 9 | #include <css_def.h> |
| 10 | #include <css_pm.h> |
| 11 | #include <debug.h> |
| 12 | #include <plat_arm.h> |
| 13 | #include <platform.h> |
| 14 | #include <string.h> |
| 15 | #include "../scmi/scmi.h" |
Samarth Parikh | 59cfa13 | 2017-11-23 14:23:21 +0530 | [diff] [blame] | 16 | #include "../mhu/css_mhu_doorbell.h" |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 17 | #include "css_scp.h" |
| 18 | |
| 19 | /* |
| 20 | * This file implements the SCP helper functions using SCMI protocol. |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * SCMI power state parameter bit field encoding for ARM CSS platforms. |
| 25 | * |
| 26 | * 31 20 19 16 15 12 11 8 7 4 3 0 |
| 27 | * +-------------------------------------------------------------+ |
| 28 | * | SBZ | Max level | Level 3 | Level 2 | Level 1 | Level 0 | |
| 29 | * | | | state | state | state | state | |
| 30 | * +-------------------------------------------------------------+ |
| 31 | * |
| 32 | * `Max level` encodes the highest level that has a valid power state |
| 33 | * encoded in the power state. |
| 34 | */ |
| 35 | #define SCMI_PWR_STATE_MAX_PWR_LVL_SHIFT 16 |
| 36 | #define SCMI_PWR_STATE_MAX_PWR_LVL_WIDTH 4 |
| 37 | #define SCMI_PWR_STATE_MAX_PWR_LVL_MASK \ |
| 38 | ((1 << SCMI_PWR_STATE_MAX_PWR_LVL_WIDTH) - 1) |
Daniel Boulby | ddf6d40 | 2018-05-09 12:21:46 +0100 | [diff] [blame] | 39 | #define SCMI_SET_PWR_STATE_MAX_PWR_LVL(_power_state, _max_level) \ |
| 40 | (_power_state) |= ((_max_level) & SCMI_PWR_STATE_MAX_PWR_LVL_MASK)\ |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 41 | << SCMI_PWR_STATE_MAX_PWR_LVL_SHIFT |
Daniel Boulby | ddf6d40 | 2018-05-09 12:21:46 +0100 | [diff] [blame] | 42 | #define SCMI_GET_PWR_STATE_MAX_PWR_LVL(_power_state) \ |
| 43 | (((_power_state) >> SCMI_PWR_STATE_MAX_PWR_LVL_SHIFT) \ |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 44 | & SCMI_PWR_STATE_MAX_PWR_LVL_MASK) |
| 45 | |
| 46 | #define SCMI_PWR_STATE_LVL_WIDTH 4 |
| 47 | #define SCMI_PWR_STATE_LVL_MASK \ |
| 48 | ((1 << SCMI_PWR_STATE_LVL_WIDTH) - 1) |
Daniel Boulby | ddf6d40 | 2018-05-09 12:21:46 +0100 | [diff] [blame] | 49 | #define SCMI_SET_PWR_STATE_LVL(_power_state, _level, _level_state) \ |
| 50 | (_power_state) |= ((_level_state) & SCMI_PWR_STATE_LVL_MASK) \ |
| 51 | << (SCMI_PWR_STATE_LVL_WIDTH * (_level)) |
| 52 | #define SCMI_GET_PWR_STATE_LVL(_power_state, _level) \ |
| 53 | (((_power_state) >> (SCMI_PWR_STATE_LVL_WIDTH * (_level))) & \ |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 54 | SCMI_PWR_STATE_LVL_MASK) |
| 55 | |
| 56 | /* |
| 57 | * The SCMI power state enumeration for a power domain level |
| 58 | */ |
| 59 | typedef enum { |
| 60 | scmi_power_state_off = 0, |
| 61 | scmi_power_state_on = 1, |
| 62 | scmi_power_state_sleep = 2, |
| 63 | } scmi_power_state_t; |
| 64 | |
| 65 | /* |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 66 | * The global handle for invoking the SCMI driver APIs after the driver |
| 67 | * has been initialized. |
| 68 | */ |
Roberto Vargas | 2b36b15 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 69 | static void *scmi_handle; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 70 | |
| 71 | /* The SCMI channel global object */ |
Daniel Boulby | ebdb634 | 2018-05-14 17:18:58 +0100 | [diff] [blame] | 72 | static scmi_channel_t channel; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 73 | |
Jeenu Viswambharan | 749d25b | 2017-08-23 14:12:59 +0100 | [diff] [blame] | 74 | ARM_INSTANTIATE_LOCK; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * Helper function to suspend a CPU power domain and its parent power domains |
| 78 | * if applicable. |
| 79 | */ |
Roberto Vargas | 5f5a5e6 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 80 | void css_scp_suspend(const struct psci_power_state *target_state) |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 81 | { |
Deepak Pandey | 207c522 | 2017-10-10 21:34:32 +0530 | [diff] [blame] | 82 | int ret; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 83 | |
| 84 | /* At least power domain level 0 should be specified to be suspended */ |
| 85 | assert(target_state->pwr_domain_state[ARM_PWR_LVL0] == |
| 86 | ARM_LOCAL_STATE_OFF); |
| 87 | |
| 88 | /* Check if power down at system power domain level is requested */ |
Nariman Poushin | cd95626 | 2018-05-01 09:28:40 +0100 | [diff] [blame] | 89 | if (css_system_pwr_state(target_state) == ARM_LOCAL_STATE_OFF) { |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 90 | /* Issue SCMI command for SYSTEM_SUSPEND */ |
| 91 | ret = scmi_sys_pwr_state_set(scmi_handle, |
| 92 | SCMI_SYS_PWR_FORCEFUL_REQ, |
| 93 | SCMI_SYS_PWR_SUSPEND); |
| 94 | if (ret != SCMI_E_SUCCESS) { |
| 95 | ERROR("SCMI system power domain suspend return 0x%x unexpected\n", |
| 96 | ret); |
| 97 | panic(); |
| 98 | } |
| 99 | return; |
| 100 | } |
Deepak Pandey | 207c522 | 2017-10-10 21:34:32 +0530 | [diff] [blame] | 101 | #if !HW_ASSISTED_COHERENCY |
| 102 | int lvl; |
| 103 | uint32_t scmi_pwr_state = 0; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 104 | /* |
| 105 | * If we reach here, then assert that power down at system power domain |
| 106 | * level is running. |
| 107 | */ |
| 108 | assert(target_state->pwr_domain_state[CSS_SYSTEM_PWR_DMN_LVL] == |
| 109 | ARM_LOCAL_STATE_RUN); |
| 110 | |
| 111 | /* For level 0, specify `scmi_power_state_sleep` as the power state */ |
| 112 | SCMI_SET_PWR_STATE_LVL(scmi_pwr_state, ARM_PWR_LVL0, |
| 113 | scmi_power_state_sleep); |
| 114 | |
| 115 | for (lvl = ARM_PWR_LVL1; lvl <= PLAT_MAX_PWR_LVL; lvl++) { |
| 116 | if (target_state->pwr_domain_state[lvl] == ARM_LOCAL_STATE_RUN) |
| 117 | break; |
| 118 | |
| 119 | assert(target_state->pwr_domain_state[lvl] == |
| 120 | ARM_LOCAL_STATE_OFF); |
| 121 | /* |
| 122 | * Specify `scmi_power_state_off` as power state for higher |
| 123 | * levels. |
| 124 | */ |
| 125 | SCMI_SET_PWR_STATE_LVL(scmi_pwr_state, lvl, |
| 126 | scmi_power_state_off); |
| 127 | } |
| 128 | |
| 129 | SCMI_SET_PWR_STATE_MAX_PWR_LVL(scmi_pwr_state, lvl - 1); |
| 130 | |
| 131 | ret = scmi_pwr_state_set(scmi_handle, |
| 132 | plat_css_core_pos_to_scmi_dmn_id_map[plat_my_core_pos()], |
| 133 | scmi_pwr_state); |
| 134 | |
| 135 | if (ret != SCMI_E_SUCCESS) { |
| 136 | ERROR("SCMI set power state command return 0x%x unexpected\n", |
| 137 | ret); |
| 138 | panic(); |
| 139 | } |
Deepak Pandey | 207c522 | 2017-10-10 21:34:32 +0530 | [diff] [blame] | 140 | #endif |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Helper function to turn off a CPU power domain and its parent power domains |
| 145 | * if applicable. |
| 146 | */ |
Roberto Vargas | 85664f5 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 147 | void css_scp_off(const struct psci_power_state *target_state) |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 148 | { |
| 149 | int lvl = 0, ret; |
| 150 | uint32_t scmi_pwr_state = 0; |
| 151 | |
| 152 | /* At-least the CPU level should be specified to be OFF */ |
| 153 | assert(target_state->pwr_domain_state[ARM_PWR_LVL0] == |
| 154 | ARM_LOCAL_STATE_OFF); |
| 155 | |
| 156 | /* PSCI CPU OFF cannot be used to turn OFF system power domain */ |
| 157 | assert(target_state->pwr_domain_state[CSS_SYSTEM_PWR_DMN_LVL] == |
| 158 | ARM_LOCAL_STATE_RUN); |
| 159 | |
| 160 | for (; lvl <= PLAT_MAX_PWR_LVL; lvl++) { |
| 161 | if (target_state->pwr_domain_state[lvl] == ARM_LOCAL_STATE_RUN) |
| 162 | break; |
| 163 | |
| 164 | assert(target_state->pwr_domain_state[lvl] == |
| 165 | ARM_LOCAL_STATE_OFF); |
| 166 | SCMI_SET_PWR_STATE_LVL(scmi_pwr_state, lvl, |
| 167 | scmi_power_state_off); |
| 168 | } |
| 169 | |
| 170 | SCMI_SET_PWR_STATE_MAX_PWR_LVL(scmi_pwr_state, lvl - 1); |
| 171 | |
| 172 | ret = scmi_pwr_state_set(scmi_handle, |
| 173 | plat_css_core_pos_to_scmi_dmn_id_map[plat_my_core_pos()], |
| 174 | scmi_pwr_state); |
| 175 | |
| 176 | if (ret != SCMI_E_QUEUED && ret != SCMI_E_SUCCESS) { |
| 177 | ERROR("SCMI set power state command return 0x%x unexpected\n", |
| 178 | ret); |
| 179 | panic(); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /* |
| 184 | * Helper function to turn ON a CPU power domain and its parent power domains |
| 185 | * if applicable. |
| 186 | */ |
| 187 | void css_scp_on(u_register_t mpidr) |
| 188 | { |
Soby Mathew | e089e3f | 2017-06-09 15:04:43 +0100 | [diff] [blame] | 189 | int lvl = 0, ret, core_pos; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 190 | uint32_t scmi_pwr_state = 0; |
| 191 | |
| 192 | for (; lvl <= PLAT_MAX_PWR_LVL; lvl++) |
| 193 | SCMI_SET_PWR_STATE_LVL(scmi_pwr_state, lvl, |
| 194 | scmi_power_state_on); |
| 195 | |
| 196 | SCMI_SET_PWR_STATE_MAX_PWR_LVL(scmi_pwr_state, lvl - 1); |
| 197 | |
Soby Mathew | e089e3f | 2017-06-09 15:04:43 +0100 | [diff] [blame] | 198 | core_pos = plat_core_pos_by_mpidr(mpidr); |
| 199 | assert(core_pos >= 0 && core_pos < PLATFORM_CORE_COUNT); |
| 200 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 201 | ret = scmi_pwr_state_set(scmi_handle, |
Soby Mathew | e089e3f | 2017-06-09 15:04:43 +0100 | [diff] [blame] | 202 | plat_css_core_pos_to_scmi_dmn_id_map[core_pos], |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 203 | scmi_pwr_state); |
| 204 | |
| 205 | if (ret != SCMI_E_QUEUED && ret != SCMI_E_SUCCESS) { |
| 206 | ERROR("SCMI set power state command return 0x%x unexpected\n", |
| 207 | ret); |
| 208 | panic(); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | * Helper function to get the power state of a power domain node as reported |
| 214 | * by the SCP. |
| 215 | */ |
| 216 | int css_scp_get_power_state(u_register_t mpidr, unsigned int power_level) |
| 217 | { |
| 218 | int ret, cpu_idx; |
| 219 | uint32_t scmi_pwr_state = 0, lvl_state; |
| 220 | |
| 221 | /* We don't support get power state at the system power domain level */ |
| 222 | if ((power_level > PLAT_MAX_PWR_LVL) || |
| 223 | (power_level == CSS_SYSTEM_PWR_DMN_LVL)) { |
| 224 | WARN("Invalid power level %u specified for SCMI get power state\n", |
| 225 | power_level); |
| 226 | return PSCI_E_INVALID_PARAMS; |
| 227 | } |
| 228 | |
| 229 | cpu_idx = plat_core_pos_by_mpidr(mpidr); |
| 230 | assert(cpu_idx > -1); |
| 231 | |
| 232 | ret = scmi_pwr_state_get(scmi_handle, |
| 233 | plat_css_core_pos_to_scmi_dmn_id_map[cpu_idx], |
| 234 | &scmi_pwr_state); |
| 235 | |
| 236 | if (ret != SCMI_E_SUCCESS) { |
| 237 | WARN("SCMI get power state command return 0x%x unexpected\n", |
| 238 | ret); |
| 239 | return PSCI_E_INVALID_PARAMS; |
| 240 | } |
| 241 | |
| 242 | /* |
| 243 | * Find the maximum power level described in the get power state |
| 244 | * command. If it is less than the requested power level, then assume |
| 245 | * the requested power level is ON. |
| 246 | */ |
| 247 | if (SCMI_GET_PWR_STATE_MAX_PWR_LVL(scmi_pwr_state) < power_level) |
| 248 | return HW_ON; |
| 249 | |
| 250 | lvl_state = SCMI_GET_PWR_STATE_LVL(scmi_pwr_state, power_level); |
| 251 | if (lvl_state == scmi_power_state_on) |
| 252 | return HW_ON; |
| 253 | |
| 254 | assert((lvl_state == scmi_power_state_off) || |
| 255 | (lvl_state == scmi_power_state_sleep)); |
| 256 | return HW_OFF; |
| 257 | } |
| 258 | |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 259 | void __dead2 css_scp_system_off(int state) |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 260 | { |
| 261 | int ret; |
| 262 | |
| 263 | /* |
| 264 | * Disable GIC CPU interface to prevent pending interrupt from waking |
| 265 | * up the AP from WFI. |
| 266 | */ |
| 267 | plat_arm_gic_cpuif_disable(); |
| 268 | |
| 269 | /* |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 270 | * Issue SCMI command. First issue a graceful |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 271 | * request and if that fails force the request. |
| 272 | */ |
| 273 | ret = scmi_sys_pwr_state_set(scmi_handle, |
| 274 | SCMI_SYS_PWR_FORCEFUL_REQ, |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 275 | state); |
| 276 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 277 | if (ret != SCMI_E_SUCCESS) { |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 278 | ERROR("SCMI system power state set 0x%x returns unexpected 0x%x\n", |
| 279 | state, ret); |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 280 | panic(); |
| 281 | } |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 282 | wfi(); |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 283 | ERROR("CSS set power state: operation not handled.\n"); |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 284 | panic(); |
| 285 | } |
| 286 | |
| 287 | /* |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 288 | * Helper function to shutdown the system via SCMI. |
| 289 | */ |
| 290 | void __dead2 css_scp_sys_shutdown(void) |
| 291 | { |
| 292 | css_scp_system_off(SCMI_SYS_PWR_SHUTDOWN); |
| 293 | } |
| 294 | |
| 295 | /* |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 296 | * Helper function to reset the system via SCMI. |
| 297 | */ |
| 298 | void __dead2 css_scp_sys_reboot(void) |
| 299 | { |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 300 | css_scp_system_off(SCMI_SYS_PWR_COLD_RESET); |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Roberto Vargas | 4d59eb4 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 303 | static scmi_channel_plat_info_t plat_css_scmi_plat_info = { |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 304 | .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE, |
| 305 | .db_reg_addr = PLAT_CSS_MHU_BASE + CSS_SCMI_MHU_DB_REG_OFF, |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 306 | .db_preserve_mask = 0xfffffffe, |
| 307 | .db_modify_mask = 0x1, |
Samarth Parikh | 59cfa13 | 2017-11-23 14:23:21 +0530 | [diff] [blame] | 308 | .ring_doorbell = &mhu_ring_doorbell, |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 309 | }; |
| 310 | |
Dimitris Papastamos | d7a3651 | 2018-06-18 13:01:06 +0100 | [diff] [blame] | 311 | static int scmi_ap_core_init(scmi_channel_t *ch) |
| 312 | { |
| 313 | #if PROGRAMMABLE_RESET_ADDRESS |
| 314 | uint32_t version; |
| 315 | int ret; |
| 316 | |
| 317 | ret = scmi_proto_version(ch, SCMI_AP_CORE_PROTO_ID, &version); |
| 318 | if (ret != SCMI_E_SUCCESS) { |
| 319 | WARN("SCMI AP core protocol version message failed\n"); |
| 320 | return -1; |
| 321 | } |
| 322 | |
| 323 | if (!is_scmi_version_compatible(SCMI_AP_CORE_PROTO_VER, version)) { |
| 324 | WARN("SCMI AP core protocol version 0x%x incompatible with driver version 0x%x\n", |
| 325 | version, SCMI_AP_CORE_PROTO_VER); |
| 326 | return -1; |
| 327 | } |
| 328 | INFO("SCMI AP core protocol version 0x%x detected\n", version); |
| 329 | #endif |
| 330 | return 0; |
| 331 | } |
| 332 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 333 | void plat_arm_pwrc_setup(void) |
| 334 | { |
Daniel Boulby | ebdb634 | 2018-05-14 17:18:58 +0100 | [diff] [blame] | 335 | channel.info = &plat_css_scmi_plat_info; |
| 336 | channel.lock = ARM_LOCK_GET_INSTANCE; |
| 337 | scmi_handle = scmi_init(&channel); |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 338 | if (scmi_handle == NULL) { |
| 339 | ERROR("SCMI Initialization failed\n"); |
| 340 | panic(); |
| 341 | } |
Dimitris Papastamos | d7a3651 | 2018-06-18 13:01:06 +0100 | [diff] [blame] | 342 | if (scmi_ap_core_init(&channel) < 0) { |
| 343 | ERROR("SCMI AP core protocol initialization failed\n"); |
| 344 | panic(); |
| 345 | } |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | /****************************************************************************** |
| 349 | * This function overrides the default definition for ARM platforms. Initialize |
| 350 | * the SCMI driver, query capability via SCMI and modify the PSCI capability |
| 351 | * based on that. |
| 352 | *****************************************************************************/ |
| 353 | const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops) |
| 354 | { |
| 355 | uint32_t msg_attr; |
| 356 | int ret; |
| 357 | |
| 358 | assert(scmi_handle); |
| 359 | |
| 360 | /* Check that power domain POWER_STATE_SET message is supported */ |
| 361 | ret = scmi_proto_msg_attr(scmi_handle, SCMI_PWR_DMN_PROTO_ID, |
| 362 | SCMI_PWR_STATE_SET_MSG, &msg_attr); |
| 363 | if (ret != SCMI_E_SUCCESS) { |
| 364 | ERROR("Set power state command is not supported by SCMI\n"); |
| 365 | panic(); |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Don't support PSCI NODE_HW_STATE call if SCMI doesn't support |
| 370 | * POWER_STATE_GET message. |
| 371 | */ |
| 372 | ret = scmi_proto_msg_attr(scmi_handle, SCMI_PWR_DMN_PROTO_ID, |
| 373 | SCMI_PWR_STATE_GET_MSG, &msg_attr); |
| 374 | if (ret != SCMI_E_SUCCESS) |
| 375 | ops->get_node_hw_state = NULL; |
| 376 | |
| 377 | /* Check if the SCMI SYSTEM_POWER_STATE_SET message is supported */ |
| 378 | ret = scmi_proto_msg_attr(scmi_handle, SCMI_SYS_PWR_PROTO_ID, |
| 379 | SCMI_SYS_PWR_STATE_SET_MSG, &msg_attr); |
| 380 | if (ret != SCMI_E_SUCCESS) { |
| 381 | /* System power management operations are not supported */ |
| 382 | ops->system_off = NULL; |
| 383 | ops->system_reset = NULL; |
| 384 | ops->get_sys_suspend_power_state = NULL; |
Roberto Vargas | 3caafd7 | 2017-08-16 08:57:45 +0100 | [diff] [blame] | 385 | } else { |
| 386 | if (!(msg_attr & SCMI_SYS_PWR_SUSPEND_SUPPORTED)) { |
| 387 | /* |
| 388 | * System power management protocol is available, but |
| 389 | * it does not support SYSTEM SUSPEND. |
| 390 | */ |
| 391 | ops->get_sys_suspend_power_state = NULL; |
| 392 | } |
| 393 | if (!(msg_attr & SCMI_SYS_PWR_WARM_RESET_SUPPORTED)) { |
| 394 | /* |
| 395 | * WARM reset is not available. |
| 396 | */ |
| 397 | ops->system_reset2 = NULL; |
| 398 | } |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | return ops; |
| 402 | } |
Roberto Vargas | 3caafd7 | 2017-08-16 08:57:45 +0100 | [diff] [blame] | 403 | |
| 404 | int css_system_reset2(int is_vendor, int reset_type, u_register_t cookie) |
| 405 | { |
| 406 | if (is_vendor || (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET)) |
| 407 | return PSCI_E_INVALID_PARAMS; |
| 408 | |
| 409 | css_scp_system_off(SCMI_SYS_PWR_WARM_RESET); |
| 410 | /* |
| 411 | * css_scp_system_off cannot return (it is a __dead function), |
| 412 | * but css_system_reset2 has to return some value, even in |
| 413 | * this case. |
| 414 | */ |
| 415 | return 0; |
| 416 | } |
Dimitris Papastamos | d7a3651 | 2018-06-18 13:01:06 +0100 | [diff] [blame] | 417 | |
| 418 | #if PROGRAMMABLE_RESET_ADDRESS |
| 419 | void plat_arm_program_trusted_mailbox(uintptr_t address) |
| 420 | { |
| 421 | int ret; |
| 422 | |
| 423 | assert(scmi_handle); |
| 424 | ret = scmi_ap_core_set_reset_addr(scmi_handle, address, |
| 425 | SCMI_AP_CORE_LOCK_ATTR); |
| 426 | if (ret != SCMI_E_SUCCESS) { |
| 427 | ERROR("CSS: Failed to program reset address: %d\n", ret); |
| 428 | panic(); |
| 429 | } |
| 430 | } |
| 431 | #endif |