Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 May 2019 22:22:40 +0000 (UTC)
From:      Colin Percival <cperciva@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r348342 - in stable/12/sys: conf dev/uart
Message-ID:  <201905282222.x4SMMeDF031790@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cperciva
Date: Tue May 28 22:22:40 2019
New Revision: 348342
URL: https://svnweb.freebsd.org/changeset/base/348342

Log:
  MFC r345405,345406,346228,346657,348195,348198: UART SPCR fixes.
  
  r345405: Obey SPCR AccessWidth parameter.
  r345406: Initialize uart_bus_space_mem on arm64.
  r346228: Add quirk to ignore AccessWidth on PL011 UART.
  r346657: Handle SPCR BaudRate = 0.
  r348195: Extract arm64 SPCR code and make it MI; use on x86 too.
  r348198: Fix for r348195.
  
  This unbreaks the console on EC2 a1.* and *.metal instances.
  
  Sponsored by:	https://www.patreon.com/cperciva

Added:
  stable/12/sys/dev/uart/uart_cpu_acpi.c
     - copied, changed from r348195, head/sys/dev/uart/uart_cpu_acpi.c
Modified:
  stable/12/sys/conf/files
  stable/12/sys/dev/uart/uart_bus.h
  stable/12/sys/dev/uart/uart_cpu_acpi.h
  stable/12/sys/dev/uart/uart_cpu_arm64.c
  stable/12/sys/dev/uart/uart_cpu_x86.c
  stable/12/sys/dev/uart/uart_dev_pl011.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/conf/files
==============================================================================
--- stable/12/sys/conf/files	Tue May 28 21:57:01 2019	(r348341)
+++ stable/12/sys/conf/files	Tue May 28 22:22:40 2019	(r348342)
@@ -3251,6 +3251,7 @@ dev/uart/uart_bus_pci.c		optional uart pci
 dev/uart/uart_bus_puc.c		optional uart puc
 dev/uart/uart_bus_scc.c		optional uart scc
 dev/uart/uart_core.c		optional uart
+dev/uart/uart_cpu_acpi.c	optional uart acpi
 dev/uart/uart_dbg.c		optional uart gdb
 dev/uart/uart_dev_msm.c		optional uart uart_msm fdt
 dev/uart/uart_dev_mvebu.c	optional uart uart_mvebu

Modified: stable/12/sys/dev/uart/uart_bus.h
==============================================================================
--- stable/12/sys/dev/uart/uart_bus.h	Tue May 28 21:57:01 2019	(r348341)
+++ stable/12/sys/dev/uart/uart_bus.h	Tue May 28 22:22:40 2019	(r348342)
@@ -57,7 +57,8 @@
 #define	UART_IOCTL_BAUD		4
 
 /* UART quirk flags */
-#define	UART_F_BUSY_DETECT	0x1
+#define	UART_F_BUSY_DETECT		0x1
+#define	UART_F_IGNORE_SPCR_REGSHFT	0x2
 
 /*
  * UART class & instance (=softc)

Copied and modified: stable/12/sys/dev/uart/uart_cpu_acpi.c (from r348195, head/sys/dev/uart/uart_cpu_acpi.c)
==============================================================================
--- head/sys/dev/uart/uart_cpu_acpi.c	Thu May 23 19:55:53 2019	(r348195, copy source)
+++ stable/12/sys/dev/uart/uart_cpu_acpi.c	Tue May 28 22:22:40 2019	(r348342)
@@ -45,9 +45,6 @@ __FBSDID("$FreeBSD$");
 #include <contrib/dev/acpica/include/accommon.h>
 #include <contrib/dev/acpica/include/actables.h>
 
-extern bus_space_tag_t uart_bus_space_io;
-extern bus_space_tag_t uart_bus_space_mem;
-
 static struct acpi_uart_compat_data *
 uart_cpu_acpi_scan(uint8_t interface_type)
 {

Modified: stable/12/sys/dev/uart/uart_cpu_acpi.h
==============================================================================
--- stable/12/sys/dev/uart/uart_cpu_acpi.h	Tue May 28 21:57:01 2019	(r348341)
+++ stable/12/sys/dev/uart/uart_cpu_acpi.h	Tue May 28 22:22:40 2019	(r348342)
@@ -66,4 +66,7 @@ SET_DECLARE(uart_acpi_class_set, struct acpi_uart_comp
 #define UART_ACPI_CLASS(data)				\
 	DATA_SET(uart_acpi_class_set, data)
 
+/* Try to initialize UART device from SPCR data. */
+int uart_cpu_acpi_spcr(int devtype, struct uart_devinfo *di);
+
 #endif /* _DEV_UART_CPU_ACPI_H_ */

