From 22457186d1887b641ca69e49a6cca3d3edcc413d Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Fri, 6 Feb 2004 23:09:36 +0000 Subject: [PATCH] Adjust infrastructure for NEWCARD --- sys/bus/pci/pci.c | 23 ++++++++++------------- sys/bus/pci/pci_private.h | 34 ++++++++++++++++++++++++++++++++++ sys/bus/pci/pcivar.h | 5 +++-- sys/kern/bus_if.m | 39 ++++++++++++++++++++++++++++++++++++++- sys/kern/subr_bus.c | 8 +++++++- sys/sys/bus.h | 3 ++- 6 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 sys/bus/pci/pci_private.h diff --git a/sys/bus/pci/pci.c b/sys/bus/pci/pci.c index 7ab1a82c8b..0f2f98145e 100644 --- a/sys/bus/pci/pci.c +++ b/sys/bus/pci/pci.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/pci.c,v 1.141.2.15 2002/04/30 17:48:18 tmm Exp $ - * $DragonFly: src/sys/bus/pci/pci.c,v 1.14 2004/01/16 20:21:42 joerg Exp $ + * $DragonFly: src/sys/bus/pci/pci.c,v 1.15 2004/02/06 23:09:36 joerg Exp $ * */ @@ -61,6 +61,7 @@ #include #include "pcireg.h" #include "pcivar.h" +#include "pci_private.h" #include "pcib_if.h" @@ -326,8 +327,8 @@ pci_hdrtypedata(device_t pcib, int b, int s, int f, pcicfgregs *cfg) /* read configuration header into pcicfgrect structure */ -static struct pci_devinfo * -pci_read_device(device_t pcib, int b, int s, int f) +struct pci_devinfo * +pci_read_device(device_t pcib, int b, int s, int f, int width) { #define REG(n, w) PCIB_READ_CONFIG(pcib, b, s, f, n, w) @@ -341,7 +342,7 @@ pci_read_device(device_t pcib, int b, int s, int f) if (PCIB_READ_CONFIG(pcib, b, s, f, PCIR_DEVVENDOR, 4) != -1) { - devlist_entry = malloc(sizeof(struct pci_devinfo), + devlist_entry = malloc(width, M_DEVBUF, M_WAITOK | M_ZERO); if (devlist_entry == NULL) return (NULL); @@ -482,10 +483,9 @@ pci_read_extcap(device_t pcib, pcicfgregs *cfg) #undef REG } -#if 0 /* free pcicfgregs structure and all depending data structures */ -static int +int pci_freecfg(struct pci_devinfo *dinfo) { struct devlist *devlist_head; @@ -494,8 +494,6 @@ pci_freecfg(struct pci_devinfo *dinfo) if (dinfo->cfg.hdrspec != NULL) free(dinfo->cfg.hdrspec, M_DEVBUF); - if (dinfo->cfg.map != NULL) - free(dinfo->cfg.map, M_DEVBUF); /* XXX this hasn't been tested */ STAILQ_REMOVE(devlist_head, dinfo, pci_devinfo, pci_links); free(dinfo, M_DEVBUF); @@ -507,7 +505,6 @@ pci_freecfg(struct pci_devinfo *dinfo) pci_numdevs--; return (0); } -#endif /* @@ -1130,7 +1127,7 @@ static struct cdevsw pcicdev = { * pci-pci-bridge. Both kinds are represented by instances of pcib. */ -static void +void pci_print_verbose(struct pci_devinfo *dinfo) { if (bootverbose) { @@ -1286,7 +1283,7 @@ pci_add_children(device_t dev, int busno) int pcifunchigh = 0; for (f = 0; f <= pcifunchigh; f++) { struct pci_devinfo *dinfo = - pci_read_device(pcib, busno, s, f); + pci_read_device(pcib, busno, s, f, sizeof *dinfo); if (dinfo != NULL) { if (dinfo->cfg.mfdev) pcifunchigh = 7; @@ -1422,7 +1419,7 @@ pci_probe_nomatch(device_t dev, device_t child) return; } -static int +int pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) { struct pci_devinfo *dinfo; @@ -1486,7 +1483,7 @@ pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) return 0; } -static int +int pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value) { struct pci_devinfo *dinfo; diff --git a/sys/bus/pci/pci_private.h b/sys/bus/pci/pci_private.h new file mode 100644 index 0000000000..cd9c8ba2a0 --- /dev/null +++ b/sys/bus/pci/pci_private.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2004, Joerg Sonnenberger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $DragonFly: src/sys/bus/pci/pci_private.h,v 1.1 2004/02/06 23:09:36 joerg Exp $ + * + */ + +void pci_print_verbose(struct pci_devinfo *); +struct pci_devinfo *pci_read_device(device_t, int, int, int, int); +int pci_freecfg(struct pci_devinfo *); +int pci_read_ivar(device_t, device_t, int, uintptr_t *); +int pci_write_ivar(device_t, device_t, int, uintptr_t); diff --git a/sys/bus/pci/pcivar.h b/sys/bus/pci/pcivar.h index 681e6f71e2..876f998f37 100644 --- a/sys/bus/pci/pcivar.h +++ b/sys/bus/pci/pcivar.h @@ -23,8 +23,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/pci/pcivar.h,v 1.41.2.2 2002/01/10 12:08:22 mdodd Exp $ - * $DragonFly: src/sys/bus/pci/pcivar.h,v 1.5 2004/01/15 20:35:06 joerg Exp $ + * $FreeBSD: src/sys/pci/pcivar.h,v 1.48 2000/09/28 00:37:32 peter Exp $ + * $DragonFly: src/sys/bus/pci/pcivar.h,v 1.6 2004/02/06 23:09:36 joerg Exp $ * */ @@ -197,6 +197,7 @@ enum pci_device_ivars { PCI_IVAR_FUNCTION, PCI_IVAR_SECONDARYBUS, PCI_IVAR_SUBORDINATEBUS, + PCI_IVAR_ETHADDR, }; /* diff --git a/sys/kern/bus_if.m b/sys/kern/bus_if.m index a370d73b8d..cf532e6827 100644 --- a/sys/kern/bus_if.m +++ b/sys/kern/bus_if.m @@ -24,7 +24,7 @@ # SUCH DAMAGE. # # $FreeBSD: src/sys/kern/bus_if.m,v 1.16 1999/10/12 21:35:50 dfr Exp $ -# $DragonFly: src/sys/kern/bus_if.m,v 1.3 2003/11/17 00:54:40 asmodai Exp $ +# $DragonFly: src/sys/kern/bus_if.m,v 1.4 2004/02/06 23:09:36 joerg Exp $ # #include @@ -237,3 +237,40 @@ METHOD void delete_resource { int type; int rid; }; + +# +# Is the hardware described by _child still attached to the system? +# +# This method should return 0 if the device is not present. It should +# return -1 if it is present. Any errors in determining should be +# returned as a normal errno value. Client drivers are to assume that +# the device is present, even if there is an error determining if it is +# there. Busses are to try to avoid returning errors, but newcard will return +# an error if the device fails to implement this method. +# +METHOD int child_present { + device_t _dev; + device_t _child; +} DEFAULT bus_generic_child_present; + +# +# Returns the pnp info for this device. Return it as a string. If the +# string is insufficient for the storage, then return EOVERFLOW. +# +METHOD int child_pnpinfo_str { + device_t _dev; + device_t _child; + char *_buf; + size_t _buflen; +}; + +# +# Returns the location for this device. Return it as a string. If the +# string is insufficient for the storage, then return EOVERFLOW. +# +METHOD int child_location_str { + device_t _dev; + device_t _child; + char *_buf; + size_t _buflen; +}; diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index ea32024551..053510ec49 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/subr_bus.c,v 1.54.2.9 2002/10/10 15:13:32 jhb Exp $ - * $DragonFly: src/sys/kern/subr_bus.c,v 1.9 2003/11/18 05:10:31 dillon Exp $ + * $DragonFly: src/sys/kern/subr_bus.c,v 1.10 2004/02/06 23:09:36 joerg Exp $ */ #include "opt_bus.h" @@ -1914,6 +1914,12 @@ bus_generic_teardown_intr(device_t dev, device_t child, struct resource *irq, return (EINVAL); } +int +bus_generic_child_present(device_t bus, device_t child) +{ + return (BUS_CHILD_PRESENT(device_get_parent(bus), bus)); +} + struct resource * bus_generic_alloc_resource(device_t dev, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 36c7b0e19e..d6bb30b794 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/sys/bus.h,v 1.30.2.4 2002/10/10 15:13:33 jhb Exp $ - * $DragonFly: src/sys/sys/bus.h,v 1.4 2003/11/22 19:30:57 asmodai Exp $ + * $DragonFly: src/sys/sys/bus.h,v 1.5 2004/02/06 23:09:36 joerg Exp $ */ #ifndef _SYS_BUS_H_ @@ -173,6 +173,7 @@ struct resource *bus_generic_alloc_resource(device_t bus, device_t child, u_long start, u_long end, u_long count, u_int flags); int bus_generic_attach(device_t dev); +int bus_generic_child_present(device_t dev, device_t child); int bus_generic_deactivate_resource(device_t dev, device_t child, int type, int rid, struct resource *r); int bus_generic_detach(device_t dev); -- 2.41.0