2019-05-19 13:51:31 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-02-09 16:47:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Linaro Limited.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
2016-02-15 19:16:24 +00:00
|
|
|
#include <linux/irqchip/arm-gic-v3.h>
|
2012-02-09 16:47:17 +00:00
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <asm/assembler.h>
|
|
|
|
#include <asm/virt.h>
|
|
|
|
|
ARM: 9263/1: use .arch directives instead of assembler command line flags
Similar to commit a6c30873ee4a ("ARM: 8989/1: use .fpu assembler
directives instead of assembler arguments").
GCC and GNU binutils support setting the "sub arch" via -march=,
-Wa,-march, target function attribute, and .arch assembler directive.
Clang was missing support for -Wa,-march=, but this was implemented in
clang-13.
The behavior of both GCC and Clang is to
prefer -Wa,-march= over -march= for assembler and assembler-with-cpp
sources, but Clang will warn about the -march= being unused.
clang: warning: argument unused during compilation: '-march=armv6k'
[-Wunused-command-line-argument]
Since most assembler is non-conditionally assembled with one sub arch
(modulo arch/arm/delay-loop.S which conditionally is assembled as armv4
based on CONFIG_ARCH_RPC, and arch/arm/mach-at91/pm-suspend.S which is
conditionally assembled as armv7-a based on CONFIG_CPU_V7), prefer the
.arch assembler directive.
Add a few more instances found in compile testing as found by Arnd and
Nathan.
Link: https://github.com/llvm/llvm-project/commit/1d51c699b9e2ebc5bcfdbe85c74cc871426333d4
Link: https://bugs.llvm.org/show_bug.cgi?id=48894
Link: https://github.com/ClangBuiltLinux/linux/issues/1195
Link: https://github.com/ClangBuiltLinux/linux/issues/1315
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
2022-10-24 19:44:41 +00:00
|
|
|
.arch armv7-a
|
|
|
|
|
2012-02-11 02:07:07 +00:00
|
|
|
#ifndef ZIMAGE
|
2012-02-09 16:47:17 +00:00
|
|
|
/*
|
|
|
|
* For the kernel proper, we need to find out the CPU boot mode long after
|
|
|
|
* boot, so we need to store it in a writable variable.
|
|
|
|
*
|
|
|
|
* This is not in .bss, because we set it sufficiently early that the boot-time
|
|
|
|
* zeroing of .bss would clobber it.
|
|
|
|
*/
|
|
|
|
.data
|
2017-07-26 11:49:31 +00:00
|
|
|
.align 2
|
2012-02-09 16:47:17 +00:00
|
|
|
ENTRY(__boot_cpu_mode)
|
|
|
|
.long 0
|
|
|
|
.text
|
|
|
|
|
|
|
|
/*
|
2020-09-14 08:25:52 +00:00
|
|
|
* Save the primary CPU boot mode. Requires 2 scratch registers.
|
2012-02-09 16:47:17 +00:00
|
|
|
*/
|
2020-09-14 08:25:52 +00:00
|
|
|
.macro store_primary_cpu_mode reg1, reg2
|
2012-02-09 16:47:17 +00:00
|
|
|
mrs \reg1, cpsr
|
|
|
|
and \reg1, \reg1, #MODE_MASK
|
2020-09-14 08:25:52 +00:00
|
|
|
str_l \reg1, __boot_cpu_mode, \reg2
|
2012-02-09 16:47:17 +00:00
|
|
|
.endm
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare the current mode with the one saved on the primary CPU.
|
|
|
|
* If they don't match, record that fact. The Z bit indicates
|
|
|
|
* if there's a match or not.
|
2020-09-14 08:25:52 +00:00
|
|
|
* Requires 2 additional scratch registers.
|
2012-02-09 16:47:17 +00:00
|
|
|
*/
|
2020-09-14 08:25:52 +00:00
|
|
|
.macro compare_cpu_mode_with_primary mode, reg1, reg2
|
|
|
|
adr_l \reg2, __boot_cpu_mode
|
|
|
|
ldr \reg1, [\reg2]
|
2012-02-09 16:47:17 +00:00
|
|
|
cmp \mode, \reg1 @ matches primary CPU boot mode?
|
2013-07-18 16:20:32 +00:00
|
|
|
orrne \reg1, \reg1, #BOOT_CPU_MODE_MISMATCH
|
2020-09-14 08:25:52 +00:00
|
|
|
strne \reg1, [\reg2] @ record what happened and give up
|
2012-02-09 16:47:17 +00:00
|
|
|
.endm
|
|
|
|
|
2012-02-11 02:07:07 +00:00
|
|
|
#else /* ZIMAGE */
|
|
|
|
|
2020-09-14 08:25:52 +00:00
|
|
|
.macro store_primary_cpu_mode reg1:req, reg2:req
|
2012-02-11 02:07:07 +00:00
|
|
|
.endm
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The zImage loader only runs on one CPU, so we don't bother with mult-CPU
|
|
|
|
* consistency checking:
|
|
|
|
*/
|
2020-09-14 08:25:52 +00:00
|
|
|
.macro compare_cpu_mode_with_primary mode, reg1, reg2
|
2012-02-11 02:07:07 +00:00
|
|
|
cmp \mode, \mode
|
|
|
|
.endm
|
|
|
|
|
|
|
|
#endif /* ZIMAGE */
|
|
|
|
|
2012-02-09 16:47:17 +00:00
|
|
|
/*
|
|
|
|
* Hypervisor stub installation functions.
|
|
|
|
*
|
|
|
|
* These must be called with the MMU and D-cache off.
|
|
|
|
* They are not ABI compliant and are only intended to be called from the kernel
|
|
|
|
* entry points in head.S.
|
|
|
|
*/
|
|
|
|
@ Call this from the primary CPU
|
|
|
|
ENTRY(__hyp_stub_install)
|
2020-09-14 08:25:52 +00:00
|
|
|
store_primary_cpu_mode r4, r5
|
2012-02-09 16:47:17 +00:00
|
|
|
ENDPROC(__hyp_stub_install)
|
|
|
|
|
|
|
|
@ fall through...
|
|
|
|
|
|
|
|
@ Secondary CPUs should call here
|
|
|
|
ENTRY(__hyp_stub_install_secondary)
|
|
|
|
mrs r4, cpsr
|
|
|
|
and r4, r4, #MODE_MASK
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the secondary has booted with a different mode, give up
|
|
|
|
* immediately.
|
|
|
|
*/
|
2020-09-14 08:25:52 +00:00
|
|
|
compare_cpu_mode_with_primary r4, r5, r6
|
2014-06-30 15:29:12 +00:00
|
|
|
retne lr
|
2012-02-09 16:47:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Once we have given up on one CPU, we do not try to install the
|
|
|
|
* stub hypervisor on the remaining ones: because the saved boot mode
|
|
|
|
* is modified, it can't compare equal to the CPSR mode field any
|
|
|
|
* more.
|
|
|
|
*
|
|
|
|
* Otherwise...
|
|
|
|
*/
|
|
|
|
|
|
|
|
cmp r4, #HYP_MODE
|
2014-06-30 15:29:12 +00:00
|
|
|
retne lr @ give up if the CPU is not in HYP mode
|
2012-02-09 16:47:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure HSCTLR to set correct exception endianness/instruction set
|
|
|
|
* state etc.
|
|
|
|
* Turn off all traps
|
|
|
|
* Eventually, CPU-specific code might be needed -- assume not for now
|
|
|
|
*
|
|
|
|
* This code relies on the "eret" instruction to synchronize the
|
2013-01-04 17:44:15 +00:00
|
|
|
* various coprocessor accesses. This is done when we switch to SVC
|
|
|
|
* (see safe_svcmode_maskall).
|
2012-02-09 16:47:17 +00:00
|
|
|
*/
|
|
|
|
@ Now install the hypervisor stub:
|
2017-04-20 10:16:20 +00:00
|
|
|
W(adr) r7, __hyp_stub_vectors
|
2012-02-09 16:47:17 +00:00
|
|
|
mcr p15, 4, r7, c12, c0, 0 @ set hypervisor vector base (HVBAR)
|
|
|
|
|
|
|
|
@ Disable all traps, so we don't get any nasty surprise
|
|
|
|
mov r7, #0
|
|
|
|
mcr p15, 4, r7, c1, c1, 0 @ HCR
|
|
|
|
mcr p15, 4, r7, c1, c1, 2 @ HCPTR
|
|
|
|
mcr p15, 4, r7, c1, c1, 3 @ HSTR
|
|
|
|
|
|
|
|
THUMB( orr r7, #(1 << 30) ) @ HSCTLR.TE
|
2014-07-01 10:01:50 +00:00
|
|
|
ARM_BE8(orr r7, r7, #(1 << 25)) @ HSCTLR.EE
|
2012-02-09 16:47:17 +00:00
|
|
|
mcr p15, 4, r7, c1, c0, 0 @ HSCTLR
|
|
|
|
|
|
|
|
mrc p15, 4, r7, c1, c1, 1 @ HDCR
|
|
|
|
and r7, #0x1f @ Preserve HPMN
|
|
|
|
mcr p15, 4, r7, c1, c1, 1 @ HDCR
|
|
|
|
|
2016-08-19 18:38:41 +00:00
|
|
|
@ Make sure NS-SVC is initialised appropriately
|
|
|
|
mrc p15, 0, r7, c1, c0, 0 @ SCTLR
|
|
|
|
orr r7, #(1 << 5) @ CP15 barriers enabled
|
|
|
|
bic r7, #(3 << 7) @ Clear SED/ITD for v8 (RES0 for v7)
|
|
|
|
bic r7, #(3 << 19) @ WXN and UWXN disabled
|
|
|
|
mcr p15, 0, r7, c1, c0, 0 @ SCTLR
|
|
|
|
|
|
|
|
mrc p15, 0, r7, c0, c0, 0 @ MIDR
|
|
|
|
mcr p15, 4, r7, c0, c0, 0 @ VPIDR
|
|
|
|
|
|
|
|
mrc p15, 0, r7, c0, c0, 5 @ MPIDR
|
|
|
|
mcr p15, 4, r7, c0, c0, 5 @ VMPIDR
|
|
|
|
|
2012-08-01 13:46:41 +00:00
|
|
|
#if !defined(ZIMAGE) && defined(CONFIG_ARM_ARCH_TIMER)
|
|
|
|
@ make CNTP_* and CNTPCT accessible from PL1
|
|
|
|
mrc p15, 0, r7, c0, c1, 1 @ ID_PFR1
|
2020-01-20 14:07:46 +00:00
|
|
|
ubfx r7, r7, #16, #4
|
|
|
|
teq r7, #0
|
|
|
|
beq 1f
|
2012-08-01 13:46:41 +00:00
|
|
|
mrc p15, 4, r7, c14, c1, 0 @ CNTHCTL
|
|
|
|
orr r7, r7, #3 @ PL1PCEN | PL1PCTEN
|
|
|
|
mcr p15, 4, r7, c14, c1, 0 @ CNTHCTL
|
2013-01-30 18:17:49 +00:00
|
|
|
mov r7, #0
|
|
|
|
mcrr p15, 4, r7, r7, c14 @ CNTVOFF
|
2013-03-12 14:56:12 +00:00
|
|
|
|
|
|
|
@ Disable virtual timer in case it was counting
|
|
|
|
mrc p15, 0, r7, c14, c3, 1 @ CNTV_CTL
|
|
|
|
bic r7, #1 @ Clear ENABLE
|
|
|
|
mcr p15, 0, r7, c14, c3, 1 @ CNTV_CTL
|
2012-08-01 13:46:41 +00:00
|
|
|
1:
|
2016-02-15 19:16:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARM_GIC_V3
|
|
|
|
@ Check whether GICv3 system registers are available
|
|
|
|
mrc p15, 0, r7, c0, c1, 1 @ ID_PFR1
|
|
|
|
ubfx r7, r7, #28, #4
|
2019-02-20 14:00:13 +00:00
|
|
|
teq r7, #0
|
|
|
|
beq 2f
|
2016-02-15 19:16:24 +00:00
|
|
|
|
|
|
|
@ Enable system register accesses
|
|
|
|
mrc p15, 4, r7, c12, c9, 5 @ ICC_HSRE
|
|
|
|
orr r7, r7, #(ICC_SRE_EL2_ENABLE | ICC_SRE_EL2_SRE)
|
|
|
|
mcr p15, 4, r7, c12, c9, 5 @ ICC_HSRE
|
|
|
|
isb
|
|
|
|
|
|
|
|
@ SRE bit could be forced to 0 by firmware.
|
|
|
|
@ Check whether it sticks before accessing any other sysreg
|
|
|
|
mrc p15, 4, r7, c12, c9, 5 @ ICC_HSRE
|
|
|
|
tst r7, #ICC_SRE_EL2_SRE
|
|
|
|
beq 2f
|
|
|
|
mov r7, #0
|
|
|
|
mcr p15, 4, r7, c12, c11, 0 @ ICH_HCR
|
|
|
|
2:
|
2012-08-01 13:46:41 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-04 17:44:15 +00:00
|
|
|
bx lr @ The boot CPU mode is left in r4.
|
2012-02-09 16:47:17 +00:00
|
|
|
ENDPROC(__hyp_stub_install_secondary)
|
|
|
|
|
|
|
|
__hyp_stub_do_trap:
|
2020-02-16 12:01:26 +00:00
|
|
|
#ifdef ZIMAGE
|
2017-04-03 18:38:03 +00:00
|
|
|
teq r0, #HVC_SET_VECTORS
|
2017-04-03 18:37:45 +00:00
|
|
|
bne 1f
|
2020-02-16 12:01:26 +00:00
|
|
|
/* Only the ZIMAGE stubs can change the HYP vectors */
|
2017-04-03 18:37:45 +00:00
|
|
|
mcr p15, 4, r1, c12, c0, 0 @ set HVBAR
|
|
|
|
b __hyp_stub_exit
|
2020-02-16 12:01:26 +00:00
|
|
|
#endif
|
2017-04-03 18:37:45 +00:00
|
|
|
|
2017-04-03 18:37:46 +00:00
|
|
|
1: teq r0, #HVC_SOFT_RESTART
|
2020-02-16 12:01:26 +00:00
|
|
|
bne 2f
|
2017-04-03 18:37:49 +00:00
|
|
|
bx r1
|
2017-04-03 18:37:46 +00:00
|
|
|
|
2020-02-16 12:01:26 +00:00
|
|
|
2: ldr r0, =HVC_STUB_ERR
|
2017-04-03 18:38:06 +00:00
|
|
|
__ERET
|
2017-04-03 18:37:45 +00:00
|
|
|
|
|
|
|
__hyp_stub_exit:
|
2017-04-03 18:38:06 +00:00
|
|
|
mov r0, #0
|
2012-02-09 16:47:17 +00:00
|
|
|
__ERET
|
|
|
|
ENDPROC(__hyp_stub_do_trap)
|
|
|
|
|
|
|
|
/*
|
2020-02-16 12:01:26 +00:00
|
|
|
* __hyp_set_vectors is only used when ZIMAGE must bounce between HYP
|
|
|
|
* and SVC. For the kernel itself, the vectors are set once and for
|
|
|
|
* all by the stubs.
|
2012-02-09 16:47:17 +00:00
|
|
|
*/
|
|
|
|
ENTRY(__hyp_set_vectors)
|
2017-04-03 18:37:45 +00:00
|
|
|
mov r1, r0
|
|
|
|
mov r0, #HVC_SET_VECTORS
|
2012-02-09 16:47:17 +00:00
|
|
|
__HVC(0)
|
2014-06-30 15:29:12 +00:00
|
|
|
ret lr
|
2012-02-09 16:47:17 +00:00
|
|
|
ENDPROC(__hyp_set_vectors)
|
|
|
|
|
2017-04-03 18:37:46 +00:00
|
|
|
ENTRY(__hyp_soft_restart)
|
2017-04-03 18:37:49 +00:00
|
|
|
mov r1, r0
|
2017-04-03 18:37:46 +00:00
|
|
|
mov r0, #HVC_SOFT_RESTART
|
|
|
|
__HVC(0)
|
|
|
|
ret lr
|
|
|
|
ENDPROC(__hyp_soft_restart)
|
|
|
|
|
2012-02-09 16:47:17 +00:00
|
|
|
.align 5
|
2017-04-03 18:37:53 +00:00
|
|
|
ENTRY(__hyp_stub_vectors)
|
2012-02-09 16:47:17 +00:00
|
|
|
__hyp_stub_reset: W(b) .
|
|
|
|
__hyp_stub_und: W(b) .
|
|
|
|
__hyp_stub_svc: W(b) .
|
|
|
|
__hyp_stub_pabort: W(b) .
|
|
|
|
__hyp_stub_dabort: W(b) .
|
|
|
|
__hyp_stub_trap: W(b) __hyp_stub_do_trap
|
|
|
|
__hyp_stub_irq: W(b) .
|
|
|
|
__hyp_stub_fiq: W(b) .
|
|
|
|
ENDPROC(__hyp_stub_vectors)
|
|
|
|
|