Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/arch/hp300/dev/dcm.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/arch/hp300/dev/dcm.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.47 retrieving revision 1.47.8.6 diff -u -p -r1.47 -r1.47.8.6 --- src/sys/arch/hp300/dev/dcm.c 2001/05/30 15:24:29 1.47 +++ src/sys/arch/hp300/dev/dcm.c 2002/10/18 02:36:44 1.47.8.6 @@ -1,4 +1,4 @@ -/* $NetBSD: dcm.c,v 1.47 2001/05/30 15:24:29 lukem Exp $ */ +/* $NetBSD: dcm.c,v 1.47.8.6 2002/10/18 02:36:44 nathanw Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -88,6 +88,9 @@ * 98642/MUX */ +#include +__KERNEL_RCSID(0, "$NetBSD: dcm.c,v 1.47.8.6 2002/10/18 02:36:44 nathanw Exp $"); + #include "opt_kgdb.h" #include @@ -157,18 +160,6 @@ struct dcmischeme { int dis_char; /* characters read during last interval */ }; -/* - * Stuff for DCM console support. This could probably be done a little - * better. - */ -static struct dcmdevice *dcm_cn = NULL; /* pointer to hardware */ -static int dcmconsinit; /* has been initialized */ -/* static int dcm_lastcnpri = CN_DEAD; */ /* XXX last priority */ - -int dcmdefaultrate = DEFAULT_BAUD_RATE; -int dcmconbrdbusy = 0; -int dcmmajor; - #ifdef KGDB /* * Kernel GDB support @@ -285,8 +276,6 @@ struct dcm_softc { #endif }; -cdev_decl(dcm); - int dcmintr __P((void *)); void dcmpint __P((struct dcm_softc *, int, int)); void dcmrint __P((struct dcm_softc *)); @@ -296,28 +285,53 @@ void dcmmint __P((struct dcm_softc *, in int dcmparam __P((struct tty *, struct termios *)); void dcmstart __P((struct tty *)); -void dcmstop __P((struct tty *, int)); int dcmmctl __P((dev_t, int, int)); void dcmsetischeme __P((int, int)); void dcminit __P((struct dcmdevice *, int, int)); int dcmselftest __P((struct dcm_softc *)); -int dcm_console_scan __P((int, caddr_t, void *)); -void dcmcnprobe __P((struct consdev *)); -void dcmcninit __P((struct consdev *)); +int dcmcnattach __P((bus_space_tag_t, bus_addr_t, int)); int dcmcngetc __P((dev_t)); void dcmcnputc __P((dev_t, int)); int dcmmatch __P((struct device *, struct cfdata *, void *)); void dcmattach __P((struct device *, struct device *, void *)); -struct cfattach dcm_ca = { - sizeof(struct dcm_softc), dcmmatch, dcmattach +CFATTACH_DECL(dcm, sizeof(struct dcm_softc), + dcmmatch, dcmattach, NULL, NULL); + +/* + * Stuff for DCM console support. This could probably be done a little + * better. + */ +static struct dcmdevice *dcm_cn = NULL; /* pointer to hardware */ +static int dcmconsinit; /* has been initialized */ +/* static int dcm_lastcnpri = CN_DEAD; */ /* XXX last priority */ + +static struct consdev dcm_cons = { + NULL, NULL, dcmcngetc, dcmcnputc, nullcnpollc, NULL, NODEV, CN_REMOTE }; +int dcmconscode; +int dcmdefaultrate = DEFAULT_BAUD_RATE; +int dcmconbrdbusy = 0; extern struct cfdriver dcm_cd; +dev_type_open(dcmopen); +dev_type_close(dcmclose); +dev_type_read(dcmread); +dev_type_write(dcmwrite); +dev_type_ioctl(dcmioctl); +dev_type_stop(dcmstop); +dev_type_tty(dcmtty); +dev_type_poll(dcmpoll); + +const struct cdevsw dcm_cdevsw = { + dcmopen, dcmclose, dcmread, dcmwrite, dcmioctl, + dcmstop, dcmtty, dcmpoll, nommap, D_TTY +}; + int dcmmatch(parent, match, aux) struct device *parent; @@ -349,8 +363,8 @@ dcmattach(parent, self, aux) sc->sc_flags = 0; - if (scode == conscode) { - dcm = (struct dcmdevice *)conaddr; + if (scode == dcmconscode) { + dcm = dcm_cn; sc->sc_flags |= DCM_ISCONSOLE; /* @@ -358,7 +372,8 @@ dcmattach(parent, self, aux) * the console probe, so we have to fixup cn_dev here. * Note that we always assume port 1 on the board. */ - cn_tab->cn_dev = makedev(dcmmajor, (brd << 2) | DCMCONSPORT); + cn_tab->cn_dev = makedev(cdevsw_lookup_major(&dcm_cdevsw), + (brd << 2) | DCMCONSPORT); } else { dcm = (struct dcmdevice *)iomap(dio_scodetopa(da->da_scode), da->da_size); @@ -438,7 +453,7 @@ dcmattach(parent, self, aux) printf("\n"); #ifdef KGDB - if (major(kgdb_dev) == dcmmajor && + if (cdevsw_lookup(kgdb_dev) == &dcm_cdevsw && DCMBOARD(DCMUNIT(kgdb_dev)) == brd) { if (dcmconsole == DCMUNIT(kgdb_dev)) /* XXX fixme */ kgdb_dev = NODEV; /* can't debug over console port */ @@ -830,7 +845,11 @@ dcmreadbuf(sc, port) if ((tp->t_state & TS_ISOPEN) == 0) { #ifdef KGDB - if ((makedev(dcmmajor, minor(tp->t_dev)) == kgdb_dev) && + int maj; + + maj = cdevsw_lookup_major(&dcm_cdevsw); + + if ((makedev(maj, minor(tp->t_dev)) == kgdb_dev) && (head = pp->r_head & RX_MASK) != (pp->r_tail & RX_MASK) && dcm->dcm_rfifos[3-port][head>>1].data_char == FRAME_START) { pp->r_head = (head + 2) & RX_MASK; @@ -988,11 +1007,13 @@ dcmioctl(dev, cmd, data, flag, p) printf("%s port %d: dcmioctl: cmd %lx data %x flag %x\n", sc->sc_dev.dv_xname, port, cmd, *data, flag); #endif + error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p); - if (error >= 0) + if (error != EPASSTHROUGH) return (error); + error = ttioctl(tp, cmd, data, flag, p); - if (error >= 0) + if (error != EPASSTHROUGH) return (error); switch (cmd) { @@ -1075,7 +1096,7 @@ dcmioctl(dev, cmd, data, flag, p) } default: - return (ENOTTY); + return (EPASSTHROUGH); } return (0); } @@ -1360,7 +1381,7 @@ dcmmctl(dev, bits, how) dcm->dcm_cr |= CR_MODM; SEM_UNLOCK(dcm); DELAY(10); /* delay until done */ - (void) splx(s); + splx(s); } return (bits); } @@ -1520,77 +1541,40 @@ dcmselftest(sc) */ int -dcm_console_scan(scode, va, arg) - int scode; - caddr_t va; - void *arg; +dcmcnattach(bus_space_tag_t bst, bus_addr_t addr, int scode) { - struct dcmdevice *dcm = (struct dcmdevice *)va; - struct consdev *cp = arg; - u_char *dioiidev; - int force = 0, pri; + bus_space_handle_t bsh; + caddr_t va; + struct dcmdevice *dcm; + int maj; + + if (bus_space_map(bst, addr, DIOCSIZE, 0, &bsh)) + return (1); + + va = bus_space_vaddr(bst, bsh); + dcm = (struct dcmdevice *)va; switch (dcm->dcm_rsid) { +#ifdef CONSCODE case DCMID: - pri = CN_NORMAL; - break; - +#endif case DCMID|DCMCON: - pri = CN_REMOTE; break; - default: - return (0); - } - -#ifdef CONSCODE - /* - * Raise our priority, if appropriate. - */ - if (scode == CONSCODE) { - pri = CN_REMOTE; - force = conforced = 1; - } -#endif - - /* Only raise priority. */ - if (pri > cp->cn_pri) - cp->cn_pri = pri; - - /* - * If our priority is higher than the currently-remembered - * console, stash our priority, for the benefit of dcmcninit(). - */ - if (((cn_tab == NULL) || (cp->cn_pri > cn_tab->cn_pri)) || force) { - cn_tab = cp; - if (scode >= 132) { - dioiidev = (u_char *)va; - return ((dioiidev[0x101] + 1) * 0x100000); - } - return (DIOCSIZE); + goto error; } - return (0); -} - -void -dcmcnprobe(cp) - struct consdev *cp; -{ - - /* locate the major number */ - for (dcmmajor = 0; dcmmajor < nchrdev; dcmmajor++) - if (cdevsw[dcmmajor].d_open == dcmopen) - break; - /* initialize required fields */ - cp->cn_dev = makedev(dcmmajor, 0); /* XXX */ - cp->cn_pri = CN_DEAD; + dcminit(dcm, DCMCONSPORT, dcmdefaultrate); + dcmconsinit = 1; + dcmconscode = scode; + dcm_cn = dcm; - /* Abort early if console already forced. */ - if (conforced) - return; + /* locate the major number */ + maj = cdevsw_lookup_major(&dcm_cdevsw); - console_scan(dcm_console_scan, cp); + /* initialize required fields */ + cn_tab = &dcm_cons; + cn_tab->cn_dev = makedev(maj, 0); #ifdef KGDB_CHEAT /* XXX this needs to be fixed. */ @@ -1598,7 +1582,7 @@ dcmcnprobe(cp) * This doesn't currently work, at least not with ite consoles; * the console hasn't been initialized yet. */ - if (major(kgdb_dev) == dcmmajor && + if (major(kgdb_dev) == maj && DCMBOARD(DCMUNIT(kgdb_dev)) == DCMBOARD(unit)) { dcminit(dcm_cn, DCMPORT(DCMUNIT(kgdb_dev)), kgdb_rate); if (kgdb_debug_init) { @@ -1613,17 +1597,13 @@ dcmcnprobe(cp) } } #endif -} -/* ARGSUSED */ -void -dcmcninit(cp) - struct consdev *cp; -{ - dcm_cn = (struct dcmdevice *)conaddr; - dcminit(dcm_cn, DCMCONSPORT, dcmdefaultrate); - dcmconsinit = 1; + return (0); + +error: + bus_space_unmap(bst, bsh, DIOCSIZE); + return (1); } /* ARGSUSED */