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