Skip to contentSkip to conversation

x86/boot: Enable earlyprintk for HS UARTs

PATCH In review Andy Shevchenko 4 participants 39 messages Mar 19, 2019 – Mar 28, 2019 x86

lore
Share & tools
lore
#0 lore raw

v2 cover x86/boot: Enable earlyprintk for HS UARTs

Newer Intel platforms sometimes have only HS UART enabled and accessible via MMIO on high addresses.

For now, earlyprintk doesn't handle such cases and always rely on the legacy serial port to be present.

This series fills the gap and enables earlyprintk on HS UARTs.

Since v2:
- rebase on top of v5.1-rc1
- parse 'mmio' keyword instead of port range check (Ingo)
- deduplicate code wherever it's possible (Ingo)

Andy Shevchenko (7):
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: Add MMIO byte accessors
x86/boot: Introduce MMIO accessors and their support in earlyprintk x86/boot: Support nocfg parameter for earlyprintk

 arch/x86/boot/boot.h                          |  16 ++-
 .../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          | 135 ++++++++++++++----
 arch/x86/boot/tty.c                           |   9 +-
 6 files changed, 140 insertions(+), 37 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/7 x86/boot: Convert early_serial_base to unsigned long

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 32a09eb5c101..f41291903da7 100644
@@ -299,7 +299,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 261e81fb9582..5e3a66478754 100644
@@ -1,5 +1,5 @@
 #include "misc.h"
 
-int early_serial_base;
+unsigned long early_serial_base;
 
 #include "../early_serial_console.c"
arch/x86/boot/compressed/misc.h +2 -2
index fd13655e0f9b..6f2bdf813949 100644
@@ -110,10 +110,10 @@ static inline void finalize_identity_maps(void)
 
 #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..2b663beda582 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;
@@ -48,7 +48,7 @@ static void parse_earlyprintk(void)
 	int baud = DEFAULT_BAUD;
 	char arg[32];
 	int pos = 0;
-	int port = 0;
+	unsigned long 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 def2451f46ae..d1d34c6ca153 100644
@@ -15,7 +15,7 @@
 
 #include "boot.h"
 
-int early_serial_base;
+unsigned long early_serial_base;
 
 #define XMTRDY          0x20
 
Signature · 1 line
2.20.1
maintainer
#2 lore raw

Re: [PATCH v2 1/7] x86/boot: Convert early_serial_base to unsigned long

Quoted 14 lines · 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(-)

...

Quoted 23 lines
arch/x86/boot/early_serial_console.c +2 -2
index 023bf1c3de8b..2b663beda582 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;
@@ -48,7 +48,7 @@ static void parse_earlyprintk(void)
 	int baud = DEFAULT_BAUD;
 	char arg[32];
 	int pos = 0;
-	int port = 0;
+	unsigned long port = 0;
 
 	if (cmdline_find_option("earlyprintk", arg, sizeof(arg)) > 0) {
 		char *e;

arch/x86/boot/early_serial_console.c static void parse_console_uart8250(void) · line 121

Quoted 5 lines
arch/x86/boot/early_serial_console.c +1 -1
@@ -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;

Here and above:

Please sort function local variables declaration in a reverse christmas tree order:

	<type A> longest_variable_name;
	<type B> shorter_var_name;
	<type C> even_shorter;
	<type D> i;
Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#3 lore raw

Re: [PATCH v2 1/7] x86/boot: Convert early_serial_base to unsigned long

Quoted 12 lines · Borislav Petkov
Quoted 11 lines · 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.

arch/x86/boot/early_serial_console.c +1 -1
@@ -48,7 +48,7 @@ static void parse_earlyprintk(void)
 	int baud = DEFAULT_BAUD;
 	char arg[32];
 	int pos = 0;
-	int port = 0;
+	unsigned long port = 0;
 
Quoted 10 lines

arch/x86/boot/early_serial_console.c static void parse_console_uart8250(void) · line 121

Quoted 8 lines
arch/x86/boot/early_serial_console.c +1 -1
 	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;

Here and above:

Agree on above and will fix, but don't see how this different in the latter?

Quoted 9 lines

Please sort function local variables declaration in a reverse christmas tree order:

	<type A> longest_variable_name;
	<type B> shorter_var_name;
	<type C> even_shorter;
	<type D> i;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw

Re: [PATCH v2 1/7] x86/boot: Convert early_serial_base to unsigned long

Quoted 1 line · Andy Shevchenko

Agree on above and will fix, but don't see how this different in the latter?

Ok, so only the above.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#5 lore raw

PATCH v2 2/7 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 f41291903da7..86641b2e83f8 100644
@@ -299,6 +299,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 5e3a66478754..4b6269624b59 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);
+
 unsigned long early_serial_base;
 
 #include "../early_serial_console.c"
