2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/kernel/head.S
|
|
|
|
*
|
|
|
|
* Copyright (C) 1994-2002 Russell King
|
2005-06-18 16:33:31 +08:00
|
|
|
* Copyright (c) 2003 ARM Limited
|
|
|
|
* All Rights Reserved
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Kernel startup code for all 32-bit CPUs
|
|
|
|
*/
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <asm/assembler.h>
|
2012-01-19 18:05:41 +08:00
|
|
|
#include <asm/cp15.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/domain.h>
|
|
|
|
#include <asm/ptrace.h>
|
2005-09-10 03:08:59 +08:00
|
|
|
#include <asm/asm-offsets.h>
|
2005-10-30 04:44:55 +08:00
|
|
|
#include <asm/memory.h>
|
2005-05-05 20:11:00 +08:00
|
|
|
#include <asm/thread_info.h>
|
2011-08-23 21:07:23 +08:00
|
|
|
#include <asm/pgtable.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-08-31 13:03:46 +08:00
|
|
|
#if defined(CONFIG_DEBUG_LL) && !defined(CONFIG_DEBUG_SEMIHOSTING)
|
|
|
|
#include CONFIG_DEBUG_LL_INCLUDE
|
2010-07-07 11:19:48 +08:00
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2005-10-30 04:44:56 +08:00
|
|
|
* swapper_pg_dir is the virtual address of the initial page table.
|
2006-12-12 06:29:16 +08:00
|
|
|
* We place the page tables 16K below KERNEL_RAM_VADDR. Therefore, we must
|
|
|
|
* make sure that KERNEL_RAM_VADDR is correctly set. Currently, we expect
|
2005-10-30 04:44:56 +08:00
|
|
|
* the least significant 16 bits to be 0x8000, but we could probably
|
2006-12-12 06:29:16 +08:00
|
|
|
* relax this restriction to KERNEL_RAM_VADDR >= PAGE_OFFSET + 0x4000.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
ARM: P2V: eliminate head.S use of PHYS_OFFSET for !XIP_KERNEL
head.S makes use of PHYS_OFFSET. When it becomes a variable, the
assembler won't understand this. Compute PHYS_OFFSET by the following
method. This code is linked at its virtual address, but run at before
the MMU is enabled, so at his physical address.
1: .long .
.long PAGE_OFFSET
adr r0, 1b @ r0 = physical ','
ldmia r0, {r1, r2} @ r1 = virtual '.', r2 = PAGE_OFFSET
sub r1, r0, r1 @ r1 = physical-virtual
add r2, r2, r1 @ r2 = PAGE_OFFSET + physical-virtual
@ := PHYS_OFFSET.
Switch XIP users of PHYS_OFFSET to use PLAT_PHYS_OFFSET - we can't
use this method for XIP kernels as the code doesn't execute in RAM.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:04:00 +08:00
|
|
|
#define KERNEL_RAM_VADDR (PAGE_OFFSET + TEXT_OFFSET)
|
2006-12-12 06:29:16 +08:00
|
|
|
#if (KERNEL_RAM_VADDR & 0xffff) != 0x8000
|
|
|
|
#error KERNEL_RAM_VADDR must start at 0xXXXX8000
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2011-11-23 01:30:29 +08:00
|
|
|
#ifdef CONFIG_ARM_LPAE
|
|
|
|
/* LPAE requires an additional page for the PGD */
|
|
|
|
#define PG_DIR_SIZE 0x5000
|
|
|
|
#define PMD_ORDER 3
|
|
|
|
#else
|
2011-08-23 21:07:23 +08:00
|
|
|
#define PG_DIR_SIZE 0x4000
|
|
|
|
#define PMD_ORDER 2
|
2011-11-23 01:30:29 +08:00
|
|
|
#endif
|
2011-08-23 21:07:23 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
.globl swapper_pg_dir
|
2011-08-23 21:07:23 +08:00
|
|
|
.equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
|
2005-04-17 06:20:36 +08:00
|
|
|
|
ARM: P2V: eliminate head.S use of PHYS_OFFSET for !XIP_KERNEL
head.S makes use of PHYS_OFFSET. When it becomes a variable, the
assembler won't understand this. Compute PHYS_OFFSET by the following
method. This code is linked at its virtual address, but run at before
the MMU is enabled, so at his physical address.
1: .long .
.long PAGE_OFFSET
adr r0, 1b @ r0 = physical ','
ldmia r0, {r1, r2} @ r1 = virtual '.', r2 = PAGE_OFFSET
sub r1, r0, r1 @ r1 = physical-virtual
add r2, r2, r1 @ r2 = PAGE_OFFSET + physical-virtual
@ := PHYS_OFFSET.
Switch XIP users of PHYS_OFFSET to use PLAT_PHYS_OFFSET - we can't
use this method for XIP kernels as the code doesn't execute in RAM.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:04:00 +08:00
|
|
|
.macro pgtbl, rd, phys
|
2011-08-23 21:07:23 +08:00
|
|
|
add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
|
2005-04-17 06:20:36 +08:00
|
|
|
.endm
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel startup entry point.
|
|
|
|
* ---------------------------
|
|
|
|
*
|
|
|
|
* This is normally called from the decompressor code. The requirements
|
|
|
|
* are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,
|
2011-04-29 04:27:20 +08:00
|
|
|
* r1 = machine nr, r2 = atags or dtb pointer.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This code is mostly position independent, so if you link the kernel at
|
|
|
|
* 0xc0008000, you call this at __pa(0xc0008000).
|
|
|
|
*
|
|
|
|
* See linux/arch/arm/tools/mach-types for the complete list of machine
|
|
|
|
* numbers for r1.
|
|
|
|
*
|
|
|
|
* We're trying to keep crap to a minimum; DO NOT add any machine specific
|
|
|
|
* crap here - that's what the boot loader (or in extreme, well justified
|
|
|
|
* circumstances, zImage) is for.
|
|
|
|
*/
|
2011-07-13 22:53:30 +08:00
|
|
|
.arm
|
|
|
|
|
2009-10-03 04:32:46 +08:00
|
|
|
__HEAD
|
2005-04-17 06:20:36 +08:00
|
|
|
ENTRY(stext)
|
2011-07-13 22:53:30 +08:00
|
|
|
|
|
|
|
THUMB( adr r9, BSYM(1f) ) @ Kernel is always entered in ARM.
|
|
|
|
THUMB( bx r9 ) @ If this is a Thumb-2 kernel,
|
|
|
|
THUMB( .thumb ) @ switch to Thumb now.
|
|
|
|
THUMB(1: )
|
|
|
|
|
2012-02-10 00:47:17 +08:00
|
|
|
#ifdef CONFIG_ARM_VIRT_EXT
|
|
|
|
bl __hyp_stub_install
|
|
|
|
#endif
|
|
|
|
@ ensure svc mode and all interrupts masked
|
|
|
|
safe_svcmode_maskall r9
|
|
|
|
|
2006-02-25 05:04:56 +08:00
|
|
|
mrc p15, 0, r9, c0, c0 @ get processor id
|
2005-04-17 06:20:36 +08:00
|
|
|
bl __lookup_processor_type @ r5=procinfo r9=cpuid
|
|
|
|
movs r10, r5 @ invalid processor (r5=0)?
|
2010-11-30 02:43:28 +08:00
|
|
|
THUMB( it eq ) @ force fixup-able long branch encoding
|
2005-11-25 23:43:22 +08:00
|
|
|
beq __error_p @ yes, error 'p'
|
2010-11-22 20:06:28 +08:00
|
|
|
|
2012-01-09 19:24:47 +08:00
|
|
|
#ifdef CONFIG_ARM_LPAE
|
|
|
|
mrc p15, 0, r3, c0, c1, 4 @ read ID_MMFR0
|
|
|
|
and r3, r3, #0xf @ extract VMSA support
|
|
|
|
cmp r3, #5 @ long-descriptor translation table format?
|
|
|
|
THUMB( it lo ) @ force fixup-able long branch encoding
|
|
|
|
blo __error_p @ only classic page table format
|
|
|
|
#endif
|
|
|
|
|
ARM: P2V: eliminate head.S use of PHYS_OFFSET for !XIP_KERNEL
head.S makes use of PHYS_OFFSET. When it becomes a variable, the
assembler won't understand this. Compute PHYS_OFFSET by the following
method. This code is linked at its virtual address, but run at before
the MMU is enabled, so at his physical address.
1: .long .
.long PAGE_OFFSET
adr r0, 1b @ r0 = physical ','
ldmia r0, {r1, r2} @ r1 = virtual '.', r2 = PAGE_OFFSET
sub r1, r0, r1 @ r1 = physical-virtual
add r2, r2, r1 @ r2 = PAGE_OFFSET + physical-virtual
@ := PHYS_OFFSET.
Switch XIP users of PHYS_OFFSET to use PLAT_PHYS_OFFSET - we can't
use this method for XIP kernels as the code doesn't execute in RAM.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:04:00 +08:00
|
|
|
#ifndef CONFIG_XIP_KERNEL
|
|
|
|
adr r3, 2f
|
|
|
|
ldmia r3, {r4, r8}
|
|
|
|
sub r4, r3, r4 @ (PHYS_OFFSET - PAGE_OFFSET)
|
|
|
|
add r8, r8, r4 @ PHYS_OFFSET
|
|
|
|
#else
|
2011-07-06 10:52:51 +08:00
|
|
|
ldr r8, =PHYS_OFFSET @ always constant in this case
|
ARM: P2V: eliminate head.S use of PHYS_OFFSET for !XIP_KERNEL
head.S makes use of PHYS_OFFSET. When it becomes a variable, the
assembler won't understand this. Compute PHYS_OFFSET by the following
method. This code is linked at its virtual address, but run at before
the MMU is enabled, so at his physical address.
1: .long .
.long PAGE_OFFSET
adr r0, 1b @ r0 = physical ','
ldmia r0, {r1, r2} @ r1 = virtual '.', r2 = PAGE_OFFSET
sub r1, r0, r1 @ r1 = physical-virtual
add r2, r2, r1 @ r2 = PAGE_OFFSET + physical-virtual
@ := PHYS_OFFSET.
Switch XIP users of PHYS_OFFSET to use PLAT_PHYS_OFFSET - we can't
use this method for XIP kernels as the code doesn't execute in RAM.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:04:00 +08:00
|
|
|
#endif
|
|
|
|
|
2010-11-22 20:06:28 +08:00
|
|
|
/*
|
2011-04-29 04:27:20 +08:00
|
|
|
* r1 = machine no, r2 = atags or dtb,
|
ARM: P2V: eliminate head.S use of PHYS_OFFSET for !XIP_KERNEL
head.S makes use of PHYS_OFFSET. When it becomes a variable, the
assembler won't understand this. Compute PHYS_OFFSET by the following
method. This code is linked at its virtual address, but run at before
the MMU is enabled, so at his physical address.
1: .long .
.long PAGE_OFFSET
adr r0, 1b @ r0 = physical ','
ldmia r0, {r1, r2} @ r1 = virtual '.', r2 = PAGE_OFFSET
sub r1, r0, r1 @ r1 = physical-virtual
add r2, r2, r1 @ r2 = PAGE_OFFSET + physical-virtual
@ := PHYS_OFFSET.
Switch XIP users of PHYS_OFFSET to use PLAT_PHYS_OFFSET - we can't
use this method for XIP kernels as the code doesn't execute in RAM.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:04:00 +08:00
|
|
|
* r8 = phys_offset, r9 = cpuid, r10 = procinfo
|
2010-11-22 20:06:28 +08:00
|
|
|
*/
|
2007-06-01 05:02:22 +08:00
|
|
|
bl __vet_atags
|
2010-09-04 17:47:48 +08:00
|
|
|
#ifdef CONFIG_SMP_ON_UP
|
|
|
|
bl __fixup_smp
|
ARM: P2V: introduce phys_to_virt/virt_to_phys runtime patching
This idea came from Nicolas, Eric Miao produced an initial version,
which was then rewritten into this.
Patch the physical to virtual translations at runtime. As we modify
the code, this makes it incompatible with XIP kernels, but allows us
to achieve this with minimal loss of performance.
As many translations are of the form:
physical = virtual + (PHYS_OFFSET - PAGE_OFFSET)
virtual = physical - (PHYS_OFFSET - PAGE_OFFSET)
we generate an 'add' instruction for __virt_to_phys(), and a 'sub'
instruction for __phys_to_virt(). We calculate at run time (PHYS_OFFSET
- PAGE_OFFSET) by comparing the address prior to MMU initialization with
where it should be once the MMU has been initialized, and place this
constant into the above add/sub instructions.
Once we have (PHYS_OFFSET - PAGE_OFFSET), we can calculate the real
PHYS_OFFSET as PAGE_OFFSET is a build-time constant, and save this for
the C-mode PHYS_OFFSET variable definition to use.
At present, we are unable to support Realview with Sparsemem enabled
as this uses a complex mapping function, and MSM as this requires a
constant which will not fit in our math instruction.
Add a module version magic string for this feature to prevent
incompatible modules being loaded.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Tested-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:09:43 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT
|
|
|
|
bl __fixup_pv_table
|
2010-09-04 17:47:48 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
bl __create_page_tables
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following calls CPU specific code in a position independent
|
|
|
|
* manner. See arch/arm/mm/proc-*.S for details. r10 = base of
|
2011-01-13 01:50:42 +08:00
|
|
|
* xxx_proc_info structure selected by __lookup_processor_type
|
2005-04-17 06:20:36 +08:00
|
|
|
* above. On return, the CPU will be ready for the MMU to be
|
|
|
|
* turned on, and r0 will hold the CPU control register value.
|
|
|
|
*/
|
2010-10-04 23:22:34 +08:00
|
|
|
ldr r13, =__mmap_switched @ address to jump to after
|
2005-04-17 06:20:36 +08:00
|
|
|
@ mmu has been enabled
|
2010-10-05 00:56:13 +08:00
|
|
|
adr lr, BSYM(1f) @ return (PIC) address
|
2011-05-26 18:22:44 +08:00
|
|
|
mov r8, r4 @ set TTBR1 to swapper_pg_dir
|
2009-07-24 19:32:54 +08:00
|
|
|
ARM( add pc, r10, #PROCINFO_INITFUNC )
|
|
|
|
THUMB( add r12, r10, #PROCINFO_INITFUNC )
|
|
|
|
THUMB( mov pc, r12 )
|
2010-10-05 00:56:13 +08:00
|
|
|
1: b __enable_mmu
|
2008-08-28 18:22:32 +08:00
|
|
|
ENDPROC(stext)
|
2010-10-04 23:22:34 +08:00
|
|
|
.ltorg
|
ARM: P2V: eliminate head.S use of PHYS_OFFSET for !XIP_KERNEL
head.S makes use of PHYS_OFFSET. When it becomes a variable, the
assembler won't understand this. Compute PHYS_OFFSET by the following
method. This code is linked at its virtual address, but run at before
the MMU is enabled, so at his physical address.
1: .long .
.long PAGE_OFFSET
adr r0, 1b @ r0 = physical ','
ldmia r0, {r1, r2} @ r1 = virtual '.', r2 = PAGE_OFFSET
sub r1, r0, r1 @ r1 = physical-virtual
add r2, r2, r1 @ r2 = PAGE_OFFSET + physical-virtual
@ := PHYS_OFFSET.
Switch XIP users of PHYS_OFFSET to use PLAT_PHYS_OFFSET - we can't
use this method for XIP kernels as the code doesn't execute in RAM.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:04:00 +08:00
|
|
|
#ifndef CONFIG_XIP_KERNEL
|
|
|
|
2: .long .
|
|
|
|
.long PAGE_OFFSET
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup the initial page tables. We only setup the barest
|
|
|
|
* amount which are required to get the kernel running, which
|
|
|
|
* generally means mapping in the kernel code.
|
|
|
|
*
|
ARM: P2V: eliminate head.S use of PHYS_OFFSET for !XIP_KERNEL
head.S makes use of PHYS_OFFSET. When it becomes a variable, the
assembler won't understand this. Compute PHYS_OFFSET by the following
method. This code is linked at its virtual address, but run at before
the MMU is enabled, so at his physical address.
1: .long .
.long PAGE_OFFSET
adr r0, 1b @ r0 = physical ','
ldmia r0, {r1, r2} @ r1 = virtual '.', r2 = PAGE_OFFSET
sub r1, r0, r1 @ r1 = physical-virtual
add r2, r2, r1 @ r2 = PAGE_OFFSET + physical-virtual
@ := PHYS_OFFSET.
Switch XIP users of PHYS_OFFSET to use PLAT_PHYS_OFFSET - we can't
use this method for XIP kernels as the code doesn't execute in RAM.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:04:00 +08:00
|
|
|
* r8 = phys_offset, r9 = cpuid, r10 = procinfo
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Returns:
|
2010-10-05 00:51:54 +08:00
|
|
|
* r0, r3, r5-r7 corrupted
|
2012-07-22 03:55:04 +08:00
|
|
|
* r4 = page table (see ARCH_PGD_SHIFT in asm/memory.h)
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
__create_page_tables:
|
ARM: P2V: eliminate head.S use of PHYS_OFFSET for !XIP_KERNEL
head.S makes use of PHYS_OFFSET. When it becomes a variable, the
assembler won't understand this. Compute PHYS_OFFSET by the following
method. This code is linked at its virtual address, but run at before
the MMU is enabled, so at his physical address.
1: .long .
.long PAGE_OFFSET
adr r0, 1b @ r0 = physical ','
ldmia r0, {r1, r2} @ r1 = virtual '.', r2 = PAGE_OFFSET
sub r1, r0, r1 @ r1 = physical-virtual
add r2, r2, r1 @ r2 = PAGE_OFFSET + physical-virtual
@ := PHYS_OFFSET.
Switch XIP users of PHYS_OFFSET to use PLAT_PHYS_OFFSET - we can't
use this method for XIP kernels as the code doesn't execute in RAM.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:04:00 +08:00
|
|
|
pgtbl r4, r8 @ page table address
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2011-08-23 21:07:23 +08:00
|
|
|
* Clear the swapper page table
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
mov r0, r4
|
|
|
|
mov r3, #0
|
2011-08-23 21:07:23 +08:00
|
|
|
add r6, r0, #PG_DIR_SIZE
|
2005-04-17 06:20:36 +08:00
|
|
|
1: str r3, [r0], #4
|
|
|
|
str r3, [r0], #4
|
|
|
|
str r3, [r0], #4
|
|
|
|
str r3, [r0], #4
|
|
|
|
teq r0, r6
|
|
|
|
bne 1b
|
|
|
|
|
2011-11-23 01:30:29 +08:00
|
|
|
#ifdef CONFIG_ARM_LPAE
|
|
|
|
/*
|
|
|
|
* Build the PGD table (first level) to point to the PMD table. A PGD
|
|
|
|
* entry is 64-bit wide.
|
|
|
|
*/
|
|
|
|
mov r0, r4
|
|
|
|
add r3, r4, #0x1000 @ first PMD table address
|
|
|
|
orr r3, r3, #3 @ PGD block type
|
|
|
|
mov r6, #4 @ PTRS_PER_PGD
|
|
|
|
mov r7, #1 << (55 - 32) @ L_PGD_SWAPPER
|
2013-03-01 00:46:16 +08:00
|
|
|
1:
|
|
|
|
#ifdef CONFIG_CPU_ENDIAN_BE8
|
2011-11-23 01:30:29 +08:00
|
|
|
str r7, [r0], #4 @ set top PGD entry bits
|
2013-03-01 00:46:16 +08:00
|
|
|
str r3, [r0], #4 @ set bottom PGD entry bits
|
|
|
|
#else
|
|
|
|
str r3, [r0], #4 @ set bottom PGD entry bits
|
|
|
|
str r7, [r0], #4 @ set top PGD entry bits
|
|
|
|
#endif
|
2011-11-23 01:30:29 +08:00
|
|
|
add r3, r3, #0x1000 @ next PMD table
|
|
|
|
subs r6, r6, #1
|
|
|
|
bne 1b
|
|
|
|
|
|
|
|
add r4, r4, #0x1000 @ point to the PMD tables
|
2013-03-01 00:46:16 +08:00
|
|
|
#ifdef CONFIG_CPU_ENDIAN_BE8
|
|
|
|
add r4, r4, #4 @ we only write the bottom word
|
|
|
|
#endif
|
2011-11-23 01:30:29 +08:00
|
|
|
#endif
|
|
|
|
|
2006-06-30 01:24:21 +08:00
|
|
|
ldr r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2010-10-05 00:51:54 +08:00
|
|
|
* Create identity mapping to cater for __enable_mmu.
|
|
|
|
* This identity mapping will be removed by paging_init().
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2011-11-23 20:03:27 +08:00
|
|
|
adr r0, __turn_mmu_on_loc
|
2010-10-05 00:51:54 +08:00
|
|
|
ldmia r0, {r3, r5, r6}
|
|
|
|
sub r0, r0, r3 @ virt->phys offset
|
2011-11-23 20:03:27 +08:00
|
|
|
add r5, r5, r0 @ phys __turn_mmu_on
|
|
|
|
add r6, r6, r0 @ phys __turn_mmu_on_end
|
2011-08-23 21:07:23 +08:00
|
|
|
mov r5, r5, lsr #SECTION_SHIFT
|
|
|
|
mov r6, r6, lsr #SECTION_SHIFT
|
2010-10-05 00:51:54 +08:00
|
|
|
|
2011-08-23 21:07:23 +08:00
|
|
|
1: orr r3, r7, r5, lsl #SECTION_SHIFT @ flags + kernel base
|
|
|
|
str r3, [r4, r5, lsl #PMD_ORDER] @ identity mapping
|
|
|
|
cmp r5, r6
|
|
|
|
addlo r5, r5, #1 @ next section
|
|
|
|
blo 1b
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2012-07-04 11:58:12 +08:00
|
|
|
* Map our RAM from the start to the end of the kernel .bss section.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2012-07-04 11:58:12 +08:00
|
|
|
add r0, r4, #PAGE_OFFSET >> (SECTION_SHIFT - PMD_ORDER)
|
|
|
|
ldr r6, =(_end - 1)
|
|
|
|
orr r3, r8, r7
|
2011-08-23 21:07:23 +08:00
|
|
|
add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ORDER)
|
2012-07-04 11:58:12 +08:00
|
|
|
1: str r3, [r0], #1 << PMD_ORDER
|
2011-08-23 21:07:23 +08:00
|
|
|
add r3, r3, #1 << SECTION_SHIFT
|
2012-07-04 11:58:12 +08:00
|
|
|
cmp r0, r6
|
2007-02-22 23:18:09 +08:00
|
|
|
bls 1b
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-21 22:32:28 +08:00
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
|
|
|
/*
|
2012-07-04 11:58:12 +08:00
|
|
|
* Map the kernel image separately as it is not located in RAM.
|
2007-02-21 22:32:28 +08:00
|
|
|
*/
|
2012-07-04 11:58:12 +08:00
|
|
|
#define XIP_START XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR)
|
|
|
|
mov r3, pc
|
|
|
|
mov r3, r3, lsr #SECTION_SHIFT
|
|
|
|
orr r3, r7, r3, lsl #SECTION_SHIFT
|
|
|
|
add r0, r4, #(XIP_START & 0xff000000) >> (SECTION_SHIFT - PMD_ORDER)
|
|
|
|
str r3, [r0, #((XIP_START & 0x00f00000) >> SECTION_SHIFT) << PMD_ORDER]!
|
|
|
|
ldr r6, =(_edata_loc - 1)
|
|
|
|
add r0, r0, #1 << PMD_ORDER
|
2011-08-23 21:07:23 +08:00
|
|
|
add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ORDER)
|
2007-02-21 22:32:28 +08:00
|
|
|
1: cmp r0, r6
|
2012-07-04 11:58:12 +08:00
|
|
|
add r3, r3, #1 << SECTION_SHIFT
|
|
|
|
strls r3, [r0], #1 << PMD_ORDER
|
2007-02-21 22:32:28 +08:00
|
|
|
bls 1b
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2012-07-04 11:58:12 +08:00
|
|
|
* Then map boot params address in r2 if specified.
|
2013-01-16 01:51:32 +08:00
|
|
|
* We map 2 sections in case the ATAGs/DTB crosses a section boundary.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2011-08-23 21:07:23 +08:00
|
|
|
mov r0, r2, lsr #SECTION_SHIFT
|
|
|
|
movs r0, r0, lsl #SECTION_SHIFT
|
2012-07-04 11:58:12 +08:00
|
|
|
subne r3, r0, r8
|
|
|
|
addne r3, r3, #PAGE_OFFSET
|
|
|
|
addne r3, r4, r3, lsr #(SECTION_SHIFT - PMD_ORDER)
|
|
|
|
orrne r6, r7, r0
|
2013-01-16 01:51:32 +08:00
|
|
|
strne r6, [r3], #1 << PMD_ORDER
|
|
|
|
addne r6, r6, #1 << SECTION_SHIFT
|
2012-07-04 11:58:12 +08:00
|
|
|
strne r6, [r3]
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-04-03 19:24:45 +08:00
|
|
|
#if defined(CONFIG_ARM_LPAE) && defined(CONFIG_CPU_ENDIAN_BE8)
|
2013-03-01 00:46:16 +08:00
|
|
|
sub r4, r4, #4 @ Fixup page table pointer
|
|
|
|
@ for 64-bit descriptors
|
|
|
|
#endif
|
|
|
|
|
2005-07-01 18:56:55 +08:00
|
|
|
#ifdef CONFIG_DEBUG_LL
|
2012-02-23 04:58:03 +08:00
|
|
|
#if !defined(CONFIG_DEBUG_ICEDCC) && !defined(CONFIG_DEBUG_SEMIHOSTING)
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Map in IO space for serial debugging.
|
|
|
|
* This allows debug messages to be output
|
|
|
|
* via a serial console before paging_init.
|
|
|
|
*/
|
2011-09-01 10:55:46 +08:00
|
|
|
addruart r7, r3, r0
|
2010-07-07 11:19:48 +08:00
|
|
|
|
2011-08-23 21:07:23 +08:00
|
|
|
mov r3, r3, lsr #SECTION_SHIFT
|
|
|
|
mov r3, r3, lsl #PMD_ORDER
|
2010-07-07 11:19:48 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
add r0, r4, r3
|
2011-08-23 21:07:23 +08:00
|
|
|
mov r3, r7, lsr #SECTION_SHIFT
|
2010-07-07 11:19:48 +08:00
|
|
|
ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
|
2011-08-23 21:07:23 +08:00
|
|
|
orr r3, r7, r3, lsl #SECTION_SHIFT
|
2011-11-23 01:30:29 +08:00
|
|
|
#ifdef CONFIG_ARM_LPAE
|
|
|
|
mov r7, #1 << (54 - 32) @ XN
|
2013-03-01 00:46:16 +08:00
|
|
|
#ifdef CONFIG_CPU_ENDIAN_BE8
|
|
|
|
str r7, [r0], #4
|
|
|
|
str r3, [r0], #4
|
2011-11-23 01:30:29 +08:00
|
|
|
#else
|
2012-03-19 03:29:42 +08:00
|
|
|
str r3, [r0], #4
|
2011-11-23 01:30:29 +08:00
|
|
|
str r7, [r0], #4
|
|
|
|
#endif
|
2013-03-01 00:46:16 +08:00
|
|
|
#else
|
|
|
|
orr r3, r3, #PMD_SECT_XN
|
|
|
|
str r3, [r0], #4
|
|
|
|
#endif
|
2010-07-07 11:19:48 +08:00
|
|
|
|
2012-02-23 04:58:03 +08:00
|
|
|
#else /* CONFIG_DEBUG_ICEDCC || CONFIG_DEBUG_SEMIHOSTING */
|
|
|
|
/* we don't need any serial debugging mappings */
|
2010-07-07 11:19:48 +08:00
|
|
|
ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
|
2012-02-23 04:58:03 +08:00
|
|
|
#endif
|
2010-07-07 11:19:48 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#if defined(CONFIG_ARCH_NETWINDER) || defined(CONFIG_ARCH_CATS)
|
|
|
|
/*
|
2005-11-25 23:43:22 +08:00
|
|
|
* If we're using the NetWinder or CATS, we also need to map
|
|
|
|
* in the 16550-type serial port for the debug messages
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2011-08-23 21:07:23 +08:00
|
|
|
add r0, r4, #0xff000000 >> (SECTION_SHIFT - PMD_ORDER)
|
2005-07-01 18:56:55 +08:00
|
|
|
orr r3, r7, #0x7c000000
|
|
|
|
str r3, [r0]
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ARCH_RPC
|
|
|
|
/*
|
|
|
|
* Map in screen at 0x02000000 & SCREEN2_BASE
|
|
|
|
* Similar reasons here - for debug. This is
|
|
|
|
* only for Acorn RiscPC architectures.
|
|
|
|
*/
|
2011-08-23 21:07:23 +08:00
|
|
|
add r0, r4, #0x02000000 >> (SECTION_SHIFT - PMD_ORDER)
|
2005-07-01 18:56:55 +08:00
|
|
|
orr r3, r7, #0x02000000
|
2005-04-17 06:20:36 +08:00
|
|
|
str r3, [r0]
|
2011-08-23 21:07:23 +08:00
|
|
|
add r0, r4, #0xd8000000 >> (SECTION_SHIFT - PMD_ORDER)
|
2005-04-17 06:20:36 +08:00
|
|
|
str r3, [r0]
|
2005-07-01 18:56:55 +08:00
|
|
|
#endif
|
2011-11-23 01:30:29 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ARM_LPAE
|
|
|
|
sub r4, r4, #0x1000 @ point to the PGD table
|
2012-07-22 03:55:04 +08:00
|
|
|
mov r4, r4, lsr #ARCH_PGD_SHIFT
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
mov pc, lr
|
2008-08-28 18:22:32 +08:00
|
|
|
ENDPROC(__create_page_tables)
|
2005-04-17 06:20:36 +08:00
|
|
|
.ltorg
|
2010-11-30 02:43:24 +08:00
|
|
|
.align
|
2011-11-23 20:03:27 +08:00
|
|
|
__turn_mmu_on_loc:
|
2010-10-05 00:51:54 +08:00
|
|
|
.long .
|
2011-11-23 20:03:27 +08:00
|
|
|
.long __turn_mmu_on
|
|
|
|
.long __turn_mmu_on_end
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-05 00:56:13 +08:00
|
|
|
#if defined(CONFIG_SMP)
|
2013-07-31 18:37:17 +08:00
|
|
|
.text
|
2010-10-05 00:56:13 +08:00
|
|
|
ENTRY(secondary_startup)
|
|
|
|
/*
|
|
|
|
* Common entry point for secondary CPUs.
|
|
|
|
*
|
|
|
|
* Ensure that we're in SVC mode, and IRQs are disabled. Lookup
|
|
|
|
* the processor type - there is no need to check the machine type
|
|
|
|
* as it has already been validated by the primary processor.
|
|
|
|
*/
|
2012-02-10 00:47:17 +08:00
|
|
|
#ifdef CONFIG_ARM_VIRT_EXT
|
2013-01-05 01:44:14 +08:00
|
|
|
bl __hyp_stub_install_secondary
|
2012-02-10 00:47:17 +08:00
|
|
|
#endif
|
|
|
|
safe_svcmode_maskall r9
|
|
|
|
|
2010-10-05 00:56:13 +08:00
|
|
|
mrc p15, 0, r9, c0, c0 @ get processor id
|
|
|
|
bl __lookup_processor_type
|
|
|
|
movs r10, r5 @ invalid processor?
|
|
|
|
moveq r0, #'p' @ yes, error 'p'
|
2010-11-30 02:43:28 +08:00
|
|
|
THUMB( it eq ) @ force fixup-able long branch encoding
|
2010-10-05 00:56:13 +08:00
|
|
|
beq __error_p
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use the page tables supplied from __cpu_up.
|
|
|
|
*/
|
|
|
|
adr r4, __secondary_data
|
|
|
|
ldmia r4, {r5, r7, r12} @ address to jump to after
|
2011-05-26 18:22:44 +08:00
|
|
|
sub lr, r4, r5 @ mmu has been enabled
|
|
|
|
ldr r4, [r7, lr] @ get secondary_data.pgdir
|
|
|
|
add r7, r7, #4
|
|
|
|
ldr r8, [r7, lr] @ get secondary_data.swapper_pg_dir
|
2010-10-05 00:56:13 +08:00
|
|
|
adr lr, BSYM(__enable_mmu) @ return address
|
|
|
|
mov r13, r12 @ __secondary_switched address
|
|
|
|
ARM( add pc, r10, #PROCINFO_INITFUNC ) @ initialise processor
|
|
|
|
@ (return control reg)
|
|
|
|
THUMB( add r12, r10, #PROCINFO_INITFUNC )
|
|
|
|
THUMB( mov pc, r12 )
|
|
|
|
ENDPROC(secondary_startup)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* r6 = &secondary_data
|
|
|
|
*/
|
|
|
|
ENTRY(__secondary_switched)
|
|
|
|
ldr sp, [r7, #4] @ get secondary_data.stack
|
|
|
|
mov fp, #0
|
|
|
|
b secondary_start_kernel
|
|
|
|
ENDPROC(__secondary_switched)
|
|
|
|
|
2010-11-30 02:43:24 +08:00
|
|
|
.align
|
|
|
|
|
2010-10-05 00:56:13 +08:00
|
|
|
.type __secondary_data, %object
|
|
|
|
__secondary_data:
|
|
|
|
.long .
|
|
|
|
.long secondary_data
|
|
|
|
.long __secondary_switched
|
|
|
|
#endif /* defined(CONFIG_SMP) */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup common bits before finally enabling the MMU. Essentially
|
|
|
|
* this is just loading the page table pointer and domain access
|
|
|
|
* registers.
|
2010-10-05 01:02:59 +08:00
|
|
|
*
|
|
|
|
* r0 = cp#15 control register
|
|
|
|
* r1 = machine ID
|
2011-04-29 04:27:20 +08:00
|
|
|
* r2 = atags or dtb pointer
|
2012-07-22 03:55:04 +08:00
|
|
|
* r4 = page table (see ARCH_PGD_SHIFT in asm/memory.h)
|
2010-10-05 01:02:59 +08:00
|
|
|
* r9 = processor ID
|
|
|
|
* r13 = *virtual* address to jump to upon completion
|
2010-10-05 00:56:13 +08:00
|
|
|
*/
|
|
|
|
__enable_mmu:
|
2011-11-08 01:05:53 +08:00
|
|
|
#if defined(CONFIG_ALIGNMENT_TRAP) && __LINUX_ARM_ARCH__ < 6
|
2010-10-05 00:56:13 +08:00
|
|
|
orr r0, r0, #CR_A
|
|
|
|
#else
|
|
|
|
bic r0, r0, #CR_A
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CPU_DCACHE_DISABLE
|
|
|
|
bic r0, r0, #CR_C
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CPU_BPREDICT_DISABLE
|
|
|
|
bic r0, r0, #CR_Z
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CPU_ICACHE_DISABLE
|
|
|
|
bic r0, r0, #CR_I
|
|
|
|
#endif
|
2012-07-22 03:55:04 +08:00
|
|
|
#ifndef CONFIG_ARM_LPAE
|
2010-10-05 00:56:13 +08:00
|
|
|
mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
|
|
|
|
domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
|
|
|
|
domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
|
|
|
|
domain_val(DOMAIN_IO, DOMAIN_CLIENT))
|
|
|
|
mcr p15, 0, r5, c3, c0, 0 @ load domain access register
|
|
|
|
mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
|
2011-11-23 01:30:29 +08:00
|
|
|
#endif
|
2010-10-05 00:56:13 +08:00
|
|
|
b __turn_mmu_on
|
|
|
|
ENDPROC(__enable_mmu)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable the MMU. This completely changes the structure of the visible
|
|
|
|
* memory space. You will not be able to trace execution through this.
|
|
|
|
* If you have an enquiry about this, *please* check the linux-arm-kernel
|
|
|
|
* mailing list archives BEFORE sending another post to the list.
|
|
|
|
*
|
|
|
|
* r0 = cp#15 control register
|
2010-10-05 01:02:59 +08:00
|
|
|
* r1 = machine ID
|
2011-04-29 04:27:20 +08:00
|
|
|
* r2 = atags or dtb pointer
|
2010-10-05 01:02:59 +08:00
|
|
|
* r9 = processor ID
|
2010-10-05 00:56:13 +08:00
|
|
|
* r13 = *virtual* address to jump to upon completion
|
|
|
|
*
|
|
|
|
* other registers depend on the function called upon completion
|
|
|
|
*/
|
|
|
|
.align 5
|
2011-11-23 20:26:25 +08:00
|
|
|
.pushsection .idmap.text, "ax"
|
|
|
|
ENTRY(__turn_mmu_on)
|
2010-10-05 00:56:13 +08:00
|
|
|
mov r0, r0
|
2011-11-23 01:30:28 +08:00
|
|
|
instr_sync
|
2010-10-05 00:56:13 +08:00
|
|
|
mcr p15, 0, r0, c1, c0, 0 @ write control reg
|
|
|
|
mrc p15, 0, r3, c0, c0, 0 @ read id reg
|
2011-11-23 01:30:28 +08:00
|
|
|
instr_sync
|
2010-10-05 00:56:13 +08:00
|
|
|
mov r3, r3
|
|
|
|
mov r3, r13
|
|
|
|
mov pc, r3
|
2011-11-23 20:03:27 +08:00
|
|
|
__turn_mmu_on_end:
|
2010-10-05 00:56:13 +08:00
|
|
|
ENDPROC(__turn_mmu_on)
|
2011-11-23 20:26:25 +08:00
|
|
|
.popsection
|
2010-10-05 00:56:13 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-09-04 17:47:48 +08:00
|
|
|
#ifdef CONFIG_SMP_ON_UP
|
2011-02-10 23:25:18 +08:00
|
|
|
__INIT
|
2010-09-04 17:47:48 +08:00
|
|
|
__fixup_smp:
|
2011-01-31 00:40:20 +08:00
|
|
|
and r3, r9, #0x000f0000 @ architecture version
|
|
|
|
teq r3, #0x000f0000 @ CPU ID supported?
|
2010-09-04 17:47:48 +08:00
|
|
|
bne __fixup_smp_on_up @ no, assume UP
|
|
|
|
|
2011-01-31 00:40:20 +08:00
|
|
|
bic r3, r9, #0x00ff0000
|
|
|
|
bic r3, r3, #0x0000000f @ mask 0xff00fff0
|
|
|
|
mov r4, #0x41000000
|
2010-11-22 20:06:28 +08:00
|
|
|
orr r4, r4, #0x0000b000
|
2011-01-31 00:40:20 +08:00
|
|
|
orr r4, r4, #0x00000020 @ val 0x4100b020
|
|
|
|
teq r3, r4 @ ARM 11MPCore?
|
2010-09-04 17:47:48 +08:00
|
|
|
moveq pc, lr @ yes, assume SMP
|
|
|
|
|
|
|
|
mrc p15, 0, r0, c0, c0, 5 @ read MPIDR
|
2011-01-31 00:40:20 +08:00
|
|
|
and r0, r0, #0xc0000000 @ multiprocessing extensions and
|
|
|
|
teq r0, #0x80000000 @ not part of a uniprocessor system?
|
|
|
|
moveq pc, lr @ yes, assume SMP
|
2010-09-04 17:47:48 +08:00
|
|
|
|
|
|
|
__fixup_smp_on_up:
|
|
|
|
adr r0, 1f
|
2010-11-22 20:06:28 +08:00
|
|
|
ldmia r0, {r3 - r5}
|
2010-09-04 17:47:48 +08:00
|
|
|
sub r3, r0, r3
|
2010-11-22 20:06:28 +08:00
|
|
|
add r4, r4, r3
|
|
|
|
add r5, r5, r3
|
2011-02-10 23:25:18 +08:00
|
|
|
b __do_fixup_smp_on_up
|
2010-09-04 17:47:48 +08:00
|
|
|
ENDPROC(__fixup_smp)
|
|
|
|
|
2010-11-30 02:43:24 +08:00
|
|
|
.align
|
2010-09-04 17:47:48 +08:00
|
|
|
1: .word .
|
|
|
|
.word __smpalt_begin
|
|
|
|
.word __smpalt_end
|
|
|
|
|
|
|
|
.pushsection .data
|
|
|
|
.globl smp_on_up
|
|
|
|
smp_on_up:
|
|
|
|
ALT_SMP(.long 1)
|
|
|
|
ALT_UP(.long 0)
|
|
|
|
.popsection
|
2011-02-10 23:25:18 +08:00
|
|
|
#endif
|
2010-09-04 17:47:48 +08:00
|
|
|
|
2011-02-10 23:25:18 +08:00
|
|
|
.text
|
|
|
|
__do_fixup_smp_on_up:
|
|
|
|
cmp r4, r5
|
|
|
|
movhs pc, lr
|
|
|
|
ldmia r4!, {r0, r6}
|
|
|
|
ARM( str r6, [r0, r3] )
|
|
|
|
THUMB( add r0, r0, r3 )
|
|
|
|
#ifdef __ARMEB__
|
|
|
|
THUMB( mov r6, r6, ror #16 ) @ Convert word order for big-endian.
|
2010-09-04 17:47:48 +08:00
|
|
|
#endif
|
2011-02-10 23:25:18 +08:00
|
|
|
THUMB( strh r6, [r0], #2 ) @ For Thumb-2, store as two halfwords
|
|
|
|
THUMB( mov r6, r6, lsr #16 ) @ to be robust against misaligned r3.
|
|
|
|
THUMB( strh r6, [r0] )
|
|
|
|
b __do_fixup_smp_on_up
|
|
|
|
ENDPROC(__do_fixup_smp_on_up)
|
|
|
|
|
|
|
|
ENTRY(fixup_smp)
|
|
|
|
stmfd sp!, {r4 - r6, lr}
|
|
|
|
mov r4, r0
|
|
|
|
add r5, r0, r1
|
|
|
|
mov r3, #0
|
|
|
|
bl __do_fixup_smp_on_up
|
|
|
|
ldmfd sp!, {r4 - r6, pc}
|
|
|
|
ENDPROC(fixup_smp)
|
2010-09-04 17:47:48 +08:00
|
|
|
|
ARM: P2V: introduce phys_to_virt/virt_to_phys runtime patching
This idea came from Nicolas, Eric Miao produced an initial version,
which was then rewritten into this.
Patch the physical to virtual translations at runtime. As we modify
the code, this makes it incompatible with XIP kernels, but allows us
to achieve this with minimal loss of performance.
As many translations are of the form:
physical = virtual + (PHYS_OFFSET - PAGE_OFFSET)
virtual = physical - (PHYS_OFFSET - PAGE_OFFSET)
we generate an 'add' instruction for __virt_to_phys(), and a 'sub'
instruction for __phys_to_virt(). We calculate at run time (PHYS_OFFSET
- PAGE_OFFSET) by comparing the address prior to MMU initialization with
where it should be once the MMU has been initialized, and place this
constant into the above add/sub instructions.
Once we have (PHYS_OFFSET - PAGE_OFFSET), we can calculate the real
PHYS_OFFSET as PAGE_OFFSET is a build-time constant, and save this for
the C-mode PHYS_OFFSET variable definition to use.
At present, we are unable to support Realview with Sparsemem enabled
as this uses a complex mapping function, and MSM as this requires a
constant which will not fit in our math instruction.
Add a module version magic string for this feature to prevent
incompatible modules being loaded.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Tested-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:09:43 +08:00
|
|
|
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT
|
|
|
|
|
|
|
|
/* __fixup_pv_table - patch the stub instructions with the delta between
|
|
|
|
* PHYS_OFFSET and PAGE_OFFSET, which is assumed to be 16MiB aligned and
|
|
|
|
* can be expressed by an immediate shifter operand. The stub instruction
|
|
|
|
* has a form of '(add|sub) rd, rn, #imm'.
|
|
|
|
*/
|
|
|
|
__HEAD
|
|
|
|
__fixup_pv_table:
|
|
|
|
adr r0, 1f
|
|
|
|
ldmia r0, {r3-r5, r7}
|
|
|
|
sub r3, r0, r3 @ PHYS_OFFSET - PAGE_OFFSET
|
|
|
|
add r4, r4, r3 @ adjust table start address
|
|
|
|
add r5, r5, r3 @ adjust table end address
|
2011-02-21 13:53:35 +08:00
|
|
|
add r7, r7, r3 @ adjust __pv_phys_offset address
|
|
|
|
str r8, [r7] @ save computed PHYS_OFFSET to __pv_phys_offset
|
ARM: P2V: introduce phys_to_virt/virt_to_phys runtime patching
This idea came from Nicolas, Eric Miao produced an initial version,
which was then rewritten into this.
Patch the physical to virtual translations at runtime. As we modify
the code, this makes it incompatible with XIP kernels, but allows us
to achieve this with minimal loss of performance.
As many translations are of the form:
physical = virtual + (PHYS_OFFSET - PAGE_OFFSET)
virtual = physical - (PHYS_OFFSET - PAGE_OFFSET)
we generate an 'add' instruction for __virt_to_phys(), and a 'sub'
instruction for __phys_to_virt(). We calculate at run time (PHYS_OFFSET
- PAGE_OFFSET) by comparing the address prior to MMU initialization with
where it should be once the MMU has been initialized, and place this
constant into the above add/sub instructions.
Once we have (PHYS_OFFSET - PAGE_OFFSET), we can calculate the real
PHYS_OFFSET as PAGE_OFFSET is a build-time constant, and save this for
the C-mode PHYS_OFFSET variable definition to use.
At present, we are unable to support Realview with Sparsemem enabled
as this uses a complex mapping function, and MSM as this requires a
constant which will not fit in our math instruction.
Add a module version magic string for this feature to prevent
incompatible modules being loaded.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Tested-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:09:43 +08:00
|
|
|
mov r6, r3, lsr #24 @ constant for add/sub instructions
|
|
|
|
teq r3, r6, lsl #24 @ must be 16MiB aligned
|
2011-02-21 13:53:35 +08:00
|
|
|
THUMB( it ne @ cross section branch )
|
ARM: P2V: introduce phys_to_virt/virt_to_phys runtime patching
This idea came from Nicolas, Eric Miao produced an initial version,
which was then rewritten into this.
Patch the physical to virtual translations at runtime. As we modify
the code, this makes it incompatible with XIP kernels, but allows us
to achieve this with minimal loss of performance.
As many translations are of the form:
physical = virtual + (PHYS_OFFSET - PAGE_OFFSET)
virtual = physical - (PHYS_OFFSET - PAGE_OFFSET)
we generate an 'add' instruction for __virt_to_phys(), and a 'sub'
instruction for __phys_to_virt(). We calculate at run time (PHYS_OFFSET
- PAGE_OFFSET) by comparing the address prior to MMU initialization with
where it should be once the MMU has been initialized, and place this
constant into the above add/sub instructions.
Once we have (PHYS_OFFSET - PAGE_OFFSET), we can calculate the real
PHYS_OFFSET as PAGE_OFFSET is a build-time constant, and save this for
the C-mode PHYS_OFFSET variable definition to use.
At present, we are unable to support Realview with Sparsemem enabled
as this uses a complex mapping function, and MSM as this requires a
constant which will not fit in our math instruction.
Add a module version magic string for this feature to prevent
incompatible modules being loaded.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Tested-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:09:43 +08:00
|
|
|
bne __error
|
|
|
|
str r6, [r7, #4] @ save to __pv_offset
|
|
|
|
b __fixup_a_pv_table
|
|
|
|
ENDPROC(__fixup_pv_table)
|
|
|
|
|
|
|
|
.align
|
|
|
|
1: .long .
|
|
|
|
.long __pv_table_begin
|
|
|
|
.long __pv_table_end
|
|
|
|
2: .long __pv_phys_offset
|
|
|
|
|
|
|
|
.text
|
|
|
|
__fixup_a_pv_table:
|
2011-02-21 13:53:35 +08:00
|
|
|
#ifdef CONFIG_THUMB2_KERNEL
|
2011-08-12 07:14:29 +08:00
|
|
|
lsls r6, #24
|
|
|
|
beq 2f
|
2011-02-21 13:53:35 +08:00
|
|
|
clz r7, r6
|
|
|
|
lsr r6, #24
|
|
|
|
lsl r6, r7
|
|
|
|
bic r6, #0x0080
|
|
|
|
lsrs r7, #1
|
|
|
|
orrcs r6, #0x0080
|
|
|
|
orr r6, r6, r7, lsl #12
|
|
|
|
orr r6, #0x4000
|
2011-08-12 07:14:29 +08:00
|
|
|
b 2f
|
|
|
|
1: add r7, r3
|
|
|
|
ldrh ip, [r7, #2]
|
2011-02-21 13:53:35 +08:00
|
|
|
and ip, 0x8f00
|
2011-08-12 07:14:29 +08:00
|
|
|
orr ip, r6 @ mask in offset bits 31-24
|
2011-02-21 13:53:35 +08:00
|
|
|
strh ip, [r7, #2]
|
2011-08-12 07:14:29 +08:00
|
|
|
2: cmp r4, r5
|
2011-02-21 13:53:35 +08:00
|
|
|
ldrcc r7, [r4], #4 @ use branch for delay slot
|
2011-08-12 07:14:29 +08:00
|
|
|
bcc 1b
|
2011-02-21 13:53:35 +08:00
|
|
|
bx lr
|
|
|
|
#else
|
2011-08-12 07:14:29 +08:00
|
|
|
b 2f
|
|
|
|
1: ldr ip, [r7, r3]
|
ARM: P2V: introduce phys_to_virt/virt_to_phys runtime patching
This idea came from Nicolas, Eric Miao produced an initial version,
which was then rewritten into this.
Patch the physical to virtual translations at runtime. As we modify
the code, this makes it incompatible with XIP kernels, but allows us
to achieve this with minimal loss of performance.
As many translations are of the form:
physical = virtual + (PHYS_OFFSET - PAGE_OFFSET)
virtual = physical - (PHYS_OFFSET - PAGE_OFFSET)
we generate an 'add' instruction for __virt_to_phys(), and a 'sub'
instruction for __phys_to_virt(). We calculate at run time (PHYS_OFFSET
- PAGE_OFFSET) by comparing the address prior to MMU initialization with
where it should be once the MMU has been initialized, and place this
constant into the above add/sub instructions.
Once we have (PHYS_OFFSET - PAGE_OFFSET), we can calculate the real
PHYS_OFFSET as PAGE_OFFSET is a build-time constant, and save this for
the C-mode PHYS_OFFSET variable definition to use.
At present, we are unable to support Realview with Sparsemem enabled
as this uses a complex mapping function, and MSM as this requires a
constant which will not fit in our math instruction.
Add a module version magic string for this feature to prevent
incompatible modules being loaded.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Tested-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:09:43 +08:00
|
|
|
bic ip, ip, #0x000000ff
|
2011-08-12 07:14:29 +08:00
|
|
|
orr ip, ip, r6 @ mask in offset bits 31-24
|
ARM: P2V: introduce phys_to_virt/virt_to_phys runtime patching
This idea came from Nicolas, Eric Miao produced an initial version,
which was then rewritten into this.
Patch the physical to virtual translations at runtime. As we modify
the code, this makes it incompatible with XIP kernels, but allows us
to achieve this with minimal loss of performance.
As many translations are of the form:
physical = virtual + (PHYS_OFFSET - PAGE_OFFSET)
virtual = physical - (PHYS_OFFSET - PAGE_OFFSET)
we generate an 'add' instruction for __virt_to_phys(), and a 'sub'
instruction for __phys_to_virt(). We calculate at run time (PHYS_OFFSET
- PAGE_OFFSET) by comparing the address prior to MMU initialization with
where it should be once the MMU has been initialized, and place this
constant into the above add/sub instructions.
Once we have (PHYS_OFFSET - PAGE_OFFSET), we can calculate the real
PHYS_OFFSET as PAGE_OFFSET is a build-time constant, and save this for
the C-mode PHYS_OFFSET variable definition to use.
At present, we are unable to support Realview with Sparsemem enabled
as this uses a complex mapping function, and MSM as this requires a
constant which will not fit in our math instruction.
Add a module version magic string for this feature to prevent
incompatible modules being loaded.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Tested-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:09:43 +08:00
|
|
|
str ip, [r7, r3]
|
2011-08-12 07:14:29 +08:00
|
|
|
2: cmp r4, r5
|
ARM: P2V: introduce phys_to_virt/virt_to_phys runtime patching
This idea came from Nicolas, Eric Miao produced an initial version,
which was then rewritten into this.
Patch the physical to virtual translations at runtime. As we modify
the code, this makes it incompatible with XIP kernels, but allows us
to achieve this with minimal loss of performance.
As many translations are of the form:
physical = virtual + (PHYS_OFFSET - PAGE_OFFSET)
virtual = physical - (PHYS_OFFSET - PAGE_OFFSET)
we generate an 'add' instruction for __virt_to_phys(), and a 'sub'
instruction for __phys_to_virt(). We calculate at run time (PHYS_OFFSET
- PAGE_OFFSET) by comparing the address prior to MMU initialization with
where it should be once the MMU has been initialized, and place this
constant into the above add/sub instructions.
Once we have (PHYS_OFFSET - PAGE_OFFSET), we can calculate the real
PHYS_OFFSET as PAGE_OFFSET is a build-time constant, and save this for
the C-mode PHYS_OFFSET variable definition to use.
At present, we are unable to support Realview with Sparsemem enabled
as this uses a complex mapping function, and MSM as this requires a
constant which will not fit in our math instruction.
Add a module version magic string for this feature to prevent
incompatible modules being loaded.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Tested-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:09:43 +08:00
|
|
|
ldrcc r7, [r4], #4 @ use branch for delay slot
|
2011-08-12 07:14:29 +08:00
|
|
|
bcc 1b
|
ARM: P2V: introduce phys_to_virt/virt_to_phys runtime patching
This idea came from Nicolas, Eric Miao produced an initial version,
which was then rewritten into this.
Patch the physical to virtual translations at runtime. As we modify
the code, this makes it incompatible with XIP kernels, but allows us
to achieve this with minimal loss of performance.
As many translations are of the form:
physical = virtual + (PHYS_OFFSET - PAGE_OFFSET)
virtual = physical - (PHYS_OFFSET - PAGE_OFFSET)
we generate an 'add' instruction for __virt_to_phys(), and a 'sub'
instruction for __phys_to_virt(). We calculate at run time (PHYS_OFFSET
- PAGE_OFFSET) by comparing the address prior to MMU initialization with
where it should be once the MMU has been initialized, and place this
constant into the above add/sub instructions.
Once we have (PHYS_OFFSET - PAGE_OFFSET), we can calculate the real
PHYS_OFFSET as PAGE_OFFSET is a build-time constant, and save this for
the C-mode PHYS_OFFSET variable definition to use.
At present, we are unable to support Realview with Sparsemem enabled
as this uses a complex mapping function, and MSM as this requires a
constant which will not fit in our math instruction.
Add a module version magic string for this feature to prevent
incompatible modules being loaded.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Tested-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:09:43 +08:00
|
|
|
mov pc, lr
|
2011-02-21 13:53:35 +08:00
|
|
|
#endif
|
ARM: P2V: introduce phys_to_virt/virt_to_phys runtime patching
This idea came from Nicolas, Eric Miao produced an initial version,
which was then rewritten into this.
Patch the physical to virtual translations at runtime. As we modify
the code, this makes it incompatible with XIP kernels, but allows us
to achieve this with minimal loss of performance.
As many translations are of the form:
physical = virtual + (PHYS_OFFSET - PAGE_OFFSET)
virtual = physical - (PHYS_OFFSET - PAGE_OFFSET)
we generate an 'add' instruction for __virt_to_phys(), and a 'sub'
instruction for __phys_to_virt(). We calculate at run time (PHYS_OFFSET
- PAGE_OFFSET) by comparing the address prior to MMU initialization with
where it should be once the MMU has been initialized, and place this
constant into the above add/sub instructions.
Once we have (PHYS_OFFSET - PAGE_OFFSET), we can calculate the real
PHYS_OFFSET as PAGE_OFFSET is a build-time constant, and save this for
the C-mode PHYS_OFFSET variable definition to use.
At present, we are unable to support Realview with Sparsemem enabled
as this uses a complex mapping function, and MSM as this requires a
constant which will not fit in our math instruction.
Add a module version magic string for this feature to prevent
incompatible modules being loaded.
Tested-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Tested-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-05 03:09:43 +08:00
|
|
|
ENDPROC(__fixup_a_pv_table)
|
|
|
|
|
|
|
|
ENTRY(fixup_pv_table)
|
|
|
|
stmfd sp!, {r4 - r7, lr}
|
|
|
|
ldr r2, 2f @ get address of __pv_phys_offset
|
|
|
|
mov r3, #0 @ no offset
|
|
|
|
mov r4, r0 @ r0 = table start
|
|
|
|
add r5, r0, r1 @ r1 = table size
|
|
|
|
ldr r6, [r2, #4] @ get __pv_offset
|
|
|
|
bl __fixup_a_pv_table
|
|
|
|
ldmfd sp!, {r4 - r7, pc}
|
|
|
|
ENDPROC(fixup_pv_table)
|
|
|
|
|
|
|
|
.align
|
|
|
|
2: .long __pv_phys_offset
|
|
|
|
|
|
|
|
.data
|
|
|
|
.globl __pv_phys_offset
|
|
|
|
.type __pv_phys_offset, %object
|
|
|
|
__pv_phys_offset:
|
|
|
|
.long 0
|
|
|
|
.size __pv_phys_offset, . - __pv_phys_offset
|
|
|
|
__pv_offset:
|
|
|
|
.long 0
|
|
|
|
#endif
|
|
|
|
|
2006-03-27 21:58:25 +08:00
|
|
|
#include "head-common.S"
|