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