Skip to contentSkip to conversation

x86/boot: Enable earlyprintk on MMIO (8-bit)

PATCH In review Andy Shevchenko 2 participants 16 messages May 2, 2025 – May 7, 2025 x86

lore
Share & tools
lore
#2 lore raw

PATCH 2/6 x86/boot: Introduce helpers for serial I/O

In reply to Andy Shevchenko

As preparatory to enable earlyprintk on non-standard ports on x86, introduce serial_in() and serial_out() helpers to perform serial I/O.

No functional change intended.

---
 arch/x86/boot/boot.h                          |  2 +
 .../boot/compressed/early_serial_console.c    |  3 +
 arch/x86/boot/compressed/misc.c               |  4 +-
 arch/x86/boot/compressed/misc.h               |  4 ++
 arch/x86/boot/early_serial_console.c          | 63 +++++++++++++------
 arch/x86/boot/tty.c                           |  7 ++-
 6 files changed, 61 insertions(+), 22 deletions(-)
arch/x86/boot/boot.h +2 -0
index 753f429b28cb..6688c2053707 100644
@@ -274,6 +274,8 @@ int check_knl_erratum(void);
 int validate_cpu(void);
 
 /* early_serial_console.c */
+extern unsigned int (*serial_in)(unsigned long addr, int offset);
+extern void (*serial_out)(unsigned long addr, int offset, int value);
 extern unsigned long early_serial_base;
 void console_init(void);
 
arch/x86/boot/compressed/early_serial_console.c +3 -0
index 5b8db03f40ad..a5e0459c3d2f 100644
@@ -1,5 +1,8 @@
 #include "misc.h"
 
+unsigned int (*serial_in)(unsigned long addr, int offset);
+void (*serial_out)(unsigned long addr, int offset, int value);
+
 /* This might be accessed before .bss is cleared, so use .data instead. */
 unsigned long early_serial_base __section(".data");
 
arch/x86/boot/compressed/misc.c +2 -2
index 94b5991da001..056fa5f01598 100644
@@ -109,10 +109,10 @@ static void serial_putchar(int ch)
 {
 	unsigned timeout = 0xffff;
 
-	while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
+	while ((serial_in(early_serial_base, LSR) & XMTRDY) == 0 && --timeout)
 		cpu_relax();
 
-	outb(ch, early_serial_base + TXR);
+	serial_out(early_serial_base, TXR, ch);
 }
 
 void __putstr(const char *s)
arch/x86/boot/compressed/misc.h +4 -0
index f083360c84c1..a70e5f31765b 100644
@@ -127,9 +127,13 @@ extern unsigned char _pgtable[];
 
 #ifdef CONFIG_EARLY_PRINTK
 /* early_serial_console.c */
+extern unsigned int (*serial_in)(unsigned long addr, int offset);
+extern void (*serial_out)(unsigned long addr, int offset, int value);
 extern unsigned long early_serial_base;
 void console_init(void);
 #else
+static unsigned int (*serial_in)(unsigned long addr, int offset);
+static void (*serial_out)(unsigned long addr, int offset, int value);
 static const unsigned long early_serial_base;
 static inline void console_init(void)
 { }
arch/x86/boot/early_serial_console.c +45 -18

101 lines not on this page · raw message

arch/x86/boot/tty.c +5 -2
index e2ab8b8076ef..eb0eacd88db7 100644
@@ -13,6 +13,9 @@
 
 #include "boot.h"
 
+unsigned int (*serial_in)(unsigned long addr, int offset);
+void (*serial_out)(unsigned long addr, int offset, int value);
+
 unsigned long early_serial_base;
 
 #define XMTRDY          0x20
@@ -29,10 +32,10 @@ static void __section(".inittext") serial_putchar(int ch)
 {
 	unsigned timeout = 0xffff;
 
-	while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
+	while ((serial_in(early_serial_base, LSR) & XMTRDY) == 0 && --timeout)
 		cpu_relax();
 
-	outb(ch, early_serial_base + TXR);
+	serial_out(early_serial_base, TXR, ch);
 }
 
 static void __section(".inittext") bios_putchar(int ch)
