From owner-svn-src-all@FreeBSD.ORG Fri Aug 30 14:51:15 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id AFD583FD; Fri, 30 Aug 2013 14:51:15 +0000 (UTC) (envelope-from dumbbell@FreeBSD.org) Received: from mail.made4.biz (unknown [IPv6:2001:41d0:1:7018::1:3]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 494D32AD8; Fri, 30 Aug 2013 14:51:15 +0000 (UTC) Received: from [2001:1b48:10b:cafe:225:64ff:febe:589f] (helo=viking.yzserv.com) by mail.made4.biz with esmtpsa (TLSv1:DHE-RSA-CAMELLIA256-SHA:256) (Exim 4.80.1 (FreeBSD)) (envelope-from ) id 1VFQ2a-000PGq-Pd; Fri, 30 Aug 2013 16:51:13 +0200 Message-ID: <5220B15C.6050203@FreeBSD.org> Date: Fri, 30 Aug 2013 16:51:08 +0200 From: =?ISO-8859-15?Q?Jean-S=E9bastien_P=E9dron?= User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130813 Thunderbird/17.0.8 MIME-Version: 1.0 To: John Baldwin Subject: Re: svn commit: r254882 - head/sys/dev/pci References: <201308251809.r7PI9CsE052978@svn.freebsd.org> <201308261055.17964.jhb@freebsd.org> <521F1E0C.5000404@FreeBSD.org> <201308291007.26828.jhb@freebsd.org> In-Reply-To: <201308291007.26828.jhb@freebsd.org> X-Enigmail-Version: 1.5.1 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="----enig2ETXCTURHJDGLUJQMSAWP" Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Aug 2013 14:51:15 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2ETXCTURHJDGLUJQMSAWP Content-Type: multipart/mixed; boundary="------------090600000304090500090803" This is a multi-part message in MIME format. --------------090600000304090500090803 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable On 29.08.2013 16:07, John Baldwin wrote: > Here is an untested cut at this, it only changes these functions and do= esn't > fix the callers to work with the returned struct resource, etc.: I attached an updated patch including changes to pcivar.h and radeon. However, BUS_ALLOC_RESOURCE() returns NULL in my tests. --=20 Jean-S=E9bastien P=E9dron --------------090600000304090500090803 Content-Type: text/x-patch; name="vgapci.2.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vgapci.2.patch" diff --git a/sys/dev/drm2/radeon/radeon_bios.c b/sys/dev/drm2/radeon/rade= on_bios.c index b9ee4d1..11e9be4 100644 --- a/sys/dev/drm2/radeon/radeon_bios.c +++ b/sys/dev/drm2/radeon/radeon_bios.c @@ -100,6 +100,7 @@ static bool igp_read_bios_from_vram(struct radeon_dev= ice *rdev) =20 static bool radeon_read_bios(struct radeon_device *rdev) { + struct resource *res; uint8_t __iomem *bios; size_t size; =20 @@ -107,10 +108,13 @@ static bool radeon_read_bios(struct radeon_device *= rdev) =20 rdev->bios =3D NULL; /* XXX: some cards may return 0 for rom size? ddx has a workaround */ - bios =3D vga_pci_map_bios(rdev->dev, &size); - if (!bios) { + res =3D vga_pci_map_bios(rdev->dev); + DRM_INFO("%s: res=3D%p\n", __func__, res); + if (!res) { return false; } + bios =3D rman_get_virtual(res); + size =3D rman_get_size(res); DRM_INFO("%s: Map address: %p (%zu bytes)\n", __func__, bios, size); =20 if (size =3D=3D 0 || bios[0] !=3D 0x55 || bios[1] !=3D 0xaa) { @@ -120,11 +124,11 @@ static bool radeon_read_bios(struct radeon_device *= rdev) DRM_INFO("%s: Incorrect BIOS signature: 0x%02X%02X\n", __func__, bios[0], bios[1]); } - vga_pci_unmap_bios(rdev->dev, bios); + vga_pci_unmap_bios(rdev->dev, res); } rdev->bios =3D malloc(size, DRM_MEM_DRIVER, M_WAITOK); memcpy(rdev->bios, bios, size); - vga_pci_unmap_bios(rdev->dev, bios); + vga_pci_unmap_bios(rdev->dev, res); return true; } =20 diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index d733e3b..a8148e9 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -520,8 +520,8 @@ int pci_bar_enabled(device_t dev, struct pci_map *pm)= ; #define VGA_PCI_BIOS_SHADOW_ADDR 0xC0000 #define VGA_PCI_BIOS_SHADOW_SIZE 131072 =20 -int vga_pci_is_boot_display(device_t dev); -void * vga_pci_map_bios(device_t dev, size_t *size); -void vga_pci_unmap_bios(device_t dev, void *bios); +int vga_pci_is_boot_display(device_t dev); +struct resource * vga_pci_map_bios(device_t dev); +void vga_pci_unmap_bios(device_t dev, struct resource *res); =20 #endif /* _PCIVAR_H_ */ diff --git a/sys/dev/pci/vga_pci.c b/sys/dev/pci/vga_pci.c index 94c64c0..59c954e 100644 --- a/sys/dev/pci/vga_pci.c +++ b/sys/dev/pci/vga_pci.c @@ -46,11 +46,6 @@ __FBSDID("$FreeBSD$"); #include #include =20 -#if defined(__amd64__) || defined(__i386__) || defined(__ia64__) -#include -#include -#endif - #include #include =20 @@ -72,95 +67,6 @@ TUNABLE_INT("hw.pci.default_vgapci_unit", &vga_pci_def= ault_unit); SYSCTL_INT(_hw_pci, OID_AUTO, default_vgapci_unit, CTLFLAG_RDTUN, &vga_pci_default_unit, -1, "Default VGA-compatible display"); =20 -int -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) =3D=3D PCIC_DISPLAY || - (pci_get_class(dev) =3D=3D PCIC_OLD && - pci_get_subclass(dev) =3D=3D PCIS_OLD_VGA)) && - device_get_unit(dev) =3D=3D vga_pci_default_unit); -} - -void * -vga_pci_map_bios(device_t dev, size_t *size) -{ - int rid; - struct resource *res; - -#if defined(__amd64__) || defined(__i386__) || defined(__ia64__) - if (vga_pci_is_boot_display(dev)) { - /* - * On x86, the System BIOS copy the default display - * device's Video BIOS at a fixed location in system - * memory (0xC0000, 128 kBytes long) at boot time. - * - * We use this copy for the default boot device, because - * the original ROM may not be valid after boot. - */ - - *size =3D VGA_PCI_BIOS_SHADOW_SIZE; - return (pmap_mapbios(VGA_PCI_BIOS_SHADOW_ADDR, *size)); - } -#endif - - rid =3D PCIR_BIOS; - res =3D bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - if (res =3D=3D NULL) { - return (NULL); - } - - *size =3D rman_get_size(res); - return (rman_get_virtual(res)); -} - -void -vga_pci_unmap_bios(device_t dev, void *bios) -{ - int rid; - struct resource *res; - - if (bios =3D=3D NULL) { - return; - } - -#if defined(__amd64__) || defined(__i386__) || defined(__ia64__) - if (vga_pci_is_boot_display(dev)) { - /* We mapped the BIOS shadow copy located at 0xC0000. */ - pmap_unmapdev((vm_offset_t)bios, VGA_PCI_BIOS_SHADOW_SIZE); - - return; - } -#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. - */ - - rid =3D PCIR_BIOS; - res =3D bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - - KASSERT(res !=3D NULL, - ("%s: Can't get BIOS resource back", __func__)); - KASSERT(bios =3D=3D 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); -} - static int vga_pci_probe(device_t dev) { @@ -327,6 +233,75 @@ vga_pci_release_resource(device_t dev, device_t chil= d, int type, int rid, return (bus_release_resource(dev, type, rid, r)); } =20 +int +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) =3D=3D PCIC_DISPLAY || + (pci_get_class(dev) =3D=3D PCIC_OLD && + pci_get_subclass(dev) =3D=3D PCIS_OLD_VGA)) && + device_get_unit(dev) =3D=3D vga_pci_default_unit); +} + +struct resource * +vga_pci_map_bios(device_t dev) +{ + int rid; + +#if defined(__amd64__) || defined(__i386__) || defined(__ia64__) + if (vga_pci_is_boot_display(dev)) { + /* + * On x86, the System BIOS copy the default display + * device's Video BIOS at a fixed location in system + * memory (0xC0000, 128 kBytes long) at boot time. + * + * We use this copy for the default boot device, because + * the original ROM may not be valid after boot. + * + * Allocate this from our grandparent to by-pass the + * checks for a valid rid in the PCI bus driver as this + * is not a BAR. + */ + rid =3D 1; + return (BUS_ALLOC_RESOURCE(device_get_parent( + device_get_parent(dev)), dev, SYS_RES_MEMORY, &rid, + VGA_PCI_BIOS_SHADOW_ADDR, + VGA_PCI_BIOS_SHADOW_ADDR + VGA_PCI_BIOS_SHADOW_SIZE - 1, + VGA_PCI_BIOS_SHADOW_SIZE, RF_ACTIVE)); + } +#endif + + rid =3D PCIR_BIOS; + return (vga_pci_alloc_resource(dev, NULL, SYS_RES_MEMORY, &rid, 0ul, + ~0ul, 1, RF_ACTIVE)); +} + +void +vga_pci_unmap_bios(device_t dev, struct resource *res) +{ + + if (res =3D=3D NULL) { + return; + } + +#if defined(__amd64__) || defined(__i386__) || defined(__ia64__) + if (vga_pci_is_boot_display(dev)) { + /* We mapped the BIOS shadow copy located at 0xC0000. */ + BUS_RELEASE_RESOURCE(device_get_parent( + device_get_parent(dev)), dev, SYS_RES_MEMORY, 1, res); + + return; + } +#endif + vga_pci_release_resource(dev, NULL, SYS_RES_MEMORY, PCIR_BIOS, res); +} + /* PCI interface. */ =20 static uint32_t --------------090600000304090500090803-- ------enig2ETXCTURHJDGLUJQMSAWP Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (FreeBSD) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlIgsWAACgkQa+xGJsFYOlMSWQCgghxVpqRptcq6Elr3q4LwpReL fSgAn3Hx/EiAuclofsPShxVwLBxDwR1g =Nab5 -----END PGP SIGNATURE----- ------enig2ETXCTURHJDGLUJQMSAWP--