Commit d12013c8 authored by Petr Mladek's avatar Petr Mladek

Merge branch 'console-registration-cleanup' into for-linus

parents 73d86812 5e8ba485
...@@ -280,7 +280,6 @@ static struct console *exclusive_console; ...@@ -280,7 +280,6 @@ static struct console *exclusive_console;
static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
static int preferred_console = -1; static int preferred_console = -1;
static bool has_preferred_console;
int console_set_on_cmdline; int console_set_on_cmdline;
EXPORT_SYMBOL(console_set_on_cmdline); EXPORT_SYMBOL(console_set_on_cmdline);
...@@ -2861,7 +2860,8 @@ early_param("keep_bootcon", keep_bootcon_setup); ...@@ -2861,7 +2860,8 @@ early_param("keep_bootcon", keep_bootcon_setup);
* Care need to be taken with consoles that are statically * Care need to be taken with consoles that are statically
* enabled such as netconsole * enabled such as netconsole
*/ */
static int try_enable_new_console(struct console *newcon, bool user_specified) static int try_enable_preferred_console(struct console *newcon,
bool user_specified)
{ {
struct console_cmdline *c; struct console_cmdline *c;
int i, err; int i, err;
...@@ -2891,10 +2891,8 @@ static int try_enable_new_console(struct console *newcon, bool user_specified) ...@@ -2891,10 +2891,8 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
return err; return err;
} }
newcon->flags |= CON_ENABLED; newcon->flags |= CON_ENABLED;
if (i == preferred_console) { if (i == preferred_console)
newcon->flags |= CON_CONSDEV; newcon->flags |= CON_CONSDEV;
has_preferred_console = true;
}
return 0; return 0;
} }
...@@ -2909,6 +2907,21 @@ static int try_enable_new_console(struct console *newcon, bool user_specified) ...@@ -2909,6 +2907,21 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
return -ENOENT; return -ENOENT;
} }
/* Try to enable the console unconditionally */
static void try_enable_default_console(struct console *newcon)
{
if (newcon->index < 0)
newcon->index = 0;
if (newcon->setup && newcon->setup(newcon, NULL) != 0)
return;
newcon->flags |= CON_ENABLED;
if (newcon->device)
newcon->flags |= CON_CONSDEV;
}
/* /*
* The console driver calls this routine during kernel initialization * The console driver calls this routine during kernel initialization
* to register the console printing procedure with printk() and to * to register the console printing procedure with printk() and to
...@@ -2930,59 +2943,56 @@ static int try_enable_new_console(struct console *newcon, bool user_specified) ...@@ -2930,59 +2943,56 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
*/ */
void register_console(struct console *newcon) void register_console(struct console *newcon)
{ {
struct console *bcon = NULL; struct console *con;
bool bootcon_enabled = false;
bool realcon_enabled = false;
int err; int err;
for_each_console(bcon) { for_each_console(con) {
if (WARN(bcon == newcon, "console '%s%d' already registered\n", if (WARN(con == newcon, "console '%s%d' already registered\n",
bcon->name, bcon->index)) con->name, con->index))
return; return;
} }
/* for_each_console(con) {
* before we register a new CON_BOOT console, make sure we don't if (con->flags & CON_BOOT)
* already have a valid console bootcon_enabled = true;
*/ else
if (newcon->flags & CON_BOOT) { realcon_enabled = true;
for_each_console(bcon) {
if (!(bcon->flags & CON_BOOT)) {
pr_info("Too late to register bootconsole %s%d\n",
newcon->name, newcon->index);
return;
}
}
} }
if (console_drivers && console_drivers->flags & CON_BOOT) /* Do not register boot consoles when there already is a real one. */
bcon = console_drivers; if (newcon->flags & CON_BOOT && realcon_enabled) {
pr_info("Too late to register bootconsole %s%d\n",
if (!has_preferred_console || bcon || !console_drivers) newcon->name, newcon->index);
has_preferred_console = preferred_console >= 0; return;
}
/* /*
* See if we want to use this console driver. If we * See if we want to enable this console driver by default.
* didn't select a console we take the first one *
* that registers here. * Nope when a console is preferred by the command line, device
* tree, or SPCR.
*
* The first real console with tty binding (driver) wins. More
* consoles might get enabled before the right one is found.
*
* Note that a console with tty binding will have CON_CONSDEV
* flag set and will be first in the list.
*/ */
if (!has_preferred_console) { if (preferred_console < 0) {
if (newcon->index < 0) if (!console_drivers || !console_drivers->device ||
newcon->index = 0; console_drivers->flags & CON_BOOT) {
if (newcon->setup == NULL || try_enable_default_console(newcon);
newcon->setup(newcon, NULL) == 0) {
newcon->flags |= CON_ENABLED;
if (newcon->device) {
newcon->flags |= CON_CONSDEV;
has_preferred_console = true;
}
} }
} }
/* See if this console matches one we selected on the command line */ /* See if this console matches one we selected on the command line */
err = try_enable_new_console(newcon, true); err = try_enable_preferred_console(newcon, true);
/* If not, try to match against the platform default(s) */ /* If not, try to match against the platform default(s) */
if (err == -ENOENT) if (err == -ENOENT)
err = try_enable_new_console(newcon, false); err = try_enable_preferred_console(newcon, false);
/* printk() messages are not printed to the Braille console. */ /* printk() messages are not printed to the Braille console. */
if (err || newcon->flags & CON_BRL) if (err || newcon->flags & CON_BRL)
...@@ -2994,8 +3004,10 @@ void register_console(struct console *newcon) ...@@ -2994,8 +3004,10 @@ void register_console(struct console *newcon)
* the real console are the same physical device, it's annoying to * the real console are the same physical device, it's annoying to
* see the beginning boot messages twice * see the beginning boot messages twice
*/ */
if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) if (bootcon_enabled &&
((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) {
newcon->flags &= ~CON_PRINTBUFFER; newcon->flags &= ~CON_PRINTBUFFER;
}
/* /*
* Put this console in the list - keep the * Put this console in the list - keep the
...@@ -3051,15 +3063,15 @@ void register_console(struct console *newcon) ...@@ -3051,15 +3063,15 @@ void register_console(struct console *newcon)
pr_info("%sconsole [%s%d] enabled\n", pr_info("%sconsole [%s%d] enabled\n",
(newcon->flags & CON_BOOT) ? "boot" : "" , (newcon->flags & CON_BOOT) ? "boot" : "" ,
newcon->name, newcon->index); newcon->name, newcon->index);
if (bcon && if (bootcon_enabled &&
((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
!keep_bootcon) { !keep_bootcon) {
/* We need to iterate through all boot consoles, to make /* We need to iterate through all boot consoles, to make
* sure we print everything out, before we unregister them. * sure we print everything out, before we unregister them.
*/ */
for_each_console(bcon) for_each_console(con)
if (bcon->flags & CON_BOOT) if (con->flags & CON_BOOT)
unregister_console(bcon); unregister_console(con);
} }
} }
EXPORT_SYMBOL(register_console); EXPORT_SYMBOL(register_console);
......
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