From 2899c8b10a9ba33e95424087609e42a4ce3d1987 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Tue, 13 Jan 2004 18:31:58 +0000 Subject: [PATCH] Add PCIBUS to nexus --- sys/i386/i386/nexus.c | 46 +++++++++++++++++++++-- sys/i386/include/nexusvar.h | 56 ++++++++++++++++++++++++++++ sys/platform/pc32/i386/nexus.c | 46 +++++++++++++++++++++-- sys/platform/pc32/include/nexusvar.h | 56 ++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+), 8 deletions(-) create mode 100644 sys/i386/include/nexusvar.h create mode 100644 sys/platform/pc32/include/nexusvar.h diff --git a/sys/i386/i386/nexus.c b/sys/i386/i386/nexus.c index 28484d05c7..252a827ac4 100644 --- a/sys/i386/i386/nexus.c +++ b/sys/i386/i386/nexus.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/nexus.c,v 1.26.2.10 2003/02/22 13:16:45 imp Exp $ - * $DragonFly: src/sys/i386/i386/Attic/nexus.c,v 1.3 2003/08/07 21:17:22 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/nexus.c,v 1.4 2004/01/13 18:31:58 joerg Exp $ */ /* @@ -57,6 +57,7 @@ #include #include +#include #include #ifdef APIC_IO #include @@ -73,6 +74,7 @@ static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device"); struct nexus_device { struct resource_list nx_resources; + int nx_pcibus; }; #define DEVTONX(dev) ((struct nexus_device *)device_get_ivars(dev)) @@ -87,6 +89,8 @@ static device_t nexus_add_child(device_t bus, int order, const char *name, int unit); static struct resource *nexus_alloc_resource(device_t, device_t, int, int *, u_long, u_long, u_long, u_int); +static int nexus_read_ivar(device_t, device_t, int, uintptr_t *); +static int nexus_write_ivar(device_t, device_t, int, uintptr_t); static int nexus_activate_resource(device_t, device_t, int, int, struct resource *); static int nexus_deactivate_resource(device_t, device_t, int, int, @@ -113,8 +117,8 @@ static device_method_t nexus_methods[] = { /* Bus interface */ DEVMETHOD(bus_print_child, nexus_print_child), DEVMETHOD(bus_add_child, nexus_add_child), - DEVMETHOD(bus_read_ivar, bus_generic_read_ivar), - DEVMETHOD(bus_write_ivar, bus_generic_write_ivar), + DEVMETHOD(bus_read_ivar, nexus_read_ivar), + DEVMETHOD(bus_write_ivar, nexus_write_ivar), DEVMETHOD(bus_alloc_resource, nexus_alloc_resource), DEVMETHOD(bus_release_resource, nexus_release_resource), DEVMETHOD(bus_activate_resource, nexus_activate_resource), @@ -262,7 +266,7 @@ nexus_print_all_resources(device_t dev) struct resource_list *rl = &ndev->nx_resources; int retval = 0; - if (SLIST_FIRST(rl)) + if (SLIST_FIRST(rl) || ndev->nx_pcibus != -1) retval += printf(" at"); retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx"); @@ -275,10 +279,13 @@ nexus_print_all_resources(device_t dev) static int nexus_print_child(device_t bus, device_t child) { + struct nexus_device *ndev = DEVTONX(child); int retval = 0; retval += bus_print_child_header(bus, child); retval += nexus_print_all_resources(child); + if (ndev->nx_pcibus != -1) + retval += printf(" pcibus %d", ndev->nx_pcibus); retval += printf(" on motherboard\n"); return (retval); @@ -294,6 +301,7 @@ nexus_add_child(device_t bus, int order, const char *name, int unit) if (!ndev) return(0); resource_list_init(&ndev->nx_resources); + ndev->nx_pcibus = -1; child = device_add_child_ordered(bus, order, name, unit); @@ -303,6 +311,36 @@ nexus_add_child(device_t bus, int order, const char *name, int unit) return(child); } +static int +nexus_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) +{ + struct nexus_device *ndev = DEVTONX(child); + + switch (which) { + case NEXUS_IVAR_PCIBUS: + *result = ndev->nx_pcibus; + break; + default: + return ENOENT; + } + return 0; +} + +static int +nexus_write_ivar(device_t dev, device_t child, int which, uintptr_t value) +{ + struct nexus_device *ndev = DEVTONX(child); + + switch (which) { + case NEXUS_IVAR_PCIBUS: + ndev->nx_pcibus = value; + break; + default: + return ENOENT; + } + return 0; +} + /* * Allocate a resource on behalf of child. NB: child is usually going to be a * child of one of our descendants, not a direct child of nexus0. diff --git a/sys/i386/include/nexusvar.h b/sys/i386/include/nexusvar.h new file mode 100644 index 0000000000..744bf889d9 --- /dev/null +++ b/sys/i386/include/nexusvar.h @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2000 Peter Wemm + * 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, 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. + * + * $FreeBSD: src/sys/i386/include/nexusvar.h,v 1.1 2000/09/28 00:37:31 peter Exp $ + * $DragonFly: src/sys/i386/include/Attic/nexusvar.h,v 1.1 2004/01/13 18:31:58 joerg Exp $ + */ + +#ifndef _MACHINE_NEXUSVAR_H_ +#define _MACHINE_NEXUSVAR_H_ 1 + +enum nexus_device_ivars { + NEXUS_IVAR_PCIBUS +}; + +#define NEXUS_ACCESSOR(A, B, T) \ + \ +static __inline T nexus_get_ ## A(device_t dev) \ +{ \ + uintptr_t v; \ + BUS_READ_IVAR(device_get_parent(dev), dev, NEXUS_IVAR_ ## B, &v); \ + return (T) v; \ +} \ + \ +static __inline void nexus_set_ ## A(device_t dev, T t) \ +{ \ + uintptr_t v = (uintptr_t) t; \ + BUS_WRITE_IVAR(device_get_parent(dev), dev, NEXUS_IVAR_ ## B, v); \ +} + +NEXUS_ACCESSOR(pcibus, PCIBUS, u_int32_t) + +#undef NEXUS_ACCESSOR + +#endif /* !_MACHINE_NEXUSVAR_H_ */ diff --git a/sys/platform/pc32/i386/nexus.c b/sys/platform/pc32/i386/nexus.c index d4b42fb2bb..376e6077c0 100644 --- a/sys/platform/pc32/i386/nexus.c +++ b/sys/platform/pc32/i386/nexus.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/nexus.c,v 1.26.2.10 2003/02/22 13:16:45 imp Exp $ - * $DragonFly: src/sys/platform/pc32/i386/nexus.c,v 1.3 2003/08/07 21:17:22 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/nexus.c,v 1.4 2004/01/13 18:31:58 joerg Exp $ */ /* @@ -57,6 +57,7 @@ #include #include +#include #include #ifdef APIC_IO #include @@ -73,6 +74,7 @@ static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device"); struct nexus_device { struct resource_list nx_resources; + int nx_pcibus; }; #define DEVTONX(dev) ((struct nexus_device *)device_get_ivars(dev)) @@ -87,6 +89,8 @@ static device_t nexus_add_child(device_t bus, int order, const char *name, int unit); static struct resource *nexus_alloc_resource(device_t, device_t, int, int *, u_long, u_long, u_long, u_int); +static int nexus_read_ivar(device_t, device_t, int, uintptr_t *); +static int nexus_write_ivar(device_t, device_t, int, uintptr_t); static int nexus_activate_resource(device_t, device_t, int, int, struct resource *); static int nexus_deactivate_resource(device_t, device_t, int, int, @@ -113,8 +117,8 @@ static device_method_t nexus_methods[] = { /* Bus interface */ DEVMETHOD(bus_print_child, nexus_print_child), DEVMETHOD(bus_add_child, nexus_add_child), - DEVMETHOD(bus_read_ivar, bus_generic_read_ivar), - DEVMETHOD(bus_write_ivar, bus_generic_write_ivar), + DEVMETHOD(bus_read_ivar, nexus_read_ivar), + DEVMETHOD(bus_write_ivar, nexus_write_ivar), DEVMETHOD(bus_alloc_resource, nexus_alloc_resource), DEVMETHOD(bus_release_resource, nexus_release_resource), DEVMETHOD(bus_activate_resource, nexus_activate_resource), @@ -262,7 +266,7 @@ nexus_print_all_resources(device_t dev) struct resource_list *rl = &ndev->nx_resources; int retval = 0; - if (SLIST_FIRST(rl)) + if (SLIST_FIRST(rl) || ndev->nx_pcibus != -1) retval += printf(" at"); retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx"); @@ -275,10 +279,13 @@ nexus_print_all_resources(device_t dev) static int nexus_print_child(device_t bus, device_t child) { + struct nexus_device *ndev = DEVTONX(child); int retval = 0; retval += bus_print_child_header(bus, child); retval += nexus_print_all_resources(child); + if (ndev->nx_pcibus != -1) + retval += printf(" pcibus %d", ndev->nx_pcibus); retval += printf(" on motherboard\n"); return (retval); @@ -294,6 +301,7 @@ nexus_add_child(device_t bus, int order, const char *name, int unit) if (!ndev) return(0); resource_list_init(&ndev->nx_resources); + ndev->nx_pcibus = -1; child = device_add_child_ordered(bus, order, name, unit); @@ -303,6 +311,36 @@ nexus_add_child(device_t bus, int order, const char *name, int unit) return(child); } +static int +nexus_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) +{ + struct nexus_device *ndev = DEVTONX(child); + + switch (which) { + case NEXUS_IVAR_PCIBUS: + *result = ndev->nx_pcibus; + break; + default: + return ENOENT; + } + return 0; +} + +static int +nexus_write_ivar(device_t dev, device_t child, int which, uintptr_t value) +{ + struct nexus_device *ndev = DEVTONX(child); + + switch (which) { + case NEXUS_IVAR_PCIBUS: + ndev->nx_pcibus = value; + break; + default: + return ENOENT; + } + return 0; +} + /* * Allocate a resource on behalf of child. NB: child is usually going to be a * child of one of our descendants, not a direct child of nexus0. diff --git a/sys/platform/pc32/include/nexusvar.h b/sys/platform/pc32/include/nexusvar.h new file mode 100644 index 0000000000..8f6743831d --- /dev/null +++ b/sys/platform/pc32/include/nexusvar.h @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2000 Peter Wemm + * 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, 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. + * + * $FreeBSD: src/sys/i386/include/nexusvar.h,v 1.1 2000/09/28 00:37:31 peter Exp $ + * $DragonFly: src/sys/platform/pc32/include/nexusvar.h,v 1.1 2004/01/13 18:31:58 joerg Exp $ + */ + +#ifndef _MACHINE_NEXUSVAR_H_ +#define _MACHINE_NEXUSVAR_H_ 1 + +enum nexus_device_ivars { + NEXUS_IVAR_PCIBUS +}; + +#define NEXUS_ACCESSOR(A, B, T) \ + \ +static __inline T nexus_get_ ## A(device_t dev) \ +{ \ + uintptr_t v; \ + BUS_READ_IVAR(device_get_parent(dev), dev, NEXUS_IVAR_ ## B, &v); \ + return (T) v; \ +} \ + \ +static __inline void nexus_set_ ## A(device_t dev, T t) \ +{ \ + uintptr_t v = (uintptr_t) t; \ + BUS_WRITE_IVAR(device_get_parent(dev), dev, NEXUS_IVAR_ ## B, v); \ +} + +NEXUS_ACCESSOR(pcibus, PCIBUS, u_int32_t) + +#undef NEXUS_ACCESSOR + +#endif /* !_MACHINE_NEXUSVAR_H_ */ -- 2.41.0