From nobody Sun Mar 27 20:14:02 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 C11B51A53497; Sun, 27 Mar 2022 20:14:03 +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 4KRRqZ5cf0z4nqH; Sun, 27 Mar 2022 20:14:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648412043; 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=c7wnk730z6RvZAIZ8unNC3kzPhWrLM4ZFYuz6y0KwHU=; b=X8WDAyqQANrEEhbXJip3a2KQ93KJeGAD+N0DzmCL8Rr9IHJehMxd3m0PWnxAr4bI6uEAHT E4SKOJaV+XQjWmdt4zvlSNBcIVqCSr3EkIRzX92dYbP8kJSU51y+NirqKk3RE0NhDkfIuh sIaMPdeBADp6C5cNxztZcXDMbOKudDw1eOvncfUT8Hmm/whEExV7Gn+23pBlhg5+5xWBQR i/2DNdS++7h6daBcr40FmZGgiOt39RaO8EAutL6XzSJ48i7mX1BOVy+mlmQ71NjLE/HMZb 9rao6G2zHaZk0JBdufeNm0hj4+WhGQ0YV/wGCvATOnln+9J3aAuFTJwR7KzH5Q== 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 665661BCA2; Sun, 27 Mar 2022 20:14:02 +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 22RKE2Sa037166; Sun, 27 Mar 2022 20:14:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22RKE2MY037165; Sun, 27 Mar 2022 20:14:02 GMT (envelope-from git) Date: Sun, 27 Mar 2022 20:14:02 GMT Message-Id: <202203272014.22RKE2MY037165@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: 50136233846e - stable/13 - LinuxKPI: pci: implement pci_upstream_bridge() 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 50136233846e59eeb53c95498fdd4f3e1acf0a16 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648412043; 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=c7wnk730z6RvZAIZ8unNC3kzPhWrLM4ZFYuz6y0KwHU=; b=fiHI8I43gz30N2uhD7xv1kWqzxzxUNwLcQINy1xODp020CzY6Bje+Mmcs5LR7VAuKU7XR9 QOQVQ986Y5k7J+gnu/RP4grHzMkXxMqfeSIWx4AlmBd8QSM/gezE8kFGxWELeG4BvkeMST jcdRj/e9aeEFjIiIbN0G8e77AFIDPRex7Y/QdbPA59WoCRBX5VQu1K9I+OhU7iqedrH98k 6tGgPL/mWnbaOlUAPh4qszro0Ar001yfPWxFYzYWdR5iLKWS2Fka1fcC9S180bSTqejLR1 thIuEN4ltkiuhEcXhlqCxGK+XdSyM+LRJAc1XtRGjUO/6vQM1f/yUQ8VIvXbog== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648412043; a=rsa-sha256; cv=none; b=CNxDjQ6PxZZ8gh5G7F3b7fXGtBRth25WaFNBdkJf+IktBHQjsrAi5QdldS1aizkh5ZcTyI I1enkttr0dc4G0vHQyWecuiXyMA3oG6W5a+Pt/qehJ3jDMtKIc65Mb31xfMo5nZMMhh9zM 2owT/rJp88qRj2mETnEmxW3Wt27ub3ru3G8ZBaG+nbdspS8OaO/jDe9D4RRNSr3kq3AF6u C63yGJvX8hYl8WeYCFremyByhFx8RGA0Umjdhrt8gFKlvEY9K8PWA80xtr7GLWMTTi3ePM LEzXnGTpU4prhuXqT/kzLbEpswwI1HGurrigFajoVMiu5eanzeQYQMaFuqJdOA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=50136233846e59eeb53c95498fdd4f3e1acf0a16 commit 50136233846e59eeb53c95498fdd4f3e1acf0a16 Author: Bjoern A. Zeeb AuthorDate: 2022-02-16 18:04:08 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-03-27 18:08:35 +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. 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) --- 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); }