Source-Changes-HG archive

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

[src/trunk]: src/sys Add to pci_bus_devorder() an argument that tells the num...



details:   https://anonhg.NetBSD.org/src/rev/8b6dc7c2326c
branches:  trunk
changeset: 768687:8b6dc7c2326c
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Wed Aug 24 20:27:35 2011 +0000

description:
Add to pci_bus_devorder() an argument that tells the number of slots
available in the devs array.  Change the type of the devs array from
char to uint8_t.  Treat the return value of pci_bus_devorder() as the
number of slots that it filled.

Don't use the __PCI_BUS_DEVORDER #definition to configure the kernel
but let the linker do it.  Make pci_bus_devorder() available on all
architectures by adding a default implementation that will DTRT on
all architectures but hpcmips, the only architecture to #define
__PCI_BUS_DEVORDER.  On hpcmips, adapt the implementation to the new
calling convention.

XXX I can compile an hpcmips GENERIC kernel, but I don't have a
XXX hpcmips box to test it on.

diffstat:

 sys/arch/hpcmips/conf/files.hpcmips    |   4 ++-
 sys/arch/hpcmips/include/pci_machdep.h |  13 +--------
 sys/arch/hpcmips/pci/pci_machdep.c     |  16 ++++++++++++
 sys/arch/hpcmips/vr/vrc4172pci.c       |  20 ++++++--------
 sys/arch/hpcmips/vr/vrpciu.c           |  31 +++++++++++++++--------
 sys/dev/pci/files.pci                  |   3 +-
 sys/dev/pci/pci.c                      |  21 ++++++---------
 sys/dev/pci/pci_stub.c                 |  45 ++++++++++++++++++++++++++++++++++
 sys/dev/pci/pciconf.c                  |  23 ++++++----------
 sys/dev/pci/pcivar.h                   |   3 +-
 10 files changed, 116 insertions(+), 63 deletions(-)

diffs (truncated from 386 to 300 lines):

diff -r 64083f2136e7 -r 8b6dc7c2326c sys/arch/hpcmips/conf/files.hpcmips
--- a/sys/arch/hpcmips/conf/files.hpcmips       Wed Aug 24 20:13:56 2011 +0000
+++ b/sys/arch/hpcmips/conf/files.hpcmips       Wed Aug 24 20:27:35 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.hpcmips,v 1.105 2011/03/16 13:23:41 tsutsui Exp $
+#      $NetBSD: files.hpcmips,v 1.106 2011/08/24 20:27:36 dyoung Exp $
 
 # maxpartitions must be first item in files.${ARCH}.
 maxpartitions 8
@@ -455,4 +455,6 @@
 attach optpoint at txspiif
 file arch/hpcmips/dev/optpoint.c       optpoint
 
+file arch/hpcmips/pci/pci_machdep.c
+
 include "arch/hpcmips/conf/majors.hpcmips"
diff -r 64083f2136e7 -r 8b6dc7c2326c sys/arch/hpcmips/include/pci_machdep.h
--- a/sys/arch/hpcmips/include/pci_machdep.h    Wed Aug 24 20:13:56 2011 +0000
+++ b/sys/arch/hpcmips/include/pci_machdep.h    Wed Aug 24 20:27:35 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_machdep.h,v 1.6 2005/12/11 12:17:33 christos Exp $ */
+/*     $NetBSD: pci_machdep.h,v 1.7 2011/08/24 20:27:36 dyoung Exp $   */
 
 /*-
  * Copyright (c) 2001 Enami Tsugutomo.
@@ -31,11 +31,6 @@
  */
 
 /*
- * We want to control both device probe order.
- */
-#define        __PCI_BUS_DEVORDER
-
-/*
  * Types provided to machine-independent PCI code
  */
 typedef struct hpcmips_pci_chipset *pci_chipset_tag_t;
@@ -57,7 +52,7 @@
        void (*pc_attach_hook)(struct device *, struct device *,
            struct pcibus_attach_args *);
        int (*pc_bus_maxdevs)(pci_chipset_tag_t, int);
-       int (*pc_bus_devorder)(pci_chipset_tag_t, int, char *);
+       int (*pc_bus_devorder)(pci_chipset_tag_t, int, uint8_t *, int);
        pcitag_t (*pc_make_tag)(pci_chipset_tag_t, int, int, int);
        void (*pc_decompose_tag)(pci_chipset_tag_t, pcitag_t, int *, int *,
            int *);
