Commit 4d091611 authored by Robin Getz's avatar Robin Getz Committed by Ingo Molnar

printk: Enable the use of more than one CON_BOOT (early console)

Today, register_console() assumes the following usage:

  - The first console to register with a flag set to CON_BOOT
    is the one and only bootconsole.

  - If another register_console() is called with an additional
    CON_BOOT, it is silently rejected.

  - As soon as a console without the CON_BOOT set calls
    registers the bootconsole is automatically unregistered.

  - Once there is a "real" console - register_console() will
    silently reject any consoles with it's CON_BOOT flag set.

In many systems (alpha, blackfin, microblaze, mips, powerpc,
sh, & x86), there are early_printk implementations, which use
the CON_BOOT which come out serial ports, vga, usb, & memory
buffers.

In many embedded systems, it would be nice to have two
bootconsoles - in case the primary fails, you always have
access to a backup memory buffer - but this requires at least
two CON_BOOT consoles...

This patch enables that functionality.

With the change applied, on boot you get (if you try to
re-enable a boot console after the "real" console has been
registered):

  root:/> dmesg | grep console
  bootconsole [early_shadow0] enabled
  bootconsole [early_BFuart0] enabled
  Kernel command line: root=/dev/mtdblock0 rw earlyprintk=serial,uart0,57600 console=ttyBF0,57600 nmi_debug=regs
  console handover:boot [early_BFuart0] boot [early_shadow0]  -> real [ttyBF0]
  Too late to register bootconsole early_shadow0

or:

  root:/> dmesg | grep console
  Kernel command line: root=/dev/mtdblock0 rw console=ttyBF0,57600
  console [ttyBF0] enabled