arch/x86/boot/compressed/misc.c +2 -2
index c0d6c560df69..75b3c8bb92ac 100644
@@ -98,10 +98,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 6f2bdf813949..2fd3ec89a70d 100644
@@ -110,9 +110,13 @@ static inline void finalize_identity_maps(void)
 
 #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 d1d34c6ca153..b6aa9db65cda 100644
@@ -15,6 +15,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
@@ -31,10 +34,10 @@ static void __attribute__((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 __attribute__((section(".inittext"))) bios_putchar(int ch)
Signature · 1 line
2.20.1
maintainer
#6 lore raw

Re: [PATCH v2 2/7] x86/boot: Introduce helpers for serial I/O

Quoted 4 lines · 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/early_serial_console.c line 60

Quoted 7 lines
arch/x86/boot/early_serial_console.c +7 -0
+/* Assign serial I/O accessors */
+static void early_serial_use_io_accessors(void)
+{
+	/* These will always be IO based ports */
+	serial_in = io_serial_in;
+	serial_out = io_serial_out;
+}

This and the early_serial_use_mmio_accessors() in a later patch is just silly because you need to export and forward-declare those serial_in and serial_out function pointers in a bunch of places.

Just define exactly *two* simple functions serial_in() and serial_out() which have enough logic to decide whether to do serial IO or MMIO and put all that logic in those functions. No need for all that function pointer assignment "fun".

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#7 lore raw

Re: [PATCH v2 2/7] x86/boot: Introduce helpers for serial I/O

Quoted 8 lines · Borislav Petkov
Quoted 4 lines · 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.

...

Quoted 11 lines

arch/x86/boot/early_serial_console.c line 60

Quoted 7 lines
arch/x86/boot/early_serial_console.c +7 -0
+/* Assign serial I/O accessors */
+static void early_serial_use_io_accessors(void)
+{
+	/* These will always be IO based ports */
+	serial_in = io_serial_in;
+	serial_out = io_serial_out;
+}

This and the early_serial_use_mmio_accessors() in a later patch is just silly because you need to export and forward-declare those serial_in and serial_out function pointers in a bunch of places.

This is the same approach as it's done in earlyprintk support in the main part of the kernel. Besides the fact that many drivers do it in the same way.

And I wouldn't call 'few' a 'bunch'...

Quoted 3 lines

Just define exactly *two* simple functions serial_in() and serial_out() which have enough logic to decide whether to do serial IO or MMIO and put all that logic in those functions.

Any idea how it can be done?

Quoted 2 lines

No need for all that function
pointer assignment "fun".

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#8 lore raw

Re: [PATCH v2 2/7] x86/boot: Introduce helpers for serial I/O

Quoted 1 line · Andy Shevchenko

Any idea how it can be done?

Like this?

static u8 serial_inb(unsigned long addr, int offset)

{
	if (early_serial_do_mmio) {
		asm volatile("movb %1,%0" : "=q" (v) : "m" (*(volatile u8 __force *)addr));

		return v;
	} else {
		 return inb(addr + offset);
	}
}
Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#9 lore raw

Re: [PATCH v2 2/7] x86/boot: Introduce helpers for serial I/O

Quoted 6 lines · Borislav Petkov
Quoted 1 line · Andy Shevchenko

Any idea how it can be done?

Like this?

static u8 serial_inb(unsigned long addr, int offset)

It's not a generic serial_in()...

Quoted 9 lines
{
	if (early_serial_do_mmio) {
		asm volatile("movb %1,%0" : "=q" (v) : "m" (*(volatile u8 __force *)addr));

		return v;
	} else {
		 return inb(addr + offset);
	}
}

What about mmio32 as next step?

Do we have to "fix" earlyprintk implementation in kernel to do the same?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#10 lore raw

Re: [PATCH v2 2/7] x86/boot: Introduce helpers for serial I/O

Quoted 1 line · Andy Shevchenko

It's not a generic serial_in()...

Why?

Quoted 1 line

What about mmio32 as next step?

Next step where? Is it part of your patches?

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#11 lore raw

Re: [PATCH v2 2/7] x86/boot: Introduce helpers for serial I/O

Quoted 4 lines · Borislav Petkov
Quoted 1 line · Andy Shevchenko

It's not a generic serial_in()...

Why?

By name and by what it's handling (only byte accesses to I/O or MMIO).

Quoted 3 lines
Quoted 1 line

What about mmio32 as next step?

Next step where? Is it part of your patches?

Not this series, but we have hardware that does MMIO32 accesses and yet using non-standard address.

My point is, that doing branch(es) on each I/O call is not good as simple calling the proper (pre-defined) I/O accessor.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#12 lore raw

Re: [PATCH v2 2/7] x86/boot: Introduce helpers for serial I/O

Quoted 1 line · Andy Shevchenko

By name and by what it's handling (only byte accesses to I/O or MMIO).

Your series does only byte accesses so you can use byte variant.

Quoted 2 lines

My point is, that doing branch(es) on each I/O call is not good as simple calling the proper (pre-defined) I/O accessor.

What branches?

You do a branch and *then* you do an IO call.

What does "not good" even mean?

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#13 lore raw

Re: [PATCH v2 2/7] x86/boot: Introduce helpers for serial I/O

Quoted 9 lines · Borislav Petkov
Quoted 1 line · Andy Shevchenko

By name and by what it's handling (only byte accesses to I/O or MMIO).

Your series does only byte accesses so you can use byte variant.

Quoted 2 lines

My point is, that doing branch(es) on each I/O call is not good as simple calling the proper (pre-defined) I/O accessor.

What branches?

Something like this at the end

if (mmio32)

	...
else if (mmio)
	...
else if (whatever)
	...
else
	...
Quoted 1 line

You do a branch and *then* you do an IO call.

Yes.

Quoted 1 line

What does "not good" even mean?

We still export global flag variable, on top of this we need an additional branch which we can avoid for free.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#14 lore raw

PATCH v2 3/7 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 05d02cd4de99..85a227a21f95 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.20.1
maintainer
#15 lore raw

Re: [PATCH v2 3/7] x86/boot: Split out parse_serial_port() helper for earlyprintk

Quoted 15 lines · 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 +0 -0
index 05d02cd4de99..85a227a21f95 100644

arch/x86/boot/early_serial_console.c static void early_serial_init(unsigned long port, int baud) · line 74

Quoted 9 lines
arch/x86/boot/early_serial_console.c +6 -0
@@ -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);

WARNING: simple_strtoull is obsolete, use kstrtoull instead #41: FILE: arch/x86/boot/early_serial_console.c:74:
+ port = simple_strtoull(arg + off, &e, 16);

Please do a conversion patch ontop.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#16 lore raw

Re: [PATCH v2 3/7] x86/boot: Split out parse_serial_port() helper for earlyprintk

Quoted 19 lines · Borislav Petkov
Quoted 18 lines · 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 +0 -0
index 05d02cd4de99..85a227a21f95 100644
@@ -66,6 +66,20 @@ static void early_serial_init(unsigned long port, int baud)
 	early_serial_base = port;
 }
 
