From owner-svn-src-head@FreeBSD.ORG Sat Sep 14 17:17:33 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 0FFBD97D; Sat, 14 Sep 2013 17:17:33 +0000 (UTC) (envelope-from dumbbell@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E0E342071; Sat, 14 Sep 2013 17:17:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r8EHHWDF056899; Sat, 14 Sep 2013 17:17:32 GMT (envelope-from dumbbell@svn.freebsd.org) Received: (from dumbbell@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r8EHHWcc056898; Sat, 14 Sep 2013 17:17:32 GMT (envelope-from dumbbell@svn.freebsd.org) Message-Id: <201309141717.r8EHHWcc056898@svn.freebsd.org> From: Jean-Sebastien Pedron Date: Sat, 14 Sep 2013 17:17:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r255571 - head/sys/dev/pci X-SVN-Group: head 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.14 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: Sat, 14 Sep 2013 17:17:33 -0000 Author: dumbbell Date: Sat Sep 14 17:17:32 2013 New Revision: 255571 URL: http://svnweb.freebsd.org/changeset/base/255571 Log: vgapci: Use vga_pci_alloc_resource() to map PCI Expansion ROM This is cleaner and fixes Video BIOS mapping when the given device isn't the boot display. Submitted by: jhb@ Approved by: re (kib) Modified: head/sys/dev/pci/vga_pci.c Modified: head/sys/dev/pci/vga_pci.c ============================================================================== --- head/sys/dev/pci/vga_pci.c Sat Sep 14 15:29:06 2013 (r255570) +++ head/sys/dev/pci/vga_pci.c Sat Sep 14 17:17:32 2013 (r255571) @@ -67,6 +67,12 @@ struct vga_pci_softc { SYSCTL_DECL(_hw_pci); +static struct vga_resource *lookup_res(struct vga_pci_softc *sc, int rid); +static struct resource *vga_pci_alloc_resource(device_t dev, device_t child, + int type, int *rid, u_long start, u_long end, u_long count, u_int flags); +static int vga_pci_release_resource(device_t dev, device_t child, int type, + int rid, struct resource *r); + int vga_pci_default_unit = -1; TUNABLE_INT("hw.pci.default_vgapci_unit", &vga_pci_default_unit); SYSCTL_INT(_hw_pci, OID_AUTO, default_vgapci_unit, CTLFLAG_RDTUN, @@ -80,7 +86,6 @@ vga_pci_is_boot_display(device_t dev) * Return true if the given device is the default display used * at boot time. */ - return ( (pci_get_class(dev) == PCIC_DISPLAY || (pci_get_class(dev) == PCIC_OLD && @@ -111,7 +116,8 @@ vga_pci_map_bios(device_t dev, size_t *s #endif rid = PCIR_BIOS; - res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); + res = vga_pci_alloc_resource(dev, NULL, SYS_RES_MEMORY, &rid, 0ul, + ~0ul, 1, RF_ACTIVE); if (res == NULL) { return (NULL); } @@ -123,8 +129,7 @@ vga_pci_map_bios(device_t dev, size_t *s void vga_pci_unmap_bios(device_t dev, void *bios) { - int rid; - struct resource *res; + struct vga_resource *vr; if (bios == NULL) { return; @@ -140,25 +145,15 @@ vga_pci_unmap_bios(device_t dev, void *b #endif /* - * FIXME: We returned only the virtual address of the resource - * to the caller. Now, to get the resource struct back, we - * allocate it again: the struct exists once in memory in - * device softc. Therefore, we release twice now to release the - * reference we just obtained to get the structure back and the - * caller's reference. + * Look up the PCIR_BIOS resource in our softc. It should match + * the address we returned previously. */ - - rid = PCIR_BIOS; - res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - - KASSERT(res != NULL, - ("%s: Can't get BIOS resource back", __func__)); - KASSERT(bios == rman_get_virtual(res), - ("%s: Given BIOS address doesn't match " - "resource virtual address", __func__)); - - bus_release_resource(dev, SYS_RES_MEMORY, rid, bios); - bus_release_resource(dev, SYS_RES_MEMORY, rid, bios); + vr = lookup_res(device_get_softc(dev), PCIR_BIOS); + KASSERT(vr->vr_res != NULL, ("vga_pci_unmap_bios: bios not mapped")); + KASSERT(rman_get_virtual(vr->vr_res) == bios, + ("vga_pci_unmap_bios: mismatch")); + vga_pci_release_resource(dev, NULL, SYS_RES_MEMORY, PCIR_BIOS, + vr->vr_res); } static int