Skip to contentSkip to conversation

serial_core: add pci uart early console support

PATCH Superseded Bin Gao 3 participants 5 messages May 29, 2015 – Jul 27, 2015

Subsystems (4)
lore
Share & tools
lore

Bin Gao

author
#0 lore raw

PATCH v5 1/2 serial_core: add pci uart early console support

On some Intel Atom SoCs, the legacy IO port UART(0x3F8) is not available. Instead, a 8250 compatible PCI uart can be used as early console. This patch adds pci support to the 8250 early console driver uart8250. For example, to enable pci uart(00:21.3) as early console on these platforms, append the following line to the kernel command line (assume baud rate is 115200):
earlyprintk=uart8250,pci32,0:24.2,115200n8

---
Changes in v5:
- updated Documentation/kernel-parameters.txt.
- moved earlyprintk= to patch 2/2 (requires x86 people's review).
- rolled back to simple_strto* APIs.
- seperate pci/pci32 format description.
- minor error and debug message changes.
- if/else statements in uart_parse_earlycon() were refactored to avoid logic steering locals.
Changes in v4:
- moved PCI_EARLY definition from arch/x86/Kconfig to drivers/pci/Kconfig
- made earlycon= for all archs but earlyprintk= only for x86 by changing "#ifdef #else #endif" to "#if #endif".
Changes in v3:
- introduced CONFIG_EARLY_PCI to protect pci codes in serial_core.c.
- added earlyprintk= as alia to earlycon= to keep x86 compatibility.
changes in v2:
- added the second patch (2/2) to remove existed pci early console support from arch/x86/kernel/early_printk.c.

 Documentation/kernel-parameters.txt |  15 +++++
 arch/x86/Kconfig                    |   1 +
 drivers/pci/Kconfig                 |  11 ++++
 drivers/tty/serial/serial_core.c    | 106 +++++++++++++++++++++++++++++++++++-
 4 files changed, 132 insertions(+), 1 deletion(-)
Documentation/kernel-parameters.txt +15 -0
index 61ab162..598606e 100644
@@ -969,6 +969,16 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			same format described for "console=ttyS<n>"; if
 			unspecified, the h/w is not initialized.
 
+		uart8250,pci,<bus:dev.func>[,options]
+		uart8250,pci32,<bus:dev.func>[,options]
+			Start an early, polled-mode console on the 8250/16550
+			UART at the specified PCI device (bus:dev.func).
+			The io or memory mmaped register width is either 8-bit
+			(pci) or 32-bit (pci32).
+			'options' are specified in the same format described
+			for "console=ttyS<n>"; if unspecified, the h/w is not
+			initialized.
+
 		pl011,<addr>
 			Start an early, polled-mode console on a pl011 serial
 			port at the specified address. The pl011 serial port
@@ -1009,6 +1019,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			earlyprintk=serial[,0x...[,baudrate]]
 			earlyprintk=ttySn[,baudrate]
 			earlyprintk=dbgp[debugController#]
+			earlyprintk=uart8250,pci,<bus:dev.fun>[,options]
+			earlyprintk=uart8250,pci32,<bus:dev.func>[,options]
 
 			earlyprintk is useful when the kernel crashes before
 			the normal console is initialized. It is not enabled by
@@ -1037,6 +1049,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 
 			The xen output can only be used by Xen PV guests.
 
+			The uart8250,pci and uart8250,pci32 output share the
+			same definition that is in earlycon= section.
+
 	edac_report=	[HW,EDAC] Control how to report EDAC event
 			Format: {"on" | "off" | "force"}
 			on: enable EDAC to report H/W event. May be overridden
arch/x86/Kconfig +1 -0
index 226d569..bdedd61 100644
@@ -143,6 +143,7 @@ config X86
 	select ACPI_LEGACY_TABLES_LOOKUP if ACPI
 	select X86_FEATURE_NAMES if PROC_FS
 	select SRCU
+	select PCI_EARLY if PCI
 
 config INSTRUCTION_DECODER
 	def_bool y
drivers/pci/Kconfig +11 -0
index 7a8f1c5..4f0f055 100644
@@ -114,4 +114,15 @@ config PCI_LABEL
 	def_bool y if (DMI || ACPI)
 	select NLS
 
+config PCI_EARLY
+	bool "Early PCI access"
+	depends on PCI
+	default n
+	help
+	  This option indicates that a group of APIs are available (in
+	  asm/pci-direct.h) so the kernel can access pci config registers
+	  before the PCI subsystem is initialized. Any arch that supports
+	  early pci APIs should enable this option which is required  by
+	  arch independent codes, e.g. uart8250 pci early console driver.
+
 source "drivers/pci/host/Kconfig"
drivers/tty/serial/serial_core.c +105 -1

150 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v6 1/2 serial_core: add pci uart early console support

On some Intel Atom SoCs, the legacy IO port UART(0x3F8) is not available. Instead, a 8250 compatible PCI uart can be used as early console. This patch adds pci support to the 8250 early console driver uart8250. For example, to enable pci uart(00:21.3) as early console on these platforms, append the following line to the kernel command line (assume baud rate is 115200):
earlyprintk=uart8250,pci32,0:24.2,115200n8

---
Changes in v6: None
Changes in v5:
- updated Documentation/kernel-parameters.txt.
- moved earlyprintk= to patch 2/2 (requires x86 people's review).
- rolled back to simple_strto* APIs.
- seperate pci/pci32 format description.
- minor error and debug message changes.
- if/else statements in uart_parse_earlycon() were refactored to avoid logic steering locals.
Changes in v4:
- moved PCI_EARLY definition from arch/x86/Kconfig to drivers/pci/Kconfig
- made earlycon= for all archs but earlyprintk= only for x86 by changing "#ifdef #else #endif" to "#if #endif".
Changes in v3:
- introduced CONFIG_EARLY_PCI to protect pci codes in serial_core.c.
- added earlyprintk= as alia to earlycon= to keep x86 compatibility.
changes in v2:
- added the second patch (2/2) to remove existed pci early console support from arch/x86/kernel/early_printk.c.

 Documentation/kernel-parameters.txt |  15 +++++
 arch/x86/Kconfig                    |   1 +
 drivers/pci/Kconfig                 |  11 ++++
 drivers/tty/serial/serial_core.c    | 106 +++++++++++++++++++++++++++++++++++-
 4 files changed, 132 insertions(+), 1 deletion(-)
Documentation/kernel-parameters.txt +15 -0
index 61ab162..598606e 100644
@@ -969,6 +969,16 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			same format described for "console=ttyS<n>"; if
 			unspecified, the h/w is not initialized.
 
+		uart8250,pci,<bus:dev.func>[,options]
+		uart8250,pci32,<bus:dev.func>[,options]
+			Start an early, polled-mode console on the 8250/16550
+			UART at the specified PCI device (bus:dev.func).
+			The io or memory mmaped register width is either 8-bit
+			(pci) or 32-bit (pci32).
+			'options' are specified in the same format described
+			for "console=ttyS<n>"; if unspecified, the h/w is not
+			initialized.
+
 		pl011,<addr>
 			Start an early, polled-mode console on a pl011 serial
 			port at the specified address. The pl011 serial port
@@ -1009,6 +1019,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			earlyprintk=serial[,0x...[,baudrate]]
 			earlyprintk=ttySn[,baudrate]
 			earlyprintk=dbgp[debugController#]
+			earlyprintk=uart8250,pci,<bus:dev.fun>[,options]
+			earlyprintk=uart8250,pci32,<bus:dev.func>[,options]
 
 			earlyprintk is useful when the kernel crashes before
 			the normal console is initialized. It is not enabled by
@@ -1037,6 +1049,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 
 			The xen output can only be used by Xen PV guests.
 
+			The uart8250,pci and uart8250,pci32 output share the
+			same definition that is in earlycon= section.
+
 	edac_report=	[HW,EDAC] Control how to report EDAC event
 			Format: {"on" | "off" | "force"}
 			on: enable EDAC to report H/W event. May be overridden
arch/x86/Kconfig +1 -0
index 226d569..bdedd61 100644
@@ -143,6 +143,7 @@ config X86
 	select ACPI_LEGACY_TABLES_LOOKUP if ACPI
 	select X86_FEATURE_NAMES if PROC_FS
 	select SRCU
+	select PCI_EARLY if PCI
 
 config INSTRUCTION_DECODER
 	def_bool y
drivers/pci/Kconfig +11 -0
index 7a8f1c5..4f0f055 100644
@@ -114,4 +114,15 @@ config PCI_LABEL
 	def_bool y if (DMI || ACPI)
 	select NLS
 
+config PCI_EARLY
+	bool "Early PCI access"
+	depends on PCI
+	default n
+	help
+	  This option indicates that a group of APIs are available (in
+	  asm/pci-direct.h) so the kernel can access pci config registers
+	  before the PCI subsystem is initialized. Any arch that supports
+	  early pci APIs should enable this option which is required  by
+	  arch independent codes, e.g. uart8250 pci early console driver.
+
 source "drivers/pci/host/Kconfig"
drivers/tty/serial/serial_core.c +105 -1

150 lines not on this page · raw message

Signature · 1 line
1.9.1
Reviewed-by on v6 1/2
#2 lore raw
Quoted 7 lines · Bin Gao

On some Intel Atom SoCs, the legacy IO port UART(0x3F8) is not available. Instead, a 8250 compatible PCI uart can be used as early console. This patch adds pci support to the 8250 early console driver uart8250. For example, to enable pci uart(00:21.3) as early console on these platforms, append the following line to the kernel command line (assume baud rate is 115200):
earlyprintk=uart8250,pci32,0:24.2,115200n8

#3 lore raw
In reply to Bin Gao
Quoted 92 lines · Bin Gao

On some Intel Atom SoCs, the legacy IO port UART(0x3F8) is not available. Instead, a 8250 compatible PCI uart can be used as early console. This patch adds pci support to the 8250 early console driver uart8250. For example, to enable pci uart(00:21.3) as early console on these platforms, append the following line to the kernel command line (assume baud rate is 115200):
earlyprintk=uart8250,pci32,0:24.2,115200n8

---
Changes in v6: None
Changes in v5:
- updated Documentation/kernel-parameters.txt.
- moved earlyprintk= to patch 2/2 (requires x86 people's review).
- rolled back to simple_strto* APIs.
- seperate pci/pci32 format description.
- minor error and debug message changes.
- if/else statements in uart_parse_earlycon() were refactored to avoid logic steering locals.
Changes in v4:
- moved PCI_EARLY definition from arch/x86/Kconfig to drivers/pci/Kconfig
- made earlycon= for all archs but earlyprintk= only for x86 by changing "#ifdef #else #endif" to "#if #endif".
Changes in v3:
- introduced CONFIG_EARLY_PCI to protect pci codes in serial_core.c.
- added earlyprintk= as alia to earlycon= to keep x86 compatibility.
changes in v2:
- added the second patch (2/2) to remove existed pci early console support from arch/x86/kernel/early_printk.c.

 Documentation/kernel-parameters.txt |  15 +++++
 arch/x86/Kconfig                    |   1 +
 drivers/pci/Kconfig                 |  11 ++++
 drivers/tty/serial/serial_core.c    | 106 +++++++++++++++++++++++++++++++++++-
 4 files changed, 132 insertions(+), 1 deletion(-)
Documentation/kernel-parameters.txt +15 -0
index 61ab162..598606e 100644
@@ -969,6 +969,16 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			same format described for "console=ttyS<n>"; if
 			unspecified, the h/w is not initialized.
 
+		uart8250,pci,<bus:dev.func>[,options]
+		uart8250,pci32,<bus:dev.func>[,options]
+			Start an early, polled-mode console on the 8250/16550
+			UART at the specified PCI device (bus:dev.func).
+			The io or memory mmaped register width is either 8-bit
+			(pci) or 32-bit (pci32).
+			'options' are specified in the same format described
+			for "console=ttyS<n>"; if unspecified, the h/w is not
+			initialized.
+
 		pl011,<addr>
 			Start an early, polled-mode console on a pl011 serial
 			port at the specified address. The pl011 serial port
@@ -1009,6 +1019,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			earlyprintk=serial[,0x...[,baudrate]]
 			earlyprintk=ttySn[,baudrate]
 			earlyprintk=dbgp[debugController#]
+			earlyprintk=uart8250,pci,<bus:dev.fun>[,options]
+			earlyprintk=uart8250,pci32,<bus:dev.func>[,options]
 
 			earlyprintk is useful when the kernel crashes before
 			the normal console is initialized. It is not enabled by
@@ -1037,6 +1049,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 
 			The xen output can only be used by Xen PV guests.
 
+			The uart8250,pci and uart8250,pci32 output share the
+			same definition that is in earlycon= section.
+
 	edac_report=	[HW,EDAC] Control how to report EDAC event
 			Format: {"on" | "off" | "force"}
 			on: enable EDAC to report H/W event. May be overridden
arch/x86/Kconfig +1 -0
index 226d569..bdedd61 100644
@@ -143,6 +143,7 @@ config X86
 	select ACPI_LEGACY_TABLES_LOOKUP if ACPI
 	select X86_FEATURE_NAMES if PROC_FS
 	select SRCU
+	select PCI_EARLY if PCI
 
 config INSTRUCTION_DECODER
 	def_bool y
drivers/pci/Kconfig +0 -0
index 7a8f1c5..4f0f055 100644

drivers/pci/Kconfig config PCI_LABEL · line 120

Quoted 7 lines
drivers/pci/Kconfig +4 -0
@@ -114,4 +114,15 @@ config PCI_LABEL
 	def_bool y if (DMI || ACPI)
 	select NLS
 
+config PCI_EARLY
+	bool "Early PCI access"
+	depends on PCI
+	default n

Default is always 'n' so this isn't needed here.

Quoted 14 lines
drivers/pci/Kconfig +7 -0
+	help
+	  This option indicates that a group of APIs are available (in
+	  asm/pci-direct.h) so the kernel can access pci config registers
+	  before the PCI subsystem is initialized. Any arch that supports
+	  early pci APIs should enable this option which is required  by
+	  arch independent codes, e.g. uart8250 pci early console driver.
+
 source "drivers/pci/host/Kconfig"
drivers/tty/serial/serial_core.c +0 -0
index 0b7bb12..5b21999 100644
@@ -34,10 +34,15 @@
 #include <linux/serial_core.h>

drivers/tty/serial/serial_core.c line 44

Quoted 10 lines
drivers/tty/serial/serial_core.c +4 -0
 #include <linux/delay.h>
 #include <linux/mutex.h>
+#include <linux/pci_regs.h>
 
 #include <asm/irq.h>
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_PCI_EARLY
+#include <asm/pci-direct.h>
+#endif

You shouldn't need an #ifdef here, the .h file should handle it. Why doesn't pci.h always include this if it is present?

thanks,

greg k-h

author
#4 lore raw
Quoted 6 lines · Greg Kroah-Hartman

drivers/pci/Kconfig config PCI_LABEL · line 120

Quoted 4 lines
drivers/pci/Kconfig +4 -0
+config PCI_EARLY
+	bool "Early PCI access"
+	depends on PCI
+	default n

Default is always 'n' so this isn't needed here.

Will fix this.

Quoted 13 lines
Quoted 13 lines
drivers/tty/serial/serial_core.c +1 -0
index 0b7bb12..5b21999 100644
@@ -34,10 +34,15 @@
 #include <linux/serial_core.h>
 #include <linux/delay.h>
 #include <linux/mutex.h>
+#include <linux/pci_regs.h>
 
 #include <asm/irq.h>
 #include <asm/uaccess.h>
 
Quoted 6 lines

drivers/tty/serial/serial_core.c line 44

Quoted 3 lines
drivers/tty/serial/serial_core.c +3 -0
+#ifdef CONFIG_PCI_EARLY
+#include <asm/pci-direct.h>
+#endif

You shouldn't need an #ifdef here, the .h file should handle it. Why doesn't pci.h always include this if it is present?

Only x86 has asm/pci-direct.h. Compiling on any other archs will fail if we don't put CONFIG_PCI_EARLY here. That's way I added a new config option CONFIG_PCI_EARLY to drivers/pci/Kconfig and let an arch to select it. Do you want me to move "#include <asm/pci-direct.h>" to linux/pci.h?

Quoted 4 lines

thanks,

greg k-h