serial: amba-pl011: Enable UART in earlycon setup
PATCH 1/1 serial: amba-pl011: Enable UART in earlycon setup
Currently the PL011 driver only enables the UART (by setting UARTEN in REG_CR) in pl011_startup(), so if it is used for earlycon it is relying on the bootrom/firmware having left the UART enabled.
There's no particular reason not to actively enable the UART before using it for earlycon, and the earlycon handling for e.g. the 8250 UART sets up the UART in its setup function, so follow that in the PL011.
This allows use of earlycon with a UART that the firmware hasn't already been using for its own output, but the main motivation is that QEMU will otherwise log a message complaining that the guest is trying to write to a UART it never enabled.
---
NB: I have tested this under QEMU, but I do not have any real PL011-using hardware to hand to test with.
--- drivers/tty/serial/amba-pl011.c | 35 ++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/tty/serial/amba-pl011.c +32 -3
@@ -2700,6 +2700,37 @@ static int pl011_early_read(struct console *con, char *s, unsigned int n)*/ static int __init pl011_early_console_setup (struct earlycon_device *device,const char *opt) +{ +unsigned int cr; + +if (!device->port.membase) +return -ENODEV ; + + device->con->write = pl011_early_write; + device->con->read = pl011_early_read; + +if (device->port.iotype ==UPIO_MEM32 ) + cr =readl (device->port.membase +UART011_CR ); +else + cr =readw (device->port.membase +UART011_CR ); + cr &=UART011_CR_RTS |UART011_CR_DTR ; + cr |= UART01x_CR_UARTEN |UART011_CR_RXE |UART011_CR_TXE ; +if (device->port.iotype ==UPIO_MEM32 ) +writel (cr, device->port.membase +UART011_CR ); +else +writew (cr, device->port.membase +UART011_CR ); + +return 0 ; +} + +OF_EARLYCON_DECLARE (pl011,"arm,pl011" , pl011_early_console_setup); + +/* +* The SBSA UART has no defined control register and is assumed to +* be pre-enabled by firmware, so we do not write to UART011_CR. +*/ +static int __init sbsa_uart_early_console_setup (struct earlycon_device *device, +const char *opt) {if (!device->port.membase)return -ENODEV ;
@@ -2710,9 +2741,7 @@ static int __init pl011_early_console_setup(struct earlycon_device *device,return 0 ; } -OF_EARLYCON_DECLARE (pl011,"arm,pl011" , pl011_early_console_setup); - -OF_EARLYCON_DECLARE (pl011,"arm,sbsa-uart" , pl011_early_console_setup); +OF_EARLYCON_DECLARE (pl011,"arm,sbsa-uart" , sbsa_uart_early_console_setup);/* * On Qualcomm Datacenter Technologies QDF2400 SOCs affected by
Signature · 1 line
2.43.0
Quoted 14 lines · Peter Maydell
Currently the PL011 driver only enables the UART (by setting UARTEN in
REG_CR) inpl011_startup(), so if it is used for earlycon it is relying on the bootrom/firmware having left the UART enabled.There's no particular reason not to actively enable the UART before using it for earlycon, and the earlycon handling for e.g. the 8250 UART sets up the UART in its setup function, so follow that in the PL011.
This allows use of earlycon with a UART that the firmware hasn't already been using for its own output, but the main motivation is that QEMU will otherwise log a message complaining that the guest is trying to write to a UART it never enabled.
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>---
NB: I have tested this under QEMU, but I do not have any real PL011-using hardware to hand to test with.
Looks good to me,
One more question: what is the symptom without this patch with qemu? You mentioned on IRC that qemu may warn about attempting to write to the uart when it is disabled. Would we still get the correct early console output before the uart is enabled?
Arnd
Quoted 21 lines · Arnd Bergmann
Quoted 14 lines · Peter Maydell
Currently the PL011 driver only enables the UART (by setting UARTEN in
REG_CR) inpl011_startup(), so if it is used for earlycon it is relying on the bootrom/firmware having left the UART enabled.There's no particular reason not to actively enable the UART before using it for earlycon, and the earlycon handling for e.g. the 8250 UART sets up the UART in its setup function, so follow that in the PL011.
This allows use of earlycon with a UART that the firmware hasn't already been using for its own output, but the main motivation is that QEMU will otherwise log a message complaining that the guest is trying to write to a UART it never enabled.
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>---
NB: I have tested this under QEMU, but I do not have any real PL011-using hardware to hand to test with.
Quoted 8 lines
Looks good to me,
Acked-by Arnd Bergmann <[email protected]>One more question: what is the symptom without this patch with qemu? You mentioned on IRC that qemu may warn about attempting to write to the uart when it is disabled. Would we still get the correct early console output before the uart is enabled?
The symptom is that if you run QEMU with '-d guest_errors' to ask it to log things the guest does that it thinks are bugs in the guest, then you get a lot of "PL011 data written to disabled UART" warnings. The guest still boots fine, and assuming you directed the logging to a file rather than stdout you see the guest output.
(This is because for PL011 we have deliberately not emulated the hardware behaviour of discarding data when the UART isn't initialized, because we think there is a lot of "my first bare metal hello world program" type code out there that was written against older QEMU versions and not tested on hardware and never enables the PL011, and we figured that making all that code break wasn't a sensible tradeoff for theoretically increased emulation fidelity. For newer UART models where we modelled the enable flag correctly from the start, you would have to explicitly enable. The CMSDK UART model is one example of that.)
I have also sent a QEMU patch to restrict the complaint to "print this once" rather than "print this every time the guest writes to the UART TX register".
thanks
-- PMM
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Arnd Bergmann
On Tue, Feb 10, 2026, at 13:50, Peter Maydell wrote:
One more question: what is the symptom without this patch with qemu? You mentioned on IRC that qemu may warn about attempting to write to the uart when it is disabled. Would we still get the correct early console output before the uart is enabled?
Quoted 5 lines
The symptom is that if you run QEMU with '-d
guest_errors' to ask it to log things the guest does that it thinks are bugs in the guest, then you get a lot of "PL011 data written to disabled UART" warnings. The guest still boots fine, and assuming you directed the logging to a file rather than stdout you see the guest output.
Ok, thanks for the explanation! I still wonder whether we will want a stable backport of the patch. It sounds like it won't be needed for qemu (because most people won't see the harmless warning especially after your patch) or most real hardware (because the bootloader will have initialized the console), but there may still be corner cases that need it.
Arnd