Quoted 10 lines

arch/x86/boot/early_serial_console.c static void early_serial_init(unsigned long port, int baud) · line 74

Quoted 6 lines
arch/x86/boot/early_serial_console.c +6 -0
+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);

WARNING: simple_strtoull is obsolete, use kstrtoull instead #41: FILE: arch/x86/boot/early_serial_console.c:74:
+ port = simple_strtoull(arg + off, &e, 16);

kstrtox() simple can't cover _all_ simple_strtox() cases.

Quoted 1 line

Please do a conversion patch ontop.

I don't feel like uglifying code to satisfy a tool producing a silly warning.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#17 lore raw

Re: [PATCH v2 3/7] x86/boot: Split out parse_serial_port() helper for earlyprintk

Quoted 1 line · Andy Shevchenko

kstrtox() simple can't cover _all_ simple_strtox() cases.

I see only one case here. Are you saying kstrtoull() cannot work here?

Quoted 1 line

I don't feel like uglifying code to satisfy a tool producing a silly

warning.

Uglifying how?

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#18 lore raw

Re: [PATCH v2 3/7] x86/boot: Split out parse_serial_port() helper for earlyprintk

Quoted 5 lines · Borislav Petkov
Quoted 1 line · Andy Shevchenko

kstrtox() simple can't cover _all_ simple_strtox() cases.

I see only one case here. Are you saying kstrtoull() cannot work here?

