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> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 32 | #include <asm_macros.S> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 33 | #include <psci.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 34 | |
| 35 | .globl psci_aff_on_finish_entry |
| 36 | .globl psci_aff_suspend_finish_entry |
| 37 | .globl __psci_cpu_off |
| 38 | .globl __psci_cpu_suspend |
| 39 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 40 | /* ----------------------------------------------------- |
| 41 | * This cpu has been physically powered up. Depending |
| 42 | * upon whether it was resumed from suspend or simply |
| 43 | * turned on, call the common power on finisher with |
| 44 | * the handlers (chosen depending upon original state). |
| 45 | * For ease, the finisher is called with coherent |
| 46 | * stacks. This allows the cluster/cpu finishers to |
| 47 | * enter coherency and enable the mmu without running |
| 48 | * into issues. We switch back to normal stacks once |
| 49 | * all this is done. |
| 50 | * ----------------------------------------------------- |
| 51 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 52 | func psci_aff_on_finish_entry |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 53 | adr x23, psci_afflvl_on_finishers |
| 54 | b psci_aff_common_finish_entry |
| 55 | |
| 56 | psci_aff_suspend_finish_entry: |
| 57 | adr x23, psci_afflvl_suspend_finishers |
| 58 | |
| 59 | psci_aff_common_finish_entry: |
| 60 | adr x22, psci_afflvl_power_on_finish |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 61 | |
| 62 | /* --------------------------------------------- |
| 63 | * Exceptions should not occur at this point. |
| 64 | * Set VBAR in order to handle and report any |
| 65 | * that do occur |
| 66 | * --------------------------------------------- |
| 67 | */ |
| 68 | adr x0, early_exceptions |
| 69 | msr vbar_el3, x0 |
| 70 | isb |
| 71 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 72 | /* --------------------------------------------- |
| 73 | * Use SP_EL0 for the C runtime stack. |
| 74 | * --------------------------------------------- |
| 75 | */ |
| 76 | msr spsel, #0 |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 77 | |
Andrew Thoelke | f977ed8 | 2014-04-28 12:32:02 +0100 | [diff] [blame] | 78 | mrs x0, mpidr_el1 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 79 | bl platform_set_coherent_stack |
| 80 | |
| 81 | /* --------------------------------------------- |
| 82 | * Call the finishers starting from affinity |
| 83 | * level 0. |
| 84 | * --------------------------------------------- |
| 85 | */ |
Andrew Thoelke | f977ed8 | 2014-04-28 12:32:02 +0100 | [diff] [blame] | 86 | mrs x0, mpidr_el1 |
Achin Gupta | a45e397 | 2013-12-05 15:10:48 +0000 | [diff] [blame] | 87 | bl get_power_on_target_afflvl |
| 88 | cmp x0, xzr |
| 89 | b.lt _panic |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 90 | mov x3, x23 |
| 91 | mov x2, x0 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 92 | mov x1, #MPIDR_AFFLVL0 |
Andrew Thoelke | f977ed8 | 2014-04-28 12:32:02 +0100 | [diff] [blame] | 93 | mrs x0, mpidr_el1 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 94 | blr x22 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 95 | |
| 96 | /* -------------------------------------------- |
| 97 | * Give ourselves a stack allocated in Normal |
| 98 | * -IS-WBWA memory |
| 99 | * -------------------------------------------- |
| 100 | */ |
Andrew Thoelke | f977ed8 | 2014-04-28 12:32:02 +0100 | [diff] [blame] | 101 | mrs x0, mpidr_el1 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 102 | bl platform_set_stack |
| 103 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 104 | b el3_exit |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 105 | _panic: |
| 106 | b _panic |
| 107 | |
| 108 | /* ----------------------------------------------------- |
| 109 | * The following two stubs give the calling cpu a |
| 110 | * coherent stack to allow flushing of caches without |
| 111 | * suffering from stack coherency issues |
| 112 | * ----------------------------------------------------- |
| 113 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 114 | func __psci_cpu_off |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 115 | func_prologue |
| 116 | sub sp, sp, #0x10 |
| 117 | stp x19, x20, [sp, #0] |
| 118 | mov x19, sp |
Andrew Thoelke | f977ed8 | 2014-04-28 12:32:02 +0100 | [diff] [blame] | 119 | mrs x0, mpidr_el1 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 120 | bl platform_set_coherent_stack |
| 121 | bl psci_cpu_off |
| 122 | mov x1, #PSCI_E_SUCCESS |
| 123 | cmp x0, x1 |
| 124 | b.eq final_wfi |
| 125 | mov sp, x19 |
| 126 | ldp x19, x20, [sp,#0] |
| 127 | add sp, sp, #0x10 |
| 128 | func_epilogue |
| 129 | ret |
| 130 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 131 | func __psci_cpu_suspend |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 132 | func_prologue |
| 133 | sub sp, sp, #0x20 |
| 134 | stp x19, x20, [sp, #0] |
| 135 | stp x21, x22, [sp, #0x10] |
| 136 | mov x19, sp |
| 137 | mov x20, x0 |
| 138 | mov x21, x1 |
| 139 | mov x22, x2 |
Andrew Thoelke | f977ed8 | 2014-04-28 12:32:02 +0100 | [diff] [blame] | 140 | mrs x0, mpidr_el1 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 141 | bl platform_set_coherent_stack |
| 142 | mov x0, x20 |
| 143 | mov x1, x21 |
| 144 | mov x2, x22 |
| 145 | bl psci_cpu_suspend |
| 146 | mov x1, #PSCI_E_SUCCESS |
| 147 | cmp x0, x1 |
| 148 | b.eq final_wfi |
| 149 | mov sp, x19 |
| 150 | ldp x21, x22, [sp,#0x10] |
| 151 | ldp x19, x20, [sp,#0] |
| 152 | add sp, sp, #0x20 |
| 153 | func_epilogue |
| 154 | ret |
| 155 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 156 | func final_wfi |
Andrew Thoelke | 42e75a7 | 2014-04-28 12:28:39 +0100 | [diff] [blame] | 157 | dsb sy // ensure write buffer empty |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 158 | wfi |
| 159 | wfi_spill: |
| 160 | b wfi_spill |
| 161 | |