Skip to contentSkip to conversation

Early 8250 fixlets

PATCH Superseded Vineet Gupta 2 participants 9 messages Jan 5, 2015

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Early 8250 fixlets

Hi,

This series addresses some of the issues seen on early 8250 uart when working with ARC SDP platform.

Changes since v1 [1]
-Rebased to linux-next of 20150105
-Patch 3/3 SNAFU fixed (arch over-ride was not correct due to mix up
of orig work based off 3.13 vs. 3.19+ based linux next submission (different core earlycon code)
Thx,
-Vineet

[1] http://www.spinics.net/lists/kernel/msg1893299.html

Vineet Gupta (3):
serial: 8250_early: optimize early 8250 uart
serial: 8250_early: prepare for dynamic BASE_BAUD
ARC: runtime determine BASE_BAUD per machine

 arch/arc/include/asm/serial.h        | 24 ++++--------------------
 arch/arc/kernel/devtree.c            | 24 ++++++++++++++++++++++++
 drivers/tty/serial/8250/8250_early.c |  7 +++++--
 drivers/tty/serial/earlycon.c        | 13 +++++++++++--
 4 files changed, 44 insertions(+), 24 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/3 serial: 8250_early: optimize early 8250 uart

In early 8250, IER is already zero so no point in writing this - twice per char.

This helped improve the SystemC model based ARC OSCI platform

---
 drivers/tty/serial/8250/8250_early.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_early.c +5 -2
index 4858b8a99d3b..ce2a8abd1f54 100644
@@ -95,13 +95,16 @@ static void __init early_serial8250_write(struct console *console,
 
 	/* Save the IER and disable interrupts */
 	ier = serial8250_early_in(port, UART_IER);
-	serial8250_early_out(port, UART_IER, 0);
+	if (ier)
+		serial8250_early_out(port, UART_IER, 0);
 
 	uart_console_write(port, s, count, serial_putc);
 
 	/* Wait for transmitter to become empty and restore the IER */
 	wait_for_xmitr(port);
-	serial8250_early_out(port, UART_IER, ier);
+
+	if (ier)
+		serial8250_early_out(port, UART_IER, ier);
 }
 
 static unsigned int __init probe_baud(struct uart_port *port)
Signature · 1 line
1.9.1
#2 lore raw

PATCH v2 2/3 serial: 8250_early: prepare for dynamic BASE_BAUD

In reply to Vineet Gupta

BASE_BAUD is pain in neck for multi-platform support as it hard codes at build time the clk value for early uart.

Mitigate this by allowing arches/platforms to provide their own version which can do dynamic setup based on DT values etc (see next patch for usage)

This was needed for ARC SDP platforms based on 2 different FPGA flows, each with a different UART clk value.

Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 drivers/tty/serial/earlycon.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/tty/serial/earlycon.c +11 -2
index 64fe25a4285c..bfd3537739e0 100644
@@ -54,6 +54,15 @@ static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
 	return base;
 }
 
