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 | |
| 31 | #include <arch.h> |
| 32 | #include <platform.h> |
| 33 | #include <psci.h> |
| 34 | #include <psci_private.h> |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 35 | #include <runtime_svc.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 36 | #include <asm_macros.S> |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 37 | #include <cm_macros.S> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 38 | |
| 39 | .globl psci_aff_on_finish_entry |
| 40 | .globl psci_aff_suspend_finish_entry |
| 41 | .globl __psci_cpu_off |
| 42 | .globl __psci_cpu_suspend |
| 43 | |
Sandrine Bailleux | 8d69a03 | 2013-11-27 09:38:52 +0000 | [diff] [blame] | 44 | .section .text, "ax"; .align 3 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 45 | |
| 46 | /* ----------------------------------------------------- |
| 47 | * This cpu has been physically powered up. Depending |
| 48 | * upon whether it was resumed from suspend or simply |
| 49 | * turned on, call the common power on finisher with |
| 50 | * the handlers (chosen depending upon original state). |
| 51 | * For ease, the finisher is called with coherent |
| 52 | * stacks. This allows the cluster/cpu finishers to |
| 53 | * enter coherency and enable the mmu without running |
| 54 | * into issues. We switch back to normal stacks once |
| 55 | * all this is done. |
| 56 | * ----------------------------------------------------- |
| 57 | */ |
| 58 | psci_aff_on_finish_entry: |
| 59 | adr x23, psci_afflvl_on_finishers |
| 60 | b psci_aff_common_finish_entry |
| 61 | |
| 62 | psci_aff_suspend_finish_entry: |
| 63 | adr x23, psci_afflvl_suspend_finishers |
| 64 | |
| 65 | psci_aff_common_finish_entry: |
| 66 | adr x22, psci_afflvl_power_on_finish |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 67 | |
| 68 | /* --------------------------------------------- |
| 69 | * Exceptions should not occur at this point. |
| 70 | * Set VBAR in order to handle and report any |
| 71 | * that do occur |
| 72 | * --------------------------------------------- |
| 73 | */ |
| 74 | adr x0, early_exceptions |
| 75 | msr vbar_el3, x0 |
| 76 | isb |
| 77 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 78 | /* --------------------------------------------- |
| 79 | * Use SP_EL0 for the C runtime stack. |
| 80 | * --------------------------------------------- |
| 81 | */ |
| 82 | msr spsel, #0 |
| 83 | isb |
| 84 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 85 | bl read_mpidr |
| 86 | mov x19, x0 |
| 87 | bl platform_set_coherent_stack |
| 88 | |
| 89 | /* --------------------------------------------- |
| 90 | * Call the finishers starting from affinity |
| 91 | * level 0. |
| 92 | * --------------------------------------------- |
| 93 | */ |
Achin Gupta | a45e397 | 2013-12-05 15:10:48 +0000 | [diff] [blame] | 94 | mov x0, x19 |
| 95 | bl get_power_on_target_afflvl |
| 96 | cmp x0, xzr |
| 97 | b.lt _panic |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 98 | mov x3, x23 |
| 99 | mov x2, x0 |
| 100 | mov x0, x19 |
| 101 | mov x1, #MPIDR_AFFLVL0 |
| 102 | blr x22 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 103 | |
| 104 | /* -------------------------------------------- |
| 105 | * Give ourselves a stack allocated in Normal |
| 106 | * -IS-WBWA memory |
| 107 | * -------------------------------------------- |
| 108 | */ |
| 109 | mov x0, x19 |
| 110 | bl platform_set_stack |
| 111 | |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 112 | /* --------------------------------------------- |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 113 | * Now that the context management has been set |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 114 | * up, enable full runtime exception handling. |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 115 | * SP_EL3 is pointing to a 'cpu_context' |
| 116 | * structure which has an exception stack |
| 117 | * allocated. Since we're just about to leave |
| 118 | * this EL with ERET, we don't need an ISB here |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 119 | * --------------------------------------------- |
| 120 | */ |
| 121 | adr x0, runtime_exceptions |
| 122 | msr vbar_el3, x0 |
| 123 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 124 | zero_callee_saved_regs |
| 125 | b el3_exit |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 126 | _panic: |
| 127 | b _panic |
| 128 | |
| 129 | /* ----------------------------------------------------- |
| 130 | * The following two stubs give the calling cpu a |
| 131 | * coherent stack to allow flushing of caches without |
| 132 | * suffering from stack coherency issues |
| 133 | * ----------------------------------------------------- |
| 134 | */ |
| 135 | __psci_cpu_off: |
| 136 | func_prologue |
| 137 | sub sp, sp, #0x10 |
| 138 | stp x19, x20, [sp, #0] |
| 139 | mov x19, sp |
| 140 | bl read_mpidr |
| 141 | bl platform_set_coherent_stack |
| 142 | bl psci_cpu_off |
| 143 | mov x1, #PSCI_E_SUCCESS |
| 144 | cmp x0, x1 |
| 145 | b.eq final_wfi |
| 146 | mov sp, x19 |
| 147 | ldp x19, x20, [sp,#0] |
| 148 | add sp, sp, #0x10 |
| 149 | func_epilogue |
| 150 | ret |
| 151 | |
| 152 | __psci_cpu_suspend: |
| 153 | func_prologue |
| 154 | sub sp, sp, #0x20 |
| 155 | stp x19, x20, [sp, #0] |
| 156 | stp x21, x22, [sp, #0x10] |
| 157 | mov x19, sp |
| 158 | mov x20, x0 |
| 159 | mov x21, x1 |
| 160 | mov x22, x2 |
| 161 | bl read_mpidr |
| 162 | bl platform_set_coherent_stack |
| 163 | mov x0, x20 |
| 164 | mov x1, x21 |
| 165 | mov x2, x22 |
| 166 | bl psci_cpu_suspend |
| 167 | mov x1, #PSCI_E_SUCCESS |
| 168 | cmp x0, x1 |
| 169 | b.eq final_wfi |
| 170 | mov sp, x19 |
| 171 | ldp x21, x22, [sp,#0x10] |
| 172 | ldp x19, x20, [sp,#0] |
| 173 | add sp, sp, #0x20 |
| 174 | func_epilogue |
| 175 | ret |
| 176 | |
| 177 | final_wfi: |
| 178 | dsb sy |
| 179 | wfi |
| 180 | wfi_spill: |
| 181 | b wfi_spill |
| 182 | |