OF earlycon cleanup
Subsystems (2)
cover OF earlycon cleanup
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: "libfdt: Teach fdt_path_offset() about ':' path separator"
Regards
Peter Hurley (12):
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: 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: Id 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 | 16 +++--- drivers/of/fdt_address.c | 11 ++++- drivers/tty/serial/8250/8250_early.c | 29 ++++++++++- drivers/tty/serial/earlycon.c | 94 +++++++++++++++++++++++++++++------- include/linux/of_fdt.h | 2 +- include/linux/serial_core.h | 20 ++++++-- 6 files changed, 138 insertions(+), 34 deletions(-)
Signature · 1 line
2.3.1
PATCH 1/12 serial: earlycon: Fixup earlycon console name and index
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 | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/tty/serial/earlycon.c +21 -2
@@ -28,7 +28,7 @@#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 , };
@@ -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
PATCH 2/12 serial: earlycon: Emit earlycon name in the OF table
In reply to Peter HurleyThe 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
@@ -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
Re: [PATCH -next 02/12] serial: earlycon: Emit earlycon name in the OF table
Quoted 23 lines · 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.
Signed-off-by Peter Hurley <[email protected]>--- include/linux/serial_core.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)include/linux/serial_core.h +1
-0@@ -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
include/linux/serial_core.h extern int of_setup_earlycon(unsigned long addr, · line 357
Quoted 5 lines
include/linux/serial_core.h +0
-2@@ -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 *)
The purpose of this was to follow the same structure for all users of this. We're not there yet, but this moves in the wrong direction.
include/linux/serial_core.h extern int of_setup_earlycon(unsigned long addr, · line 366
Quoted 10 lines
include/linux/serial_core.h +10
-0+#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), \
While convenient, this is an abuse of name which is supposed to be the DT node name.
Perhaps instead of trying to make the earlycon have the right name, the real console can know the matching earlycon's name?
Rob
Quoted 8 lines
include/linux/serial_core.h +2
-1+ .compatible = compat, \ + .data = (fn == (void *)NULL) ? fn : fn }struct uart_port *uart_get_console (struct uart_port *ports,int nr,struct console *c); --2.3.1
Re: [PATCH -next 02/12] serial: earlycon: Emit earlycon name in the OF table
Quoted 27 lines · Rob Herring
Quoted 26 lines · 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.
Signed-off-by Peter Hurley <[email protected]>--- include/linux/serial_core.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)include/linux/serial_core.h +1
-0@@ -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 }
Quoted 5 lines
include/linux/serial_core.h extern int of_setup_earlycon(unsigned long addr, · line 357
Quoted 2 lines
include/linux/serial_core.h +0
-2-#define OF_EARLYCON_DECLARE (name, compat, fn) \ - _OF_DECLARE(earlycon, name, compat, fn, void *)The purpose of this was to follow the same structure for all users of this. We're not there yet, but this moves in the wrong direction.
Ok.
There's no special dependence on the earlycons needing to be of_device_ids; afaict that's simply for convenience' sake also.
Maybe this is a good time to ditch separate OF_EARLYCON_DECLARE/EARLYCON_DECLARE macros and simply use a single table to find and start the correct earlycon?
Quoted 14 lines
include/linux/serial_core.h extern int of_setup_earlycon(unsigned long addr, · line 366
Quoted 10 lines
include/linux/serial_core.h +10
-0+#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), \While convenient, this is an abuse of name which is supposed to be the DT node name.
Quoted 2 lines
Perhaps instead of trying to make the earlycon have the right name, the real console can know the matching earlycon's name?
Just to be clear here: as of the other patch series, "Extensible console matching & direct earlycon", the name and index values stored in the earlycon struct console have no effect on earlycon->console handoff (which at the moment, is supported by command line matching).
However, console names are really the basis for the whole console subsystem; I'd really like to see devicetree working within that framework rather than parallel to it.
Regards,
Peter Hurley
Quoted 8 lines
Quoted 8 lines
include/linux/serial_core.h +2
-1+ .compatible = compat, \ + .data = (fn == (void *)NULL) ? fn : fn }struct uart_port *uart_get_console (struct uart_port *ports,int nr,struct console *c); --2.3.1
PATCH 3/12 of: earlycon: Fixup earlycon console name and index
In reply to Peter HurleyUse 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
@@ -798,7 +798,7 @@ 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
@@ -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
@@ -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
PATCH 4/12 of: earlycon: Add options string handling
In reply to Peter Hurleycommit 7914a7c5651a5 ("of: support passing console options with stdout-path") added options string support to the stdout-path property.
Handle the options string for earlycon as well.
Requires: "libfdt: Teach fdt_path_offset() about ':' path separator"
--- drivers/of/fdt.c | 8 ++++++-- drivers/tty/serial/earlycon.c | 9 +++++++-- include/linux/serial_core.h | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-)
drivers/of/fdt.c +6 -2
@@ -765,7 +765,7 @@ extern struct of_device_id __earlycon_of_table[];int __init early_init_dt_scan_chosen_serial (void ) {int offset; -const char *p; +const char *p, *options;int l;const struct of_device_id *match = __earlycon_of_table;const void *fdt = initial_boot_params;
@@ -782,6 +782,10 @@ int __init early_init_dt_scan_chosen_serial(void)if (!p || !l)return -ENOENT ; + options =strchr (p,':' ); +if (options) + options++; +/* Get the node specified by stdout-path */ offset =fdt_path_offset (fdt, p);if (offset <0 )
@@ -798,7 +802,7 @@ 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
@@ -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
@@ -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
Re: [PATCH -next 04/12] of: earlycon: Add options string handling
Quoted 8 lines · Peter Hurley
commit
7914a7c5651a5("of: support passing console options with stdout-path") added options string support to the stdout-path property.Handle the options string for earlycon as well.
Requires: "libfdt: Teach
fdt_path_offset()about ':' path separator"Cc Leif Lindholm <[email protected]>Signed-off-by Peter Hurley <[email protected]>
Quoted 84 lines
--- drivers/of/fdt.c | 8 ++++++-- drivers/tty/serial/earlycon.c | 9 +++++++-- include/linux/serial_core.h | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-)drivers/of/fdt.c +6
-2@@ -765,7 +765,7 @@ extern struct of_device_id __earlycon_of_table[];int __init early_init_dt_scan_chosen_serial (void ) {int offset; -const char *p; +const char *p, *options;int l;const struct of_device_id *match = __earlycon_of_table;const void *fdt = initial_boot_params;@@ -782,6 +782,10 @@ int __init early_init_dt_scan_chosen_serial(void)if (!p || !l)return -ENOENT ; + options =strchr (p,':' ); +if (options) + options++; +/* Get the node specified by stdout-path */ offset =fdt_path_offset (fdt, p);if (offset <0 )@@ -798,7 +802,7 @@ 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@@ -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
-2@@ -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 \ --2.3.1
PATCH 5/12 of: earlycon: Initialize port fields from DT properties
In reply to Peter HurleyRead 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
@@ -802,7 +802,7 @@ 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
@@ -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
@@ -219,17 +223,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
@@ -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
Re: [PATCH -next 05/12] of: earlycon: Initialize port fields from DT properties
Quoted 8 lines · Peter Hurley
Read the optional "reg-offset", "reg-shift" and "reg-io-width" properties and initialize the respective struct
uart_portfield 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.Signed-off-by Peter Hurley <[email protected]>
Quoted 90 lines
--- 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@@ -802,7 +802,7 @@ 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@@ -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 @@ -219,17 +223,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
-1@@ -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) \ --2.3.1
PATCH 6/12 of: earlycon: Move address translation to of_setup_earlycon()
In reply to Peter HurleyCleanup 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
@@ -792,17 +792,12 @@ 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
@@ -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
@@ -221,8 +221,7 @@ 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, +int __init of_setup_earlycon (const struct of_device_id *match,unsigned long node,const char *options) {
@@ -232,9 +231,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
@@ -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
@@ -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
Re: [PATCH -next 06/12] of: earlycon: Move address translation to of_setup_earlycon()
Quoted 6 lines · 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(). Limitfdt_translate_address()to file scope.Signed-off-by Peter Hurley <[email protected]>
Quoted 117 lines
--- 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@@ -792,17 +792,12 @@ 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@@ -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@@ -221,8 +221,7 @@ 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, +int __init of_setup_earlycon (const struct of_device_id *match,unsigned long node,const char *options) {@@ -232,9 +231,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@@ -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
-3@@ -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); --2.3.1
PATCH 7/12 serial: earlycon: Common log banner for command line and DT
In reply to Peter HurleyRefactor 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
@@ -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
Re: [PATCH -next 07/12] serial: earlycon: Common log banner for command line and DT
Hi Peter,
Quoted 11 lines · Peter Hurley
drivers/tty/serial/earlycon.c +1
-0@@ -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;
drivers/tty/serial/earlycon.c static void __init earlycon_init(struct earlycon_device *device, · line 90
Quoted 8 lines
drivers/tty/serial/earlycon.c +5
-0@@ -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,
I know you're just moving this piece of code around, but mapbase is a resource_size_t (it should actually be phys_addr_t, which probably didn't exist in 2007), so it should be printed using %pa and passing a reference, instead of %llx and using a cast.
drivers/tty/serial/earlycon.c static void __init earlycon_init(struct earlycon_device *device, · line 91
Quoted 1 line
drivers/tty/serial/earlycon.c +1
-0+ device->options);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH -next 07/12] serial: earlycon: Common log banner for command line and DT
Hi Geert,
Quoted 13 lines · Geert Uytterhoeven
Hi Peter,
Quoted 10 lines · Peter Hurley
drivers/tty/serial/earlycon.c +1
-0@@ -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;
Quoted 14 lines
drivers/tty/serial/earlycon.c static void __init earlycon_init(struct earlycon_device *device, · line 90
Quoted 9 lines
drivers/tty/serial/earlycon.c +5
-0@@ -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,I know you're just moving this piece of code around, but mapbase is a
resource_size_t(it should actually bephys_addr_t, which probably didn't exist in 2007), so it should be printed using %pa and passing a reference, instead of %llx and using a cast.
Good point.
I could add that fix to the 8/12 patch which adds the earlycon name to the banner. I have to respin anyway because of a rebase error that breaks x86 build.
Regards,
Peter Hurley
PATCH 8/12 serial: earlycon: Id the earlycon "driver" in banner
In reply to Peter HurleyOutput the earlycon "driver" from the just-parsed console ::name and ::index fields.
--- drivers/tty/serial/earlycon.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/tty/serial/earlycon.c +4 -2
@@ -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 0x%llx (options '%s')\n" , + earlycon->name, earlycon->index, (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" , +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
PATCH 9/12 of: earlycon: Allow multiple OF_EARLYCON_DECLARE() with same name
In reply to Peter HurleySince 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
@@ -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
PATCH 10/12 of: earlycon: Log more helpful message if earlycon not found
In reply to Peter HurleyEarlycon 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
@@ -800,7 +800,8 @@ 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
PATCH 11/12 serial: 8250_early: Use port->regshift
In reply to Peter Hurleyearlycon 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
@@ -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 offsevoid __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
PATCH 12/12 serial: 8250_omap: Add omap8250 earlycon
In reply to Peter HurleyAdd 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
@@ -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
Quoted 13 lines · Peter Hurley
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 withof_serialproperties (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
Quoted 5 lines
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: "libfdt: Teach
fdt_path_offset()about ':' path separator"
I forgot to mention that 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.
Quoted 24 lines
Regards
Peter Hurley (12):
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: Initialize port fields from DT properties
of: earlycon: Move address translation toof_setup_earlycon()
serial: earlycon: Common log banner for command line and DT
serial: earlycon: Id the earlycon "driver" in banner
of: earlycon: Allow multipleOF_EARLYCON_DECLARE()with same name
of: earlycon: Log more helpful message if earlycon not found
serial: 8250_early: Useport->regshift
serial: 8250_omap: Add omap8250 earlycondrivers/of/fdt.c | 16 +++--- drivers/of/fdt_address.c | 11 ++++- drivers/tty/serial/8250/8250_early.c | 29 ++++++++++- drivers/tty/serial/earlycon.c | 94 +++++++++++++++++++++++++++++------- include/linux/of_fdt.h | 2 +- include/linux/serial_core.h | 20 ++++++-- 6 files changed, 138 insertions(+), 34 deletions(-)