+unsigned int __weak __init earlycon_base_baud(char *options)
+{
+#ifdef BASE_BAUD
+	return BASE_BAUD;
+#else
+	return 1843200/16;	/* x86 early console */
+#endif
+}
+
 static int __init parse_options(struct earlycon_device *device,
 				char *options)
 {
@@ -87,7 +96,7 @@ static int __init parse_options(struct earlycon_device *device,
 		return -EINVAL;
 	}
 
-	port->uartclk = BASE_BAUD * 16;
+	port->uartclk = earlycon_base_baud(options) * 16;
 
 	options = strchr(options, ',');
 	if (options) {
@@ -156,7 +165,7 @@ int __init of_setup_earlycon(unsigned long addr,
 
 	port->iotype = UPIO_MEM;
 	port->mapbase = addr;
-	port->uartclk = BASE_BAUD * 16;
+	port->uartclk = earlycon_base_baud(NULL) * 16;
 	port->membase = earlycon_map(addr, SZ_4K);
 
 	early_console_dev.con->data = &early_console_dev;
Signature · 1 line
1.9.1
#8 lore raw

PATCH v2 3/3 ARC: runtime determine BASE_BAUD per machine

In reply to Vineet Gupta
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 arch/arc/include/asm/serial.h | 24 ++++--------------------
 arch/arc/kernel/devtree.c     | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 20 deletions(-)
arch/arc/include/asm/serial.h +4 -20
index 602b0970a764..a8c0b8743709 100644
@@ -10,26 +10,10 @@
 #define _ASM_ARC_SERIAL_H
 
 /*
- * early-8250 requires BASE_BAUD to be defined and includes this header.
- * We put in a typical value:
- * 	(core clk / 16) - i.e. UART samples 16 times per sec.
- * Athough in multi-platform-image this might not work, specially if the
- * clk driving the UART is different.
- * We can't use DeviceTree as this is typically for early serial.
+ * 8250_early (now earlycon) include this hdr and expect BASE_BAUD definition
+ * for setting up uartclk.
+ * Now that is done via arch provided earlycon_base_baud() which can use FDT
+ * provided info as well to provide uartclk based on DT in use.
  */
 
-#include <asm/clk.h>
-
-#define BASE_BAUD	(arc_get_core_freq() / 16)
-
-/*
- * This is definitely going to break early 8250 consoles on multi-platform
- * images but hey, it won't add any code complexity for a debug feature of
- * one broken driver.
- */
-#ifdef CONFIG_ARC_PLAT_TB10X
-#undef BASE_BAUD
-#define BASE_BAUD	(arc_get_core_freq() / 16 / 3)
-#endif
-
 #endif /* _ASM_ARC_SERIAL_H */
arch/arc/kernel/devtree.c +24 -0
index fffdb5e41b20..4530f5a7eeb1 100644
@@ -17,6 +17,28 @@
 #include <asm/clk.h>
 #include <asm/mach_desc.h>
 
+#ifdef CONFIG_SERIAL_8250_CONSOLE
+
+static unsigned int arc_base_baud = 33333333;
+
+unsigned int __init earlycon_base_baud(char *options)
+{
+	return arc_base_baud/16;
+}
+
+static void __init arc_set_early_base_baud(unsigned long dt_root)
+{
+	unsigned int core_clk = arc_get_core_freq();
+
+	if (of_flat_dt_is_compatible(dt_root, "abilis,arc-tb10x"))
+		arc_base_baud = core_clk/3;
+	else
+		arc_base_baud = core_clk;
+}
+#else
+#define arc_set_early_base_baud(dt_root)
+#endif
+
 static const void * __init arch_get_next_mach(const char *const **match)
 {
 	static const struct machine_desc *mdesc = __arch_info_begin;
@@ -56,5 +78,7 @@ const struct machine_desc * __init setup_machine_fdt(void *dt)
 	if (clk)
 		arc_set_core_freq(of_read_ulong(clk, len/4));
 
+	arc_set_early_base_baud(dt_root);
+
 	return mdesc;
 }
Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH v2 2/3] serial: 8250_early: prepare for dynamic BASE_BAUD

In reply to Vineet Gupta

Hi Vineet,

Quoted 42 lines · Vineet Gupta

BASE_BAUD is pain in neck for multi-platform support as it hard codes at build time the clk value for early uart.

Mitigate this by allowing arches/platforms to provide their own version which can do dynamic setup based on DT values etc (see next patch for usage)

This was needed for ARC SDP platforms based on 2 different FPGA flows, each with a different UART clk value.

Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 drivers/tty/serial/earlycon.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/tty/serial/earlycon.c +9 -0
index 64fe25a4285c..bfd3537739e0 100644
@@ -54,6 +54,15 @@ static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
 	return base;
 }
 
+unsigned int __weak __init earlycon_base_baud(char *options)
+{
+#ifdef BASE_BAUD
+	return BASE_BAUD;
+#else
+	return 1843200/16;	/* x86 early console */
+#endif
+}
+
 static int __init parse_options(struct earlycon_device *device,
 				char *options)
 {

drivers/tty/serial/earlycon.c static int __init parse_options(struct earlycon_device *device, · line 99

Quoted 5 lines
drivers/tty/serial/earlycon.c +1 -1
@@ -87,7 +96,7 @@ static int __init parse_options(struct earlycon_device *device,
 		return -EINVAL;
 	}
 
-	port->uartclk = BASE_BAUD * 16;
+	port->uartclk = earlycon_base_baud(options) * 16;

I don't understand why BASE_BAUD can't be defined by arc as arc_earlycon_base_baud(). Why is the weak binding necessary?

I'm pushing back on this because port initialization (and especially 8250) is already a ridiculous spiderweb.

Regards,
Peter Hurley

Quoted 12 lines
drivers/tty/serial/earlycon.c +1 -1
 	options = strchr(options, ',');
 	if (options) {
@@ -156,7 +165,7 @@ int __init of_setup_earlycon(unsigned long addr,
 
 	port->iotype = UPIO_MEM;
 	port->mapbase = addr;
-	port->uartclk = BASE_BAUD * 16;
+	port->uartclk = earlycon_base_baud(NULL) * 16;
 	port->membase = earlycon_map(addr, SZ_4K);
 
 	early_console_dev.con->data = &early_console_dev;
#4 lore raw

Re: [PATCH v2 2/3] serial: 8250_early: prepare for dynamic BASE_BAUD

Hi Peter,

Quoted 7 lines · Peter Hurley

Hi Vineet,

drivers/tty/serial/earlycon.c static int __init parse_options(struct earlycon_device *device, · line 99

Quoted 2 lines · Vineet Gupta
drivers/tty/serial/earlycon.c +1 -1
-	port->uartclk = BASE_BAUD * 16;
+	port->uartclk = earlycon_base_baud(options) * 16;

I don't understand why BASE_BAUD can't be defined by arc as arc_earlycon_base_baud(). Why is the weak binding necessary?

Indeed weak semantics are not really needed - even now we have what u r suggesting
- the missing part was existing conditional definition which will simply go away if I implement the fdt parsing in that singly defined function. Thx for the tip :-)

In that case this requires no change to driver and I can fixup the platform - perhaps ur Ack on next version will be nice.
Also what do u think of the early IER optimization ?

Quoted 3 lines

I'm pushing back on this because port initialization (and especially 8250) is already a ridiculous spiderweb.

I totally agree.

Thx,
-Vineet

Quoted 17 lines

Regards,
Peter Hurley

Quoted 12 lines
drivers/tty/serial/earlycon.c +1 -1
 	options = strchr(options, ',');
 	if (options) {
@@ -156,7 +165,7 @@ int __init of_setup_earlycon(unsigned long addr,
 
 	port->iotype = UPIO_MEM;
 	port->mapbase = addr;
-	port->uartclk = BASE_BAUD * 16;
+	port->uartclk = earlycon_base_baud(NULL) * 16;
 	port->membase = earlycon_map(addr, SZ_4K);
 
 	early_console_dev.con->data = &early_console_dev;
#5 lore raw

Re: [PATCH v2 2/3] serial: 8250_early: prepare for dynamic BASE_BAUD

Quoted 11 lines · Vineet Gupta

Hi Peter,

Quoted 7 lines · Peter Hurley

Hi Vineet,

drivers/tty/serial/earlycon.c static int __init parse_options(struct earlycon_device *device, · line 99

Quoted 2 lines · Vineet Gupta
drivers/tty/serial/earlycon.c +1 -1
-	port->uartclk = BASE_BAUD * 16;
+	port->uartclk = earlycon_base_baud(options) * 16;

I don't understand why BASE_BAUD can't be defined by arc as arc_earlycon_base_baud(). Why is the weak binding necessary?

Quoted 6 lines

Indeed weak semantics are not really needed - even now we have what u r suggesting
- the missing part was existing conditional definition which will simply go away if I implement the fdt parsing in that singly defined function. Thx for the tip :-)

In that case this requires no change to driver and I can fixup the platform - perhaps ur Ack on next version will be nice.

Will do.

Quoted 1 line

Also what do u think of the early IER optimization ?

Seems ok except the commit changelog is wrong: IER is disabled twice per _line_. How did you profile it? It's ok if the answer is "seemed faster"; I'm just curious.

Regards,
Peter Hurley

Quoted 26 lines
Quoted 2 lines

I'm pushing back on this because port initialization (and especially 8250) is already a ridiculous spiderweb.

I totally agree.

Thx,
-Vineet

Quoted 17 lines

Regards,
Peter Hurley

Quoted 12 lines
drivers/tty/serial/earlycon.c +1 -1
 	options = strchr(options, ',');
 	if (options) {
@@ -156,7 +165,7 @@ int __init of_setup_earlycon(unsigned long addr,
 
 	port->iotype = UPIO_MEM;
 	port->mapbase = addr;
-	port->uartclk = BASE_BAUD * 16;
+	port->uartclk = earlycon_base_baud(NULL) * 16;
 	port->membase = earlycon_map(addr, SZ_4K);
 
 	early_console_dev.con->data = &early_console_dev;
#6 lore raw

Re: [PATCH v2 2/3] serial: 8250_early: prepare for dynamic BASE_BAUD

Quoted 4 lines · Peter Hurley
Quoted 1 line

Also what do u think of the early IER optimization ?

Seems ok except the commit changelog is wrong: IER is disabled twice per _line_. How did you profile it? It's ok if the answer is "seemed faster"; I'm just curious.

Looking at the code yes this would be per line - but I vaguely remember seeing it for every char - this was when debugging a systemC model for 8250. Its been a while... I'd added prints in the model whenever IER would wiggle and it was just being written with 0's again and again when in the early polling based printing mode.

I'll send a revised version with fixed changelog.

Thx,
-Vineet

#7 lore raw

Re: [PATCH v2 2/3] serial: 8250_early: prepare for dynamic BASE_BAUD

Quoted 10 lines · Vineet Gupta
Quoted 4 lines · Peter Hurley
Quoted 1 line

Also what do u think of the early IER optimization ?

Seems ok except the commit changelog is wrong: IER is disabled twice per _line_. How did you profile it? It's ok if the answer is "seemed faster"; I'm just curious.

Looking at the code yes this would be per line - but I vaguely remember seeing it for every char - this was when debugging a systemC model for 8250. Its been a while... I'd added prints in the model whenever IER would wiggle and it was just being written with 0's again and again when in the early polling based printing mode.

Maybe that was while running kgdb through serial8250_put_poll_char(), which is per-char.

Regards,
Peter Hurley