156819Sralph /*- 263205Sbostic * Copyright (c) 1992, 1993 363205Sbostic * The Regents of the University of California. All rights reserved. 452130Smckusick * 552130Smckusick * This code is derived from software contributed to Berkeley by 656819Sralph * Ralph Campbell and Rick Macklem. 756819Sralph * 856819Sralph * %sccs.include.redist.c% 956819Sralph * 10*64978Smckusick * @(#)dc.c 8.2 (Berkeley) 11/30/93 1152693Sralph */ 1252693Sralph 1352693Sralph /* 1452130Smckusick * devDC7085.c -- 1552130Smckusick * 1652130Smckusick * This file contains machine-dependent routines that handle the 1752130Smckusick * output queue for the serial lines. 1852130Smckusick * 1952130Smckusick * Copyright (C) 1989 Digital Equipment Corporation. 2052130Smckusick * Permission to use, copy, modify, and distribute this software and 2152130Smckusick * its documentation for any purpose and without fee is hereby granted, 2252130Smckusick * provided that the above copyright notice appears in all copies. 2352130Smckusick * Digital Equipment Corporation makes no representations about the 2452130Smckusick * suitability of this software for any purpose. It is provided "as is" 2552130Smckusick * without express or implied warranty. 2652130Smckusick * 2752130Smckusick * from: $Header: /sprite/src/kernel/dev/ds3100.md/RCS/devDC7085.c, 2852130Smckusick * v 1.4 89/08/29 11:55:30 nelson Exp $ SPRITE (DECWRL)"; 2952130Smckusick */ 3052130Smckusick 3156819Sralph #include <dc.h> 3252130Smckusick #if NDC > 0 3352130Smckusick /* 3452130Smckusick * DC7085 (DZ-11 look alike) Driver 3552130Smckusick */ 3656522Sbostic #include <sys/param.h> 3756522Sbostic #include <sys/systm.h> 3856522Sbostic #include <sys/ioctl.h> 3956522Sbostic #include <sys/tty.h> 4056522Sbostic #include <sys/proc.h> 4156522Sbostic #include <sys/map.h> 4256522Sbostic #include <sys/buf.h> 4356522Sbostic #include <sys/conf.h> 4456522Sbostic #include <sys/file.h> 4556522Sbostic #include <sys/uio.h> 4656522Sbostic #include <sys/kernel.h> 4756522Sbostic #include <sys/syslog.h> 4852130Smckusick 4956522Sbostic #include <machine/dc7085cons.h> 5056819Sralph #include <machine/pmioctl.h> 5152130Smckusick 5256819Sralph #include <pmax/pmax/pmaxtype.h> 5356819Sralph #include <pmax/pmax/cons.h> 5456819Sralph 5556525Sbostic #include <pmax/dev/device.h> 5656525Sbostic #include <pmax/dev/pdma.h> 5756819Sralph #include <pmax/dev/fbreg.h> 5852130Smckusick 5956819Sralph extern int pmax_boardtype; 6056819Sralph extern struct consdev cn_tab; 6156819Sralph 6252130Smckusick /* 6352130Smckusick * Driver information for auto-configuration stuff. 6452130Smckusick */ 6552130Smckusick int dcprobe(); 6652693Sralph void dcintr(); 6752130Smckusick struct driver dcdriver = { 6852693Sralph "dc", dcprobe, 0, 0, dcintr, 6952130Smckusick }; 7052130Smckusick 7152130Smckusick #define NDCLINE (NDC*4) 7252130Smckusick 7356819Sralph void dcstart __P((struct tty *)); 7456819Sralph void dcxint __P((struct tty *)); 7556819Sralph void dcPutc __P((dev_t, int)); 7656819Sralph void dcscan __P((void *)); 7756226Sralph extern void ttrstrt __P((void *)); 7856819Sralph int dcGetc __P((dev_t)); 7956819Sralph int dcparam __P((struct tty *, struct termios *)); 8052130Smckusick 8152130Smckusick struct tty dc_tty[NDCLINE]; 8252130Smckusick int dc_cnt = NDCLINE; 8352863Sralph void (*dcDivertXInput)(); /* X windows keyboard input routine */ 8452863Sralph void (*dcMouseEvent)(); /* X windows mouse motion event routine */ 8552863Sralph void (*dcMouseButtons)(); /* X windows mouse buttons event routine */ 8652130Smckusick #ifdef DEBUG 8752130Smckusick int debugChar; 8852130Smckusick #endif 8952130Smckusick 9052130Smckusick /* 9152130Smckusick * Software copy of brk register since it isn't readable 9252130Smckusick */ 9352130Smckusick int dc_brk[NDC]; 9452130Smckusick char dcsoftCAR[NDC]; /* mask of dc's with carrier on (DSR) */ 9552130Smckusick 9652130Smckusick /* 9752130Smckusick * The DC7085 doesn't interrupt on carrier transitions, so 9852130Smckusick * we have to use a timer to watch it. 9952130Smckusick */ 10052130Smckusick int dc_timer; /* true if timer started */ 10152130Smckusick 10252130Smckusick /* 10352130Smckusick * Pdma structures for fast output code 10452130Smckusick */ 10552130Smckusick struct pdma dcpdma[NDCLINE]; 10652130Smckusick 10752130Smckusick struct speedtab dcspeedtab[] = { 10852130Smckusick 0, 0, 10952130Smckusick 50, LPR_B50, 11052130Smckusick 75, LPR_B75, 11152130Smckusick 110, LPR_B110, 11252130Smckusick 134, LPR_B134, 11352130Smckusick 150, LPR_B150, 11452130Smckusick 300, LPR_B300, 11552130Smckusick 600, LPR_B600, 11652130Smckusick 1200, LPR_B1200, 11752130Smckusick 1800, LPR_B1800, 11852130Smckusick 2400, LPR_B2400, 11952130Smckusick 4800, LPR_B4800, 12052130Smckusick 9600, LPR_B9600, 12152693Sralph 19200, LPR_B19200, 12252130Smckusick -1, -1 12352130Smckusick }; 12452130Smckusick 12552130Smckusick #ifndef PORTSELECTOR 12652130Smckusick #define ISPEED TTYDEF_SPEED 12752130Smckusick #define LFLAG TTYDEF_LFLAG 12852130Smckusick #else 12952130Smckusick #define ISPEED B4800 13052130Smckusick #define LFLAG (TTYDEF_LFLAG & ~ECHO) 13152130Smckusick #endif 13252130Smckusick 13352130Smckusick /* 13452130Smckusick * Test to see if device is present. 13552130Smckusick * Return true if found and initialized ok. 13652130Smckusick */ 13752130Smckusick dcprobe(cp) 13852130Smckusick register struct pmax_ctlr *cp; 13952130Smckusick { 14052130Smckusick register dcregs *dcaddr; 14152130Smckusick register struct pdma *pdp; 14252130Smckusick register struct tty *tp; 14352130Smckusick register int cntr; 14456819Sralph int s; 14552130Smckusick 14652130Smckusick if (cp->pmax_unit >= NDC) 14752130Smckusick return (0); 14852130Smckusick if (badaddr(cp->pmax_addr, 2)) 14952130Smckusick return (0); 15052130Smckusick 15157234Sralph /* 15257234Sralph * For a remote console, wait a while for previous output to 15357234Sralph * complete. 15457234Sralph */ 15557234Sralph if (major(cn_tab.cn_dev) == DCDEV && cp->pmax_unit == 0 && 15657234Sralph cn_tab.cn_screen == 0) 15757234Sralph DELAY(10000); 15857234Sralph 15952130Smckusick /* reset chip */ 16052130Smckusick dcaddr = (dcregs *)cp->pmax_addr; 16152130Smckusick dcaddr->dc_csr = CSR_CLR; 16252130Smckusick MachEmptyWriteBuffer(); 16352130Smckusick while (dcaddr->dc_csr & CSR_CLR) 16452130Smckusick ; 16552130Smckusick dcaddr->dc_csr = CSR_MSE | CSR_TIE | CSR_RIE; 16652130Smckusick 16752130Smckusick /* init pseudo DMA structures */ 16852130Smckusick pdp = &dcpdma[cp->pmax_unit * 4]; 16952130Smckusick tp = &dc_tty[cp->pmax_unit * 4]; 17052130Smckusick for (cntr = 0; cntr < 4; cntr++) { 17156819Sralph pdp->p_addr = (void *)dcaddr; 17252130Smckusick pdp->p_arg = (int)tp; 17352130Smckusick pdp->p_fcn = dcxint; 17452130Smckusick pdp++, tp++; 17552130Smckusick } 17652130Smckusick dcsoftCAR[cp->pmax_unit] = cp->pmax_flags | 0xB; 17752130Smckusick 17852130Smckusick if (dc_timer == 0) { 17952130Smckusick dc_timer = 1; 18055744Sralph timeout(dcscan, (void *)0, hz); 18152130Smckusick } 18256819Sralph 18356819Sralph /* 18456819Sralph * Special handling for consoles. 18556819Sralph */ 18652130Smckusick if (cp->pmax_unit == 0) { 18756819Sralph if (cn_tab.cn_screen) { 18856819Sralph s = spltty(); 18956819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_8_BIT_CHAR | 19056819Sralph LPR_B4800 | DCKBD_PORT; 19158975Sralph MachEmptyWriteBuffer(); 19256819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_B4800 | LPR_OPAR | 19356819Sralph LPR_PARENB | LPR_8_BIT_CHAR | DCMOUSE_PORT; 19456819Sralph MachEmptyWriteBuffer(); 19557234Sralph DELAY(1000); 19656819Sralph KBDReset(makedev(DCDEV, DCKBD_PORT), dcPutc); 19756819Sralph MouseInit(makedev(DCDEV, DCMOUSE_PORT), dcPutc, dcGetc); 19856819Sralph splx(s); 19956819Sralph } else if (major(cn_tab.cn_dev) == DCDEV) { 20056819Sralph s = spltty(); 20156819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_8_BIT_CHAR | 20256819Sralph LPR_B9600 | minor(cn_tab.cn_dev); 20356819Sralph MachEmptyWriteBuffer(); 20457234Sralph DELAY(1000); 20556819Sralph cn_tab.cn_disabled = 0; 20656819Sralph splx(s); 20756819Sralph } 20852130Smckusick } 20957234Sralph printf("dc%d at nexus0 csr 0x%x priority %d\n", 21057234Sralph cp->pmax_unit, cp->pmax_addr, cp->pmax_pri); 21152130Smckusick return (1); 21252130Smckusick } 21352130Smckusick 21454146Sralph dcopen(dev, flag, mode, p) 21552130Smckusick dev_t dev; 21654146Sralph int flag, mode; 21754146Sralph struct proc *p; 21852130Smckusick { 21952130Smckusick register struct tty *tp; 22052130Smckusick register int unit; 22152130Smckusick int s, error = 0; 22252130Smckusick 22352130Smckusick unit = minor(dev); 22456819Sralph if (unit >= dc_cnt || dcpdma[unit].p_addr == (void *)0) 22552130Smckusick return (ENXIO); 22652130Smckusick tp = &dc_tty[unit]; 22752130Smckusick tp->t_oproc = dcstart; 22852130Smckusick tp->t_param = dcparam; 22952130Smckusick tp->t_dev = dev; 23052130Smckusick if ((tp->t_state & TS_ISOPEN) == 0) { 23152130Smckusick tp->t_state |= TS_WOPEN; 23252130Smckusick ttychars(tp); 23352130Smckusick #ifndef PORTSELECTOR 23452130Smckusick if (tp->t_ispeed == 0) { 23552130Smckusick #endif 23652130Smckusick tp->t_iflag = TTYDEF_IFLAG; 23752130Smckusick tp->t_oflag = TTYDEF_OFLAG; 23852130Smckusick tp->t_cflag = TTYDEF_CFLAG; 23952130Smckusick tp->t_lflag = LFLAG; 24052130Smckusick tp->t_ispeed = tp->t_ospeed = ISPEED; 24152130Smckusick #ifdef PORTSELECTOR 24252130Smckusick tp->t_cflag |= HUPCL; 24352130Smckusick #else 24452130Smckusick } 24552130Smckusick #endif 24652130Smckusick (void) dcparam(tp, &tp->t_termios); 24752130Smckusick ttsetwater(tp); 24852130Smckusick } else if ((tp->t_state & TS_XCLUDE) && curproc->p_ucred->cr_uid != 0) 24952130Smckusick return (EBUSY); 25052130Smckusick (void) dcmctl(dev, DML_DTR, DMSET); 25152130Smckusick s = spltty(); 25252130Smckusick while (!(flag & O_NONBLOCK) && !(tp->t_cflag & CLOCAL) && 25352130Smckusick !(tp->t_state & TS_CARR_ON)) { 25452130Smckusick tp->t_state |= TS_WOPEN; 25552130Smckusick if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH, 25652130Smckusick ttopen, 0)) 25752130Smckusick break; 25852130Smckusick } 25952130Smckusick splx(s); 26052130Smckusick if (error) 26152130Smckusick return (error); 26252130Smckusick return ((*linesw[tp->t_line].l_open)(dev, tp)); 26352130Smckusick } 26452130Smckusick 26552130Smckusick /*ARGSUSED*/ 26654146Sralph dcclose(dev, flag, mode, p) 26752130Smckusick dev_t dev; 26854146Sralph int flag, mode; 26954146Sralph struct proc *p; 27052130Smckusick { 27152130Smckusick register struct tty *tp; 27252130Smckusick register int unit, bit; 27352130Smckusick 27452130Smckusick unit = minor(dev); 27552130Smckusick tp = &dc_tty[unit]; 27652130Smckusick bit = 1 << ((unit & 03) + 8); 27752130Smckusick if (dc_brk[unit >> 2] & bit) { 27852130Smckusick dc_brk[unit >> 2] &= ~bit; 27952130Smckusick ttyoutput(0, tp); 28052130Smckusick } 28154146Sralph (*linesw[tp->t_line].l_close)(tp, flag); 28252130Smckusick if ((tp->t_cflag & HUPCL) || (tp->t_state & TS_WOPEN) || 28352130Smckusick !(tp->t_state & TS_ISOPEN)) 28452130Smckusick (void) dcmctl(dev, 0, DMSET); 28552130Smckusick return (ttyclose(tp)); 28652130Smckusick } 28752130Smckusick 28852130Smckusick dcread(dev, uio, flag) 28952130Smckusick dev_t dev; 29052130Smckusick struct uio *uio; 29152130Smckusick { 29252130Smckusick register struct tty *tp; 29352130Smckusick 29452130Smckusick tp = &dc_tty[minor(dev)]; 29552130Smckusick return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); 29652130Smckusick } 29752130Smckusick 29852130Smckusick dcwrite(dev, uio, flag) 29952130Smckusick dev_t dev; 30052130Smckusick struct uio *uio; 30152130Smckusick { 30252130Smckusick register struct tty *tp; 30352130Smckusick 30452130Smckusick tp = &dc_tty[minor(dev)]; 30552130Smckusick return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); 30652130Smckusick } 30752130Smckusick 30852130Smckusick /*ARGSUSED*/ 30954146Sralph dcioctl(dev, cmd, data, flag, p) 31052130Smckusick dev_t dev; 31156819Sralph int cmd; 31252130Smckusick caddr_t data; 31354146Sralph int flag; 31454146Sralph struct proc *p; 31552130Smckusick { 31652130Smckusick register struct tty *tp; 31752130Smckusick register int unit = minor(dev); 31852130Smckusick register int dc = unit >> 2; 31952130Smckusick int error; 32052130Smckusick 32152130Smckusick tp = &dc_tty[unit]; 32254146Sralph error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p); 32352130Smckusick if (error >= 0) 32452130Smckusick return (error); 32552130Smckusick error = ttioctl(tp, cmd, data, flag); 32652130Smckusick if (error >= 0) 32752130Smckusick return (error); 32852130Smckusick 32952130Smckusick switch (cmd) { 33052130Smckusick 33152130Smckusick case TIOCSBRK: 33252130Smckusick dc_brk[dc] |= 1 << ((unit & 03) + 8); 33352130Smckusick ttyoutput(0, tp); 33452130Smckusick break; 33552130Smckusick 33652130Smckusick case TIOCCBRK: 33752130Smckusick dc_brk[dc] &= ~(1 << ((unit & 03) + 8)); 33852130Smckusick ttyoutput(0, tp); 33952130Smckusick break; 34052130Smckusick 34152130Smckusick case TIOCSDTR: 34252130Smckusick (void) dcmctl(dev, DML_DTR|DML_RTS, DMBIS); 34352130Smckusick break; 34452130Smckusick 34552130Smckusick case TIOCCDTR: 34652130Smckusick (void) dcmctl(dev, DML_DTR|DML_RTS, DMBIC); 34752130Smckusick break; 34852130Smckusick 34952130Smckusick case TIOCMSET: 35052130Smckusick (void) dcmctl(dev, *(int *)data, DMSET); 35152130Smckusick break; 35252130Smckusick 35352130Smckusick case TIOCMBIS: 35452130Smckusick (void) dcmctl(dev, *(int *)data, DMBIS); 35552130Smckusick break; 35652130Smckusick 35752130Smckusick case TIOCMBIC: 35852130Smckusick (void) dcmctl(dev, *(int *)data, DMBIC); 35952130Smckusick break; 36052130Smckusick 36152130Smckusick case TIOCMGET: 36252130Smckusick *(int *)data = dcmctl(dev, 0, DMGET); 36352130Smckusick break; 36452130Smckusick 36552130Smckusick default: 36652130Smckusick return (ENOTTY); 36752130Smckusick } 36852130Smckusick return (0); 36952130Smckusick } 37052130Smckusick 37152130Smckusick dcparam(tp, t) 37252130Smckusick register struct tty *tp; 37352130Smckusick register struct termios *t; 37452130Smckusick { 37552130Smckusick register dcregs *dcaddr; 37652130Smckusick register int lpr; 37752130Smckusick register int cflag = t->c_cflag; 37852130Smckusick int unit = minor(tp->t_dev); 37952130Smckusick int ospeed = ttspeedtab(t->c_ospeed, dcspeedtab); 38052130Smckusick 38152130Smckusick /* check requested parameters */ 38252130Smckusick if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed) || 38356819Sralph (cflag & CSIZE) == CS5 || (cflag & CSIZE) == CS6 || 38456819Sralph (pmax_boardtype == DS_PMAX && t->c_ospeed == 19200)) 38552130Smckusick return (EINVAL); 38652130Smckusick /* and copy to tty */ 38752130Smckusick tp->t_ispeed = t->c_ispeed; 38852130Smckusick tp->t_ospeed = t->c_ospeed; 38952130Smckusick tp->t_cflag = cflag; 39052130Smckusick 39156819Sralph dcaddr = (dcregs *)dcpdma[unit].p_addr; 39256819Sralph 39356819Sralph /* 39456819Sralph * Handle console cases specially. 39556819Sralph */ 39656819Sralph if (cn_tab.cn_screen) { 39756819Sralph if (unit == DCKBD_PORT) { 39856819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_8_BIT_CHAR | 39956819Sralph LPR_B4800 | DCKBD_PORT; 40056819Sralph MachEmptyWriteBuffer(); 40156819Sralph return (0); 40256819Sralph } else if (unit == DCMOUSE_PORT) { 40356819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_B4800 | LPR_OPAR | 40456819Sralph LPR_PARENB | LPR_8_BIT_CHAR | DCMOUSE_PORT; 40556819Sralph MachEmptyWriteBuffer(); 40656819Sralph return (0); 40756819Sralph } 40856819Sralph } else if (tp->t_dev == cn_tab.cn_dev) { 40956819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_8_BIT_CHAR | 41056819Sralph LPR_B9600 | unit; 41152130Smckusick MachEmptyWriteBuffer(); 41252130Smckusick return (0); 41352130Smckusick } 41452130Smckusick if (ospeed == 0) { 41552130Smckusick (void) dcmctl(unit, 0, DMSET); /* hang up line */ 41652130Smckusick return (0); 41752130Smckusick } 41852130Smckusick lpr = LPR_RXENAB | ospeed | (unit & 03); 41952130Smckusick if ((cflag & CSIZE) == CS7) 42052130Smckusick lpr |= LPR_7_BIT_CHAR; 42152130Smckusick else 42252130Smckusick lpr |= LPR_8_BIT_CHAR; 42352130Smckusick if (cflag & PARENB) 42452130Smckusick lpr |= LPR_PARENB; 42552130Smckusick if (cflag & PARODD) 42652130Smckusick lpr |= LPR_OPAR; 42752130Smckusick if (cflag & CSTOPB) 42852130Smckusick lpr |= LPR_2_STOP; 42952130Smckusick dcaddr->dc_lpr = lpr; 43052130Smckusick MachEmptyWriteBuffer(); 43158975Sralph DELAY(10); 43252130Smckusick return (0); 43352130Smckusick } 43452130Smckusick 43552693Sralph /* 43652693Sralph * Check for interrupts from all devices. 43752693Sralph */ 43852693Sralph void 43952693Sralph dcintr(unit) 44052693Sralph register int unit; 44152693Sralph { 44252693Sralph register dcregs *dcaddr; 44352693Sralph register unsigned csr; 44452693Sralph 44552693Sralph unit <<= 2; 44656819Sralph dcaddr = (dcregs *)dcpdma[unit].p_addr; 44752693Sralph while ((csr = dcaddr->dc_csr) & (CSR_RDONE | CSR_TRDY)) { 44852693Sralph if (csr & CSR_RDONE) 44952693Sralph dcrint(unit); 45052693Sralph if (csr & CSR_TRDY) 45152693Sralph dcxint(&dc_tty[unit + ((csr >> 8) & 03)]); 45252693Sralph } 45352693Sralph } 45452693Sralph 45552693Sralph dcrint(unit) 45652693Sralph register int unit; 45752693Sralph { 45852693Sralph register dcregs *dcaddr; 45952693Sralph register struct tty *tp; 46052693Sralph register int c, cc; 46152693Sralph register struct tty *tp0; 46252693Sralph int overrun = 0; 46352693Sralph 46456819Sralph dcaddr = (dcregs *)dcpdma[unit].p_addr; 46552693Sralph tp0 = &dc_tty[unit]; 46652693Sralph while ((c = dcaddr->dc_rbuf) < 0) { /* char present */ 46752693Sralph cc = c & 0xff; 46852693Sralph tp = tp0 + ((c >> 8) & 03); 46952693Sralph if ((c & RBUF_OERR) && overrun == 0) { 47052693Sralph log(LOG_WARNING, "dc%d,%d: silo overflow\n", unit >> 2, 47152693Sralph (c >> 8) & 03); 47252693Sralph overrun = 1; 47352693Sralph } 47452693Sralph /* the keyboard requires special translation */ 47556819Sralph if (tp == &dc_tty[DCKBD_PORT] && cn_tab.cn_screen) { 47652693Sralph #ifdef KADB 47752693Sralph if (cc == LK_DO) { 47852693Sralph spl0(); 47952693Sralph kdbpanic(); 48052693Sralph return; 48152693Sralph } 48252693Sralph #endif 48352693Sralph #ifdef DEBUG 48452693Sralph debugChar = cc; 48552693Sralph #endif 48652693Sralph if (dcDivertXInput) { 48752863Sralph (*dcDivertXInput)(cc); 48852693Sralph return; 48952693Sralph } 49056819Sralph if ((cc = kbdMapChar(cc)) < 0) 49152693Sralph return; 49256819Sralph } else if (tp == &dc_tty[DCMOUSE_PORT] && dcMouseButtons) { 49352863Sralph register MouseReport *mrp; 49452693Sralph static MouseReport currentRep; 49552693Sralph 49652863Sralph mrp = ¤tRep; 49752863Sralph mrp->byteCount++; 49852693Sralph if (cc & MOUSE_START_FRAME) { 49952693Sralph /* 50052693Sralph * The first mouse report byte (button state). 50152693Sralph */ 50252863Sralph mrp->state = cc; 50352863Sralph if (mrp->byteCount > 1) 50452863Sralph mrp->byteCount = 1; 50552863Sralph } else if (mrp->byteCount == 2) { 50652693Sralph /* 50752693Sralph * The second mouse report byte (delta x). 50852693Sralph */ 50952863Sralph mrp->dx = cc; 51052863Sralph } else if (mrp->byteCount == 3) { 51152693Sralph /* 51252693Sralph * The final mouse report byte (delta y). 51352693Sralph */ 51452863Sralph mrp->dy = cc; 51552863Sralph mrp->byteCount = 0; 51652863Sralph if (mrp->dx != 0 || mrp->dy != 0) { 51752693Sralph /* 51852693Sralph * If the mouse moved, 51952693Sralph * post a motion event. 52052693Sralph */ 52152863Sralph (*dcMouseEvent)(mrp); 52252693Sralph } 52352863Sralph (*dcMouseButtons)(mrp); 52452693Sralph } 52552693Sralph return; 52652693Sralph } 52752693Sralph if (!(tp->t_state & TS_ISOPEN)) { 52852693Sralph wakeup((caddr_t)&tp->t_rawq); 52952693Sralph #ifdef PORTSELECTOR 53052693Sralph if (!(tp->t_state & TS_WOPEN)) 53152693Sralph #endif 53252693Sralph return; 53352693Sralph } 53452693Sralph if (c & RBUF_FERR) 53552693Sralph cc |= TTY_FE; 53652693Sralph if (c & RBUF_PERR) 53752693Sralph cc |= TTY_PE; 53852693Sralph (*linesw[tp->t_line].l_rint)(cc, tp); 53952693Sralph } 54052693Sralph DELAY(10); 54152693Sralph } 54252693Sralph 54352755Sralph void 54452130Smckusick dcxint(tp) 54552130Smckusick register struct tty *tp; 54652130Smckusick { 54752130Smckusick register struct pdma *dp; 54852130Smckusick register dcregs *dcaddr; 54952130Smckusick 550*64978Smckusick dp = &dcpdma[minor(tp->t_dev)]; 55152130Smckusick if (dp->p_mem < dp->p_end) { 55256819Sralph dcaddr = (dcregs *)dp->p_addr; 55352130Smckusick dcaddr->dc_tdr = dc_brk[(tp - dc_tty) >> 2] | *dp->p_mem++; 55452130Smckusick MachEmptyWriteBuffer(); 55552130Smckusick DELAY(10); 55652130Smckusick return; 55752130Smckusick } 55852130Smckusick tp->t_state &= ~TS_BUSY; 55952130Smckusick if (tp->t_state & TS_FLUSH) 56052130Smckusick tp->t_state &= ~TS_FLUSH; 56152130Smckusick else { 56252130Smckusick ndflush(&tp->t_outq, dp->p_mem-tp->t_outq.c_cf); 56352130Smckusick dp->p_end = dp->p_mem = tp->t_outq.c_cf; 56452130Smckusick } 56552130Smckusick if (tp->t_line) 56652130Smckusick (*linesw[tp->t_line].l_start)(tp); 56752130Smckusick else 56852130Smckusick dcstart(tp); 56952130Smckusick if (tp->t_outq.c_cc == 0 || !(tp->t_state & TS_BUSY)) { 57058975Sralph dcaddr = (dcregs *)dp->p_addr; 57158975Sralph dcaddr->dc_tcr &= ~(1 << (minor(tp->t_dev) & 03)); 57252130Smckusick MachEmptyWriteBuffer(); 57352130Smckusick DELAY(10); 57452130Smckusick } 57552130Smckusick } 57652130Smckusick 57752755Sralph void 57852130Smckusick dcstart(tp) 57952130Smckusick register struct tty *tp; 58052130Smckusick { 58152130Smckusick register struct pdma *dp; 58252130Smckusick register dcregs *dcaddr; 58352130Smckusick register int cc; 58452130Smckusick int s; 58552130Smckusick 586*64978Smckusick dp = &dcpdma[minor(tp->t_dev)]; 58756819Sralph dcaddr = (dcregs *)dp->p_addr; 58852130Smckusick s = spltty(); 58952130Smckusick if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) 59052130Smckusick goto out; 59152130Smckusick if (tp->t_outq.c_cc <= tp->t_lowat) { 59252130Smckusick if (tp->t_state & TS_ASLEEP) { 59352130Smckusick tp->t_state &= ~TS_ASLEEP; 59452130Smckusick wakeup((caddr_t)&tp->t_outq); 59552130Smckusick } 59652674Smckusick selwakeup(&tp->t_wsel); 59752130Smckusick } 59852130Smckusick if (tp->t_outq.c_cc == 0) 59952130Smckusick goto out; 60052130Smckusick /* handle console specially */ 60156819Sralph if (tp == &dc_tty[DCKBD_PORT] && cn_tab.cn_screen) { 60252130Smckusick while (tp->t_outq.c_cc > 0) { 60352130Smckusick cc = getc(&tp->t_outq) & 0x7f; 60452863Sralph cnputc(cc); 60552130Smckusick } 60652130Smckusick /* 60752130Smckusick * After we flush the output queue we may need to wake 60852130Smckusick * up the process that made the output. 60952130Smckusick */ 61052130Smckusick if (tp->t_outq.c_cc <= tp->t_lowat) { 61152130Smckusick if (tp->t_state & TS_ASLEEP) { 61252130Smckusick tp->t_state &= ~TS_ASLEEP; 61352130Smckusick wakeup((caddr_t)&tp->t_outq); 61452130Smckusick } 61552674Smckusick selwakeup(&tp->t_wsel); 61652130Smckusick } 61752130Smckusick goto out; 61852130Smckusick } 61952130Smckusick if (tp->t_flags & (RAW|LITOUT)) 62052130Smckusick cc = ndqb(&tp->t_outq, 0); 62152130Smckusick else { 62252130Smckusick cc = ndqb(&tp->t_outq, 0200); 62352130Smckusick if (cc == 0) { 62452130Smckusick cc = getc(&tp->t_outq); 62555744Sralph timeout(ttrstrt, (void *)tp, (cc & 0x7f) + 6); 62652130Smckusick tp->t_state |= TS_TIMEOUT; 62752130Smckusick goto out; 62852130Smckusick } 62952130Smckusick } 63052130Smckusick tp->t_state |= TS_BUSY; 63152130Smckusick dp->p_end = dp->p_mem = tp->t_outq.c_cf; 63252130Smckusick dp->p_end += cc; 63352130Smckusick dcaddr->dc_tcr |= 1 << (minor(tp->t_dev) & 03); 63452130Smckusick MachEmptyWriteBuffer(); 63552130Smckusick out: 63652130Smckusick splx(s); 63752130Smckusick } 63852130Smckusick 63952130Smckusick /* 64052130Smckusick * Stop output on a line. 64152130Smckusick */ 64252130Smckusick /*ARGSUSED*/ 64352130Smckusick dcstop(tp, flag) 64452130Smckusick register struct tty *tp; 64552130Smckusick { 64652130Smckusick register struct pdma *dp; 64752130Smckusick register int s; 64852130Smckusick 649*64978Smckusick dp = &dcpdma[minor(tp->t_dev)]; 65052130Smckusick s = spltty(); 65152130Smckusick if (tp->t_state & TS_BUSY) { 65252130Smckusick dp->p_end = dp->p_mem; 65352130Smckusick if (!(tp->t_state & TS_TTSTOP)) 65452130Smckusick tp->t_state |= TS_FLUSH; 65552130Smckusick } 65652130Smckusick splx(s); 65752130Smckusick } 65852130Smckusick 65952130Smckusick dcmctl(dev, bits, how) 66052130Smckusick dev_t dev; 66152130Smckusick int bits, how; 66252130Smckusick { 66352130Smckusick register dcregs *dcaddr; 66452130Smckusick register int unit, mbits; 66552130Smckusick int b, s; 66652693Sralph register int msr; 66752130Smckusick 66852130Smckusick unit = minor(dev); 66952130Smckusick b = 1 << (unit & 03); 67056819Sralph dcaddr = (dcregs *)dcpdma[unit].p_addr; 67152130Smckusick s = spltty(); 67252130Smckusick /* only channel 2 has modem control (what about line 3?) */ 67356819Sralph mbits = DML_DTR | DML_DSR | DML_CAR; 67452693Sralph switch (unit & 03) { 67552693Sralph case 2: 67652130Smckusick mbits = 0; 67752130Smckusick if (dcaddr->dc_tcr & TCR_DTR2) 67852130Smckusick mbits |= DML_DTR; 67952693Sralph msr = dcaddr->dc_msr; 68052693Sralph if (msr & MSR_CD2) 68152693Sralph mbits |= DML_CAR; 68256819Sralph if (msr & MSR_DSR2) { 68356819Sralph if (pmax_boardtype == DS_PMAX) 68456819Sralph mbits |= DML_CAR | DML_DSR; 68556819Sralph else 68656819Sralph mbits |= DML_DSR; 68756819Sralph } 68852693Sralph break; 68952693Sralph 69052693Sralph case 3: 69156819Sralph if (pmax_boardtype != DS_PMAX) { 69256819Sralph mbits = 0; 69356819Sralph if (dcaddr->dc_tcr & TCR_DTR3) 69456819Sralph mbits |= DML_DTR; 69556819Sralph msr = dcaddr->dc_msr; 69656819Sralph if (msr & MSR_CD3) 69756819Sralph mbits |= DML_CAR; 69856819Sralph if (msr & MSR_DSR3) 69956819Sralph mbits |= DML_DSR; 70056819Sralph } 70152693Sralph } 70252130Smckusick switch (how) { 70352130Smckusick case DMSET: 70452130Smckusick mbits = bits; 70552130Smckusick break; 70652130Smckusick 70752130Smckusick case DMBIS: 70852130Smckusick mbits |= bits; 70952130Smckusick break; 71052130Smckusick 71152130Smckusick case DMBIC: 71252130Smckusick mbits &= ~bits; 71352130Smckusick break; 71452130Smckusick 71552130Smckusick case DMGET: 71652130Smckusick (void) splx(s); 71752130Smckusick return (mbits); 71852130Smckusick } 71952693Sralph switch (unit & 03) { 72052693Sralph case 2: 72152130Smckusick if (mbits & DML_DTR) 72252130Smckusick dcaddr->dc_tcr |= TCR_DTR2; 72352130Smckusick else 72452130Smckusick dcaddr->dc_tcr &= ~TCR_DTR2; 72552693Sralph break; 72652693Sralph 72752693Sralph case 3: 72856819Sralph if (pmax_boardtype != DS_PMAX) { 72956819Sralph if (mbits & DML_DTR) 73056819Sralph dcaddr->dc_tcr |= TCR_DTR3; 73156819Sralph else 73256819Sralph dcaddr->dc_tcr &= ~TCR_DTR3; 73356819Sralph } 73452130Smckusick } 73552130Smckusick if ((mbits & DML_DTR) && (dcsoftCAR[unit >> 2] & b)) 73652130Smckusick dc_tty[unit].t_state |= TS_CARR_ON; 73752130Smckusick (void) splx(s); 73852130Smckusick return (mbits); 73952130Smckusick } 74052130Smckusick 74152130Smckusick /* 74252130Smckusick * This is called by timeout() periodically. 74352130Smckusick * Check to see if modem status bits have changed. 74452130Smckusick */ 74556819Sralph void 74655744Sralph dcscan(arg) 74755744Sralph void *arg; 74852130Smckusick { 74952130Smckusick register dcregs *dcaddr; 75052130Smckusick register struct tty *tp; 75152130Smckusick register int i, bit, car; 75252130Smckusick int s; 75352130Smckusick 75452130Smckusick s = spltty(); 75552130Smckusick /* only channel 2 has modem control (what about line 3?) */ 75656819Sralph dcaddr = (dcregs *)dcpdma[i = 2].p_addr; 75752130Smckusick tp = &dc_tty[i]; 75852130Smckusick bit = TCR_DTR2; 75952130Smckusick if (dcsoftCAR[i >> 2] & bit) 76052130Smckusick car = 1; 76152130Smckusick else 76252130Smckusick car = dcaddr->dc_msr & MSR_DSR2; 76352130Smckusick if (car) { 76452130Smckusick /* carrier present */ 76552130Smckusick if (!(tp->t_state & TS_CARR_ON)) 76652130Smckusick (void)(*linesw[tp->t_line].l_modem)(tp, 1); 76752130Smckusick } else if ((tp->t_state & TS_CARR_ON) && 76852130Smckusick (*linesw[tp->t_line].l_modem)(tp, 0) == 0) 76952130Smckusick dcaddr->dc_tcr &= ~bit; 77052130Smckusick splx(s); 77155744Sralph timeout(dcscan, (void *)0, hz); 77252130Smckusick } 77352130Smckusick 77452130Smckusick /* 77552130Smckusick * ---------------------------------------------------------------------------- 77652130Smckusick * 77756819Sralph * dcGetc -- 77852130Smckusick * 77956819Sralph * Read a character from a serial line. 78052130Smckusick * 78152130Smckusick * Results: 78256819Sralph * A character read from the serial port. 78352130Smckusick * 78452130Smckusick * Side effects: 78552130Smckusick * None. 78652130Smckusick * 78752130Smckusick * ---------------------------------------------------------------------------- 78852130Smckusick */ 78952130Smckusick int 79056819Sralph dcGetc(dev) 79156819Sralph dev_t dev; 79252130Smckusick { 79352130Smckusick register dcregs *dcaddr; 79452130Smckusick register int c; 79554146Sralph int s; 79652130Smckusick 79756819Sralph dcaddr = (dcregs *)dcpdma[minor(dev)].p_addr; 79852130Smckusick if (!dcaddr) 79952130Smckusick return (0); 80054146Sralph s = spltty(); 80152693Sralph for (;;) { 80252693Sralph if (!(dcaddr->dc_csr & CSR_RDONE)) 80352693Sralph continue; 80452693Sralph c = dcaddr->dc_rbuf; 80552693Sralph DELAY(10); 80656819Sralph if (((c >> 8) & 03) == (minor(dev) & 03)) 80752693Sralph break; 80852693Sralph } 80952693Sralph splx(s); 81056819Sralph return (c & 0xff); 81152693Sralph } 81252693Sralph 81352693Sralph /* 81456819Sralph * Send a char on a port, non interrupt driven. 81552693Sralph */ 81652130Smckusick void 81756819Sralph dcPutc(dev, c) 81856819Sralph dev_t dev; 81952130Smckusick int c; 82052130Smckusick { 82152130Smckusick register dcregs *dcaddr; 82252130Smckusick register u_short tcr; 82352130Smckusick register int timeout; 82456819Sralph int s, line; 82552130Smckusick 82656819Sralph s = spltty(); 82756819Sralph 82856819Sralph dcaddr = (dcregs *)dcpdma[minor(dev)].p_addr; 82952130Smckusick tcr = dcaddr->dc_tcr; 83056819Sralph dcaddr->dc_tcr = tcr | (1 << minor(dev)); 83152130Smckusick MachEmptyWriteBuffer(); 83252130Smckusick DELAY(10); 83352130Smckusick while (1) { 83452130Smckusick /* 83552130Smckusick * Wait for transmitter to be not busy. 83652130Smckusick */ 83752130Smckusick timeout = 1000000; 83852130Smckusick while (!(dcaddr->dc_csr & CSR_TRDY) && timeout > 0) 83952130Smckusick timeout--; 84052130Smckusick if (timeout == 0) { 84156819Sralph printf("dcPutc: timeout waiting for CSR_TRDY\n"); 84252130Smckusick break; 84352130Smckusick } 84452130Smckusick line = (dcaddr->dc_csr >> 8) & 3; 84552130Smckusick /* 84652130Smckusick * Check to be sure its the right port. 84752130Smckusick */ 84856819Sralph if (line != minor(dev)) { 84952130Smckusick tcr |= 1 << line; 85052130Smckusick dcaddr->dc_tcr &= ~(1 << line); 85152130Smckusick MachEmptyWriteBuffer(); 85252130Smckusick DELAY(10); 85352130Smckusick continue; 85452130Smckusick } 85552130Smckusick /* 85652130Smckusick * Start sending the character. 85752130Smckusick */ 85852130Smckusick dcaddr->dc_tdr = dc_brk[0] | (c & 0xff); 85952130Smckusick MachEmptyWriteBuffer(); 86052130Smckusick DELAY(10); 86152130Smckusick /* 86252130Smckusick * Wait for character to be sent. 86352130Smckusick */ 86452130Smckusick while (1) { 86552130Smckusick /* 86652130Smckusick * cc -O bug: this code produces and infinite loop! 86752130Smckusick * while (!(dcaddr->dc_csr & CSR_TRDY)) 86852130Smckusick * ; 86952130Smckusick */ 87052130Smckusick timeout = 1000000; 87152130Smckusick while (!(dcaddr->dc_csr & CSR_TRDY) && timeout > 0) 87252130Smckusick timeout--; 87352130Smckusick line = (dcaddr->dc_csr >> 8) & 3; 87456819Sralph if (line != minor(dev)) { 87552130Smckusick tcr |= 1 << line; 87652130Smckusick dcaddr->dc_tcr &= ~(1 << line); 87752130Smckusick MachEmptyWriteBuffer(); 87852130Smckusick DELAY(10); 87952130Smckusick continue; 88052130Smckusick } 88156819Sralph dcaddr->dc_tcr &= ~(1 << minor(dev)); 88252130Smckusick MachEmptyWriteBuffer(); 88352130Smckusick DELAY(10); 88452130Smckusick break; 88552130Smckusick } 88652130Smckusick break; 88752130Smckusick } 88852130Smckusick /* 88952130Smckusick * Enable interrupts for other lines which became ready. 89052130Smckusick */ 89152130Smckusick if (tcr & 0xF) { 89252130Smckusick dcaddr->dc_tcr = tcr; 89352130Smckusick MachEmptyWriteBuffer(); 89452130Smckusick DELAY(10); 89552130Smckusick } 89652130Smckusick 89756819Sralph splx(s); 89852130Smckusick } 89952130Smckusick #endif /* NDC */ 900