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