Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 31 | #include <arch_helpers.h> |
Dan Handley | fb42b12 | 2014-06-20 09:43:15 +0100 | [diff] [blame] | 32 | #include <arm_gic.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 33 | #include <assert.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 34 | #include <bakery_lock.h> |
Vikram Kanigiri | 4e97e54 | 2015-02-26 15:25:58 +0000 | [diff] [blame] | 35 | #include <cci.h> |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 36 | #include <debug.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 37 | #include <mmio.h> |
| 38 | #include <platform.h> |
Dan Handley | 1c54d97 | 2014-06-20 12:02:01 +0100 | [diff] [blame] | 39 | #include <plat_config.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 40 | #include <platform_def.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 41 | #include <psci.h> |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 42 | #include <errno.h> |
Dan Handley | 4d2e49d | 2014-04-11 11:52:12 +0100 | [diff] [blame] | 43 | #include "drivers/pwrc/fvp_pwrc.h" |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 44 | #include "fvp_def.h" |
| 45 | #include "fvp_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 46 | |
| 47 | /******************************************************************************* |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 48 | * Private FVP function to program the mailbox for a cpu before it is released |
| 49 | * from reset. |
| 50 | ******************************************************************************/ |
| 51 | static void fvp_program_mailbox(uint64_t mpidr, uint64_t address) |
| 52 | { |
| 53 | uint64_t linear_id; |
| 54 | mailbox_t *fvp_mboxes; |
| 55 | |
| 56 | linear_id = platform_get_core_pos(mpidr); |
| 57 | fvp_mboxes = (mailbox_t *)MBOX_BASE; |
| 58 | fvp_mboxes[linear_id].value = address; |
| 59 | flush_dcache_range((unsigned long) &fvp_mboxes[linear_id], |
| 60 | sizeof(unsigned long)); |
| 61 | } |
| 62 | |
| 63 | /******************************************************************************* |
| 64 | * Function which implements the common FVP specific operations to power down a |
| 65 | * cpu in response to a CPU_OFF or CPU_SUSPEND request. |
| 66 | ******************************************************************************/ |
Sandrine Bailleux | a64a854 | 2015-03-05 10:54:34 +0000 | [diff] [blame] | 67 | static void fvp_cpu_pwrdwn_common(void) |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 68 | { |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 69 | /* Prevent interrupts from spuriously waking up this cpu */ |
| 70 | arm_gic_cpuif_deactivate(); |
| 71 | |
| 72 | /* Program the power controller to power off this cpu. */ |
| 73 | fvp_pwrc_write_ppoffr(read_mpidr_el1()); |
| 74 | } |
| 75 | |
| 76 | /******************************************************************************* |
| 77 | * Function which implements the common FVP specific operations to power down a |
| 78 | * cluster in response to a CPU_OFF or CPU_SUSPEND request. |
| 79 | ******************************************************************************/ |
Sandrine Bailleux | a64a854 | 2015-03-05 10:54:34 +0000 | [diff] [blame] | 80 | static void fvp_cluster_pwrdwn_common(void) |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 81 | { |
| 82 | uint64_t mpidr = read_mpidr_el1(); |
| 83 | |
| 84 | /* Disable coherency if this cluster is to be turned off */ |
Vikram Kanigiri | 4e97e54 | 2015-02-26 15:25:58 +0000 | [diff] [blame] | 85 | fvp_cci_disable(); |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 86 | |
| 87 | /* Program the power controller to turn the cluster off */ |
| 88 | fvp_pwrc_write_pcoffr(mpidr); |
| 89 | } |
| 90 | |
| 91 | /******************************************************************************* |
| 92 | * Private FVP function which is used to determine if any platform actions |
| 93 | * should be performed for the specified affinity instance given its |
| 94 | * state. Nothing needs to be done if the 'state' is not off or if this is not |
| 95 | * the highest affinity level which will enter the 'state'. |
| 96 | ******************************************************************************/ |
| 97 | static int32_t fvp_do_plat_actions(unsigned int afflvl, unsigned int state) |
| 98 | { |
| 99 | unsigned int max_phys_off_afflvl; |
| 100 | |
| 101 | assert(afflvl <= MPIDR_AFFLVL1); |
| 102 | |
| 103 | if (state != PSCI_STATE_OFF) |
| 104 | return -EAGAIN; |
| 105 | |
| 106 | /* |
| 107 | * Find the highest affinity level which will be suspended and postpone |
| 108 | * all the platform specific actions until that level is hit. |
| 109 | */ |
| 110 | max_phys_off_afflvl = psci_get_max_phys_off_afflvl(); |
| 111 | assert(max_phys_off_afflvl != PSCI_INVALID_DATA); |
| 112 | if (afflvl != max_phys_off_afflvl) |
| 113 | return -EAGAIN; |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | /******************************************************************************* |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 119 | * FVP handler called when an affinity instance is about to enter standby. |
| 120 | ******************************************************************************/ |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 121 | void fvp_affinst_standby(unsigned int power_state) |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 122 | { |
Andrew Thoelke | 42e75a7 | 2014-04-28 12:28:39 +0100 | [diff] [blame] | 123 | /* |
| 124 | * Enter standby state |
| 125 | * dsb is good practice before using wfi to enter low power states |
| 126 | */ |
| 127 | dsb(); |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 128 | wfi(); |
Vikram Kanigiri | 3b7c59b | 2014-03-21 11:57:10 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /******************************************************************************* |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 132 | * FVP handler called when an affinity instance is about to be turned on. The |
| 133 | * level and mpidr determine the affinity instance. |
| 134 | ******************************************************************************/ |
| 135 | int fvp_affinst_on(unsigned long mpidr, |
| 136 | unsigned long sec_entrypoint, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 137 | unsigned int afflvl, |
| 138 | unsigned int state) |
| 139 | { |
| 140 | int rc = PSCI_E_SUCCESS; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 141 | unsigned int psysr; |
| 142 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 143 | /* |
| 144 | * It's possible to turn on only affinity level 0 i.e. a cpu |
| 145 | * on the FVP. Ignore any other affinity level. |
| 146 | */ |
| 147 | if (afflvl != MPIDR_AFFLVL0) |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 148 | return rc; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * Ensure that we do not cancel an inflight power off request |
| 152 | * for the target cpu. That would leave it in a zombie wfi. |
| 153 | * Wait for it to power off, program the jump address for the |
| 154 | * target cpu and then program the power controller to turn |
| 155 | * that cpu on |
| 156 | */ |
| 157 | do { |
| 158 | psysr = fvp_pwrc_read_psysr(mpidr); |
| 159 | } while (psysr & PSYSR_AFF_L0); |
| 160 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 161 | fvp_program_mailbox(mpidr, sec_entrypoint); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 162 | fvp_pwrc_write_pponr(mpidr); |
| 163 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 164 | return rc; |
| 165 | } |
| 166 | |
| 167 | /******************************************************************************* |
| 168 | * FVP handler called when an affinity instance is about to be turned off. The |
| 169 | * level and mpidr determine the affinity instance. The 'state' arg. allows the |
| 170 | * platform to decide whether the cluster is being turned off and take apt |
| 171 | * actions. |
| 172 | * |
Achin Gupta | 9c60d80 | 2014-06-26 11:12:37 +0100 | [diff] [blame] | 173 | * CAUTION: There is no guarantee that caches will remain turned on across calls |
| 174 | * to this function as each affinity level is dealt with. So do not write & read |
| 175 | * global variables across calls. It will be wise to do flush a write to the |
| 176 | * global to prevent unpredictable results. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 177 | ******************************************************************************/ |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 178 | void fvp_affinst_off(unsigned int afflvl, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 179 | unsigned int state) |
| 180 | { |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 181 | /* Determine if any platform actions need to be executed */ |
| 182 | if (fvp_do_plat_actions(afflvl, state) == -EAGAIN) |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 183 | return; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 184 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 185 | /* |
| 186 | * If execution reaches this stage then this affinity level will be |
| 187 | * suspended. Perform at least the cpu specific actions followed the |
| 188 | * cluster specific operations if applicable. |
| 189 | */ |
| 190 | fvp_cpu_pwrdwn_common(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 191 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 192 | if (afflvl != MPIDR_AFFLVL0) |
| 193 | fvp_cluster_pwrdwn_common(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 194 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /******************************************************************************* |
| 198 | * FVP handler called when an affinity instance is about to be suspended. The |
| 199 | * level and mpidr determine the affinity instance. The 'state' arg. allows the |
| 200 | * platform to decide whether the cluster is being turned off and take apt |
| 201 | * actions. |
| 202 | * |
Achin Gupta | 9c60d80 | 2014-06-26 11:12:37 +0100 | [diff] [blame] | 203 | * CAUTION: There is no guarantee that caches will remain turned on across calls |
| 204 | * to this function as each affinity level is dealt with. So do not write & read |
| 205 | * global variables across calls. It will be wise to do flush a write to the |
| 206 | * global to prevent unpredictable results. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 207 | ******************************************************************************/ |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 208 | void fvp_affinst_suspend(unsigned long sec_entrypoint, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 209 | unsigned int afflvl, |
| 210 | unsigned int state) |
| 211 | { |
Soby Mathew | ffb4ab1 | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 212 | unsigned long mpidr; |
| 213 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 214 | /* Determine if any platform actions need to be executed. */ |
| 215 | if (fvp_do_plat_actions(afflvl, state) == -EAGAIN) |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 216 | return; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 217 | |
Soby Mathew | ffb4ab1 | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 218 | /* Get the mpidr for this cpu */ |
| 219 | mpidr = read_mpidr_el1(); |
| 220 | |
| 221 | /* Program the jump address for the this cpu */ |
| 222 | fvp_program_mailbox(mpidr, sec_entrypoint); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 223 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 224 | /* Program the power controller to enable wakeup interrupts. */ |
| 225 | fvp_pwrc_set_wen(mpidr); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 226 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 227 | /* Perform the common cpu specific operations */ |
| 228 | fvp_cpu_pwrdwn_common(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 229 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 230 | /* Perform the common cluster specific operations */ |
| 231 | if (afflvl != MPIDR_AFFLVL0) |
| 232 | fvp_cluster_pwrdwn_common(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /******************************************************************************* |
| 236 | * FVP handler called when an affinity instance has just been powered on after |
| 237 | * being turned off earlier. The level and mpidr determine the affinity |
| 238 | * instance. The 'state' arg. allows the platform to decide whether the cluster |
| 239 | * was turned off prior to wakeup and do what's necessary to setup it up |
| 240 | * correctly. |
| 241 | ******************************************************************************/ |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 242 | void fvp_affinst_on_finish(unsigned int afflvl, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 243 | unsigned int state) |
| 244 | { |
Soby Mathew | ffb4ab1 | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 245 | unsigned long mpidr; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 246 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 247 | /* Determine if any platform actions need to be executed. */ |
| 248 | if (fvp_do_plat_actions(afflvl, state) == -EAGAIN) |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 249 | return; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 250 | |
Soby Mathew | ffb4ab1 | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 251 | /* Get the mpidr for this cpu */ |
| 252 | mpidr = read_mpidr_el1(); |
| 253 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 254 | /* Perform the common cluster specific operations */ |
| 255 | if (afflvl != MPIDR_AFFLVL0) { |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 256 | /* |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 257 | * This CPU might have woken up whilst the cluster was |
| 258 | * attempting to power down. In this case the FVP power |
| 259 | * controller will have a pending cluster power off request |
| 260 | * which needs to be cleared by writing to the PPONR register. |
| 261 | * This prevents the power controller from interpreting a |
| 262 | * subsequent entry of this cpu into a simple wfi as a power |
| 263 | * down request. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 264 | */ |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 265 | fvp_pwrc_write_pponr(mpidr); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 266 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 267 | /* Enable coherency if this cluster was off */ |
| 268 | fvp_cci_enable(); |
| 269 | } |
Achin Gupta | b127cdb | 2013-11-12 16:40:00 +0000 | [diff] [blame] | 270 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 271 | /* |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 272 | * Clear PWKUPR.WEN bit to ensure interrupts do not interfere |
| 273 | * with a cpu power down unless the bit is set again |
| 274 | */ |
| 275 | fvp_pwrc_clr_wen(mpidr); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 276 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 277 | /* Zero the jump address in the mailbox for this cpu */ |
Soby Mathew | ffb4ab1 | 2014-09-26 15:08:52 +0100 | [diff] [blame] | 278 | fvp_program_mailbox(mpidr, 0); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 279 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 280 | /* Enable the gic cpu interface */ |
| 281 | arm_gic_cpuif_setup(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 282 | |
Achin Gupta | 8587639 | 2014-07-31 17:45:51 +0100 | [diff] [blame] | 283 | /* TODO: This setup is needed only after a cold boot */ |
| 284 | arm_gic_pcpu_distif_setup(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /******************************************************************************* |
| 288 | * FVP handler called when an affinity instance has just been powered on after |
| 289 | * having been suspended earlier. The level and mpidr determine the affinity |
| 290 | * instance. |
| 291 | * TODO: At the moment we reuse the on finisher and reinitialize the secure |
| 292 | * context. Need to implement a separate suspend finisher. |
| 293 | ******************************************************************************/ |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 294 | void fvp_affinst_suspend_finish(unsigned int afflvl, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 295 | unsigned int state) |
| 296 | { |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 297 | fvp_affinst_on_finish(afflvl, state); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 298 | } |
| 299 | |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 300 | /******************************************************************************* |
| 301 | * FVP handlers to shutdown/reboot the system |
| 302 | ******************************************************************************/ |
| 303 | static void __dead2 fvp_system_off(void) |
| 304 | { |
| 305 | /* Write the System Configuration Control Register */ |
| 306 | mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL, |
| 307 | CFGCTRL_START | CFGCTRL_RW | CFGCTRL_FUNC(FUNC_SHUTDOWN)); |
| 308 | wfi(); |
| 309 | ERROR("FVP System Off: operation not handled.\n"); |
| 310 | panic(); |
| 311 | } |
| 312 | |
| 313 | static void __dead2 fvp_system_reset(void) |
| 314 | { |
| 315 | /* Write the System Configuration Control Register */ |
| 316 | mmio_write_32(VE_SYSREGS_BASE + V2M_SYS_CFGCTRL, |
| 317 | CFGCTRL_START | CFGCTRL_RW | CFGCTRL_FUNC(FUNC_REBOOT)); |
| 318 | wfi(); |
| 319 | ERROR("FVP System Reset: operation not handled.\n"); |
| 320 | panic(); |
| 321 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 322 | |
| 323 | /******************************************************************************* |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 324 | * FVP handler called to check the validity of the power state parameter. |
| 325 | ******************************************************************************/ |
| 326 | int fvp_validate_power_state(unsigned int power_state) |
| 327 | { |
| 328 | /* Sanity check the requested state */ |
| 329 | if (psci_get_pstate_type(power_state) == PSTATE_TYPE_STANDBY) { |
| 330 | /* |
| 331 | * It's possible to enter standby only on affinity level 0 |
| 332 | * i.e. a cpu on the fvp. Ignore any other affinity level. |
| 333 | */ |
| 334 | if (psci_get_pstate_afflvl(power_state) != MPIDR_AFFLVL0) |
| 335 | return PSCI_E_INVALID_PARAMS; |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * We expect the 'state id' to be zero. |
| 340 | */ |
| 341 | if (psci_get_pstate_id(power_state)) |
| 342 | return PSCI_E_INVALID_PARAMS; |
| 343 | |
| 344 | return PSCI_E_SUCCESS; |
| 345 | } |
| 346 | |
| 347 | /******************************************************************************* |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 348 | * Export the platform handlers to enable psci to invoke them |
| 349 | ******************************************************************************/ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 350 | static const plat_pm_ops_t fvp_plat_pm_ops = { |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 351 | .affinst_standby = fvp_affinst_standby, |
| 352 | .affinst_on = fvp_affinst_on, |
| 353 | .affinst_off = fvp_affinst_off, |
| 354 | .affinst_suspend = fvp_affinst_suspend, |
| 355 | .affinst_on_finish = fvp_affinst_on_finish, |
| 356 | .affinst_suspend_finish = fvp_affinst_suspend_finish, |
| 357 | .system_off = fvp_system_off, |
Soby Mathew | 74e52a7 | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 358 | .system_reset = fvp_system_reset, |
| 359 | .validate_power_state = fvp_validate_power_state |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 360 | }; |
| 361 | |
| 362 | /******************************************************************************* |
| 363 | * Export the platform specific power ops & initialize the fvp power controller |
| 364 | ******************************************************************************/ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 365 | int platform_setup_pm(const plat_pm_ops_t **plat_ops) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 366 | { |
| 367 | *plat_ops = &fvp_plat_pm_ops; |
| 368 | return 0; |
| 369 | } |