Modified: stable/12/sys/dev/uart/uart_cpu_arm64.c
==============================================================================
--- stable/12/sys/dev/uart/uart_cpu_arm64.c	Tue May 28 21:57:01 2019	(r348341)
+++ stable/12/sys/dev/uart/uart_cpu_arm64.c	Tue May 28 22:22:40 2019	(r348342)
@@ -65,8 +65,9 @@ __FBSDID("$FreeBSD$");
 /*
  * UART console routines.
  */
+extern struct bus_space memmap_bus;
 bus_space_tag_t uart_bus_space_io;
-bus_space_tag_t uart_bus_space_mem;
+bus_space_tag_t uart_bus_space_mem = &memmap_bus;
 
 int
 uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
@@ -79,85 +80,6 @@ uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b
 	return ((pmap_kextract(b1->bsh) == pmap_kextract(b2->bsh)) ? 1 : 0);
 }
 
-#ifdef DEV_ACPI
-static struct acpi_uart_compat_data *
-uart_cpu_acpi_scan(uint8_t interface_type)
-{
-	struct acpi_uart_compat_data **cd, *curcd;
-	int i;
-
-	SET_FOREACH(cd, uart_acpi_class_and_device_set) {
-		curcd = *cd;
-		for (i = 0; curcd[i].cd_hid != NULL; i++) {
-			if (curcd[i].cd_port_subtype == interface_type)
-				return (&curcd[i]);
-		}
-	}
-
-	SET_FOREACH(cd, uart_acpi_class_set) {
-		curcd = *cd;
-		for (i = 0; curcd[i].cd_hid != NULL; i++) {
-			if (curcd[i].cd_port_subtype == interface_type)
-				return (&curcd[i]);
-		}
-	}
-
-	return (NULL);
-}
-
-static int
-uart_cpu_acpi_probe(struct uart_class **classp, bus_space_tag_t *bst,
-    bus_space_handle_t *bsh, int *baud, u_int *rclk, u_int *shiftp,
-    u_int *iowidthp)
-{
-	struct acpi_uart_compat_data *cd;
-	ACPI_TABLE_SPCR *spcr;
-	vm_paddr_t spcr_physaddr;
-	int err;
-
-	err = ENXIO;
-	spcr_physaddr = acpi_find_table(ACPI_SIG_SPCR);
-	if (spcr_physaddr == 0)
-		return (ENXIO);
-
-	spcr = acpi_map_table(spcr_physaddr, ACPI_SIG_SPCR);
-
-	cd = uart_cpu_acpi_scan(spcr->InterfaceType);
-	if (cd == NULL)
-		goto out;
-
-	switch(spcr->BaudRate) {
-	case 3:
-		*baud = 9600;
-		break;
-	case 4:
-		*baud = 19200;
-		break;
-	case 6:
-		*baud = 57600;
-		break;
-	case 7:
-		*baud = 115200;
-		break;
-	default:
-		goto out;
-	}
-
-	err = acpi_map_addr(&spcr->SerialPort, bst, bsh, PAGE_SIZE);
-	if (err != 0)
-		goto out;
-
-	*classp = cd->cd_class;
-	*rclk = 0;
-	*shiftp = 2;
-	*iowidthp = spcr->SerialPort.BitWidth / 8;
-
-out:
-	acpi_unmap_table(spcr);
-	return (err);
-}
-#endif
-
 int
 uart_cpu_getdev(int devtype, struct uart_devinfo *di)
 {
@@ -173,14 +95,16 @@ uart_cpu_getdev(int devtype, struct uart_devinfo *di)
 	if (err == 0)
 		return (0);
 
+#ifdef DEV_ACPI
+	/* Check if SPCR can tell us what console to use. */
+	if (uart_cpu_acpi_spcr(devtype, di) == 0)
+		return (0);
+#endif
+
 	if (devtype != UART_DEV_CONSOLE)
 		return (ENXIO);
 
 	err = ENXIO;
-#ifdef DEV_ACPI
-	err = uart_cpu_acpi_probe(&class, &bst, &bsh, &br, &rclk, &shift,
-	    &iowidth);
-#endif
 #ifdef FDT
 	if (err != 0) {
 		err = uart_cpu_fdt_probe(&class, &bst, &bsh, &br, &rclk,

Modified: stable/12/sys/dev/uart/uart_cpu_x86.c
==============================================================================
--- stable/12/sys/dev/uart/uart_cpu_x86.c	Tue May 28 21:57:01 2019	(r348341)
+++ stable/12/sys/dev/uart/uart_cpu_x86.c	Tue May 28 22:22:40 2019	(r348342)
@@ -26,6 +26,8 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "opt_acpi.h"
+
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -37,6 +39,7 @@ __FBSDID("$FreeBSD$");
 
 #include <dev/uart/uart.h>
 #include <dev/uart/uart_cpu.h>
+#include <dev/uart/uart_cpu_acpi.h>
 
 bus_space_tag_t uart_bus_space_io = X86_BUS_SPACE_IO;
 bus_space_tag_t uart_bus_space_mem = X86_BUS_SPACE_MEM;
@@ -61,6 +64,12 @@ uart_cpu_getdev(int devtype, struct uart_devinfo *di)
 	/* Check the environment. */
 	if (uart_getenv(devtype, di, class) == 0)
 		return (0);
+
+#ifdef DEV_ACPI
+	/* Check if SPCR can tell us what console to use. */
+	if (uart_cpu_acpi_spcr(devtype, di) == 0)
+		return (0);
+#endif
 
 	/*
 	 * Scan the hints. We only try units 0 to 3 (inclusive). This

Modified: stable/12/sys/dev/uart/uart_dev_pl011.c
==============================================================================
--- stable/12/sys/dev/uart/uart_dev_pl011.c	Tue May 28 21:57:01 2019	(r348341)
+++ stable/12/sys/dev/uart/uart_dev_pl011.c	Tue May 28 22:22:40 2019	(r348342)
@@ -342,8 +342,9 @@ UART_FDT_CLASS_AND_DEVICE(fdt_compat_data);
 
 #ifdef DEV_ACPI
 static struct acpi_uart_compat_data acpi_compat_data[] = {
-	{"ARMH0011", &uart_pl011_class, ACPI_DBG2_ARM_PL011, 2, 0, 0, 0, "uart plo11"},
-	{"ARMH0011", &uart_pl011_class, ACPI_DBG2_ARM_SBSA_GENERIC, 2, 0, 0, 0, "uart plo11"},
+	{"ARMH0011", &uart_pl011_class, ACPI_DBG2_ARM_PL011, 2, 0, 0, UART_F_IGNORE_SPCR_REGSHFT, "uart pl011"},
+	{"ARMH0011", &uart_pl011_class, ACPI_DBG2_ARM_SBSA_GENERIC, 2, 0, 0, UART_F_IGNORE_SPCR_REGSHFT, "uart pl011"},
+	{"ARMH0011", &uart_pl011_class, ACPI_DBG2_ARM_SBSA_32BIT, 2, 0, 0, UART_F_IGNORE_SPCR_REGSHFT, "uart pl011"},
 	{NULL, NULL, 0, 0, 0, 0, 0, NULL},
 };
 UART_ACPI_CLASS_AND_DEVICE(acpi_compat_data);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905282222.x4SMMeDF031790>