Home | History | Annotate | Line # | Download | only in iomd
vidcvideo.c revision 1.34.4.3
      1  1.34.4.3      yamt /* $NetBSD: vidcvideo.c,v 1.34.4.3 2010/03/11 15:02:06 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  *
     16       1.1   reinoud  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.1   reinoud  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18       1.1   reinoud  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19       1.1   reinoud  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20       1.1   reinoud  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21       1.1   reinoud  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22       1.1   reinoud  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23       1.1   reinoud  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24       1.1   reinoud  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25       1.1   reinoud  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26       1.1   reinoud  *
     27       1.1   reinoud  * Created vidcvideo.c from /dev/tc/cfb.c to fit the Acorn/ARM VIDC1 and VIDC20 chips
     28       1.1   reinoud  *
     29       1.1   reinoud  */
     30       1.1   reinoud 
     31       1.1   reinoud #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     32       1.1   reinoud 
     33  1.34.4.3      yamt __KERNEL_RCSID(0, "$NetBSD: vidcvideo.c,v 1.34.4.3 2010/03/11 15:02:06 yamt Exp $");
     34       1.1   reinoud 
     35       1.1   reinoud #include <sys/param.h>
     36       1.1   reinoud #include <sys/systm.h>
     37       1.1   reinoud #include <sys/kernel.h>
     38       1.1   reinoud #include <sys/device.h>
     39       1.1   reinoud #include <sys/malloc.h>
     40       1.1   reinoud #include <sys/buf.h>
     41       1.1   reinoud #include <sys/ioctl.h>
     42       1.1   reinoud 
     43       1.1   reinoud #include <arm/mainbus/mainbus.h>
     44       1.1   reinoud #include <machine/bus.h>
     45       1.1   reinoud #include <machine/intr.h>
     46       1.1   reinoud 
     47       1.1   reinoud #include <dev/wscons/wsconsio.h>
     48       1.1   reinoud #include <dev/wscons/wsdisplayvar.h>
     49       1.1   reinoud 
     50       1.1   reinoud #include <dev/rasops/rasops.h>
     51       1.1   reinoud #include <dev/wsfont/wsfont.h>
     52       1.1   reinoud 
     53      1.34     chris #include <dev/wscons/wsdisplay_vconsvar.h>
     54      1.34     chris 
     55       1.1   reinoud #include <uvm/uvm_extern.h>
     56       1.1   reinoud #include <arm/arm32/pmap.h>
     57       1.9   reinoud #include <arm/cpufunc.h>
     58       1.1   reinoud 
     59       1.1   reinoud /* for vidc_mode ... needs to be MI indepenent one day */
     60       1.1   reinoud #include <arm/iomd/vidc.h>
     61       1.1   reinoud #include <arm/iomd/vidc20config.h>
     62       1.9   reinoud #include <arm/iomd/vidcvideo.h>
     63       1.1   reinoud #include <machine/bootconfig.h>
     64       1.9   reinoud 
     65       1.1   reinoud /* FOR DEBUG */
     66       1.1   reinoud extern videomemory_t videomemory;
     67       1.1   reinoud 
     68       1.1   reinoud struct hwcmap256 {
     69       1.1   reinoud #define	CMAP_SIZE	256	/* 256 R/G/B entries */
     70      1.34     chris 	uint8_t r[CMAP_SIZE];
     71      1.34     chris 	uint8_t g[CMAP_SIZE];
     72      1.34     chris 	uint8_t b[CMAP_SIZE];
     73       1.1   reinoud };
     74       1.1   reinoud 
     75       1.1   reinoud 
     76       1.1   reinoud /* XXX for CURSOR_MAX_WIDTH = 32 */
     77       1.1   reinoud struct hwcursor32 {
     78       1.1   reinoud 	struct wsdisplay_curpos cc_pos;
     79       1.1   reinoud 	struct wsdisplay_curpos cc_hot;
     80       1.1   reinoud 	struct wsdisplay_curpos cc_size;
     81      1.34     chris 	uint8_t cc_color[6];		/* how many? */
     82      1.34     chris 	uint32_t cc_image[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
     83      1.34     chris 	uint32_t cc_mask[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
     84       1.1   reinoud };
     85       1.1   reinoud 
     86       1.1   reinoud 
     87       1.9   reinoud struct fb_devconfig {
     88      1.11   reinoud 	vaddr_t dc_vaddr;		/* memory space virtual base address */
     89      1.11   reinoud 	paddr_t dc_paddr;		/* memory space physical base address */
     90      1.11   reinoud 	vsize_t dc_size;		/* size of slot memory */
     91      1.34     chris 	int	dc_width;		/* width of frame buffer */
     92      1.34     chris 	int	dc_height;		/* height of frame buffer */
     93      1.11   reinoud 	int	dc_log2_depth;		/* log2 of bits per pixel */
     94      1.11   reinoud 	int	dc_depth;		/* depth, bits per pixel */
     95      1.11   reinoud 	int	dc_rowbytes;		/* bytes in a FB scan line */
     96      1.11   reinoud 	vaddr_t	dc_videobase;		/* base of flat frame buffer */
     97      1.11   reinoud 	int	dc_blanked;		/* currently has video disabled */
     98      1.11   reinoud 	void   *dc_hwscroll_cookie;	/* cookie for hardware scroll */
     99      1.33     chris 	void   *dc_ih;			/* interrupt handler for dc */
    100      1.11   reinoud 
    101      1.11   reinoud 	int	dc_curenb;		/* is cursor sprite enabled ?	*/
    102      1.33     chris 	int	_internal_dc_changed;	/* need update of hardware	*/
    103      1.11   reinoud 	int	dc_writeback_delay;	/* Screenarea write back vsync counter */
    104       1.9   reinoud #define	WSDISPLAY_CMAP_DOLUT	0x20
    105       1.9   reinoud #define WSDISPLAY_VIDEO_ONOFF	0x40
    106       1.9   reinoud #define WSDISPLAY_WB_COUNTER	0x80
    107       1.9   reinoud 
    108      1.34     chris 	struct hwcmap256	dc_cmap;   /* software copy of colormap	*/
    109      1.34     chris 	struct hwcursor32	dc_cursor; /* software copy of cursor	*/
    110       1.9   reinoud 
    111       1.9   reinoud 	struct vidc_mode	mode_info;
    112       1.9   reinoud 
    113       1.9   reinoud 	struct wsdisplay_emulops orig_ri_ops;	/* Rasops functions for deligation */
    114      1.34     chris 
    115      1.34     chris 	/* virtual console support */
    116      1.34     chris 	struct vcons_data dc_vd;
    117      1.34     chris 	struct vcons_screen dc_console;
    118       1.9   reinoud };
    119       1.9   reinoud 
    120       1.9   reinoud 
    121       1.1   reinoud struct vidcvideo_softc {
    122       1.1   reinoud 	struct device sc_dev;
    123       1.9   reinoud 	struct fb_devconfig *sc_dc;	/* device configuration		*/
    124       1.1   reinoud };
    125       1.1   reinoud 
    126       1.1   reinoud 
    127       1.1   reinoud /* Function prototypes for glue */
    128      1.25     bjh21 static int  vidcvideo_match(struct device *, struct cfdata *, void *);
    129      1.25     bjh21 static void vidcvideo_attach(struct device *, struct device *, void *);
    130       1.1   reinoud 
    131       1.1   reinoud 
    132       1.1   reinoud /* config glue */
    133      1.15   thorpej CFATTACH_DECL(vidcvideo, sizeof(struct vidcvideo_softc),
    134      1.16   thorpej     vidcvideo_match, vidcvideo_attach, NULL, NULL);
    135       1.1   reinoud 
    136       1.1   reinoud static struct fb_devconfig vidcvideo_console_dc;
    137      1.34     chris static bool vidcvideo_is_console = false;
    138       1.1   reinoud 
    139       1.1   reinoud 
    140       1.1   reinoud static struct wsscreen_descr vidcvideo_stdscreen = {
    141       1.1   reinoud 	"std", 0, 0,
    142      1.34     chris 	NULL, /* textops */
    143      1.34     chris 	8, 16,
    144      1.34     chris 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    145      1.34     chris 	NULL
    146       1.1   reinoud };
    147       1.1   reinoud 
    148       1.1   reinoud static const struct wsscreen_descr *_vidcvideo_scrlist[] = {
    149       1.1   reinoud 	&vidcvideo_stdscreen,
    150       1.1   reinoud };
    151       1.1   reinoud 
    152       1.1   reinoud static const struct wsscreen_list vidcvideo_screenlist = {
    153      1.25     bjh21 	sizeof(_vidcvideo_scrlist) / sizeof(struct wsscreen_descr *),
    154      1.25     bjh21 	_vidcvideo_scrlist
    155       1.1   reinoud };
    156       1.1   reinoud 
    157      1.31  christos static int	vidcvideoioctl(void *, void *, u_long, void *, int,
    158      1.25     bjh21     struct lwp *);
    159      1.25     bjh21 static paddr_t	vidcvideommap(void *, void *, off_t, int);
    160      1.34     chris static void	vidcvideoinit_screen(void *, struct vcons_screen *, int, long *);
    161       1.1   reinoud 
    162      1.33     chris static void	vidcvideo_queue_dc_change(struct fb_devconfig*, int);
    163      1.33     chris static int	flush_dc_changes_to_screen(struct fb_devconfig*);
    164      1.33     chris 
    165      1.34     chris static struct wsdisplay_accessops vidcvideo_accessops = {
    166       1.1   reinoud 	vidcvideoioctl,
    167       1.1   reinoud 	vidcvideommap,
    168      1.34     chris 	NULL,	/* alloc_screen */
    169      1.34     chris 	NULL,	/* free_screen */
    170      1.34     chris 	NULL,	/* show_screen */
    171      1.34     chris 	NULL,	/* load_font */
    172      1.34     chris 	NULL,	/* pollc */
    173      1.34     chris 	NULL	/* scroll */
    174       1.1   reinoud };
    175       1.1   reinoud 
    176       1.6   reinoud 
    177       1.1   reinoud /* Function prototypes */
    178      1.25     bjh21 int         vidcvideo_cnattach(vaddr_t);
    179      1.25     bjh21 static void vidcvideo_colourmap_and_cursor_init(struct fb_devconfig *);
    180       1.1   reinoud 
    181      1.25     bjh21 static int  get_cmap(struct vidcvideo_softc *, struct wsdisplay_cmap *);
    182      1.25     bjh21 static int  set_cmap(struct vidcvideo_softc *, struct wsdisplay_cmap *);
    183      1.25     bjh21 static int  set_cursor(struct vidcvideo_softc *, struct wsdisplay_cursor *);
    184      1.25     bjh21 static int  get_cursor(struct vidcvideo_softc *, struct wsdisplay_cursor *);
    185      1.25     bjh21 static void set_curpos(struct vidcvideo_softc *, struct wsdisplay_curpos *);
    186      1.34     chris static void vidcvideo_getdevconfig(vaddr_t, u_int, struct fb_devconfig *);
    187       1.1   reinoud 
    188      1.25     bjh21 static int  vidcvideointr(void *);
    189       1.6   reinoud 
    190       1.1   reinoud /* Acceleration function prototypes */
    191      1.25     bjh21 static void vv_copyrows(void *, int, int, int);
    192      1.25     bjh21 static void vv_eraserows(void *, int, int, long);
    193      1.25     bjh21 static void vv_putchar(void *c, int row, int col, u_int uc, long attr);
    194       1.1   reinoud 
    195       1.1   reinoud 
    196       1.1   reinoud static int
    197  1.34.4.2      yamt vidcvideo_match(struct device *parent, struct cfdata *match, void *aux)
    198       1.1   reinoud {
    199      1.25     bjh21 
    200       1.1   reinoud 	/* Can't probe AFAIK ; how ? */
    201      1.25     bjh21 	return 1;
    202       1.1   reinoud }
    203       1.1   reinoud 
    204       1.1   reinoud 
    205       1.1   reinoud static void
    206      1.34     chris vidcvideo_getdevconfig(vaddr_t dense_addr, u_int mem_size,
    207      1.34     chris 		struct fb_devconfig *dc)
    208       1.1   reinoud {
    209      1.25     bjh21 
    210       1.1   reinoud 	dc->dc_vaddr = dense_addr;
    211      1.11   reinoud 	(void) pmap_extract(pmap_kernel(), dc->dc_vaddr, &(dc->dc_paddr));
    212       1.1   reinoud 
    213       1.1   reinoud 	vidcvideo_getmode(&dc->mode_info);
    214       1.1   reinoud 
    215      1.34     chris 	dc->dc_width = dc->mode_info.timings.hdisplay;
    216      1.34     chris 	dc->dc_height = dc->mode_info.timings.vdisplay;
    217       1.1   reinoud 	dc->dc_log2_depth = dc->mode_info.log2_bpp;
    218       1.1   reinoud 	dc->dc_depth = 1 << dc->dc_log2_depth;
    219       1.1   reinoud 	dc->dc_videobase = dc->dc_vaddr;
    220       1.1   reinoud 	dc->dc_blanked = 0;
    221       1.1   reinoud 
    222       1.1   reinoud 	/* this should/could be done somewhat more elegant! */
    223       1.1   reinoud 	switch (dc->dc_depth) {
    224       1.1   reinoud 		case 1:
    225      1.34     chris 			dc->dc_rowbytes = dc->dc_width / 8;
    226       1.1   reinoud 			break;
    227       1.1   reinoud 		case 2:
    228      1.34     chris 			dc->dc_rowbytes = dc->dc_width / 4;
    229       1.1   reinoud 			break;
    230       1.1   reinoud 		case 4:
    231      1.34     chris 			dc->dc_rowbytes = dc->dc_width / 2;
    232       1.1   reinoud 			break;
    233       1.1   reinoud 		case 8:
    234      1.34     chris 			dc->dc_rowbytes = dc->dc_width;
    235       1.1   reinoud 			break;
    236       1.1   reinoud 		case 16:
    237      1.34     chris 			dc->dc_rowbytes = dc->dc_width * 2;
    238       1.1   reinoud 			break;
    239       1.1   reinoud 		case 32:
    240      1.34     chris 			dc->dc_rowbytes = dc->dc_width * 4;
    241       1.1   reinoud 			break;
    242       1.1   reinoud 		default:
    243       1.1   reinoud 			printf("Unknown colour depth %d ... what to do ?", dc->dc_depth);
    244       1.1   reinoud 			break;
    245      1.25     bjh21 	}
    246       1.1   reinoud 
    247      1.34     chris 	/* setup the correct size */
    248      1.34     chris 	dc->dc_size = mem_size;
    249       1.1   reinoud 
    250       1.1   reinoud 	/* initialize colormap and cursor resource */
    251       1.1   reinoud 	vidcvideo_colourmap_and_cursor_init(dc);
    252       1.1   reinoud 
    253      1.34     chris 	/* blank the memory */
    254  1.34.4.2      yamt 	memset((void*)dc->dc_vaddr, 0, dc->dc_size);
    255       1.9   reinoud 
    256       1.9   reinoud 	/* intitialise miscelanious */
    257       1.9   reinoud 	dc->dc_writeback_delay = 0;
    258       1.1   reinoud }
    259       1.1   reinoud 
    260       1.1   reinoud static void
    261      1.34     chris vidcvideoinit_screen(void *cookie, struct vcons_screen *scr,
    262      1.34     chris 		    int existing, long *defattr)
    263       1.1   reinoud {
    264      1.34     chris 	struct rasops_info *ri = &scr->scr_ri;
    265      1.34     chris 	struct fb_devconfig *dc = cookie;
    266       1.1   reinoud 
    267      1.34     chris 	if ((scr == &dc->dc_console) && (dc->dc_vd.active != NULL))
    268       1.1   reinoud 		return;
    269       1.1   reinoud 
    270      1.34     chris 	ri->ri_flg    = 0; /* RI_CENTER | RI_FULLCLEAR; */
    271      1.34     chris 	ri->ri_depth  = dc->dc_depth;
    272      1.34     chris 	ri->ri_bits   = (void *) dc->dc_videobase;
    273      1.34     chris 	ri->ri_width  = dc->dc_width;
    274      1.34     chris 	ri->ri_height = dc->dc_height;
    275      1.34     chris 	ri->ri_stride = dc->dc_rowbytes;
    276      1.34     chris 	ri->ri_hw     = &dc->dc_console;	/* link back */
    277      1.34     chris 
    278      1.34     chris 	rasops_init(ri,
    279      1.34     chris 	    ri->ri_height / 8,
    280      1.34     chris 	    ri->ri_width / 8);
    281      1.34     chris 
    282      1.34     chris 	ri->ri_caps = WSSCREEN_WSCOLORS;
    283      1.34     chris 
    284      1.34     chris 	rasops_reconfig(ri,
    285      1.34     chris 	    ri->ri_height / ri->ri_font->fontheight,
    286      1.34     chris 	    ri->ri_width / ri->ri_font->fontwidth);
    287       1.1   reinoud 
    288       1.6   reinoud 	/*
    289       1.6   reinoud 	 * Provide a hook for the acceleration functions and make a copy of the
    290       1.6   reinoud 	 * original rasops functions for passing on calls
    291       1.6   reinoud 	 */
    292      1.34     chris 	memcpy(&(dc->orig_ri_ops), &(ri->ri_ops),
    293      1.25     bjh21 	    sizeof(struct wsdisplay_emulops));
    294       1.6   reinoud 
    295       1.6   reinoud 	/* add our accelerated functions */
    296      1.34     chris 	ri->ri_ops.eraserows = vv_eraserows;
    297      1.34     chris 	ri->ri_ops.copyrows  = vv_copyrows;
    298       1.1   reinoud 
    299       1.6   reinoud 	/* add the extra activity measuring functions; they just delegate on */
    300      1.34     chris 	ri->ri_ops.putchar   = vv_putchar;
    301       1.1   reinoud 
    302      1.34     chris 	vidcvideo_stdscreen.nrows = ri->ri_rows;
    303      1.34     chris 	vidcvideo_stdscreen.ncols = ri->ri_cols;
    304      1.34     chris 	vidcvideo_stdscreen.textops = &ri->ri_ops;
    305      1.34     chris 	vidcvideo_stdscreen.capabilities = ri->ri_caps;
    306       1.1   reinoud }
    307       1.1   reinoud 
    308       1.1   reinoud static void
    309      1.25     bjh21 vidcvideo_attach(struct device *parent, struct device *self, void *aux)
    310       1.1   reinoud {
    311       1.1   reinoud 	struct vidcvideo_softc *sc = (struct vidcvideo_softc *)self;
    312       1.9   reinoud 	struct fb_devconfig *dc;
    313       1.1   reinoud 	struct wsemuldisplaydev_attach_args waa;
    314       1.6   reinoud 	long defattr;
    315       1.1   reinoud 
    316      1.34     chris 	dc = sc->sc_dc = &vidcvideo_console_dc;
    317      1.34     chris 
    318      1.34     chris 	/*
    319      1.34     chris 	 * for reasons which are crazy we init vidcvideo twice,
    320      1.34     chris 	 * the second time sets up the cursor
    321      1.34     chris 	 */
    322       1.1   reinoud 	vidcvideo_init();
    323      1.34     chris 	if (!vidcvideo_is_console) {
    324      1.34     chris 		vidcvideo_getdevconfig(videomemory.vidm_vbase,
    325      1.34     chris 				videomemory.vidm_size,
    326      1.34     chris 			       	sc->sc_dc);
    327      1.25     bjh21 	}
    328       1.1   reinoud 
    329      1.34     chris 	vcons_init(&dc->dc_vd, dc, &vidcvideo_stdscreen, &vidcvideo_accessops);
    330      1.34     chris 	dc->dc_vd.init_screen = vidcvideoinit_screen;
    331      1.34     chris 
    332      1.34     chris 	vcons_init_screen(&dc->dc_vd, &dc->dc_console, 1, &defattr);
    333      1.34     chris 
    334      1.34     chris 	dc->dc_console.scr_flags |= VCONS_SCREEN_IS_STATIC;
    335       1.9   reinoud 
    336       1.1   reinoud 	vidcvideo_printdetails();
    337      1.28     bjh21 	printf(": mode %s, %dbpp\n", dc->mode_info.timings.name,
    338       1.9   reinoud 	    dc->dc_depth);
    339       1.1   reinoud 
    340       1.1   reinoud 	/* set up interrupt flags */
    341      1.33     chris 	vidcvideo_queue_dc_change(dc, WSDISPLAY_CMAP_DOLUT);
    342       1.1   reinoud 
    343       1.1   reinoud 	/* Establish an interrupt handler, and clear any pending interrupts */
    344      1.33     chris 	dc->dc_ih = intr_claim(IRQ_FLYBACK, IPL_TTY, "vblank", vidcvideointr, dc);
    345       1.1   reinoud 
    346       1.1   reinoud 	waa.console = (vidcvideo_is_console ? 1 : 0);
    347       1.1   reinoud 	waa.scrdata = &vidcvideo_screenlist;
    348       1.1   reinoud 	waa.accessops = &vidcvideo_accessops;
    349      1.34     chris 	waa.accesscookie = &dc->dc_vd;
    350       1.1   reinoud 
    351       1.1   reinoud 	config_found(self, &waa, wsemuldisplaydevprint);
    352       1.1   reinoud }
    353       1.1   reinoud 
    354       1.1   reinoud 
    355       1.1   reinoud static int
    356      1.31  christos vidcvideoioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    357      1.25     bjh21     struct lwp *l)
    358       1.1   reinoud {
    359      1.34     chris 	struct vcons_data *vd = v;
    360      1.34     chris 	struct vidcvideo_softc *sc = vd->cookie;
    361       1.1   reinoud 	struct fb_devconfig *dc = sc->sc_dc;
    362      1.34     chris 	struct vcons_screen *ms = vd->active;
    363       1.1   reinoud 	int state;
    364       1.1   reinoud 
    365       1.1   reinoud 	switch (cmd) {
    366       1.1   reinoud 	case WSDISPLAYIO_GTYPE:
    367       1.1   reinoud 		*(u_int *)data = WSDISPLAY_TYPE_VIDC;
    368      1.25     bjh21 		return 0;
    369       1.1   reinoud 
    370       1.1   reinoud 	case WSDISPLAYIO_GINFO:
    371      1.34     chris 		if (ms == NULL)
    372      1.34     chris 			return ENODEV;
    373       1.1   reinoud #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    374      1.34     chris 		wsd_fbip->height = dc->dc_height;
    375      1.34     chris 		wsd_fbip->width  = dc->dc_width;
    376       1.9   reinoud 		wsd_fbip->depth  = dc->dc_depth;
    377       1.1   reinoud 		wsd_fbip->cmsize = CMAP_SIZE;
    378       1.1   reinoud #undef fbt
    379      1.25     bjh21 		return 0;
    380       1.1   reinoud 
    381       1.1   reinoud 	case WSDISPLAYIO_GETCMAP:
    382       1.1   reinoud 		return get_cmap(sc, (struct wsdisplay_cmap *)data);
    383       1.1   reinoud 
    384       1.1   reinoud 	case WSDISPLAYIO_PUTCMAP:
    385       1.1   reinoud 		return set_cmap(sc, (struct wsdisplay_cmap *)data);
    386      1.34     chris 
    387      1.34     chris 	case WSDISPLAYIO_LINEBYTES:
    388      1.34     chris 		*(u_int *)data = dc->dc_rowbytes;
    389      1.34     chris 		return 0;
    390       1.1   reinoud 
    391       1.1   reinoud 	case WSDISPLAYIO_SVIDEO:
    392       1.1   reinoud 		state = *(int *)data;
    393       1.1   reinoud 		dc->dc_blanked = (state == WSDISPLAYIO_VIDEO_OFF);
    394      1.33     chris 		vidcvideo_queue_dc_change(dc, WSDISPLAY_VIDEO_ONOFF);
    395       1.1   reinoud 		/* done on video blank */
    396      1.25     bjh21 		return 0;
    397       1.1   reinoud 
    398       1.1   reinoud 	case WSDISPLAYIO_GVIDEO:
    399       1.1   reinoud 		*(u_int *)data = dc->dc_blanked ?
    400       1.1   reinoud 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    401      1.25     bjh21 		return 0;
    402       1.1   reinoud 
    403       1.1   reinoud 	case WSDISPLAYIO_GCURPOS:
    404       1.9   reinoud 		*(struct wsdisplay_curpos *)data = dc->dc_cursor.cc_pos;
    405      1.25     bjh21 		return 0;
    406       1.1   reinoud 
    407       1.1   reinoud 	case WSDISPLAYIO_SCURPOS:
    408       1.1   reinoud 		set_curpos(sc, (struct wsdisplay_curpos *)data);
    409      1.33     chris 		vidcvideo_queue_dc_change(dc, WSDISPLAY_CURSOR_DOPOS);
    410      1.25     bjh21 		return 0;
    411       1.1   reinoud 
    412       1.1   reinoud 	case WSDISPLAYIO_GCURMAX:
    413       1.1   reinoud 		((struct wsdisplay_curpos *)data)->x = CURSOR_MAX_WIDTH;
    414       1.1   reinoud 		((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_HEIGHT;
    415      1.25     bjh21 		return 0;
    416       1.1   reinoud 
    417       1.1   reinoud 	case WSDISPLAYIO_GCURSOR:
    418       1.1   reinoud 		return get_cursor(sc, (struct wsdisplay_cursor *)data);
    419       1.1   reinoud 
    420       1.1   reinoud 	case WSDISPLAYIO_SCURSOR:
    421       1.1   reinoud 		return set_cursor(sc, (struct wsdisplay_cursor *)data);
    422       1.1   reinoud 
    423       1.1   reinoud 	case WSDISPLAYIO_SMODE:
    424       1.1   reinoud 		state = *(int *)data;
    425      1.25     bjh21 		if (state == WSDISPLAYIO_MODE_MAPPED)
    426       1.1   reinoud 			dc->dc_hwscroll_cookie = vidcvideo_hwscroll_reset();
    427      1.25     bjh21 		if (state == WSDISPLAYIO_MODE_EMUL)
    428       1.1   reinoud 			vidcvideo_hwscroll_back(dc->dc_hwscroll_cookie);
    429       1.1   reinoud 		vidcvideo_progr_scroll();
    430      1.11   reinoud 
    431      1.25     bjh21 		return 0;
    432       1.1   reinoud 	}
    433       1.5    atatat 	return EPASSTHROUGH;
    434       1.1   reinoud }
    435       1.1   reinoud 
    436       1.1   reinoud 
    437       1.1   reinoud paddr_t
    438      1.25     bjh21 vidcvideommap(void *v, void *vs, off_t offset, int prot)
    439       1.1   reinoud {
    440      1.34     chris 	struct vcons_data *vd = v;
    441      1.34     chris 	struct vidcvideo_softc *sc = vd->cookie;
    442       1.1   reinoud 
    443       1.1   reinoud 	if (offset >= sc->sc_dc->dc_size || offset < 0)
    444      1.25     bjh21 		return -1;
    445      1.11   reinoud 
    446      1.11   reinoud 	return arm_btop(sc->sc_dc->dc_paddr + offset);
    447       1.1   reinoud }
    448       1.1   reinoud 
    449       1.1   reinoud 
    450       1.1   reinoud /* EXPORT */ int
    451      1.25     bjh21 vidcvideo_cnattach(vaddr_t addr)
    452       1.1   reinoud {
    453      1.34     chris 	struct fb_devconfig *dc = &vidcvideo_console_dc;
    454      1.34     chris 	struct rasops_info *ri;
    455       1.1   reinoud 	long defattr;
    456       1.1   reinoud 
    457       1.1   reinoud 	vidcvideo_init();
    458       1.1   reinoud 
    459      1.34     chris 	/* fetch current framebuffer config */
    460      1.34     chris 	vidcvideo_getdevconfig(videomemory.vidm_vbase,
    461      1.34     chris 			videomemory.vidm_size,
    462      1.34     chris 		       	dc);
    463      1.34     chris 
    464      1.34     chris 	dc->dc_vd.active = NULL;
    465      1.34     chris 	vidcvideoinit_screen(dc, &dc->dc_console, 1, &defattr);
    466      1.34     chris 
    467      1.34     chris 	ri = &(dc->dc_console.scr_ri);
    468      1.34     chris 	ri->ri_hw = &dc->dc_console;
    469      1.34     chris 	dc->dc_console.scr_cookie = dc;
    470      1.34     chris 
    471      1.34     chris 	(*ri->ri_ops.allocattr)(ri,
    472      1.34     chris 				WS_DEFAULT_FG, /* fg */
    473      1.34     chris 				WS_DEFAULT_BG, /* bg */
    474      1.34     chris 				0,           /* wsattrs */
    475      1.34     chris 				&defattr);
    476      1.34     chris 
    477      1.34     chris 	wsdisplay_cnattach(&vidcvideo_stdscreen,
    478      1.34     chris 			   ri,   /* emulcookie */
    479      1.34     chris 		       	   0, 0, /* cursor position */
    480      1.34     chris 			   defattr);
    481      1.34     chris 
    482      1.34     chris 	vidcvideo_is_console = true;
    483      1.34     chris 
    484      1.25     bjh21 	return 0;
    485       1.1   reinoud }
    486       1.1   reinoud 
    487       1.1   reinoud 
    488       1.1   reinoud static int
    489      1.25     bjh21 vidcvideointr(void *arg)
    490       1.1   reinoud {
    491       1.9   reinoud 	struct fb_devconfig *dc = arg;
    492      1.33     chris 
    493      1.33     chris 	return flush_dc_changes_to_screen(dc);
    494      1.33     chris }
    495      1.33     chris 
    496      1.33     chris static int
    497      1.33     chris flush_dc_changes_to_screen(struct fb_devconfig *dc)
    498      1.33     chris {
    499       1.9   reinoud 	int v, cleared = 0;
    500       1.1   reinoud 
    501      1.33     chris 	v = dc->_internal_dc_changed;
    502      1.33     chris 
    503      1.33     chris 	if (v == 0) {
    504      1.33     chris 		disable_irq(IRQ_FLYBACK);
    505      1.25     bjh21 		return 1;
    506      1.33     chris 	}
    507       1.1   reinoud 
    508       1.9   reinoud 	if (v & WSDISPLAY_WB_COUNTER) {
    509       1.9   reinoud 	    	dc->dc_writeback_delay--;
    510       1.9   reinoud 		if (dc->dc_writeback_delay == 0) {
    511       1.9   reinoud 		    	cpu_dcache_wb_range(dc->dc_vaddr, dc->dc_size);
    512       1.9   reinoud 			cleared |= WSDISPLAY_WB_COUNTER;
    513      1.25     bjh21 		}
    514       1.9   reinoud 	}
    515       1.9   reinoud 
    516       1.1   reinoud 	if (v & WSDISPLAY_CMAP_DOLUT) {
    517       1.9   reinoud 		struct hwcmap256 *cm = &dc->dc_cmap;
    518       1.1   reinoud 		int index;
    519       1.1   reinoud 
    520       1.9   reinoud 		if (dc->dc_depth == 4) {
    521       1.1   reinoud 			/* palette for 4 bpp is different from 8bpp */
    522       1.1   reinoud 			vidcvideo_write(VIDC_PALREG, 0x00000000);
    523       1.9   reinoud 			for (index=0; index < (1 << dc->dc_depth); index++)
    524       1.1   reinoud 				vidcvideo_write(VIDC_PALETTE,
    525       1.1   reinoud 					VIDC_COL(cm->r[index],
    526       1.1   reinoud 						 cm->g[index],
    527       1.1   reinoud 						 cm->b[index]));
    528      1.25     bjh21 		}
    529       1.1   reinoud 
    530       1.9   reinoud 		if (dc->dc_depth == 8) {
    531      1.25     bjh21 			/*
    532      1.25     bjh21 			 * dunno what to do in more than 8bpp
    533      1.25     bjh21 			 * palettes only make sense in 8bpp and less modes
    534      1.25     bjh21 			 * on VIDC
    535      1.25     bjh21 			 */
    536       1.1   reinoud 			vidcvideo_write(VIDC_PALREG, 0x00000000);
    537       1.1   reinoud 			for (index = 0; index < CMAP_SIZE; index++) {
    538       1.1   reinoud 				vidcvideo_write(VIDC_PALETTE,
    539      1.25     bjh21 					VIDC_COL(cm->r[index], cm->g[index],
    540      1.25     bjh21 					    cm->b[index]));
    541      1.25     bjh21 			}
    542      1.25     bjh21 		}
    543       1.9   reinoud 		cleared |= WSDISPLAY_CMAP_DOLUT;
    544       1.1   reinoud 	}
    545       1.1   reinoud 
    546       1.1   reinoud 	if (v & WSDISPLAY_VIDEO_ONOFF) {
    547       1.9   reinoud 		vidcvideo_blank(dc->dc_blanked);
    548       1.9   reinoud 		cleared |= WSDISPLAY_VIDEO_ONOFF;
    549      1.25     bjh21 	}
    550       1.1   reinoud 
    551       1.1   reinoud 	if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
    552       1.1   reinoud 		int x, y;
    553       1.9   reinoud 		x = dc->dc_cursor.cc_pos.x - dc->dc_cursor.cc_hot.x;
    554       1.9   reinoud 		y = dc->dc_cursor.cc_pos.y - dc->dc_cursor.cc_hot.y;
    555       1.1   reinoud 
    556       1.1   reinoud 		vidcvideo_updatecursor(x, y);
    557       1.9   reinoud 		cleared |= WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT;
    558      1.25     bjh21 	}
    559       1.1   reinoud 
    560       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    561       1.9   reinoud 		vidcvideo_enablecursor(dc->dc_curenb);
    562       1.9   reinoud 		cleared |= WSDISPLAY_CURSOR_DOCUR;
    563      1.25     bjh21 	}
    564       1.1   reinoud 
    565      1.33     chris 	dc->_internal_dc_changed ^= cleared;
    566      1.33     chris 
    567      1.33     chris 	if (dc->_internal_dc_changed == 0) {
    568      1.33     chris 		disable_irq(IRQ_FLYBACK);
    569      1.33     chris 	}
    570       1.9   reinoud 
    571      1.25     bjh21 	return 1;
    572       1.1   reinoud }
    573       1.1   reinoud 
    574       1.1   reinoud 
    575      1.33     chris static void vidcvideo_queue_dc_change(struct fb_devconfig *dc, int dc_change)
    576      1.33     chris {
    577      1.33     chris 	dc->_internal_dc_changed |= dc_change;
    578      1.33     chris 
    579  1.34.4.1      yamt 	if (curcpl() == IPL_HIGH) {
    580      1.33     chris 		/* running in ddb or without interrupts */
    581      1.33     chris 	    	dc->dc_writeback_delay = 1;
    582      1.33     chris 		flush_dc_changes_to_screen(dc);
    583      1.33     chris 	} else {
    584      1.33     chris 		/*
    585      1.33     chris 		 * running with interrupts so handle this in the next
    586      1.33     chris 		 * vsync
    587      1.33     chris 		 */
    588      1.33     chris 		if (dc->dc_ih) {
    589      1.33     chris 			enable_irq(IRQ_FLYBACK);
    590      1.33     chris 		}
    591      1.33     chris 	}
    592      1.33     chris }
    593      1.33     chris 
    594      1.33     chris 
    595  1.34.4.1      yamt static const u_char ri_col_data[6][6] = {
    596       1.1   reinoud 	{ 0,  0,  0,   0,  0,  0},	/*  1 bpp */
    597       1.1   reinoud 	{ 0,  0,  0,   0,  0,  0},	/*  2 bpp */
    598       1.1   reinoud 	{ 0,  0,  0,   0,  0,  0},	/*  4 bpp */
    599       1.1   reinoud 	{ 0,  0,  0,   0,  0,  0},	/*  8 bpp */
    600      1.12     bjh21 	{ 6,  5,  5,   0,  6, 11},	/* 16 bpp */
    601       1.1   reinoud 	{ 8,  8,  8,   0,  8, 16},	/* 32 bpp */
    602       1.1   reinoud };
    603       1.1   reinoud 
    604       1.1   reinoud static void
    605      1.25     bjh21 vidcvideo_colourmap_and_cursor_init(struct fb_devconfig *dc)
    606       1.1   reinoud {
    607      1.34     chris 	struct rasops_info *ri = &dc->dc_console.scr_ri;
    608  1.34.4.1      yamt 	const u_char *rgbdat;
    609      1.34     chris 	struct hwcmap256 *cm;
    610      1.34     chris 	const u_int8_t *p;
    611      1.34     chris 	int index;
    612       1.1   reinoud 
    613       1.1   reinoud 	/* Whatever we do later... just make sure we have a
    614       1.1   reinoud 	 * sane palette to start with
    615       1.1   reinoud 	 */
    616       1.1   reinoud 	vidcvideo_stdpalette();
    617       1.1   reinoud 
    618       1.1   reinoud 	/* set up rgb bit pattern values for rasops_init */
    619       1.1   reinoud 	rgbdat = ri_col_data[dc->dc_log2_depth];
    620       1.1   reinoud 	ri->ri_rnum = rgbdat[0];
    621       1.1   reinoud 	ri->ri_gnum = rgbdat[1];
    622       1.1   reinoud 	ri->ri_bnum = rgbdat[2];
    623       1.1   reinoud 	ri->ri_rpos = rgbdat[3];
    624       1.1   reinoud 	ri->ri_gpos = rgbdat[4];
    625       1.1   reinoud 	ri->ri_bpos = rgbdat[5];
    626      1.34     chris 
    627      1.34     chris 	/* initialise color map */
    628      1.34     chris 	cm = &dc->dc_cmap;
    629      1.34     chris 	p = rasops_cmap;
    630      1.34     chris 	for (index = 0; index < CMAP_SIZE; index++, p += 3) {
    631      1.34     chris 		cm->r[index] = p[0];
    632      1.34     chris 		cm->g[index] = p[1];
    633      1.34     chris 		cm->b[index] = p[2];
    634      1.34     chris 	}
    635      1.34     chris 	/* flush to hardware */
    636      1.34     chris 	vidcvideo_queue_dc_change(dc, WSDISPLAY_CMAP_DOLUT);
    637       1.1   reinoud }
    638       1.1   reinoud 
    639       1.1   reinoud 
    640       1.1   reinoud static int
    641      1.25     bjh21 get_cmap(struct vidcvideo_softc *sc, struct wsdisplay_cmap *p)
    642       1.1   reinoud {
    643       1.1   reinoud 	u_int index = p->index, count = p->count;
    644      1.20       chs 	int error;
    645       1.1   reinoud 
    646      1.14    itojun 	if (index >= CMAP_SIZE || count > CMAP_SIZE - index)
    647      1.25     bjh21 		return EINVAL;
    648       1.1   reinoud 
    649      1.20       chs 	error = copyout(&sc->sc_dc->dc_cmap.r[index], p->red, count);
    650      1.20       chs 	if (error)
    651      1.20       chs 		return error;
    652      1.20       chs 	error = copyout(&sc->sc_dc->dc_cmap.g[index], p->green, count);
    653      1.20       chs 	if (error)
    654      1.20       chs 		return error;
    655      1.20       chs 	error = copyout(&sc->sc_dc->dc_cmap.b[index], p->blue, count);
    656      1.20       chs 	return error;
    657       1.1   reinoud }
    658       1.1   reinoud 
    659       1.1   reinoud 
    660       1.1   reinoud static int
    661      1.25     bjh21 set_cmap(struct vidcvideo_softc *sc, struct wsdisplay_cmap *p)
    662       1.1   reinoud {
    663       1.9   reinoud     	struct fb_devconfig *dc = sc->sc_dc;
    664      1.20       chs 	struct hwcmap256 cmap;
    665       1.1   reinoud 	u_int index = p->index, count = p->count;
    666      1.20       chs 	int error;
    667       1.1   reinoud 
    668       1.1   reinoud 	if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
    669      1.25     bjh21 		return EINVAL;
    670       1.1   reinoud 
    671      1.20       chs 	error = copyin(p->red, &cmap.r[index], count);
    672      1.20       chs 	if (error)
    673      1.20       chs 		return error;
    674      1.20       chs 	error = copyin(p->green, &cmap.g[index], count);
    675      1.20       chs 	if (error)
    676      1.20       chs 		return error;
    677      1.20       chs 	error = copyin(p->blue, &cmap.b[index], count);
    678      1.20       chs 	if (error)
    679      1.20       chs 		return error;
    680      1.20       chs 	memcpy(&dc->dc_cmap.r[index], &cmap.r[index], count);
    681      1.20       chs 	memcpy(&dc->dc_cmap.g[index], &cmap.g[index], count);
    682      1.20       chs 	memcpy(&dc->dc_cmap.b[index], &cmap.b[index], count);
    683      1.33     chris 	vidcvideo_queue_dc_change(dc, WSDISPLAY_CMAP_DOLUT);
    684      1.25     bjh21 	return 0;
    685       1.1   reinoud }
    686       1.1   reinoud 
    687       1.1   reinoud 
    688       1.1   reinoud static int
    689      1.25     bjh21 set_cursor(struct vidcvideo_softc *sc, struct wsdisplay_cursor *p)
    690       1.1   reinoud {
    691       1.9   reinoud #define	cc (&dc->dc_cursor)
    692       1.9   reinoud     	struct fb_devconfig *dc = sc->sc_dc;
    693      1.20       chs 	u_int v, index = 0, count = 0, icount = 0;
    694      1.20       chs 	uint8_t r[2], g[2], b[2], image[512], mask[512];
    695      1.20       chs 	int error;
    696      1.19        he 
    697      1.19        he 	/* XXX gcc does not detect identical conditions */
    698      1.19        he 	index = count = icount = 0;
    699       1.1   reinoud 
    700       1.1   reinoud 	v = p->which;
    701       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    702       1.1   reinoud 		index = p->cmap.index;
    703       1.1   reinoud 		count = p->cmap.count;
    704      1.20       chs 		if (index >= CURSOR_MAX_COLOURS ||
    705      1.20       chs 		    (index + count) > CURSOR_MAX_COLOURS)
    706      1.25     bjh21 			return EINVAL;
    707      1.20       chs 		error = copyin(p->cmap.red, &r[index], count);
    708      1.20       chs 		if (error)
    709      1.20       chs 			return error;
    710      1.20       chs 		error = copyin(p->cmap.green, &g[index], count);
    711      1.20       chs 		if (error)
    712      1.20       chs 			return error;
    713      1.20       chs 		error = copyin(p->cmap.blue, &b[index], count);
    714      1.20       chs 		if (error)
    715      1.20       chs 			return error;
    716       1.1   reinoud 	}
    717       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    718      1.20       chs 		if (p->size.x > CURSOR_MAX_WIDTH ||
    719      1.20       chs 		    p->size.y > CURSOR_MAX_HEIGHT)
    720      1.25     bjh21 			return EINVAL;
    721       1.1   reinoud 		icount = sizeof(u_int32_t) * p->size.y;
    722      1.20       chs 		error = copyin(p->image, &image, icount);
    723      1.20       chs 		if (error)
    724      1.20       chs 			return error;
    725      1.20       chs 		error = copyin(p->mask, &mask, icount);
    726      1.20       chs 		if (error)
    727      1.20       chs 			return error;
    728       1.1   reinoud 	}
    729       1.1   reinoud 
    730       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOCUR)
    731       1.9   reinoud 		dc->dc_curenb = p->enable;
    732       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOPOS)
    733       1.1   reinoud 		set_curpos(sc, &p->pos);
    734       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOHOT)
    735       1.1   reinoud 		cc->cc_hot = p->hot;
    736       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    737      1.20       chs 		memcpy(&cc->cc_color[index], &r[index], count);
    738      1.20       chs 		memcpy(&cc->cc_color[index + 2], &g[index], count);
    739      1.20       chs 		memcpy(&cc->cc_color[index + 4], &b[index], count);
    740       1.1   reinoud 	}
    741       1.1   reinoud 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    742       1.1   reinoud 		cc->cc_size = p->size;
    743       1.1   reinoud 		memset(cc->cc_image, 0, sizeof cc->cc_image);
    744      1.20       chs 		memcpy(cc->cc_image, image, icount);
    745       1.1   reinoud 		memset(cc->cc_mask, 0, sizeof cc->cc_mask);
    746      1.20       chs 		memcpy(cc->cc_mask, mask, icount);
    747       1.1   reinoud 	}
    748      1.33     chris 	vidcvideo_queue_dc_change(dc, v);
    749       1.1   reinoud 
    750      1.25     bjh21 	return 0;
    751       1.1   reinoud #undef cc
    752       1.1   reinoud }
    753       1.1   reinoud 
    754       1.1   reinoud 
    755       1.1   reinoud static int
    756      1.25     bjh21 get_cursor(struct vidcvideo_softc *sc, struct wsdisplay_cursor *p)
    757       1.1   reinoud {
    758      1.25     bjh21 
    759      1.25     bjh21 	return EPASSTHROUGH; /* XXX */
    760       1.1   reinoud }
    761       1.1   reinoud 
    762       1.1   reinoud 
    763       1.1   reinoud static void
    764      1.25     bjh21 set_curpos(struct vidcvideo_softc *sc, struct wsdisplay_curpos *curpos)
    765       1.1   reinoud {
    766       1.1   reinoud 	struct fb_devconfig *dc = sc->sc_dc;
    767       1.1   reinoud 	int x = curpos->x, y = curpos->y;
    768       1.1   reinoud 
    769       1.1   reinoud 	if (y < 0)
    770       1.1   reinoud 		y = 0;
    771      1.34     chris 	else if (y > dc->dc_height)
    772      1.34     chris 		y = dc->dc_height;
    773       1.1   reinoud 	if (x < 0)
    774       1.1   reinoud 		x = 0;
    775      1.34     chris 	else if (x > dc->dc_width)
    776      1.34     chris 		x = dc->dc_width;
    777       1.9   reinoud 	dc->dc_cursor.cc_pos.x = x;
    778       1.9   reinoud 	dc->dc_cursor.cc_pos.y = y;
    779       1.1   reinoud }
    780       1.1   reinoud 
    781       1.1   reinoud 
    782      1.25     bjh21 static void vv_copyrows(void *id, int srcrow, int dstrow, int nrows)
    783       1.1   reinoud {
    784       1.1   reinoud 	struct rasops_info *ri = id;
    785       1.1   reinoud 	int height, offset, size;
    786       1.1   reinoud 	int scrollup, scrolldown;
    787       1.1   reinoud 	unsigned char *src, *dst;
    788      1.34     chris 	struct vcons_screen *scr = ri->ri_hw;
    789      1.34     chris 	struct fb_devconfig *dc = (struct fb_devconfig *) (scr->scr_cookie);
    790       1.1   reinoud 
    791       1.1   reinoud 	/* All movements are done in multiples of character heigths */
    792       1.1   reinoud 	height = ri->ri_font->fontheight * nrows;
    793       1.1   reinoud 	offset = (srcrow - dstrow) * ri->ri_yscale;
    794       1.1   reinoud 	size   = height * ri->ri_stride;
    795       1.1   reinoud 
    796       1.1   reinoud 	/* check if we are full screen scrolling */
    797       1.1   reinoud 	scrollup   = (srcrow + nrows >= ri->ri_rows);
    798       1.1   reinoud 	scrolldown = (dstrow + nrows >= ri->ri_rows);
    799       1.1   reinoud 
    800      1.34     chris #if 0
    801      1.25     bjh21 	if ((scrollup || scrolldown) &&
    802      1.25     bjh21 	    (videomemory.vidm_type == VIDEOMEM_TYPE_VRAM)) {
    803       1.1   reinoud 		ri->ri_bits = vidcvideo_hwscroll(offset);
    804       1.1   reinoud 		vidcvideo_progr_scroll();	/* sadistic ; shouldnt this be on vsync? */
    805       1.1   reinoud 
    806       1.1   reinoud 		/* wipe out remains of the screen if nessisary */
    807      1.25     bjh21 		if (ri->ri_emuheight != ri->ri_height)
    808      1.25     bjh21 			vv_eraserows(id, ri->ri_rows, 1, 0);
    809       1.1   reinoud 		return;
    810      1.25     bjh21 	}
    811      1.34     chris #endif
    812       1.1   reinoud 
    813      1.25     bjh21 	/*
    814      1.25     bjh21 	 * Else we just copy the area : we're braindead for now
    815      1.25     bjh21 	 * Note: we can't use hardware scrolling when the softc isnt
    816      1.25     bjh21 	 * known yet...  if its not known we dont have interrupts and
    817      1.25     bjh21 	 * we can't change the display address reliable other than in
    818      1.25     bjh21 	 * a Vsync
    819       1.1   reinoud 	 */
    820       1.1   reinoud 
    821       1.1   reinoud 	src = ri->ri_bits + srcrow * ri->ri_font->fontheight * ri->ri_stride;
    822       1.1   reinoud 	dst = ri->ri_bits + dstrow * ri->ri_font->fontheight * ri->ri_stride;
    823       1.1   reinoud 
    824      1.32     chris 	memmove(dst, src, size);
    825      1.33     chris 
    826      1.33     chris 	/* delay the write back operation of the screen area */
    827      1.33     chris 	dc->dc_writeback_delay = SCREEN_WRITE_BACK_DELAY;
    828      1.33     chris 	vidcvideo_queue_dc_change(dc, WSDISPLAY_WB_COUNTER);
    829       1.1   reinoud }
    830       1.1   reinoud 
    831       1.1   reinoud 
    832      1.25     bjh21 static void vv_eraserows(void *id, int startrow, int nrows, long attr)
    833       1.1   reinoud {
    834       1.1   reinoud 	struct rasops_info *ri = id;
    835       1.1   reinoud 	int height;
    836       1.1   reinoud 	unsigned char *src;
    837      1.34     chris 	struct vcons_screen *scr = ri->ri_hw;
    838      1.34     chris 	struct fb_devconfig *dc = (struct fb_devconfig *) (scr->scr_cookie);
    839       1.1   reinoud 
    840       1.1   reinoud 	/* we're braindead for now */
    841       1.1   reinoud 	height = ri->ri_font->fontheight * nrows * ri->ri_stride;
    842       1.1   reinoud 
    843       1.1   reinoud 	src = ri->ri_bits + startrow * ri->ri_font->fontheight * ri->ri_stride;
    844       1.1   reinoud 
    845      1.26     bjh21 	memset(src, 0, height);
    846      1.33     chris 
    847      1.33     chris 	/* delay the write back operation of the screen area */
    848      1.33     chris 	dc->dc_writeback_delay = SCREEN_WRITE_BACK_DELAY;
    849      1.33     chris 	vidcvideo_queue_dc_change(dc, WSDISPLAY_WB_COUNTER);
    850       1.6   reinoud }
    851       1.6   reinoud 
    852       1.6   reinoud 
    853      1.25     bjh21 static void vv_putchar(void *id, int row, int col, u_int uc, long attr)
    854       1.6   reinoud {
    855       1.6   reinoud     	struct rasops_info *ri = id;
    856      1.34     chris 	struct vcons_screen *scr = ri->ri_hw;
    857      1.34     chris 	struct fb_devconfig *dc = (struct fb_devconfig *) (scr->scr_cookie);
    858       1.9   reinoud 
    859      1.33     chris 	/* just delegate */
    860      1.33     chris 	dc->orig_ri_ops.putchar(id, row, col, uc, attr);
    861      1.33     chris 
    862       1.9   reinoud 	/* delay the write back operation of the screen area */
    863       1.9   reinoud 	dc->dc_writeback_delay = SCREEN_WRITE_BACK_DELAY;
    864      1.33     chris 	vidcvideo_queue_dc_change(dc, WSDISPLAY_WB_COUNTER);
    865       1.1   reinoud }
    866