All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Alastair D'Silva <alastair@d-silva.org>
Cc: u-boot@lists.u-boot-project.org, Tom Rini <trini@konsulko.com>,
	Hans de Goede <hdegoede@redhat.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Jaehoon Chung <jh80.chung@samsung.com>,
	Lukasz Majewski <lukma@nabladev.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Peng Fan <peng.fan@nxp.com>,
	Tanmay Kathpalia <tanmay.kathpalia@altera.com>,
	Yixun Lan <dlan@kernel.org>, Yixun Lan <dlan@gentoo.org>,
	Enzo Adriano <enzo.adriano.code@gmail.com>,
	Junhui Liu <junhui.liu@pigmoral.tech>
Subject: Re: [PATCH 13/26] sunxi: fel: Add Allwinner A733 ERET FEL return support
Date: Fri, 20 Nov 2026 00:53:34 +0100	[thread overview]
Message-ID: <20261120005334.655e5170@ryzen.lan> (raw)
In-Reply-To: <20261113023236.569054-14-alastair@d-silva.org>

Hi,

On Fri, 13 Nov 2026 13:32:23 +1100
Alastair D'Silva <alastair@d-silva.org> wrote:

> On the Allwinner A733, boot0.h latches CLU0_CPU0_CTRL_REG to AArch64
> and sunxi-fel uses SRAM swap buffers across 0x47000.

Sorry, but what? Claude, is that you? What's that supposed to mean, how
are those two statements related and why does that matter?

> Rather than arming
> R_CPUCFG hotplug magic and warm-resetting through BROM, drop directly

Why?

> to Secure AArch32 SVC via ERET after draining UART0 TX, and install an

I am afraid this doesn't really work: even though the core resets in
AArch32 secure SVC, this isn't the same as ERETing into that
mode: the former is PL3, so the highest implemented exception level, the
latter is not. This is admittedly a weird corner case of AArch32
firmware operation on Armv8 hardware, I guess trying to somewhat
retro-fit the clear ARMv8 exception levels into the slightly murky
situation on ARMv7.

The difference is that some operations are reserved for running in the
highest implemented exception level: writing CNTFRQ_EL0, and writing to
RVBAR are prominent examples. The former is bad already, but the latter
prevents switching to AArch64, which is crucial for our boot flow.

So again, why is this needed, and what is the problem with the existing
way of doing things?

> EL3 SMC vector in SH_SRAM (0x00080000) so sunxi-fel can re-enter AArch64
> EL3 for BL31.
> 
> Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
> ---
>  arch/arm/cpu/armv8/fel_utils.S | 113 ++++++++++++++++++++++++++++++++-
>  1 file changed, 112 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/cpu/armv8/fel_utils.S b/arch/arm/cpu/armv8/fel_utils.S
> index ccddfaaf04c..fc0e0b93c37 100644
> --- a/arch/arm/cpu/armv8/fel_utils.S
> +++ b/arch/arm/cpu/armv8/fel_utils.S
> @@ -11,6 +11,30 @@
>  #include <asm/system.h>
>  #include <linux/linkage.h>
>  #include <asm/arch/cpu.h>
> +#include <asm/arch/serial.h>
> +
> +#ifdef CONFIG_MACH_SUN60I_A733
> +#define A733_FEL_EL3_VBAR		SUNXI_FEL_EL3_VBAR
> +#define A733_FEL_EL3_A32_SYNC_OFF	0x600
> +#define UART_LSR_OFFSET			0x14
> +#define UART_LSR_TEMT_BIT		6
> +#define SCR_EL3_IRQ_EN			(1 << 1)
> +#define SCR_EL3_FIQ_EN			(1 << 2)
> +#define SCR_EL3_FEL_A32_CLEAR		(SCR_EL3_RW_AARCH64 | \
> +					 SCR_EL3_SMD_DIS | \
> +					 SCR_EL3_EA_EN | \
> +					 SCR_EL3_FIQ_EN | \
> +					 SCR_EL3_IRQ_EN | \
> +					 SCR_EL3_NS_EN)
> +#define ICC_SRE_EL3_ENABLE_ALL		0xf
> +#define ICC_SRE_EL1_ENABLE_ALL		0x7
> +#define ICC_IGRPEN1_EL3_ENABLE_ALL	0x3
> +#define SPSR_EL3_A32_SVC_MASKED		(SPSR_EL_ASYN_MASK | \
> +					 SPSR_EL_IRQ_MASK | \
> +					 SPSR_EL_FIQ_MASK | \
> +					 SPSR_EL_M_AARCH32 | \
> +					 SPSR_EL_M_SVC)
> +#endif
>  
>  /*
>   * We don't overwrite save_boot_params() here, to save the FEL state upon
> @@ -40,6 +64,89 @@ ENTRY(return_to_fel)
>  	adr	x1, fel_stash_addr	// to find the fel_stash address in AA32
>  	str	w2, [x1]
>  
> +#if defined(CONFIG_MACH_SUN60I_A733)
> +#if CONFIG_IS_ENABLED(SERIAL)
> +	/* Drain UART0 TX FIFO before dropping to AArch32 */

