wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 2 | * armboot - Startup Code for XScale CPU-core |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1998 Dan Malek <dmalek@jlc.net> |
| 5 | * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se> |
| 6 | * Copyright (C) 2000 Wolfgang Denk <wd@denx.de> |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 7 | * Copyright (C) 2001 Alex Zuepke <azu@sysgo.de> |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 8 | * Copyright (C) 2001 Marius Groger <mag@sysgo.de> |
| 9 | * Copyright (C) 2002 Alex Zupke <azu@sysgo.de> |
| 10 | * Copyright (C) 2002 Gary Jennejohn <garyj@denx.de> |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 11 | * Copyright (C) 2002 Kyle Harris <kharris@nexus-tech.net> |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 12 | * Copyright (C) 2003 Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de> |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 13 | * Copyright (C) 2003 Kshitij <kshitij@ti.com> |
| 14 | * Copyright (C) 2003 Richard Woodruff <r-woodruff2@ti.com> |
| 15 | * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de> |
| 16 | * Copyright (C) 2004 Texas Instruments <r-woodruff2@ti.com> |
| 17 | * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 18 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 19 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 22 | #include <asm-offsets.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 23 | #include <config.h> |
Marek Vasut | 7f4cfcf | 2011-11-05 19:26:47 +0100 | [diff] [blame] | 24 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 25 | /* |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 26 | ************************************************************************* |
| 27 | * |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 28 | * Startup Code (reset vector) |
| 29 | * |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 30 | * do important init only if we don't start from memory! |
| 31 | * setup Memory and board specific bits prior to relocation. |
| 32 | * relocate armboot to ram |
| 33 | * setup stack |
| 34 | * |
| 35 | ************************************************************************* |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 36 | */ |
| 37 | |
Albert ARIBAUD | 41623c9 | 2014-04-15 16:13:51 +0200 | [diff] [blame] | 38 | .globl reset |
Heiko Schocher | 5347f68 | 2010-09-17 13:10:46 +0200 | [diff] [blame] | 39 | |
| 40 | reset: |
| 41 | /* |
| 42 | * set the cpu to SVC32 mode |
| 43 | */ |
| 44 | mrs r0,cpsr |
| 45 | bic r0,r0,#0x1f |
| 46 | orr r0,r0,#0xd3 |
| 47 | msr cpsr,r0 |
| 48 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 49 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 50 | bl cpu_init_crit |
| 51 | #endif |
Heiko Schocher | 5347f68 | 2010-09-17 13:10:46 +0200 | [diff] [blame] | 52 | |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 53 | #ifdef CONFIG_CPU_PXA25X |
Marek Vasut | 7f4cfcf | 2011-11-05 19:26:47 +0100 | [diff] [blame] | 54 | bl lock_cache_for_stack |
| 55 | #endif |
| 56 | |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 57 | bl _main |
Heiko Schocher | 5347f68 | 2010-09-17 13:10:46 +0200 | [diff] [blame] | 58 | |
| 59 | /*------------------------------------------------------------------------------*/ |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 60 | |
| 61 | .globl c_runtime_cpu_setup |
| 62 | c_runtime_cpu_setup: |
| 63 | |
Albert ARIBAUD | 3da0e57 | 2013-05-19 01:48:15 +0000 | [diff] [blame] | 64 | #ifdef CONFIG_CPU_PXA25X |
| 65 | /* |
| 66 | * Unlock (actually, disable) the cache now that board_init_f |
| 67 | * is done. We could do this earlier but we would need to add |
| 68 | * a new C runtime hook, whereas c_runtime_cpu_setup already |
| 69 | * exists. |
| 70 | * As this routine is just a call to cpu_init_crit, let us |
| 71 | * tail-optimize and do a simple branch here. |
| 72 | */ |
| 73 | b cpu_init_crit |
| 74 | #else |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 75 | bx lr |
Albert ARIBAUD | 3da0e57 | 2013-05-19 01:48:15 +0000 | [diff] [blame] | 76 | #endif |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 77 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 78 | /* |
| 79 | ************************************************************************* |
| 80 | * |
| 81 | * CPU_init_critical registers |
| 82 | * |
| 83 | * setup important registers |
| 84 | * setup memory timing |
| 85 | * |
| 86 | ************************************************************************* |
| 87 | */ |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 88 | #if !defined(CONFIG_SKIP_LOWLEVEL_INIT) || defined(CONFIG_CPU_PXA25X) |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 89 | cpu_init_crit: |
| 90 | /* |
| 91 | * flush v4 I/D caches |
| 92 | */ |
| 93 | mov r0, #0 |
| 94 | mcr p15, 0, r0, c7, c7, 0 /* Invalidate I+D+BTB caches */ |
| 95 | mcr p15, 0, r0, c8, c7, 0 /* Invalidate Unified TLB */ |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 96 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 97 | /* |
| 98 | * disable MMU stuff and caches |
| 99 | */ |
| 100 | mrc p15, 0, r0, c1, c0, 0 |
Mike Dunn | 097d86d | 2013-06-17 10:47:28 -0700 | [diff] [blame] | 101 | bic r0, r0, #0x00003300 @ clear bits 13:12, 9:8 (--VI --RS) |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 102 | bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM) |
| 103 | orr r0, r0, #0x00000002 @ set bit 2 (A) Align |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 104 | mcr p15, 0, r0, c1, c0, 0 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 105 | |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 106 | mov pc, lr /* back to my caller */ |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 107 | #endif /* !CONFIG_SKIP_LOWLEVEL_INIT || CONFIG_CPU_PXA25X */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 108 | |
Marek Vasut | 7f4cfcf | 2011-11-05 19:26:47 +0100 | [diff] [blame] | 109 | /* |
| 110 | * Enable MMU to use DCache as DRAM. |
| 111 | * |
| 112 | * This is useful on PXA25x and PXA26x in early bootstages, where there is no |
| 113 | * other possible memory available to hold stack. |
| 114 | */ |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 115 | #ifdef CONFIG_CPU_PXA25X |
Marek Vasut | 7f4cfcf | 2011-11-05 19:26:47 +0100 | [diff] [blame] | 116 | .macro CPWAIT reg |
| 117 | mrc p15, 0, \reg, c2, c0, 0 |
| 118 | mov \reg, \reg |
| 119 | sub pc, pc, #4 |
| 120 | .endm |
| 121 | lock_cache_for_stack: |
| 122 | /* Domain access -- enable for all CPs */ |
| 123 | ldr r0, =0x0000ffff |
| 124 | mcr p15, 0, r0, c3, c0, 0 |
| 125 | |
| 126 | /* Point TTBR to MMU table */ |
| 127 | ldr r0, =mmutable |
| 128 | mcr p15, 0, r0, c2, c0, 0 |
| 129 | |
| 130 | /* Kick in MMU, ICache, DCache, BTB */ |
| 131 | mrc p15, 0, r0, c1, c0, 0 |
| 132 | bic r0, #0x1b00 |
| 133 | bic r0, #0x0087 |
| 134 | orr r0, #0x1800 |
| 135 | orr r0, #0x0005 |
| 136 | mcr p15, 0, r0, c1, c0, 0 |
| 137 | CPWAIT r0 |
| 138 | |
| 139 | /* Unlock Icache, Dcache */ |
| 140 | mcr p15, 0, r0, c9, c1, 1 |
| 141 | mcr p15, 0, r0, c9, c2, 1 |
| 142 | |
| 143 | /* Flush Icache, Dcache, BTB */ |
| 144 | mcr p15, 0, r0, c7, c7, 0 |
| 145 | |
| 146 | /* Unlock I-TLB, D-TLB */ |
| 147 | mcr p15, 0, r0, c10, c4, 1 |
| 148 | mcr p15, 0, r0, c10, c8, 1 |
| 149 | |
| 150 | /* Flush TLB */ |
| 151 | mcr p15, 0, r0, c8, c7, 0 |
| 152 | |
| 153 | /* Allocate 4096 bytes of Dcache as RAM */ |
| 154 | |
| 155 | /* Drain pending loads and stores */ |
| 156 | mcr p15, 0, r0, c7, c10, 4 |
| 157 | |
| 158 | mov r4, #0x00 |
| 159 | mov r5, #0x00 |
| 160 | mov r2, #0x01 |
| 161 | mcr p15, 0, r0, c9, c2, 0 |
| 162 | CPWAIT r0 |
| 163 | |
| 164 | /* 128 lines reserved (128 x 32bytes = 4096 bytes total) */ |
| 165 | mov r0, #128 |
| 166 | ldr r1, =0xfffff000 |
| 167 | |
| 168 | alloc: |
| 169 | mcr p15, 0, r1, c7, c2, 5 |
| 170 | /* Drain pending loads and stores */ |
| 171 | mcr p15, 0, r0, c7, c10, 4 |
| 172 | strd r4, [r1], #8 |
| 173 | strd r4, [r1], #8 |
| 174 | strd r4, [r1], #8 |
| 175 | strd r4, [r1], #8 |
| 176 | subs r0, #0x01 |
| 177 | bne alloc |
| 178 | /* Drain pending loads and stores */ |
| 179 | mcr p15, 0, r0, c7, c10, 4 |
| 180 | mov r2, #0x00 |
| 181 | mcr p15, 0, r2, c9, c2, 0 |
| 182 | CPWAIT r0 |
| 183 | |
| 184 | mov pc, lr |
| 185 | |
| 186 | .section .mmutable, "a" |
| 187 | mmutable: |
| 188 | .align 14 |
| 189 | /* 0x00000000 - 0xffe00000 : 1:1, uncached mapping */ |
| 190 | .set __base, 0 |
| 191 | .rept 0xfff |
| 192 | .word (__base << 20) | 0xc12 |
| 193 | .set __base, __base + 1 |
| 194 | .endr |
| 195 | |
| 196 | /* 0xfff00000 : 1:1, cached mapping */ |
| 197 | .word (0xfff << 20) | 0x1c1e |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 198 | #endif /* CONFIG_CPU_PXA25X */ |