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