2019-06-04 15:11:33 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2006-03-27 20:58:25 +07:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/kernel/head-nommu.S
|
|
|
|
*
|
|
|
|
* Copyright (C) 1994-2002 Russell King
|
|
|
|
* Copyright (C) 2003-2006 Hyok S. Choi
|
|
|
|
*
|
|
|
|
* Common kernel startup code (non-paged MM)
|
|
|
|
*/
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <linux/init.h>
|
2017-10-16 18:54:05 +07:00
|
|
|
#include <linux/errno.h>
|
2006-03-27 20:58:25 +07:00
|
|
|
|
|
|
|
#include <asm/assembler.h>
|
|
|
|
#include <asm/ptrace.h>
|
2006-05-05 21:11:14 +07:00
|
|
|
#include <asm/asm-offsets.h>
|
2013-02-23 00:48:56 +07:00
|
|
|
#include <asm/memory.h>
|
2012-03-29 00:30:01 +07:00
|
|
|
#include <asm/cp15.h>
|
2006-04-24 15:45:35 +07:00
|
|
|
#include <asm/thread_info.h>
|
2010-05-22 00:06:41 +07:00
|
|
|
#include <asm/v7m.h>
|
2013-02-23 00:48:56 +07:00
|
|
|
#include <asm/mpu.h>
|
2013-04-19 00:37:24 +07:00
|
|
|
#include <asm/page.h>
|
2006-03-27 20:58:25 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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,
|
|
|
|
* r1 = machine nr.
|
|
|
|
*
|
|
|
|
* See linux/arch/arm/tools/mach-types for the complete list of machine
|
|
|
|
* numbers for r1.
|
|
|
|
*
|
|
|
|
*/
|
2011-07-13 21:53:30 +07:00
|
|
|
|
2009-10-03 03:32:46 +07:00
|
|
|
__HEAD
|
2011-12-10 02:52:10 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_CPU_THUMBONLY
|
|
|
|
.thumb
|
|
|
|
ENTRY(stext)
|
|
|
|
#else
|
|
|
|
.arm
|
2006-03-27 20:58:25 +07:00
|
|
|
ENTRY(stext)
|
2011-07-13 21:53:30 +07:00
|
|
|
|
2015-04-21 20:17:25 +07:00
|
|
|
THUMB( badr r9, 1f ) @ Kernel is always entered in ARM.
|
2011-07-13 21:53:30 +07:00
|
|
|
THUMB( bx r9 ) @ If this is a Thumb-2 kernel,
|
|
|
|
THUMB( .thumb ) @ switch to Thumb now.
|
|
|
|
THUMB(1: )
|
2011-12-10 02:52:10 +07:00
|
|
|
#endif
|
2011-07-13 21:53:30 +07:00
|
|
|
|
2018-07-23 15:37:09 +07:00
|
|
|
#ifdef CONFIG_ARM_VIRT_EXT
|
|
|
|
bl __hyp_stub_install
|
|
|
|
#endif
|
|
|
|
@ ensure svc mode and all interrupts masked
|
|
|
|
safe_svcmode_maskall r9
|
2006-03-27 20:58:25 +07:00
|
|
|
@ and irqs disabled
|
2010-05-22 00:06:41 +07:00
|
|
|
#if defined(CONFIG_CPU_CP15)
|
2006-03-27 20:58:25 +07:00
|
|
|
mrc p15, 0, r9, c0, c0 @ get processor id
|
2010-05-22 00:06:41 +07:00
|
|
|
#elif defined(CONFIG_CPU_V7M)
|
|
|
|
ldr r9, =BASEADDR_V7M_SCB
|
|
|
|
ldr r9, [r9, V7M_SCB_CPUID]
|
|
|
|
#else
|
|
|
|
ldr r9, =CONFIG_PROCESSOR_ID
|
2006-09-26 15:36:37 +07:00
|
|
|
#endif
|
2006-03-27 20:58:25 +07:00
|
|
|
bl __lookup_processor_type @ r5=procinfo r9=cpuid
|
|
|
|
movs r10, r5 @ invalid processor (r5=0)?
|
|
|
|
beq __error_p @ yes, error 'p'
|
|
|
|
|
2013-02-23 00:48:56 +07:00
|
|
|
#ifdef CONFIG_ARM_MPU
|
|
|
|
bl __setup_mpu
|
|
|
|
#endif
|
2015-06-03 02:43:24 +07:00
|
|
|
|
2015-04-21 20:17:25 +07:00
|
|
|
badr lr, 1f @ return (PIC) address
|
2015-04-20 02:28:53 +07:00
|
|
|
ldr r12, [r10, #PROCINFO_INITFUNC]
|
|
|
|
add r12, r12, r10
|
|
|
|
ret r12
|
2018-04-03 16:37:47 +07:00
|
|
|
1: ldr lr, =__mmap_switched
|
|
|
|
b __after_proc_init
|
2008-08-28 17:22:32 +07:00
|
|
|
ENDPROC(stext)
|
2006-03-27 20:58:25 +07:00
|
|
|
|
2012-02-28 18:50:32 +07:00
|
|
|
#ifdef CONFIG_SMP
|
2013-07-31 17:37:17 +07:00
|
|
|
.text
|
2012-02-28 18:50:32 +07: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.
|
|
|
|
*/
|
2018-07-23 15:37:09 +07:00
|
|
|
#ifdef CONFIG_ARM_VIRT_EXT
|
|
|
|
bl __hyp_stub_install_secondary
|
|
|
|
#endif
|
|
|
|
safe_svcmode_maskall r9
|
|
|
|
|
2012-02-28 18:50:32 +07:00
|
|
|
#ifndef CONFIG_CPU_CP15
|
|
|
|
ldr r9, =CONFIG_PROCESSOR_ID
|
|
|
|
#else
|
|
|
|
mrc p15, 0, r9, c0, c0 @ get processor id
|
|
|
|
#endif
|
|
|
|
bl __lookup_processor_type @ r5=procinfo r9=cpuid
|
|
|
|
movs r10, r5 @ invalid processor?
|
|
|
|
beq __error_p @ yes, error 'p'
|
|
|
|
|
2015-06-03 02:43:24 +07:00
|
|
|
ldr r7, __secondary_data
|
2013-02-23 01:51:30 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARM_MPU
|
2017-10-16 18:54:05 +07:00
|
|
|
bl __secondary_setup_mpu @ Initialize the MPU
|
2013-02-23 01:51:30 +07:00
|
|
|
#endif
|
|
|
|
|
2015-06-03 02:43:24 +07:00
|
|
|
badr lr, 1f @ return (PIC) address
|
2015-04-20 02:28:53 +07:00
|
|
|
ldr r12, [r10, #PROCINFO_INITFUNC]
|
|
|
|
add r12, r12, r10
|
|
|
|
ret r12
|
2015-06-03 02:43:24 +07:00
|
|
|
1: bl __after_proc_init
|
2015-04-05 02:09:46 +07:00
|
|
|
ldr sp, [r7, #12] @ set up the stack pointer
|
2012-02-28 18:50:32 +07:00
|
|
|
mov fp, #0
|
|
|
|
b secondary_start_kernel
|
2015-06-03 02:43:24 +07:00
|
|
|
ENDPROC(secondary_startup)
|
2012-02-28 18:50:32 +07:00
|
|
|
|
|
|
|
.type __secondary_data, %object
|
|
|
|
__secondary_data:
|
|
|
|
.long secondary_data
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
2006-03-27 20:58:25 +07:00
|
|
|
/*
|
|
|
|
* Set the Control Register and Read the process ID.
|
|
|
|
*/
|
2018-04-03 16:37:47 +07:00
|
|
|
.text
|
2006-03-27 20:58:25 +07:00
|
|
|
__after_proc_init:
|
2018-04-03 16:38:37 +07:00
|
|
|
M_CLASS(movw r12, #:lower16:BASEADDR_V7M_SCB)
|
|
|
|
M_CLASS(movt r12, #:upper16:BASEADDR_V7M_SCB)
|
2019-04-05 20:16:13 +07:00
|
|
|
#ifdef CONFIG_ARM_MPU
|
2018-04-03 16:38:37 +07:00
|
|
|
M_CLASS(ldr r3, [r12, 0x50])
|
|
|
|
AR_CLASS(mrc p15, 0, r3, c0, c1, 4) @ Read ID_MMFR0
|
|
|
|
and r3, r3, #(MMFR0_PMSA) @ PMSA field
|
|
|
|
teq r3, #(MMFR0_PMSAv7) @ PMSA v7
|
2018-04-03 16:39:23 +07:00
|
|
|
beq 1f
|
|
|
|
teq r3, #(MMFR0_PMSAv8) @ PMSA v8
|
|
|
|
/*
|
|
|
|
* Memory region attributes for PMSAv8:
|
|
|
|
*
|
|
|
|
* n = AttrIndx[2:0]
|
|
|
|
* n MAIR
|
|
|
|
* DEVICE_nGnRnE 000 00000000
|
|
|
|
* NORMAL 001 11111111
|
|
|
|
*/
|
|
|
|
ldreq r3, =PMSAv8_MAIR(0x00, PMSAv8_RGN_DEVICE_nGnRnE) | \
|
|
|
|
PMSAv8_MAIR(0xff, PMSAv8_RGN_NORMAL)
|
|
|
|
AR_CLASS(mcreq p15, 0, r3, c10, c2, 0) @ MAIR 0
|
|
|
|
M_CLASS(streq r3, [r12, #PMSAv8_MAIR0])
|
|
|
|
moveq r3, #0
|
|
|
|
AR_CLASS(mcreq p15, 0, r3, c10, c2, 1) @ MAIR 1
|
|
|
|
M_CLASS(streq r3, [r12, #PMSAv8_MAIR1])
|
|
|
|
|
|
|
|
1:
|
2018-04-03 16:38:37 +07:00
|
|
|
#endif
|
2006-09-26 15:36:37 +07:00
|
|
|
#ifdef CONFIG_CPU_CP15
|
2009-07-24 18:34:59 +07:00
|
|
|
/*
|
|
|
|
* CP15 system control register value returned in r0 from
|
|
|
|
* the CPU init function.
|
|
|
|
*/
|
2018-04-03 16:38:37 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARM_MPU
|
|
|
|
biceq r0, r0, #CR_BR @ Disable the 'default mem-map'
|
|
|
|
orreq r0, r0, #CR_M @ Set SCTRL.M (MPU on)
|
|
|
|
#endif
|
2012-12-04 16:34:39 +07:00
|
|
|
#if defined(CONFIG_ALIGNMENT_TRAP) && __LINUX_ARM_ARCH__ < 6
|
2006-03-27 20:58:25 +07: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
|
|
|
|
mcr p15, 0, r0, c1, c0, 0 @ write control reg
|
2018-06-18 20:33:03 +07:00
|
|
|
instr_sync
|
2016-08-30 23:31:22 +07:00
|
|
|
#elif defined (CONFIG_CPU_V7M)
|
2018-04-03 16:38:37 +07:00
|
|
|
#ifdef CONFIG_ARM_MPU
|
|
|
|
ldreq r3, [r12, MPU_CTRL]
|
|
|
|
biceq r3, #MPU_CTRL_PRIVDEFENA
|
|
|
|
orreq r3, #MPU_CTRL_ENABLE
|
|
|
|
streq r3, [r12, MPU_CTRL]
|
|
|
|
isb
|
|
|
|
#endif
|
2016-08-30 23:31:22 +07:00
|
|
|
/* For V7M systems we want to modify the CCR similarly to the SCTLR */
|
|
|
|
#ifdef CONFIG_CPU_DCACHE_DISABLE
|
|
|
|
bic r0, r0, #V7M_SCB_CCR_DC
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CPU_BPREDICT_DISABLE
|
|
|
|
bic r0, r0, #V7M_SCB_CCR_BP
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CPU_ICACHE_DISABLE
|
|
|
|
bic r0, r0, #V7M_SCB_CCR_IC
|
|
|
|
#endif
|
2018-04-03 16:38:37 +07:00
|
|
|
str r0, [r12, V7M_SCB_CCR]
|
2019-10-10 16:12:20 +07:00
|
|
|
/* Pass exc_ret to __mmap_switched */
|
|
|
|
mov r0, r10
|
2016-08-30 23:31:22 +07:00
|
|
|
#endif /* CONFIG_CPU_CP15 elif CONFIG_CPU_V7M */
|
2015-06-03 02:43:24 +07:00
|
|
|
ret lr
|
2008-08-28 17:22:32 +07:00
|
|
|
ENDPROC(__after_proc_init)
|
2006-04-24 15:45:35 +07:00
|
|
|
.ltorg
|
2006-03-27 20:58:25 +07:00
|
|
|
|
2013-02-23 00:48:56 +07:00
|
|
|
#ifdef CONFIG_ARM_MPU
|
|
|
|
|
|
|
|
|
2017-10-16 18:57:48 +07:00
|
|
|
#ifndef CONFIG_CPU_V7M
|
2013-02-23 00:48:56 +07:00
|
|
|
/* Set which MPU region should be programmed */
|
2017-10-16 18:57:48 +07:00
|
|
|
.macro set_region_nr tmp, rgnr, unused
|
2013-02-23 00:48:56 +07:00
|
|
|
mov \tmp, \rgnr @ Use static region numbers
|
|
|
|
mcr p15, 0, \tmp, c6, c2, 0 @ Write RGNR
|
|
|
|
.endm
|
|
|
|
|
|
|
|
/* Setup a single MPU region, either D or I side (D-side for unified) */
|
2018-04-03 16:36:37 +07:00
|
|
|
.macro setup_region bar, acr, sr, side = PMSAv7_DATA_SIDE, unused
|
2013-02-23 00:48:56 +07:00
|
|
|
mcr p15, 0, \bar, c6, c1, (0 + \side) @ I/DRBAR
|
|
|
|
mcr p15, 0, \acr, c6, c1, (4 + \side) @ I/DRACR
|
|
|
|
mcr p15, 0, \sr, c6, c1, (2 + \side) @ I/DRSR
|
|
|
|
.endm
|
2017-10-16 18:57:48 +07:00
|
|
|
#else
|
|
|
|
.macro set_region_nr tmp, rgnr, base
|
|
|
|
mov \tmp, \rgnr
|
2018-04-03 16:36:37 +07:00
|
|
|
str \tmp, [\base, #PMSAv7_RNR]
|
2017-10-16 18:57:48 +07:00
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro setup_region bar, acr, sr, unused, base
|
|
|
|
lsl \acr, \acr, #16
|
|
|
|
orr \acr, \acr, \sr
|
2018-04-03 16:36:37 +07:00
|
|
|
str \bar, [\base, #PMSAv7_RBAR]
|
|
|
|
str \acr, [\base, #PMSAv7_RASR]
|
2017-10-16 18:57:48 +07:00
|
|
|
.endm
|
2013-02-23 00:48:56 +07:00
|
|
|
|
2017-10-16 18:57:48 +07:00
|
|
|
#endif
|
2013-02-23 00:48:56 +07:00
|
|
|
/*
|
|
|
|
* Setup the MPU and initial MPU Regions. We create the following regions:
|
|
|
|
* Region 0: Use this for probing the MPU details, so leave disabled.
|
|
|
|
* Region 1: Background region - covers the whole of RAM as strongly ordered
|
|
|
|
* Region 2: Normal, Shared, cacheable for RAM. From PHYS_OFFSET, size from r6
|
2013-04-19 00:37:24 +07:00
|
|
|
* Region 3: Normal, shared, inaccessible from PL0 to protect the vectors page
|
2013-02-23 00:48:56 +07:00
|
|
|
*
|
2018-04-03 16:36:37 +07:00
|
|
|
* r6: Value to be written to DRSR (and IRSR if required) for PMSAv7_RAM_REGION
|
2013-02-23 00:48:56 +07:00
|
|
|
*/
|
2018-04-03 16:37:47 +07:00
|
|
|
__HEAD
|
2013-02-23 00:48:56 +07:00
|
|
|
|
|
|
|
ENTRY(__setup_mpu)
|
|
|
|
|
|
|
|
/* Probe for v7 PMSA compliance */
|
2017-10-16 18:57:48 +07:00
|
|
|
M_CLASS(movw r12, #:lower16:BASEADDR_V7M_SCB)
|
|
|
|
M_CLASS(movt r12, #:upper16:BASEADDR_V7M_SCB)
|
|
|
|
|
|
|
|
AR_CLASS(mrc p15, 0, r0, c0, c1, 4) @ Read ID_MMFR0
|
|
|
|
M_CLASS(ldr r0, [r12, 0x50])
|
2013-02-23 00:48:56 +07:00
|
|
|
and r0, r0, #(MMFR0_PMSA) @ PMSA field
|
|
|
|
teq r0, #(MMFR0_PMSAv7) @ PMSA v7
|
2018-04-03 16:36:37 +07:00
|
|
|
beq __setup_pmsa_v7
|
2018-04-03 16:39:23 +07:00
|
|
|
teq r0, #(MMFR0_PMSAv8) @ PMSA v8
|
|
|
|
beq __setup_pmsa_v8
|
2018-04-03 16:36:37 +07:00
|
|
|
|
|
|
|
ret lr
|
|
|
|
ENDPROC(__setup_mpu)
|
|
|
|
|
|
|
|
ENTRY(__setup_pmsa_v7)
|
|
|
|
/* Calculate the size of a region covering just the kernel */
|
|
|
|
ldr r5, =PLAT_PHYS_OFFSET @ Region start: PHYS_OFFSET
|
|
|
|
ldr r6, =(_end) @ Cover whole kernel
|
|
|
|
sub r6, r6, r5 @ Minimum size of region to map
|
|
|
|
clz r6, r6 @ Region size must be 2^N...
|
|
|
|
rsb r6, r6, #31 @ ...so round up region size
|
|
|
|
lsl r6, r6, #PMSAv7_RSR_SZ @ Put size in right field
|
|
|
|
orr r6, r6, #(1 << PMSAv7_RSR_EN) @ Set region enabled bit
|
2013-02-23 00:48:56 +07:00
|
|
|
|
|
|
|
/* Determine whether the D/I-side memory map is unified. We set the
|
|
|
|
* flags here and continue to use them for the rest of this function */
|
2017-10-16 18:57:48 +07:00
|
|
|
AR_CLASS(mrc p15, 0, r0, c0, c0, 4) @ MPUIR
|
|
|
|
M_CLASS(ldr r0, [r12, #MPU_TYPE])
|
2013-02-23 00:48:56 +07:00
|
|
|
ands r5, r0, #MPUIR_DREGION_SZMASK @ 0 size d region => No MPU
|
2017-10-16 18:54:05 +07:00
|
|
|
bxeq lr
|
2013-02-23 00:48:56 +07:00
|
|
|
tst r0, #MPUIR_nU @ MPUIR_nU = 0 for unified
|
|
|
|
|
|
|
|
/* Setup second region first to free up r6 */
|
2018-04-03 16:36:37 +07:00
|
|
|
set_region_nr r0, #PMSAv7_RAM_REGION, r12
|
2013-02-23 00:48:56 +07:00
|
|
|
isb
|
|
|
|
/* Full access from PL0, PL1, shared for CONFIG_SMP, cacheable */
|
2013-12-11 02:21:08 +07:00
|
|
|
ldr r0, =PLAT_PHYS_OFFSET @ RAM starts at PHYS_OFFSET
|
2018-04-03 16:36:37 +07:00
|
|
|
ldr r5,=(PMSAv7_AP_PL1RW_PL0RW | PMSAv7_RGN_NORMAL)
|
2013-02-23 00:48:56 +07:00
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
setup_region r0, r5, r6, PMSAv7_DATA_SIDE, r12 @ PHYS_OFFSET, shared, enabled
|
2017-10-16 18:57:48 +07:00
|
|
|
beq 1f @ Memory-map not unified
|
2018-04-03 16:36:37 +07:00
|
|
|
setup_region r0, r5, r6, PMSAv7_INSTR_SIDE, r12 @ PHYS_OFFSET, shared, enabled
|
2013-02-23 00:48:56 +07:00
|
|
|
1: isb
|
|
|
|
|
|
|
|
/* First/background region */
|
2018-04-03 16:36:37 +07:00
|
|
|
set_region_nr r0, #PMSAv7_BG_REGION, r12
|
2013-02-23 00:48:56 +07:00
|
|
|
isb
|
|
|
|
/* Execute Never, strongly ordered, inaccessible to PL0, rw PL1 */
|
|
|
|
mov r0, #0 @ BG region starts at 0x0
|
2018-04-03 16:36:37 +07:00
|
|
|
ldr r5,=(PMSAv7_ACR_XN | PMSAv7_RGN_STRONGLY_ORDERED | PMSAv7_AP_PL1RW_PL0NA)
|
|
|
|
mov r6, #PMSAv7_RSR_ALL_MEM @ 4GB region, enabled
|
2013-02-23 00:48:56 +07:00
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
setup_region r0, r5, r6, PMSAv7_DATA_SIDE, r12 @ 0x0, BG region, enabled
|
2017-10-16 18:57:48 +07:00
|
|
|
beq 2f @ Memory-map not unified
|
2018-04-03 16:36:37 +07:00
|
|
|
setup_region r0, r5, r6, PMSAv7_INSTR_SIDE r12 @ 0x0, BG region, enabled
|
2013-02-23 00:48:56 +07:00
|
|
|
2: isb
|
|
|
|
|
2017-10-16 19:00:45 +07:00
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
2018-04-03 16:36:37 +07:00
|
|
|
set_region_nr r0, #PMSAv7_ROM_REGION, r12
|
2017-10-16 19:00:45 +07:00
|
|
|
isb
|
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
ldr r5,=(PMSAv7_AP_PL1RO_PL0NA | PMSAv7_RGN_NORMAL)
|
2017-10-16 19:00:45 +07:00
|
|
|
|
|
|
|
ldr r0, =CONFIG_XIP_PHYS_ADDR @ ROM start
|
|
|
|
ldr r6, =(_exiprom) @ ROM end
|
|
|
|
sub r6, r6, r0 @ Minimum size of region to map
|
|
|
|
clz r6, r6 @ Region size must be 2^N...
|
|
|
|
rsb r6, r6, #31 @ ...so round up region size
|
2018-04-03 16:36:37 +07:00
|
|
|
lsl r6, r6, #PMSAv7_RSR_SZ @ Put size in right field
|
|
|
|
orr r6, r6, #(1 << PMSAv7_RSR_EN) @ Set region enabled bit
|
2017-10-16 19:00:45 +07:00
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
setup_region r0, r5, r6, PMSAv7_DATA_SIDE, r12 @ XIP_PHYS_ADDR, shared, enabled
|
2017-10-16 19:00:45 +07:00
|
|
|
beq 3f @ Memory-map not unified
|
2018-04-03 16:36:37 +07:00
|
|
|
setup_region r0, r5, r6, PMSAv7_INSTR_SIDE, r12 @ XIP_PHYS_ADDR, shared, enabled
|
2017-10-16 19:00:45 +07:00
|
|
|
3: isb
|
|
|
|
#endif
|
2017-10-16 18:54:05 +07:00
|
|
|
ret lr
|
2018-04-03 16:36:37 +07:00
|
|
|
ENDPROC(__setup_pmsa_v7)
|
2017-10-16 18:54:05 +07:00
|
|
|
|
2018-04-03 16:39:23 +07:00
|
|
|
ENTRY(__setup_pmsa_v8)
|
|
|
|
mov r0, #0
|
|
|
|
AR_CLASS(mcr p15, 0, r0, c6, c2, 1) @ PRSEL
|
|
|
|
M_CLASS(str r0, [r12, #PMSAv8_RNR])
|
|
|
|
isb
|
|
|
|
|
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
|
|
|
ldr r5, =CONFIG_XIP_PHYS_ADDR @ ROM start
|
|
|
|
ldr r6, =(_exiprom) @ ROM end
|
|
|
|
sub r6, r6, #1
|
|
|
|
bic r6, r6, #(PMSAv8_MINALIGN - 1)
|
|
|
|
|
|
|
|
orr r5, r5, #(PMSAv8_AP_PL1RW_PL0NA | PMSAv8_RGN_SHARED)
|
|
|
|
orr r6, r6, #(PMSAv8_LAR_IDX(PMSAv8_RGN_NORMAL) | PMSAv8_LAR_EN)
|
|
|
|
|
|
|
|
AR_CLASS(mcr p15, 0, r5, c6, c8, 0) @ PRBAR0
|
|
|
|
AR_CLASS(mcr p15, 0, r6, c6, c8, 1) @ PRLAR0
|
|
|
|
M_CLASS(str r5, [r12, #PMSAv8_RBAR_A(0)])
|
|
|
|
M_CLASS(str r6, [r12, #PMSAv8_RLAR_A(0)])
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ldr r5, =KERNEL_START
|
|
|
|
ldr r6, =KERNEL_END
|
|
|
|
sub r6, r6, #1
|
|
|
|
bic r6, r6, #(PMSAv8_MINALIGN - 1)
|
|
|
|
|
|
|
|
orr r5, r5, #(PMSAv8_AP_PL1RW_PL0NA | PMSAv8_RGN_SHARED)
|
|
|
|
orr r6, r6, #(PMSAv8_LAR_IDX(PMSAv8_RGN_NORMAL) | PMSAv8_LAR_EN)
|
|
|
|
|
|
|
|
AR_CLASS(mcr p15, 0, r5, c6, c8, 4) @ PRBAR1
|
|
|
|
AR_CLASS(mcr p15, 0, r6, c6, c8, 5) @ PRLAR1
|
|
|
|
M_CLASS(str r5, [r12, #PMSAv8_RBAR_A(1)])
|
|
|
|
M_CLASS(str r6, [r12, #PMSAv8_RLAR_A(1)])
|
|
|
|
|
|
|
|
/* Setup Background: 0x0 - min(KERNEL_START, XIP_PHYS_ADDR) */
|
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
|
|
|
ldr r6, =KERNEL_START
|
|
|
|
ldr r5, =CONFIG_XIP_PHYS_ADDR
|
|
|
|
cmp r6, r5
|
|
|
|
movcs r6, r5
|
|
|
|
#else
|
|
|
|
ldr r6, =KERNEL_START
|
|
|
|
#endif
|
|
|
|
cmp r6, #0
|
|
|
|
beq 1f
|
|
|
|
|
|
|
|
mov r5, #0
|
|
|
|
sub r6, r6, #1
|
|
|
|
bic r6, r6, #(PMSAv8_MINALIGN - 1)
|
|
|
|
|
|
|
|
orr r5, r5, #(PMSAv8_AP_PL1RW_PL0NA | PMSAv8_RGN_SHARED | PMSAv8_BAR_XN)
|
|
|
|
orr r6, r6, #(PMSAv8_LAR_IDX(PMSAv8_RGN_DEVICE_nGnRnE) | PMSAv8_LAR_EN)
|
|
|
|
|
|
|
|
AR_CLASS(mcr p15, 0, r5, c6, c9, 0) @ PRBAR2
|
|
|
|
AR_CLASS(mcr p15, 0, r6, c6, c9, 1) @ PRLAR2
|
|
|
|
M_CLASS(str r5, [r12, #PMSAv8_RBAR_A(2)])
|
|
|
|
M_CLASS(str r6, [r12, #PMSAv8_RLAR_A(2)])
|
|
|
|
|
|
|
|
1:
|
|
|
|
/* Setup Background: max(KERNEL_END, _exiprom) - 0xffffffff */
|
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
|
|
|
ldr r5, =KERNEL_END
|
|
|
|
ldr r6, =(_exiprom)
|
|
|
|
cmp r5, r6
|
|
|
|
movcc r5, r6
|
|
|
|
#else
|
|
|
|
ldr r5, =KERNEL_END
|
|
|
|
#endif
|
|
|
|
mov r6, #0xffffffff
|
|
|
|
bic r6, r6, #(PMSAv8_MINALIGN - 1)
|
|
|
|
|
|
|
|
orr r5, r5, #(PMSAv8_AP_PL1RW_PL0NA | PMSAv8_RGN_SHARED | PMSAv8_BAR_XN)
|
|
|
|
orr r6, r6, #(PMSAv8_LAR_IDX(PMSAv8_RGN_DEVICE_nGnRnE) | PMSAv8_LAR_EN)
|
|
|
|
|
|
|
|
AR_CLASS(mcr p15, 0, r5, c6, c9, 4) @ PRBAR3
|
|
|
|
AR_CLASS(mcr p15, 0, r6, c6, c9, 5) @ PRLAR3
|
|
|
|
M_CLASS(str r5, [r12, #PMSAv8_RBAR_A(3)])
|
|
|
|
M_CLASS(str r6, [r12, #PMSAv8_RLAR_A(3)])
|
|
|
|
|
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
|
|
|
/* Setup Background: min(_exiprom, KERNEL_END) - max(KERNEL_START, XIP_PHYS_ADDR) */
|
|
|
|
ldr r5, =(_exiprom)
|
|
|
|
ldr r6, =KERNEL_END
|
|
|
|
cmp r5, r6
|
|
|
|
movcs r5, r6
|
|
|
|
|
|
|
|
ldr r6, =KERNEL_START
|
|
|
|
ldr r0, =CONFIG_XIP_PHYS_ADDR
|
|
|
|
cmp r6, r0
|
|
|
|
movcc r6, r0
|
|
|
|
|
|
|
|
sub r6, r6, #1
|
|
|
|
bic r6, r6, #(PMSAv8_MINALIGN - 1)
|
|
|
|
|
|
|
|
orr r5, r5, #(PMSAv8_AP_PL1RW_PL0NA | PMSAv8_RGN_SHARED | PMSAv8_BAR_XN)
|
|
|
|
orr r6, r6, #(PMSAv8_LAR_IDX(PMSAv8_RGN_DEVICE_nGnRnE) | PMSAv8_LAR_EN)
|
|
|
|
|
|
|
|
#ifdef CONFIG_CPU_V7M
|
|
|
|
/* There is no alias for n == 4 */
|
|
|
|
mov r0, #4
|
|
|
|
str r0, [r12, #PMSAv8_RNR] @ PRSEL
|
|
|
|
isb
|
|
|
|
|
|
|
|
str r5, [r12, #PMSAv8_RBAR_A(0)]
|
|
|
|
str r6, [r12, #PMSAv8_RLAR_A(0)]
|
|
|
|
#else
|
ARM: 8849/1: NOMMU: Fix encodings for PMSAv8's PRBAR4/PRLAR4
To access PRBARn, where n is referenced as a binary number:
MRC p15, 0, <Rt>, c6, c8+n[3:1], 4*n[0] ; Read PRBARn into Rt
MCR p15, 0, <Rt>, c6, c8+n[3:1], 4*n[0] ; Write Rt into PRBARn
To access PRLARn, where n is referenced as a binary number:
MRC p15, 0, <Rt>, c6, c8+n[3:1], 4*n[0]+1 ; Read PRLARn into Rt
MCR p15, 0, <Rt>, c6, c8+n[3:1], 4*n[0]+1 ; Write Rt into PRLARn
For PR{B,L}AR4, n is 4, n[0] is 0, n[3:1] is 2, while current encoding
done with n[0] set to 1 which is wrong. Use proper encoding instead.
Fixes: 046835b4aa22b9ab6aa0bb274e3b71047c4b887d ("ARM: 8757/1: NOMMU: Support PMSAv8 MPU")
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
2019-02-20 21:00:53 +07:00
|
|
|
mcr p15, 0, r5, c6, c10, 0 @ PRBAR4
|
|
|
|
mcr p15, 0, r6, c6, c10, 1 @ PRLAR4
|
2018-04-03 16:39:23 +07:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
ret lr
|
|
|
|
ENDPROC(__setup_pmsa_v8)
|
|
|
|
|
2017-10-16 18:54:05 +07:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/*
|
|
|
|
* r6: pointer at mpu_rgn_info
|
|
|
|
*/
|
|
|
|
|
2018-04-03 16:37:47 +07:00
|
|
|
.text
|
2017-10-16 18:54:05 +07:00
|
|
|
ENTRY(__secondary_setup_mpu)
|
2018-04-03 16:36:37 +07:00
|
|
|
/* Use MPU region info supplied by __cpu_up */
|
|
|
|
ldr r6, [r7] @ get secondary_data.mpu_rgn_info
|
|
|
|
|
2017-10-16 18:54:05 +07:00
|
|
|
/* Probe for v7 PMSA compliance */
|
|
|
|
mrc p15, 0, r0, c0, c1, 4 @ Read ID_MMFR0
|
|
|
|
and r0, r0, #(MMFR0_PMSA) @ PMSA field
|
|
|
|
teq r0, #(MMFR0_PMSAv7) @ PMSA v7
|
2018-04-03 16:36:37 +07:00
|
|
|
beq __secondary_setup_pmsa_v7
|
2018-04-03 16:39:23 +07:00
|
|
|
teq r0, #(MMFR0_PMSAv8) @ PMSA v8
|
|
|
|
beq __secondary_setup_pmsa_v8
|
2018-04-03 16:36:37 +07:00
|
|
|
b __error_p
|
|
|
|
ENDPROC(__secondary_setup_mpu)
|
2017-10-16 18:54:05 +07:00
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
/*
|
|
|
|
* r6: pointer at mpu_rgn_info
|
|
|
|
*/
|
|
|
|
ENTRY(__secondary_setup_pmsa_v7)
|
2017-10-16 18:54:05 +07:00
|
|
|
/* Determine whether the D/I-side memory map is unified. We set the
|
|
|
|
* flags here and continue to use them for the rest of this function */
|
|
|
|
mrc p15, 0, r0, c0, c0, 4 @ MPUIR
|
|
|
|
ands r5, r0, #MPUIR_DREGION_SZMASK @ 0 size d region => No MPU
|
|
|
|
beq __error_p
|
|
|
|
|
|
|
|
ldr r4, [r6, #MPU_RNG_INFO_USED]
|
|
|
|
mov r5, #MPU_RNG_SIZE
|
|
|
|
add r3, r6, #MPU_RNG_INFO_RNGS
|
|
|
|
mla r3, r4, r5, r3
|
|
|
|
|
|
|
|
1:
|
|
|
|
tst r0, #MPUIR_nU @ MPUIR_nU = 0 for unified
|
|
|
|
sub r3, r3, #MPU_RNG_SIZE
|
|
|
|
sub r4, r4, #1
|
|
|
|
|
|
|
|
set_region_nr r0, r4
|
2013-04-19 00:37:24 +07:00
|
|
|
isb
|
|
|
|
|
2017-10-16 18:54:05 +07:00
|
|
|
ldr r0, [r3, #MPU_RGN_DRBAR]
|
|
|
|
ldr r6, [r3, #MPU_RGN_DRSR]
|
|
|
|
ldr r5, [r3, #MPU_RGN_DRACR]
|
|
|
|
|
2018-04-03 16:36:37 +07:00
|
|
|
setup_region r0, r5, r6, PMSAv7_DATA_SIDE
|
2017-10-16 18:54:05 +07:00
|
|
|
beq 2f
|
2018-04-03 16:36:37 +07:00
|
|
|
setup_region r0, r5, r6, PMSAv7_INSTR_SIDE
|
2017-10-16 18:54:05 +07:00
|
|
|
2: isb
|
|
|
|
|
|
|
|
mrc p15, 0, r0, c0, c0, 4 @ Reevaluate the MPUIR
|
|
|
|
cmp r4, #0
|
|
|
|
bgt 1b
|
2013-04-19 00:37:24 +07:00
|
|
|
|
2014-06-30 22:29:12 +07:00
|
|
|
ret lr
|
2018-04-03 16:36:37 +07:00
|
|
|
ENDPROC(__secondary_setup_pmsa_v7)
|
2017-10-16 18:54:05 +07:00
|
|
|
|
2018-04-03 16:39:23 +07:00
|
|
|
ENTRY(__secondary_setup_pmsa_v8)
|
|
|
|
ldr r4, [r6, #MPU_RNG_INFO_USED]
|
|
|
|
#ifndef CONFIG_XIP_KERNEL
|
|
|
|
add r4, r4, #1
|
|
|
|
#endif
|
|
|
|
mov r5, #MPU_RNG_SIZE
|
|
|
|
add r3, r6, #MPU_RNG_INFO_RNGS
|
|
|
|
mla r3, r4, r5, r3
|
|
|
|
|
|
|
|
1:
|
|
|
|
sub r3, r3, #MPU_RNG_SIZE
|
|
|
|
sub r4, r4, #1
|
|
|
|
|
|
|
|
mcr p15, 0, r4, c6, c2, 1 @ PRSEL
|
|
|
|
isb
|
|
|
|
|
|
|
|
ldr r5, [r3, #MPU_RGN_PRBAR]
|
|
|
|
ldr r6, [r3, #MPU_RGN_PRLAR]
|
|
|
|
|
|
|
|
mcr p15, 0, r5, c6, c3, 0 @ PRBAR
|
|
|
|
mcr p15, 0, r6, c6, c3, 1 @ PRLAR
|
|
|
|
|
|
|
|
cmp r4, #0
|
|
|
|
bgt 1b
|
|
|
|
|
|
|
|
ret lr
|
|
|
|
ENDPROC(__secondary_setup_pmsa_v8)
|
2017-10-16 18:54:05 +07:00
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
#endif /* CONFIG_ARM_MPU */
|
2006-03-27 20:58:25 +07:00
|
|
|
#include "head-common.S"
|