Can, but with code uglifying to workaround kstrtox() restrictions. simple_strtox() _just works_ as expected.

Quoted 4 lines
Quoted 1 line

I don't feel like uglifying code to satisfy a tool producing a silly

warning.

Uglifying how?

Requires buffer copying, finding digits there, making a proper termination. And basically dropping the error check, because we don't care at this stage about wrong input.

And we didn't start to talk about possible user expectation breakage and basically breakage weird user cases.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#19 lore raw

Re: [PATCH v2 3/7] x86/boot: Split out parse_serial_port() helper for earlyprintk

Quoted 2 lines · Andy Shevchenko

Can, but with code uglifying to workaround kstrtox() restrictions. simple_strtox() _just works_ as expected.

simple_strtox() also has its problems.

Quoted 1 line

Requires buffer copying, finding digits there, making a proper termination. And

It needs a single kstrtoull() call to parse the port. And we have kstrtoull() available in the compressed stage so pls do the conversion ontop.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#20 lore raw

Re: [PATCH v2 3/7] x86/boot: Split out parse_serial_port() helper for earlyprintk

Quoted 5 lines · Borislav Petkov
Quoted 2 lines · Andy Shevchenko

Can, but with code uglifying to workaround kstrtox() restrictions. simple_strtox() _just works_ as expected.

simple_strtox() also has its problems.

Yes! And point here: we do not care.

Quoted 3 lines
Quoted 1 line

Requires buffer copying, finding digits there, making a proper termination. And

It needs a single kstrtoull() call to parse the port.

No, it does not. It needs more as I described. Have you investigated a topic? Have you seen all possible combinations of input here?

Quoted 3 lines

And we have
kstrtoull() available in the compressed stage so pls do the conversion ontop.

If it's strong opinion, I consider this rather as NAK. Thank you for review.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#21 lore raw

Re: [PATCH v2 3/7] x86/boot: Split out parse_serial_port() helper for earlyprintk

Quoted 2 lines · Andy Shevchenko

If it's strong opinion, I consider this rather as NAK. Thank you for review.

Your call.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#22 lore raw

Re: [PATCH v2 3/7] x86/boot: Split out parse_serial_port() helper for earlyprintk

Quoted 5 lines · Borislav Petkov
Quoted 2 lines · Andy Shevchenko

If it's strong opinion, I consider this rather as NAK. Thank you for review.

Your call.

Yes, as I said I won't uglify code to pursue kstrtox() whim. Thanks again!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#23 lore raw

PATCH v2 4/7 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 85a227a21f95..98aee6c6e374 100644
@@ -83,7 +83,7 @@ static unsigned long parse_serial_port(const char *arg, int off, int *pos)
 static void parse_earlyprintk(void)
 {
 	int baud = DEFAULT_BAUD;
-	char arg[32];
+	char arg[64];
 	int pos = 0;
 	unsigned long port = 0;
 
Signature · 1 line
2.20.1
#24 lore raw

PATCH v2 5/7 x86/boot: Add MMIO byte accessors

In reply to Andy Shevchenko

readb() and writeb() would help to access serial device via MMIO address space.

---
 arch/x86/boot/boot.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/x86/boot/boot.h +12 -0
index 86641b2e83f8..b2a272d3f36b 100644
@@ -79,6 +79,18 @@ static inline void io_delay(void)
 	asm volatile("outb %%al,%0" : : "dN" (DELAY_PORT));
 }
 
+static inline u8 readb(const volatile void __iomem *addr)
+{
+	u8 v;
+	asm volatile("movb %1,%0" : "=q" (v) : "m" (*(volatile u8 __force *)addr));
+	return v;
+}
+
+static inline void writeb(u8 v, volatile void __iomem *addr)
+{
+	asm volatile("movb %0,%1" : : "q" (v), "m" (*(volatile u8 __force *)addr));
+}
+
 /* These functions are used to reference data in other segments. */
 
 static inline u16 ds(void)
Signature · 1 line
2.20.1
#25 lore raw

PATCH v2 6/7 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 98aee6c6e374..cfc9e55cd68a 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.20.1
#26 lore raw

PATCH v2 7/7 x86/boot: Support nocfg parameter for earlyprintk

In reply to Andy Shevchenko

If by BIOS or by other means the serial port is configured user might want to skip reconfiguration in the boot code.

Add support of 'nocfg' parameter to earlyprintk.

---
 arch/x86/boot/early_serial_console.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
