Commit | Line | Data |
---|---|---|
515ce90f | 1 | /* va.c 4.13.1.2 82/11/27 */ |
20cc8b5b | 2 | |
66b4fb09 | 3 | #include "va.h" |
a5cc519e BJ |
4 | #if NVA > 0 |
5 | /* | |
fc4d0a69 | 6 | * Varian printer plotter |
a5cc519e | 7 | */ |
20cc8b5b BJ |
8 | #include "../h/param.h" |
9 | #include "../h/dir.h" | |
10 | #include "../h/user.h" | |
11 | #include "../h/buf.h" | |
12 | #include "../h/systm.h" | |
13 | #include "../h/map.h" | |
14 | #include "../h/pte.h" | |
fc4d0a69 BJ |
15 | #include "../h/ubareg.h" |
16 | #include "../h/ubavar.h" | |
20cc8b5b | 17 | #include "../h/vcmd.h" |
515ce90f | 18 | #include "../h/uio.h" |
20cc8b5b | 19 | |
410d35e9 | 20 | int vadebug = 0; |
915905f4 KM |
21 | #define dprintf if(vadebug)printf |
22 | ||
71357272 | 23 | unsigned minvaph(); |
20cc8b5b BJ |
24 | |
25 | #define VAPRI (PZERO-1) | |
26 | ||
fc4d0a69 BJ |
27 | struct vadevice { |
28 | u_short vaba; /* buffer address */ | |
29 | short vawc; /* word count (2's complement) */ | |
20cc8b5b | 30 | union { |
fc4d0a69 BJ |
31 | short Vacsw; /* control status as word */ |
32 | struct { /* control status as bytes */ | |
71357272 BJ |
33 | char Vacsl; |
34 | char Vacsh; | |
35 | } vacsr; | |
36 | } vacs; | |
fc4d0a69 | 37 | short vadata; /* programmed i/o data buffer */ |
20cc8b5b BJ |
38 | }; |
39 | ||
71357272 BJ |
40 | #define vacsw vacs.Vacsw |
41 | #define vacsh vacs.vacsr.Vacsh | |
42 | #define vacsl vacs.vacsr.Vacsl | |
43 | ||
71357272 | 44 | /* vacsw bits */ |
fc4d0a69 BJ |
45 | #define VA_ERROR 0100000 /* some error has occurred */ |
46 | #define VA_NPRTIMO 0001000 /* DMA timeout error */ | |
47 | #define VA_NOTREADY 0000400 /* something besides NPRTIMO */ | |
48 | #define VA_DONE 0000200 | |
49 | #define VA_IENABLE 0000100 /* interrupt enable */ | |
915905f4 | 50 | #define VA_DMAGO 0000010 /* DMA go bit */ |
515ce90f | 51 | #define VA_DMAGO 0000010 /* DMA go bit */ |
fc4d0a69 BJ |
52 | #define VA_SUPPLIESLOW 0000004 |
53 | #define VA_BOTOFFORM 0000002 | |
54 | #define VA_BYTEREVERSE 0000001 /* reverse byte order in words */ | |
71357272 BJ |
55 | |
56 | /* vacsh command bytes */ | |
fc4d0a69 BJ |
57 | #define VAPLOT 0000340 |
58 | #define VAPRINT 0000100 | |
59 | #define VAPRINTPLOT 0000160 | |
60 | #define VAAUTOSTEP 0000244 | |
61 | #define VANOAUTOSTEP 0000045 | |
62 | #define VAFORMFEED 0000263 | |
63 | #define VASLEW 0000265 | |
64 | #define VASTEP 0000064 | |
65 | ||
66 | struct va_softc { | |
915905f4 KM |
67 | u_char sc_openf; /* exclusive open flag */ |
68 | u_char sc_iostate; /* kind of I/O going on */ | |
69 | #define VAS_IDLE 0 /* no I/O, free */ | |
70 | #define VAS_PIO 1 /* programmed I/O */ | |
71 | #define VAS_DMA 2 /* DMA, block pio */ | |
72 | #define VAS_WANT 4 /* wakeup when iostate changes */ | |
73 | short sc_tocnt; /* time out counter */ | |
74 | short sc_info; /* csw passed from vaintr */ | |
75 | int sc_state; /* print/plot state of device */ | |
fc4d0a69 BJ |
76 | } va_softc[NVA]; |
77 | ||
fc4d0a69 BJ |
78 | #define VAUNIT(dev) (minor(dev)) |
79 | ||
80 | struct buf rvabuf[NVA]; | |
81 | ||
915905f4 | 82 | int vaprobe(), vaslave(), vaattach(), vadgo(); |
fc4d0a69 | 83 | struct uba_device *vadinfo[NVA]; |
915905f4 | 84 | struct uba_ctlr *vaminfo[NVA]; |
410d35e9 | 85 | struct buf vabhdr[NVA]; |
fc4d0a69 BJ |
86 | u_short vastd[] = { 0764000, 0 }; |
87 | struct uba_driver vadriver = | |
915905f4 | 88 | { vaprobe, vaslave, vaattach, vadgo, vastd, "vz", vadinfo, "va", vaminfo }; |
fc4d0a69 BJ |
89 | |
90 | vaprobe(reg) | |
91 | caddr_t reg; | |
92 | { | |
93 | register int br, cvec; /* value-result */ | |
94 | register struct vadevice *vaaddr = (struct vadevice *)reg; | |
95 | ||
915905f4 KM |
96 | #ifdef lint |
97 | br = 0; cvec = br; br = cvec; | |
98 | vaintr(0); | |
99 | #endif | |
877283f6 | 100 | #ifndef UCBVAX |
fc4d0a69 BJ |
101 | vaaddr->vacsl = VA_IENABLE; |
102 | vaaddr->vaba = 0; | |
103 | vaaddr->vacsh = VAPLOT; | |
515ce90f | 104 | #ifndef VARIANGOBIT |
877283f6 | 105 | vaaddr->vacsl = VA_IENABLE|VA_DMAGO; |
fc4d0a69 | 106 | vaaddr->vawc = -1; |
877283f6 | 107 | DELAY(10000); |
fc4d0a69 | 108 | vaaddr->vacsl = 0; |
515ce90f | 109 | return (sizeof (struct vadevice)); |
877283f6 KM |
110 | vaaddr->vawc = 0; |
111 | #else | |
112 | br=0x14; | |
113 | cvec=0170; | |
114 | #endif | |
fc4d0a69 BJ |
115 | } |
116 | ||
915905f4 KM |
117 | /*ARGSUSED*/ |
118 | vaslave(ui, reg) | |
119 | struct uba_device *ui; | |
120 | caddr_t reg; | |
121 | { | |
122 | ||
123 | ui->ui_dk = 0; | |
124 | return (ui->ui_unit <= 0); | |
125 | } | |
126 | ||
fc4d0a69 BJ |
127 | /*ARGSUSED*/ |
128 | vaattach(ui) | |
129 | struct uba_device *ui; | |
130 | { | |
131 | ||
410d35e9 | 132 | ui->ui_mi->um_tab.b_actf = &vabhdr[ui->ui_unit]; |
fc4d0a69 BJ |
133 | } |
134 | ||
135 | vaopen(dev) | |
136 | dev_t dev; | |
20cc8b5b | 137 | { |
fc4d0a69 BJ |
138 | register struct va_softc *sc; |
139 | register struct vadevice *vaaddr; | |
140 | register struct uba_device *ui; | |
915905f4 | 141 | int unit = VAUNIT(dev); |
20cc8b5b | 142 | |
915905f4 KM |
143 | if (unit >= NVA || (sc = &va_softc[unit])->sc_openf || |
144 | (ui = vadinfo[unit]) == 0 || ui->ui_alive == 0) { | |
20cc8b5b BJ |
145 | u.u_error = ENXIO; |
146 | return; | |
147 | } | |
fc4d0a69 BJ |
148 | vaaddr = (struct vadevice *)ui->ui_addr; |
149 | sc->sc_openf = 1; | |
150 | vaaddr->vawc = 0; | |
fc4d0a69 | 151 | sc->sc_state = 0; |
877283f6 | 152 | sc->sc_tocnt = 0; |
915905f4 | 153 | sc->sc_iostate = VAS_IDLE; |
fc4d0a69 BJ |
154 | vaaddr->vacsl = VA_IENABLE; |
155 | vatimo(dev); | |
156 | vacmd(dev, VPRINT); | |
20cc8b5b | 157 | if (u.u_error) |
fc4d0a69 | 158 | vaclose(dev); |
20cc8b5b BJ |
159 | } |
160 | ||
161 | vastrategy(bp) | |
162 | register struct buf *bp; | |
163 | { | |
915905f4 KM |
164 | register struct uba_device *ui; |
165 | register struct uba_ctlr *um; | |
166 | int s; | |
167 | ||
410d35e9 | 168 | dprintf("vastrategy(%x)\n", bp); |
915905f4 KM |
169 | ui = vadinfo[VAUNIT(bp->b_dev)]; |
170 | if (ui == 0 || ui->ui_alive == 0) { | |
171 | bp->b_flags |= B_ERROR; | |
172 | iodone(bp); | |
173 | return; | |
20cc8b5b | 174 | } |
915905f4 KM |
175 | s = spl4(); |
176 | um = ui->ui_mi; | |
410d35e9 KM |
177 | bp->b_actf = NULL; |
178 | if (um->um_tab.b_actf->b_actf == NULL) | |
179 | um->um_tab.b_actf->b_actf = bp; | |
180 | else { | |
181 | printf("bp = 0x%x, um->um_tab.b_actf->b_actf = 0x%x\n", | |
182 | bp, um->um_tab.b_actf->b_actf); | |
183 | panic("vastrategy"); | |
184 | um->um_tab.b_actf->b_actl->b_forw = bp; | |
185 | } | |
186 | um->um_tab.b_actf->b_actl = bp; | |
187 | bp = um->um_tab.b_actf; | |
188 | dprintf("vastrategy: bp=%x actf=%x active=%d\n", | |
189 | bp, bp->b_actf, bp->b_active); | |
915905f4 KM |
190 | if (bp->b_actf && bp->b_active == 0) |
191 | (void) vastart(um); | |
192 | splx(s); | |
20cc8b5b BJ |
193 | } |
194 | ||
195 | int vablock = 16384; | |
196 | ||
197 | unsigned | |
198 | minvaph(bp) | |
fc4d0a69 | 199 | struct buf *bp; |
20cc8b5b | 200 | { |
fc4d0a69 | 201 | |
20cc8b5b BJ |
202 | if (bp->b_bcount > vablock) |
203 | bp->b_bcount = vablock; | |
204 | } | |
205 | ||
206 | /*ARGSUSED*/ | |
515ce90f | 207 | vawrite(dev, uio) |
fc4d0a69 | 208 | dev_t dev; |
515ce90f | 209 | struct uio *uio; |
20cc8b5b | 210 | { |
915905f4 | 211 | |
515ce90f KM |
212 | if (VAUNIT(dev) > NVA) |
213 | u.u_error = ENXIO; | |
214 | else | |
215 | physio(vastrategy, &rvabuf[VAUNIT(dev)], dev, B_WRITE, | |
216 | minvaph, uio); | |
20cc8b5b BJ |
217 | } |
218 | ||
915905f4 KM |
219 | vastart(um) |
220 | register struct uba_ctlr *um; | |
20cc8b5b | 221 | { |
915905f4 KM |
222 | struct buf *bp; |
223 | struct vadevice *vaaddr; | |
224 | register struct va_softc *sc; | |
225 | int unit; | |
20cc8b5b | 226 | |
410d35e9 KM |
227 | dprintf("vastart(%x), bp=%x\n", um, um->um_tab.b_actf->b_actf); |
228 | if ((bp = um->um_tab.b_actf->b_actf) == NULL) | |
915905f4 | 229 | return; |
915905f4 KM |
230 | unit = VAUNIT(bp->b_dev); |
231 | sc = &va_softc[unit]; | |
410d35e9 | 232 | sc->sc_tocnt = 0; |
915905f4 KM |
233 | while (sc->sc_iostate&VAS_PIO) { |
234 | sc->sc_iostate |= VAS_WANT; | |
235 | sleep((caddr_t)&sc->sc_iostate, VAPRI); | |
877283f6 | 236 | } |
915905f4 KM |
237 | sc->sc_iostate |= VAS_DMA; |
238 | vaaddr = (struct vadevice *)um->um_addr; | |
239 | vaaddr->vacsl = 0; | |
240 | vaaddr->vawc = -(bp->b_bcount / 2); | |
241 | um->um_cmd = VA_DMAGO | VA_IENABLE; | |
242 | (void) ubago(vadinfo[unit]); | |
20cc8b5b BJ |
243 | } |
244 | ||
915905f4 KM |
245 | vadgo(um) |
246 | register struct uba_ctlr *um; | |
20cc8b5b | 247 | { |
915905f4 | 248 | register struct vadevice *vaaddr = (struct vadevice *)um->um_addr; |
410d35e9 | 249 | register struct buf *bp; |
915905f4 | 250 | |
410d35e9 KM |
251 | bp = um->um_tab.b_actf; |
252 | va_softc[VAUNIT(bp->b_actf->b_dev)].sc_tocnt = 0; | |
253 | bp->b_active++; | |
915905f4 KM |
254 | vaaddr->vaba = um->um_ubinfo; |
255 | vaaddr->vacsl = ((um->um_ubinfo >> 12) & 0x30) | um->um_cmd; | |
20cc8b5b BJ |
256 | } |
257 | ||
258 | /*ARGSUSED*/ | |
515ce90f KM |
259 | vaioctl(dev, cmd, data, flag) |
260 | register caddr_t data; | |
20cc8b5b BJ |
261 | { |
262 | register int vcmd; | |
fc4d0a69 | 263 | register struct va_softc *sc = &va_softc[VAUNIT(dev)]; |
20cc8b5b BJ |
264 | |
265 | switch (cmd) { | |
266 | ||
267 | case VGETSTATE: | |
515ce90f | 268 | *(int *)data = sc->sc_state; |
20cc8b5b BJ |
269 | return; |
270 | ||
271 | case VSETSTATE: | |
515ce90f | 272 | vacmd(dev, *(int *)data); |
20cc8b5b BJ |
273 | return; |
274 | ||
275 | default: | |
fc4d0a69 | 276 | u.u_error = ENOTTY; |
20cc8b5b BJ |
277 | return; |
278 | } | |
279 | } | |
280 | ||
fc4d0a69 BJ |
281 | vacmd(dev, vcmd) |
282 | dev_t dev; | |
283 | int vcmd; | |
20cc8b5b | 284 | { |
fc4d0a69 | 285 | register struct va_softc *sc = &va_softc[VAUNIT(dev)]; |
915905f4 | 286 | int s, cmd; |
fc4d0a69 | 287 | |
915905f4 KM |
288 | s = spl4(); |
289 | while (sc->sc_iostate&VAS_DMA) { | |
290 | sc->sc_iostate |= VAS_WANT; | |
291 | sleep((caddr_t)&sc->sc_iostate, VAPRI); | |
292 | } | |
293 | sc->sc_iostate |= VAS_PIO; | |
877283f6 | 294 | sc->sc_tocnt = 0; |
915905f4 | 295 | cmd = 0; |
20cc8b5b BJ |
296 | switch (vcmd) { |
297 | ||
298 | case VPLOT: | |
299 | /* Must turn on plot AND autostep modes. */ | |
915905f4 | 300 | if (vadopio(dev, VAPLOT)) |
20cc8b5b | 301 | u.u_error = EIO; |
915905f4 | 302 | cmd = VAAUTOSTEP; |
20cc8b5b BJ |
303 | break; |
304 | ||
305 | case VPRINT: | |
915905f4 | 306 | cmd = VAPRINT; |
20cc8b5b BJ |
307 | break; |
308 | ||
309 | case VPRINTPLOT: | |
915905f4 | 310 | cmd = VAPRINTPLOT; |
20cc8b5b BJ |
311 | break; |
312 | } | |
fc4d0a69 | 313 | sc->sc_state = (sc->sc_state & ~(VPLOT|VPRINT|VPRINTPLOT)) | vcmd; |
915905f4 | 314 | if (cmd && vadopio(dev, cmd)) |
20cc8b5b | 315 | u.u_error = EIO; |
915905f4 KM |
316 | sc->sc_iostate &= ~VAS_PIO; |
317 | if (sc->sc_iostate&VAS_WANT) { | |
318 | sc->sc_iostate &= ~VAS_WANT; | |
319 | wakeup((caddr_t)&sc->sc_iostate); | |
320 | } | |
321 | splx(s); | |
322 | } | |
323 | ||
324 | vadopio(dev, cmd) | |
325 | dev_t dev; | |
326 | int cmd; | |
327 | { | |
328 | register struct vadevice *vaaddr = | |
329 | (struct vadevice *)vaminfo[VAUNIT(dev)]->um_addr; | |
330 | register struct va_softc *sc = &va_softc[VAUNIT(dev)]; | |
331 | ||
332 | sc->sc_info = 0; | |
333 | vaaddr->vacsh = cmd; | |
334 | while ((sc->sc_info&(VA_DONE|VA_ERROR)) == 0) | |
335 | sleep((caddr_t)&sc->sc_info, VAPRI); | |
336 | return (sc->sc_info&VA_ERROR); | |
20cc8b5b BJ |
337 | } |
338 | ||
fc4d0a69 BJ |
339 | vatimo(dev) |
340 | dev_t dev; | |
20cc8b5b | 341 | { |
fc4d0a69 BJ |
342 | register struct va_softc *sc = &va_softc[VAUNIT(dev)]; |
343 | ||
344 | if (sc->sc_openf) | |
877283f6 | 345 | timeout(vatimo, (caddr_t)dev, hz/2); |
915905f4 KM |
346 | if (++sc->sc_tocnt < 2) |
347 | return; | |
348 | sc->sc_tocnt = 0; | |
410d35e9 | 349 | dprintf("vatimo: calling vaintr\n"); |
915905f4 | 350 | vaintr(dev); |
20cc8b5b BJ |
351 | } |
352 | ||
353 | /*ARGSUSED*/ | |
354 | vaintr(dev) | |
fc4d0a69 | 355 | dev_t dev; |
20cc8b5b | 356 | { |
915905f4 KM |
357 | register struct uba_ctlr *um; |
358 | struct vadevice *vaaddr; | |
359 | struct buf *bp; | |
360 | register int unit = VAUNIT(dev), e; | |
361 | register struct va_softc *sc = &va_softc[unit]; | |
362 | ||
363 | um = vaminfo[unit]; | |
364 | vaaddr = (struct vadevice *)um->um_addr; | |
365 | e = vaaddr->vacsw; | |
410d35e9 KM |
366 | dprintf("vaintr: um=0x%x, e=0x%x, b_active %d\n", |
367 | um, e, um->um_tab.b_actf->b_active); | |
915905f4 KM |
368 | if ((e&(VA_DONE|VA_ERROR)) == 0) |
369 | return; | |
370 | vaaddr->vacsl = 0; | |
371 | if ((e&VA_ERROR) && (e&VA_NPRTIMO)) | |
372 | printf("va%d: npr timeout\n", unit); | |
373 | if (sc->sc_iostate&VAS_PIO) { | |
374 | sc->sc_info = e; | |
375 | wakeup((caddr_t)&sc->sc_info); | |
376 | return; | |
377 | } | |
410d35e9 KM |
378 | if (um->um_tab.b_actf->b_active) { |
379 | bp = um->um_tab.b_actf->b_actf; | |
915905f4 KM |
380 | if (e&VA_ERROR) |
381 | bp->b_flags |= B_ERROR; | |
382 | if (sc->sc_state&VPRINTPLOT) { | |
383 | sc->sc_state = (sc->sc_state & ~VPRINTPLOT) | VPLOT; | |
384 | vaaddr->vacsh = VAAUTOSTEP; | |
385 | return; | |
386 | } | |
410d35e9 KM |
387 | ubadone(um); |
388 | um->um_tab.b_actf->b_active = 0; | |
389 | um->um_tab.b_actf->b_actf = bp->b_forw; | |
915905f4 KM |
390 | bp->b_active = 0; |
391 | bp->b_errcnt = 0; | |
392 | bp->b_resid = 0; | |
393 | iodone(bp); | |
394 | } | |
410d35e9 | 395 | if (um->um_tab.b_actf->b_actf == 0) { |
915905f4 KM |
396 | sc->sc_iostate &= ~VAS_DMA; |
397 | if (sc->sc_iostate&VAS_WANT) { | |
398 | sc->sc_iostate &= ~VAS_WANT; | |
399 | wakeup((caddr_t)&sc->sc_iostate); | |
400 | } | |
401 | return; | |
402 | } | |
410d35e9 | 403 | if (um->um_tab.b_actf->b_active == 0) |
915905f4 | 404 | vastart(um); |
20cc8b5b BJ |
405 | } |
406 | ||
fc4d0a69 BJ |
407 | vaclose(dev) |
408 | dev_t dev; | |
20cc8b5b | 409 | { |
fc4d0a69 BJ |
410 | register struct va_softc *sc = &va_softc[VAUNIT(dev)]; |
411 | register struct vadevice *vaaddr = | |
412 | (struct vadevice *)vadinfo[VAUNIT(dev)]->ui_addr; | |
413 | ||
414 | sc->sc_openf = 0; | |
fc4d0a69 | 415 | sc->sc_state = 0; |
915905f4 KM |
416 | if (sc->sc_iostate != VAS_IDLE) |
417 | wakeup((caddr_t)&sc->sc_iostate); | |
418 | sc->sc_iostate = VAS_IDLE; | |
fc4d0a69 | 419 | vaaddr->vacsl = 0; |
877283f6 | 420 | vaaddr->vawc = 0; |
71357272 BJ |
421 | } |
422 | ||
fc4d0a69 BJ |
423 | vareset(uban) |
424 | int uban; | |
71357272 | 425 | { |
fc4d0a69 | 426 | register int va11; |
915905f4 | 427 | register struct uba_ctlr *um; |
fc4d0a69 | 428 | register struct vadevice *vaaddr; |
915905f4 | 429 | register struct va_softc *sc; |
fc4d0a69 BJ |
430 | |
431 | for (va11 = 0; va11 < NVA; va11++, sc++) { | |
915905f4 KM |
432 | if ((um = vaminfo[va11]) == 0 || um->um_ubanum != uban || |
433 | um->um_alive == 0) | |
434 | continue; | |
435 | sc = &va_softc[um->um_ctlr]; | |
436 | if (sc->sc_openf == 0) | |
fc4d0a69 BJ |
437 | continue; |
438 | printf(" va%d", va11); | |
915905f4 | 439 | vaaddr = (struct vadevice *)um->um_addr; |
fc4d0a69 BJ |
440 | vaaddr->vacsl = VA_IENABLE; |
441 | if (sc->sc_state & VPLOT) { | |
442 | vaaddr->vacsh = VAPLOT; | |
443 | DELAY(10000); | |
444 | vaaddr->vacsh = VAAUTOSTEP; | |
445 | } else if (sc->sc_state & VPRINTPLOT) | |
446 | vaaddr->vacsh = VPRINTPLOT; | |
447 | else | |
448 | vaaddr->vacsh = VAPRINTPLOT; | |
71357272 | 449 | DELAY(10000); |
915905f4 | 450 | sc->sc_iostate = VAS_IDLE; |
410d35e9 KM |
451 | um->um_tab.b_actf->b_active = 0; |
452 | um->um_tab.b_actf->b_actf = um->um_tab.b_actf->b_actl = 0; | |
915905f4 KM |
453 | if (um->um_ubinfo) { |
454 | printf("<%d>", (um->um_ubinfo >> 28) & 0xf); | |
455 | ubadone(um); | |
fc4d0a69 | 456 | } |
915905f4 | 457 | (void) vastart(um); |
71357272 | 458 | } |
20cc8b5b | 459 | } |
941b74fe SL |
460 | |
461 | vaselect() | |
462 | { | |
463 | return (1); | |
464 | } | |
a5cc519e | 465 | #endif |