Signature · 1 line
2.47.2
#4 lore raw

PATCH 4/6 x86/boot: Allow longer parameter list for earlyprintk

In reply to Andy Shevchenko

Allow longer parameter list, up to 64 characters, for earlyprintk to support new coming parameters.

If the parsed string is longer than this buffer it will be cut up by the buffer size.

No functional change intended.

Note, that 'console' case is already covered.

---
 arch/x86/boot/early_serial_console.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/early_serial_console.c +1 -1
index fa6520719a1e..6841f14346c2 100644
@@ -84,7 +84,7 @@ static void parse_earlyprintk(void)
 {
 	int baud = DEFAULT_BAUD;
 	unsigned long port = 0;
-	char arg[32];
+	char arg[64];
 	int pos = 0;
 
 	if (cmdline_find_option("earlyprintk", arg, sizeof(arg)) > 0) {
Signature · 1 line
2.47.2
#3 lore raw

PATCH 3/6 x86/boot: Split out parse_serial_port() helper for earlyprintk

In reply to Andy Shevchenko

The newly introduced helper will be used later on to parse serial port in different type of earlyprintk command line arguments.

No functional change intended.

---
 arch/x86/boot/early_serial_console.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
arch/x86/boot/early_serial_console.c +15 -5
index f52a14284854..fa6520719a1e 100644
@@ -66,6 +66,20 @@ static void early_serial_init(unsigned long port, int baud)
 	early_serial_base = port;
 }
 
+static unsigned long parse_serial_port(const char *arg, int off, int *pos)
+{
+	unsigned long port;
+	char *e;
+
+	port = simple_strtoull(arg + off, &e, 16);
+	if (port == 0 || arg + off == e)
+		port = DEFAULT_SERIAL_PORT;
+	else
+		*pos = e - arg;
+
+	return port;
+}
+
 static void parse_earlyprintk(void)
 {
 	int baud = DEFAULT_BAUD;
@@ -91,11 +105,7 @@ static void parse_earlyprintk(void)
 		 *	"ttyS0,115200"
 		 */
 		if (pos == 7 && !strncmp(arg + pos, "0x", 2)) {
-			port = simple_strtoull(arg + pos, &e, 16);
-			if (port == 0 || arg + pos == e)
-				port = DEFAULT_SERIAL_PORT;
-			else
-				pos = e - arg;
+			port = parse_serial_port(arg, pos + 0, &pos);
 			early_serial_use_io_accessors();
 		} else if (!strncmp(arg + pos, "ttyS", 4)) {
 			static const int bases[] = { 0x3f8, 0x2f8 };
Signature · 1 line
2.47.2
#0 lore raw

cover x86/boot: Enable earlyprintk on MMIO (8-bit)

Some of the platforms may have no legacy COM ports and only provide an MMIO accessible UART. Add support for such to earlyprintk for the boot phase of the kernel.

Andy Shevchenko (6):
x86/boot: Convert early_serial_base to unsigned long x86/boot: Introduce helpers for serial I/O
x86/boot: Split out parse_serial_port() helper for earlyprintk x86/boot: Allow longer parameter list for earlyprintk x86/boot: Also share MMIO accessors
x86/boot: Introduce MMIO accessors and their support in earlyprintk

 arch/x86/boot/boot.h                          |   4 +-
 .../boot/compressed/early_serial_console.c    |   5 +-
 arch/x86/boot/compressed/misc.c               |   4 +-
 arch/x86/boot/compressed/misc.h               |   8 +-
 arch/x86/boot/early_serial_console.c          | 114 ++++++++++++++----
 arch/x86/boot/tty.c                           |   9 +-
 arch/x86/include/asm/io.h                     |  65 ----------
 arch/x86/include/asm/shared/io.h              |  68 +++++++++++
 8 files changed, 177 insertions(+), 100 deletions(-)
Signature · 1 line
2.47.2
#5 lore raw

PATCH 5/6 x86/boot: Also share MMIO accessors

For the enabling an arbitrary MMIO for earlyprintk, share MMIO accessors with a boot code.

---
 arch/x86/include/asm/io.h        | 65 ------------------------------
 arch/x86/include/asm/shared/io.h | 68 ++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 65 deletions(-)
arch/x86/include/asm/io.h +0 -65
index e889c3bab5a2..e6ca50fbcbbf 100644
@@ -44,71 +44,6 @@
 #include <asm/shared/io.h>
 #include <asm/special_insns.h>
 
-#define build_mmio_read(name, size, type, reg, barrier) \
-static inline type name(const volatile void __iomem *addr) \
-{ type ret; asm volatile("mov" size " %1,%0":reg (ret) \
-:"m" (*(volatile type __force *)addr) barrier); return ret; }
-
-#define build_mmio_write(name, size, type, reg, barrier) \
-static inline void name(type val, volatile void __iomem *addr) \
-{ asm volatile("mov" size " %0,%1": :reg (val), \
-"m" (*(volatile type __force *)addr) barrier); }
-
-build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
-
-build_mmio_read(__readb, "b", unsigned char, "=q", )
-build_mmio_read(__readw, "w", unsigned short, "=r", )
-build_mmio_read(__readl, "l", unsigned int, "=r", )
-
-build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
-build_mmio_write(writew, "w", unsigned short, "r", :"memory")
-build_mmio_write(writel, "l", unsigned int, "r", :"memory")
-
-build_mmio_write(__writeb, "b", unsigned char, "q", )
-build_mmio_write(__writew, "w", unsigned short, "r", )
-build_mmio_write(__writel, "l", unsigned int, "r", )
-
-#define readb readb
-#define readw readw
-#define readl readl
-#define readb_relaxed(a) __readb(a)
-#define readw_relaxed(a) __readw(a)
-#define readl_relaxed(a) __readl(a)
-#define __raw_readb __readb
-#define __raw_readw __readw
-#define __raw_readl __readl
-
-#define writeb writeb
-#define writew writew
-#define writel writel
-#define writeb_relaxed(v, a) __writeb(v, a)
-#define writew_relaxed(v, a) __writew(v, a)
-#define writel_relaxed(v, a) __writel(v, a)
-#define __raw_writeb __writeb
-#define __raw_writew __writew
-#define __raw_writel __writel
-
-#ifdef CONFIG_X86_64
-
-build_mmio_read(readq, "q", u64, "=r", :"memory")
-build_mmio_read(__readq, "q", u64, "=r", )
-build_mmio_write(writeq, "q", u64, "r", :"memory")
-build_mmio_write(__writeq, "q", u64, "r", )
-
-#define readq_relaxed(a)	__readq(a)
-#define writeq_relaxed(v, a)	__writeq(v, a)
-
-#define __raw_readq		__readq
-#define __raw_writeq		__writeq
-
-/* Let people know that we have them */
-#define readq			readq
-#define writeq			writeq
-
-#endif
-
 #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
 extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
 extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
arch/x86/include/asm/shared/io.h +68 -0

72 lines not on this page · raw message

Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/6 x86/boot: Convert early_serial_base to unsigned long

In reply to Andy Shevchenko

As a preparatory of adding flexible serial I/O accessors, convert early_serial_base to unsigned long to cover all possible bus addresses on the system.

No functional change intended.

---
 arch/x86/boot/boot.h                            | 2 +-
 arch/x86/boot/compressed/early_serial_console.c | 2 +-
 arch/x86/boot/compressed/misc.h                 | 4 ++--
 arch/x86/boot/early_serial_console.c            | 6 +++---
 arch/x86/boot/tty.c                             | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
arch/x86/boot/boot.h +1 -1
index 38f17a1e1e36..753f429b28cb 100644
@@ -274,7 +274,7 @@ int check_knl_erratum(void);
 int validate_cpu(void);
 
 /* early_serial_console.c */
-extern int early_serial_base;
+extern unsigned long early_serial_base;
 void console_init(void);
 
 /* edd.c */
arch/x86/boot/compressed/early_serial_console.c +1 -1
index 70a8d1706d0f..5b8db03f40ad 100644
@@ -1,6 +1,6 @@
 #include "misc.h"
 
 /* This might be accessed before .bss is cleared, so use .data instead. */
-int early_serial_base __section(".data");
+unsigned long early_serial_base __section(".data");
 
 #include "../early_serial_console.c"
arch/x86/boot/compressed/misc.h +2 -2
index dd8d1a85f671..f083360c84c1 100644
@@ -127,10 +127,10 @@ extern unsigned char _pgtable[];
 
 #ifdef CONFIG_EARLY_PRINTK
 /* early_serial_console.c */
-extern int early_serial_base;
+extern unsigned long early_serial_base;
 void console_init(void);
 #else
-static const int early_serial_base;
+static const unsigned long early_serial_base;
 static inline void console_init(void)
 { }
 #endif
arch/x86/boot/early_serial_console.c +3 -3
index 023bf1c3de8b..7a7766fa16e5 100644
@@ -23,7 +23,7 @@
 
 #define DEFAULT_BAUD 9600
 
-static void early_serial_init(int port, int baud)
+static void early_serial_init(unsigned long port, int baud)
 {
 	unsigned char c;
 	unsigned divisor;
@@ -46,9 +46,9 @@ static void early_serial_init(int port, int baud)
 static void parse_earlyprintk(void)
 {
 	int baud = DEFAULT_BAUD;
+	unsigned long port = 0;
 	char arg[32];
 	int pos = 0;
-	int port = 0;
 
 	if (cmdline_find_option("earlyprintk", arg, sizeof(arg)) > 0) {
 		char *e;
@@ -118,7 +118,7 @@ static void parse_console_uart8250(void)
 {
 	char optstr[64], *options;
 	int baud = DEFAULT_BAUD;
-	int port = 0;
+	unsigned long port = 0;
 
 	/*
 	 * console=uart8250,io,0x3f8,115200n8
arch/x86/boot/tty.c +1 -1
index f7eb976b0a4b..e2ab8b8076ef 100644
@@ -13,7 +13,7 @@
 
 #include "boot.h"
 
-int early_serial_base;
+unsigned long early_serial_base;
 
 #define XMTRDY          0x20
 
Signature · 1 line
2.47.2
#6 lore raw

PATCH 6/6 x86/boot: Introduce MMIO accessors and their support in earlyprintk

In reply to Andy Shevchenko

If user supplied serial base address via kernel command line and at the same time the word 'mmio' is present, use MMIO accessors.

---
 arch/x86/boot/early_serial_console.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
arch/x86/boot/early_serial_console.c +25 -0
index 6841f14346c2..fa8eb0b4542e 100644
@@ -33,6 +33,20 @@ static void io_serial_out(unsigned long addr, int offset, int value)
 	outb(value, addr + offset);
 }
 
+static void mem8_serial_out(unsigned long addr, int offset, int value)
+{
+	u8 __iomem *vaddr = (u8 __iomem *)addr;
+	/* shift implied by pointer type */
+	writeb(value, vaddr + offset);
+}
+
+static unsigned int mem8_serial_in(unsigned long addr, int offset)
+{
+	u8 __iomem *vaddr = (u8 __iomem *)addr;
+	/* shift implied by pointer type */
+	return readb(vaddr + offset);
+}
+
 static void early_serial_configure(unsigned long port, int baud)
 {
 	unsigned char c;
@@ -59,6 +73,13 @@ static void early_serial_use_io_accessors(void)
 	serial_out = io_serial_out;
 }
 
+static void early_serial_use_mmio_accessors(void)
+{
+	/* It is memory mapped - assume 8-bit alignment */
+	serial_in = mem8_serial_in;
+	serial_out = mem8_serial_out;
+}
+
 static void early_serial_init(unsigned long port, int baud)
 {
 	early_serial_configure(port, baud);
@@ -101,12 +122,16 @@ static void parse_earlyprintk(void)
 		/*
 		 * make sure we have
 		 *	"serial,0x3f8,115200"
+		 *	"serial,mmio,0xff010180,115200"
 		 *	"serial,ttyS0,115200"
 		 *	"ttyS0,115200"
 		 */
 		if (pos == 7 && !strncmp(arg + pos, "0x", 2)) {
 			port = parse_serial_port(arg, pos + 0, &pos);
 			early_serial_use_io_accessors();
+		} else if (pos == 7 && !strncmp(arg + pos, "mmio,0x", 7)) {
+			port = parse_serial_port(arg, pos + 5, &pos);
+			early_serial_use_mmio_accessors();
 		} else if (!strncmp(arg + pos, "ttyS", 4)) {
 			static const int bases[] = { 0x3f8, 0x2f8 };
 			int idx = 0;
Signature · 1 line
2.47.2
#7 lore raw
In reply to Andy Shevchenko
Quoted 3 lines · Andy Shevchenko

Some of the platforms may have no legacy COM ports and only provide an MMIO accessible UART. Add support for such to earlyprintk for the boot phase of the kernel.

Shiny. I had to hack QEMU's PCI serial port to do unnatural things, in order to test the mmio32 variant which was the only thing the earlyprintk code used to support. But I *did* so, and it works with the kexec debugging.

Can you add support for this mode to the kexec debugging too, please?

I believe it's currently in tip/asm. This should be a simple example to work from:
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?h=x86/asm&id=7516e7216bdfb9e2fab0a0ca3bd23cb2e61e46ed

#8 lore raw
Quoted 11 lines · David Woodhouse
Quoted 3 lines · Andy Shevchenko

Some of the platforms may have no legacy COM ports and only provide an MMIO accessible UART. Add support for such to earlyprintk for the boot phase of the kernel.

Shiny. I had to hack QEMU's PCI serial port to do unnatural things, in order to test the mmio32 variant which was the only thing the earlyprintk code used to support. But I *did* so, and it works with the kexec debugging.

Can you add support for this mode to the kexec debugging too, please?

Do you mean to add MMIO 8-bit to kexec assembly code and other parts like you did in the below mentioned change?

I can try it at some point, but have no time right now for this. I would appreciate if you can give a try for this patch series functionality to see if it helps for the initial messages (as far as I understand you also want to have this in the second kernel, right?).

Quoted 3 lines

I believe it's currently in tip/asm. This should be a simple example to work from:
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?h=x86/asm&id=7516e7216bdfb9e2fab0a0ca3bd23cb2e61e46ed

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · David Woodhouse
Quoted 3 lines · Andy Shevchenko

Some of the platforms may have no legacy COM ports and only provide an MMIO accessible UART. Add support for such to earlyprintk for the boot phase of the kernel.

Shiny. I had to hack QEMU's PCI serial port to do unnatural things, in order to test the mmio32 variant which was the only thing the earlyprintk code used to support. But I *did* so, and it works with the kexec debugging.

Can you add support for this mode to the kexec debugging too, please?

Quoted 8 lines

Do you mean to add MMIO 8-bit to kexec assembly code and other parts like you did in the below mentioned change?

I can try it at some point, but have no time right now for this. I would appreciate if you can give a try for this patch series functionality to see if it helps for the initial messages (as far as I understand you also want to have this in the second kernel, right?).

I'll see if I can find the time to take a look. Got a branch I can pull your series from?

#10 lore raw
Quoted 17 lines · David Woodhouse
Quoted 16 lines · Andy Shevchenko
Quoted 11 lines · David Woodhouse
Quoted 3 lines · Andy Shevchenko

Some of the platforms may have no legacy COM ports and only provide an MMIO accessible UART. Add support for such to earlyprintk for the boot phase of the kernel.

Shiny. I had to hack QEMU's PCI serial port to do unnatural things, in order to test the mmio32 variant which was the only thing the earlyprintk code used to support. But I *did* so, and it works with the kexec debugging.

Can you add support for this mode to the kexec debugging too, please?

Do you mean to add MMIO 8-bit to kexec assembly code and other parts like you did in the below mentioned change?

Quoted 8 lines
Quoted 5 lines

I can try it at some point, but have no time right now for this. I would appreciate if you can give a try for this patch series functionality to see if it helps for the initial messages (as far as I understand you also want to have this in the second kernel, right?).

I'll see if I can find the time to take a look. Got a branch I can pull your series from?

Yeo, https://bitbucket.org/andy-shev/linux/commits/branch/topic%2Fx86%2Fboot-earlyprintk.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw
Quoted 24 lines · Andy Shevchenko
Quoted 23 lines · David Woodhouse
Quoted 21 lines · Andy Shevchenko
Quoted 11 lines · David Woodhouse
Quoted 3 lines · Andy Shevchenko

Some of the platforms may have no legacy COM ports and only provide an MMIO accessible UART. Add support for such to earlyprintk for the boot phase of the kernel.

Shiny. I had to hack QEMU's PCI serial port to do unnatural things, in order to test the mmio32 variant which was the only thing the earlyprintk code used to support. But I *did* so, and it works with the kexec debugging.

Can you add support for this mode to the kexec debugging too, please?

Do you mean to add MMIO 8-bit to kexec assembly code and other parts like you did in the below mentioned change?

I can try it at some point, but have no time right now for this. I would appreciate if you can give a try for this patch series functionality to see if it helps for the initial messages (as far as I understand you also want to have this in the second kernel, right?).

Quoted 4 lines
Quoted 2 lines

I'll see if I can find the time to take a look. Got a branch I can pull your series from?

Yeo, https://bitbucket.org/andy-shev/linux/commits/branch/topic%2Fx86%2Fboot-earlyprintk.

But just FYI that with b4 it's as easy to pull from the mailing list as from a branch:

	b4 am [email protected]
	git am -C1 -s ...
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#12 lore raw
Quoted 41 lines · Andy Shevchenko
Quoted 32 lines · Andy Shevchenko
Quoted 31 lines · David Woodhouse
Quoted 29 lines · Andy Shevchenko
Quoted 14 lines · David Woodhouse
Quoted 5 lines · Andy Shevchenko

Some of the platforms may have no legacy COM ports and only provide
an MMIO accessible UART. Add support for such to earlyprintk for the
boot phase of the kernel.

Shiny. I had to hack QEMU's PCI serial port to do unnatural things, in
order to test the mmio32 variant which was the only thing the earlyprintk code used to support. But I *did* so, and it works with the
kexec debugging.

Quoted 2 lines

Can you add support for this mode to the kexec debugging too, please?

Do you mean to add MMIO 8-bit to kexec assembly code and other parts like you
did in the below mentioned change?

I can try it at some point, but have no time right now for this.
I would appreciate if you can give a try for this patch series functionality to see if it helps for the initial messages (as far as I understand you also want to have this in the second kernel, right?).

Quoted 7 lines
Quoted 3 lines

I'll see if I can find the time to take a look. Got a branch I can pull
your series from?

Yeo,
https://bitbucket.org/andy-shev/linux/commits/branch/topic%2Fx86%2Fboot-earlyprintk
.

Quoted 7 lines

But just FYI that with b4 it's as easy to pull from the mailing list as from
a branch:

b4 am
[email protected]

	git am -C1 -s ...

Thanks. Should I be expecting this to work...?

qemu-system-x86_64 -display none -vga none -accel kvm,kernel-irqchip=split \
-kernel arch/x86/boot/bzImage \
-append "console=ttyS4 root=/dev/vda1 earlyprintk=pciserial" \
-chardev stdio,mux=on,id=char0,signal=off -mon char0 -device pci-serial,chardev=char0

I get no early output (I think it's still using the mmio32 variant), and I only see output from when the real driver takes over:

[    0.894054] printk: legacy console [ttyS4] enabled
[    0.895498] printk: legacy bootconsole [earlyser0] disabled

...

#13 lore raw
Quoted 7 lines · David Woodhouse

Thanks. Should I be expecting this to work...?

qemu-system-x86_64 -display none -vga none  -accel kvm,kernel-irqchip=split \
  -kernel arch/x86/boot/bzImage \
  -append "console=ttyS4 root=/dev/vda1 earlyprintk=pciserial" \
  -chardev stdio,mux=on,id=char0,signal=off -mon char0 -device pci-serial,chardev=char0

Hm, no, qemu's pci-serial is PIO. I'd need to do this:

hw/char/serial-pci.c +1 -1
@@ -58,7 +58,7 @@ static void serial_pci_realize(PCIDevice *dev, Error **errp)
     s->irq = pci_allocate_irq(&pci->dev);
 
     memory_region_init_io(&s->io, OBJECT(pci), &serial_io_ops, s, "serial", 8);
-    pci_register_bar(&pci->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io);
+    pci_register_bar(&pci->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->io);
 }
 
 static void serial_pci_exit(PCIDevice *dev)

And then the kernel's 'earlyprintk=pciserial' needs to be told the BDF, e.g. earlyprintk=pciserial,00:03.0,keep

And it's still defaulting to mmio32 unless I do this in the kernel...

arch/x86/kernel/early_printk.c +2 -2
@@ -198,7 +198,7 @@ static __init void early_serial_init(char *s)
 
 static __noendbr void mem32_serial_out(unsigned long addr, int offset, int value)
 {
-       u32 __iomem *vaddr = (u32 __iomem *)addr;
+       u8 __iomem *vaddr = (u8 __iomem *)addr;
        /* shift implied by pointer type */
        writel(value, vaddr + offset);
 }
@@ -206,7 +206,7 @@ ANNOTATE_NOENDBR_SYM(mem32_serial_out);
 
 static __noendbr unsigned int mem32_serial_in(unsigned long addr, int offset)
 {
-       u32 __iomem *vaddr = (u32 __iomem *)addr;
+       u8 __iomem *vaddr = (u8 __iomem *)addr;
        /* shift implied by pointer type */
        return readl(vaddr + offset);
 }

If you can get this part working sanely, I'll happily add the kexec debug part.

#14 lore raw
In reply to Andy Shevchenko
Quoted 3 lines · Andy Shevchenko

Some of the platforms may have no legacy COM ports and only provide an MMIO accessible UART. Add support for such to earlyprintk for the boot phase of the kernel.

Aha, I understand now... you've added this *only* for the boot code, and haven't added the corresponding support to the in-kernel earlyprintk, in arch/x86/kernel/early_printk.c

The latter does already support MMIO but it only supports a 32-bit stride, not 8-bit.

Please could you make that consistent, and ensure the earlyprintk= arguments function the same for both phases? I'm happy to add the kexec-debug parts on top of *that*.

It would be really helpful if we could test this in QEMU; it shouldn't be that hard to make it provide a 16550 on MMIO, along the lines of the one-line hack I posted yesterday.

#15 lore raw
Quoted 8 lines · David Woodhouse
Quoted 3 lines · Andy Shevchenko

Some of the platforms may have no legacy COM ports and only provide an MMIO accessible UART. Add support for such to earlyprintk for the boot phase of the kernel.

Aha, I understand now... you've added this *only* for the boot code, and haven't added the corresponding support to the in-kernel earlyprintk, in arch/x86/kernel/early_printk.c

Haven't added yet. This is part 1 only.

Quoted 6 lines

The latter does already support MMIO but it only supports a 32-bit stride, not 8-bit.

Please could you make that consistent, and ensure the earlyprintk= arguments function the same for both phases? I'm happy to add the kexec-debug parts on top of *that*.

It's not as easy as it looks like. I had done in the past the comparison table of what we have between all early*=... for serial consoles and it all so inconsistent to begin with. A big work needs to be fulfilled in order to put this mess in order. Hence this is just the first step.

Quoted 3 lines

It would be really helpful if we could test this in QEMU; it shouldn't be that hard to make it provide a 16550 on MMIO, along the lines of the one-line hack I posted yesterday.

I understand. But if no go for this series, I don't won't to spend time on the next part.

In any case, thanks for looking into this.

Signature · 2 lines
With Best Regards,
Andy Shevchenko