diff options
| author | Emmanuel Vadot <manu@FreeBSD.org> | 2019-05-08 15:42:39 +0000 |
|---|---|---|
| committer | Emmanuel Vadot <manu@FreeBSD.org> | 2019-05-08 15:42:39 +0000 |
| commit | 052073c38209a57b06576c14eb19c008807a3744 (patch) | |
| tree | af1d3dca71dd065bb0385186ece11a9148d27703 /sys | |
| parent | 85ae89f4bb5a023f54ab93e661d7de337c743dbe (diff) | |
Notes
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/arm64/conf/GENERIC | 2 | ||||
| -rw-r--r-- | sys/conf/files.arm64 | 4 | ||||
| -rw-r--r-- | sys/dev/usb/controller/generic_xhci.c | 85 | ||||
| -rw-r--r-- | sys/dev/usb/controller/generic_xhci.h | 44 | ||||
| -rw-r--r-- | sys/dev/usb/controller/generic_xhci_acpi.c | 83 | ||||
| -rw-r--r-- | sys/dev/usb/controller/generic_xhci_fdt.c | 139 |
6 files changed, 287 insertions, 70 deletions
diff --git a/sys/arm64/conf/GENERIC b/sys/arm64/conf/GENERIC index b3f27def13c3..c83f9771b4aa 100644 --- a/sys/arm64/conf/GENERIC +++ b/sys/arm64/conf/GENERIC @@ -206,7 +206,7 @@ device dwcotg # DWC OTG controller device ohci # OHCI USB interface device ehci # EHCI USB interface (USB 2.0) device ehci_mv # Marvell EHCI USB interface -device xhci # XHCI PCI->USB interface (USB 3.0) +device xhci # XHCI USB interface (USB 3.0) device usb # USB Bus (required) device ukbd # Keyboard device umass # Disks/Mass storage - Requires scbus and da diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index 770541862f09..73c1901d7a96 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -240,7 +240,9 @@ dev/usb/controller/generic_ehci.c optional ehci acpi dev/usb/controller/generic_ohci.c optional ohci fdt dev/usb/controller/generic_usb_if.m optional ohci fdt dev/usb/controller/usb_nop_xceiv.c optional fdt ext_resources -dev/usb/controller/generic_xhci.c optional xhci fdt +dev/usb/controller/generic_xhci.c optional xhci +dev/usb/controller/generic_xhci_acpi.c optional xhci acpi +dev/usb/controller/generic_xhci_fdt.c optional xhci fdt dev/vnic/mrml_bridge.c optional vnic fdt dev/vnic/nic_main.c optional vnic pci dev/vnic/nicvf_main.c optional vnic pci pci_iov diff --git a/sys/dev/usb/controller/generic_xhci.c b/sys/dev/usb/controller/generic_xhci.c index 7b51dccda125..727f72fefd9e 100644 --- a/sys/dev/usb/controller/generic_xhci.c +++ b/sys/dev/usb/controller/generic_xhci.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * Copyright (c) 2015 Semihalf. * Copyright (c) 2015 Stormshield. * All rights reserved. @@ -28,8 +30,6 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include "opt_bus.h" - #include <sys/stdint.h> #include <sys/stddef.h> #include <sys/param.h> @@ -48,9 +48,6 @@ __FBSDID("$FreeBSD$"); #include <sys/priv.h> #include <sys/rman.h> -#include <dev/ofw/ofw_bus.h> -#include <dev/ofw/ofw_bus_subr.h> - #include <dev/usb/usb.h> #include <dev/usb/usbdi.h> @@ -64,50 +61,15 @@ __FBSDID("$FreeBSD$"); #include <dev/usb/controller/xhci.h> #include <dev/usb/controller/xhcireg.h> -#ifdef EXT_RESOURCES -#include <dev/extres/phy/phy.h> -#endif - -#define XHCI_HC_DEVSTR "Marvell Integrated USB 3.0 controller" -#define XHCI_HC_VENDOR "Marvell" +#include "generic_xhci.h" #define IS_DMA_32B 1 -static device_attach_t xhci_attach; -static device_detach_t xhci_detach; - -static struct ofw_compat_data compat_data[] = { - {"marvell,armada-380-xhci", true}, - {"marvell,armada3700-xhci", true}, - {"marvell,armada-8k-xhci", true}, - {"generic-xhci", true}, - {NULL, false} -}; - -static int -xhci_probe(device_t dev) -{ - - if (!ofw_bus_status_okay(dev)) - return (ENXIO); - - if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) - return (ENXIO); - - device_set_desc(dev, XHCI_HC_DEVSTR); - - return (BUS_PROBE_DEFAULT); -} - -static int -xhci_attach(device_t dev) +int +generic_xhci_attach(device_t dev) { struct xhci_softc *sc = device_get_softc(dev); int err = 0, rid = 0; -#ifdef EXT_RESOURCES - phandle_t node; - phy_t phy; -#endif sc->sc_bus.parent = dev; sc->sc_bus.devices = sc->sc_devices; @@ -117,7 +79,7 @@ xhci_attach(device_t dev) RF_ACTIVE); if (sc->sc_io_res == NULL) { device_printf(dev, "Failed to map memory\n"); - xhci_detach(dev); + generic_xhci_detach(dev); return (ENXIO); } @@ -129,21 +91,14 @@ xhci_attach(device_t dev) RF_SHAREABLE | RF_ACTIVE); if (sc->sc_irq_res == NULL) { device_printf(dev, "Failed to allocate IRQ\n"); - xhci_detach(dev); + generic_xhci_detach(dev); return (ENXIO); } -#ifdef EXT_RESOURCES - node = ofw_bus_get_node(dev); - if (phy_get_by_ofw_property(dev, node, "usb-phy", &phy) == 0) - if (phy_enable(phy) != 0) - device_printf(dev, "Cannot enable phy\n"); -#endif - sc->sc_bus.bdev = device_add_child(dev, "usbus", -1); if (sc->sc_bus.bdev == NULL) { device_printf(dev, "Failed to add USB device\n"); - xhci_detach(dev); + generic_xhci_detach(dev); return (ENXIO); } @@ -157,36 +112,36 @@ xhci_attach(device_t dev) if (err != 0) { device_printf(dev, "Failed to setup error IRQ, %d\n", err); sc->sc_intr_hdl = NULL; - xhci_detach(dev); + generic_xhci_detach(dev); return (err); } err = xhci_init(sc, dev, IS_DMA_32B); if (err != 0) { device_printf(dev, "Failed to init XHCI, with error %d\n", err); - xhci_detach(dev); + generic_xhci_detach(dev); return (ENXIO); } err = xhci_start_controller(sc); if (err != 0) { device_printf(dev, "Failed to start XHCI controller, with error %d\n", err); - xhci_detach(dev); + generic_xhci_detach(dev); return (ENXIO); } err = device_probe_and_attach(sc->sc_bus.bdev); if (err != 0) { device_printf(dev, "Failed to initialize USB, with error %d\n", err); - xhci_detach(dev); + generic_xhci_detach(dev); return (ENXIO); } return (0); } -static int -xhci_detach(device_t dev) +int +generic_xhci_detach(device_t dev) { struct xhci_softc *sc = device_get_softc(dev); int err; @@ -221,9 +176,8 @@ xhci_detach(device_t dev) static device_method_t xhci_methods[] = { /* Device interface */ - DEVMETHOD(device_probe, xhci_probe), - DEVMETHOD(device_attach, xhci_attach), - DEVMETHOD(device_detach, xhci_detach), + DEVMETHOD(device_attach, generic_xhci_attach), + DEVMETHOD(device_detach, generic_xhci_detach), DEVMETHOD(device_suspend, bus_generic_suspend), DEVMETHOD(device_resume, bus_generic_resume), DEVMETHOD(device_shutdown, bus_generic_shutdown), @@ -231,13 +185,8 @@ static device_method_t xhci_methods[] = { DEVMETHOD_END }; -static driver_t xhci_driver = { +driver_t generic_xhci_driver = { "xhci", xhci_methods, sizeof(struct xhci_softc), }; - -static devclass_t xhci_devclass; - -DRIVER_MODULE(xhci, simplebus, xhci_driver, xhci_devclass, 0, 0); -MODULE_DEPEND(xhci, usb, 1, 1, 1); diff --git a/sys/dev/usb/controller/generic_xhci.h b/sys/dev/usb/controller/generic_xhci.h new file mode 100644 index 000000000000..1c086d4a5304 --- /dev/null +++ b/sys/dev/usb/controller/generic_xhci.h @@ -0,0 +1,44 @@ +/* $FreeBSD$ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2015 Semihalf. + * Copyright (c) 2015 Stormshield. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef _GENERIC_XHCI_H_ +#define _GENERIC_XHCI_H_ + +#define XHCI_HC_DEVSTR "Generic USB 3.0 controller" +#define XHCI_HC_VENDOR "Generic" + +extern driver_t generic_xhci_driver; + +device_attach_t generic_xhci_attach; +device_detach_t generic_xhci_detach; + +#endif /* !_GENERIC_XHCI_H_ */ diff --git a/sys/dev/usb/controller/generic_xhci_acpi.c b/sys/dev/usb/controller/generic_xhci_acpi.c new file mode 100644 index 000000000000..80ad8ca4e8a4 --- /dev/null +++ b/sys/dev/usb/controller/generic_xhci_acpi.c @@ -0,0 +1,83 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 Greg V <greg@unrelenting.technology> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "opt_acpi.h" + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/condvar.h> +#include <sys/kernel.h> +#include <sys/module.h> + +#include <dev/usb/usb.h> +#include <dev/usb/usbdi.h> + +#include <dev/usb/usb_core.h> +#include <dev/usb/usb_busdma.h> +#include <dev/usb/usb_process.h> + +#include <dev/usb/usb_controller.h> +#include <dev/usb/usb_bus.h> +#include <dev/usb/controller/xhci.h> + +#include <contrib/dev/acpica/include/acpi.h> +#include <dev/acpica/acpivar.h> + +#include "generic_xhci.h" + +static int +generic_xhci_acpi_probe(device_t dev) +{ + ACPI_HANDLE h; + + if ((h = acpi_get_handle(dev)) == NULL || + acpi_MatchHid(h, "PNP0D10") == ACPI_MATCHHID_NOMATCH) + return (ENXIO); + + device_set_desc(dev, XHCI_HC_DEVSTR); + + return (BUS_PROBE_DEFAULT); +} + +static device_method_t xhci_acpi_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, generic_xhci_acpi_probe), + + DEVMETHOD_END +}; + +DEFINE_CLASS_1(xhci, xhci_acpi_driver, xhci_acpi_methods, + sizeof(struct xhci_softc), generic_xhci_driver); + +static devclass_t xhci_acpi_devclass; + +DRIVER_MODULE(xhci, acpi, xhci_acpi_driver, xhci_acpi_devclass, 0, 0); +MODULE_DEPEND(xhci, usb, 1, 1, 1); diff --git a/sys/dev/usb/controller/generic_xhci_fdt.c b/sys/dev/usb/controller/generic_xhci_fdt.c new file mode 100644 index 000000000000..7f020a979e9e --- /dev/null +++ b/sys/dev/usb/controller/generic_xhci_fdt.c @@ -0,0 +1,139 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2015 Semihalf. + * Copyright (c) 2015 Stormshield. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "opt_bus.h" + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/condvar.h> +#include <sys/kernel.h> +#include <sys/module.h> + +#include <dev/usb/usb.h> +#include <dev/usb/usbdi.h> + +#include <dev/usb/usb_core.h> +#include <dev/usb/usb_busdma.h> +#include <dev/usb/usb_process.h> + +#include <dev/usb/usb_controller.h> +#include <dev/usb/usb_bus.h> +#include <dev/usb/controller/xhci.h> + +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#ifdef EXT_RESOURCES +#include <dev/extres/phy/phy.h> +#endif + +#include "generic_xhci.h" + +static struct ofw_compat_data compat_data[] = { + {"marvell,armada-380-xhci", true}, + {"marvell,armada3700-xhci", true}, + {"marvell,armada-8k-xhci", true}, + {"generic-xhci", true}, + {NULL, false} +}; + +static int +generic_xhci_fdt_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) + return (ENXIO); + + device_set_desc(dev, XHCI_HC_DEVSTR); + + return (BUS_PROBE_DEFAULT); +} + +static int +generic_xhci_fdt_attach(device_t dev) +{ +#ifdef EXT_RESOURCES + phandle_t node; + phy_t phy; + + node = ofw_bus_get_node(dev); + if (phy_get_by_ofw_property(dev, node, "usb-phy", &phy) == 0) + if (phy_enable(phy) != 0) + device_printf(dev, "Cannot enable phy\n"); +#endif + + return (generic_xhci_attach(dev)); +} + +static int +generic_xhci_fdt_detach(device_t dev) +{ +#ifdef EXT_RESOURCES + phandle_t node; + phy_t phy; +#endif + int err; + + err = generic_xhci_detach(dev); + if (err != 0) + return (err); + +#ifdef EXT_RESOURCES + node = ofw_bus_get_node(dev); + if (phy_get_by_ofw_property(dev, node, "usb-phy", &phy) == 0) + phy_release(phy); +#endif + + return (0); +} + + +static device_method_t xhci_fdt_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, generic_xhci_fdt_probe), + DEVMETHOD(device_attach, generic_xhci_fdt_attach), + DEVMETHOD(device_detach, generic_xhci_fdt_detach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_1(xhci, xhci_fdt_driver, xhci_fdt_methods, + sizeof(struct xhci_softc), generic_xhci_driver); + +static devclass_t xhci_fdt_devclass; + +DRIVER_MODULE(xhci, simplebus, xhci_fdt_driver, xhci_fdt_devclass, 0, 0); +MODULE_DEPEND(xhci, usb, 1, 1, 1); |
