xref: /csrg-svn/sys/vax/uba/vp.c (revision 8494)
1*8494Sroot /*	vp.c	4.20	82/10/10	*/
244Sbill 
31939Swnj #include "vp.h"
41565Sbill #if NVP > 0
51565Sbill /*
61565Sbill  * Versatec matrix printer/plotter
71565Sbill  * dma interface driver
83439Swnj  *
93439Swnj  * SETUP NOTES:
103439Swnj  *	Set up both print and plot interrupts to go through the same vector
113439Swnj  *	Give the address of the plcsr register in the config specification
121565Sbill  */
1344Sbill #include "../h/param.h"
1444Sbill #include "../h/dir.h"
1544Sbill #include "../h/user.h"
1644Sbill #include "../h/buf.h"
1744Sbill #include "../h/systm.h"
1844Sbill #include "../h/map.h"
1944Sbill #include "../h/pte.h"
203184Swnj #include "../h/vcmd.h"
217737Sroot #include "../h/uio.h"
2244Sbill 
238484Sroot #include "../vaxuba/ubavar.h"
248484Sroot #include "../vaxuba/ubareg.h"
258484Sroot 
2644Sbill unsigned minvpph();
2744Sbill 
2844Sbill #define	VPPRI	(PZERO-1)
2944Sbill 
303184Swnj struct	vpdevice {
3144Sbill 	short	plbcr;
321903Swnj 	short	pbxaddr;
3344Sbill 	short	prbcr;
343184Swnj 	u_short pbaddr;
3544Sbill 	short	plcsr;
3644Sbill 	short	plbuf;
3744Sbill 	short	prcsr;
383184Swnj 	u_short prbuf;
3944Sbill };
4044Sbill 
413184Swnj #define	VP_ERROR	0100000
423184Swnj #define	VP_DTCINTR	0040000
433184Swnj #define	VP_DMAACT	0020000
443184Swnj #define	VP_READY	0000200
453184Swnj #define	VP_IENABLE	0000100
463184Swnj #define	VP_TERMCOM	0000040
473184Swnj #define	VP_FFCOM	0000020
483184Swnj #define	VP_EOTCOM	0000010
493184Swnj #define	VP_CLRCOM	0000004
503184Swnj #define	VP_RESET	0000002
513184Swnj #define	VP_SPP		0000001
5244Sbill 
533184Swnj struct vp_softc {
543184Swnj 	int	sc_state;
553184Swnj 	int	sc_count;
563184Swnj 	int	sc_bufp;
573184Swnj 	struct	buf *sc_bp;
583184Swnj 	int	sc_ubinfo;
593184Swnj } vp_softc[NVP];
6044Sbill 
613184Swnj /* sc_state bits */
623184Swnj #define	VPSC_BUSY	0001000
633184Swnj #define	VPSC_MODE	0000700
643184Swnj #define	VPSC_SPP	0000400
653184Swnj #define	VPSC_PLOT	0000200
663184Swnj #define	VPSC_PRINT	0000100
673184Swnj #define	VPSC_CMNDS	0000076
683184Swnj #define	VPSC_OPEN	0000001
6944Sbill 
703184Swnj struct	uba_device *vpdinfo[NVP];
7144Sbill 
723184Swnj #define	VPUNIT(dev)	(minor(dev))
733184Swnj 
743184Swnj struct	buf rvpbuf[NVP];
753184Swnj 
763184Swnj int	vpprobe(), vpattach();
773184Swnj struct	uba_device *vpdinfo[NVP];
783184Swnj u_short	vpstd[] = { 0777500, 0 };
793184Swnj struct	uba_driver vpdriver =
803184Swnj     { vpprobe, 0, vpattach, 0, vpstd, "vp", vpdinfo };
813184Swnj 
823184Swnj vpprobe(reg)
833184Swnj 	caddr_t reg;
8444Sbill {
853184Swnj 	register int br, cvec;		/* value-result */
863184Swnj 	register struct vpdevice *vpaddr = (struct vpdevice *)(reg-010);
8744Sbill 
884942Swnj #ifdef lint
894942Swnj 	br = 0; cvec = br; br = cvec;
904942Swnj 	vpintr(0);
914942Swnj #endif
923184Swnj 	vpaddr->prcsr = VP_IENABLE|VP_DTCINTR;
933184Swnj 	vpaddr->pbaddr = 0;
943184Swnj 	vpaddr->pbxaddr = 0;
953439Swnj 	vpaddr->prbcr = 1;
963184Swnj 	DELAY(10000);
973184Swnj 	vpaddr->prcsr = 0;
986859Ssam #if ERNIE || CAD || UCBVAX
993439Swnj 	/* UNTIL REWIRED, GET INTERRUPT AT 200 BUT WANT 174 */
1003439Swnj 	if (cvec == 0200) {
1013439Swnj 		printf("vp reset vec from 200 to 174\n");
1023439Swnj 		cvec = 0174;
1033439Swnj 	}
1043439Swnj #endif
1057408Skre 	return (sizeof (struct vpdevice));
1063184Swnj }
1073184Swnj 
1083184Swnj /*ARGSUSED*/
1093184Swnj vpattach(ui)
1103184Swnj 	struct uba_device *ui;
1113184Swnj {
1123184Swnj 
1133184Swnj 	ui->ui_addr -= 010;
1143184Swnj 	ui->ui_physaddr -= 010;
1153184Swnj }
1163184Swnj 
1173184Swnj vpopen(dev)
1183184Swnj 	dev_t dev;
1193184Swnj {
1203184Swnj 	register struct vp_softc *sc;
1213184Swnj 	register struct vpdevice *vpaddr;
1223184Swnj 	register struct uba_device *ui;
1233184Swnj 
1243184Swnj 	if (VPUNIT(dev) >= NVP ||
1253184Swnj 	    ((sc = &vp_softc[minor(dev)])->sc_state&VPSC_OPEN) ||
1263184Swnj 	    (ui = vpdinfo[VPUNIT(dev)]) == 0 || ui->ui_alive == 0) {
12744Sbill 		u.u_error = ENXIO;
12844Sbill 		return;
12944Sbill 	}
1303184Swnj 	vpaddr = (struct vpdevice *)ui->ui_addr;
1313184Swnj 	sc->sc_state = VPSC_OPEN|VPSC_PRINT | VP_CLRCOM|VP_RESET;
1323184Swnj 	sc->sc_count = 0;
1333184Swnj 	vpaddr->prcsr = VP_IENABLE|VP_DTCINTR;
1343184Swnj 	vptimo(dev);
1353184Swnj 	while (sc->sc_state & VPSC_CMNDS) {
136134Sbill 		(void) spl4();
1373184Swnj 		if (vpwait(dev)) {
1383184Swnj 			vpclose(dev);
13944Sbill 			u.u_error = EIO;
14044Sbill 			return;
14144Sbill 		}
1423184Swnj 		vpstart(dev);
143134Sbill 		(void) spl0();
14444Sbill 	}
14544Sbill }
14644Sbill 
14744Sbill vpstrategy(bp)
14844Sbill 	register struct buf *bp;
14944Sbill {
15044Sbill 	register int e;
1513184Swnj 	register struct vp_softc *sc = &vp_softc[VPUNIT(bp->b_dev)];
1523184Swnj 	register struct uba_device *ui = vpdinfo[VPUNIT(bp->b_dev)];
1533184Swnj 	register struct vpdevice *vpaddr = (struct vpdevice *)ui->ui_addr;
15444Sbill 
155134Sbill 	(void) spl4();
1563184Swnj 	while (sc->sc_state & VPSC_BUSY)
1573184Swnj 		sleep((caddr_t)sc, VPPRI);
1583184Swnj 	sc->sc_state |= VPSC_BUSY;
1593184Swnj 	sc->sc_bp = bp;
1603184Swnj 	sc->sc_ubinfo = ubasetup(ui->ui_ubanum, bp, UBA_NEEDBDP);
1613184Swnj 	if (e = vpwait(bp->b_dev))
16244Sbill 		goto brkout;
1633184Swnj 	sc->sc_count = bp->b_bcount;
1643184Swnj 	vpstart(bp->b_dev);
1653184Swnj 	while (((sc->sc_state&VPSC_PLOT) ? vpaddr->plcsr : vpaddr->prcsr) & VP_DMAACT)
1663184Swnj 		sleep((caddr_t)sc, VPPRI);
1673184Swnj 	sc->sc_count = 0;
1683184Swnj 	if ((sc->sc_state&VPSC_MODE) == VPSC_SPP)
1693184Swnj 		sc->sc_state = (sc->sc_state &~ VPSC_MODE) | VPSC_PLOT;
170134Sbill 	(void) spl0();
17144Sbill brkout:
1723184Swnj 	ubarelse(ui->ui_ubanum, &sc->sc_ubinfo);
1733184Swnj 	sc->sc_state &= ~VPSC_BUSY;
1743184Swnj 	sc->sc_bp = 0;
175*8494Sroot 	if (e)
176*8494Sroot 		bp->b_flags |= B_ERROR;
17744Sbill 	iodone(bp);
1783184Swnj 	wakeup((caddr_t)sc);
17944Sbill }
18044Sbill 
18144Sbill int	vpblock = 16384;
18244Sbill 
18344Sbill unsigned
18444Sbill minvpph(bp)
1853184Swnj 	struct buf *bp;
18644Sbill {
18744Sbill 
18844Sbill 	if (bp->b_bcount > vpblock)
18944Sbill 		bp->b_bcount = vpblock;
19044Sbill }
19144Sbill 
19244Sbill /*ARGSUSED*/
1938168Sroot vpwrite(dev, uio)
1943184Swnj 	dev_t dev;
1958168Sroot 	struct uio *uio;
19644Sbill {
19744Sbill 
1987848Sroot 	if (VPUNIT(dev) >= NVP)
1998168Sroot 		return (ENXIO);
2008168Sroot 	return (physio(vpstrategy, &rvpbuf[VPUNIT(dev)], dev, B_WRITE,
2018168Sroot 		    minvpph, uio));
20244Sbill }
20344Sbill 
2043184Swnj vpwait(dev)
2053184Swnj 	dev_t dev;
20644Sbill {
2073184Swnj 	register struct vpdevice *vpaddr =
2083184Swnj 	    (struct vpdevice *)vpdinfo[VPUNIT(dev)]->ui_addr;
2093184Swnj 	register struct vp_softc *sc = &vp_softc[VPUNIT(dev)];
2103184Swnj 	register int e;
21144Sbill 
2123184Swnj 	for (;;) {
2133184Swnj 		e = (sc->sc_state & VPSC_PLOT) ? vpaddr->plcsr : vpaddr->prcsr;
2143184Swnj 		if (e & (VP_READY|VP_ERROR))
2153184Swnj 			break;
2163184Swnj 		sleep((caddr_t)sc, VPPRI);
2173184Swnj 	}
218*8494Sroot 	/* I WISH I COULD TELL WHETHER AN ERROR INDICATED AN NPR TIMEOUT */
2193184Swnj 	return (e & VP_ERROR);
22044Sbill }
22144Sbill 
2223184Swnj vpstart(dev)
2233184Swnj 	dev_t;
22444Sbill {
2253184Swnj 	register struct vp_softc *sc = &vp_softc[VPUNIT(dev)];
2263184Swnj 	register struct vpdevice *vpaddr =
2273184Swnj 	    (struct vpdevice *)vpdinfo[VPUNIT(dev)]->ui_addr;
2283184Swnj 	short bit;
22944Sbill 
2303184Swnj 	if (sc->sc_count) {
2313184Swnj 		vpaddr->pbaddr = sc->sc_ubinfo;
2323184Swnj 		vpaddr->pbxaddr = (sc->sc_ubinfo>>12)&0x30;
2333184Swnj 		if (sc->sc_state & (VPSC_PRINT|VPSC_SPP))
2343184Swnj 			vpaddr->prbcr = sc->sc_count;
23544Sbill 		else
2363184Swnj 			vpaddr->plbcr = sc->sc_count;
23744Sbill 		return;
23844Sbill 	}
23944Sbill 	for (bit = 1; bit != 0; bit <<= 1)
2403184Swnj 		if (sc->sc_state&bit&VPSC_CMNDS) {
2413184Swnj 			vpaddr->plcsr |= bit;
2423184Swnj 			sc->sc_state &= ~bit;
24344Sbill 			return;
24444Sbill 		}
24544Sbill }
24644Sbill 
24744Sbill /*ARGSUSED*/
24844Sbill vpioctl(dev, cmd, addr, flag)
2493184Swnj 	dev_t dev;
2503184Swnj 	int cmd;
25144Sbill 	register caddr_t addr;
2523184Swnj 	int flag;
25344Sbill {
25444Sbill 	register int m;
2553184Swnj 	register struct vp_softc *sc = &vp_softc[VPUNIT(dev)];
2563184Swnj 	register struct vpdevice *vpaddr =
2573184Swnj 	    (struct vpdevice *)vpdinfo[VPUNIT(dev)]->ui_addr;
25844Sbill 
25944Sbill 	switch (cmd) {
26044Sbill 
2613184Swnj 	case VGETSTATE:
2623184Swnj 		(void) suword(addr, sc->sc_state);
26344Sbill 		return;
26444Sbill 
2653184Swnj 	case VSETSTATE:
26644Sbill 		m = fuword(addr);
26744Sbill 		if (m == -1) {
26844Sbill 			u.u_error = EFAULT;
26944Sbill 			return;
27044Sbill 		}
2713184Swnj 		sc->sc_state =
2723184Swnj 		    (sc->sc_state & ~VPSC_MODE) | (m&(VPSC_MODE|VPSC_CMNDS));
27344Sbill 		break;
27444Sbill 
27544Sbill 	default:
27644Sbill 		u.u_error = ENOTTY;
27744Sbill 		return;
27844Sbill 	}
279134Sbill 	(void) spl4();
2803184Swnj 	(void) vpwait(dev);
2813184Swnj 	if (sc->sc_state&VPSC_SPP)
2823184Swnj 		vpaddr->plcsr |= VP_SPP;
28344Sbill 	else
2843184Swnj 		vpaddr->plcsr &= ~VP_SPP;
2853184Swnj 	sc->sc_count = 0;
2863184Swnj 	while (sc->sc_state & VPSC_CMNDS) {
2873184Swnj 		(void) vpwait(dev);
2883184Swnj 		vpstart(dev);
28944Sbill 	}
290134Sbill 	(void) spl0();
29144Sbill }
29244Sbill 
2933184Swnj vptimo(dev)
2943184Swnj 	dev_t dev;
29544Sbill {
2963184Swnj 	register struct vp_softc *sc = &vp_softc[VPUNIT(dev)];
29744Sbill 
2983184Swnj 	if (sc->sc_state&VPSC_OPEN)
2993184Swnj 		timeout(vptimo, (caddr_t)dev, hz/10);
3003184Swnj 	vpintr(dev);
30144Sbill }
30244Sbill 
30344Sbill /*ARGSUSED*/
30444Sbill vpintr(dev)
3053184Swnj 	dev_t dev;
30644Sbill {
3073184Swnj 	register struct vp_softc *sc = &vp_softc[VPUNIT(dev)];
30844Sbill 
3093184Swnj 	wakeup((caddr_t)sc);
31044Sbill }
31144Sbill 
3123184Swnj vpclose(dev)
3133184Swnj 	dev_t dev;
31444Sbill {
3153184Swnj 	register struct vp_softc *sc = &vp_softc[VPUNIT(dev)];
3163184Swnj 	register struct vpdevice *vpaddr =
3173184Swnj 	    (struct vpdevice *)vpdinfo[VPUNIT(dev)]->ui_addr;
31844Sbill 
3193184Swnj 	sc->sc_state = 0;
3203184Swnj 	sc->sc_count = 0;
3213184Swnj 	vpaddr->plcsr = 0;
32244Sbill }
323288Sbill 
3243184Swnj vpreset(uban)
3253184Swnj 	int uban;
326288Sbill {
3273184Swnj 	register int vp11;
3283184Swnj 	register struct uba_device *ui;
3293184Swnj 	register struct vp_softc *sc = vp_softc;
3303184Swnj 	register struct vpdevice *vpaddr;
331288Sbill 
3323184Swnj 	for (vp11 = 0; vp11 < NVP; vp11++, sc++) {
3333184Swnj 		if ((ui = vpdinfo[vp11]) == 0 || ui->ui_alive == 0 ||
3343184Swnj 		    ui->ui_ubanum != uban || (sc->sc_state&VPSC_OPEN) == 0)
3353184Swnj 			continue;
3363184Swnj 		printf(" vp%d", vp11);
3373184Swnj 		vpaddr = (struct vpdevice *)ui->ui_addr;
3383184Swnj 		vpaddr->prcsr = VP_IENABLE|VP_DTCINTR;
3393184Swnj 		if ((sc->sc_state & VPSC_BUSY) == 0)
3403184Swnj 			continue;
3413184Swnj 		if (sc->sc_ubinfo) {
3423184Swnj 			printf("<%d>", (sc->sc_ubinfo>>28)&0xf);
3433184Swnj 			ubarelse(ui->ui_ubanum, &sc->sc_ubinfo);
3443184Swnj 		}
3453184Swnj 		sc->sc_count = sc->sc_bp->b_bcount;
3463184Swnj 		vpstart(sc->sc_bp->b_dev);
347288Sbill 	}
348288Sbill }
3496432Ssam 
3506432Ssam vpselect()
3516432Ssam {
3526432Ssam 	return (1);
3536432Ssam }
3541565Sbill #endif
355