Author: manu Date: Wed May 8 15:42:39 2019 New Revision: 347343 URL: https://svnweb.freebsd.org/changeset/base/347343
Log: Add support for USB 3.0 XHCI via ACPI Ampere eMAG systems have XHCI just described in ACPI, not on PCI. Submitted by: Greg V <greg@unrelenting.technology> Reviewed by: andrew MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D19986 Added: head/sys/dev/usb/controller/generic_xhci.h (contents, props changed) head/sys/dev/usb/controller/generic_xhci_acpi.c (contents, props changed) head/sys/dev/usb/controller/generic_xhci_fdt.c (contents, props changed) Modified: head/sys/arm64/conf/GENERIC head/sys/conf/files.arm64 head/sys/dev/usb/controller/generic_xhci.c Modified: head/sys/arm64/conf/GENERIC ============================================================================== --- head/sys/arm64/conf/GENERIC Wed May 8 15:36:57 2019 (r347342) +++ head/sys/arm64/conf/GENERIC Wed May 8 15:42:39 2019 (r347343) @@ -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 Modified: head/sys/conf/files.arm64 ============================================================================== --- head/sys/conf/files.arm64 Wed May 8 15:36:57 2019 (r347342) +++ head/sys/conf/files.arm64 Wed May 8 15:42:39 2019 (r347343) @@ -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 Modified: head/sys/dev/usb/controller/generic_xhci.c ============================================================================== --- head/sys/dev/usb/controller/generic_xhci.c Wed May 8 15:36:57 2019 (r347342) +++ head/sys/dev/usb/controller/generic_xhci.c Wed May 8 15:42:39 2019 (r347343) @@ -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 +#include "generic_xhci.h" -#define XHCI_HC_DEVSTR "Marvell Integrated USB 3.0 controller" -#define XHCI_HC_VENDOR "Marvell" - #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) +int +generic_xhci_attach(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) -{ 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); Added: head/sys/dev/usb/controller/generic_xhci.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/usb/controller/generic_xhci.h Wed May 8 15:42:39 2019 (r347343) @@ -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_ */ Added: head/sys/dev/usb/controller/generic_xhci_acpi.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/usb/controller/generic_xhci_acpi.c Wed May 8 15:42:39 2019 (r347343) @@ -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); Added: head/sys/dev/usb/controller/generic_xhci_fdt.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/usb/controller/generic_xhci_fdt.c Wed May 8 15:42:39 2019 (r347343) @@ -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); _______________________________________________ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"