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