Module Name: src
Committed By: jmcneill
Date: Thu Jan 30 00:42:47 UTC 2025
Modified Files:
src/sys/dev/acpi: xhci_acpi.c
src/sys/dev/usb: xhci.c xhcivar.h
Log Message:
xhci: Always do 32-bit accesses for platform (ACPI) XHCI devices.
The XHCI IP found in the CIX CD8180 throws an serror for any access that
is not 32-bit aligned. Let's add an XHCI_32BIT_ACCESS flag and set it
unconditionally for platform devices as there are only a handful of non-
32-bit accesses at init time.
To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/acpi/xhci_acpi.c
cvs rdiff -u -r1.186 -r1.187 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/usb/xhcivar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/acpi/xhci_acpi.c
diff -u src/sys/dev/acpi/xhci_acpi.c:1.14 src/sys/dev/acpi/xhci_acpi.c:1.15
--- src/sys/dev/acpi/xhci_acpi.c:1.14 Mon Dec 9 22:15:33 2024
+++ src/sys/dev/acpi/xhci_acpi.c Thu Jan 30 00:42:47 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: xhci_acpi.c,v 1.14 2024/12/09 22:15:33 jmcneill Exp $ */
+/* $NetBSD: xhci_acpi.c,v 1.15 2025/01/30 00:42:47 jmcneill Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.14 2024/12/09 22:15:33 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.15 2025/01/30 00:42:47 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -112,7 +112,7 @@ xhci_acpi_attach(device_t parent, device
sc->sc_dev = self;
sc->sc_bus.ub_hcpriv = sc;
sc->sc_bus.ub_revision = USBREV_3_0;
- sc->sc_quirks = 0;
+ sc->sc_quirks = XHCI_32BIT_ACCESS;
sc->sc_vendor_init = xhci_acpi_init;
rv = acpi_resource_parse(sc->sc_dev, asc->sc_handle, "_CRS",
Index: src/sys/dev/usb/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.186 src/sys/dev/usb/xhci.c:1.187
--- src/sys/dev/usb/xhci.c:1.186 Thu Jan 9 10:17:22 2025
+++ src/sys/dev/usb/xhci.c Thu Jan 30 00:42:47 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: xhci.c,v 1.186 2025/01/09 10:17:22 jmcneill Exp $ */
+/* $NetBSD: xhci.c,v 1.187 2025/01/30 00:42:47 jmcneill Exp $ */
/*
* Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.186 2025/01/09 10:17:22 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.187 2025/01/30 00:42:47 jmcneill Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -287,13 +287,25 @@ static const struct usbd_pipe_methods xh
static inline uint32_t
xhci_read_1(const struct xhci_softc * const sc, bus_size_t offset)
{
- return bus_space_read_1(sc->sc_iot, sc->sc_ioh, offset);
+ if (ISSET(sc->sc_quirks, XHCI_32BIT_ACCESS)) {
+ uint32_t val;
+ val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset & ~3);
+ return (val >> ((offset & 3) * NBBY)) & 0xff;
+ } else {
+ return bus_space_read_1(sc->sc_iot, sc->sc_ioh, offset);
+ }
}
static inline uint32_t
xhci_read_2(const struct xhci_softc * const sc, bus_size_t offset)
{
- return bus_space_read_2(sc->sc_iot, sc->sc_ioh, offset);
+ if (ISSET(sc->sc_quirks, XHCI_32BIT_ACCESS)) {
+ uint32_t val;
+ val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset & ~3);
+ return (val >> ((offset & 3) * NBBY)) & 0xffff;
+ } else {
+ return bus_space_read_2(sc->sc_iot, sc->sc_ioh, offset);
+ }
}
static inline uint32_t
@@ -306,7 +318,16 @@ static inline void
xhci_write_1(const struct xhci_softc * const sc, bus_size_t offset,
uint32_t value)
{
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, offset, value);
+ if (ISSET(sc->sc_quirks, XHCI_32BIT_ACCESS)) {
+ const uint32_t mask = 0xffU << ((offset & 3) * NBBY);
+ uint32_t val;
+ val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset & ~3);
+ val &= ~mask;
+ val |= __SHIFTIN(value, mask);
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, offset & ~3, val);
+ } else {
+ bus_space_write_1(sc->sc_iot, sc->sc_ioh, offset, value);
+ }
}
#if 0 /* unused */
Index: src/sys/dev/usb/xhcivar.h
diff -u src/sys/dev/usb/xhcivar.h:1.24 src/sys/dev/usb/xhcivar.h:1.25
--- src/sys/dev/usb/xhcivar.h:1.24 Sun Apr 9 20:41:29 2023
+++ src/sys/dev/usb/xhcivar.h Thu Jan 30 00:42:47 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: xhcivar.h,v 1.24 2023/04/09 20:41:29 riastradh Exp $ */
+/* $NetBSD: xhcivar.h,v 1.25 2025/01/30 00:42:47 jmcneill Exp $ */
/*
* Copyright (c) 2013 Jonathan A. Kollasch
@@ -149,6 +149,7 @@ struct xhci_softc {
int sc_quirks;
#define XHCI_QUIRK_INTEL __BIT(0) /* Intel xhci chip */
#define XHCI_DEFERRED_START __BIT(1)
+#define XHCI_32BIT_ACCESS __BIT(2)
uint32_t sc_hcc; /* copy of HCCPARAMS1 */
uint32_t sc_hcc2; /* copy of HCCPARAMS2 */