Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 1 | /* |
Varun Wadekar | 84a775e | 2019-01-03 10:12:55 -0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <platform_def.h> |
| 10 | |
| 11 | #include <arch_helpers.h> |
| 12 | #include <common/bl_common.h> |
| 13 | #include <common/debug.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 14 | #include <context.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <drivers/console.h> |
| 16 | #include <lib/el3_runtime/context_mgmt.h> |
| 17 | #include <lib/mmio.h> |
| 18 | #include <lib/psci/psci.h> |
| 19 | #include <plat/common/platform.h> |
| 20 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 21 | #include <memctrl.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 22 | #include <pmc.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 23 | #include <tegra_def.h> |
Harvey Hsieh | 9e083c7 | 2017-04-10 16:20:32 +0800 | [diff] [blame] | 24 | #include <tegra_platform.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 25 | #include <tegra_private.h> |
| 26 | |
| 27 | extern uint64_t tegra_bl31_phys_base; |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 28 | extern uint64_t tegra_sec_entry_point; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 29 | |
| 30 | /* |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 31 | * tegra_fake_system_suspend acts as a boolean var controlling whether |
| 32 | * we are going to take fake system suspend code or normal system suspend code |
| 33 | * path. This variable is set inside the sip call handlers,when the kernel |
| 34 | * requests a SIP call to set the suspend debug flags. |
| 35 | */ |
| 36 | uint8_t tegra_fake_system_suspend; |
| 37 | |
| 38 | /* |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 39 | * The following platform setup functions are weakly defined. They |
| 40 | * provide typical implementations that will be overridden by a SoC. |
| 41 | */ |
Varun Wadekar | 99782e8 | 2017-07-05 17:44:12 -0700 | [diff] [blame] | 42 | #pragma weak tegra_soc_pwr_domain_suspend_pwrdown_early |
Varun Wadekar | b3421ce | 2017-12-27 18:10:12 -0800 | [diff] [blame] | 43 | #pragma weak tegra_soc_cpu_standby |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 44 | #pragma weak tegra_soc_pwr_domain_suspend |
| 45 | #pragma weak tegra_soc_pwr_domain_on |
| 46 | #pragma weak tegra_soc_pwr_domain_off |
| 47 | #pragma weak tegra_soc_pwr_domain_on_finish |
Varun Wadekar | d22429d | 2016-03-18 14:35:28 -0700 | [diff] [blame] | 48 | #pragma weak tegra_soc_pwr_domain_power_down_wfi |
Varun Wadekar | 8b82fae | 2015-11-09 17:39:28 -0800 | [diff] [blame] | 49 | #pragma weak tegra_soc_prepare_system_reset |
Varun Wadekar | e5caeed | 2016-01-07 14:04:21 -0800 | [diff] [blame] | 50 | #pragma weak tegra_soc_prepare_system_off |
Varun Wadekar | f2aa1be | 2016-06-07 12:00:06 -0700 | [diff] [blame] | 51 | #pragma weak tegra_soc_get_target_pwr_state |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 52 | |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 53 | int32_t tegra_soc_pwr_domain_suspend_pwrdown_early(const psci_power_state_t *target_state) |
Varun Wadekar | 99782e8 | 2017-07-05 17:44:12 -0700 | [diff] [blame] | 54 | { |
| 55 | return PSCI_E_NOT_SUPPORTED; |
| 56 | } |
| 57 | |
Varun Wadekar | b3421ce | 2017-12-27 18:10:12 -0800 | [diff] [blame] | 58 | int32_t tegra_soc_cpu_standby(plat_local_state_t cpu_state) |
| 59 | { |
| 60 | (void)cpu_state; |
| 61 | return PSCI_E_SUCCESS; |
| 62 | } |
| 63 | |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 64 | int32_t tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 65 | { |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 66 | (void)target_state; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 67 | return PSCI_E_NOT_SUPPORTED; |
| 68 | } |
| 69 | |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 70 | int32_t tegra_soc_pwr_domain_on(u_register_t mpidr) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 71 | { |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 72 | (void)mpidr; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 73 | return PSCI_E_SUCCESS; |
| 74 | } |
| 75 | |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 76 | int32_t tegra_soc_pwr_domain_off(const psci_power_state_t *target_state) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 77 | { |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 78 | (void)target_state; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 79 | return PSCI_E_SUCCESS; |
| 80 | } |
| 81 | |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 82 | int32_t tegra_soc_pwr_domain_on_finish(const psci_power_state_t *target_state) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 83 | { |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 84 | (void)target_state; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 85 | return PSCI_E_SUCCESS; |
| 86 | } |
| 87 | |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 88 | int32_t tegra_soc_pwr_domain_power_down_wfi(const psci_power_state_t *target_state) |
Varun Wadekar | d22429d | 2016-03-18 14:35:28 -0700 | [diff] [blame] | 89 | { |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 90 | (void)target_state; |
Varun Wadekar | d22429d | 2016-03-18 14:35:28 -0700 | [diff] [blame] | 91 | return PSCI_E_SUCCESS; |
| 92 | } |
| 93 | |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 94 | int32_t tegra_soc_prepare_system_reset(void) |
Varun Wadekar | 8b82fae | 2015-11-09 17:39:28 -0800 | [diff] [blame] | 95 | { |
| 96 | return PSCI_E_SUCCESS; |
| 97 | } |
| 98 | |
Varun Wadekar | e5caeed | 2016-01-07 14:04:21 -0800 | [diff] [blame] | 99 | __dead2 void tegra_soc_prepare_system_off(void) |
| 100 | { |
| 101 | ERROR("Tegra System Off: operation not handled.\n"); |
| 102 | panic(); |
| 103 | } |
| 104 | |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 105 | plat_local_state_t tegra_soc_get_target_pwr_state(uint32_t lvl, |
Varun Wadekar | f2aa1be | 2016-06-07 12:00:06 -0700 | [diff] [blame] | 106 | const plat_local_state_t *states, |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 107 | uint32_t ncpu) |
Varun Wadekar | f2aa1be | 2016-06-07 12:00:06 -0700 | [diff] [blame] | 108 | { |
Varun Wadekar | 14eaede | 2016-09-01 14:51:59 -0700 | [diff] [blame] | 109 | plat_local_state_t target = PLAT_MAX_OFF_STATE, temp; |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 110 | uint32_t num_cpu = ncpu; |
| 111 | const plat_local_state_t *local_state = states; |
| 112 | |
| 113 | (void)lvl; |
Varun Wadekar | f2aa1be | 2016-06-07 12:00:06 -0700 | [diff] [blame] | 114 | |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 115 | assert(ncpu != 0U); |
Varun Wadekar | f2aa1be | 2016-06-07 12:00:06 -0700 | [diff] [blame] | 116 | |
| 117 | do { |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 118 | temp = *local_state; |
| 119 | if ((temp < target)) { |
Varun Wadekar | f2aa1be | 2016-06-07 12:00:06 -0700 | [diff] [blame] | 120 | target = temp; |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 121 | } |
| 122 | --num_cpu; |
| 123 | local_state++; |
| 124 | } while (num_cpu != 0U); |
Varun Wadekar | f2aa1be | 2016-06-07 12:00:06 -0700 | [diff] [blame] | 125 | |
| 126 | return target; |
| 127 | } |
| 128 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 129 | /******************************************************************************* |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 130 | * This handler is called by the PSCI implementation during the `SYSTEM_SUSPEND` |
| 131 | * call to get the `power_state` parameter. This allows the platform to encode |
| 132 | * the appropriate State-ID field within the `power_state` parameter which can |
| 133 | * be utilized in `pwr_domain_suspend()` to suspend to system affinity level. |
| 134 | ******************************************************************************/ |
| 135 | void tegra_get_sys_suspend_power_state(psci_power_state_t *req_state) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 136 | { |
Varun Wadekar | f2aa1be | 2016-06-07 12:00:06 -0700 | [diff] [blame] | 137 | /* all affinities use system suspend state id */ |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 138 | for (uint32_t i = MPIDR_AFFLVL0; i <= PLAT_MAX_PWR_LVL; i++) { |
Varun Wadekar | f2aa1be | 2016-06-07 12:00:06 -0700 | [diff] [blame] | 139 | req_state->pwr_domain_state[i] = PSTATE_ID_SOC_POWERDN; |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 140 | } |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /******************************************************************************* |
| 144 | * Handler called when an affinity instance is about to enter standby. |
| 145 | ******************************************************************************/ |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 146 | void tegra_cpu_standby(plat_local_state_t cpu_state) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 147 | { |
Vignesh Radhakrishnan | 16d82ae | 2018-04-20 14:31:41 -0700 | [diff] [blame] | 148 | u_register_t saved_scr_el3; |
| 149 | |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 150 | (void)cpu_state; |
| 151 | |
Varun Wadekar | b3421ce | 2017-12-27 18:10:12 -0800 | [diff] [blame] | 152 | /* Tegra SoC specific handler */ |
| 153 | if (tegra_soc_cpu_standby(cpu_state) != PSCI_E_SUCCESS) |
| 154 | ERROR("%s failed\n", __func__); |
| 155 | |
Vignesh Radhakrishnan | 16d82ae | 2018-04-20 14:31:41 -0700 | [diff] [blame] | 156 | saved_scr_el3 = read_scr_el3(); |
| 157 | |
| 158 | /* |
| 159 | * As per ARM ARM D1.17.2, any physical IRQ interrupt received by the |
| 160 | * PE will be treated as a wake-up event, if SCR_EL3.IRQ is set to '1', |
| 161 | * irrespective of the value of the PSTATE.I bit value. |
| 162 | */ |
| 163 | write_scr_el3(saved_scr_el3 | SCR_IRQ_BIT); |
| 164 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 165 | /* |
| 166 | * Enter standby state |
Vignesh Radhakrishnan | 16d82ae | 2018-04-20 14:31:41 -0700 | [diff] [blame] | 167 | * |
| 168 | * dsb & isb is good practice before using wfi to enter low power states |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 169 | */ |
| 170 | dsb(); |
Vignesh Radhakrishnan | 16d82ae | 2018-04-20 14:31:41 -0700 | [diff] [blame] | 171 | isb(); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 172 | wfi(); |
Vignesh Radhakrishnan | 16d82ae | 2018-04-20 14:31:41 -0700 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * Restore saved scr_el3 that has IRQ bit cleared as we don't want EL3 |
| 176 | * handling any further interrupts |
| 177 | */ |
| 178 | write_scr_el3(saved_scr_el3); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /******************************************************************************* |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 182 | * Handler called when an affinity instance is about to be turned on. The |
| 183 | * level and mpidr determine the affinity instance. |
| 184 | ******************************************************************************/ |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 185 | int32_t tegra_pwr_domain_on(u_register_t mpidr) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 186 | { |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 187 | return tegra_soc_pwr_domain_on(mpidr); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /******************************************************************************* |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 191 | * Handler called when a power domain is about to be turned off. The |
| 192 | * target_state encodes the power state that each level should transition to. |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 193 | ******************************************************************************/ |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 194 | void tegra_pwr_domain_off(const psci_power_state_t *target_state) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 195 | { |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 196 | (void)tegra_soc_pwr_domain_off(target_state); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /******************************************************************************* |
Varun Wadekar | d22429d | 2016-03-18 14:35:28 -0700 | [diff] [blame] | 200 | * Handler called when a power domain is about to be suspended. The |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 201 | * target_state encodes the power state that each level should transition to. |
Varun Wadekar | 99782e8 | 2017-07-05 17:44:12 -0700 | [diff] [blame] | 202 | * This handler is called with SMP and data cache enabled, when |
| 203 | * HW_ASSISTED_COHERENCY = 0 |
| 204 | ******************************************************************************/ |
| 205 | void tegra_pwr_domain_suspend_pwrdown_early(const psci_power_state_t *target_state) |
| 206 | { |
| 207 | tegra_soc_pwr_domain_suspend_pwrdown_early(target_state); |
| 208 | } |
| 209 | |
| 210 | /******************************************************************************* |
| 211 | * Handler called when a power domain is about to be suspended. The |
| 212 | * target_state encodes the power state that each level should transition to. |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 213 | ******************************************************************************/ |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 214 | void tegra_pwr_domain_suspend(const psci_power_state_t *target_state) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 215 | { |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 216 | (void)tegra_soc_pwr_domain_suspend(target_state); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 217 | |
Varun Wadekar | a2c6be6 | 2016-08-01 22:16:21 -0700 | [diff] [blame] | 218 | /* Disable console if we are entering deep sleep. */ |
| 219 | if (target_state->pwr_domain_state[PLAT_MAX_PWR_LVL] == |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 220 | PSTATE_ID_SOC_POWERDN) { |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 221 | (void)console_flush(); |
| 222 | console_switch_state(0); |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 223 | } |
Varun Wadekar | a2c6be6 | 2016-08-01 22:16:21 -0700 | [diff] [blame] | 224 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 225 | /* disable GICC */ |
| 226 | tegra_gic_cpuif_deactivate(); |
| 227 | } |
| 228 | |
| 229 | /******************************************************************************* |
Varun Wadekar | d22429d | 2016-03-18 14:35:28 -0700 | [diff] [blame] | 230 | * Handler called at the end of the power domain suspend sequence. The |
| 231 | * target_state encodes the power state that each level should transition to. |
| 232 | ******************************************************************************/ |
| 233 | __dead2 void tegra_pwr_domain_power_down_wfi(const psci_power_state_t |
| 234 | *target_state) |
| 235 | { |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 236 | uint8_t pwr_state = target_state->pwr_domain_state[PLAT_MAX_PWR_LVL]; |
| 237 | uint64_t rmr_el3 = 0; |
| 238 | |
Varun Wadekar | d22429d | 2016-03-18 14:35:28 -0700 | [diff] [blame] | 239 | /* call the chip's power down handler */ |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 240 | (void)tegra_soc_pwr_domain_power_down_wfi(target_state); |
Varun Wadekar | d22429d | 2016-03-18 14:35:28 -0700 | [diff] [blame] | 241 | |
Vignesh Radhakrishnan | b4a7294 | 2017-03-03 10:58:05 -0800 | [diff] [blame] | 242 | /* |
| 243 | * If we are in fake system suspend mode, ensure we start doing |
| 244 | * procedures that help in looping back towards system suspend exit |
| 245 | * instead of calling WFI by requesting a warm reset. |
| 246 | * Else, just call WFI to enter low power state. |
| 247 | */ |
| 248 | if ((tegra_fake_system_suspend != 0U) && |
| 249 | (pwr_state == (uint8_t)PSTATE_ID_SOC_POWERDN)) { |
| 250 | |
| 251 | /* warm reboot */ |
| 252 | rmr_el3 = read_rmr_el3(); |
| 253 | write_rmr_el3(rmr_el3 | RMR_WARM_RESET_CPU); |
| 254 | |
| 255 | } else { |
| 256 | /* enter power down state */ |
| 257 | wfi(); |
| 258 | } |
Varun Wadekar | d22429d | 2016-03-18 14:35:28 -0700 | [diff] [blame] | 259 | |
| 260 | /* we can never reach here */ |
Varun Wadekar | d22429d | 2016-03-18 14:35:28 -0700 | [diff] [blame] | 261 | panic(); |
| 262 | } |
| 263 | |
| 264 | /******************************************************************************* |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 265 | * Handler called when a power domain has just been powered on after |
| 266 | * being turned off earlier. The target_state encodes the low power state that |
| 267 | * each level has woken up from. |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 268 | ******************************************************************************/ |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 269 | void tegra_pwr_domain_on_finish(const psci_power_state_t *target_state) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 270 | { |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 271 | const plat_params_from_bl2_t *plat_params; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 272 | |
| 273 | /* |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 274 | * Initialize the GIC cpu and distributor interfaces |
| 275 | */ |
Varun Wadekar | 84a775e | 2019-01-03 10:12:55 -0800 | [diff] [blame] | 276 | tegra_gic_init(); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 277 | |
| 278 | /* |
| 279 | * Check if we are exiting from deep sleep. |
| 280 | */ |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 281 | if (target_state->pwr_domain_state[PLAT_MAX_PWR_LVL] == |
| 282 | PSTATE_ID_SOC_POWERDN) { |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 283 | |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 284 | /* Restart console output. */ |
| 285 | console_switch_state(CONSOLE_FLAG_RUNTIME); |
Varun Wadekar | a2c6be6 | 2016-08-01 22:16:21 -0700 | [diff] [blame] | 286 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 287 | /* |
Varun Wadekar | 6eec6d6 | 2016-03-03 13:28:10 -0800 | [diff] [blame] | 288 | * Restore Memory Controller settings as it loses state |
| 289 | * during system suspend. |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 290 | */ |
Varun Wadekar | 6eec6d6 | 2016-03-03 13:28:10 -0800 | [diff] [blame] | 291 | tegra_memctrl_restore_settings(); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 292 | |
| 293 | /* |
| 294 | * Security configuration to allow DRAM/device access. |
| 295 | */ |
| 296 | plat_params = bl31_get_plat_params(); |
Varun Wadekar | 6bb6246 | 2015-10-06 12:49:31 +0530 | [diff] [blame] | 297 | tegra_memctrl_tzdram_setup(plat_params->tzdram_base, |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 298 | (uint32_t)plat_params->tzdram_size); |
Varun Wadekar | d5f578a | 2016-06-01 19:34:37 -0700 | [diff] [blame] | 299 | |
| 300 | /* |
| 301 | * Set up the TZRAM memory aperture to allow only secure world |
| 302 | * access |
| 303 | */ |
| 304 | tegra_memctrl_tzram_setup(TEGRA_TZRAM_BASE, TEGRA_TZRAM_SIZE); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /* |
| 308 | * Reset hardware settings. |
| 309 | */ |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 310 | (void)tegra_soc_pwr_domain_on_finish(target_state); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /******************************************************************************* |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 314 | * Handler called when a power domain has just been powered on after |
| 315 | * having been suspended earlier. The target_state encodes the low power state |
| 316 | * that each level has woken up from. |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 317 | ******************************************************************************/ |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 318 | void tegra_pwr_domain_suspend_finish(const psci_power_state_t *target_state) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 319 | { |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 320 | tegra_pwr_domain_on_finish(target_state); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /******************************************************************************* |
| 324 | * Handler called when the system wants to be powered off |
| 325 | ******************************************************************************/ |
| 326 | __dead2 void tegra_system_off(void) |
| 327 | { |
Varun Wadekar | e5caeed | 2016-01-07 14:04:21 -0800 | [diff] [blame] | 328 | INFO("Powering down system...\n"); |
| 329 | |
| 330 | tegra_soc_prepare_system_off(); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /******************************************************************************* |
| 334 | * Handler called when the system wants to be restarted. |
| 335 | ******************************************************************************/ |
| 336 | __dead2 void tegra_system_reset(void) |
| 337 | { |
Varun Wadekar | e5caeed | 2016-01-07 14:04:21 -0800 | [diff] [blame] | 338 | INFO("Restarting system...\n"); |
| 339 | |
Varun Wadekar | 8b82fae | 2015-11-09 17:39:28 -0800 | [diff] [blame] | 340 | /* per-SoC system reset handler */ |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 341 | (void)tegra_soc_prepare_system_reset(); |
Varun Wadekar | 8b82fae | 2015-11-09 17:39:28 -0800 | [diff] [blame] | 342 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 343 | /* |
| 344 | * Program the PMC in order to restart the system. |
| 345 | */ |
| 346 | tegra_pmc_system_reset(); |
| 347 | } |
| 348 | |
| 349 | /******************************************************************************* |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 350 | * Handler called to check the validity of the power state parameter. |
| 351 | ******************************************************************************/ |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 352 | int32_t tegra_validate_power_state(uint32_t power_state, |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 353 | psci_power_state_t *req_state) |
| 354 | { |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 355 | assert(req_state != NULL); |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 356 | |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 357 | return tegra_soc_validate_power_state(power_state, req_state); |
| 358 | } |
| 359 | |
| 360 | /******************************************************************************* |
| 361 | * Platform handler called to check the validity of the non secure entrypoint. |
| 362 | ******************************************************************************/ |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 363 | int32_t tegra_validate_ns_entrypoint(uintptr_t entrypoint) |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 364 | { |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 365 | int32_t ret = PSCI_E_INVALID_ADDRESS; |
| 366 | |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 367 | /* |
| 368 | * Check if the non secure entrypoint lies within the non |
| 369 | * secure DRAM. |
| 370 | */ |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 371 | if ((entrypoint >= TEGRA_DRAM_BASE) && (entrypoint <= TEGRA_DRAM_END)) { |
| 372 | ret = PSCI_E_SUCCESS; |
| 373 | } |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 374 | |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 375 | return ret; |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /******************************************************************************* |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 379 | * Export the platform handlers to enable psci to invoke them |
| 380 | ******************************************************************************/ |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 381 | static const plat_psci_ops_t tegra_plat_psci_ops = { |
| 382 | .cpu_standby = tegra_cpu_standby, |
| 383 | .pwr_domain_on = tegra_pwr_domain_on, |
| 384 | .pwr_domain_off = tegra_pwr_domain_off, |
Varun Wadekar | 99782e8 | 2017-07-05 17:44:12 -0700 | [diff] [blame] | 385 | .pwr_domain_suspend_pwrdown_early = tegra_pwr_domain_suspend_pwrdown_early, |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 386 | .pwr_domain_suspend = tegra_pwr_domain_suspend, |
| 387 | .pwr_domain_on_finish = tegra_pwr_domain_on_finish, |
| 388 | .pwr_domain_suspend_finish = tegra_pwr_domain_suspend_finish, |
Varun Wadekar | d22429d | 2016-03-18 14:35:28 -0700 | [diff] [blame] | 389 | .pwr_domain_pwr_down_wfi = tegra_pwr_domain_power_down_wfi, |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 390 | .system_off = tegra_system_off, |
| 391 | .system_reset = tegra_system_reset, |
| 392 | .validate_power_state = tegra_validate_power_state, |
| 393 | .validate_ns_entrypoint = tegra_validate_ns_entrypoint, |
| 394 | .get_sys_suspend_power_state = tegra_get_sys_suspend_power_state, |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 395 | }; |
| 396 | |
| 397 | /******************************************************************************* |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 398 | * Export the platform specific power ops and initialize Power Controller |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 399 | ******************************************************************************/ |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 400 | int plat_setup_psci_ops(uintptr_t sec_entrypoint, |
| 401 | const plat_psci_ops_t **psci_ops) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 402 | { |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 403 | psci_power_state_t target_state = { { PSCI_LOCAL_STATE_RUN } }; |
| 404 | |
| 405 | /* |
| 406 | * Flush entrypoint variable to PoC since it will be |
| 407 | * accessed after a reset with the caches turned off. |
| 408 | */ |
| 409 | tegra_sec_entry_point = sec_entrypoint; |
| 410 | flush_dcache_range((uint64_t)&tegra_sec_entry_point, sizeof(uint64_t)); |
| 411 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 412 | /* |
| 413 | * Reset hardware settings. |
| 414 | */ |
Anthony Zhou | 85a8fa0 | 2017-03-22 14:42:42 +0800 | [diff] [blame] | 415 | (void)tegra_soc_pwr_domain_on_finish(&target_state); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 416 | |
| 417 | /* |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 418 | * Initialize PSCI ops struct |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 419 | */ |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 420 | *psci_ops = &tegra_plat_psci_ops; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 421 | |
| 422 | return 0; |
| 423 | } |
Varun Wadekar | 2497539 | 2016-05-05 14:13:30 -0700 | [diff] [blame] | 424 | |
| 425 | /******************************************************************************* |
| 426 | * Platform handler to calculate the proper target power level at the |
| 427 | * specified affinity level |
| 428 | ******************************************************************************/ |
| 429 | plat_local_state_t plat_get_target_pwr_state(unsigned int lvl, |
| 430 | const plat_local_state_t *states, |
| 431 | unsigned int ncpu) |
| 432 | { |
Varun Wadekar | f2aa1be | 2016-06-07 12:00:06 -0700 | [diff] [blame] | 433 | return tegra_soc_get_target_pwr_state(lvl, states, ncpu); |
Varun Wadekar | 2497539 | 2016-05-05 14:13:30 -0700 | [diff] [blame] | 434 | } |