Skip to contentSkip to conversation

Generic serial earlycon

PATCH Superseded Rob Herring 6 participants 34 messages Mar 21, 2014 – Apr 23, 2014

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Generic serial earlycon

From: Rob Herring <[email protected]>

This started out as an attempt to add arm64's earlyprintk support to ARM in order to get an earlier, runtime setup console on multi-platform kernels. The first issue was needing the fixmap support which conveniently Mark Salter was working on and is mostly in place now. Like many things on ARM and arm64 now, it then became where do I put the now common, shared code. After digging more into various early console/printk support, it turns out the 8250_early.c setup code was the best starting point.

This is based on Mark Salter's fixmap support currently in linux-next. This is tested on arm64 and ARM with pl011 and 8250. The ARM support also requires fixmap and fixed mapping support which are not yet in place. I have some patches in my tree to support fixmap, but they need some more work. Fortunately, once fixmap is in place, it is just a Kconfig option to enable earlycon support on ARM. A git tree is available here[1].

Based on this series, I would like to add support for doing earlycon setup using DT.

Rob

[1] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git earlycon

Rob Herring (8):
x86: move FIX_EARLYCON_MEM kconfig into x86
arm64: add FIXMAP_PAGE_NOCACHE definition
arm64: enable FIX_EARLYCON_MEM kconfig
tty/serial: add generic serial earlycon
tty/serial: convert 8250 to generic earlycon
tty/serial: pl011: add generic earlycon support
tty/serial: add arm64 semihosting earlycon
arm64: remove arch specific earlyprintk

 Documentation/kernel-parameters.txt        |   6 +-
 arch/arm64/Kconfig                         |   3 +
 arch/arm64/Kconfig.debug                   |   9 --
 arch/arm64/include/asm/fixmap.h            |   3 +-
 arch/arm64/kernel/Makefile                 |   1 -
 arch/arm64/kernel/early_printk.c           | 158 -----------------------------
 arch/x86/Kconfig                           |   3 +
 drivers/tty/serial/8250/8250_early.c       | 138 +++----------------------
 drivers/tty/serial/8250/Kconfig            |   5 -
 drivers/tty/serial/Kconfig                 |  24 ++++-
 drivers/tty/serial/Makefile                |   3 +
 drivers/tty/serial/amba-pl011.c            |  30 +++++-
 drivers/tty/serial/earlycon-arm-semihost.c |  44 ++++++++
 drivers/tty/serial/earlycon.c              | 148 +++++++++++++++++++++++++++
 include/linux/serial_core.h                |  16 +++
 15 files changed, 287 insertions(+), 304 deletions(-)
 delete mode 100644 arch/arm64/kernel/early_printk.c
 create mode 100644 drivers/tty/serial/earlycon-arm-semihost.c
 create mode 100644 drivers/tty/serial/earlycon.c
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/8 x86: move FIX_EARLYCON_MEM kconfig into x86

From: Rob Herring <[email protected]>

In preparation to support FIX_EARLYCON_MEM on other arches, make the option per arch.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc x86 at kernel.org
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 arch/x86/Kconfig                | 3 +++
 drivers/tty/serial/8250/Kconfig | 5 -----
 2 files changed, 3 insertions(+), 5 deletions(-)
arch/x86/Kconfig +3 -0
index 9c0a657..600046c 100644
@@ -261,6 +261,9 @@ config ARCH_HWEIGHT_CFLAGS
 config ARCH_SUPPORTS_UPROBES
 	def_bool y
 
+config FIX_EARLYCON_MEM
+	def_bool y
+
 source "init/Kconfig"
 source "kernel/Kconfig.freezer"
 
drivers/tty/serial/8250/Kconfig +0 -5
index 2332991..91f1d83 100644
@@ -90,11 +90,6 @@ config SERIAL_8250_CONSOLE
 
 	  If unsure, say N.
 
-config FIX_EARLYCON_MEM
-	bool
-	depends on X86
-	default y
-
 config SERIAL_8250_GSC
 	tristate
 	depends on SERIAL_8250 && GSC
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH 2/8 arm64: add FIXMAP_PAGE_NOCACHE definition

In reply to Rob Herring

From: Rob Herring <[email protected]>

