|
|
1.1 ! root 1: /* ova.c 4.23 90/02/17 */ ! 2: ! 3: #include "va.h" ! 4: #if NVA > 0 ! 5: /* ! 6: * Varian printer plotter ! 7: */ ! 8: #include "../sys/param.h" ! 9: #include "../sys/user.h" ! 10: #include "../sys/buf.h" ! 11: #include "../sys/systm.h" ! 12: #include "../sys/map.h" ! 13: #include "../sys/pte.h" ! 14: #include "../sys/vcmd.h" ! 15: #include "../sys/uio.h" ! 16: ! 17: #include "../vaxuba/ubareg.h" ! 18: #include "../vaxuba/ubavar.h" ! 19: ! 20: unsigned minvaph(); ! 21: ! 22: #define VAPRI (PZERO-1) ! 23: ! 24: struct vadevice { ! 25: u_short vaba; /* buffer address */ ! 26: short vawc; /* word count (2's complement) */ ! 27: union { ! 28: short Vacsw; /* control status as word */ ! 29: struct { /* control status as bytes */ ! 30: char Vacsl; ! 31: char Vacsh; ! 32: } vacsr; ! 33: } vacs; ! 34: short vadata; /* programmed i/o data buffer */ ! 35: }; ! 36: ! 37: #define vacsw vacs.Vacsw ! 38: #define vacsh vacs.vacsr.Vacsh ! 39: #define vacsl vacs.vacsr.Vacsl ! 40: ! 41: /* vacsw bits */ ! 42: #define VA_ERROR 0100000 /* some error has occurred */ ! 43: #define VA_NPRTIMO 0001000 /* DMA timeout error */ ! 44: #define VA_NOTREADY 0000400 /* something besides NPRTIMO */ ! 45: #define VA_DONE 0000200 ! 46: #define VA_IENABLE 0000100 /* interrupt enable */ ! 47: #define VA_DMAGO 0000010 /* DMA go bit */ ! 48: #define VA_SUPPLIESLOW 0000004 ! 49: #define VA_BOTOFFORM 0000002 ! 50: #define VA_BYTEREVERSE 0000001 /* reverse byte order in words */ ! 51: ! 52: /* vacsh command bytes */ ! 53: #define VAPLOT 0000340 ! 54: #define VAPRINT 0000100 ! 55: #define VAPRINTPLOT 0000160 ! 56: #define VAAUTOSTEP 0000244 ! 57: #define VANOAUTOSTEP 0000045 ! 58: #define VAFORMFEED 0000263 ! 59: #define VASLEW 0000265 ! 60: #define VASTEP 0000064 ! 61: ! 62: struct va_softc { ! 63: char sc_openf; ! 64: char sc_busy; ! 65: int sc_state; ! 66: int sc_wc; ! 67: struct buf *sc_bp; ! 68: int sc_ubinfo; ! 69: } va_softc[NVA]; ! 70: ! 71: #define VAUNIT(dev) (minor(dev)) ! 72: ! 73: struct buf rvabuf[NVA]; ! 74: ! 75: int vaprobe(), vaattach(); ! 76: struct uba_device *vadinfo[NVA]; ! 77: u_short vastd[] = { 0764000, 0 }; ! 78: struct uba_driver vadriver = ! 79: { vaprobe, 0, vaattach, 0, vastd, "va", vadinfo }; ! 80: ! 81: vaprobe(reg) ! 82: caddr_t reg; ! 83: { ! 84: register int br, cvec; /* value-result */ ! 85: register struct vadevice *vaaddr = (struct vadevice *)reg; ! 86: ! 87: #ifdef lint ! 88: br = 0; cvec = br; br = cvec; ! 89: vaintr(0); ! 90: #endif ! 91: vaaddr->vacsl = VA_IENABLE; ! 92: vaaddr->vaba = 0; ! 93: vaaddr->vacsh = VAPLOT; ! 94: #ifndef VARIANGOBIT ! 95: vaaddr->vacsl = 0; ! 96: #endif ! 97: vaaddr->vawc = -1; ! 98: DELAY(100000); ! 99: vaaddr->vacsl = 0; ! 100: return (sizeof (struct vadevice)); ! 101: } ! 102: ! 103: /*ARGSUSED*/ ! 104: vaattach(ui) ! 105: struct uba_device *ui; ! 106: { ! 107: ! 108: } ! 109: ! 110: vaopen(dev) ! 111: dev_t dev; ! 112: { ! 113: register struct va_softc *sc; ! 114: register struct vadevice *vaaddr; ! 115: register struct uba_device *ui; ! 116: int error; ! 117: ! 118: if (VAUNIT(dev) >= NVA || (sc = &va_softc[minor(dev)])->sc_openf || ! 119: (ui = vadinfo[VAUNIT(dev)]) == 0 || ui->ui_alive == 0) ! 120: return (ENXIO); ! 121: vaaddr = (struct vadevice *)ui->ui_addr; ! 122: sc->sc_openf = 1; ! 123: vaaddr->vawc = 0; ! 124: sc->sc_wc = 0; ! 125: sc->sc_state = 0; ! 126: vaaddr->vacsl = VA_IENABLE; ! 127: vatimo(dev); ! 128: error = vacmd(dev, VPRINT); ! 129: if (error) ! 130: vaclose(dev); ! 131: return (error); ! 132: } ! 133: ! 134: vastrategy(bp) ! 135: register struct buf *bp; ! 136: { ! 137: register int e; ! 138: register struct va_softc *sc = &va_softc[VAUNIT(bp->b_dev)]; ! 139: register struct uba_device *ui = vadinfo[VAUNIT(bp->b_dev)]; ! 140: register struct vadevice *vaaddr = (struct vadevice *)ui->ui_addr; ! 141: ! 142: (void) spl4(); ! 143: while (sc->sc_busy) ! 144: sleep((caddr_t)sc, VAPRI); ! 145: sc->sc_busy = 1; ! 146: sc->sc_bp = bp; ! 147: sc->sc_ubinfo = ubasetup(ui->ui_ubanum, bp, UBA_NEEDBDP); ! 148: if (e = vawait(bp->b_dev)) ! 149: goto brkout; ! 150: sc->sc_wc = -(bp->b_bcount/2); ! 151: vastart(bp->b_dev); ! 152: e = vawait(bp->b_dev); ! 153: sc->sc_wc = 0; ! 154: if (sc->sc_state & VPRINTPLOT) { ! 155: sc->sc_state = (sc->sc_state & ~VPRINTPLOT) | VPLOT; ! 156: vaaddr->vacsh = VAAUTOSTEP; ! 157: e |= vawait(bp->b_dev); ! 158: } ! 159: (void) spl0(); ! 160: brkout: ! 161: ubarelse(ui->ui_ubanum, &sc->sc_ubinfo); ! 162: sc->sc_bp = 0; ! 163: sc->sc_busy = 0; ! 164: if (e) ! 165: bp->b_flags |= B_ERROR; ! 166: iodone(bp); ! 167: wakeup((caddr_t)sc); ! 168: } ! 169: ! 170: int vablock = 16384; ! 171: ! 172: unsigned ! 173: minvaph(bp) ! 174: struct buf *bp; ! 175: { ! 176: ! 177: if (bp->b_bcount > vablock) ! 178: bp->b_bcount = vablock; ! 179: } ! 180: ! 181: /*ARGSUSED*/ ! 182: vawrite(dev, uio) ! 183: dev_t dev; ! 184: struct uio *uio; ! 185: { ! 186: ! 187: if (VAUNIT(dev) > NVA) ! 188: return (ENXIO); ! 189: return (physio(vastrategy, &rvabuf[VAUNIT(dev)], dev, B_WRITE, ! 190: minvaph, uio)); ! 191: } ! 192: ! 193: vawait(dev) ! 194: dev_t dev; ! 195: { ! 196: register struct vadevice *vaaddr = ! 197: (struct vadevice *)vadinfo[VAUNIT(dev)]->ui_addr; ! 198: register int e; ! 199: ! 200: while (((e = vaaddr->vacsw) & (VA_DONE|VA_ERROR)) == 0) ! 201: sleep((caddr_t)&va_softc[VAUNIT(dev)], VAPRI); ! 202: if (e & VA_NPRTIMO) ! 203: printf("va%d: npr timeout\n", VAUNIT(dev)); ! 204: return (e & VA_ERROR); ! 205: } ! 206: ! 207: vastart(dev) ! 208: dev_t; ! 209: { ! 210: register struct va_softc *sc = &va_softc[VAUNIT(dev)]; ! 211: register struct vadevice *vaaddr = ! 212: (struct vadevice *)vadinfo[VAUNIT(dev)]->ui_addr; ! 213: ! 214: if (sc->sc_wc == 0) ! 215: return; ! 216: vaaddr->vaba = sc->sc_ubinfo; ! 217: #ifndef VARIANGOBIT ! 218: vaaddr->vacsl = (sc->sc_ubinfo >> 12) & 0x30; ! 219: #else ! 220: vaaddr->vacsl = (sc->sc_ubinfo >> 12) & 0x30 | VA_IENABLE | VA_DMAGO; ! 221: #endif ! 222: vaaddr->vawc = sc->sc_wc; ! 223: } ! 224: ! 225: /*ARGSUSED*/ ! 226: vaioctl(dev, cmd, data, flag) ! 227: register caddr_t data; ! 228: { ! 229: register int vcmd; ! 230: register struct va_softc *sc = &va_softc[VAUNIT(dev)]; ! 231: ! 232: switch (cmd) { ! 233: ! 234: case VGETSTATE: ! 235: *(int *)data = sc->sc_state; ! 236: break; ! 237: ! 238: case VSETSTATE: ! 239: return (vacmd(dev, *(int *)data)); ! 240: break; ! 241: ! 242: default: ! 243: return (ENOTTY); ! 244: } ! 245: return (0); ! 246: } ! 247: ! 248: vacmd(dev, vcmd) ! 249: dev_t dev; ! 250: int vcmd; ! 251: { ! 252: register struct va_softc *sc = &va_softc[VAUNIT(dev)]; ! 253: register struct vadevice *vaaddr = ! 254: (struct vadevice *)vadinfo[VAUNIT(dev)]->ui_addr; ! 255: int error = 0; ! 256: ! 257: (void) spl4(); ! 258: (void) vawait(dev); ! 259: switch (vcmd) { ! 260: ! 261: case VPLOT: ! 262: /* Must turn on plot AND autostep modes. */ ! 263: vaaddr->vacsh = VAPLOT; ! 264: if (vawait(dev)) ! 265: error = EIO; ! 266: vaaddr->vacsh = VAAUTOSTEP; ! 267: break; ! 268: ! 269: case VPRINT: ! 270: vaaddr->vacsh = VAPRINT; ! 271: break; ! 272: ! 273: case VPRINTPLOT: ! 274: vaaddr->vacsh = VAPRINTPLOT; ! 275: break; ! 276: } ! 277: sc->sc_state = (sc->sc_state & ~(VPLOT|VPRINT|VPRINTPLOT)) | vcmd; ! 278: if (vawait(dev)) ! 279: error = EIO; ! 280: (void) spl0(); ! 281: return (error); ! 282: } ! 283: ! 284: vatimo(dev) ! 285: dev_t dev; ! 286: { ! 287: register struct va_softc *sc = &va_softc[VAUNIT(dev)]; ! 288: ! 289: if (sc->sc_openf) ! 290: timeout(vatimo, (caddr_t)dev, hz/10); ! 291: vaintr(dev); ! 292: } ! 293: ! 294: /*ARGSUSED*/ ! 295: vaintr(dev) ! 296: dev_t dev; ! 297: { ! 298: register struct va_softc *sc = &va_softc[VAUNIT(dev)]; ! 299: ! 300: wakeup((caddr_t)sc); ! 301: } ! 302: ! 303: vaclose(dev) ! 304: dev_t dev; ! 305: { ! 306: register struct va_softc *sc = &va_softc[VAUNIT(dev)]; ! 307: register struct vadevice *vaaddr = ! 308: (struct vadevice *)vadinfo[VAUNIT(dev)]->ui_addr; ! 309: ! 310: sc->sc_openf = 0; ! 311: sc->sc_busy = 0; ! 312: sc->sc_state = 0; ! 313: sc->sc_ubinfo = 0; ! 314: vaaddr->vacsl = 0; ! 315: } ! 316: ! 317: vareset(uban) ! 318: int uban; ! 319: { ! 320: register int va11; ! 321: register struct uba_device *ui; ! 322: register struct va_softc *sc = va_softc; ! 323: register struct vadevice *vaaddr; ! 324: ! 325: for (va11 = 0; va11 < NVA; va11++, sc++) { ! 326: if ((ui = vadinfo[va11]) == 0 || ui->ui_alive == 0 || ! 327: ui->ui_ubanum != uban || sc->sc_openf == 0) ! 328: continue; ! 329: printf(" va%d", va11); ! 330: vaaddr = (struct vadevice *)ui->ui_addr; ! 331: vaaddr->vacsl = VA_IENABLE; ! 332: if (sc->sc_state & VPLOT) { ! 333: vaaddr->vacsh = VAPLOT; ! 334: DELAY(10000); ! 335: vaaddr->vacsh = VAAUTOSTEP; ! 336: } else if (sc->sc_state & VPRINTPLOT) ! 337: vaaddr->vacsh = VPRINTPLOT; ! 338: else ! 339: vaaddr->vacsh = VAPRINTPLOT; ! 340: DELAY(10000); ! 341: if (sc->sc_busy == 0) ! 342: continue; ! 343: sc->sc_ubinfo = ubasetup(ui->ui_ubanum, sc->sc_bp, UBA_NEEDBDP); ! 344: sc->sc_wc = -(sc->sc_bp->b_bcount/2); ! 345: vastart(sc->sc_bp->b_dev); ! 346: } ! 347: } ! 348: ! 349: vaselect() ! 350: { ! 351: ! 352: return (1); ! 353: } ! 354: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.