1 /* 2 * Copyright (c) 1982 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)ct.c 6.3 (Berkeley) 06/08/85 7 */ 8 9 #include "ct.h" 10 #if NCT > 0 11 /* 12 * GP DR11C driver used for C/A/T 13 * 14 * BUGS: 15 * This driver hasn't been tested in 4.1bsd 16 */ 17 #include "../machine/pte.h" 18 19 #include "param.h" 20 #include "systm.h" 21 #include "tty.h" 22 #include "map.h" 23 #include "buf.h" 24 #include "conf.h" 25 #include "dir.h" 26 #include "user.h" 27 28 #include "ubareg.h" 29 #include "ubavar.h" 30 31 #define PCAT (PZERO+9) 32 #define CATHIWAT 100 33 #define CATLOWAT 30 34 35 struct ct_softc { 36 int sc_openf; 37 struct clist sc_oq; 38 } ct_softc[NCT]; 39 40 struct ctdevice { 41 short ctcsr; 42 short ctbuf; 43 }; 44 45 int ctprobe(), ctattach(), ctintr(); 46 struct uba_device *ctdinfo[NCT]; 47 u_short ctstd[] = { 0 }; 48 struct uba_driver ctdriver = 49 { ctprobe, 0, ctattach, 0, ctstd, "ct", ctdinfo }; 50 51 #define CTUNIT(dev) (minor(dev)) 52 53 ctprobe(reg) 54 caddr_t reg; 55 { 56 register int br, cvec; /* value-result */ 57 register struct ctdevice *ctaddr = (struct ctdevice *)reg; 58 59 #ifdef lint 60 br = 0; cvec = br; br = cvec; 61 ctintr(0); 62 #endif 63 ctaddr->ctcsr = IENABLE; 64 DELAY(10000); 65 ctaddr->ctcsr = 0; 66 return (sizeof (struct ctdevice)); 67 } 68 69 /*ARGSUSED*/ 70 ctattach(ui) 71 register struct uba_device *ui; 72 { 73 74 } 75 76 ctopen(dev) 77 dev_t dev; 78 { 79 register struct ct_softc *sc; 80 register struct uba_device *ui; 81 register struct ctdevice *ctaddr; 82 83 if (CTUNIT(dev) >= NCT || (ui = ctdinfo[CTUNIT(dev)]) == 0 || 84 ui->ui_alive == 0 || (sc = &ct_softc[CTUNIT(dev)])->sc_openf) 85 return (ENXIO); 86 sc->sc_openf = 1; 87 ctaddr->ctcsr |= IENABLE; 88 return (0); 89 } 90 91 ctclose(dev) 92 dev_t dev; 93 { 94 95 ct_softc[CTUNIT(dev)].sc_openf = 0; 96 ctintr(dev); 97 } 98 99 ctwrite(dev, uio) 100 dev_t dev; 101 struct uio *uio; 102 { 103 register struct ct_softc *sc = &ct_softc[CTUNIT(dev)]; 104 register int c; 105 106 while ((c=cupass(uio)) >= 0) { 107 (void) spl5(); 108 while (sc->sc_oq.c_cc > CATHIWAT) 109 sleep((caddr_t)&sc->sc_oq, PCAT); 110 while (putc(c, &sc->sc_oq) < 0) 111 sleep((caddr_t)&lbolt, PCAT); 112 ctintr(dev); 113 (void) spl0(); 114 } 115 } 116 117 ctintr(dev) 118 dev_t dev; 119 { 120 register int c; 121 register struct ct_softc *sc = &ct_softc[CTUNIT(dev)]; 122 register struct ctdevice *ctaddr = 123 (struct ctdevice *)ctdinfo[CTUNIT(dev)]->ui_addr; 124 125 if (ctaddr->ctcsr&DONE) { 126 if ((c = getc(&sc->sc_oq)) >= 0) { 127 ctaddr->ctbuf = c; 128 if (sc->sc_oq.c_cc==0 || sc->sc_oq.c_cc==CATLOWAT) 129 wakeup(&sc->sc_oq); 130 } else { 131 if (sc->sc_openf==0) 132 ctaddr->ctcsr = 0; 133 } 134 } 135 136 } 137 #endif 138