blob: a6d75c32ed9c6b13208bf0c093359014f981b2a6 [file] [log] [blame]
Andre Przywara46c3d992017-01-02 11:48:36 +00001@
2@ ARMv8 RMR reset sequence on Allwinner SoCs.
3@
4@ All 64-bit capable Allwinner SoCs reset in AArch32 (and continue to
5@ exectute the Boot ROM in this state), so we need to switch to AArch64
6@ at some point.
7@ Section G6.2.133 of the ARMv8 ARM describes the Reset Management Register
8@ (RMR), which triggers a warm-reset of a core and can request to switch
9@ into a different execution state (AArch32 or AArch64).
10@ The address at which execution starts after the reset is held in the
11@ RVBAR system register, which is architecturally read-only.
12@ Allwinner provides a writable alias of this register in MMIO space, so
13@ we can easily set the start address of AArch64 code.
14@ This code below switches to AArch64 and starts execution at the specified
15@ start address. It needs to be assembled by an ARM(32) assembler and
16@ the machine code must be inserted as verbatim .word statements into the
17@ beginning of the AArch64 U-Boot code.
18@ To get the encoded bytes, use:
Andre Przywaraf9872df2025-03-23 11:35:36 +000019@ ${CROSS_COMPILE}gcc -c -Iinclude -Iarch/arm/include \
20@ -D__ASSEMBLY__ -DCONFIG_ARM64 \
21@ -o rmr_switch.o arch/arm/mach-sunxi/rmr_switch.S
Andre Przywara46c3d992017-01-02 11:48:36 +000022@ ${CROSS_COMPILE}objdump -d rmr_switch.o
23@
24@ The resulting words should be inserted into the U-Boot file at
25@ arch/arm/include/asm/arch-sunxi/boot0.h.
26@
27@ This file is not build by the U-Boot build system, but provided only as a
28@ reference and to be able to regenerate a (probably fixed) version of this
29@ code found in encoded form in boot0.h.
30
Icenowy Zhengbb769d62018-07-21 16:20:22 +080031#include <config.h>
32
Andre Przywara46c3d992017-01-02 11:48:36 +000033.text
Andre Przywaraf9872df2025-03-23 11:35:36 +000034 b start32 // this is "tst x0, x0" in AArch64
35 .word 0x14000047 // this is "b reset" in AArch64
Andre Przywara46c3d992017-01-02 11:48:36 +000036
Andre Przywaraf9872df2025-03-23 11:35:36 +000037 .space 0x78 // gap distance set by the common
38 // encoding of the first instruction
39fel_stash_addr:
40 .word fel_stash - . // distance to fel_stash buffer
41
42start32:
43 adr r0, fel_stash_addr // absolute location of fel_stash_addr
44 ldr r1, fel_stash_addr // distance to actual fel_stash
45 add r0, r0, r1 // real address of fel_stash
46
47 /* save the current state as needed by the BROM for a later return */
48 str sp, [r0]
49 str lr, [r0, #4]
50 mrs lr, CPSR
51 str lr, [r0, #8]
Andre Przywara578321c2025-02-10 00:25:29 +000052 mrs lr, SP_irq
53 str lr, [r0, #20]
Andre Przywaraf9872df2025-03-23 11:35:36 +000054 mrc p15, 0, lr, cr1, cr0, 0 // SCTLR
55 str lr, [r0, #12]
56 mrc p15, 0, lr, cr12, cr0, 0 // VBAR
57 str lr, [r0, #16]
Andre Przywara43aa1702025-01-05 21:51:59 +000058//#ifdef CONFIG_MACH_SUN55I_A523
59 mrc p15, 0, lr, cr12, cr12, 5 // ICC_SRE
60 tst lr, #1
61 beq 1f
62 mrc p15, 0, lr, c4, c6, 0 // ICC_PMR
Andre Przywara43aa1702025-01-05 21:51:59 +000063 str lr, [r0, #24]
Andre Przywara578321c2025-02-10 00:25:29 +000064 mrc p15, 0, lr, c12, c12, 7 // ICC_IGRPEN1
65 str lr, [r0, #28]
Andre Przywara43aa1702025-01-05 21:51:59 +0000661:
67//#endif
Andre Przywaraf9872df2025-03-23 11:35:36 +000068
69 ldr r1, =CONFIG_SUNXI_RVBAR_ADDRESS
70 ldr r0, =SUNXI_SRAMC_BASE
71 ldr r0, [r0, #36] // SRAM_VER_REG
72 ands r0, r0, #0xff
73 ldrne r1, =CONFIG_SUNXI_RVBAR_ALTERNATIVE
74#ifdef CONFIG_XPL_BUILD
75 ldr r0, =CONFIG_SPL_TEXT_BASE
Icenowy Zhengbb769d62018-07-21 16:20:22 +080076#else
Andre Przywaraf9872df2025-03-23 11:35:36 +000077 ldr r0, =CONFIG_TEXT_BASE
Icenowy Zhengbb769d62018-07-21 16:20:22 +080078#endif
Andre Przywaraf9872df2025-03-23 11:35:36 +000079 str r0, [r1] // store start address in RVBAR
Andre Przywara46c3d992017-01-02 11:48:36 +000080 dsb sy
81 isb sy
82 mrc 15, 0, r0, cr12, cr0, 2 @ read RMR register
83 orr r0, r0, #3 @ request reset in AArch64
84 mcr 15, 0, r0, cr12, cr0, 2 @ write RMR register
85 isb sy
861: wfi
87 b 1b