Module Name: src
Committed By: riastradh
Date: Thu Oct 16 12:31:23 UTC 2014
Modified Files:
src/sys/dev/pci: pci_map.c pcivar.h radeonfb.c
src/sys/external/bsd/drm2/include/linux: pci.h
Log Message:
Generalize pci_find_rom and use it to locate x86 video ROM in drm2.
- Make pci_find_rom take the ROM `BAR' size as a parameter, instead
of using pci_find_mem with the ROM `BAR' to detect the size.
- Use it to find the x86 video ROM in [0xc0000, 0xe0000) in drm2,
when nothing else reports that location.
- Adapt the one other caller in radeonfb, which already has the
maximum ROM size handy (romsz).
XXX pullup to netbsd-7
To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/pci/pci_map.c
cvs rdiff -u -r1.99 -r1.100 src/sys/dev/pci/pcivar.h
cvs rdiff -u -r1.84 -r1.85 src/sys/dev/pci/radeonfb.c
cvs rdiff -u -r1.8 -r1.9 src/sys/external/bsd/drm2/include/linux/pci.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/pci/pci_map.c
diff -u src/sys/dev/pci/pci_map.c:1.30 src/sys/dev/pci/pci_map.c:1.31
--- src/sys/dev/pci/pci_map.c:1.30 Sat Oct 20 06:03:38 2012
+++ src/sys/dev/pci/pci_map.c Thu Oct 16 12:31:23 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_map.c,v 1.30 2012/10/20 06:03:38 matt Exp $ */
+/* $NetBSD: pci_map.c,v 1.31 2014/10/16 12:31:23 riastradh Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_map.c,v 1.30 2012/10/20 06:03:38 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_map.c,v 1.31 2014/10/16 12:31:23 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -347,24 +347,21 @@ pci_mapreg_submap(const struct pci_attac
int
pci_find_rom(const struct pci_attach_args *pa, bus_space_tag_t bst,
- bus_space_handle_t bsh, int type, bus_space_handle_t *romh, bus_size_t *sz)
+ bus_space_handle_t bsh, bus_size_t sz, int type,
+ bus_space_handle_t *romh, bus_size_t *romsz)
{
- bus_size_t romsz, offset = 0, imagesz;
+ bus_size_t offset = 0, imagesz;
uint16_t ptr;
int done = 0;
- if (pci_mem_find(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM,
- PCI_MAPREG_TYPE_ROM, NULL, &romsz, NULL))
- return 1;
-
/*
* no upper bound check; i cannot imagine a 4GB ROM, but
* it appears the spec would allow it!
*/
- if (romsz < 1024)
+ if (sz < 1024)
return 1;
- while (offset < romsz && !done){
+ while (offset < sz && !done){
struct pci_rom_header hdr;
struct pci_rom rom;
@@ -379,7 +376,7 @@ pci_find_rom(const struct pci_attach_arg
ptr = offset + hdr.romh_data_ptr;
- if (ptr > romsz) {
+ if (ptr > sz) {
printf("pci_find_rom: rom data ptr out of range\n");
return 1;
}
@@ -415,7 +412,7 @@ pci_find_rom(const struct pci_attach_arg
(rom.rom_subclass == PCI_SUBCLASS(pa->pa_class)) &&
(rom.rom_interface == PCI_INTERFACE(pa->pa_class)) &&
(rom.rom_code_type == type)) {
- *sz = imagesz;
+ *romsz = imagesz;
bus_space_subregion(bst, bsh, offset, imagesz, romh);
return 0;
}
Index: src/sys/dev/pci/pcivar.h
diff -u src/sys/dev/pci/pcivar.h:1.99 src/sys/dev/pci/pcivar.h:1.100
--- src/sys/dev/pci/pcivar.h:1.99 Sat Mar 29 19:28:25 2014
+++ src/sys/dev/pci/pcivar.h Thu Oct 16 12:31:23 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: pcivar.h,v 1.99 2014/03/29 19:28:25 christos Exp $ */
+/* $NetBSD: pcivar.h,v 1.100 2014/10/16 12:31:23 riastradh Exp $ */
/*
* Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
@@ -271,7 +271,7 @@ int pci_mapreg_map(const struct pci_atta
bus_size_t *);
int pci_find_rom(const struct pci_attach_args *, bus_space_tag_t,
- bus_space_handle_t,
+ bus_space_handle_t, bus_size_t,
int, bus_space_handle_t *, bus_size_t *);
int pci_get_capability(pci_chipset_tag_t, pcitag_t, int, int *, pcireg_t *);
Index: src/sys/dev/pci/radeonfb.c
diff -u src/sys/dev/pci/radeonfb.c:1.84 src/sys/dev/pci/radeonfb.c:1.85
--- src/sys/dev/pci/radeonfb.c:1.84 Tue Jul 22 15:42:59 2014
+++ src/sys/dev/pci/radeonfb.c Thu Oct 16 12:31:23 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: radeonfb.c,v 1.84 2014/07/22 15:42:59 riastradh Exp $ */
+/* $NetBSD: radeonfb.c,v 1.85 2014/10/16 12:31:23 riastradh Exp $ */
/*-
* Copyright (c) 2006 Itronix Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: radeonfb.c,v 1.84 2014/07/22 15:42:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeonfb.c,v 1.85 2014/10/16 12:31:23 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1321,7 +1321,7 @@ radeonfb_loadbios(struct radeonfb_softc
return;
}
- pci_find_rom(pa, romt, romh, PCI_ROM_CODE_TYPE_X86, &biosh,
+ pci_find_rom(pa, romt, romh, romsz, PCI_ROM_CODE_TYPE_X86, &biosh,
&sc->sc_biossz);
if (sc->sc_biossz == 0) {
aprint_verbose("%s: Video BIOS not present\n", XNAME(sc));
Index: src/sys/external/bsd/drm2/include/linux/pci.h
diff -u src/sys/external/bsd/drm2/include/linux/pci.h:1.8 src/sys/external/bsd/drm2/include/linux/pci.h:1.9
--- src/sys/external/bsd/drm2/include/linux/pci.h:1.8 Wed Aug 13 20:56:21 2014
+++ src/sys/external/bsd/drm2/include/linux/pci.h Thu Oct 16 12:31:23 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: pci.h,v 1.8 2014/08/13 20:56:21 riastradh Exp $ */
+/* $NetBSD: pci.h,v 1.9 2014/10/16 12:31:23 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -430,6 +430,36 @@ pci_unmap_rom(struct pci_dev *pdev, void
pdev->pd_rom_vaddr = NULL;
}
+/* XXX Whattakludge! Should move this in sys/arch/. */
+static int
+pci_map_rom_md(struct pci_dev *pdev)
+{
+#if defined(__i386__) || defined(__x86_64__) || defined(__ia64__)
+ const bus_addr_t rom_base = 0xc0000;
+ const bus_size_t rom_size = 0x20000;
+ bus_space_handle_t rom_bsh;
+ int error;
+
+ if (PCI_CLASS(pdev->pd_pa.pa_class) != PCI_CLASS_DISPLAY)
+ return ENXIO;
+ if (PCI_SUBCLASS(pdev->pd_pa.pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
+ return ENXIO;
+ /* XXX Check whether this is the primary VGA card? */
+ error = bus_space_map(pdev->pd_pa.pa_memt, rom_base, rom_size,
+ (BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE), &rom_bsh);
+ if (error)
+ return ENXIO;
+
+ pdev->pd_rom_bst = pdev->pd_pa.pa_memt;
+ pdev->pd_rom_bsh = rom_bsh;
+ pdev->pd_rom_size = rom_size;
+
+ return 0;
+#else
+ return ENXIO;
+#endif
+}
+
static inline void __pci_rom_iomem *
pci_map_rom(struct pci_dev *pdev, size_t *sizep)
{
@@ -441,13 +471,14 @@ pci_map_rom(struct pci_dev *pdev, size_t
if (pci_mapreg_map(&pdev->pd_pa, PCI_MAPREG_ROM, PCI_MAPREG_TYPE_ROM,
(BUS_SPACE_MAP_PREFETCHABLE | BUS_SPACE_MAP_LINEAR),
&pdev->pd_rom_bst, &pdev->pd_rom_bsh, NULL, &pdev->pd_rom_size)
- != 0)
+ != 0 &&
+ pci_map_rom_md(pdev) != 0)
return NULL;
pdev->pd_kludges |= NBPCI_KLUDGE_MAP_ROM;
/* XXX This type is obviously wrong in general... */
if (pci_find_rom(&pdev->pd_pa, pdev->pd_rom_bst, pdev->pd_rom_bsh,
- PCI_ROM_CODE_TYPE_X86, &bsh, &size)) {
+ pdev->pd_rom_size, PCI_ROM_CODE_TYPE_X86, &bsh, &size)) {
pci_unmap_rom(pdev, NULL);
return NULL;
}