@@ -79,10 +74,6 @@
     (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
 #define        pci_bus_maxdevs(c, b)                                           \
     (*(c)->pc_bus_maxdevs)((c), (b))
-#ifdef __PCI_BUS_DEVORDER
-#define        pci_bus_devorder(c, b, d)                                       \
-    (*(c)->pc_bus_devorder)((c), (b), (d))
-#endif
 #define        pci_make_tag(c, b, d, f)                                        \
     (*(c)->pc_make_tag)((c), (b), (d), (f))
 #define        pci_decompose_tag(c, t, bp, dp, fp)                             \
diff -r 64083f2136e7 -r 8b6dc7c2326c sys/arch/hpcmips/pci/pci_machdep.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcmips/pci/pci_machdep.c        Wed Aug 24 20:27:35 2011 +0000
@@ -0,0 +1,16 @@
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.1 2011/08/24 20:27:36 dyoung Exp $");
+
+#include "opt_pci.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+int
+pci_bus_devorder(pci_chipset_tag_t pc, int bus, uint8_t *devs, int maxdevs)
+{
+       return (*pc->pc_bus_devorder)(pc, bus, devs, maxdevs);
+}
diff -r 64083f2136e7 -r 8b6dc7c2326c sys/arch/hpcmips/vr/vrc4172pci.c
--- a/sys/arch/hpcmips/vr/vrc4172pci.c  Wed Aug 24 20:13:56 2011 +0000
+++ b/sys/arch/hpcmips/vr/vrc4172pci.c  Wed Aug 24 20:27:35 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vrc4172pci.c,v 1.14 2011/05/17 17:34:49 dyoung Exp $   */
+/*     $NetBSD: vrc4172pci.c,v 1.15 2011/08/24 20:27:36 dyoung Exp $   */
 
 /*-
  * Copyright (c) 2002 TAKEMURA Shin
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vrc4172pci.c,v 1.14 2011/05/17 17:34:49 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vrc4172pci.c,v 1.15 2011/08/24 20:27:36 dyoung Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -81,7 +81,7 @@
 static void    vrc4172pci_attach_hook(struct device *, struct device *,
                    struct pcibus_attach_args *);
 static int     vrc4172pci_bus_maxdevs(pci_chipset_tag_t, int);
-static int     vrc4172pci_bus_devorder(pci_chipset_tag_t, int, char *);
+static int     vrc4172pci_bus_devorder(pci_chipset_tag_t, int, uint8_t *, int);
 static pcitag_t        vrc4172pci_make_tag(pci_chipset_tag_t, int, int, int);
 static void    vrc4172pci_decompose_tag(pci_chipset_tag_t, pcitag_t, int *,
                    int *, int *);
@@ -224,15 +224,13 @@
 }
 
 int
-vrc4172pci_bus_devorder(pci_chipset_tag_t pc, int busno, char *devs)
+vrc4172pci_bus_devorder(pci_chipset_tag_t pc, int busno, uint8_t *devs,
+    int maxdevs)
 {
-       int i;
-
-       *devs++ = 0;
-       for (i = 1; i < 32; i++)
-               *devs++ = -1;
-
-       return (1);
+       if (maxdevs <= 0)
+               return 0;
+       devs[0] = 0;
+       return 1;
 }
 
 pcitag_t
diff -r 64083f2136e7 -r 8b6dc7c2326c sys/arch/hpcmips/vr/vrpciu.c
--- a/sys/arch/hpcmips/vr/vrpciu.c      Wed Aug 24 20:13:56 2011 +0000
+++ b/sys/arch/hpcmips/vr/vrpciu.c      Wed Aug 24 20:27:35 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vrpciu.c,v 1.18 2011/05/17 17:34:50 dyoung Exp $       */
+/*     $NetBSD: vrpciu.c,v 1.19 2011/08/24 20:27:36 dyoung Exp $       */
 
 /*-
  * Copyright (c) 2001 Enami Tsugutomo.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vrpciu.c,v 1.18 2011/05/17 17:34:50 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vrpciu.c,v 1.19 2011/08/24 20:27:36 dyoung Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -84,7 +84,7 @@
 static void    vrpciu_attach_hook(struct device *, struct device *,
                    struct pcibus_attach_args *);
 static int     vrpciu_bus_maxdevs(pci_chipset_tag_t, int);
-static int     vrpciu_bus_devorder(pci_chipset_tag_t, int, char *);
+static int     vrpciu_bus_devorder(pci_chipset_tag_t, int, uint8_t *, int);
 static pcitag_t        vrpciu_make_tag(pci_chipset_tag_t, int, int, int);
 static void    vrpciu_decompose_tag(pci_chipset_tag_t, pcitag_t, int *, int *,
                    int *);
@@ -358,32 +358,41 @@
 }
 
 int
-vrpciu_bus_devorder(pci_chipset_tag_t pc, int busno, char *devs)
+vrpciu_bus_devorder(pci_chipset_tag_t pc, int busno, uint8_t *devs, int maxdevs)
 {
-       int i, dev;
+       int dev, i, n;
+       uint8_t *devn;
        char priorities[32];
        static pcireg_t ids[] = {
                /* these devices should be attached first */
                PCI_ID_CODE(PCI_VENDOR_NEC, PCI_PRODUCT_NEC_VRC4173_BCU),
        };
 
