1/* 2 * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core 3 * 4 * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com> 5 * 6 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de> 7 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de> 8 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de> 9 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com> 10 * Copyright (c) 2003 Kshitij <kshitij@ti.com> 11 * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com> 12 * 13 * SPDX-License-Identifier: GPL-2.0+ 14 */ 15 16#include <asm-offsets.h> 17#include <config.h> 18#include <asm/system.h> 19#include <linux/linkage.h> 20#include <asm/armv7.h> 21 22/************************************************************************* 23 * 24 * Startup Code (reset vector) 25 * 26 * Do important init only if we don't start from memory! 27 * Setup memory and board specific bits prior to relocation. 28 * Relocate armboot to ram. Setup stack. 29 * 30 *************************************************************************/ 31 32 .globl reset 33 .globl save_boot_params_ret 34 .type save_boot_params_ret,%function 35#ifdef CONFIG_ARMV7_LPAE 36 .global switch_to_hypervisor_ret 37#endif 38 39#if !CONFIG_IS_ENABLED(TINY_FRAMEWORK) 40 41reset: 42 /* Allow the board to save important registers */ 43 b save_boot_params 44save_boot_params_ret: 45#ifdef CONFIG_ARMV7_LPAE 46/* 47 * check for Hypervisor support 48 */ 49 mrc p15, 0, r0, c0, c1, 1 @ read ID_PFR1 50 and r0, r0, #CPUID_ARM_VIRT_MASK @ mask virtualization bits 51 cmp r0, #(1 << CPUID_ARM_VIRT_SHIFT) 52 beq switch_to_hypervisor 53switch_to_hypervisor_ret: 54#endif 55 /* 56 * disable interrupts (FIQ and IRQ), also set the cpu to SVC32 mode, 57 * except if in HYP mode already 58 */ 59 mrs r0, cpsr 60 and r1, r0, #0x1f @ mask mode bits 61 teq r1, #0x1a @ test for HYP mode 62 bicne r0, r0, #0x1f @ clear all mode bits 63 orrne r0, r0, #0x13 @ set SVC mode 64 orr r0, r0, #0xc0 @ disable FIQ and IRQ 65 msr cpsr,r0 66 67 /* Enable ACTLR.SMP bit */ 68 mrc p15, 0, r0, c1, c0, 1 69 orr r0, r0, #(1 << 6) @ Enable ACTLR.SMP bit 70 mcr p15, 0, r0, c1, c0, 1 71 72/* 73 * Setup vector: 74 * (OMAP4 spl TEXT_BASE is not 32 byte aligned. 75 * Continue to use ROM code vector only in OMAP4 spl) 76 */ 77#if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD)) 78 /* Set V=0 in CP15 SCTLR register - for VBAR to point to vector */ 79 mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTLR Register 80 bic r0, #CR_V @ V = 0 81 mcr p15, 0, r0, c1, c0, 0 @ Write CP15 SCTLR Register 82 83 /* Set vector address in CP15 VBAR register */ 84 ldr r0, =_start 85 mcr p15, 0, r0, c12, c0, 0 @Set VBAR 86#endif 87 88 /* Enable Asynchronous external abort after vectors setup */ 89 mrs r0, cpsr 90 bic r0, r0, #0x100 @ CPSR.A bit 91 msr cpsr_x,r0 92 93 /* the mask ROM code should have PLL and others stable */ 94#ifndef CONFIG_SKIP_LOWLEVEL_INIT 95 bl cpu_init_cp15 96#ifndef CONFIG_SKIP_LOWLEVEL_INIT_ONLY 97 bl cpu_init_crit 98#endif 99#endif 100 101 bl _main 102 103/*------------------------------------------------------------------------------*/ 104 105ENTRY(c_runtime_cpu_setup) 106/* 107 * If I-cache is enabled invalidate it 108 */ 109#ifndef CONFIG_SYS_ICACHE_OFF 110 mcr p15, 0, r0, c7, c5, 0 @ invalidate icache 111 mcr p15, 0, r0, c7, c10, 4 @ DSB 112 mcr p15, 0, r0, c7, c5, 4 @ ISB 113#endif 114 115 bx lr 116 117ENDPROC(c_runtime_cpu_setup) 118 119#endif/* !CONFIG_IS_ENABLED(TINY_FRAMEWORK) */ 120 121/************************************************************************* 122 * 123 * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) 124 * __attribute__((weak)); 125 * 126 * Stack pointer is not yet initialized at this moment 127 * Don't save anything to stack even if compiled with -O0 128 * 129 *************************************************************************/ 130ENTRY(save_boot_params) 131 b save_boot_params_ret @ back to my caller 132ENDPROC(save_boot_params) 133 .weak save_boot_params 134 135#ifdef CONFIG_ARMV7_LPAE 136ENTRY(switch_to_hypervisor) 137 b switch_to_hypervisor_ret 138ENDPROC(switch_to_hypervisor) 139 .weak switch_to_hypervisor 140#endif 141 142/************************************************************************* 143 * 144 * cpu_init_cp15 145 * 146 * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless 147 * CONFIG_SYS_ICACHE_OFF is defined. 148 * 149 *************************************************************************/ 150ENTRY(cpu_init_cp15) 151 /* 152 * Invalidate L1 I/D 153 */ 154 mov r0, #0 @ set up for MCR 155 mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs 156 mcr p15, 0, r0, c7, c5, 0 @ invalidate icache 157 mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array 158 mcr p15, 0, r0, c7, c10, 4 @ DSB 159 mcr p15, 0, r0, c7, c5, 4 @ ISB 160 161 /* 162 * disable MMU stuff and caches 163 */ 164 mrc p15, 0, r0, c1, c0, 0 165 bic r0, r0, #0x00002000 @ clear bits 13 (--V-) 166 bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM) 167 orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align 168 orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB 169#ifdef CONFIG_SYS_ICACHE_OFF 170 bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache 171#else 172 orr r0, r0, #0x00001000 @ set bit 12 (I) I-cache 173#endif 174 mcr p15, 0, r0, c1, c0, 0 175 176#ifdef CONFIG_ARM_ERRATA_716044 177 mrc p15, 0, r0, c1, c0, 0 @ read system control register 178 orr r0, r0, #1 << 11 @ set bit #11 179 mcr p15, 0, r0, c1, c0, 0 @ write system control register 180#endif 181 182#if (defined(CONFIG_ARM_ERRATA_742230) || defined(CONFIG_ARM_ERRATA_794072)) 183 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 184 orr r0, r0, #1 << 4 @ set bit #4 185 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 186#endif 187 188#ifdef CONFIG_ARM_ERRATA_743622 189 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 190 orr r0, r0, #1 << 6 @ set bit #6 191 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 192#endif 193 194#ifdef CONFIG_ARM_ERRATA_751472 195 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 196 orr r0, r0, #1 << 11 @ set bit #11 197 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 198#endif 199#ifdef CONFIG_ARM_ERRATA_761320 200 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 201 orr r0, r0, #1 << 21 @ set bit #21 202 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 203#endif 204 205#ifdef CONFIG_ARM_ERRATA_845369 206 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 207 orr r0, r0, #1 << 22 @ set bit #22 208 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 209#endif 210 211 mov r5, lr @ Store my Caller 212 mrc p15, 0, r1, c0, c0, 0 @ r1 has Read Main ID Register (MIDR) 213 mov r3, r1, lsr #20 @ get variant field 214 and r3, r3, #0xf @ r3 has CPU variant 215 and r4, r1, #0xf @ r4 has CPU revision 216 mov r2, r3, lsl #4 @ shift variant field for combined value 217 orr r2, r4, r2 @ r2 has combined CPU variant + revision 218 219#ifdef CONFIG_ARM_ERRATA_798870 220 cmp r2, #0x30 @ Applies to lower than R3p0 221 bge skip_errata_798870 @ skip if not affected rev 222 cmp r2, #0x20 @ Applies to including and above R2p0 223 blt skip_errata_798870 @ skip if not affected rev 224 225 mrc p15, 1, r0, c15, c0, 0 @ read l2 aux ctrl reg 226 orr r0, r0, #1 << 7 @ Enable hazard-detect timeout 227 push {r1-r5} @ Save the cpu info registers 228 bl v7_arch_cp15_set_l2aux_ctrl 229 isb @ Recommended ISB after l2actlr update 230 pop {r1-r5} @ Restore the cpu info - fall through 231skip_errata_798870: 232#endif 233 234#ifdef CONFIG_ARM_ERRATA_801819 235 cmp r2, #0x24 @ Applies to lt including R2p4 236 bgt skip_errata_801819 @ skip if not affected rev 237 cmp r2, #0x20 @ Applies to including and above R2p0 238 blt skip_errata_801819 @ skip if not affected rev 239 mrc p15, 0, r0, c0, c0, 6 @ pick up REVIDR reg 240 and r0, r0, #1 << 3 @ check REVIDR[3] 241 cmp r0, #1 << 3 242 beq skip_errata_801819 @ skip erratum if REVIDR[3] is set 243 244 mrc p15, 0, r0, c1, c0, 1 @ read auxilary control register 245 orr r0, r0, #3 << 27 @ Disables streaming. All write-allocate 246 @ lines allocate in the L1 or L2 cache. 247 orr r0, r0, #3 << 25 @ Disables streaming. All write-allocate 248 @ lines allocate in the L1 cache. 249 push {r1-r5} @ Save the cpu info registers 250 bl v7_arch_cp15_set_acr 251 pop {r1-r5} @ Restore the cpu info - fall through 252skip_errata_801819: 253#endif 254 255#ifdef CONFIG_ARM_ERRATA_454179 256 cmp r2, #0x21 @ Only on < r2p1 257 bge skip_errata_454179 258 259 mrc p15, 0, r0, c1, c0, 1 @ Read ACR 260 orr r0, r0, #(0x3 << 6) @ Set DBSM(BIT7) and IBE(BIT6) bits 261 push {r1-r5} @ Save the cpu info registers 262 bl v7_arch_cp15_set_acr 263 pop {r1-r5} @ Restore the cpu info - fall through 264 265skip_errata_454179: 266#endif 267 268#ifdef CONFIG_ARM_ERRATA_430973 269 cmp r2, #0x21 @ Only on < r2p1 270 bge skip_errata_430973 271 272 mrc p15, 0, r0, c1, c0, 1 @ Read ACR 273 orr r0, r0, #(0x1 << 6) @ Set IBE bit 274 push {r1-r5} @ Save the cpu info registers 275 bl v7_arch_cp15_set_acr 276 pop {r1-r5} @ Restore the cpu info - fall through 277 278skip_errata_430973: 279#endif 280 281#ifdef CONFIG_ARM_ERRATA_621766 282 cmp r2, #0x21 @ Only on < r2p1 283 bge skip_errata_621766 284 285 mrc p15, 0, r0, c1, c0, 1 @ Read ACR 286 orr r0, r0, #(0x1 << 5) @ Set L1NEON bit 287 push {r1-r5} @ Save the cpu info registers 288 bl v7_arch_cp15_set_acr 289 pop {r1-r5} @ Restore the cpu info - fall through 290 291skip_errata_621766: 292#endif 293 294#ifdef CONFIG_ARM_ERRATA_725233 295 cmp r2, #0x21 @ Only on < r2p1 (Cortex A8) 296 bge skip_errata_725233 297 298 mrc p15, 1, r0, c9, c0, 2 @ Read L2ACR 299 orr r0, r0, #(0x1 << 27) @ L2 PLD data forwarding disable 300 push {r1-r5} @ Save the cpu info registers 301 bl v7_arch_cp15_set_l2aux_ctrl 302 pop {r1-r5} @ Restore the cpu info - fall through 303 304skip_errata_725233: 305#endif 306 307#ifdef CONFIG_ARM_ERRATA_852421 308 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 309 orr r0, r0, #1 << 24 @ set bit #24 310 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 311#endif 312 313#ifdef CONFIG_ARM_ERRATA_852423 314 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register 315 orr r0, r0, #1 << 12 @ set bit #12 316 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register 317#endif 318 319 mov pc, r5 @ back to my caller 320ENDPROC(cpu_init_cp15) 321 322#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) && \ 323 !defined(CONFIG_SKIP_LOWLEVEL_INIT_ONLY) 324/************************************************************************* 325 * 326 * CPU_init_critical registers 327 * 328 * setup important registers 329 * setup memory timing 330 * 331 *************************************************************************/ 332ENTRY(cpu_init_crit) 333 /* 334 * Jump to board specific initialization... 335 * The Mask ROM will have already initialized 336 * basic memory. Go here to bump up clock rate and handle 337 * wake up conditions. 338 */ 339 b lowlevel_init @ go setup pll,mux,memory 340ENDPROC(cpu_init_crit) 341#endif 342