Home | History | Annotate | Line # | Download | only in uba
qv.c revision 1.33.10.1
      1  1.33.10.1  christos /*$Header: /tank/opengrok/rsync2/NetBSD/src/sys/arch/vax/uba/qv.c,v 1.33.10.1 2019/06/10 22:06:51 christos 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.33.10.1  christos __KERNEL_RCSID(0, "$Header: /tank/opengrok/rsync2/NetBSD/src/sys/arch/vax/uba/qv.c,v 1.33.10.1 2019/06/10 22:06:51 christos 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.31      matt #include <sys/malloc.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.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.32   msaitoh         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.32   msaitoh 			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.32   msaitoh 				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.32   msaitoh 			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.32   msaitoh 				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.33.10.1  christos 		if (copyin(v->cmap.red, &red, sizeof(red)) == 0 &&
    789  1.33.10.1  christos 		    copyin(v->cmap.green, &green, sizeof(green)) == 0 &&
    790  1.33.10.1  christos 		    copyin(v->cmap.blue, &blue, sizeof(blue)) == 0) {
    791  1.33.10.1  christos 			bgmask = (((30L * red + 59L * green + 11L * blue) >> 8)
    792  1.33.10.1  christos 			    >= (((1<<8)-1)*50)) ? ~0 : 0;
    793  1.33.10.1  christos 		}
    794  1.33.10.1  christos 		if (copyin(v->cmap.red + 2, &red, sizeof(red)) == 0 &&
    795  1.33.10.1  christos 		    copyin(v->cmap.green + 2, &green, sizeof(green)) == 0 &&
    796  1.33.10.1  christos 		    copyin(v->cmap.blue + 2, &blue, sizeof(blue)) == 0) {
    797  1.33.10.1  christos 			fgmask = (((30L * red + 59L * green + 11L * blue) >> 8)
    798  1.33.10.1  christos 			    >= (((1<<8)-1)*50)) ? ~0 : 0;
    799  1.33.10.1  christos 		}
    800       1.31      matt 	}
    801       1.31      matt 	if (v->which & WSDISPLAY_CURSOR_DOSHAPE) {
    802       1.31      matt 		copyin(v->image, curfg, sizeof(curfg));
    803       1.31      matt 		copyin(v->mask, curmask, sizeof(curmask));      /* not used */
    804       1.31      matt 	        curp = (uint16_t *) &(sc->sc_fb)[QV_CURSRAM];
    805       1.31      matt 		for (i = 0; i < sizeof(curfg)/sizeof(curfg[0]); i++) {
    806       1.31      matt 		        curp[i] = (uint16_t)curfg[i];
    807        1.1  jonathan 		}
    808        1.1  jonathan 	}
    809        1.1  jonathan }
    810        1.1  jonathan 
    811        1.1  jonathan /*
    812       1.31      matt  * emulop ioctl
    813        1.1  jonathan  */
    814        1.8   gehenna int
    815       1.31      matt qv_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    816        1.1  jonathan {
    817       1.31      matt 	struct wsdisplay_fbinfo *fb = (void *)data;
    818       1.31      matt 	//static uint16_t curc;
    819       1.31      matt         struct qv_softc *sc = device_private(v);
    820       1.31      matt 
    821       1.31      matt 	switch (cmd) {
    822       1.31      matt 	case WSDISPLAYIO_GTYPE:
    823       1.31      matt 		*(u_int *)data = WSDISPLAY_TYPE_VAX_MONO;
    824        1.1  jonathan 		break;
    825        1.1  jonathan 
    826       1.31      matt 	case WSDISPLAYIO_GINFO:
    827       1.31      matt 		fb->height = QV_YWIDTH;
    828       1.31      matt 		fb->width = QV_XWIDTH;
    829       1.31      matt 		fb->depth = 1;
    830       1.31      matt 		fb->cmsize = 2;
    831        1.1  jonathan 		break;
    832        1.1  jonathan 
    833       1.31      matt 	case WSDISPLAYIO_SVIDEO:
    834       1.31      matt 		if (*(u_int *)data == WSDISPLAYIO_VIDEO_ON) {
    835       1.31      matt                         /* enable video output */
    836       1.31      matt   		        qv_reg_wr(sc, QV_CSR,
    837       1.31      matt   		            qv_reg_rd(sc, QV_CSR) | (1 << 2));
    838       1.31      matt 		} else {
    839       1.31      matt                         /* disable video output */
    840       1.31      matt                         qv_reg_wr(sc, QV_CSR,
    841       1.31      matt                             qv_reg_rd(sc, QV_CSR) & ~(1 << 2));
    842       1.31      matt 		}
    843       1.31      matt 		break;
    844       1.31      matt 
    845       1.31      matt 	case WSDISPLAYIO_GVIDEO:
    846       1.31      matt 		*(u_int *)data = (qv_reg_rd(sc, QV_CSR) & (1 << 2))
    847       1.31      matt 		    ? WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    848       1.31      matt 		break;
    849       1.31      matt 
    850       1.31      matt 	case WSDISPLAYIO_SCURSOR:
    851       1.31      matt 		qv_setcursor(sc, (struct wsdisplay_cursor *)data);
    852        1.1  jonathan 		break;
    853        1.1  jonathan 
    854       1.31      matt 	case WSDISPLAYIO_SCURPOS:
    855       1.31      matt 	        sc->sc_curx = ((struct wsdisplay_curpos *)data)->x;
    856       1.31      matt 		sc->sc_cury = ((struct wsdisplay_curpos *)data)->y;
    857       1.31      matt                 qv_crtc_wr(sc, CUR_START, CUR_OFF | (sc->sc_cury & 0x0f));
    858       1.31      matt                 qv_crtc_wr(sc, CUR_HI, sc->sc_cury >> 4);
    859       1.31      matt                 qv_reg_wr(sc, QV_CUR_X, sc->sc_curx);
    860       1.31      matt                 qv_crtc_wr(sc, CUR_START,
    861       1.32   msaitoh                     sc->sc_curon | (sc->sc_cury & 0x0f));
    862        1.1  jonathan 		break;
    863       1.31      matt 
    864       1.31      matt 	case WSDISPLAYIO_GCURPOS:
    865       1.31      matt 		((struct wsdisplay_curpos *)data)->x = sc->sc_curx;
    866       1.31      matt 		((struct wsdisplay_curpos *)data)->y = sc->sc_cury;
    867        1.1  jonathan 		break;
    868       1.31      matt 
    869       1.31      matt 	case WSDISPLAYIO_GCURMAX:
    870       1.31      matt 		((struct wsdisplay_curpos *)data)->x = 16;
    871       1.31      matt 		((struct wsdisplay_curpos *)data)->y = 16;
    872        1.1  jonathan 		break;
    873       1.31      matt 
    874       1.31      matt 	default:
    875       1.31      matt 		return EPASSTHROUGH;
    876        1.1  jonathan 	}
    877       1.31      matt 	return 0;
    878        1.1  jonathan }
    879       1.31      matt 
    880        1.1  jonathan /*
    881       1.31      matt  * emulop mmap
    882        1.1  jonathan  */
    883       1.31      matt static paddr_t
    884       1.31      matt qv_mmap(void *v, void *vs, off_t offset, int prot)
    885        1.1  jonathan {
    886       1.31      matt         struct qv_softc *sc = device_private(v);
    887       1.31      matt 
    888       1.31      matt 	if (offset >= QVSIZE || offset < 0)
    889       1.31      matt 		return -1;
    890       1.31      matt 	return (sc->sc_fbphys) >> PGSHIFT;
    891        1.1  jonathan }
    892        1.1  jonathan 
    893        1.1  jonathan /*
    894       1.31      matt  * emulop allocate screen
    895        1.1  jonathan  */
    896       1.31      matt int
    897       1.31      matt qv_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    898       1.31      matt     int *curxp, int *curyp, long *defattrp)
    899        1.1  jonathan {
    900       1.31      matt         struct qv_softc *sc = device_private(v);
    901       1.31      matt         struct qv_screen *ss;
    902        1.1  jonathan 
    903       1.31      matt 	ss = malloc(sizeof(struct qv_screen), M_DEVBUF, M_WAITOK|M_ZERO);
    904       1.31      matt 	ss->ss_sc = sc;
    905       1.31      matt 	ss->ss_type = type;
    906       1.31      matt 	*cookiep = ss;
    907       1.31      matt 	*curxp = *curyp = *defattrp = 0;
    908       1.31      matt         printf("qv_alloc_screen: \"%s\" %p\n", type->name, ss);
    909       1.31      matt 	return 0;
    910        1.1  jonathan }
    911        1.1  jonathan 
    912        1.1  jonathan /*
    913       1.31      matt  * emulop free screen
    914        1.1  jonathan  */
    915        1.2   mycroft void
    916       1.31      matt qv_free_screen(void *v, void *cookie)
    917        1.1  jonathan {
    918       1.31      matt         printf("qv_free_screen: %p\n", cookie);
    919       1.31      matt         free(cookie, M_DEVBUF);
    920       1.31      matt }
    921        1.1  jonathan 
    922       1.31      matt /*
    923       1.31      matt  * emulop show screen
    924       1.31      matt  */
    925       1.31      matt int
    926       1.31      matt qv_show_screen(void *v, void *cookie, int waitok,
    927       1.31      matt     void (*cb)(void *, int, int), void *cbarg)
    928       1.31      matt {
    929       1.31      matt 	struct qv_screen *ss = cookie;
    930       1.31      matt 	const struct _wsscreen_descr *descr;
    931       1.31      matt 	int row, col, line;
    932       1.31      matt         printf("qv_show_screen: %p\n", cookie);
    933       1.31      matt 
    934       1.31      matt 	if (ss == ss->ss_sc->sc_curscr)
    935       1.31      matt 		return (0);
    936       1.31      matt 
    937       1.31      matt         descr = (const struct _wsscreen_descr *)(ss->ss_type);
    938       1.31      matt         qv_setcrtc(ss->ss_sc, descr->qv_crtc_param);
    939       1.31      matt 	for (row = 0; row < QV_ROWS; row++)
    940       1.31      matt 		for (line = 0; line < QV_CHEIGHT; line++) {
    941       1.31      matt 			for (col = 0; col < QV_COLS; col++) {
    942       1.31      matt 				u_char s, c = ss->ss_image[row][col];
    943       1.31      matt 
    944       1.31      matt 				if (c < 32)
    945       1.31      matt 					c = 32;
    946       1.31      matt 				s = *qv_font(ss->ss_sc, c, line);
    947       1.31      matt 				if (ss->ss_attr[row][col] & WSATTR_REVERSE)
    948       1.31      matt 					s ^= 255;
    949       1.31      matt 				*qv_fbp(ss->ss_sc, row, col, line) = s;
    950       1.31      matt 
    951       1.31      matt 				if (ss->ss_attr[row][col] & WSATTR_UNDERLINE)
    952       1.31      matt 					*qv_fbp(ss->ss_sc, row, col, line)
    953       1.31      matt 					    = 255;
    954       1.31      matt 			}
    955       1.31      matt 		}
    956       1.31      matt         cursor = qv_fbp(ss->ss_sc, ss->ss_cury, ss->ss_curx, 14);
    957       1.31      matt 	ss->ss_sc->sc_curscr = ss;
    958       1.31      matt 	return (0);
    959        1.1  jonathan }
    960        1.1  jonathan 
    961       1.31      matt #if 0
    962       1.31      matt void
    963       1.31      matt qv_reset_establish(void (*reset)(device_t), device_t dev)
    964        1.1  jonathan {
    965       1.31      matt         uba_reset_establish(reset, device_parent(dev));
    966        1.1  jonathan }
    967       1.31      matt #endif
    968       1.31      matt cons_decl(qv);
    969        1.1  jonathan 
    970       1.31      matt void
    971       1.31      matt qvcninit(struct consdev *cndev)
    972        1.1  jonathan {
    973       1.31      matt 	int fcookie;
    974       1.31      matt 	struct wsdisplay_font *console_font;
    975       1.31      matt 	extern void lkccninit(struct consdev *);
    976       1.31      matt 	extern int lkccngetc(dev_t);
    977       1.31      matt 	extern int dz_vsbus_lk201_cnattach(int);
    978       1.31      matt 
    979       1.31      matt         //printf("qvcninit: \n");
    980       1.31      matt 	/* Clear screen */
    981       1.31      matt 	//memset(qv_addr, 0, 128*864);
    982       1.31      matt 
    983       1.31      matt 	callout_init(&qv_cursor_ch, 0);
    984       1.31      matt 	//curscr = &qv_conscreen;
    985       1.31      matt 	wsdisplay_cnattach(&qv_stdscreen[0].qv_stdscreen,
    986       1.31      matt 	    &qv_conscreen, 0, 0, 0);
    987       1.31      matt 	cn_tab->cn_pri = CN_INTERNAL;
    988       1.31      matt 	wsfont_init();
    989       1.31      matt 	if ((fcookie = wsfont_find(NULL, 8, 15, 0, WSDISPLAY_FONTORDER_R2L,
    990       1.31      matt 	    WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP)) < 0)
    991       1.31      matt 	{
    992       1.31      matt 		printf("qv: could not find 8x15 font\n");
    993        1.1  jonathan 		return;
    994       1.31      matt 	}
    995       1.31      matt 	if (wsfont_lock(fcookie, &console_font) != 0) {
    996       1.31      matt 		printf("qv: could not lock 8x15 font\n");
    997        1.1  jonathan 		return;
    998       1.31      matt 	}
    999       1.31      matt 	//qf = console_font->data;
   1000        1.1  jonathan 
   1001       1.31      matt #if NQVKBD > 0 && 0
   1002       1.31      matt 	qvkbd_cnattach(0); /* Connect keyboard and screen together */
   1003       1.31      matt #endif
   1004        1.1  jonathan }
   1005        1.1  jonathan 
   1006        1.1  jonathan /*
   1007       1.31      matt  * Called very early to setup the glass tty as console.
   1008       1.31      matt  * Because it's called before the VM system is inited, virtual memory
   1009       1.31      matt  * for the framebuffer can be stolen directly without disturbing anything.
   1010        1.1  jonathan  */
   1011       1.31      matt void
   1012       1.31      matt qvcnprobe(struct consdev *cndev)
   1013        1.1  jonathan {
   1014       1.31      matt         printf("qvcnprobe: \n");
   1015       1.31      matt #if 0
   1016       1.31      matt 	extern vaddr_t virtual_avail;
   1017       1.31      matt 	extern const struct cdevsw wsdisplay_cdevsw;
   1018       1.31      matt 
   1019       1.31      matt 	switch (vax_boardtype) {
   1020       1.31      matt 	case VAX_BTYP_410:
   1021       1.31      matt 	case VAX_BTYP_420:
   1022       1.31      matt 	case VAX_BTYP_43:
   1023       1.31      matt 		if ((vax_confdata & KA420_CFG_L3CON) ||
   1024       1.31      matt 		    (vax_confdata & KA420_CFG_MULTU))
   1025       1.31      matt 			break; /* doesn't use graphics console */
   1026       1.31      matt 		qv_addr = (void *)virtual_avail;
   1027       1.31      matt 		virtual_avail += QVSIZE;
   1028       1.31      matt 		ioaccess((vaddr_t)qv_addr, QVADDR, (QVSIZE/VAX_NBPG));
   1029       1.31      matt 		cndev->cn_pri = CN_INTERNAL;
   1030       1.31      matt 		cndev->cn_dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw),
   1031       1.31      matt 					0);
   1032       1.31      matt 		break;
   1033       1.31      matt 	default:
   1034       1.31      matt 		break;
   1035        1.1  jonathan 	}
   1036       1.31      matt #endif
   1037        1.1  jonathan }
   1038