Why? And why is this not done in C?

> +	ldr	x2, =SUNXI_UART0_BASE
> +	mov	w1, #0x10000
> +2:	ldr	w0, [x2, #UART_LSR_OFFSET]
> +	tbnz	w0, #UART_LSR_TEMT_BIT, 3f
> +	subs	w1, w1, #1
> +	b.ne	2b

Yeah, no, this seems like another case of an LLM going wild in writing
assembly code, and adding many hard-to-parse lines (without comments),
to solve an issue that isn't even properly justified.

Cheers,
Andre

> +3:
> +#endif
> +
> +	/*
> +	 * On A733, boot0.h latches CLU0_CPU0_CTRL_REG to AArch64 and FEL uses
> +	 * SRAM swap buffers across 0x47000. Rather than warm-resetting through
> +	 * the BROM hotplug path, drop directly to Secure AArch32 SVC via ERET
> +	 * and install an EL3 SMC vector in SH_SRAM outside the FEL swap buffer
> +	 * so sunxi-fel can re-enter AArch64 EL3 for BL31.
> +	 */
> +	adr	x4, el3_a32_sync
> +	adr	x5, el3_a32_sync_end
> +	ldr	x6, =(A733_FEL_EL3_VBAR + A733_FEL_EL3_A32_SYNC_OFF)
> +	mov	x8, x6
> +4:	ldr	w7, [x4], #4
> +	str	w7, [x6], #4
> +	cmp	x4, x5
> +	b.lo	4b
> +
> +5:	dc	cvau, x8
> +	add	x8, x8, #64
> +	cmp	x8, x6
> +	b.lo	5b
> +	dsb	ish
> +	ic	iallu
> +	dsb	ish
> +	isb
> +
> +	ldr	x0, =A733_FEL_EL3_VBAR
> +	msr	vbar_el3, x0
> +
> +	mrs	x1, ICC_SRE_EL3
> +	orr	x1, x1, #ICC_SRE_EL3_ENABLE_ALL
> +	msr	ICC_SRE_EL3, x1
> +	isb
> +
> +	mrs	x1, ICC_SRE_EL1
> +	orr	x1, x1, #ICC_SRE_EL1_ENABLE_ALL
> +	msr	ICC_SRE_EL1, x1
> +	mov	x1, #ICC_IGRPEN1_EL3_ENABLE_ALL
> +	msr	ICC_IGRPEN1_EL3, x1
> +
> +	mrs	x0, scr_el3
> +	mov	x1, #SCR_EL3_FEL_A32_CLEAR
> +	bic	x0, x0, x1
> +	msr	scr_el3, x0
> +
> +	mov	x0, #SPSR_EL3_A32_SVC_MASKED
> +	msr	spsr_el3, x0
> +
> +	adr	x0, back_in_32
> +	msr	elr_el3, x0
> +
> +	dsb	sy
> +	isb
> +	eret
> +
> +	.align	2
> +el3_a32_sync:
> +	mrs	x9, scr_el3
> +	mov	x10, #SCR_EL3_RW_AARCH64
> +	orr	x9, x9, x10
> +	msr	scr_el3, x9
> +	isb
> +	cbnz	w0, 6f
> +	movz	w0, #(CONFIG_SUNXI_BL31_BASE & 0xffff)
> +	movk	w0, #(CONFIG_SUNXI_BL31_BASE >> 16), lsl #16
> +6:	uxtw	x0, w0
> +	ic	iallu
> +	dsb	sy
> +	isb
> +	br	x0
> +el3_a32_sync_end:
> +#else
>  	ldr	w0, =0xfa50392f		// CPU hotplug magic
>  #if defined(CONFIG_MACH_SUN50I_H616) || defined(CONFIG_MACH_SUN50I_A133) || \
>      defined(CONFIG_MACH_SUN55I_A523)
> @@ -63,6 +170,7 @@ ENTRY(return_to_fel)
>  	isb	sy
>  1:	wfi
>  	b	1b
> +#endif
>  
>  fel_stash_addr:			// must immediately precede back_in_32:
>  	.word   0x00000000	// receives fel_stash addr, by AA64 code above
> @@ -71,6 +179,9 @@ fel_stash_addr:			// must immediately precede back_in_32:
>  back_in_32:
>  	.word	0xe51f000c	// ldr	r0, [pc, #-12]  ; load fel_stash address
>  	.word	0xe5901008	// ldr	r1, [r0, #8]
> +#ifdef CONFIG_MACH_SUN60I_A733
> +	.word	0xe38110c0	// orr	r1, r1, #0xc0   ; mask IRQ/FIQ in thunk
> +#endif
>  	.word	0xe129f001	// msr	CPSR_fc, r1
>  	.word	0xf57ff06f	// isb
>  	.word	0xe590d000	// ldr	sp, [r0]
> @@ -82,7 +193,7 @@ back_in_32:
>  	.word	0xe590100c	// ldr	r1, [r0, #12]
>  	.word	0xee011f10	// mcr	15, 0, r1, cr1, cr0, {0}  ; SCTLR
>  	.word	0xf57ff06f	// isb
> -#ifdef CONFIG_MACH_SUN55I_A523
> +#if defined(CONFIG_MACH_SUN55I_A523) || defined(CONFIG_MACH_SUN60I_A733)
>  	.word	0xe5901018	// ldr  r1, [r0, #24]
>  	.word	0xee041f16	// mcr  15, 0, r1, cr4, cr6, {0}; ICC_PMR
>  	.word	0xe590101c	// ldr  r1, [r0, #28]


  reply	other threads:[~2026-11-19 23:53 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  2:32 [PATCH 00/26] sunxi: Add Allwinner A733 (sun60i) and Orange Pi 4 Pro support Alastair D'Silva
2026-11-13  2:32 ` [PATCH 01/26] power: regulator: axp: Fix AXP318W ELDO voltage mask Alastair D'Silva
2026-11-20  0:06   ` Andre Przywara
2026-11-13  2:32 ` [PATCH 02/26] power: pmic: axp: Fix AXP318W sysreset shutdown register Alastair D'Silva
2026-11-13  2:32 ` [PATCH 03/26] power: axp: Extend AXP318W SPL support with DCDC6/7 and LDOs Alastair D'Silva
2026-11-13  2:32 ` [PATCH 04/26] dt-bindings: clk: sun60i-a733-ccu: Add Allwinner A733 support Alastair D'Silva
2026-11-13  2:32 ` [PATCH 05/26] mmc: sunxi: Scale data transfer timeout with transfer size Alastair D'Silva
2026-11-13  2:32 ` [PATCH 06/26] gpio: a733: add initial support Alastair D'Silva
2026-11-13  2:32 ` [PATCH 07/26] pinctrl: sunxi: " Alastair D'Silva
2026-11-13  2:32 ` [PATCH 08/26] clock: reset: " Alastair D'Silva
2026-11-13  2:32 ` [PATCH 09/26] clock: a733: implement support for mmc/uart Alastair D'Silva
2026-11-13  2:32 ` [PATCH 10/26] sunxi: mmc: enable support for A733 Alastair D'Silva
2026-11-13  2:32 ` [PATCH 11/26] sunxi: a733: uart: setup serial console Alastair D'Silva
2026-11-13  2:32 ` [PATCH 12/26] arm64: spl: Support disposable .init.rodata section after _image_binary_end Alastair D'Silva
2026-11-13  2:32 ` [PATCH 13/26] sunxi: fel: Add Allwinner A733 ERET FEL return support Alastair D'Silva
2026-11-19 23:53   ` Andre Przywara [this message]
2026-11-13  2:32 ` [PATCH 14/26] sunxi: dram: a733: Add ARC PMU register, ABI, and build definitions Alastair D'Silva
2026-11-13  2:32 ` [PATCH 15/26] sunxi: dram: a733: Add ARC PMU primitives, clock, telemetry, and CBT Alastair D'Silva
2026-11-13  2:32 ` [PATCH 16/26] sunxi: dram: a733: Add ARC PMU deskew and BIST training firmware Alastair D'Silva
2026-11-13  2:32 ` [PATCH 17/26] sunxi: dram: a733: Add ARC PMU 1D/2D eye " Alastair D'Silva
2026-11-13  2:32 ` [PATCH 18/26] sunxi: dram: a733: Add ARC PMU training state machine Alastair D'Silva
2026-11-13  2:32 ` [PATCH 19/26] sunxi: dram: a733: Add Allwinner A733 LPDDR5 DRAM driver Alastair D'Silva
2026-11-13  2:32 ` [PATCH 20/26] sunxi: sun60i: initial support for A733 SoC Alastair D'Silva
2026-11-13  2:32 ` [PATCH 21/26] doc: sunxi: Document Allwinner A733 LPDDR5 PMU architecture Alastair D'Silva
2026-11-13  2:32 ` [PATCH 22/26] phy: sunxi: Add Allwinner A733 Cadence Combo PHY driver Alastair D'Silva
2026-11-13  2:32 ` [PATCH 23/26] pci: sunxi: Add Allwinner A733 DesignWare PCIe host controller driver Alastair D'Silva
2026-11-13  2:32 ` [PATCH 24/26] sunxi: Add NVMe to distro boot targets Alastair D'Silva
2026-11-13  2:32 ` [PATCH 25/26] arm64: dts: allwinner: add A733 SoC description Alastair D'Silva
2026-11-13  2:32 ` [PATCH 26/26] sunxi: Add Xunlong Orange Pi 4 Pro board support Alastair D'Silva
2026-11-13  7:28 ` [PATCH 00/26] sunxi: Add Allwinner A733 (sun60i) and Orange Pi 4 Pro support Alastair D'Silva
2026-11-20  0:31 ` Andre Przywara

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=20261120005334.655e5170@ryzen.lan \
    --to=andre.przywara@arm.com \
    --cc=alastair@d-silva.org \
    --cc=dlan@gentoo.org \
    --cc=dlan@kernel.org \
    --cc=enzo.adriano.code@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jh80.chung@samsung.com \
    --cc=junhui.liu@pigmoral.tech \
    --cc=lukma@nabladev.com \
    --cc=neil.armstrong@linaro.org \
    --cc=peng.fan@nxp.com \
    --cc=tanmay.kathpalia@altera.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.