serial: 8250: Add preferred console in serial8250_isa_init_ports()
authorTony Lindgren <tony@atomide.com>
Wed, 27 Mar 2024 10:59:40 +0000 (12:59 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 9 Apr 2024 13:30:13 +0000 (15:30 +0200)
Prepare 8250 ISA ports to drop kernel command line serial console
handling from console_setup().

We need to set the preferred console in serial8250_isa_init_ports()
to drop a dependency to setup_console() handling the ttyS related
quirks. Otherwise when console_setup() handles the ttyS related
options, console gets enabled only at driver probe time.

Note that this mostly affects x86 as this happens based on define
SERIAL_PORT_DFNS.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/20240327110021.59793-7-tony@atomide.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/8250/8250_core.c
drivers/tty/serial/serial_base.h
drivers/tty/serial/serial_base_bus.c

index 3a1936b7f05fa56e9805983e293e416dd16cdcf3..43824a174a51560c1d1ae95cb363919e58d4c09c 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/cleanup.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/ioport.h>
@@ -41,6 +42,8 @@
 
 #include <asm/irq.h>
 
+#include "../serial_base.h"    /* For serial_base_add_isa_preferred_console() */
+
 #include "8250.h"
 
 /*
@@ -564,6 +567,8 @@ static void __init serial8250_isa_init_ports(void)
                port->irqflags |= irqflag;
                if (serial8250_isa_config != NULL)
                        serial8250_isa_config(i, &up->port, &up->capabilities);
+
+               serial_base_add_isa_preferred_console(serial8250_reg.dev_name, i);
        }
 }
 
index 327a18b1813b680732834219a0afa9a348e316e8..39dab6bd4b76babf3b85975b2c2a72305248bdc4 100644 (file)
@@ -51,6 +51,8 @@ void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port
 int serial_base_add_preferred_console(struct uart_driver *drv,
                                      struct uart_port *port);
 
+int serial_base_add_isa_preferred_console(const char *name, int idx);
+
 #else
 
 static inline
@@ -60,4 +62,10 @@ int serial_base_add_preferred_console(struct uart_driver *drv,
        return 0;
 }
 
+static inline
+int serial_base_add_isa_preferred_console(const char *name, int idx)
+{
+       return 0;
+}
+
 #endif
index 1375be3315e6d459dea56b47dd59ad24bd7d48e1..ae18871c0f3641d4829b660efff6055fa3b56647 100644 (file)
@@ -317,6 +317,27 @@ int serial_base_add_preferred_console(struct uart_driver *drv,
        return serial_base_add_one_prefcon(port_match, drv->dev_name, port->line);
 }
 
+#ifdef CONFIG_SERIAL_8250_CONSOLE
+
+/*
+ * Early ISA ports initialize the console before there is no struct device.
+ * This should be only called from serial8250_isa_init_preferred_console(),
+ * other callers are likely wrong and should rely on earlycon instead.
+ */
+int serial_base_add_isa_preferred_console(const char *name, int idx)
+{
+       return serial_base_add_prefcon(name, idx);
+}
+
+#else
+
+int serial_base_add_isa_preferred_console(const char *name, int idx)
+{
+       return 0;
+}
+
+#endif
+
 #endif
 
 static int serial_base_init(void)