Skip to contentSkip to conversation

console: Add console=spcr option

PATCH Superseded Prarit Bhargava 3 participants 4 messages Aug 29, 2018 – Aug 30, 2018

Subsystems (5)
Documentation x86 ACPI Printk +1 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 console: Add console=spcr option

ACPI may contain an SPCR table that defines a default system console. On ARM if the table is present then the SPCR console is enabled by default. On x86 the SPCR console is used if 'earlycon' (no parameters) is specified as a kernel parameter and is used only as the early console. To use the SPCR data as a console a user must boot with 'earlycon', grep logs & specify a console= kernel parameter, and then reboot again.

Add 'console=spcr' that enables a firmware or hardware console, and on x86 enable the SPCR console if 'console=spcr' is specified.

Tested on systems with and without an ACPI SPCR. The following kernel parameters were also tested:

console=ttyS0,115200    		works
earlycon                		works (early console only)
console=spcr            		works (full console as expected)

no console or earlycon arguments works (no output as expected)

v2: Fix prototype.
v3: Change parameter to "spcr" and add error message to spcr init call.

Cc Mark Salter <[email protected]>
Cc Al Stone <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Petr Mladek <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Kees Cook <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 Documentation/admin-guide/kernel-parameters.txt |  1 +
 arch/x86/kernel/acpi/boot.c                     |  9 +++++++++
 include/linux/console.h                         |  1 +
 kernel/printk/printk.c                          | 10 ++++++++++
 4 files changed, 21 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +1 -0
index 9871e649ffef..f51a32cda90c 100644
@@ -635,6 +635,7 @@
 
 		hvc<n>	Use the hypervisor console device <n>. This is for
 			both Xen and PowerPC hypervisors.
+		spcr	[X86] Enable ACPI SPCR console
 
 		If the device connected to the port is not a TTY but a braille
 		device, prepend "brl," before the device type, for instance
arch/x86/kernel/acpi/boot.c +9 -0
index 3b20607d581b..3fed5e9a6b82 100644
@@ -1771,3 +1771,12 @@ void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
 	e820__range_add(addr, size, E820_TYPE_ACPI);
 	e820__update_table_print();
 }
+
+void __init arch_console_setup(void)
+{
+	int ret;
+
+	ret = acpi_parse_spcr(false, true);
+	if (ret)
+		pr_err(PREFIX "ERROR: SPCR console is not enabled (%d)\n", ret);
+}
include/linux/console.h +1 -0
index ec9bdb3d7bab..562b825d911c 100644
@@ -183,6 +183,7 @@ extern int is_console_locked(void);
 extern int braille_register_console(struct console *, int index,
 		char *console_options, char *braille_options);
 extern int braille_unregister_console(struct console *);
+void arch_console_setup(void);
 #ifdef CONFIG_TTY
 extern void console_sysfs_notify(void);
 #else
kernel/printk/printk.c +10 -0
index 924e37fb1620..35859606e714 100644
@@ -2097,6 +2097,11 @@ static int __init console_msg_format_setup(char *str)
 }
 __setup("console_msg_format=", console_msg_format_setup);
 
