Index: sys/arm64/conf/GENERIC =================================================================== --- sys/arm64/conf/GENERIC +++ sys/arm64/conf/GENERIC @@ -205,7 +205,7 @@ 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 Index: sys/conf/files.arm64 =================================================================== --- sys/conf/files.arm64 +++ sys/conf/files.arm64 @@ -237,7 +237,9 @@ 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 Index: sys/dev/usb/controller/generic_xhci.h =================================================================== --- /dev/null +++ sys/dev/usb/controller/generic_xhci.h @@ -0,0 +1,39 @@ +/*- + * 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_ */ Index: sys/dev/usb/controller/generic_xhci.c =================================================================== --- sys/dev/usb/controller/generic_xhci.c +++ sys/dev/usb/controller/generic_xhci.c @@ -28,8 +28,6 @@ #include __FBSDID("$FreeBSD$"); -#include "opt_bus.h" - #include #include #include @@ -48,9 +46,6 @@ #include #include -#include -#include - #include #include @@ -64,50 +59,15 @@ #include #include -#ifdef EXT_RESOURCES -#include -#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 +77,7 @@ 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 +89,14 @@ 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 +110,36 @@ 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 +174,8 @@ 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 +183,8 @@ 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); Index: sys/dev/usb/controller/generic_xhci_acpi.c =================================================================== --- /dev/null +++ sys/dev/usb/controller/generic_xhci_acpi.c @@ -0,0 +1,84 @@ +/*- + * 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 +__FBSDID("$FreeBSD$"); + +#include "opt_acpi.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#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); Index: sys/dev/usb/controller/generic_xhci_fdt.c =================================================================== --- /dev/null +++ sys/dev/usb/controller/generic_xhci_fdt.c @@ -0,0 +1,114 @@ +/*- + * 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 +__FBSDID("$FreeBSD$"); + +#include "opt_bus.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#ifdef EXT_RESOURCES +#include +#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 device_method_t xhci_fdt_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, generic_xhci_fdt_probe), + DEVMETHOD(device_attach, generic_xhci_fdt_attach), + + 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);