From: Jules Maselbas <jmaselbas@zdiv.net>
To: barebox@lists.infradead.org
Cc: Jules Maselbas <jmaselbas@zdiv.net>
Subject: [PATCH v2 05/13] ARM: sunxi: Add lowlevel switch to aarch64
Date: Thu, 25 May 2023 01:43:20 +0200 [thread overview]
Message-ID: <20230524234328.82741-6-jmaselbas@zdiv.net> (raw)
In-Reply-To: <20230524234328.82741-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
Signed-off-by: Jules Maselbas <jmaselbas@zdiv.net>
---
rfc->v2:
- code is no longer assembled from .S, it now an array of 16 u32
- added 3 nops at the end of padding (aligning the header on 16*4 bytes)
- the code can be "modified" for other rvbar addresses
include/mach/sunxi/rmr_switch.h | 50 +++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 include/mach/sunxi/rmr_switch.h
diff --git a/include/mach/sunxi/rmr_switch.h b/include/mach/sunxi/rmr_switch.h
new file mode 100644
index 0000000000..f136b11e46
--- /dev/null
+++ b/include/mach/sunxi/rmr_switch.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef MACH_SUNXI_RMR_SWITCH_H
+#define MACH_SUNXI_RMR_SWITCH_H
+
+/*
+ * ARMv8 RMR reset sequence on Allwinner SoCs.
+ *
+ * All 64-bit capable Allwinner SoCs reset in AArch32 (and continue to
+ * execute 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).
+ *
+ */
+#define SUNXI_RMR_SWITCH_CODE(rvbar_addr) { \
+ 0xeb000000, /* bl .+8 subs x0, x0, x0 */ \
+ 0x1400000c, /* .word 0x1400000c b end */ \
+ 0xe59f0020, /* ldr r0, [pc, #32] ; rvbar */ \
+ 0xe580e000, /* str lr, [r0] */ \
+ 0xf57ff04f, /* dsb sy */ \
+ 0xf57ff06f, /* isb syo */ \
+ 0xee1c0f50, /* mrc 15, 0, r0, cr12, cr0, {2} */ \
+ 0xe3800003, /* orr r0, r0, #3 */ \
+ 0xee0c0f50, /* mcr 15, 0, r0, cr12, cr0, {2} */ \
+ 0xf57ff06f, /* isb sy */ \
+ 0xe320f003, /* 1b: wfi */ \
+ 0xeafffffd, /* b 1b */ \
+ rvbar_addr, \
+ 0xd503201f, 0xd503201f, 0xd503201f } /* nop * 3 */
+#define sunxi_switch_to_aarch64(section, rvbar_addr) { \
+ __section(section) static const u32 rmr_switch[] = \
+ SUNXI_RMR_SWITCH_CODE(rvbar_addr); \
+ __keep_symbolref(rmr_switch); \
+ }
+
+#endif
--
2.40.1
next prev parent reply other threads:[~2023-05-24 23:45 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-24 23:43 [PATCH v2 00/13] Add support for Allwinner (sunxi) A64 SoC Jules Maselbas
2023-05-24 23:43 ` [PATCH v2 01/13] Documentation: sunxi: Add some documentation Jules Maselbas
2023-05-29 9:24 ` Jules Maselbas
2023-05-24 23:43 ` [PATCH v2 02/13] scripts: Add Allwinner eGON image support Jules Maselbas
2023-06-16 22:00 ` Marco Felsch
2023-06-17 7:25 ` Jules Maselbas
2023-06-20 4:52 ` Marco Felsch
2023-06-21 8:26 ` Sascha Hauer
2023-05-24 23:43 ` [PATCH v2 03/13] ARM: sunxi: introduce mach-sunxi Jules Maselbas
2023-05-24 23:43 ` [PATCH v2 04/13] ARM: lds: Add SoC specific sections to go before .text_head_prologue Jules Maselbas
2023-06-01 6:34 ` Ahmad Fatoum
2023-06-01 21:20 ` Jules Maselbas
2023-05-24 23:43 ` Jules Maselbas [this message]
2023-05-24 23:43 ` [PATCH v2 06/13] ARM: sunxi: Add debug_ll Jules Maselbas
2023-05-24 23:43 ` [PATCH v2 07/13] clk: Add clock driver for sun50i-a64 Jules Maselbas
2023-05-24 23:43 ` [PATCH v2 08/13] pinctrl: Add sun50i-a64 pinctrl driver Jules Maselbas
2023-05-24 23:43 ` [PATCH v2 09/13] mci: Add sunxi-mmc driver Jules Maselbas
2023-05-30 8:14 ` Sascha Hauer
2023-06-01 6:15 ` Jules Maselbas
2023-06-01 8:35 ` Sascha Hauer
2023-05-24 23:43 ` [PATCH v2 10/13] ARM: sunxi: Add sun50i SDRAM init Jules Maselbas
2023-05-24 23:43 ` [PATCH v2 11/13] ARM: boards: sunxi: Add initial support for the pinephone Jules Maselbas
2023-05-30 8:42 ` Sascha Hauer
2023-06-01 5:50 ` Jules Maselbas
2023-06-01 6:00 ` Ahmad Fatoum
2023-06-01 6:19 ` Jules Maselbas
2023-06-01 6:36 ` Ahmad Fatoum
2023-06-01 7:09 ` Ahmad Fatoum
2023-05-24 23:43 ` [PATCH v2 12/13] ARM: boards: sunxi: Add pine64 board Jules Maselbas
2023-05-24 23:43 ` [PATCH v2 13/13] ARM: sunxi: xload: Add helpers for chain-loading from SD-card 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=20230524234328.82741-6-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