Skip to contentSkip to conversation

OF earlycon cleanup

PATCH Superseded Peter Hurley 1 participant 15 messages Mar 6, 2015

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover OF earlycon cleanup

I thought I'd respin this to address the bugs in v1.

I'm still having an open conversation with Rob Herring about the OF_EARLYCON_DECLARE macro and earlycon console names.

* Changes from v1 *

- Rebase on top of device-tree compiler patch submission, "libfdt: Add fdt_path_offset_namelen()"
- Fixed x86 build breakage, conditionally compile of_setup_earlycon();
Note: this should have already been the case since of_setup_earlycon() is dead code without CONFIG_OF_EARLY_FLATTREE
- Fixed Geert's suggestion to change the printf specifier for ->mapbase
- Fixed initial console index value for earlycon name without trailing numerals

Hi Greg, Grant & Rob,

This patch series builds on my earlier "Extensible console matching & direct earlycon" to add several useful features to earlycon:
* Proper port i/o configuration from DT node with of_serial properties (such as reg-io-width, reg-shift and reg-offset)
* Proper console name & index initialization from earlycon name (for both command line and DT-defined earlycons)
* Support for DT 'stdout-path' options pass-through to earlycon setup
* Improved log messages for troubleshooting
* Support for multiple OF earlycon declarations so different compatible strings can specify the same OF earlycon

Lastly, this patch series adds an omap8250 OF earlycon. I don't think the last patch requires the "Split 8250 driver" to work but it won't apply cleanly without it.

Requires: 1) "libfdt: Add fdt_path_offset_namelen()"
2) the last patch which adds omap8250 earlycon requires some kind of fixmap support, such as "ARM: early fixmap support for earlycon", which has not yet been accepted upstream.

Regards,

Peter Hurley (14):
of: earlycon: Fix 'stdout-path' with ':' path terminator
serial: earlycon: Fixup earlycon console name and index
serial: earlycon: Emit earlycon name in the OF table
of: earlycon: Fixup earlycon console name and index
of: earlycon: Add options string handling
of: earlycon: of_setup_earlycon() requires CONFIG_OF_EARLY_FLATTREE
of: earlycon: Initialize port fields from DT properties
of: earlycon: Move address translation to of_setup_earlycon()
serial: earlycon: Common log banner for command line and DT
serial: earlycon: Show the earlycon "driver" in banner
of: earlycon: Allow multiple OF_EARLYCON_DECLARE() with same name
of: earlycon: Log more helpful message if earlycon not found
serial: 8250_early: Use port->regshift
serial: 8250_omap: Add omap8250 earlycon

 drivers/of/fdt.c                     |  18 +++----
 drivers/of/fdt_address.c             |  11 +++-
 drivers/tty/serial/8250/8250_early.c |  29 +++++++++-
 drivers/tty/serial/earlycon.c        | 100 ++++++++++++++++++++++++++++-------
 include/linux/of_fdt.h               |   2 +-
 include/linux/serial_core.h          |  20 +++++--
 6 files changed, 144 insertions(+), 36 deletions(-)
Signature · 1 line
2.3.1
#1 lore raw

PATCH v2 1/14 of: earlycon: Fix 'stdout-path' with ':' path terminator

stdout-path defines ':' as a path terminator and commit 75c28c09af99a ("of: add optional options parameter to of_find_node_by_path()") added the necessary support to parse paths terminated with ':'. commit 7914a7c5651a5 ("of: support passing console options with stdout-path") added options string support to the stdout-path property, which broke earlycon.

Add the same support to earlycon to process 'stdout-path' properties which contain an options string.

Requires: "libfdt: Add fdt_path_offset_namelen()"

---
 drivers/of/fdt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/of/fdt.c +4 -2