Similar to ioremap and ioremap_nocache, we want the same definition for both using PROT_DEVICE_nGnRE.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/include/asm/fixmap.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/include/asm/fixmap.h +2 -1
index 5f7bfe6..68eab3c 100644
@@ -54,7 +54,8 @@ enum fixed_addresses {
 #define FIXADDR_SIZE	(__end_of_permanent_fixed_addresses << PAGE_SHIFT)
 #define FIXADDR_START	(FIXADDR_TOP - FIXADDR_SIZE)
 
-#define FIXMAP_PAGE_IO     __pgprot(PROT_DEVICE_nGnRE)
+#define FIXMAP_PAGE_IO		__pgprot(PROT_DEVICE_nGnRE)
+#define FIXMAP_PAGE_NOCACHE	__pgprot(PROT_DEVICE_nGnRE)
 
 extern void __early_set_fixmap(enum fixed_addresses idx,
 			       phys_addr_t phys, pgprot_t flags);
Signature · 1 line
1.8.3.2
#4 lore raw

PATCH 3/8 arm64: enable FIX_EARLYCON_MEM kconfig

In reply to Rob Herring

From: Rob Herring <[email protected]>

In order to support earlycon on arm64, we need to enable earlycon fixmap support.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/Kconfig | 3 +++
 1 file changed, 3 insertions(+)
arch/arm64/Kconfig +3 -0
index e2424f9..a839444 100644
@@ -112,6 +112,9 @@ config IOMMU_HELPER
 config KERNEL_MODE_NEON
 	def_bool y
 
+config FIX_EARLYCON_MEM
+	def_bool y
+
 source "init/Kconfig"
 
 source "kernel/Kconfig.freezer"
Signature · 1 line
1.8.3.2
#6 lore raw

PATCH 4/8 tty/serial: add generic serial earlycon

In reply to Rob Herring

From: Rob Herring <[email protected]>

This introduces generic earlycon infrastructure for serial devices based on the 8250 earlycon. This allows for supporting earlycon option with other serial devices. The earlycon output is enabled at the time early_params are processed.

Only architectures that have fixmap support or have functional ioremap when early_params are processed are supported. This is the same restriction that the 8250 driver had.

Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 drivers/tty/serial/Kconfig    |   7 ++
 drivers/tty/serial/Makefile   |   2 +
 drivers/tty/serial/earlycon.c | 148 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/serial_core.h   |  16 +++++
 4 files changed, 173 insertions(+)
 create mode 100644 drivers/tty/serial/earlycon.c
drivers/tty/serial/Kconfig +7 -0
index 2e6d8dd..1685189 100644
@@ -7,6 +7,13 @@ if TTY
 menu "Serial drivers"
 	depends on HAS_IOMEM
 
+config SERIAL_EARLYCON
+	bool "Early console for serial ports"
+	help
+	  Support for early consoles with the earlycon parameter. This enables
+	  the console before standard serial driver is probed. The console is
+	  enabled when early_param is processed.
+
 source "drivers/tty/serial/8250/Kconfig"
 
 comment "Non-8250 serial port support"
drivers/tty/serial/Makefile +2 -0
index 3680854..8af1415 100644
@@ -5,6 +5,8 @@
 obj-$(CONFIG_SERIAL_CORE) += serial_core.o
 obj-$(CONFIG_SERIAL_21285) += 21285.o
 
+obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o
+
 # These Sparc drivers have to appear before others such as 8250
 # which share ttySx minor node space.  Otherwise console device
 # names change and other unplesantries.
drivers/tty/serial/earlycon.c new file +148 -0

148 lines not on this page · raw message

include/linux/serial_core.h +16 -0
index f729be9..7a15b5b 100644
@@ -285,6 +285,22 @@ static inline int uart_poll_timeout(struct uart_port *port)
 /*
  * Console helpers.
  */
+struct earlycon_device {
+	struct console *con;
+	struct uart_port port;
+	char options[16];		/* e.g., 115200n8 */
+	unsigned int baud;
+};
+int setup_earlycon(char *buf, const char *match,
+		   int (*setup)(struct earlycon_device *, const char *));
+
+#define EARLYCON_DECLARE(name, func) \
+static int __init name ## _setup_earlycon(char *buf) \
+{ \
+	return setup_earlycon(buf, __stringify(name), func); \
+} \
+early_param("earlycon", name ## _setup_earlycon);
+
 struct uart_port *uart_get_console(struct uart_port *ports, int nr,
 				   struct console *c);
 void uart_parse_options(char *options, int *baud, int *parity, int *bits,
Signature · 1 line
1.8.3.2
maintainer
#7 lore raw

Re: [PATCH 4/8] tty/serial: add generic serial earlycon

Quoted 5 lines · Rob Herring
drivers/tty/serial/earlycon.c new file +0 -0
new file mode 100644
index 0000000..241757a

[...]

drivers/tty/serial/earlycon.c line 41

Quoted 10 lines
drivers/tty/serial/earlycon.c new file +10 -0
+static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
+{
+	void __iomem *base;
+#ifdef CONFIG_FIX_EARLYCON_MEM
+	set_fixmap_nocache(FIX_EARLYCON_MEM_BASE, paddr & PAGE_MASK);
+	base = (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
+	base += paddr & ~PAGE_MASK;
+#else
+	base = ioremap_nocache(paddr, size);
+#endif

Just curious why not set_fixmap_io (and plain ioremap)?

Quoted 3 lines
drivers/tty/serial/earlycon.c new file +3 -0
+static int __init parse_options(struct earlycon_device *device,
+				char *options)
+{

[...]

drivers/tty/serial/earlycon.c line 89

Quoted 2 lines
drivers/tty/serial/earlycon.c new file +2 -0
+	if (port->mapbase)
+		port->membase = earlycon_map(port->mapbase, 64);

I would move the earlycon_map() call in setup_earlycon() (personal preference, parse_options() implies just parsing the options rather than having additional side-effects).

Signature · 1 line
Catalin
#8 lore raw

Re: [PATCH 4/8] tty/serial: add generic serial earlycon

Quoted 7 lines · On Monday 24 March 2014 11:22:03 Catalin Marinas wrote:
Quoted 5 lines · Rob Herring
drivers/tty/serial/earlycon.c new file +0 -0
new file mode 100644
index 0000000..241757a

[...]

Quoted 12 lines

drivers/tty/serial/earlycon.c line 41

Quoted 10 lines
drivers/tty/serial/earlycon.c new file +10 -0
+static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
+{
+	void __iomem *base;
+#ifdef CONFIG_FIX_EARLYCON_MEM
+	set_fixmap_nocache(FIX_EARLYCON_MEM_BASE, paddr & PAGE_MASK);
+	base = (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
+	base += paddr & ~PAGE_MASK;
+#else
+	base = ioremap_nocache(paddr, size);
+#endif

Just curious why not set_fixmap_io (and plain ioremap)?

Good point. Note that ioremap_nocache() is the same as ioremap() on *all* architectures.

Arnd

#9 lore raw

Re: [PATCH 4/8] tty/serial: add generic serial earlycon

Quoted 21 lines · Arnd Bergmann
Quoted 7 lines · On Monday 24 March 2014 11:22:03 Catalin Marinas wrote:
Quoted 5 lines · Rob Herring
drivers/tty/serial/earlycon.c new file +0 -0
new file mode 100644
index 0000000..241757a

[...]

Quoted 12 lines

drivers/tty/serial/earlycon.c line 41

Quoted 10 lines
drivers/tty/serial/earlycon.c new file +10 -0
+static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
+{
+   void __iomem *base;
+#ifdef CONFIG_FIX_EARLYCON_MEM
+   set_fixmap_nocache(FIX_EARLYCON_MEM_BASE, paddr & PAGE_MASK);
+   base = (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
+   base += paddr & ~PAGE_MASK;
+#else
+   base = ioremap_nocache(paddr, size);
+#endif

Just curious why not set_fixmap_io (and plain ioremap)?

Quoted 2 lines

Good point. Note that ioremap_nocache() is the same as ioremap() on *all* architectures.

I investigated this before adding this to arm64. set_fixmap_io and set_fixmap_nocache are not the same settings on x86. Whether the mapping type really matters on x86 or not, I don't know. So I added the nocache variant to arm64 to avoid a change to x86.

Rob

#10 lore raw

Re: [PATCH 4/8] tty/serial: add generic serial earlycon

Quoted 22 lines · On Monday 24 March 2014 08:36:46 Rob Herring wrote:
Quoted 21 lines · Arnd Bergmann
Quoted 19 lines · On Monday 24 March 2014 11:22:03 Catalin Marinas wrote:
Quoted 5 lines · Rob Herring
drivers/tty/serial/earlycon.c new file +0 -0
new file mode 100644
index 0000000..241757a

[...]

drivers/tty/serial/earlycon.c line 41

Quoted 10 lines
drivers/tty/serial/earlycon.c new file +10 -0
+static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
+{
+   void __iomem *base;
+#ifdef CONFIG_FIX_EARLYCON_MEM
+   set_fixmap_nocache(FIX_EARLYCON_MEM_BASE, paddr & PAGE_MASK);
+   base = (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
+   base += paddr & ~PAGE_MASK;
+#else
+   base = ioremap_nocache(paddr, size);
+#endif

Just curious why not set_fixmap_io (and plain ioremap)?

Quoted 7 lines
Quoted 2 lines

Good point. Note that ioremap_nocache() is the same as ioremap() on *all* architectures.

I investigated this before adding this to arm64. set_fixmap_io and set_fixmap_nocache are not the same settings on x86. Whether the mapping type really matters on x86 or not, I don't know. So I added the nocache variant to arm64 to avoid a change to x86.

My best guess is that it's an x86 bug. ioremap() always uses an uncached mapping on x86, so it's strange to see early_ioremap() and set_fixmap_io() use a cached mapping. It probably doesn't matter as long as the mtrr is set up to treat all MMIO registers as non-cacheable, but I think there should not be a difference.

Arnd

#11 lore raw

Re: [PATCH 4/8] tty/serial: add generic serial earlycon

Quoted 23 lines · Arnd Bergmann
Quoted 22 lines · On Monday 24 March 2014 08:36:46 Rob Herring wrote:
Quoted 21 lines · Arnd Bergmann
Quoted 19 lines · On Monday 24 March 2014 11:22:03 Catalin Marinas wrote:
Quoted 5 lines · Rob Herring
drivers/tty/serial/earlycon.c new file +0 -0
new file mode 100644
index 0000000..241757a

[...]

drivers/tty/serial/earlycon.c line 41

Quoted 10 lines
drivers/tty/serial/earlycon.c new file +10 -0
+static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
+{
+   void __iomem *base;
+#ifdef CONFIG_FIX_EARLYCON_MEM
+   set_fixmap_nocache(FIX_EARLYCON_MEM_BASE, paddr & PAGE_MASK);
+   base = (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
+   base += paddr & ~PAGE_MASK;
+#else
+   base = ioremap_nocache(paddr, size);
+#endif

Just curious why not set_fixmap_io (and plain ioremap)?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Good point. Note that ioremap_nocache() is the same as ioremap() on *all* architectures.

Did you mean "not the same"? Why are there 2 flavors if they are always the same.

Quoted 10 lines
Quoted 4 lines

I investigated this before adding this to arm64. set_fixmap_io and set_fixmap_nocache are not the same settings on x86. Whether the mapping type really matters on x86 or not, I don't know. So I added the nocache variant to arm64 to avoid a change to x86.

My best guess is that it's an x86 bug. ioremap() always uses an uncached mapping on x86, so it's strange to see early_ioremap() and set_fixmap_io() use a cached mapping. It probably doesn't matter as long as the mtrr is set up to treat all MMIO registers as non-cacheable, but I think there should not be a difference.

At some point it was believed to be needed on the 8250 driver. Perhaps Alan can comment since the commit message tells us nothing:

commit 6f441fe99814f64315b8c11890744230b990c460

Author: Alan Cox <[email protected]>
Date:   Thu May 1 04:34:59 2008 -0700

8250: switch 8250 drivers to use _nocache ioremaps

Rob

#12 lore raw

Re: [PATCH 4/8] tty/serial: add generic serial earlycon

Quoted 2 lines

At some point it was believed to be needed on the 8250 driver. Perhaps Alan can comment since the commit message tells us nothing:

Don't remember sorry - I guess at the time someone had ioremap on their plaform acting as cached. It was a long time ago 8)

#13 lore raw

Re: [PATCH 4/8] tty/serial: add generic serial earlycon

In reply to Rob Herring
Quoted 24 lines · Rob Herring
Quoted 23 lines · Arnd Bergmann
Quoted 22 lines · On Monday 24 March 2014 08:36:46 Rob Herring wrote:
Quoted 21 lines · Arnd Bergmann
Quoted 19 lines · On Monday 24 March 2014 11:22:03 Catalin Marinas wrote:
Quoted 5 lines · Rob Herring
drivers/tty/serial/earlycon.c new file +0 -0
new file mode 100644
index 0000000..241757a

[...]

drivers/tty/serial/earlycon.c line 41

Quoted 10 lines
drivers/tty/serial/earlycon.c new file +10 -0
+static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
+{
+   void __iomem *base;
+#ifdef CONFIG_FIX_EARLYCON_MEM
+   set_fixmap_nocache(FIX_EARLYCON_MEM_BASE, paddr & PAGE_MASK);
+   base = (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
+   base += paddr & ~PAGE_MASK;
+#else
+   base = ioremap_nocache(paddr, size);
+#endif

Just curious why not set_fixmap_io (and plain ioremap)?

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Good point. Note that ioremap_nocache() is the same as ioremap() on *all* architectures.

Did you mean "not the same"?

No

Quoted 2 lines

Why are there 2 flavors if they are
always the same.

I assume it's just a mistake someone made a long time ago and nobody ever changed it because they didn't want to break obscure code.

x86 seems to be a bit odd here, because is has both page-table and MTRR method of setting up whether an access can be cached or not. This may have led to the introduction of the _nocache variant, when the regular ioremap was already uncached on all other architectures but cached on x86.

Arnd

#14 lore raw

PATCH 5/8 tty/serial: convert 8250 to generic earlycon

In reply to Rob Herring

From: Rob Herring <[email protected]>

With the generic earlycon infrastructure in place, convert the 8250 early console to use it.

Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 drivers/tty/serial/8250/8250_early.c | 138 ++++-------------------------------
 1 file changed, 15 insertions(+), 123 deletions(-)
drivers/tty/serial/8250/8250_early.c +15 -123
index c100d63..e83c9db 100644
@@ -35,18 +35,8 @@
 #include <linux/serial_8250.h>
 #include <asm/io.h>
 #include <asm/serial.h>
-#ifdef CONFIG_FIX_EARLYCON_MEM
-#include <asm/pgtable.h>
-#include <asm/fixmap.h>
-#endif
 
-struct early_serial8250_device {
-	struct uart_port port;
-	char options[16];		/* e.g., 115200n8 */
-	unsigned int baud;
-};
-
-static struct early_serial8250_device early_device;
+static struct earlycon_device *early_device;
 
 unsigned int __weak __init serial8250_early_in(struct uart_port *port, int offset)
 {
@@ -100,7 +90,7 @@ static void __init serial_putc(struct uart_port *port, int c)
 static void __init early_serial8250_write(struct console *console,
 					const char *s, unsigned int count)
 {
-	struct uart_port *port = &early_device.port;
+	struct uart_port *port = &early_device->port;
 	unsigned int ier;
 
 	/* Save the IER and disable interrupts */
@@ -129,7 +119,7 @@ static unsigned int __init probe_baud(struct uart_port *port)
 	return (port->uartclk / 16) / quot;
 }
 
-static void __init init_port(struct early_serial8250_device *device)
+static void __init init_port(struct earlycon_device *device)
 {
 	struct uart_port *port = &device->port;
 	unsigned int divisor;
@@ -148,128 +138,32 @@ static void __init init_port(struct early_serial8250_device *device)
 	serial8250_early_out(port, UART_LCR, c & ~UART_LCR_DLAB);
 }
 
-static int __init parse_options(struct early_serial8250_device *device,
-								char *options)
-{
-	struct uart_port *port = &device->port;
-	int mmio, mmio32, length;
-
-	if (!options)
-		return -ENODEV;
-
-	port->uartclk = BASE_BAUD * 16;
-
-	mmio = !strncmp(options, "mmio,", 5);
-	mmio32 = !strncmp(options, "mmio32,", 7);
-	if (mmio || mmio32) {
-		port->iotype = (mmio ? UPIO_MEM : UPIO_MEM32);
-		port->mapbase = simple_strtoul(options + (mmio ? 5 : 7),
-					       &options, 0);
-		if (mmio32)
-			port->regshift = 2;
-#ifdef CONFIG_FIX_EARLYCON_MEM
-		set_fixmap_nocache(FIX_EARLYCON_MEM_BASE,
-					port->mapbase & PAGE_MASK);
-		port->membase =
-			(void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
-		port->membase += port->mapbase & ~PAGE_MASK;
-#else
-		port->membase = ioremap_nocache(port->mapbase, 64);
-		if (!port->membase) {
-			printk(KERN_ERR "%s: Couldn't ioremap 0x%llx\n",
-				__func__,
-			       (unsigned long long) port->mapbase);
-			return -ENOMEM;
-		}
-#endif
-	} else if (!strncmp(options, "io,", 3)) {
-		port->iotype = UPIO_PORT;
-		port->iobase = simple_strtoul(options + 3, &options, 0);
-		mmio = 0;
-	} else
-		return -EINVAL;
-
-	options = strchr(options, ',');
-	if (options) {
-		options++;
-		device->baud = simple_strtoul(options, NULL, 0);
-		length = min(strcspn(options, " ") + 1,
-			     (size_t)(sizeof(device->options)));
-		strlcpy(device->options, options, length);
-	} else {
-		device->baud = probe_baud(port);
-		snprintf(device->options, sizeof(device->options), "%u",
-			device->baud);
-	}
-
-	if (mmio || mmio32)
-		printk(KERN_INFO
-		       "Early serial console at MMIO%s 0x%llx (options '%s')\n",
-			mmio32 ? "32" : "",
-			(unsigned long long)port->mapbase,
-			device->options);
-	else
-		printk(KERN_INFO
-		      "Early serial console at I/O port 0x%lx (options '%s')\n",
-			port->iobase,
-			device->options);
-
-	return 0;
-}
-
-static struct console early_serial8250_console __initdata = {
-	.name	= "uart",
-	.write	= early_serial8250_write,
-	.flags	= CON_PRINTBUFFER | CON_BOOT,
-	.index	= -1,
-};
-
-static int __init early_serial8250_setup(char *options)
+static int __init early_serial8250_setup(struct earlycon_device *device,
+					 const char *options)
 {
-	struct early_serial8250_device *device = &early_device;
-	int err;
-
-	if (device->port.membase || device->port.iobase)
+	if (!(device->port.membase || device->port.iobase))
 		return 0;
 
-	err = parse_options(device, options);
-	if (err < 0)
-		return err;
+	if (!device->baud)
+		device->baud = probe_baud(&device->port);
 
 	init_port(device);
-	return 0;
-}
-
-int __init setup_early_serial8250_console(char *cmdline)
-{
-	char *options;
-	int err;
-
-	options = strstr(cmdline, "uart8250,");
-	if (!options) {
-		options = strstr(cmdline, "uart,");
-		if (!options)
-			return 0;
-	}
-
-	options = strchr(cmdline, ',') + 1;
-	err = early_serial8250_setup(options);
-	if (err < 0)
-		return err;
-
-	register_console(&early_serial8250_console);
 
+	early_device = device;
+	device->con->write = early_serial8250_write;
 	return 0;
 }
+EARLYCON_DECLARE(uart8250, early_serial8250_setup);
+EARLYCON_DECLARE(uart, early_serial8250_setup);
 
 int serial8250_find_port_for_earlycon(void)
 {
-	struct early_serial8250_device *device = &early_device;
-	struct uart_port *port = &device->port;
+	struct earlycon_device *device = early_device;
+	struct uart_port *port = device ? &device->port : NULL;
 	int line;
 	int ret;
 
-	if (!device->port.membase && !device->port.iobase)
+	if (!port || (!port->membase && !port->iobase))
 		return -ENODEV;
 
 	line = serial8250_find_port(port);
@@ -284,5 +178,3 @@ int serial8250_find_port_for_earlycon(void)
 
 	return ret;
 }
-
-early_param("earlycon", setup_early_serial8250_console);
Signature · 1 line
1.8.3.2
#15 lore raw

PATCH 6/8 tty/serial: pl011: add generic earlycon support

In reply to Rob Herring

From: Rob Herring <[email protected]>

Add earlycon support for the pl011 serial port. This allows enabling the pl011 for console when early_params are processed. This is based on the arm64 earlyprintk support and is intended to replace it.

Cc Russell King <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 Documentation/kernel-parameters.txt |  5 +++--
 drivers/tty/serial/amba-pl011.c     | 30 +++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)
Documentation/kernel-parameters.txt +3 -2
index 5ce8b7a..81bdd52 100644
@@ -887,8 +887,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 		uart[8250],io,<addr>[,options]
 		uart[8250],mmio,<addr>[,options]
 		uart[8250],mmio32,<addr>[,options]
-			Start an early, polled-mode console on the 8250/16550
-			UART at the specified I/O port or MMIO address.
+		pl011,<addr>
+			Start an early, polled-mode console on a serial port
+			at the specified I/O port or MMIO address. 8250
 			MMIO inter-register address stride is either 8-bit
 			(mmio) or 32-bit (mmio32).
 			The options are the same as for ttyS, above.
drivers/tty/serial/amba-pl011.c +29 -1
index d4eda24..4227c0a 100644
@@ -303,7 +303,7 @@ static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port *
 
 	/* Optionally make use of an RX channel as well */
 	chan = dma_request_slave_channel(dev, "rx");
-	
+
 	if (!chan && plat->dma_rx_param) {
 		chan = dma_request_channel(mask, plat->dma_filter, plat->dma_rx_param);
 
@@ -2045,6 +2045,34 @@ static struct console amba_console = {
 };
 
 #define AMBA_CONSOLE	(&amba_console)
+
+static void pl011_putc(struct uart_port *port, int c)
+{
+	while (readl(port->membase + UART01x_FR) & UART01x_FR_TXFF)
+		;
+	writeb(c, port->membase + UART01x_DR);
+	while (readl(port->membase + UART01x_FR) & UART01x_FR_BUSY)
+		;
+}
+
+static void pl011_early_write(struct console *con, const char *s, unsigned n)
+{
+	struct earlycon_device *dev = con->data;
+
+	uart_console_write(&dev->port, s, n, pl011_putc);
+}
+
+static int __init pl011_early_console_setup(struct earlycon_device *device,
+					    const char *opt)
+{
+	if (!device->port.membase)
+		return -ENODEV;
+
+	device->con->write = pl011_early_write;
+	return 0;
+}
+EARLYCON_DECLARE(pl011, pl011_early_console_setup);
+
 #else
 #define AMBA_CONSOLE	NULL
 #endif
Signature · 1 line
1.8.3.2
maintainer
#16 lore raw

Re: [PATCH 6/8] tty/serial: pl011: add generic earlycon support

Quoted 21 lines · Rob Herring

From: Rob Herring <[email protected]>

Add earlycon support for the pl011 serial port. This allows enabling the pl011 for console when early_params are processed. This is based on the arm64 earlyprintk support and is intended to replace it.

Cc Russell King <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 Documentation/kernel-parameters.txt |  5 +++--
 drivers/tty/serial/amba-pl011.c     | 30 +++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)
Documentation/kernel-parameters.txt +0 -0
index 5ce8b7a..81bdd52 100644
@@ -887,8 +887,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 		uart[8250],io,<addr>[,options]

Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 895

Quoted 10 lines
Documentation/kernel-parameters.txt +3 -2
 		uart[8250],mmio,<addr>[,options]
 		uart[8250],mmio32,<addr>[,options]
-			Start an early, polled-mode console on the 8250/16550
-			UART at the specified I/O port or MMIO address.
+		pl011,<addr>
+			Start an early, polled-mode console on a serial port
+			at the specified I/O port or MMIO address. 8250
 			MMIO inter-register address stride is either 8-bit
 			(mmio) or 32-bit (mmio32).
 			The options are the same as for ttyS, above.

I think the last line is a bit misleading. Or did you intend to leave it with the uart[8250] parameter? See below:

Quoted 4 lines
drivers/tty/serial/amba-pl011.c +0 -0
index d4eda24..4227c0a 100644

[...]

drivers/tty/serial/amba-pl011.c static struct console amba_console = { · line 2074

Quoted 10 lines
drivers/tty/serial/amba-pl011.c +10 -0
+static int __init pl011_early_console_setup(struct earlycon_device *device,
+					    const char *opt)
+{
+	if (!device->port.membase)
+		return -ENODEV;
+
+	device->con->write = pl011_early_write;
+	return 0;
+}
+EARLYCON_DECLARE(pl011, pl011_early_console_setup);

Here we expect the PL011 to be already initialised by the boot loader and the kernel continues using the same settings. So maybe clarify this in the pl011 kernel parameter doc and we can add proper configuration using a separate patch.

Signature · 1 line
Catalin
#17 lore raw

Re: [PATCH 6/8] tty/serial: pl011: add generic earlycon support

Quoted 27 lines · Catalin Marinas
Quoted 26 lines · Rob Herring

From: Rob Herring <[email protected]>

Add earlycon support for the pl011 serial port. This allows enabling the pl011 for console when early_params are processed. This is based on the arm64 earlyprintk support and is intended to replace it.

Cc Russell King <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 Documentation/kernel-parameters.txt |  5 +++--
 drivers/tty/serial/amba-pl011.c     | 30 +++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)
Documentation/kernel-parameters.txt +1 -2
index 5ce8b7a..81bdd52 100644
@@ -887,8 +887,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
              uart[8250],io,<addr>[,options]
              uart[8250],mmio,<addr>[,options]
              uart[8250],mmio32,<addr>[,options]
-                     Start an early, polled-mode console on the 8250/16550
-                     UART at the specified I/O port or MMIO address.
+             pl011,<addr>
Quoted 8 lines

Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 895

Quoted 5 lines
Documentation/kernel-parameters.txt +2 -0
+                     Start an early, polled-mode console on a serial port
+                     at the specified I/O port or MMIO address. 8250
                      MMIO inter-register address stride is either 8-bit
                      (mmio) or 32-bit (mmio32).
                      The options are the same as for ttyS, above.

I think the last line is a bit misleading. Or did you intend to leave it with the uart[8250] parameter? See below:

How about this (excuse the gmail lack of tabs):

earlycon= [KNL] Output early console device and options.

uart[8250],io,<addr>[,options] uart[8250],mmio,<addr>[,options] uart[8250],mmio32,<addr>[,options]
Start an early, polled-mode console on an 8250 serial port at the specified I/O port or MMIO address. 8250 MMIO inter-register address stride is either 8-bit (mmio) or 32-bit (mmio32).

The options are the same as for ttyS, above.

pl011,<addr>
Start an early, polled-mode console on a pl011 serial port at the specified address. The pl011 serial port must already be setup and configured. Options are not yet supported.

smh Use ARM semihosting calls for early console.

Quoted 6 lines
Quoted 5 lines
drivers/tty/serial/amba-pl011.c +0 -0
index d4eda24..4227c0a 100644

[...]

Quoted 15 lines

drivers/tty/serial/amba-pl011.c static struct console amba_console = { · line 2074

Quoted 10 lines
drivers/tty/serial/amba-pl011.c +10 -0
+static int __init pl011_early_console_setup(struct earlycon_device *device,
+                                         const char *opt)
+{
+     if (!device->port.membase)
+             return -ENODEV;
+
+     device->con->write = pl011_early_write;
+     return 0;
+}
+EARLYCON_DECLARE(pl011, pl011_early_console_setup);

Here we expect the PL011 to be already initialised by the boot loader and the kernel continues using the same settings. So maybe clarify this in the pl011 kernel parameter doc and we can add proper configuration using a separate patch.

Enabling and setup would not be too hard, but either baud rate will always have to be configured or we'll have to specify the input clock rate too. The 8250 driver basically does the former or assumes a fixed clock.

Adding any setup will also break any non-pl011 based SBSA compliant uart since the configuration registers are not standardized. I guess we can add "sbsauart" when/if that happens.

Rob

maintainer
#18 lore raw

Re: [PATCH 6/8] tty/serial: pl011: add generic earlycon support

Quoted 52 lines · Rob Herring
Quoted 27 lines · Catalin Marinas
Quoted 26 lines · Rob Herring

From: Rob Herring <[email protected]>

Add earlycon support for the pl011 serial port. This allows enabling the pl011 for console when early_params are processed. This is based on the arm64 earlyprintk support and is intended to replace it.

Cc Russell King <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 Documentation/kernel-parameters.txt |  5 +++--
 drivers/tty/serial/amba-pl011.c     | 30 +++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)
Documentation/kernel-parameters.txt +1 -2
index 5ce8b7a..81bdd52 100644
@@ -887,8 +887,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
              uart[8250],io,<addr>[,options]
              uart[8250],mmio,<addr>[,options]
              uart[8250],mmio32,<addr>[,options]
-                     Start an early, polled-mode console on the 8250/16550
-                     UART at the specified I/O port or MMIO address.
+             pl011,<addr>
Quoted 8 lines

Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 895

Quoted 5 lines
Documentation/kernel-parameters.txt +2 -0
+                     Start an early, polled-mode console on a serial port
+                     at the specified I/O port or MMIO address. 8250
                      MMIO inter-register address stride is either 8-bit
                      (mmio) or 32-bit (mmio32).
                      The options are the same as for ttyS, above.

I think the last line is a bit misleading. Or did you intend to leave it with the uart[8250] parameter? See below:

How about this (excuse the gmail lack of tabs):

earlycon= [KNL] Output early console device and options.

uart[8250],io,<addr>[,options] uart[8250],mmio,<addr>[,options] uart[8250],mmio32,<addr>[,options]
Start an early, polled-mode console on an 8250 serial port at the specified I/O port or MMIO address. 8250 MMIO inter-register address stride is either 8-bit (mmio) or 32-bit (mmio32).

The options are the same as for ttyS, above.

Quoted 7 lines

pl011,<addr>
Start an early, polled-mode console on a pl011 serial port at the specified address. The pl011 serial port must already be setup and configured. Options are not yet supported.

smh Use ARM semihosting calls for early console.

It looks fine.

Quoted 21 lines
Quoted 5 lines
Quoted 4 lines
drivers/tty/serial/amba-pl011.c +0 -0
index d4eda24..4227c0a 100644

[...]

Quoted 15 lines

drivers/tty/serial/amba-pl011.c static struct console amba_console = { · line 2074

Quoted 10 lines
drivers/tty/serial/amba-pl011.c +10 -0
+static int __init pl011_early_console_setup(struct earlycon_device *device,
+                                         const char *opt)
+{
+     if (!device->port.membase)
+             return -ENODEV;
+
+     device->con->write = pl011_early_write;
+     return 0;
+}
+EARLYCON_DECLARE(pl011, pl011_early_console_setup);

Here we expect the PL011 to be already initialised by the boot loader and the kernel continues using the same settings. So maybe clarify this in the pl011 kernel parameter doc and we can add proper configuration using a separate patch.

Quoted 8 lines

Enabling and setup would not be too hard, but either baud rate will always have to be configured or we'll have to specify the input clock rate too. The 8250 driver basically does the former or assumes a fixed clock.

Adding any setup will also break any non-pl011 based SBSA compliant uart since the configuration registers are not standardized. I guess we can add "sbsauart" when/if that happens.

I think for now we can assume that the pl011 is initialised at the right baud rate prior to starting the kernel.

Signature · 1 line
Catalin
#19 lore raw

PATCH 7/8 tty/serial: add arm64 semihosting earlycon

In reply to Rob Herring

From: Rob Herring <[email protected]>

Add earlycon support for the arm64 semihosting debug serial interface. This allows enabling a debug console when early_params are processed. This is based on the arm64 earlyprintk smh support and is intended to replace it.

This is named arm rather than arm64 in hopes it will be used for both, but only arm64 is supported ATM.

Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 Documentation/kernel-parameters.txt        |  1 +
 drivers/tty/serial/Kconfig                 | 17 +++++++++---
 drivers/tty/serial/Makefile                |  1 +
 drivers/tty/serial/earlycon-arm-semihost.c | 44 ++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 4 deletions(-)
 create mode 100644 drivers/tty/serial/earlycon-arm-semihost.c
Documentation/kernel-parameters.txt +1 -0
index 81bdd52..e96e2ba 100644
@@ -888,6 +888,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 		uart[8250],mmio,<addr>[,options]
 		uart[8250],mmio32,<addr>[,options]
 		pl011,<addr>
+		smh
 			Start an early, polled-mode console on a serial port
 			at the specified I/O port or MMIO address. 8250
 			MMIO inter-register address stride is either 8-bit
drivers/tty/serial/Kconfig +13 -4
index 1685189..8b8f40e 100644
@@ -14,6 +14,15 @@ config SERIAL_EARLYCON
 	  the console before standard serial driver is probed. The console is
 	  enabled when early_param is processed.
 
+config SERIAL_EARLYCON_ARM_SEMIHOST
+	bool "Early console using ARM64 semihosting"
+	depends on ARM64
+	help
+	  Support for early debug console using ARM64 semihosting. This enables
+	  the console before standard serial driver is probed. This is enabled
+	  with "earlycon=smh" on the kernel command line. The console is
+	  enabled when early_param is processed.
+
 source "drivers/tty/serial/8250/Kconfig"
 
 comment "Non-8250 serial port support"
@@ -230,7 +239,7 @@ config SERIAL_SAMSUNG_UARTS
 	help
 	  Select the number of available UART ports for the Samsung S3C
 	  serial driver
-	
+
 config SERIAL_SAMSUNG_DEBUG
 	bool "Samsung SoC serial debug"
 	depends on SERIAL_SAMSUNG && DEBUG_LL
@@ -666,8 +675,8 @@ config PDC_CONSOLE
 	depends on PARISC && !SERIAL_MUX && VT
 	default n
 	help
-	  Saying Y here will enable the software based PDC console to be 
-	  used as the system console.  This is useful for machines in 
+	  Saying Y here will enable the software based PDC console to be
+	  used as the system console.  This is useful for machines in
 	  which the hardware based console has not been written yet.  The
 	  following steps must be competed to use the PDC console:
 
@@ -858,7 +867,7 @@ config SERIAL_CPM
 	depends on CPM2 || 8xx
 	select SERIAL_CORE
 	help
-	  This driver supports the SCC and SMC serial ports on Motorola 
+	  This driver supports the SCC and SMC serial ports on Motorola
 	  embedded PowerPC that contain a CPM1 (8xx) or CPM2 (8xxx)
 
 config SERIAL_CPM_CONSOLE
drivers/tty/serial/Makefile +1 -0
index 8af1415..9965b65 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_SERIAL_CORE) += serial_core.o
 obj-$(CONFIG_SERIAL_21285) += 21285.o
 
 obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o
+obj-$(CONFIG_SERIAL_EARLYCON_ARM_SEMIHOST) += earlycon-arm-semihost.o
 
 # These Sparc drivers have to appear before others such as 8250
 # which share ttySx minor node space.  Otherwise console device
drivers/tty/serial/earlycon-arm-semihost.c new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#20 lore raw

Re: [PATCH 7/8] tty/serial: add arm64 semihosting earlycon

Quoted 9 lines · Rob Herring

From: Rob Herring <[email protected]>

Add earlycon support for the arm64 semihosting debug serial interface. This allows enabling a debug console when early_params are processed. This is based on the arm64 earlyprintk smh support and is intended to replace it.

This is named arm rather than arm64 in hopes it will be used for both, but only arm64 is supported ATM.

It can't be used for both as the semihosting calls themselves need assembly code and this is not compatible with the equivalent ARM32 calls. So I'd suggest naming this "arm64" to avoid potential confusion.

Quoted 143 lines
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 Documentation/kernel-parameters.txt        |  1 +
 drivers/tty/serial/Kconfig                 | 17 +++++++++---
 drivers/tty/serial/Makefile                |  1 +
 drivers/tty/serial/earlycon-arm-semihost.c | 44 ++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 4 deletions(-)
 create mode 100644 drivers/tty/serial/earlycon-arm-semihost.c
Documentation/kernel-parameters.txt +1 -0
index 81bdd52..e96e2ba 100644
@@ -888,6 +888,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 		uart[8250],mmio,<addr>[,options]
 		uart[8250],mmio32,<addr>[,options]
 		pl011,<addr>
+		smh
 			Start an early, polled-mode console on a serial port
 			at the specified I/O port or MMIO address. 8250
 			MMIO inter-register address stride is either 8-bit
drivers/tty/serial/Kconfig +13 -4
index 1685189..8b8f40e 100644
@@ -14,6 +14,15 @@ config SERIAL_EARLYCON
 	  the console before standard serial driver is probed. The console is
 	  enabled when early_param is processed.
 
+config SERIAL_EARLYCON_ARM_SEMIHOST
+	bool "Early console using ARM64 semihosting"
+	depends on ARM64
+	help
+	  Support for early debug console using ARM64 semihosting. This enables
+	  the console before standard serial driver is probed. This is enabled
+	  with "earlycon=smh" on the kernel command line. The console is
+	  enabled when early_param is processed.
+
 source "drivers/tty/serial/8250/Kconfig"
 
 comment "Non-8250 serial port support"
@@ -230,7 +239,7 @@ config SERIAL_SAMSUNG_UARTS
 	help
 	  Select the number of available UART ports for the Samsung S3C
 	  serial driver
-	
+
 config SERIAL_SAMSUNG_DEBUG
 	bool "Samsung SoC serial debug"
 	depends on SERIAL_SAMSUNG && DEBUG_LL
@@ -666,8 +675,8 @@ config PDC_CONSOLE
 	depends on PARISC && !SERIAL_MUX && VT
 	default n
 	help
-	  Saying Y here will enable the software based PDC console to be 
-	  used as the system console.  This is useful for machines in 
+	  Saying Y here will enable the software based PDC console to be
+	  used as the system console.  This is useful for machines in
 	  which the hardware based console has not been written yet.  The
 	  following steps must be competed to use the PDC console:
 
@@ -858,7 +867,7 @@ config SERIAL_CPM
 	depends on CPM2 || 8xx
 	select SERIAL_CORE
 	help
-	  This driver supports the SCC and SMC serial ports on Motorola 
+	  This driver supports the SCC and SMC serial ports on Motorola
 	  embedded PowerPC that contain a CPM1 (8xx) or CPM2 (8xxx)
 
 config SERIAL_CPM_CONSOLE
drivers/tty/serial/Makefile +1 -0
index 8af1415..9965b65 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_SERIAL_CORE) += serial_core.o
 obj-$(CONFIG_SERIAL_21285) += 21285.o
 
 obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o
+obj-$(CONFIG_SERIAL_EARLYCON_ARM_SEMIHOST) += earlycon-arm-semihost.o
 
 # These Sparc drivers have to appear before others such as 8250
 # which share ttySx minor node space.  Otherwise console device
drivers/tty/serial/earlycon-arm-semihost.c new file +44 -0
new file mode 100644
index 0000000..fecec9a
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ * Author: Catalin Marinas <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <linux/kernel.h>
+#include <linux/console.h>
+#include <linux/init.h>
+#include <linux/serial_core.h>
+
+/*
+ * Semihosting-based debug console
+ */
+static void smh_putc(struct uart_port *port, int c)
+{
+	asm volatile("mov  x1, %0\n"
+		     "mov  x0, #3\n"
+		     "hlt  0xf000\n"
+		     : : "r" (&c) : "x0", "x1", "memory");
+}
+
+static void smh_write(struct console *con, const char *s, unsigned n)
+{
+	struct earlycon_device *dev = con->data;
+	uart_console_write(&dev->port, s, n, smh_putc);
+}
+
+int __init early_smh_setup(struct earlycon_device *device, const char *opt)
+{
+	device->con->write = smh_write;
+	return 0;
+}
+EARLYCON_DECLARE(smh, early_smh_setup);
Signature · 7 lines
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#21 lore raw

Re: [PATCH 7/8] tty/serial: add arm64 semihosting earlycon

Quoted 9 lines · On Sunday 23 March 2014 16:04:41 Nicolas Pitre wrote:
Quoted 7 lines · Rob Herring

From: Rob Herring <[email protected]>

Add earlycon support for the arm64 semihosting debug serial interface. This allows enabling a debug console when early_params are processed. This is based on the arm64 earlyprintk smh support and is intended to replace it.

Quoted 6 lines
Quoted 2 lines

This is named arm rather than arm64 in hopes it will be used for both, but only arm64 is supported ATM.

It can't be used for both as the semihosting calls themselves need assembly code and this is not compatible with the equivalent ARM32 calls. So I'd suggest naming this "arm64" to avoid potential confusion.

How about using an compile-time conditional to put both inline assemblies in there? While the driver is rather trivial to start with, I don't see a point in duplicating it either.

Arnd

#22 lore raw

Re: [PATCH 7/8] tty/serial: add arm64 semihosting earlycon

Quoted 13 lines · Arnd Bergmann
Quoted 12 lines · On Sunday 23 March 2014 16:04:41 Nicolas Pitre wrote:
Quoted 9 lines · Rob Herring

From: Rob Herring <[email protected]>

Add earlycon support for the arm64 semihosting debug serial interface. This allows enabling a debug console when early_params are processed. This is based on the arm64 earlyprintk smh support and is intended to replace it.

This is named arm rather than arm64 in hopes it will be used for both, but only arm64 is supported ATM.

Quoted 7 lines
Quoted 3 lines

It can't be used for both as the semihosting calls themselves need assembly code and this is not compatible with the equivalent ARM32 calls. So I'd suggest naming this "arm64" to avoid potential confusion.

How about using an compile-time conditional to put both inline assemblies in there? While the driver is rather trivial to start with, I don't see a point in duplicating it either.

Sure. But it can be trivially renamed at that point.

Or, even better would be to add the ARM calls right away. And of course ARM in Thumb mode has yet another call convention.

The printascii and printch code in arch/arm/kernel/debug.S for CONFIG_DEBUG_SEMIHOSTING can be copied almost as is.

Nicolas

maintainer
#23 lore raw

Re: [PATCH 7/8] tty/serial: add arm64 semihosting earlycon

In reply to Rob Herring

Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 894

Quoted 12 lines · Rob Herring
Documentation/kernel-parameters.txt +1 -0
index 81bdd52..e96e2ba 100644
@@ -888,6 +888,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 		uart[8250],mmio,<addr>[,options]
 		uart[8250],mmio32,<addr>[,options]
 		pl011,<addr>
+		smh
 			Start an early, polled-mode console on a serial port
 			at the specified I/O port or MMIO address. 8250
 			MMIO inter-register address stride is either 8-bit

Same comment as per a previous patch, "smh" does not take any parameters at all here.

drivers/tty/serial/earlycon-arm-semihost.c line 3

Quoted 6 lines
drivers/tty/serial/earlycon-arm-semihost.c new file +3 -0
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ * Author: Catalin Marinas <[email protected]>

Nitpick: author should be Mark Zyngier <[email protected]> as per commit 0492f72508184 (arm64: early_printk: add support for FastModel console output)

Signature · 1 line
Catalin
maintainer
#24 lore raw

Re: [PATCH 7/8] tty/serial: add arm64 semihosting earlycon

Quoted 9 lines · Catalin Marinas

drivers/tty/serial/earlycon-arm-semihost.c line 3

Quoted 6 lines · Rob Herring
drivers/tty/serial/earlycon-arm-semihost.c new file +3 -0
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ * Author: Catalin Marinas <[email protected]>

Nitpick: author should be Mark Zyngier <[email protected]>

And a typo in my email: s/Mark/Marc/.

Thanks.

Signature · 1 line
Catalin
#25 lore raw

PATCH 8/8 arm64: remove arch specific earlyprintk

In reply to Rob Herring

From: Rob Herring <[email protected]>

Now that we have equivalent earlycon support, arm64's earlyprintk code can be removed.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/Kconfig.debug         |   9 ---
 arch/arm64/kernel/Makefile       |   1 -
 arch/arm64/kernel/early_printk.c | 158 ---------------------------------------
 3 files changed, 168 deletions(-)
 delete mode 100644 arch/arm64/kernel/early_printk.c
arch/arm64/Kconfig.debug +0 -9
index 835c5597..7d7fb6f 100644
@@ -6,15 +6,6 @@ config FRAME_POINTER
 	bool
 	default y
 
-config EARLY_PRINTK
-	bool "Early printk support"
-	default y
-	help
-	  Say Y here if you want to have an early console using the
-	  earlyprintk=<name>[,<addr>][,<options>] kernel parameter. It
-	  is assumed that the early console device has been initialised
-	  by the boot loader prior to starting the Linux kernel.
-
 config PID_IN_CONTEXTIDR
 	bool "Write the current PID to the CONTEXTIDR register"
 	help
arch/arm64/kernel/Makefile +0 -1
index 7d811d9..7a6fce5 100644
@@ -18,7 +18,6 @@ arm64-obj-$(CONFIG_SMP)			+= smp.o smp_spin_table.o topology.o
 arm64-obj-$(CONFIG_PERF_EVENTS)		+= perf_regs.o
 arm64-obj-$(CONFIG_HW_PERF_EVENTS)	+= perf_event.o
 arm64-obj-$(CONFIG_HAVE_HW_BREAKPOINT)	+= hw_breakpoint.o
-arm64-obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 arm64-obj-$(CONFIG_ARM64_CPU_SUSPEND)	+= sleep.o suspend.o
 arm64-obj-$(CONFIG_JUMP_LABEL)		+= jump_label.o
 arm64-obj-$(CONFIG_KGDB)		+= kgdb.o
arch/arm64/kernel/early_printk.c deleted +0 -158

158 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#26 lore raw
In reply to Rob Herring
Quoted 18 lines · Rob Herring

From: Rob Herring <[email protected]>

This started out as an attempt to add arm64's earlyprintk support to ARM in order to get an earlier, runtime setup console on multi-platform kernels. The first issue was needing the fixmap support which conveniently Mark Salter was working on and is mostly in place now. Like many things on ARM and arm64 now, it then became where do I put the now common, shared code. After digging more into various early console/printk support, it turns out the 8250_early.c setup code was the best starting point.

This is based on Mark Salter's fixmap support currently in linux-next. This is tested on arm64 and ARM with pl011 and 8250. The ARM support also requires fixmap and fixed mapping support which are not yet in place. I have some patches in my tree to support fixmap, but they need some more work. Fortunately, once fixmap is in place, it is just a Kconfig option to enable earlycon support on ARM. A git tree is available here[1].

Quoted 2 lines

Based on this series, I would like to add support for doing earlycon setup using DT.

Hi Rob,

I like this series a lot, great work!

I would consider the DT parsing support essential here, we should not merge the patches until that is done as well, because I don't want to see users pass earlycon command line options in DT when they can use the established "linux,stdout-path" property instead. I would expect that in almost every case in which we are booting using DT today, we can just use linux,stdout-path to locate the device that the boot loader has already set up and start usign it.

Arnd

#27 lore raw
Quoted 26 lines · Arnd Bergmann
Quoted 18 lines · Rob Herring

From: Rob Herring <[email protected]>

This started out as an attempt to add arm64's earlyprintk support to ARM in order to get an earlier, runtime setup console on multi-platform kernels. The first issue was needing the fixmap support which conveniently Mark Salter was working on and is mostly in place now. Like many things on ARM and arm64 now, it then became where do I put the now common, shared code. After digging more into various early console/printk support, it turns out the 8250_early.c setup code was the best starting point.

This is based on Mark Salter's fixmap support currently in linux-next. This is tested on arm64 and ARM with pl011 and 8250. The ARM support also requires fixmap and fixed mapping support which are not yet in place. I have some patches in my tree to support fixmap, but they need some more work. Fortunately, once fixmap is in place, it is just a Kconfig option to enable earlycon support on ARM. A git tree is available here[1].

Quoted 2 lines

Based on this series, I would like to add support for doing earlycon setup using DT.

Hi Rob,

I like this series a lot, great work!

Quoted 7 lines

I would consider the DT parsing support essential here, we should not merge the patches until that is done as well, because I don't want to see users pass earlycon command line options in DT when they can use the established "linux,stdout-path" property instead. I would expect that in almost every case in which we are booting using DT today, we can just use linux,stdout-path to locate the device that the boot loader has already set up and start usign it.

I think this series stands on its own. It is largely refactoring existing code and supporting existing command line options (arm64 just changes from earlyprintk= to earlycon=). There will be cases where changing the kernel command line is the only way to setup the earlycon. Also, I think we would still want the kernel command line to control whether or not we enable the earlycon (i.e. earlycon=dt). There's not a standard way for how bootloaders would decide to set "linux,stdout-path" or not.

The DT support won't be all that quick to implement. The challenge with the DT parsing is we have to do it on the flattened DT. I have something functioning, but it doesn't do any address translation which is the hard part.

Rob

#28 lore raw
Quoted 9 lines · Rob Herring

I think this series stands on its own. It is largely refactoring existing code and supporting existing command line options (arm64 just changes from earlyprintk= to earlycon=). There will be cases where changing the kernel command line is the only way to setup the earlycon. Also, I think we would still want the kernel command line to control whether or not we enable the earlycon (i.e. earlycon=dt). There's not a standard way for how bootloaders would decide to set "linux,stdout-path" or not.

Quoted 4 lines

The DT support won't be all that quick to implement. The challenge with the DT parsing is we have to do it on the flattened DT. I have something functioning, but it doesn't do any address translation which is the hard part.

Ah, I hadn't realized that we call parse_early_param() twice, both in start_kernel() and before that in setup_arch(). You are right that the first one of these can only look at the flat device tree at the moment. I wonder if that's out of necessity or just coincidence though.

There is relatively little going on between the first parse_early_param() and the call to unflatten_device_tree(), so it may be possible to move the former down, or the latter up.

        parse_early_param();

        sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL);

        early_paging_init(mdesc, lookup_processor_type(read_cpuid_id()));
        setup_dma_zone(mdesc);  
        sanity_check_meminfo();
        arm_memblock_init(&meminfo, mdesc);
                                
        paging_init(mdesc);
        request_standard_resources(mdesc);
                
        if (mdesc->restart)
                arm_pm_restart = mdesc->restart;
        
        unflatten_device_tree();

On powerpc, unflatten_device_tree is called way before paging_init, so I assume it has to be possible, but it might end up being harder to do than what you have in mind with parsing the flat device tree.

Arnd

#29 lore raw
Quoted 42 lines · Arnd Bergmann
Quoted 9 lines · Rob Herring

I think this series stands on its own. It is largely refactoring existing code and supporting existing command line options (arm64 just changes from earlyprintk= to earlycon=). There will be cases where changing the kernel command line is the only way to setup the earlycon. Also, I think we would still want the kernel command line to control whether or not we enable the earlycon (i.e. earlycon=dt). There's not a standard way for how bootloaders would decide to set "linux,stdout-path" or not.

Quoted 4 lines

The DT support won't be all that quick to implement. The challenge with the DT parsing is we have to do it on the flattened DT. I have something functioning, but it doesn't do any address translation which is the hard part.

Ah, I hadn't realized that we call parse_early_param() twice, both in start_kernel() and before that in setup_arch(). You are right that the first one of these can only look at the flat device tree at the moment. I wonder if that's out of necessity or just coincidence though.

There is relatively little going on between the first parse_early_param() and the call to unflatten_device_tree(), so it may be possible to move the former down, or the latter up.

        parse_early_param();

        sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL);

        early_paging_init(mdesc, lookup_processor_type(read_cpuid_id()));
        setup_dma_zone(mdesc);
        sanity_check_meminfo();
        arm_memblock_init(&meminfo, mdesc);

        paging_init(mdesc);
        request_standard_resources(mdesc);

        if (mdesc->restart)
                arm_pm_restart = mdesc->restart;

        unflatten_device_tree();
Quoted 3 lines

On powerpc, unflatten_device_tree is called way before paging_init, so I assume it has to be possible, but it might end up being harder to do than what you have in mind with parsing the flat device tree.

IIRC, the unflattening cannot be done before memblock is up which is in arm_memblock_init. I believe that will get done earlier similar to PPC with Laura's meminfo removal series. However, in interest of getting output enabled as early as possible, the earliest point is always going to be with a flat tree. So I think we do want to be able to parse the flat tree for this. There's code in u-boot to do the address translation on FDT we can steal. Really, i'd like to put that code in libfdt, but there's a licensing problem with the u-boot code being GPL and libfdt being BSD.

Rob

#30 lore raw
Quoted 9 lines · Rob Herring

IIRC, the unflattening cannot be done before memblock is up which is in arm_memblock_init. I believe that will get done earlier similar to PPC with Laura's meminfo removal series. However, in interest of getting output enabled as early as possible, the earliest point is always going to be with a flat tree. So I think we do want to be able to parse the flat tree for this. There's code in u-boot to do the address translation on FDT we can steal. Really, i'd like to put that code in libfdt, but there's a licensing problem with the u-boot code being GPL and libfdt being BSD.

I suppose it depends on what the goal is. If you are trying to get as close as possible to the debug_ll functionality without losing the ability to turn it on unconditionally, I agree that it needs to be done on the flat tree.

However, the goal that interests me more at the moment is to have reliable debug output done in a simple way earlier than what we have today with the normal console support. For this, it seems a better tradeoff to initialize the early console slightly later. This can actually be done independent of the the command line option, I don't see any downsides from having a compile-time option that would initialize the early console from setup_arch (after unflatten_device_tree) whenever there is a linux,stdout-path property that points to a usable device.

Arnd

#31 lore raw
In reply to Rob Herring
Quoted 35 lines · Rob Herring
Quoted 26 lines · Arnd Bergmann
Quoted 18 lines · Rob Herring

From: Rob Herring <[email protected]>

This started out as an attempt to add arm64's earlyprintk support to ARM in order to get an earlier, runtime setup console on multi-platform kernels. The first issue was needing the fixmap support which conveniently Mark Salter was working on and is mostly in place now. Like many things on ARM and arm64 now, it then became where do I put the now common, shared code. After digging more into various early console/printk support, it turns out the 8250_early.c setup code was the best starting point.

This is based on Mark Salter's fixmap support currently in linux-next. This is tested on arm64 and ARM with pl011 and 8250. The ARM support also requires fixmap and fixed mapping support which are not yet in place. I have some patches in my tree to support fixmap, but they need some more work. Fortunately, once fixmap is in place, it is just a Kconfig option to enable earlycon support on ARM. A git tree is available here[1].

Quoted 2 lines

Based on this series, I would like to add support for doing earlycon setup using DT.

Hi Rob,

I like this series a lot, great work!

Quoted 7 lines

I would consider the DT parsing support essential here, we should not merge the patches until that is done as well, because I don't want to see users pass earlycon command line options in DT when they can use the established "linux,stdout-path" property instead. I would expect that in almost every case in which we are booting using DT today, we can just use linux,stdout-path to locate the device that the boot loader has already set up and start usign it.

Quoted 8 lines

I think this series stands on its own. It is largely refactoring existing code and supporting existing command line options (arm64 just changes from earlyprintk= to earlycon=). There will be cases where changing the kernel command line is the only way to setup the earlycon. Also, I think we would still want the kernel command line to control whether or not we enable the earlycon (i.e. earlycon=dt). There's not a standard way for how bootloaders would decide to set "linux,stdout-path" or not.

I agree. I really like this series and I don't think it needs to wait for DT parsing.

Another issue is that the earlycon assumes the port is already set up, but the /chosen/stdout-path binding doesn't guarantee that. We'll have to make sure the kernel knows when it is valid to use /chosen/stdout-path before enabling an early console.

g.

#32 lore raw
Quoted 45 lines · Grant Likely
Quoted 35 lines · Rob Herring
Quoted 26 lines · Arnd Bergmann
Quoted 18 lines · Rob Herring

From: Rob Herring <[email protected]>

This started out as an attempt to add arm64's earlyprintk support to ARM in order to get an earlier, runtime setup console on multi-platform kernels. The first issue was needing the fixmap support which conveniently Mark Salter was working on and is mostly in place now. Like many things on ARM and arm64 now, it then became where do I put the now common, shared code. After digging more into various early console/printk support, it turns out the 8250_early.c setup code was the best starting point.

This is based on Mark Salter's fixmap support currently in linux-next. This is tested on arm64 and ARM with pl011 and 8250. The ARM support also requires fixmap and fixed mapping support which are not yet in place. I have some patches in my tree to support fixmap, but they need some more work. Fortunately, once fixmap is in place, it is just a Kconfig option to enable earlycon support on ARM. A git tree is available here[1].

Quoted 2 lines

Based on this series, I would like to add support for doing earlycon setup using DT.

Hi Rob,

I like this series a lot, great work!

Quoted 7 lines

I would consider the DT parsing support essential here, we should not merge the patches until that is done as well, because I don't want to see users pass earlycon command line options in DT when they can use the established "linux,stdout-path" property instead. I would expect that in almost every case in which we are booting using DT today, we can just use linux,stdout-path to locate the device that the boot loader has already set up and start usign it.

Quoted 8 lines

I think this series stands on its own. It is largely refactoring existing code and supporting existing command line options (arm64 just changes from earlyprintk= to earlycon=). There will be cases where changing the kernel command line is the only way to setup the earlycon. Also, I think we would still want the kernel command line to control whether or not we enable the earlycon (i.e. earlycon=dt). There's not a standard way for how bootloaders would decide to set "linux,stdout-path" or not.

Quoted 7 lines

I agree. I really like this series and I don't think it needs to wait for DT parsing.

Another issue is that the earlycon assumes the port is already set up, but the /chosen/stdout-path binding doesn't guarantee that. We'll have to make sure the kernel knows when it is valid to use /chosen/stdout-path before enabling an early console.

It's driver dependent whether the port setup is done in the earlycon driver or not. The 8250 driver does port setup while the pl011 driver does not. We could add setup to the pl011 or checks that it is setup already, but then it would not work with SBSA compliant UARTs.

I don't think we want to enable earlycon solely if stdout-path is set. My plan here is that adding "earlycon" with no parameters to the command line enables DT based setup of earlycon. That doesn't really solve the issue with setup, but does limit it to a developer's feature at least.

Rob

#33 lore raw
Quoted 54 lines · Rob Herring
Quoted 45 lines · Grant Likely
Quoted 35 lines · Rob Herring
Quoted 26 lines · Arnd Bergmann
Quoted 18 lines · Rob Herring

From: Rob Herring <[email protected]>

This started out as an attempt to add arm64's earlyprintk support to ARM in order to get an earlier, runtime setup console on multi-platform kernels. The first issue was needing the fixmap support which conveniently Mark Salter was working on and is mostly in place now. Like many things on ARM and arm64 now, it then became where do I put the now common, shared code. After digging more into various early console/printk support, it turns out the 8250_early.c setup code was the best starting point.

This is based on Mark Salter's fixmap support currently in linux-next. This is tested on arm64 and ARM with pl011 and 8250. The ARM support also requires fixmap and fixed mapping support which are not yet in place. I have some patches in my tree to support fixmap, but they need some more work. Fortunately, once fixmap is in place, it is just a Kconfig option to enable earlycon support on ARM. A git tree is available here[1].

Quoted 2 lines

Based on this series, I would like to add support for doing earlycon setup using DT.

Hi Rob,

I like this series a lot, great work!

Quoted 7 lines

I would consider the DT parsing support essential here, we should not merge the patches until that is done as well, because I don't want to see users pass earlycon command line options in DT when they can use the established "linux,stdout-path" property instead. I would expect that in almost every case in which we are booting using DT today, we can just use linux,stdout-path to locate the device that the boot loader has already set up and start usign it.

Quoted 8 lines

I think this series stands on its own. It is largely refactoring existing code and supporting existing command line options (arm64 just changes from earlyprintk= to earlycon=). There will be cases where changing the kernel command line is the only way to setup the earlycon. Also, I think we would still want the kernel command line to control whether or not we enable the earlycon (i.e. earlycon=dt). There's not a standard way for how bootloaders would decide to set "linux,stdout-path" or not.

Quoted 7 lines

I agree. I really like this series and I don't think it needs to wait for DT parsing.

Another issue is that the earlycon assumes the port is already set up, but the /chosen/stdout-path binding doesn't guarantee that. We'll have to make sure the kernel knows when it is valid to use /chosen/stdout-path before enabling an early console.

Quoted 4 lines

It's driver dependent whether the port setup is done in the earlycon driver or not. The 8250 driver does port setup while the pl011 driver does not. We could add setup to the pl011 or checks that it is setup already, but then it would not work with SBSA compliant UARTs.

Well, it would work in most cases, but would be unnecessary and makes it more likely that there will be no output if the kernel gets the setup wrong.

Quoted 5 lines

I don't think we want to enable earlycon solely if stdout-path is set. My plan here is that adding "earlycon" with no parameters to the command line enables DT based setup of earlycon. That doesn't really solve the issue with setup, but does limit it to a developer's feature at least.

That is reasonable. Alternately, we could also add a property to chosen indicating that the console is set up and ready to go.

g.