mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jason Wessel <jason.wessel@windriver.com>
To: gregkh@suse.de
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jason Wessel <jason.wessel@windriver.com>,
	Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Yinghai Lu <yinghai@kernel.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Randy Dunlap <randy.dunlap@oracle.com>
Subject: [PATCH 05/10] printk,early_printk,console: Allow more than one early console
Date: Fri, 31 Jul 2009 10:07:08 -0500	[thread overview]
Message-ID: <1249052833-9655-6-git-send-email-jason.wessel@windriver.com> (raw)
In-Reply-To: <1249052833-9655-5-git-send-email-jason.wessel@windriver.com>

It is very nice to be able to use one early boot device to debug
another or to have multiple places you can see the early boot
diagnostics, such as the vga screen or serial device.

This patch changes the early_printk console device registration to
allow more than one early printk device to get registered via
register_console().

A corresponding change is required to the console registration code
such that it will properly unregister any console marked with the
CON_BOOT flag via a simple loop during a console handover or at late
init time.

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Cc: Greg KH <gregkh@suse.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
---
 arch/x86/kernel/early_printk.c |   65 ++++++++++++++++++++-------------------
 kernel/printk.c                |   41 ++++++++++++++++---------
 2 files changed, 59 insertions(+), 47 deletions(-)

diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index 519a5e1..2acfd3f 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -176,10 +176,19 @@ asmlinkage void early_printk(const char *fmt, ...)
 	va_end(ap);
 }
 
+static inline void early_console_register(struct console *con, int keep_early)
+{
+	early_console = con;
+	if (keep_early)
+		early_console->flags &= ~CON_BOOT;
+	else
+		early_console->flags |= CON_BOOT;
+	register_console(early_console);
+}
 
 static int __init setup_early_printk(char *buf)
 {
-	int keep_early;
+	int keep;
 
 	if (!buf)
 		return 0;
@@ -188,42 +197,34 @@ static int __init setup_early_printk(char *buf)
 		return 0;
 	early_console_initialized = 1;
 
-	keep_early = (strstr(buf, "keep") != NULL);
-
-	if (!strncmp(buf, "serial", 6)) {
-		early_serial_init(buf + 6);
-		early_console = &early_serial_console;
-	} else if (!strncmp(buf, "ttyS", 4)) {
-		early_serial_init(buf);
-		early_console = &early_serial_console;
-	} else if (!strncmp(buf, "vga", 3)
-		&& boot_params.screen_info.orig_video_isVGA == 1) {
-		max_xpos = boot_params.screen_info.orig_video_cols;
-		max_ypos = boot_params.screen_info.orig_video_lines;
-		current_ypos = boot_params.screen_info.orig_y;
-		early_console = &early_vga_console;
+	keep = (strstr(buf, "keep") != NULL);
+
+	while (*buf != '\0') {
+		if (!strncmp(buf, "serial", 6)) {
+			early_serial_init(buf + 6);
+			early_console_register(&early_serial_console, keep);
+		}
+		if (!strncmp(buf, "ttyS", 4)) {
+			early_serial_init(buf + 4);
+			early_console_register(&early_serial_console, keep);
+		}
+		if (!strncmp(buf, "vga", 3) &&
+		    boot_params.screen_info.orig_video_isVGA == 1) {
+			max_xpos = boot_params.screen_info.orig_video_cols;
+			max_ypos = boot_params.screen_info.orig_video_lines;
+			current_ypos = boot_params.screen_info.orig_y;
+			early_console_register(&early_vga_console, keep);
+		}
 #ifdef CONFIG_EARLY_PRINTK_DBGP
-	} else if (!strncmp(buf, "dbgp", 4)) {
-		if (early_dbgp_init(buf+4) < 0)
-			return 0;
-		early_console = &early_dbgp_console;
-		/*
-		 * usb subsys will reset ehci controller, so don't keep
-		 * that early console
-		 */
-		keep_early = 0;
+		if (!strncmp(buf, "dbgp", 4) && !early_dbgp_init(buf + 4))
+			early_console_register(&early_dbgp_console, keep);
 #endif
 #ifdef CONFIG_HVC_XEN
-	} else if (!strncmp(buf, "xen", 3)) {
-		early_console = &xenboot_console;
+		if (!strncmp(buf, "xen", 3))
+			early_console_register(&xenboot_console, keep);
 #endif
+		buf++;
 	}
-
-	if (keep_early)
-		early_console->flags &= ~CON_BOOT;
-	else
-		early_console->flags |= CON_BOOT;
-	register_console(early_console);
 	return 0;
 }
 
diff --git a/kernel/printk.c b/kernel/printk.c
index b4d97b5..45e0cec 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -1129,6 +1129,28 @@ void console_start(struct console *console)
 }
 EXPORT_SYMBOL(console_start);
 