index 3a896c9..7cef9f9 100644
@@ -765,7 +765,7 @@ extern struct of_device_id __earlycon_of_table[];
 static int __init early_init_dt_scan_chosen_serial(void)
 {
 	int offset;
-	const char *p;
+	const char *p, *q;
 	int l;
 	const struct of_device_id *match = __earlycon_of_table;
 	const void *fdt = initial_boot_params;
@@ -782,8 +782,10 @@ static int __init early_init_dt_scan_chosen_serial(void)
 	if (!p || !l)
 		return -ENOENT;
 
+	q = strchrnul(p, ':');
+
 	/* Get the node specified by stdout-path */
-	offset = fdt_path_offset(fdt, p);
+	offset = fdt_path_offset_namelen(fdt, p, (int)(q - p));
 	if (offset < 0)
 		return -ENODEV;
 
Signature · 1 line
2.3.1
#2 lore raw

PATCH v2 2/14 serial: earlycon: Fixup earlycon console name and index

In reply to Peter Hurley

Properly initialize the struct console::name and ::index for the registering earlycon. The earlycon's ::index == 0 for earlycons without trailing numerals and the numeral value for earlycons with trailing numerals. For example, exynos4210 earlycon ::name == "exynos" and ::index = 4210. Earlycons with embedded numerals will have all non-trailing numerals as part of the name; for example, s3c2412 earlycon ::name == "s3c" and ::index == 2412. This ackward scheme was initially supported for the uart8250 earlycon; this patch extends this support to the other earlycon "drivers".

Introduce earlycon_init() which performs the string scanning and initializes the ::name and ::index fields; encapsulate the other console field initializations within.

---
 drivers/tty/serial/earlycon.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/tty/serial/earlycon.c +22 -3
index 5fdc9f3..1ffdb61 100644
@@ -28,9 +28,9 @@
 #include <asm/serial.h>
 
 static struct console early_con = {
-	.name =		"uart", /* 8250 console switch requires this name */
+	.name =		"uart",		/* fixed up at earlycon registration */
 	.flags =	CON_PRINTBUFFER | CON_BOOT,
-	.index =	-1,
+	.index =	0,
 };
 
 static struct earlycon_device early_console_dev = {
@@ -61,6 +61,25 @@ static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
 	return base;
 }
 
+static void __init earlycon_init(struct earlycon_device *device,
+				 const char *name)
+{
+	struct console *earlycon = device->con;
+	const char *s;
+	size_t len;
+
+	/* scan backwards from end of string for first non-numeral */
+	for (s = name + strlen(name);
+	     s > name && s[-1] >= '0' && s[-1] <= '9';
+	     s--)
+		;
+	if (*s)
+		earlycon->index = simple_strtoul(s, NULL, 10);
+	len = s - name;
+	strlcpy(earlycon->name, name, min(len + 1, sizeof(earlycon->name)));
+	earlycon->data = &early_console_dev;
+}
+
 static int __init parse_options(struct earlycon_device *device, char *options)
 {
 	struct uart_port *port = &device->port;
@@ -116,7 +135,7 @@ static int __init register_earlycon(char *buf, const struct earlycon_id *match)
 	if (port->mapbase)
 		port->membase = earlycon_map(port->mapbase, 64);
 
-	early_console_dev.con->data = &early_console_dev;
+	earlycon_init(&early_console_dev, match->name);
 	err = match->setup(&early_console_dev, buf);
 	if (err < 0)
 		return err;
Signature · 1 line
2.3.1
#3 lore raw

PATCH v2 3/14 serial: earlycon: Emit earlycon name in the OF table

In reply to Peter Hurley

The OF device name of the earlycon is never used because there is no device; re-purpose the name field to store the earlycon name in the OF earlycon table. Earlycon will use the table entry to fixup the console name and index.

---
 include/linux/serial_core.h | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
include/linux/serial_core.h +13 -2
index 8aeec49..c523785 100644
@@ -29,6 +29,7 @@
 #include <linux/tty.h>
 #include <linux/mutex.h>
 #include <linux/sysrq.h>
+#include <linux/mod_devicetable.h>
 #include <uapi/linux/serial_core.h>
 
 #ifdef CONFIG_SERIAL_CORE_CONSOLE
@@ -353,8 +354,18 @@ extern int of_setup_earlycon(unsigned long addr,
 		 = { .name  = __stringify(_name),			\
 		     .setup = func  }
 
-#define OF_EARLYCON_DECLARE(name, compat, fn)				\
-	_OF_DECLARE(earlycon, name, compat, fn, void *)
+#ifdef CONFIG_OF
+#define EARLYCON_OF_TABLE_ATTR __used __section(__earlycon_of_table)
+#else
+#define EARLYCON_OF_TABLE_ATTR __attribute__((unused))
+#endif
+
+#define OF_EARLYCON_DECLARE(_name, compat, fn)				\
+	static const struct of_device_id __of_table_##_name		\
+		EARLYCON_OF_TABLE_ATTR					\
+		 = { .name = __stringify(_name),			\
+		     .compatible = compat,				\
+		     .data = (fn == (void *)NULL) ? fn : fn  }
 
 struct uart_port *uart_get_console(struct uart_port *ports, int nr,
 				   struct console *c);
Signature · 1 line
2.3.1
#4 lore raw

PATCH v2 4/14 of: earlycon: Fixup earlycon console name and index

In reply to Peter Hurley

Use the console name embedded in the OF earlycon table by the OF_EARLYCON_DECLARE() macro to initialize the struct console::name and ::index fields.

---
 drivers/of/fdt.c              | 2 +-
 drivers/tty/serial/earlycon.c | 5 +++--
 include/linux/serial_core.h   | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)
drivers/of/fdt.c +1 -1
index 7cef9f9..777c894 100644
@@ -800,7 +800,7 @@ static int __init early_init_dt_scan_chosen_serial(void)
 		if (!addr)
 			return -ENXIO;
 
-		of_setup_earlycon(addr, match->data);
+		of_setup_earlycon(addr, match);
 		return 0;
 	}
 	return -ENODEV;
drivers/tty/serial/earlycon.c +3 -2
index 1ffdb61..bfe5e27 100644
@@ -218,17 +218,18 @@ static int __init param_setup_earlycon(char *buf)
 early_param("earlycon", param_setup_earlycon);
 
 int __init of_setup_earlycon(unsigned long addr,
-			     int (*setup)(struct earlycon_device *, const char *))
+			     const struct of_device_id *match)
 {
 	int err;
 	struct uart_port *port = &early_console_dev.port;
+	int (*setup)(struct earlycon_device *, const char *) = match->data;
 
 	port->iotype = UPIO_MEM;
 	port->mapbase = addr;
 	port->uartclk = BASE_BAUD * 16;
 	port->membase = earlycon_map(addr, SZ_4K);
 
-	early_console_dev.con->data = &early_console_dev;
+	earlycon_init(&early_console_dev, match->name);
 	err = setup(&early_console_dev, NULL);
 	if (err < 0)
 		return err;
include/linux/serial_core.h +1 -1
index c523785..a2db5bd 100644
@@ -346,7 +346,7 @@ struct earlycon_id {
 
 extern int setup_earlycon(char *buf);
 extern int of_setup_earlycon(unsigned long addr,
-			     int (*setup)(struct earlycon_device *, const char *));
+			     const struct of_device_id *match);
 
 #define EARLYCON_DECLARE(_name, func)					\
 	static const struct earlycon_id __earlycon_##_name		\
Signature · 1 line
2.3.1
#5 lore raw

PATCH v2 5/14 of: earlycon: Add options string handling

In reply to Peter Hurley

Pass-through any options string in the 'stdout-path' property to the earlycon "driver" setup.

---
 drivers/of/fdt.c              | 6 ++++--
 drivers/tty/serial/earlycon.c | 9 +++++++--
 include/linux/serial_core.h   | 3 ++-
 3 files changed, 13 insertions(+), 5 deletions(-)
drivers/of/fdt.c +4 -2
index 777c894..a8ad540 100644
@@ -765,7 +765,7 @@ extern struct of_device_id __earlycon_of_table[];
 static int __init early_init_dt_scan_chosen_serial(void)
 {
 	int offset;
-	const char *p, *q;
+	const char *p, *q, *options = NULL;
 	int l;
 	const struct of_device_id *match = __earlycon_of_table;
 	const void *fdt = initial_boot_params;
@@ -783,6 +783,8 @@ static int __init early_init_dt_scan_chosen_serial(void)
 		return -ENOENT;
 
 	q = strchrnul(p, ':');
+	if (*q != '\0')
+		options = q + 1;
 
 	/* Get the node specified by stdout-path */
 	offset = fdt_path_offset_namelen(fdt, p, (int)(q - p));
@@ -800,7 +802,7 @@ static int __init early_init_dt_scan_chosen_serial(void)
 		if (!addr)
 			return -ENXIO;
 
-		of_setup_earlycon(addr, match);
+		of_setup_earlycon(addr, match, options);
 		return 0;
 	}
 	return -ENODEV;
drivers/tty/serial/earlycon.c +7 -2
index bfe5e27..023ebbb 100644
@@ -218,7 +218,8 @@ static int __init param_setup_earlycon(char *buf)
 early_param("earlycon", param_setup_earlycon);
 
 int __init of_setup_earlycon(unsigned long addr,
-			     const struct of_device_id *match)
+			     const struct of_device_id *match,
+			     const char *options)
 {
 	int err;
 	struct uart_port *port = &early_console_dev.port;
@@ -229,8 +230,12 @@ int __init of_setup_earlycon(unsigned long addr,
 	port->uartclk = BASE_BAUD * 16;
 	port->membase = earlycon_map(addr, SZ_4K);
 
+	if (options) {
+		strlcpy(early_console_dev.options, options,
+			sizeof(early_console_dev.options));
+	}
 	earlycon_init(&early_console_dev, match->name);
-	err = setup(&early_console_dev, NULL);
+	err = setup(&early_console_dev, options);
 	if (err < 0)
 		return err;
 	if (!early_console_dev.con->write)
include/linux/serial_core.h +2 -1
index a2db5bd..ebbcd43 100644
@@ -346,7 +346,8 @@ struct earlycon_id {
 
 extern int setup_earlycon(char *buf);
 extern int of_setup_earlycon(unsigned long addr,
-			     const struct of_device_id *match);
+			     const struct of_device_id *match,
+			     const char *options);
 
 #define EARLYCON_DECLARE(_name, func)					\
 	static const struct earlycon_id __earlycon_##_name		\
Signature · 1 line
2.3.1
#6 lore raw

PATCH v2 6/14 of: earlycon: of_setup_earlycon() requires CONFIG_OF_EARLY_FLATTREE

In reply to Peter Hurley

DT earlycon is only supported for CONFIG_OF_EARLY_FLATTREE=y; exclude of_setup_earlycon() if not defined.

---
 drivers/tty/serial/earlycon.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tty/serial/earlycon.c +4 -0
index 023ebbb..1a37f27 100644
@@ -217,6 +217,8 @@ static int __init param_setup_earlycon(char *buf)
 }
 early_param("earlycon", param_setup_earlycon);
 
+#ifdef CONFIG_OF_EARLY_FLATTREE
+
 int __init of_setup_earlycon(unsigned long addr,
 			     const struct of_device_id *match,
 			     const char *options)
@@ -245,3 +247,5 @@ int __init of_setup_earlycon(unsigned long addr,
 	register_console(early_console_dev.con);
 	return 0;
 }
+
+#endif /* CONFIG_OF_EARLY_FLATTREE */
Signature · 1 line
2.3.1
#7 lore raw

PATCH v2 7/14 of: earlycon: Initialize port fields from DT properties

In reply to Peter Hurley

Read the optional "reg-offset", "reg-shift" and "reg-io-width" properties and initialize the respective struct uart_port field if found.

NB: These bindings are common to several drivers and the values merely indicate the default value; the registering earlycon setup() method can simply override the values if required.

---
 drivers/of/fdt.c              |  2 +-
 drivers/tty/serial/earlycon.c | 27 +++++++++++++++++++++++++++
 include/linux/serial_core.h   |  1 +
 3 files changed, 29 insertions(+), 1 deletion(-)
drivers/of/fdt.c +1 -1
index a8ad540..4de1171 100644
@@ -802,7 +802,7 @@ static int __init early_init_dt_scan_chosen_serial(void)
 		if (!addr)
 			return -ENXIO;
 
-		of_setup_earlycon(addr, match, options);
+		of_setup_earlycon(addr, match, offset, options);
 		return 0;
 	}
 	return -ENODEV;
