Skip to contentSkip to conversation

Serial console transition hook

PATCH New Bjorn Helgaas 1 participant 1 message Mar 5, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Serial console transition hook

Here's another piece of serial console support. In general, we don't know the (device -> ttySN) mapping until the serial driver is initialized, so we really can't make "console=ttySN" work early.

The idea here is that early platform code can discover the serial console device (on IA64, this comes from firmware), set up an early console on it, then transparently switch to using the normal serial console driver after it is initialized.

This hook allows the platform code to supply the UART info, and we match it to a ttySN, register that as a console, and return N. The platform code may need to export N to userland so it can figure out where to start a getty on the console. (Currently we insert the correct "console=ttySN" string in saved_command_line[] so it shows up in /proc/cmdline, for lack of a better approach.)

This is against 2.6.4-rc1 plus the previous late console init patch (no dependency, just happens to be adjacent in the source).

===== drivers/serial/8250.c 1.46 vs edited =====

drivers/serial/8250.c +23 -0
@@ -2017,6 +2017,29 @@
 }
 late_initcall(serial8250_late_console_init);
 
+int __init serial8250_start_console(struct uart_port *port, char *options)
+{
+	struct uart_port *up;
+	int i;
+
+	for (i = 0; i < UART_NR; i++) {
+		up = &serial8250_ports[i].port;
+		if (up->iotype == port->iotype &&up->iobase == port->iobase &&
+		    up->membase == port->membase) {
+			add_preferred_console("ttyS", i, options);
+			break;
+		}
+	}
+	if (i == UART_NR)
+		return -ENODEV;
+
+	if (!(serial8250_console.flags & CON_ENABLED)) {
+		serial8250_console.flags &= ~CON_PRINTBUFFER;
+		register_console(&serial8250_console);
+	}
+	return i;
+}
+
 #define SERIAL8250_CONSOLE	&serial8250_console
 #else
 #define SERIAL8250_CONSOLE	NULL

===== drivers/serial/8250.h 1.7 vs edited =====

drivers/serial/8250.h +1 -0
@@ -29,6 +29,7 @@
 void serial8250_get_irq_map(unsigned int *map);
 void serial8250_suspend_port(int line);
 void serial8250_resume_port(int line);
+int __init serial8250_start_console(struct uart_port *port, char *options);
 
 struct old_serial_port {
 	unsigned int uart;