git: 473c0b44ae8c - main - uart: Split out initilisation of the acpi devinfo

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Mon, 18 Mar 2024 16:37:55 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=473c0b44ae8c51b2aebc51887714b2ed14de50bf

commit 473c0b44ae8c51b2aebc51887714b2ed14de50bf
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2024-03-12 18:06:18 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2024-03-18 16:20:52 +0000

    uart: Split out initilisation of the acpi devinfo
    
    Split out the common parts of building the uart devinfo from ACPI
    tables from the SPCR parser. This will be used when we support the DBG2
    table to find the debug uart to be used by the kernel gdb stub.
    
    Reviewed by:    imp
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D44357
---
 sys/dev/uart/uart_cpu_acpi.c | 86 +++++++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 37 deletions(-)

diff --git a/sys/dev/uart/uart_cpu_acpi.c b/sys/dev/uart/uart_cpu_acpi.c
index 9bac5a0df170..09f69e951e81 100644
--- a/sys/dev/uart/uart_cpu_acpi.c
+++ b/sys/dev/uart/uart_cpu_acpi.c
@@ -69,35 +69,10 @@ uart_cpu_acpi_scan(uint8_t interface_type)
 	return (NULL);
 }
 
-int
-uart_cpu_acpi_spcr(int devtype, struct uart_devinfo *di)
+static int
+uart_cpu_acpi_init_devinfo(struct uart_devinfo *di, struct uart_class *class,
+    ACPI_GENERIC_ADDRESS *addr)
 {
-	vm_paddr_t spcr_physaddr;
-	ACPI_TABLE_SPCR *spcr;
-	struct acpi_uart_compat_data *cd;
-	struct uart_class *class;
-	int error = ENXIO;
-
-	/* SPCR only tells us about consoles. */
-	if (devtype != UART_DEV_CONSOLE)
-		return (error);
-
-	/* Look for the SPCR table. */
-	spcr_physaddr = acpi_find_table(ACPI_SIG_SPCR);
-	if (spcr_physaddr == 0)
-		return (error);
-	spcr = acpi_map_table(spcr_physaddr, ACPI_SIG_SPCR);
-	if (spcr == NULL) {
-		printf("Unable to map the SPCR table!\n");
-		return (error);
-	}
-
-	/* Search for information about this SPCR interface type. */
-	cd = uart_cpu_acpi_scan(spcr->InterfaceType);
-	if (cd == NULL)
-		goto out;
-	class = cd->cd_class;
-
 	/* Fill in some fixed details. */
 	di->bas.chan = 0;
 	di->bas.rclk = 0;
@@ -107,7 +82,7 @@ uart_cpu_acpi_spcr(int devtype, struct uart_devinfo *di)
 	di->ops = uart_getops(class);
 
 	/* Fill in details from SPCR table. */
-	switch (spcr->SerialPort.SpaceId) {
+	switch (addr->SpaceId) {
 	case 0:
 		di->bas.bst = uart_bus_space_mem;
 		break;
@@ -116,10 +91,10 @@ uart_cpu_acpi_spcr(int devtype, struct uart_devinfo *di)
 		break;
 	default:
 		printf("UART in unrecognized address space: %d!\n",
-		    (int)spcr->SerialPort.SpaceId);
-		goto out;
+		    (int)addr->SpaceId);
+		return (ENXIO);
 	}
-	switch (spcr->SerialPort.AccessWidth) {
+	switch (addr->AccessWidth) {
 	case 0: /* EFI_ACPI_6_0_UNDEFINED */
 		/* FALLTHROUGH */
 	case 1: /* EFI_ACPI_6_0_BYTE */
@@ -136,10 +111,10 @@ uart_cpu_acpi_spcr(int devtype, struct uart_devinfo *di)
 		break;
 	default:
 		printf("UART unsupported access width: %d!\n",
-		    (int)spcr->SerialPort.AccessWidth);
-		goto out;
+		    (int)addr->AccessWidth);
+		return (ENXIO);
 	}
-	switch (spcr->SerialPort.BitWidth) {
+	switch (addr->BitWidth) {
 	case 0:
 		/* FALLTHROUGH */
 	case 8:
@@ -156,9 +131,46 @@ uart_cpu_acpi_spcr(int devtype, struct uart_devinfo *di)
 		break;
 	default:
 		printf("UART unsupported bit width: %d!\n",
-		    (int)spcr->SerialPort.BitWidth);
-		goto out;
+		    (int)addr->BitWidth);
+		return (ENXIO);
 	}
+
+	return (0);
+}
+
+int
+uart_cpu_acpi_spcr(int devtype, struct uart_devinfo *di)
+{
+	vm_paddr_t spcr_physaddr;
+	ACPI_TABLE_SPCR *spcr;
+	struct acpi_uart_compat_data *cd;
+	struct uart_class *class;
+	int error = ENXIO;
+
+	/* SPCR only tells us about consoles. */
+	if (devtype != UART_DEV_CONSOLE)
+		return (error);
+
+	/* Look for the SPCR table. */
+	spcr_physaddr = acpi_find_table(ACPI_SIG_SPCR);
+	if (spcr_physaddr == 0)
+		return (error);
+	spcr = acpi_map_table(spcr_physaddr, ACPI_SIG_SPCR);
+	if (spcr == NULL) {
+		printf("Unable to map the SPCR table!\n");
+		return (error);
+	}
+
+	/* Search for information about this SPCR interface type. */
+	cd = uart_cpu_acpi_scan(spcr->InterfaceType);
+	if (cd == NULL)
+		goto out;
+	class = cd->cd_class;
+
+	error = uart_cpu_acpi_init_devinfo(di, class, &spcr->SerialPort);
+	if (error != 0)
+		goto out;
+
 	switch (spcr->BaudRate) {
 	case 0:
 		/* Special value; means "keep current value unchanged". */