2019-06-04 16:11:33 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
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
|
|
|
*
|
|
|
|
* Kernel startup code for all 32-bit CPUs
|
|
|
|
*/
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <linux/init.h>
|
2020-06-09 12:32:42 +08:00
|
|
|
#include <linux/pgtable.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#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>
|
ARM: mm: Make virt_to_pfn() a static inline
Making virt_to_pfn() a static inline taking a strongly typed
(const void *) makes the contract of a passing a pointer of that
type to the function explicit and exposes any misuse of the
macro virt_to_pfn() acting polymorphic and accepting many types
such as (void *), (unitptr_t) or (unsigned long) as arguments
without warnings.
Doing this is a bit intrusive: virt_to_pfn() requires
PHYS_PFN_OFFSET and PAGE_SHIFT to be defined, and this is defined in
<asm/page.h>, so this must be included *before* <asm/memory.h>.
The use of macros were obscuring the unclear inclusion order here,
as the macros would eventually be resolved, but a static inline
like this cannot be compiled with unresolved macros.
The naive solution to include <asm/page.h> at the top of
<asm/memory.h> does not work, because <asm/memory.h> sometimes
includes <asm/page.h> at the end of itself, which would create a
confusing inclusion loop. So instead, take the approach to always
unconditionally include <asm/page.h> at the end of <asm/memory.h>
arch/arm uses <asm/memory.h> explicitly in a lot of places,
however it turns out that if we just unconditionally include
<asm/memory.h> into <asm/page.h> and switch all inclusions of
<asm/memory.h> to <asm/page.h> instead, we enforce the right
order and <asm/memory.h> will always have access to the
definitions.
Put an inclusion guard in place making it impossible to include
<asm/memory.h> explicitly.
Link: https://lore.kernel.org/linux-mm/20220701160004.2ffff4e5ab59a55499f4c736@linux-foundation.org/
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2022-06-02 16:18:32 +08:00
|
|
|
#include <asm/page.h>
|
2005-05-05 20:11:00 +08:00
|
|
|
#include <asm/thread_info.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
|
|
|
*/
|
2021-06-03 16:50:16 +08:00
|
|
|
#define KERNEL_RAM_VADDR (KERNEL_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
|
2022-07-05 23:47:08 +08:00
|
|
|
#define PMD_ENTRY_ORDER 3 /* PMD entry size is 2^PMD_ENTRY_ORDER */
|
2011-11-23 01:30:29 +08:00
|
|
|
#else
|
2011-08-23 21:07:23 +08:00
|
|
|
#define PG_DIR_SIZE 0x4000
|
2022-07-05 23:47:08 +08:00
|
|
|
#define PMD_ENTRY_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
|
|
|
|
2021-06-03 16:51:21 +08:00
|
|
|
/*
|
|
|
|
* This needs to be assigned at runtime when the linker symbols are
|
2021-08-09 19:57:19 +08:00
|
|
|
* resolved. These are unsigned 64bit really, but in this assembly code
|
|
|
|
* We store them as 32bit.
|
2021-06-03 16:51:21 +08:00
|
|
|
*/
|
|
|
|
.pushsection .data
|
|
|
|
.align 2
|
|
|
|
.globl kernel_sec_start
|
|
|
|
.globl kernel_sec_end
|
|
|
|
kernel_sec_start:
|
|
|
|
.long 0
|
2021-08-09 19:57:19 +08:00
|
|
|
.long 0
|
2021-06-03 16:51:21 +08:00
|
|
|
kernel_sec_end:
|
2021-08-09 19:57:19 +08:00
|
|
|
.long 0
|
2021-06-03 16:51:21 +08:00
|
|
|
.long 0
|
|
|
|
.popsection
|
|
|
|
|
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
|
2014-01-21 23:25:34 +08:00
|
|
|
add \rd, \phys, #TEXT_OFFSET
|
|
|
|
sub \rd, \rd, #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)
|
2013-02-01 17:40:42 +08:00
|
|
|
ARM_BE8(setend be ) @ ensure we are in BE8 mode
|
2011-07-13 22:53:30 +08:00
|
|
|
|
2015-04-21 21:17:25 +08:00
|
|
|
THUMB( badr r9, 1f ) @ Kernel is always entered in ARM.
|
2011-07-13 22:53:30 +08:00
|
|
|
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
|
ARM: 7980/1: kernel: improve error message when LPAE config doesn't match CPU
Currently, when the kernel is configured with LPAE support, but the
CPU doesn't support it, the error message is fairly cryptic:
Error: unrecognized/unsupported processor variant (0x561f5811).
This messages is normally shown when there is an issue when comparing
the processor ID (CP15 0, c0, c0) with the values/masks described in
proc-v7.S. However, the same message is displayed when LPAE support is
enabled in the kernel configuration, but not available in the CPU,
after looking at ID_MMFR0 (CP15 0, c0, c1, 4). Having the same error
message is highly misleading.
This commit improves this by showing a different error message when
this situation occurs:
Error: Kernel with LPAE support, but CPU does not support LPAE.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2014-02-19 00:02:54 +08:00
|
|
|
blo __error_lpae @ only classic page table format
|
2012-01-09 19:24:47 +08:00
|
|
|
#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
|
2020-09-14 16:25:46 +08:00
|
|
|
adr_l r8, _text @ __pa(_text)
|
|
|
|
sub r8, r8, #TEXT_OFFSET @ PHYS_OFFSET
|
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
|
|
|
#else
|
2013-12-11 03:21:08 +08:00
|
|
|
ldr r8, =PLAT_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
|
2015-04-05 03:09:46 +08:00
|
|
|
* above.
|
|
|
|
*
|
|
|
|
* The processor init function will be called with:
|
|
|
|
* r1 - machine type
|
|
|
|
* r2 - boot data (atags/dt) pointer
|
|
|
|
* r4 - translation table base (low word)
|
|
|
|
* r5 - translation table base (high word, if LPAE)
|
|
|
|
* r8 - translation table base 1 (pfn if LPAE)
|
|
|
|
* r9 - cpuid
|
|
|
|
* r13 - virtual address for __enable_mmu -> __turn_mmu_on
|
|
|
|
*
|
|
|
|
* On return, the CPU will be ready for the MMU to be turned on,
|
|
|
|
* r0 will hold the CPU control register value, r1, r2, r4, and
|
|
|
|
* r9 will be preserved. r5 will also be preserved if LPAE.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
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
|
2015-04-21 21:17:25 +08:00
|
|
|
badr lr, 1f @ return (PIC) address
|
2015-04-05 03:09:46 +08:00
|
|
|
#ifdef CONFIG_ARM_LPAE
|
|
|
|
mov r5, #0 @ high TTBR0
|
|
|
|
mov r8, r4, lsr #12 @ TTBR1 is swapper_pg_dir pfn
|
|
|
|
#else
|
2011-05-26 18:22:44 +08:00
|
|
|
mov r8, r4 @ set TTBR1 to swapper_pg_dir
|
2015-04-05 03:09:46 +08:00
|
|
|
#endif
|
2015-03-18 14:29:32 +08:00
|
|
|
ldr r12, [r10, #PROCINFO_INITFUNC]
|
|
|
|
add r12, r12, r10
|
|
|
|
ret 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
|
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
|
2015-04-05 03:09:46 +08:00
|
|
|
* r4 = physical page table address
|
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
|
|
|
*/
|
2020-09-14 16:25:16 +08:00
|
|
|
adr_l r5, __turn_mmu_on @ _pa(__turn_mmu_on)
|
|
|
|
adr_l r6, __turn_mmu_on_end @ _pa(__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
|
2022-07-05 23:47:08 +08:00
|
|
|
str r3, [r4, r5, lsl #PMD_ENTRY_ORDER] @ identity mapping
|
2011-08-23 21:07:23 +08:00
|
|
|
cmp r5, r6
|
|
|
|
addlo r5, r5, #1 @ next section
|
|
|
|
blo 1b
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2021-06-03 16:51:21 +08:00
|
|
|
* The main matter: map in the kernel using section mappings, and
|
|
|
|
* set two variables to indicate the physical start and end of the
|
|
|
|
* kernel.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2022-07-05 23:47:08 +08:00
|
|
|
add r0, r4, #KERNEL_OFFSET >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
|
2012-07-04 11:58:12 +08:00
|
|
|
ldr r6, =(_end - 1)
|
2021-06-03 16:51:21 +08:00
|
|
|
adr_l r5, kernel_sec_start @ _pa(kernel_sec_start)
|
2021-10-21 17:26:57 +08:00
|
|
|
#if defined CONFIG_CPU_ENDIAN_BE8 || defined CONFIG_CPU_ENDIAN_BE32
|
2021-08-09 19:57:19 +08:00
|
|
|
str r8, [r5, #4] @ Save physical start of kernel (BE)
|
|
|
|
#else
|
|
|
|
str r8, [r5] @ Save physical start of kernel (LE)
|
|
|
|
#endif
|
2021-06-03 16:51:21 +08:00
|
|
|
orr r3, r8, r7 @ Add the MMU flags
|
2022-07-05 23:47:08 +08:00
|
|
|
add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ENTRY_ORDER)
|
|
|
|
1: str r3, [r0], #1 << PMD_ENTRY_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
|
2021-06-03 16:51:21 +08:00
|
|
|
eor r3, r3, r7 @ Remove the MMU flags
|
|
|
|
adr_l r5, kernel_sec_end @ _pa(kernel_sec_end)
|
2021-10-21 17:26:57 +08:00
|
|
|
#if defined CONFIG_CPU_ENDIAN_BE8 || defined CONFIG_CPU_ENDIAN_BE32
|
2021-08-09 19:57:19 +08:00
|
|
|
str r3, [r5, #4] @ Save physical end of kernel (BE)
|
|
|
|
#else
|
|
|
|
str r3, [r5] @ Save physical end of kernel (LE)
|
|
|
|
#endif
|
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
|
2022-07-05 23:47:08 +08:00
|
|
|
add r0, r4, #(XIP_START & 0xff000000) >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
|
|
|
|
str r3, [r0, #((XIP_START & 0x00f00000) >> SECTION_SHIFT) << PMD_ENTRY_ORDER]!
|
2012-07-04 11:58:12 +08:00
|
|
|
ldr r6, =(_edata_loc - 1)
|
2022-07-05 23:47:08 +08:00
|
|
|
add r0, r0, #1 << PMD_ENTRY_ORDER
|
|
|
|
add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ENTRY_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
|
2022-07-05 23:47:08 +08:00
|
|
|
strls r3, [r0], #1 << PMD_ENTRY_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
|
2020-11-17 15:41:01 +08:00
|
|
|
cmp r2, #0
|
2022-07-05 23:47:08 +08:00
|
|
|
ldrne r3, =FDT_FIXED_BASE >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
|
ARM: 9012/1: move device tree mapping out of linear region
On ARM, setting up the linear region is tricky, given the constraints
around placement and alignment of the memblocks, and how the kernel
itself as well as the DT are placed in physical memory.
Let's simplify matters a bit, by moving the device tree mapping to the
top of the address space, right between the end of the vmalloc region
and the start of the the fixmap region, and create a read-only mapping
for it that is independent of the size of the linear region, and how it
is organized.
Since this region was formerly used as a guard region, which will now be
populated fully on LPAE builds by this read-only mapping (which will
still be able to function as a guard region for stray writes), bump the
start of the [underutilized] fixmap region by 512 KB as well, to ensure
that there is always a proper guard region here. Doing so still leaves
ample room for the fixmap space, even with NR_CPUS set to its maximum
value of 32.
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2020-10-11 17:21:37 +08:00
|
|
|
addne r3, r3, r4
|
2020-11-17 15:41:01 +08:00
|
|
|
orrne r6, r7, r0, lsl #SECTION_SHIFT
|
2022-07-05 23:47:08 +08:00
|
|
|
strne r6, [r3], #1 << PMD_ENTRY_ORDER
|
2013-01-16 01:51:32 +08:00
|
|
|
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
|
2022-07-05 23:47:08 +08:00
|
|
|
mov r3, r3, lsl #PMD_ENTRY_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
|
|
|
|
2022-09-29 21:39:13 +08:00
|
|
|
#if defined(CONFIG_ARCH_NETWINDER)
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
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
|
|
|
*/
|
2022-07-05 23:47:08 +08:00
|
|
|
add r0, r4, #0xff000000 >> (SECTION_SHIFT - PMD_ENTRY_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.
|
|
|
|
*/
|
2022-07-05 23:47:08 +08:00
|
|
|
add r0, r4, #0x02000000 >> (SECTION_SHIFT - PMD_ENTRY_ORDER)
|
2005-07-01 18:56:55 +08:00
|
|
|
orr r3, r7, #0x02000000
|
2005-04-17 06:20:36 +08:00
|
|
|
str r3, [r0]
|
2022-07-05 23:47:08 +08:00
|
|
|
add r0, r4, #0xd8000000 >> (SECTION_SHIFT - PMD_ENTRY_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
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2008-08-28 18:22:32 +08:00
|
|
|
ENDPROC(__create_page_tables)
|
2005-04-17 06:20:36 +08:00
|
|
|
.ltorg
|
|
|
|
|
2010-10-05 00:56:13 +08:00
|
|
|
#if defined(CONFIG_SMP)
|
2013-07-31 18:37:17 +08:00
|
|
|
.text
|
2015-01-31 07:25:30 +08:00
|
|
|
.arm
|
2015-05-18 16:04:31 +08:00
|
|
|
ENTRY(secondary_startup_arm)
|
2015-04-21 21:17:25 +08:00
|
|
|
THUMB( badr r9, 1f ) @ Kernel is entered in ARM.
|
2015-01-31 07:25:30 +08:00
|
|
|
THUMB( bx r9 ) @ If this is a Thumb-2 kernel,
|
|
|
|
THUMB( .thumb ) @ switch to Thumb now.
|
|
|
|
THUMB(1: )
|
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.
|
|
|
|
*/
|
2013-02-01 17:40:42 +08:00
|
|
|
|
|
|
|
ARM_BE8(setend be) @ ensure we are in BE8 mode
|
|
|
|
|
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.
|
|
|
|
*/
|
2020-09-14 16:25:23 +08:00
|
|
|
adr_l r3, secondary_data
|
|
|
|
mov_l r12, __secondary_switched
|
2018-11-09 11:26:39 +08:00
|
|
|
ldrd r4, r5, [r3, #0] @ get secondary_data.pgdir
|
2015-08-06 22:07:04 +08:00
|
|
|
ARM_BE8(eor r4, r4, r5) @ Swap r5 and r4 in BE:
|
|
|
|
ARM_BE8(eor r5, r4, r5) @ it can be done in 3 steps
|
|
|
|
ARM_BE8(eor r4, r4, r5) @ without using a temp reg.
|
2015-04-05 03:09:46 +08:00
|
|
|
ldr r8, [r3, #8] @ get secondary_data.swapper_pg_dir
|
2015-04-21 21:17:25 +08:00
|
|
|
badr lr, __enable_mmu @ return address
|
2010-10-05 00:56:13 +08:00
|
|
|
mov r13, r12 @ __secondary_switched address
|
2015-03-18 14:29:32 +08:00
|
|
|
ldr r12, [r10, #PROCINFO_INITFUNC]
|
|
|
|
add r12, r12, r10 @ initialise processor
|
|
|
|
@ (return control reg)
|
|
|
|
ret r12
|
2010-10-05 00:56:13 +08:00
|
|
|
ENDPROC(secondary_startup)
|
2015-01-31 07:25:30 +08:00
|
|
|
ENDPROC(secondary_startup_arm)
|
2010-10-05 00:56:13 +08:00
|
|
|
|
|
|
|
ENTRY(__secondary_switched)
|
2022-01-25 02:51:58 +08:00
|
|
|
#if defined(CONFIG_VMAP_STACK) && !defined(CONFIG_ARM_LPAE)
|
|
|
|
@ Before using the vmap'ed stack, we have to switch to swapper_pg_dir
|
|
|
|
@ as the ID map does not cover the vmalloc region.
|
|
|
|
mrc p15, 0, ip, c2, c0, 1 @ read TTBR1
|
|
|
|
mcr p15, 0, ip, c2, c0, 0 @ set TTBR0
|
|
|
|
instr_sync
|
|
|
|
#endif
|
2021-09-18 16:44:35 +08:00
|
|
|
adr_l r7, secondary_data + 12 @ get secondary_data.stack
|
|
|
|
ldr sp, [r7]
|
|
|
|
ldr r0, [r7, #4] @ get secondary_data.task
|
2010-10-05 00:56:13 +08:00
|
|
|
mov fp, #0
|
|
|
|
b secondary_start_kernel
|
|
|
|
ENDPROC(__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
|
2015-04-05 03:09:46 +08:00
|
|
|
* registers. All these registers need to be preserved by the
|
|
|
|
* processor setup function (or set in the case of r0)
|
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
|
2015-04-05 03:09:46 +08:00
|
|
|
* r4 = TTBR pointer (low word)
|
|
|
|
* r5 = TTBR pointer (high word if LPAE)
|
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
|
2015-04-05 03:09:46 +08:00
|
|
|
#ifdef CONFIG_ARM_LPAE
|
|
|
|
mcrr p15, 0, r4, r5, c2 @ load TTBR0
|
|
|
|
#else
|
2015-08-21 16:23:26 +08:00
|
|
|
mov r5, #DACR_INIT
|
2010-10-05 00:56:13 +08:00
|
|
|
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
|
2014-06-30 23:29:12 +08:00
|
|
|
ret 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
|
2014-04-16 22:38:26 +08:00
|
|
|
__HEAD
|
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?
|
2014-06-30 23:29:12 +08:00
|
|
|
reteq lr @ yes, assume SMP
|
2010-09-04 17:47:48 +08:00
|
|
|
|
|
|
|
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?
|
2013-09-28 04:56:31 +08:00
|
|
|
bne __fixup_smp_on_up @ no, assume UP
|
|
|
|
|
|
|
|
@ Core indicates it is SMP. Check for Aegis SOC where a single
|
|
|
|
@ Cortex-A9 CPU is present but SMP operations fault.
|
|
|
|
mov r4, #0x41000000
|
|
|
|
orr r4, r4, #0x0000c000
|
|
|
|
orr r4, r4, #0x00000090
|
|
|
|
teq r3, r4 @ Check for ARM Cortex-A9
|
2014-06-30 23:29:12 +08:00
|
|
|
retne lr @ Not ARM Cortex-A9,
|
2013-09-28 04:56:31 +08:00
|
|
|
|
|
|
|
@ If a future SoC *does* use 0x0 as the PERIPH_BASE, then the
|
|
|
|
@ below address check will need to be #ifdef'd or equivalent
|
|
|
|
@ for the Aegis platform.
|
|
|
|
mrc p15, 4, r0, c15, c0 @ get SCU base address
|
|
|
|
teq r0, #0x0 @ '0' on actual UP A9 hardware
|
|
|
|
beq __fixup_smp_on_up @ So its an A9 UP
|
|
|
|
ldr r0, [r0, #4] @ read SCU Config
|
2013-11-07 15:42:40 +08:00
|
|
|
ARM_BE8(rev r0, r0) @ byteswap if big endian
|
2013-09-28 04:56:31 +08:00
|
|
|
and r0, r0, #0x3 @ number of CPUs
|
|
|
|
teq r0, #0x0 @ is 1?
|
2014-06-30 23:29:12 +08:00
|
|
|
retne lr
|
2010-09-04 17:47:48 +08:00
|
|
|
|
|
|
|
__fixup_smp_on_up:
|
2020-09-14 16:25:29 +08:00
|
|
|
adr_l r4, __smpalt_begin
|
|
|
|
adr_l r5, __smpalt_end
|
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)
|
|
|
|
|
|
|
|
.pushsection .data
|
2017-07-26 19:49:31 +08:00
|
|
|
.align 2
|
2010-09-04 17:47:48 +08:00
|
|
|
.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
|
2014-06-30 23:29:12 +08:00
|
|
|
reths lr
|
2020-09-14 16:48:20 +08:00
|
|
|
ldmia r4, {r0, r6}
|
|
|
|
ARM( str r6, [r0, r4] )
|
|
|
|
THUMB( add r0, r0, r4 )
|
|
|
|
add r4, r4, #8
|
2011-02-10 23:25:18 +08:00
|
|
|
#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
|
2020-09-14 16:48:20 +08:00
|
|
|
THUMB( mov r6, r6, lsr #16 ) @ to be robust against misaligned r0.
|
2011-02-10 23:25:18 +08:00
|
|
|
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
|
|
|
|
bl __do_fixup_smp_on_up
|
|
|
|
ldmfd sp!, {r4 - r6, pc}
|
|
|
|
ENDPROC(fixup_smp)
|
2010-09-04 17:47:48 +08:00
|
|
|
|
2006-03-27 21:58:25 +08:00
|
|
|
#include "head-common.S"
|