diff --git a/sys/dev/uart/uart_cpu_acpi.c b/sys/dev/uart/uart_cpu_acpi.c --- a/sys/dev/uart/uart_cpu_acpi.c +++ b/sys/dev/uart/uart_cpu_acpi.c @@ -69,35 +69,10 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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". */