Signed-off-by: default avatarRobin Getz <rgetz@blackfin.uclinux.org>
Cc: "Linus Torvalds" <torvalds@linux-foundation.org>
Cc: "Andrew Morton" <akpm@linux-foundation.org>
Cc: "Mike Frysinger" <vapier.adi@gmail.com>
Cc: "Paul Mundt" <lethal@linux-sh.org>
LKML-Reference: <200907012108.38030.rgetz@blackfin.uclinux.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 7c5371c4
...@@ -36,6 +36,12 @@ ...@@ -36,6 +36,12 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
/*
* for_each_console() allows you to iterate on each console
*/
#define for_each_console(con) \
for (con = console_drivers; con != NULL; con = con->next)
/* /*
* Architectures can override it: * Architectures can override it:
*/ */
...@@ -412,7 +418,7 @@ static void __call_console_drivers(unsigned start, unsigned end) ...@@ -412,7 +418,7 @@ static void __call_console_drivers(unsigned start, unsigned end)
{ {
struct console *con; struct console *con;
for (con = console_drivers; con; con = con->next) { for_each_console(con) {
if ((con->flags & CON_ENABLED) && con->write && if ((con->flags & CON_ENABLED) && con->write &&
(cpu_online(smp_processor_id()) || (cpu_online(smp_processor_id()) ||
(con->flags & CON_ANYTIME))) (con->flags & CON_ANYTIME)))
...@@ -544,7 +550,7 @@ static int have_callable_console(void) ...@@ -544,7 +550,7 @@ static int have_callable_console(void)
{ {
struct console *con; struct console *con;
for (con = console_drivers; con; con = con->next) for_each_console(con)
if (con->flags & CON_ANYTIME) if (con->flags & CON_ANYTIME)
return 1; return 1;
...@@ -1082,7 +1088,7 @@ void console_unblank(void) ...@@ -1082,7 +1088,7 @@ void console_unblank(void)
console_locked = 1; console_locked = 1;
console_may_schedule = 0; console_may_schedule = 0;
for (c = console_drivers; c != NULL; c = c->next) for_each_console(c)
if ((c->flags & CON_ENABLED) && c->unblank) if ((c->flags & CON_ENABLED) && c->unblank)
c->unblank(); c->unblank();
release_console_sem(); release_console_sem();
...@@ -1097,7 +1103,7 @@ struct tty_driver *console_device(int *index) ...@@ -1097,7 +1103,7 @@ struct tty_driver *console_device(int *index)
struct tty_driver *driver = NULL; struct tty_driver *driver = NULL;
acquire_console_sem(); acquire_console_sem();
for (c = console_drivers; c != NULL; c = c->next) { for_each_console(c) {
if (!c->device) if (!c->device)
continue; continue;
driver = c->device(c, index); driver = c->device(c, index);
...@@ -1134,25 +1140,49 @@ EXPORT_SYMBOL(console_start); ...@@ -1134,25 +1140,49 @@ EXPORT_SYMBOL(console_start);
* to register the console printing procedure with printk() and to * to register the console printing procedure with printk() and to
* print any messages that were printed by the kernel before the * print any messages that were printed by the kernel before the
* console driver was initialized. * console driver was initialized.
*
* This can happen pretty early during the boot process (because of
* early_printk) - sometimes before setup_arch() completes - be careful
* of what kernel features are used - they may not be initialised yet.
*
* There are two types of consoles - bootconsoles (early_printk) and
* "real" consoles (everything which is not a bootconsole) which are
* handled differently.
* - Any number of bootconsoles can be registered at any time.
* - As soon as a "real" console is registered, all bootconsoles
* will be unregistered automatically.
* - Once a "real" console is registered, any attempt to register a
* bootconsoles will be rejected
*/ */
void register_console(struct console *console) void register_console(struct console *newcon)
{ {
int i; int i;
unsigned long flags; unsigned long flags;
struct console *bootconsole = NULL; struct console *bcon = NULL;
if (console_drivers) { /*
if (console->flags & CON_BOOT) * before we register a new CON_BOOT console, make sure we don't
* already have a valid console
*/
if (console_drivers && newcon->flags & CON_BOOT) {
/* find the last or real console */
for_each_console(bcon) {
if (!(bcon->flags & CON_BOOT)) {
printk(KERN_INFO "Too late to register bootconsole %s%d\n",
newcon->name, newcon->index);
return; return;
if (console_drivers->flags & CON_BOOT)
bootconsole = console_drivers;
} }
}
}
if (console_drivers && console_drivers->flags & CON_BOOT)
bcon = console_drivers;
if (preferred_console < 0 || bootconsole || !console_drivers) if (preferred_console < 0 || bcon || !console_drivers)
preferred_console = selected_console; preferred_console = selected_console;
if (console->early_setup) if (newcon->early_setup)
console->early_setup(); newcon->early_setup();
/* /*
* See if we want to use this console driver. If we * See if we want to use this console driver. If we
...@@ -1160,13 +1190,13 @@ void register_console(struct console *console) ...@@ -1160,13 +1190,13 @@ void register_console(struct console *console)
* that registers here. * that registers here.
*/ */
if (preferred_console < 0) { if (preferred_console < 0) {
if (console->index < 0) if (newcon->index < 0)
console->index = 0; newcon->index = 0;
if (console->setup == NULL || if (newcon->setup == NULL ||
console->setup(console, NULL) == 0) { newcon->setup(newcon, NULL) == 0) {
console->flags |= CON_ENABLED; newcon->flags |= CON_ENABLED;
if (console->device) { if (newcon->device) {
console->flags |= CON_CONSDEV; newcon->flags |= CON_CONSDEV;
preferred_console = 0; preferred_console = 0;
} }
} }
...@@ -1178,47 +1208,53 @@ void register_console(struct console *console) ...@@ -1178,47 +1208,53 @@ void register_console(struct console *console)
*/ */
for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0];
i++) { i++) {
if (strcmp(console_cmdline[i].name, console->name) != 0) if (strcmp(console_cmdline[i].name, newcon->name) != 0)
continue; continue;
if (console->index >= 0 && if (newcon->index >= 0 &&
console->index != console_cmdline[i].index) newcon->index != console_cmdline[i].index)
continue; continue;
if (console->index < 0) if (newcon->index < 0)
console->index = console_cmdline[i].index; newcon->index = console_cmdline[i].index;
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
if (console_cmdline[i].brl_options) { if (console_cmdline[i].brl_options) {
console->flags |= CON_BRL; newcon->flags |= CON_BRL;
braille_register_console(console, braille_register_console(newcon,
console_cmdline[i].index, console_cmdline[i].index,
console_cmdline[i].options, console_cmdline[i].options,
console_cmdline[i].brl_options); console_cmdline[i].brl_options);
return; return;
} }
#endif #endif
if (console->setup && if (newcon->setup &&
console->setup(console, console_cmdline[i].options) != 0) newcon->setup(newcon, console_cmdline[i].options) != 0)
break; break;
console->flags |= CON_ENABLED; newcon->flags |= CON_ENABLED;
console->index = console_cmdline[i].index; newcon->index = console_cmdline[i].index;
if (i == selected_console) { if (i == selected_console) {
console->flags |= CON_CONSDEV; newcon->flags |= CON_CONSDEV;
preferred_console = selected_console; preferred_console = selected_console;
} }
break; break;
} }
if (!(console->flags & CON_ENABLED)) if (!(newcon->flags & CON_ENABLED))
return; return;
if (bootconsole && (console->flags & CON_CONSDEV)) { if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) {
printk(KERN_INFO "console handover: boot [%s%d] -> real [%s%d]\n", /* we need to iterate through twice, to make sure we print
bootconsole->name, bootconsole->index, * everything out, before we unregister the console(s)
console->name, console->index); */
unregister_console(bootconsole); printk(KERN_INFO "console handover:");
console->flags &= ~CON_PRINTBUFFER; for_each_console(bcon)
printk("boot [%s%d] ", bcon->name, bcon->index);
printk(" -> real [%s%d]\n", newcon->name, newcon->index);
for_each_console(bcon)
unregister_console(bcon);
newcon->flags &= ~CON_PRINTBUFFER;
} else { } else {
printk(KERN_INFO "console [%s%d] enabled\n", printk(KERN_INFO "%sconsole [%s%d] enabled\n",
console->name, console->index); (newcon->flags & CON_BOOT) ? "boot" : "" ,
newcon->name, newcon->index);
} }
/* /*
...@@ -1226,16 +1262,16 @@ void register_console(struct console *console) ...@@ -1226,16 +1262,16 @@ void register_console(struct console *console)
* preferred driver at the head of the list. * preferred driver at the head of the list.
*/ */
acquire_console_sem(); acquire_console_sem();
if ((console->flags & CON_CONSDEV) || console_drivers == NULL) { if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) {
console->next = console_drivers; newcon->next = console_drivers;
console_drivers = console; console_drivers = newcon;
if (console->next) if (newcon->next)
console->next->flags &= ~CON_CONSDEV; newcon->next->flags &= ~CON_CONSDEV;
} else { } else {
console->next = console_drivers->next; newcon->next = console_drivers->next;
console_drivers->next = console; console_drivers->next = newcon;
} }
if (console->flags & CON_PRINTBUFFER) { if (newcon->flags & CON_PRINTBUFFER) {
/* /*
* release_console_sem() will print out the buffered messages * release_console_sem() will print out the buffered messages
* for us. * for us.
...@@ -1287,11 +1323,13 @@ EXPORT_SYMBOL(unregister_console); ...@@ -1287,11 +1323,13 @@ EXPORT_SYMBOL(unregister_console);
static int __init disable_boot_consoles(void) static int __init disable_boot_consoles(void)
{ {
if (console_drivers != NULL) { struct console *con;
if (console_drivers->flags & CON_BOOT) {
for_each_console(con) {
if (con->flags & CON_BOOT) {
printk(KERN_INFO "turn off boot console %s%d\n", printk(KERN_INFO "turn off boot console %s%d\n",
console_drivers->name, console_drivers->index); con->name, con->index);
return unregister_console(console_drivers); return unregister_console(con);
} }
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment