From nobody Wed Jul 6 11:44:48 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 3069D1D09534; Wed, 6 Jul 2022 11:44:49 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LdHlP0KR0z3p9V; Wed, 6 Jul 2022 11:44:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657107889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3gvZ2AFeB811tWJbTEu1wXlB2fV0fAAqfPSkXIcoplA=; b=x46r75rdLb6+FNESQi/Yxr37PsfYOjHym203LyYzPPWo7Q4Nrq/+puTJevgB/OCo/WhLPE HmpKhWJO7Lo+VUkI0btb0pQEVlLn1yh25L2DViwhgwKMnOBTomtuwPpByE/mRFIA47GMPc L2u6msskRehCEWl7Ef76hDjZQjRd3nLpyuIpFbMrBxG70+wZxFU4DezqN6OsksoOBLw/q9 ILYPU2ZDUP8Uq4+llvCHuLjUxttj+RKMdfQSyhVp761JLYfMfXRQV8fKSAkDONi4O00pd8 n8iWQF55vO7bbzRYjnurEG87hwENikR0prcMehr95dOKE2NZIl5VwytRCw/5QQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D549219E82; Wed, 6 Jul 2022 11:44:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 266BimVE050581; Wed, 6 Jul 2022 11:44:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 266BimA7050580; Wed, 6 Jul 2022 11:44:48 GMT (envelope-from git) Date: Wed, 6 Jul 2022 11:44:48 GMT Message-Id: <202207061144.266BimA7050580@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: fbb5cb66f74c - main - dwc3: add ACPI attachment List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fbb5cb66f74cd9e7c2b1491dee6f5a3df72aea7a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657107889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3gvZ2AFeB811tWJbTEu1wXlB2fV0fAAqfPSkXIcoplA=; b=boLPJyQuBhlYu3B3ULoASf6jXQxkKydjb7hSKgWAMejlcxYGFJ48Wob+kK2hkZhhPyM3mn 7zHa1NZxhJNVj3jHv2VsP72Lbyb7CiXNXvq/QhvrH9DQoVX2+FVKHfLakfS+CGdv99U9pR GL2Eu87I0WDBdZ3b4zSxF8Miyi7jKTV+2Uq4Ojnq+BUP6jIYH+I+gj3+U7Rpz8b8NtkpKz uxcRFTRSBO3ixyStiQHmvmw839tCTBa8ZJKX29LXEtNeNEQ52gPygPH0AwC79SZZ2poqpm x3mQzCxSGilZbZBbNYqy5CHCVvvamds3PbFacSR3AxfVpJ+kuamzpXTUOxCRJA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657107889; a=rsa-sha256; cv=none; b=VLoPLSkcV/Neq37iEfUsrOG8KLKsktFzEafgLB+XL0n8PGUhLgctDEKnh6RmxV3XIjz86l FalD5Kj+IISG6UhuAHD7wMbKkCSo1Ss3r0rg03eFEb8HM/jsBZRBBM0Doe4A8ngF42c8Re G9rf5cK0QjNxiQc8nKLpIi718w83rUkj9lXt6v3dwSuSz9jqGM0nn0AYquHwEEfuDGkeD8 ysmQJTcCZIb/ozgY48N/b8FBB16XGzTZqCpGpPmmuQZ7VnxWC1wTtB6GAyDLalA9HuenDL +F1EMXT8Jg2ZM4isbb8M02Hodri1cLvDQm/8COTiYnroEKA5jcK08JvZJvXi/w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=fbb5cb66f74cd9e7c2b1491dee6f5a3df72aea7a commit fbb5cb66f74cd9e7c2b1491dee6f5a3df72aea7a Author: Bjoern A. Zeeb AuthorDate: 2022-07-05 01:07:07 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-07-06 11:26:34 +0000 dwc3: add ACPI attachment Split the current FDT-only implementation up into an FDT and an ACPI part reusing and sharing as much code as possible (thanks mw!). This makes the Synopsis XHCI root hubs attach correctly on SolidRun's HoenyComb instead of just the generic XHCI root and this means we are also doing proper chip setup and applying the quirk needed there [1]. There is one problem with ACPI attachment in that it uses the generic XHCI PNP ID. So we need to do extra checks in order to not claim all xhci, which means we check for a known quirk to be present in acpi_probe. Long term this isn't scaling and this was discussed in SolidRun's Discord Channel in 2021 with the intend that "jnettlet" will take this to a steering committee. Since then ACPI has kind-of become a technology non grata (due to not getting changes into Linux timely) so it is unclear if this will ever happen. If there will be further hardware with dwc3/ACPI we should go and make sure this problem gets solved. [1] https://github.com/SolidRun/edk2-platforms/blob/24698f90b79facfbbfc4067b39a4ddf8c7fdfa88/Silicon/NXP/LX2160A/AcpiTables/Dsdt/Usb.asl Reviewed by: manu, mw MFC after: 10 days Differential Revision: https://reviews.freebsd.org/D32256 --- sys/conf/files.arm64 | 2 +- sys/dev/usb/controller/dwc3.c | 199 +++++++++++++++++++++++++++++++----------- 2 files changed, 149 insertions(+), 52 deletions(-) diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index 3c77c8656500..d11d77001a47 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -307,7 +307,7 @@ dev/uart/uart_dev_mu.c optional uart uart_mu dev/uart/uart_dev_pl011.c optional uart pl011 dev/usb/controller/dwc_otg_hisi.c optional dwcotg fdt soc_hisi_hi6220 -dev/usb/controller/dwc3.c optional fdt dwc3 +dev/usb/controller/dwc3.c optional xhci acpi dwc3 | xhci fdt dwc3 dev/usb/controller/ehci_mv.c optional ehci_mv fdt dev/usb/controller/generic_ehci.c optional ehci dev/usb/controller/generic_ehci_acpi.c optional ehci acpi diff --git a/sys/dev/usb/controller/dwc3.c b/sys/dev/usb/controller/dwc3.c index a71f92abebd9..19237ef4c11d 100644 --- a/sys/dev/usb/controller/dwc3.c +++ b/sys/dev/usb/controller/dwc3.c @@ -2,6 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2019 Emmanuel Vadot + * Copyright (c) 2021-2022 Bjoern A. Zeeb * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -25,12 +26,14 @@ * SUCH DAMAGE. * * $FreeBSD$ - * */ #include __FBSDID("$FreeBSD$"); +#include "opt_platform.h" +#include "opt_acpi.h" + #include #include #include @@ -38,15 +41,11 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef FDT #include -#include - -#include +#endif -#include -#include -#include -#include +#include #include #include @@ -60,15 +59,25 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef FDT +#include + +#include +#include +#include +#include + #include #include +#endif -#include "generic_xhci.h" +#ifdef DEV_ACPI +#include +#include +#include +#endif -static struct ofw_compat_data compat_data[] = { - { "snps,dwc3", 1 }, - { NULL, 0 } -}; +#include "generic_xhci.h" struct snps_dwc3_softc { struct xhci_softc sc; @@ -76,9 +85,6 @@ struct snps_dwc3_softc { struct resource * mem_res; bus_space_tag_t bst; bus_space_handle_t bsh; - phandle_t node; - phy_t usb2_phy; - phy_t usb3_phy; uint32_t snpsid; }; @@ -87,6 +93,8 @@ struct snps_dwc3_softc { #define DWC3_READ(_sc, _off) \ bus_space_read_4(_sc->bst, _sc->bsh, _off) +#define IS_DMA_32B 1 + static int snps_dwc3_attach_xhci(device_t dev) { @@ -125,7 +133,7 @@ snps_dwc3_attach_xhci(device_t dev) return (err); } - err = xhci_init(sc, dev, 1); + err = xhci_init(sc, dev, IS_DMA_32B); if (err != 0) { device_printf(dev, "Failed to init XHCI, with error %d\n", err); return (ENXIO); @@ -175,9 +183,7 @@ snsp_dwc3_dump_regs(struct snps_dwc3_softc *sc, const char *msg) xsc = &sc->sc; device_printf(sc->dev, "xhci quirks: %#012x\n", xsc->sc_quirks); } -#endif -#ifdef DWC3_DEBUG static void snps_dwc3_dump_ctrlparams(struct snps_dwc3_softc *sc) { @@ -202,11 +208,6 @@ snps_dwc3_reset(struct snps_dwc3_softc *sc) { uint32_t gctl, ghwp0, phy2, phy3; - if (sc->usb2_phy) - phy_enable(sc->usb2_phy); - if (sc->usb3_phy) - phy_enable(sc->usb3_phy); - ghwp0 = DWC3_READ(sc, DWC3_GHWPARAMS0); gctl = DWC3_READ(sc, DWC3_GCTL); @@ -260,15 +261,16 @@ snps_dwc3_configure_host(struct snps_dwc3_softc *sc) DWC3_WRITE(sc, DWC3_GUCTL, reg); } +#ifdef FDT static void -snps_dwc3_configure_phy(struct snps_dwc3_softc *sc) +snps_dwc3_configure_phy(struct snps_dwc3_softc *sc, phandle_t node) { char *phy_type; uint32_t reg; int nphy_types; phy_type = NULL; - nphy_types = OF_getprop_alloc(sc->node, "phy_type", (void **)&phy_type); + nphy_types = OF_getprop_alloc(node, "phy_type", (void **)&phy_type); if (nphy_types <= 0) return; @@ -285,6 +287,7 @@ snps_dwc3_configure_phy(struct snps_dwc3_softc *sc) DWC3_WRITE(sc, DWC3_GUSB2PHYCFG0, reg); OF_prop_free(phy_type); } +#endif static void snps_dwc3_do_quirks(struct snps_dwc3_softc *sc) @@ -334,17 +337,11 @@ snps_dwc3_do_quirks(struct snps_dwc3_softc *sc) } static int -snps_dwc3_probe(device_t dev) +snps_dwc3_probe_common(device_t dev) { - char dr_mode[16]; + char dr_mode[16] = { 0 }; ssize_t s; - if (!ofw_bus_status_okay(dev)) - return (ENXIO); - - if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) - return (ENXIO); - s = device_get_property(dev, "dr_mode", dr_mode, sizeof(dr_mode), DEVICE_PROP_BUFFER); if (s == -1) { @@ -363,14 +360,19 @@ snps_dwc3_probe(device_t dev) } static int -snps_dwc3_attach(device_t dev) +snps_dwc3_common_attach(device_t dev, bool is_fdt) { struct snps_dwc3_softc *sc; - int rid = 0; +#ifdef FDT + phandle_t node; + phy_t usb2_phy, usb3_phy; +#endif + int error, rid; sc = device_get_softc(dev); sc->dev = dev; + rid = 0; sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->mem_res == NULL) { @@ -387,40 +389,135 @@ snps_dwc3_attach(device_t dev) snps_dwc3_dump_ctrlparams(sc); #endif +#ifdef FDT + if (!is_fdt) + goto skip_phys; + /* Get the phys */ - sc->node = ofw_bus_get_node(dev); - phy_get_by_ofw_name(dev, sc->node, "usb2-phy", &sc->usb2_phy); - phy_get_by_ofw_name(dev, sc->node, "usb3-phy", &sc->usb3_phy); + node = ofw_bus_get_node(dev); + + usb2_phy = usb3_phy = NULL; + error = phy_get_by_ofw_name(dev, node, "usb2-phy", &usb2_phy); + if (error == 0 && usb2_phy != NULL) + phy_enable(usb2_phy); + error = phy_get_by_ofw_name(dev, node, "usb3-phy", &usb3_phy); + if (error == 0 && usb3_phy != NULL) + phy_enable(usb3_phy); + + snps_dwc3_configure_phy(sc, node); +skip_phys: +#endif snps_dwc3_reset(sc); snps_dwc3_configure_host(sc); - snps_dwc3_configure_phy(sc); snps_dwc3_do_quirks(sc); #ifdef DWC3_DEBUG snsp_dwc3_dump_regs(sc, "Pre XHCI init"); #endif - snps_dwc3_attach_xhci(dev); + error = snps_dwc3_attach_xhci(dev); #ifdef DWC3_DEBUG snsp_dwc3_dump_regs(sc, "Post XHCI init"); #endif - return (0); + return (error); +} + +#ifdef FDT +static struct ofw_compat_data compat_data[] = { + { "snps,dwc3", 1 }, + { NULL, 0 } +}; + +static int +snps_dwc3_fdt_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); + + return (snps_dwc3_probe_common(dev)); } -static device_method_t snps_dwc3_methods[] = { +static int +snps_dwc3_fdt_attach(device_t dev) +{ + + return (snps_dwc3_common_attach(dev, true)); +} + +static device_method_t snps_dwc3_fdt_methods[] = { /* Device interface */ - DEVMETHOD(device_probe, snps_dwc3_probe), - DEVMETHOD(device_attach, snps_dwc3_attach), + DEVMETHOD(device_probe, snps_dwc3_fdt_probe), + DEVMETHOD(device_attach, snps_dwc3_fdt_attach), DEVMETHOD_END }; -static driver_t snps_dwc3_driver = { - "xhci", - snps_dwc3_methods, - sizeof(struct snps_dwc3_softc) +DEFINE_CLASS_1(snps_dwc3_fdt, snps_dwc3_fdt_driver, snps_dwc3_fdt_methods, + sizeof(struct snps_dwc3_softc), generic_xhci_driver); + +DRIVER_MODULE(snps_dwc3_fdt, simplebus, snps_dwc3_fdt_driver, 0, 0); +MODULE_DEPEND(snps_dwc3_fdt, xhci, 1, 1, 1); +#endif + +#ifdef DEV_ACPI +static char *dwc3_acpi_ids[] = { + "808622B7", /* This was an Intel PCI Vendor/Device ID used. */ + "PNP0D10", /* The generic XHCI PNP ID needing extra probe checks. */ + NULL +}; + +static int +snps_dwc3_acpi_probe(device_t dev) +{ + char *match; + int error; + + if (acpi_disabled("snps_dwc3")) + return (ENXIO); + + error = ACPI_ID_PROBE(device_get_parent(dev), dev, dwc3_acpi_ids, &match); + if (error > 0) + return (ENXIO); + + /* + * If we found the Generic XHCI PNP ID we can only attach if we have + * some other means to identify the device as dwc3. + */ + if (strcmp(match, "PNP0D10") == 0) { + /* This is needed in SolidRun's HoneyComb. */ + if (device_has_property(dev, "snps,dis_rxdet_inp3_quirk")) + goto is_dwc3; + + return (ENXIO); + } + +is_dwc3: + return (snps_dwc3_probe_common(dev)); +} + +static int +snps_dwc3_acpi_attach(device_t dev) +{ + + return (snps_dwc3_common_attach(dev, false)); +} + +static device_method_t snps_dwc3_acpi_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, snps_dwc3_acpi_probe), + DEVMETHOD(device_attach, snps_dwc3_acpi_attach), + + DEVMETHOD_END }; -DRIVER_MODULE(snps_dwc3, simplebus, snps_dwc3_driver, 0, 0); -MODULE_DEPEND(snps_dwc3, xhci, 1, 1, 1); +DEFINE_CLASS_1(snps_dwc3_acpi, snps_dwc3_acpi_driver, snps_dwc3_acpi_methods, + sizeof(struct snps_dwc3_softc), generic_xhci_driver); + +DRIVER_MODULE(snps_dwc3_acpi, acpi, snps_dwc3_acpi_driver, 0, 0); +MODULE_DEPEND(snps_dwc3_acpi, usb, 1, 1, 1); +#endif