arch/x86/boot/early_serial_console.c +21 -4
index cfc9e55cd68a..5b4a81bf5d0e 100644
@@ -80,9 +80,10 @@ static void early_serial_use_mmio_accessors(void)
 	serial_out = mem8_serial_out;
 }
 
-static void early_serial_init(unsigned long port, int baud)
+static void early_serial_init(unsigned long port, int baud, bool configure)
 {
-	early_serial_configure(port, baud);
+	if (configure)
+		early_serial_configure(port, baud);
 
 	early_serial_base = port;
 }
@@ -101,12 +102,22 @@ static unsigned long parse_serial_port(const char *arg, int off, int *pos)
 	return port;
 }
 
+static bool parse_serial_configure(const char *arg, int off, int *pos)
+{
+	if (strncmp(arg + off, "nocfg", 5))
+		return true;
+
+	*pos = off + 5;
+	return false;
+}
+
 static void parse_earlyprintk(void)
 {
 	int baud = DEFAULT_BAUD;
 	char arg[64];
 	int pos = 0;
 	unsigned long port = 0;
+	bool configure = true;
 
 	if (cmdline_find_option("earlyprintk", arg, sizeof(arg)) > 0) {
 		char *e;
@@ -146,6 +157,11 @@ static void parse_earlyprintk(void)
 			early_serial_use_io_accessors();
 		}
 
+		if (arg[pos] == ',')
+			pos++;
+
+		configure = parse_serial_configure(arg, pos, &pos);
+
 		if (arg[pos] == ',')
 			pos++;
 
@@ -155,7 +171,7 @@ static void parse_earlyprintk(void)
 	}
 
 	if (port)
-		early_serial_init(port, baud);
+		early_serial_init(port, baud, configure);
 }
 
 #define BASE_BAUD (1843200/16)
@@ -179,6 +195,7 @@ static void parse_console_uart8250(void)
 	char optstr[64], *options;
 	int baud = DEFAULT_BAUD;
 	unsigned long port = 0;
