Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 1 | /* |
Ambroise Vincent | a88a35d | 2019-02-14 09:48:21 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, 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 | 326f56b | 2019-01-23 18:55:03 +0000 | [diff] [blame] | 12 | #include <drivers/arm/css/css_scp.h> |
Antonio Nino Diaz | c30db5b | 2019-01-23 20:37:32 +0000 | [diff] [blame] | 13 | #include <drivers/arm/css/scmi.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 14 | #include <plat/arm/common/plat_arm.h> |
| 15 | #include <plat/arm/css/common/css_pm.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | #include <plat/common/platform.h> |
Antonio Nino Diaz | a320ecd | 2019-01-15 14:19:50 +0000 | [diff] [blame] | 17 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 18 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 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 | |
Roberto Vargas | 0099694 | 2017-11-13 13:41:58 +0000 | [diff] [blame] | 74 | ARM_SCMI_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 |
Ambroise Vincent | a88a35d | 2019-02-14 09:48:21 +0000 | [diff] [blame] | 102 | unsigned int lvl; |
Deepak Pandey | 207c522 | 2017-10-10 21:34:32 +0530 | [diff] [blame] | 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 | */ |
Soby Mathew | fd2e5e4 | 2018-09-10 11:32:49 +0100 | [diff] [blame] | 108 | assert(css_system_pwr_state(target_state) == ARM_LOCAL_STATE_RUN); |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 109 | |
| 110 | /* For level 0, specify `scmi_power_state_sleep` as the power state */ |
| 111 | SCMI_SET_PWR_STATE_LVL(scmi_pwr_state, ARM_PWR_LVL0, |
| 112 | scmi_power_state_sleep); |
| 113 | |
| 114 | for (lvl = ARM_PWR_LVL1; lvl <= PLAT_MAX_PWR_LVL; lvl++) { |
| 115 | if (target_state->pwr_domain_state[lvl] == ARM_LOCAL_STATE_RUN) |
| 116 | break; |
| 117 | |
| 118 | assert(target_state->pwr_domain_state[lvl] == |
| 119 | ARM_LOCAL_STATE_OFF); |
| 120 | /* |
| 121 | * Specify `scmi_power_state_off` as power state for higher |
| 122 | * levels. |
| 123 | */ |
| 124 | SCMI_SET_PWR_STATE_LVL(scmi_pwr_state, lvl, |
| 125 | scmi_power_state_off); |
| 126 | } |
| 127 | |
| 128 | SCMI_SET_PWR_STATE_MAX_PWR_LVL(scmi_pwr_state, lvl - 1); |
| 129 | |
| 130 | ret = scmi_pwr_state_set(scmi_handle, |
| 131 | plat_css_core_pos_to_scmi_dmn_id_map[plat_my_core_pos()], |
| 132 | scmi_pwr_state); |
| 133 | |
| 134 | if (ret != SCMI_E_SUCCESS) { |
| 135 | ERROR("SCMI set power state command return 0x%x unexpected\n", |
| 136 | ret); |
| 137 | panic(); |
| 138 | } |
Deepak Pandey | 207c522 | 2017-10-10 21:34:32 +0530 | [diff] [blame] | 139 | #endif |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /* |
| 143 | * Helper function to turn off a CPU power domain and its parent power domains |
| 144 | * if applicable. |
| 145 | */ |
Roberto Vargas | 85664f5 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 146 | void css_scp_off(const struct psci_power_state *target_state) |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 147 | { |
Ambroise Vincent | a88a35d | 2019-02-14 09:48:21 +0000 | [diff] [blame] | 148 | unsigned int lvl = 0; |
| 149 | int ret; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 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 | { |
Ambroise Vincent | a88a35d | 2019-02-14 09:48:21 +0000 | [diff] [blame] | 188 | unsigned int lvl = 0; |
Deepika Bhavnani | 4287c0c | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 189 | int core_pos, ret; |
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); |
Deepika Bhavnani | 4287c0c | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 199 | assert((core_pos >= 0) && |
| 200 | (((unsigned int)core_pos) < PLATFORM_CORE_COUNT)); |
Soby Mathew | e089e3f | 2017-06-09 15:04:43 +0100 | [diff] [blame] | 201 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 202 | ret = scmi_pwr_state_set(scmi_handle, |
Soby Mathew | e089e3f | 2017-06-09 15:04:43 +0100 | [diff] [blame] | 203 | plat_css_core_pos_to_scmi_dmn_id_map[core_pos], |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 204 | scmi_pwr_state); |
| 205 | |
| 206 | if (ret != SCMI_E_QUEUED && ret != SCMI_E_SUCCESS) { |
| 207 | ERROR("SCMI set power state command return 0x%x unexpected\n", |
| 208 | ret); |
| 209 | panic(); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Helper function to get the power state of a power domain node as reported |
| 215 | * by the SCP. |
| 216 | */ |
| 217 | int css_scp_get_power_state(u_register_t mpidr, unsigned int power_level) |
| 218 | { |
| 219 | int ret, cpu_idx; |
| 220 | uint32_t scmi_pwr_state = 0, lvl_state; |
| 221 | |
| 222 | /* We don't support get power state at the system power domain level */ |
| 223 | if ((power_level > PLAT_MAX_PWR_LVL) || |
| 224 | (power_level == CSS_SYSTEM_PWR_DMN_LVL)) { |
| 225 | WARN("Invalid power level %u specified for SCMI get power state\n", |
| 226 | power_level); |
| 227 | return PSCI_E_INVALID_PARAMS; |
| 228 | } |
| 229 | |
| 230 | cpu_idx = plat_core_pos_by_mpidr(mpidr); |
| 231 | assert(cpu_idx > -1); |
| 232 | |
| 233 | ret = scmi_pwr_state_get(scmi_handle, |
| 234 | plat_css_core_pos_to_scmi_dmn_id_map[cpu_idx], |
| 235 | &scmi_pwr_state); |
| 236 | |
| 237 | if (ret != SCMI_E_SUCCESS) { |
| 238 | WARN("SCMI get power state command return 0x%x unexpected\n", |
| 239 | ret); |
| 240 | return PSCI_E_INVALID_PARAMS; |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * Find the maximum power level described in the get power state |
| 245 | * command. If it is less than the requested power level, then assume |
| 246 | * the requested power level is ON. |
| 247 | */ |
| 248 | if (SCMI_GET_PWR_STATE_MAX_PWR_LVL(scmi_pwr_state) < power_level) |
| 249 | return HW_ON; |
| 250 | |
| 251 | lvl_state = SCMI_GET_PWR_STATE_LVL(scmi_pwr_state, power_level); |
| 252 | if (lvl_state == scmi_power_state_on) |
| 253 | return HW_ON; |
| 254 | |
| 255 | assert((lvl_state == scmi_power_state_off) || |
| 256 | (lvl_state == scmi_power_state_sleep)); |
| 257 | return HW_OFF; |
| 258 | } |
| 259 | |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 260 | void __dead2 css_scp_system_off(int state) |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 261 | { |
| 262 | int ret; |
| 263 | |
| 264 | /* |
| 265 | * Disable GIC CPU interface to prevent pending interrupt from waking |
| 266 | * up the AP from WFI. |
| 267 | */ |
| 268 | plat_arm_gic_cpuif_disable(); |
| 269 | |
| 270 | /* |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 271 | * Issue SCMI command. First issue a graceful |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 272 | * request and if that fails force the request. |
| 273 | */ |
| 274 | ret = scmi_sys_pwr_state_set(scmi_handle, |
| 275 | SCMI_SYS_PWR_FORCEFUL_REQ, |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 276 | state); |
| 277 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 278 | if (ret != SCMI_E_SUCCESS) { |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 279 | ERROR("SCMI system power state set 0x%x returns unexpected 0x%x\n", |
| 280 | state, ret); |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 281 | panic(); |
| 282 | } |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 283 | wfi(); |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 284 | ERROR("CSS set power state: operation not handled.\n"); |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 285 | panic(); |
| 286 | } |
| 287 | |
| 288 | /* |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 289 | * Helper function to shutdown the system via SCMI. |
| 290 | */ |
| 291 | void __dead2 css_scp_sys_shutdown(void) |
| 292 | { |
| 293 | css_scp_system_off(SCMI_SYS_PWR_SHUTDOWN); |
| 294 | } |
| 295 | |
| 296 | /* |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 297 | * Helper function to reset the system via SCMI. |
| 298 | */ |
| 299 | void __dead2 css_scp_sys_reboot(void) |
| 300 | { |
Roberto Vargas | fc2b4eb | 2017-07-31 09:45:10 +0100 | [diff] [blame] | 301 | css_scp_system_off(SCMI_SYS_PWR_COLD_RESET); |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Dimitris Papastamos | d7a3651 | 2018-06-18 13:01:06 +0100 | [diff] [blame] | 304 | static int scmi_ap_core_init(scmi_channel_t *ch) |
| 305 | { |
| 306 | #if PROGRAMMABLE_RESET_ADDRESS |
| 307 | uint32_t version; |
| 308 | int ret; |
| 309 | |
| 310 | ret = scmi_proto_version(ch, SCMI_AP_CORE_PROTO_ID, &version); |
| 311 | if (ret != SCMI_E_SUCCESS) { |
| 312 | WARN("SCMI AP core protocol version message failed\n"); |
| 313 | return -1; |
| 314 | } |
| 315 | |
| 316 | if (!is_scmi_version_compatible(SCMI_AP_CORE_PROTO_VER, version)) { |
| 317 | WARN("SCMI AP core protocol version 0x%x incompatible with driver version 0x%x\n", |
| 318 | version, SCMI_AP_CORE_PROTO_VER); |
| 319 | return -1; |
| 320 | } |
| 321 | INFO("SCMI AP core protocol version 0x%x detected\n", version); |
| 322 | #endif |
| 323 | return 0; |
| 324 | } |
| 325 | |
Daniel Boulby | f45a4bb | 2018-09-18 13:26:03 +0100 | [diff] [blame] | 326 | void __init plat_arm_pwrc_setup(void) |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 327 | { |
Chandni Cherukuri | 61f3a7c | 2018-10-11 14:08:08 +0530 | [diff] [blame] | 328 | channel.info = plat_css_get_scmi_info(); |
Roberto Vargas | 0099694 | 2017-11-13 13:41:58 +0000 | [diff] [blame] | 329 | channel.lock = ARM_SCMI_LOCK_GET_INSTANCE; |
Daniel Boulby | ebdb634 | 2018-05-14 17:18:58 +0100 | [diff] [blame] | 330 | scmi_handle = scmi_init(&channel); |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 331 | if (scmi_handle == NULL) { |
| 332 | ERROR("SCMI Initialization failed\n"); |
| 333 | panic(); |
| 334 | } |
Dimitris Papastamos | d7a3651 | 2018-06-18 13:01:06 +0100 | [diff] [blame] | 335 | if (scmi_ap_core_init(&channel) < 0) { |
| 336 | ERROR("SCMI AP core protocol initialization failed\n"); |
| 337 | panic(); |
| 338 | } |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /****************************************************************************** |
| 342 | * This function overrides the default definition for ARM platforms. Initialize |
| 343 | * the SCMI driver, query capability via SCMI and modify the PSCI capability |
| 344 | * based on that. |
| 345 | *****************************************************************************/ |
Chandni Cherukuri | e4bf6a0 | 2018-11-14 13:43:59 +0530 | [diff] [blame] | 346 | 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] | 347 | { |
| 348 | uint32_t msg_attr; |
| 349 | int ret; |
| 350 | |
| 351 | assert(scmi_handle); |
| 352 | |
| 353 | /* Check that power domain POWER_STATE_SET message is supported */ |
| 354 | ret = scmi_proto_msg_attr(scmi_handle, SCMI_PWR_DMN_PROTO_ID, |
| 355 | SCMI_PWR_STATE_SET_MSG, &msg_attr); |
| 356 | if (ret != SCMI_E_SUCCESS) { |
| 357 | ERROR("Set power state command is not supported by SCMI\n"); |
| 358 | panic(); |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * Don't support PSCI NODE_HW_STATE call if SCMI doesn't support |
| 363 | * POWER_STATE_GET message. |
| 364 | */ |
| 365 | ret = scmi_proto_msg_attr(scmi_handle, SCMI_PWR_DMN_PROTO_ID, |
| 366 | SCMI_PWR_STATE_GET_MSG, &msg_attr); |
| 367 | if (ret != SCMI_E_SUCCESS) |
| 368 | ops->get_node_hw_state = NULL; |
| 369 | |
| 370 | /* Check if the SCMI SYSTEM_POWER_STATE_SET message is supported */ |
| 371 | ret = scmi_proto_msg_attr(scmi_handle, SCMI_SYS_PWR_PROTO_ID, |
| 372 | SCMI_SYS_PWR_STATE_SET_MSG, &msg_attr); |
| 373 | if (ret != SCMI_E_SUCCESS) { |
| 374 | /* System power management operations are not supported */ |
| 375 | ops->system_off = NULL; |
| 376 | ops->system_reset = NULL; |
| 377 | ops->get_sys_suspend_power_state = NULL; |
Roberto Vargas | 3caafd7 | 2017-08-16 08:57:45 +0100 | [diff] [blame] | 378 | } else { |
| 379 | if (!(msg_attr & SCMI_SYS_PWR_SUSPEND_SUPPORTED)) { |
| 380 | /* |
| 381 | * System power management protocol is available, but |
| 382 | * it does not support SYSTEM SUSPEND. |
| 383 | */ |
| 384 | ops->get_sys_suspend_power_state = NULL; |
| 385 | } |
| 386 | if (!(msg_attr & SCMI_SYS_PWR_WARM_RESET_SUPPORTED)) { |
| 387 | /* |
| 388 | * WARM reset is not available. |
| 389 | */ |
| 390 | ops->system_reset2 = NULL; |
| 391 | } |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | return ops; |
| 395 | } |
Roberto Vargas | 3caafd7 | 2017-08-16 08:57:45 +0100 | [diff] [blame] | 396 | |
| 397 | int css_system_reset2(int is_vendor, int reset_type, u_register_t cookie) |
| 398 | { |
| 399 | if (is_vendor || (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET)) |
| 400 | return PSCI_E_INVALID_PARAMS; |
| 401 | |
| 402 | css_scp_system_off(SCMI_SYS_PWR_WARM_RESET); |
| 403 | /* |
| 404 | * css_scp_system_off cannot return (it is a __dead function), |
| 405 | * but css_system_reset2 has to return some value, even in |
| 406 | * this case. |
| 407 | */ |
| 408 | return 0; |
| 409 | } |
Dimitris Papastamos | d7a3651 | 2018-06-18 13:01:06 +0100 | [diff] [blame] | 410 | |
| 411 | #if PROGRAMMABLE_RESET_ADDRESS |
| 412 | void plat_arm_program_trusted_mailbox(uintptr_t address) |
| 413 | { |
| 414 | int ret; |
| 415 | |
| 416 | assert(scmi_handle); |
| 417 | ret = scmi_ap_core_set_reset_addr(scmi_handle, address, |
| 418 | SCMI_AP_CORE_LOCK_ATTR); |
| 419 | if (ret != SCMI_E_SUCCESS) { |
| 420 | ERROR("CSS: Failed to program reset address: %d\n", ret); |
| 421 | panic(); |
| 422 | } |
| 423 | } |
| 424 | #endif |