Home | History | Annotate | Line # | Download | only in iomd
vidcvideo.c revision 1.21.8.1
      1  1.21.8.1      yamt /* $NetBSD: vidcvideo.c,v 1.21.8.1 2006/05/24 10:56:35 yamt Exp $ */
      2       1.1   reinoud 
      3       1.1   reinoud /*
      4       1.1   reinoud  * Copyright (c) 2001 Reinoud Zandijk
      5       1.1   reinoud  * Copyright (c) 1998, 1999 Tohru Nishimura.  All rights reserved.
      6       1.1   reinoud  *
      7       1.1   reinoud  * Redistribution and use in source and binary forms, with or without
      8       1.1   reinoud  * modification, are permitted provided that the following conditions
      9       1.1   reinoud  * are met:
     10       1.1   reinoud  * 1. Redistributions of source code must retain the above copyright
     11       1.1   reinoud  *    notice, this list of conditions and the following disclaimer.
     12       1.1   reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   reinoud  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   reinoud  *    documentation and/or other materials provided with the distribution.
     15       1.1   reinoud  * 3. All advertising materials mentioning features or use of this software
     16       1.1   reinoud  *    must display the following acknowledgement:
     17       1.1   reinoud  *      This product includes software developed by Tohru Nishimura
     18       1.1   reinoud  *	and Reinoud Zandijk for the NetBSD Project.
     19       1.1   reinoud  * 4. The name of the author may not be used to endorse or promote products
     20       1.1   reinoud  *    derived from this software without specific prior written permission
     21       1.1   reinoud  *
     22       1.1   reinoud  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23       1.1   reinoud  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24       1.1   reinoud  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25       1.1   reinoud  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26       1.1   reinoud  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27       1.1   reinoud  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28       1.1   reinoud  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29       1.1   reinoud  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30       1.1   reinoud  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31       1.1   reinoud  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32       1.1   reinoud  *
     33       1.1   reinoud  * Created vidcvideo.c from /dev/tc/cfb.c to fit the Acorn/ARM VIDC1 and VIDC20 chips
     34       1.1   reinoud  *
     35       1.1   reinoud  */
     36       1.1   reinoud 
     37       1.1   reinoud #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     38       1.1   reinoud 
     39  1.21.8.1      yamt __KERNEL_RCSID(0, "$NetBSD: vidcvideo.c,v 1.21.8.1 2006/05/24 10:56:35 yamt Exp $");
     40       1.1   reinoud 
     41       1.1   reinoud #include <sys/param.h>
     42       1.1   reinoud #include <sys/systm.h>
     43       1.1   reinoud #include <sys/kernel.h>
     44       1.1   reinoud #include <sys/device.h>
     45       1.1   reinoud #include <sys/malloc.h>
     46       1.1   reinoud #include <sys/buf.h>
     47       1.1   reinoud #include <sys/ioctl.h>
     48       1.1   reinoud 
     49       1.1   reinoud #include <arm/mainbus/mainbus.h>
     50       1.1   reinoud #include <machine/bus.h>
     51       1.1   reinoud #include <machine/intr.h>
     52       1.1   reinoud 
     53       1.1   reinoud #include <dev/wscons/wsconsio.h>
     54       1.1   reinoud #include <dev/wscons/wsdisplayvar.h>
     55       1.1   reinoud 
     56       1.1   reinoud #include <dev/rasops/rasops.h>
     57       1.1   reinoud #include <dev/wsfont/wsfont.h>
     58       1.1   reinoud 
     59       1.1   reinoud #include <uvm/uvm_extern.h>
     60       1.1   reinoud #include <arm/arm32/pmap.h>
     61       1.9   reinoud #include <arm/cpufunc.h>
     62       1.2   thorpej #include <machine/intr.h>
     63       1.1   reinoud 
     64       1.1   reinoud /* for vidc_mode ... needs to be MI indepenent one day */
     65       1.1   reinoud #include <arm/iomd/vidc.h>
     66       1.1   reinoud #include <arm/iomd/vidc20config.h>
     67       1.9   reinoud #include <arm/iomd/vidcvideo.h>
     68       1.1   reinoud #include <machine/bootconfig.h>
     69       1.9   reinoud 
     70       1.1   reinoud /* FOR DEBUG */
     71       1.1   reinoud extern videomemory_t videomemory;
     72       1.1   reinoud 
     73       1.1   reinoud struct hwcmap256 {
     74       1.1   reinoud #define	CMAP_SIZE	256	/* 256 R/G/B entries */
     75       1.1   reinoud 	u_int8_t r[CMAP_SIZE];
     76       1.1   reinoud 	u_int8_t g[CMAP_SIZE];
     77       1.1   reinoud 	u_int8_t b[CMAP_SIZE];
     78       1.1   reinoud };
     79       1.1   reinoud 
     80       1.1   reinoud 
     81       1.1   reinoud /* XXX for CURSOR_MAX_WIDTH = 32 */
     82       1.1   reinoud struct hwcursor32 {
     83       1.1   reinoud 	struct wsdisplay_curpos cc_pos;
     84       1.1   reinoud 	struct wsdisplay_curpos cc_hot;
     85       1.1   reinoud 	struct wsdisplay_curpos cc_size;
     86       1.1   reinoud 	struct wsdisplay_curpos cc_magic;
     87       1.1   reinoud 	u_int8_t cc_color[6];		/* how many? */
     88       1.1   reinoud 	u_int32_t cc_image[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
     89       1.1   reinoud 	u_int32_t cc_mask[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
     90       1.1   reinoud };
     91       1.1   reinoud 
     92       1.1   reinoud 
     93       1.9   reinoud struct fb_devconfig {
     94      1.11   reinoud 	vaddr_t dc_vaddr;		/* memory space virtual base address */
     95      1.11   reinoud 	paddr_t dc_paddr;		/* memory space physical base address */
     96      1.11   reinoud 	vsize_t dc_size;		/* size of slot memory */
     97      1.11   reinoud 	int	dc_wid;			/* width of frame buffer */
     98      1.11   reinoud 	int	dc_ht;			/* height of frame buffer */
     99      1.11   reinoud 	int	dc_log2_depth;		/* log2 of bits per pixel */
    100      1.11   reinoud 	int	dc_depth;		/* depth, bits per pixel */
    101      1.11   reinoud 	int	dc_rowbytes;		/* bytes in a FB scan line */
    102      1.11   reinoud 	vaddr_t	dc_videobase;		/* base of flat frame buffer */
    103      1.11   reinoud 	int	dc_blanked;		/* currently has video disabled */
    104      1.11   reinoud 	void   *dc_hwscroll_cookie;	/* cookie for hardware scroll */
    105      1.11   reinoud 
    106      1.11   reinoud 	int	dc_curenb;		/* is cursor sprite enabled ?	*/
    107      1.11   reinoud 	int	dc_changed;		/* need update of hardware	*/
    108      1.11   reinoud 	int	dc_writeback_delay;	/* Screenarea write back vsync counter */
    109       1.9   reinoud #define	WSDISPLAY_CMAP_DOLUT	0x20
    110       1.9   reinoud #define WSDISPLAY_VIDEO_ONOFF	0x40
    111       1.9   reinoud #define WSDISPLAY_WB_COUNTER	0x80
    112       1.9   reinoud 
    113      1.11   reinoud 	struct hwcmap256	dc_cmap;/* software copy of colormap	*/
    114      1.11   reinoud 	struct hwcursor32	dc_cursor;/* software copy of cursor	*/
    115       1.9   reinoud 
    116       1.9   reinoud 	struct vidc_mode	mode_info;
    117       1.9   reinoud 	struct rasops_info	rinfo;
    118       1.9   reinoud 
    119       1.9   reinoud 	struct wsdisplay_emulops orig_ri_ops;	/* Rasops functions for deligation */
    120       1.9   reinoud };
    121       1.9   reinoud 
    122       1.9   reinoud 
    123       1.1   reinoud struct vidcvideo_softc {
    124       1.1   reinoud 	struct device sc_dev;
    125       1.9   reinoud 	struct fb_devconfig *sc_dc;	/* device configuration		*/
    126       1.9   reinoud 	int nscreens;			/* number of screens configured */
    127       1.1   reinoud };
    128       1.1   reinoud 
    129       1.1   reinoud 
    130       1.1   reinoud /* XXX has to go XXX */
    131       1.1   reinoud #define	CX_MAGIC_X	220
    132       1.1   reinoud #define	CX_MAGIC_Y 	35
    133       1.1   reinoud #define	CX_FB_OFFSET	0x000000
    134       1.1   reinoud #define	CX_FB_SIZE	0x100000
    135       1.1   reinoud #define	CX_BT459_OFFSET	0x200000
    136       1.1   reinoud #define	CX_OFFSET_IREQ	0x300000	/* Interrupt req. control */
    137       1.1   reinoud /* XXX till here XXX */
    138       1.1   reinoud 
    139       1.1   reinoud 
    140       1.1   reinoud /* Function prototypes for glue */
    141       1.1   reinoud static int  vidcvideo_match __P((struct device *, struct cfdata *, void *));
    142       1.1   reinoud static void vidcvideo_attach __P((struct device *, struct device *, void *));
    143       1.1   reinoud 
    144       1.1   reinoud 
    145       1.1   reinoud /* config glue */
    146      1.15   thorpej CFATTACH_DECL(vidcvideo, sizeof(struct vidcvideo_softc),
    147      1.16   thorpej     vidcvideo_match, vidcvideo_attach, NULL, NULL);
    148       1.1   reinoud 
    149       1.1   reinoud static struct fb_devconfig vidcvideo_console_dc;
    150       1.1   reinoud static int vidcvideo_is_console;
    151       1.1   reinoud 
    152       1.1   reinoud 
    153       1.1   reinoud static struct wsscreen_descr vidcvideo_stdscreen = {
    154       1.1   reinoud 	"std", 0, 0,
    155       1.1   reinoud 	0, /* textops */
    156       1.1   reinoud 	0, 0,
    157       1.1   reinoud 	WSSCREEN_REVERSE
    158       1.1   reinoud };
    159       1.1   reinoud 
    160       1.1   reinoud static const struct wsscreen_descr *_vidcvideo_scrlist[] = {
    161       1.1   reinoud 	&vidcvideo_stdscreen,
    162       1.1   reinoud };
    163       1.1   reinoud 
    164       1.1   reinoud static const struct wsscreen_list vidcvideo_screenlist = {
    165       1.1   reinoud 	sizeof(_vidcvideo_scrlist) / sizeof(struct wsscreen_descr *), _vidcvideo_scrlist
    166       1.1   reinoud };
    167       1.1   reinoud 
    168  1.21.8.1      yamt static int	vidcvideoioctl __P((void *, void *, u_long, caddr_t, int,
    169  1.21.8.1      yamt 		    struct lwp *));
    170  1.21.8.1      yamt static paddr_t	vidcvideommap __P((void *, void *, off_t, int));
    171       1.1   reinoud 
    172       1.1   reinoud static int	vidcvideo_alloc_screen __P((void *, const struct wsscreen_descr *,
    173       1.1   reinoud 				      void **, int *, int *, long *));
    174       1.1   reinoud static void	vidcvideo_free_screen __P((void *, void *));
    175       1.1   reinoud static int	vidcvideo_show_screen __P((void *, void *, int,
    176       1.1   reinoud 				     void (*) (void *, int, int), void *));
    177       1.1   reinoud 
    178       1.1   reinoud static const struct wsdisplay_accessops vidcvideo_accessops = {
    179       1.1   reinoud 	vidcvideoioctl,
    180       1.1   reinoud 	vidcvideommap,
    181       1.1   reinoud 	vidcvideo_alloc_screen,
    182       1.1   reinoud 	vidcvideo_free_screen,
    183       1.1   reinoud 	vidcvideo_show_screen,
    184      1.17   reinoud 	NULL, /* load_font	*/
    185  1.21.8.1      yamt 	NULL  /* pollc		*/
    186       1.1   reinoud };
    187       1.1   reinoud 
    188       1.6   reinoud 
    189       1.1   reinoud /* Function prototypes */
    190       1.1   reinoud int         vidcvideo_cnattach __P((vaddr_t));
    191       1.1   reinoud static void vidcvideo_colourmap_and_cursor_init __P((struct fb_devconfig *));
    192       1.1   reinoud 
    193       1.1   reinoud static int  get_cmap __P((struct vidcvideo_softc *, struct wsdisplay_cmap *));
    194       1.1   reinoud static int  set_cmap __P((struct vidcvideo_softc *, struct wsdisplay_cmap *));
    195       1.1   reinoud static int  set_cursor __P((struct vidcvideo_softc *, struct wsdisplay_cursor *));
    196       1.1   reinoud static int  get_cursor __P((struct vidcvideo_softc *, struct wsdisplay_cursor *));
    197       1.1   reinoud static void set_curpos __P((struct vidcvideo_softc *, struct wsdisplay_curpos *));
    198       1.1   reinoud static void vidcvideo_getdevconfig __P((vaddr_t, struct fb_devconfig *));
    199       1.1   reinoud 
    200       1.1   reinoud static int  vidcvideointr __P((void *));
    201       1.3     bjh21 static void vidcvideo_config_wscons __P((struct fb_devconfig *));
    202       1.1   reinoud 
    203       1.6   reinoud 
    204       1.1   reinoud /* Acceleration function prototypes */
    205       1.1   reinoud static void vv_copyrows __P((void *, int, int, int));
    206       1.1   reinoud static void vv_eraserows __P((void *, int, int, long));
    207       1.6   reinoud static void vv_putchar __P((void *c, int row, int col, u_int uc, long attr));
    208       1.1   reinoud 
    209       1.1   reinoud 
    210       1.1   reinoud static int
    211       1.1   reinoud vidcvideo_match(parent, match, aux)
    212       1.1   reinoud 	struct device *parent;
    213       1.1   reinoud 	struct cfdata *match;
    214       1.1   reinoud 	void *aux;
    215       1.1   reinoud {
    216       1.1   reinoud 	/* Can't probe AFAIK ; how ? */
    217       1.1   reinoud 	return (1);
    218       1.1   reinoud }
    219       1.1   reinoud 
    220       1.1   reinoud 
    221       1.1   reinoud static void
    222       1.1   reinoud vidcvideo_getdevconfig(dense_addr, dc)
    223       1.1   reinoud 	vaddr_t dense_addr;
    224       1.1   reinoud 	struct fb_devconfig *dc;
    225       1.1   reinoud {
    226       1.1   reinoud 	dc->dc_vaddr = dense_addr;
    227      1.11   reinoud 	(void) pmap_extract(pmap_kernel(), dc->dc_vaddr, &(dc->dc_paddr));
    228       1.1   reinoud 
    229       1.1   reinoud 	vidcvideo_getmode(&dc->mode_info);
    230       1.1   reinoud 
    231       1.1   reinoud 	dc->dc_wid = dc->mode_info.hder;
    232       1.1   reinoud 	dc->dc_ht = dc->mode_info.vder;
    233       1.1   reinoud 	dc->dc_log2_depth = dc->mode_info.log2_bpp;
    234       1.1   reinoud 	dc->dc_depth = 1 << dc->dc_log2_depth;
    235       1.1   reinoud 	dc->dc_videobase = dc->dc_vaddr;
    236       1.1   reinoud 	dc->dc_blanked = 0;
    237       1.1   reinoud 
    238       1.1   reinoud 	/* this should/could be done somewhat more elegant! */
    239       1.1   reinoud 	switch (dc->dc_depth) {
    240       1.1   reinoud 		case 1:
    241       1.1   reinoud 			dc->dc_rowbytes = dc->dc_wid / 8;
    242       1.1   reinoud 			break;
    243       1.1   reinoud 		case 2:
    244       1.1   reinoud 			dc->dc_rowbytes = dc->dc_wid / 4;
    245       1.1   reinoud 			break;
    246       1.1   reinoud 		case 4:
    247       1.1   reinoud 			dc->dc_rowbytes = dc->dc_wid / 2;
    248       1.1   reinoud 			break;
    249       1.1   reinoud 		case 8:
    250       1.1   reinoud 			dc->dc_rowbytes = dc->dc_wid;
    251       1.1   reinoud 			break;
    252       1.1   reinoud 		case 16:
    253       1.1   reinoud 			dc->dc_rowbytes = dc->dc_wid * 2;
    254       1.1   reinoud 			break;
    255       1.1   reinoud 		case 32:
    256       1.1   reinoud 			dc->dc_rowbytes = dc->dc_wid * 4;
    257       1.1   reinoud 			break;
    258       1.1   reinoud 		default:
    259       1.1   reinoud 			printf("Unknown colour depth %d ... what to do ?", dc->dc_depth);
    260       1.1   reinoud 			break;
    261       1.1   reinoud 	};
    262       1.1   reinoud 
    263       1.1   reinoud 	/* euhm... correct ? i.e. not complete VIDC memory */
    264       1.1   reinoud 	dc->dc_size = dc->mode_info.vder * dc->dc_rowbytes;
    265       1.1   reinoud 
    266       1.1   reinoud 	/* initialize colormap and cursor resource */
    267       1.1   reinoud 	vidcvideo_colourmap_and_cursor_init(dc);
    268       1.1   reinoud 
    269       1.1   reinoud 	dc->rinfo.ri_flg    = 0; /* RI_CENTER; */
    270       1.1   reinoud 	dc->rinfo.ri_depth  = dc->dc_depth;
    271       1.1   reinoud 	dc->rinfo.ri_bits   = (void *) dc->dc_videobase;
    272       1.1   reinoud 	dc->rinfo.ri_width  = dc->dc_wid;
    273       1.1   reinoud 	dc->rinfo.ri_height = dc->dc_ht;
    274       1.1   reinoud 	dc->rinfo.ri_stride = dc->dc_rowbytes;
    275       1.9   reinoud 	dc->rinfo.ri_hw	    = dc;		/* link back */
    276       1.9   reinoud 
    277       1.9   reinoud 	/* intitialise miscelanious */
    278       1.9   reinoud 	dc->dc_writeback_delay = 0;
    279       1.1   reinoud }
    280       1.1   reinoud 
    281       1.1   reinoud 
    282       1.1   reinoud static void
    283       1.1   reinoud vidcvideo_config_wscons(dc)
    284       1.1   reinoud 	struct fb_devconfig *dc;
    285       1.1   reinoud {
    286       1.4        ad 	int i, cookie, font_not_locked;
    287       1.1   reinoud 
    288       1.1   reinoud 	/* clear the screen ; why not a memset ? - it was this way so keep it for now */
    289       1.1   reinoud 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    290       1.1   reinoud 		*(u_int32_t *)(dc->dc_videobase + i) = 0x0;
    291       1.1   reinoud 
    292       1.1   reinoud 	wsfont_init();
    293       1.1   reinoud 
    294       1.1   reinoud 	/* prefer 8 pixel wide font */
    295       1.4        ad 	cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
    296       1.4        ad 	    WSDISPLAY_FONTORDER_L2R);
    297       1.4        ad 	if (cookie <= 0)
    298       1.4        ad 		cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
    299       1.4        ad 		    WSDISPLAY_FONTORDER_L2R);
    300       1.1   reinoud 
    301       1.1   reinoud 	if (cookie < 0) {
    302       1.1   reinoud 		/* Can I even print here ? */
    303       1.1   reinoud 		printf("Font table empty! exiting\n");
    304       1.1   reinoud 		return;
    305       1.1   reinoud 	};
    306       1.1   reinoud 
    307       1.4        ad 	font_not_locked = wsfont_lock(cookie, &dc->rinfo.ri_font);
    308       1.1   reinoud 
    309       1.1   reinoud 	dc->rinfo.ri_wsfcookie = cookie;
    310       1.1   reinoud 
    311       1.1   reinoud 	rasops_init(&dc->rinfo,
    312       1.1   reinoud 		dc->rinfo.ri_height / dc->rinfo.ri_font->fontheight,
    313       1.1   reinoud 		dc->rinfo.ri_width / dc->rinfo.ri_font->fontwidth
    314       1.1   reinoud 	);
    315       1.1   reinoud 
    316       1.6   reinoud 	/*
    317       1.6   reinoud 	 * Provide a hook for the acceleration functions and make a copy of the
    318       1.6   reinoud 	 * original rasops functions for passing on calls
    319       1.6   reinoud 	 */
    320       1.6   reinoud 	dc->rinfo.ri_hw = dc;
    321       1.6   reinoud 	memcpy(&(dc->orig_ri_ops), &(dc->rinfo.ri_ops), sizeof(struct wsdisplay_emulops));
    322       1.6   reinoud 
    323       1.6   reinoud 	/* add our accelerated functions */
    324       1.1   reinoud 	dc->rinfo.ri_ops.eraserows = vv_eraserows;
    325       1.1   reinoud 	dc->rinfo.ri_ops.copyrows  = vv_copyrows;
    326       1.1   reinoud 
    327       1.6   reinoud 	/* add the extra activity measuring functions; they just delegate on */
    328       1.6   reinoud 	dc->rinfo.ri_ops.putchar   = vv_putchar;
    329       1.6   reinoud 
    330       1.1   reinoud 	/* XXX shouldn't be global */
    331       1.1   reinoud 	vidcvideo_stdscreen.nrows = dc->rinfo.ri_rows;
    332       1.1   reinoud 	vidcvideo_stdscreen.ncols = dc->rinfo.ri_cols;
    333       1.1   reinoud 	vidcvideo_stdscreen.textops = &dc->rinfo.ri_ops;
    334       1.1   reinoud 	vidcvideo_stdscreen.capabilities = dc->rinfo.ri_caps;
    335       1.1   reinoud 
    336       1.4        ad 	if (font_not_locked) {
    337       1.1   reinoud 		printf(" warning ... couldn't lock font! ");
    338       1.1   reinoud 	};
    339       1.1   reinoud }
    340       1.1   reinoud 
    341       1.1   reinoud 
    342       1.1   reinoud static void
    343       1.1   reinoud vidcvideo_attach(parent, self, aux)
    344       1.1   reinoud 	struct device *parent, *self;
    345       1.1   reinoud 	void *aux;
    346       1.1   reinoud {
    347       1.1   reinoud 	struct vidcvideo_softc *sc = (struct vidcvideo_softc *)self;
    348       1.9   reinoud 	struct fb_devconfig *dc;
    349       1.1   reinoud 	struct wsemuldisplaydev_attach_args waa;
    350       1.1   reinoud 	struct hwcmap256 *cm;
    351       1.1   reinoud 	const u_int8_t *p;
    352       1.6   reinoud 	long defattr;
    353       1.1   reinoud 	int index;
    354       1.1   reinoud 
    355       1.1   reinoud 	vidcvideo_init();
    356       1.1   reinoud 	if (sc->nscreens == 0) {
    357       1.6   reinoud 		sc->sc_dc = &vidcvideo_console_dc;
    358       1.6   reinoud 		if (!vidcvideo_is_console) {
    359       1.6   reinoud 			printf(" : non console (no kbd yet) ");
    360       1.6   reinoud 			vidcvideo_getdevconfig(videomemory.vidm_vbase, sc->sc_dc);
    361       1.6   reinoud 			vidcvideo_config_wscons(sc->sc_dc);
    362      1.13  junyoung 			(*sc->sc_dc->rinfo.ri_ops.allocattr)(&sc->sc_dc->rinfo, 0, 0, 0, &defattr);
    363       1.1   reinoud 		};
    364       1.1   reinoud 		sc->nscreens = 1;
    365       1.1   reinoud 	} else {
    366  1.21.8.1      yamt 			printf(": already attached ... can't cope with this\n");
    367       1.1   reinoud 			return;
    368       1.1   reinoud 	};
    369       1.1   reinoud 
    370       1.9   reinoud 	dc = sc->sc_dc;
    371       1.9   reinoud 
    372       1.1   reinoud 	vidcvideo_printdetails();
    373       1.9   reinoud 	printf(": using %d x %d, %dbpp\n", dc->dc_wid, dc->dc_ht,
    374       1.9   reinoud 	    dc->dc_depth);
    375       1.1   reinoud 
    376       1.1   reinoud 	/* initialise rasops */
    377       1.9   reinoud 	cm = &dc->dc_cmap;
    378       1.1   reinoud 	p = rasops_cmap;
    379       1.1   reinoud 	for (index = 0; index < CMAP_SIZE; index++, p += 3) {
    380       1.1   reinoud 		cm->r[index] = p[0];
    381       1.1   reinoud 		cm->g[index] = p[1];
    382       1.1   reinoud 		cm->b[index] = p[2];
    383       1.1   reinoud 	}
    384       1.1   reinoud 
    385       1.1   reinoud 	/* what does these do ? */
    386       1.9   reinoud 	dc->dc_cursor.cc_magic.x = CX_MAGIC_X;
    387       1.9   reinoud 	dc->dc_cursor.cc_magic.y = CX_MAGIC_Y;
    388       1.1   reinoud 
    389       1.1   reinoud 	/* set up interrupt flags */
    390       1.9   reinoud 	dc->dc_changed |= WSDISPLAY_CMAP_DOLUT;
    391       1.1   reinoud 
    392       1.6   reinoud 	/*
    393       1.6   reinoud 	 * Set up a link in the rasops structure to our device config
    394       1.6   reinoud 	 * for acceleration stuff
    395       1.6   reinoud 	 */
    396       1.9   reinoud 	dc->rinfo.ri_hw = sc->sc_dc;
    397       1.1   reinoud 
    398       1.1   reinoud 	/* Establish an interrupt handler, and clear any pending interrupts */
    399       1.9   reinoud 	intr_claim(IRQ_FLYBACK, IPL_TTY, "vblank", vidcvideointr, dc);
    400       1.1   reinoud 
    401       1.1   reinoud 	waa.console = (vidcvideo_is_console ? 1 : 0);
    402       1.1   reinoud 	waa.scrdata = &vidcvideo_screenlist;
    403       1.1   reinoud 	waa.accessops = &vidcvideo_accessops;
    404       1.1   reinoud 	waa.accesscookie = sc;
    405       1.1   reinoud 
    406       1.1   reinoud 	config_found(self, &waa, wsemuldisplaydevprint);
    407       1.1   reinoud }
    408       1.1   reinoud 
    409       1.1   reinoud 
    410       1.1   reinoud static int
    411  1.21.8.1      yamt vidcvideoioctl(v, vs, cmd, data, flag, l)
    412       1.1   reinoud 	void *v;
    413  1.21.8.1      yamt 	void *vs;
    414       1.1   reinoud 	u_long cmd;
    415       1.1   reinoud 	caddr_t data;
    416       1.1   reinoud 	int flag;
    417      1.21  christos 	struct lwp *l;
    418       1.1   reinoud {
    419       1.1   reinoud 	struct vidcvideo_softc *sc = v;
    420       1.1   reinoud 	struct fb_devconfig *dc = sc->sc_dc;
    421       1.1   reinoud 	int state;
    422       1.1   reinoud 
    423       1.1   reinoud 	switch (cmd) {
    424       1.1   reinoud 	case WSDISPLAYIO_GTYPE:
    425       1.1   reinoud 		*(u_int *)data = WSDISPLAY_TYPE_VIDC;
    426       1.1   reinoud 		return (0);
    427       1.1   reinoud 
    428       1.1   reinoud 	case WSDISPLAYIO_GINFO:
    429       1.1   reinoud #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    430       1.9   reinoud 		wsd_fbip->height = dc->dc_ht;
    431       1.9   reinoud 		wsd_fbip->width  = dc->dc_wid;
    432       1.9   reinoud 		wsd_fbip->depth  = dc->dc_depth;
    433       1.1   reinoud 		wsd_fbip->cmsize = CMAP_SIZE;
    434       1.1   reinoud #undef fbt
    435       1.1   reinoud 		return (0);
    436       1.1   reinoud 
    437       1.1   reinoud 	case WSDISPLAYIO_GETCMAP:
    438       1.1   reinoud 		return get_cmap(sc, (struct wsdisplay_cmap *)data);
    439       1.1   reinoud 
    440       1.1   reinoud 	case WSDISPLAYIO_PUTCMAP:
    441       1.1   reinoud 		return set_cmap(sc, (struct wsdisplay_cmap *)data);
    442       1.1   reinoud 
    443       1.1   reinoud 	case WSDISPLAYIO_SVIDEO:
    444       1.1   reinoud 		state = *(int *)data;
    445       1.1   reinoud 		dc->dc_blanked = (state == WSDISPLAYIO_VIDEO_OFF);
    446       1.9   reinoud 		dc->dc_changed |= WSDISPLAY_VIDEO_ONOFF;
    447       1.1   reinoud 		/* done on video blank */
    448       1.1   reinoud 		return (0);
    449       1.1   reinoud 
    450       1.1   reinoud 	case WSDISPLAYIO_GVIDEO:
    451       1.1   reinoud 		*(u_int *)data = dc->dc_blanked ?
    452       1.1   reinoud 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    453       1.1   reinoud 		return (0);
    454       1.1   reinoud 
    455       1.1   reinoud 	case WSDISPLAYIO_GCURPOS:
    456       1.9   reinoud 		*(struct wsdisplay_curpos *)data = dc->dc_cursor.cc_pos;
    457       1.1   reinoud 		return (0);
    458       1.1   reinoud 
    459       1.1   reinoud 	case WSDISPLAYIO_SCURPOS:
    460       1.1   reinoud 		set_curpos(sc, (struct wsdisplay_curpos *)data);
    461       1.9   reinoud 		dc->dc_changed |= WSDISPLAY_CURSOR_DOPOS;
    462       1.1   reinoud 		return (0);
    463       1.1   reinoud 
    464       1.1   reinoud 	case WSDISPLAYIO_GCURMAX:
    465       1.1   reinoud 		((struct wsdisplay_curpos *)data)->x = CURSOR_MAX_WIDTH;
    466       1.1   reinoud 		((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_HEIGHT;
    467       1.1   reinoud 		return (0);
    468       1.1   reinoud 
    469       1.1   reinoud 	case WSDISPLAYIO_GCURSOR:
    470       1.1   reinoud 		return get_cursor(sc, (struct wsdisplay_cursor *)data);
    471       1.1   reinoud 
    472       1.1   reinoud 	case WSDISPLAYIO_SCURSOR:
    473       1.1   reinoud 		return set_cursor(sc, (struct wsdisplay_cursor *)data);
    474       1.1   reinoud 
    475       1.1   reinoud 	case WSDISPLAYIO_SMODE:
    476       1.1   reinoud 		state = *(int *)data;
    477       1.1   reinoud 		if (state == WSDISPLAYIO_MODE_MAPPED) {
    478       1.1   reinoud 			dc->dc_hwscroll_cookie = vidcvideo_hwscroll_reset();
    479       1.1   reinoud 		};
    480       1.1   reinoud 		if (state == WSDISPLAYIO_MODE_EMUL) {
    481       1.1   reinoud 			vidcvideo_hwscroll_back(dc->dc_hwscroll_cookie);
    482       1.1   reinoud 		};
    483       1.1   reinoud 		vidcvideo_progr_scroll();
    484      1.11   reinoud 
    485       1.1   reinoud 		return (0);
    486       1.1   reinoud 	}
    487       1.5    atatat 	return EPASSTHROUGH;
    488       1.1   reinoud }
    489       1.1   reinoud 
    490       1.1   reinoud 
    491       1.1   reinoud paddr_t
    492  1.21.8.1      yamt vidcvideommap(v, vs, offset, prot)
    493       1.1   reinoud 	void *v;
    494  1.21.8.1      yamt 	void *vs;
    495       1.1   reinoud 	off_t offset;
    496       1.1   reinoud 	int prot;
    497       1.1   reinoud {
    498       1.1   reinoud 	struct vidcvideo_softc *sc = v;
    499       1.1   reinoud 
    500       1.1   reinoud 	if (offset >= sc->sc_dc->dc_size || offset < 0)
    501       1.1   reinoud 		return (-1);
    502      1.11   reinoud 
    503      1.11   reinoud 	return arm_btop(sc->sc_dc->dc_paddr + offset);
    504       1.1   reinoud }
    505       1.1   reinoud 
    506       1.1   reinoud 
    507       1.1   reinoud static int
    508       1.1   reinoud vidcvideo_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
    509       1.1   reinoud 	void *v;
    510       1.1   reinoud 	const struct wsscreen_descr *type;
    511       1.1   reinoud 	void **cookiep;
    512       1.1   reinoud 	int *curxp, *curyp;
    513       1.1   reinoud 	long *attrp;
    514       1.1   reinoud {
    515       1.1   reinoud 	struct vidcvideo_softc *sc = v;
    516       1.9   reinoud 	struct fb_devconfig *dc = sc->sc_dc;
    517       1.1   reinoud 	long defattr;
    518       1.1   reinoud 
    519       1.6   reinoud 	/*
    520       1.6   reinoud 	 * One and just only one for now :( ... if the vidcconsole is not the
    521       1.6   reinoud 	 * console then this makes one wsconsole screen free for use !
    522       1.6   reinoud 	 */
    523       1.6   reinoud 	if ((sc->nscreens > 1) || vidcvideo_is_console)
    524       1.1   reinoud 		return (ENOMEM);
    525       1.1   reinoud 
    526       1.6   reinoud 	/* Add the screen to wscons to control */
    527       1.9   reinoud 	*cookiep = &dc->rinfo;
    528       1.1   reinoud 	*curxp = 0;
    529       1.1   reinoud 	*curyp = 0;
    530       1.9   reinoud 	vidcvideo_getdevconfig(videomemory.vidm_vbase, dc);
    531       1.9   reinoud 	vidcvideo_config_wscons(dc);
    532      1.13  junyoung 	(*dc->rinfo.ri_ops.allocattr)(&dc->rinfo, 0, 0, 0, &defattr);
    533       1.1   reinoud 	*attrp = defattr;
    534       1.1   reinoud 	sc->nscreens++;
    535       1.6   reinoud 
    536       1.1   reinoud 	return (0);
    537       1.1   reinoud }
    538       1.1   reinoud 
    539       1.1   reinoud 
    540       1.1   reinoud static void
    541       1.1   reinoud vidcvideo_free_screen(v, cookie)
    542       1.1   reinoud 	void *v;
    543       1.1   reinoud 	void *cookie;
    544       1.1   reinoud {
    545       1.1   reinoud 	struct vidcvideo_softc *sc = v;
    546       1.1   reinoud 
    547       1.1   reinoud 	if (sc->sc_dc == &vidcvideo_console_dc)
    548       1.1   reinoud 		panic("vidcvideo_free_screen: console");
    549       1.1   reinoud 
    550       1.1   reinoud 	sc->nscreens--;
    551       1.1   reinoud }
    552       1.1   reinoud 
    553       1.1   reinoud 
    554       1.1   reinoud static int
    555       1.1   reinoud vidcvideo_show_screen(v, cookie, waitok, cb, cbarg)
    556       1.1   reinoud 	void *v;
    557       1.1   reinoud 	void *cookie;
    558       1.1   reinoud 	int waitok;
    559       1.1   reinoud 	void (*cb) __P((void *, int, int));
    560       1.1   reinoud 	void *cbarg;
    561       1.1   reinoud {
    562       1.1   reinoud 
    563       1.1   reinoud 	return (0);
    564       1.1   reinoud }
    565       1.1   reinoud 
    566       1.1   reinoud 
    567       1.1   reinoud /* EXPORT */ int
    568       1.1   reinoud vidcvideo_cnattach(addr)
    569       1.1   reinoud 	vaddr_t addr;
    570       1.1   reinoud {
    571       1.1   reinoud 	struct fb_devconfig *dcp = &vidcvideo_console_dc;
    572       1.1   reinoud 	long defattr;
    573       1.1   reinoud 
    574       1.1   reinoud 	vidcvideo_init();
    575       1.1   reinoud 	vidcvideo_getdevconfig(addr, dcp);
    576       1.1   reinoud 	vidcvideo_config_wscons(dcp);
    577      1.13  junyoung 	(*dcp->rinfo.ri_ops.allocattr)(&dcp->rinfo, 0, 0, 0, &defattr);
    578       1.1   reinoud 	wsdisplay_cnattach(&vidcvideo_stdscreen, &dcp->rinfo, 0, 0, defattr);
    579       1.1   reinoud 
    580       1.1   reinoud 	vidcvideo_is_console = 1;
    581       1.1   reinoud 	return(0);
    582       1.1   reinoud }
    583       1.1   reinoud 
    584       1.1   reinoud 
    585       1.1   reinoud static int
    586       1.1   reinoud vidcvideointr(arg)
    587       1.1   reinoud 	void *arg;
    588       1.1   reinoud {
    589       1.9   reinoud 	struct fb_devconfig *dc = arg;
    590       1.9   reinoud 	int v, cleared = 0;
    591       1.1   reinoud 
    592       1.9   reinoud 	v = dc->dc_changed;
    593       1.1   reinoud 	if (v == 0)
    594       1.1   reinoud 		return (1);
    595       1.1   reinoud 
    596       1.9   reinoud 	if (v & WSDISPLAY_WB_COUNTER) {
    597       1.9   reinoud 	    	dc->dc_writeback_delay--;
    598       1.9   reinoud 		if (dc->dc_writeback_delay == 0) {
    599       1.9   reinoud 		    	cpu_dcache_wb_range(dc->dc_vaddr, dc->dc_size);
    600       1.9   reinoud 			cleared |= WSDISPLAY_WB_COUNTER;
    601       1.9   reinoud 		};
    602       1.9   reinoud 	}
    603       1.9   reinoud 
    604       1.1   reinoud 	if (v & WSDISPLAY_CMAP_DOLUT) {
    605       1.9   reinoud 		struct hwcmap256 *cm = &dc->dc_cmap;
    606       1.1   reinoud 		int index;
    607       1.1   reinoud 
    608       1.9   reinoud 		if (dc->dc_depth == 4) {
    609       1.1   reinoud 			/* palette for 4 bpp is different from 8bpp */
    610       1.1   reinoud 			vidcvideo_write(VIDC_PALREG, 0x00000000);
    611       1.9   reinoud 			for (index=0; index < (1 << dc->dc_depth); index++)
    612       1.1   reinoud 				vidcvideo_write(VIDC_PALETTE,
    613       1.1   reinoud 					VIDC_COL(cm->r[index],
    614       1.1   reinoud 						 cm->g[index],
    615       1.1   reinoud 						 cm->b[index]));
    616       1.1   reinoud 			;
    617       1.1   reinoud 		};
    618       1.1   reinoud 
    619       1.9   reinoud 		if (dc->dc_depth == 8) {
    620       1.7   reinoud 			/* dunno what to do in more than 8bpp */
    621       1.1   reinoud 			/* palettes only make sense in 8bpp and less modes on VIDC */
    622       1.1   reinoud 			vidcvideo_write(VIDC_PALREG, 0x00000000);
    623       1.1   reinoud 			for (index = 0; index < CMAP_SIZE; index++) {
    624       1.1   reinoud 				vidcvideo_write(VIDC_PALETTE,
    625       1.1   reinoud 					VIDC_COL(cm->r[index], cm->g[index], cm->b[index])
    626       1.1   reinoud 		 		);
    627       1.1   reinoud 			};
    628       1.1   reinoud 		};
    629       1.9   reinoud 		cleared |= WSDISPLAY_CMAP_DOLUT;
    630       1.1   reinoud 	}
    631       1.1   reinoud 
    632       1.1   reinoud 	if (v & WSDISPLAY_VIDEO_ONOFF) {
    633       1.9   reinoud 		vidcvideo_blank(dc->dc_blanked);
    634       1.9   reinoud 		cleared |= WSDISPLAY_VIDEO_ONOFF;
    635       1.1   reinoud 	};
    636       1.1   reinoud 
    637       1.1   reinoud 	if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
    638       1.1   reinoud 		int x, y;
    639       1.9   reinoud 		x = dc->dc_cursor.cc_pos.x - dc->dc_cursor.cc_hot.x;
    640       1.9   reinoud 		y = dc->dc_cursor.cc_pos.y - dc->dc_cursor.cc_hot.y;
    641       1.1   reinoud 
    642       1.1   reinoud 		vidcvideo_updatecursor(x, y);
    643       1.9   reinoud 		cleared |= WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT;
    644       1.1   reinoud 	};
    645       1.1   reinoud 
    646       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    647       1.9   reinoud 		vidcvideo_enablecursor(dc->dc_curenb);
    648       1.9   reinoud 		cleared |= WSDISPLAY_CURSOR_DOCUR;
    649       1.1   reinoud 	};
    650       1.1   reinoud 
    651       1.1   reinoud 
    652       1.1   reinoud #if 0	/* XXX snip XXX */
    653       1.1   reinoud 	/* XXX kept here as an archive for now XXX */
    654       1.1   reinoud 
    655       1.1   reinoud 	vdac = vidcvideobase + CX_BT459_OFFSET;
    656       1.1   reinoud 	v = sc->sc_changed;
    657       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    658       1.1   reinoud 		SELECT(vdac, BT459_IREG_CCR);
    659       1.1   reinoud 		REG(vdac, bt_reg) = (sc->sc_curenb) ? 0xc0 : 0x00;
    660       1.1   reinoud 	}
    661       1.1   reinoud 	if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
    662       1.1   reinoud 		int x, y;
    663       1.1   reinoud 
    664       1.1   reinoud 		x = sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x;
    665       1.1   reinoud 		y = sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y;
    666       1.1   reinoud 
    667       1.1   reinoud 		x += sc->sc_cursor.cc_magic.x;
    668       1.1   reinoud 		y += sc->sc_cursor.cc_magic.y;
    669       1.1   reinoud 
    670       1.1   reinoud 		SELECT(vdac, BT459_IREG_CURSOR_X_LOW);
    671       1.1   reinoud 		REG(vdac, bt_reg) = x;		tc_wmb();
    672       1.1   reinoud 		REG(vdac, bt_reg) = x >> 8;	tc_wmb();
    673       1.1   reinoud 		REG(vdac, bt_reg) = y;		tc_wmb();
    674       1.1   reinoud 		REG(vdac, bt_reg) = y >> 8;	tc_wmb();
    675       1.1   reinoud 	}
    676       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    677       1.1   reinoud 		u_int8_t *cp = sc->sc_cursor.cc_color;
    678       1.1   reinoud 
    679       1.1   reinoud 		SELECT(vdac, BT459_IREG_CCOLOR_2);
    680       1.1   reinoud 		REG(vdac, bt_reg) = cp[1];	tc_wmb();
    681       1.1   reinoud 		REG(vdac, bt_reg) = cp[3];	tc_wmb();
    682       1.1   reinoud 		REG(vdac, bt_reg) = cp[5];	tc_wmb();
    683       1.1   reinoud 
    684       1.1   reinoud 		REG(vdac, bt_reg) = cp[0];	tc_wmb();
    685       1.1   reinoud 		REG(vdac, bt_reg) = cp[2];	tc_wmb();
    686       1.1   reinoud 		REG(vdac, bt_reg) = cp[4];	tc_wmb();
    687       1.1   reinoud 	}
    688       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    689       1.1   reinoud 		u_int8_t *ip, *mp, img, msk;
    690       1.1   reinoud 		u_int8_t u;
    691       1.1   reinoud 		int bcnt;
    692       1.1   reinoud 
    693       1.1   reinoud 		ip = (u_int8_t *)sc->sc_cursor.cc_image;
    694       1.1   reinoud 		mp = (u_int8_t *)(sc->sc_cursor.cc_image + CURSOR_MAX_HEIGHT);
    695       1.1   reinoud 
    696       1.1   reinoud 		bcnt = 0;
    697       1.1   reinoud 		SELECT(vdac, BT459_IREG_CRAM_BASE+0);
    698       1.1   reinoud 		/* 64 pixel scan line is consisted with 16 byte cursor ram */
    699       1.1   reinoud 		while (bcnt < sc->sc_cursor.cc_size.y * 16) {
    700       1.1   reinoud 			/* pad right half 32 pixel when smaller than 33 */
    701       1.1   reinoud 			if ((bcnt & 0x8) && sc->sc_cursor.cc_size.x < 33) {
    702       1.1   reinoud 				REG(vdac, bt_reg) = 0; tc_wmb();
    703       1.1   reinoud 				REG(vdac, bt_reg) = 0; tc_wmb();
    704       1.1   reinoud 			}
    705       1.1   reinoud 			else {
    706       1.1   reinoud 				img = *ip++;
    707       1.1   reinoud 				msk = *mp++;
    708       1.1   reinoud 				img &= msk;	/* cookie off image */
    709       1.1   reinoud 				u = (msk & 0x0f) << 4 | (img & 0x0f);
    710       1.1   reinoud 				REG(vdac, bt_reg) = shuffle[u];	tc_wmb();
    711       1.1   reinoud 				u = (msk & 0xf0) | (img & 0xf0) >> 4;
    712       1.1   reinoud 				REG(vdac, bt_reg) = shuffle[u];	tc_wmb();
    713       1.1   reinoud 			}
    714       1.1   reinoud 			bcnt += 2;
    715       1.1   reinoud 		}
    716       1.1   reinoud 		/* pad unoccupied scan lines */
    717       1.1   reinoud 		while (bcnt < CURSOR_MAX_HEIGHT * 16) {
    718       1.1   reinoud 			REG(vdac, bt_reg) = 0; tc_wmb();
    719       1.1   reinoud 			REG(vdac, bt_reg) = 0; tc_wmb();
    720       1.1   reinoud 			bcnt += 2;
    721       1.1   reinoud 		}
    722       1.1   reinoud 	}
    723       1.1   reinoud #endif /* XXX snip XXX */
    724       1.1   reinoud 
    725       1.9   reinoud 	dc->dc_changed ^= cleared;
    726       1.9   reinoud 
    727       1.1   reinoud 	return (1);
    728       1.1   reinoud }
    729       1.1   reinoud 
    730       1.1   reinoud 
    731       1.1   reinoud static u_char ri_col_data[6][6] = {
    732       1.1   reinoud 	{ 0,  0,  0,   0,  0,  0},	/*  1 bpp */
    733       1.1   reinoud 	{ 0,  0,  0,   0,  0,  0},	/*  2 bpp */
    734       1.1   reinoud 	{ 0,  0,  0,   0,  0,  0},	/*  4 bpp */
    735       1.1   reinoud 	{ 0,  0,  0,   0,  0,  0},	/*  8 bpp */
    736      1.12     bjh21 	{ 6,  5,  5,   0,  6, 11},	/* 16 bpp */
    737       1.1   reinoud 	{ 8,  8,  8,   0,  8, 16},	/* 32 bpp */
    738       1.1   reinoud };
    739       1.1   reinoud 
    740       1.1   reinoud static void
    741       1.1   reinoud vidcvideo_colourmap_and_cursor_init(dc)
    742       1.1   reinoud 	struct fb_devconfig *dc;
    743       1.1   reinoud {
    744       1.1   reinoud 	struct rasops_info *ri = &dc->rinfo;
    745       1.1   reinoud 	u_char *rgbdat;
    746       1.1   reinoud 
    747       1.1   reinoud 	/* Whatever we do later... just make sure we have a
    748       1.1   reinoud 	 * sane palette to start with
    749       1.1   reinoud 	 */
    750       1.1   reinoud 	vidcvideo_stdpalette();
    751       1.1   reinoud 
    752       1.1   reinoud 	/* set up rgb bit pattern values for rasops_init */
    753       1.1   reinoud 	rgbdat = ri_col_data[dc->dc_log2_depth];
    754       1.1   reinoud 	ri->ri_rnum = rgbdat[0];
    755       1.1   reinoud 	ri->ri_gnum = rgbdat[1];
    756       1.1   reinoud 	ri->ri_bnum = rgbdat[2];
    757       1.1   reinoud 	ri->ri_rpos = rgbdat[3];
    758       1.1   reinoud 	ri->ri_gpos = rgbdat[4];
    759       1.1   reinoud 	ri->ri_bpos = rgbdat[5];
    760       1.1   reinoud 
    761       1.1   reinoud }
    762       1.1   reinoud 
    763       1.1   reinoud 
    764       1.1   reinoud static int
    765       1.1   reinoud get_cmap(sc, p)
    766       1.1   reinoud 	struct vidcvideo_softc *sc;
    767       1.1   reinoud 	struct wsdisplay_cmap *p;
    768       1.1   reinoud {
    769       1.1   reinoud 	u_int index = p->index, count = p->count;
    770      1.20       chs 	int error;
    771       1.1   reinoud 
    772      1.14    itojun 	if (index >= CMAP_SIZE || count > CMAP_SIZE - index)
    773       1.1   reinoud 		return (EINVAL);
    774       1.1   reinoud 
    775      1.20       chs 	error = copyout(&sc->sc_dc->dc_cmap.r[index], p->red, count);
    776      1.20       chs 	if (error)
    777      1.20       chs 		return error;
    778      1.20       chs 	error = copyout(&sc->sc_dc->dc_cmap.g[index], p->green, count);
    779      1.20       chs 	if (error)
    780      1.20       chs 		return error;
    781      1.20       chs 	error = copyout(&sc->sc_dc->dc_cmap.b[index], p->blue, count);
    782      1.20       chs 	return error;
    783       1.1   reinoud }
    784       1.1   reinoud 
    785       1.1   reinoud 
    786       1.1   reinoud static int
    787       1.1   reinoud set_cmap(sc, p)
    788       1.1   reinoud 	struct vidcvideo_softc *sc;
    789       1.1   reinoud 	struct wsdisplay_cmap *p;
    790       1.1   reinoud {
    791       1.9   reinoud     	struct fb_devconfig *dc = sc->sc_dc;
    792      1.20       chs 	struct hwcmap256 cmap;
    793       1.1   reinoud 	u_int index = p->index, count = p->count;
    794      1.20       chs 	int error;
    795       1.1   reinoud 
    796       1.1   reinoud 	if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
    797       1.1   reinoud 		return (EINVAL);
    798       1.1   reinoud 
    799      1.20       chs 	error = copyin(p->red, &cmap.r[index], count);
    800      1.20       chs 	if (error)
    801      1.20       chs 		return error;
    802      1.20       chs 	error = copyin(p->green, &cmap.g[index], count);
    803      1.20       chs 	if (error)
    804      1.20       chs 		return error;
    805      1.20       chs 	error = copyin(p->blue, &cmap.b[index], count);
    806      1.20       chs 	if (error)
    807      1.20       chs 		return error;
    808      1.20       chs 	memcpy(&dc->dc_cmap.r[index], &cmap.r[index], count);
    809      1.20       chs 	memcpy(&dc->dc_cmap.g[index], &cmap.g[index], count);
    810      1.20       chs 	memcpy(&dc->dc_cmap.b[index], &cmap.b[index], count);
    811       1.9   reinoud 	dc->dc_changed |= WSDISPLAY_CMAP_DOLUT;
    812       1.1   reinoud 	return (0);
    813       1.1   reinoud }
    814       1.1   reinoud 
    815       1.1   reinoud 
    816       1.1   reinoud static int
    817       1.1   reinoud set_cursor(sc, p)
    818       1.1   reinoud 	struct vidcvideo_softc *sc;
    819       1.1   reinoud 	struct wsdisplay_cursor *p;
    820       1.1   reinoud {
    821       1.9   reinoud #define	cc (&dc->dc_cursor)
    822       1.9   reinoud     	struct fb_devconfig *dc = sc->sc_dc;
    823      1.20       chs 	u_int v, index = 0, count = 0, icount = 0;
    824      1.20       chs 	uint8_t r[2], g[2], b[2], image[512], mask[512];
    825      1.20       chs 	int error;
    826      1.19        he 
    827      1.19        he 	/* XXX gcc does not detect identical conditions */
    828      1.19        he 	index = count = icount = 0;
    829       1.1   reinoud 
    830       1.1   reinoud 	v = p->which;
    831       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    832       1.1   reinoud 		index = p->cmap.index;
    833       1.1   reinoud 		count = p->cmap.count;
    834      1.20       chs 		if (index >= CURSOR_MAX_COLOURS ||
    835      1.20       chs 		    (index + count) > CURSOR_MAX_COLOURS)
    836       1.1   reinoud 			return (EINVAL);
    837      1.20       chs 		error = copyin(p->cmap.red, &r[index], count);
    838      1.20       chs 		if (error)
    839      1.20       chs 			return error;
    840      1.20       chs 		error = copyin(p->cmap.green, &g[index], count);
    841      1.20       chs 		if (error)
    842      1.20       chs 			return error;
    843      1.20       chs 		error = copyin(p->cmap.blue, &b[index], count);
    844      1.20       chs 		if (error)
    845      1.20       chs 			return error;
    846       1.1   reinoud 	}
    847       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    848      1.20       chs 		if (p->size.x > CURSOR_MAX_WIDTH ||
    849      1.20       chs 		    p->size.y > CURSOR_MAX_HEIGHT)
    850       1.1   reinoud 			return (EINVAL);
    851       1.1   reinoud 		icount = sizeof(u_int32_t) * p->size.y;
    852      1.20       chs 		error = copyin(p->image, &image, icount);
    853      1.20       chs 		if (error)
    854      1.20       chs 			return error;
    855      1.20       chs 		error = copyin(p->mask, &mask, icount);
    856      1.20       chs 		if (error)
    857      1.20       chs 			return error;
    858       1.1   reinoud 	}
    859       1.1   reinoud 
    860       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOCUR)
    861       1.9   reinoud 		dc->dc_curenb = p->enable;
    862       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOPOS)
    863       1.1   reinoud 		set_curpos(sc, &p->pos);
    864       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOHOT)
    865       1.1   reinoud 		cc->cc_hot = p->hot;
    866       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    867      1.20       chs 		memcpy(&cc->cc_color[index], &r[index], count);
    868      1.20       chs 		memcpy(&cc->cc_color[index + 2], &g[index], count);
    869      1.20       chs 		memcpy(&cc->cc_color[index + 4], &b[index], count);
    870       1.1   reinoud 	}
    871       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    872       1.1   reinoud 		cc->cc_size = p->size;
    873       1.1   reinoud 		memset(cc->cc_image, 0, sizeof cc->cc_image);
    874      1.20       chs 		memcpy(cc->cc_image, image, icount);
    875       1.1   reinoud 		memset(cc->cc_mask, 0, sizeof cc->cc_mask);
    876      1.20       chs 		memcpy(cc->cc_mask, mask, icount);
    877       1.1   reinoud 	}
    878       1.9   reinoud 	dc->dc_changed |= v;
    879       1.1   reinoud 
    880       1.1   reinoud 	return (0);
    881       1.1   reinoud #undef cc
    882       1.1   reinoud }
    883       1.1   reinoud 
    884       1.1   reinoud 
    885       1.1   reinoud static int
    886       1.1   reinoud get_cursor(sc, p)
    887       1.1   reinoud 	struct vidcvideo_softc *sc;
    888       1.1   reinoud 	struct wsdisplay_cursor *p;
    889       1.1   reinoud {
    890       1.5    atatat 	return (EPASSTHROUGH); /* XXX */
    891       1.1   reinoud }
    892       1.1   reinoud 
    893       1.1   reinoud 
    894       1.1   reinoud static void
    895       1.1   reinoud set_curpos(sc, curpos)
    896       1.1   reinoud 	struct vidcvideo_softc *sc;
    897       1.1   reinoud 	struct wsdisplay_curpos *curpos;
    898       1.1   reinoud {
    899       1.1   reinoud 	struct fb_devconfig *dc = sc->sc_dc;
    900       1.1   reinoud 	int x = curpos->x, y = curpos->y;
    901       1.1   reinoud 
    902       1.1   reinoud 	if (y < 0)
    903       1.1   reinoud 		y = 0;
    904       1.1   reinoud 	else if (y > dc->dc_ht)
    905       1.1   reinoud 		y = dc->dc_ht;
    906       1.1   reinoud 	if (x < 0)
    907       1.1   reinoud 		x = 0;
    908       1.1   reinoud 	else if (x > dc->dc_wid)
    909       1.1   reinoud 		x = dc->dc_wid;
    910       1.9   reinoud 	dc->dc_cursor.cc_pos.x = x;
    911       1.9   reinoud 	dc->dc_cursor.cc_pos.y = y;
    912       1.1   reinoud }
    913       1.1   reinoud 
    914       1.1   reinoud 
    915       1.1   reinoud static void vv_copyrows(id, srcrow, dstrow, nrows)
    916       1.1   reinoud 	void *id;
    917       1.1   reinoud 	int srcrow, dstrow, nrows;
    918       1.1   reinoud {
    919       1.1   reinoud 	struct rasops_info *ri = id;
    920       1.1   reinoud 	int height, offset, size;
    921       1.1   reinoud 	int scrollup, scrolldown;
    922       1.1   reinoud 	unsigned char *src, *dst;
    923       1.1   reinoud 
    924       1.1   reinoud 	/* All movements are done in multiples of character heigths */
    925       1.1   reinoud 	height = ri->ri_font->fontheight * nrows;
    926       1.1   reinoud 	offset = (srcrow - dstrow) * ri->ri_yscale;
    927       1.1   reinoud 	size   = height * ri->ri_stride;
    928       1.1   reinoud 
    929       1.1   reinoud 	/* check if we are full screen scrolling */
    930       1.1   reinoud 	scrollup   = (srcrow + nrows >= ri->ri_rows);
    931       1.1   reinoud 	scrolldown = (dstrow + nrows >= ri->ri_rows);
    932       1.1   reinoud 
    933       1.1   reinoud 	if ((scrollup || scrolldown) && (videomemory.vidm_type == VIDEOMEM_TYPE_VRAM)) {
    934       1.1   reinoud 		ri->ri_bits = vidcvideo_hwscroll(offset);
    935       1.1   reinoud 		vidcvideo_progr_scroll();	/* sadistic ; shouldnt this be on vsync? */
    936       1.1   reinoud 
    937       1.1   reinoud 		/* wipe out remains of the screen if nessisary */
    938      1.18     chris 		if (ri->ri_emuheight != ri->ri_height) vv_eraserows(id, ri->ri_rows, 1, 0);
    939       1.1   reinoud 		return;
    940       1.1   reinoud 	};
    941       1.1   reinoud 
    942       1.1   reinoud 	/* Else we just copy the area : we're braindead for now
    943       1.1   reinoud 	 * Note: we can't use hardware scrolling when the softc isnt known yet...
    944       1.1   reinoud 	 * if its not known we dont have interrupts and we can't change the display
    945       1.1   reinoud 	 * address reliable other than in a Vsync
    946       1.1   reinoud 	 */
    947       1.1   reinoud 
    948       1.1   reinoud 	src = ri->ri_bits + srcrow * ri->ri_font->fontheight * ri->ri_stride;
    949       1.1   reinoud 	dst = ri->ri_bits + dstrow * ri->ri_font->fontheight * ri->ri_stride;
    950       1.1   reinoud 
    951       1.1   reinoud 	bcopy(src, dst, size);
    952       1.1   reinoud }
    953       1.1   reinoud 
    954       1.1   reinoud 
    955       1.1   reinoud static void vv_eraserows(id, startrow, nrows, attr)
    956       1.1   reinoud 	void *id;
    957       1.1   reinoud 	int startrow, nrows;
    958       1.1   reinoud 	long attr;
    959       1.1   reinoud {
    960       1.1   reinoud 	struct rasops_info *ri = id;
    961       1.1   reinoud 	int height;
    962       1.1   reinoud 	unsigned char *src;
    963       1.1   reinoud 
    964       1.1   reinoud 	/* we're braindead for now */
    965       1.1   reinoud 	height = ri->ri_font->fontheight * nrows * ri->ri_stride;
    966       1.1   reinoud 
    967       1.1   reinoud 	src = ri->ri_bits + startrow * ri->ri_font->fontheight * ri->ri_stride;
    968       1.1   reinoud 
    969       1.1   reinoud 	bzero(src, height);
    970       1.6   reinoud }
    971       1.6   reinoud 
    972       1.6   reinoud 
    973       1.6   reinoud static void vv_putchar(id, row, col, uc, attr)
    974       1.6   reinoud     	void *id;
    975       1.6   reinoud 	int row, col;
    976       1.6   reinoud 	u_int uc;
    977       1.6   reinoud 	long attr;
    978       1.6   reinoud {
    979       1.6   reinoud     	struct rasops_info *ri = id;
    980       1.6   reinoud 	struct fb_devconfig *dc = (struct fb_devconfig *) (ri->ri_hw);
    981       1.9   reinoud 
    982       1.9   reinoud 	/* delay the write back operation of the screen area */
    983       1.9   reinoud 	dc->dc_writeback_delay = SCREEN_WRITE_BACK_DELAY;
    984       1.9   reinoud 	dc->dc_changed |= WSDISPLAY_WB_COUNTER;
    985       1.6   reinoud 
    986       1.6   reinoud 	/* just delegate */
    987       1.6   reinoud 	dc->orig_ri_ops.putchar(id, row, col, uc, attr);
    988       1.1   reinoud }
    989