David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2013 |
| 3 | * David Feng <fenghua@phytium.com.cn> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <asm-offsets.h> |
| 9 | #include <config.h> |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 10 | #include <linux/linkage.h> |
| 11 | #include <asm/macro.h> |
| 12 | #include <asm/armv8/mmu.h> |
| 13 | |
| 14 | /************************************************************************* |
| 15 | * |
| 16 | * Startup Code (reset vector) |
| 17 | * |
| 18 | *************************************************************************/ |
| 19 | |
| 20 | .globl _start |
| 21 | _start: |
| 22 | b reset |
| 23 | |
Andre Przywara | 48321ba | 2016-05-31 10:45:06 -0700 | [diff] [blame] | 24 | #ifdef CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK |
| 25 | /* |
| 26 | * Various SoCs need something special and SoC-specific up front in |
| 27 | * order to boot, allow them to set that in their boot0.h file and then |
| 28 | * use it here. |
| 29 | */ |
| 30 | #include <asm/arch/boot0.h> |
| 31 | ARM_SOC_BOOT0_HOOK |
| 32 | #endif |
| 33 | |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 34 | .align 3 |
| 35 | |
| 36 | .globl _TEXT_BASE |
| 37 | _TEXT_BASE: |
| 38 | .quad CONFIG_SYS_TEXT_BASE |
| 39 | |
| 40 | /* |
| 41 | * These are defined in the linker script. |
| 42 | */ |
| 43 | .globl _end_ofs |
| 44 | _end_ofs: |
| 45 | .quad _end - _start |
| 46 | |
| 47 | .globl _bss_start_ofs |
| 48 | _bss_start_ofs: |
| 49 | .quad __bss_start - _start |
| 50 | |
| 51 | .globl _bss_end_ofs |
| 52 | _bss_end_ofs: |
| 53 | .quad __bss_end - _start |
| 54 | |
| 55 | reset: |
Stephen Warren | 100a479 | 2016-07-18 17:01:50 -0600 | [diff] [blame] | 56 | /* Allow the board to save important registers */ |
| 57 | b save_boot_params |
| 58 | .globl save_boot_params_ret |
| 59 | save_boot_params_ret: |
| 60 | |
Sergey Temerkhanov | 78eaa49 | 2015-10-14 09:55:45 -0700 | [diff] [blame] | 61 | #ifdef CONFIG_SYS_RESET_SCTRL |
| 62 | bl reset_sctrl |
| 63 | #endif |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 64 | /* |
| 65 | * Could be EL3/EL2/EL1, Initial State: |
| 66 | * Little Endian, MMU Disabled, i/dCache Disabled |
| 67 | */ |
| 68 | adr x0, vectors |
| 69 | switch_el x1, 3f, 2f, 1f |
David Feng | 7c5eca7 | 2014-04-19 09:45:21 +0800 | [diff] [blame] | 70 | 3: msr vbar_el3, x0 |
| 71 | mrs x0, scr_el3 |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 72 | orr x0, x0, #0xf /* SCR_EL3.NS|IRQ|FIQ|EA */ |
| 73 | msr scr_el3, x0 |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 74 | msr cptr_el3, xzr /* Enable FP/SIMD */ |
Thierry Reding | 2565792 | 2015-08-20 11:42:18 +0200 | [diff] [blame] | 75 | #ifdef COUNTER_FREQUENCY |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 76 | ldr x0, =COUNTER_FREQUENCY |
| 77 | msr cntfrq_el0, x0 /* Initialize CNTFRQ */ |
Thierry Reding | 2565792 | 2015-08-20 11:42:18 +0200 | [diff] [blame] | 78 | #endif |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 79 | b 0f |
| 80 | 2: msr vbar_el2, x0 |
| 81 | mov x0, #0x33ff |
| 82 | msr cptr_el2, x0 /* Enable FP/SIMD */ |
| 83 | b 0f |
| 84 | 1: msr vbar_el1, x0 |
| 85 | mov x0, #3 << 20 |
| 86 | msr cpacr_el1, x0 /* Enable FP/SIMD */ |
| 87 | 0: |
| 88 | |
Bhupesh Sharma | 80a7e35 | 2015-01-23 15:50:04 +0530 | [diff] [blame] | 89 | /* Apply ARM core specific erratas */ |
| 90 | bl apply_core_errata |
| 91 | |
York Sun | ef04201 | 2014-02-26 13:26:04 -0800 | [diff] [blame] | 92 | /* |
| 93 | * Cache/BPB/TLB Invalidate |
| 94 | * i-cache is invalidated before enabled in icache_enable() |
| 95 | * tlb is invalidated before mmu is enabled in dcache_enable() |
| 96 | * d-cache is invalidated before enabled in dcache_enable() |
| 97 | */ |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 98 | |
| 99 | /* Processor specific initialization */ |
| 100 | bl lowlevel_init |
| 101 | |
Masahiro Yamada | 2663cd6 | 2016-06-27 19:31:05 +0900 | [diff] [blame] | 102 | #if CONFIG_IS_ENABLED(ARMV8_SPIN_TABLE) |
| 103 | branch_if_master x0, x1, master_cpu |
| 104 | b spin_table_secondary_jump |
| 105 | /* never return */ |
| 106 | #elif defined(CONFIG_ARMV8_MULTIENTRY) |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 107 | branch_if_master x0, x1, master_cpu |
| 108 | |
| 109 | /* |
| 110 | * Slave CPUs |
| 111 | */ |
| 112 | slave_cpu: |
| 113 | wfe |
| 114 | ldr x1, =CPU_RELEASE_ADDR |
| 115 | ldr x0, [x1] |
| 116 | cbz x0, slave_cpu |
| 117 | br x0 /* branch to the given address */ |
Linus Walleij | 7477139 | 2015-03-09 10:53:21 +0100 | [diff] [blame] | 118 | #endif /* CONFIG_ARMV8_MULTIENTRY */ |
Masahiro Yamada | 2663cd6 | 2016-06-27 19:31:05 +0900 | [diff] [blame] | 119 | master_cpu: |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 120 | bl _main |
| 121 | |
Sergey Temerkhanov | 78eaa49 | 2015-10-14 09:55:45 -0700 | [diff] [blame] | 122 | #ifdef CONFIG_SYS_RESET_SCTRL |
| 123 | reset_sctrl: |
| 124 | switch_el x1, 3f, 2f, 1f |
| 125 | 3: |
| 126 | mrs x0, sctlr_el3 |
| 127 | b 0f |
| 128 | 2: |
| 129 | mrs x0, sctlr_el2 |
| 130 | b 0f |
| 131 | 1: |
| 132 | mrs x0, sctlr_el1 |
| 133 | |
| 134 | 0: |
| 135 | ldr x1, =0xfdfffffa |
| 136 | and x0, x0, x1 |
| 137 | |
| 138 | switch_el x1, 6f, 5f, 4f |
| 139 | 6: |
| 140 | msr sctlr_el3, x0 |
| 141 | b 7f |
| 142 | 5: |
| 143 | msr sctlr_el2, x0 |
| 144 | b 7f |
| 145 | 4: |
| 146 | msr sctlr_el1, x0 |
| 147 | |
| 148 | 7: |
| 149 | dsb sy |
| 150 | isb |
| 151 | b __asm_invalidate_tlb_all |
| 152 | ret |
| 153 | #endif |
| 154 | |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 155 | /*-----------------------------------------------------------------------*/ |
| 156 | |
Bhupesh Sharma | 80a7e35 | 2015-01-23 15:50:04 +0530 | [diff] [blame] | 157 | WEAK(apply_core_errata) |
| 158 | |
| 159 | mov x29, lr /* Save LR */ |
| 160 | /* For now, we support Cortex-A57 specific errata only */ |
| 161 | |
| 162 | /* Check if we are running on a Cortex-A57 core */ |
| 163 | branch_if_a57_core x0, apply_a57_core_errata |
| 164 | 0: |
| 165 | mov lr, x29 /* Restore LR */ |
| 166 | ret |
| 167 | |
| 168 | apply_a57_core_errata: |
| 169 | |
| 170 | #ifdef CONFIG_ARM_ERRATA_828024 |
| 171 | mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */ |
| 172 | /* Disable non-allocate hint of w-b-n-a memory type */ |
Bhupesh Sharma | 06a0f1d | 2015-05-28 14:54:13 +0530 | [diff] [blame] | 173 | orr x0, x0, #1 << 49 |
Bhupesh Sharma | 80a7e35 | 2015-01-23 15:50:04 +0530 | [diff] [blame] | 174 | /* Disable write streaming no L1-allocate threshold */ |
Bhupesh Sharma | 06a0f1d | 2015-05-28 14:54:13 +0530 | [diff] [blame] | 175 | orr x0, x0, #3 << 25 |
Bhupesh Sharma | 80a7e35 | 2015-01-23 15:50:04 +0530 | [diff] [blame] | 176 | /* Disable write streaming no-allocate threshold */ |
Bhupesh Sharma | 06a0f1d | 2015-05-28 14:54:13 +0530 | [diff] [blame] | 177 | orr x0, x0, #3 << 27 |
Bhupesh Sharma | 80a7e35 | 2015-01-23 15:50:04 +0530 | [diff] [blame] | 178 | msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */ |
| 179 | #endif |
| 180 | |
| 181 | #ifdef CONFIG_ARM_ERRATA_826974 |
| 182 | mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */ |
| 183 | /* Disable speculative load execution ahead of a DMB */ |
Bhupesh Sharma | 06a0f1d | 2015-05-28 14:54:13 +0530 | [diff] [blame] | 184 | orr x0, x0, #1 << 59 |
Bhupesh Sharma | 80a7e35 | 2015-01-23 15:50:04 +0530 | [diff] [blame] | 185 | msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */ |
| 186 | #endif |
| 187 | |
Ashish kumar | 9c6d33c | 2016-01-27 18:09:32 +0530 | [diff] [blame] | 188 | #ifdef CONFIG_ARM_ERRATA_833471 |
| 189 | mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */ |
| 190 | /* FPSCR write flush. |
| 191 | * Note that in some cases where a flush is unnecessary this |
| 192 | could impact performance. */ |
| 193 | orr x0, x0, #1 << 38 |
| 194 | msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */ |
| 195 | #endif |
| 196 | |
| 197 | #ifdef CONFIG_ARM_ERRATA_829520 |
| 198 | mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */ |
| 199 | /* Disable Indirect Predictor bit will prevent this erratum |
| 200 | from occurring |
| 201 | * Note that in some cases where a flush is unnecessary this |
| 202 | could impact performance. */ |
| 203 | orr x0, x0, #1 << 4 |
| 204 | msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */ |
| 205 | #endif |
| 206 | |
Bhupesh Sharma | 80a7e35 | 2015-01-23 15:50:04 +0530 | [diff] [blame] | 207 | #ifdef CONFIG_ARM_ERRATA_833069 |
| 208 | mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */ |
| 209 | /* Disable Enable Invalidates of BTB bit */ |
| 210 | and x0, x0, #0xE |
| 211 | msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */ |
| 212 | #endif |
| 213 | b 0b |
| 214 | ENDPROC(apply_core_errata) |
| 215 | |
| 216 | /*-----------------------------------------------------------------------*/ |
| 217 | |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 218 | WEAK(lowlevel_init) |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 219 | mov x29, lr /* Save LR */ |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 220 | |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 221 | #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3) |
| 222 | branch_if_slave x0, 1f |
| 223 | ldr x0, =GICD_BASE |
| 224 | bl gic_init_secure |
| 225 | 1: |
| 226 | #if defined(CONFIG_GICV3) |
| 227 | ldr x0, =GICR_BASE |
| 228 | bl gic_init_secure_percpu |
| 229 | #elif defined(CONFIG_GICV2) |
| 230 | ldr x0, =GICD_BASE |
| 231 | ldr x1, =GICC_BASE |
| 232 | bl gic_init_secure_percpu |
| 233 | #endif |
Stephen Warren | 73f47af | 2016-04-28 12:45:44 -0600 | [diff] [blame] | 234 | #endif |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 235 | |
Masahiro Yamada | e4ce25f | 2016-05-20 12:13:10 +0900 | [diff] [blame] | 236 | #ifdef CONFIG_ARMV8_MULTIENTRY |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 237 | branch_if_master x0, x1, 2f |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 238 | |
| 239 | /* |
| 240 | * Slave should wait for master clearing spin table. |
| 241 | * This sync prevent salves observing incorrect |
| 242 | * value of spin table and jumping to wrong place. |
| 243 | */ |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 244 | #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3) |
| 245 | #ifdef CONFIG_GICV2 |
| 246 | ldr x0, =GICC_BASE |
| 247 | #endif |
| 248 | bl gic_wait_for_interrupt |
| 249 | #endif |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 250 | |
| 251 | /* |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 252 | * All slaves will enter EL2 and optionally EL1. |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 253 | */ |
| 254 | bl armv8_switch_to_el2 |
| 255 | #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 |
| 256 | bl armv8_switch_to_el1 |
| 257 | #endif |
| 258 | |
Linus Walleij | 7477139 | 2015-03-09 10:53:21 +0100 | [diff] [blame] | 259 | #endif /* CONFIG_ARMV8_MULTIENTRY */ |
| 260 | |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 261 | 2: |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 262 | mov lr, x29 /* Restore LR */ |
| 263 | ret |
| 264 | ENDPROC(lowlevel_init) |
| 265 | |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 266 | WEAK(smp_kick_all_cpus) |
| 267 | /* Kick secondary cpus up by SGI 0 interrupt */ |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 268 | #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3) |
| 269 | ldr x0, =GICD_BASE |
Masahiro Yamada | b914009 | 2016-06-17 18:32:47 +0900 | [diff] [blame] | 270 | b gic_kick_secondary_cpus |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 271 | #endif |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 272 | ret |
| 273 | ENDPROC(smp_kick_all_cpus) |
| 274 | |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 275 | /*-----------------------------------------------------------------------*/ |
| 276 | |
| 277 | ENTRY(c_runtime_cpu_setup) |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 278 | /* Relocate vBAR */ |
| 279 | adr x0, vectors |
| 280 | switch_el x1, 3f, 2f, 1f |
| 281 | 3: msr vbar_el3, x0 |
| 282 | b 0f |
| 283 | 2: msr vbar_el2, x0 |
| 284 | b 0f |
| 285 | 1: msr vbar_el1, x0 |
| 286 | 0: |
| 287 | |
| 288 | ret |
| 289 | ENDPROC(c_runtime_cpu_setup) |
Stephen Warren | 100a479 | 2016-07-18 17:01:50 -0600 | [diff] [blame] | 290 | |
| 291 | WEAK(save_boot_params) |
| 292 | b save_boot_params_ret /* back to my caller */ |
| 293 | ENDPROC(save_boot_params) |