ARM: make SWP emulation explicit on !CPU_USE_DOMAINS
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / kernel / head.S
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/arm/kernel/head.S
3 *
4 * Copyright (C) 1994-2002 Russell King
e65f38ed
RK
5 * Copyright (c) 2003 ARM Limited
6 * All Rights Reserved
1da177e4
LT
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Kernel startup code for all 32-bit CPUs
13 */
1da177e4
LT
14#include <linux/linkage.h>
15#include <linux/init.h>
16
17#include <asm/assembler.h>
18#include <asm/domain.h>
1da177e4 19#include <asm/ptrace.h>
e6ae744d 20#include <asm/asm-offsets.h>
f09b9979 21#include <asm/memory.h>
4f7a1812 22#include <asm/thread_info.h>
1da177e4
LT
23#include <asm/system.h>
24
c293393f
JK
25#ifdef CONFIG_DEBUG_LL
26#include <mach/debug-macro.S>
27#endif
28
d4e1c889
LW
29#if (PHYS_OFFSET & 0x001fffff)
30#error "PHYS_OFFSET must be at an even 2MiB boundary!"
31#endif
32
f06b97ff
RK
33#define KERNEL_RAM_VADDR (PAGE_OFFSET + TEXT_OFFSET)
34#define KERNEL_RAM_PADDR (PHYS_OFFSET + TEXT_OFFSET)
9d4f13e5 35
9d20fdd5 36
1da177e4 37/*
37d07b72 38 * swapper_pg_dir is the virtual address of the initial page table.
f06b97ff
RK
39 * We place the page tables 16K below KERNEL_RAM_VADDR. Therefore, we must
40 * make sure that KERNEL_RAM_VADDR is correctly set. Currently, we expect
37d07b72 41 * the least significant 16 bits to be 0x8000, but we could probably
f06b97ff 42 * relax this restriction to KERNEL_RAM_VADDR >= PAGE_OFFSET + 0x4000.
1da177e4 43 */
f06b97ff
RK
44#if (KERNEL_RAM_VADDR & 0xffff) != 0x8000
45#error KERNEL_RAM_VADDR must start at 0xXXXX8000
1da177e4
LT
46#endif
47
48 .globl swapper_pg_dir
f06b97ff 49 .equ swapper_pg_dir, KERNEL_RAM_VADDR - 0x4000
1da177e4 50
37d07b72 51 .macro pgtbl, rd
f06b97ff 52 ldr \rd, =(KERNEL_RAM_PADDR - 0x4000)
1da177e4 53 .endm
1da177e4 54
37d07b72 55#ifdef CONFIG_XIP_KERNEL
e98ff7f6
NP
56#define KERNEL_START XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR)
57#define KERNEL_END _edata_loc
37d07b72 58#else
e98ff7f6
NP
59#define KERNEL_START KERNEL_RAM_VADDR
60#define KERNEL_END _end
1da177e4
LT
61#endif
62
63/*
64 * Kernel startup entry point.
65 * ---------------------------
66 *
67 * This is normally called from the decompressor code. The requirements
68 * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,
9d20fdd5 69 * r1 = machine nr, r2 = atags pointer.
1da177e4
LT
70 *
71 * This code is mostly position independent, so if you link the kernel at
72 * 0xc0008000, you call this at __pa(0xc0008000).
73 *
74 * See linux/arch/arm/tools/mach-types for the complete list of machine
75 * numbers for r1.
76 *
77 * We're trying to keep crap to a minimum; DO NOT add any machine specific
78 * crap here - that's what the boot loader (or in extreme, well justified
79 * circumstances, zImage) is for.
80 */
2abc1c50 81 __HEAD
1da177e4 82ENTRY(stext)
b86040a5 83 setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode
1da177e4 84 @ and irqs disabled
0f44ba1d 85 mrc p15, 0, r9, c0, c0 @ get processor id
1da177e4
LT
86 bl __lookup_processor_type @ r5=procinfo r9=cpuid
87 movs r10, r5 @ invalid processor (r5=0)?
a75e5248 88 THUMB( it eq ) @ force fixup-able long branch encoding
3c0bdac3 89 beq __error_p @ yes, error 'p'
1da177e4
LT
90 bl __lookup_machine_type @ r5=machinfo
91 movs r8, r5 @ invalid machine (r5=0)?
a75e5248 92 THUMB( it eq ) @ force fixup-able long branch encoding
1da177e4 93 beq __error_a @ yes, error 'a'
0eb0511d
RK
94
95 /*
96 * r1 = machine no, r2 = atags,
97 * r8 = machinfo, r9 = cpuid, r10 = procinfo
98 */
9d20fdd5 99 bl __vet_atags
f00ec48f
RK
100#ifdef CONFIG_SMP_ON_UP
101 bl __fixup_smp
102#endif
1da177e4
LT
103 bl __create_page_tables
104
105 /*
106 * The following calls CPU specific code in a position independent
107 * manner. See arch/arm/mm/proc-*.S for details. r10 = base of
108 * xxx_proc_info structure selected by __lookup_machine_type
109 * above. On return, the CPU will be ready for the MMU to be
110 * turned on, and r0 will hold the CPU control register value.
111 */
a4ae4134 112 ldr r13, =__mmap_switched @ address to jump to after
1da177e4 113 @ mmu has been enabled
00945010 114 adr lr, BSYM(1f) @ return (PIC) address
b86040a5
CM
115 ARM( add pc, r10, #PROCINFO_INITFUNC )
116 THUMB( add r12, r10, #PROCINFO_INITFUNC )
117 THUMB( mov pc, r12 )
00945010 1181: b __enable_mmu
93ed3970 119ENDPROC(stext)
a4ae4134 120 .ltorg
1da177e4
LT
121
122/*
123 * Setup the initial page tables. We only setup the barest
124 * amount which are required to get the kernel running, which
125 * generally means mapping in the kernel code.
126 *
127 * r8 = machinfo
128 * r9 = cpuid
129 * r10 = procinfo
130 *
131 * Returns:
786f1b73 132 * r0, r3, r5-r7 corrupted
1da177e4
LT
133 * r4 = physical page table address
134 */
1da177e4 135__create_page_tables:
37d07b72 136 pgtbl r4 @ page table address
1da177e4
LT
137
138 /*
139 * Clear the 16K level 1 swapper page table
140 */
141 mov r0, r4
142 mov r3, #0
143 add r6, r0, #0x4000
1441: str r3, [r0], #4
145 str r3, [r0], #4
146 str r3, [r0], #4
147 str r3, [r0], #4
148 teq r0, r6
149 bne 1b
150
8799ee9f 151 ldr r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags
1da177e4
LT
152
153 /*
786f1b73
RK
154 * Create identity mapping to cater for __enable_mmu.
155 * This identity mapping will be removed by paging_init().
1da177e4 156 */
786f1b73
RK
157 adr r0, __enable_mmu_loc
158 ldmia r0, {r3, r5, r6}
159 sub r0, r0, r3 @ virt->phys offset
160 add r5, r5, r0 @ phys __enable_mmu
161 add r6, r6, r0 @ phys __enable_mmu_end
162 mov r5, r5, lsr #20
163 mov r6, r6, lsr #20
164
1651: orr r3, r7, r5, lsl #20 @ flags + kernel base
166 str r3, [r4, r5, lsl #2] @ identity mapping
167 teq r5, r6
168 addne r5, r5, #1 @ next section
169 bne 1b
1da177e4
LT
170
171 /*
172 * Now setup the pagetables for our kernel direct
2552fc27 173 * mapped region.
1da177e4 174 */
786f1b73
RK
175 mov r3, pc
176 mov r3, r3, lsr #20
177 orr r3, r7, r3, lsl #20
e98ff7f6
NP
178 add r0, r4, #(KERNEL_START & 0xff000000) >> 18
179 str r3, [r0, #(KERNEL_START & 0x00f00000) >> 18]!
180 ldr r6, =(KERNEL_END - 1)
181 add r0, r0, #4
182 add r6, r4, r6, lsr #18
1831: cmp r0, r6
184 add r3, r3, #1 << 20
185 strls r3, [r0], #4
186 bls 1b
1da177e4 187
ec3622d9
NP
188#ifdef CONFIG_XIP_KERNEL
189 /*
190 * Map some ram to cover our .data and .bss areas.
191 */
192 orr r3, r7, #(KERNEL_RAM_PADDR & 0xff000000)
40435792 193 .if (KERNEL_RAM_PADDR & 0x00f00000)
ec3622d9 194 orr r3, r3, #(KERNEL_RAM_PADDR & 0x00f00000)
40435792 195 .endif
ec3622d9
NP
196 add r0, r4, #(KERNEL_RAM_VADDR & 0xff000000) >> 18
197 str r3, [r0, #(KERNEL_RAM_VADDR & 0x00f00000) >> 18]!
198 ldr r6, =(_end - 1)
199 add r0, r0, #4
200 add r6, r4, r6, lsr #18
2011: cmp r0, r6
202 add r3, r3, #1 << 20
203 strls r3, [r0], #4
204 bls 1b
205#endif
206
1da177e4
LT
207 /*
208 * Then map first 1MB of ram in case it contains our boot params.
209 */
f09b9979 210 add r0, r4, #PAGE_OFFSET >> 18
d4e1c889 211 orr r6, r7, #(PHYS_OFFSET & 0xff000000)
40435792
NP
212 .if (PHYS_OFFSET & 0x00f00000)
213 orr r6, r6, #(PHYS_OFFSET & 0x00f00000)
214 .endif
1da177e4
LT
215 str r6, [r0]
216
c77b0427 217#ifdef CONFIG_DEBUG_LL
c293393f 218#ifndef CONFIG_DEBUG_ICEDCC
1da177e4
LT
219 /*
220 * Map in IO space for serial debugging.
221 * This allows debug messages to be output
222 * via a serial console before paging_init.
223 */
c293393f
JK
224 addruart r7, r3
225
226 mov r3, r3, lsr #20
227 mov r3, r3, lsl #2
228
1da177e4
LT
229 add r0, r4, r3
230 rsb r3, r3, #0x4000 @ PTRS_PER_PGD*sizeof(long)
231 cmp r3, #0x0800 @ limit to 512MB
232 movhi r3, #0x0800
233 add r6, r0, r3
c293393f
JK
234 mov r3, r7, lsr #20
235 ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
236 orr r3, r7, r3, lsl #20
1da177e4
LT
2371: str r3, [r0], #4
238 add r3, r3, #1 << 20
239 teq r0, r6
240 bne 1b
c293393f
JK
241
242#else /* CONFIG_DEBUG_ICEDCC */
243 /* we don't need any serial debugging mappings for ICEDCC */
244 ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
245#endif /* !CONFIG_DEBUG_ICEDCC */
246
1da177e4
LT
247#if defined(CONFIG_ARCH_NETWINDER) || defined(CONFIG_ARCH_CATS)
248 /*
3c0bdac3
RK
249 * If we're using the NetWinder or CATS, we also need to map
250 * in the 16550-type serial port for the debug messages
1da177e4 251 */
c77b0427
RK
252 add r0, r4, #0xff000000 >> 18
253 orr r3, r7, #0x7c000000
254 str r3, [r0]
1da177e4 255#endif
1da177e4
LT
256#ifdef CONFIG_ARCH_RPC
257 /*
258 * Map in screen at 0x02000000 & SCREEN2_BASE
259 * Similar reasons here - for debug. This is
260 * only for Acorn RiscPC architectures.
261 */
c77b0427
RK
262 add r0, r4, #0x02000000 >> 18
263 orr r3, r7, #0x02000000
1da177e4 264 str r3, [r0]
c77b0427 265 add r0, r4, #0xd8000000 >> 18
1da177e4 266 str r3, [r0]
c77b0427 267#endif
1da177e4
LT
268#endif
269 mov pc, lr
93ed3970 270ENDPROC(__create_page_tables)
1da177e4 271 .ltorg
4f79a5dd 272 .align
786f1b73
RK
273__enable_mmu_loc:
274 .long .
275 .long __enable_mmu
276 .long __enable_mmu_end
1da177e4 277
00945010
RK
278#if defined(CONFIG_SMP)
279 __CPUINIT
280ENTRY(secondary_startup)
281 /*
282 * Common entry point for secondary CPUs.
283 *
284 * Ensure that we're in SVC mode, and IRQs are disabled. Lookup
285 * the processor type - there is no need to check the machine type
286 * as it has already been validated by the primary processor.
287 */
288 setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9
289 mrc p15, 0, r9, c0, c0 @ get processor id
290 bl __lookup_processor_type
291 movs r10, r5 @ invalid processor?
292 moveq r0, #'p' @ yes, error 'p'
a75e5248 293 THUMB( it eq ) @ force fixup-able long branch encoding
00945010
RK
294 beq __error_p
295
296 /*
297 * Use the page tables supplied from __cpu_up.
298 */
299 adr r4, __secondary_data
300 ldmia r4, {r5, r7, r12} @ address to jump to after
301 sub r4, r4, r5 @ mmu has been enabled
302 ldr r4, [r7, r4] @ get secondary_data.pgdir
303 adr lr, BSYM(__enable_mmu) @ return address
304 mov r13, r12 @ __secondary_switched address
305 ARM( add pc, r10, #PROCINFO_INITFUNC ) @ initialise processor
306 @ (return control reg)
307 THUMB( add r12, r10, #PROCINFO_INITFUNC )
308 THUMB( mov pc, r12 )
309ENDPROC(secondary_startup)
310
311 /*
312 * r6 = &secondary_data
313 */
314ENTRY(__secondary_switched)
315 ldr sp, [r7, #4] @ get secondary_data.stack
316 mov fp, #0
317 b secondary_start_kernel
318ENDPROC(__secondary_switched)
319
4f79a5dd
DM
320 .align
321
00945010
RK
322 .type __secondary_data, %object
323__secondary_data:
324 .long .
325 .long secondary_data
326 .long __secondary_switched
327#endif /* defined(CONFIG_SMP) */
328
329
330
331/*
332 * Setup common bits before finally enabling the MMU. Essentially
333 * this is just loading the page table pointer and domain access
334 * registers.
865a4fae
RK
335 *
336 * r0 = cp#15 control register
337 * r1 = machine ID
338 * r2 = atags pointer
339 * r4 = page table pointer
340 * r9 = processor ID
341 * r13 = *virtual* address to jump to upon completion
00945010
RK
342 */
343__enable_mmu:
344#ifdef CONFIG_ALIGNMENT_TRAP
345 orr r0, r0, #CR_A
346#else
347 bic r0, r0, #CR_A
348#endif
349#ifdef CONFIG_CPU_DCACHE_DISABLE
350 bic r0, r0, #CR_C
351#endif
352#ifdef CONFIG_CPU_BPREDICT_DISABLE
353 bic r0, r0, #CR_Z
354#endif
355#ifdef CONFIG_CPU_ICACHE_DISABLE
356 bic r0, r0, #CR_I
357#endif
358 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
359 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
360 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
361 domain_val(DOMAIN_IO, DOMAIN_CLIENT))
362 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
363 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
364 b __turn_mmu_on
365ENDPROC(__enable_mmu)
366
367/*
368 * Enable the MMU. This completely changes the structure of the visible
369 * memory space. You will not be able to trace execution through this.
370 * If you have an enquiry about this, *please* check the linux-arm-kernel
371 * mailing list archives BEFORE sending another post to the list.
372 *
373 * r0 = cp#15 control register
865a4fae
RK
374 * r1 = machine ID
375 * r2 = atags pointer
376 * r9 = processor ID
00945010
RK
377 * r13 = *virtual* address to jump to upon completion
378 *
379 * other registers depend on the function called upon completion
380 */
381 .align 5
382__turn_mmu_on:
383 mov r0, r0
384 mcr p15, 0, r0, c1, c0, 0 @ write control reg
385 mrc p15, 0, r3, c0, c0, 0 @ read id reg
386 mov r3, r3
387 mov r3, r13
388 mov pc, r3
389__enable_mmu_end:
390ENDPROC(__turn_mmu_on)
391
1da177e4 392
f00ec48f
RK
393#ifdef CONFIG_SMP_ON_UP
394__fixup_smp:
e98ff0f5
RK
395 and r3, r9, #0x000f0000 @ architecture version
396 teq r3, #0x000f0000 @ CPU ID supported?
f00ec48f
RK
397 bne __fixup_smp_on_up @ no, assume UP
398
e98ff0f5
RK
399 bic r3, r9, #0x00ff0000
400 bic r3, r3, #0x0000000f @ mask 0xff00fff0
401 mov r4, #0x41000000
0eb0511d 402 orr r4, r4, #0x0000b000
e98ff0f5
RK
403 orr r4, r4, #0x00000020 @ val 0x4100b020
404 teq r3, r4 @ ARM 11MPCore?
f00ec48f
RK
405 moveq pc, lr @ yes, assume SMP
406
407 mrc p15, 0, r0, c0, c0, 5 @ read MPIDR
e98ff0f5
RK
408 and r0, r0, #0xc0000000 @ multiprocessing extensions and
409 teq r0, #0x80000000 @ not part of a uniprocessor system?
410 moveq pc, lr @ yes, assume SMP
f00ec48f
RK
411
412__fixup_smp_on_up:
413 adr r0, 1f
0eb0511d 414 ldmia r0, {r3 - r5}
f00ec48f 415 sub r3, r0, r3
0eb0511d
RK
416 add r4, r4, r3
417 add r5, r5, r3
4182: cmp r4, r5
ed3768a8 419 movhs pc, lr
0eb0511d 420 ldmia r4!, {r0, r6}
ed3768a8
DM
421 ARM( str r6, [r0, r3] )
422 THUMB( add r0, r0, r3 )
423#ifdef __ARMEB__
424 THUMB( mov r6, r6, ror #16 ) @ Convert word order for big-endian.
425#endif
426 THUMB( strh r6, [r0], #2 ) @ For Thumb-2, store as two halfwords
427 THUMB( mov r6, r6, lsr #16 ) @ to be robust against misaligned r3.
428 THUMB( strh r6, [r0] )
429 b 2b
f00ec48f
RK
430ENDPROC(__fixup_smp)
431
4f79a5dd 432 .align
f00ec48f
RK
4331: .word .
434 .word __smpalt_begin
435 .word __smpalt_end
436
437 .pushsection .data
438 .globl smp_on_up
439smp_on_up:
440 ALT_SMP(.long 1)
441 ALT_UP(.long 0)
442 .popsection
443
444#endif
445
75d90832 446#include "head-common.S"