drivers/tty/serial/earlycon.c +27 -0
index 1a37f27..5b3d2b5 100644
@@ -21,6 +21,10 @@
 #include <linux/sizes.h>
 #include <linux/mod_devicetable.h>
 
+#ifdef CONFIG_OF_EARLY_FLATTREE
+#include <linux/of_fdt.h>
+#endif
+
 #ifdef CONFIG_FIX_EARLYCON_MEM
 #include <asm/fixmap.h>
 #endif
@@ -221,17 +225,40 @@ early_param("earlycon", param_setup_earlycon);
 
 int __init of_setup_earlycon(unsigned long addr,
 			     const struct of_device_id *match,
+			     unsigned long node,
 			     const char *options)
 {
 	int err;
 	struct uart_port *port = &early_console_dev.port;
 	int (*setup)(struct earlycon_device *, const char *) = match->data;
+	const __be32 *val;
 
 	port->iotype = UPIO_MEM;
 	port->mapbase = addr;
 	port->uartclk = BASE_BAUD * 16;
 	port->membase = earlycon_map(addr, SZ_4K);
 
+	val = of_get_flat_dt_prop(node, "reg-offset", NULL);
+	if (val)
+		port->mapbase += be32_to_cpu(*val);
+	val = of_get_flat_dt_prop(node, "reg-shift", NULL);
+	if (val)
+		port->regshift = be32_to_cpu(*val);
+	val = of_get_flat_dt_prop(node, "reg-io-width", NULL);
+	if (val) {
+		switch (be32_to_cpu(*val)) {
+		case 1:
+			port->iotype = UPIO_MEM;
+			break;
+		case 4:
+			port->iotype = UPIO_MEM32;
+			break;
+		default:
+			pr_warn("[%s] unsupported reg-io-width\n", match->name);
+			return -EINVAL;
+		}
+	}
+
 	if (options) {
 		strlcpy(early_console_dev.options, options,
 			sizeof(early_console_dev.options));
include/linux/serial_core.h +1 -0
index ebbcd43..c8e4e8f 100644
@@ -347,6 +347,7 @@ struct earlycon_id {
 extern int setup_earlycon(char *buf);
 extern int of_setup_earlycon(unsigned long addr,
 			     const struct of_device_id *match,
+			     unsigned long node,
 			     const char *options);
 
 #define EARLYCON_DECLARE(_name, func)					\
Signature · 1 line
2.3.1
#8 lore raw

PATCH v2 8/14 of: earlycon: Move address translation to of_setup_earlycon()

In reply to Peter Hurley

Cleanup the early DT/earlycon separation; remove the 'addr' parameter from of_setup_earlycon() and get the uart phys addr directly with a new wrapper function, of_flat_dt_translate_addr(). Limit fdt_translate_address() to file scope.

---
 drivers/of/fdt.c              |  7 +------
 drivers/of/fdt_address.c      | 11 ++++++++++-
 drivers/tty/serial/earlycon.c | 11 +++++++----
 include/linux/of_fdt.h        |  2 +-
 include/linux/serial_core.h   |  3 +--
 5 files changed, 20 insertions(+), 14 deletions(-)
drivers/of/fdt.c +1 -6
index 4de1171..0850517 100644
@@ -792,17 +792,12 @@ static int __init early_init_dt_scan_chosen_serial(void)
 		return -ENODEV;
 
 	while (match->compatible[0]) {
-		unsigned long addr;
 		if (fdt_node_check_compatible(fdt, offset, match->compatible)) {
 			match++;
 			continue;
 		}
 
-		addr = fdt_translate_address(fdt, offset);
-		if (!addr)
-			return -ENXIO;
-
-		of_setup_earlycon(addr, match, offset, options);
+		of_setup_earlycon(match, offset, options);
 		return 0;
 	}
 	return -ENODEV;
drivers/of/fdt_address.c +10 -1
index 8d3dc6f..dca8f9b 100644
@@ -161,7 +161,7 @@ static int __init fdt_translate_one(const void *blob, int parent,
  * that can be mapped to a cpu physical address). This is not really specified
  * that way, but this is traditionally the way IBM at least do things
  */
-u64 __init fdt_translate_address(const void *blob, int node_offset)
+static u64 __init fdt_translate_address(const void *blob, int node_offset)
 {
 	int parent, len;
 	const struct of_bus *bus, *pbus;
@@ -239,3 +239,12 @@ u64 __init fdt_translate_address(const void *blob, int node_offset)
  bail:
 	return result;
 }
+
+/**
+ * of_flat_dt_translate_address - translate DT addr into CPU phys addr
+ * @node: node in the flat blob
+ */
+u64 __init of_flat_dt_translate_address(unsigned long node)
+{
+	return fdt_translate_address(initial_boot_params, node);
+}
drivers/tty/serial/earlycon.c +7 -4
index 5b3d2b5..6449834 100644
@@ -223,8 +223,7 @@ early_param("earlycon", param_setup_earlycon);
 
 #ifdef CONFIG_OF_EARLY_FLATTREE
 
-int __init of_setup_earlycon(unsigned long addr,
-			     const struct of_device_id *match,
+int __init of_setup_earlycon(const struct of_device_id *match,
 			     unsigned long node,
 			     const char *options)
 {
@@ -234,9 +233,13 @@ int __init of_setup_earlycon(unsigned long addr,
 	const __be32 *val;
 
 	port->iotype = UPIO_MEM;
-	port->mapbase = addr;
+	port->mapbase = of_flat_dt_translate_address(node);
+	if (!port->mapbase) {
+		pr_warn("[%s] bad address\n", match->name);
+		return -ENXIO;
+	}
 	port->uartclk = BASE_BAUD * 16;
-	port->membase = earlycon_map(addr, SZ_4K);
+	port->membase = earlycon_map(port->mapbase, SZ_4K);
 
 	val = of_get_flat_dt_prop(node, "reg-offset", NULL);
 	if (val)
include/linux/of_fdt.h +1 -1
index 0ff360d..d31e6cb 100644
@@ -85,7 +85,7 @@ extern void unflatten_device_tree(void);
 extern void unflatten_and_copy_device_tree(void);
 extern void early_init_devtree(void *);
 extern void early_get_first_memblock_info(void *, phys_addr_t *);
-extern u64 fdt_translate_address(const void *blob, int node_offset);
+extern u64 of_flat_dt_translate_address(unsigned long node);
 extern void of_fdt_limit_memory(int limit);
 #else /* CONFIG_OF_FLATTREE */
 static inline void early_init_fdt_scan_reserved_mem(void) {}
include/linux/serial_core.h +1 -2
index c8e4e8f..675d36f 100644
@@ -345,8 +345,7 @@ struct earlycon_id {
 };
 
 extern int setup_earlycon(char *buf);
-extern int of_setup_earlycon(unsigned long addr,
-			     const struct of_device_id *match,
+extern int of_setup_earlycon(const struct of_device_id *match,
 			     unsigned long node,
 			     const char *options);
 
Signature · 1 line
2.3.1
#9 lore raw

PATCH v2 9/14 serial: earlycon: Common log banner for command line and DT

In reply to Peter Hurley

Refactor the command line earlycon banner into earlycon_init() so both earlycon startup methods output an info banner.

---
 drivers/tty/serial/earlycon.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/tty/serial/earlycon.c +11 -10
index 6449834..680ff4a 100644
@@ -69,6 +69,7 @@ static void __init earlycon_init(struct earlycon_device *device,
 				 const char *name)
 {
 	struct console *earlycon = device->con;
+	struct uart_port *port = &device->port;
 	const char *s;
 	size_t len;
 
@@ -82,6 +83,16 @@ static void __init earlycon_init(struct earlycon_device *device,
 	len = s - name;
 	strlcpy(earlycon->name, name, min(len + 1, sizeof(earlycon->name)));
 	earlycon->data = &early_console_dev;
+
+	if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM32)
+		pr_info("Early serial console at MMIO%s 0x%llx (options '%s')\n",
+			(port->iotype == UPIO_MEM32) ? "32" : "",
+			(unsigned long long)port->mapbase,
+			device->options);
+	else
+		pr_info("Early serial console at I/O port 0x%lx (options '%s')\n",
+			port->iobase,
+			device->options);
 }
 
 static int __init parse_options(struct earlycon_device *device, char *options)
@@ -113,16 +124,6 @@ static int __init parse_options(struct earlycon_device *device, char *options)
 		strlcpy(device->options, options, length);
 	}
 
-	if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM32)
-		pr_info("Early serial console at MMIO%s 0x%llx (options '%s')\n",
-			(port->iotype == UPIO_MEM32) ? "32" : "",
-			(unsigned long long)port->mapbase,
-			device->options);
-	else
-		pr_info("Early serial console at I/O port 0x%lx (options '%s')\n",
-			port->iobase,
-			device->options);
-
 	return 0;
 }
 
Signature · 1 line
2.3.1
#10 lore raw

PATCH v2 10/14 serial: earlycon: Show the earlycon "driver" in banner

In reply to Peter Hurley

Output the earlycon "driver" from the just-parsed console ::name and ::index fields.

NB: ->mapbase is a resource_size_t so use %pa format specifier

---
 drivers/tty/serial/earlycon.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/tty/serial/earlycon.c +5 -3
index 680ff4a..0d93c36 100644
@@ -85,12 +85,14 @@ static void __init earlycon_init(struct earlycon_device *device,
 	earlycon->data = &early_console_dev;
 
 	if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM32)
-		pr_info("Early serial console at MMIO%s 0x%llx (options '%s')\n",
+		pr_info("%s%d at MMIO%s %pa (options '%s')\n",
+			earlycon->name, earlycon->index,
 			(port->iotype == UPIO_MEM32) ? "32" : "",
-			(unsigned long long)port->mapbase,
+			&port->mapbase,
 			device->options);
 	else
-		pr_info("Early serial console at I/O port 0x%lx (options '%s')\n",
+		pr_info("%s%d at I/O port 0x%lx (options '%s')\n",
+			earlycon->name, earlycon->index,
 			port->iobase,
 			device->options);
 }
Signature · 1 line
2.3.1
#11 lore raw

PATCH v2 11/14 of: earlycon: Allow multiple OF_EARLYCON_DECLARE() with same name

In reply to Peter Hurley

Since matching is performed only on the compatible string, allow multiple declarations of OF_EARLYCON_DECLARE() with the same name. For example,

    OF_EARLYCON_DECLARE(omap8250, "ti,omap2-uart", early_omap8250_setup);
    OF_EARLYCON_DECLARE(omap8250, "ti,omap3-uart", early_omap8250_setup);
    OF_EARLYCON_DECLARE(omap8250, "ti,omap4-uart", early_omap8250_setup);

Generate a unique identifier for each declaration in the current compilation unit.

---
 include/linux/serial_core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/serial_core.h +1 -1
index 675d36f..0a711a7 100644
@@ -362,7 +362,7 @@ extern int of_setup_earlycon(const struct of_device_id *match,
 #endif
 
 #define OF_EARLYCON_DECLARE(_name, compat, fn)				\
-	static const struct of_device_id __of_table_##_name		\
+	static const struct of_device_id __UNIQUE_ID(_name)		\
 		EARLYCON_OF_TABLE_ATTR					\
 		 = { .name = __stringify(_name),			\
 		     .compatible = compat,				\
Signature · 1 line
2.3.1
#12 lore raw

PATCH v2 12/14 of: earlycon: Log more helpful message if earlycon not found

In reply to Peter Hurley

Earlycon may fail to initialize for a variety of reasons, most of which log the default early param message. If the earlycon is not found, log the OF path which was not found (and suppress the default early param message).

---
 drivers/of/fdt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/fdt.c +2 -1
index 0850517..7b8eae3 100644
@@ -800,7 +800,8 @@ static int __init early_init_dt_scan_chosen_serial(void)
 		of_setup_earlycon(match, offset, options);
 		return 0;
 	}
-	return -ENODEV;
+	pr_warn("earlycon: %s no match\n", p);
+	return 0;
 }
 
 static int __init setup_of_earlycon(char *buf)
Signature · 1 line
2.3.1
#13 lore raw

PATCH v2 13/14 serial: 8250_early: Use port->regshift

In reply to Peter Hurley

earlycon initializes struct uart_port::regshift to the correct value for UPIO_MEM32 already. Use the port field rather than hard-coded value.

This enables broader support for various i/o access methods in 8250 earlycon (eg., omap8250 earlycon).

---
 drivers/tty/serial/8250/8250_early.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_early.c +6 -2
index a2b4e58..53db31c 100644
@@ -38,11 +38,13 @@
 
 unsigned int __weak __init serial8250_early_in(struct uart_port *port, int offset)
 {
+	offset <<= port->regshift;
+
 	switch (port->iotype) {
 	case UPIO_MEM:
 		return readb(port->membase + offset);
 	case UPIO_MEM32:
-		return readl(port->membase + (offset << 2));
+		return readl(port->membase + offset);
 	case UPIO_PORT:
 		return inb(port->iobase + offset);
 	default:
@@ -52,12 +54,14 @@ unsigned int __weak __init serial8250_early_in(struct uart_port *port, int offse
 
 void __weak __init serial8250_early_out(struct uart_port *port, int offset, int value)
 {
+	offset <<= port->regshift;
+
 	switch (port->iotype) {
 	case UPIO_MEM:
 		writeb(value, port->membase + offset);
 		break;
 	case UPIO_MEM32:
-		writel(value, port->membase + (offset << 2));
+		writel(value, port->membase + offset);
 		break;
 	case UPIO_PORT:
 		outb(value, port->iobase + offset);
Signature · 1 line
2.3.1
#14 lore raw

PATCH v2 14/14 serial: 8250_omap: Add omap8250 earlycon

In reply to Peter Hurley

Add DT earlycon for 8250_omap driver. This boot console is included for kernels built with CONFIG_SERIAL_EARLYCON=y, CONFIG_OF=y, CONFIG_SERIAL_8250_OMAP=y, and CONFIG_OF_EARLY_FLATTREE=y.

This boot console is enabled with the command line option "earlycon" (without "=<name>...") when the DT 'stdout-path' property matches a compatible uart. For example,

/ {
chosen {
stdout-path = "serial0:115200";
};

....

   aliases {
   	serial0 = &uart0;
   };

....

ocp : ocp {

   	uart0 : serial@44e09000 {
	      compatible = "ti,omap3-uart";
	}

};
};

---
 drivers/tty/serial/8250/8250_early.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/tty/serial/8250/8250_early.c +21 -0
index 53db31c..daa983d 100644
@@ -169,5 +169,26 @@ static int __init early_serial8250_setup(struct earlycon_device *device,
 	device->con->write = early_serial8250_write;
 	return 0;
 }
+
 EARLYCON_DECLARE(uart8250, early_serial8250_setup);
 EARLYCON_DECLARE(uart, early_serial8250_setup);
+
+#ifdef CONFIG_SERIAL_8250_OMAP
+
+static int __init early_omap8250_setup(struct earlycon_device *device,
+					 const char *options)
+{
+	struct uart_port *port = &device->port;
+
+	if (!(device->port.membase || device->port.iobase))
+		return -ENODEV;
+
+	port->regshift = 2;
+	device->con->write = early_serial8250_write;
+	return 0;
+}
+
+OF_EARLYCON_DECLARE(omap8250, "ti,omap2-uart", early_omap8250_setup);
+OF_EARLYCON_DECLARE(omap8250, "ti,omap3-uart", early_omap8250_setup);
+OF_EARLYCON_DECLARE(omap8250, "ti,omap4-uart", early_omap8250_setup);
+#endif
Signature · 1 line
2.3.1