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