Skip to contentSkip to conversation

early uart console support

PATCH In review Bjorn Helgaas 1 participant 1 message Oct 28, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 early uart console support

This adds an early polled-mode "uart" console driver, based on Andi Kleen's early_printk work.

The difference is that this locates the UART device directly by its MMIO or I/O port address, so we don't have to make assumptions about how ttyS devices will be named. After the normal serial driver starts, we try to locate the matching ttyS device and start a console there.

Sample usage:

    console=uart,io,0x3f8
    console=uart,mmio,0xff5e0000,115200n8

If the baud rate isn't specified, we peek at the UART to figure it out.

This adds an early polled-mode "uart" console driver, based on Andi Kleen's early_printk work.

The difference is that this locates the UART device directly by its MMIO or I/O port address, so we don't have to make assumptions about how ttyS devices will be named. After the normal serial driver starts, we try to locate the matching ttyS device and start a console there.

Sample usage:

    console=uart,io,0x3f8
    console=uart,mmio,0xff5e0000,115200n8

If the baud rate isn't specified, we peek at the UART to figure it out.

 Documentation/kernel-parameters.txt |   20 ++
 drivers/serial/8250.c               |   35 ++++
 drivers/serial/8250_early.c         |  255 ++++++++++++++++++++++++++++++++++++
 drivers/serial/Makefile             |    1 
 include/linux/serial.h              |    2 
 kernel/printk.c                     |    2 
 6 files changed, 312 insertions(+), 3 deletions(-)
Documentation/kernel-parameters.txt +18 -2
diff -u -urN 2.6.10-rc1-mm1/Documentation/kernel-parameters.txt 2.6.10-rc1-mm1-uart/Documentation/kernel-parameters.txt
@@ -311,8 +311,24 @@
 	condev=		[HW,S390] console device
 	conmode=
  
-	console=	[KNL] Output console
-			Console device and comm spec (speed, control, parity).
+	console=	[KNL] Output console device and options.
+
+		tty<n>	Use the virtual console device <n>.
+
+		ttyS<n>[,options]
+			Use the specified serial port.  The options are of
+			the form "bbbbpn", where "bbbb" is the baud rate,
+			"p" is parity ("n", "o", or "e"), and "n" is bits.
+			Default is "9600n8".
+			
+			See also Documentation/serial-console.txt.
+
+		uart,io,<addr>[,options]
+		uart,mmio,<addr>[,options]
+			Start an early, polled-mode console on the 8250/16550
+			UART at the specified I/O port or MMIO address,
+			switching to the matching ttyS device later.  The
+			options are the same as for ttyS, above.
 
 	cpcihp_generic=	[HW,PCI] Generic port I/O CompactPCI driver
 			Format: <first_slot>,<last_slot>,<port>,<enum_bit>[,<debug>]
drivers/serial/8250.c +35 -0
diff -u -urN 2.6.10-rc1-mm1/drivers/serial/8250.c 2.6.10-rc1-mm1-uart/drivers/serial/8250.c
@@ -2226,6 +2226,41 @@
 }
 late_initcall(serial8250_late_console_init);
 
+static int __init find_port(struct uart_port *p)
+{
+	int line;
+	struct uart_port *port;
+
+	for (line = 0; line < UART_NR; line++) {
+		port = &serial8250_ports[line].port;
+		if (p->iotype == port->iotype &&
+		    p->iobase == port->iobase &&
+		    p->membase == port->membase)
+			return line;
+	}
+	return -ENODEV;
+}
+
+int __init serial8250_start_console(struct uart_port *port, char *options)
+{
+	int line;
+
+	line = find_port(port);
+	if (line < 0)
+		return -ENODEV;
+
+	add_preferred_console("ttyS", line, options);
+	printk("Adding console on ttyS%d at %s 0x%lx (options '%s')\n",
+		line, port->iotype == UPIO_MEM ? "MMIO" : "I/O port",
+		port->iotype == UPIO_MEM ? (unsigned long) port->mapbase :
+		    (unsigned long) port->iobase, options);
+	if (!(serial8250_console.flags & CON_ENABLED)) {
+		serial8250_console.flags &= ~CON_PRINTBUFFER;
+		register_console(&serial8250_console);
+	}
+	return line;
+}
+
 #define SERIAL8250_CONSOLE	&serial8250_console
 #else
 #define SERIAL8250_CONSOLE	NULL
drivers/serial/8250_early.c +255 -0

255 lines not on this page · raw message

drivers/serial/Makefile +1 -0
diff -u -urN 2.6.10-rc1-mm1/drivers/serial/Makefile 2.6.10-rc1-mm1-uart/drivers/serial/Makefile
@@ -15,6 +15,7 @@
 obj-$(CONFIG_SERIAL_8250) += 8250.o $(serial-8250-y)
 obj-$(CONFIG_SERIAL_8250_CS) += serial_cs.o
 obj-$(CONFIG_SERIAL_8250_ACORN) += 8250_acorn.o
+obj-$(CONFIG_SERIAL_8250_CONSOLE) += 8250_early.o
 obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o
 obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o
 obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o
include/linux/serial.h +2 -0
diff -u -urN 2.6.10-rc1-mm1/include/linux/serial.h 2.6.10-rc1-mm1-uart/include/linux/serial.h
@@ -182,6 +182,8 @@
 /* Allow architectures to override entries in serial8250_ports[] at run time: */
 struct uart_port;	/* forward declaration */
 extern int early_serial_setup(struct uart_port *port);
+extern int early_serial_console_init(char *options);
+extern int serial8250_start_console(struct uart_port *port, char *options);
 
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SERIAL_H */
kernel/printk.c +1 -1
diff -u -urN 2.6.10-rc1-mm1/kernel/printk.c 2.6.10-rc1-mm1-uart/kernel/printk.c
@@ -142,7 +142,7 @@
 		strcpy(name, "ttyS1");
 #endif
 	for(s = name; *s; s++)
-		if (*s >= '0' && *s <= '9')
+		if ((*s >= '0' && *s <= '9') || *s == ',')
 			break;
 	idx = simple_strtoul(s, NULL, 10);
 	*s = 0;