early serial console support
PATCH 1/1 early serial console support
(Sorry if this is a duplicate; I sent this to lkml and could swear that I copied linux-ia64 and Russell, but I don't see it on the list.)
This adds fairly generic early console support to the 8250 serial driver.
The current early_serial_setup() functionality is a bit of a problem for ia64 because it assumes that you know where ttyS0 is before the driver initializes. On ia64, we don't know that because all the devices are enumerated via ACPI and PCI.
However, we do have a firmware interface to tell us where the serial console device is. So this patch adds serial8250_early_console_setup() so the architecture can specify the MMIO or I/O port address instead of the ttyS0 device name.
After the serial driver initializes, we automatically try to locate the corresponding ttyS device, and start up a console on that.
I'll post the corresponding ia64 changes that take advantage of these as a response. Feedback/comments welcome.
Bjorn
=== drivers/serial/8250.c 1.48 vs edited ==--- 1.48/drivers/serial/8250.c Mon Mar 15 15:16:26 2004
+++ edited/drivers/serial/8250.c Thu Apr 1 14:31:04 2004
@@ -1882,6 +1882,7 @@
}
#ifdef CONFIG_SERIAL_8250_CONSOLE
+static int serial8250_early_device(struct uart_port *);
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
@@ -1977,6 +1978,13 @@
return -ENODEV;
/*
+ * No need to dump the buffer again if the port is already in
+ * use as the early console device.
+ */
+ if (serial8250_early_device(port))
+ co->flags &= ~CON_PRINTBUFFER;
+
+ /*
* Temporary fix.
*/
spin_lock_init(&port->lock);
@@ -2013,6 +2021,166 @@
return 0;
}
late_initcall(serial8250_late_console_init);
+
+/*
+ * This is for use before the serial driver has initialized, in
+ * particular, before the UARTs have been discovered and named.
+ * Instead of specifying the console device as "ttyS0", platform
+ * code can call serial8250_early_console_setup() to specify it
+ * directly with an MMIO or I/O port address.
+ */
+static struct uart_8250_port serial8250_early_port __initdata;
+static char *serial8250_early_options __initdata;
+
+static void __init serial8250_early_putc(struct uart_8250_port *up, char c)
+{
+ while (!(UART_LSR_TEMT & serial_in(up, UART_LSR)))
+ ;
+
+ serial_out(up, UART_TX, c);
+}
+
+/*
+ * Can't use serial8250_console_write() because delay() might not work yet.
+ */
+static void __init serial8250_early_write(struct console *co, const char *s, unsigned int count) +{
+ struct uart_8250_port *up = &serial8250_early_port;
+
+ while (*s && count-- > 0) {
+ serial8250_early_putc(up, *s);
+ if (*s = '\n')
+ serial8250_early_putc(up, '\r');
+ s++;
+ }
+}
+
+static struct console serial8250_early_console __initdata = {
+ .name = "serial",
+ .write = serial8250_early_write,
+ .flags = CON_PRINTBUFFER,
+ .index = -1,
+};
+
+static unsigned int __init serial8250_probe_baud(struct uart_8250_port *port)
+{
+ unsigned char lcr, dll, dlm;
+ unsigned int quot, baud;
+
+ lcr = serial_in(port, UART_LCR);
+ serial_out(port, UART_LCR, lcr | UART_LCR_DLAB);
+ dll = serial_in(port, UART_DLL);
+ dlm = serial_in(port, UART_DLM);
+ serial_out(port, UART_LCR, lcr);
+
+ quot = (dlm << 8) | dll;
+ baud = BASE_BAUD / quot;
+ return baud;
+}
+
+static void __init serial8250_early_init(struct uart_8250_port *port, unsigned int baud) +{
+ unsigned char c;
+ unsigned int divisor;
+
+ serial_out(port, UART_LCR, 0x3); /* 8n1 */
+ serial_out(port, UART_IER, 0); /* no interrupt */
+ serial_out(port, UART_FCR, 0); /* no fifo */
+ serial_out(port, UART_MCR, 0x3); /* DTR + RTS */
+
+ divisor = 115200 / baud;
+ c = serial_in(port, UART_LCR);
+ serial_out(port, UART_LCR, c | UART_LCR_DLAB);
+ serial_out(port, UART_DLL, divisor & 0xff);
+ serial_out(port, UART_DLM, (divisor >> 8) & 0xff);
+ serial_out(port, UART_LCR, c & ~UART_LCR_DLAB);
+}
+
+void __init serial8250_early_console_setup(struct uart_port *port, char *options) +{
+ unsigned int baud = 9600;
+ static char probed_options[16];
+
+ serial8250_early_port.port = *port;
+ if (options) {
+ serial8250_early_options = options;
+ baud = simple_strtoul(options, 0, 0);
+ } else {
+ baud = serial8250_probe_baud(&serial8250_early_port);
+ snprintf(probed_options, sizeof(probed_options), "%u", baud);
+ serial8250_early_options = probed_options;
+ }
+ serial8250_early_init(&serial8250_early_port, baud);
+ printk("Early serial console at %s 0x%lx (options %s)\n",
+ port->iotype = SERIAL_IO_MEM ? "MMIO" : "I/O port",
+ port->iotype = SERIAL_IO_MEM ? (unsigned long) port->mapbase :
+ (unsigned long) port->iobase,
+ serial8250_early_options);
+ register_console(&serial8250_early_console);
+}
+
+static int __init serial8250_early_device(struct uart_port *port)
+{
+ struct uart_port *early = &serial8250_early_port.port;
+
+ if (early->iotype = port->iotype &&
+ early->iobase = port->iobase &&
+ early->membase = port->membase)
+ return 1;
+ return 0;
+}
+
+static int __init serial8250_start_console(char *options)
+{
+ int line;
+ struct uart_port *port;
+
+ for (line = 0; line < UART_NR; line++) {
+ port = &serial8250_ports[line].port;
+ if (serial8250_early_device(port)) {
+ add_preferred_console("ttyS", line, options);
+ break;
+ }
+ }
+ if (line = UART_NR)
+ return -ENODEV;
+
+ printk("Starting serial console on ttyS%d at %s 0x%lx (options %s)\n",
+ line,
+ port->iotype = SERIAL_IO_MEM ? "MMIO" : "I/O port",
+ port->iotype = SERIAL_IO_MEM ? (unsigned long) port->mapbase :
+ (unsigned long) port->iobase,
+ options);
+ if (!(serial8250_console.flags & CON_ENABLED))
+ register_console(&serial8250_console);
+ return line;
+}
+
+static int __init serial8250_early_console_switch(void)
+{
+ struct uart_port *port = &serial8250_early_port.port;
+ int line;
+
+ if (!(serial8250_early_console.flags & CON_ENABLED))
+ return 0;
+
+ /* Try to start the normal driver on a matching line. */
+ line = serial8250_start_console(serial8250_early_options);
+ if (line < 0)
+ printk("No ttyS device at %s 0x%lx for console\n",
+ port->iotype = SERIAL_IO_MEM ? "MMIO" : "I/O port",
+ port->iotype = SERIAL_IO_MEM ?
+ (unsigned long) port->mapbase :
+ (unsigned long) port->iobase);
+
+ unregister_console(&serial8250_early_console);
+ if (line >= 0)
+ if (port->iotype = SERIAL_IO_MEM)
+ iounmap(port->membase);
+
+ return 0;
+}
+late_initcall(serial8250_early_console_switch);
#define SERIAL8250_CONSOLE &serial8250_console
#else
=== drivers/serial/8250_hcdp.c 1.3 vs edited ==--- 1.3/drivers/serial/8250_hcdp.c Mon Mar 15 15:53:32 2004
+++ edited/drivers/serial/8250_hcdp.c Thu Apr 1 14:31:04 2004
@@ -1,8 +1,9 @@
/*
- * linux/drivers/char/hcdp_serial.c
+ * EFI HCDP support
*
- * Copyright (C) 2002 Hewlett-Packard Co.
+ * Copyright (C) 2002, 2004 Hewlett-Packard Co.
* Khalid Aziz <[email protected]>
+ * Bjorn Helgaas <[email protected]>
*
* Parse the EFI HCDP table to locate serial console and debug ports and
* initialize them.
@@ -10,19 +11,19 @@
* 2002/08/29 davidm Adjust it to new 2.5 serial driver infrastructure.
*/
-#include <linux/config.h>
+#include <linux/acpi.h>
+#include <linux/console.h>
#include <linux/kernel.h>
#include <linux/efi.h>
#include <linux/init.h>
#include <linux/tty.h>
#include <linux/serial.h>
#include <linux/serial_core.h>
+#include <linux/string.h>
#include <linux/types.h>
-#include <linux/acpi.h>
#include <asm/io.h>
#include <asm/serial.h>
-#include <asm/acpi.h>
#include "8250_hcdp.h"
@@ -203,6 +204,50 @@
#ifdef SERIAL_DEBUG_HCDP
printk("Leaving setup_serial_hcdp()\n");
#endif
+}
+
+void __init
+setup_hcdp_console(hcdp_t *hcdp, char *cmdline)
+{
+ hcdp_dev_t *dev;
+ unsigned long iobase;
+ struct uart_port port;
+ static char options[16];
+ int i;
+
+ if (!hcdp)
+ return;
+
+ /*
+ * The presence of an HCDP entry does not imply that we should
+ * use a serial console.
+ */
+ if (!strstr(cmdline, "console=serial"))
+ return;
+
+ memset(&port, 0, sizeof(port));
+
+ for (i = 0; i < hcdp->num_entries; i++) {
+ dev = hcdp->hcdp_dev + i;
+ if (dev->type != HCDP_DEV_CONSOLE)
+ continue;
+
+ iobase = (u64) dev->base_addr.addrhi << 32 | dev->base_addr.addrlo;
+ if (dev->base_addr.space_id = ACPI_MEM_SPACE) {
+ port.mapbase = iobase;
+ port.membase = ioremap(iobase, 64);
+ port.iotype = SERIAL_IO_MEM;
+ } else if (dev->base_addr.space_id = ACPI_IO_SPACE) {
+ port.iobase = iobase;
+ port.iotype = SERIAL_IO_PORT;
+ } else
+ return;
+
+ snprintf(options, sizeof(options), "%lun%d", dev->baud,
+ dev->bits ? dev->bits : 8);
+ serial8250_early_console_setup(&port, options);
+ return;
+ }
}
#ifdef CONFIG_IA64_EARLY_PRINTK_UART
=== include/linux/serial.h 1.11 vs edited ==--- 1.11/include/linux/serial.h Thu Feb 26 04:26:01 2004
+++ edited/include/linux/serial.h Thu Apr 1 14:31:05 2004
@@ -181,6 +181,7 @@
/* 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 void serial8250_early_console_setup(struct uart_port *port, char *options);
#endif /* __KERNEL__ */
#endif /* _LINUX_SERIAL_H */
Review
Quoted 6 lines · Bjorn Helgaas
(quoted diff) +6
-0+ /* + * The presence of an HCDP entry does not imply that we should + * use a serial console. + */ + if (!strstr(cmdline, "console=serial")) + return;
Yes, but ... it's legal to say "console=tty,serial". So perhaps we need something like ...
char *constart = strstr(cmdline, "console="); if (!constart) return; constart += 8; char *consend = strchr(constart, ' '); if (!consend) consend = constart + strlen(constart); if (!memmem(constart, consend - consline, "serial", 6)) return;
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Bjorn Helgaas
Bjorn> + while (!(UART_LSR_TEMT & serial_in(up, UART_LSR)))
Bjorn> + ;
This needs a cpu_relax()?
--david
Re: [PATCH] early serial console support (updated)
In reply to Bjorn HelgaasHere's an update to my early serial console patch. Changes relative to the previous post:
- serial8250_early_console_setup() callers must supply uartclk
- use uartclk rather than hardcoding BASE_BAUD or 115200
- use cpu_relax() in the early_putc busy loop
- acknowledge x86_64 as source of early init & output code (I think i386 and x86_64 could fairly easily use this to replace their current early_printk scheme)
The consensus seems to be that "console=tty,serial" is actually illegal ("console=tty console=serial" is supported, of course), so no changes required to the argument parsing in 8250_hcdp.c.
Changelog text:
This adds fairly generic early console support to the 8250 serial driver.
The current early_serial_setup() functionality is a bit of a problem for ia64 because it assumes that you know where ttyS0 is before the driver initializes. On ia64, we don't know that because all the devices are enumerated via ACPI and PCI.
However, we do have a firmware interface to tell us where the serial console device is. So this patch adds serial8250_early_console_setup() so the architecture can specify the MMIO or I/O port address instead of the ttyS0 device name.
After the serial driver initializes, we automatically try to locate the corresponding ttyS device, and start up a console on that.
The early serial init and output routines are based on arch/x86_64/kernel/early_printk.c
=== drivers/serial/8250.c 1.48 vs edited ==--- 1.48/drivers/serial/8250.c Mon Mar 15 15:16:26 2004
+++ edited/drivers/serial/8250.c Fri Apr 2 09:14:55 2004
@@ -1882,6 +1882,7 @@
}
#ifdef CONFIG_SERIAL_8250_CONSOLE
+static int serial8250_early_device(struct uart_port *);
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
@@ -1977,6 +1978,13 @@
return -ENODEV;
/*
+ * No need to dump the buffer again if the port is already in
+ * use as the early console device.
+ */
+ if (serial8250_early_device(port))
+ co->flags &= ~CON_PRINTBUFFER;
+
+ /*
* Temporary fix.
*/
spin_lock_init(&port->lock);
@@ -2013,6 +2021,165 @@
return 0;
}
late_initcall(serial8250_late_console_init);
+
+/*
+ * This is for use before the serial driver has initialized, in
+ * particular, before the UARTs have been discovered and named.
+ * Instead of specifying the console device as "ttyS0", platform
+ * code can call serial8250_early_console_setup() to specify it
+ * directly with an MMIO or I/O port address.
+ */
+static struct uart_8250_port serial8250_early_port __initdata;
+static char *serial8250_early_options __initdata;
+
+static void __init serial8250_early_putc(struct uart_8250_port *up, char c)
+{
+ while (!(UART_LSR_TEMT & serial_in(up, UART_LSR)))
+ cpu_relax();
+
+ serial_out(up, UART_TX, c);
+}
+
+/*
+ * Can't use serial8250_console_write() because delay() might not work yet.
+ */
+static void __init serial8250_early_write(struct console *co, const char *s, unsigned int count) +{
+ struct uart_8250_port *up = &serial8250_early_port;
+
+ while (*s && count-- > 0) {
+ serial8250_early_putc(up, *s);
+ if (*s = '\n')
+ serial8250_early_putc(up, '\r');
+ s++;
+ }
+}
+
+static struct console serial8250_early_console __initdata = {
+ .name = "serial",
+ .write = serial8250_early_write,
+ .flags = CON_PRINTBUFFER,
+ .index = -1,
+};
+
+static unsigned int __init serial8250_probe_baud(struct uart_8250_port *port)
+{
+ unsigned char lcr, dll, dlm;
+ unsigned int quot;
+
+ lcr = serial_in(port, UART_LCR);
+ serial_out(port, UART_LCR, lcr | UART_LCR_DLAB);
+ dll = serial_in(port, UART_DLL);
+ dlm = serial_in(port, UART_DLM);
+ serial_out(port, UART_LCR, lcr);
+
+ quot = (dlm << 8) | dll;
+ return (port->port.uartclk / 16) / quot;
+}
+
+static void __init serial8250_early_init(struct uart_8250_port *port, unsigned int baud) +{
+ unsigned char c;
+ unsigned int divisor;
+
+ serial_out(port, UART_LCR, 0x3); /* 8n1 */
+ serial_out(port, UART_IER, 0); /* no interrupt */
+ serial_out(port, UART_FCR, 0); /* no fifo */
+ serial_out(port, UART_MCR, 0x3); /* DTR + RTS */
+
+ divisor = port->port.uartclk / (16 * baud);
+ c = serial_in(port, UART_LCR);
+ serial_out(port, UART_LCR, c | UART_LCR_DLAB);
+ serial_out(port, UART_DLL, divisor & 0xff);
+ serial_out(port, UART_DLM, (divisor >> 8) & 0xff);
+ serial_out(port, UART_LCR, c & ~UART_LCR_DLAB);
+}
+
+void __init serial8250_early_console_setup(struct uart_port *port, char *options) +{
+ unsigned int baud = 9600;
+ static char probed_options[16];
+
+ serial8250_early_port.port = *port;
+ if (options) {
+ serial8250_early_options = options;
+ baud = simple_strtoul(options, 0, 0);
+ } else {
+ baud = serial8250_probe_baud(&serial8250_early_port);
+ snprintf(probed_options, sizeof(probed_options), "%u", baud);
+ serial8250_early_options = probed_options;
+ }
+ serial8250_early_init(&serial8250_early_port, baud);
+ printk("Early serial console at %s 0x%lx (options %s)\n",
+ port->iotype = SERIAL_IO_MEM ? "MMIO" : "I/O port",
+ port->iotype = SERIAL_IO_MEM ? (unsigned long) port->mapbase :
+ (unsigned long) port->iobase,
+ serial8250_early_options);
+ register_console(&serial8250_early_console);
+}
+
+static int __init serial8250_early_device(struct uart_port *port)
+{
+ struct uart_port *early = &serial8250_early_port.port;
+
+ if (early->iotype = port->iotype &&
+ early->iobase = port->iobase &&
+ early->membase = port->membase)
+ return 1;
+ return 0;
+}
+
+static int __init serial8250_start_console(char *options)
+{
+ int line;
+ struct uart_port *port;
+
+ for (line = 0; line < UART_NR; line++) {
+ port = &serial8250_ports[line].port;
+ if (serial8250_early_device(port)) {
+ add_preferred_console("ttyS", line, options);
+ break;
+ }
+ }
+ if (line = UART_NR)
+ return -ENODEV;
+
+ printk("Starting serial console on ttyS%d at %s 0x%lx (options %s)\n",
+ line,
+ port->iotype = SERIAL_IO_MEM ? "MMIO" : "I/O port",
+ port->iotype = SERIAL_IO_MEM ? (unsigned long) port->mapbase :
+ (unsigned long) port->iobase,
+ options);
+ if (!(serial8250_console.flags & CON_ENABLED))
+ register_console(&serial8250_console);
+ return line;
+}
+
+static int __init serial8250_early_console_switch(void)
+{
+ struct uart_port *port = &serial8250_early_port.port;
+ int line;
+
+ if (!(serial8250_early_console.flags & CON_ENABLED))
+ return 0;
+
+ /* Try to start the normal driver on a matching line. */
+ line = serial8250_start_console(serial8250_early_options);
+ if (line < 0)
+ printk("No ttyS device at %s 0x%lx for console\n",
+ port->iotype = SERIAL_IO_MEM ? "MMIO" : "I/O port",
+ port->iotype = SERIAL_IO_MEM ?
+ (unsigned long) port->mapbase :
+ (unsigned long) port->iobase);
+
+ unregister_console(&serial8250_early_console);
+ if (line >= 0)
+ if (port->iotype = SERIAL_IO_MEM)
+ iounmap(port->membase);
+
+ return 0;
+}
+late_initcall(serial8250_early_console_switch);
#define SERIAL8250_CONSOLE &serial8250_console
#else
=== drivers/serial/8250_hcdp.c 1.3 vs edited ==--- 1.3/drivers/serial/8250_hcdp.c Mon Mar 15 15:53:32 2004
+++ edited/drivers/serial/8250_hcdp.c Fri Apr 2 09:34:47 2004
@@ -1,8 +1,9 @@
/*
- * linux/drivers/char/hcdp_serial.c
+ * EFI HCDP support
*
- * Copyright (C) 2002 Hewlett-Packard Co.
+ * Copyright (C) 2002, 2004 Hewlett-Packard Co.
* Khalid Aziz <[email protected]>
+ * Bjorn Helgaas <[email protected]>
*
* Parse the EFI HCDP table to locate serial console and debug ports and
* initialize them.
@@ -10,19 +11,19 @@
* 2002/08/29 davidm Adjust it to new 2.5 serial driver infrastructure.
*/
-#include <linux/config.h>
+#include <linux/acpi.h>
+#include <linux/console.h>
#include <linux/kernel.h>
#include <linux/efi.h>
#include <linux/init.h>
#include <linux/tty.h>
#include <linux/serial.h>
#include <linux/serial_core.h>
+#include <linux/string.h>
#include <linux/types.h>
-#include <linux/acpi.h>
#include <asm/io.h>
#include <asm/serial.h>
-#include <asm/acpi.h>
#include "8250_hcdp.h"
@@ -203,6 +204,51 @@
#ifdef SERIAL_DEBUG_HCDP
printk("Leaving setup_serial_hcdp()\n");
#endif
+}
+
+void __init
+setup_hcdp_console(hcdp_t *hcdp, char *cmdline)
+{
+ hcdp_dev_t *dev;
+ unsigned long iobase;
+ struct uart_port port;
+ static char options[16];
+ int i;
+
+ if (!hcdp)
+ return;
+
+ /*
+ * The presence of an HCDP entry does not imply that we should
+ * use a serial console.
+ */
+ if (!strstr(cmdline, "console=serial"))
+ return;
+
+ memset(&port, 0, sizeof(port));
+
+ for (i = 0; i < hcdp->num_entries; i++) {
+ dev = hcdp->hcdp_dev + i;
+ if (dev->type != HCDP_DEV_CONSOLE)
+ continue;
+
+ port.uartclk = dev->clock_rate;
+ iobase = (u64) dev->base_addr.addrhi << 32 | dev->base_addr.addrlo;
+ if (dev->base_addr.space_id = ACPI_MEM_SPACE) {
+ port.mapbase = iobase;
+ port.membase = ioremap(iobase, 64);
+ port.iotype = SERIAL_IO_MEM;
+ } else if (dev->base_addr.space_id = ACPI_IO_SPACE) {
+ port.iobase = iobase;
+ port.iotype = SERIAL_IO_PORT;
+ } else
+ return;
+
+ snprintf(options, sizeof(options), "%lun%d", dev->baud,
+ dev->bits ? dev->bits : 8);
+ serial8250_early_console_setup(&port, options);
+ return;
+ }
}
#ifdef CONFIG_IA64_EARLY_PRINTK_UART
=== include/linux/serial.h 1.11 vs edited ==--- 1.11/include/linux/serial.h Thu Feb 26 04:26:01 2004
+++ edited/include/linux/serial.h Fri Apr 2 08:52:55 2004
@@ -181,6 +181,7 @@
/* 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 void serial8250_early_console_setup(struct uart_port *port, char *options);
#endif /* __KERNEL__ */
#endif /* _LINUX_SERIAL_H */
Re: [PATCH] early serial console support (update 2)
Proving the maxim that you always discover a new problem immediately after hitting "send", I found that some HP firmware doesn't fill in the UART clock information in the HCDP. So this adds:
- default to BASE_BAUD * 16 if HCDP doesn't supply clock rate
Changelog text:
This adds fairly generic early console support to the 8250 serial driver.
The current early_serial_setup() functionality is a bit of a problem for ia64 because it assumes that you know where ttyS0 is before the driver initializes. On ia64, we don't know that because all the devices are enumerated via ACPI and PCI.
However, we do have a firmware interface to tell us where the serial console device is. So this patch adds serial8250_early_console_setup() so the architecture can specify the MMIO or I/O port address instead of the ttyS0 device name.
After the serial driver initializes, we automatically try to locate the corresponding ttyS device, and start up a console on that.
The early serial init and output routines are based on arch/x86_64/kernel/early_printk.c
=== drivers/serial/8250.c 1.48 vs edited ==--- 1.48/drivers/serial/8250.c Mon Mar 15 15:16:26 2004
+++ edited/drivers/serial/8250.c Fri Apr 2 09:14:55 2004
@@ -1882,6 +1882,7 @@
}
#ifdef CONFIG_SERIAL_8250_CONSOLE
+static int serial8250_early_device(struct uart_port *);
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
@@ -1977,6 +1978,13 @@
return -ENODEV;
/*
+ * No need to dump the buffer again if the port is already in
+ * use as the early console device.
+ */
+ if (serial8250_early_device(port))
+ co->flags &= ~CON_PRINTBUFFER;
+
+ /*
* Temporary fix.
*/
spin_lock_init(&port->lock);
@@ -2013,6 +2021,165 @@
return 0;
}
late_initcall(serial8250_late_console_init);
+
+/*
+ * This is for use before the serial driver has initialized, in
+ * particular, before the UARTs have been discovered and named.
+ * Instead of specifying the console device as "ttyS0", platform
+ * code can call serial8250_early_console_setup() to specify it
+ * directly with an MMIO or I/O port address.
+ */
+static struct uart_8250_port serial8250_early_port __initdata;
+static char *serial8250_early_options __initdata;
+
+static void __init serial8250_early_putc(struct uart_8250_port *up, char c)
+{
+ while (!(UART_LSR_TEMT & serial_in(up, UART_LSR)))
+ cpu_relax();
+
+ serial_out(up, UART_TX, c);
+}
+
+/*
+ * Can't use serial8250_console_write() because delay() might not work yet.
+ */
+static void __init serial8250_early_write(struct console *co, const char *s, unsigned int count) +{
+ struct uart_8250_port *up = &serial8250_early_port;
+
+ while (*s && count-- > 0) {
+ serial8250_early_putc(up, *s);
+ if (*s = '\n')
+ serial8250_early_putc(up, '\r');
+ s++;
+ }
+}
+
+static struct console serial8250_early_console __initdata = {
+ .name = "serial",
+ .write = serial8250_early_write,
+ .flags = CON_PRINTBUFFER,
+ .index = -1,
+};
+
+static unsigned int __init serial8250_probe_baud(struct uart_8250_port *port)
+{
+ unsigned char lcr, dll, dlm;
+ unsigned int quot;
+
+ lcr = serial_in(port, UART_LCR);
+ serial_out(port, UART_LCR, lcr | UART_LCR_DLAB);
+ dll = serial_in(port, UART_DLL);
+ dlm = serial_in(port, UART_DLM);
+ serial_out(port, UART_LCR, lcr);
+
+ quot = (dlm << 8) | dll;
+ return (port->port.uartclk / 16) / quot;
+}
+
+static void __init serial8250_early_init(struct uart_8250_port *port, unsigned int baud) +{
+ unsigned char c;
+ unsigned int divisor;
+
+ serial_out(port, UART_LCR, 0x3); /* 8n1 */
+ serial_out(port, UART_IER, 0); /* no interrupt */
+ serial_out(port, UART_FCR, 0); /* no fifo */
+ serial_out(port, UART_MCR, 0x3); /* DTR + RTS */
+
+ divisor = port->port.uartclk / (16 * baud);
+ c = serial_in(port, UART_LCR);
+ serial_out(port, UART_LCR, c | UART_LCR_DLAB);
+ serial_out(port, UART_DLL, divisor & 0xff);
+ serial_out(port, UART_DLM, (divisor >> 8) & 0xff);
+ serial_out(port, UART_LCR, c & ~UART_LCR_DLAB);
+}
+
+void __init serial8250_early_console_setup(struct uart_port *port, char *options) +{
+ unsigned int baud = 9600;
+ static char probed_options[16];
+
+ serial8250_early_port.port = *port;
+ if (options) {
+ serial8250_early_options = options;
+ baud = simple_strtoul(options, 0, 0);
+ } else {
+ baud = serial8250_probe_baud(&serial8250_early_port);
+ snprintf(probed_options, sizeof(probed_options), "%u", baud);
+ serial8250_early_options = probed_options;
+ }
+ serial8250_early_init(&serial8250_early_port, baud);
+ printk("Early serial console at %s 0x%lx (options %s)\n",
+ port->iotype = SERIAL_IO_MEM ? "MMIO" : "I/O port",
+ port->iotype = SERIAL_IO_MEM ? (unsigned long) port->mapbase :
+ (unsigned long) port->iobase,
+ serial8250_early_options);
+ register_console(&serial8250_early_console);
+}
+
+static int __init serial8250_early_device(struct uart_port *port)
+{
+ struct uart_port *early = &serial8250_early_port.port;
+
+ if (early->iotype = port->iotype &&
+ early->iobase = port->iobase &&
+ early->membase = port->membase)
+ return 1;
+ return 0;
+}
+
+static int __init serial8250_start_console(char *options)
+{
+ int line;
+ struct uart_port *port;
+
+ for (line = 0; line < UART_NR; line++) {
+ port = &serial8250_ports[line].port;
+ if (serial8250_early_device(port)) {
+ add_preferred_console("ttyS", line, options);
+ break;
+ }
+ }
+ if (line = UART_NR)
+ return -ENODEV;
+
+ printk("Starting serial console on ttyS%d at %s 0x%lx (options %s)\n",
+ line,
+ port->iotype = SERIAL_IO_MEM ? "MMIO" : "I/O port",
+ port->iotype = SERIAL_IO_MEM ? (unsigned long) port->mapbase :
+ (unsigned long) port->iobase,
+ options);
+ if (!(serial8250_console.flags & CON_ENABLED))
+ register_console(&serial8250_console);
+ return line;
+}
+
+static int __init serial8250_early_console_switch(void)
+{
+ struct uart_port *port = &serial8250_early_port.port;
+ int line;
+
+ if (!(serial8250_early_console.flags & CON_ENABLED))
+ return 0;
+
+ /* Try to start the normal driver on a matching line. */
+ line = serial8250_start_console(serial8250_early_options);
+ if (line < 0)
+ printk("No ttyS device at %s 0x%lx for console\n",
+ port->iotype = SERIAL_IO_MEM ? "MMIO" : "I/O port",
+ port->iotype = SERIAL_IO_MEM ?
+ (unsigned long) port->mapbase :
+ (unsigned long) port->iobase);
+
+ unregister_console(&serial8250_early_console);
+ if (line >= 0)
+ if (port->iotype = SERIAL_IO_MEM)
+ iounmap(port->membase);
+
+ return 0;
+}
+late_initcall(serial8250_early_console_switch);
#define SERIAL8250_CONSOLE &serial8250_console
#else
=== drivers/serial/8250_hcdp.c 1.3 vs edited ==--- 1.3/drivers/serial/8250_hcdp.c Mon Mar 15 15:53:32 2004
+++ edited/drivers/serial/8250_hcdp.c Fri Apr 2 10:27:57 2004
@@ -1,8 +1,9 @@
/*
- * linux/drivers/char/hcdp_serial.c
+ * EFI HCDP support
*
- * Copyright (C) 2002 Hewlett-Packard Co.
+ * Copyright (C) 2002, 2004 Hewlett-Packard Co.
* Khalid Aziz <[email protected]>
+ * Bjorn Helgaas <[email protected]>
*
* Parse the EFI HCDP table to locate serial console and debug ports and
* initialize them.
@@ -10,19 +11,19 @@
* 2002/08/29 davidm Adjust it to new 2.5 serial driver infrastructure.
*/
-#include <linux/config.h>
+#include <linux/acpi.h>
+#include <linux/console.h>
#include <linux/kernel.h>
#include <linux/efi.h>
#include <linux/init.h>
#include <linux/tty.h>
#include <linux/serial.h>
#include <linux/serial_core.h>
+#include <linux/string.h>
#include <linux/types.h>
-#include <linux/acpi.h>
#include <asm/io.h>
#include <asm/serial.h>
-#include <asm/acpi.h>
#include "8250_hcdp.h"
@@ -203,6 +204,53 @@
#ifdef SERIAL_DEBUG_HCDP
printk("Leaving setup_serial_hcdp()\n");
#endif
+}
+
+void __init
+setup_hcdp_console(hcdp_t *hcdp, char *cmdline)
+{
+ hcdp_dev_t *dev;
+ unsigned long iobase;
+ struct uart_port port;
+ static char options[16];
+ int i;
+
+ if (!hcdp)
+ return;
+
+ /*
+ * The presence of an HCDP entry does not imply that we should
+ * use a serial console.
+ */
+ if (!strstr(cmdline, "console=serial"))
+ return;
+
+ memset(&port, 0, sizeof(port));
+
+ for (i = 0; i < hcdp->num_entries; i++) {
+ dev = hcdp->hcdp_dev + i;
+ if (dev->type != HCDP_DEV_CONSOLE)
+ continue;
+
+ port.uartclk = dev->clock_rate;
+ if (!port.uartclk) /* some FW doesn't supply this */
+ port.uartclk = BASE_BAUD * 16;
+ iobase = (u64) dev->base_addr.addrhi << 32 | dev->base_addr.addrlo;
+ if (dev->base_addr.space_id = ACPI_MEM_SPACE) {
+ port.mapbase = iobase;
+ port.membase = ioremap(iobase, 64);
+ port.iotype = SERIAL_IO_MEM;
+ } else if (dev->base_addr.space_id = ACPI_IO_SPACE) {
+ port.iobase = iobase;
+ port.iotype = SERIAL_IO_PORT;
+ } else
+ return;
+
+ snprintf(options, sizeof(options), "%lun%d", dev->baud,
+ dev->bits ? dev->bits : 8);
+ serial8250_early_console_setup(&port, options);
+ return;
+ }
}
#ifdef CONFIG_IA64_EARLY_PRINTK_UART
=== include/linux/serial.h 1.11 vs edited ==--- 1.11/include/linux/serial.h Thu Feb 26 04:26:01 2004
+++ edited/include/linux/serial.h Fri Apr 2 08:52:55 2004
@@ -181,6 +181,7 @@
/* 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 void serial8250_early_console_setup(struct uart_port *port, char *options);
#endif /* __KERNEL__ */
#endif /* _LINUX_SERIAL_H */
Quoted 10 lines · Matthew Wilcox
Review
Quoted 6 lines · Bjorn Helgaas
(quoted diff) +6
-0+ /* + * The presence of an HCDP entry does not imply that we should + * use a serial console. + */ + if (!strstr(cmdline, "console=serial")) + return;Yes, but ... it's legal to say "console=tty,serial". So perhaps we need something like ...
Are you sure that's legal? The existing console= parameter format is:
console=<device>[,<device-specific-parameters>]
in which case, the parameter you've given above indicates:
device = tty
device-specific-params = serial
which is obviously nonsense. I think it should be:
console=tty console=serial
which nicely fits into the current scheme.
Signature · 4 lines
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 PCMCIA - http://pcmcia.arm.linux.org.uk/
2.6 Serial core