From owner-svn-src-all@freebsd.org Wed May 8 15:42:41 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 49FF0158ABD2; Wed, 8 May 2019 15:42:41 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id EA5E880EC4; Wed, 8 May 2019 15:42:40 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D76787E24; Wed, 8 May 2019 15:42:40 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x48FgeIn013115; Wed, 8 May 2019 15:42:40 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x48FgdVM013110; Wed, 8 May 2019 15:42:39 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201905081542.x48FgdVM013110@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Wed, 8 May 2019 15:42:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r347343 - in head/sys: arm64/conf conf dev/usb/controller X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: in head/sys: arm64/conf conf dev/usb/controller X-SVN-Commit-Revision: 347343 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: EA5E880EC4 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.965,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 May 2019 15:42:41 -0000 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 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 __FBSDID("$FreeBSD$"); -#include "opt_bus.h" - #include #include #include @@ -48,9 +48,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include -#include - #include #include @@ -64,50 +61,15 @@ __FBSDID("$FreeBSD$"); #include #include -#ifdef EXT_RESOURCES -#include -#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 + * + * 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 "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 +__FBSDID("$FreeBSD$"); + +#include "opt_bus.h" + +#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 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);