+static int disable_boot_consoles(void)
+{
+	struct console *bootconsole = console_drivers;
+	struct console *nextcon;
+	if (!bootconsole)
+		return 0;
+	while (bootconsole) {
+		nextcon = bootconsole->next;
+		if (bootconsole->flags & CON_BOOT) {
+			printk(KERN_INFO "turn off boot console %s%d\n",
+			       console_drivers->name, console_drivers->index);
+			if (unregister_console(bootconsole) != 0)
+				printk(KERN_ERR "ERROR unregistering %s%d\n",
+				       console_drivers->name,
+				       console_drivers->index);
+		}
+		bootconsole = nextcon;
+	}
+	return 0;
+}
+late_initcall(disable_boot_consoles);
+
 /*
  * The console driver calls this routine during kernel initialization
  * to register the console printing procedure with printk() and to
@@ -1142,8 +1164,7 @@ void register_console(struct console *console)
 	struct console *bootconsole = NULL;
 
 	if (console_drivers) {
-		if (console->flags & CON_BOOT)
-			return;
+
 		if (console_drivers->flags & CON_BOOT)
 			bootconsole = console_drivers;
 	}
@@ -1216,6 +1237,7 @@ void register_console(struct console *console)
 		       console->name, console->index);
 		unregister_console(bootconsole);
 		console->flags &= ~CON_PRINTBUFFER;
+		disable_boot_consoles();
 	} else {
 		printk(KERN_INFO "console [%s%d] enabled\n",
 		       console->name, console->index);
@@ -1280,24 +1302,13 @@ int unregister_console(struct console *console)
 	if (console_drivers != NULL && console->flags & CON_CONSDEV)
 		console_drivers->flags |= CON_CONSDEV;
 
+	if (!res)
+		console->index = -1;
 	release_console_sem();
 	return res;
 }
 EXPORT_SYMBOL(unregister_console);
 
-static int __init disable_boot_consoles(void)
-{
-	if (console_drivers != NULL) {
-		if (console_drivers->flags & CON_BOOT) {
-			printk(KERN_INFO "turn off boot console %s%d\n",
-				console_drivers->name, console_drivers->index);
-			return unregister_console(console_drivers);
-		}
-	}
-	return 0;
-}
-late_initcall(disable_boot_consoles);
-
 #if defined CONFIG_PRINTK
 
 /*
-- 
1.6.0.3.523.g304d0


  reply	other threads:[~2009-07-31 15:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-31 15:07 [PATCH 0/10] x86: EHCI and earlyprintk= improvements (Round 2) Jason Wessel
2009-07-31 15:07 ` [PATCH 01/10] ehci early_printk: split ehci debug driver from early_printk.c Jason Wessel
2009-07-31 15:07   ` [PATCH 02/10] usb,early_printk: insert cr prior to nl as needed Jason Wessel
2009-07-31 15:07     ` [PATCH 03/10] ehci-dbgp: Execute early BIOS hand off Jason Wessel
2009-07-31 15:07       ` [PATCH 04/10] usb,early_printk: EHCI debug controller initialization delays Jason Wessel
2009-07-31 15:07         ` Jason Wessel [this message]
2009-07-31 15:07           ` [PATCH 06/10] ehci-dbgp: stability improvements and external re-init Jason Wessel
2009-07-31 15:07             ` [PATCH 07/10] ehci-dbgp,ehci: Allow early or late use of the dbgp device Jason Wessel
2009-07-31 15:07               ` [PATCH 08/10] ehci-dbgp: errata for EHCI debug controller initialization Jason Wessel
2009-07-31 15:07                 ` [PATCH 09/10] ehci-dbgp: errata for EHCI debug/host controller synchronization Jason Wessel
2009-07-31 15:07                   ` [PATCH 10/10] ehci-dbgp,documentation: Documentation updates for ehci-dbgp Jason Wessel
2009-07-31 15:41               ` [PATCH 07/10] ehci-dbgp,ehci: Allow early or late use of the dbgp device Alan Stern
2009-07-31 17:22                 ` Jason Wessel
2009-07-31 18:53                   ` Alan Stern
     [not found]                     ` <4A7355EA.60107@windriver.com>
2009-07-31 21:34                       ` Jason Wessel
2009-08-01 15:47                         ` Alan Stern
2009-08-03 14:48                           ` Jason Wessel
2009-08-18 17:47               ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2009-07-20 20:06 [PATCH 0/10] x86: EHCI and earlyprintk= improvements Jason Wessel
2009-07-20 20:06 ` [PATCH 01/10] ehci early_printk: split ehci debug driver from early_printk.c Jason Wessel
2009-07-20 20:06   ` [PATCH 02/10] usb,early_printk: insert cr prior to nl as needed Jason Wessel
2009-07-20 20:06     ` [PATCH 03/10] ehci-dbgp: Execute early BIOS hand off Jason Wessel
2009-07-20 20:06       ` [PATCH 04/10] usb,early_printk: EHCI debug controller initialization delays Jason Wessel
2009-07-20 20:06         ` [PATCH 05/10] printk,early_printk,console: Allow more than one early console Jason Wessel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1249052833-9655-6-git-send-email-jason.wessel@windriver.com \
    --to=jason.wessel@windriver.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=randy.dunlap@oracle.com \
    --cc=yinghai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®