+	bool configure = true;
 
 	/*
 	 * console=uart8250,io,0x3f8,115200n8
@@ -204,7 +221,7 @@ static void parse_console_uart8250(void)
 		baud = probe_baud(port);
 
 	if (port)
-		early_serial_init(port, baud);
+		early_serial_init(port, baud, configure);
 }
 
 void console_init(void)
Signature · 1 line
2.20.1
#27 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 7 lines · Andy Shevchenko

If by BIOS or by other means the serial port is configured user might want to skip reconfiguration in the boot code.

Add support of 'nocfg' parameter to earlyprintk.

---

Hi Andy,
Please add "nocfg" to Documentation/admin-guide/kernel-parameters.txt.

Signature · 1 line
~Randy
#28 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 7 lines · Randy Dunlap
Quoted 4 lines · Andy Shevchenko

If by BIOS or by other means the serial port is configured user might want to skip reconfiguration in the boot code.

Add support of 'nocfg' parameter to earlyprintk.

Please add "nocfg" to Documentation/admin-guide/kernel-parameters.txt.

I think it's not a time right now to do so. This only does it for boot stage.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#29 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 11 lines · Andy Shevchenko
Quoted 7 lines · Randy Dunlap
Quoted 4 lines · Andy Shevchenko

If by BIOS or by other means the serial port is configured user might want to skip reconfiguration in the boot code.

Add support of 'nocfg' parameter to earlyprintk.

Please add "nocfg" to Documentation/admin-guide/kernel-parameters.txt.

I think it's not a time right now to do so. This only does it for boot stage.

OK. Is there somewhere else that it could be added to Documentation/[x86/]?

thanks.

Signature · 1 line
~Randy
#30 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 11 lines · Randy Dunlap
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Randy Dunlap
Quoted 1 line · Andy Shevchenko

Add support of 'nocfg' parameter to earlyprintk.

Please add "nocfg" to Documentation/admin-guide/kernel-parameters.txt.

I think it's not a time right now to do so. This only does it for boot stage.

OK. Is there somewhere else that it could be added to Documentation/[x86/]?

I don't see the proper place.

I think this is can be added when it would be recognized by next stage of earlyprintk.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#31 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 1 line · Andy Shevchenko

I don't see the proper place.

I see Documentation/x86/earlyprintk.txt which kinda begs to collect earlyprintk documentation...

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#32 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 6 lines · Borislav Petkov
Quoted 1 line · Andy Shevchenko

I don't see the proper place.

I see Documentation/x86/earlyprintk.txt which kinda begs to collect earlyprintk documentation...

It says only about USB, but okay, I may shift it as a chapter.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#33 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

If by BIOS or by other means the serial port is configured user might want to skip reconfiguration in the boot code.

That needs more explanation: how can that happen? How is the user supposed to know whether the serial port is configured in order to use this cmdline param?

Why can't the kernel detect whether the serial port is configured and not touch that configuration?

A lot of why's and head scratching...

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#34 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 5 lines · Borislav Petkov
Quoted 2 lines · Andy Shevchenko

If by BIOS or by other means the serial port is configured user might want to skip reconfiguration in the boot code.

That needs more explanation: how can that happen?

I didn't get what is 'that' here? You mean that serial interface becomes configured before kernel even starts? See below.

Quoted 3 lines

How is the user
supposed to know whether the serial port is configured in order to use this cmdline param?

If the connection to the target is done via serial interface and firmware and / or bootloader already did necessary configuration.

Quoted 2 lines

Why can't the kernel detect whether the serial port is configured and not touch that configuration?

Because it can't at this stage. We simple can't afford to move all serial drivers (even partially) to the _boot_ part of the kernel.

Quoted 1 line

A lot of why's and head scratching...

What other why's should be answered?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#35 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 2 lines · Andy Shevchenko

If the connection to the target is done via serial interface and firmware and / or bootloader already did necessary configuration.

Again: how is the user supposed to know that? When a user sees "nocfg"'s documentation, how is the user supposed to decide whether she needs to supply nocfg or not?

Which exact setups will need to supply nocfg on the cmdline?

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#36 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 5 lines · Borislav Petkov
Quoted 2 lines · Andy Shevchenko

If the connection to the target is done via serial interface and firmware and / or bootloader already did necessary configuration.

Again: how is the user supposed to know that?

How one knows that she is typing on keyboard right now and not on touch screen? I really don't get this. User either knows this beforehand or doesn't care. Maybe she needs to read documentation on hardware at some point?

Quoted 3 lines

When a user sees "nocfg"'s
documentation, how is the user supposed to decide whether she needs to supply nocfg or not?

The problem nocfg tries to solve is a hard coded default baud rate and impossibility to know at this stage all parameters of the serial interface.

Quoted 1 line

Which exact setups will need to supply nocfg on the cmdline?

If it's _non-standard_ serial interface (by meaning of I/O accessors and port addresses), user may consider to use this options in case the interface to communicate with kernel is serial one and its configuration is done by other means (firmware / bootloader / EFI / etc).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#37 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 4 lines · Andy Shevchenko

If it's _non-standard_ serial interface (by meaning of I/O accessors and port addresses), user may consider to use this options in case the interface to communicate with kernel is serial one and its configuration is done by other means (firmware / bootloader / EFI / etc).

And is this non-standard interface out there in the wild or only at Intel's labs?

Are there boxes like that out there?

If I go to the store and buy a box, how do I know whether that box would need "nocfg"? Do I look in the BIOS or how do I find out I need to supply "nocfg"?

Quoted 1 line

If by BIOS or by other means the serial port is configured

How do I find out that the serial port is configured?

And don't give me that "example" about the typing on keyboard or on touch screen again.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#38 lore raw

Re: [PATCH v2 7/7] x86/boot: Support nocfg parameter for earlyprintk

Quoted 8 lines · Borislav Petkov
Quoted 4 lines · Andy Shevchenko

If it's _non-standard_ serial interface (by meaning of I/O accessors and port addresses), user may consider to use this options in case the interface to communicate with kernel is serial one and its configuration is done by other means (firmware / bootloader / EFI / etc).

And is this non-standard interface out there in the wild or only at Intel's labs?

Of course in the wild.

Quoted 1 line

Are there boxes like that out there?

One at hand now is called Intel Edison.

Quoted 3 lines

If I go to the store and buy a box, how do I know whether that box would need "nocfg"? Do I look in the BIOS or how do I find out I need to supply "nocfg"?

By reading some technical documentation I suppose.
What is your point here? earlyprintk is a mechanism for _debugging_, I suppose the user should have slightly more knowledge than user.

Quoted 3 lines
Quoted 1 line

If by BIOS or by other means the serial port is configured

How do I find out that the serial port is configured?

If you _already_ connected via it and get firmware / bootloader messages.

Signature · 2 lines
With Best Regards,
Andy Shevchenko