From: Jules Maselbas <jmaselbas@zdiv.net>
To: barebox@lists.infradead.org
Cc: Jules Maselbas <jmaselbas@zdiv.net>
Subject: [RFC PATCH 04/11] sunxi: Add lowlevel switch to aarch64
Date: Thu, 11 May 2023 01:37:04 +0200 [thread overview]
Message-ID: <20230510233711.37345-5-jmaselbas@zdiv.net> (raw)
In-Reply-To: <20230510233711.37345-1-jmaselbas@zdiv.net>
Allwinner A64 SoC (and probably others) boots in 32-bits mode. Switching
to aarch64 is achieved by writing to the Reset Management Register (RMR)
which can be accessed through the memory space thanks to an alias.
On A64 this alias is located at 0x017000a0
---
arch/arm/include/asm/barebox.lds.h | 2 ++
arch/arm/mach-sunxi/Kconfig | 5 ++++
arch/arm/mach-sunxi/Makefile | 2 ++
arch/arm/mach-sunxi/rmr_switch.S | 47 ++++++++++++++++++++++++++++++
include/mach/sunxi/barebox.lds.h | 6 ++++
include/mach/sunxi/rmr_switch.h | 10 +++++++
6 files changed, 72 insertions(+)
create mode 100644 arch/arm/mach-sunxi/rmr_switch.S
create mode 100644 include/mach/sunxi/barebox.lds.h
create mode 100644 include/mach/sunxi/rmr_switch.h
diff --git a/arch/arm/include/asm/barebox.lds.h b/arch/arm/include/asm/barebox.lds.h
index a5c74381d8..f94290128e 100644
--- a/arch/arm/include/asm/barebox.lds.h
+++ b/arch/arm/include/asm/barebox.lds.h
@@ -2,6 +2,8 @@
#if defined CONFIG_ARCH_EP93XX
#include <mach/ep93xx/barebox.lds.h>
+#elif defined CONFIG_ARCH_SUNXI
+#include <mach/sunxi/barebox.lds.h>
#endif
#ifdef CONFIG_CPU_32
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 0e8d83fedd..e28f04c354 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -4,6 +4,11 @@ config ARCH_TEXT_BASE
hex
default 0x0
+config SUNXI_RVBAR_IOMAP
+ hex
+ default 0x017000a0 if ARCH_SUN50I_A64
+ # default 0x09010040 if ARCH_SUN50I_H5
+
menuconfig SUNXI_MULTI_BOARDS
bool "Allwinner boards"
select HAVE_PBL_MULTI_IMAGES
diff --git a/arch/arm/mach-sunxi/Makefile b/arch/arm/mach-sunxi/Makefile
index d678973ca2..e7fa23c832 100644
--- a/arch/arm/mach-sunxi/Makefile
+++ b/arch/arm/mach-sunxi/Makefile
@@ -1,2 +1,4 @@
obj-y += sunxi.o
lwl-y += cpu_init.o
+
+pbl-$(CONFIG_CPU_64) += rmr_switch.o
diff --git a/arch/arm/mach-sunxi/rmr_switch.S b/arch/arm/mach-sunxi/rmr_switch.S
new file mode 100644
index 0000000000..bfe3b75e3a
--- /dev/null
+++ b/arch/arm/mach-sunxi/rmr_switch.S
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * ARMv8 RMR reset sequence on Allwinner SoCs.
+ *
+ * All 64-bit capable Allwinner SoCs reset in AArch32 (and continue to
+ * exectute the Boot ROM in this state), so we need to switch to AArch64
+ * at some point.
+ * Section G6.2.133 of the ARMv8 ARM describes the Reset Management Register
+ * (RMR), which triggers a warm-reset of a core and can request to switch
+ * into a different execution state (AArch32 or AArch64).
+ * The address at which execution starts after the reset is held in the
+ * RVBAR system register, which is architecturally read-only.
+ * Allwinner provides a writable alias of this register in MMIO space, so
+ * we can easily set the start address of AArch64 code.
+ * This code below switches to AArch64 and starts execution at the specified
+ * start address.
+ *
+ * This file has been adapted from U-Boot code sources:
+ * - arch/arm/mach-sunxi/rmr_switch.S
+ * - arch/arm/include/asm/arch-sunxi/boot0.h.
+ *
+ * The aarch32 assembly has already been assembled and are inserted verbatime
+ * as .word statements (the asm source is commented for each statement).
+ *
+ */
+
+#include <config.h>
+#include <linux/linkage.h>
+
+.section .text_head_rmr_switch, "x"
+ENTRY(sunxi_rmr_switch) /* arm32 arm64 */
+ .word 0xeb000000 /* bl .+8 subs x0, x0, x0 */
+ b end /* .word 0x1400000c b end */
+ .word 0xe59f0020 /* ldr r0, [pc, #32] ; rvbar */
+ .word 0xe580e000 /* str lr, [r0] */
+ .word 0xf57ff04f /* dsb sy */
+ .word 0xf57ff06f /* isb syo */
+ .word 0xee1c0f50 /* mrc 15, 0, r0, cr12, cr0, {2} */
+ .word 0xe3800003 /* orr r0, r0, #3 */
+ .word 0xee0c0f50 /* mcr 15, 0, r0, cr12, cr0, {2} */
+ .word 0xf57ff06f /* isb sy */
+ .word 0xe320f003 /* 1b: wfi */
+ .word 0xeafffffd /* b 1b */
+ .word CONFIG_SUNXI_RVBAR_IOMAP
+ .align 3 /* prevent linker script from adding padding for aligment */
+end: /* fall-through */
+ENDPROC(sunxi_rmr_switch)
diff --git a/include/mach/sunxi/barebox.lds.h b/include/mach/sunxi/barebox.lds.h
new file mode 100644
index 0000000000..e04c713611
--- /dev/null
+++ b/include/mach/sunxi/barebox.lds.h
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/* theses two sections should only be needed for the pbl */
+#define ENTRY_HEADER \
+ *(.text_head_egon_header*) \
+ *(.text_head_rmr_switch*)
diff --git a/include/mach/sunxi/rmr_switch.h b/include/mach/sunxi/rmr_switch.h
new file mode 100644
index 0000000000..2ecbd81d57
--- /dev/null
+++ b/include/mach/sunxi/rmr_switch.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __MACH_RMR_SWITCH_H
+#define __MACH_RMR_SWITCH_H
+
+/* 64-bits Allwinner SoCs reset in AArch32 and need to switch to AArch64 */
+extern const u32 sunxi_rmr_switch[];
+#define sunxi_switch_to_aarch64() __keep_symbolref(sunxi_rmr_switch)
+
+#endif
--
2.40.0
next prev parent reply other threads:[~2023-05-10 23:39 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-10 23:37 [RFC PATCH 00/11] Add support for Allwinner (sunxi) A64 SoC Jules Maselbas
2023-05-10 23:37 ` [RFC PATCH 01/11] scripts: Add Allwinner eGON image support Jules Maselbas
2023-05-11 7:25 ` Sascha Hauer
2023-05-11 20:14 ` Jules Maselbas
2023-05-18 18:47 ` Ahmad Fatoum
2023-05-19 9:40 ` Jules Maselbas
2023-05-10 23:37 ` [RFC PATCH 02/11] sunxi: introduce mach-sunxi Jules Maselbas
2023-05-11 7:27 ` Sascha Hauer
2023-05-18 18:46 ` Ahmad Fatoum
2023-05-19 10:09 ` Jules Maselbas
2023-05-22 10:32 ` Ahmad Fatoum
2023-05-10 23:37 ` [RFC PATCH 03/11] ARM: dls: Add ENTRY_HEADER macro to add .text section Jules Maselbas
2023-05-18 18:49 ` Ahmad Fatoum
2023-05-10 23:37 ` Jules Maselbas [this message]
2023-05-18 19:01 ` [RFC PATCH 04/11] sunxi: Add lowlevel switch to aarch64 Ahmad Fatoum
2023-05-10 23:37 ` [RFC PATCH 05/11] arm: sunxi: Add debug_ll Jules Maselbas
2023-05-18 19:05 ` Ahmad Fatoum
2023-05-19 10:36 ` Jules Maselbas
2023-05-10 23:37 ` [RFC PATCH 06/11] clk: Add clock driver for sun50i-a64 Jules Maselbas
2023-05-18 19:06 ` Ahmad Fatoum
2023-05-10 23:37 ` [RFC PATCH 07/11] pinctrl: Add sun50i-a64 pinctrl driver Jules Maselbas
2023-05-18 19:10 ` Ahmad Fatoum
2023-05-19 10:52 ` Jules Maselbas
2023-05-10 23:37 ` [RFC PATCH 08/11] mci: Add sunxi-mmc driver Jules Maselbas
2023-05-18 19:26 ` Ahmad Fatoum
2023-05-19 5:51 ` Sascha Hauer
2023-05-19 6:51 ` Ahmad Fatoum
2023-05-10 23:37 ` [RFC PATCH 09/11] arm: sunxi: Add sun50i SDRAM init Jules Maselbas
2023-05-11 7:39 ` Sascha Hauer
2023-05-10 23:37 ` [RFC PATCH 10/11] arm: boards: sunxi: Add initial support for the pinephone Jules Maselbas
2023-05-18 19:39 ` Ahmad Fatoum
2023-05-10 23:37 ` [RFC PATCH 11/11] arm: boards: sunxi: Add pine64 board Jules Maselbas
2023-05-18 19:44 ` Ahmad Fatoum
2023-05-19 16:30 ` Jules Maselbas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230510233711.37345-5-jmaselbas@zdiv.net \
--to=jmaselbas@zdiv.net \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox