Module Name: src Committed By: dyoung Date: Wed Aug 24 20:27:36 UTC 2011
Modified Files: src/sys/arch/hpcmips/conf: files.hpcmips src/sys/arch/hpcmips/include: pci_machdep.h src/sys/arch/hpcmips/vr: vrc4172pci.c vrpciu.c src/sys/dev/pci: files.pci pci.c pciconf.c pcivar.h Added Files: src/sys/arch/hpcmips/pci: pci_machdep.c src/sys/dev/pci: pci_stub.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.105 -r1.106 src/sys/arch/hpcmips/conf/files.hpcmips cvs rdiff -u -r1.6 -r1.7 src/sys/arch/hpcmips/include/pci_machdep.h cvs rdiff -u -r0 -r1.1 src/sys/arch/hpcmips/pci/pci_machdep.c cvs rdiff -u -r1.14 -r1.15 src/sys/arch/hpcmips/vr/vrc4172pci.c cvs rdiff -u -r1.18 -r1.19 src/sys/arch/hpcmips/vr/vrpciu.c cvs rdiff -u -r1.345 -r1.346 src/sys/dev/pci/files.pci cvs rdiff -u -r1.140 -r1.141 src/sys/dev/pci/pci.c cvs rdiff -u -r0 -r1.1 src/sys/dev/pci/pci_stub.c cvs rdiff -u -r1.32 -r1.33 src/sys/dev/pci/pciconf.c cvs rdiff -u -r1.94 -r1.95 src/sys/dev/pci/pcivar.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/arch/hpcmips/conf/files.hpcmips diff -u src/sys/arch/hpcmips/conf/files.hpcmips:1.105 src/sys/arch/hpcmips/conf/files.hpcmips:1.106 --- src/sys/arch/hpcmips/conf/files.hpcmips:1.105 Wed Mar 16 13:23:41 2011 +++ src/sys/arch/hpcmips/conf/files.hpcmips Wed Aug 24 20:27:36 2011 @@ -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" Index: src/sys/arch/hpcmips/include/pci_machdep.h diff -u src/sys/arch/hpcmips/include/pci_machdep.h:1.6 src/sys/arch/hpcmips/include/pci_machdep.h:1.7 --- src/sys/arch/hpcmips/include/pci_machdep.h:1.6 Sun Dec 11 12:17:33 2005 +++ src/sys/arch/hpcmips/include/pci_machdep.h Wed Aug 24 20:27:36 2011 @@ -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) \ Index: src/sys/arch/hpcmips/vr/vrc4172pci.c diff -u src/sys/arch/hpcmips/vr/vrc4172pci.c:1.14 src/sys/arch/hpcmips/vr/vrc4172pci.c:1.15 --- src/sys/arch/hpcmips/vr/vrc4172pci.c:1.14 Tue May 17 17:34:49 2011 +++ src/sys/arch/hpcmips/vr/vrc4172pci.c Wed Aug 24 20:27:36 2011 @@ -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 Index: src/sys/arch/hpcmips/vr/vrpciu.c diff -u src/sys/arch/hpcmips/vr/vrpciu.c:1.18 src/sys/arch/hpcmips/vr/vrpciu.c:1.19 --- src/sys/arch/hpcmips/vr/vrpciu.c:1.18 Tue May 17 17:34:50 2011 +++ src/sys/arch/hpcmips/vr/vrpciu.c Wed Aug 24 20:27:36 2011 @@ -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 Index: src/sys/dev/pci/files.pci diff -u src/sys/dev/pci/files.pci:1.345 src/sys/dev/pci/files.pci:1.346 --- src/sys/dev/pci/files.pci:1.345 Fri Aug 12 22:02:56 2011 +++ src/sys/dev/pci/files.pci Wed Aug 24 20:27:35 2011 @@ -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 Index: src/sys/dev/pci/pci.c diff -u src/sys/dev/pci/pci.c:1.140 src/sys/dev/pci/pci.c:1.141 --- src/sys/dev/pci/pci.c:1.140 Tue May 17 17:34:54 2011 +++ src/sys/dev/pci/pci.c Wed Aug 24 20:27:35 2011 @@ -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; + + n = pci_bus_devorder(sc->sc_pc, sc->sc_bus, devs, __arraycount(devs)); + for (i = 0; i < n; i++) { + device = devs[i]; -#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 - { if ((locators[PCICF_DEV] != PCICF_DEV_DEFAULT) && (locators[PCICF_DEV] != device)) continue; Index: src/sys/dev/pci/pciconf.c diff -u src/sys/dev/pci/pciconf.c:1.32 src/sys/dev/pci/pciconf.c:1.33 --- src/sys/dev/pci/pciconf.c:1.32 Sat Dec 11 18:21:14 2010 +++ src/sys/dev/pci/pciconf.c Wed Aug 24 20:27:35 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pciconf.c,v 1.32 2010/12/11 18:21:14 matt Exp $ */ +/* $NetBSD: pciconf.c,v 1.33 2011/08/24 20:27:35 dyoung Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -65,7 +65,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pciconf.c,v 1.32 2010/12/11 18:21:14 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pciconf.c,v 1.33 2011/08/24 20:27:35 dyoung Exp $"); #include "opt_pci.h" @@ -211,13 +211,10 @@ static int probe_bus(pciconf_bus_t *pb) { - int device, maxdevs; -#ifdef __PCI_BUS_DEVORDER - char devs[32]; - int i; -#endif + int device; + uint8_t devs[32]; + int i, n; - maxdevs = pci_bus_maxdevs(pb->pc, pb->busno); pb->ndevs = 0; pb->niowin = 0; pb->nmemwin = 0; @@ -232,17 +229,15 @@ pb->min_maxlat = 0x100; /* we are looking for the minimum */ pb->bandwidth_used = 0; -#ifdef __PCI_BUS_DEVORDER - pci_bus_devorder(pb->pc, pb->busno, devs); - for (i = 0; (device = devs[i]) < 32 && device >= 0; i++) { -#else - for (device = 0; device < maxdevs; device++) { -#endif + n = pci_bus_devorder(pb->pc, pb->busno, devs, __arraycount(devs)); + for (i = 0; i < n; i++) { pcitag_t tag; pcireg_t id, bhlcr; int function, nfunction; int confmode; + device = devs[i]; + tag = pci_make_tag(pb->pc, pb->busno, device, 0); if (pci_conf_debug) { print_tag(pb->pc, tag); Index: src/sys/dev/pci/pcivar.h diff -u src/sys/dev/pci/pcivar.h:1.94 src/sys/dev/pci/pcivar.h:1.95 --- src/sys/dev/pci/pcivar.h:1.94 Wed Jun 22 18:03:30 2011 +++ src/sys/dev/pci/pcivar.h Wed Aug 24 20:27:36 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pcivar.h,v 1.94 2011/06/22 18:03:30 matt Exp $ */ +/* $NetBSD: pcivar.h,v 1.95 2011/08/24 20:27:36 dyoung Exp $ */ /* * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. @@ -320,6 +320,7 @@ const struct pci_overrides *, void *, pci_chipset_tag_t *); void pci_chipset_tag_destroy(pci_chipset_tag_t); +int pci_bus_devorder(pci_chipset_tag_t, int, uint8_t *, int); /* * Device abstraction for inheritance by elanpci(4), for example. Added files: Index: src/sys/arch/hpcmips/pci/pci_machdep.c diff -u /dev/null src/sys/arch/hpcmips/pci/pci_machdep.c:1.1 --- /dev/null Wed Aug 24 20:27:36 2011 +++ src/sys/arch/hpcmips/pci/pci_machdep.c Wed Aug 24 20:27:36 2011 @@ -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); +} Index: src/sys/dev/pci/pci_stub.c diff -u /dev/null src/sys/dev/pci/pci_stub.c:1.1 --- /dev/null Wed Aug 24 20:27:36 2011 +++ src/sys/dev/pci/pci_stub.c Wed Aug 24 20:27:35 2011 @@ -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; +} + +void +default_pci_chipset_tag_destroy(pci_chipset_tag_t pc) +{ +} + +int +default_pci_chipset_tag_create(pci_chipset_tag_t opc, const uint64_t present, + const struct pci_overrides *ov, void *ctx, pci_chipset_tag_t *pcp) +{ + return EOPNOTSUPP; +}