From nobody Wed Mar 30 15:49:44 2022 X-Original-To: dev-commits-src-branches@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 8BA451A54321; Wed, 30 Mar 2022 15:49:44 +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 4KT9qD3DFdz3kSy; Wed, 30 Mar 2022 15:49:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648655384; 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=vAGOO/6P4jYUjUBOy92nc+GxyrWQdxG9gBc62yUXq8Q=; b=HThxEK1dvt0TDGYklRhy/ReiQb0GNgJ0Fsvh8nF7pFAZt2PIK/71f0pgVWTAXvXUb7k4Gr LuhoPsJHsm9XyVPBoN3+28j87IP3kkHIc7ibVAH3zIzpeEl8H1zgCBs7k/M0n8tjj5sH2r xBOanK1guIc0S/JnHQtfBb6oYvlokBZx8tJzbso5jPDGOFUmT27aU23MGRY0hUtP7GByUF WXbGnRXHTFFkV+tLqSK5rPYwcc2WzHYQVaB9tl4Cb0M1S31hMilAAE9Z8F+VfMOtzr3HXL siV5qI+dlY2f836hbSygz1+xvhcXq8Qomx+PhbsyxKeKrt+pg1CIFW7sI3Wvaw== 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 2179E160B1; Wed, 30 Mar 2022 15:49:44 +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 22UFniDw019258; Wed, 30 Mar 2022 15:49:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22UFniSn019257; Wed, 30 Mar 2022 15:49:44 GMT (envelope-from git) Date: Wed, 30 Mar 2022 15:49:44 GMT Message-Id: <202203301549.22UFniSn019257@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: a85cf68895d4 - releng/13.1 - LinuxKPI: pci: implement pci_upstream_bridge() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/releng/13.1 X-Git-Reftype: branch X-Git-Commit: a85cf68895d40ddcdb1f2c7313a7b415f27c0ef5 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648655384; 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=vAGOO/6P4jYUjUBOy92nc+GxyrWQdxG9gBc62yUXq8Q=; b=Be5q2LNZ6NSlqwdI/nuehioIliZgT1ofxJu6nMjbCIhOl9lbKllUmVgy/EhkOBojbunxwE LqqJHOMitQQv7d0kOuYWeA63+Uf28UjP1pYsIcwthpPRISSSKHocoCxCIx2Sv/KDSb3Kcn zLAyWygesQFvu36xGC44Pc5kDEFlGylQqB9gQyfE1jtN+MA40psIp/EzTLwp8rj8Qy1Nws MFM/t7tuO6ImvdAM8lg5nCd4DXwlFMJ6NkibJGKuIVTixtftOWZgVWFIxznVugIxXQpLn9 0JEzHcRwPxeaEmDqR7Mz3ZTAC4aLT1pTNa7ebezLfoZeFmZzgbqSKLjxansnwg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648655384; a=rsa-sha256; cv=none; b=UUYY+6rCVgnyt2AKosiS4y2hc6d0RTh/bTwa8zWRA/ch4Wsf9YYLysXXJ0+RKYNcscJ1OQ dyfAL9YPpAjo1P54EywjoLoztSDt8wLwWU0Uhrn7KDa1xYBkPM7VWY15lShYCDQZy2BDlG 3CusFPagLA3Wp0iqaCL1MIyybQvERAvTe7A5R3qnnu6fgRx+L12TfE1Smm30s1zCdb2yvX txh3aBhYA04KPBgyrieg5XunfX4Sgax8fvSdMK6yNblexIiJ68sHcRGaueBBoemYzGxP2F AJbm8mAgJalDuYHJ/3WSa1nfC0faOxbteHa9iTMGp0PTM71i4Vd92EIyPIw/WA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.1 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=a85cf68895d40ddcdb1f2c7313a7b415f27c0ef5 commit a85cf68895d40ddcdb1f2c7313a7b415f27c0ef5 Author: Bjoern A. Zeeb AuthorDate: 2022-02-16 18:04:08 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-03-30 15:46:52 +0000 LinuxKPI: pci: implement pci_upstream_bridge() Allow drivers to query the "upstream PCI bridge". Currently we point back to ourselves on pdev->bus->self rather than to the parent PCI bridge. We keep this as status-quo with an extra comment and only on-demand allocate a pci_dev for the parent bridge if we are asked for in pci_upstream_bridge(). When releasing the pci_dev we check if pdev->bus->self has changed and call pci_dev_put() to release the reference count on the parent bridge as well. This code moves pci_is_root_bus() higher up in pci.h but no functional change there. Approved by: re (gjb) Sponsored by: The FreeBSD Foundation Reviewed by: hselasky, (jhb some earlier) Thanks to: wulf for handling drm-kmod Differential Revision: https://reviews.freebsd.org/D34305 (cherry picked from commit b3b836251f9fefa817d158784189f6d336917f7a) (cherry picked from commit 50136233846e59eeb53c95498fdd4f3e1acf0a16) --- sys/compat/linuxkpi/common/include/linux/pci.h | 49 ++++++++++++++++++++++---- sys/compat/linuxkpi/common/src/linux_pci.c | 7 ++++ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index 361600a55397..eb5f46a4879c 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -482,6 +482,48 @@ pci_clear_master(struct pci_dev *pdev) return (0); } +static inline bool +pci_is_root_bus(struct pci_bus *pbus) +{ + + return (pbus->self == NULL); +} + +static inline struct pci_dev * +pci_upstream_bridge(struct pci_dev *pdev) +{ + + if (pci_is_root_bus(pdev->bus)) + return (NULL); + + /* + * If we do not have a (proper) "upstream bridge" set, e.g., we point + * to ourselves, try to handle this case on the fly like we do + * for pcie_find_root_port(). + */ + if (pdev == pdev->bus->self) { + device_t bridge; + + bridge = device_get_parent(pdev->dev.bsddev); + if (bridge == NULL) + goto done; + bridge = device_get_parent(bridge); + if (bridge == NULL) + goto done; + if (device_get_devclass(device_get_parent(bridge)) != + devclass_find("pci")) + goto done; + + /* + * "bridge" is a PCI-to-PCI bridge. Create a Linux pci_dev + * for it so it can be returned. + */ + pdev->bus->self = lkpinew_pci_dev(bridge); + } +done: + return (pdev->bus->self); +} + static inline struct pci_devres * lkpi_pci_devres_get_alloc(struct pci_dev *pdev) { @@ -1403,13 +1445,6 @@ pci_dev_present(const struct pci_device_id *cur) return (0); } -static inline bool -pci_is_root_bus(struct pci_bus *pbus) -{ - - return (pbus->self == NULL); -} - struct pci_dev *lkpi_pci_get_domain_bus_and_slot(int domain, unsigned int bus, unsigned int devfn); #define pci_get_domain_bus_and_slot(domain, bus, devfn) \ diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index ccb52732391e..bc169425c6a8 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -278,6 +278,11 @@ lkpifill_pci_dev(device_t dev, struct pci_dev *pdev) pdev->class = pci_get_class(dev); pdev->revision = pci_get_revid(dev); pdev->bus = malloc(sizeof(*pdev->bus), M_DEVBUF, M_WAITOK | M_ZERO); + /* + * This should be the upstream bridge; pci_upstream_bridge() + * handles that case on demand as otherwise we'll shadow the + * entire PCI hierarchy. + */ pdev->bus->self = pdev; pdev->bus->number = pci_get_bus(dev); pdev->bus->domain = pci_get_domain(dev); @@ -301,6 +306,8 @@ lkpinew_pci_dev_release(struct device *dev) pdev = to_pci_dev(dev); if (pdev->root != NULL) pci_dev_put(pdev->root); + if (pdev->bus->self != pdev) + pci_dev_put(pdev->bus->self); free(pdev->bus, M_DEVBUF); free(pdev, M_DEVBUF); }