1*23319Smckusick /* 2*23319Smckusick * Copyright (c) 1982 Regents of the University of California. 3*23319Smckusick * All rights reserved. The Berkeley software License Agreement 4*23319Smckusick * specifies the terms and conditions for redistribution. 5*23319Smckusick * 6*23319Smckusick * @(#)ct.c 6.3 (Berkeley) 06/08/85 7*23319Smckusick */ 82621Swnj 93201Swnj #include "ct.h" 102621Swnj #if NCT > 0 112621Swnj /* 122621Swnj * GP DR11C driver used for C/A/T 133936Sbugs * 143936Sbugs * BUGS: 153936Sbugs * This driver hasn't been tested in 4.1bsd 162621Swnj */ 179771Ssam #include "../machine/pte.h" 182621Swnj 1917073Sbloom #include "param.h" 2017073Sbloom #include "systm.h" 2117073Sbloom #include "tty.h" 2217073Sbloom #include "map.h" 2317073Sbloom #include "buf.h" 2417073Sbloom #include "conf.h" 2517073Sbloom #include "dir.h" 2617073Sbloom #include "user.h" 272621Swnj 2817073Sbloom #include "ubareg.h" 2917073Sbloom #include "ubavar.h" 308472Sroot 312621Swnj #define PCAT (PZERO+9) 322621Swnj #define CATHIWAT 100 332621Swnj #define CATLOWAT 30 342621Swnj 353201Swnj struct ct_softc { 363201Swnj int sc_openf; 373201Swnj struct clist sc_oq; 383201Swnj } ct_softc[NCT]; 392621Swnj 403201Swnj struct ctdevice { 413201Swnj short ctcsr; 423201Swnj short ctbuf; 432621Swnj }; 442621Swnj 453201Swnj int ctprobe(), ctattach(), ctintr(); 463201Swnj struct uba_device *ctdinfo[NCT]; 473201Swnj u_short ctstd[] = { 0 }; 483201Swnj struct uba_driver ctdriver = 493201Swnj { ctprobe, 0, ctattach, 0, ctstd, "ct", ctdinfo }; 502621Swnj 513217Swnj #define CTUNIT(dev) (minor(dev)) 523217Swnj 533201Swnj ctprobe(reg) 543201Swnj caddr_t reg; 553201Swnj { 563936Sbugs register int br, cvec; /* value-result */ 573201Swnj register struct ctdevice *ctaddr = (struct ctdevice *)reg; 583201Swnj 594932Swnj #ifdef lint 604932Swnj br = 0; cvec = br; br = cvec; 614932Swnj ctintr(0); 624932Swnj #endif 633201Swnj ctaddr->ctcsr = IENABLE; 643201Swnj DELAY(10000); 653201Swnj ctaddr->ctcsr = 0; 667409Skre return (sizeof (struct ctdevice)); 673201Swnj } 683201Swnj 693217Swnj /*ARGSUSED*/ 703217Swnj ctattach(ui) 713217Swnj register struct uba_device *ui; 723217Swnj { 733217Swnj 743217Swnj } 753217Swnj 762621Swnj ctopen(dev) 773201Swnj dev_t dev; 782621Swnj { 793201Swnj register struct ct_softc *sc; 803201Swnj register struct uba_device *ui; 813201Swnj register struct ctdevice *ctaddr; 823201Swnj 833201Swnj if (CTUNIT(dev) >= NCT || (ui = ctdinfo[CTUNIT(dev)]) == 0 || 848566Sroot ui->ui_alive == 0 || (sc = &ct_softc[CTUNIT(dev)])->sc_openf) 858566Sroot return (ENXIO); 863201Swnj sc->sc_openf = 1; 873201Swnj ctaddr->ctcsr |= IENABLE; 888566Sroot return (0); 892621Swnj } 902621Swnj 913201Swnj ctclose(dev) 923201Swnj dev_t dev; 932621Swnj { 943201Swnj 953201Swnj ct_softc[CTUNIT(dev)].sc_openf = 0; 963201Swnj ctintr(dev); 972621Swnj } 982621Swnj 997831Sroot ctwrite(dev, uio) 1003201Swnj dev_t dev; 1017831Sroot struct uio *uio; 1022621Swnj { 1033201Swnj register struct ct_softc *sc = &ct_softc[CTUNIT(dev)]; 1043201Swnj register int c; 1052621Swnj 1067831Sroot while ((c=cupass(uio)) >= 0) { 1073101Swnj (void) spl5(); 1083201Swnj while (sc->sc_oq.c_cc > CATHIWAT) 1093201Swnj sleep((caddr_t)&sc->sc_oq, PCAT); 1103201Swnj while (putc(c, &sc->sc_oq) < 0) 1112621Swnj sleep((caddr_t)&lbolt, PCAT); 1123201Swnj ctintr(dev); 1133101Swnj (void) spl0(); 1142621Swnj } 1152621Swnj } 1162621Swnj 1173201Swnj ctintr(dev) 1183201Swnj dev_t dev; 1192621Swnj { 1202621Swnj register int c; 1213201Swnj register struct ct_softc *sc = &ct_softc[CTUNIT(dev)]; 1223201Swnj register struct ctdevice *ctaddr = 1233201Swnj (struct ctdevice *)ctdinfo[CTUNIT(dev)]->ui_addr; 1242621Swnj 1253201Swnj if (ctaddr->ctcsr&DONE) { 1263201Swnj if ((c = getc(&sc->sc_oq)) >= 0) { 1273201Swnj ctaddr->ctbuf = c; 1283201Swnj if (sc->sc_oq.c_cc==0 || sc->sc_oq.c_cc==CATLOWAT) 1293201Swnj wakeup(&sc->sc_oq); 1302621Swnj } else { 1313201Swnj if (sc->sc_openf==0) 1323201Swnj ctaddr->ctcsr = 0; 1332621Swnj } 1342621Swnj } 1352621Swnj 1362621Swnj } 1372621Swnj #endif 138