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 | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 34 | #include <xlat_tables.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 35 | |
| 36 | .globl psci_aff_on_finish_entry |
| 37 | .globl psci_aff_suspend_finish_entry |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 38 | .globl psci_power_down_wfi |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 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). |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 45 | * ----------------------------------------------------- |
| 46 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 47 | func psci_aff_on_finish_entry |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 48 | adr x23, psci_afflvl_on_finishers |
| 49 | b psci_aff_common_finish_entry |
| 50 | |
| 51 | psci_aff_suspend_finish_entry: |
| 52 | adr x23, psci_afflvl_suspend_finishers |
| 53 | |
| 54 | psci_aff_common_finish_entry: |
Achin Gupta | 9f09835 | 2014-07-18 18:38:28 +0100 | [diff] [blame] | 55 | #if !RESET_TO_BL31 |
| 56 | /* --------------------------------------------- |
| 57 | * Enable the instruction cache, stack pointer |
| 58 | * and data access alignment checks. Also, set |
| 59 | * the EL3 exception endianess to little-endian. |
| 60 | * It can be assumed that BL3-1 entrypoint code |
| 61 | * will do this when RESET_TO_BL31 is set. The |
| 62 | * same assumption cannot be made when another |
| 63 | * boot loader executes before BL3-1 in the warm |
| 64 | * boot path e.g. BL1. |
| 65 | * --------------------------------------------- |
| 66 | */ |
| 67 | mov x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT) |
| 68 | mrs x0, sctlr_el3 |
| 69 | orr x0, x0, x1 |
| 70 | msr sctlr_el3, x0 |
| 71 | isb |
| 72 | #endif |
| 73 | |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 74 | /* --------------------------------------------- |
Andrew Thoelke | 8c28fe0 | 2014-06-02 11:40:35 +0100 | [diff] [blame] | 75 | * Initialise the pcpu cache pointer for the CPU |
| 76 | * --------------------------------------------- |
| 77 | */ |
| 78 | bl init_cpu_data_ptr |
| 79 | |
| 80 | /* --------------------------------------------- |
Soby Mathew | 8e2f287 | 2014-08-14 12:49:05 +0100 | [diff] [blame] | 81 | * Initialize the cpu_ops pointer. |
| 82 | * --------------------------------------------- |
| 83 | */ |
| 84 | bl init_cpu_ops |
| 85 | |
| 86 | /* --------------------------------------------- |
Andrew Thoelke | 4d2d553 | 2014-06-02 12:38:12 +0100 | [diff] [blame] | 87 | * Set the exception vectors |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 88 | * --------------------------------------------- |
| 89 | */ |
Andrew Thoelke | 4d2d553 | 2014-06-02 12:38:12 +0100 | [diff] [blame] | 90 | adr x0, runtime_exceptions |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 91 | msr vbar_el3, x0 |
| 92 | isb |
| 93 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 94 | /* --------------------------------------------- |
Achin Gupta | ed1744e | 2014-08-04 23:13:10 +0100 | [diff] [blame] | 95 | * Enable the SError interrupt now that the |
| 96 | * exception vectors have been setup. |
| 97 | * --------------------------------------------- |
| 98 | */ |
| 99 | msr daifclr, #DAIF_ABT_BIT |
| 100 | |
| 101 | /* --------------------------------------------- |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 102 | * Use SP_EL0 for the C runtime stack. |
| 103 | * --------------------------------------------- |
| 104 | */ |
| 105 | msr spsel, #0 |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 106 | |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 107 | /* -------------------------------------------- |
| 108 | * Give ourselves a stack whose memory will be |
| 109 | * marked as Normal-IS-WBWA when the MMU is |
| 110 | * enabled. |
| 111 | * -------------------------------------------- |
| 112 | */ |
Andrew Thoelke | f977ed8 | 2014-04-28 12:32:02 +0100 | [diff] [blame] | 113 | mrs x0, mpidr_el1 |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 114 | bl platform_set_stack |
| 115 | |
| 116 | /* -------------------------------------------- |
| 117 | * Enable the MMU with the DCache disabled. It |
| 118 | * is safe to use stacks allocated in normal |
| 119 | * memory as a result. All memory accesses are |
| 120 | * marked nGnRnE when the MMU is disabled. So |
| 121 | * all the stack writes will make it to memory. |
| 122 | * All memory accesses are marked Non-cacheable |
| 123 | * when the MMU is enabled but D$ is disabled. |
| 124 | * So used stack memory is guaranteed to be |
| 125 | * visible immediately after the MMU is enabled |
| 126 | * Enabling the DCache at the same time as the |
| 127 | * MMU can lead to speculatively fetched and |
| 128 | * possibly stale stack memory being read from |
| 129 | * other caches. This can lead to coherency |
| 130 | * issues. |
| 131 | * -------------------------------------------- |
| 132 | */ |
| 133 | mov x0, #DISABLE_DCACHE |
| 134 | bl bl31_plat_enable_mmu |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 135 | |
| 136 | /* --------------------------------------------- |
| 137 | * Call the finishers starting from affinity |
| 138 | * level 0. |
| 139 | * --------------------------------------------- |
| 140 | */ |
Achin Gupta | a45e397 | 2013-12-05 15:10:48 +0000 | [diff] [blame] | 141 | bl get_power_on_target_afflvl |
Andrew Thoelke | 2bc0785 | 2014-06-09 12:44:21 +0100 | [diff] [blame] | 142 | mov x2, x23 |
| 143 | mov x1, x0 |
| 144 | mov x0, #MPIDR_AFFLVL0 |
| 145 | bl psci_afflvl_power_on_finish |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 146 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 147 | b el3_exit |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 148 | |
Achin Gupta | 42c5280 | 2014-05-09 19:32:25 +0100 | [diff] [blame] | 149 | /* -------------------------------------------- |
| 150 | * This function is called to indicate to the |
| 151 | * power controller that it is safe to power |
| 152 | * down this cpu. It should not exit the wfi |
| 153 | * and will be released from reset upon power |
| 154 | * up. 'wfi_spill' is used to catch erroneous |
| 155 | * exits from wfi. |
| 156 | * -------------------------------------------- |
| 157 | */ |
| 158 | func psci_power_down_wfi |
Andrew Thoelke | 42e75a7 | 2014-04-28 12:28:39 +0100 | [diff] [blame] | 159 | dsb sy // ensure write buffer empty |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 160 | wfi |
| 161 | wfi_spill: |
| 162 | b wfi_spill |
| 163 | |