Andre Przywara | 46c3d99 | 2017-01-02 11:48:36 +0000 | [diff] [blame] | 1 | @ |
| 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 Przywara | f9872df | 2025-03-23 11:35:36 +0000 | [diff] [blame] | 19 | @ ${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 Przywara | 46c3d99 | 2017-01-02 11:48:36 +0000 | [diff] [blame] | 22 | @ ${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 Zheng | bb769d6 | 2018-07-21 16:20:22 +0800 | [diff] [blame] | 31 | #include <config.h> |
| 32 | |
Andre Przywara | 46c3d99 | 2017-01-02 11:48:36 +0000 | [diff] [blame] | 33 | .text |
Andre Przywara | f9872df | 2025-03-23 11:35:36 +0000 | [diff] [blame] | 34 | b start32 // this is "tst x0, x0" in AArch64 |
| 35 | .word 0x14000047 // this is "b reset" in AArch64 |
Andre Przywara | 46c3d99 | 2017-01-02 11:48:36 +0000 | [diff] [blame] | 36 | |
Andre Przywara | f9872df | 2025-03-23 11:35:36 +0000 | [diff] [blame] | 37 | .space 0x78 // gap distance set by the common |
| 38 | // encoding of the first instruction |
| 39 | fel_stash_addr: |
| 40 | .word fel_stash - . // distance to fel_stash buffer |
| 41 | |
| 42 | start32: |
| 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 Przywara | 578321c | 2025-02-10 00:25:29 +0000 | [diff] [blame] | 52 | mrs lr, SP_irq |
| 53 | str lr, [r0, #20] |
Andre Przywara | f9872df | 2025-03-23 11:35:36 +0000 | [diff] [blame] | 54 | 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 Przywara | 43aa170 | 2025-01-05 21:51:59 +0000 | [diff] [blame] | 58 | //#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 Przywara | 43aa170 | 2025-01-05 21:51:59 +0000 | [diff] [blame] | 63 | str lr, [r0, #24] |
Andre Przywara | 578321c | 2025-02-10 00:25:29 +0000 | [diff] [blame] | 64 | mrc p15, 0, lr, c12, c12, 7 // ICC_IGRPEN1 |
| 65 | str lr, [r0, #28] |
Andre Przywara | 43aa170 | 2025-01-05 21:51:59 +0000 | [diff] [blame] | 66 | 1: |
| 67 | //#endif |
Andre Przywara | f9872df | 2025-03-23 11:35:36 +0000 | [diff] [blame] | 68 | |
| 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 Zheng | bb769d6 | 2018-07-21 16:20:22 +0800 | [diff] [blame] | 76 | #else |
Andre Przywara | f9872df | 2025-03-23 11:35:36 +0000 | [diff] [blame] | 77 | ldr r0, =CONFIG_TEXT_BASE |
Icenowy Zheng | bb769d6 | 2018-07-21 16:20:22 +0800 | [diff] [blame] | 78 | #endif |
Andre Przywara | f9872df | 2025-03-23 11:35:36 +0000 | [diff] [blame] | 79 | str r0, [r1] // store start address in RVBAR |
Andre Przywara | 46c3d99 | 2017-01-02 11:48:36 +0000 | [diff] [blame] | 80 | 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 |
| 86 | 1: wfi |
| 87 | b 1b |