From owner-svn-src-head@freebsd.org Tue Aug 1 10:47:45 2017 Return-Path: Delivered-To: svn-src-head@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 77E36DCFEDD; Tue, 1 Aug 2017 10:47:45 +0000 (UTC) (envelope-from royger@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 4731E70DDB; Tue, 1 Aug 2017 10:47:45 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v71Alisw077749; Tue, 1 Aug 2017 10:47:44 GMT (envelope-from royger@FreeBSD.org) Received: (from royger@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v71AliG9077748; Tue, 1 Aug 2017 10:47:44 GMT (envelope-from royger@FreeBSD.org) Message-Id: <201708011047.v71AliG9077748@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: royger set sender to royger@FreeBSD.org using -f From: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Date: Tue, 1 Aug 2017 10:47:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r321863 - head/sys/dev/pci X-SVN-Group: head X-SVN-Commit-Author: royger X-SVN-Commit-Paths: head/sys/dev/pci X-SVN-Commit-Revision: 321863 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.23 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: Tue, 01 Aug 2017 10:47:45 -0000 Author: royger Date: Tue Aug 1 10:47:44 2017 New Revision: 321863 URL: https://svnweb.freebsd.org/changeset/base/321863 Log: pci: fix write order when sizing BARs According to the PCI Local Specification rev. 3.0 in case of a 64-bit BAR both the low and the high parts of the register should be set to ~0 before attempting to read back the size. So far I have found no single device that has problems with the previous approach, but I think it's better to stay on the safe size. This commit should not introduce any functional change. MFC after: 3 weeks Sponsored by: Citrix Systems R&D Reviewed by: jhb Differential revision: https://reviews.freebsd.org/D11750 Modified: head/sys/dev/pci/pci.c Modified: head/sys/dev/pci/pci.c ============================================================================== --- head/sys/dev/pci/pci.c Tue Aug 1 10:46:47 2017 (r321862) +++ head/sys/dev/pci/pci.c Tue Aug 1 10:47:44 2017 (r321863) @@ -2902,13 +2902,21 @@ pci_read_bar(device_t dev, int reg, pci_addr_t *mapp, * Determine the BAR's length by writing all 1's. The bottom * log_2(size) bits of the BAR will stick as 0 when we read * the value back. + * + * NB: according to the PCI Local Bus Specification, rev. 3.0: + * "Software writes 0FFFFFFFFh to both registers, reads them back, + * and combines the result into a 64-bit value." (section 6.2.5.1) + * + * Writes to both registers must be performed before attempting to + * read back the size value. */ + testval = 0; pci_write_config(dev, reg, 0xffffffff, 4); - testval = pci_read_config(dev, reg, 4); if (ln2range == 64) { pci_write_config(dev, reg + 4, 0xffffffff, 4); testval |= (pci_addr_t)pci_read_config(dev, reg + 4, 4) << 32; } + testval |= pci_read_config(dev, reg, 4); /* * Restore the original value of the BAR. We may have reprogrammed