From owner-svn-src-stable-10@freebsd.org Fri May 12 03:44:21 2017 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 75D07D69988; Fri, 12 May 2017 03:44:21 +0000 (UTC) (envelope-from sephe@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 mx1.freebsd.org (Postfix) with ESMTPS id 2D755899; Fri, 12 May 2017 03:44:21 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4C3iKWm003548; Fri, 12 May 2017 03:44:20 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4C3iKok003547; Fri, 12 May 2017 03:44:20 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201705120344.v4C3iKok003547@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 12 May 2017 03:44:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r318208 - stable/10/sys/amd64/pci X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 May 2017 03:44:21 -0000 Author: sephe Date: Fri May 12 03:44:20 2017 New Revision: 318208 URL: https://svnweb.freebsd.org/changeset/base/318208 Log: MFC 317786 pcicfg: Fix direct calls of pci_cfg{read,write} on systems w/o PCI host bridge. Reported by: dexuan@ Reviewed by: jhb@ Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D10564 Modified: stable/10/sys/amd64/pci/pci_cfgreg.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/amd64/pci/pci_cfgreg.c ============================================================================== --- stable/10/sys/amd64/pci/pci_cfgreg.c Fri May 12 03:06:45 2017 (r318207) +++ stable/10/sys/amd64/pci/pci_cfgreg.c Fri May 12 03:44:20 2017 (r318208) @@ -64,6 +64,7 @@ static vm_offset_t pcie_base; static int pcie_minbus, pcie_maxbus; static uint32_t pcie_badslots; static struct mtx pcicfg_mtx; +MTX_SYSINIT(pcicfg_mtx, &pcicfg_mtx, "pcicfg_mtx", MTX_SPIN); static int mcfg_enable = 1; TUNABLE_INT("hw.pci.mcfg", &mcfg_enable); SYSCTL_INT(_hw_pci, OID_AUTO, mcfg, CTLFLAG_RDTUN, &mcfg_enable, 0, @@ -75,15 +76,9 @@ SYSCTL_INT(_hw_pci, OID_AUTO, mcfg, CTLF int pci_cfgregopen(void) { - static int once = 0; uint64_t pciebar; uint16_t did, vid; - if (!once) { - mtx_init(&pcicfg_mtx, "pcicfg", NULL, MTX_SPIN); - once = 1; - } - if (cfgmech != CFGMECH_NONE) return (1); cfgmech = CFGMECH_1; @@ -139,6 +134,9 @@ pci_cfgregread(int bus, int slot, int fu { uint32_t line; + if (cfgmech == CFGMECH_NONE) + return (0xffffffff); + /* * Some BIOS writers seem to want to ignore the spec and put * 0 in the intline rather than 255 to indicate none. Some use @@ -163,6 +161,9 @@ void pci_cfgregwrite(int bus, int slot, int func, int reg, u_int32_t data, int bytes) { + if (cfgmech == CFGMECH_NONE) + return; + if (cfgmech == CFGMECH_PCIE && (bus >= pcie_minbus && bus <= pcie_maxbus) && (bus != 0 || !(1 << slot & pcie_badslots)))