From nobody Sun Oct 10 13:38:18 2021 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 A430312DB8CE; Sun, 10 Oct 2021 13:38:19 +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 4HS30W2MZkz4jxF; Sun, 10 Oct 2021 13:38:19 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B39136AE0; Sun, 10 Oct 2021 13:38:18 +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 19ADcISL036000; Sun, 10 Oct 2021 13:38:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19ADcIYu035999; Sun, 10 Oct 2021 13:38:18 GMT (envelope-from git) Date: Sun, 10 Oct 2021 13:38:18 GMT Message-Id: <202110101338.19ADcIYu035999@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jessica Clarke Subject: git: 398c8572b8be - stable/13 - pci_pci: Support growing bus ranges in bus_adjust_resource for NEW_PCIB 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: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 398c8572b8be32658c0d4f76481e01637d88d602 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=398c8572b8be32658c0d4f76481e01637d88d602 commit 398c8572b8be32658c0d4f76481e01637d88d602 Author: Jessica Clarke AuthorDate: 2021-10-03 18:35:26 +0000 Commit: Jessica Clarke CommitDate: 2021-10-10 13:36:54 +0000 pci_pci: Support growing bus ranges in bus_adjust_resource for NEW_PCIB This is the same underlying problem as 262459806433, just for bus ranges rather than windows. SiFive's HiFive Unmatched has the following topology: Root Port <---> Bridge <---> Bridge <-+-> Bridge <---> (Unused) (pcib0) (pcib1) (pcib2) | (pcib3) +-> Bridge <---> xHCI | (pcib4) +-> Bridge <---> M.2 E-key | (pcib5) +-> Bridge <---> M.2 M-key | (pcib6) +-> Bridge <---> x16 slot (pcib7) If a device is plugged into the x16 slot that itself has a bridge, such as many graphics cards, we currently fail to allocate a bus number for its child bus (and so pcib_attach_child skips adding a child bus for further enumeration) as, when the new child bridge attaches, it attempts to allocate a bus number from its parent (pcib7) which in turn attempts to grow its own bus range by calling bus_adjust_resource on its own parent (pcib2) whose bus rman cannot accommodate the request and needs to itself be extended by calling its own parent (pcib1). Note that pcib3-7 do not face the same issue when they attach since pcib1 ends up managing bus numbers 1-255 from the beginning and so never needs to grow its own range. Reviewed by: jhb, mav MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D32011 (cherry picked from commit 31776afdc79d5fb1ea211cc2a69c17c62b3dc8ff) --- sys/dev/pci/pci_pci.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sys/dev/pci/pci_pci.c b/sys/dev/pci/pci_pci.c index 2b86f2f50e11..cecf75024d3f 100644 --- a/sys/dev/pci/pci_pci.c +++ b/sys/dev/pci/pci_pci.c @@ -2364,7 +2364,20 @@ pcib_adjust_resource(device_t bus, device_t child, int type, struct resource *r, start, end)); #ifdef PCI_RES_BUS - if (type != PCI_RES_BUS) + if (type == PCI_RES_BUS) { + /* + * If our bus range isn't big enough to grow the sub-allocation + * then we need to grow our bus range. Any request that would + * require us to decrease the start of our own bus range is + * invalid, we can only extend the end; ignore such requests + * and let rman_adjust_resource fail below. + */ + if (start >= sc->bus.sec && end > sc->bus.sub) { + error = pcib_grow_subbus(&sc->bus, end); + if (error != 0) + return (error); + } + } else #endif { /*