diff options
Diffstat (limited to 'sys')
32 files changed, 801 insertions, 754 deletions
diff --git a/sys/alpha/alpha/autoconf.c b/sys/alpha/alpha/autoconf.c index f70e85d..cf4f581 100644 --- a/sys/alpha/alpha/autoconf.c +++ b/sys/alpha/alpha/autoconf.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: autoconf.c,v 1.1 1998/06/10 10:52:10 dfr Exp $ */ #include <sys/param.h> @@ -69,6 +69,8 @@ configure_finish() #endif } +extern void pci_configure(void); + /* * Determine i/o configuration for a machine. */ @@ -77,7 +79,7 @@ configure(void *dummy) { configure_start(); - bus_add_device(root_bus, platform.iobus, 0, 0); + device_add_child(root_bus, platform.iobus, 0, 0); root_bus_configure(); pci_configure(); diff --git a/sys/alpha/alpha/clock.c b/sys/alpha/alpha/clock.c index 24eb3c8..2fdaa68 100644 --- a/sys/alpha/alpha/clock.c +++ b/sys/alpha/alpha/clock.c @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $Id: clock.c,v 1.1 1998/06/10 10:52:13 dfr Exp $ */ /* $NetBSD: clock.c,v 1.20 1998/01/31 10:32:47 ross Exp $ */ /* @@ -52,8 +52,7 @@ #include <sys/bus.h> #include <machine/cpuconf.h> - -#include <dev/dec/clockvar.h> +#include <machine/clockvar.h> #define SECMIN ((unsigned)60) /* seconds per minute */ #define SECHOUR ((unsigned)(60*SECMIN)) /* seconds per hour */ @@ -63,13 +62,12 @@ #define LEAPYEAR(year) (((year) % 4) == 0) device_t clockdev; -const struct clockfns *clockfns; int clockinitted; int tickfix; int tickfixinterval; int wall_cmos_clock; /* wall CMOS clock assumed if != 0 */ -extern cycles_per_sec; +extern int cycles_per_sec; static timecounter_get_t alpha_get_timecount; static timecounter_pps_t alpha_poll_pps; @@ -103,18 +101,15 @@ static u_int32_t last_time; static void handleclock(void* arg); void -clockattach(dev, fns) - struct device *dev; - const struct clockfns *fns; +clockattach(device_t dev) { /* * Just bookkeeping. */ - if (clockfns != NULL) + if (clockdev) panic("clockattach: multiple clocks"); clockdev = dev; - clockfns = fns; #ifdef EVCNT_COUNTERS evcnt_attach(dev, "intr", &clock_intr_evcnt); #endif @@ -140,7 +135,7 @@ clockattach(dev, fns) void cpu_initclocks() { - if (clockfns == NULL) + if (clockdev == NULL) panic("cpu_initclocks: no clock attached"); tick = 1000000 / hz; /* number of microseconds between interrupts */ @@ -177,7 +172,7 @@ cpu_initclocks() /* * Get the clock started. */ - (*clockfns->cf_init)(clockdev); + CLOCK_INIT(clockdev); } static void @@ -241,7 +236,7 @@ inittodr(base) } else badbase = 0; - (*clockfns->cf_get)(clockdev, base, &ct); + CLOCK_GET(clockdev, base, &ct); clockinitted = 1; /* simple sanity checks */ @@ -344,7 +339,7 @@ resettodr() ct.min = t / SECMIN; ct.sec = t % SECMIN; - (*clockfns->cf_set)(clockdev, &ct); + CLOCK_SET(clockdev, &ct); } static unsigned diff --git a/sys/alpha/alpha/cons.c b/sys/alpha/alpha/cons.c index 511f370..78d1149 100644 --- a/sys/alpha/alpha/cons.c +++ b/sys/alpha/alpha/cons.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * from: @(#)cons.c 7.2 (Berkeley) 5/9/91 - * $Id: cons.c,v 1.57 1998/03/28 10:32:56 bde Exp $ + * $Id: cons.c,v 1.1 1998/06/10 10:52:15 dfr Exp $ */ #include "opt_devfs.h" @@ -424,7 +424,7 @@ cnputc(c) } } -static cn_devsw_installed = 0; +static int cn_devsw_installed = 0; static void cn_drvinit(void *unused) diff --git a/sys/alpha/alpha/dec_kn8ae.c b/sys/alpha/alpha/dec_kn8ae.c index aad572b..813d202 100644 --- a/sys/alpha/alpha/dec_kn8ae.c +++ b/sys/alpha/alpha/dec_kn8ae.c @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $Id: dec_kn8ae.c,v 1.1 1998/06/10 10:52:30 dfr Exp $ */ /* $NetBSD: dec_kn8ae.c,v 1.15 1998/02/13 00:12:50 thorpej Exp $ */ /* @@ -44,6 +44,7 @@ #include <alpha/tlsb/tlsbreg.h> #include <alpha/tlsb/gbusreg.h> +#include <alpha/tlsb/zsvar.h> void dec_kn8ae_init(int); static void dec_kn8ae_cons_init(void); diff --git a/sys/alpha/alpha/genassym.c b/sys/alpha/alpha/genassym.c index 520bd41..50ebf1d 100644 --- a/sys/alpha/alpha/genassym.c +++ b/sys/alpha/alpha/genassym.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 - * $Id: genassym.c,v 1.54 1998/04/06 18:59:14 peter Exp $ + * $Id: genassym.c,v 1.1 1998/06/10 10:52:39 dfr Exp $ */ #include <sys/param.h> @@ -64,8 +64,10 @@ int main __P((void)); int printf __P((const char *, ...)); +#define BIG(val) ((val) > 999LL || (val) < -999LL) + #define P(name, val) \ - printf(val > 999 ? "#define\t%s 0x%lx\n" : "#define\t%s %ld\n", name, val) + printf(BIG(val) ? "#define\t%s 0x%qx\n" : "#define\t%s %qd\n", name, val) /* XXX Danger Will Robinson */ struct prochd { @@ -73,9 +75,9 @@ struct prochd { struct proc *ph_rlink; }; -#define OFF(name, type, elem) P(#name, (long)&((type*)0)->elem) -#define CONST2(name, val) P(#name, val) -#define CONST1(name) P(#name, name) +#define OFF(name, type, elem) P(#name, (long long) &((type*)0)->elem) +#define CONST2(name, val) P(#name, (long long) val) +#define CONST1(name) P(#name, (long long) name) int main() diff --git a/sys/alpha/alpha/gensetdefs.c b/sys/alpha/alpha/gensetdefs.c index 0e446345..d2aaa8d 100644 --- a/sys/alpha/alpha/gensetdefs.c +++ b/sys/alpha/alpha/gensetdefs.c @@ -23,11 +23,11 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: gensetdefs.c,v 1.1 1997/05/21 23:21:25 jdp Exp $ + * $Id: gensetdefs.c,v 1.1 1998/06/10 10:52:41 dfr Exp $ */ #include <sys/types.h> -#include <machine/elf.h> +#include "../../alpha/include/elf.h" #include <err.h> #include <stddef.h> diff --git a/sys/alpha/conf/Makefile.alpha b/sys/alpha/conf/Makefile.alpha index ecc9daa..51cb957 100644 --- a/sys/alpha/conf/Makefile.alpha +++ b/sys/alpha/conf/Makefile.alpha @@ -1,7 +1,7 @@ # Makefile.alpha -- with config changes. # Copyright 1990 W. Jolitz # from: @(#)Makefile.alpha 7.1 5/10/91 -# $Id: Makefile.alpha,v 1.109 1998/04/17 07:51:36 dima Exp $ +# $Id: Makefile.alpha,v 1.1 1998/06/10 10:53:59 dfr Exp $ # # Makefile for FreeBSD # @@ -30,6 +30,9 @@ S= ../.. .endif ALPHA= ${S}/alpha +HCC?=${CC} +SIZE?=size + COPTFLAGS?=-O INCLUDES= -nostdinc -I- -I. -I$S # This hack is to allow kernel compiles to succeed on machines w/out srcdist @@ -59,6 +62,9 @@ DRIVER_C_C= ${CC} -c ${CFLAGS} ${PROF} ${PARAM} $< DRIVER_S= ${CC} -c -x assembler-with-cpp -DLOCORE ${COPTS} $< PROFILE_C= ${CC} -c ${CFLAGS} ${PARAM} $< +NORMAL_M= sh $S/kern/makedevops.sh -c $<;\ + ${CC} -c ${CFLAGS} ${PROF} `basename $< .m`.c + # ${ALPHA}/alpha/setdef0.c and ${ALPHA}/alpha/setdef1.c are intentionally # omitted from SYSTEM_CFILES. They depend on setdefs.h, a header which # is generated from all of ${OBJS}. We don't want to have to compile @@ -71,11 +77,12 @@ SYMORDER_EXCLUDE=-x symbols.exclude .endif SYSTEM_LD_HEAD= @echo loading $@; rm -f $@ .if ${BINFORMAT} == elf -SYSTEM_OBJS= locore.o setdef0.o vnode_if.o ${OBJS} ioconf.o param.o config.o \ +SYSTEM_OBJS= locore.o setdef0.o vnode_if.o \ + ${OBJS} ioconf.o param.o config.o \ setdef1.o SYSTEM_LD= @${LD} -Bstatic -N -Ttext ${LOAD_ADDRESS} -e locorestart -defsym _DYNAMIC=0 \ -o $@ -X ${SYSTEM_OBJS} vers.o -SYSTEM_LD_TAIL= @size $@; chmod 755 $@ +SYSTEM_LD_TAIL= @${SIZE} $@; chmod 755 $@ .endif %BEFORE_DEPEND @@ -123,10 +130,10 @@ setdefs.h: gensetdefs ${OBJS} @./gensetdefs ${OBJS} >setdefs.h gensetdefs: gensetdefs.o - ${CC} ${CFLAGS} gensetdefs.o -o $@ + ${HCC} gensetdefs.o -o $@ gensetdefs.o: ${ALPHA}/alpha/gensetdefs.c - ${CC} -c ${CFLAGS} ${ALPHA}/alpha/gensetdefs.c + ${HCC} ${CFLAGS} -c ${ALPHA}/alpha/gensetdefs.c # everything potentially depends on the Makefile since everything potentially # depends on the options. Some things are more dependent on the Makefile for @@ -151,10 +158,10 @@ assym.s: genassym # Some of the defines that genassym outputs may well depend on the # value of kernel options. genassym.o: ${ALPHA}/alpha/genassym.c Makefile opt_global.h - ${CC} -c ${CFLAGS} ${PARAM} -UKERNEL ${ALPHA}/alpha/genassym.c + ${HCC} -c ${COPTS} ${PARAM} -UKERNEL ${ALPHA}/alpha/genassym.c genassym: genassym.o - ${CC} ${CFLAGS} ${PARAM} genassym.o -o $@ + ${HCC} ${COPTS} ${PARAM} genassym.o -o $@ SYSTEM_OBJS+= __divqu.o __divq.o __divlu.o __divl.o SYSTEM_OBJS+= __remqu.o __remq.o __remlu.o __reml.o diff --git a/sys/alpha/conf/files.alpha b/sys/alpha/conf/files.alpha index 04e5410..57c00a6 100644 --- a/sys/alpha/conf/files.alpha +++ b/sys/alpha/conf/files.alpha @@ -1,7 +1,7 @@ # This file tells config what files go into building a kernel, # files marked standard are always included. # -# $Id$ +# $Id: files.alpha,v 1.1 1998/06/10 10:54:08 dfr Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -48,6 +48,14 @@ alpha/alpha/interrupt.c standard alpha/alpha/userconfig.c optional userconfig alpha/alpha/vm_machdep.c standard alpha/alpha/clock.c standard +alpha/alpha/clock_if.m standard \ + dependency "$S/kern/makedevops.sh" \ + clean "clock_if.c" +clock_if.h standard \ + dependency "$S/kern/makedevops.sh $S/alpha/alpha/clock_if.m" \ + compile-with "sh $S/kern/makedevops.sh -h $S/alpha/alpha/clock_if.m" \ + no-obj no-implicit-rule before-depend \ + clean "clock_if.h" alpha/alpha/diskslice_machdep.c standard alpha/tlsb/tlsb.c optional tlsb alpha/tlsb/gbus.c optional gbus @@ -56,8 +64,32 @@ alpha/tlsb/mcclock_tlsb.c optional gbus alpha/tlsb/zs_tlsb.c optional gbus alpha/tlsb/dwlpx.c optional dwlpx dev/dec/mcclock.c optional gbus +dev/dec/mcclock_if.m optional gbus \ + dependency "$S/kern/makedevops.sh" \ + clean "mcclock_if.c" +mcclock_if.h standard \ + dependency "$S/kern/makedevops.sh $S/dev/dec/mcclock_if.m" \ + compile-with "sh $S/kern/makedevops.sh -h $S/dev/dec/mcclock_if.m" \ + no-obj no-implicit-rule before-depend \ + clean "mcclock_if.h" alpha/pci/pcibus.c optional pci kern/subr_bus.c standard +kern/device_if.m standard \ + dependency "$S/kern/makedevops.sh" \ + clean "device_if.c" +device_if.h standard \ + dependency "$S/kern/makedevops.sh $S/kern/device_if.m" \ + compile-with "sh $S/kern/makedevops.sh -h $S/kern/device_if.m" \ + no-obj no-implicit-rule before-depend \ + clean "device_if.h" +kern/bus_if.m standard \ + dependency "$S/kern/makedevops.sh" \ + clean "bus_if.c" +bus_if.h standard \ + dependency "$S/kern/makedevops.sh $S/kern/bus_if.m" \ + compile-with "sh $S/kern/makedevops.sh -h $S/kern/bus_if.m" \ + no-obj no-implicit-rule before-depend \ + clean "bus_if.h" libkern/bcd.c standard libkern/bcmp.c standard libkern/ffs.c standard diff --git a/sys/alpha/include/alpha_cpu.h b/sys/alpha/include/alpha_cpu.h index 9bd97f4..5107274 100644 --- a/sys/alpha/include/alpha_cpu.h +++ b/sys/alpha/include/alpha_cpu.h @@ -1,4 +1,4 @@ -/* $Id: alpha_cpu.h,v 1.1 1998/01/10 10:13:13 jb Exp $ */ +/* $Id: alpha_cpu.h,v 1.2 1998/06/10 10:54:21 dfr Exp $ */ /* From: NetBSD: alpha_cpu.h,v 1.15 1997/09/20 19:02:34 mjacob Exp */ /* @@ -191,12 +191,12 @@ struct alpha_logout_area { #define ALPHA_L1SHIFT (ALPHA_L2SHIFT+ALPHA_PTSHIFT) #define ALPHA_USEG_BASE 0 /* virtual */ -#define ALPHA_USEG_END 0x000003ffffffffff +#define ALPHA_USEG_END 0x000003ffffffffffLL -#define ALPHA_K0SEG_BASE 0xfffffc0000000000 /* direct-mapped */ -#define ALPHA_K0SEG_END 0xfffffdffffffffff -#define ALPHA_K1SEG_BASE 0xfffffe0000000000 /* virtual */ -#define ALPHA_K1SEG_END 0xffffffffffffffff +#define ALPHA_K0SEG_BASE 0xfffffc0000000000LL /* direct-mapped */ +#define ALPHA_K0SEG_END 0xfffffdffffffffffLL +#define ALPHA_K1SEG_BASE 0xfffffe0000000000LL /* virtual */ +#define ALPHA_K1SEG_END 0xffffffffffffffffLL #define ALPHA_K0SEG_TO_PHYS(x) ((x) & ~ALPHA_K0SEG_BASE) #define ALPHA_PHYS_TO_K0SEG(x) ((x) | ALPHA_K0SEG_BASE) diff --git a/sys/alpha/include/param.h b/sys/alpha/include/param.h index 70101f0..63e203c 100644 --- a/sys/alpha/include/param.h +++ b/sys/alpha/include/param.h @@ -1,4 +1,4 @@ -/* $Id: param.h,v 1.2 1998/03/09 05:53:10 jb Exp $ */ +/* $Id: param.h,v 1.3 1998/06/10 10:55:15 dfr Exp $ */ /* From: NetBSD: param.h,v 1.20 1997/09/19 13:52:53 leo Exp */ /* @@ -75,7 +75,7 @@ #define PAGE_MASK (PAGE_SIZE-1) #define NPTEPG (PAGE_SIZE/(sizeof (pt_entry_t))) -#define KERNBASE 0xfffffc0000230000 /* start of kernel virtual */ +#define KERNBASE 0xfffffc0000230000LL /* start of kernel virtual */ #define BTOPKERNBASE ((u_long)KERNBASE >> PGSHIFT) #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ diff --git a/sys/alpha/include/vmparam.h b/sys/alpha/include/vmparam.h index 612fe8e..fead056 100644 --- a/sys/alpha/include/vmparam.h +++ b/sys/alpha/include/vmparam.h @@ -1,4 +1,4 @@ -/* $Id: vmparam.h,v 1.1.1.1 1998/03/09 05:43:16 jb Exp $ */ +/* $Id: vmparam.h,v 1.2 1998/06/10 10:55:30 dfr Exp $ */ /* From: NetBSD: vmparam.h,v 1.6 1997/09/23 23:23:23 mjacob Exp */ #ifndef _ALPHA_VMPARAM_H #define _ALPHA_VMPARAM_H @@ -133,11 +133,11 @@ */ /* user/kernel map constants */ -#define VM_MIN_ADDRESS ((vm_offset_t)ALPHA_USEG_BASE) /* 0 */ -#define VM_MAXUSER_ADDRESS ((vm_offset_t)(ALPHA_USEG_END + 1L)) +#define VM_MIN_ADDRESS (ALPHA_USEG_BASE) /* 0 */ +#define VM_MAXUSER_ADDRESS ((ALPHA_USEG_END + 1LL)) #define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS -#define VM_MIN_KERNEL_ADDRESS ((vm_offset_t)ALPHA_K1SEG_BASE) -#define VM_MAX_KERNEL_ADDRESS ((vm_offset_t)ALPHA_K1SEG_END) +#define VM_MIN_KERNEL_ADDRESS (ALPHA_K1SEG_BASE) +#define VM_MAX_KERNEL_ADDRESS (ALPHA_K1SEG_END) /* virtual sizes (bytes) for various kernel submaps */ #ifndef VM_KMEM_SIZE @@ -159,5 +159,5 @@ #endif /* some Alpha-specific constants */ -#define VPTBASE ((vm_offset_t)0xfffffffe00000000) /* Virt. pg table */ +#define VPTBASE (0xfffffffe00000000LL) /* Virt. pg table */ #endif /* !_ALPHA_VMPARAM_H */ diff --git a/sys/alpha/tlsb/dwlpx.c b/sys/alpha/tlsb/dwlpx.c index e9f2aa5..14317b6 100644 --- a/sys/alpha/tlsb/dwlpx.c +++ b/sys/alpha/tlsb/dwlpx.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: dwlpx.c,v 1.1 1998/06/10 10:55:41 dfr Exp $ */ #include "opt_simos.h" @@ -231,33 +231,37 @@ dwlpx_cfgwritel(u_int b, u_int s, u_int f, u_int r, u_int32_t data) SPARSE_WRITE_LONG(sc->cfg_base, off, data); } -static driver_probe_t dwlpx_probe; -static driver_attach_t dwlpx_attach; +static int dwlpx_probe(device_t dev); +static int dwlpx_attach(device_t dev); static driver_intr_t dwlpx_intr; +static device_method_t dwlpx_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, dwlpx_probe), + DEVMETHOD(device_attach, dwlpx_attach), + + { 0, 0 } +}; + static driver_t dwlpx_driver = { "dwlpx", - dwlpx_probe, - dwlpx_attach, - NULL, - NULL, + dwlpx_methods, DRIVER_TYPE_MISC, sizeof(struct dwlpx_softc), - NULL, }; - static int -dwlpx_probe(bus_t bus, device_t dev) +dwlpx_probe(device_t dev) { if (dwlpx0) return ENXIO; + dwlpx0 = dev; device_set_desc(dev, "DWLPA or DWLPB PCI adapter"); return 0; } static int -dwlpx_attach(bus_t bus, device_t dev) +dwlpx_attach(device_t dev) { struct dwlpx_softc* sc = DWLPX_SOFTC(dev); vm_offset_t regs; @@ -273,7 +277,7 @@ dwlpx_attach(bus_t bus, device_t dev) *(u_int32_t*) (regs + PCIA_CTL(0)) = 1; /* Type1 config cycles */ - bus_map_intr(bus, dev, dwlpx_intr, 0); + BUS_MAP_INTR(device_get_parent(dev), dev, dwlpx_intr, 0); return 0; } diff --git a/sys/alpha/tlsb/gbus.c b/sys/alpha/tlsb/gbus.c index 5235284..c7a1191 100644 --- a/sys/alpha/tlsb/gbus.c +++ b/sys/alpha/tlsb/gbus.c @@ -75,54 +75,33 @@ struct gbus_device gbus_children[] = { static devclass_t gbus_devclass; /* - * Bus handlers. + * Device methods */ -static bus_print_device_t gbus_print_device; -static bus_read_ivar_t gbus_read_ivar; - -static bus_ops_t gbus_bus_ops = { - gbus_print_device, - gbus_read_ivar, - null_write_ivar, - null_map_intr, +static int gbus_probe(device_t dev); +static void gbus_print_child(device_t dev, device_t child); +static int gbus_read_ivar(device_t dev, device_t child, int which, u_long *result);; + +static device_method_t gbus_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, gbus_probe), + DEVMETHOD(device_attach, bus_generic_attach), + DEVMETHOD(device_detach, bus_generic_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + + /* Bus interface */ + DEVMETHOD(bus_print_child, gbus_print_child), + DEVMETHOD(bus_read_ivar, gbus_read_ivar), + DEVMETHOD(bus_write_ivar, bus_generic_write_ivar), + DEVMETHOD(bus_map_intr, bus_generic_map_intr), + + { 0, 0 } }; -static void -gbus_print_device(bus_t bus, device_t dev) -{ - struct gbus_device* gdev = DEVTOGBUS(dev); - device_t gbusdev = bus_get_device(bus); - - printf(" at %s%d offset 0x%lx", - device_get_name(gbusdev), device_get_unit(gbusdev), - gdev->gd_offset); -} - -static int -gbus_read_ivar(bus_t bus, device_t dev, - int index, u_long* result) -{ - struct gbus_device* gdev = DEVTOGBUS(dev); - - switch (index) { - case GBUS_IVAR_OFFSET: - *result = gdev->gd_offset; - break; - } - return ENOENT; -} - -static driver_probe_t gbus_bus_probe; - -static driver_t gbus_bus_driver = { +static driver_t gbus_driver = { "gbus", - gbus_bus_probe, - bus_generic_attach, - bus_generic_detach, - bus_generic_shutdown, + gbus_methods, DRIVER_TYPE_MISC, - sizeof(struct bus), - NULL, + 1, /* no softc */ }; /* @@ -131,9 +110,8 @@ static driver_t gbus_bus_driver = { * are alive. */ static int -gbus_bus_probe(bus_t parent, device_t dev) +gbus_probe(device_t dev) { - bus_t bus = device_get_softc(dev); struct gbus_device *gdev; /* @@ -144,12 +122,34 @@ gbus_bus_probe(bus_t parent, device_t dev) if (!TLDEV_ISCPU(tlsb_get_dtype(dev))) return ENXIO; - bus_init(bus, dev, &gbus_bus_ops); - for (gdev = gbus_children; gdev->gd_name; gdev++) - bus_add_device(bus, gdev->gd_name, -1, gdev); + device_add_child(dev, gdev->gd_name, -1, gdev); return 0; } -DRIVER_MODULE(gbus, tlsb, gbus_bus_driver, gbus_devclass, 0, 0); +static void +gbus_print_child(device_t bus, device_t dev) +{ + struct gbus_device* gdev = DEVTOGBUS(dev); + + printf(" at %s%d offset 0x%lx", + device_get_name(bus), device_get_unit(bus), + gdev->gd_offset); +} + +static int +gbus_read_ivar(device_t bus, device_t dev, + int index, u_long* result) +{ + struct gbus_device* gdev = DEVTOGBUS(dev); + + switch (index) { + case GBUS_IVAR_OFFSET: + *result = gdev->gd_offset; + break; + } + return ENOENT; +} + +DRIVER_MODULE(gbus, tlsb, gbus_driver, gbus_devclass, 0, 0); diff --git a/sys/alpha/tlsb/gbusvar.h b/sys/alpha/tlsb/gbusvar.h index 1575817..5ece6e0 100644 --- a/sys/alpha/tlsb/gbusvar.h +++ b/sys/alpha/tlsb/gbusvar.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: gbusvar.h,v 1.2 1998/06/10 20:40:59 dfr Exp $ */ /* $NetBSD: gbusvar.h,v 1.1 1998/05/13 02:50:29 thorpej Exp $ */ @@ -81,7 +81,7 @@ enum gbus_device_ivars { static __inline T gbus_get_ ## A(device_t dev) \ { \ u_long v; \ - bus_read_ivar(device_get_parent(dev), dev, GBUS_IVAR_ ## B, &v); \ + BUS_READ_IVAR(device_get_parent(dev), dev, GBUS_IVAR_ ## B, &v); \ return (T) v; \ } diff --git a/sys/alpha/tlsb/kftxx.c b/sys/alpha/tlsb/kftxx.c index 9f41b62..d2b19d2 100644 --- a/sys/alpha/tlsb/kftxx.c +++ b/sys/alpha/tlsb/kftxx.c @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $Id: kftxx.c,v 1.1 1998/06/10 10:55:49 dfr Exp $ */ /* $NetBSD: kftxx.c,v 1.9 1998/05/14 00:01:32 thorpej Exp $ */ /* @@ -53,7 +53,6 @@ #include <alpha/tlsb/kftxxvar.h> struct kft_softc { - struct bus sc_bus; /* bus common */ int sc_node; /* TLSB node */ u_int16_t sc_dtype; /* device type */ }; @@ -73,72 +72,37 @@ struct kft_device { static devclass_t kft_devclass; /* - * Bus handlers. + * Device methods */ -static bus_print_device_t kft_print_device; -static bus_read_ivar_t kft_read_ivar; - -static bus_ops_t kft_bus_ops = { - kft_print_device, - kft_read_ivar, - null_write_ivar, - null_map_intr, +static int kft_probe(device_t dev); +static void kft_print_child(device_t dev, device_t child); +static int kft_read_ivar(device_t dev, device_t child, int which, u_long *result);; + +static device_method_t kft_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, kft_probe), + DEVMETHOD(device_attach, bus_generic_attach), + DEVMETHOD(device_detach, bus_generic_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + + /* Bus interface */ + DEVMETHOD(bus_print_child, kft_print_child), + DEVMETHOD(bus_read_ivar, kft_read_ivar), + DEVMETHOD(bus_write_ivar, bus_generic_write_ivar), + DEVMETHOD(bus_map_intr, bus_generic_map_intr), + + { 0, 0 } }; -static void -kft_print_device(bus_t bus, device_t dev) -{ - struct kft_device *kd = (struct kft_device*) device_get_ivars(dev); - device_t busdev = bus_get_device(bus); - - printf(" at %s%d hose %d", - device_get_name(busdev), device_get_unit(busdev), - kd->kd_hosenum); -} - -static int -kft_read_ivar(bus_t bus, device_t dev, - int index, u_long* result) -{ - struct kft_device *kd = (struct kft_device*) device_get_ivars(dev); - - switch (index) { - case KFT_IVAR_NAME: - *result = (u_long) kd->kd_name; - return 0; - - case KFT_IVAR_NODE: - *result = (u_long) kd->kd_node; - return 0; - - case KFT_IVAR_DTYPE: - *result = (u_long) kd->kd_dtype; - return 0; - - case KFT_IVAR_HOSENUM: - *result = (u_long) kd->kd_hosenum; - return 0; - - default: - return ENOENT; - } -} - -static driver_probe_t kft_bus_probe; - -static driver_t kft_bus_driver = { +static driver_t kft_driver = { "kft", - kft_bus_probe, - bus_generic_attach, - bus_generic_detach, - bus_generic_shutdown, + kft_methods, DRIVER_TYPE_MISC, - sizeof(struct kft_softc), - NULL, + 1, /* no softc */ }; static int -kft_bus_probe(bus_t parent, device_t dev) +kft_probe(device_t dev) { struct kft_softc *sc = (struct kft_softc *) device_get_softc(dev); struct kft_device* kd; @@ -147,8 +111,6 @@ kft_bus_probe(bus_t parent, device_t dev) if (!TLDEV_ISIOPORT(tlsb_get_dtype(dev))) return ENXIO; - bus_init(&sc->sc_bus, dev, &kft_bus_ops); - sc->sc_node = tlsb_get_node(dev); sc->sc_dtype = tlsb_get_dtype(dev); @@ -183,10 +145,48 @@ kft_bus_probe(bus_t parent, device_t dev) kd->kd_node = sc->sc_node; kd->kd_dtype = sc->sc_dtype; kd->kd_hosenum = hoseno; - bus_add_device(&sc->sc_bus, kd->kd_name, -1, kd); + device_add_child(dev, kd->kd_name, -1, kd); } return 0; } -DRIVER_MODULE(kft, tlsb, kft_bus_driver, kft_devclass, 0, 0); +static void +kft_print_child(device_t bus, device_t dev) +{ + struct kft_device *kd = (struct kft_device*) device_get_ivars(dev); + + printf(" at %s%d hose %d", + device_get_name(bus), device_get_unit(bus), + kd->kd_hosenum); +} + +static int +kft_read_ivar(device_t bus, device_t dev, + int index, u_long* result) +{ + struct kft_device *kd = (struct kft_device*) device_get_ivars(dev); + + switch (index) { + case KFT_IVAR_NAME: + *result = (u_long) kd->kd_name; + return 0; + + case KFT_IVAR_NODE: + *result = (u_long) kd->kd_node; + return 0; + + case KFT_IVAR_DTYPE: + *result = (u_long) kd->kd_dtype; + return 0; + + case KFT_IVAR_HOSENUM: + *result = (u_long) kd->kd_hosenum; + return 0; + + default: + return ENOENT; + } +} + +DRIVER_MODULE(kft, tlsb, kft_driver, kft_devclass, 0, 0); diff --git a/sys/alpha/tlsb/kftxxvar.h b/sys/alpha/tlsb/kftxxvar.h index 40c7424..56168e6 100644 --- a/sys/alpha/tlsb/kftxxvar.h +++ b/sys/alpha/tlsb/kftxxvar.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: kftxxvar.h,v 1.2 1998/06/10 20:48:03 dfr Exp $ */ /* @@ -45,7 +45,7 @@ enum kft_dev_ivars { static __inline T kft_get_ ## A(device_t dev) \ { \ u_long v; \ - bus_read_ivar(device_get_parent(dev), dev, KFT_IVAR_ ## B, &v); \ + BUS_READ_IVAR(device_get_parent(dev), dev, KFT_IVAR_ ## B, &v); \ return (T) v; \ } diff --git a/sys/alpha/tlsb/mcclock_tlsb.c b/sys/alpha/tlsb/mcclock_tlsb.c index 15974fc..593b00f 100644 --- a/sys/alpha/tlsb/mcclock_tlsb.c +++ b/sys/alpha/tlsb/mcclock_tlsb.c @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $Id: mcclock_tlsb.c,v 1.1 1998/06/10 10:55:52 dfr Exp $ */ /* $NetBSD: mcclock_tlsb.c,v 1.8 1998/05/13 02:50:29 thorpej Exp $ */ /* @@ -37,7 +37,7 @@ #include <sys/module.h> #include <sys/bus.h> -#include <dev/dec/clockvar.h> +#include <machine/clockvar.h> #include <dev/dec/mcclockvar.h> #include <alpha/tlsb/gbusvar.h> @@ -53,71 +53,73 @@ #define REGSHIFT 6 struct mcclock_tlsb_softc { - struct mcclock_softc sc_mcclock; unsigned long regbase; }; -static int mcclock_tlsb_probe(bus_t, device_t); -static int mcclock_tlsb_attach(bus_t, device_t); +static int mcclock_tlsb_probe(device_t dev); +static int mcclock_tlsb_attach(device_t dev); +static void mcclock_tlsb_write(device_t, u_int, u_int); +static u_int mcclock_tlsb_read(device_t, u_int); -static devclass_t mcclock_devclass; +static device_method_t mcclock_tlsb_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, mcclock_tlsb_probe), + DEVMETHOD(device_attach, mcclock_tlsb_attach), + + /* mcclock interface */ + DEVMETHOD(mcclock_write, mcclock_tlsb_write), + DEVMETHOD(mcclock_read, mcclock_tlsb_read), + + /* clock interface */ + DEVMETHOD(clock_init, mcclock_init), + DEVMETHOD(clock_get, mcclock_get), + DEVMETHOD(clock_set, mcclock_set), + + { 0, 0 } +}; -driver_t mcclock_tlsb_driver = { +static driver_t mcclock_tlsb_driver = { "mcclock", - mcclock_tlsb_probe, - mcclock_tlsb_attach, - NULL, - NULL, + mcclock_tlsb_methods, DRIVER_TYPE_MISC, sizeof(struct mcclock_tlsb_softc), - NULL, }; -static void mcclock_tlsb_write __P((struct mcclock_softc *, u_int, u_int)); -static u_int mcclock_tlsb_read __P((struct mcclock_softc *, u_int)); - -const struct mcclock_busfns mcclock_tlsb_busfns = { - mcclock_tlsb_write, mcclock_tlsb_read, -}; +static devclass_t mcclock_devclass; int -mcclock_tlsb_probe(bus_t bus, device_t dev) +mcclock_tlsb_probe(device_t dev) { device_set_desc(dev, "MC146818A real time clock"); return 0; } int -mcclock_tlsb_attach(bus_t bus, device_t dev) +mcclock_tlsb_attach(device_t dev) { struct mcclock_tlsb_softc *sc = device_get_softc(dev); /* XXX Should be bus.h'd, so we can accomodate the kn7aa. */ - sc->sc_mcclock.sc_dev = dev; sc->regbase = TLSB_GBUS_BASE + gbus_get_offset(dev); - mcclock_attach(&sc->sc_mcclock, &mcclock_tlsb_busfns); + mcclock_attach(dev); return 0; } static void -mcclock_tlsb_write(mcsc, reg, val) - struct mcclock_softc *mcsc; - u_int reg, val; +mcclock_tlsb_write(device_t dev, u_int reg, u_int val) { - struct mcclock_tlsb_softc *sc = (struct mcclock_tlsb_softc *)mcsc; + struct mcclock_tlsb_softc *sc = device_get_softc(dev); unsigned char *ptr = (unsigned char *) KV(sc->regbase + (reg << REGSHIFT)); *ptr = val; } static u_int -mcclock_tlsb_read(mcsc, reg) - struct mcclock_softc *mcsc; - u_int reg; +mcclock_tlsb_read(device_t dev, u_int reg) { - struct mcclock_tlsb_softc *sc = (struct mcclock_tlsb_softc *)mcsc; + struct mcclock_tlsb_softc *sc = device_get_softc(dev); unsigned char *ptr = (unsigned char *) KV(sc->regbase + (reg << REGSHIFT)); return *ptr; diff --git a/sys/alpha/tlsb/tlsb.c b/sys/alpha/tlsb/tlsb.c index 7b778ac..cb9639f 100644 --- a/sys/alpha/tlsb/tlsb.c +++ b/sys/alpha/tlsb/tlsb.c @@ -78,7 +78,6 @@ struct intr_mapping { }; struct tlsb_softc { - struct bus bus; STAILQ_HEAD(, intr_mapping) intr_handlers; }; @@ -86,88 +85,39 @@ static char *tlsb_node_type_str(u_int32_t); static void tlsb_intr(void* frame, u_long vector); /* There can be only one. */ -static int tlsb_found; -static struct tlsb_softc* tlsb0_softc; +static int tlsb_found; +static struct tlsb_softc* tlsb0_softc; +static devclass_t tlsb_devclass; /* - * Bus handlers. + * Device methods */ -static bus_print_device_t tlsb_print_device; -static bus_read_ivar_t tlsb_read_ivar; -static bus_map_intr_t tlsb_map_intr; - -static bus_ops_t tlsb_bus_ops = { - tlsb_print_device, - tlsb_read_ivar, - null_write_ivar, - tlsb_map_intr, +static int tlsb_probe(device_t dev); +static void tlsb_print_child(device_t dev, device_t child); +static int tlsb_read_ivar(device_t dev, device_t child, int which, u_long* result); +static int tlsb_map_intr(device_t dev, device_t child, driver_intr_t *intr, void *arg); + +static device_method_t tlsb_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, tlsb_probe), + DEVMETHOD(device_attach, bus_generic_attach), + DEVMETHOD(device_detach, bus_generic_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + + /* Bus interface */ + DEVMETHOD(bus_print_child, tlsb_print_child), + DEVMETHOD(bus_read_ivar, tlsb_read_ivar), + DEVMETHOD(bus_write_ivar, bus_generic_write_ivar), + DEVMETHOD(bus_map_intr, tlsb_map_intr), + + { 0, 0 } }; -static void -tlsb_print_device(bus_t bus, device_t dev) -{ - device_t busdev = bus_get_device(bus); - struct tlsb_device* tdev = DEVTOTLSB(dev); - - printf(" at %s%d node %d", - device_get_name(busdev), - device_get_unit(busdev), - tdev->td_node); -} - -static int -tlsb_read_ivar(bus_t bus, device_t dev, - int index, u_long* result) -{ - struct tlsb_device* tdev = DEVTOTLSB(dev); - - switch (index) { - case TLSB_IVAR_NODE: - *result = tdev->td_node; - break; - - case TLSB_IVAR_DTYPE: - *result = tdev->td_dtype; - break; - - case TLSB_IVAR_SWREV: - *result = tdev->td_swrev; - break; - - case TLSB_IVAR_HWREV: - *result = tdev->td_hwrev; - break; - } - return ENOENT; -} - -static int -tlsb_map_intr(bus_t bus, device_t dev, driver_intr_t *intr, void *arg) -{ - struct tlsb_softc* sc = (struct tlsb_softc*) bus; - struct intr_mapping* i; - i = malloc(sizeof(struct intr_mapping), M_DEVBUF, M_NOWAIT); - if (!i) - return ENOMEM; - i->intr = intr; - i->arg = arg; - STAILQ_INSERT_TAIL(&sc->intr_handlers, i, queue); - - return 0; -} - -static driver_probe_t tlsb_bus_probe; -static devclass_t tlsb_devclass; - -static driver_t tlsb_bus_driver = { +static driver_t tlsb_driver = { "tlsb", - tlsb_bus_probe, - bus_generic_attach, - bus_generic_detach, - bus_generic_shutdown, + tlsb_methods, DRIVER_TYPE_MISC, sizeof(struct tlsb_softc), - NULL, }; /* @@ -176,17 +126,17 @@ static driver_t tlsb_bus_driver = { * are alive. */ static int -tlsb_bus_probe(bus_t parent, device_t dev) +tlsb_probe(device_t dev) { struct tlsb_softc* sc = device_get_softc(dev); struct tlsb_device *tdev; u_int32_t tldev; u_int8_t vid; int node; - device_t subdev; + device_t child; device_set_desc(dev, "TurboLaser bus"); - bus_init(&sc->bus, dev, &tlsb_bus_ops); + STAILQ_INIT(&sc->intr_handlers); tlsb0_softc = sc; @@ -252,8 +202,8 @@ tlsb_bus_probe(bus_t parent, device_t dev) tdev->td_swrev = TLDEV_SWREV(tldev); tdev->td_hwrev = TLDEV_HWREV(tldev); - subdev = bus_add_device(&sc->bus, NULL, -1, tdev); - device_set_desc(subdev, tlsb_node_type_str(tdev->td_dtype)); + child = device_add_child(dev, NULL, -1, tdev); + device_set_desc(child, tlsb_node_type_str(tdev->td_dtype)); /* * Deal with hooking CPU instances to TurboLaser nodes. @@ -277,6 +227,58 @@ tlsb_bus_probe(bus_t parent, device_t dev) } static void +tlsb_print_child(device_t dev, device_t child) +{ + struct tlsb_device* tdev = DEVTOTLSB(child); + + printf(" at %s%d node %d", + device_get_name(dev), + device_get_unit(dev), + tdev->td_node); +} + +static int +tlsb_read_ivar(device_t dev, device_t child, + int index, u_long* result) +{ + struct tlsb_device* tdev = DEVTOTLSB(child); + + switch (index) { + case TLSB_IVAR_NODE: + *result = tdev->td_node; + break; + + case TLSB_IVAR_DTYPE: + *result = tdev->td_dtype; + break; + + case TLSB_IVAR_SWREV: + *result = tdev->td_swrev; + break; + + case TLSB_IVAR_HWREV: + *result = tdev->td_hwrev; + break; + } + return ENOENT; +} + +static int +tlsb_map_intr(device_t dev, device_t child, driver_intr_t *intr, void *arg) +{ + struct tlsb_softc* sc = device_get_softc(dev); + struct intr_mapping* i; + i = malloc(sizeof(struct intr_mapping), M_DEVBUF, M_NOWAIT); + if (!i) + return ENOMEM; + i->intr = intr; + i->arg = arg; + STAILQ_INSERT_TAIL(&sc->intr_handlers, i, queue); + + return 0; +} + +static void tlsb_intr(void* frame, u_long vector) { struct tlsb_softc* sc = tlsb0_softc; @@ -291,7 +293,7 @@ tlsb_intr(void* frame, u_long vector) i->intr(i->arg); } -DRIVER_MODULE(tlsb, root, tlsb_bus_driver, tlsb_devclass, 0, 0); +DRIVER_MODULE(tlsb, root, tlsb_driver, tlsb_devclass, 0, 0); static char * tlsb_node_type_str(u_int32_t dtype) diff --git a/sys/alpha/tlsb/tlsbvar.h b/sys/alpha/tlsb/tlsbvar.h index bfb24ed..6b72785 100644 --- a/sys/alpha/tlsb/tlsbvar.h +++ b/sys/alpha/tlsb/tlsbvar.h @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $Id: tlsbvar.h,v 1.1 1998/06/10 10:55:58 dfr Exp $ */ /* $NetBSD: tlsbvar.h,v 1.5 1998/05/13 23:23:23 thorpej Exp $ */ /* @@ -55,7 +55,7 @@ enum tlsb_device_instvars { static __inline T tlsb_get_ ## A(device_t dev) \ { \ u_long v; \ - bus_read_ivar(device_get_parent(dev), dev, TLSB_IVAR_ ## B, &v); \ + BUS_READ_IVAR(device_get_parent(dev), dev, TLSB_IVAR_ ## B, &v); \ return v; \ } diff --git a/sys/alpha/tlsb/zs_tlsb.c b/sys/alpha/tlsb/zs_tlsb.c index 8532ed3..bc20705 100644 --- a/sys/alpha/tlsb/zs_tlsb.c +++ b/sys/alpha/tlsb/zs_tlsb.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: zs_tlsb.c,v 1.1 1998/06/10 10:55:59 dfr Exp $ */ /* * This driver is a hopeless hack to get the SimOS console working. A real @@ -47,6 +47,7 @@ #include <alpha/tlsb/gbusvar.h> #include <alpha/tlsb/tlsbreg.h> /* XXX */ #include <alpha/tlsb/zsreg.h> +#include <alpha/tlsb/zsvar.h> #define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr))) @@ -96,31 +97,35 @@ struct consdev zs_cons = { static caddr_t zs_console_addr; static int zs_console; -static int zs_probe(bus_t, device_t); -static int zs_attach(bus_t, device_t); +static int zs_probe(device_t); +static int zs_attach(device_t); static devclass_t zs_devclass; static devclass_t zsc_devclass; -driver_t zs_driver = { +static device_method_t zs_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, zs_probe), + DEVMETHOD(device_attach, zs_attach), + + { 0, 0 } +}; + +static driver_t zs_driver = { "zs", - zs_probe, - zs_attach, - NULL, - NULL, + zs_methods, DRIVER_TYPE_MISC, sizeof(struct zs_softc), - NULL, }; static int -zs_probe(bus_t bus, device_t dev) +zs_probe(device_t dev) { return 0; } static int -zs_attach(bus_t bus, device_t dev) +zs_attach(device_t dev) { struct zs_softc *sc = device_get_softc(dev); @@ -355,34 +360,38 @@ CDEV_DRIVER_MODULE(zs, zsc, zs_driver, zs_devclass, */ struct zsc_softc { - struct bus bus; caddr_t base; struct zs_softc* sc_a; struct zs_softc* sc_b; }; -static driver_probe_t zsc_tlsb_probe; -static driver_attach_t zsc_tlsb_attach; -static driver_intr_t zsc_tlsb_intr; -static bus_print_device_t zsc_tlsb_print_device; +static int zsc_tlsb_probe(device_t dev); +static int zsc_tlsb_attach(device_t dev); +static void zsc_tlsb_print_child(device_t dev, device_t child); +static driver_intr_t zsc_tlsb_intr; + + +static device_method_t zsc_tlsb_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, zsc_tlsb_probe), + DEVMETHOD(device_attach, zsc_tlsb_attach), + DEVMETHOD(device_detach, bus_generic_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + + /* Bus interface */ + DEVMETHOD(bus_print_child, zsc_tlsb_print_child), + DEVMETHOD(bus_read_ivar, bus_generic_read_ivar), + DEVMETHOD(bus_write_ivar, bus_generic_write_ivar), + DEVMETHOD(bus_map_intr, bus_generic_map_intr), -driver_t zsc_tlsb_driver = { + { 0, 0 } +}; + +static driver_t zsc_tlsb_driver = { "zsc", - zsc_tlsb_probe, - zsc_tlsb_attach, - NULL, - NULL, + zsc_tlsb_methods, DRIVER_TYPE_MISC, sizeof(struct zsc_softc), - NULL, -}; - - -static bus_ops_t zsc_tlsb_ops = { - zsc_tlsb_print_device, - null_read_ivar, - null_write_ivar, - null_map_intr, }; static int @@ -394,56 +403,51 @@ zsc_get_channel(device_t dev) static caddr_t zsc_get_base(device_t dev) { - device_t busdev = bus_get_device(device_get_parent(dev)); - struct zsc_softc* sc = device_get_softc(busdev); + device_t bus = device_get_parent(dev); + struct zsc_softc* sc = device_get_softc(bus); return sc->base; } -static void -zsc_tlsb_print_device(bus_t bus, device_t dev) -{ - device_t busdev = bus_get_device(bus); - - printf(" at %s%d channel %c", - device_get_name(busdev), device_get_unit(busdev), - 'A' + (device_get_unit(dev) & 1)); -} - static int -zsc_tlsb_probe(bus_t parent, device_t dev) +zsc_tlsb_probe(device_t dev) { struct zsc_softc* sc = device_get_softc(dev); device_set_desc(dev, "Z8530 uart"); - bus_init(&sc->bus, dev, &zsc_tlsb_ops); - sc->base = (caddr_t) ALPHA_PHYS_TO_K0SEG(TLSB_GBUS_BASE + gbus_get_offset(dev)); /* * Add channel A for now. */ - bus_add_device(&sc->bus, "zs", -1, (void*) 0); + device_add_child(dev, "zs", -1, (void*) 0); return 0; } static int -zsc_tlsb_attach(bus_t parent, device_t dev) +zsc_tlsb_attach(device_t dev) { struct zsc_softc* sc = device_get_softc(dev); - bus_generic_attach(parent, dev); + bus_generic_attach(dev); /* XXX */ sc->sc_a = ZS_SOFTC(0); - bus_map_intr(parent, dev, zsc_tlsb_intr, sc); + BUS_MAP_INTR(device_get_parent(dev), dev, zsc_tlsb_intr, sc); return 0; } +static void +zsc_tlsb_print_child(device_t bus, device_t dev) +{ + printf(" at %s%d channel %c", + device_get_name(bus), device_get_unit(bus), + 'A' + (device_get_unit(dev) & 1)); +} static void zsc_tlsb_intr(void* arg) diff --git a/sys/conf/Makefile.alpha b/sys/conf/Makefile.alpha index ecc9daa..51cb957 100644 --- a/sys/conf/Makefile.alpha +++ b/sys/conf/Makefile.alpha @@ -1,7 +1,7 @@ # Makefile.alpha -- with config changes. # Copyright 1990 W. Jolitz # from: @(#)Makefile.alpha 7.1 5/10/91 -# $Id: Makefile.alpha,v 1.109 1998/04/17 07:51:36 dima Exp $ +# $Id: Makefile.alpha,v 1.1 1998/06/10 10:53:59 dfr Exp $ # # Makefile for FreeBSD # @@ -30,6 +30,9 @@ S= ../.. .endif ALPHA= ${S}/alpha +HCC?=${CC} +SIZE?=size + COPTFLAGS?=-O INCLUDES= -nostdinc -I- -I. -I$S # This hack is to allow kernel compiles to succeed on machines w/out srcdist @@ -59,6 +62,9 @@ DRIVER_C_C= ${CC} -c ${CFLAGS} ${PROF} ${PARAM} $< DRIVER_S= ${CC} -c -x assembler-with-cpp -DLOCORE ${COPTS} $< PROFILE_C= ${CC} -c ${CFLAGS} ${PARAM} $< +NORMAL_M= sh $S/kern/makedevops.sh -c $<;\ + ${CC} -c ${CFLAGS} ${PROF} `basename $< .m`.c + # ${ALPHA}/alpha/setdef0.c and ${ALPHA}/alpha/setdef1.c are intentionally # omitted from SYSTEM_CFILES. They depend on setdefs.h, a header which # is generated from all of ${OBJS}. We don't want to have to compile @@ -71,11 +77,12 @@ SYMORDER_EXCLUDE=-x symbols.exclude .endif SYSTEM_LD_HEAD= @echo loading $@; rm -f $@ .if ${BINFORMAT} == elf -SYSTEM_OBJS= locore.o setdef0.o vnode_if.o ${OBJS} ioconf.o param.o config.o \ +SYSTEM_OBJS= locore.o setdef0.o vnode_if.o \ + ${OBJS} ioconf.o param.o config.o \ setdef1.o SYSTEM_LD= @${LD} -Bstatic -N -Ttext ${LOAD_ADDRESS} -e locorestart -defsym _DYNAMIC=0 \ -o $@ -X ${SYSTEM_OBJS} vers.o -SYSTEM_LD_TAIL= @size $@; chmod 755 $@ +SYSTEM_LD_TAIL= @${SIZE} $@; chmod 755 $@ .endif %BEFORE_DEPEND @@ -123,10 +130,10 @@ setdefs.h: gensetdefs ${OBJS} @./gensetdefs ${OBJS} >setdefs.h gensetdefs: gensetdefs.o - ${CC} ${CFLAGS} gensetdefs.o -o $@ + ${HCC} gensetdefs.o -o $@ gensetdefs.o: ${ALPHA}/alpha/gensetdefs.c - ${CC} -c ${CFLAGS} ${ALPHA}/alpha/gensetdefs.c + ${HCC} ${CFLAGS} -c ${ALPHA}/alpha/gensetdefs.c # everything potentially depends on the Makefile since everything potentially # depends on the options. Some things are more dependent on the Makefile for @@ -151,10 +158,10 @@ assym.s: genassym # Some of the defines that genassym outputs may well depend on the # value of kernel options. genassym.o: ${ALPHA}/alpha/genassym.c Makefile opt_global.h - ${CC} -c ${CFLAGS} ${PARAM} -UKERNEL ${ALPHA}/alpha/genassym.c + ${HCC} -c ${COPTS} ${PARAM} -UKERNEL ${ALPHA}/alpha/genassym.c genassym: genassym.o - ${CC} ${CFLAGS} ${PARAM} genassym.o -o $@ + ${HCC} ${COPTS} ${PARAM} genassym.o -o $@ SYSTEM_OBJS+= __divqu.o __divq.o __divlu.o __divl.o SYSTEM_OBJS+= __remqu.o __remq.o __remlu.o __reml.o diff --git a/sys/conf/files b/sys/conf/files index 957a92a..bc9694b 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -86,7 +86,7 @@ kern/inflate.c optional gzip kern/init_main.c standard kern/init_sysent.c standard kern/init_sysvec.c standard -kern/kern_intr.c standard +#kern/kern_intr.c standard kern/kern_module.c standard kern/kern_linker.c standard kern/link_aout.c standard diff --git a/sys/conf/files.alpha b/sys/conf/files.alpha index 04e5410..57c00a6 100644 --- a/sys/conf/files.alpha +++ b/sys/conf/files.alpha @@ -1,7 +1,7 @@ # This file tells config what files go into building a kernel, # files marked standard are always included. # -# $Id$ +# $Id: files.alpha,v 1.1 1998/06/10 10:54:08 dfr Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -48,6 +48,14 @@ alpha/alpha/interrupt.c standard alpha/alpha/userconfig.c optional userconfig alpha/alpha/vm_machdep.c standard alpha/alpha/clock.c standard +alpha/alpha/clock_if.m standard \ + dependency "$S/kern/makedevops.sh" \ + clean "clock_if.c" +clock_if.h standard \ + dependency "$S/kern/makedevops.sh $S/alpha/alpha/clock_if.m" \ + compile-with "sh $S/kern/makedevops.sh -h $S/alpha/alpha/clock_if.m" \ + no-obj no-implicit-rule before-depend \ + clean "clock_if.h" alpha/alpha/diskslice_machdep.c standard alpha/tlsb/tlsb.c optional tlsb alpha/tlsb/gbus.c optional gbus @@ -56,8 +64,32 @@ alpha/tlsb/mcclock_tlsb.c optional gbus alpha/tlsb/zs_tlsb.c optional gbus alpha/tlsb/dwlpx.c optional dwlpx dev/dec/mcclock.c optional gbus +dev/dec/mcclock_if.m optional gbus \ + dependency "$S/kern/makedevops.sh" \ + clean "mcclock_if.c" +mcclock_if.h standard \ + dependency "$S/kern/makedevops.sh $S/dev/dec/mcclock_if.m" \ + compile-with "sh $S/kern/makedevops.sh -h $S/dev/dec/mcclock_if.m" \ + no-obj no-implicit-rule before-depend \ + clean "mcclock_if.h" alpha/pci/pcibus.c optional pci kern/subr_bus.c standard +kern/device_if.m standard \ + dependency "$S/kern/makedevops.sh" \ + clean "device_if.c" +device_if.h standard \ + dependency "$S/kern/makedevops.sh $S/kern/device_if.m" \ + compile-with "sh $S/kern/makedevops.sh -h $S/kern/device_if.m" \ + no-obj no-implicit-rule before-depend \ + clean "device_if.h" +kern/bus_if.m standard \ + dependency "$S/kern/makedevops.sh" \ + clean "bus_if.c" +bus_if.h standard \ + dependency "$S/kern/makedevops.sh $S/kern/bus_if.m" \ + compile-with "sh $S/kern/makedevops.sh -h $S/kern/bus_if.m" \ + no-obj no-implicit-rule before-depend \ + clean "bus_if.h" libkern/bcd.c standard libkern/bcmp.c standard libkern/ffs.c standard diff --git a/sys/dev/dec/clockvar.h b/sys/dev/dec/clockvar.h deleted file mode 100644 index 920d162..0000000 --- a/sys/dev/dec/clockvar.h +++ /dev/null @@ -1,62 +0,0 @@ -/* $NetBSD: clockvar.h,v 1.4 1997/06/22 08:02:18 jonathan Exp $ */ - -/* - * Copyright (c) 1994, 1995 Carnegie-Mellon University. - * All rights reserved. - * - * Author: Chris G. Demetriou - * - * Permission to use, copy, modify and distribute this software and - * its documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND - * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -/* - * Definitions for cpu-independent clock handling for the alpha and pmax. - */ - -/* - * clocktime structure: - * - * structure passed to TOY clocks when setting them. broken out this - * way, so that the time_t -> field conversion can be shared. - */ -struct clocktime { - int year; /* year - 1900 */ - int mon; /* month (1 - 12) */ - int day; /* day (1 - 31) */ - int hour; /* hour (0 - 23) */ - int min; /* minute (0 - 59) */ - int sec; /* second (0 - 59) */ - int dow; /* day of week (0 - 6; 0 = Sunday) */ -}; - -/* - * clockfns structure: - * - * function switch used by chip-independent clock code, to access - * chip-dependent routines. - */ -struct clockfns { - void (*cf_init) __P((struct device *)); - void (*cf_get) __P((struct device *, time_t, struct clocktime *)); - void (*cf_set) __P((struct device *, struct clocktime *)); -}; - -void clockattach __P((device_t, const struct clockfns *)); diff --git a/sys/dev/dec/mc146818reg.h b/sys/dev/dec/mc146818reg.h index 95c3ccf..18cc979 100644 --- a/sys/dev/dec/mc146818reg.h +++ b/sys/dev/dec/mc146818reg.h @@ -142,14 +142,6 @@ #define MC_BASE_NONE 0x60 /* actually, both of these reset */ #define MC_BASE_RESET 0x70 - -/* - * RTC register/NVRAM read and write functions -- machine-dependent. - * Appropriately manipulate RTC registers to get/put data values. - */ -u_int mc146818_read __P((void *sc, u_int reg)); -void mc146818_write __P((void *sc, u_int reg, u_int datum)); - /* * A collection of TOD/Alarm registers. */ @@ -159,36 +151,36 @@ typedef u_int mc_todregs[MC_NTODREGS]; * Get all of the TOD/Alarm registers * Must be called at splhigh(), and with the RTC properly set up. */ -#define MC146818_GETTOD(sc, regs) \ +#define MC146818_GETTOD(dev, regs) \ do { \ int i; \ \ /* update in progress; spin loop */ \ - while (mc146818_read(sc, MC_REGA) & MC_REGA_UIP) \ + while (MCCLOCK_READ(dev, MC_REGA) & MC_REGA_UIP) \ ; \ \ /* read all of the tod/alarm regs */ \ for (i = 0; i < MC_NTODREGS; i++) \ - (*regs)[i] = mc146818_read(sc, i); \ + (*regs)[i] = MCCLOCK_READ(dev, i); \ } while (0); /* * Set all of the TOD/Alarm registers * Must be called at splhigh(), and with the RTC properly set up. */ -#define MC146818_PUTTOD(sc, regs) \ +#define MC146818_PUTTOD(dev, regs) \ do { \ int i; \ \ /* stop updates while setting */ \ - mc146818_write(sc, MC_REGB, \ - mc146818_read(sc, MC_REGB) | MC_REGB_SET); \ + MCCLOCK_WRITE(dev, MC_REGB, \ + MCCLOCK_READ(dev, MC_REGB) | MC_REGB_SET); \ \ /* write all of the tod/alarm regs */ \ for (i = 0; i < MC_NTODREGS; i++) \ - mc146818_write(sc, i, (*regs)[i]); \ + MCCLOCK_WRITE(dev, i, (*regs)[i]); \ \ /* reenable updates */ \ - mc146818_write(sc, MC_REGB, \ - mc146818_read(sc, MC_REGB) & ~MC_REGB_SET); \ + MCCLOCK_WRITE(dev, MC_REGB, \ + MCCLOCK_READ(dev, MC_REGB) & ~MC_REGB_SET); \ } while (0); diff --git a/sys/dev/dec/mcclock.c b/sys/dev/dec/mcclock.c index 76e3805..3aada8b 100644 --- a/sys/dev/dec/mcclock.c +++ b/sys/dev/dec/mcclock.c @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $Id: mcclock.c,v 1.1 1998/06/10 10:56:23 dfr Exp $ */ /* $NetBSD: mcclock.c,v 1.11 1998/04/19 07:50:25 jonathan Exp $ */ /* @@ -33,7 +33,7 @@ #include <sys/systm.h> #include <sys/bus.h> -#include <dev/dec/clockvar.h> +#include <machine/clockvar.h> #include <dev/dec/mcclockvar.h> #include <dev/dec/mc146818reg.h> @@ -47,41 +47,20 @@ #define MC_DEFAULTRATE MC_RATE_256_Hz #endif - -void mcclock_init __P((struct device *)); -void mcclock_get __P((struct device *, time_t, struct clocktime *)); -void mcclock_set __P((struct device *, struct clocktime *)); - -const struct clockfns mcclock_clockfns = { - mcclock_init, mcclock_get, mcclock_set, -}; - -#define mc146818_write(dev, reg, datum) \ - (*(dev)->sc_busfns->mc_bf_write)(dev, reg, datum) -#define mc146818_read(dev, reg) \ - (*(dev)->sc_busfns->mc_bf_read)(dev, reg) - void -mcclock_attach(sc, busfns) - struct mcclock_softc *sc; - const struct mcclock_busfns *busfns; +mcclock_attach(device_t dev) { - sc->sc_busfns = busfns; - /* Turn interrupts off, just in case. */ - mc146818_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR); + MCCLOCK_WRITE(dev, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR); - clockattach(sc->sc_dev, &mcclock_clockfns); + clockattach(dev); } void -mcclock_init(dev) - device_t dev; +mcclock_init(device_t dev) { - struct mcclock_softc *sc = device_get_softc(dev); - - mc146818_write(sc, MC_REGA, MC_BASE_32_KHz | MC_DEFAULTRATE); - mc146818_write(sc, MC_REGB, + MCCLOCK_WRITE(dev, MC_REGA, MC_BASE_32_KHz | MC_DEFAULTRATE); + MCCLOCK_WRITE(dev, MC_REGB, MC_REGB_PIE | MC_REGB_SQWE | MC_REGB_BINARY | MC_REGB_24HR); } @@ -89,17 +68,13 @@ mcclock_init(dev) * Get the time of day, based on the clock's value and/or the base value. */ void -mcclock_get(dev, base, ct) - struct device *dev; - time_t base; - struct clocktime *ct; +mcclock_get(device_t dev, time_t base, struct clocktime *ct) { - struct mcclock_softc *sc = device_get_softc(dev); mc_todregs regs; int s; s = splclock(); - MC146818_GETTOD(sc, ®s) + MC146818_GETTOD(dev, ®s) splx(s); ct->sec = regs[MC_SEC]; @@ -115,16 +90,13 @@ mcclock_get(dev, base, ct) * Reset the TODR based on the time value. */ void -mcclock_set(dev, ct) - struct device *dev; - struct clocktime *ct; +mcclock_set(device_t dev, struct clocktime *ct) { - struct mcclock_softc *sc = device_get_softc(dev); mc_todregs regs; int s; s = splclock(); - MC146818_GETTOD(sc, ®s); + MC146818_GETTOD(dev, ®s); splx(s); regs[MC_SEC] = ct->sec; @@ -136,6 +108,6 @@ mcclock_set(dev, ct) regs[MC_YEAR] = ct->year; s = splclock(); - MC146818_PUTTOD(sc, ®s); + MC146818_PUTTOD(dev, ®s); splx(s); } diff --git a/sys/dev/dec/mcclockvar.h b/sys/dev/dec/mcclockvar.h index d2c0ac8..0c9f5df 100644 --- a/sys/dev/dec/mcclockvar.h +++ b/sys/dev/dec/mcclockvar.h @@ -27,15 +27,9 @@ * rights to redistribute these changes. */ -struct mcclock_softc { - device_t sc_dev; - const struct mcclock_busfns *sc_busfns; -}; +#include "mcclock_if.h" -struct mcclock_busfns { - void (*mc_bf_write) __P((struct mcclock_softc *, u_int, u_int)); - u_int (*mc_bf_read) __P((struct mcclock_softc *, u_int)); -}; - -void mcclock_attach __P((struct mcclock_softc *, - const struct mcclock_busfns *)); +void mcclock_attach(device_t dev); +void mcclock_init(device_t); +void mcclock_get(device_t, time_t, struct clocktime *); +void mcclock_set(device_t, struct clocktime *); diff --git a/sys/dev/mc146818/mc146818reg.h b/sys/dev/mc146818/mc146818reg.h index 95c3ccf..18cc979 100644 --- a/sys/dev/mc146818/mc146818reg.h +++ b/sys/dev/mc146818/mc146818reg.h @@ -142,14 +142,6 @@ #define MC_BASE_NONE 0x60 /* actually, both of these reset */ #define MC_BASE_RESET 0x70 - -/* - * RTC register/NVRAM read and write functions -- machine-dependent. - * Appropriately manipulate RTC registers to get/put data values. - */ -u_int mc146818_read __P((void *sc, u_int reg)); -void mc146818_write __P((void *sc, u_int reg, u_int datum)); - /* * A collection of TOD/Alarm registers. */ @@ -159,36 +151,36 @@ typedef u_int mc_todregs[MC_NTODREGS]; * Get all of the TOD/Alarm registers * Must be called at splhigh(), and with the RTC properly set up. */ -#define MC146818_GETTOD(sc, regs) \ +#define MC146818_GETTOD(dev, regs) \ do { \ int i; \ \ /* update in progress; spin loop */ \ - while (mc146818_read(sc, MC_REGA) & MC_REGA_UIP) \ + while (MCCLOCK_READ(dev, MC_REGA) & MC_REGA_UIP) \ ; \ \ /* read all of the tod/alarm regs */ \ for (i = 0; i < MC_NTODREGS; i++) \ - (*regs)[i] = mc146818_read(sc, i); \ + (*regs)[i] = MCCLOCK_READ(dev, i); \ } while (0); /* * Set all of the TOD/Alarm registers * Must be called at splhigh(), and with the RTC properly set up. */ -#define MC146818_PUTTOD(sc, regs) \ +#define MC146818_PUTTOD(dev, regs) \ do { \ int i; \ \ /* stop updates while setting */ \ - mc146818_write(sc, MC_REGB, \ - mc146818_read(sc, MC_REGB) | MC_REGB_SET); \ + MCCLOCK_WRITE(dev, MC_REGB, \ + MCCLOCK_READ(dev, MC_REGB) | MC_REGB_SET); \ \ /* write all of the tod/alarm regs */ \ for (i = 0; i < MC_NTODREGS; i++) \ - mc146818_write(sc, i, (*regs)[i]); \ + MCCLOCK_WRITE(dev, i, (*regs)[i]); \ \ /* reenable updates */ \ - mc146818_write(sc, MC_REGB, \ - mc146818_read(sc, MC_REGB) & ~MC_REGB_SET); \ + MCCLOCK_WRITE(dev, MC_REGB, \ + MCCLOCK_READ(dev, MC_REGB) & ~MC_REGB_SET); \ } while (0); diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 883666d..d0e789d 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1997 Doug Rabson + * Copyright (c) 1997,1998 Doug Rabson * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: subr_bus.c,v 1.1 1998/06/10 10:56:45 dfr Exp $ */ #include <sys/param.h> @@ -34,45 +34,98 @@ #include <sys/bus_private.h> #include <sys/systm.h> -device_t -bus_get_device(bus_t bus) -{ - return bus->dev; -} +/* + * Method table handling + */ -void -bus_print_device(bus_t bus, device_t dev) -{ - printf("%s%d", device_get_name(dev), device_get_unit(dev)); - if (device_is_alive(dev)) { - if (device_get_desc(dev)) - printf(": <%s>", device_get_desc(dev)); - bus->ops->print_device(bus, dev); - } else - printf(" not found"); - printf("\n"); -} +static int next_method_offset = 1; +static int methods_count = 0; +static int methods_size = 0; -int -bus_read_ivar(bus_t bus, device_t dev, - int index, u_long *result) +struct method { + int offset; + char* name; +}; + +static struct method *methods = 0; + +static void +register_method(struct device_op_desc *desc) { - return bus->ops->read_ivar(bus, dev, index, result); + int i; + struct method* m; + + for (i = 0; i < methods_count; i++) + if (!strcmp(methods[i].name, desc->name)) { + desc->offset = methods[i].offset; + return; + } + + if (methods_count == methods_size) { + struct method* p; + + methods_size += 10; + p = (struct method*) malloc(methods_size * sizeof(struct method), + M_DEVBUF, M_NOWAIT); + if (!p) + panic("register_method: out of memory"); + if (methods) { + bcopy(methods, p, methods_count * sizeof(struct method)); + free(methods, M_DEVBUF); + } + methods = p; + } + m = &methods[methods_count++]; + m->name = malloc(strlen(desc->name) + 1, M_DEVBUF, M_NOWAIT); + if (!m->name) + panic("register_method: out of memory"); + strcpy(m->name, desc->name); + desc->offset = m->offset = next_method_offset++; } -int -bus_write_ivar(bus_t bus, device_t dev, - int index, u_long value) +static int error_method(void) { - return bus->ops->write_ivar(bus, dev, index, value); + return ENXIO; } -int -bus_map_intr(bus_t bus, device_t dev, driver_intr_t *intr, void *arg) +static struct device_ops null_ops = { + 1, + { error_method } +}; + +static void +compile_methods(driver_t *driver) { - return bus->ops->map_intr(bus, dev, intr, arg); + device_ops_t ops; + struct device_method *m; + int i; + + /* + * First register any methods which need it. + */ + for (i = 0, m = driver->methods; m->desc; i++, m++) + if (!m->desc->offset) + register_method(m->desc); + + /* + * Then allocate the compiled op table. + */ + ops = malloc(sizeof(struct device_ops) + (next_method_offset-1) * sizeof(devop_t), + M_DEVBUF, M_NOWAIT); + if (!ops) + panic("compile_methods: out of memory"); + ops->maxoffset = next_method_offset; + for (i = 0; i < next_method_offset; i++) + ops->methods[i] = error_method; + for (i = 0, m = driver->methods; m->desc; i++, m++) + ops->methods[m->desc->offset] = m->func; + driver->ops = ops; } +/* + * Devclass implementation + */ + static devclass_list_t devclasses; static void @@ -117,6 +170,11 @@ int devclass_add_driver(devclass_t dc, driver_t *driver) { /* + * Compile the drivers methods. + */ + compile_methods(driver); + + /* * Make sure the devclass which the driver is implementing exists. */ devclass_find_internal(driver->name, TRUE); @@ -129,7 +187,7 @@ devclass_add_driver(devclass_t dc, driver_t *driver) int devclass_delete_driver(devclass_t dc, driver_t *driver) { - bus_t bus; + device_t bus; device_t dev; int i; int error; @@ -140,11 +198,11 @@ devclass_delete_driver(devclass_t dc, driver_t *driver) */ for (i = 0; i < dc->maxunit; i++) { if (dc->devices[i]) { - bus = dc->devices[i]->softc; - for (dev = TAILQ_FIRST(&bus->devices); dev; + bus = dc->devices[i]->parent; + for (dev = TAILQ_FIRST(&bus->children); dev; dev = TAILQ_NEXT(dev, link)) if (dev->driver == driver) { - if (error = device_detach(dev)) + if (error = DEVICE_DETACH(dev)) return error; device_set_driver(dev, NULL); } @@ -305,7 +363,7 @@ devclass_delete_device(devclass_t dc, device_t dev) } static device_t -make_device(bus_t bus, const char *name, +make_device(device_t parent, const char *name, int unit, void *ivars) { driver_t *driver; @@ -329,7 +387,9 @@ make_device(bus_t bus, const char *name, if (!dev) return 0; - dev->parent = bus; + dev->parent = parent; + TAILQ_INIT(&dev->children); + dev->ops = &null_ops; dev->driver = NULL; dev->devclass = dc; dev->unit = unit; @@ -351,53 +411,58 @@ make_device(bus_t bus, const char *name, return dev; } -void -bus_init(bus_t bus, device_t dev, bus_ops_t *ops) +static void +device_print_child(device_t dev, device_t child) { - bus->ops = ops; - bus->dev = dev; - TAILQ_INIT(&bus->devices); + printf("%s%d", device_get_name(child), device_get_unit(child)); + if (device_is_alive(child)) { + if (device_get_desc(child)) + printf(": <%s>", device_get_desc(child)); + BUS_PRINT_CHILD(dev, child); + } else + printf(" not found"); + printf("\n"); } device_t -bus_add_device(bus_t bus, const char *name, int unit, void *ivars) +device_add_child(device_t dev, const char *name, int unit, void *ivars) { - device_t dev; + device_t child; - dev = make_device(bus, name, unit, ivars); + child = make_device(dev, name, unit, ivars); - TAILQ_INSERT_TAIL(&bus->devices, dev, link); + TAILQ_INSERT_TAIL(&dev->children, child, link); - return dev; + return child; } device_t -bus_add_device_after(bus_t bus, device_t place, const char *name, - int unit, void *ivars) +device_add_child_after(device_t dev, device_t place, const char *name, + int unit, void *ivars) { - device_t dev; + device_t child; - dev = make_device(bus, name, unit, ivars); + child = make_device(dev, name, unit, ivars); if (place) { - TAILQ_INSERT_AFTER(&bus->devices, place, dev, link); + TAILQ_INSERT_AFTER(&dev->children, place, dev, link); } else { - TAILQ_INSERT_HEAD(&bus->devices, dev, link); + TAILQ_INSERT_HEAD(&dev->children, dev, link); } - return dev; + return child; } int -bus_delete_device(bus_t bus, device_t dev) +device_delete_child(device_t dev, device_t child) { int error; - if (error = device_detach(dev)) + if (error = DEVICE_DETACH(child)) return error; - if (dev->devclass) - devclass_delete_device(dev->devclass, dev); - TAILQ_REMOVE(&bus->devices, dev, link); + if (child->devclass) + devclass_delete_device(child->devclass, child); + TAILQ_REMOVE(&dev->children, child, link); free(dev, M_DEVBUF); return 0; @@ -407,18 +472,18 @@ bus_delete_device(bus_t bus, device_t dev) * Find only devices attached to this bus. */ device_t -bus_find_device(bus_t bus, const char *classname, int unit) +device_find_child(device_t dev, const char *classname, int unit) { devclass_t dc; - device_t dev; + device_t child; dc = devclass_find(classname); if (!dc) return NULL; - dev = devclass_get_device(dc, unit); - if (dev && dev->parent == bus) - return dev; + child = devclass_get_device(dc, unit); + if (child && child->parent == dev) + return child; return NULL; } @@ -446,27 +511,27 @@ next_matching_driver(devclass_t dc, device_t dev, driver_t *last) } static int -bus_probe_device(bus_t bus, device_t dev) +device_probe_child(device_t dev, device_t child) { devclass_t dc; driver_t *driver; void *softc; - dc = bus->dev->devclass; + dc = dev->devclass; if (dc == NULL) - panic("bus_probe_device: bus' device has no devclass"); + panic("device_probe_child: parent device has no devclass"); - if (dev->state == DS_ALIVE) + if (child->state == DS_ALIVE) return 0; - for (driver = first_matching_driver(dc, dev); + for (driver = first_matching_driver(dc, child); driver; - driver = next_matching_driver(dc, dev, driver)) { - device_set_driver(dev, driver); - if (driver->probe(bus, dev) == 0) { - if (!dev->devclass) - device_set_devclass(dev, driver->name); - dev->state = DS_ALIVE; + driver = next_matching_driver(dc, child, driver)) { + device_set_driver(child, driver); + if (DEVICE_PROBE(child) == 0) { + if (!child->devclass) + device_set_devclass(child, driver->name); + child->state = DS_ALIVE; return 0; } } @@ -474,51 +539,7 @@ bus_probe_device(bus_t bus, device_t dev) return ENXIO; } -int -bus_generic_attach(bus_t parent, device_t busdev) -{ - bus_t bus = busdev->softc; - device_t dev; - int error; - - for (dev = TAILQ_FIRST(&bus->devices); - dev; dev = TAILQ_NEXT(dev, link)) - device_probe_and_attach(dev); - - return 0; -} - -int -bus_generic_detach(bus_t parent, device_t busdev) -{ - bus_t bus = busdev->softc; - device_t dev; - int error; - - if (busdev->state != DS_ATTACHED) - return EBUSY; - - for (dev = TAILQ_FIRST(&bus->devices); - dev; dev = TAILQ_NEXT(dev, link)) - device_detach(dev); - - return 0; -} - -int -bus_generic_shutdown(bus_t parent, device_t busdev) -{ - bus_t bus = busdev->softc; - device_t dev; - - for (dev = TAILQ_FIRST(&bus->devices); - dev; dev = TAILQ_NEXT(dev, link)) - device_shutdown(dev); - - return 0; -} - -bus_t +device_t device_get_parent(device_t dev) { return dev->parent; @@ -598,7 +619,7 @@ device_busy(device_t dev) if (dev->state < DS_ATTACHED) panic("device_busy: called for unattached device"); if (dev->busy == 0 && dev->parent) - device_busy(dev->parent->dev); + device_busy(dev->parent); dev->busy++; dev->state = DS_BUSY; } @@ -610,8 +631,8 @@ device_unbusy(device_t dev) panic("device_unbusy: called for non-busy device"); dev->busy--; if (dev->busy == 0) { - if (dev->parent->dev) - device_unbusy(dev->parent->dev); + if (dev->parent) + device_unbusy(dev->parent); dev->state = DS_ATTACHED; } } @@ -658,8 +679,10 @@ device_set_driver(device_t dev, driver_t *driver) free(dev->softc, M_DEVBUF); dev->softc = NULL; } + dev->ops = &null_ops; dev->driver = driver; if (driver) { + dev->ops = driver->ops; dev->softc = malloc(driver->softc, M_DEVBUF, M_NOWAIT); bzero(dev->softc, driver->softc); } @@ -669,17 +692,17 @@ device_set_driver(device_t dev, driver_t *driver) int device_probe_and_attach(device_t dev) { - bus_t bus = dev->parent; + device_t bus = dev->parent; int error; if (dev->state >= DS_ALIVE) return 0; if (dev->flags & DF_ENABLED) { - bus_probe_device(bus, dev); - bus_print_device(bus, dev); + device_probe_child(bus, dev); + device_print_child(bus, dev); if (dev->state == DS_ALIVE) { - error = dev->driver->attach(bus, dev); + error = DEVICE_ATTACH(dev); if (!error) dev->state = DS_ATTACHED; else { @@ -706,11 +729,8 @@ device_detach(device_t dev) if (dev->state != DS_ATTACHED) return 0; - if (dev->driver->detach) { - if (error = dev->driver->detach(dev->parent, dev)) + if (error = DEVICE_DETACH(dev)) return error; - } else - return EBUSY; if (!(dev->flags & DF_FIXEDCLASS)) devclass_delete_device(dev->devclass, dev); @@ -726,67 +746,108 @@ device_shutdown(device_t dev) { if (dev->state < DS_ATTACHED) return 0; - if (dev->driver->shutdown) - return dev->driver->shutdown(dev->parent, dev); - else - return 0; + return DEVICE_SHUTDOWN(dev); +} + +/* + * Some useful method implementations to make life easier for bus drivers. + */ +int +bus_generic_attach(device_t dev) +{ + device_t child; + int error; + + for (child = TAILQ_FIRST(&dev->children); + child; child = TAILQ_NEXT(child, link)) + device_probe_and_attach(child); + + return 0; +} + +int +bus_generic_detach(device_t dev) +{ + device_t child; + int error; + + if (dev->state != DS_ATTACHED) + return EBUSY; + + for (child = TAILQ_FIRST(&dev->children); + child; child = TAILQ_NEXT(child, link)) + DEVICE_DETACH(child); + + return 0; +} + +int +bus_generic_shutdown(device_t dev) +{ + device_t child; + + for (child = TAILQ_FIRST(&dev->children); + child; child = TAILQ_NEXT(child, link)) + DEVICE_SHUTDOWN(child); + + return 0; } void -null_print_device(bus_t bus, device_t dev) +bus_generic_print_child(device_t dev, device_t child) { } int -null_read_ivar(bus_t bus, device_t dev, int index, u_long* result) +bus_generic_read_ivar(device_t dev, device_t child, int index, u_long* result) { return ENOENT; } int -null_write_ivar(bus_t bus, device_t dev, int index, u_long value) +bus_generic_write_ivar(device_t dev, device_t child, int index, u_long value) { return ENOENT; } int -null_map_intr(bus_t bus, device_t dev, driver_intr_t *intr, void *arg) +bus_generic_map_intr(device_t dev, device_t child, driver_intr_t *intr, void *arg) { /* Propagate up the bus hierarchy until someone handles it. */ - if (bus->dev) - return bus_map_intr(bus->dev->parent, bus->dev, intr, arg); + if (dev->parent) + return BUS_MAP_INTR(dev->parent, dev, intr, arg); else return EINVAL; } -bus_ops_t null_bus_ops = { - null_print_device, - null_read_ivar, - null_write_ivar, - null_map_intr, -}; - -static void -root_bus_print_device(bus_t bus, device_t dev) -{ -} - -static int root_bus_map_intr(bus_t bus, device_t dev, - driver_intr_t *intr, void *arg) +static int root_map_intr(device_t dev, device_t child, + driver_intr_t *intr, void *arg) { + /* + * If an interrupt mapping gets to here something bad has happened. + * Should probably panic. + */ return EINVAL; } -static bus_ops_t root_bus_ops = { - root_bus_print_device, - null_read_ivar, - null_write_ivar, - root_bus_map_intr, +static device_method_t root_methods[] = { + /* Bus interface */ + DEVMETHOD(bus_print_child, bus_generic_print_child), + DEVMETHOD(bus_read_ivar, bus_generic_read_ivar), + DEVMETHOD(bus_write_ivar, bus_generic_write_ivar), + DEVMETHOD(bus_map_intr, root_map_intr), + + { 0, 0 } +}; + +static driver_t root_driver = { + "root", + root_methods, + DRIVER_TYPE_MISC, + 1, /* no softc */ }; -static struct bus the_root_bus; -bus_t root_bus = &the_root_bus; -device_t root_device; +device_t root_bus; devclass_t root_devclass; static int @@ -795,9 +856,11 @@ root_bus_module_handler(module_t mod, modeventtype_t what, void* arg) switch (what) { case MOD_LOAD: devclass_init(); - root_device = make_device(NULL, "root", 0, NULL); - root_device->state = DS_ATTACHED; - bus_init(root_bus, root_device, &root_bus_ops); + compile_methods(&root_driver); + root_bus = make_device(NULL, "root", 0, NULL); + root_bus->ops = root_driver.ops; + root_bus->driver = &root_driver; + root_bus->state = DS_ATTACHED; root_devclass = devclass_find("root"); return 0; } @@ -818,7 +881,7 @@ root_bus_configure() device_t dev; int error; - for (dev = TAILQ_FIRST(&root_bus->devices); dev; + for (dev = TAILQ_FIRST(&root_bus->children); dev; dev = TAILQ_NEXT(dev, link)) { device_probe_and_attach(dev); } diff --git a/sys/powerpc/powerpc/genassym.c b/sys/powerpc/powerpc/genassym.c index 520bd41..50ebf1d 100644 --- a/sys/powerpc/powerpc/genassym.c +++ b/sys/powerpc/powerpc/genassym.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 - * $Id: genassym.c,v 1.54 1998/04/06 18:59:14 peter Exp $ + * $Id: genassym.c,v 1.1 1998/06/10 10:52:39 dfr Exp $ */ #include <sys/param.h> @@ -64,8 +64,10 @@ int main __P((void)); int printf __P((const char *, ...)); +#define BIG(val) ((val) > 999LL || (val) < -999LL) + #define P(name, val) \ - printf(val > 999 ? "#define\t%s 0x%lx\n" : "#define\t%s %ld\n", name, val) + printf(BIG(val) ? "#define\t%s 0x%qx\n" : "#define\t%s %qd\n", name, val) /* XXX Danger Will Robinson */ struct prochd { @@ -73,9 +75,9 @@ struct prochd { struct proc *ph_rlink; }; -#define OFF(name, type, elem) P(#name, (long)&((type*)0)->elem) -#define CONST2(name, val) P(#name, val) -#define CONST1(name) P(#name, name) +#define OFF(name, type, elem) P(#name, (long long) &((type*)0)->elem) +#define CONST2(name, val) P(#name, (long long) val) +#define CONST1(name) P(#name, (long long) name) int main() diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 54ca3d1..0eb0481 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1997 Doug Rabson + * Copyright (c) 1997,1998 Doug Rabson * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: bus.h,v 1.1 1998/06/10 10:57:21 dfr Exp $ */ #ifndef _SYS_BUS_H_ @@ -34,15 +34,13 @@ /* * Forward declarations */ -typedef struct bus *bus_t; -typedef struct device *device_t; -typedef struct driver driver_t; -typedef struct devclass *devclass_t; - -typedef int driver_probe_t(bus_t bus, device_t dev); -typedef int driver_attach_t(bus_t bus, device_t dev); -typedef int driver_detach_t(bus_t bus, device_t dev); -typedef int driver_shutdown_t(bus_t bus, device_t dev); +typedef struct device *device_t; +typedef struct driver driver_t; +typedef struct device_method device_method_t; +typedef struct devclass *devclass_t; +typedef struct device_ops *device_ops_t; +typedef struct device_op_desc *device_op_desc_t; + typedef void driver_intr_t(void*); typedef enum driver_type { @@ -53,100 +51,62 @@ typedef enum driver_type { MAX_DRIVER_TYPE } driver_type_t; +typedef int (*devop_t)(void); + +struct device_method { + device_op_desc_t desc; + devop_t func; +}; + struct driver { - const char *name; - driver_probe_t *probe; - driver_attach_t *attach; - driver_detach_t *detach; - driver_shutdown_t *shutdown; + const char *name; /* driver name */ + device_method_t *methods; /* method table */ driver_type_t type; - size_t softc; /* size of device softc struct */ - TAILQ_ENTRY(driver) link; /* list of devices on bus */ - void *buspriv; /* private data for the owning bus */ + size_t softc; /* size of device softc struct */ + TAILQ_ENTRY(driver) link; /* list of devices on bus */ + device_ops_t ops; /* compiled method table */ }; typedef enum device_state device_state_t; enum device_state { - DS_NOTPRESENT, /* not probed or probe failed */ - DS_ALIVE, /* probe succeeded */ - DS_ATTACHED, /* attach method called */ - DS_BUSY /* device is open */ + DS_NOTPRESENT, /* not probed or probe failed */ + DS_ALIVE, /* probe succeeded */ + DS_ATTACHED, /* attach method called */ + DS_BUSY /* device is open */ }; /* - * Busses - containers of devices. - */ -typedef void bus_print_device_t(bus_t bus, device_t dev); -typedef int bus_read_ivar_t(bus_t bus, device_t dev, - int index, u_long *result); -typedef int bus_write_ivar_t(bus_t bus, device_t dev, - int index, u_long value); -typedef int bus_map_intr_t(bus_t bus, device_t dev, - driver_intr_t *intr, void *arg); - -typedef struct bus_ops { - bus_print_device_t *print_device; - bus_read_ivar_t *read_ivar; - bus_write_ivar_t *write_ivar; - bus_map_intr_t *map_intr; -} bus_ops_t; - -typedef TAILQ_HEAD(device_list, device) device_list_t; - -struct bus { - bus_ops_t *ops; - device_t dev; /* device instance in parent bus */ - device_list_t devices; -}; - -/* - * Bus priorities. This determines the order in which busses are probed. - */ -#define BUS_PRIORITY_HIGH 1 -#define BUS_PRIORITY_MEDIUM 2 -#define BUS_PRIORITY_LOW 3 - -/* * The root bus, to which all top-level busses are attached. */ -extern bus_t root_bus; +extern device_t root_bus; extern devclass_t root_devclass; void root_bus_configure(void); /* - * Access functions for bus. + * Access functions for busses. */ -device_t bus_get_device(bus_t bus); -void bus_print_device(bus_t bus, device_t dev); -int bus_read_ivar(bus_t bus, device_t dev, - int index, u_long *result); -int bus_write_ivar(bus_t bus, device_t dev, - int index, u_long value); -int bus_map_intr(bus_t bus, device_t dev, driver_intr_t *intr, void *arg); -device_t bus_add_device(bus_t bus, const char *name, - int unit, void *ivars); -device_t bus_add_device_after(bus_t bus, device_t place, const char *name, - int unit, void *ivars); -int bus_delete_device(bus_t bus, device_t dev); -device_t bus_find_device(bus_t bus, const char *classname, int unit); +device_t device_add_child(device_t dev, const char *name, + int unit, void *ivars); +device_t device_add_child_after(device_t dev, device_t place, const char *name, + int unit, void *ivars); +int device_delete_child(device_t dev, device_t child); +device_t device_find_child(device_t dev, const char *classname, int unit); /* * Useful functions for implementing busses. */ -void bus_init(bus_t bus, device_t dev, bus_ops_t *ops); -driver_attach_t bus_generic_attach; -driver_detach_t bus_generic_detach; -driver_shutdown_t bus_generic_shutdown; -bus_print_device_t null_print_device; -bus_read_ivar_t null_read_ivar; -bus_write_ivar_t null_write_ivar; -bus_map_intr_t null_map_intr; -extern bus_ops_t null_bus_ops; +int bus_generic_attach(device_t dev); +int bus_generic_detach(device_t dev); +int bus_generic_shutdown(device_t dev); +void bus_generic_print_child(device_t dev, device_t child); +int bus_generic_read_ivar(device_t dev, device_t child, int which, u_long *result); +int bus_generic_write_ivar(device_t dev, device_t child, int which, u_long value); +int bus_generic_map_intr(device_t dev, device_t child, driver_intr_t *intr, void *arg); /* * Access functions for device. */ -bus_t device_get_parent(device_t dev); +device_t device_get_parent(device_t dev); driver_t *device_get_driver(device_t dev); devclass_t device_get_devclass(device_t dev); int device_set_devclass(device_t dev, const char *classname); @@ -181,6 +141,17 @@ void *devclass_get_softc(devclass_t dc, int unit); int devclass_get_devices(devclass_t dc, device_t **devlistp, int *devcountp); int devclass_get_maxunit(devclass_t dc); +/* + * Shorthand for constructing method tables. + */ +#define DEVMETHOD(NAME, FUNC) { &NAME##_desc, (devop_t) FUNC } + +/* + * Some common device interfaces. + */ +#include "device_if.h" +#include "bus_if.h" + #ifdef _SYS_MODULE_H_ /* @@ -194,7 +165,7 @@ struct driver_module_data { devclass_t* devclass; }; -int driver_module_handler __P((module_t, modeventtype_t, void*)); +int driver_module_handler(module_t, modeventtype_t, void*); #define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ \ diff --git a/sys/sys/bus_private.h b/sys/sys/bus_private.h index 5a9fba9..15d7620 100644 --- a/sys/sys/bus_private.h +++ b/sys/sys/bus_private.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1997 Doug Rabson + * Copyright (c) 1997,1998 Doug Rabson * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: bus_private.h,v 1.1 1998/06/10 10:57:23 dfr Exp $ */ #ifndef _SYS_BUS_PRIVATE_H_ @@ -36,6 +36,7 @@ */ typedef TAILQ_HEAD(devclass_list, devclass) devclass_list_t; typedef TAILQ_HEAD(driver_list, driver) driver_list_t; +typedef TAILQ_HEAD(device_list, device) device_list_t; struct devclass { TAILQ_ENTRY(devclass) link; @@ -47,11 +48,40 @@ struct devclass { }; /* + * Compiled device methods. + */ +struct device_ops { + int maxoffset; + devop_t methods[1]; +}; + +/* + * Helpers for device method wrappers. + */ +#define DEVOPDESC(OP) (&OP##_##desc) + +#define DEVOPOFF(DEV, OP) \ + ((DEVOPDESC(OP)->offset >= DEV->ops->maxoffset \ + || !DEV->ops->methods[DEVOPDESC(OP)->offset]) \ + ? 0 : DEVOPDESC(OP)->offset) + +#define DEVOPMETH(DEV, OP) (DEV->ops->methods[DEVOPOFF(DEV, OP)]) + +/* * Implementation of device. */ struct device { - TAILQ_ENTRY(device) link; /* list of devices on a bus */ - bus_t parent; + /* + * Device hierarchy. + */ + TAILQ_ENTRY(device) link; /* list of devices in parent */ + device_t parent; + device_list_t children; /* list of subordinate devices */ + + /* + * Details of this device. + */ + device_ops_t ops; driver_t *driver; devclass_t devclass; /* device class which we are in */ int unit; @@ -66,6 +96,9 @@ struct device { void *softc; }; - +struct device_op_desc { + unsigned int offset; /* offset in driver ops */ + const char* name; /* unique name (for registration) */ +}; #endif /* !_SYS_BUS_PRIVATE_H_ */ |