123324Smckusick /* 223324Smckusick * Copyright (c) 1982 Regents of the University of California. 323324Smckusick * All rights reserved. The Berkeley software License Agreement 423324Smckusick * specifies the terms and conditions for redistribution. 523324Smckusick * 6*26366Skarels * @(#)dmf.c 6.15 (Berkeley) 02/23/86 723324Smckusick */ 86940Ssam 96940Ssam #include "dmf.h" 106940Ssam #if NDMF > 0 116940Ssam /* 126940Ssam * DMF32 driver 136940Ssam * 1421955Sbloom * 156940Ssam * TODO: 166940Ssam * test with modem 176940Ssam * load as much as possible into silo 186940Ssam * use auto XON/XOFF 196940Ssam * test reset code 2021955Sbloom **************************** 2121955Sbloom * DMF32 line printer driver 2221955Sbloom * 2321955Sbloom * the line printer on dmfx is indicated by a minor device code of 128+x 2421955Sbloom * 2521955Sbloom * the flags field of the config file is interpreted like so: 2621955Sbloom * bits meaning 2721955Sbloom * ---- ------- 2821955Sbloom * 0-7 soft carrier bits for ttys part of dmf32 2921955Sbloom * 8-15 number of cols/line on the line printer 3021955Sbloom * if 0, 132 will be used. 3121955Sbloom * 16-23 number of lines/page on the line printer 3221955Sbloom * if 0, 66 will be used. 3321955Sbloom * 346940Ssam */ 359772Ssam #include "../machine/pte.h" 369772Ssam 376940Ssam #include "bk.h" 3816063Skarels #include "uba.h" 3917124Sbloom #include "param.h" 4017124Sbloom #include "conf.h" 4117124Sbloom #include "dir.h" 4217124Sbloom #include "user.h" 4317124Sbloom #include "ioctl.h" 4417124Sbloom #include "tty.h" 4517124Sbloom #include "map.h" 4617124Sbloom #include "buf.h" 4717124Sbloom #include "vm.h" 4817124Sbloom #include "bkmac.h" 4917124Sbloom #include "clist.h" 5017124Sbloom #include "file.h" 5117124Sbloom #include "uio.h" 5221955Sbloom #include "kernel.h" 5318312Sralph #include "syslog.h" 546940Ssam 5517124Sbloom #include "ubareg.h" 5617124Sbloom #include "ubavar.h" 5717124Sbloom #include "dmfreg.h" 588473Sroot 596940Ssam /* 606940Ssam * Definition of the driver for the auto-configuration program. 616940Ssam */ 626940Ssam int dmfprobe(), dmfattach(), dmfrint(), dmfxint(); 6321955Sbloom int dmflint(); 646940Ssam struct uba_device *dmfinfo[NDMF]; 656940Ssam u_short dmfstd[] = { 0 }; 666940Ssam struct uba_driver dmfdriver = 676940Ssam { dmfprobe, 0, dmfattach, 0, dmfstd, "dmf", dmfinfo }; 686940Ssam 6925449Skarels int dmf_timeout = 10; /* silo timeout, in ms */ 7021955Sbloom int dmf_mindma = 4; /* don't dma below this point */ 7121955Sbloom 726940Ssam /* 736940Ssam * Local variables for the driver 746940Ssam */ 756940Ssam char dmf_speeds[] = 766940Ssam { 0, 0, 1, 2, 3, 4, 0, 5, 6, 7, 010, 012, 014, 016, 017, 0 }; 776940Ssam 7825449Skarels #ifndef PORTSELECTOR 7925449Skarels #define ISPEED B9600 8025449Skarels #define IFLAGS (EVENP|ODDP|ECHO) 8125449Skarels #else 8225449Skarels #define ISPEED B4800 8325449Skarels #define IFLAGS (EVENP|ODDP) 8425449Skarels #endif 8525449Skarels 866940Ssam struct tty dmf_tty[NDMF*8]; 876940Ssam char dmfsoftCAR[NDMF]; 8821955Sbloom 89*26366Skarels struct dmfl_softc { 90*26366Skarels u_int dmfl_state; /* soft state bits */ 91*26366Skarels int dmfl_info; /* uba info */ 92*26366Skarels u_short dmfl_lines; /* lines per page (66 def.) */ 93*26366Skarels u_short dmfl_cols; /* cols per line (132 def.) */ 94*26366Skarels char dmfl_buf[DMFL_BUFSIZ]; 9521955Sbloom } dmfl_softc[NDMF]; 9621955Sbloom 9721955Sbloom /* 9821955Sbloom * convert device number into DMF line printer unit number 9921955Sbloom */ 10021955Sbloom #define DMFL_UNIT(d) (minor(d)&0xF) /* up to 16 DMFs */ 10121955Sbloom 10221955Sbloom #define ASLP 1 /* waiting for interrupt from dmf */ 10321955Sbloom #define OPEN 2 /* line printer is open */ 10421955Sbloom #define ERROR 4 /* error while printing, driver 10521955Sbloom refuses to do anything till closed */ 10621955Sbloom 1078778Sroot #ifndef lint 1088778Sroot int ndmf = NDMF*8; /* used by iostat */ 1098778Sroot #endif 1106940Ssam int dmfact; /* mask of active dmf's */ 1116940Ssam int dmfstart(), ttrstrt(); 1126940Ssam 1136940Ssam /* 1146940Ssam * The clist space is mapped by the driver onto each UNIBUS. 1156940Ssam * The UBACVT macro converts a clist space address for unibus uban 1166940Ssam * into an i/o space address for the DMA routine. 1176940Ssam */ 11816063Skarels int dmf_ubinfo[NUBA]; /* info about allocated unibus map */ 11925449Skarels int cbase[NUBA]; /* base address in unibus map */ 1206940Ssam #define UBACVT(x, uban) (cbase[uban] + ((x)-(char *)cfree)) 12121955Sbloom char dmf_dma[NDMF*8]; 1226940Ssam 1236940Ssam /* 1246940Ssam * Routine for configuration to set dmf interrupt. 1256940Ssam */ 1266940Ssam /*ARGSUSED*/ 1276940Ssam dmfprobe(reg, ctlr) 1286940Ssam caddr_t reg; 12921955Sbloom struct uba_device *ctlr; 1306940Ssam { 1316940Ssam register int br, cvec; /* these are ``value-result'' */ 1326940Ssam register struct dmfdevice *dmfaddr = (struct dmfdevice *)reg; 13321955Sbloom register int i; 13421955Sbloom register unsigned int a; 13521955Sbloom static char *dmfdevs[]= 13621955Sbloom {"parallel","printer","synch","asynch"}; 13721955Sbloom unsigned int dmfoptions; 13825449Skarels static int (*intrv[3])() = { (int (*)())0, (int (*)())0, (int (*)())0 }; 1396940Ssam 1406940Ssam #ifdef lint 1416940Ssam br = 0; cvec = br; br = cvec; 1428808Sroot dmfxint(0); dmfrint(0); 143*26366Skarels dmfsrint(); dmfsxint(); dmfdaint(); dmfdbint(); dmflint(0); 1446940Ssam #endif 14521955Sbloom /* 14621955Sbloom * Pick the usual size DMF vector here (don't decrement it here). 14721955Sbloom * grab configuration; note that the DMF32 14821955Sbloom * doesn't seem to put the right bits in this 14921955Sbloom * register until AFTER the interrupt vector is set. 15021955Sbloom */ 1516940Ssam br = 0x15; 15221955Sbloom cvec = (uba_hd[numuba].uh_lastiv - 4*8); 15325449Skarels dmfaddr->dmfccsr0 = (cvec >> 2); 15421955Sbloom dmfoptions = dmfaddr->dmfccsr0 & DMFC_CONFMASK; 15521955Sbloom 15621955Sbloom /* catch a couple of special cases: Able vmz/32n and vmz/lp */ 15721955Sbloom if (dmfoptions == DMFC_ASYNC) { 15825449Skarels /* Async portion only */ 15925449Skarels 16025449Skarels cvec = (uba_hd[numuba].uh_lastiv -= 8); 16125449Skarels dmfaddr->dmfccsr0 = (cvec - 2*8) >> 2; 16225449Skarels intrv[0] = ctlr->ui_intr[4]; 16325449Skarels intrv[1] = ctlr->ui_intr[5]; 16425449Skarels ctlr->ui_intr = intrv; 16526312Skarels } else if (dmfoptions == DMFC_LP) { 16625449Skarels /* LP portion only */ 16721955Sbloom 16825449Skarels cvec = (uba_hd[numuba].uh_lastiv -= 8); 16925449Skarels ctlr->ui_intr = &ctlr->ui_intr[6]; 17026312Skarels } else if (dmfoptions == (DMFC_LP|DMFC_ASYNC)) { 17125449Skarels /* LP ans Async portions only */ 17225449Skarels 17325449Skarels cvec = (uba_hd[numuba].uh_lastiv -= 2*8); 17425449Skarels ctlr->ui_intr = &ctlr->ui_intr[4]; 17526312Skarels } else { 17625449Skarels /* All other configurations get everything */ 17721955Sbloom 17821955Sbloom cvec = (uba_hd[numuba].uh_lastiv -= 4*8); 17921955Sbloom } 18025449Skarels a = (dmfoptions >> 12) & 0xf; 18125449Skarels printf("dmf%d:", ctlr->ui_unit); 18226312Skarels for (i = 0; a != 0; ++i, a >>= 1) { 18326312Skarels if (a & 1) 18425449Skarels printf(" %s",dmfdevs[i]); 18525449Skarels } 18625449Skarels printf(".\n"); 18721955Sbloom 18821955Sbloom if (dmfoptions & DMFC_LP) 18921955Sbloom dmfaddr->dmfl[0] = DMFL_RESET; 1907412Skre return (sizeof (struct dmfdevice)); 1916940Ssam } 1926940Ssam 1936940Ssam /* 1946940Ssam * Routine called to attach a dmf. 1956940Ssam */ 1966940Ssam dmfattach(ui) 1976940Ssam struct uba_device *ui; 1986940Ssam { 19921955Sbloom register int cols = (ui->ui_flags>>8) & 0xff; 20021955Sbloom register int lines = (ui->ui_flags>>16) & 0xff; 2016940Ssam 20221955Sbloom dmfsoftCAR[ui->ui_unit] = ui->ui_flags & 0xff; 20321955Sbloom dmfl_softc[ui->ui_unit].dmfl_cols = cols==0?DMFL_DEFCOLS:cols; 20421955Sbloom dmfl_softc[ui->ui_unit].dmfl_lines = lines==0?DMFL_DEFLINES:lines; 20526221Skarels cbase[ui->ui_ubanum] = -1; 2066940Ssam } 2076940Ssam 2086940Ssam 2096940Ssam /* 2106940Ssam * Open a DMF32 line, mapping the clist onto the uba if this 2116940Ssam * is the first dmf on this uba. Turn on this dmf if this is 2126940Ssam * the first use of it. 2136940Ssam */ 2146940Ssam /*ARGSUSED*/ 2156940Ssam dmfopen(dev, flag) 2166940Ssam dev_t dev; 2176940Ssam { 2186940Ssam register struct tty *tp; 2196940Ssam register int unit, dmf; 2206940Ssam register struct dmfdevice *addr; 2216940Ssam register struct uba_device *ui; 2226940Ssam int s; 2236940Ssam 2246940Ssam unit = minor(dev); 22526312Skarels if (unit & 0200) 22626312Skarels return (dmflopen(dev,flag)); 2276940Ssam dmf = unit >> 3; 2288567Sroot if (unit >= NDMF*8 || (ui = dmfinfo[dmf])== 0 || ui->ui_alive == 0) 2298567Sroot return (ENXIO); 2306940Ssam tp = &dmf_tty[unit]; 2318567Sroot if (tp->t_state&TS_XCLUDE && u.u_uid!=0) 2328567Sroot return (EBUSY); 2336940Ssam addr = (struct dmfdevice *)ui->ui_addr; 2346940Ssam tp->t_addr = (caddr_t)addr; 2356940Ssam tp->t_oproc = dmfstart; 2366971Ssam tp->t_state |= TS_WOPEN; 2376940Ssam /* 2386940Ssam * While setting up state for this uba and this dmf, 2396940Ssam * block uba resets which can clear the state. 2406940Ssam */ 24121955Sbloom s = spltty(); 24226221Skarels if (cbase[ui->ui_ubanum] == -1) { 2436940Ssam dmf_ubinfo[ui->ui_ubanum] = 2446940Ssam uballoc(ui->ui_ubanum, (caddr_t)cfree, 2456940Ssam nclist*sizeof(struct cblock), 0); 24626221Skarels cbase[ui->ui_ubanum] = UBAI_ADDR(dmf_ubinfo[ui->ui_ubanum]); 2476940Ssam } 2486940Ssam if ((dmfact&(1<<dmf)) == 0) { 2496940Ssam addr->dmfcsr |= DMF_IE; 2506940Ssam dmfact |= (1<<dmf); 25121955Sbloom addr->dmfrsp = dmf_timeout; 2526940Ssam } 2536940Ssam splx(s); 2546940Ssam /* 2556940Ssam * If this is first open, initialze tty state to default. 2566940Ssam */ 2576971Ssam if ((tp->t_state&TS_ISOPEN) == 0) { 2586940Ssam ttychars(tp); 25925449Skarels tp->t_ispeed = ISPEED; 26025449Skarels tp->t_ospeed = ISPEED; 26125449Skarels tp->t_flags = IFLAGS; 2626940Ssam dmfparam(unit); 2636940Ssam } 2646940Ssam /* 2656940Ssam * Wait for carrier, then process line discipline specific open. 2666940Ssam */ 2676940Ssam if ((dmfmctl(dev, DMF_ON, DMSET) & (DMF_CAR<<8)) || 2686940Ssam (dmfsoftCAR[dmf] & (1<<(unit&07)))) 2696971Ssam tp->t_state |= TS_CARR_ON; 27021955Sbloom s = spltty(); 2716971Ssam while ((tp->t_state & TS_CARR_ON) == 0) { 2726971Ssam tp->t_state |= TS_WOPEN; 2736940Ssam sleep((caddr_t)&tp->t_rawq, TTIPRI); 2746940Ssam } 2756940Ssam splx(s); 2768567Sroot return ((*linesw[tp->t_line].l_open)(dev, tp)); 2776940Ssam } 2786940Ssam 2796940Ssam /* 2806940Ssam * Close a DMF32 line. 2816940Ssam */ 2826940Ssam /*ARGSUSED*/ 2836940Ssam dmfclose(dev, flag) 2846940Ssam dev_t dev; 2856940Ssam int flag; 2866940Ssam { 2876940Ssam register struct tty *tp; 2886940Ssam register unit; 2896940Ssam 2906940Ssam unit = minor(dev); 29126312Skarels if (unit & 0200) { 29226312Skarels dmflclose(dev,flag); 29326312Skarels return; 29426312Skarels } 29521955Sbloom 2966940Ssam tp = &dmf_tty[unit]; 2976940Ssam (*linesw[tp->t_line].l_close)(tp); 2988702Sroot (void) dmfmctl(unit, DMF_BRK, DMBIC); 2996971Ssam if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0) 3008702Sroot (void) dmfmctl(unit, DMF_OFF, DMSET); 3016940Ssam ttyclose(tp); 3026940Ssam } 3036940Ssam 3047726Sroot dmfread(dev, uio) 3056940Ssam dev_t dev; 3067726Sroot struct uio *uio; 3076940Ssam { 3086940Ssam register struct tty *tp; 3096940Ssam 31026312Skarels if (minor(dev) & 0200) 31121955Sbloom return(ENXIO); 3126940Ssam tp = &dmf_tty[minor(dev)]; 3137726Sroot return ((*linesw[tp->t_line].l_read)(tp, uio)); 3146940Ssam } 3156940Ssam 3167832Sroot dmfwrite(dev, uio) 3176940Ssam dev_t dev; 3187832Sroot struct uio *uio; 3196940Ssam { 3206940Ssam register struct tty *tp; 3216940Ssam 32226312Skarels if (minor(dev) & 0200) 32326312Skarels return (dmflwrite(dev,uio)); 3246940Ssam tp = &dmf_tty[minor(dev)]; 3258530Sroot return ((*linesw[tp->t_line].l_write)(tp, uio)); 3266940Ssam } 3276940Ssam 3286940Ssam /* 3296940Ssam * DMF32 receiver interrupt. 3306940Ssam */ 3316940Ssam dmfrint(dmf) 3326940Ssam int dmf; 3336940Ssam { 3346940Ssam register c; 33526312Skarels register struct tty *tp; 3366940Ssam register struct dmfdevice *addr; 3376940Ssam register struct tty *tp0; 33821955Sbloom int unit; 33925449Skarels int overrun = 0; 34026312Skarels register struct uba_device *ui; 3416940Ssam 34226312Skarels ui = dmfinfo[dmf]; 34326312Skarels if (ui == 0 || ui->ui_alive == 0) 34426312Skarels return; 34526312Skarels addr = (struct dmfdevice *)ui->ui_addr; 34621955Sbloom tp0 = &dmf_tty[dmf * 8]; 3476940Ssam /* 3486940Ssam * Loop fetching characters from the silo for this 3496940Ssam * dmf until there are no more in the silo. 3506940Ssam */ 3516940Ssam while ((c = addr->dmfrbuf) < 0) { 35221955Sbloom 35321955Sbloom unit = (c >> 8) & 07; 35421955Sbloom tp = tp0 + unit; 3556940Ssam if (c & DMF_DSC) { 35621955Sbloom addr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 35725449Skarels if (addr->dmfrms & DMF_CAR) 35825449Skarels (void)(*linesw[tp->t_line].l_modem)(tp, 1); 35926312Skarels else if ((dmfsoftCAR[dmf] & (1 << unit)) == 0 && 36025449Skarels (*linesw[tp->t_line].l_modem)(tp, 0) == 0) { 36125449Skarels addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 36225449Skarels addr->dmflctms = DMFLCR_ENA; 3636940Ssam } 3646940Ssam continue; 3656940Ssam } 36626312Skarels if ((tp->t_state&TS_ISOPEN) == 0) { 36725449Skarels wakeup((caddr_t)&tp->t_rawq); 36825449Skarels #ifdef PORTSELECTOR 36926312Skarels if ((tp->t_state & TS_WOPEN) == 0) 37025449Skarels #endif 37125449Skarels continue; 3726940Ssam } 37321956Sbloom if (c & (DMF_PE|DMF_DO|DMF_FE)) { 37421955Sbloom if (c & DMF_PE) 37526312Skarels if ((tp->t_flags & (EVENP|ODDP)) == EVENP 37626312Skarels || (tp->t_flags & (EVENP|ODDP)) == ODDP) 37721955Sbloom continue; 37821955Sbloom if ((c & DMF_DO) && overrun == 0) { 37924842Seric log(LOG_WARNING, "dmf%d: silo overflow\n", dmf); 38021955Sbloom overrun = 1; 38121955Sbloom } 38221955Sbloom if (c & DMF_FE) 38321955Sbloom /* 38421955Sbloom * At framing error (break) generate 38521955Sbloom * a null (in raw mode, for getty), or a 38621955Sbloom * interrupt (in cooked/cbreak mode). 38721955Sbloom */ 38826312Skarels if (tp->t_flags & RAW) 38921955Sbloom c = 0; 39021955Sbloom else 39121955Sbloom c = tp->t_intrc; 3926940Ssam } 3936940Ssam #if NBK > 0 3946940Ssam if (tp->t_line == NETLDISC) { 3956940Ssam c &= 0177; 3966940Ssam BKINPUT(c, tp); 3976940Ssam } else 3986940Ssam #endif 3996940Ssam (*linesw[tp->t_line].l_rint)(c, tp); 4006940Ssam } 4016940Ssam } 4026940Ssam 4036940Ssam /* 4046940Ssam * Ioctl for DMF32. 4056940Ssam */ 4066940Ssam /*ARGSUSED*/ 4077630Ssam dmfioctl(dev, cmd, data, flag) 4086940Ssam dev_t dev; 4097630Ssam caddr_t data; 4106940Ssam { 4116940Ssam register struct tty *tp; 4126940Ssam register int unit = minor(dev); 4138567Sroot int error; 4146940Ssam 41526312Skarels if (unit & 0200) 41621955Sbloom return (ENOTTY); 4176940Ssam tp = &dmf_tty[unit]; 4188567Sroot error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); 4198567Sroot if (error >= 0) 4208567Sroot return (error); 4218567Sroot error = ttioctl(tp, cmd, data, flag); 4228567Sroot if (error >= 0) { 42317562Sbloom if (cmd == TIOCSETP || cmd == TIOCSETN || cmd == TIOCLBIS || 42417562Sbloom cmd == TIOCLBIC || cmd == TIOCLSET) 4256940Ssam dmfparam(unit); 4268567Sroot return (error); 4278567Sroot } 4288567Sroot switch (cmd) { 4296940Ssam 4306940Ssam case TIOCSBRK: 4318702Sroot (void) dmfmctl(dev, DMF_BRK, DMBIS); 4326940Ssam break; 4337630Ssam 4346940Ssam case TIOCCBRK: 4358702Sroot (void) dmfmctl(dev, DMF_BRK, DMBIC); 4366940Ssam break; 4377630Ssam 4386940Ssam case TIOCSDTR: 4398702Sroot (void) dmfmctl(dev, DMF_DTR|DMF_RTS, DMBIS); 4406940Ssam break; 4417630Ssam 4426940Ssam case TIOCCDTR: 4438702Sroot (void) dmfmctl(dev, DMF_DTR|DMF_RTS, DMBIC); 4446940Ssam break; 4457630Ssam 4466940Ssam case TIOCMSET: 4478702Sroot (void) dmfmctl(dev, dmtodmf(*(int *)data), DMSET); 4486940Ssam break; 4497630Ssam 4506940Ssam case TIOCMBIS: 4518702Sroot (void) dmfmctl(dev, dmtodmf(*(int *)data), DMBIS); 4526940Ssam break; 4537630Ssam 4546940Ssam case TIOCMBIC: 4558702Sroot (void) dmfmctl(dev, dmtodmf(*(int *)data), DMBIC); 4566940Ssam break; 4577630Ssam 4586940Ssam case TIOCMGET: 4597630Ssam *(int *)data = dmftodm(dmfmctl(dev, 0, DMGET)); 4606940Ssam break; 4617630Ssam 4626940Ssam default: 4638567Sroot return (ENOTTY); 4646940Ssam } 4658567Sroot return (0); 4666940Ssam } 4676940Ssam 4686940Ssam dmtodmf(bits) 4696940Ssam register int bits; 4706940Ssam { 4716940Ssam register int b; 4726940Ssam 4736940Ssam b = bits & 012; 4746940Ssam if (bits & DML_ST) b |= DMF_RATE; 4756940Ssam if (bits & DML_RTS) b |= DMF_RTS; 4766940Ssam if (bits & DML_USR) b |= DMF_USRW; 4776940Ssam return(b); 4786940Ssam } 4796940Ssam 4806940Ssam dmftodm(bits) 4816940Ssam register int bits; 4826940Ssam { 4836940Ssam register int b; 4846940Ssam 4856940Ssam b = (bits & 012) | ((bits >> 7) & 0760) | DML_LE; 4866940Ssam if (bits & DMF_USRR) b |= DML_USR; 4876940Ssam if (bits & DMF_RTS) b |= DML_RTS; 4886940Ssam return(b); 4896940Ssam } 4906940Ssam 4916940Ssam 4926940Ssam /* 4936940Ssam * Set parameters from open or stty into the DMF hardware 4946940Ssam * registers. 4956940Ssam */ 4966940Ssam dmfparam(unit) 4976940Ssam register int unit; 4986940Ssam { 4996940Ssam register struct tty *tp; 5006940Ssam register struct dmfdevice *addr; 5016940Ssam register int lpar, lcr; 5026940Ssam int s; 5036940Ssam 5046940Ssam tp = &dmf_tty[unit]; 5056940Ssam addr = (struct dmfdevice *)tp->t_addr; 5066940Ssam /* 5076940Ssam * Block interrupts so parameters will be set 5086940Ssam * before the line interrupts. 5096940Ssam */ 51021955Sbloom s = spltty(); 5116940Ssam addr->dmfcsr = (unit&07) | DMFIR_LCR | DMF_IE; 5126940Ssam if ((tp->t_ispeed)==0) { 5136971Ssam tp->t_state |= TS_HUPCLS; 5148702Sroot (void) dmfmctl(unit, DMF_OFF, DMSET); 51525449Skarels splx(s); 5166940Ssam return; 5176940Ssam } 5186940Ssam lpar = (dmf_speeds[tp->t_ospeed]<<12) | (dmf_speeds[tp->t_ispeed]<<8); 5196940Ssam lcr = DMFLCR_ENA; 5206940Ssam if ((tp->t_ispeed) == B134) 5216940Ssam lpar |= BITS6|PENABLE; 52224270Slepreau else if (tp->t_flags & (RAW|LITOUT|PASS8)) 5236940Ssam lpar |= BITS8; 5246940Ssam else { 5256940Ssam lpar |= BITS7|PENABLE; 5266940Ssam /* CHECK FOR XON/XOFF AND SET lcr |= DMF_AUTOX; */ 5276940Ssam } 52812450Ssam if (tp->t_flags&EVENP) 52912450Ssam lpar |= EPAR; 5306940Ssam if ((tp->t_ospeed) == B110) 5316940Ssam lpar |= TWOSB; 5326940Ssam lpar |= (unit&07); 5336940Ssam addr->dmflpr = lpar; 53425654Skarels addr->dmflctms = (addr->dmflctms &~ 0xff) | lcr; 5356940Ssam splx(s); 5366940Ssam } 5376940Ssam 5386940Ssam /* 5396940Ssam * DMF32 transmitter interrupt. 5406940Ssam * Restart the idle line. 5416940Ssam */ 5426940Ssam dmfxint(dmf) 5436940Ssam int dmf; 5446940Ssam { 54526312Skarels int unit0 = dmf * 8; 54626312Skarels struct tty *tp0 = &dmf_tty[unit0]; 5476940Ssam register struct tty *tp; 5486940Ssam register struct dmfdevice *addr; 5496940Ssam register struct uba_device *ui; 55021955Sbloom register int t; 5516940Ssam short cntr; 5526940Ssam 5536940Ssam ui = dmfinfo[dmf]; 5546940Ssam addr = (struct dmfdevice *)ui->ui_addr; 5556940Ssam while ((t = addr->dmfcsr) & DMF_TI) { 55621955Sbloom if (t & DMF_NXM) 55721955Sbloom /* SHOULD RESTART OR SOMETHING... */ 55821955Sbloom printf("dmf%d: NXM line %d\n", dmf, t >> 8 & 7); 55921955Sbloom t = t >> 8 & 7; 56021955Sbloom tp = tp0 + t; 5616971Ssam tp->t_state &= ~TS_BUSY; 5626971Ssam if (tp->t_state&TS_FLUSH) 5636971Ssam tp->t_state &= ~TS_FLUSH; 56426312Skarels else if (dmf_dma[unit0 + t]) { 56521955Sbloom /* 56621955Sbloom * Do arithmetic in a short to make up 56721955Sbloom * for lost 16&17 bits. 56821955Sbloom */ 56921955Sbloom addr->dmfcsr = DMFIR_TBA | DMF_IE | t; 57021955Sbloom cntr = addr->dmftba - 57121955Sbloom UBACVT(tp->t_outq.c_cf, ui->ui_ubanum); 57221955Sbloom ndflush(&tp->t_outq, (int)cntr); 5736940Ssam } 5746940Ssam if (tp->t_line) 5756940Ssam (*linesw[tp->t_line].l_start)(tp); 5766940Ssam else 5776940Ssam dmfstart(tp); 5786940Ssam } 5796940Ssam } 5806940Ssam 5816940Ssam /* 5826940Ssam * Start (restart) transmission on the given DMF32 line. 5836940Ssam */ 5846940Ssam dmfstart(tp) 5856940Ssam register struct tty *tp; 5866940Ssam { 5876940Ssam register struct dmfdevice *addr; 5888607Sroot register int unit, nch; 5896940Ssam int s; 59021955Sbloom register int dmf; 5916940Ssam 5926940Ssam unit = minor(tp->t_dev); 59321955Sbloom dmf = unit >> 3; 5946940Ssam unit &= 07; 5956940Ssam addr = (struct dmfdevice *)tp->t_addr; 5966940Ssam 5976940Ssam /* 5986940Ssam * Must hold interrupts in following code to prevent 5996940Ssam * state of the tp from changing. 6006940Ssam */ 60121955Sbloom s = spltty(); 6026940Ssam /* 6036940Ssam * If it's currently active, or delaying, no need to do anything. 6046940Ssam */ 6056971Ssam if (tp->t_state&(TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) 6066940Ssam goto out; 6076940Ssam /* 6086940Ssam * If there are still characters in the silo, 6096940Ssam * just reenable the transmitter. 6106940Ssam */ 6116940Ssam addr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 6126940Ssam if (addr->dmftsc) { 6136940Ssam addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 61425449Skarels addr->dmflctms = addr->dmflctms | DMF_TE; 6156971Ssam tp->t_state |= TS_BUSY; 6166940Ssam goto out; 6176940Ssam } 6186940Ssam /* 6196940Ssam * If there are sleepers, and output has drained below low 6206940Ssam * water mark, wake up the sleepers. 6216940Ssam */ 62221955Sbloom if (tp->t_outq.c_cc<=TTLOWAT(tp)) { 62321955Sbloom if (tp->t_state&TS_ASLEEP) { 62421955Sbloom tp->t_state &= ~TS_ASLEEP; 62521955Sbloom wakeup((caddr_t)&tp->t_outq); 62621955Sbloom } 62721955Sbloom if (tp->t_wsel) { 62821955Sbloom selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); 62921955Sbloom tp->t_wsel = 0; 63021955Sbloom tp->t_state &= ~TS_WCOLL; 63121955Sbloom } 6326940Ssam } 6336940Ssam /* 6346940Ssam * Now restart transmission unless the output queue is 6356940Ssam * empty. 6366940Ssam */ 6376940Ssam if (tp->t_outq.c_cc == 0) 6386940Ssam goto out; 6399550Ssam if (tp->t_flags & (RAW|LITOUT)) 6406940Ssam nch = ndqb(&tp->t_outq, 0); 6416940Ssam else { 64221955Sbloom if ((nch = ndqb(&tp->t_outq, 0200)) == 0) { 64321955Sbloom /* 64421955Sbloom * If first thing on queue is a delay process it. 64521955Sbloom */ 6466940Ssam nch = getc(&tp->t_outq); 6476940Ssam timeout(ttrstrt, (caddr_t)tp, (nch&0x7f)+6); 6486971Ssam tp->t_state |= TS_TIMEOUT; 6496940Ssam goto out; 6506940Ssam } 6516940Ssam } 6526940Ssam /* 6536940Ssam * If characters to transmit, restart transmission. 6546940Ssam */ 65521955Sbloom if (nch >= dmf_mindma) { 65621955Sbloom register car; 65721955Sbloom 65821955Sbloom dmf_dma[minor(tp->t_dev)] = 1; 6596940Ssam addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 66025449Skarels addr->dmflctms = addr->dmflctms | DMF_TE; 6616940Ssam car = UBACVT(tp->t_outq.c_cf, dmfinfo[dmf]->ui_ubanum); 6626940Ssam addr->dmfcsr = DMF_IE | DMFIR_TBA | unit; 6636940Ssam addr->dmftba = car; 66421955Sbloom addr->dmftcc = ((car >> 2) & 0xc000) | nch; 66521955Sbloom tp->t_state |= TS_BUSY; 66621955Sbloom } else if (nch) { 6676940Ssam register char *cp = tp->t_outq.c_cf; 6686940Ssam register int i; 6696940Ssam 67021955Sbloom dmf_dma[minor(tp->t_dev)] = 0; 6716940Ssam nch = MIN(nch, DMF_SILOCNT); 6726940Ssam addr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 67325449Skarels addr->dmflctms = addr->dmflctms | DMF_TE; 6746940Ssam addr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 6756940Ssam for (i = 0; i < nch; i++) 6766940Ssam addr->dmftbuf = *cp++; 6776940Ssam ndflush(&tp->t_outq, nch); 6786971Ssam tp->t_state |= TS_BUSY; 6796940Ssam } 6806940Ssam out: 6816940Ssam splx(s); 6826940Ssam } 6836940Ssam 6846940Ssam /* 6856940Ssam * Stop output on a line, e.g. for ^S/^Q or output flush. 6866940Ssam */ 6876940Ssam /*ARGSUSED*/ 6886940Ssam dmfstop(tp, flag) 6896940Ssam register struct tty *tp; 6906940Ssam { 6916940Ssam register struct dmfdevice *addr; 69221955Sbloom register unit = minor(tp->t_dev) & 7; 69321955Sbloom int s; 6946940Ssam 6956940Ssam addr = (struct dmfdevice *)tp->t_addr; 6966940Ssam /* 6976940Ssam * Block input/output interrupts while messing with state. 6986940Ssam */ 69921955Sbloom s = spltty(); 70021955Sbloom if (flag) { 70121955Sbloom addr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 70221955Sbloom if (addr->dmftsc) { 70321955Sbloom /* 70421955Sbloom * Flush regardless of whether we're transmitting 70521955Sbloom * (TS_BUSY), if the silo contains untransmitted 70621955Sbloom * characters. 70721955Sbloom */ 70821955Sbloom addr->dmfcsr = DMFIR_LCR | unit | DMF_IE; 70925449Skarels addr->dmflctms = addr->dmflctms | DMF_TE | DMF_FLUSH; 71021955Sbloom /* this will interrupt so let dmfxint handle the rest */ 71121955Sbloom tp->t_state |= TS_FLUSH|TS_BUSY; 71221955Sbloom } 71321955Sbloom } else { 71421955Sbloom if (tp->t_state & TS_BUSY) { 71521955Sbloom /* 71621955Sbloom * Stop transmission by disabling 71721955Sbloom * the transmitter. We'll pick up where we 71821955Sbloom * left off by reenabling in dmfstart. 71921955Sbloom */ 72021955Sbloom addr->dmfcsr = DMFIR_LCR | unit | DMF_IE; 72125449Skarels addr->dmflctms = addr->dmflctms &~ DMF_TE; 72221955Sbloom /* no interrupt here */ 7236971Ssam tp->t_state &= ~TS_BUSY; 72421955Sbloom } 7256940Ssam } 7266940Ssam splx(s); 7276940Ssam } 7286940Ssam 7296940Ssam /* 7306940Ssam * DMF32 modem control 7316940Ssam */ 7326940Ssam dmfmctl(dev, bits, how) 7336940Ssam dev_t dev; 7346940Ssam int bits, how; 7356940Ssam { 7366940Ssam register struct dmfdevice *dmfaddr; 7376940Ssam register int unit, mbits, lcr; 7386940Ssam int s; 7396940Ssam 7406940Ssam unit = minor(dev); 7416940Ssam dmfaddr = (struct dmfdevice *)(dmf_tty[unit].t_addr); 7426940Ssam unit &= 07; 74321955Sbloom s = spltty(); 7446940Ssam dmfaddr->dmfcsr = DMF_IE | DMFIR_TBUF | unit; 7456940Ssam mbits = dmfaddr->dmfrms << 8; 7466940Ssam dmfaddr->dmfcsr = DMF_IE | DMFIR_LCR | unit; 74725654Skarels lcr = dmfaddr->dmflctms; 74825449Skarels mbits |= (lcr & 0xff00) >> 8; 7496940Ssam switch (how) { 7506940Ssam case DMSET: 75112449Ssam mbits = (mbits &0xff00) | bits; 7526940Ssam break; 7536940Ssam 7546940Ssam case DMBIS: 7556940Ssam mbits |= bits; 7566940Ssam break; 7576940Ssam 7586940Ssam case DMBIC: 7596940Ssam mbits &= ~bits; 7606940Ssam break; 7616940Ssam 7626940Ssam case DMGET: 7636940Ssam (void) splx(s); 7646940Ssam return(mbits); 7656940Ssam } 7666940Ssam if (mbits & DMF_BRK) 7676940Ssam lcr |= DMF_RBRK; 7686940Ssam else 7696940Ssam lcr &= ~DMF_RBRK; 77025449Skarels dmfaddr->dmflctms = ((mbits & 037) << 8) | (lcr & 0xff); 7716940Ssam (void) splx(s); 7726940Ssam return(mbits); 7736940Ssam } 7746940Ssam 7756940Ssam /* 7766940Ssam * Reset state of driver if UBA reset was necessary. 7776940Ssam * Reset the csr, lpr, and lcr registers on open lines, and 7786940Ssam * restart transmitters. 7796940Ssam */ 7806940Ssam dmfreset(uban) 7816940Ssam int uban; 7826940Ssam { 7836940Ssam register int dmf, unit; 7846940Ssam register struct tty *tp; 7856940Ssam register struct uba_device *ui; 7866940Ssam register struct dmfdevice *addr; 7876940Ssam int i; 7886940Ssam 7896940Ssam for (dmf = 0; dmf < NDMF; dmf++) { 7906940Ssam ui = dmfinfo[dmf]; 7916940Ssam if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban) 7926940Ssam continue; 7936940Ssam printf(" dmf%d", dmf); 79426221Skarels if (dmf_ubinfo[uban]) { 79525449Skarels dmf_ubinfo[uban] = uballoc(uban, (caddr_t)cfree, 79625449Skarels nclist*sizeof (struct cblock), 0); 79726221Skarels cbase[uban] = UBAI_ADDR(dmf_ubinfo[uban]); 79825449Skarels } 7996940Ssam addr = (struct dmfdevice *)ui->ui_addr; 8006940Ssam addr->dmfcsr = DMF_IE; 80121955Sbloom addr->dmfrsp = dmf_timeout; 8026940Ssam unit = dmf * 8; 8036940Ssam for (i = 0; i < 8; i++) { 8046940Ssam tp = &dmf_tty[unit]; 8056971Ssam if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) { 8066940Ssam dmfparam(unit); 8078702Sroot (void) dmfmctl(unit, DMF_ON, DMSET); 8086971Ssam tp->t_state &= ~TS_BUSY; 8096940Ssam dmfstart(tp); 8106940Ssam } 8116940Ssam unit++; 8126940Ssam } 8136940Ssam } 8146940Ssam } 8156940Ssam 81626312Skarels /* 81726312Skarels * dmflopen -- open the line printer port on a dmf32 81821955Sbloom */ 81926312Skarels /* ARGSUSED */ 82026312Skarels dmflopen(dev, flag) 82126312Skarels dev_t dev; 82226312Skarels int flag; 82321955Sbloom { 82421955Sbloom register int dmf; 82521955Sbloom register struct dmfl_softc *sc; 82621955Sbloom register struct uba_device *ui; 82721955Sbloom register struct dmfdevice *addr; 82821955Sbloom 82926312Skarels dmf = DMFL_UNIT(dev); 83026312Skarels if (((sc= &dmfl_softc[dmf])->dmfl_state & OPEN) || 83121955Sbloom ((ui=dmfinfo[dmf]) == 0) || ui->ui_alive == 0) 83221955Sbloom return(ENXIO); 83321955Sbloom addr = (struct dmfdevice *)ui->ui_addr; 83426312Skarels if ((addr->dmfl[0] & DMFL_OFFLINE)) { 83521955Sbloom /*printf("dmf: line printer offline/jammed\n");*/ 83626312Skarels return (EIO); 83721955Sbloom } 83826312Skarels if ((addr->dmfl[0] & DMFL_CONV)) { 83921955Sbloom printf("dmf:line printer disconnected\n"); 84026312Skarels return (EIO); 84121955Sbloom } 84221955Sbloom 84321955Sbloom addr->dmfl[0] = 0; 84421955Sbloom sc->dmfl_state |= OPEN; 84526312Skarels return (0); 84621955Sbloom } 84721955Sbloom 84826312Skarels /* ARGSUSED */ 84926312Skarels dmflclose(dev, flag) 85026312Skarels dev_t dev; 85126312Skarels int flag; 85221955Sbloom { 85321955Sbloom register int dmf= DMFL_UNIT(dev); 85421955Sbloom register struct dmfl_softc *sc = &dmfl_softc[dmf]; 85521955Sbloom 856*26366Skarels (void)dmflout(dev, "\f", 1); 85721955Sbloom sc->dmfl_state = 0; 85826312Skarels if (sc->dmfl_info != 0) 859*26366Skarels ubarelse((int)dmfinfo[dmf]->ui_ubanum, 86021955Sbloom &(sc->dmfl_info)); 86121955Sbloom 86226312Skarels ((struct dmfdevice *)(dmfinfo[dmf]->ui_addr))->dmfl[0] = 0; 86321955Sbloom } 86421955Sbloom 86526312Skarels dmflwrite(dev, uio) 86626312Skarels dev_t dev; 86726312Skarels struct uio *uio; 86821955Sbloom { 869*26366Skarels register int n; 87021955Sbloom register int error; 87121955Sbloom register struct dmfl_softc *sc; 87221955Sbloom 87321955Sbloom sc = &dmfl_softc[DMFL_UNIT(dev)]; 87426312Skarels if (sc->dmfl_state&ERROR) 87526312Skarels return(EIO); 876*26366Skarels while (n = MIN(DMFL_BUFSIZ, (unsigned)uio->uio_resid)) { 87726312Skarels if (error = uiomove(&sc->dmfl_buf[0], (int)n, UIO_WRITE, uio)) { 87821955Sbloom printf("uio move error\n"); 87926312Skarels return (error); 88021955Sbloom } 88126312Skarels if (error = dmflout(dev, &sc->dmfl_buf[0], n)) 88226312Skarels return (error); 88321955Sbloom } 88426312Skarels return (0); 88521955Sbloom } 88621955Sbloom 88721955Sbloom 88826312Skarels /* 88926312Skarels * dmflout -- start io operation to dmf line printer 89021955Sbloom * cp is addr of buf of n chars to be sent. 89121955Sbloom * 89221955Sbloom * -- dmf will be put in formatted output mode, this will 89321955Sbloom * be selectable from an ioctl if the 89421955Sbloom * need ever arises. 89521955Sbloom */ 89626312Skarels dmflout(dev, cp, n) 89726312Skarels dev_t dev; 89826312Skarels char *cp; 89926312Skarels int n; 90021955Sbloom { 90121955Sbloom register struct dmfl_softc *sc; 90221955Sbloom register int dmf; 90321955Sbloom register struct uba_device *ui; 90421955Sbloom register struct dmfdevice *d; 905*26366Skarels int i; 90621955Sbloom 90726312Skarels dmf = DMFL_UNIT(dev); 90826312Skarels sc = &dmfl_softc[dmf]; 90926312Skarels if (sc->dmfl_state & ERROR) 91026312Skarels return (EIO); 91126312Skarels ui = dmfinfo[dmf]; 91226312Skarels /* 91326312Skarels * allocate unibus resources, will be released when io 91426312Skarels * operation is done. 91521955Sbloom */ 916*26366Skarels sc->dmfl_info = uballoc(ui->ui_ubanum,cp,n,0); 91726312Skarels d = (struct dmfdevice *)ui->ui_addr; 91826312Skarels d->dmfl[0] = (2<<8) | DMFL_FORMAT; /* indir reg 2 */ 91921955Sbloom /* indir reg auto increments on r/w */ 92021955Sbloom /* SO DON'T CHANGE THE ORDER OF THIS CODE */ 92126312Skarels d->dmfl[1] = 0; /* prefix chars & num */ 92226312Skarels d->dmfl[1] = 0; /* suffix chars & num */ 923*26366Skarels d->dmfl[1] = sc->dmfl_info; /* dma lo 16 bits addr */ 92421955Sbloom 92521955Sbloom /* NOT DOCUMENTED !! */ 92621955Sbloom d->dmfl[1] = -n; /* number of chars */ 92721955Sbloom /* ----------^-------- */ 92821955Sbloom 929*26366Skarels d->dmfl[1] = ((sc->dmfl_info>>16)&3) /* dma hi 2 bits addr */ 93021955Sbloom | (1<<8) /* auto cr insert */ 93121955Sbloom | (1<<9) /* use real ff */ 93221955Sbloom | (1<<15); /* no u/l conversion */ 93321955Sbloom d->dmfl[1] = sc->dmfl_lines /* lines per page */ 93421955Sbloom | (sc->dmfl_cols<<8); /* carriage width */ 93521955Sbloom sc->dmfl_state |= ASLP; 93626312Skarels i = spltty(); 93721955Sbloom d->dmfl[0] |= DMFL_PEN|DMFL_IE; 93826312Skarels while (sc->dmfl_state & ASLP) { 93926312Skarels sleep(&sc->dmfl_buf[0], (PZERO+8)); 94026312Skarels while (sc->dmfl_state & ERROR) { 941*26366Skarels timeout(dmflint, (caddr_t)dmf, 10*hz); 942*26366Skarels sleep((caddr_t)&sc->dmfl_state, (PZERO+8)); 94321955Sbloom } 94426312Skarels /*if (sc->dmfl_state&ERROR) return (EIO);*/ 94521955Sbloom } 94621955Sbloom splx(i); 94726312Skarels return (0); 94821955Sbloom } 94926312Skarels 95026312Skarels /* 95126312Skarels * dmflint -- handle an interrupt from the line printer part of the dmf32 95221955Sbloom */ 95321955Sbloom dmflint(dmf) 95426312Skarels int dmf; 95521955Sbloom { 95621955Sbloom register struct uba_device *ui; 95721955Sbloom register struct dmfl_softc *sc; 95821955Sbloom register struct dmfdevice *d; 95921955Sbloom 96026312Skarels ui = dmfinfo[dmf]; 96126312Skarels sc = &dmfl_softc[dmf]; 96226312Skarels d = (struct dmfdevice *)ui->ui_addr; 96321955Sbloom 96421955Sbloom d->dmfl[0] &= ~DMFL_IE; 96521955Sbloom 96626312Skarels if (sc->dmfl_state & ERROR) { 96721955Sbloom printf("dmfl: intr while in error state \n"); 96826312Skarels if ((d->dmfl[0]&DMFL_OFFLINE) == 0) 96921955Sbloom sc->dmfl_state &= ~ERROR; 970*26366Skarels wakeup((caddr_t)&sc->dmfl_state); 97121955Sbloom return; 97221955Sbloom } 97326312Skarels if (d->dmfl[0] & DMFL_DMAERR) 97421955Sbloom printf("dmf:NXM\n"); 97526312Skarels if (d->dmfl[0] & DMFL_OFFLINE) { 97621955Sbloom printf("dmf:printer error\n"); 97721955Sbloom sc->dmfl_state |= ERROR; 97821955Sbloom } 97926312Skarels if (d->dmfl[0] & DMFL_PDONE) { 98021955Sbloom #ifdef notdef 98126312Skarels printf("bytes= %d\n", d->dmfl[1]); 98226312Skarels printf("lines= %d\n", d->dmfl[1]); 98321955Sbloom #endif 98421955Sbloom } 98521955Sbloom sc->dmfl_state &= ~ASLP; 986*26366Skarels wakeup((caddr_t)&sc->dmfl_buf[0]); 98726312Skarels if (sc->dmfl_info != 0) 98826312Skarels ubarelse(ui->ui_ubanum, &sc->dmfl_info); 98921955Sbloom sc->dmfl_info = 0; 99021955Sbloom } 99121955Sbloom 9926940Ssam /* stubs for interrupt routines for devices not yet supported */ 9936940Ssam 99426312Skarels dmfsrint() 99526312Skarels { 99626312Skarels printf("dmfsrint\n"); 99726312Skarels } 9986940Ssam 99926312Skarels dmfsxint() 100026312Skarels { 100126312Skarels printf("dmfsxint\n"); 100226312Skarels } 10036940Ssam 100426312Skarels dmfdaint() 100526312Skarels { 100626312Skarels printf("dmfdaint\n"); 100726312Skarels } 10086940Ssam 100926312Skarels dmfdbint() 101026312Skarels { 101126312Skarels printf("dmfdbint\n"); 101226312Skarels } 10136940Ssam #endif 1014