+void __init __weak arch_console_setup(void)
+{
+	return;
+}
+
 /*
  * Set up a console.  Called via do_early_param() in init/main.c
  * for each "console=" parameter in the boot command line.
@@ -2107,6 +2112,11 @@ static int __init console_setup(char *str)
 	char *s, *options, *brl_options = NULL;
 	int idx;
 
+	if (!strcmp(str, "spcr")) {
+		arch_console_setup();
+		return 1;
+	}
+
 	if (_braille_console_setup(&str, &brl_options))
 		return 1;
 
Signature · 1 line
2.14.4
#1 lore raw

PATCH v4 1/1 console: Add console=spcr option

ACPI may contain an SPCR table that defines a default system console. On ARM if the table is present then the SPCR console is enabled by default. On x86 the SPCR console is used if 'earlycon' (no parameters) is specified as a kernel parameter and is used only as the early console. To use the SPCR data as a console a user must boot with 'earlycon', grep logs & specify a console= kernel parameter, and then reboot again.

Add 'console=spcr' that enables a firmware or hardware console, and on x86 enable the SPCR console if 'console=spcr' is specified.

Tested on systems with and without an ACPI SPCR. The following kernel parameters were also tested:

console=ttyS0,115200    		works
earlycon                		works (early console only)
console=spcr            		works (full console as expected)

no console or earlycon arguments works (no output as expected)

v2: Fix prototype.
v3: Change parameter to "spcr" and add error message to spcr init call.
v4: move spcr to x86 (really make it arch specific)

Cc Petr Mladek <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
---
 Documentation/admin-guide/kernel-parameters.txt |  1 +
 arch/x86/kernel/acpi/boot.c                     | 14 ++++++++++++++
 include/linux/console.h                         |  1 +
 kernel/printk/printk.c                          |  8 ++++++++
 4 files changed, 24 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +1 -0
index 9871e649ffef..f51a32cda90c 100644
@@ -635,6 +635,7 @@
 
 		hvc<n>	Use the hypervisor console device <n>. This is for
 			both Xen and PowerPC hypervisors.
+		spcr	[X86] Enable ACPI SPCR console
 
 		If the device connected to the port is not a TTY but a braille
 		device, prepend "brl," before the device type, for instance
arch/x86/kernel/acpi/boot.c +14 -0
index 3b20607d581b..a43a34734f02 100644
@@ -1771,3 +1771,17 @@ void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
 	e820__range_add(addr, size, E820_TYPE_ACPI);
 	e820__update_table_print();
 }
+
+int __init arch_console_setup(char *str)
+{
+	int ret;
+
+	if (strcmp("spcr", str))
+		return 1;
+
+	ret = acpi_parse_spcr(false, true);
+	if (ret)
+		pr_err(PREFIX "ERROR: SPCR console is not enabled (%d)\n", ret);
+
+	return 0;
+}
include/linux/console.h +1 -0
index ec9bdb3d7bab..9bb6a79823a2 100644
@@ -183,6 +183,7 @@ struct console {
 extern int braille_register_console(struct console *, int index,
 		char *console_options, char *braille_options);
 extern int braille_unregister_console(struct console *);
+int arch_console_setup(char *str);
 #ifdef CONFIG_TTY
 extern void console_sysfs_notify(void);
 #else
kernel/printk/printk.c +8 -0
index 924e37fb1620..ceee021a37ec 100644
@@ -2097,6 +2097,11 @@ static int __init console_msg_format_setup(char *str)
 }
 __setup("console_msg_format=", console_msg_format_setup);
 
+int __init __weak arch_console_setup(char *str)
+{
+	return 1;
+}
+
 /*
  * Set up a console.  Called via do_early_param() in init/main.c
  * for each "console=" parameter in the boot command line.
@@ -2107,6 +2112,9 @@ static int __init console_setup(char *str)
 	char *s, *options, *brl_options = NULL;
 	int idx;
 
+	if (!arch_console_setup(str))
+		return 1;
+
 	if (_braille_console_setup(&str, &brl_options))
 		return 1;
 
Signature · 1 line
1.8.3.1
maintainer
#2 lore raw
Quoted 37 lines · Prarit Bhargava

ACPI may contain an SPCR table that defines a default system console. On ARM if the table is present then the SPCR console is enabled by default. On x86 the SPCR console is used if 'earlycon' (no parameters) is specified as a kernel parameter and is used only as the early console. To use the SPCR data as a console a user must boot with 'earlycon', grep logs & specify a console= kernel parameter, and then reboot again.

Add 'console=spcr' that enables a firmware or hardware console, and on x86 enable the SPCR console if 'console=spcr' is specified.

arch/x86/kernel/acpi/boot.c +14 -0
index 3b20607d581b..a43a34734f02 100644
@@ -1771,3 +1771,17 @@ void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
 	e820__range_add(addr, size, E820_TYPE_ACPI);
 	e820__update_table_print();
 }
+
+int __init arch_console_setup(char *str)
+{
+	int ret;
+
+	if (strcmp("spcr", str))
+		return 1;
+
+	ret = acpi_parse_spcr(false, true);
+	if (ret)
+		pr_err(PREFIX "ERROR: SPCR console is not enabled (%d)\n", ret);
+
+	return 0;
+}
kernel/printk/printk.c +0 -0
index 924e37fb1620..ceee021a37ec 100644

kernel/printk/printk.c static int __init console_setup(char *str) · line 2119

Quoted 8 lines
kernel/printk/printk.c +3 -0
@@ -2107,6 +2112,9 @@ static int __init console_setup(char *str)
 	char *s, *options, *brl_options = NULL;
 	int idx;
 
+	if (!arch_console_setup(str))
+		return 1;
+
 	if (_braille_console_setup(&str, &brl_options))
 		return 1;

Sigh, I am still a bit confused by the error handling. Especially I am not sure why console_setup() always returns 1.

It looks like it means an error when called from do_early_param(). But it means that the option was proceed when called from obsolete_checksetup(). Do I get this correctly, please?

If this is true, we should change the logic in arch_console_setup(). It should return 1 when "spcr" is handled and it should return 0 otherwise. Also it should be commented.

It looks like a historic mess. This is why I do not ask you to do any bigger clean up. But the new patch should not make it even more confusing by an inverted 0/1 logic.

Best Regards,
Petr

#3 lore raw
In reply to Prarit Bhargava

arch/x86/kernel/acpi/boot.c void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size) · line 1782

Quoted 9 lines · Prarit Bhargava
arch/x86/kernel/acpi/boot.c +9 -0
+
+void __init arch_console_setup(void)
+{
+	int ret;
+
+	ret = acpi_parse_spcr(false, true);
+	if (ret)
+		pr_err(PREFIX "ERROR: SPCR console is not enabled (%d)\n", ret);
+}

Why does this require yet another arch/weak function?

kernel/printk/printk.c static int __init console_setup(char *str) · line 2117

Quoted 10 lines

/*
* Set up a console. Called via do_early_param() in init/main.c
* for each "console=" parameter in the boot command line.

kernel/printk/printk.c +3 -0
@@ -2107,6 +2112,11 @@ static int __init console_setup(char *str)
 	char *s, *options, *brl_options = NULL;
 	int idx;
 
+	if (!strcmp(str, "spcr")) {
+		arch_console_setup();
+		return 1;

And this gets added to everything and the world whether it's needed/supported or not.

Why can't we simply register the SPCR console as we do with any other console when it is detected?

If we can't for some real good reason then there is no need to invoke acpi_parse_spcr() twice. We simply can store the fact that it got selected and use that information in acpi_boot_init().

Thanks,

tglx