156819Sralph /*- 256819Sralph * Copyright (c) 1992 The Regents of the University of California. 352130Smckusick * 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*58975Sralph * @(#)dc.c 7.13 (Berkeley) 04/05/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 tp->t_addr = (caddr_t)pdp; 17552130Smckusick pdp++, tp++; 17652130Smckusick } 17752130Smckusick dcsoftCAR[cp->pmax_unit] = cp->pmax_flags | 0xB; 17852130Smckusick 17952130Smckusick if (dc_timer == 0) { 18052130Smckusick dc_timer = 1; 18155744Sralph timeout(dcscan, (void *)0, hz); 18252130Smckusick } 18356819Sralph 18456819Sralph /* 18556819Sralph * Special handling for consoles. 18656819Sralph */ 18752130Smckusick if (cp->pmax_unit == 0) { 18856819Sralph if (cn_tab.cn_screen) { 18956819Sralph s = spltty(); 19056819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_8_BIT_CHAR | 19156819Sralph LPR_B4800 | DCKBD_PORT; 192*58975Sralph MachEmptyWriteBuffer(); 19356819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_B4800 | LPR_OPAR | 19456819Sralph LPR_PARENB | LPR_8_BIT_CHAR | DCMOUSE_PORT; 19556819Sralph MachEmptyWriteBuffer(); 19657234Sralph DELAY(1000); 19756819Sralph KBDReset(makedev(DCDEV, DCKBD_PORT), dcPutc); 19856819Sralph MouseInit(makedev(DCDEV, DCMOUSE_PORT), dcPutc, dcGetc); 19956819Sralph splx(s); 20056819Sralph } else if (major(cn_tab.cn_dev) == DCDEV) { 20156819Sralph s = spltty(); 20256819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_8_BIT_CHAR | 20356819Sralph LPR_B9600 | minor(cn_tab.cn_dev); 20456819Sralph MachEmptyWriteBuffer(); 20557234Sralph DELAY(1000); 20656819Sralph cn_tab.cn_disabled = 0; 20756819Sralph splx(s); 20856819Sralph } 20952130Smckusick } 21057234Sralph printf("dc%d at nexus0 csr 0x%x priority %d\n", 21157234Sralph cp->pmax_unit, cp->pmax_addr, cp->pmax_pri); 21252130Smckusick return (1); 21352130Smckusick } 21452130Smckusick 21554146Sralph dcopen(dev, flag, mode, p) 21652130Smckusick dev_t dev; 21754146Sralph int flag, mode; 21854146Sralph struct proc *p; 21952130Smckusick { 22052130Smckusick register struct tty *tp; 22152130Smckusick register int unit; 22252130Smckusick int s, error = 0; 22352130Smckusick 22452130Smckusick unit = minor(dev); 22556819Sralph if (unit >= dc_cnt || dcpdma[unit].p_addr == (void *)0) 22652130Smckusick return (ENXIO); 22752130Smckusick tp = &dc_tty[unit]; 22852130Smckusick tp->t_addr = (caddr_t)&dcpdma[unit]; 22952130Smckusick tp->t_oproc = dcstart; 23052130Smckusick tp->t_param = dcparam; 23152130Smckusick tp->t_dev = dev; 23252130Smckusick if ((tp->t_state & TS_ISOPEN) == 0) { 23352130Smckusick tp->t_state |= TS_WOPEN; 23452130Smckusick ttychars(tp); 23552130Smckusick #ifndef PORTSELECTOR 23652130Smckusick if (tp->t_ispeed == 0) { 23752130Smckusick #endif 23852130Smckusick tp->t_iflag = TTYDEF_IFLAG; 23952130Smckusick tp->t_oflag = TTYDEF_OFLAG; 24052130Smckusick tp->t_cflag = TTYDEF_CFLAG; 24152130Smckusick tp->t_lflag = LFLAG; 24252130Smckusick tp->t_ispeed = tp->t_ospeed = ISPEED; 24352130Smckusick #ifdef PORTSELECTOR 24452130Smckusick tp->t_cflag |= HUPCL; 24552130Smckusick #else 24652130Smckusick } 24752130Smckusick #endif 24852130Smckusick (void) dcparam(tp, &tp->t_termios); 24952130Smckusick ttsetwater(tp); 25052130Smckusick } else if ((tp->t_state & TS_XCLUDE) && curproc->p_ucred->cr_uid != 0) 25152130Smckusick return (EBUSY); 25252130Smckusick (void) dcmctl(dev, DML_DTR, DMSET); 25352130Smckusick s = spltty(); 25452130Smckusick while (!(flag & O_NONBLOCK) && !(tp->t_cflag & CLOCAL) && 25552130Smckusick !(tp->t_state & TS_CARR_ON)) { 25652130Smckusick tp->t_state |= TS_WOPEN; 25752130Smckusick if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH, 25852130Smckusick ttopen, 0)) 25952130Smckusick break; 26052130Smckusick } 26152130Smckusick splx(s); 26252130Smckusick if (error) 26352130Smckusick return (error); 26452130Smckusick return ((*linesw[tp->t_line].l_open)(dev, tp)); 26552130Smckusick } 26652130Smckusick 26752130Smckusick /*ARGSUSED*/ 26854146Sralph dcclose(dev, flag, mode, p) 26952130Smckusick dev_t dev; 27054146Sralph int flag, mode; 27154146Sralph struct proc *p; 27252130Smckusick { 27352130Smckusick register struct tty *tp; 27452130Smckusick register int unit, bit; 27552130Smckusick 27652130Smckusick unit = minor(dev); 27752130Smckusick tp = &dc_tty[unit]; 27852130Smckusick bit = 1 << ((unit & 03) + 8); 27952130Smckusick if (dc_brk[unit >> 2] & bit) { 28052130Smckusick dc_brk[unit >> 2] &= ~bit; 28152130Smckusick ttyoutput(0, tp); 28252130Smckusick } 28354146Sralph (*linesw[tp->t_line].l_close)(tp, flag); 28452130Smckusick if ((tp->t_cflag & HUPCL) || (tp->t_state & TS_WOPEN) || 28552130Smckusick !(tp->t_state & TS_ISOPEN)) 28652130Smckusick (void) dcmctl(dev, 0, DMSET); 28752130Smckusick return (ttyclose(tp)); 28852130Smckusick } 28952130Smckusick 29052130Smckusick dcread(dev, uio, flag) 29152130Smckusick dev_t dev; 29252130Smckusick struct uio *uio; 29352130Smckusick { 29452130Smckusick register struct tty *tp; 29552130Smckusick 29652130Smckusick tp = &dc_tty[minor(dev)]; 29752130Smckusick return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); 29852130Smckusick } 29952130Smckusick 30052130Smckusick dcwrite(dev, uio, flag) 30152130Smckusick dev_t dev; 30252130Smckusick struct uio *uio; 30352130Smckusick { 30452130Smckusick register struct tty *tp; 30552130Smckusick 30652130Smckusick tp = &dc_tty[minor(dev)]; 30752130Smckusick return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); 30852130Smckusick } 30952130Smckusick 31052130Smckusick /*ARGSUSED*/ 31154146Sralph dcioctl(dev, cmd, data, flag, p) 31252130Smckusick dev_t dev; 31356819Sralph int cmd; 31452130Smckusick caddr_t data; 31554146Sralph int flag; 31654146Sralph struct proc *p; 31752130Smckusick { 31852130Smckusick register struct tty *tp; 31952130Smckusick register int unit = minor(dev); 32052130Smckusick register int dc = unit >> 2; 32152130Smckusick int error; 32252130Smckusick 32352130Smckusick tp = &dc_tty[unit]; 32454146Sralph error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p); 32552130Smckusick if (error >= 0) 32652130Smckusick return (error); 32752130Smckusick error = ttioctl(tp, cmd, data, flag); 32852130Smckusick if (error >= 0) 32952130Smckusick return (error); 33052130Smckusick 33152130Smckusick switch (cmd) { 33252130Smckusick 33352130Smckusick case TIOCSBRK: 33452130Smckusick dc_brk[dc] |= 1 << ((unit & 03) + 8); 33552130Smckusick ttyoutput(0, tp); 33652130Smckusick break; 33752130Smckusick 33852130Smckusick case TIOCCBRK: 33952130Smckusick dc_brk[dc] &= ~(1 << ((unit & 03) + 8)); 34052130Smckusick ttyoutput(0, tp); 34152130Smckusick break; 34252130Smckusick 34352130Smckusick case TIOCSDTR: 34452130Smckusick (void) dcmctl(dev, DML_DTR|DML_RTS, DMBIS); 34552130Smckusick break; 34652130Smckusick 34752130Smckusick case TIOCCDTR: 34852130Smckusick (void) dcmctl(dev, DML_DTR|DML_RTS, DMBIC); 34952130Smckusick break; 35052130Smckusick 35152130Smckusick case TIOCMSET: 35252130Smckusick (void) dcmctl(dev, *(int *)data, DMSET); 35352130Smckusick break; 35452130Smckusick 35552130Smckusick case TIOCMBIS: 35652130Smckusick (void) dcmctl(dev, *(int *)data, DMBIS); 35752130Smckusick break; 35852130Smckusick 35952130Smckusick case TIOCMBIC: 36052130Smckusick (void) dcmctl(dev, *(int *)data, DMBIC); 36152130Smckusick break; 36252130Smckusick 36352130Smckusick case TIOCMGET: 36452130Smckusick *(int *)data = dcmctl(dev, 0, DMGET); 36552130Smckusick break; 36652130Smckusick 36752130Smckusick default: 36852130Smckusick return (ENOTTY); 36952130Smckusick } 37052130Smckusick return (0); 37152130Smckusick } 37252130Smckusick 37352130Smckusick dcparam(tp, t) 37452130Smckusick register struct tty *tp; 37552130Smckusick register struct termios *t; 37652130Smckusick { 37752130Smckusick register dcregs *dcaddr; 37852130Smckusick register int lpr; 37952130Smckusick register int cflag = t->c_cflag; 38052130Smckusick int unit = minor(tp->t_dev); 38152130Smckusick int ospeed = ttspeedtab(t->c_ospeed, dcspeedtab); 38252130Smckusick 38352130Smckusick /* check requested parameters */ 38452130Smckusick if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed) || 38556819Sralph (cflag & CSIZE) == CS5 || (cflag & CSIZE) == CS6 || 38656819Sralph (pmax_boardtype == DS_PMAX && t->c_ospeed == 19200)) 38752130Smckusick return (EINVAL); 38852130Smckusick /* and copy to tty */ 38952130Smckusick tp->t_ispeed = t->c_ispeed; 39052130Smckusick tp->t_ospeed = t->c_ospeed; 39152130Smckusick tp->t_cflag = cflag; 39252130Smckusick 39356819Sralph dcaddr = (dcregs *)dcpdma[unit].p_addr; 39456819Sralph 39556819Sralph /* 39656819Sralph * Handle console cases specially. 39756819Sralph */ 39856819Sralph if (cn_tab.cn_screen) { 39956819Sralph if (unit == DCKBD_PORT) { 40056819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_8_BIT_CHAR | 40156819Sralph LPR_B4800 | DCKBD_PORT; 40256819Sralph MachEmptyWriteBuffer(); 40356819Sralph return (0); 40456819Sralph } else if (unit == DCMOUSE_PORT) { 40556819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_B4800 | LPR_OPAR | 40656819Sralph LPR_PARENB | LPR_8_BIT_CHAR | DCMOUSE_PORT; 40756819Sralph MachEmptyWriteBuffer(); 40856819Sralph return (0); 40956819Sralph } 41056819Sralph } else if (tp->t_dev == cn_tab.cn_dev) { 41156819Sralph dcaddr->dc_lpr = LPR_RXENAB | LPR_8_BIT_CHAR | 41256819Sralph LPR_B9600 | unit; 41352130Smckusick MachEmptyWriteBuffer(); 41452130Smckusick return (0); 41552130Smckusick } 41652130Smckusick if (ospeed == 0) { 41752130Smckusick (void) dcmctl(unit, 0, DMSET); /* hang up line */ 41852130Smckusick return (0); 41952130Smckusick } 42052130Smckusick lpr = LPR_RXENAB | ospeed | (unit & 03); 42152130Smckusick if ((cflag & CSIZE) == CS7) 42252130Smckusick lpr |= LPR_7_BIT_CHAR; 42352130Smckusick else 42452130Smckusick lpr |= LPR_8_BIT_CHAR; 42552130Smckusick if (cflag & PARENB) 42652130Smckusick lpr |= LPR_PARENB; 42752130Smckusick if (cflag & PARODD) 42852130Smckusick lpr |= LPR_OPAR; 42952130Smckusick if (cflag & CSTOPB) 43052130Smckusick lpr |= LPR_2_STOP; 43152130Smckusick dcaddr->dc_lpr = lpr; 43252130Smckusick MachEmptyWriteBuffer(); 433*58975Sralph DELAY(10); 43452130Smckusick return (0); 43552130Smckusick } 43652130Smckusick 43752693Sralph /* 43852693Sralph * Check for interrupts from all devices. 43952693Sralph */ 44052693Sralph void 44152693Sralph dcintr(unit) 44252693Sralph register int unit; 44352693Sralph { 44452693Sralph register dcregs *dcaddr; 44552693Sralph register unsigned csr; 44652693Sralph 44752693Sralph unit <<= 2; 44856819Sralph dcaddr = (dcregs *)dcpdma[unit].p_addr; 44952693Sralph while ((csr = dcaddr->dc_csr) & (CSR_RDONE | CSR_TRDY)) { 45052693Sralph if (csr & CSR_RDONE) 45152693Sralph dcrint(unit); 45252693Sralph if (csr & CSR_TRDY) 45352693Sralph dcxint(&dc_tty[unit + ((csr >> 8) & 03)]); 45452693Sralph } 45552693Sralph } 45652693Sralph 45752693Sralph dcrint(unit) 45852693Sralph register int unit; 45952693Sralph { 46052693Sralph register dcregs *dcaddr; 46152693Sralph register struct tty *tp; 46252693Sralph register int c, cc; 46352693Sralph register struct tty *tp0; 46452693Sralph int overrun = 0; 46552693Sralph 46656819Sralph dcaddr = (dcregs *)dcpdma[unit].p_addr; 46752693Sralph tp0 = &dc_tty[unit]; 46852693Sralph while ((c = dcaddr->dc_rbuf) < 0) { /* char present */ 46952693Sralph cc = c & 0xff; 47052693Sralph tp = tp0 + ((c >> 8) & 03); 47152693Sralph if ((c & RBUF_OERR) && overrun == 0) { 47252693Sralph log(LOG_WARNING, "dc%d,%d: silo overflow\n", unit >> 2, 47352693Sralph (c >> 8) & 03); 47452693Sralph overrun = 1; 47552693Sralph } 47652693Sralph /* the keyboard requires special translation */ 47756819Sralph if (tp == &dc_tty[DCKBD_PORT] && cn_tab.cn_screen) { 47852693Sralph #ifdef KADB 47952693Sralph if (cc == LK_DO) { 48052693Sralph spl0(); 48152693Sralph kdbpanic(); 48252693Sralph return; 48352693Sralph } 48452693Sralph #endif 48552693Sralph #ifdef DEBUG 48652693Sralph debugChar = cc; 48752693Sralph #endif 48852693Sralph if (dcDivertXInput) { 48952863Sralph (*dcDivertXInput)(cc); 49052693Sralph return; 49152693Sralph } 49256819Sralph if ((cc = kbdMapChar(cc)) < 0) 49352693Sralph return; 49456819Sralph } else if (tp == &dc_tty[DCMOUSE_PORT] && dcMouseButtons) { 49552863Sralph register MouseReport *mrp; 49652693Sralph static MouseReport currentRep; 49752693Sralph 49852863Sralph mrp = ¤tRep; 49952863Sralph mrp->byteCount++; 50052693Sralph if (cc & MOUSE_START_FRAME) { 50152693Sralph /* 50252693Sralph * The first mouse report byte (button state). 50352693Sralph */ 50452863Sralph mrp->state = cc; 50552863Sralph if (mrp->byteCount > 1) 50652863Sralph mrp->byteCount = 1; 50752863Sralph } else if (mrp->byteCount == 2) { 50852693Sralph /* 50952693Sralph * The second mouse report byte (delta x). 51052693Sralph */ 51152863Sralph mrp->dx = cc; 51252863Sralph } else if (mrp->byteCount == 3) { 51352693Sralph /* 51452693Sralph * The final mouse report byte (delta y). 51552693Sralph */ 51652863Sralph mrp->dy = cc; 51752863Sralph mrp->byteCount = 0; 51852863Sralph if (mrp->dx != 0 || mrp->dy != 0) { 51952693Sralph /* 52052693Sralph * If the mouse moved, 52152693Sralph * post a motion event. 52252693Sralph */ 52352863Sralph (*dcMouseEvent)(mrp); 52452693Sralph } 52552863Sralph (*dcMouseButtons)(mrp); 52652693Sralph } 52752693Sralph return; 52852693Sralph } 52952693Sralph if (!(tp->t_state & TS_ISOPEN)) { 53052693Sralph wakeup((caddr_t)&tp->t_rawq); 53152693Sralph #ifdef PORTSELECTOR 53252693Sralph if (!(tp->t_state & TS_WOPEN)) 53352693Sralph #endif 53452693Sralph return; 53552693Sralph } 53652693Sralph if (c & RBUF_FERR) 53752693Sralph cc |= TTY_FE; 53852693Sralph if (c & RBUF_PERR) 53952693Sralph cc |= TTY_PE; 54052693Sralph (*linesw[tp->t_line].l_rint)(cc, tp); 54152693Sralph } 54252693Sralph DELAY(10); 54352693Sralph } 54452693Sralph 54552755Sralph void 54652130Smckusick dcxint(tp) 54752130Smckusick register struct tty *tp; 54852130Smckusick { 54952130Smckusick register struct pdma *dp; 55052130Smckusick register dcregs *dcaddr; 55152130Smckusick 55252130Smckusick dp = (struct pdma *)tp->t_addr; 55352130Smckusick if (dp->p_mem < dp->p_end) { 55456819Sralph dcaddr = (dcregs *)dp->p_addr; 55552130Smckusick dcaddr->dc_tdr = dc_brk[(tp - dc_tty) >> 2] | *dp->p_mem++; 55652130Smckusick MachEmptyWriteBuffer(); 55752130Smckusick DELAY(10); 55852130Smckusick return; 55952130Smckusick } 56052130Smckusick tp->t_state &= ~TS_BUSY; 56152130Smckusick if (tp->t_state & TS_FLUSH) 56252130Smckusick tp->t_state &= ~TS_FLUSH; 56352130Smckusick else { 56452130Smckusick ndflush(&tp->t_outq, dp->p_mem-tp->t_outq.c_cf); 56552130Smckusick dp->p_end = dp->p_mem = tp->t_outq.c_cf; 56652130Smckusick } 56752130Smckusick if (tp->t_line) 56852130Smckusick (*linesw[tp->t_line].l_start)(tp); 56952130Smckusick else 57052130Smckusick dcstart(tp); 57152130Smckusick if (tp->t_outq.c_cc == 0 || !(tp->t_state & TS_BUSY)) { 572*58975Sralph dcaddr = (dcregs *)dp->p_addr; 573*58975Sralph dcaddr->dc_tcr &= ~(1 << (minor(tp->t_dev) & 03)); 57452130Smckusick MachEmptyWriteBuffer(); 57552130Smckusick DELAY(10); 57652130Smckusick } 57752130Smckusick } 57852130Smckusick 57952755Sralph void 58052130Smckusick dcstart(tp) 58152130Smckusick register struct tty *tp; 58252130Smckusick { 58352130Smckusick register struct pdma *dp; 58452130Smckusick register dcregs *dcaddr; 58552130Smckusick register int cc; 58652130Smckusick int s; 58752130Smckusick 58852130Smckusick dp = (struct pdma *)tp->t_addr; 58956819Sralph dcaddr = (dcregs *)dp->p_addr; 59052130Smckusick s = spltty(); 59152130Smckusick if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) 59252130Smckusick goto out; 59352130Smckusick if (tp->t_outq.c_cc <= tp->t_lowat) { 59452130Smckusick if (tp->t_state & TS_ASLEEP) { 59552130Smckusick tp->t_state &= ~TS_ASLEEP; 59652130Smckusick wakeup((caddr_t)&tp->t_outq); 59752130Smckusick } 59852674Smckusick selwakeup(&tp->t_wsel); 59952130Smckusick } 60052130Smckusick if (tp->t_outq.c_cc == 0) 60152130Smckusick goto out; 60252130Smckusick /* handle console specially */ 60356819Sralph if (tp == &dc_tty[DCKBD_PORT] && cn_tab.cn_screen) { 60452130Smckusick while (tp->t_outq.c_cc > 0) { 60552130Smckusick cc = getc(&tp->t_outq) & 0x7f; 60652863Sralph cnputc(cc); 60752130Smckusick } 60852130Smckusick /* 60952130Smckusick * After we flush the output queue we may need to wake 61052130Smckusick * up the process that made the output. 61152130Smckusick */ 61252130Smckusick if (tp->t_outq.c_cc <= tp->t_lowat) { 61352130Smckusick if (tp->t_state & TS_ASLEEP) { 61452130Smckusick tp->t_state &= ~TS_ASLEEP; 61552130Smckusick wakeup((caddr_t)&tp->t_outq); 61652130Smckusick } 61752674Smckusick selwakeup(&tp->t_wsel); 61852130Smckusick } 61952130Smckusick goto out; 62052130Smckusick } 62152130Smckusick if (tp->t_flags & (RAW|LITOUT)) 62252130Smckusick cc = ndqb(&tp->t_outq, 0); 62352130Smckusick else { 62452130Smckusick cc = ndqb(&tp->t_outq, 0200); 62552130Smckusick if (cc == 0) { 62652130Smckusick cc = getc(&tp->t_outq); 62755744Sralph timeout(ttrstrt, (void *)tp, (cc & 0x7f) + 6); 62852130Smckusick tp->t_state |= TS_TIMEOUT; 62952130Smckusick goto out; 63052130Smckusick } 63152130Smckusick } 63252130Smckusick tp->t_state |= TS_BUSY; 63352130Smckusick dp->p_end = dp->p_mem = tp->t_outq.c_cf; 63452130Smckusick dp->p_end += cc; 63552130Smckusick dcaddr->dc_tcr |= 1 << (minor(tp->t_dev) & 03); 63652130Smckusick MachEmptyWriteBuffer(); 63752130Smckusick out: 63852130Smckusick splx(s); 63952130Smckusick } 64052130Smckusick 64152130Smckusick /* 64252130Smckusick * Stop output on a line. 64352130Smckusick */ 64452130Smckusick /*ARGSUSED*/ 64552130Smckusick dcstop(tp, flag) 64652130Smckusick register struct tty *tp; 64752130Smckusick { 64852130Smckusick register struct pdma *dp; 64952130Smckusick register int s; 65052130Smckusick 65152130Smckusick dp = (struct pdma *)tp->t_addr; 65252130Smckusick s = spltty(); 65352130Smckusick if (tp->t_state & TS_BUSY) { 65452130Smckusick dp->p_end = dp->p_mem; 65552130Smckusick if (!(tp->t_state & TS_TTSTOP)) 65652130Smckusick tp->t_state |= TS_FLUSH; 65752130Smckusick } 65852130Smckusick splx(s); 65952130Smckusick } 66052130Smckusick 66152130Smckusick dcmctl(dev, bits, how) 66252130Smckusick dev_t dev; 66352130Smckusick int bits, how; 66452130Smckusick { 66552130Smckusick register dcregs *dcaddr; 66652130Smckusick register int unit, mbits; 66752130Smckusick int b, s; 66852693Sralph register int msr; 66952130Smckusick 67052130Smckusick unit = minor(dev); 67152130Smckusick b = 1 << (unit & 03); 67256819Sralph dcaddr = (dcregs *)dcpdma[unit].p_addr; 67352130Smckusick s = spltty(); 67452130Smckusick /* only channel 2 has modem control (what about line 3?) */ 67556819Sralph mbits = DML_DTR | DML_DSR | DML_CAR; 67652693Sralph switch (unit & 03) { 67752693Sralph case 2: 67852130Smckusick mbits = 0; 67952130Smckusick if (dcaddr->dc_tcr & TCR_DTR2) 68052130Smckusick mbits |= DML_DTR; 68152693Sralph msr = dcaddr->dc_msr; 68252693Sralph if (msr & MSR_CD2) 68352693Sralph mbits |= DML_CAR; 68456819Sralph if (msr & MSR_DSR2) { 68556819Sralph if (pmax_boardtype == DS_PMAX) 68656819Sralph mbits |= DML_CAR | DML_DSR; 68756819Sralph else 68856819Sralph mbits |= DML_DSR; 68956819Sralph } 69052693Sralph break; 69152693Sralph 69252693Sralph case 3: 69356819Sralph if (pmax_boardtype != DS_PMAX) { 69456819Sralph mbits = 0; 69556819Sralph if (dcaddr->dc_tcr & TCR_DTR3) 69656819Sralph mbits |= DML_DTR; 69756819Sralph msr = dcaddr->dc_msr; 69856819Sralph if (msr & MSR_CD3) 69956819Sralph mbits |= DML_CAR; 70056819Sralph if (msr & MSR_DSR3) 70156819Sralph mbits |= DML_DSR; 70256819Sralph } 70352693Sralph } 70452130Smckusick switch (how) { 70552130Smckusick case DMSET: 70652130Smckusick mbits = bits; 70752130Smckusick break; 70852130Smckusick 70952130Smckusick case DMBIS: 71052130Smckusick mbits |= bits; 71152130Smckusick break; 71252130Smckusick 71352130Smckusick case DMBIC: 71452130Smckusick mbits &= ~bits; 71552130Smckusick break; 71652130Smckusick 71752130Smckusick case DMGET: 71852130Smckusick (void) splx(s); 71952130Smckusick return (mbits); 72052130Smckusick } 72152693Sralph switch (unit & 03) { 72252693Sralph case 2: 72352130Smckusick if (mbits & DML_DTR) 72452130Smckusick dcaddr->dc_tcr |= TCR_DTR2; 72552130Smckusick else 72652130Smckusick dcaddr->dc_tcr &= ~TCR_DTR2; 72752693Sralph break; 72852693Sralph 72952693Sralph case 3: 73056819Sralph if (pmax_boardtype != DS_PMAX) { 73156819Sralph if (mbits & DML_DTR) 73256819Sralph dcaddr->dc_tcr |= TCR_DTR3; 73356819Sralph else 73456819Sralph dcaddr->dc_tcr &= ~TCR_DTR3; 73556819Sralph } 73652130Smckusick } 73752130Smckusick if ((mbits & DML_DTR) && (dcsoftCAR[unit >> 2] & b)) 73852130Smckusick dc_tty[unit].t_state |= TS_CARR_ON; 73952130Smckusick (void) splx(s); 74052130Smckusick return (mbits); 74152130Smckusick } 74252130Smckusick 74352130Smckusick /* 74452130Smckusick * This is called by timeout() periodically. 74552130Smckusick * Check to see if modem status bits have changed. 74652130Smckusick */ 74756819Sralph void 74855744Sralph dcscan(arg) 74955744Sralph void *arg; 75052130Smckusick { 75152130Smckusick register dcregs *dcaddr; 75252130Smckusick register struct tty *tp; 75352130Smckusick register int i, bit, car; 75452130Smckusick int s; 75552130Smckusick 75652130Smckusick s = spltty(); 75752130Smckusick /* only channel 2 has modem control (what about line 3?) */ 75856819Sralph dcaddr = (dcregs *)dcpdma[i = 2].p_addr; 75952130Smckusick tp = &dc_tty[i]; 76052130Smckusick bit = TCR_DTR2; 76152130Smckusick if (dcsoftCAR[i >> 2] & bit) 76252130Smckusick car = 1; 76352130Smckusick else 76452130Smckusick car = dcaddr->dc_msr & MSR_DSR2; 76552130Smckusick if (car) { 76652130Smckusick /* carrier present */ 76752130Smckusick if (!(tp->t_state & TS_CARR_ON)) 76852130Smckusick (void)(*linesw[tp->t_line].l_modem)(tp, 1); 76952130Smckusick } else if ((tp->t_state & TS_CARR_ON) && 77052130Smckusick (*linesw[tp->t_line].l_modem)(tp, 0) == 0) 77152130Smckusick dcaddr->dc_tcr &= ~bit; 77252130Smckusick splx(s); 77355744Sralph timeout(dcscan, (void *)0, hz); 77452130Smckusick } 77552130Smckusick 77652130Smckusick /* 77752130Smckusick * ---------------------------------------------------------------------------- 77852130Smckusick * 77956819Sralph * dcGetc -- 78052130Smckusick * 78156819Sralph * Read a character from a serial line. 78252130Smckusick * 78352130Smckusick * Results: 78456819Sralph * A character read from the serial port. 78552130Smckusick * 78652130Smckusick * Side effects: 78752130Smckusick * None. 78852130Smckusick * 78952130Smckusick * ---------------------------------------------------------------------------- 79052130Smckusick */ 79152130Smckusick int 79256819Sralph dcGetc(dev) 79356819Sralph dev_t dev; 79452130Smckusick { 79552130Smckusick register dcregs *dcaddr; 79652130Smckusick register int c; 79754146Sralph int s; 79852130Smckusick 79956819Sralph dcaddr = (dcregs *)dcpdma[minor(dev)].p_addr; 80052130Smckusick if (!dcaddr) 80152130Smckusick return (0); 80254146Sralph s = spltty(); 80352693Sralph for (;;) { 80452693Sralph if (!(dcaddr->dc_csr & CSR_RDONE)) 80552693Sralph continue; 80652693Sralph c = dcaddr->dc_rbuf; 80752693Sralph DELAY(10); 80856819Sralph if (((c >> 8) & 03) == (minor(dev) & 03)) 80952693Sralph break; 81052693Sralph } 81152693Sralph splx(s); 81256819Sralph return (c & 0xff); 81352693Sralph } 81452693Sralph 81552693Sralph /* 81656819Sralph * Send a char on a port, non interrupt driven. 81752693Sralph */ 81852130Smckusick void 81956819Sralph dcPutc(dev, c) 82056819Sralph dev_t dev; 82152130Smckusick int c; 82252130Smckusick { 82352130Smckusick register dcregs *dcaddr; 82452130Smckusick register u_short tcr; 82552130Smckusick register int timeout; 82656819Sralph int s, line; 82752130Smckusick 82856819Sralph s = spltty(); 82956819Sralph 83056819Sralph dcaddr = (dcregs *)dcpdma[minor(dev)].p_addr; 83152130Smckusick tcr = dcaddr->dc_tcr; 83256819Sralph dcaddr->dc_tcr = tcr | (1 << minor(dev)); 83352130Smckusick MachEmptyWriteBuffer(); 83452130Smckusick DELAY(10); 83552130Smckusick while (1) { 83652130Smckusick /* 83752130Smckusick * Wait for transmitter to be not busy. 83852130Smckusick */ 83952130Smckusick timeout = 1000000; 84052130Smckusick while (!(dcaddr->dc_csr & CSR_TRDY) && timeout > 0) 84152130Smckusick timeout--; 84252130Smckusick if (timeout == 0) { 84356819Sralph printf("dcPutc: timeout waiting for CSR_TRDY\n"); 84452130Smckusick break; 84552130Smckusick } 84652130Smckusick line = (dcaddr->dc_csr >> 8) & 3; 84752130Smckusick /* 84852130Smckusick * Check to be sure its the right port. 84952130Smckusick */ 85056819Sralph if (line != minor(dev)) { 85152130Smckusick tcr |= 1 << line; 85252130Smckusick dcaddr->dc_tcr &= ~(1 << line); 85352130Smckusick MachEmptyWriteBuffer(); 85452130Smckusick DELAY(10); 85552130Smckusick continue; 85652130Smckusick } 85752130Smckusick /* 85852130Smckusick * Start sending the character. 85952130Smckusick */ 86052130Smckusick dcaddr->dc_tdr = dc_brk[0] | (c & 0xff); 86152130Smckusick MachEmptyWriteBuffer(); 86252130Smckusick DELAY(10); 86352130Smckusick /* 86452130Smckusick * Wait for character to be sent. 86552130Smckusick */ 86652130Smckusick while (1) { 86752130Smckusick /* 86852130Smckusick * cc -O bug: this code produces and infinite loop! 86952130Smckusick * while (!(dcaddr->dc_csr & CSR_TRDY)) 87052130Smckusick * ; 87152130Smckusick */ 87252130Smckusick timeout = 1000000; 87352130Smckusick while (!(dcaddr->dc_csr & CSR_TRDY) && timeout > 0) 87452130Smckusick timeout--; 87552130Smckusick line = (dcaddr->dc_csr >> 8) & 3; 87656819Sralph if (line != minor(dev)) { 87752130Smckusick tcr |= 1 << line; 87852130Smckusick dcaddr->dc_tcr &= ~(1 << line); 87952130Smckusick MachEmptyWriteBuffer(); 88052130Smckusick DELAY(10); 88152130Smckusick continue; 88252130Smckusick } 88356819Sralph dcaddr->dc_tcr &= ~(1 << minor(dev)); 88452130Smckusick MachEmptyWriteBuffer(); 88552130Smckusick DELAY(10); 88652130Smckusick break; 88752130Smckusick } 88852130Smckusick break; 88952130Smckusick } 89052130Smckusick /* 89152130Smckusick * Enable interrupts for other lines which became ready. 89252130Smckusick */ 89352130Smckusick if (tcr & 0xF) { 89452130Smckusick dcaddr->dc_tcr = tcr; 89552130Smckusick MachEmptyWriteBuffer(); 89652130Smckusick DELAY(10); 89752130Smckusick } 89852130Smckusick 89956819Sralph splx(s); 90052130Smckusick } 90152130Smckusick #endif /* NDC */ 902