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