qd.c revision 1.22.2.3 1 /* $NetBSD: qd.c,v 1.22.2.3 2002/01/10 19:57:33 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1988 Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)qd.c 7.1 (Berkeley) 6/28/91
36 */
37
38 /************************************************************************
39 * *
40 * Copyright (c) 1985-1988 by *
41 * Digital Equipment Corporation, Maynard, MA *
42 * All rights reserved. *
43 * *
44 * This software is furnished under a license and may be used and *
45 * copied only in accordance with the terms of such license and *
46 * with the inclusion of the above copyright notice. This *
47 * software or any other copies thereof may not be provided or *
48 * otherwise made available to any other person. No title to and *
49 * ownership of the software is hereby transferred. *
50 * *
51 * The information in this software is subject to change without *
52 * notice and should not be construed as a commitment by Digital *
53 * Equipment Corporation. *
54 * *
55 * Digital assumes no responsibility for the use or reliability *
56 * of its software on equipment which is not supplied by Digital. *
57 * *
58 *************************************************************************/
59
60 /*
61 * qd.c - QDSS display driver for VAXSTATION-II GPX workstation
62 */
63
64 #include <sys/cdefs.h>
65 __KERNEL_RCSID(0, "$NetBSD: qd.c,v 1.22.2.3 2002/01/10 19:57:33 thorpej Exp $");
66
67 #include "opt_ddb.h"
68
69 #include "qd.h"
70
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/conf.h>
74 #include <sys/tty.h>
75 #include <sys/kernel.h>
76 #include <sys/device.h>
77 #include <sys/poll.h>
78 #include <sys/buf.h>
79
80 #include <uvm/uvm_extern.h>
81
82 #include <dev/cons.h>
83
84 #include <machine/bus.h>
85 #include <machine/scb.h>
86
87 #ifdef __vax__
88 #include <machine/sid.h>
89 #include <machine/cpu.h>
90 #include <machine/pte.h>
91 #endif
92
93 #include <dev/qbus/ubavar.h>
94
95 #include <dev/qbus/qduser.h>
96 #include <dev/qbus/qdreg.h>
97 #include <dev/qbus/qdioctl.h>
98
99 #include "ioconf.h"
100
101 /*
102 * QDSS driver status flags for tracking operational state
103 */
104 struct qdflags {
105 u_int inuse; /* which minor dev's are in use now */
106 u_int config; /* I/O page register content */
107 u_int mapped; /* user mapping status word */
108 u_int kernel_loop; /* if kernel console is redirected */
109 u_int user_dma; /* DMA from user space in progress */
110 u_short pntr_id; /* type code of pointing device */
111 u_short duart_imask; /* shadowing for duart intrpt mask reg */
112 u_short adder_ie; /* shadowing for adder intrpt enbl reg */
113 u_short curs_acc; /* cursor acceleration factor */
114 u_short curs_thr; /* cursor acceleration threshold level */
115 u_short tab_res; /* tablet resolution factor */
116 u_short selmask; /* mask for active qd select entries */
117 };
118
119 /*
120 * Softc struct to keep track of all states in this driver.
121 */
122 struct qd_softc {
123 struct device sc_dev;
124 bus_space_tag_t sc_iot;
125 bus_space_handle_t sc_ioh;
126 bus_dma_tag_t sc_dmat;
127 };
128
129 /*
130 * bit definitions for 'inuse' entry
131 */
132 #define CONS_DEV 0x01
133 #define GRAPHIC_DEV 0x04
134
135 /*
136 * bit definitions for 'mapped' member of flag structure
137 */
138 #define MAPDEV 0x01 /* hardware is mapped */
139 #define MAPDMA 0x02 /* DMA buffer mapped */
140 #define MAPEQ 0x04 /* event queue buffer mapped */
141 #define MAPSCR 0x08 /* scroll param area mapped */
142 #define MAPCOLOR 0x10 /* color map writing buffer mapped */
143
144 /*
145 * constants used in shared memory operations
146 */
147 #define EVENT_BUFSIZE 1024 /* # of bytes per device's event buffer */
148 #define MAXEVENTS ( (EVENT_BUFSIZE - sizeof(struct qdinput)) \
149 / sizeof(struct _vs_event) )
150 #define DMA_BUFSIZ (1024 * 10)
151 #define COLOR_BUFSIZ ((sizeof(struct color_buf) + 512) & ~0x01FF)
152
153 /*
154 * reference to an array of "uba_device" structures built by the auto
155 * configuration program. The uba_device structure decribes the device
156 * sufficiently for the driver to talk to it. The auto configuration code
157 * fills in the uba_device structures (located in ioconf.c) from user
158 * maintained info.
159 */
160 struct uba_device *qdinfo[NQD]; /* array of pntrs to each QDSS's */
161 struct tty *qd_tty[NQD*4]; /* teletype structures for each.. */
162 volatile char *qvmem[NQD];
163 volatile struct pte *QVmap[NQD];
164 #define CHUNK (64 * 1024)
165 #define QMEMSIZE (1024 * 1024 * 4) /* 4 meg */
166
167 /*
168 * static storage used by multiple functions in this code
169 */
170 int Qbus_unmap[NQD]; /* Qbus mapper release code */
171 struct qdmap qdmap[NQD]; /* QDSS register map structure */
172 struct qdflags qdflags[NQD]; /* QDSS register map structure */
173 caddr_t qdbase[NQD]; /* base address of each QDSS unit */
174 struct buf qdbuf[NQD]; /* buf structs used by strategy */
175 short qdopened[NQD]; /* graphics device is open exclusive use */
176
177 /*
178 * the array "event_shared[]" is made up of a number of event queue buffers
179 * equal to the number of QDSS's configured into the running kernel (NQD).
180 * Each event queue buffer begins with an event queue header (struct qdinput)
181 * followed by a group of event queue entries (struct _vs_event). The array
182 * "*eq_header[]" is an array of pointers to the start of each event queue
183 * buffer in "event_shared[]".
184 */
185 #define EQSIZE ((EVENT_BUFSIZE * NQD) + 512)
186
187 char event_shared[EQSIZE]; /* reserve space for event bufs */
188 struct qdinput *eq_header[NQD]; /* event queue header pntrs */
189
190 /*
191 * This allocation method reserves enough memory pages for NQD shared DMA I/O
192 * buffers. Each buffer must consume an integral number of memory pages to
193 * guarantee that a following buffer will begin on a page boundary. Also,
194 * enough space is allocated so that the FIRST I/O buffer can start at the
195 * 1st page boundary after "&DMA_shared". Page boundaries are used so that
196 * memory protections can be turned on/off for individual buffers.
197 */
198 #define IOBUFSIZE ((DMA_BUFSIZ * NQD) + 512)
199
200 char DMA_shared[IOBUFSIZE]; /* reserve I/O buffer space */
201 struct DMAreq_header *DMAheader[NQD]; /* DMA buffer header pntrs */
202
203 /*
204 * The driver assists a client in scroll operations by loading dragon
205 * registers from an interrupt service routine. The loading is done using
206 * parameters found in memory shrade between the driver and it's client.
207 * The scroll parameter structures are ALL loacted in the same memory page
208 * for reasons of memory economy.
209 */
210 char scroll_shared[2 * 512]; /* reserve space for scroll structs */
211 struct scroll *scroll[NQD]; /* pointers to scroll structures */
212
213 /*
214 * the driver is programmable to provide the user with color map write
215 * services at VSYNC interrupt time. At interrupt time the driver loads
216 * the color map with any user-requested load data found in shared memory
217 */
218 #define COLOR_SHARED ((COLOR_BUFSIZ * NQD) + 512)
219
220 char color_shared[COLOR_SHARED]; /* reserve space: color bufs */
221 struct color_buf *color_buf[NQD]; /* pointers to color bufs */
222
223 /*
224 * mouse input event structures
225 */
226 struct mouse_report last_rep[NQD];
227 struct mouse_report current_rep[NQD];
228
229 struct selinfo qdrsel[NQD]; /* process waiting for select */
230 struct _vs_cursor cursor[NQD]; /* console cursor */
231 int qdcount = 0; /* count of successfully probed qd's */
232 int nNQD = NQD;
233 int DMAbuf_size = DMA_BUFSIZ;
234 int QDlast_DMAtype; /* type of the last DMA operation */
235
236 /* #define QDSSMAJOR 41 */ /* QDSS major device number. We don't care! */
237
238 /*
239 * macro to get system time. Used to time stamp event queue entries
240 */
241 #define TOY ((time.tv_sec * 100) + (time.tv_usec / 10000))
242
243 void qd_attach __P((struct device *, struct device *, void *));
244 static int qd_match __P((struct device *, struct cfdata *, void *));
245
246 static void qddint __P((void *)); /* DMA gate array intrpt service */
247 static void qdaint __P((void *)); /* Dragon ADDER intrpt service */
248 static void qdiint __P((void *));
249
250 #define QDPRIOR (PZERO-1) /* must be negative */
251 #define FALSE 0
252 #ifdef TRUE
253 #undef TRUE
254 #endif
255 #define TRUE ~FALSE
256 #define BAD -1
257 #define GOOD 0
258
259 /*
260 * macro to create a system virtual page number from system virtual adrs
261 */
262 #define VTOP(x) (((int)x & ~0xC0000000) >> VAX_PGSHIFT)
263
264 /*
265 * QDSS register address offsets from start of QDSS address space
266 */
267 #define QDSIZE (52 * 1024) /* size of entire QDSS foot print */
268 #define TMPSIZE (16 * 1024) /* template RAM is 8k SHORT WORDS */
269 #define TMPSTART 0x8000 /* offset of template RAM from base adrs */
270 #define REGSIZE (5 * 512) /* regs touch 2.5k (5 pages) of addr space */
271 #define REGSTART 0xC000 /* offset of reg pages from base adrs */
272 #define ADDER (REGSTART+0x000)
273 #define DGA (REGSTART+0x200)
274 #define DUART (REGSTART+0x400)
275 #define MEMCSR (REGSTART+0x800)
276 #define CLRSIZE (3 * 512) /* color map size */
277 #define CLRSTART (REGSTART+0xA00) /* color map start offset from base */
278 /* 0x0C00 really */
279 #define RED (CLRSTART+0x000)
280 #define BLUE (CLRSTART+0x200)
281 #define GREEN (CLRSTART+0x400)
282
283
284 /*
285 * QDSS minor device numbers. The *real* minor device numbers are in
286 * the bottom two bits of the major/minor device spec. Bits 2 and up are
287 * used to specify the QDSS device number (ie: which one?)
288 */
289
290 #define CONS 0
291 #define GRAPHIC 2
292
293 /*
294 * console cursor bitmap (white block cursor)
295 */
296 short cons_cursor[32] = {
297 /* A */ 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,
298 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,
299 /* B */ 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF,
300 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF
301 };
302
303 /*
304 * constants used in font operations
305 */
306 #define CHARS 190 /* # of chars in the font */
307 #define CHAR_HEIGHT 15 /* char height in pixels */
308 #define CHAR_WIDTH 8 /* char width in pixels*/
309 #define FONT_WIDTH (CHAR_WIDTH * CHARS) /* font width in pixels */
310 #define ROWS CHAR_HEIGHT
311 #define FONT_X 0 /* font's off screen adrs */
312 #define FONT_Y (2048 - CHAR_HEIGHT)
313
314 /* Offset to second row characters (XXX - should remove) */
315 #define FONT_OFFSET ((MAX_SCREEN_X/CHAR_WIDTH)*CHAR_HEIGHT)
316
317 extern char q_font[]; /* reference font object code */
318 extern u_short q_key[]; /* reference key xlation tables */
319 extern u_short q_shift_key[];
320 extern char *q_special[];
321
322 /*
323 * definitions for cursor acceleration reporting
324 */
325 #define ACC_OFF 0x01 /* acceleration is inactive */
326
327 /*
328 * virtual console support.
329 */
330 extern struct cdevsw *consops;
331 cons_decl(qd);
332 cdev_decl(qd);
333 void setup_dragon __P((int));
334 void init_shared __P((int));
335 void clear_qd_screen __P((int));
336 void ldfont __P((int));
337 void ldcursor __P((int, short *));
338 void setup_input __P((int));
339 void blitc __P((int, u_char));
340 void scroll_up __P((volatile struct adder *));
341 void write_ID __P((volatile struct adder *, short, short));
342 int wait_status __P((volatile struct adder *, int));
343 void led_control __P((int, int, int));
344 void qdstart(struct tty *);
345 void qdearly(void);
346 int qdpolling = 0;
347
348 /*
349 * LK-201 state storage for input console keyboard conversion to ASCII
350 */
351 struct q_keyboard {
352 int shift; /* state variables */
353 int cntrl;
354 int lock;
355 int lastcode; /* last keycode typed */
356 unsigned kup[8]; /* bits for each keycode*/
357 unsigned dkeys[8]; /* down/up mode keys */
358 char last; /* last character */
359 } q_keyboard;
360
361 /*
362 * tty settings on first open
363 */
364 #define IFLAG (BRKINT|ISTRIP|IXON|IXANY|ICRNL|IMAXBEL)
365 #define OFLAG (OPOST|OXTABS|ONLCR)
366 #define LFLAG (ISIG|ICANON|ECHO|IEXTEN)
367 #define CFLAG (PARENB|CREAD|CS7|CLOCAL)
368
369 /*
370 * Kernel virtual addresses where we can map in the QBUS io page and the
371 * QDSS memory during qdcninit. pmap_bootstrap fills this in.
372 */
373 void *qd_ubaio;
374
375 /* This is the QDSS unit 0 CSR. It is hard-coded in here so that the
376 * QDSS can be used as the console. The console routines don't get
377 * any config info. The ROM also autodetects at this address, so
378 * the console QDSS should be at this address. Furthermore, nothing
379 * else shuld be at this address instead because that would confuse the
380 * ROM and this driver.
381 */
382 #define QDSSCSR 0x1F00
383
384 volatile u_short *qdaddr; /* Virtual address for QDSS CSR */
385
386 /*
387 * This flag is set to 1 if the console initialization (qdcninit)
388 * has been performed on qd0. That initialization is required and must
389 * be done before the device probe routine.
390 */
391 int qd0cninited = 0, qd0iscons = 0;
392
393 /*
394 * Do early check if the qdss is console. If not; don't allocate
395 * any memory for it in bootstrap.
396 */
397 void
398 qdearly()
399 {
400 extern vaddr_t virtual_avail;
401 int tmp;
402
403 /* Make sure we're running on a system that can have a QDSS */
404 if (vax_boardtype == VAX_BTYP_630) {
405 /* Now check some undocumented flag */
406 if ((*(int *)(0x200B801E) & 0x60) == 0)
407 /* The KA630 isn't using a QDSS as the console,
408 * so we won't either */
409 return;
410 } else if (vax_boardtype != VAX_BTYP_650)
411 return;
412
413 /* How to check for console on KA650? We assume that if there is a
414 * QDSS, it is console.
415 */
416 #define QIOPAGE 0x20000000 /* XXX */
417 #define UBAIOPAGES 16
418 tmp = QIOPAGE + ubdevreg(QDSSCSR);
419 if (badaddr((caddr_t)tmp, sizeof(short)))
420 return;
421
422 MAPVIRT(qvmem[0], 64 * 1024 * NQD / VAX_NBPG);
423 MAPVIRT(qd_ubaio, 16);
424 pmap_map((int)qd_ubaio, QIOPAGE, QIOPAGE + UBAIOPAGES * VAX_NBPG,
425 VM_PROT_READ|VM_PROT_WRITE);
426 qdaddr = (u_short *)((u_int)qd_ubaio + ubdevreg(QDSSCSR));
427 qd0iscons = 1;
428 }
429
430 void
431 qdcnprobe(cndev)
432 struct consdev *cndev;
433 {
434 int i;
435
436 cndev->cn_pri = CN_DEAD;
437
438 if (mfpr(PR_MAPEN) == 0)
439 return; /* Cannot use qd if vm system is OFF */
440
441 if (!qd0iscons)
442 return;
443
444 /* Find the console device corresponding to the console QDSS */
445 for (i = 0; i < nchrdev; i++)
446 if (cdevsw[i].d_open == qdopen) {
447 cndev->cn_dev = makedev(i,0);
448 cndev->cn_pri = CN_INTERNAL;
449 return;
450 }
451 return;
452 }
453
454
455 /*
456 * Init QDSS as console (before probe routine)
457 */
458 void
459 qdcninit(cndev)
460 struct consdev *cndev;
461 {
462 caddr_t phys_adr; /* physical QDSS base adrs */
463 u_int mapix; /* index into QVmap[] array */
464 int unit;
465
466 /* qdaddr must point to CSR for this unit! */
467
468 /* The console QDSS is QDSS unit 0 */
469 unit = 0;
470
471 /*
472 * Map q-bus memory used by qdss. (separate map)
473 */
474 mapix = QMEMSIZE - (CHUNK * (unit + 1));
475 #define QMEM 0x30000000
476 (int)phys_adr = QMEM + mapix;
477 pmap_map((int)(qvmem[0]), (int)phys_adr, (int)(phys_adr + (CHUNK*NQD)),
478 VM_PROT_READ|VM_PROT_WRITE);
479
480 /*
481 * Set QVmap to point to page table entries for what we just
482 * mapped.
483 */
484 QVmap[0] = (struct pte *)kvtopte(qvmem[0]);
485
486 /*
487 * tell QDSS which Q memory address base to decode
488 * (shifted right 16 bits - its in 64K units)
489 */
490 *qdaddr = (u_short)((int)mapix >> 16);
491 qdflags[unit].config = *(u_short *)qdaddr;
492
493 /*
494 * load qdmap struct with the virtual addresses of the QDSS elements
495 */
496 qdbase[unit] = (caddr_t) (qvmem[0]);
497 qdmap[unit].template = qdbase[unit] + TMPSTART;
498 qdmap[unit].adder = qdbase[unit] + ADDER;
499 qdmap[unit].dga = qdbase[unit] + DGA;
500 qdmap[unit].duart = qdbase[unit] + DUART;
501 qdmap[unit].memcsr = qdbase[unit] + MEMCSR;
502 qdmap[unit].red = qdbase[unit] + RED;
503 qdmap[unit].blue = qdbase[unit] + BLUE;
504 qdmap[unit].green = qdbase[unit] + GREEN;
505
506 qdflags[unit].duart_imask = 0; /* init shadow variables */
507
508 /*
509 * init the QDSS
510 */
511
512 *(short *)qdmap[unit].memcsr |= SYNC_ON; /* once only: turn on sync */
513
514 cursor[unit].x = 0;
515 cursor[unit].y = 0;
516 init_shared(unit); /* init shared memory */
517 setup_dragon(unit); /* init the ADDER/VIPER stuff */
518 clear_qd_screen(unit); /* clear the screen */
519 ldfont(unit); /* load the console font */
520 ldcursor(unit, cons_cursor); /* load default cursor map */
521 setup_input(unit); /* init the DUART */
522
523 /* Set flag so probe knows */
524 qd0cninited = 1;
525 } /* qdcninit */
526
527 /* see <sys/device.h> */
528 struct cfattach qd_ca = {
529 sizeof(struct qd_softc), qd_match, qd_attach
530 };
531
532 #define QD_RCSR(reg) \
533 bus_space_read_2(sc->sc_iot, sc->sc_ioh, reg)
534 #define QD_WCSR(reg, val) \
535 bus_space_write_2(sc->sc_iot, sc->sc_ioh, reg, val)
536
537 /*
538 * Configure QDSS into Q memory and make it intrpt.
539 *
540 * side effects: QDSS gets mapped into Qbus memory space at the first
541 * vacant 64kb boundary counting back from the top of
542 * Qbus memory space (qvmem+4mb)
543 *
544 * return: QDSS bus request level and vector address returned in
545 * registers by UNIX convention.
546 *
547 */
548 static int
549 qd_match(parent, match, aux)
550 struct device *parent;
551 struct cfdata *match;
552 void *aux;
553 {
554 struct qd_softc ssc;
555 struct qd_softc *sc = &ssc;
556 struct uba_attach_args *ua = aux;
557 struct uba_softc *uh = (void *)parent;
558 int unit;
559 volatile struct dga *dga; /* pointer to gate array structure */
560 int vector;
561 #ifdef notdef
562 int *ptep; /* page table entry pointer */
563 caddr_t phys_adr; /* physical QDSS base adrs */
564 u_int mapix;
565 #endif
566
567 /* Create a "fake" softc with only a few fields used. */
568 sc->sc_iot = ua->ua_iot;
569 sc->sc_ioh = ua->ua_ioh;
570 sc->sc_dmat = ua->ua_dmat;
571 /*
572 * calculate board unit number from I/O page register address
573 */
574 unit = (int) (((int)sc->sc_ioh >> 1) & 0x0007);
575
576 /*
577 * QDSS regs must be mapped to Qbus memory space at a 64kb
578 * physical boundary. The Qbus memory space is mapped into
579 * the system memory space at config time. After config
580 * runs, "qvmem[0]" (ubavar.h) holds the system virtual adrs
581 * of the start of Qbus memory. The Qbus memory page table
582 * is found via an array of pte ptrs called "QVmap[]" (ubavar.h)
583 * which is also loaded at config time. These are the
584 * variables used below to find a vacant 64kb boundary in
585 * Qbus memory, and load it's corresponding physical adrs
586 * into the QDSS's I/O page CSR.
587 */
588
589 /*
590 * Only if QD is the graphics device.
591 */
592
593 /* if this QDSS is NOT the console, then do init here.. */
594
595 if (unit != 0) {
596 printf("qd: can't support two qdss's (yet)\n");
597 #ifdef notdef /* can't test */
598 if (v_consputc != qdputc || unit != 0) {
599
600 /*
601 * read QDSS config info
602 */
603 qdflags[unit].config = *(u_short *)reg;
604
605 /*
606 * find an empty 64kb adrs boundary
607 */
608
609 qdbase[unit] = (caddr_t) (qvmem[0] + QMEMSIZE - CHUNK);
610
611 /*
612 * find the cpusw entry that matches this machine.
613 */
614 cpup = &cpusw[cpu];
615 while (!(BADADDR(qdbase[unit], sizeof(short))))
616 qdbase[unit] -= CHUNK;
617
618 /*
619 * tell QDSS which Q memory address base to decode
620 */
621 mapix = (int) (VTOP(qdbase[unit]) - VTOP(qvmem[0]));
622 ptep = (int *) QVmap[0] + mapix;
623 phys_adr = (caddr_t)(((int)*ptep&0x001FFFFF)<<VAX_PGSHIFT);
624 *(u_short *)reg = (u_short) ((int)phys_adr >> 16);
625
626 /*
627 * load QDSS adrs map with system addresses
628 * of device regs
629 */
630 qdmap[unit].template = qdbase[unit] + TMPSTART;
631 qdmap[unit].adder = qdbase[unit] + ADDER;
632 qdmap[unit].dga = qdbase[unit] + DGA;
633 qdmap[unit].duart = qdbase[unit] + DUART;
634 qdmap[unit].memcsr = qdbase[unit] + MEMCSR;
635 qdmap[unit].red = qdbase[unit] + RED;
636 qdmap[unit].blue = qdbase[unit] + BLUE;
637 qdmap[unit].green = qdbase[unit] + GREEN;
638
639 /* device init */
640
641 cursor[unit].x = 0;
642 cursor[unit].y = 0;
643 init_shared(unit); /* init shared memory */
644 setup_dragon(unit); /* init the ADDER/VIPER stuff */
645 ldcursor(unit, cons_cursor); /* load default cursor map */
646 setup_input(unit); /* init the DUART */
647 clear_qd_screen(unit);
648 ldfont(unit); /* load the console font */
649
650 /* once only: turn on sync */
651
652 *(short *)qdmap[unit].memcsr |= SYNC_ON;
653 }
654 #endif /*notdef*/
655 } else {
656 /* We are dealing with qd0 */
657
658 if (!qd0cninited) {
659 /*
660 * qd0 has not been initiallized as the console.
661 * We need to do some initialization now
662 *
663 * XXX
664 * However, if the QDSS is not the console then
665 * that stupid undocumented bit (see qdcnprobe)
666 * is cleared. Then the QDSS refuses to work.
667 * (What did the ROM do to it!?)
668 * XXX
669 */
670 return 0;
671
672 #if 0
673 qdaddr = (void *)reg;
674
675 /* Lame probe for QDSS. Should be ok for qd0 */
676 if (badaddr((caddr_t)qdaddr, sizeof(short)))
677 return 0;
678
679 qdcninit(NULL);
680 #endif
681 }
682 }
683
684
685 /*
686 * The QDSS interrupts at HEX vectors xx0 (DMA) xx4
687 * (ADDER) and xx8 (DUART). Therefore, we take three
688 * vectors from the vector pool, and then continue
689 * to take them until we get a xx0 HEX vector. The
690 * pool provides vectors in contiguous decending
691 * order.
692 */
693
694 vector = (uh->uh_lastiv -= 4*3); /* take three vectors */
695
696 while (vector & 0x0F) { /* if lo nibble != 0.. */
697 /* ..take another vector */
698 vector = (uh->uh_lastiv -= 4);
699 }
700
701 /*
702 * setup DGA to do a DMA interrupt (transfer count = 0)
703 */
704 dga = (struct dga *) qdmap[unit].dga;
705 dga->csr = (short) HALT; /* disable everything */
706 dga->ivr = (short) vector; /* load intrpt base vector */
707 dga->bytcnt_lo = (short) 0; /* DMA xfer count = 0 */
708 dga->bytcnt_hi = (short) 0;
709
710 /*
711 * turn on DMA interrupts
712 */
713 dga->csr &= ~SET_DONE_FIFO;
714 dga->csr |= DMA_IE | DL_ENB;
715
716 DELAY(20000); /* wait for the intrpt */
717 dga->csr = HALT; /* stop the wheels */
718
719 /*
720 * score this as an existing qdss
721 */
722 qdcount++;
723
724 return 1;
725 } /* qdprobe */
726
727
728 void qd_attach(parent, self, aux)
729 struct device *parent, *self;
730 void *aux;
731 {
732 struct uba_attach_args *ua = aux;
733 int unit; /* QDSS module # for this call */
734
735 printf("\n");
736
737 unit = self->dv_unit; /* get QDSS number */
738
739 /* Set interrupt vectors for interrupt handlers */
740
741 uba_intr_establish(ua->ua_icookie, ua->ua_cvec , qddint, self);
742 uba_intr_establish(ua->ua_icookie, ua->ua_cvec + 4, qdaint, self);
743 uba_intr_establish(ua->ua_icookie, ua->ua_cvec + 8, qdiint, self);
744
745 /*
746 * init "qdflags[]" for this QDSS
747 */
748 qdflags[unit].inuse = 0; /* init inuse variable EARLY! */
749 qdflags[unit].mapped = 0;
750 qdflags[unit].kernel_loop = -1;
751 qdflags[unit].user_dma = 0;
752 qdflags[unit].curs_acc = ACC_OFF;
753 qdflags[unit].curs_thr = 128;
754 qdflags[unit].tab_res = 2; /* default tablet resolution factor */
755 qdflags[unit].duart_imask = 0; /* init shadow variables */
756 qdflags[unit].adder_ie = 0;
757
758 /*
759 * init structures used in kbd/mouse interrupt service. This code must
760 * come after the "init_shared()" routine has run since that routine
761 * inits the eq_header[unit] structure used here.
762 */
763
764 /*
765 * init the "latest mouse report" structure
766 */
767 last_rep[unit].state = 0;
768 last_rep[unit].dx = 0;
769 last_rep[unit].dy = 0;
770 last_rep[unit].bytcnt = 0;
771
772 /*
773 * init the event queue (except mouse position)
774 */
775 eq_header[unit]->header.events =
776 (struct _vs_event *)((int)eq_header[unit] + sizeof(struct qdinput));
777
778 eq_header[unit]->header.size = MAXEVENTS;
779 eq_header[unit]->header.head = 0;
780 eq_header[unit]->header.tail = 0;
781
782 /*
783 * open exclusive for graphics device.
784 */
785 qdopened[unit] = 0;
786
787 } /* qdattach */
788
789
790 /*ARGSUSED*/
791 int
792 qdopen(dev, flag, mode, p)
793 dev_t dev;
794 int flag, mode;
795 struct proc *p;
796 {
797 volatile struct dga *dga; /* ptr to gate array struct */
798 struct tty *tp;
799 volatile struct duart *duart;
800 int unit;
801 int minor_dev;
802
803 minor_dev = minor(dev); /* get QDSS minor device number */
804 unit = minor_dev >> 2;
805
806 /*
807 * check for illegal conditions
808 */
809 if (unit >= qd_cd.cd_ndevs || qd_cd.cd_devs[unit] == NULL)
810 return (ENXIO); /* no such device or address */
811
812 duart = (struct duart *) qdmap[unit].duart;
813 dga = (struct dga *) qdmap[unit].dga;
814
815 if ((minor_dev & 0x03) == 2) {
816 /*
817 * this is the graphic device...
818 */
819 if (qdopened[unit] != 0)
820 return(EBUSY);
821 else
822 qdopened[unit] = 1;
823 qdflags[unit].inuse |= GRAPHIC_DEV; /* graphics dev is open */
824 /*
825 * enble kbd & mouse intrpts in DUART mask reg
826 */
827 qdflags[unit].duart_imask |= 0x22;
828 duart->imask = qdflags[unit].duart_imask;
829 } else {
830 /* Only one console */
831 if (minor_dev) return ENXIO;
832
833 /* If not done already, allocate tty structure */
834 if (qd_tty[minor_dev] == NULL)
835 qd_tty[minor_dev] = ttymalloc();
836
837 if (qd_tty[minor_dev] == NULL)
838 return ENXIO;
839
840 /*
841 * this is the console
842 */
843 qdflags[unit].inuse |= CONS_DEV; /* mark console as open */
844 dga->csr |= CURS_ENB;
845 qdflags[unit].duart_imask |= 0x02;
846 duart->imask = qdflags[unit].duart_imask;
847 /*
848 * some setup for tty handling
849 */
850 tp = qd_tty[minor_dev];
851 /* tp->t_addr = ui->ui_addr; */
852 tp->t_oproc = qdstart;
853 tp->t_dev = dev;
854 if ((tp->t_state & TS_ISOPEN) == 0) {
855 ttychars(tp);
856 tp->t_ispeed = B9600;
857 tp->t_ospeed = B9600;
858 tp->t_state = TS_ISOPEN | TS_CARR_ON;
859 tp->t_iflag = TTYDEF_IFLAG;
860 tp->t_oflag = TTYDEF_OFLAG;
861 tp->t_lflag = TTYDEF_LFLAG;
862 tp->t_cflag = TTYDEF_CFLAG;
863 ttsetwater(tp);
864 }
865 /*
866 * enable intrpts, open line discipline
867 */
868 dga->csr |= GLOBAL_IE; /* turn on the interrupts */
869 return ((*tp->t_linesw->l_open)(dev, tp));
870 }
871 dga->csr |= GLOBAL_IE; /* turn on the interrupts */
872 return(0);
873
874 } /* qdopen */
875
876 /*ARGSUSED*/
877 int
878 qdclose(dev, flag, mode, p)
879 dev_t dev;
880 int flag, mode;
881 struct proc *p;
882 {
883 struct tty *tp;
884 struct qdmap *qd;
885 volatile int *ptep;
886 volatile struct dga *dga; /* gate array register map pointer */
887 volatile struct duart *duart;
888 volatile struct adder *adder;
889 int unit;
890 int minor_dev;
891 u_int mapix;
892 int i; /* SIGNED index */
893 struct uba_softc *uh;
894
895 minor_dev = minor(dev); /* get minor device number */
896 unit = minor_dev >> 2; /* get QDSS number */
897 qd = &qdmap[unit];
898
899 uh = (struct uba_softc *)
900 (((struct device *)(qd_cd.cd_devs[unit]))->dv_parent);
901
902
903 if ((minor_dev & 0x03) == 2) {
904 /*
905 * this is the graphic device...
906 */
907 if (qdopened[unit] != 1)
908 return(EBUSY);
909 else
910 qdopened[unit] = 0; /* allow it to be re-opened */
911 /*
912 * re-protect device memory
913 */
914 if (qdflags[unit].mapped & MAPDEV) {
915 /*
916 * TEMPLATE RAM
917 */
918 mapix = VTOP((int)qd->template) - VTOP(qvmem[0]);
919 ptep = (int *)(QVmap[0] + mapix);
920 for (i = 0; i < vax_btop(TMPSIZE); i++, ptep++)
921 *ptep = (*ptep & ~PG_PROT) | PG_V | PG_KW;
922 /*
923 * ADDER
924 */
925 mapix = VTOP((int)qd->adder) - VTOP(qvmem[0]);
926 ptep = (int *)(QVmap[0] + mapix);
927 for (i = 0; i < vax_btop(REGSIZE); i++, ptep++)
928 *ptep = (*ptep & ~PG_PROT) | PG_V | PG_KW;
929 /*
930 * COLOR MAPS
931 */
932 mapix = VTOP((int)qd->red) - VTOP(qvmem[0]);
933 ptep = (int *)(QVmap[0] + mapix);
934 for (i = 0; i < vax_btop(CLRSIZE); i++, ptep++)
935 *ptep = (*ptep & ~PG_PROT) | PG_V | PG_KW;
936 }
937
938 /*
939 * re-protect DMA buffer and free the map registers
940 */
941 if (qdflags[unit].mapped & MAPDMA) {
942 panic("Unmapping unmapped buffer");
943 #ifdef notyet
944 /*
945 * Ragge 990620:
946 * Can't happen because the buffer can't be mapped.
947 */
948 dga = (struct dga *) qdmap[unit].dga;
949 adder = (struct adder *) qdmap[unit].adder;
950 dga->csr &= ~DMA_IE;
951 dga->csr &= ~0x0600; /* kill DMA */
952 adder->command = CANCEL;
953 /*
954 * if DMA was running, flush spurious intrpt
955 */
956 if (dga->bytcnt_lo != 0) {
957 dga->bytcnt_lo = 0;
958 dga->bytcnt_hi = 0;
959 DMA_SETIGNORE(DMAheader[unit]);
960 dga->csr |= DMA_IE;
961 dga->csr &= ~DMA_IE;
962 }
963 ptep = (int *)
964 ((VTOP(DMAheader[unit]*4)) + (mfpr(PR_SBR)|0x80000000));
965 for (i = 0; i < vax_btop(DMAbuf_size); i++, ptep++)
966 *ptep = (*ptep & ~PG_PROT) | PG_V | PG_KW;
967 ubarelse(uh, &Qbus_unmap[unit]);
968 #endif
969 }
970
971 /*
972 * re-protect 1K (2 pages) event queue
973 */
974 if (qdflags[unit].mapped & MAPEQ) {
975 ptep = (int *)
976 ((VTOP(eq_header[unit])*4) + (mfpr(PR_SBR)|0x80000000));
977 *ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V; ptep++;
978 *ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V;
979 }
980 /*
981 * re-protect scroll param area and disable scroll intrpts
982 */
983 if (qdflags[unit].mapped & MAPSCR) {
984 ptep = (int *) ((VTOP(scroll[unit]) * 4)
985 + (mfpr(PR_SBR) | 0x80000000));
986 /*
987 * re-protect 512 scroll param area
988 */
989 *ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V;
990 adder = (struct adder *) qdmap[unit].adder;
991 qdflags[unit].adder_ie &= ~FRAME_SYNC;
992 adder->interrupt_enable = qdflags[unit].adder_ie;
993 }
994 /*
995 * re-protect color map write buffer area and kill intrpts
996 */
997 if (qdflags[unit].mapped & MAPCOLOR) {
998 ptep = (int *) ((VTOP(color_buf[unit]) * 4)
999 + (mfpr(PR_SBR) | 0x80000000));
1000 *ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V; ptep++;
1001 *ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V;
1002 color_buf[unit]->status = 0;
1003 adder = (struct adder *) qdmap[unit].adder;
1004 qdflags[unit].adder_ie &= ~VSYNC;
1005 adder->interrupt_enable = qdflags[unit].adder_ie;
1006 }
1007 mtpr(0, PR_TBIA);
1008 /* flag everything now unmapped */
1009 qdflags[unit].mapped = 0;
1010 qdflags[unit].inuse &= ~GRAPHIC_DEV;
1011 qdflags[unit].curs_acc = ACC_OFF;
1012 qdflags[unit].curs_thr = 128;
1013 /*
1014 * restore the console
1015 */
1016 dga = (struct dga *) qdmap[unit].dga;
1017 adder = (struct adder *) qdmap[unit].adder;
1018 dga->csr &= ~DMA_IE;
1019 dga->csr &= ~0x0600; /* halt the DMA! (just in case...) */
1020 dga->csr |= DMA_ERR; /* clear error condition */
1021 adder->command = CANCEL;
1022 /*
1023 * if DMA was running, flush spurious intrpt
1024 */
1025 if (dga->bytcnt_lo != 0) {
1026 dga->bytcnt_lo = 0;
1027 dga->bytcnt_hi = 0;
1028 DMA_SETIGNORE(DMAheader[unit]);
1029 dga->csr |= DMA_IE;
1030 dga->csr &= ~DMA_IE;
1031 }
1032 init_shared(unit); /* init shared memory */
1033 setup_dragon(unit); /* init ADDER/VIPER */
1034 ldcursor(unit, cons_cursor); /* load default cursor map */
1035 setup_input(unit); /* init the DUART */
1036 ldfont(unit);
1037 cursor[unit].x = 0;
1038 cursor[unit].y = 0;
1039 /*
1040 * shut off the mouse rcv intrpt and turn on kbd intrpts
1041 */
1042 duart = (struct duart *) qdmap[unit].duart;
1043 qdflags[unit].duart_imask &= ~(0x20);
1044 qdflags[unit].duart_imask |= 0x02;
1045 duart->imask = qdflags[unit].duart_imask;
1046 /*
1047 * shut off interrupts if all is closed
1048 */
1049 if (!(qdflags[unit].inuse & CONS_DEV)) {
1050 dga = (struct dga *) qdmap[unit].dga;
1051 dga->csr &= ~(GLOBAL_IE | DMA_IE);
1052 }
1053 } else {
1054 /*
1055 * this is the console
1056 */
1057 tp = qd_tty[minor_dev];
1058 (*tp->t_linesw->l_close)(tp, flag);
1059 ttyclose(tp);
1060 tp->t_state = 0;
1061 qdflags[unit].inuse &= ~CONS_DEV;
1062 /*
1063 * if graphics device is closed, kill interrupts
1064 */
1065 if (!(qdflags[unit].inuse & GRAPHIC_DEV)) {
1066 dga = (struct dga *) qdmap[unit].dga;
1067 dga->csr &= ~(GLOBAL_IE | DMA_IE);
1068 }
1069 }
1070
1071 return(0);
1072
1073 } /* qdclose */
1074
1075 int
1076 qdioctl(dev, cmd, datap, flags, p)
1077 dev_t dev;
1078 u_long cmd;
1079 caddr_t datap;
1080 int flags;
1081 struct proc *p;
1082 {
1083 volatile int *ptep; /* page table entry pointer */
1084 int mapix; /* QVmap[] page table index */
1085 struct _vs_event *event;
1086 struct tty *tp;
1087 int i;
1088 struct qdmap *qd; /* pointer to device map struct */
1089 volatile struct dga *dga; /* Gate Array reg structure pntr */
1090 volatile struct duart *duart; /* DUART reg structure pointer */
1091 volatile struct adder *adder; /* ADDER reg structure pointer */
1092 struct prgkbd *cmdbuf;
1093 struct prg_cursor *curs;
1094 struct _vs_cursor *pos;
1095 int unit = minor(dev) >> 2; /* number of caller's QDSS */
1096 u_int minor_dev = minor(dev);
1097 int error;
1098 int s;
1099 short *temp; /* a pointer to template RAM */
1100 struct uba_softc *uh;
1101
1102 uh = (struct uba_softc *)
1103 (((struct device *)(qd_cd.cd_devs[unit]))->dv_parent);
1104
1105 /*
1106 * service graphic device ioctl commands
1107 */
1108 switch (cmd) {
1109
1110 case QD_GETEVENT:
1111 /*
1112 * extract the oldest event from the event queue
1113 */
1114 if (ISEMPTY(eq_header[unit])) {
1115 event = (struct _vs_event *) datap;
1116 event->vse_device = VSE_NULL;
1117 break;
1118 }
1119 event = (struct _vs_event *) GETBEGIN(eq_header[unit]);
1120 s = spl5();
1121 GETEND(eq_header[unit]);
1122 splx(s);
1123 bcopy((caddr_t)event, datap, sizeof(struct _vs_event));
1124 break;
1125
1126 case QD_RESET:
1127 /*
1128 * init the dragon stuff, DUART, and driver variables
1129 */
1130 init_shared(unit); /* init shared memory */
1131 setup_dragon(unit); /* init the ADDER/VIPER stuff */
1132 clear_qd_screen(unit);
1133 ldcursor(unit, cons_cursor); /* load default cursor map */
1134 ldfont(unit); /* load the console font */
1135 setup_input(unit); /* init the DUART */
1136 break;
1137
1138 case QD_SET:
1139 /*
1140 * init the DUART and driver variables
1141 */
1142 init_shared(unit);
1143 setup_input(unit);
1144 break;
1145
1146 case QD_CLRSCRN:
1147 /*
1148 * clear the QDSS screen. (NOTE that this reinits the dragon)
1149 */
1150 #ifdef notdef /* has caused problems and isn't necessary */
1151 setup_dragon(unit);
1152 clear_qd_screen(unit);
1153 #endif
1154 break;
1155
1156 case QD_WTCURSOR:
1157 /*
1158 * load a cursor into template RAM
1159 */
1160 ldcursor(unit, (short *)datap);
1161 break;
1162
1163 case QD_RDCURSOR:
1164
1165 temp = (short *) qdmap[unit].template;
1166 /*
1167 * cursor is 32 WORDS from the end of the 8k WORD...
1168 * ...template space
1169 */
1170 temp += (8 * 1024) - 32;
1171 for (i = 0; i < 32; ++i, datap += sizeof(short))
1172 *(short *)datap = *temp++;
1173 break;
1174
1175 case QD_POSCURSOR:
1176 /*
1177 * position the mouse cursor
1178 */
1179 dga = (struct dga *) qdmap[unit].dga;
1180 pos = (struct _vs_cursor *) datap;
1181 s = spl5();
1182 dga->x_cursor = TRANX(pos->x);
1183 dga->y_cursor = TRANY(pos->y);
1184 eq_header[unit]->curs_pos.x = pos->x;
1185 eq_header[unit]->curs_pos.y = pos->y;
1186 splx(s);
1187 break;
1188
1189 case QD_PRGCURSOR:
1190 /*
1191 * set the cursor acceleration factor
1192 */
1193 curs = (struct prg_cursor *) datap;
1194 s = spl5();
1195 qdflags[unit].curs_acc = curs->acc_factor;
1196 qdflags[unit].curs_thr = curs->threshold;
1197 splx(s);
1198 break;
1199
1200 case QD_MAPDEVICE:
1201 /*
1202 * enable 'user write' to device pages
1203 */
1204 qdflags[unit].mapped |= MAPDEV;
1205 qd = (struct qdmap *) &qdmap[unit];
1206 /*
1207 * enable user write to template RAM
1208 */
1209 mapix = VTOP((int)qd->template) - VTOP(qvmem[0]);
1210 ptep = (int *)(QVmap[0] + mapix);
1211 for (i = 0; i < vax_btop(TMPSIZE); i++, ptep++)
1212 *ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
1213
1214 /*
1215 * enable user write to registers
1216 */
1217 mapix = VTOP((int)qd->adder) - VTOP(qvmem[0]);
1218 ptep = (int *)(QVmap[0] + mapix);
1219 for (i = 0; i < vax_btop(REGSIZE); i++, ptep++)
1220 *ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
1221
1222 /*
1223 * enable user write to color maps
1224 */
1225 mapix = VTOP((int)qd->red) - VTOP(qvmem[0]);
1226 ptep = (int *)(QVmap[0] + mapix);
1227 for (i = 0; i < vax_btop(CLRSIZE); i++, ptep++)
1228 *ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
1229
1230 /*
1231 * enable user write to DUART
1232 */
1233 mapix = VTOP((int)qd->duart) - VTOP(qvmem[0]);
1234 ptep = (int *)(QVmap[0] + mapix);
1235 *ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V; /* duart page */
1236
1237 mtpr(0, PR_TBIA); /* invalidate translation buffer */
1238
1239 /*
1240 * stuff qdmap structure in return buffer
1241 */
1242 bcopy((caddr_t)qd, datap, sizeof(struct qdmap));
1243
1244 break;
1245
1246 #ifdef notyet
1247 /*
1248 * Ragge 999620:
1249 * Can't map in the graphic buffer into user space for now.
1250 * The best way to fix this is to convert this driver to wscons.
1251 */
1252 case QD_MAPIOBUF:
1253 /*
1254 * do setup for DMA by user process
1255 *
1256 * set 'user write enable' bits for DMA buffer
1257 */
1258 qdflags[unit].mapped |= MAPDMA;
1259 ptep = (int *) ((VTOP(DMAheader[unit]) * 4)
1260 + (mfpr(PR_SBR) | 0x80000000));
1261 for (i = 0; i < vax_btop(DMAbuf_size); i++, ptep++)
1262 *ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
1263 mtpr(0, PR_TBIA); /* invalidate translation buffer */
1264 /*
1265 * set up QBUS map registers for DMA
1266 */
1267 DMAheader[unit]->QBAreg =
1268 uballoc(uh, (caddr_t)DMAheader[unit], DMAbuf_size, 0);
1269 if (DMAheader[unit]->QBAreg == 0)
1270 printf("qd%d: qdioctl: QBA setup error\n", unit);
1271 Qbus_unmap[unit] = DMAheader[unit]->QBAreg;
1272 DMAheader[unit]->QBAreg &= 0x3FFFF;
1273 /*
1274 * return I/O buf adr
1275 */
1276 *(int *)datap = (int) DMAheader[unit];
1277 break;
1278 #endif
1279
1280 case QD_MAPSCROLL:
1281 /*
1282 * map the shared scroll param area and enable scroll interpts
1283 */
1284 qdflags[unit].mapped |= MAPSCR;
1285 ptep = (int *) ((VTOP(scroll[unit]) * 4)
1286 + (mfpr(PR_SBR) | 0x80000000));
1287 /*
1288 * allow user write to scroll area
1289 */
1290 *ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
1291 mtpr(0, PR_TBIA); /* invalidate translation buf */
1292 scroll[unit]->status = 0;
1293 adder = (struct adder *) qdmap[unit].adder;
1294 qdflags[unit].adder_ie |= FRAME_SYNC;
1295 adder->interrupt_enable = qdflags[unit].adder_ie;
1296 *(int *)datap = (int) scroll[unit]; /* return scroll area */
1297 break;
1298
1299 case QD_UNMAPSCROLL:
1300 /*
1301 * unmap shared scroll param area and disable scroll intrpts
1302 */
1303 if (qdflags[unit].mapped & MAPSCR) {
1304 qdflags[unit].mapped &= ~MAPSCR;
1305 ptep = (int *) ((VTOP(scroll[unit]) * 4)
1306 + (mfpr(PR_SBR) | 0x80000000));
1307 /*
1308 * re-protect 512 scroll param area
1309 */
1310 *ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V;
1311 mtpr(0, PR_TBIA); /* smash CPU's translation buf */
1312 adder = (struct adder *) qdmap[unit].adder;
1313 qdflags[unit].adder_ie &= ~FRAME_SYNC;
1314 adder->interrupt_enable = qdflags[unit].adder_ie;
1315 }
1316 break;
1317
1318 case QD_MAPCOLOR:
1319 /*
1320 * map shared color map write buf and turn on vsync intrpt
1321 */
1322 qdflags[unit].mapped |= MAPCOLOR;
1323 ptep = (int *) ((VTOP(color_buf[unit]) * 4)
1324 + (mfpr(PR_SBR) | 0x80000000));
1325 /*
1326 * allow user write to color map write buffer
1327 */
1328 *ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V; ptep++;
1329 *ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
1330 mtpr(0, PR_TBIA); /* clr CPU translation buf */
1331 adder = (struct adder *) qdmap[unit].adder;
1332 qdflags[unit].adder_ie |= VSYNC;
1333 adder->interrupt_enable = qdflags[unit].adder_ie;
1334 /*
1335 * return color area address
1336 */
1337 *(int *)datap = (int) color_buf[unit];
1338 break;
1339
1340 case QD_UNMAPCOLOR:
1341 /*
1342 * unmap shared color map write buffer and kill VSYNC intrpts
1343 */
1344 if (qdflags[unit].mapped & MAPCOLOR) {
1345 qdflags[unit].mapped &= ~MAPCOLOR;
1346 ptep = (int *) ((VTOP(color_buf[unit]) * 4)
1347 + (mfpr(PR_SBR) | 0x80000000));
1348 /*
1349 * re-protect color map write buffer
1350 */
1351 *ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V; ptep++;
1352 *ptep = (*ptep & ~PG_PROT) | PG_KW | PG_V;
1353 mtpr(0, PR_TBIA);
1354 adder = (struct adder *) qdmap[unit].adder;
1355 qdflags[unit].adder_ie &= ~VSYNC;
1356 adder->interrupt_enable = qdflags[unit].adder_ie;
1357 }
1358 break;
1359
1360 case QD_MAPEVENT:
1361 /*
1362 * give user write access to the event queue
1363 */
1364 qdflags[unit].mapped |= MAPEQ;
1365 ptep = (int *) ((VTOP(eq_header[unit]) * 4)
1366 + (mfpr(PR_SBR) | 0x80000000));
1367 /*
1368 * allow user write to 1K event queue
1369 */
1370 *ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V; ptep++;
1371 *ptep = (*ptep & ~PG_PROT) | PG_RW | PG_V;
1372 mtpr(0, PR_TBIA); /* clr CPU translation buf */
1373 /*
1374 * return event queue address
1375 */
1376 *(int *)datap = (int)eq_header[unit];
1377 break;
1378
1379 case QD_PRGKBD:
1380 /*
1381 * pass caller's programming commands to LK201
1382 */
1383 duart = (struct duart *)qdmap[unit].duart;
1384 cmdbuf = (struct prgkbd *)datap; /* pnt to kbd cmd buf */
1385 /*
1386 * send command
1387 */
1388 for (i = 1000; i > 0; --i) {
1389 if (duart->statusA&XMT_RDY) {
1390 duart->dataA = cmdbuf->cmd;
1391 break;
1392 }
1393 }
1394 if (i == 0) {
1395 printf("qd%d: qdioctl: timeout on XMT_RDY [1]\n", unit);
1396 break;
1397 }
1398 /*
1399 * send param1?
1400 */
1401 if (cmdbuf->cmd & LAST_PARAM)
1402 break;
1403 for (i = 1000; i > 0; --i) {
1404 if (duart->statusA&XMT_RDY) {
1405 duart->dataA = cmdbuf->param1;
1406 break;
1407 }
1408 }
1409 if (i == 0) {
1410 printf("qd%d: qdioctl: timeout on XMT_RDY [2]\n", unit);
1411 break;
1412 }
1413 /*
1414 * send param2?
1415 */
1416 if (cmdbuf->param1 & LAST_PARAM)
1417 break;
1418 for (i = 1000; i > 0; --i) {
1419 if (duart->statusA&XMT_RDY) {
1420 duart->dataA = cmdbuf->param2;
1421 break;
1422 }
1423 }
1424 if (i == 0) {
1425 printf("qd%d: qdioctl: timeout on XMT_RDY [3]\n", unit);
1426 break;
1427 }
1428 break;
1429
1430 case QD_PRGMOUSE:
1431 /*
1432 * pass caller's programming commands to the mouse
1433 */
1434 duart = (struct duart *) qdmap[unit].duart;
1435 for (i = 1000; i > 0; --i) {
1436 if (duart->statusB&XMT_RDY) {
1437 duart->dataB = *datap;
1438 break;
1439 }
1440 }
1441 if (i == 0) {
1442 printf("qd%d: qdioctl: timeout on XMT_RDY [4]\n", unit);
1443 }
1444 break;
1445
1446 case QD_RDCONFIG:
1447 /*
1448 * get QDSS configuration word and return it
1449 */
1450 *(short *)datap = qdflags[unit].config;
1451 break;
1452
1453 case QD_KERN_LOOP:
1454 case QD_KERN_UNLOOP:
1455 /*
1456 * vestige from ultrix. BSD uses TIOCCONS to redirect
1457 * kernel console output.
1458 */
1459 break;
1460
1461 case QD_PRGTABLET:
1462 /*
1463 * program the tablet
1464 */
1465 duart = (struct duart *) qdmap[unit].duart;
1466 for (i = 1000; i > 0; --i) {
1467 if (duart->statusB&XMT_RDY) {
1468 duart->dataB = *datap;
1469 break;
1470 }
1471 }
1472 if (i == 0) {
1473 printf("qd%d: qdioctl: timeout on XMT_RDY [5]\n", unit);
1474 }
1475 break;
1476
1477 case QD_PRGTABRES:
1478 /*
1479 * program the tablet report resolution factor
1480 */
1481 qdflags[unit].tab_res = *(short *)datap;
1482 break;
1483
1484 default:
1485 /*
1486 * service tty ioctl's
1487 */
1488 if (!(minor_dev & 0x02)) {
1489 tp = qd_tty[minor_dev];
1490 error =
1491
1492 (*tp->t_linesw->l_ioctl)(tp, cmd, datap, flags, p);
1493 if (error >= 0) {
1494 return(error);
1495 }
1496 error = ttioctl(tp, cmd, datap, flags, p);
1497 if (error >= 0) {
1498 return(error);
1499 }
1500 }
1501 break;
1502 }
1503
1504 return(0);
1505
1506 } /* qdioctl */
1507
1508
1509 int
1510 qdpoll(dev, events, p)
1511 dev_t dev;
1512 int events;
1513 struct proc *p;
1514 {
1515 int s;
1516 int unit;
1517 struct tty *tp;
1518 u_int minor_dev = minor(dev);
1519 int revents = 0;
1520
1521 s = spl5();
1522 unit = minor_dev >> 2;
1523
1524 if ((minor_dev & 0x03) == 2) {
1525 /*
1526 * This is a graphics device, so check for events.
1527 */
1528
1529 if (events & (POLLIN | POLLRDNORM))
1530 if(!(ISEMPTY(eq_header[unit])))
1531 revents |= events & (POLLIN | POLLRDNORM);
1532
1533 if (events & (POLLOUT | POLLWRNORM))
1534 if (DMA_ISEMPTY(DMAheader[unit]))
1535 revents |= events & (POLLOUT | POLLWRNORM);
1536
1537 if (revents == 0) {
1538 if (events & (POLLIN | POLLRDNORM))
1539 selrecord(p, &qdrsel[unit]);
1540
1541 if (events & (POLLOUT | POLLWRNORM))
1542 selrecord(p, &qdrsel[unit]);
1543 }
1544 } else {
1545 /*
1546 * this is a tty device
1547 */
1548 tp = qd_tty[minor_dev];
1549 revents = (*tp->t_linesw->l_poll)(tp, events, p);
1550 }
1551
1552 splx(s);
1553 return (revents);
1554 } /* qdpoll() */
1555
1556 static void
1557 filt_qdrdetach(struct knote *kn)
1558 {
1559 dev_t dev = (u_long) kn->kn_hook;
1560 u_int minor_dev = minor(dev);
1561 int unit = minor_dev >> 2;
1562 int s;
1563
1564 s = spl5();
1565 SLIST_REMOVE(&qdrsel[unit].si_klist, kn, knote, kn_selnext);
1566 splx(s);
1567 }
1568
1569 static int
1570 filt_qdread(struct knote *kn, long hint)
1571 {
1572 dev_t dev = (u_long) kn->kn_hook;
1573 u_int minor_dev = minor(dev);
1574 int unit = minor_dev >> 2;
1575
1576 if (ISEMPTY(eq_header[unit]))
1577 return (0);
1578
1579 kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */
1580 return (1);
1581 }
1582
1583 static int
1584 filt_qdwrite(struct knote *kn, long hint)
1585 {
1586 dev_t dev = (u_long) kn->kn_hook;
1587 u_int minor_dev = minor(dev);
1588 int unit = minor_dev >> 2;
1589
1590 if (! DMA_ISEMPTY(DMAheader[unit]))
1591 return (0);
1592
1593 kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */
1594 return (1);
1595 }
1596
1597 static const struct filterops qdread_filtops =
1598 { 1, NULL, filt_qdrdetach, filt_qdread };
1599
1600 static const struct filterops qdwrite_filtops =
1601 { 1, NULL, filt_qdrdetach, filt_qdwrite };
1602
1603 int
1604 qdkqfilter(dev_t dev, struct knote *kn)
1605 {
1606 struct klist *klist;
1607 u_int minor_dev = minor(dev);
1608 int s, unit = minor_dev >> 2;
1609
1610 if ((minor_dev & 0x03) != 2) {
1611 /* TTY device. */
1612 return (ttykqfilter(dev, kn));
1613 }
1614
1615 switch (kn->kn_filter) {
1616 case EVFILT_READ:
1617 klist = &qdrsel[unit].si_klist;
1618 kn->kn_fop = &qdread_filtops;
1619 break;
1620
1621 case EVFILT_WRITE:
1622 klist = &qdrsel[unit].si_klist;
1623 kn->kn_fop = &qdwrite_filtops;
1624 break;
1625
1626 default:
1627 return (1);
1628 }
1629
1630 kn->kn_hook = (caddr_t)(u_long) dev;
1631
1632 s = spl5();
1633 SLIST_INSERT_HEAD(klist, kn, kn_selnext);
1634 splx(s);
1635
1636 return (0);
1637 }
1638
1639 void qd_strategy(struct buf *bp);
1640
1641 /*ARGSUSED*/
1642 int
1643 qdwrite(dev, uio, flag)
1644 dev_t dev;
1645 struct uio *uio;
1646 {
1647 struct tty *tp;
1648 int minor_dev;
1649 int unit;
1650
1651 minor_dev = minor(dev);
1652 unit = (minor_dev >> 2) & 0x07;
1653
1654 if (((minor_dev&0x03) != 0x02) && (qdflags[unit].inuse&CONS_DEV)) {
1655 /*
1656 * this is the console...
1657 */
1658 tp = qd_tty[minor_dev];
1659 return ((*tp->t_linesw->l_write)(tp, uio, flag));
1660 } else if (qdflags[unit].inuse & GRAPHIC_DEV) {
1661 /*
1662 * this is a DMA xfer from user space
1663 */
1664 return (physio(qd_strategy, &qdbuf[unit],
1665 dev, B_WRITE, minphys, uio));
1666 }
1667 return (ENXIO);
1668 }
1669
1670 /*ARGSUSED*/
1671 int
1672 qdread(dev, uio, flag)
1673 dev_t dev;
1674 struct uio *uio;
1675 {
1676 struct tty *tp;
1677 int minor_dev;
1678 int unit;
1679
1680 minor_dev = minor(dev);
1681 unit = (minor_dev >> 2) & 0x07;
1682
1683 if ((minor_dev & 0x03) != 0x02 && qdflags[unit].inuse & CONS_DEV) {
1684 /*
1685 * this is the console
1686 */
1687 tp = qd_tty[minor_dev];
1688 return ((*tp->t_linesw->l_read)(tp, uio, flag));
1689 } else if (qdflags[unit].inuse & GRAPHIC_DEV) {
1690 /*
1691 * this is a bitmap-to-processor xfer
1692 */
1693 return (physio(qd_strategy, &qdbuf[unit],
1694 dev, B_READ, minphys, uio));
1695 }
1696 return (ENXIO);
1697 }
1698
1699 /***************************************************************
1700 *
1701 * qd_strategy()... strategy routine to do DMA
1702 *
1703 ***************************************************************/
1704
1705 void
1706 qd_strategy(bp)
1707 struct buf *bp;
1708 {
1709 volatile struct dga *dga;
1710 volatile struct adder *adder;
1711 int unit;
1712 int QBAreg;
1713 int s;
1714 int cookie;
1715 struct uba_softc *uh;
1716
1717 unit = (minor(bp->b_dev) >> 2) & 0x07;
1718
1719 uh = (struct uba_softc *)
1720 (((struct device *)(qd_cd.cd_devs[unit]))->dv_parent);
1721
1722 /*
1723 * init pointers
1724 */
1725 dga = (struct dga *) qdmap[unit].dga;
1726 panic("qd_strategy");
1727 #ifdef notyet
1728 if ((QBAreg = ubasetup(uh, bp, 0)) == 0) {
1729 printf("qd%d: qd_strategy: QBA setup error\n", unit);
1730 goto STRAT_ERR;
1731 }
1732 #endif
1733 s = spl5();
1734 qdflags[unit].user_dma = -1;
1735 dga->csr |= DMA_IE;
1736 cookie = QBAreg & 0x3FFFF;
1737 dga->adrs_lo = (short) cookie;
1738 dga->adrs_hi = (short) (cookie >> 16);
1739 dga->bytcnt_lo = (short) bp->b_bcount;
1740 dga->bytcnt_hi = (short) (bp->b_bcount >> 16);
1741
1742 while (qdflags[unit].user_dma) {
1743 (void) tsleep(&qdflags[unit].user_dma, QSPRIOR,
1744 "qdstrat", 0);
1745 }
1746 splx(s);
1747 #ifdef notyet
1748 ubarelse(uh, &QBAreg);
1749 #endif
1750 if (!(dga->csr & DMA_ERR)) {
1751 biodone(bp);
1752 return;
1753 }
1754
1755 /* STRAT_ERR: */
1756 adder = (struct adder *) qdmap[unit].adder;
1757 adder->command = CANCEL; /* cancel adder activity */
1758 dga->csr &= ~DMA_IE;
1759 dga->csr &= ~0x0600; /* halt DMA (reset fifo) */
1760 dga->csr |= DMA_ERR; /* clear error condition */
1761 bp->b_flags |= B_ERROR; /* flag an error to physio() */
1762
1763 /*
1764 * if DMA was running, flush spurious intrpt
1765 */
1766 if (dga->bytcnt_lo != 0) {
1767 dga->bytcnt_lo = 0;
1768 dga->bytcnt_hi = 0;
1769 DMA_SETIGNORE(DMAheader[unit]);
1770 dga->csr |= DMA_IE;
1771 }
1772 biodone(bp);
1773 } /* qd_strategy */
1774
1775
1776 /*
1777 * Start output to the console screen
1778 */
1779 void qdstart(tp)
1780 struct tty *tp;
1781 {
1782 int which_unit, unit, c;
1783 int s;
1784
1785 unit = minor(tp->t_dev);
1786 which_unit = (unit >> 2) & 0x3;
1787 unit &= 0x03;
1788
1789 s = spl5();
1790
1791 /*
1792 * If it's currently active, or delaying, no need to do anything.
1793 */
1794 if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
1795 goto out;
1796
1797 /*
1798 * Display chars until the queue is empty.
1799 * Drop input from anything but the console
1800 * device on the floor.
1801 *
1802 * XXX - this loop is done at spltty.
1803 *
1804 */
1805 while (tp->t_outq.c_cc) {
1806 c = getc(&tp->t_outq);
1807 if (unit == 0)
1808 blitc(which_unit, (u_char)c);
1809 }
1810 /*
1811 * If there are sleepers, and output has drained below low
1812 * water mark, wake up the sleepers.
1813 */
1814 if (tp->t_outq.c_cc <= tp->t_lowat) {
1815 if (tp->t_state & TS_ASLEEP){
1816 tp->t_state &= ~TS_ASLEEP;
1817 wakeup((caddr_t) &tp->t_outq);
1818 }
1819 }
1820
1821 tp->t_state &= ~TS_BUSY;
1822
1823 out:
1824 splx(s);
1825
1826 } /* qdstart */
1827
1828 /*ARGSUSED*/
1829 void
1830 qdstop(tp, flag)
1831 struct tty *tp;
1832 int flag;
1833 {
1834 int s;
1835
1836 s = spl5(); /* block intrpts during state modification */
1837 if (tp->t_state & TS_BUSY) {
1838 if ((tp->t_state & TS_TTSTOP) == 0)
1839 tp->t_state |= TS_FLUSH;
1840 else
1841 tp->t_state &= ~TS_BUSY;
1842 }
1843 splx(s);
1844 }
1845
1846 /*
1847 * Output a character to the QDSS screen
1848 */
1849 void
1850 blitc(unit, chr)
1851 int unit;
1852 u_char chr;
1853 {
1854 volatile struct adder *adder;
1855 volatile struct dga *dga;
1856 int i;
1857 int nograph = !(qdflags[unit].inuse&GRAPHIC_DEV);
1858 static short inescape[NQD];
1859
1860 adder = (struct adder *)qdmap[unit].adder;
1861 dga = (struct dga *) qdmap[unit].dga;
1862 /*
1863 * BSD comment: this (&=0177) defeats the extended character
1864 * set code for the glass tty, but if i had the time i would
1865 * spend it ripping out the code completely. This driver
1866 * is too big for its own good.
1867 */
1868 chr &= 0177;
1869 /*
1870 * Cursor addressing (so vi will work).
1871 * Decode for "\E=%.%." cursor motion description.
1872 * Corresponds to type "qdcons" in /etc/termcap:
1873 *
1874 * qd|qdss|qdcons|qdss glass tty (4.4 BSD):\
1875 * :am:do=^J:le=^H:bs:cm=\E=%.%.:cl=1^Z:co#128:li#57::nd=^L:up=^K:
1876 *
1877 */
1878 if (inescape[unit] && nograph) {
1879 switch (inescape[unit]++) {
1880 case 1:
1881 if (chr != '=') {
1882 /* abort escape sequence */
1883 inescape[unit] = 0;
1884 blitc(unit, chr);
1885 }
1886 return;
1887 case 2:
1888 /* position row */
1889 cursor[unit].y = CHAR_HEIGHT * chr;
1890 if (cursor[unit].y > 863 - CHAR_HEIGHT)
1891 cursor[unit].y = 863 - CHAR_HEIGHT;
1892 dga->y_cursor = TRANY(cursor[unit].y);
1893 return;
1894 case 3:
1895 /* position column */
1896 cursor[unit].x = CHAR_WIDTH * chr;
1897 if (cursor[unit].x > 1024 - CHAR_WIDTH)
1898 cursor[unit].x = 1023 - CHAR_WIDTH;
1899 dga->x_cursor = TRANX(cursor[unit].x);
1900 inescape[unit] = 0;
1901 return;
1902 default:
1903 inescape[unit] = 0;
1904 blitc(unit, chr);
1905 }
1906 }
1907
1908 switch (chr) {
1909 case '\r': /* return char */
1910 cursor[unit].x = 0;
1911 if (nograph)
1912 dga->x_cursor = TRANX(cursor[unit].x);
1913 return;
1914
1915 case '\t': /* tab char */
1916 for (i = 8 - ((cursor[unit].x >> 3) & 0x07); i > 0; --i) {
1917 blitc(unit, ' ');
1918 }
1919 return;
1920
1921 case '\n': /* line feed char */
1922 if ((cursor[unit].y += CHAR_HEIGHT) > (863 - CHAR_HEIGHT)) {
1923 if (nograph) {
1924 cursor[unit].y -= CHAR_HEIGHT;
1925 scroll_up(adder);
1926 } else
1927 cursor[unit].y = 0;
1928 }
1929 if (nograph)
1930 dga->y_cursor = TRANY(cursor[unit].y);
1931 return;
1932
1933 case '\b': /* backspace char */
1934 if (cursor[unit].x > 0) {
1935 cursor[unit].x -= CHAR_WIDTH;
1936 if (nograph)
1937 dga->x_cursor = TRANX(cursor[unit].x);
1938 }
1939 return;
1940 case CTRL('k'): /* cursor up */
1941 if (nograph && cursor[unit].y > 0) {
1942 cursor[unit].y -= CHAR_HEIGHT;
1943 dga->y_cursor = TRANY(cursor[unit].y);
1944 }
1945 return;
1946
1947 case CTRL('^'): /* home cursor */
1948 if (nograph) {
1949 cursor[unit].x = 0;
1950 dga->x_cursor = TRANX(cursor[unit].x);
1951 cursor[unit].y = 0;
1952 dga->y_cursor = TRANY(cursor[unit].y);
1953 }
1954 return;
1955
1956 case CTRL('l'): /* cursor right */
1957 if (nograph && cursor[unit].x < 1023 - CHAR_WIDTH) {
1958 cursor[unit].x += CHAR_WIDTH;
1959 dga->x_cursor = TRANX(cursor[unit].x);
1960 }
1961 return;
1962
1963 case CTRL('z'): /* clear screen */
1964 if (nograph) {
1965 setup_dragon(unit);
1966 clear_qd_screen(unit);
1967 /* home cursor - termcap seems to assume this */
1968 cursor[unit].x = 0;
1969 dga->x_cursor = TRANX(cursor[unit].x);
1970 cursor[unit].y = 0;
1971 dga->y_cursor = TRANY(cursor[unit].y);
1972 }
1973 return;
1974
1975 case '\033': /* start escape sequence */
1976 if (nograph)
1977 inescape[unit] = 1;
1978 return;
1979
1980 default:
1981 if ((chr < ' ') || (chr > '~'))
1982 return;
1983 }
1984 /*
1985 * setup VIPER operand control registers
1986 */
1987 write_ID(adder, CS_UPDATE_MASK, 0x0001); /* select plane #0 */
1988 write_ID(adder, SRC1_OCR_B,
1989 EXT_NONE | INT_SOURCE | ID | BAR_SHIFT_DELAY);
1990 write_ID(adder, CS_UPDATE_MASK, 0x00FE); /* select other planes */
1991 write_ID(adder, SRC1_OCR_B,
1992 EXT_SOURCE | INT_NONE | NO_ID | BAR_SHIFT_DELAY);
1993 write_ID(adder, CS_UPDATE_MASK, 0x00FF); /* select all planes */
1994 write_ID(adder, DST_OCR_B,
1995 EXT_NONE | INT_NONE | NO_ID | NO_BAR_SHIFT_DELAY);
1996 write_ID(adder, MASK_1, 0xFFFF);
1997 write_ID(adder, VIPER_Z_LOAD | FOREGROUND_COLOR_Z, 1);
1998 write_ID(adder, VIPER_Z_LOAD | BACKGROUND_COLOR_Z, 0);
1999 adder->x_clip_min = 0;
2000 adder->x_clip_max = 1024;
2001 adder->y_clip_min = 0;
2002 adder->y_clip_max = 864;
2003 /*
2004 * load DESTINATION origin and vectors
2005 */
2006 adder->fast_dest_dy = 0;
2007 adder->slow_dest_dx = 0;
2008 adder->error_1 = 0;
2009 adder->error_2 = 0;
2010 adder->rasterop_mode = DST_WRITE_ENABLE | NORMAL;
2011 (void)wait_status(adder, RASTEROP_COMPLETE);
2012 adder->destination_x = cursor[unit].x;
2013 adder->fast_dest_dx = CHAR_WIDTH;
2014 adder->destination_y = cursor[unit].y;
2015 adder->slow_dest_dy = CHAR_HEIGHT;
2016 /*
2017 * load SOURCE origin and vectors
2018 */
2019 if ((chr - ' ') > (CHARS - 1)) {
2020 printf("Invalid character (x)%x in blitc\n",chr);
2021 chr = ' ';
2022 }
2023 /*
2024 * X position is modulo the number of characters per line
2025 */
2026 adder->source_1_x = FONT_X +
2027 (((chr - ' ') % (MAX_SCREEN_X/CHAR_WIDTH)) * CHAR_WIDTH);
2028 /*
2029 * Point to either first or second row
2030 */
2031 adder->source_1_y = 2048 - 15 *
2032 (((chr - ' ')/(MAX_SCREEN_X/CHAR_WIDTH)) + 1);
2033 adder->source_1_dx = CHAR_WIDTH;
2034 adder->source_1_dy = CHAR_HEIGHT;
2035 write_ID(adder, LU_FUNCTION_R1, FULL_SRC_RESOLUTION | LF_SOURCE);
2036 adder->cmd = RASTEROP | OCRB | 0 | S1E | DTE;
2037 /*
2038 * update console cursor coordinates
2039 */
2040 cursor[unit].x += CHAR_WIDTH;
2041 if (nograph)
2042 dga->x_cursor = TRANX(cursor[unit].x);
2043 if (cursor[unit].x > (1024 - CHAR_WIDTH)) {
2044 blitc(unit, '\r');
2045 blitc(unit, '\n');
2046 }
2047
2048 } /* blitc */
2049
2050 /*
2051 * INTERRUPT SERVICE ROUTINES
2052 */
2053
2054 /*
2055 * Service "DMA DONE" interrupt condition
2056 */
2057
2058 static void
2059 qddint(arg)
2060 void *arg;
2061 {
2062 struct device *dv = arg;
2063 struct DMAreq_header *header;
2064 struct DMAreq *request;
2065 volatile struct dga *dga;
2066 volatile struct adder *adder;
2067 int cookie; /* DMA adrs for QDSS */
2068
2069 (void)spl4(); /* allow interval timer in */
2070
2071 /*
2072 * init pointers
2073 */
2074 header = DMAheader[dv->dv_unit]; /* register for optimization */
2075 dga = (struct dga *) qdmap[dv->dv_unit].dga;
2076 adder = (struct adder *) qdmap[dv->dv_unit].adder;
2077
2078 /*
2079 * if this interrupt flagged as bogus for interrupt flushing purposes..
2080 */
2081 if (DMA_ISIGNORE(header)) {
2082 DMA_CLRIGNORE(header);
2083 return;
2084 }
2085
2086 /*
2087 * dump a DMA hardware error message if appropriate
2088 */
2089 if (dga->csr & DMA_ERR) {
2090
2091 if (dga->csr & PARITY_ERR)
2092 printf("qd%d: qddint: DMA hardware parity fault.\n", dv->dv_unit);
2093
2094 if (dga->csr & BUS_ERR)
2095 printf("qd%d: qddint: DMA hardware bus error.\n", dv->dv_unit);
2096 }
2097
2098 /*
2099 * if this was a DMA from user space...
2100 */
2101 if (qdflags[dv->dv_unit].user_dma) {
2102 qdflags[dv->dv_unit].user_dma = 0;
2103 wakeup((caddr_t)&qdflags[dv->dv_unit].user_dma);
2104 return;
2105 }
2106
2107 /*
2108 * if we're doing DMA request queue services, field the error condition
2109 */
2110 if (dga->csr & DMA_ERR) {
2111
2112 dga->csr &= ~0x0600; /* halt DMA (reset fifo) */
2113 dga->csr |= DMA_ERR; /* clear error condition */
2114 adder->command = CANCEL; /* cancel adder activity */
2115
2116 DMA_SETERROR(header); /* flag error in header status word */
2117 DMA_CLRACTIVE(header);
2118 header->DMAreq[header->oldest].DMAdone |= HARD_ERROR;
2119 header->newest = header->oldest;
2120 header->used = 0;
2121
2122 selnotify(&qdrsel[dv->dv_unit], 0);
2123
2124 if (dga->bytcnt_lo != 0) {
2125 dga->bytcnt_lo = 0;
2126 dga->bytcnt_hi = 0;
2127 DMA_SETIGNORE(header);
2128 }
2129 return;
2130 }
2131
2132 /*
2133 * if the DMA request queue is now becoming non-full,
2134 * wakeup "select" client.
2135 */
2136 if (DMA_ISFULL(header)) {
2137 selnotify(&qdrsel[dv->dv_unit], 0);
2138 }
2139
2140 header->DMAreq[header->oldest].DMAdone |= REQUEST_DONE;
2141 QDlast_DMAtype = header->DMAreq[header->oldest].DMAtype;
2142
2143 /* check for unexpected interrupt */
2144 if (DMA_ISEMPTY(header))
2145 return;
2146
2147 DMA_GETEND(header); /* update request queue indices */
2148
2149 /*
2150 * if no more DMA pending, wake up "select" client and exit
2151 */
2152 if (DMA_ISEMPTY(header)) {
2153 selnotify(&qdrsel[dv->dv_unit], 0);
2154 DMA_CLRACTIVE(header); /* flag DMA done */
2155 return;
2156 }
2157
2158 /*
2159 * initiate next DMA xfer
2160 */
2161 request = DMA_GETBEGIN(header);
2162 if (request->DMAtype != QDlast_DMAtype) {
2163 dga->csr &= ~0x0600; /* halt DMA (reset fifo) */
2164 adder->command = CANCEL; /* cancel adder activity */
2165 }
2166
2167
2168 switch (request->DMAtype) {
2169
2170 case DISPLIST:
2171 if (request->DMAtype != QDlast_DMAtype) {
2172 dga->csr |= DL_ENB;
2173 dga->csr &= ~(BTOP_ENB | BYTE_DMA);
2174 }
2175 break;
2176
2177 case PTOB:
2178 if (request->DMAtype != QDlast_DMAtype) {
2179 if (request->DMAdone & BYTE_PACK)
2180 dga->csr |= (PTOB_ENB | BYTE_DMA);
2181 else {
2182 dga->csr |= PTOB_ENB;
2183 dga->csr &= ~BYTE_DMA;
2184 }
2185 }
2186 break;
2187
2188 case BTOP:
2189 if (request->DMAtype != QDlast_DMAtype) {
2190 if (request->DMAdone & BYTE_PACK) {
2191 dga->csr &= ~DL_ENB;
2192 dga->csr |= (BTOP_ENB | BYTE_DMA);
2193 }
2194 else {
2195 dga->csr |= BTOP_ENB;
2196 dga->csr &= ~(BYTE_DMA | DL_ENB);
2197 }
2198 }
2199 break;
2200 default:
2201 printf("qd%d: qddint: illegal DMAtype parameter.\n", dv->dv_unit);
2202 DMA_CLRACTIVE(header); /* flag DMA done */
2203 return;
2204 }
2205
2206 if (request->DMAdone & COUNT_ZERO) {
2207 dga->csr &= ~SET_DONE_FIFO;
2208 }
2209 else if (request->DMAdone & FIFO_EMPTY) {
2210 dga->csr |= SET_DONE_FIFO;
2211 }
2212
2213 if (request->DMAdone & WORD_PACK)
2214 dga->csr &= ~BYTE_DMA;
2215 else if (request->DMAdone & BYTE_PACK)
2216 dga->csr |= BYTE_DMA;
2217
2218 dga->csr |= DMA_IE;
2219 QDlast_DMAtype = request->DMAtype;
2220
2221 cookie = ((int)request->bufp - (int)header) + (int)header->QBAreg;
2222
2223 dga->adrs_lo = (short) cookie;
2224 dga->adrs_hi = (short) (cookie >> 16);
2225
2226 dga->bytcnt_lo = (short) request->length;
2227 dga->bytcnt_hi = (short) (request->length >> 16);
2228
2229 return;
2230 }
2231
2232 /*
2233 * ADDER interrupt service routine
2234 */
2235 static void
2236 qdaint(arg)
2237 void *arg;
2238 {
2239 struct device *dv = arg;
2240 volatile struct adder *adder;
2241 struct color_buf *cbuf;
2242 int i;
2243 struct rgb *rgbp;
2244 volatile short *red;
2245 volatile short *green;
2246 volatile short *blue;
2247
2248 (void)spl4(); /* allow interval timer in */
2249
2250 adder = (struct adder *) qdmap[dv->dv_unit].adder;
2251
2252 /*
2253 * service the vertical blank interrupt (VSYNC bit) by loading
2254 * any pending color map load request
2255 */
2256 if (adder->status & VSYNC) {
2257 adder->status &= ~VSYNC; /* clear the interrupt */
2258 cbuf = color_buf[dv->dv_unit];
2259 if (cbuf->status & LOAD_COLOR_MAP) {
2260
2261 red = (short *) qdmap[dv->dv_unit].red;
2262 green = (short *) qdmap[dv->dv_unit].green;
2263 blue = (short *) qdmap[dv->dv_unit].blue;
2264
2265 for (i = cbuf->count, rgbp = cbuf->rgb;
2266 --i >= 0; rgbp++) {
2267 red[rgbp->offset] = (short) rgbp->red;
2268 green[rgbp->offset] = (short) rgbp->green;
2269 blue[rgbp->offset] = (short) rgbp->blue;
2270 }
2271
2272 cbuf->status &= ~LOAD_COLOR_MAP;
2273 }
2274 }
2275
2276 /*
2277 * service the scroll interrupt (FRAME_SYNC bit)
2278 */
2279 if (adder->status & FRAME_SYNC) {
2280 adder->status &= ~FRAME_SYNC; /* clear the interrupt */
2281
2282 if (scroll[dv->dv_unit]->status & LOAD_REGS) {
2283
2284 for (i = 1000, adder->status = 0; i > 0 &&
2285 !(adder->status&ID_SCROLL_READY); --i)
2286 ;
2287
2288 if (i == 0) {
2289 printf("qd%d: qdaint: timeout on ID_SCROLL_READY\n",
2290 qd);
2291 return;
2292 }
2293
2294 adder->ID_scroll_data = scroll[dv->dv_unit]->viper_constant;
2295 adder->ID_scroll_command = ID_LOAD | SCROLL_CONSTANT;
2296
2297 adder->y_scroll_constant =
2298 scroll[dv->dv_unit]->y_scroll_constant;
2299 adder->y_offset_pending = scroll[dv->dv_unit]->y_offset;
2300
2301 if (scroll[dv->dv_unit]->status & LOAD_INDEX) {
2302
2303 adder->x_index_pending =
2304 scroll[dv->dv_unit]->x_index_pending;
2305 adder->y_index_pending =
2306 scroll[dv->dv_unit]->y_index_pending;
2307 }
2308
2309 scroll[dv->dv_unit]->status = 0x00;
2310 }
2311 }
2312 }
2313
2314 /*
2315 * DUART input interrupt service routine
2316 *
2317 * XXX - this routine should be broken out - it is essentially
2318 * straight line code.
2319 */
2320
2321 static void
2322 qdiint(arg)
2323 void *arg;
2324 {
2325 struct device *dv = arg;
2326 struct _vs_event *event;
2327 struct qdinput *eqh;
2328 volatile struct dga *dga;
2329 volatile struct duart *duart;
2330 struct mouse_report *new_rep;
2331 struct tty *tp;
2332 u_short chr;
2333 u_short status;
2334 u_short data;
2335 u_short key;
2336 char do_wakeup = 0; /* flag to do a select wakeup call */
2337 char a, b, c; /* mouse button test variables */
2338
2339 (void)spl4(); /* allow interval timer in */
2340
2341 eqh = eq_header[dv->dv_unit]; /* optimized as a register */
2342 new_rep = ¤t_rep[dv->dv_unit];
2343 duart = (struct duart *) qdmap[dv->dv_unit].duart;
2344
2345 /*
2346 * if the graphic device is turned on..
2347 */
2348 if (qdflags[dv->dv_unit].inuse & GRAPHIC_DEV) {
2349 /*
2350 * empty DUART
2351 */
2352 while (duart->statusA&RCV_RDY || duart->statusB&RCV_RDY) {
2353 /*
2354 * pick up LK-201 input (if any)
2355 */
2356 if (duart->statusA&RCV_RDY) {
2357
2358 /* if error condition, then reset it */
2359
2360 if (duart->statusA&0x70) {
2361 duart->cmdA = 0x40;
2362 continue;
2363 }
2364
2365 /* event queue full now? (overflow condition) */
2366
2367 if (ISFULL(eqh) == TRUE) {
2368 printf(
2369 "qd%d: qdiint: event queue overflow\n",
2370 qd);
2371 break;
2372 }
2373
2374 /*
2375 * Check for various keyboard errors */
2376
2377 key = duart->dataA & 0xFF;
2378
2379 if (key==LK_POWER_ERROR ||
2380 key==LK_KDOWN_ERROR ||
2381 key == LK_INPUT_ERROR ||
2382 key == LK_OUTPUT_ERROR) {
2383 printf(
2384 "qd%d: qdiint: keyboard error, code = %x\n",
2385 qd,key);
2386 return;
2387 }
2388
2389 if (key < LK_LOWEST)
2390 return;
2391
2392 ++do_wakeup; /* request a select wakeup call */
2393
2394 event = PUTBEGIN(eqh);
2395 PUTEND(eqh);
2396
2397 event->vse_key = key;
2398 event->vse_key &= 0x00FF;
2399 event->vse_x = eqh->curs_pos.x;
2400 event->vse_y = eqh->curs_pos.y;
2401 event->vse_time = TOY;
2402 event->vse_type = VSE_BUTTON;
2403 event->vse_direction = VSE_KBTRAW;
2404 event->vse_device = VSE_DKB;
2405 }
2406
2407 /*
2408 * pick up the mouse input (if any) */
2409
2410 if ((status = duart->statusB) & RCV_RDY &&
2411 qdflags[dv->dv_unit].pntr_id == MOUSE_ID) {
2412
2413 if (status & 0x70) {
2414 duart->cmdB = 0x40;
2415 continue;
2416 }
2417
2418 /* event queue full now? (overflow condition) */
2419
2420 if (ISFULL(eqh) == TRUE) {
2421 printf(
2422 "qd%d: qdiint: event queue overflow\n",
2423 qd);
2424 break;
2425 }
2426
2427 data = duart->dataB; /* get report byte */
2428 ++new_rep->bytcnt; /* bump report byte count */
2429
2430 /*
2431 * if 1st byte of report.. */
2432
2433 if ( data & START_FRAME) {
2434 new_rep->state = data;
2435 if (new_rep->bytcnt > 1) {
2436 /* start of new frame */
2437 new_rep->bytcnt = 1;
2438 /* ..continue looking */
2439 continue;
2440 }
2441 }
2442
2443 /*
2444 * if 2nd byte of report.. */
2445
2446 else if (new_rep->bytcnt == 2) {
2447 new_rep->dx = data & 0x00FF;
2448 }
2449
2450 /*
2451 * if 3rd byte of report, load input event queue */
2452
2453 else if (new_rep->bytcnt == 3) {
2454
2455 new_rep->dy = data & 0x00FF;
2456 new_rep->bytcnt = 0;
2457
2458 /*
2459 * if mouse position has changed.. */
2460
2461 if (new_rep->dx != 0 || new_rep->dy != 0) {
2462
2463 /*
2464 * calculate acceleration factor, if needed */
2465
2466 if (qdflags[dv->dv_unit].curs_acc > ACC_OFF) {
2467
2468 if (qdflags[dv->dv_unit].curs_thr <= new_rep->dx)
2469 new_rep->dx +=
2470 (new_rep->dx - qdflags[dv->dv_unit].curs_thr)
2471 * qdflags[dv->dv_unit].curs_acc;
2472
2473 if (qdflags[dv->dv_unit].curs_thr <= new_rep->dy)
2474 new_rep->dy +=
2475 (new_rep->dy - qdflags[dv->dv_unit].curs_thr)
2476 * qdflags[dv->dv_unit].curs_acc;
2477 }
2478
2479 /*
2480 * update cursor position coordinates */
2481
2482 if (new_rep->state & X_SIGN) {
2483 eqh->curs_pos.x += new_rep->dx;
2484 if (eqh->curs_pos.x > 1023)
2485 eqh->curs_pos.x = 1023;
2486 }
2487 else {
2488 eqh->curs_pos.x -= new_rep->dx;
2489 if (eqh->curs_pos.x < -15)
2490 eqh->curs_pos.x = -15;
2491 }
2492
2493 if (new_rep->state & Y_SIGN) {
2494 eqh->curs_pos.y -= new_rep->dy;
2495 if (eqh->curs_pos.y < -15)
2496 eqh->curs_pos.y = -15;
2497 }
2498 else {
2499 eqh->curs_pos.y += new_rep->dy;
2500 if (eqh->curs_pos.y > 863)
2501 eqh->curs_pos.y = 863;
2502 }
2503
2504 /*
2505 * update cursor screen position */
2506
2507 dga = (struct dga *) qdmap[dv->dv_unit].dga;
2508 dga->x_cursor = TRANX(eqh->curs_pos.x);
2509 dga->y_cursor = TRANY(eqh->curs_pos.y);
2510
2511 /*
2512 * if cursor is in the box, no event report */
2513
2514 if (eqh->curs_pos.x <= eqh->curs_box.right &&
2515 eqh->curs_pos.x >= eqh->curs_box.left &&
2516 eqh->curs_pos.y >= eqh->curs_box.top &&
2517 eqh->curs_pos.y <= eqh->curs_box.bottom ) {
2518 goto GET_MBUTTON;
2519 }
2520
2521 /*
2522 * report the mouse motion event */
2523
2524 event = PUTBEGIN(eqh);
2525 PUTEND(eqh);
2526
2527 ++do_wakeup; /* request a select wakeup call */
2528
2529 event->vse_x = eqh->curs_pos.x;
2530 event->vse_y = eqh->curs_pos.y;
2531
2532 event->vse_device = VSE_MOUSE; /* mouse */
2533 event->vse_type = VSE_MMOTION; /* pos changed */
2534 event->vse_key = 0;
2535 event->vse_direction = 0;
2536 event->vse_time = TOY; /* time stamp */
2537 }
2538
2539 GET_MBUTTON:
2540 /*
2541 * if button state has changed */
2542
2543 a = new_rep->state & 0x07; /*mask nonbutton bits */
2544 b = last_rep[dv->dv_unit].state & 0x07;
2545
2546 if (a ^ b) {
2547
2548 for ( c = 1; c < 8; c <<= 1) {
2549
2550 if (!( c & (a ^ b))) /* this button change? */
2551 continue;
2552
2553 /* event queue full? (overflow condition) */
2554
2555 if (ISFULL(eqh) == TRUE) {
2556 printf("qd%d: qdiint: event queue overflow\n", qd);
2557 break;
2558 }
2559
2560 event = PUTBEGIN(eqh); /* get new event */
2561 PUTEND(eqh);
2562
2563 ++do_wakeup; /* request select wakeup */
2564
2565 event->vse_x = eqh->curs_pos.x;
2566 event->vse_y = eqh->curs_pos.y;
2567
2568 event->vse_device = VSE_MOUSE; /* mouse */
2569 event->vse_type = VSE_BUTTON; /* new button */
2570 event->vse_time = TOY; /* time stamp */
2571
2572 /* flag changed button and if up or down */
2573
2574 if (c == RIGHT_BUTTON)
2575 event->vse_key = VSE_RIGHT_BUTTON;
2576 else if (c == MIDDLE_BUTTON)
2577 event->vse_key = VSE_MIDDLE_BUTTON;
2578 else if (c == LEFT_BUTTON)
2579 event->vse_key = VSE_LEFT_BUTTON;
2580
2581 /* set bit = button depressed */
2582
2583 if (c & a)
2584 event->vse_direction = VSE_KBTDOWN;
2585 else
2586 event->vse_direction = VSE_KBTUP;
2587 }
2588 }
2589
2590 /* refresh last report */
2591
2592 last_rep[dv->dv_unit] = current_rep[dv->dv_unit];
2593
2594 } /* get last byte of report */
2595 } else if ((status = duart->statusB)&RCV_RDY &&
2596 qdflags[dv->dv_unit].pntr_id == TABLET_ID) {
2597 /*
2598 * pickup tablet input, if any
2599 */
2600 if (status&0x70) {
2601 duart->cmdB = 0x40;
2602 continue;
2603 }
2604 /*
2605 * event queue full now? (overflow condition)
2606 */
2607 if (ISFULL(eqh) == TRUE) {
2608 printf("qd%d: qdiint: event queue overflow\n", qd);
2609 break;
2610 }
2611
2612 data = duart->dataB; /* get report byte */
2613 ++new_rep->bytcnt; /* bump report byte count */
2614
2615 /*
2616 * if 1st byte of report.. */
2617
2618 if (data & START_FRAME) {
2619 new_rep->state = data;
2620 if (new_rep->bytcnt > 1) {
2621 new_rep->bytcnt = 1; /* start of new frame */
2622 continue; /* ..continue looking */
2623 }
2624 }
2625
2626 /*
2627 * if 2nd byte of report.. */
2628
2629 else if (new_rep->bytcnt == 2) {
2630 new_rep->dx = data & 0x3F;
2631 }
2632
2633 /*
2634 * if 3rd byte of report.. */
2635
2636 else if (new_rep->bytcnt == 3) {
2637 new_rep->dx |= (data & 0x3F) << 6;
2638 }
2639
2640 /*
2641 * if 4th byte of report.. */
2642
2643 else if (new_rep->bytcnt == 4) {
2644 new_rep->dy = data & 0x3F;
2645 }
2646
2647 /*
2648 * if 5th byte of report, load input event queue */
2649
2650 else if (new_rep->bytcnt == 5) {
2651
2652 new_rep->dy |= (data & 0x3F) << 6;
2653 new_rep->bytcnt = 0;
2654
2655 /*
2656 * update cursor position coordinates */
2657
2658 new_rep->dx /= qdflags[dv->dv_unit].tab_res;
2659 new_rep->dy = (2200 - new_rep->dy)
2660 / qdflags[dv->dv_unit].tab_res;
2661
2662 if (new_rep->dx > 1023) {
2663 new_rep->dx = 1023;
2664 }
2665 if (new_rep->dy > 863) {
2666 new_rep->dy = 863;
2667 }
2668
2669 /*
2670 * report an event if the puck/stylus has moved
2671 */
2672
2673 if (eqh->curs_pos.x != new_rep->dx ||
2674 eqh->curs_pos.y != new_rep->dy) {
2675
2676 eqh->curs_pos.x = new_rep->dx;
2677 eqh->curs_pos.y = new_rep->dy;
2678
2679 /*
2680 * update cursor screen position */
2681
2682 dga = (struct dga *) qdmap[dv->dv_unit].dga;
2683 dga->x_cursor = TRANX(eqh->curs_pos.x);
2684 dga->y_cursor = TRANY(eqh->curs_pos.y);
2685
2686 /*
2687 * if cursor is in the box, no event report
2688 */
2689
2690 if (eqh->curs_pos.x <= eqh->curs_box.right &&
2691 eqh->curs_pos.x >= eqh->curs_box.left &&
2692 eqh->curs_pos.y >= eqh->curs_box.top &&
2693 eqh->curs_pos.y <= eqh->curs_box.bottom ) {
2694 goto GET_TBUTTON;
2695 }
2696
2697 /*
2698 * report the tablet motion event */
2699
2700 event = PUTBEGIN(eqh);
2701 PUTEND(eqh);
2702
2703 ++do_wakeup; /* request a select wakeup call */
2704
2705 event->vse_x = eqh->curs_pos.x;
2706 event->vse_y = eqh->curs_pos.y;
2707
2708 event->vse_device = VSE_TABLET; /* tablet */
2709 /*
2710 * right now, X handles tablet motion the same
2711 * as mouse motion
2712 */
2713 event->vse_type = VSE_MMOTION; /* pos changed */
2714 event->vse_key = 0;
2715 event->vse_direction = 0;
2716 event->vse_time = TOY; /* time stamp */
2717 }
2718 GET_TBUTTON:
2719 /*
2720 * if button state has changed */
2721
2722 a = new_rep->state & 0x1E; /* mask nonbutton bits */
2723 b = last_rep[dv->dv_unit].state & 0x1E;
2724
2725 if (a ^ b) {
2726
2727 /* event queue full now? (overflow condition) */
2728
2729 if (ISFULL(eqh) == TRUE) {
2730 printf("qd%d: qdiint: event queue overflow\n",qd);
2731 break;
2732 }
2733
2734 event = PUTBEGIN(eqh); /* get new event */
2735 PUTEND(eqh);
2736
2737 ++do_wakeup; /* request a select wakeup call */
2738
2739 event->vse_x = eqh->curs_pos.x;
2740 event->vse_y = eqh->curs_pos.y;
2741
2742 event->vse_device = VSE_TABLET; /* tablet */
2743 event->vse_type = VSE_BUTTON; /* button changed */
2744 event->vse_time = TOY; /* time stamp */
2745
2746 /* define the changed button and if up or down */
2747
2748 for ( c = 1; c <= 0x10; c <<= 1) {
2749 if (c & (a ^ b)) {
2750 if (c == T_LEFT_BUTTON)
2751 event->vse_key = VSE_T_LEFT_BUTTON;
2752 else if (c == T_FRONT_BUTTON)
2753 event->vse_key = VSE_T_FRONT_BUTTON;
2754 else if (c == T_RIGHT_BUTTON)
2755 event->vse_key = VSE_T_RIGHT_BUTTON;
2756 else if (c == T_BACK_BUTTON)
2757 event->vse_key = VSE_T_BACK_BUTTON;
2758 break;
2759 }
2760 }
2761
2762 /* set bit = button depressed */
2763
2764 if (c & a)
2765 event->vse_direction = VSE_KBTDOWN;
2766 else
2767 event->vse_direction = VSE_KBTUP;
2768 }
2769
2770 /* refresh last report */
2771
2772 last_rep[dv->dv_unit] = current_rep[dv->dv_unit];
2773
2774 } /* get last byte of report */
2775 } /* pick up tablet input */
2776
2777 } /* while input available.. */
2778
2779 /*
2780 * do select wakeup
2781 */
2782 if (do_wakeup) {
2783 selnotify(&qdrsel[dv->dv_unit], 0);
2784 do_wakeup = 0;
2785 }
2786 } else {
2787 /*
2788 * if the graphic device is not turned on, this is console input
2789 */
2790 if (qdpolling)
2791 return;
2792
2793 if (dv->dv_unit >= qd_cd.cd_ndevs || qd_cd.cd_devs[dv->dv_unit] == NULL)
2794 return; /* no such device or address */
2795
2796 tp = qd_tty[dv->dv_unit << 2];
2797
2798 /*
2799 * Get a character from the keyboard.
2800 */
2801 while (duart->statusA&RCV_RDY) {
2802 key = duart->dataA;
2803 key &= 0xFF;
2804 /*
2805 * Check for various keyboard errors
2806 */
2807 if (key == LK_POWER_ERROR || key == LK_KDOWN_ERROR ||
2808 key == LK_INPUT_ERROR || key == LK_OUTPUT_ERROR) {
2809 printf("qd%d: qdiint: Keyboard error, code = %x\n",qd,key);
2810 return;
2811 }
2812
2813 if (key < LK_LOWEST)
2814 return;
2815
2816 /*
2817 * See if its a state change key */
2818
2819 switch (key) {
2820
2821 case LOCK:
2822 q_keyboard.lock ^= 0xffff; /* toggle */
2823 if (q_keyboard.lock)
2824 led_control(qd, LK_LED_ENABLE,
2825 LK_LED_LOCK);
2826 else
2827 led_control(qd, LK_LED_DISABLE,
2828 LK_LED_LOCK);
2829 return;
2830
2831 case SHIFT:
2832 q_keyboard.shift ^= 0xFFFF;
2833 return;
2834
2835 case CNTRL:
2836 q_keyboard.cntrl ^= 0xFFFF;
2837 return;
2838
2839 case ALLUP:
2840 q_keyboard.cntrl = 0;
2841 q_keyboard.shift = 0;
2842 return;
2843
2844 case REPEAT:
2845 chr = q_keyboard.last;
2846 break;
2847
2848 /*
2849 * Test for cntrl characters. If set, see if the character
2850 * is elligible to become a control character. */
2851
2852 default:
2853
2854 if (q_keyboard.cntrl) {
2855 chr = q_key[key];
2856 if (chr >= ' ' && chr <= '~')
2857 chr &= 0x1F;
2858 else if (chr >= 0xA1 && chr <= 0xFE)
2859 chr &= 0x9F;
2860 }
2861 else if( q_keyboard.lock || q_keyboard.shift )
2862 chr = q_shift_key[key];
2863 else
2864 chr = q_key[key];
2865 break;
2866 }
2867
2868 q_keyboard.last = chr;
2869
2870 /*
2871 * Check for special function keys */
2872
2873 if (chr & 0x100) {
2874 char *string;
2875 string = q_special[chr & 0x7F];
2876 while(*string)
2877 (*tp->t_linesw->l_rint)(*string++, tp);
2878 }
2879 else {
2880 #ifdef DDB
2881 /* Check for kernel debugger escape here */
2882 int j;
2883
2884 j = kdbrint(chr&0177);
2885
2886 if (j == 1) /* Escape received, just return */
2887 return;
2888
2889 if (j == 2) /* Second char wasn't 'D' */
2890 (*tp->t_linesw->l_rint)(27, tp);
2891 #endif
2892 (*tp->t_linesw->l_rint)(chr&0177, tp);
2893 }
2894 }
2895 }
2896 } /* qdiint */
2897
2898 /*
2899 *
2900 * Clear the QDSS screen
2901 *
2902 * >>> NOTE <<<
2903 *
2904 * This code requires that certain adder initialization be valid. To
2905 * assure that this requirement is satisfied, this routine should be
2906 * called only after calling the "setup_dragon()" function.
2907 *
2908 * Clear the bitmap a piece at a time. Since the fast scroll clear
2909 * only clears the current displayed portion of the bitmap put a
2910 * temporary value in the y limit register so we can access whole
2911 * bitmap
2912 *
2913 */
2914 void
2915 clear_qd_screen(unit)
2916 int unit;
2917 {
2918 volatile struct adder *adder;
2919 adder = (struct adder *) qdmap[unit].adder;
2920
2921 adder->x_limit = 1024;
2922 adder->y_limit = 2048 - CHAR_HEIGHT;
2923 adder->y_offset_pending = 0;
2924 #define WSV (void)wait_status(adder, VSYNC); (void)wait_status(adder, VSYNC)
2925 WSV;
2926 adder->y_scroll_constant = SCROLL_ERASE;
2927 WSV;
2928 adder->y_offset_pending = 864;
2929 WSV;
2930 adder->y_scroll_constant = SCROLL_ERASE;
2931 WSV;
2932 adder->y_offset_pending = 1728;
2933 WSV;
2934 adder->y_scroll_constant = SCROLL_ERASE;
2935 WSV;
2936 adder->y_offset_pending = 0; /* back to normal */
2937 WSV;
2938 adder->x_limit = MAX_SCREEN_X;
2939 adder->y_limit = MAX_SCREEN_Y + FONT_HEIGHT;
2940 #undef WSV
2941
2942 } /* clear_qd_screen */
2943
2944 /*
2945 * kernel console output to the glass tty
2946 */
2947 void
2948 qdcnputc(dev, chr)
2949 dev_t dev;
2950 int chr;
2951 {
2952
2953 /*
2954 * if system is now physical, forget it (ie: crash DUMP)
2955 */
2956 if ((mfpr(PR_MAPEN) & 1) == 0)
2957 return;
2958
2959 blitc(0, (u_char)(chr & 0xff));
2960 if ((chr & 0177) == '\n')
2961 blitc(0, '\r');
2962
2963 } /* qdputc */
2964
2965 /*
2966 * load the mouse cursor's template RAM bitmap
2967 */
2968 void
2969 ldcursor(unit, bitmap)
2970 int unit;
2971 short *bitmap;
2972 {
2973 volatile struct dga *dga;
2974 volatile short *temp;
2975 int i;
2976 int curs;
2977
2978 dga = (struct dga *) qdmap[unit].dga;
2979 temp = (short *) qdmap[unit].template;
2980
2981 if (dga->csr & CURS_ENB) { /* if the cursor is enabled.. */
2982 curs = -1; /* ..note that.. */
2983 dga->csr &= ~CURS_ENB; /* ..and shut it off */
2984 } else
2985 curs = 0;
2986
2987 dga->csr &= ~CURS_ENB; /* shut off the cursor */
2988
2989 temp += (8 * 1024) - 32; /* cursor is 32 WORDS from the end */
2990 /* ..of the 8k WORD template space */
2991 for (i = 0; i < 32; ++i)
2992 *temp++ = *bitmap++;
2993
2994 if (curs) { /* if cursor was enabled.. */
2995 dga->csr |= CURS_ENB; /* ..turn it back on */
2996 }
2997
2998 } /* ldcursor */
2999
3000 /*
3001 * Put the console font in the QDSS off-screen memory
3002 */
3003 void
3004 ldfont(unit)
3005 int unit;
3006 {
3007 volatile struct adder *adder;
3008
3009 int i, j, k, max_chars_line;
3010 short packed;
3011
3012 adder = (struct adder *) qdmap[unit].adder;
3013
3014 /*
3015 * setup VIPER operand control registers
3016 */
3017 write_ID(adder, MASK_1, 0xFFFF);
3018 write_ID(adder, VIPER_Z_LOAD | FOREGROUND_COLOR_Z, 255);
3019 write_ID(adder, VIPER_Z_LOAD | BACKGROUND_COLOR_Z, 0);
3020
3021 write_ID(adder, SRC1_OCR_B,
3022 EXT_NONE | INT_NONE | ID | BAR_SHIFT_DELAY);
3023 write_ID(adder, SRC2_OCR_B,
3024 EXT_NONE | INT_NONE | ID | BAR_SHIFT_DELAY);
3025 write_ID(adder, DST_OCR_B,
3026 EXT_SOURCE | INT_NONE | NO_ID | NO_BAR_SHIFT_DELAY);
3027
3028 adder->rasterop_mode = DST_WRITE_ENABLE | DST_INDEX_ENABLE | NORMAL;
3029
3030 /*
3031 * load destination data
3032 */
3033 (void)wait_status(adder, RASTEROP_COMPLETE);
3034
3035 adder->destination_x = FONT_X;
3036 adder->destination_y = FONT_Y;
3037 #if FONT_WIDTH > MAX_SCREEN_X
3038 adder->fast_dest_dx = MAX_SCREEN_X;
3039 #else
3040 adder->fast_dest_dx = FONT_WIDTH;
3041 #endif
3042 adder->slow_dest_dy = CHAR_HEIGHT;
3043
3044 /*
3045 * setup for processor to bitmap xfer */
3046
3047 write_ID(adder, CS_UPDATE_MASK, 0x0001);
3048 adder->cmd = PBT | OCRB | 2 | DTE | 2;
3049
3050 /*
3051 * Figure out how many characters can be stored on one "line" of
3052 * offscreen memory.
3053 */
3054 max_chars_line = MAX_SCREEN_X/(CHAR_WIDTH*2);
3055 if ((CHARS/2 + CHARS%2) < max_chars_line)
3056 max_chars_line = CHARS/2 + CHARS%2;
3057
3058 /*
3059 * iteratively do the processor to bitmap xfer */
3060
3061 for (i = 0; i < ROWS; ++i) {
3062
3063 /* PTOB a scan line */
3064
3065 for (j = 0, k = i; j < max_chars_line; ++j) {
3066 /* PTOB one scan of a char cell */
3067
3068 packed = q_font[k];
3069 k += ROWS;
3070 packed |= ((short)q_font[k] << 8);
3071 k += ROWS;
3072
3073 (void)wait_status(adder, TX_READY);
3074 adder->id_data = packed;
3075 }
3076 }
3077
3078 /*
3079 * (XXX XXX XXX - should remove)
3080 *
3081 * Copy the second row of characters. Subtract the first
3082 * row from the total number. Divide this quantity by 2
3083 * because 2 chars are stored in a short in the PTOB loop
3084 * below. Figure out how many characters can be stored on
3085 * one "line" of offscreen memory
3086 */
3087
3088 max_chars_line = MAX_SCREEN_X/(CHAR_WIDTH*2);
3089 if ((CHARS/2 + CHARS%2) < max_chars_line)
3090 return;
3091 max_chars_line = (CHARS/2 + CHARS%2) - max_chars_line; /* 95 - 64 */
3092 /* Paranoia check to see if 3rd row may be needed */
3093 if (max_chars_line > (MAX_SCREEN_X/(CHAR_WIDTH*2)))
3094 max_chars_line = MAX_SCREEN_X/(CHAR_WIDTH*2);
3095
3096 adder->destination_x = FONT_X;
3097 adder->destination_y = FONT_Y - CHAR_HEIGHT;
3098 adder->fast_dest_dx = max_chars_line * CHAR_WIDTH * 2;
3099 adder->slow_dest_dy = CHAR_HEIGHT;
3100
3101 /*
3102 * setup for processor to bitmap xfer
3103 */
3104 write_ID(adder, CS_UPDATE_MASK, 0x0001);
3105 adder->cmd = PBT | OCRB | 2 | DTE | 2;
3106
3107 /*
3108 * iteratively do the processor to bitmap xfer
3109 */
3110 for (i = 0; i < ROWS; ++i) {
3111 /*
3112 * PTOB a scan line
3113 */
3114 for (j = 0, k = i; j < max_chars_line; ++j) {
3115 /*
3116 * PTOB one scan of a char cell
3117 */
3118 packed = q_font[k + FONT_OFFSET];
3119 k += ROWS;
3120 packed |= ((short)q_font[k + FONT_OFFSET] << 8);
3121 k += ROWS;
3122 (void)wait_status(adder, TX_READY);
3123 adder->id_data = packed;
3124 }
3125 }
3126
3127 } /* ldfont */
3128
3129
3130 /*
3131 * Disable or enable polling. This is used when entering or leaving the
3132 * kernel debugger.
3133 */
3134 void
3135 qdcnpollc(dev, onoff)
3136 dev_t dev;
3137 int onoff;
3138 {
3139 qdpolling = onoff;
3140 }
3141
3142
3143 /*
3144 * Get a character from the LK201 (polled)
3145 */
3146 int
3147 qdcngetc(dev)
3148 dev_t dev;
3149 {
3150 short key;
3151 char chr;
3152 volatile struct duart *duart;
3153
3154 duart = (struct duart *) qdmap[0].duart;
3155
3156 /*
3157 * Get a character from the keyboard.
3158 */
3159 LOOP:
3160 while (!(duart->statusA&RCV_RDY))
3161 ;
3162
3163 key = duart->dataA;
3164 key &= 0xFF;
3165
3166 /*
3167 * Check for various keyboard errors */
3168
3169 if (key == LK_POWER_ERROR || key == LK_KDOWN_ERROR ||
3170 key == LK_INPUT_ERROR || key == LK_OUTPUT_ERROR) {
3171 printf("Keyboard error, code = %x\n", key);
3172 return(0);
3173 }
3174
3175 if (key < LK_LOWEST)
3176 return(0);
3177
3178 /*
3179 * See if its a state change key
3180 */
3181 switch (key) {
3182
3183 case LOCK:
3184 q_keyboard.lock ^= 0xffff; /* toggle */
3185 if (q_keyboard.lock)
3186 led_control(0, LK_LED_ENABLE, LK_LED_LOCK);
3187 else
3188 led_control(0, LK_LED_DISABLE, LK_LED_LOCK);
3189 goto LOOP;
3190
3191 case SHIFT:
3192 q_keyboard.shift ^= 0xFFFF;
3193 goto LOOP;
3194
3195 case CNTRL:
3196 q_keyboard.cntrl ^= 0xFFFF;
3197 goto LOOP;
3198
3199 case ALLUP:
3200 q_keyboard.cntrl = 0;
3201 q_keyboard.shift = 0;
3202 goto LOOP;
3203
3204 case REPEAT:
3205 chr = q_keyboard.last;
3206 break;
3207
3208 /*
3209 * Test for cntrl characters. If set, see if the character
3210 * is elligible to become a control character.
3211 */
3212 default:
3213
3214 if (q_keyboard.cntrl) {
3215 chr = q_key[key];
3216 if (chr >= ' ' && chr <= '~')
3217 chr &= 0x1F;
3218 }
3219 else if ( q_keyboard.lock || q_keyboard.shift )
3220 chr = q_shift_key[key];
3221 else
3222 chr = q_key[key];
3223 break;
3224 }
3225
3226 if (chr < ' ' && chr > '~') /* if input is non-displayable */
3227 return(0); /* ..then pitch it! */
3228
3229 q_keyboard.last = chr;
3230
3231 /*
3232 * Check for special function keys */
3233
3234 if (chr & 0x80) /* pitch the function keys */
3235 return(0);
3236 else
3237 return(chr);
3238
3239 } /* qdgetc */
3240
3241 /*
3242 * led_control()... twiddle LK-201 LED's
3243 */
3244 void
3245 led_control(unit, cmd, led_mask)
3246 int unit, cmd, led_mask;
3247 {
3248 int i;
3249 volatile struct duart *duart;
3250
3251 duart = (struct duart *)qdmap[unit].duart;
3252
3253 for (i = 1000; i > 0; --i) {
3254 if (duart->statusA&XMT_RDY) {
3255 duart->dataA = cmd;
3256 break;
3257 }
3258 }
3259 for (i = 1000; i > 0; --i) {
3260 if (duart->statusA&XMT_RDY) {
3261 duart->dataA = led_mask;
3262 break;
3263 }
3264 }
3265 return;
3266
3267 } /* led_control */
3268
3269 /*
3270 * scroll_up()... move the screen up one character height
3271 */
3272 void
3273 scroll_up(adder)
3274 volatile struct adder *adder;
3275 {
3276 /*
3277 * setup VIPER operand control registers
3278 */
3279 (void)wait_status(adder, ADDRESS_COMPLETE);
3280 write_ID(adder, CS_UPDATE_MASK, 0x00FF); /* select all planes */
3281 write_ID(adder, MASK_1, 0xFFFF);
3282 write_ID(adder, VIPER_Z_LOAD | FOREGROUND_COLOR_Z, 255);
3283 write_ID(adder, VIPER_Z_LOAD | BACKGROUND_COLOR_Z, 0);
3284 write_ID(adder, SRC1_OCR_B,
3285 EXT_NONE | INT_SOURCE | ID | BAR_SHIFT_DELAY);
3286 write_ID(adder, DST_OCR_B,
3287 EXT_NONE | INT_NONE | NO_ID | NO_BAR_SHIFT_DELAY);
3288 /*
3289 * load DESTINATION origin and vectors
3290 */
3291 adder->fast_dest_dy = 0;
3292 adder->slow_dest_dx = 0;
3293 adder->error_1 = 0;
3294 adder->error_2 = 0;
3295 adder->rasterop_mode = DST_WRITE_ENABLE | NORMAL;
3296 adder->destination_x = 0;
3297 adder->fast_dest_dx = 1024;
3298 adder->destination_y = 0;
3299 adder->slow_dest_dy = 864 - CHAR_HEIGHT;
3300 /*
3301 * load SOURCE origin and vectors
3302 */
3303 adder->source_1_x = 0;
3304 adder->source_1_dx = 1024;
3305 adder->source_1_y = 0 + CHAR_HEIGHT;
3306 adder->source_1_dy = 864 - CHAR_HEIGHT;
3307 write_ID(adder, LU_FUNCTION_R1, FULL_SRC_RESOLUTION | LF_SOURCE);
3308 adder->cmd = RASTEROP | OCRB | 0 | S1E | DTE;
3309 /*
3310 * do a rectangle clear of last screen line
3311 */
3312 write_ID(adder, MASK_1, 0xffff);
3313 write_ID(adder, SOURCE, 0xffff);
3314 write_ID(adder,DST_OCR_B,
3315 (EXT_NONE | INT_NONE | NO_ID | NO_BAR_SHIFT_DELAY));
3316 write_ID(adder, VIPER_Z_LOAD | FOREGROUND_COLOR_Z, 0);
3317 adder->error_1 = 0;
3318 adder->error_2 = 0;
3319 adder->slow_dest_dx = 0; /* set up the width of */
3320 adder->slow_dest_dy = CHAR_HEIGHT; /* rectangle */
3321 adder->rasterop_mode = (NORMAL | DST_WRITE_ENABLE) ;
3322 (void)wait_status(adder, RASTEROP_COMPLETE);
3323 adder->destination_x = 0;
3324 adder->destination_y = 864 - CHAR_HEIGHT;
3325 adder->fast_dest_dx = 1024; /* set up the height */
3326 adder->fast_dest_dy = 0; /* of rectangle */
3327 write_ID(adder, LU_FUNCTION_R2, (FULL_SRC_RESOLUTION | LF_SOURCE));
3328 adder->cmd = (RASTEROP | OCRB | LF_R2 | DTE ) ;
3329
3330 } /* scroll_up */
3331
3332 /*
3333 * init shared memory pointers and structures
3334 */
3335 void
3336 init_shared(unit)
3337 int unit;
3338 {
3339 volatile struct dga *dga;
3340
3341 dga = (struct dga *) qdmap[unit].dga;
3342
3343 /*
3344 * initialize the event queue pointers and header */
3345
3346 eq_header[unit] = (struct qdinput *)
3347 ((((int)event_shared & ~(0x01FF)) + 512)
3348 + (EVENT_BUFSIZE * unit));
3349 eq_header[unit]->curs_pos.x = 0;
3350 eq_header[unit]->curs_pos.y = 0;
3351 dga->x_cursor = TRANX(eq_header[unit]->curs_pos.x);
3352 dga->y_cursor = TRANY(eq_header[unit]->curs_pos.y);
3353 eq_header[unit]->curs_box.left = 0;
3354 eq_header[unit]->curs_box.right = 0;
3355 eq_header[unit]->curs_box.top = 0;
3356 eq_header[unit]->curs_box.bottom = 0;
3357 /*
3358 * assign a pointer to the DMA I/O buffer for this QDSS.
3359 */
3360 DMAheader[unit] = (struct DMAreq_header *)
3361 (((int)(&DMA_shared[0] + 512) & ~0x1FF)
3362 + (DMAbuf_size * unit));
3363 DMAheader[unit]->DMAreq = (struct DMAreq *) ((int)DMAheader[unit]
3364 + sizeof(struct DMAreq_header));
3365 DMAheader[unit]->QBAreg = 0;
3366 DMAheader[unit]->status = 0;
3367 DMAheader[unit]->shared_size = DMAbuf_size;
3368 DMAheader[unit]->used = 0;
3369 DMAheader[unit]->size = 10; /* default = 10 requests */
3370 DMAheader[unit]->oldest = 0;
3371 DMAheader[unit]->newest = 0;
3372 /*
3373 * assign a pointer to the scroll structure for this QDSS.
3374 */
3375 scroll[unit] = (struct scroll *)
3376 (((int)(&scroll_shared[0] + 512) & ~0x1FF)
3377 + (sizeof(struct scroll) * unit));
3378 scroll[unit]->status = 0;
3379 scroll[unit]->viper_constant = 0;
3380 scroll[unit]->y_scroll_constant = 0;
3381 scroll[unit]->y_offset = 0;
3382 scroll[unit]->x_index_pending = 0;
3383 scroll[unit]->y_index_pending = 0;
3384 /*
3385 * assign a pointer to the color map write buffer for this QDSS
3386 */
3387 color_buf[unit] = (struct color_buf *)
3388 (((int)(&color_shared[0] + 512) & ~0x1FF)
3389 + (COLOR_BUFSIZ * unit));
3390 color_buf[unit]->status = 0;
3391 color_buf[unit]->count = 0;
3392
3393 } /* init_shared */
3394
3395 /*
3396 * init the ADDER, VIPER, bitmaps, & color map
3397 */
3398 void
3399 setup_dragon(unit)
3400 int unit;
3401 {
3402
3403 volatile struct adder *adder;
3404 volatile struct dga *dga;
3405 volatile short *memcsr;
3406 int i;
3407 short top; /* clipping/scrolling boundaries */
3408 short bottom;
3409 short right;
3410 short left;
3411 volatile short *red; /* color map pointers */
3412 volatile short *green;
3413 volatile short *blue;
3414
3415 /*
3416 * init for setup
3417 */
3418 adder = (struct adder *) qdmap[unit].adder;
3419 dga = (struct dga *) qdmap[unit].dga;
3420 memcsr = (short *) qdmap[unit].memcsr;
3421 dga->csr &= ~(DMA_IE | 0x700); /* halt DMA and kill the intrpts */
3422 *memcsr = SYNC_ON; /* blank screen and turn off LED's */
3423 adder->command = CANCEL;
3424 /*
3425 * set monitor timing
3426 */
3427 adder->x_scan_count_0 = 0x2800;
3428 adder->x_scan_count_1 = 0x1020;
3429 adder->x_scan_count_2 = 0x003A;
3430 adder->x_scan_count_3 = 0x38F0;
3431 adder->x_scan_count_4 = 0x6128;
3432 adder->x_scan_count_5 = 0x093A;
3433 adder->x_scan_count_6 = 0x313C;
3434 adder->sync_phase_adj = 0x0100;
3435 adder->x_scan_conf = 0x00C8;
3436 /*
3437 * got a bug in secound pass ADDER! lets take care of it
3438 *
3439 * normally, just use the code in the following bug fix code, but to
3440 * make repeated demos look pretty, load the registers as if there was
3441 * no bug and then test to see if we are getting sync
3442 */
3443 adder->y_scan_count_0 = 0x135F;
3444 adder->y_scan_count_1 = 0x3363;
3445 adder->y_scan_count_2 = 0x2366;
3446 adder->y_scan_count_3 = 0x0388;
3447 /*
3448 * if no sync, do the bug fix code
3449 */
3450 if (wait_status(adder, VSYNC) == BAD) {
3451 /* first load all Y scan registers with very short frame and
3452 * wait for scroll service. This guarantees at least one SYNC
3453 * to fix the pass 2 Adder initialization bug (synchronizes
3454 * XCINCH with DMSEEDH)
3455 */
3456 adder->y_scan_count_0 = 0x01;
3457 adder->y_scan_count_1 = 0x01;
3458 adder->y_scan_count_2 = 0x01;
3459 adder->y_scan_count_3 = 0x01;
3460 /*
3461 * delay at least 1 full frame time
3462 */
3463 (void)wait_status(adder, VSYNC);
3464 (void)wait_status(adder, VSYNC);
3465 /*
3466 * now load the REAL sync values (in reverse order just to
3467 * be safe.
3468 */
3469 adder->y_scan_count_3 = 0x0388;
3470 adder->y_scan_count_2 = 0x2366;
3471 adder->y_scan_count_1 = 0x3363;
3472 adder->y_scan_count_0 = 0x135F;
3473 }
3474 *memcsr = SYNC_ON | UNBLANK; /* turn off leds and turn on video */
3475 /*
3476 * zero the index registers
3477 */
3478 adder->x_index_pending = 0;
3479 adder->y_index_pending = 0;
3480 adder->x_index_new = 0;
3481 adder->y_index_new = 0;
3482 adder->x_index_old = 0;
3483 adder->y_index_old = 0;
3484 adder->pause = 0;
3485 /*
3486 * set rasterop mode to normal pen down
3487 */
3488 adder->rasterop_mode = DST_WRITE_ENABLE | DST_INDEX_ENABLE | NORMAL;
3489 /*
3490 * set the rasterop registers to a default values
3491 */
3492 adder->source_1_dx = 1;
3493 adder->source_1_dy = 1;
3494 adder->source_1_x = 0;
3495 adder->source_1_y = 0;
3496 adder->destination_x = 0;
3497 adder->destination_y = 0;
3498 adder->fast_dest_dx = 1;
3499 adder->fast_dest_dy = 0;
3500 adder->slow_dest_dx = 0;
3501 adder->slow_dest_dy = 1;
3502 adder->error_1 = 0;
3503 adder->error_2 = 0;
3504 /*
3505 * scale factor = UNITY
3506 */
3507 adder->fast_scale = UNITY;
3508 adder->slow_scale = UNITY;
3509 /*
3510 * set the source 2 parameters
3511 */
3512 adder->source_2_x = 0;
3513 adder->source_2_y = 0;
3514 adder->source_2_size = 0x0022;
3515 /*
3516 * initialize plane addresses for eight vipers
3517 */
3518 write_ID(adder, CS_UPDATE_MASK, 0x0001);
3519 write_ID(adder, PLANE_ADDRESS, 0x0000);
3520 write_ID(adder, CS_UPDATE_MASK, 0x0002);
3521 write_ID(adder, PLANE_ADDRESS, 0x0001);
3522 write_ID(adder, CS_UPDATE_MASK, 0x0004);
3523 write_ID(adder, PLANE_ADDRESS, 0x0002);
3524 write_ID(adder, CS_UPDATE_MASK, 0x0008);
3525 write_ID(adder, PLANE_ADDRESS, 0x0003);
3526 write_ID(adder, CS_UPDATE_MASK, 0x0010);
3527 write_ID(adder, PLANE_ADDRESS, 0x0004);
3528 write_ID(adder, CS_UPDATE_MASK, 0x0020);
3529 write_ID(adder, PLANE_ADDRESS, 0x0005);
3530 write_ID(adder, CS_UPDATE_MASK, 0x0040);
3531 write_ID(adder, PLANE_ADDRESS, 0x0006);
3532 write_ID(adder, CS_UPDATE_MASK, 0x0080);
3533 write_ID(adder, PLANE_ADDRESS, 0x0007);
3534 /*
3535 * initialize the external registers.
3536 */
3537 write_ID(adder, CS_UPDATE_MASK, 0x00FF);
3538 write_ID(adder, CS_SCROLL_MASK, 0x00FF);
3539 /*
3540 * initialize resolution mode
3541 */
3542 write_ID(adder, MEMORY_BUS_WIDTH, 0x000C); /* bus width = 16 */
3543 write_ID(adder, RESOLUTION_MODE, 0x0000); /* one bit/pixel */
3544 /*
3545 * initialize viper registers
3546 */
3547 write_ID(adder, SCROLL_CONSTANT, SCROLL_ENABLE|VIPER_LEFT|VIPER_UP);
3548 write_ID(adder, SCROLL_FILL, 0x0000);
3549 /*
3550 * set clipping and scrolling limits to full screen
3551 */
3552 for (i = 1000, adder->status = 0;
3553 i > 0 && !(adder->status&ADDRESS_COMPLETE); --i)
3554 ;
3555 if (i == 0)
3556 printf("qd%d: setup_dragon: timeout on ADDRESS_COMPLETE\n",unit);
3557 top = 0;
3558 bottom = 2048;
3559 left = 0;
3560 right = 1024;
3561 adder->x_clip_min = left;
3562 adder->x_clip_max = right;
3563 adder->y_clip_min = top;
3564 adder->y_clip_max = bottom;
3565 adder->scroll_x_min = left;
3566 adder->scroll_x_max = right;
3567 adder->scroll_y_min = top;
3568 adder->scroll_y_max = bottom;
3569 (void)wait_status(adder, VSYNC); /* wait at LEAST 1 full frame */
3570 (void)wait_status(adder, VSYNC);
3571 adder->x_index_pending = left;
3572 adder->y_index_pending = top;
3573 adder->x_index_new = left;
3574 adder->y_index_new = top;
3575 adder->x_index_old = left;
3576 adder->y_index_old = top;
3577
3578 for (i = 1000, adder->status = 0; i > 0 &&
3579 !(adder->status&ADDRESS_COMPLETE) ; --i)
3580 ;
3581 if (i == 0)
3582 printf("qd%d: setup_dragon: timeout on ADDRESS_COMPLETE\n",unit);
3583
3584 write_ID(adder, LEFT_SCROLL_MASK, 0x0000);
3585 write_ID(adder, RIGHT_SCROLL_MASK, 0x0000);
3586 /*
3587 * set source and the mask register to all ones (ie: white) o
3588 */
3589 write_ID(adder, SOURCE, 0xFFFF);
3590 write_ID(adder, MASK_1, 0xFFFF);
3591 write_ID(adder, VIPER_Z_LOAD | FOREGROUND_COLOR_Z, 255);
3592 write_ID(adder, VIPER_Z_LOAD | BACKGROUND_COLOR_Z, 0);
3593 /*
3594 * initialize Operand Control Register banks for fill command
3595 */
3596 write_ID(adder, SRC1_OCR_A, EXT_NONE | INT_M1_M2 | NO_ID | WAIT);
3597 write_ID(adder, SRC2_OCR_A, EXT_NONE | INT_SOURCE | NO_ID | NO_WAIT);
3598 write_ID(adder, DST_OCR_A, EXT_NONE | INT_NONE | NO_ID | NO_WAIT);
3599 write_ID(adder, SRC1_OCR_B, EXT_NONE | INT_SOURCE | NO_ID | WAIT);
3600 write_ID(adder, SRC2_OCR_B, EXT_NONE | INT_M1_M2 | NO_ID | NO_WAIT);
3601 write_ID(adder, DST_OCR_B, EXT_NONE | INT_NONE | NO_ID | NO_WAIT);
3602 /*
3603 * init Logic Unit Function registers, (these are just common values,
3604 * and may be changed as required).
3605 */
3606 write_ID(adder, LU_FUNCTION_R1, FULL_SRC_RESOLUTION | LF_SOURCE);
3607 write_ID(adder, LU_FUNCTION_R2, FULL_SRC_RESOLUTION | LF_SOURCE |
3608 INV_M1_M2);
3609 write_ID(adder, LU_FUNCTION_R3, FULL_SRC_RESOLUTION | LF_D_OR_S);
3610 write_ID(adder, LU_FUNCTION_R4, FULL_SRC_RESOLUTION | LF_D_XOR_S);
3611 /*
3612 * load the color map for black & white
3613 */
3614 for (i = 0, adder->status = 0; i < 10000 && !(adder->status&VSYNC); ++i)
3615 ;
3616
3617 if (i == 0)
3618 printf("qd%d: setup_dragon: timeout on VSYNC\n", unit);
3619
3620 red = (short *) qdmap[unit].red;
3621 green = (short *) qdmap[unit].green;
3622 blue = (short *) qdmap[unit].blue;
3623
3624 *red++ = 0x00; /* black */
3625 *green++ = 0x00;
3626 *blue++ = 0x00;
3627
3628 *red-- = 0xFF; /* white */
3629 *green-- = 0xFF;
3630 *blue-- = 0xFF;
3631
3632 /*
3633 * set color map for mouse cursor
3634 */
3635
3636 red += 254;
3637 green += 254;
3638 blue += 254;
3639
3640 *red++ = 0x00; /* black */
3641 *green++ = 0x00;
3642 *blue++ = 0x00;
3643
3644 *red = 0xFF; /* white */
3645 *green = 0xFF;
3646 *blue = 0xFF;
3647
3648 } /* setup_dragon */
3649
3650 /*
3651 * Init the DUART and set defaults in input
3652 */
3653 void
3654 setup_input(unit)
3655 int unit;
3656 {
3657 volatile struct duart *duart; /* DUART register structure pointer */
3658 int i, bits;
3659 char id_byte;
3660
3661 duart = (struct duart *) qdmap[unit].duart;
3662 duart->imask = 0;
3663
3664 /*
3665 * setup the DUART for kbd & pointing device
3666 */
3667 duart->cmdA = RESET_M; /* reset mode reg ptr for kbd */
3668 duart->modeA = 0x13; /* 8 bits, no parity, rcv IE, */
3669 /* no RTS control,char error mode */
3670 duart->modeA = 0x07; /* 1 stop bit,CTS does not IE XMT */
3671 /* no RTS control,no echo or loop */
3672 duart->cmdB = RESET_M; /* reset mode reg pntr for host */
3673 duart->modeB = 0x07; /* 8 bits, odd parity, rcv IE.. */
3674 /* ..no RTS cntrl, char error mode */
3675 duart->modeB = 0x07; /* 1 stop bit,CTS does not IE XMT */
3676 /* no RTS control,no echo or loop */
3677 duart->auxctl = 0x00; /* baud rate set 1 */
3678 duart->clkselA = 0x99; /* 4800 baud for kbd */
3679 duart->clkselB = 0x99; /* 4800 baud for mouse */
3680
3681 /* reset everything for keyboard */
3682
3683 for (bits = RESET_M; bits < START_BREAK; bits += 0x10)
3684 duart->cmdA = bits;
3685
3686 /* reset everything for host */
3687
3688 for (bits = RESET_M; bits < START_BREAK; bits += 0x10)
3689 duart->cmdB = bits;
3690
3691 duart->cmdA = EN_RCV | EN_XMT; /* enbl xmt & rcv for kbd */
3692 duart->cmdB = EN_RCV | EN_XMT; /* enbl xmt & rcv for pointer device */
3693
3694 /*
3695 * init keyboard defaults (DUART channel A)
3696 */
3697 for (i = 500; i > 0; --i) {
3698 if (duart->statusA&XMT_RDY) {
3699 duart->dataA = LK_DEFAULTS;
3700 break;
3701 }
3702 }
3703
3704 for (i = 100000; i > 0; --i) {
3705 if (duart->statusA&RCV_RDY) {
3706 break;
3707 }
3708 }
3709
3710 if (duart->dataA) /* flush the ACK */
3711 ;
3712
3713 /*
3714 * identify the pointing device
3715 */
3716 for (i = 500; i > 0; --i) {
3717 if (duart->statusB&XMT_RDY) {
3718 duart->dataB = SELF_TEST;
3719 break;
3720 }
3721 }
3722
3723 /*
3724 * wait for 1st byte of self test report */
3725
3726 for (i = 100000; i > 0; --i) {
3727 if (duart->statusB&RCV_RDY) {
3728 break;
3729 }
3730 }
3731
3732 if (i == 0) {
3733 printf("qd[%d]: setup_input: timeout on 1st byte of self test\n"
3734 ,unit);
3735 goto OUT;
3736 }
3737
3738 if (duart->dataB)
3739 ;
3740
3741 /*
3742 * wait for ID byte of self test report
3743 */
3744 for (i = 100000; i > 0; --i) {
3745 if (duart->statusB&RCV_RDY) {
3746 break;
3747 }
3748 }
3749
3750 if (i == 0) {
3751 printf("qd[%d]: setup_input: timeout on 2nd byte of self test\n", unit);
3752 goto OUT;
3753 }
3754
3755 id_byte = duart->dataB;
3756
3757 /*
3758 * wait for other bytes to come in
3759 */
3760 for (i = 100000; i > 0; --i) {
3761 if (duart->statusB & RCV_RDY) {
3762 if (duart->dataB)
3763 ;
3764 break;
3765 }
3766 }
3767 if (i == 0) {
3768 printf("qd[%d]: setup_input: timeout on 3rd byte of self test\n", unit);
3769 goto OUT;
3770 }
3771 for (i = 100000; i > 0; --i) {
3772 if (duart->statusB&RCV_RDY) {
3773 if (duart->dataB)
3774 ;
3775 break;
3776 }
3777 }
3778 if (i == 0) {
3779 printf("qd[%d]: setup_input: timeout on 4th byte of self test\n", unit);
3780 goto OUT;
3781 }
3782 /*
3783 * flag pointing device type and set defaults
3784 */
3785 for (i=100000; i>0; --i)
3786 ; /*XXX*/
3787
3788 if ((id_byte & 0x0F) != TABLET_ID) {
3789 qdflags[unit].pntr_id = MOUSE_ID;
3790
3791 for (i = 500; i > 0; --i) {
3792 if (duart->statusB&XMT_RDY) {
3793 duart->dataB = INC_STREAM_MODE;
3794 break;
3795 }
3796 }
3797 }
3798 else {
3799 qdflags[unit].pntr_id = TABLET_ID;
3800
3801 for (i = 500; i > 0; --i) {
3802 if (duart->statusB&XMT_RDY) {
3803 duart->dataB = T_STREAM;
3804 break;
3805 }
3806 }
3807 }
3808 OUT:
3809 duart->imask = qdflags[unit].duart_imask;
3810
3811 } /* setup_input */
3812
3813 /*
3814 * delay for at least one display frame time
3815 *
3816 * return: BAD means that we timed out without ever seeing the
3817 * vertical sync status bit
3818 * GOOD otherwise
3819 */
3820 int
3821 wait_status(adder, mask)
3822 volatile struct adder *adder;
3823 int mask;
3824 {
3825 int i;
3826
3827 for (i = 10000, adder->status = 0 ; i > 0 &&
3828 !(adder->status&mask) ; --i)
3829 ;
3830
3831 if (i == 0) {
3832 printf("wait_status: timeout polling for 0x%x in adder->status\n", mask);
3833 return(BAD);
3834 }
3835
3836 return(GOOD);
3837
3838 } /* wait_status */
3839
3840 /*
3841 * write out onto the ID bus
3842 */
3843 void
3844 write_ID(adder, adrs, data)
3845 volatile struct adder *adder;
3846 short adrs;
3847 short data;
3848 {
3849 int i;
3850
3851 for (i = 100000, adder->status = 0 ;
3852 i > 0 && !(adder->status&ADDRESS_COMPLETE) ; --i)
3853 ;
3854
3855 if (i == 0)
3856 goto ERR;
3857
3858 for (i = 100000, adder->status = 0 ;
3859 i > 0 && !(adder->status&TX_READY) ; --i)
3860 ;
3861
3862 if (i > 0) {
3863 adder->id_data = data;
3864 adder->command = ID_LOAD | adrs;
3865 return ;
3866 }
3867
3868 ERR:
3869 printf("write_ID: timeout trying to write to VIPER\n");
3870 return ;
3871
3872 } /* write_ID */
3873