Date: Fri, 30 Aug 2013 16:51:08 +0200 From: =?ISO-8859-15?Q?Jean-S=E9bastien_P=E9dron?= <dumbbell@FreeBSD.org> To: John Baldwin <jhb@freebsd.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r254882 - head/sys/dev/pci Message-ID: <5220B15C.6050203@FreeBSD.org> In-Reply-To: <201308291007.26828.jhb@freebsd.org> References: <201308251809.r7PI9CsE052978@svn.freebsd.org> <201308261055.17964.jhb@freebsd.org> <521F1E0C.5000404@FreeBSD.org> <201308291007.26828.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <sys/sysctl.h> #include <sys/systm.h> =20 -#if defined(__amd64__) || defined(__i386__) || defined(__ia64__) -#include <vm/vm.h> -#include <vm/pmap.h> -#endif - #include <dev/pci/pcireg.h> #include <dev/pci/pcivar.h> =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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5220B15C.6050203>