From owner-svn-src-head@freebsd.org Thu Dec 26 21:00:07 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 607731D9127; Thu, 26 Dec 2019 21:00:07 +0000 (UTC) (envelope-from scottl@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 47kMm71vbQz4KbB; Thu, 26 Dec 2019 21:00:07 +0000 (UTC) (envelope-from scottl@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 3CA5D664A; Thu, 26 Dec 2019 21:00:07 +0000 (UTC) (envelope-from scottl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xBQL07Pa001005; Thu, 26 Dec 2019 21:00:07 GMT (envelope-from scottl@FreeBSD.org) Received: (from scottl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xBQL06Tu001003; Thu, 26 Dec 2019 21:00:06 GMT (envelope-from scottl@FreeBSD.org) Message-Id: <201912262100.xBQL06Tu001003@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: scottl set sender to scottl@FreeBSD.org using -f From: Scott Long Date: Thu, 26 Dec 2019 21:00:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356098 - head/sys/dev/pci X-SVN-Group: head X-SVN-Commit-Author: scottl X-SVN-Commit-Paths: head/sys/dev/pci X-SVN-Commit-Revision: 356098 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Dec 2019 21:00:07 -0000 Author: scottl Date: Thu Dec 26 21:00:06 2019 New Revision: 356098 URL: https://svnweb.freebsd.org/changeset/base/356098 Log: Abstract the locking for PCIe hotplug. It still uses Giant so there's no functional change yet. Modified: head/sys/dev/pci/pci_pci.c head/sys/dev/pci/pcib_private.h Modified: head/sys/dev/pci/pci_pci.c ============================================================================== --- head/sys/dev/pci/pci_pci.c Thu Dec 26 19:41:09 2019 (r356097) +++ head/sys/dev/pci/pci_pci.c Thu Dec 26 21:00:06 2019 (r356098) @@ -1174,6 +1174,7 @@ pcib_pcie_intr_hotplug(void *arg) sc = arg; dev = sc->dev; + PCIB_HP_LOCK(sc); old_slot_sta = sc->pcie_slot_sta; sc->pcie_slot_sta = pcie_read_config(dev, PCIER_SLOT_STA, 2); @@ -1221,6 +1222,7 @@ pcib_pcie_intr_hotplug(void *arg) } pcib_pcie_hotplug_update(sc, 0, 0, true); + PCIB_HP_UNLOCK(sc); } static void @@ -1230,7 +1232,7 @@ pcib_pcie_hotplug_task(void *context, int pending) device_t dev; sc = context; - mtx_lock(&Giant); + PCIB_HP_LOCK(sc); dev = sc->dev; if (pcib_hotplug_present(sc) != 0) { if (sc->child == NULL) { @@ -1243,7 +1245,7 @@ pcib_pcie_hotplug_task(void *context, int pending) sc->child = NULL; } } - mtx_unlock(&Giant); + PCIB_HP_UNLOCK(sc); } static void @@ -1252,7 +1254,7 @@ pcib_pcie_ab_timeout(void *arg) struct pcib_softc *sc; sc = arg; - mtx_assert(&Giant, MA_OWNED); + PCIB_HP_LOCK_ASSERT(sc); if (sc->flags & PCIB_DETACH_PENDING) { sc->flags |= PCIB_DETACHING; sc->flags &= ~PCIB_DETACH_PENDING; @@ -1269,7 +1271,7 @@ pcib_pcie_cc_timeout(void *arg) sc = arg; dev = sc->dev; - mtx_assert(&Giant, MA_OWNED); + PCIB_HP_LOCK_ASSERT(sc); sta = pcie_read_config(dev, PCIER_SLOT_STA, 2); if (!(sta & PCIEM_SLOT_STA_CC)) { device_printf(dev, "HotPlug Command Timed Out\n"); @@ -1290,7 +1292,7 @@ pcib_pcie_dll_timeout(void *arg) sc = arg; dev = sc->dev; - mtx_assert(&Giant, MA_OWNED); + PCIB_HP_LOCK_ASSERT(sc); sta = pcie_read_config(dev, PCIER_LINK_STA, 2); if (!(sta & PCIEM_LINK_STA_DL_ACTIVE)) { device_printf(dev, @@ -1345,7 +1347,7 @@ pcib_alloc_pcie_irq(struct pcib_softc *sc) return (ENXIO); } - error = bus_setup_intr(dev, sc->pcie_irq, INTR_TYPE_MISC, + error = bus_setup_intr(dev, sc->pcie_irq, INTR_TYPE_MISC|INTR_MPSAFE, NULL, pcib_pcie_intr_hotplug, sc, &sc->pcie_ihand); if (error) { device_printf(dev, "Failed to setup PCI-e interrupt handler\n"); @@ -1384,6 +1386,7 @@ pcib_setup_hotplug(struct pcib_softc *sc) callout_init(&sc->pcie_cc_timer, 0); callout_init(&sc->pcie_dll_timer, 0); TASK_INIT(&sc->pcie_hp_task, 0, pcib_pcie_hotplug_task, sc); + sc->pcie_hp_lock = &Giant; /* Allocate IRQ. */ if (pcib_alloc_pcie_irq(sc) != 0) Modified: head/sys/dev/pci/pcib_private.h ============================================================================== --- head/sys/dev/pci/pcib_private.h Thu Dec 26 19:41:09 2019 (r356097) +++ head/sys/dev/pci/pcib_private.h Thu Dec 26 21:00:06 2019 (r356098) @@ -141,7 +141,12 @@ struct pcib_softc struct callout pcie_ab_timer; struct callout pcie_cc_timer; struct callout pcie_dll_timer; + struct mtx *pcie_hp_lock; }; + +#define PCIB_HP_LOCK(sc) mtx_lock((sc)->pcie_hp_lock) +#define PCIB_HP_UNLOCK(sc) mtx_unlock((sc)->pcie_hp_lock) +#define PCIB_HP_LOCK_ASSERT(sc) mtx_assert((sc)->pcie_hp_lock, MA_OWNED) #define PCIB_SUPPORTED_ARI_VER 1