2 * Machine dependant startup code for BEAGLEBOARD boards.
3 * Based on omap_start.S
5 * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
6 * Written by Hiroyuki Bessho for Genetec Corporation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of Genetec Corporation may not be used to endorse or
17 * promote products derived from this software without specific prior
20 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
33 * Ichiro FUKUHARA <ichiro@ichiro.org>.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
46 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
49 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * Copyright (c) 2007 Microsoft
58 * All rights reserved.
60 * Redistribution and use in source and binary forms, with or without
61 * modification, are permitted provided that the following conditions
63 * 1. Redistributions of source code must retain the above copyright
64 * notice, this list of conditions and the following disclaimer.
65 * 2. Redistributions in binary form must reproduce the above copyright
66 * notice, this list of conditions and the following disclaimer in the
67 * documentation and/or other materials provided with the distribution.
68 * 3. All advertising materials mentioning features or use of this software
69 * must display the following acknowledgement:
70 * This product includes software developed by Microsoft
72 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
73 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
74 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
75 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
76 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
77 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
78 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
80 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
81 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89 #include <machine/asm.h>
90 #include <arm/armreg.h>
91 #undef DOMAIN_CLIENT /* assym.h defines as 1, but pte.h defines as 0x01 */
92 #include <arm/arm32/pmap.h>
93 #include <arm/omap/omap2_obioreg.h>
94 #include <evbarm/beagle/beagle.h>
96 RCSID("$NetBSD: beagle_start.S,v 1.2 2008/10/22 17:29:33 matt Exp $")
98 #define Invalidate_I_cache(reg) \
99 mcr p15, 0, reg, c7, c5, 0 /* Invalidate Entire I cache */
102 * Kernel start routine for BEAGLEBOARD boards.
103 * At this point, this code has been loaded into SDRAM
106 .section .start,"ax",%progbits
108 .global _C_LABEL(beagle_start)
109 _C_LABEL(beagle_start):
110 /* Move into supervisor mode and disable IRQs/FIQs. */
112 bic r0, r0, #PSR_MODE
113 orr r0, r0, #(I32_bit | F32_bit | PSR_SVC32_MODE)
117 * Set up a preliminary mapping in the MMU to allow us to run
118 * at KERNEL_BASE with caches on.
120 /* Build page table from scratch */
121 ldr r0, Ltemp_l1_table
122 mov r1, r0 /* Save the page table address. */
123 /* Zero the entire table so all virtual addresses are invalid. */
124 mov r2, #L1_TABLE_SIZE /* in bytes */
133 1: stmia r1!, {r3-r8,r10-r11}
134 stmia r1!, {r3-r8,r10-r11}
135 stmia r1!, {r3-r8,r10-r11}
136 stmia r1!, {r3-r8,r10-r11}
137 subs r2, r2, #(4 * 4 * 8) /* bytes per loop */
140 /* Now create our entries per the mmu_init_table. */
148 adr itable, mmu_init_table
149 ldr l1sfrm, Ll1_s_frame
151 2: str pa, [l1table, va]
153 add pa, pa, #(L1_S_SIZE)
154 adds n_sec, n_sec, #-1
156 3: ldmia itable!, {va,pa,n_sec,attr}
157 /* Convert va to l1 offset: va = 4 * (va >> L1_S_SHIFT) */
158 mov va, va, LSR #L1_S_SHIFT
160 /* Convert pa to l1 entry: pa = (pa & L1_S_FRAME) | attr */
174 * In theory, because the MMU is off, we shouldn't need all of this,
175 * but let's not take any chances and do a typical sequence to set
176 * the Translation Table Base.
179 Invalidate_I_cache(r0)
181 mcr p15, 0, r0, c7, c14, 0 /* Clean and Invalidate Entire Data Cache */
183 ldr r2, Lctl_ID_dis /* Disable I+D caches */
184 mrc p15, 0, r1, c1, c0, 0 /* " " " */
185 and r1, r1, r2 /* " " " */
186 mcr p15, 0, r1, c1, c0, 0 /* " " " */
188 mcr p15, 0, r0, c7, c10, 4 /* Drain the write buffers. */
189 mcr p15, 0, r0, c2, c0, 0 /* Set Translation Table Base */
190 mcr p15, 0, r0, c8, c7, 0 /* Invalidate TLBs */
192 /* Set the Domain Access register. Very important! */
193 mov r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
194 mcr p15, 0, r0, c3, c0, 0
197 * Enable the MMU, etc.
199 mrc p15, 0, r0, c1, c0, 0
207 mcr p15, 0, r0, c1, c0, 0
210 * Ensure that the coprocessor has finished turning on the MMU.
212 mrc p15, 0, r0, c2, c0, 0 /* Read an arbitrary value. */
213 mov r0, r0 /* Stall until read completes. */
216 * Jump to start in locore.S, which in turn will call initarm and main.
218 b start /* Jump to start (flushes pipeline). */
229 /* Put the temporary L1 translation table at the end of SDRAM. */
230 .word 0x80000000 + MEMSIZE * 0x100000 - L1_TABLE_SIZE
233 * Coprocessor register initialization values
235 # define CPU_AUXCTL_CZ (1 << 6) /* Restrict Cache Size */
237 /* bits to set in the Control Register */
239 .word CPU_CONTROL_MMU_ENABLE | \
240 CPU_CONTROL_AFLT_ENABLE | \
241 CPU_CONTROL_DC_ENABLE | \
242 CPU_CONTROL_WBUF_ENABLE | \
243 CPU_CONTROL_32BP_ENABLE | \
244 CPU_CONTROL_32BD_ENABLE | \
245 CPU_CONTROL_LABT_ENABLE | \
246 CPU_CONTROL_SYST_ENABLE | \
247 CPU_CONTROL_IC_ENABLE
249 /* bits to clear in the Control Register */
253 /* bits to "write as existing" in the Control Register */
262 /* bits to disable the caches */
264 .word ~(CPU_CONTROL_IC_ENABLE|CPU_CONTROL_DC_ENABLE)
266 /* bit to restrict cache size */
271 /* We'll modify va and pa at run time so we can use relocatable addresses. */
272 #define MMU_INIT(va,pa,n_sec,attr) \
279 /* Map KERNEL_BASE VA to SDRAM PA, write-back cacheable */
280 MMU_INIT(KERNEL_BASE, KERNEL_BASE,
281 (MEMSIZE * L1_S_SIZE + L1_S_SIZE - 1) / L1_S_SIZE,
282 L1_S_PROTO | L1_S_AP(AP_KRW) | L1_S_B | L1_S_C)
284 /* Map first 1MB of L4 CORE (so console will work) */
285 MMU_INIT(OMAP3530_L4_CORE_VBASE, OMAP3530_L4_CORE_BASE,
287 L1_S_PROTO | L1_S_AP(AP_KRW))
289 /* Map first(all) 1MB of L4 PERIPHERAL (so console will work) */
290 MMU_INIT(OMAP3530_L4_PERIPHERAL_VBASE, OMAP3530_L4_PERIPHERAL_BASE,
292 L1_S_PROTO | L1_S_AP(AP_KRW))
294 /* Map all 256KB of L4 WAKEUP (so console will work) */
295 MMU_INIT(OMAP3530_L4_WAKEUP_VBASE, OMAP3530_L4_WAKEUP_BASE,
297 L1_S_PROTO | L1_S_AP(AP_KRW))