Home | History | Annotate | Line # | Download | only in uba
qv.c revision 1.31
      1  1.31      matt /*$Header: /tank/opengrok/rsync2/NetBSD/src/sys/arch/vax/uba/qv.c,v 1.31 2015/07/05 03:07:21 matt Exp $*/
      2  1.31      matt /*
      3  1.31      matt  * Copyright (c) 2015 Charles H. Dickman. All rights reserved.
      4  1.31      matt  * Derived from smg.c
      5  1.31      matt  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
      6  1.31      matt  * All rights reserved.
      7   1.1  jonathan  *
      8   1.1  jonathan  * Redistribution and use in source and binary forms, with or without
      9   1.1  jonathan  * modification, are permitted provided that the following conditions
     10   1.1  jonathan  * are met:
     11   1.1  jonathan  * 1. Redistributions of source code must retain the above copyright
     12   1.1  jonathan  *    notice, this list of conditions and the following disclaimer.
     13   1.1  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1  jonathan  *    notice, this list of conditions and the following disclaimer in the
     15   1.1  jonathan  *    documentation and/or other materials provided with the distribution.
     16  1.31      matt  * 3. All advertising materials mentioning features or use of this software
     17  1.31      matt  *    must display the following acknowledgement:
     18  1.31      matt  *	This product includes software developed at Ludd, University of
     19  1.31      matt  *	Lule}, Sweden and its contributors.
     20  1.31      matt  * 4. The name of the author may not be used to endorse or promote products
     21  1.31      matt  *    derived from this software without specific prior written permission
     22   1.1  jonathan  *
     23  1.31      matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  1.31      matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  1.31      matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  1.31      matt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  1.31      matt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  1.31      matt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  1.31      matt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  1.31      matt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  1.31      matt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  1.31      matt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33   1.1  jonathan  */
     34  1.31      matt /*       1         2         3         4         5         6         7        */
     35  1.31      matt /*3456789012345678901234567890123456789012345678901234567890123456789012345678*/
     36  1.31      matt 
     37  1.31      matt #include <sys/cdefs.h>
     38  1.31      matt __KERNEL_RCSID(0, "$Header: /tank/opengrok/rsync2/NetBSD/src/sys/arch/vax/uba/qv.c,v 1.31 2015/07/05 03:07:21 matt Exp $");
     39  1.31      matt 
     40  1.31      matt #include <sys/param.h>
     41  1.31      matt #include <sys/systm.h>
     42  1.31      matt #include <sys/callout.h>
     43  1.31      matt #include <sys/conf.h>
     44  1.31      matt #include <sys/cpu.h>
     45  1.31      matt #include <sys/device.h>
     46  1.31      matt #include <sys/kernel.h>
     47  1.31      matt #include <sys/malloc.h>
     48  1.31      matt #include <sys/extent.h>		/***/
     49  1.31      matt #include <sys/time.h>
     50  1.31      matt #include <sys/bus.h>
     51  1.31      matt #include <vax/include/pte.h>                /* temporary */
     52  1.31      matt #include <machine/sid.h>
     53  1.31      matt #include <dev/cons.h>
     54  1.31      matt #include <dev/qbus/ubavar.h>
     55  1.31      matt #include <dev/wscons/wsdisplayvar.h>
     56  1.31      matt #include <dev/wscons/wsconsio.h>
     57  1.31      matt #include <dev/wscons/wscons_callbacks.h>
     58  1.31      matt #include <dev/wsfont/wsfont.h>
     59  1.31      matt #include <dev/wsfb/genfbvar.h>
     60  1.31      matt #include <vax/include/sgmap.h> /***/
     61  1.31      matt 
     62  1.31      matt #include "uba_common.h"		/***/
     63  1.31      matt #include "qv.h"
     64  1.31      matt #include "qv_ic.h"
     65  1.31      matt #include "qvaux.h"
     66  1.31      matt #include "opt_wsfont.h"
     67  1.31      matt 
     68  1.31      matt #define QMEMBASE        0x30000000
     69  1.31      matt #define QVSIZE          0x40000
     70  1.31      matt #define QV_SCANMAP      0x3F800
     71  1.31      matt #define QV_CURSRAM      0x3FFE0
     72  1.31      matt 
     73  1.31      matt #define QV_CSR          0
     74  1.31      matt #define QV_CSR_1        (1 << 2)
     75  1.31      matt #define QV_CSR_2        (1 << 3)
     76  1.31      matt #define QV_CSR_BANK     (15 << 11)
     77  1.31      matt #define QV_CUR_X        2
     78  1.31      matt #define QV_CRTC_AR      8
     79  1.31      matt #define QV_CRTC_DR      10
     80  1.31      matt #define QV_IC           12
     81  1.31      matt #define QV_ICDR         QV_ICDR
     82  1.31      matt #define QV_ICSR         (QV_ICDR + 2)
     83  1.31      matt 
     84  1.31      matt /* Screen hardware defs */
     85  1.31      matt #define QV_COLS		128	/* char width of screen */
     86  1.31      matt #define QV_ROWS		57	/* rows of char on screen */
     87  1.31      matt #define QV_CHEIGHT	15	/* lines a char consists of */
     88  1.31      matt #define QV_NEXTROW	(QV_COLS * QV_CHEIGHT)
     89  1.31      matt #define	QV_YWIDTH	864
     90  1.31      matt #define QV_XWIDTH	1024
     91  1.31      matt 
     92  1.31      matt /* hardware cursor */
     93  1.31      matt #define CUR_BLINKN      0x00
     94  1.31      matt #define CUR_BLANK       0x20
     95  1.31      matt #define CUR_BLINKS      0x40
     96  1.31      matt #define CUR_BLINKF      0x60
     97  1.31      matt #define CUR_BLINKM      0x60
     98  1.31      matt #define CUR_OFF         CUR_BLANK
     99  1.31      matt #define CUR_ON          CUR_BLINKS
    100  1.31      matt #define CUR_START       10
    101  1.31      matt #define CUR_END         11
    102  1.31      matt #define CUR_HI          14
    103  1.31      matt #define CUR_LO          15
    104  1.31      matt 
    105  1.31      matt //static	uint16_t curcmd, curx, cury, hotX, hotY;
    106  1.31      matt static	int     bgmask, fgmask;
    107  1.31      matt 
    108  1.31      matt static	int     qv_match(device_t, cfdata_t, void *);
    109  1.31      matt static	void    qv_attach(device_t, device_t, void *);
    110  1.31      matt 
    111  1.31      matt static void	qv_cursor(void *, int, int, int);
    112  1.31      matt static int	qv_mapchar(void *, int, unsigned int *);
    113  1.31      matt static void	qv_putchar(void *, int, int, u_int, long);
    114  1.31      matt static void	qv_copycols(void *, int, int, int,int);
    115  1.31      matt static void	qv_erasecols(void *, int, int, int, long);
    116  1.31      matt static void	qv_copyrows(void *, int, int, int);
    117  1.31      matt static void	qv_eraserows(void *, int, int, long);
    118  1.31      matt static int	qv_allocattr(void *, int, int, int, long *);
    119  1.31      matt 
    120  1.31      matt const struct wsdisplay_emulops qv_emulops = {
    121  1.31      matt 	.cursor = qv_cursor,
    122  1.31      matt 	.mapchar = qv_mapchar,
    123  1.31      matt 	.putchar = qv_putchar,
    124  1.31      matt 	.copycols = qv_copycols,
    125  1.31      matt 	.erasecols = qv_erasecols,
    126  1.31      matt 	.copyrows = qv_copyrows,
    127  1.31      matt 	.eraserows = qv_eraserows,
    128  1.31      matt 	.allocattr = qv_allocattr
    129  1.31      matt };
    130  1.31      matt 
    131  1.31      matt struct _wsscreen_descr {
    132  1.31      matt         const struct wsscreen_descr qv_stdscreen;       /* MUST BE FIRST */
    133  1.31      matt         const uint16_t qv_crtc_param[16];
    134  1.31      matt };
    135   1.1  jonathan 
    136   1.1  jonathan /*
    137  1.31      matt  * Notes from the original Ultrix drivers
    138  1.31      matt  *
    139  1.31      matt  * Screen controller initialization parameters. The definations [sic] and use
    140  1.31      matt  * of these parameters can be found in the Motorola 68045 [sic] crtc specs. In
    141  1.31      matt  * essence they set the display parameters for the chip. The first set is
    142  1.31      matt  * for the 15" screen and the second is for the 19" separate sync. There
    143  1.31      matt  * is also a third set for a 19" composite sync monitor which we have not
    144  1.31      matt  * tested and which is not supported.
    145   1.1  jonathan  */
    146   1.1  jonathan 
    147  1.31      matt const struct _wsscreen_descr qv_stdscreen[] = {
    148  1.31      matt         { { "80x30", 80, 30, &qv_emulops, 8,
    149  1.31      matt                 QV_CHEIGHT, WSSCREEN_UNDERLINE|WSSCREEN_REVERSE },
    150  1.31      matt             { 31, 25, 27, 0142, 31, 13, 30, 31, 4, 15, 040, 0, 0, 0, 0, 0 } },
    151  1.31      matt         { { "120x55", 120, 55, &qv_emulops, 8,
    152  1.31      matt                 QV_CHEIGHT, WSSCREEN_UNDERLINE|WSSCREEN_REVERSE },
    153  1.31      matt             { 39, 30, 32, 0262, 55, 5, 54, 54, 4, 15, 040, 0, 0, 0, 0, 0 } },
    154  1.31      matt         { { "128x57", QV_COLS, QV_ROWS, &qv_emulops, 8,
    155  1.31      matt                 QV_CHEIGHT, WSSCREEN_UNDERLINE|WSSCREEN_REVERSE },
    156  1.31      matt             { 39, 32, 33, 0264, 56, 5, 54, 54, 4, 15, 040, 0, 0, 0, 0, 0 } },
    157  1.31      matt };
    158  1.31      matt 
    159  1.31      matt const struct wsscreen_descr *_qv_scrlist[] = {
    160  1.31      matt 	&qv_stdscreen[2].qv_stdscreen,	/* default */
    161  1.31      matt 	&qv_stdscreen[1].qv_stdscreen,
    162  1.31      matt 	&qv_stdscreen[0].qv_stdscreen,
    163  1.31      matt };
    164  1.31      matt 
    165  1.31      matt const struct wsscreen_list qv_screenlist = {
    166  1.31      matt 	.nscreens = __arraycount(_qv_scrlist),
    167  1.31      matt 	.screens = _qv_scrlist,
    168  1.31      matt };
    169  1.31      matt 
    170  1.31      matt struct qv_softc {
    171  1.31      matt         device_t sc_dev;                /* device pointer */
    172  1.31      matt         bus_space_tag_t sc_iot;         /* register base */
    173  1.31      matt         bus_space_handle_t sc_ioh;
    174  1.31      matt         bus_space_tag_t sc_fbt;         /* frame buffer base */
    175  1.31      matt         bus_space_handle_t sc_fbh;
    176  1.31      matt         paddr_t sc_fbphys;              /* frame buffer phys addr */
    177  1.31      matt         char *sc_fb;                    /* frame buffer virt addr */
    178  1.31      matt 	uint16_t *sc_scanmap;		/* scan map virt addr */
    179  1.31      matt         char *sc_font;                  /* font glyph table */
    180  1.31      matt 
    181  1.31      matt         uint8_t sc_curon;               /* cursor on */
    182  1.31      matt         uint16_t sc_curx;               /* cursor x position */
    183  1.31      matt         uint16_t sc_cury;               /* cursor y position */
    184  1.31      matt         uint16_t sc_curhotX;            /* cursor x hot spot */
    185  1.31      matt         uint16_t sc_curhotY;            /* cursor y hot spot */
    186  1.31      matt 
    187  1.31      matt         struct qv_screen *sc_curscr;    /* current screen */
    188  1.31      matt };
    189   1.1  jonathan 
    190  1.31      matt #if 0
    191  1.31      matt struct genfb_qv_softc {
    192  1.31      matt 	struct genfb_softc      sc_gen;
    193  1.31      matt 	bus_space_tag_t         sc_iot;
    194  1.31      matt 	bus_space_handle_t	sc_ioh;
    195  1.31      matt 	uint32_t		sc_wstype;
    196  1.31      matt };
    197  1.31      matt #endif
    198   1.1  jonathan 
    199  1.31      matt static void     qv_crtc_wr(struct qv_softc *, uint16_t, uint16_t);
    200  1.31      matt static void     qv_setcrtc(struct qv_softc *, const uint16_t *);
    201   1.1  jonathan 
    202  1.31      matt static int	qv_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    203  1.31      matt static paddr_t	qv_mmap(void *, void *, off_t, int);
    204  1.31      matt static int	qv_alloc_screen(void *, const struct wsscreen_descr *,
    205  1.31      matt                          void **, int *, int *, long *);
    206  1.31      matt static void	qv_free_screen(void *, void *);
    207  1.31      matt static int	qv_show_screen(void *, void *, int,
    208  1.31      matt 				     void (*) (void *, int, int), void *);
    209  1.31      matt //static void	qv_crsr_blink(void *);
    210  1.31      matt 
    211  1.31      matt int             qvauxprint(void *, const char *);
    212  1.31      matt 
    213  1.31      matt const struct wsdisplay_accessops qv_accessops = {
    214  1.31      matt 	.ioctl = qv_ioctl,
    215  1.31      matt 	.mmap = qv_mmap,
    216  1.31      matt 	.alloc_screen = qv_alloc_screen,
    217  1.31      matt 	.free_screen = qv_free_screen,
    218  1.31      matt 	.show_screen = qv_show_screen,
    219  1.31      matt };
    220   1.1  jonathan 
    221  1.31      matt struct	qv_screen {
    222  1.31      matt         struct qv_softc *ss_sc;
    223  1.31      matt         const struct wsscreen_descr *ss_type;
    224  1.31      matt 	int	        ss_curx;
    225  1.31      matt 	int	        ss_cury;
    226  1.31      matt 	u_char	        ss_image[QV_ROWS][QV_COLS];	/* Image of screen */
    227  1.31      matt 	u_char	        ss_attr[QV_ROWS][QV_COLS];	/* Reversed etc... */
    228  1.31      matt };
    229   1.1  jonathan 
    230  1.31      matt static	struct qv_screen qv_conscreen; /* XXX no console support */
    231   1.1  jonathan 
    232  1.31      matt static	callout_t qv_cursor_ch;
    233   1.1  jonathan 
    234  1.31      matt CFATTACH_DECL_NEW(qv, sizeof(struct qv_softc),
    235  1.31      matt     qv_match, qv_attach, NULL, NULL);
    236  1.31      matt #if 0
    237  1.31      matt static int	genfb_match_qv(device_t, cfdata_t, void *);
    238  1.31      matt static void	genfb_attach_qv(device_t, device_t, void *);
    239  1.31      matt static int	genfb_ioctl_qv(void *, void *, u_long, void *, int, struct lwp*);
    240  1.31      matt static paddr_t	genfb_mmap_qv(void *, void *, off_t, int);
    241  1.31      matt static int      genfb_borrow_qv(void *, bus_addr_t, bus_space_handle_t *);
    242   1.1  jonathan 
    243  1.31      matt CFATTACH_DECL_NEW(genfb_qv, sizeof(struct genfb_qv_softc),
    244  1.31      matt     genfb_match_qv, genfb_attach_qv, NULL, NULL);
    245  1.31      matt #endif
    246   1.1  jonathan 
    247   1.1  jonathan /*
    248  1.31      matt  * autoconf match function
    249   1.1  jonathan  */
    250  1.31      matt int
    251  1.31      matt qv_match(device_t parent, cfdata_t match, void *aux)
    252  1.31      matt {
    253  1.31      matt         struct uba_attach_args *ua = aux;
    254  1.31      matt         struct uba_softc *uh = device_private(parent);
    255  1.31      matt 
    256  1.31      matt         /* set up interrupts so the vector can be detected */
    257  1.31      matt 
    258  1.31      matt  	/* initialize qv interrupt controller */
    259  1.31      matt  	qv_ic_init(ua, QV_IC);
    260  1.31      matt 
    261  1.31      matt         /* set vertical retrace interrupt */
    262  1.31      matt         qv_ic_setvec(ua, QV_IC, QV_SYNC_VEC, uh->uh_lastiv - 4);
    263  1.31      matt         qv_ic_enable(ua, QV_IC, QV_SYNC_VEC, QV_IC_ENA);
    264  1.31      matt         qv_ic_arm(ua, QV_IC, QV_SYNC_VEC);
    265  1.31      matt 
    266  1.31      matt         /* enable interrupts */
    267  1.31      matt 	bus_space_write_2(ua->ua_iot, ua->ua_ioh, QV_CSR,
    268  1.31      matt 	        bus_space_read_2(ua->ua_iot, ua->ua_ioh, QV_CSR) | (1 << 6));
    269   1.1  jonathan 
    270  1.31      matt         qv_ic_force(ua, QV_IC, QV_SYNC_VEC);
    271  1.31      matt 
    272  1.31      matt 	DELAY(20000);
    273  1.31      matt 
    274  1.31      matt         /* disable interrupts */
    275  1.31      matt         qv_ic_enable(ua, QV_IC, QV_SYNC_VEC, QV_IC_DIS);
    276  1.31      matt 
    277  1.31      matt         return 1;
    278  1.31      matt }
    279   1.1  jonathan 
    280  1.31      matt /* controller register write helper function */
    281  1.31      matt static inline void
    282  1.31      matt qv_reg_wr(struct qv_softc *sc, uint16_t addr, uint16_t data)
    283  1.31      matt {
    284  1.31      matt         bus_space_write_2(sc->sc_iot, sc->sc_ioh, addr, data);
    285  1.31      matt }
    286   1.1  jonathan 
    287  1.31      matt /* controller register read helper function */
    288  1.31      matt static inline uint16_t
    289  1.31      matt qv_reg_rd(struct qv_softc *sc, uint16_t addr)
    290  1.31      matt {
    291  1.31      matt         return bus_space_read_2(sc->sc_iot, sc->sc_ioh, addr);
    292  1.31      matt }
    293   1.1  jonathan 
    294   1.1  jonathan /*
    295  1.31      matt  * write a 6845 CRT controller register
    296   1.1  jonathan  */
    297  1.31      matt static  void
    298  1.31      matt qv_crtc_wr(struct qv_softc *sc, uint16_t addr, uint16_t data)
    299  1.31      matt {
    300  1.31      matt         qv_reg_wr(sc, QV_CRTC_AR, addr);
    301  1.31      matt         qv_reg_wr(sc, QV_CRTC_DR, data);
    302  1.31      matt }
    303  1.31      matt 
    304   1.1  jonathan /*
    305  1.31      matt  * write a set of a set of video timing parameters to the CRTC
    306   1.1  jonathan  */
    307  1.31      matt static void
    308  1.31      matt qv_setcrtc(struct qv_softc *sc, const uint16_t *pp)
    309  1.31      matt {
    310  1.31      matt         int i;
    311  1.31      matt 
    312  1.31      matt         for (i = 0; i < 14; i++)
    313  1.31      matt                 qv_crtc_wr(sc, i, pp[i]);
    314  1.31      matt }
    315   1.1  jonathan 
    316  1.31      matt static void inline
    317  1.31      matt qv_ic_write(struct uba_attach_args *ua, bus_size_t offs, uint16_t value)
    318  1.31      matt {
    319  1.31      matt         bus_space_write_2(ua->ua_iot, ua->ua_ioh, offs, value);
    320  1.31      matt }
    321   1.1  jonathan 
    322  1.31      matt void
    323  1.31      matt qv_ic_init(struct uba_attach_args *ua, bus_size_t offs)
    324  1.31      matt {
    325  1.31      matt         static int initted;
    326  1.31      matt         int i;
    327  1.31      matt 
    328  1.31      matt         if (!initted) {
    329  1.31      matt 		/* init the interrupt controller */
    330  1.31      matt 	        qv_ic_write(ua, QV_IC_SR + offs, QV_IC_RESET);
    331  1.31      matt 		/* reset irr			 */
    332  1.31      matt 	        qv_ic_write(ua, QV_IC_SR + offs, QV_IC_CLRIRR);
    333  1.31      matt 		/* specify individual vectors	 */
    334  1.31      matt 	        qv_ic_write(ua, QV_IC_SR + offs, QV_IC_MODE);
    335  1.31      matt 		/* preset autoclear data	 */
    336  1.31      matt 	        qv_ic_write(ua, QV_IC_SR + offs, QV_IC_ACREG);
    337  1.31      matt 		/* all setup as autoclear	 */
    338  1.31      matt 	        qv_ic_write(ua, QV_IC_DR + offs, 0xff);
    339  1.31      matt 
    340  1.31      matt 		/* clear all vector addresses */
    341  1.31      matt                 for (i = 0; i < 8; i++)
    342  1.31      matt                         qv_ic_setvec(ua, offs, i, 0);
    343  1.31      matt 
    344  1.31      matt                 initted = 1;
    345  1.31      matt         }
    346  1.31      matt }
    347  1.31      matt 
    348  1.31      matt void
    349  1.31      matt qv_ic_setvec(struct uba_attach_args *ua, bus_size_t offs, int ic_vec, int vecnum)
    350  1.31      matt {
    351  1.31      matt 	/* preset vector address	*/
    352  1.31      matt 	qv_ic_write(ua, QV_IC_SR + offs, QV_IC_RMEM | RMEM_BC_1 | ic_vec);
    353  1.31      matt 	/* give it the vector number	*/
    354  1.31      matt 	qv_ic_write(ua, QV_IC_DR + offs, vecnum);
    355  1.31      matt }
    356  1.31      matt 
    357  1.31      matt void
    358  1.31      matt qv_ic_enable(struct uba_attach_args *ua, bus_size_t offs, int ic_vec, int enable)
    359  1.31      matt {
    360  1.31      matt         if (enable)
    361  1.31      matt 		/* enable the interrupt */
    362  1.31      matt 	        qv_ic_write(ua, QV_IC_SR + offs, QV_IC_CIMR | ic_vec);
    363  1.31      matt         else
    364  1.31      matt 		/* disable the interrupt */
    365  1.31      matt 	        qv_ic_write(ua, QV_IC_SR + offs, QV_IC_SIMR | ic_vec);
    366  1.31      matt }
    367  1.31      matt 
    368  1.31      matt void
    369  1.31      matt qv_ic_arm(struct uba_attach_args *ua, bus_size_t offs, int arm)
    370  1.31      matt {
    371  1.31      matt         if (arm)
    372  1.31      matt 		/* arm the interrupt ctrl	*/
    373  1.31      matt                 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_ARM);
    374  1.31      matt         else
    375  1.31      matt 		/* disarm the interrupt ctrl	*/
    376  1.31      matt                 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_DISARM);
    377  1.31      matt }
    378  1.31      matt 
    379  1.31      matt void
    380  1.31      matt qv_ic_force(struct uba_attach_args *ua, bus_size_t offs, int ic_vec)
    381  1.31      matt {
    382  1.31      matt 	/* force an interrupt	*/
    383  1.31      matt 	qv_ic_write(ua, QV_IC_SR + offs, QV_IC_SIRR | ic_vec);
    384  1.31      matt }
    385   1.1  jonathan 
    386   1.1  jonathan /*
    387  1.31      matt  * print attachment message
    388   1.1  jonathan  */
    389  1.31      matt int
    390  1.31      matt qvauxprint(void *aux, const char *pnp)
    391  1.31      matt {
    392  1.31      matt         if (pnp) {
    393  1.31      matt                 aprint_normal("qvaux at %s", pnp);
    394  1.31      matt                 return (UNCONF);
    395  1.31      matt         }
    396  1.31      matt         return 0;
    397  1.31      matt }
    398   1.1  jonathan 
    399   1.1  jonathan /*
    400  1.31      matt  * autoconf attach function
    401   1.1  jonathan  */
    402  1.31      matt void
    403  1.31      matt qv_attach(device_t parent, device_t self, void *aux)
    404  1.31      matt {
    405  1.31      matt         struct qv_softc *sc = device_private(self);
    406  1.31      matt         struct uba_softc *uh = device_private(parent);
    407  1.31      matt         struct uba_attach_args *ua = aux;
    408  1.31      matt         struct uba_attach_args aa;
    409  1.31      matt 	int fcookie;
    410  1.31      matt         struct wsemuldisplaydev_attach_args emulaa;
    411  1.31      matt //        struct wsdisplaydev_attach_args dispaa;
    412  1.31      matt         struct wsdisplay_font *console_font;
    413  1.31      matt 	int line;
    414  1.31      matt 
    415  1.31      matt         sc->sc_dev = self;
    416  1.31      matt         sc->sc_iot = ua->ua_iot;
    417  1.31      matt         sc->sc_ioh = ua->ua_ioh;
    418  1.31      matt         sc->sc_fbt = sc->sc_iot;
    419  1.31      matt         sc->sc_fbphys = QMEMBASE + ((qv_reg_rd(sc, QV_CSR) & QV_CSR_BANK) << 7);
    420  1.31      matt 	if (bus_space_map(sc->sc_fbt, sc->sc_fbphys, QVSIZE,
    421  1.31      matt 			BUS_SPACE_MAP_LINEAR, &sc->sc_fbh)) {
    422  1.31      matt 		aprint_error_dev(self, "Couldn't alloc graphics memory.\n");
    423  1.31      matt 		return;
    424  1.31      matt 	}
    425   1.1  jonathan 
    426  1.31      matt 	aprint_normal(": fb %8lo", sc->sc_fbphys & 0x3fffff);
    427  1.31      matt 	sc->sc_fb = bus_space_vaddr(sc->sc_fbt, sc->sc_fbh);
    428  1.31      matt 	sc->sc_scanmap = (uint16_t *)&sc->sc_fb[QV_SCANMAP];
    429  1.31      matt #if 0
    430  1.31      matt 	if (extent_alloc_region(((struct uba_vsoftc*)uh)->uv_sgmap.aps_ex,
    431  1.31      matt 			sc->sc_fbphys & 0x3fffff, QVSIZE, EX_NOWAIT)) {
    432  1.31      matt 		aprint_error_dev(self,
    433  1.31      matt 			"Couldn't alloc graphics memory in sgmap.\n");
    434  1.31      matt 		return;
    435  1.31      matt 	}
    436  1.31      matt #endif
    437  1.31      matt 	//aprint_normal(": fb 0x%08lx", sc->sc_fbphys & 0x3fffff);
    438   1.8   gehenna 
    439  1.31      matt 	bzero(sc->sc_fb, QVSIZE);
    440  1.31      matt 
    441  1.31      matt 	for (line = 0; line < QV_YWIDTH; line++) {
    442  1.31      matt 	        sc->sc_scanmap[line] = line;
    443  1.31      matt 	}
    444   1.1  jonathan 
    445  1.31      matt         /* program crtc */
    446  1.31      matt         qv_setcrtc(sc, qv_stdscreen[2].qv_crtc_param);
    447  1.31      matt 
    448  1.31      matt         /* enable video output */
    449  1.31      matt         qv_reg_wr(sc, QV_CSR, qv_reg_rd(sc, QV_CSR) | (1 << 2) | (1 << 3));
    450  1.31      matt #if 0
    451  1.31      matt 	if (sc->sc_curscr == NULL)
    452  1.31      matt 		callout_init(&qv_cursor_ch, 0);
    453  1.31      matt 	sc->sc_curscr = &qv_conscreen;
    454   1.1  jonathan 
    455  1.31      matt 	callout_reset(&qv_cursor_ch, hz / 2, qv_crsr_blink, sc);
    456   1.1  jonathan #endif
    457  1.31      matt         /* interrupt handlers - XXX */
    458   1.1  jonathan 
    459  1.31      matt         uh->uh_lastiv -= 4;
    460   1.1  jonathan 
    461  1.31      matt         wsfont_init();
    462  1.31      matt 	if ((fcookie = wsfont_find(NULL, 8, 15, 0, WSDISPLAY_FONTORDER_R2L,
    463  1.31      matt 	    WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP)) < 0) {
    464  1.31      matt 		aprint_error_dev(self, "could not find 8x15 font\n");
    465  1.31      matt 		return;
    466  1.31      matt 	}
    467  1.31      matt 	if (wsfont_lock(fcookie, &console_font) != 0) {
    468  1.31      matt 		aprint_error_dev(self, "could not lock 8x15 font\n");
    469  1.31      matt 		return;
    470  1.31      matt 	}
    471  1.31      matt 	sc->sc_font = console_font->data;
    472   1.1  jonathan 
    473  1.31      matt         aprint_normal("\n");
    474   1.1  jonathan 
    475  1.31      matt 	aa.ua_iot = ua->ua_iot;
    476  1.31      matt 	aa.ua_ioh = ua->ua_ioh + 32; // offset
    477  1.31      matt 	aa.ua_cvec = ua->ua_cvec - 4;
    478  1.31      matt 	if (config_search_ia(NULL, self, "qv", &aa) != NULL) {
    479  1.31      matt 	        config_found_ia(self, "qv", &aa, qvauxprint);
    480  1.31      matt                 uh->uh_lastiv -= 4;
    481  1.31      matt 	}
    482   1.1  jonathan 
    483  1.31      matt 	emulaa.console = 0; /* Not console */
    484  1.31      matt 	emulaa.scrdata = &qv_screenlist;
    485  1.31      matt 	emulaa.accessops = &qv_accessops;
    486  1.31      matt 	emulaa.accesscookie = self;
    487  1.31      matt 	if (config_search_ia(NULL, self, "wsemuldisplaydev", &emulaa) != NULL) {
    488  1.31      matt 	        config_found_ia(self, "wsemuldisplaydev", &emulaa,
    489  1.31      matt 	            wsemuldisplaydevprint);
    490  1.31      matt 	}
    491  1.31      matt 
    492  1.31      matt         //console_debugger();
    493  1.31      matt 	return;
    494  1.31      matt }
    495  1.31      matt 
    496  1.31      matt /* QVSS frame buffer */
    497   1.1  jonathan 
    498  1.31      matt /*      uint_32 is stored little endian in frame buffer */
    499  1.31      matt /*      bits are stored little endian in frame buffer   */
    500   1.1  jonathan 
    501  1.31      matt /*      uint_32 *fb;                                     */
    502  1.31      matt /*      fb = (int *)phystova(0x303c0000);                */
    503  1.31      matt /*      *fb = 0x00000001; */ /* sets bit in first column */
    504   1.1  jonathan 
    505  1.31      matt /* Frame Buffer Usage */
    506  1.31      matt 
    507  1.31      matt /* characters are 8 bits wide and QVHEIGHT high */
    508  1.31      matt /* the scan map is allocated in terms of character height, */
    509  1.31      matt /* so a pointer to the top line of a character can step to the */
    510  1.31      matt /* next row without looking up the memory location in the scan map */
    511  1.31      matt 
    512  1.31      matt static	char *cursor;
    513  1.31      matt static	int cur_on;
    514  1.31      matt 
    515  1.31      matt /*
    516  1.31      matt  * return pointer to line in character glyph
    517  1.31      matt  */
    518  1.31      matt static inline char *
    519  1.31      matt qv_font(struct qv_softc *sc, int c, int line)
    520  1.31      matt {
    521  1.31      matt         /* map char to font table offset */
    522  1.31      matt         if (c < 32)
    523  1.31      matt                 c = 32;
    524  1.31      matt         else if (c > 127)
    525  1.31      matt                 c -= 66;
    526  1.31      matt         else
    527  1.31      matt                 c -= 32;
    528  1.31      matt 
    529  1.31      matt         /* return pointer line in font glyph */
    530  1.31      matt         return &sc->sc_font[c*QV_CHEIGHT + line];
    531   1.1  jonathan }
    532   1.1  jonathan 
    533   1.1  jonathan /*
    534  1.31      matt  * return pointer to character line in frame buffer
    535   1.1  jonathan  */
    536  1.31      matt static inline char *
    537  1.31      matt qv_fbp(struct qv_softc *sc, int row, int col, int line)
    538   1.1  jonathan {
    539  1.31      matt         return &sc->sc_fb[col + sc->sc_scanmap[row*QV_CHEIGHT + line]*QV_COLS];
    540   1.1  jonathan }
    541   1.1  jonathan 
    542  1.31      matt /*
    543  1.31      matt  * callout callback function to blink cursor
    544  1.31      matt  */
    545  1.31      matt #if 0
    546  1.31      matt static void
    547  1.31      matt qv_crsr_blink(void *arg)
    548   1.1  jonathan {
    549  1.31      matt         struct qv_softc *sc = arg;
    550  1.31      matt 
    551  1.31      matt 	if (cur_on)
    552  1.31      matt 		*cursor ^= 255;
    553  1.31      matt 	callout_reset(&qv_cursor_ch, hz / 2, qv_crsr_blink, sc);
    554  1.31      matt }
    555   1.1  jonathan #endif
    556  1.31      matt /*
    557  1.31      matt  * emulop cursor
    558  1.31      matt  */
    559  1.31      matt void
    560  1.31      matt qv_cursor(void *id, int on, int row, int col)
    561  1.31      matt {
    562  1.31      matt 	struct qv_screen * const ss = id;
    563  1.31      matt 
    564  1.31      matt 	if (ss == ss->ss_sc->sc_curscr) {
    565  1.31      matt 		*qv_fbp(ss->ss_sc, ss->ss_cury, ss->ss_curx, 14)
    566  1.31      matt 		    = *qv_font(ss->ss_sc,
    567  1.31      matt 		        ss->ss_image[ss->ss_cury][ss->ss_curx], 14);
    568  1.31      matt 		cursor = qv_fbp(ss->ss_sc, row, col, 14);
    569  1.31      matt 		if ((cur_on = on))
    570  1.31      matt 			*cursor ^= 255;
    571   1.1  jonathan 	}
    572  1.31      matt 	ss->ss_curx = col;
    573  1.31      matt 	ss->ss_cury = row;
    574   1.1  jonathan }
    575   1.1  jonathan 
    576   1.1  jonathan /*
    577  1.31      matt  * emulop mapchar
    578   1.1  jonathan  */
    579   1.8   gehenna int
    580  1.31      matt qv_mapchar(void *id, int uni, unsigned int *index)
    581   1.1  jonathan {
    582  1.31      matt 	if (uni < 256) {
    583  1.31      matt 		*index = uni;
    584  1.31      matt 		return (5);
    585   1.1  jonathan 	}
    586  1.31      matt 	*index = ' ';
    587  1.31      matt 	return (0);
    588   1.1  jonathan }
    589   1.1  jonathan 
    590  1.31      matt /*
    591  1.31      matt  * emulop putchar
    592  1.31      matt  */
    593  1.31      matt static void
    594  1.31      matt qv_putchar(void *id, int row, int col, u_int c, long attr)
    595   1.1  jonathan {
    596  1.31      matt 	struct qv_screen * const ss = id;
    597  1.31      matt 	int i;
    598  1.31      matt         char *gp;
    599  1.31      matt         char *fp;
    600  1.31      matt         char rvid;
    601  1.31      matt 
    602  1.31      matt 	c &= 0xff;
    603  1.31      matt 
    604  1.31      matt 	ss->ss_image[row][col] = c;
    605  1.31      matt 	ss->ss_attr[row][col] = attr;
    606  1.31      matt 	if (ss != ss->ss_sc->sc_curscr)
    607  1.31      matt 		return;
    608  1.31      matt 
    609  1.31      matt         gp = qv_font(ss->ss_sc, c, 0);
    610  1.31      matt         fp = qv_fbp(ss->ss_sc, row, col, 0);
    611  1.31      matt         rvid = (attr & WSATTR_REVERSE) ? 0xff : 0x00;
    612  1.31      matt         for (i = 0; i < QV_CHEIGHT; i++) {
    613  1.31      matt                 *fp = *gp++ ^ rvid;
    614  1.31      matt                 fp += QV_COLS;
    615  1.31      matt         }
    616   1.1  jonathan 
    617  1.31      matt 	if (attr & WSATTR_UNDERLINE)
    618  1.31      matt 	        *qv_fbp(ss->ss_sc, row, col, 14)
    619  1.31      matt 	            ^= *qv_fbp(ss->ss_sc, row, col, 14);
    620   1.1  jonathan }
    621   1.1  jonathan 
    622  1.31      matt /*
    623  1.31      matt  * emulop copy columns - copies columns inside a row
    624  1.31      matt  */
    625  1.31      matt static void
    626  1.31      matt qv_copycols(void *id, int row, int srccol, int dstcol, int ncols)
    627   1.1  jonathan {
    628  1.31      matt 	struct qv_screen * const ss = id;
    629  1.31      matt 	int i;
    630   1.1  jonathan 
    631  1.31      matt 	memcpy(&ss->ss_image[row][dstcol], &ss->ss_image[row][srccol], ncols);
    632  1.31      matt 	memcpy(&ss->ss_attr[row][dstcol], &ss->ss_attr[row][srccol], ncols);
    633  1.31      matt 	if (ss != ss->ss_sc->sc_curscr)
    634  1.31      matt 		return;
    635  1.31      matt 	for (i = 0; i < QV_CHEIGHT; i++)
    636  1.31      matt 	        memcpy(qv_fbp(ss->ss_sc, row, dstcol, i),
    637  1.31      matt 	            qv_fbp(ss->ss_sc, row, srccol, i), ncols);
    638   1.1  jonathan }
    639   1.1  jonathan 
    640  1.31      matt /*
    641  1.31      matt  * emulop erase columns - erases a bunch of chars inside one row
    642  1.31      matt  */
    643  1.31      matt static void
    644  1.31      matt qv_erasecols(void *id, int row, int startcol, int ncols, long fillattr)
    645   1.5       scw {
    646  1.31      matt 	struct qv_screen * const ss = id;
    647  1.31      matt 	int i;
    648   1.5       scw 
    649  1.31      matt 	memset(&ss->ss_image[row][startcol], 0, ncols);
    650  1.31      matt 	memset(&ss->ss_attr[row][startcol], 0, ncols);
    651  1.31      matt 	if (ss != ss->ss_sc->sc_curscr)
    652  1.31      matt 		return;
    653  1.31      matt 	for (i = 0; i < QV_CHEIGHT; i++)
    654  1.31      matt 	        memset(qv_fbp(ss->ss_sc, row, startcol, i), 0, ncols);
    655   1.5       scw }
    656   1.5       scw 
    657   1.5       scw /*
    658  1.31      matt  * overlap check
    659  1.31      matt  * return 0 if no overlap
    660  1.31      matt  *        -1 if overlap and dst is less than src (move up)
    661  1.31      matt  * 	  +1 if overlap and src is less than dst (move down)
    662   1.5       scw  */
    663  1.31      matt static inline int
    664  1.31      matt qv_rows_overlap(int srcrow, int dstrow, int nrows)
    665  1.31      matt {
    666  1.31      matt 	if (dstrow < srcrow) {
    667  1.31      matt 		if (dstrow + nrows <= srcrow)
    668  1.31      matt 			return 0;
    669  1.31      matt 		else
    670  1.31      matt 			return -1;
    671  1.31      matt 	}
    672  1.31      matt 	else {
    673  1.31      matt 		if (srcrow + nrows <= dstrow)
    674  1.31      matt 			return 0;
    675  1.31      matt 		else
    676  1.31      matt 			return 1;
    677  1.31      matt 	}
    678  1.31      matt }
    679   1.1  jonathan 
    680   1.1  jonathan /*
    681  1.31      matt  * emulop copyrows - copy entire rows
    682   1.1  jonathan  */
    683  1.31      matt static void
    684  1.31      matt qv_copyrows(void *id, int srcrow, int dstrow, int nrows)
    685   1.1  jonathan {
    686  1.31      matt 	struct qv_screen * const ss = id;
    687  1.31      matt 	int ol;
    688  1.31      matt 	int n;
    689  1.31      matt 	int line;
    690  1.31      matt 	int tmp;
    691  1.31      matt 	uint16_t *sp;
    692  1.31      matt 	uint16_t *dp;
    693  1.31      matt 
    694  1.31      matt 	memcpy(&ss->ss_image[dstrow][0], &ss->ss_image[srcrow][0],
    695  1.31      matt 	    nrows * QV_COLS);
    696  1.31      matt 	memcpy(&ss->ss_attr[dstrow][0], &ss->ss_attr[srcrow][0],
    697  1.31      matt 	    nrows * QV_COLS);
    698  1.31      matt 	if (ss != ss->ss_sc->sc_curscr)
    699  1.31      matt 		return;
    700  1.31      matt 
    701  1.31      matt 	ol = qv_rows_overlap(srcrow, dstrow, nrows);
    702  1.31      matt 	if (ol == 0)
    703  1.31      matt 		for (n = 0; n < nrows; n++)
    704  1.31      matt 			bcopy(qv_fbp(ss->ss_sc, srcrow + n, 0, 0),
    705  1.31      matt 	    		    qv_fbp(ss->ss_sc, dstrow + n, 0, 0), QV_NEXTROW);
    706  1.31      matt 	else if (ol < 0) {
    707  1.31      matt 	 	for (n = 0; n < nrows; n++) {
    708  1.31      matt 			dp = &ss->ss_sc->sc_scanmap[(dstrow + n)*QV_CHEIGHT];
    709  1.31      matt 			sp = &ss->ss_sc->sc_scanmap[(srcrow + n)*QV_CHEIGHT];
    710  1.31      matt 			for (line = 0; line < QV_CHEIGHT; line++) {
    711  1.31      matt 				tmp = *dp;
    712  1.31      matt 				*dp = *sp;
    713  1.31      matt 				*sp = tmp;
    714  1.31      matt 				dp++;
    715  1.31      matt 				sp++;
    716   1.1  jonathan 			}
    717  1.31      matt 		}
    718  1.31      matt 		qv_copyrows(id, dstrow + nrows - srcrow + dstrow,
    719  1.31      matt 		    dstrow + nrows, srcrow - dstrow);
    720  1.31      matt 	}
    721   1.1  jonathan 	else {
    722  1.31      matt 	 	for (n = nrows - 1; n >= 0; n--) {
    723  1.31      matt 			dp = &ss->ss_sc->sc_scanmap[(dstrow + n)*QV_CHEIGHT];
    724  1.31      matt 			sp = &ss->ss_sc->sc_scanmap[(srcrow + n)*QV_CHEIGHT];
    725  1.31      matt 			for (line = 0; line < QV_CHEIGHT; line++) {
    726  1.31      matt 				tmp = *dp;
    727  1.31      matt 				*dp = *sp;
    728  1.31      matt 				*sp = tmp;
    729  1.31      matt 				dp++;
    730  1.31      matt 				sp++;
    731  1.31      matt 			}
    732  1.31      matt 		}
    733  1.31      matt 		qv_copyrows(id, srcrow, dstrow, dstrow - srcrow);
    734   1.1  jonathan 	}
    735   1.1  jonathan }
    736  1.31      matt 
    737   1.1  jonathan /*
    738  1.31      matt  * emulop eraserows - erase a number of entire rows
    739   1.1  jonathan  */
    740  1.31      matt static void
    741  1.31      matt qv_eraserows(void *id, int startrow, int nrows, long fillattr)
    742   1.1  jonathan {
    743  1.31      matt 	struct qv_screen * const ss = id;
    744  1.31      matt 	int row;
    745   1.1  jonathan 
    746  1.31      matt 	memset(&ss->ss_image[startrow][0], 0, nrows * QV_COLS);
    747  1.31      matt 	memset(&ss->ss_attr[startrow][0], 0, nrows * QV_COLS);
    748  1.31      matt 	if (ss != ss->ss_sc->sc_curscr)
    749   1.1  jonathan 		return;
    750  1.31      matt 
    751  1.31      matt 	for (row = startrow; row < startrow + nrows; row++) {
    752  1.31      matt 	        memset(qv_fbp(ss->ss_sc, row, 0, 0), 0, QV_NEXTROW);
    753  1.31      matt 	}
    754  1.31      matt }
    755  1.31      matt 
    756  1.31      matt /*
    757  1.31      matt  * emulop allocattr
    758  1.31      matt  */
    759  1.31      matt static int
    760  1.31      matt qv_allocattr(void *id, int fg, int bg, int flags, long *attrp)
    761  1.31      matt {
    762  1.31      matt 	*attrp = flags;
    763  1.31      matt 	return 0;
    764  1.31      matt }
    765   1.1  jonathan 
    766  1.31      matt /*
    767  1.31      matt  * emulop setcursor
    768  1.31      matt  */
    769  1.31      matt static void
    770  1.31      matt qv_setcursor(struct qv_softc *sc, struct wsdisplay_cursor *v)
    771  1.31      matt {
    772  1.31      matt 	uint16_t red, green, blue;
    773  1.31      matt 	uint32_t curfg[16], curmask[16];
    774  1.31      matt 	uint16_t *curp;
    775  1.31      matt 	int i;
    776   1.1  jonathan 
    777  1.31      matt 	/* Enable cursor */
    778  1.31      matt 	if (v->which & WSDISPLAY_CURSOR_DOCUR) {
    779  1.31      matt 	        sc->sc_curon = (v->enable) ? CUR_ON : CUR_OFF;
    780  1.31      matt 	        qv_crtc_wr(sc, CUR_START, sc->sc_curon | (sc->sc_cury & 0x0f));
    781  1.31      matt 	}
    782  1.31      matt 	if (v->which & WSDISPLAY_CURSOR_DOHOT) {
    783  1.31      matt 		sc->sc_curhotX = v->hot.x;
    784  1.31      matt 		sc->sc_curhotY = v->hot.y;
    785  1.31      matt 	}
    786  1.31      matt 	if (v->which & WSDISPLAY_CURSOR_DOCMAP) {
    787  1.31      matt 		/* First background */
    788  1.31      matt 		red = fusword(v->cmap.red);
    789  1.31      matt 		green = fusword(v->cmap.green);
    790  1.31      matt 		blue = fusword(v->cmap.blue);
    791  1.31      matt 		bgmask = (((30L * red + 59L * green + 11L * blue) >> 8) >=
    792  1.31      matt 		    (((1<<8)-1)*50)) ? ~0 : 0;
    793  1.31      matt 		red = fusword(v->cmap.red+2);
    794  1.31      matt 		green = fusword(v->cmap.green+2);
    795  1.31      matt 		blue = fusword(v->cmap.blue+2);
    796  1.31      matt 		fgmask = (((30L * red + 59L * green + 11L * blue) >> 8) >=
    797  1.31      matt 		    (((1<<8)-1)*50)) ? ~0 : 0;
    798  1.31      matt 	}
    799  1.31      matt 	if (v->which & WSDISPLAY_CURSOR_DOSHAPE) {
    800  1.31      matt 		copyin(v->image, curfg, sizeof(curfg));
    801  1.31      matt 		copyin(v->mask, curmask, sizeof(curmask));      /* not used */
    802  1.31      matt 	        curp = (uint16_t *) &(sc->sc_fb)[QV_CURSRAM];
    803  1.31      matt 		for (i = 0; i < sizeof(curfg)/sizeof(curfg[0]); i++) {
    804  1.31      matt 		        curp[i] = (uint16_t)curfg[i];
    805   1.1  jonathan 		}
    806   1.1  jonathan 	}
    807   1.1  jonathan }
    808   1.1  jonathan 
    809   1.1  jonathan /*
    810  1.31      matt  * emulop ioctl
    811   1.1  jonathan  */
    812   1.8   gehenna int
    813  1.31      matt qv_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    814   1.1  jonathan {
    815  1.31      matt 	struct wsdisplay_fbinfo *fb = (void *)data;
    816  1.31      matt 	//static uint16_t curc;
    817  1.31      matt         struct qv_softc *sc = device_private(v);
    818  1.31      matt 
    819  1.31      matt 	switch (cmd) {
    820  1.31      matt 	case WSDISPLAYIO_GTYPE:
    821  1.31      matt 		*(u_int *)data = WSDISPLAY_TYPE_VAX_MONO;
    822   1.1  jonathan 		break;
    823   1.1  jonathan 
    824  1.31      matt 	case WSDISPLAYIO_GINFO:
    825  1.31      matt 		fb->height = QV_YWIDTH;
    826  1.31      matt 		fb->width = QV_XWIDTH;
    827  1.31      matt 		fb->depth = 1;
    828  1.31      matt 		fb->cmsize = 2;
    829   1.1  jonathan 		break;
    830   1.1  jonathan 
    831  1.31      matt 	case WSDISPLAYIO_SVIDEO:
    832  1.31      matt 		if (*(u_int *)data == WSDISPLAYIO_VIDEO_ON) {
    833  1.31      matt                         /* enable video output */
    834  1.31      matt   		        qv_reg_wr(sc, QV_CSR,
    835  1.31      matt   		            qv_reg_rd(sc, QV_CSR) | (1 << 2));
    836  1.31      matt 		} else {
    837  1.31      matt                         /* disable video output */
    838  1.31      matt                         qv_reg_wr(sc, QV_CSR,
    839  1.31      matt                             qv_reg_rd(sc, QV_CSR) & ~(1 << 2));
    840  1.31      matt 		}
    841  1.31      matt 		break;
    842  1.31      matt 
    843  1.31      matt 	case WSDISPLAYIO_GVIDEO:
    844  1.31      matt 		*(u_int *)data = (qv_reg_rd(sc, QV_CSR) & (1 << 2))
    845  1.31      matt 		    ? WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    846  1.31      matt 		break;
    847  1.31      matt 
    848  1.31      matt 	case WSDISPLAYIO_SCURSOR:
    849  1.31      matt 		qv_setcursor(sc, (struct wsdisplay_cursor *)data);
    850   1.1  jonathan 		break;
    851   1.1  jonathan 
    852  1.31      matt 	case WSDISPLAYIO_SCURPOS:
    853  1.31      matt 	        sc->sc_curx = ((struct wsdisplay_curpos *)data)->x;
    854  1.31      matt 		sc->sc_cury = ((struct wsdisplay_curpos *)data)->y;
    855  1.31      matt                 qv_crtc_wr(sc, CUR_START, CUR_OFF | (sc->sc_cury & 0x0f));
    856  1.31      matt                 qv_crtc_wr(sc, CUR_HI, sc->sc_cury >> 4);
    857  1.31      matt                 qv_reg_wr(sc, QV_CUR_X, sc->sc_curx);
    858  1.31      matt                 qv_crtc_wr(sc, CUR_START,
    859  1.31      matt                     sc->sc_curon | (sc->sc_cury & 0x0f));
    860   1.1  jonathan 		break;
    861  1.31      matt 
    862  1.31      matt 	case WSDISPLAYIO_GCURPOS:
    863  1.31      matt 		((struct wsdisplay_curpos *)data)->x = sc->sc_curx;
    864  1.31      matt 		((struct wsdisplay_curpos *)data)->y = sc->sc_cury;
    865   1.1  jonathan 		break;
    866  1.31      matt 
    867  1.31      matt 	case WSDISPLAYIO_GCURMAX:
    868  1.31      matt 		((struct wsdisplay_curpos *)data)->x = 16;
    869  1.31      matt 		((struct wsdisplay_curpos *)data)->y = 16;
    870   1.1  jonathan 		break;
    871  1.31      matt 
    872  1.31      matt 	default:
    873  1.31      matt 		return EPASSTHROUGH;
    874   1.1  jonathan 	}
    875  1.31      matt 	return 0;
    876   1.1  jonathan }
    877  1.31      matt 
    878   1.1  jonathan /*
    879  1.31      matt  * emulop mmap
    880   1.1  jonathan  */
    881  1.31      matt static paddr_t
    882  1.31      matt qv_mmap(void *v, void *vs, off_t offset, int prot)
    883   1.1  jonathan {
    884  1.31      matt         struct qv_softc *sc = device_private(v);
    885  1.31      matt 
    886  1.31      matt 	if (offset >= QVSIZE || offset < 0)
    887  1.31      matt 		return -1;
    888  1.31      matt 	return (sc->sc_fbphys) >> PGSHIFT;
    889   1.1  jonathan }
    890   1.1  jonathan 
    891   1.1  jonathan /*
    892  1.31      matt  * emulop allocate screen
    893   1.1  jonathan  */
    894  1.31      matt int
    895  1.31      matt qv_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    896  1.31      matt     int *curxp, int *curyp, long *defattrp)
    897   1.1  jonathan {
    898  1.31      matt         struct qv_softc *sc = device_private(v);
    899  1.31      matt         struct qv_screen *ss;
    900   1.1  jonathan 
    901  1.31      matt 	ss = malloc(sizeof(struct qv_screen), M_DEVBUF, M_WAITOK|M_ZERO);
    902  1.31      matt 	ss->ss_sc = sc;
    903  1.31      matt 	ss->ss_type = type;
    904  1.31      matt 	*cookiep = ss;
    905  1.31      matt 	*curxp = *curyp = *defattrp = 0;
    906  1.31      matt         printf("qv_alloc_screen: \"%s\" %p\n", type->name, ss);
    907  1.31      matt 	return 0;
    908   1.1  jonathan }
    909   1.1  jonathan 
    910   1.1  jonathan /*
    911  1.31      matt  * emulop free screen
    912   1.1  jonathan  */
    913   1.2   mycroft void
    914  1.31      matt qv_free_screen(void *v, void *cookie)
    915   1.1  jonathan {
    916  1.31      matt         printf("qv_free_screen: %p\n", cookie);
    917  1.31      matt         free(cookie, M_DEVBUF);
    918  1.31      matt }
    919   1.1  jonathan 
    920  1.31      matt /*
    921  1.31      matt  * emulop show screen
    922  1.31      matt  */
    923  1.31      matt int
    924  1.31      matt qv_show_screen(void *v, void *cookie, int waitok,
    925  1.31      matt     void (*cb)(void *, int, int), void *cbarg)
    926  1.31      matt {
    927  1.31      matt 	struct qv_screen *ss = cookie;
    928  1.31      matt 	const struct _wsscreen_descr *descr;
    929  1.31      matt 	int row, col, line;
    930  1.31      matt         printf("qv_show_screen: %p\n", cookie);
    931  1.31      matt 
    932  1.31      matt 	if (ss == ss->ss_sc->sc_curscr)
    933  1.31      matt 		return (0);
    934  1.31      matt 
    935  1.31      matt         descr = (const struct _wsscreen_descr *)(ss->ss_type);
    936  1.31      matt         qv_setcrtc(ss->ss_sc, descr->qv_crtc_param);
    937  1.31      matt 	for (row = 0; row < QV_ROWS; row++)
    938  1.31      matt 		for (line = 0; line < QV_CHEIGHT; line++) {
    939  1.31      matt 			for (col = 0; col < QV_COLS; col++) {
    940  1.31      matt 				u_char s, c = ss->ss_image[row][col];
    941  1.31      matt 
    942  1.31      matt 				if (c < 32)
    943  1.31      matt 					c = 32;
    944  1.31      matt 				s = *qv_font(ss->ss_sc, c, line);
    945  1.31      matt 				if (ss->ss_attr[row][col] & WSATTR_REVERSE)
    946  1.31      matt 					s ^= 255;
    947  1.31      matt 				*qv_fbp(ss->ss_sc, row, col, line) = s;
    948  1.31      matt 
    949  1.31      matt 				if (ss->ss_attr[row][col] & WSATTR_UNDERLINE)
    950  1.31      matt 					*qv_fbp(ss->ss_sc, row, col, line)
    951  1.31      matt 					    = 255;
    952  1.31      matt 			}
    953  1.31      matt 		}
    954  1.31      matt         cursor = qv_fbp(ss->ss_sc, ss->ss_cury, ss->ss_curx, 14);
    955  1.31      matt 	ss->ss_sc->sc_curscr = ss;
    956  1.31      matt 	return (0);
    957   1.1  jonathan }
    958   1.1  jonathan 
    959  1.31      matt #if 0
    960  1.31      matt void
    961  1.31      matt qv_reset_establish(void (*reset)(device_t), device_t dev)
    962   1.1  jonathan {
    963  1.31      matt         uba_reset_establish(reset, device_parent(dev));
    964   1.1  jonathan }
    965  1.31      matt #endif
    966  1.31      matt cons_decl(qv);
    967   1.1  jonathan 
    968  1.31      matt void
    969  1.31      matt qvcninit(struct consdev *cndev)
    970   1.1  jonathan {
    971  1.31      matt 	int fcookie;
    972  1.31      matt 	struct wsdisplay_font *console_font;
    973  1.31      matt 	extern void lkccninit(struct consdev *);
    974  1.31      matt 	extern int lkccngetc(dev_t);
    975  1.31      matt 	extern int dz_vsbus_lk201_cnattach(int);
    976  1.31      matt 
    977  1.31      matt         //printf("qvcninit: \n");
    978  1.31      matt 	/* Clear screen */
    979  1.31      matt 	//memset(qv_addr, 0, 128*864);
    980  1.31      matt 
    981  1.31      matt 	callout_init(&qv_cursor_ch, 0);
    982  1.31      matt 	//curscr = &qv_conscreen;
    983  1.31      matt 	wsdisplay_cnattach(&qv_stdscreen[0].qv_stdscreen,
    984  1.31      matt 	    &qv_conscreen, 0, 0, 0);
    985  1.31      matt 	cn_tab->cn_pri = CN_INTERNAL;
    986  1.31      matt 	wsfont_init();
    987  1.31      matt 	if ((fcookie = wsfont_find(NULL, 8, 15, 0, WSDISPLAY_FONTORDER_R2L,
    988  1.31      matt 	    WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP)) < 0)
    989  1.31      matt 	{
    990  1.31      matt 		printf("qv: could not find 8x15 font\n");
    991   1.1  jonathan 		return;
    992  1.31      matt 	}
    993  1.31      matt 	if (wsfont_lock(fcookie, &console_font) != 0) {
    994  1.31      matt 		printf("qv: could not lock 8x15 font\n");
    995   1.1  jonathan 		return;
    996  1.31      matt 	}
    997  1.31      matt 	//qf = console_font->data;
    998   1.1  jonathan 
    999  1.31      matt #if NQVKBD > 0 && 0
   1000  1.31      matt 	qvkbd_cnattach(0); /* Connect keyboard and screen together */
   1001  1.31      matt #endif
   1002   1.1  jonathan }
   1003   1.1  jonathan 
   1004   1.1  jonathan /*
   1005  1.31      matt  * Called very early to setup the glass tty as console.
   1006  1.31      matt  * Because it's called before the VM system is inited, virtual memory
   1007  1.31      matt  * for the framebuffer can be stolen directly without disturbing anything.
   1008   1.1  jonathan  */
   1009  1.31      matt void
   1010  1.31      matt qvcnprobe(struct consdev *cndev)
   1011   1.1  jonathan {
   1012  1.31      matt         printf("qvcnprobe: \n");
   1013  1.31      matt #if 0
   1014  1.31      matt 	extern vaddr_t virtual_avail;
   1015  1.31      matt 	extern const struct cdevsw wsdisplay_cdevsw;
   1016  1.31      matt 
   1017  1.31      matt 	switch (vax_boardtype) {
   1018  1.31      matt 	case VAX_BTYP_410:
   1019  1.31      matt 	case VAX_BTYP_420:
   1020  1.31      matt 	case VAX_BTYP_43:
   1021  1.31      matt 		if ((vax_confdata & KA420_CFG_L3CON) ||
   1022  1.31      matt 		    (vax_confdata & KA420_CFG_MULTU))
   1023  1.31      matt 			break; /* doesn't use graphics console */
   1024  1.31      matt 		qv_addr = (void *)virtual_avail;
   1025  1.31      matt 		virtual_avail += QVSIZE;
   1026  1.31      matt 		ioaccess((vaddr_t)qv_addr, QVADDR, (QVSIZE/VAX_NBPG));
   1027  1.31      matt 		cndev->cn_pri = CN_INTERNAL;
   1028  1.31      matt 		cndev->cn_dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw),
   1029  1.31      matt 					0);
   1030  1.31      matt 		break;
   1031  1.31      matt 	default:
   1032  1.31      matt 		break;
   1033   1.1  jonathan 	}
   1034  1.31      matt #endif
   1035   1.1  jonathan }
   1036