+       n = MIN(32, maxdevs);
+       if (n <= 0)
+               return 0;
+
+       devn = devs + n;
+
        /* scan PCI devices and check the id table */
        memset(priorities, 0, sizeof(priorities));
        for (dev = 0; dev < 32; dev++) {
                pcireg_t id;
-               id = pci_conf_read(pc, pci_make_tag(pc, 0, dev, 0),PCI_ID_REG);
-               for (i = 0; i < sizeof(ids)/sizeof(*ids); i++)
+               id = pci_conf_read(pc, pci_make_tag(pc, 0, dev, 0), PCI_ID_REG);
+               for (i = 0; i < __arraycount(ids); i++)
                        if (id == ids[i])
                                priorities[dev] = 1;
        }
 
        /* fill order array */
-       for (i = 1; 0 <= i; i--)
-               for (dev = 0; dev < 32; dev++)
-                       if (priorities[dev] == i)
+       for (i = 1; 0 <= i; i--) {
+               for (dev = 0; dev < 32; dev++) {
+                       if (priorities[dev] == i && devs != devn)
                                *devs++ = dev;
+               }
+       }
 
-       return (32);
+       return n;
 }
 
 pcitag_t
diff -r 64083f2136e7 -r 8b6dc7c2326c sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci     Wed Aug 24 20:13:56 2011 +0000
+++ b/sys/dev/pci/files.pci     Wed Aug 24 20:27:35 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pci,v 1.345 2011/08/12 22:02:56 dyoung Exp $
+#      $NetBSD: files.pci,v 1.346 2011/08/24 20:27:35 dyoung Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -21,6 +21,7 @@
 file   dev/pci/pci_map.c               pci
 file   dev/pci/pci_quirks.c            pci
 file   dev/pci/pci_subr.c              pci
+file   dev/pci/pci_stub.c              pci
 file   dev/pci/pci_usrreq.c            pci
 file   dev/pci/pciconf.c               pci & pci_netbsd_configure
 
diff -r 64083f2136e7 -r 8b6dc7c2326c sys/dev/pci/pci.c
--- a/sys/dev/pci/pci.c Wed Aug 24 20:13:56 2011 +0000
+++ b/sys/dev/pci/pci.c Wed Aug 24 20:27:35 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci.c,v 1.140 2011/05/17 17:34:54 dyoung Exp $ */
+/*     $NetBSD: pci.c,v 1.141 2011/08/24 20:27:35 dyoung Exp $ */
 
 /*
  * Copyright (c) 1995, 1996, 1997, 1998
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.140 2011/05/17 17:34:54 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.141 2011/08/24 20:27:35 dyoung Exp $");
 
 #include "opt_pci.h"
 
@@ -542,18 +542,13 @@
        const struct pci_quirkdata *qd;
        pcireg_t id, bhlcr;
        pcitag_t tag;
-#ifdef __PCI_BUS_DEVORDER
-       char devs[32];
-       int i;
-#endif
+       uint8_t devs[32];
+       int i, n;
 
-#ifdef __PCI_BUS_DEVORDER
-       pci_bus_devorder(sc->sc_pc, sc->sc_bus, devs);
-       for (i = 0; (device = devs[i]) < 32 && device >= 0; i++)
-#else
-       for (device = 0; device < sc->sc_maxndevs; device++)
-#endif
-       {
+       n = pci_bus_devorder(sc->sc_pc, sc->sc_bus, devs, __arraycount(devs));
+       for (i = 0; i < n; i++) {
+               device = devs[i];
+
                if ((locators[PCICF_DEV] != PCICF_DEV_DEFAULT) &&
                    (locators[PCICF_DEV] != device))
                        continue;
diff -r 64083f2136e7 -r 8b6dc7c2326c sys/dev/pci/pci_stub.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/pci_stub.c    Wed Aug 24 20:27:35 2011 +0000
@@ -0,0 +1,45 @@
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: pci_stub.c,v 1.1 2011/08/24 20:27:35 dyoung Exp $");
+
+#include "opt_pci.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+int default_pci_bus_devorder(pci_chipset_tag_t, int, uint8_t *, int);
+int default_pci_chipset_tag_create(pci_chipset_tag_t, uint64_t,
+    const struct pci_overrides *, void *, pci_chipset_tag_t *);
+void default_pci_chipset_tag_destroy(pci_chipset_tag_t);
+
+__strict_weak_alias(pci_bus_devorder, default_pci_bus_devorder);
+__strict_weak_alias(pci_chipset_tag_create, default_pci_chipset_tag_create);
+__strict_weak_alias(pci_chipset_tag_destroy, default_pci_chipset_tag_destroy);
+
+int
+default_pci_bus_devorder(pci_chipset_tag_t pc, int bus, uint8_t *devs,
+    int maxdevs)
+{
+       int i, n;
+
+       n = MIN(pci_bus_maxdevs(pc, bus), maxdevs);
+       for (i = 0; i < n; i++)
+               devs[i] = i;
+
+       return n;
+}



Home | Main Index | Thread Index | Old Index