Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Determine BAR type with pci_mapreg_probe() inste...



details:   https://anonhg.NetBSD.org/src/rev/4a77220006f4
branches:  trunk
changeset: 762020:4a77220006f4
user:      phx <phx%NetBSD.org@localhost>
date:      Sun Feb 13 11:00:58 2011 +0000

description:
Determine BAR type with pci_mapreg_probe() instead of pci_mapreg_type(),
to skip unimplemented BARs.
Do not probe non-BAR registers (like subsystem id). This fixes potential
panics in pci_mem_find().

diffstat:

 sys/dev/pci/genfb_pci.c |  18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diffs (50 lines):

diff -r eae924cf2a79 -r 4a77220006f4 sys/dev/pci/genfb_pci.c
--- a/sys/dev/pci/genfb_pci.c   Sun Feb 13 08:34:00 2011 +0000
+++ b/sys/dev/pci/genfb_pci.c   Sun Feb 13 11:00:58 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: genfb_pci.c,v 1.30 2011/02/10 11:35:20 jmcneill Exp $ */
+/*     $NetBSD: genfb_pci.c,v 1.31 2011/02/13 11:00:58 phx Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: genfb_pci.c,v 1.30 2011/02/10 11:35:20 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb_pci.c,v 1.31 2011/02/13 11:00:58 phx Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -145,7 +145,16 @@
        bar = PCI_MAPREG_START;
        while (bar <= PCI_MAPREG_ROM) {
 
-               type = pci_mapreg_type(sc->sc_pc, sc->sc_pcitag, bar);
+               sc->sc_bars[(bar - PCI_MAPREG_START) >> 2] = rom =
+                   pci_conf_read(sc->sc_pc, sc->sc_pcitag, bar);
+
+               if ((bar >= PCI_MAPREG_END && bar < PCI_MAPREG_ROM) ||
+                   pci_mapreg_probe(sc->sc_pc, sc->sc_pcitag, bar, &type)
+                   == 0) {
+                       /* skip unimplemented and non-BAR registers */
+                       bar += 4;
+                       continue;
+               }
                if (PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_MEM || 
                    PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_ROM) {
                        pci_mapreg_info(sc->sc_pc, sc->sc_pcitag, bar, type,
@@ -154,13 +163,10 @@
                            &sc->sc_ranges[idx].flags);
                        idx++;
                }
-               sc->sc_bars[(bar - PCI_MAPREG_START) >> 2] = rom =
-                   pci_conf_read(sc->sc_pc, sc->sc_pcitag, bar);
                if ((bar == PCI_MAPREG_ROM) && (rom != 0)) {
                        pci_conf_write(sc->sc_pc, sc->sc_pcitag, bar, rom |
                            PCI_MAPREG_ROM_ENABLE);
                }
-
                if (PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_MEM &&
                    PCI_MAPREG_MEM_TYPE(type) == PCI_MAPREG_MEM_TYPE_64BIT)
                        bar += 8;



Home | Main Index | Thread Index | Old Index