Home | History | Annotate | Line # | Download | only in wscons
wsdisplay_vcons.c revision 1.26
      1  1.26  macallan /*	$NetBSD: wsdisplay_vcons.c,v 1.26 2011/05/25 06:13:29 macallan Exp $ */
      2   1.1  macallan 
      3   1.1  macallan /*-
      4   1.1  macallan  * Copyright (c) 2005, 2006 Michael Lorenz
      5   1.1  macallan  * All rights reserved.
      6   1.1  macallan  *
      7   1.1  macallan  * Redistribution and use in source and binary forms, with or without
      8   1.1  macallan  * modification, are permitted provided that the following conditions
      9   1.1  macallan  * are met:
     10   1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     11   1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     12   1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  macallan  *    documentation and/or other materials provided with the distribution.
     15   1.1  macallan  *
     16   1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17   1.1  macallan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18   1.1  macallan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19   1.1  macallan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20   1.1  macallan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21   1.1  macallan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22   1.1  macallan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23   1.1  macallan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24   1.1  macallan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25   1.1  macallan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26   1.1  macallan  * POSSIBILITY OF SUCH DAMAGE.
     27   1.1  macallan  */
     28   1.1  macallan 
     29   1.1  macallan #include <sys/cdefs.h>
     30  1.26  macallan __KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.26 2011/05/25 06:13:29 macallan Exp $");
     31   1.1  macallan 
     32   1.1  macallan #include <sys/param.h>
     33   1.1  macallan #include <sys/systm.h>
     34   1.1  macallan #include <sys/kernel.h>
     35   1.1  macallan #include <sys/buf.h>
     36   1.1  macallan #include <sys/device.h>
     37   1.1  macallan #include <sys/ioctl.h>
     38   1.1  macallan #include <sys/malloc.h>
     39   1.1  macallan #include <sys/mman.h>
     40   1.1  macallan #include <sys/tty.h>
     41   1.1  macallan #include <sys/conf.h>
     42   1.1  macallan #include <sys/proc.h>
     43   1.1  macallan #include <sys/kthread.h>
     44   1.1  macallan #include <sys/tprintf.h>
     45  1.19  macallan #include <sys/atomic.h>
     46   1.1  macallan 
     47   1.1  macallan #include <dev/wscons/wsdisplayvar.h>
     48   1.1  macallan #include <dev/wscons/wsconsio.h>
     49   1.1  macallan #include <dev/wsfont/wsfont.h>
     50   1.1  macallan #include <dev/rasops/rasops.h>
     51   1.1  macallan 
     52   1.1  macallan #include <dev/wscons/wsdisplay_vconsvar.h>
     53   1.1  macallan 
     54  1.14  macallan #include "opt_wsemul.h"
     55  1.14  macallan #include "opt_wsdisplay_compat.h"
     56  1.14  macallan #include "opt_vcons.h"
     57  1.14  macallan 
     58   1.1  macallan static void vcons_dummy_init_screen(void *, struct vcons_screen *, int,
     59   1.1  macallan 	    long *);
     60   1.1  macallan 
     61  1.10  christos static int  vcons_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     62   1.1  macallan static int  vcons_alloc_screen(void *, const struct wsscreen_descr *, void **,
     63   1.1  macallan 	    int *, int *, long *);
     64   1.1  macallan static void vcons_free_screen(void *, void *);
     65   1.1  macallan static int  vcons_show_screen(void *, void *, int, void (*)(void *, int, int),
     66   1.1  macallan 	    void *);
     67   1.1  macallan 
     68  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
     69  1.14  macallan static void vcons_scroll(void *, void *, int);
     70  1.14  macallan static void vcons_do_scroll(struct vcons_screen *);
     71  1.14  macallan #endif
     72  1.14  macallan 
     73  1.15     joerg static void vcons_do_switch(void *);
     74   1.1  macallan 
     75   1.1  macallan /* methods that work only on text buffers */
     76   1.1  macallan static void vcons_copycols_buffer(void *, int, int, int, int);
     77   1.1  macallan static void vcons_erasecols_buffer(void *, int, int, int, long);
     78   1.1  macallan static void vcons_copyrows_buffer(void *, int, int, int);
     79   1.1  macallan static void vcons_eraserows_buffer(void *, int, int, long);
     80   1.1  macallan static void vcons_putchar_buffer(void *, int, int, u_int, long);
     81   1.1  macallan 
     82   1.1  macallan /*
     83   1.1  macallan  * actual wrapper methods which call both the _buffer ones above and the
     84   1.1  macallan  * driver supplied ones to do the drawing
     85   1.1  macallan  */
     86   1.1  macallan static void vcons_copycols(void *, int, int, int, int);
     87   1.1  macallan static void vcons_erasecols(void *, int, int, int, long);
     88   1.1  macallan static void vcons_copyrows(void *, int, int, int);
     89   1.1  macallan static void vcons_eraserows(void *, int, int, long);
     90   1.1  macallan static void vcons_putchar(void *, int, int, u_int, long);
     91  1.25  macallan #ifdef VCONS_DRAW_INTR
     92  1.25  macallan static void vcons_putchar_cached(void *, int, int, u_int, long);
     93  1.25  macallan #endif
     94   1.1  macallan static void vcons_cursor(void *, int, int, int);
     95   1.1  macallan 
     96  1.17  macallan /*
     97  1.17  macallan  * methods that avoid framebuffer reads
     98  1.17  macallan  */
     99  1.17  macallan static void vcons_copycols_noread(void *, int, int, int, int);
    100  1.17  macallan static void vcons_copyrows_noread(void *, int, int, int);
    101  1.17  macallan 
    102  1.17  macallan 
    103  1.14  macallan /* support for reading/writing text buffers. For wsmoused */
    104   1.6      jmmv static int  vcons_putwschar(struct vcons_screen *, struct wsdisplay_char *);
    105   1.6      jmmv static int  vcons_getwschar(struct vcons_screen *, struct wsdisplay_char *);
    106   1.1  macallan 
    107   1.1  macallan static void vcons_lock(struct vcons_screen *);
    108   1.1  macallan static void vcons_unlock(struct vcons_screen *);
    109   1.1  macallan 
    110  1.20  jmcneill #ifdef VCONS_DRAW_INTR
    111  1.20  jmcneill static void vcons_intr(void *);
    112  1.22  jmcneill static void vcons_softintr(void *);
    113  1.21  jmcneill static void vcons_intr_enable(device_t);
    114  1.20  jmcneill #endif
    115   1.1  macallan 
    116   1.1  macallan int
    117   1.1  macallan vcons_init(struct vcons_data *vd, void *cookie, struct wsscreen_descr *def,
    118   1.1  macallan     struct wsdisplay_accessops *ao)
    119   1.1  macallan {
    120   1.2  macallan 
    121   1.2  macallan 	/* zero out everything so we can rely on untouched fields being 0 */
    122   1.3  macallan 	memset(vd, 0, sizeof(struct vcons_data));
    123   1.2  macallan 
    124   1.1  macallan 	vd->cookie = cookie;
    125   1.1  macallan 
    126   1.1  macallan 	vd->init_screen = vcons_dummy_init_screen;
    127   1.1  macallan 	vd->show_screen_cb = NULL;
    128   1.1  macallan 
    129   1.6      jmmv 	/* keep a copy of the accessops that we replace below with our
    130   1.6      jmmv 	 * own wrappers */
    131   1.6      jmmv 	vd->ioctl = ao->ioctl;
    132   1.6      jmmv 
    133   1.6      jmmv 	/* configure the accessops */
    134   1.6      jmmv 	ao->ioctl = vcons_ioctl;
    135   1.1  macallan 	ao->alloc_screen = vcons_alloc_screen;
    136   1.1  macallan 	ao->free_screen = vcons_free_screen;
    137   1.1  macallan 	ao->show_screen = vcons_show_screen;
    138  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    139  1.14  macallan 	ao->scroll = vcons_scroll;
    140  1.14  macallan #endif
    141   1.1  macallan 
    142   1.1  macallan 	LIST_INIT(&vd->screens);
    143   1.1  macallan 	vd->active = NULL;
    144   1.1  macallan 	vd->wanted = NULL;
    145   1.1  macallan 	vd->currenttype = def;
    146  1.11        ad 	callout_init(&vd->switch_callout, 0);
    147  1.15     joerg 	callout_setfunc(&vd->switch_callout, vcons_do_switch, vd);
    148  1.25  macallan #ifdef VCONS_DRAW_INTR
    149  1.25  macallan 	vd->cells = 0;
    150  1.25  macallan 	vd->attrs = NULL;
    151  1.25  macallan 	vd->chars = NULL;
    152  1.25  macallan 	vd->cursor_offset = -1;
    153  1.25  macallan #endif
    154   1.1  macallan 
    155   1.1  macallan 	/*
    156   1.1  macallan 	 * a lock to serialize access to the framebuffer.
    157   1.1  macallan 	 * when switching screens we need to make sure there's no rasops
    158   1.1  macallan 	 * operation in progress
    159   1.1  macallan 	 */
    160   1.1  macallan #ifdef DIAGNOSTIC
    161   1.1  macallan 	vd->switch_poll_count = 0;
    162   1.1  macallan #endif
    163  1.20  jmcneill #ifdef VCONS_DRAW_INTR
    164  1.22  jmcneill 	vd->intr_softint = softint_establish(SOFTINT_SERIAL,
    165  1.22  jmcneill 	    vcons_softintr, vd);
    166  1.20  jmcneill 	callout_init(&vd->intr, 0);
    167  1.20  jmcneill 	callout_setfunc(&vd->intr, vcons_intr, vd);
    168  1.23  jmcneill 	vd->intr_valid = 1;
    169  1.21  jmcneill 
    170  1.21  jmcneill 	/* XXX assume that the 'dev' arg is never dereferenced */
    171  1.21  jmcneill 	config_interrupts((device_t)vd, vcons_intr_enable);
    172  1.20  jmcneill #endif
    173   1.1  macallan 	return 0;
    174   1.1  macallan }
    175   1.1  macallan 
    176   1.1  macallan static void
    177   1.1  macallan vcons_lock(struct vcons_screen *scr)
    178   1.1  macallan {
    179   1.1  macallan #ifdef VCONS_PARANOIA
    180   1.1  macallan 	int s;
    181   1.1  macallan 
    182   1.1  macallan 	s = splhigh();
    183   1.1  macallan #endif
    184   1.1  macallan 	SCREEN_BUSY(scr);
    185   1.1  macallan #ifdef VCONS_PARANOIA
    186   1.1  macallan 	splx(s);
    187   1.1  macallan #endif
    188   1.1  macallan }
    189   1.1  macallan 
    190   1.1  macallan static void
    191   1.1  macallan vcons_unlock(struct vcons_screen *scr)
    192   1.1  macallan {
    193   1.1  macallan #ifdef VCONS_PARANOIA
    194   1.1  macallan 	int s;
    195   1.1  macallan 
    196   1.1  macallan 	s = splhigh();
    197   1.1  macallan #endif
    198   1.1  macallan 	SCREEN_IDLE(scr);
    199   1.1  macallan #ifdef VCONS_PARANOIA
    200   1.1  macallan 	splx(s);
    201   1.1  macallan #endif
    202   1.1  macallan }
    203   1.1  macallan 
    204   1.1  macallan static void
    205   1.9  christos vcons_dummy_init_screen(void *cookie,
    206   1.9  christos     struct vcons_screen *scr, int exists,
    207   1.9  christos     long *defattr)
    208   1.1  macallan {
    209   1.1  macallan 
    210   1.1  macallan 	/*
    211   1.1  macallan 	 * default init_screen() method.
    212   1.1  macallan 	 * Needs to be overwritten so we bitch and whine in case anyone ends
    213   1.1  macallan 	 * up in here.
    214   1.1  macallan 	 */
    215   1.1  macallan 	printf("vcons_init_screen: dummy function called. Your driver is "
    216   1.1  macallan 	       "supposed to supply a replacement for proper operation\n");
    217   1.1  macallan }
    218   1.1  macallan 
    219   1.1  macallan int
    220   1.1  macallan vcons_init_screen(struct vcons_data *vd, struct vcons_screen *scr,
    221   1.1  macallan     int existing, long *defattr)
    222   1.1  macallan {
    223   1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
    224   1.1  macallan 	int cnt, i;
    225  1.25  macallan #ifdef VCONS_DRAW_INTR
    226  1.25  macallan 	int size;
    227  1.25  macallan #endif
    228   1.1  macallan 
    229   1.1  macallan 	scr->scr_cookie = vd->cookie;
    230   1.4  jmcneill 	scr->scr_vd = scr->scr_origvd = vd;
    231  1.14  macallan 	scr->scr_busy = 0;
    232   1.2  macallan 
    233   1.1  macallan 	/*
    234   1.1  macallan 	 * call the driver-supplied init_screen function which is expected
    235   1.1  macallan 	 * to set up rasops_info, override cursor() and probably others
    236   1.1  macallan 	 */
    237   1.1  macallan 	vd->init_screen(vd->cookie, scr, existing, defattr);
    238   1.1  macallan 
    239   1.1  macallan 	/*
    240   1.1  macallan 	 * save the non virtual console aware rasops and replace them with
    241   1.1  macallan 	 * our wrappers
    242   1.1  macallan 	 */
    243   1.1  macallan 	vd->eraserows = ri->ri_ops.eraserows;
    244   1.1  macallan 	vd->erasecols = ri->ri_ops.erasecols;
    245   1.1  macallan 	vd->putchar   = ri->ri_ops.putchar;
    246   1.1  macallan 	vd->cursor    = ri->ri_ops.cursor;
    247   1.1  macallan 
    248  1.18  macallan 	if (scr->scr_flags & VCONS_NO_COPYCOLS) {
    249  1.19  macallan 		vd->copycols  = vcons_copycols_noread;
    250  1.18  macallan 	} else {
    251  1.19  macallan 		vd->copycols = ri->ri_ops.copycols;
    252  1.18  macallan 	}
    253  1.18  macallan 
    254  1.18  macallan 	if (scr->scr_flags & VCONS_NO_COPYROWS) {
    255  1.19  macallan 		vd->copyrows  = vcons_copyrows_noread;
    256  1.17  macallan 	} else {
    257  1.19  macallan 		vd->copyrows = ri->ri_ops.copyrows;
    258  1.17  macallan 	}
    259  1.17  macallan 
    260  1.19  macallan 	ri->ri_ops.eraserows = vcons_eraserows;
    261  1.19  macallan 	ri->ri_ops.erasecols = vcons_erasecols;
    262  1.19  macallan 	ri->ri_ops.putchar   = vcons_putchar;
    263  1.19  macallan 	ri->ri_ops.cursor    = vcons_cursor;
    264  1.19  macallan 	ri->ri_ops.copycols  = vcons_copycols;
    265  1.19  macallan 	ri->ri_ops.copyrows  = vcons_copyrows;
    266  1.19  macallan 
    267  1.19  macallan 
    268   1.1  macallan 	ri->ri_hw = scr;
    269   1.1  macallan 
    270   1.1  macallan 	/*
    271   1.1  macallan 	 * we allocate both chars and attributes in one chunk, attributes first
    272   1.1  macallan 	 * because they have the (potentially) bigger alignment
    273   1.1  macallan 	 */
    274  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    275  1.14  macallan 	cnt = (ri->ri_rows + WSDISPLAY_SCROLLBACK_LINES) * ri->ri_cols;
    276  1.14  macallan 	scr->scr_lines_in_buffer = WSDISPLAY_SCROLLBACK_LINES;
    277  1.14  macallan 	scr->scr_current_line = 0;
    278  1.14  macallan 	scr->scr_line_wanted = 0;
    279  1.14  macallan 	scr->scr_offset_to_zero = ri->ri_cols * WSDISPLAY_SCROLLBACK_LINES;
    280  1.14  macallan 	scr->scr_current_offset = scr->scr_offset_to_zero;
    281  1.14  macallan #else
    282   1.1  macallan 	cnt = ri->ri_rows * ri->ri_cols;
    283  1.14  macallan #endif
    284   1.1  macallan 	scr->scr_attrs = (long *)malloc(cnt * (sizeof(long) +
    285   1.1  macallan 	    sizeof(uint16_t)), M_DEVBUF, M_WAITOK);
    286   1.1  macallan 	if (scr->scr_attrs == NULL)
    287   1.1  macallan 		return ENOMEM;
    288   1.1  macallan 
    289   1.1  macallan 	scr->scr_chars = (uint16_t *)&scr->scr_attrs[cnt];
    290   1.1  macallan 
    291   1.1  macallan 	ri->ri_ops.allocattr(ri, WS_DEFAULT_FG, WS_DEFAULT_BG, 0, defattr);
    292   1.1  macallan 	scr->scr_defattr = *defattr;
    293   1.1  macallan 
    294   1.1  macallan 	/*
    295   1.1  macallan 	 * fill the attribute buffer with *defattr, chars with 0x20
    296   1.1  macallan 	 * since we don't know if the driver tries to mimic firmware output or
    297   1.1  macallan 	 * reset everything we do nothing to VRAM here, any driver that feels
    298   1.1  macallan 	 * the need to clear screen or something will have to do it on its own
    299   1.1  macallan 	 * Additional screens will start out in the background anyway so
    300   1.1  macallan 	 * cleaning or not only really affects the initial console screen
    301   1.1  macallan 	 */
    302   1.1  macallan 	for (i = 0; i < cnt; i++) {
    303   1.1  macallan 		scr->scr_attrs[i] = *defattr;
    304   1.1  macallan 		scr->scr_chars[i] = 0x20;
    305   1.1  macallan 	}
    306   1.1  macallan 
    307  1.25  macallan #ifdef VCONS_DRAW_INTR
    308  1.25  macallan 	size = ri->ri_cols * ri->ri_rows;
    309  1.25  macallan 	if (size > vd->cells) {
    310  1.25  macallan 		if (vd->chars != NULL) free(vd->chars, M_DEVBUF);
    311  1.25  macallan 		if (vd->attrs != NULL) free(vd->attrs, M_DEVBUF);
    312  1.25  macallan 		vd->cells = size;
    313  1.25  macallan 		vd->chars = malloc(size * sizeof(uint16_t), M_DEVBUF, M_WAITOK);
    314  1.25  macallan 		vd->attrs = malloc(size * sizeof(long), M_DEVBUF, M_WAITOK);
    315  1.25  macallan 		vcons_invalidate_cache(vd);
    316  1.25  macallan 	}
    317  1.25  macallan #endif
    318  1.25  macallan 
    319   1.2  macallan 	if(vd->active == NULL) {
    320   1.2  macallan 		vd->active = scr;
    321   1.2  macallan 		SCREEN_VISIBLE(scr);
    322   1.2  macallan 	}
    323   1.2  macallan 
    324   1.1  macallan 	if (existing) {
    325   1.2  macallan 		SCREEN_VISIBLE(scr);
    326   1.2  macallan 		vd->active = scr;
    327   1.1  macallan 	} else {
    328   1.2  macallan 		SCREEN_INVISIBLE(scr);
    329   1.1  macallan 	}
    330   1.1  macallan 
    331   1.1  macallan 	LIST_INSERT_HEAD(&vd->screens, scr, next);
    332   1.1  macallan 	return 0;
    333   1.1  macallan }
    334   1.1  macallan 
    335   1.1  macallan static void
    336  1.15     joerg vcons_do_switch(void *arg)
    337   1.1  macallan {
    338  1.15     joerg 	struct vcons_data *vd = arg;
    339   1.1  macallan 	struct vcons_screen *scr, *oldscr;
    340   1.1  macallan 
    341   1.1  macallan 	scr = vd->wanted;
    342   1.1  macallan 	if (!scr) {
    343   1.1  macallan 		printf("vcons_switch_screen: disappeared\n");
    344   1.1  macallan 		vd->switch_cb(vd->switch_cb_arg, EIO, 0);
    345   1.1  macallan 		return;
    346   1.1  macallan 	}
    347   1.1  macallan 	oldscr = vd->active; /* can be NULL! */
    348   1.1  macallan 
    349   1.1  macallan 	/*
    350   1.1  macallan 	 * if there's an old, visible screen we mark it invisible and wait
    351   1.1  macallan 	 * until it's not busy so we can safely switch
    352   1.1  macallan 	 */
    353   1.1  macallan 	if (oldscr != NULL) {
    354   1.1  macallan 		SCREEN_INVISIBLE(oldscr);
    355   1.1  macallan 		if (SCREEN_IS_BUSY(oldscr)) {
    356  1.15     joerg 			callout_schedule(&vd->switch_callout, 1);
    357   1.1  macallan #ifdef DIAGNOSTIC
    358   1.1  macallan 			/* bitch if we wait too long */
    359   1.1  macallan 			vd->switch_poll_count++;
    360   1.1  macallan 			if (vd->switch_poll_count > 100) {
    361   1.1  macallan 				panic("vcons: screen still busy");
    362   1.1  macallan 			}
    363   1.1  macallan #endif
    364   1.1  macallan 			return;
    365   1.1  macallan 		}
    366   1.1  macallan 		/* invisible screen -> no visible cursor image */
    367   1.1  macallan 		oldscr->scr_ri.ri_flg &= ~RI_CURSOR;
    368   1.1  macallan #ifdef DIAGNOSTIC
    369   1.1  macallan 		vd->switch_poll_count = 0;
    370   1.1  macallan #endif
    371   1.1  macallan 	}
    372   1.1  macallan 
    373   1.1  macallan 	if (scr == oldscr)
    374   1.1  macallan 		return;
    375   1.1  macallan 
    376   1.1  macallan #ifdef DIAGNOSTIC
    377   1.1  macallan 	if (SCREEN_IS_VISIBLE(scr))
    378  1.14  macallan 		printf("vcons_switch_screen: already active");
    379   1.1  macallan #endif
    380   1.1  macallan 
    381   1.1  macallan #ifdef notyet
    382   1.1  macallan 	if (vd->currenttype != type) {
    383   1.1  macallan 		vcons_set_screentype(vd, type);
    384   1.1  macallan 		vd->currenttype = type;
    385   1.1  macallan 	}
    386   1.1  macallan #endif
    387   1.1  macallan 
    388   1.1  macallan 	SCREEN_VISIBLE(scr);
    389   1.1  macallan 	vd->active = scr;
    390   1.1  macallan 	vd->wanted = NULL;
    391   1.1  macallan 
    392   1.1  macallan 	if (vd->show_screen_cb != NULL)
    393   1.1  macallan 		vd->show_screen_cb(scr);
    394   1.1  macallan 
    395   1.1  macallan 	if ((scr->scr_flags & VCONS_NO_REDRAW) == 0)
    396   1.1  macallan 		vcons_redraw_screen(scr);
    397   1.1  macallan 
    398   1.1  macallan 	if (vd->switch_cb)
    399   1.1  macallan 		vd->switch_cb(vd->switch_cb_arg, 0, 0);
    400   1.1  macallan }
    401   1.1  macallan 
    402   1.1  macallan void
    403   1.1  macallan vcons_redraw_screen(struct vcons_screen *scr)
    404   1.1  macallan {
    405   1.1  macallan 	uint16_t *charptr = scr->scr_chars;
    406   1.1  macallan 	long *attrptr = scr->scr_attrs;
    407   1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
    408  1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
    409  1.25  macallan 	int i, j, offset, boffset = 0;
    410   1.1  macallan 
    411   1.1  macallan 	vcons_lock(scr);
    412   1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    413   1.1  macallan 
    414   1.1  macallan 		/*
    415   1.1  macallan 		 * only clear the screen when RI_FULLCLEAR is set since we're
    416   1.1  macallan 		 * going to overwrite every single character cell anyway
    417   1.1  macallan 		 */
    418   1.1  macallan 		if (ri->ri_flg & RI_FULLCLEAR) {
    419  1.25  macallan 			vd->eraserows(ri, 0, ri->ri_rows,
    420   1.1  macallan 			    scr->scr_defattr);
    421   1.1  macallan 		}
    422   1.1  macallan 
    423   1.1  macallan 		/* redraw the screen */
    424  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    425  1.14  macallan 		offset = scr->scr_current_offset;
    426  1.14  macallan #else
    427   1.1  macallan 		offset = 0;
    428  1.14  macallan #endif
    429   1.1  macallan 		for (i = 0; i < ri->ri_rows; i++) {
    430   1.1  macallan 			for (j = 0; j < ri->ri_cols; j++) {
    431   1.1  macallan 				/*
    432   1.1  macallan 				 * no need to use the wrapper function - we
    433   1.1  macallan 				 * don't change any characters or attributes
    434   1.1  macallan 				 * and we already made sure the screen we're
    435   1.1  macallan 				 * working on is visible
    436   1.1  macallan 				 */
    437  1.25  macallan 				vd->putchar(ri, i, j,
    438   1.1  macallan 				    charptr[offset], attrptr[offset]);
    439  1.25  macallan #ifdef VCONS_DRAW_INTR
    440  1.25  macallan 				vd->chars[boffset] = charptr[offset];
    441  1.25  macallan 				vd->attrs[boffset] = attrptr[offset];
    442  1.25  macallan #endif
    443  1.25  macallan 				offset++;
    444  1.25  macallan 				boffset++;
    445  1.25  macallan 			}
    446  1.25  macallan 		}
    447  1.25  macallan 		ri->ri_flg &= ~RI_CURSOR;
    448  1.25  macallan 		scr->scr_vd->cursor(ri, 1, ri->ri_crow, ri->ri_ccol);
    449  1.25  macallan #ifdef VCONS_DRAW_INTR
    450  1.25  macallan 		vd->cursor_offset = ri->ri_crow * ri->ri_cols + ri->ri_ccol;
    451  1.25  macallan #endif
    452  1.25  macallan 	}
    453  1.25  macallan 	vcons_unlock(scr);
    454  1.25  macallan }
    455  1.25  macallan 
    456  1.25  macallan #ifdef VCONS_DRAW_INTR
    457  1.25  macallan void
    458  1.25  macallan vcons_update_screen(struct vcons_screen *scr)
    459  1.25  macallan {
    460  1.25  macallan 	uint16_t *charptr = scr->scr_chars;
    461  1.25  macallan 	long *attrptr = scr->scr_attrs;
    462  1.25  macallan 	struct rasops_info *ri = &scr->scr_ri;
    463  1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
    464  1.25  macallan 	int i, j, offset, boffset = 0;
    465  1.25  macallan 
    466  1.25  macallan 	vcons_lock(scr);
    467  1.25  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    468  1.25  macallan 
    469  1.25  macallan 		/* redraw the screen */
    470  1.25  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    471  1.25  macallan 		offset = scr->scr_current_offset;
    472  1.25  macallan #else
    473  1.25  macallan 		offset = 0;
    474  1.25  macallan #endif
    475  1.25  macallan 		/*
    476  1.25  macallan 		 * we mark the character cell occupied by the cursor as dirty
    477  1.25  macallan 		 * so we don't have to deal with it
    478  1.25  macallan 		 * notice that this isn't necessarily the position where rasops
    479  1.25  macallan 		 * thinks it is, just where we drew it the last time
    480  1.25  macallan 		 */
    481  1.25  macallan 		if (vd->cursor_offset >= 0)
    482  1.25  macallan 			vd->attrs[vd->cursor_offset] = 0xffffffff;
    483  1.25  macallan 
    484  1.25  macallan 		for (i = 0; i < ri->ri_rows; i++) {
    485  1.25  macallan 			for (j = 0; j < ri->ri_cols; j++) {
    486  1.25  macallan 				/*
    487  1.25  macallan 				 * no need to use the wrapper function - we
    488  1.25  macallan 				 * don't change any characters or attributes
    489  1.25  macallan 				 * and we already made sure the screen we're
    490  1.25  macallan 				 * working on is visible
    491  1.25  macallan 				 */
    492  1.25  macallan 				if ((vd->chars[boffset] != charptr[offset]) ||
    493  1.25  macallan 				    (vd->attrs[boffset] != attrptr[offset])) {
    494  1.25  macallan 					vd->putchar(ri, i, j,
    495  1.25  macallan 				 	   charptr[offset], attrptr[offset]);
    496  1.25  macallan 					vd->chars[boffset] = charptr[offset];
    497  1.25  macallan 					vd->attrs[boffset] = attrptr[offset];
    498  1.25  macallan 				}
    499   1.1  macallan 				offset++;
    500  1.25  macallan 				boffset++;
    501   1.1  macallan 			}
    502   1.1  macallan 		}
    503   1.1  macallan 		ri->ri_flg &= ~RI_CURSOR;
    504   1.1  macallan 		scr->scr_vd->cursor(ri, 1, ri->ri_crow, ri->ri_ccol);
    505  1.25  macallan 		vd->cursor_offset = ri->ri_crow * ri->ri_cols + ri->ri_ccol;
    506   1.1  macallan 	}
    507   1.1  macallan 	vcons_unlock(scr);
    508   1.1  macallan }
    509  1.25  macallan #endif
    510   1.1  macallan 
    511   1.1  macallan static int
    512  1.10  christos vcons_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    513   1.6      jmmv 	struct lwp *l)
    514   1.6      jmmv {
    515   1.6      jmmv 	struct vcons_data *vd = v;
    516   1.6      jmmv 	int error;
    517   1.6      jmmv 
    518   1.6      jmmv 	switch (cmd) {
    519   1.6      jmmv 	case WSDISPLAYIO_GETWSCHAR:
    520   1.6      jmmv 		error = vcons_getwschar((struct vcons_screen *)vs,
    521   1.6      jmmv 			(struct wsdisplay_char *)data);
    522   1.6      jmmv 		break;
    523   1.6      jmmv 
    524   1.6      jmmv 	case WSDISPLAYIO_PUTWSCHAR:
    525   1.6      jmmv 		error = vcons_putwschar((struct vcons_screen *)vs,
    526   1.6      jmmv 			(struct wsdisplay_char *)data);
    527   1.6      jmmv 		break;
    528   1.6      jmmv 
    529   1.6      jmmv 	default:
    530   1.6      jmmv 		if (vd->ioctl != NULL)
    531   1.6      jmmv 			error = (*vd->ioctl)(v, vs, cmd, data, flag, l);
    532   1.6      jmmv 		else
    533   1.6      jmmv 			error = EPASSTHROUGH;
    534   1.6      jmmv 	}
    535   1.6      jmmv 
    536   1.6      jmmv 	return error;
    537   1.6      jmmv }
    538   1.6      jmmv 
    539   1.6      jmmv static int
    540   1.1  macallan vcons_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    541   1.1  macallan     int *curxp, int *curyp, long *defattrp)
    542   1.1  macallan {
    543   1.1  macallan 	struct vcons_data *vd = v;
    544   1.1  macallan 	struct vcons_screen *scr;
    545   1.1  macallan 	int ret;
    546   1.1  macallan 
    547   1.1  macallan 	scr = malloc(sizeof(struct vcons_screen), M_DEVBUF, M_WAITOK | M_ZERO);
    548   1.1  macallan 	if (scr == NULL)
    549   1.1  macallan 		return ENOMEM;
    550   1.1  macallan 
    551   1.1  macallan 	scr->scr_flags = 0;
    552   1.2  macallan 	scr->scr_status = 0;
    553   1.2  macallan 	scr->scr_busy = 0;
    554   1.1  macallan 	scr->scr_type = type;
    555   1.1  macallan 
    556   1.1  macallan 	ret = vcons_init_screen(vd, scr, 0, defattrp);
    557   1.1  macallan 	if (ret != 0) {
    558   1.1  macallan 		free(scr, M_DEVBUF);
    559   1.1  macallan 		return ret;
    560   1.1  macallan 	}
    561   1.1  macallan 
    562   1.1  macallan 	if (vd->active == NULL) {
    563   1.1  macallan 		SCREEN_VISIBLE(scr);
    564   1.1  macallan 		vd->active = scr;
    565   1.1  macallan 		vd->currenttype = type;
    566   1.1  macallan 	}
    567   1.1  macallan 
    568   1.1  macallan 	*cookiep = scr;
    569   1.1  macallan 	*curxp = scr->scr_ri.ri_ccol;
    570   1.1  macallan 	*curyp = scr->scr_ri.ri_crow;
    571   1.1  macallan 	return 0;
    572   1.1  macallan }
    573   1.1  macallan 
    574   1.1  macallan static void
    575   1.1  macallan vcons_free_screen(void *v, void *cookie)
    576   1.1  macallan {
    577   1.1  macallan 	struct vcons_data *vd = v;
    578   1.1  macallan 	struct vcons_screen *scr = cookie;
    579   1.1  macallan 
    580   1.1  macallan 	vcons_lock(scr);
    581   1.1  macallan 	/* there should be no rasops activity here */
    582   1.1  macallan 
    583   1.1  macallan 	LIST_REMOVE(scr, next);
    584   1.1  macallan 
    585   1.1  macallan 	if ((scr->scr_flags & VCONS_SCREEN_IS_STATIC) == 0) {
    586   1.1  macallan 		free(scr->scr_attrs, M_DEVBUF);
    587   1.1  macallan 		free(scr, M_DEVBUF);
    588   1.1  macallan 	} else {
    589   1.1  macallan 		/*
    590   1.1  macallan 		 * maybe we should just restore the old rasops_info methods
    591   1.1  macallan 		 * and free the character/attribute buffer here?
    592   1.1  macallan 		 */
    593   1.1  macallan #ifdef VCONS_DEBUG
    594   1.1  macallan 		panic("vcons_free_screen: console");
    595   1.1  macallan #else
    596   1.1  macallan 		printf("vcons_free_screen: console\n");
    597   1.1  macallan #endif
    598   1.1  macallan 	}
    599   1.1  macallan 
    600   1.1  macallan 	if (vd->active == scr)
    601   1.1  macallan 		vd->active = NULL;
    602   1.1  macallan }
    603   1.1  macallan 
    604   1.1  macallan static int
    605   1.9  christos vcons_show_screen(void *v, void *cookie, int waitok,
    606   1.1  macallan     void (*cb)(void *, int, int), void *cb_arg)
    607   1.1  macallan {
    608   1.1  macallan 	struct vcons_data *vd = v;
    609   1.1  macallan 	struct vcons_screen *scr;
    610   1.1  macallan 
    611   1.1  macallan 	scr = cookie;
    612   1.1  macallan 	if (scr == vd->active)
    613   1.1  macallan 		return 0;
    614   1.1  macallan 
    615   1.1  macallan 	vd->wanted = scr;
    616   1.1  macallan 	vd->switch_cb = cb;
    617   1.1  macallan 	vd->switch_cb_arg = cb_arg;
    618   1.1  macallan 	if (cb) {
    619  1.15     joerg 		callout_schedule(&vd->switch_callout, 0);
    620   1.1  macallan 		return EAGAIN;
    621   1.1  macallan 	}
    622   1.1  macallan 
    623   1.1  macallan 	vcons_do_switch(vd);
    624   1.1  macallan 	return 0;
    625   1.1  macallan }
    626   1.1  macallan 
    627   1.1  macallan /* wrappers for rasops_info methods */
    628   1.1  macallan 
    629   1.1  macallan static void
    630   1.1  macallan vcons_copycols_buffer(void *cookie, int row, int srccol, int dstcol, int ncols)
    631   1.1  macallan {
    632   1.1  macallan 	struct rasops_info *ri = cookie;
    633   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    634   1.1  macallan 	int from = srccol + row * ri->ri_cols;
    635   1.1  macallan 	int to = dstcol + row * ri->ri_cols;
    636   1.1  macallan 
    637  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    638  1.14  macallan 	int offset;
    639  1.14  macallan 	offset = scr->scr_offset_to_zero;
    640  1.14  macallan 
    641  1.14  macallan 	memmove(&scr->scr_attrs[offset + to], &scr->scr_attrs[offset + from],
    642  1.14  macallan 	    ncols * sizeof(long));
    643  1.14  macallan 	memmove(&scr->scr_chars[offset + to], &scr->scr_chars[offset + from],
    644  1.14  macallan 	    ncols * sizeof(uint16_t));
    645  1.14  macallan #else
    646   1.1  macallan 	memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
    647   1.1  macallan 	    ncols * sizeof(long));
    648   1.1  macallan 	memmove(&scr->scr_chars[to], &scr->scr_chars[from],
    649   1.1  macallan 	    ncols * sizeof(uint16_t));
    650  1.14  macallan #endif
    651  1.20  jmcneill 
    652  1.20  jmcneill #ifdef VCONS_DRAW_INTR
    653  1.22  jmcneill 	atomic_inc_uint(&scr->scr_dirty);
    654  1.20  jmcneill #endif
    655   1.1  macallan }
    656   1.1  macallan 
    657   1.1  macallan static void
    658   1.1  macallan vcons_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
    659   1.1  macallan {
    660   1.1  macallan 	struct rasops_info *ri = cookie;
    661   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    662   1.1  macallan 
    663   1.1  macallan 	vcons_copycols_buffer(cookie, row, srccol, dstcol, ncols);
    664   1.1  macallan 
    665  1.21  jmcneill #if defined(VCONS_DRAW_INTR)
    666  1.21  jmcneill 	if (scr->scr_vd->use_intr)
    667  1.21  jmcneill 		return;
    668  1.21  jmcneill #endif
    669  1.21  jmcneill 
    670   1.1  macallan 	vcons_lock(scr);
    671   1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    672  1.26  macallan 		scr->scr_vd->copycols(cookie, row, srccol, dstcol, ncols);
    673   1.1  macallan 	}
    674   1.1  macallan 	vcons_unlock(scr);
    675   1.1  macallan }
    676   1.1  macallan 
    677   1.1  macallan static void
    678  1.17  macallan vcons_copycols_noread(void *cookie, int row, int srccol, int dstcol, int ncols)
    679  1.17  macallan {
    680  1.17  macallan 	struct rasops_info *ri = cookie;
    681  1.17  macallan 	struct vcons_screen *scr = ri->ri_hw;
    682  1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
    683  1.17  macallan 
    684  1.17  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    685  1.25  macallan 		int pos, c, offset, ppos;
    686  1.17  macallan 
    687  1.17  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    688  1.17  macallan 		offset = scr->scr_current_offset;
    689  1.17  macallan #else
    690  1.17  macallan 		offset = 0;
    691  1.17  macallan #endif
    692  1.25  macallan 		ppos = ri->ri_cols * row + dstcol;
    693  1.25  macallan 		pos = ppos + offset;
    694  1.17  macallan 		for (c = dstcol; c < (dstcol + ncols); c++) {
    695  1.25  macallan #ifdef VCONS_DRAW_INTR
    696  1.25  macallan 			if ((scr->scr_chars[pos] != vd->chars[ppos]) ||
    697  1.25  macallan 			    (scr->scr_attrs[pos] != vd->attrs[ppos])) {
    698  1.25  macallan 				vd->putchar(cookie, row, c,
    699  1.25  macallan 				   scr->scr_chars[pos], scr->scr_attrs[pos]);
    700  1.25  macallan 				vd->chars[ppos] = scr->scr_chars[pos];
    701  1.25  macallan 				vd->attrs[ppos] = scr->scr_attrs[pos];
    702  1.25  macallan 			}
    703  1.25  macallan #else
    704  1.25  macallan 			vd->putchar(cookie, row, c, scr->scr_chars[pos],
    705  1.25  macallan 			    scr->scr_attrs[pos]);
    706  1.25  macallan #endif
    707  1.17  macallan 			pos++;
    708  1.25  macallan 			ppos++;
    709  1.17  macallan 		}
    710  1.17  macallan 	}
    711  1.17  macallan }
    712  1.17  macallan 
    713  1.17  macallan static void
    714   1.1  macallan vcons_erasecols_buffer(void *cookie, int row, int startcol, int ncols, long fillattr)
    715   1.1  macallan {
    716   1.1  macallan 	struct rasops_info *ri = cookie;
    717   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    718   1.1  macallan 	int start = startcol + row * ri->ri_cols;
    719   1.1  macallan 	int end = start + ncols, i;
    720   1.1  macallan 
    721  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    722  1.14  macallan 	int offset;
    723  1.14  macallan 	offset = scr->scr_offset_to_zero;
    724  1.14  macallan 
    725  1.14  macallan 	for (i = start; i < end; i++) {
    726  1.14  macallan 		scr->scr_attrs[offset + i] = fillattr;
    727  1.14  macallan 		scr->scr_chars[offset + i] = 0x20;
    728  1.14  macallan 	}
    729  1.14  macallan #else
    730   1.1  macallan 	for (i = start; i < end; i++) {
    731   1.1  macallan 		scr->scr_attrs[i] = fillattr;
    732   1.1  macallan 		scr->scr_chars[i] = 0x20;
    733   1.1  macallan 	}
    734  1.14  macallan #endif
    735  1.20  jmcneill 
    736  1.20  jmcneill #ifdef VCONS_DRAW_INTR
    737  1.22  jmcneill 	atomic_inc_uint(&scr->scr_dirty);
    738  1.20  jmcneill #endif
    739   1.1  macallan }
    740   1.1  macallan 
    741  1.25  macallan #ifdef VCONS_DRAW_INTR
    742  1.25  macallan static void
    743  1.25  macallan vcons_erasecols_cached(void *cookie, int row, int startcol, int ncols, long fillattr)
    744  1.25  macallan {
    745  1.25  macallan 	struct rasops_info *ri = cookie;
    746  1.25  macallan 	struct vcons_screen *scr = ri->ri_hw;
    747  1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
    748  1.25  macallan 	int i, pos = row * ri->ri_cols + startcol;
    749  1.25  macallan 
    750  1.25  macallan 	for (i = pos; i < ncols; i++) {
    751  1.25  macallan 		vd->chars[i] = 0x20;
    752  1.25  macallan 		vd->attrs[i] = fillattr;
    753  1.25  macallan 	}
    754  1.25  macallan 	vd->erasecols(cookie, row, startcol, ncols, fillattr);
    755  1.25  macallan }
    756  1.25  macallan #endif
    757  1.25  macallan 
    758   1.1  macallan static void
    759   1.1  macallan vcons_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
    760   1.1  macallan {
    761   1.1  macallan 	struct rasops_info *ri = cookie;
    762   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    763   1.1  macallan 
    764   1.1  macallan 	vcons_erasecols_buffer(cookie, row, startcol, ncols, fillattr);
    765   1.1  macallan 
    766  1.21  jmcneill #if defined(VCONS_DRAW_INTR)
    767  1.21  jmcneill 	if (scr->scr_vd->use_intr)
    768  1.21  jmcneill 		return;
    769  1.21  jmcneill #endif
    770  1.21  jmcneill 
    771   1.1  macallan 	vcons_lock(scr);
    772   1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    773  1.25  macallan #ifdef VCONS_DRAW_INTR
    774  1.25  macallan 			vcons_erasecols_cached(cookie, row, startcol, ncols,
    775  1.19  macallan 			    fillattr);
    776  1.25  macallan #else
    777  1.25  macallan 		scr->scr_vd->erasecols(cookie, row, startcol, ncols, fillattr);
    778  1.25  macallan #endif
    779   1.1  macallan 	}
    780   1.1  macallan 	vcons_unlock(scr);
    781   1.1  macallan }
    782   1.1  macallan 
    783   1.1  macallan static void
    784   1.1  macallan vcons_copyrows_buffer(void *cookie, int srcrow, int dstrow, int nrows)
    785   1.1  macallan {
    786   1.1  macallan 	struct rasops_info *ri = cookie;
    787   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    788   1.1  macallan 	int from, to, len;
    789   1.1  macallan 
    790  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    791  1.14  macallan 	int offset;
    792  1.14  macallan 	offset = scr->scr_offset_to_zero;
    793  1.14  macallan 
    794  1.14  macallan 	/* do we need to scroll the back buffer? */
    795  1.14  macallan 	if (dstrow == 0) {
    796  1.14  macallan 		from = ri->ri_cols * srcrow;
    797  1.14  macallan 		to = ri->ri_cols * dstrow;
    798  1.14  macallan 
    799  1.14  macallan 		memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
    800  1.14  macallan 		    scr->scr_offset_to_zero * sizeof(long));
    801  1.14  macallan 		memmove(&scr->scr_chars[to], &scr->scr_chars[from],
    802  1.14  macallan 		    scr->scr_offset_to_zero * sizeof(uint16_t));
    803  1.14  macallan 	}
    804  1.14  macallan 	from = ri->ri_cols * srcrow + offset;
    805  1.14  macallan 	to = ri->ri_cols * dstrow + offset;
    806  1.14  macallan 	len = ri->ri_cols * nrows;
    807  1.14  macallan 
    808  1.14  macallan #else
    809   1.1  macallan 	from = ri->ri_cols * srcrow;
    810   1.1  macallan 	to = ri->ri_cols * dstrow;
    811   1.1  macallan 	len = ri->ri_cols * nrows;
    812  1.14  macallan #endif
    813   1.1  macallan 	memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
    814   1.1  macallan 	    len * sizeof(long));
    815   1.1  macallan 	memmove(&scr->scr_chars[to], &scr->scr_chars[from],
    816   1.1  macallan 	    len * sizeof(uint16_t));
    817  1.20  jmcneill 
    818  1.20  jmcneill #ifdef VCONS_DRAW_INTR
    819  1.22  jmcneill 	atomic_inc_uint(&scr->scr_dirty);
    820  1.20  jmcneill #endif
    821   1.1  macallan }
    822   1.1  macallan 
    823   1.1  macallan static void
    824   1.1  macallan vcons_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
    825   1.1  macallan {
    826   1.1  macallan 	struct rasops_info *ri = cookie;
    827   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    828   1.1  macallan 
    829   1.1  macallan 	vcons_copyrows_buffer(cookie, srcrow, dstrow, nrows);
    830   1.1  macallan 
    831  1.21  jmcneill #if defined(VCONS_DRAW_INTR)
    832  1.21  jmcneill 	if (scr->scr_vd->use_intr)
    833  1.21  jmcneill 		return;
    834  1.21  jmcneill #endif
    835  1.21  jmcneill 
    836   1.1  macallan 	vcons_lock(scr);
    837   1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    838  1.26  macallan 		scr->scr_vd->copyrows(cookie, srcrow, dstrow, nrows);
    839   1.1  macallan 	}
    840   1.1  macallan 	vcons_unlock(scr);
    841   1.1  macallan }
    842   1.1  macallan 
    843   1.1  macallan static void
    844  1.17  macallan vcons_copyrows_noread(void *cookie, int srcrow, int dstrow, int nrows)
    845  1.17  macallan {
    846  1.17  macallan 	struct rasops_info *ri = cookie;
    847  1.17  macallan 	struct vcons_screen *scr = ri->ri_hw;
    848  1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
    849  1.25  macallan 	int dist;
    850  1.17  macallan 
    851  1.17  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    852  1.25  macallan 		int pos, l, c, offset, ppos;
    853  1.17  macallan 
    854  1.17  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    855  1.17  macallan 		offset = scr->scr_current_offset;
    856  1.17  macallan #else
    857  1.17  macallan 		offset = 0;
    858  1.17  macallan #endif
    859  1.25  macallan 		dist = (dstrow - srcrow) * ri->ri_cols;
    860  1.25  macallan 		ppos = ri->ri_cols * dstrow;
    861  1.25  macallan 		pos = ppos + offset;
    862  1.17  macallan 		for (l = dstrow; l < (dstrow + nrows); l++) {
    863  1.17  macallan 			for (c = 0; c < ri->ri_cols; c++) {
    864  1.25  macallan #ifdef VCONS_DRAW_INTR
    865  1.25  macallan 				if ((scr->scr_chars[pos] != vd->chars[ppos]) ||
    866  1.25  macallan 				    (scr->scr_attrs[pos] != vd->attrs[ppos])) {
    867  1.25  macallan 					vd->putchar(cookie, l, c,
    868  1.25  macallan 					   scr->scr_chars[pos], scr->scr_attrs[pos]);
    869  1.25  macallan 					vd->chars[ppos] = scr->scr_chars[pos];
    870  1.25  macallan 					vd->attrs[ppos] = scr->scr_attrs[pos];
    871  1.25  macallan 				}
    872  1.25  macallan #else
    873  1.25  macallan 				vd->putchar(cookie, l, c, scr->scr_chars[pos],
    874  1.25  macallan 				    scr->scr_attrs[pos]);
    875  1.25  macallan #endif
    876  1.17  macallan 				pos++;
    877  1.25  macallan 				ppos++;
    878  1.17  macallan 			}
    879  1.17  macallan 		}
    880  1.17  macallan 	}
    881  1.17  macallan }
    882  1.17  macallan 
    883  1.17  macallan static void
    884   1.1  macallan vcons_eraserows_buffer(void *cookie, int row, int nrows, long fillattr)
    885   1.1  macallan {
    886   1.1  macallan 	struct rasops_info *ri = cookie;
    887   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    888   1.1  macallan 	int start, end, i;
    889   1.1  macallan 
    890  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    891  1.14  macallan 	int offset;
    892  1.14  macallan 	offset = scr->scr_offset_to_zero;
    893  1.14  macallan 
    894  1.14  macallan 	start = ri->ri_cols * row + offset;
    895  1.14  macallan 	end = ri->ri_cols * (row + nrows) + offset;
    896  1.14  macallan #else
    897   1.1  macallan 	start = ri->ri_cols * row;
    898   1.1  macallan 	end = ri->ri_cols * (row + nrows);
    899  1.14  macallan #endif
    900   1.1  macallan 
    901   1.1  macallan 	for (i = start; i < end; i++) {
    902   1.1  macallan 		scr->scr_attrs[i] = fillattr;
    903   1.1  macallan 		scr->scr_chars[i] = 0x20;
    904   1.1  macallan 	}
    905  1.20  jmcneill 
    906  1.20  jmcneill #ifdef VCONS_DRAW_INTR
    907  1.22  jmcneill 	atomic_inc_uint(&scr->scr_dirty);
    908  1.20  jmcneill #endif
    909   1.1  macallan }
    910   1.1  macallan 
    911   1.1  macallan static void
    912   1.1  macallan vcons_eraserows(void *cookie, int row, int nrows, long fillattr)
    913   1.1  macallan {
    914   1.1  macallan 	struct rasops_info *ri = cookie;
    915   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    916   1.1  macallan 
    917   1.1  macallan 	vcons_eraserows_buffer(cookie, row, nrows, fillattr);
    918   1.1  macallan 
    919  1.21  jmcneill #if defined(VCONS_DRAW_INTR)
    920  1.21  jmcneill 	if (scr->scr_vd->use_intr)
    921  1.21  jmcneill 		return;
    922  1.21  jmcneill #endif
    923  1.21  jmcneill 
    924   1.1  macallan 	vcons_lock(scr);
    925   1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    926  1.25  macallan 		scr->scr_vd->eraserows(cookie, row, nrows, fillattr);
    927   1.1  macallan 	}
    928   1.1  macallan 	vcons_unlock(scr);
    929   1.1  macallan }
    930   1.1  macallan 
    931   1.1  macallan static void
    932   1.1  macallan vcons_putchar_buffer(void *cookie, int row, int col, u_int c, long attr)
    933   1.1  macallan {
    934   1.1  macallan 	struct rasops_info *ri = cookie;
    935   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    936   1.1  macallan 	int pos;
    937   1.1  macallan 
    938  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    939  1.14  macallan 	int offset;
    940  1.14  macallan 	offset = scr->scr_offset_to_zero;
    941  1.14  macallan 
    942  1.14  macallan 	if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
    943  1.14  macallan 	     (col < ri->ri_cols)) {
    944  1.14  macallan 		pos = col + row * ri->ri_cols;
    945  1.14  macallan 		scr->scr_attrs[pos + offset] = attr;
    946  1.14  macallan 		scr->scr_chars[pos + offset] = c;
    947  1.14  macallan 	}
    948  1.14  macallan #else
    949   1.1  macallan 	if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
    950   1.1  macallan 	     (col < ri->ri_cols)) {
    951   1.1  macallan 		pos = col + row * ri->ri_cols;
    952   1.1  macallan 		scr->scr_attrs[pos] = attr;
    953   1.1  macallan 		scr->scr_chars[pos] = c;
    954   1.1  macallan 	}
    955  1.14  macallan #endif
    956  1.20  jmcneill 
    957  1.20  jmcneill #ifdef VCONS_DRAW_INTR
    958  1.22  jmcneill 	atomic_inc_uint(&scr->scr_dirty);
    959  1.20  jmcneill #endif
    960   1.1  macallan }
    961   1.1  macallan 
    962  1.25  macallan #ifdef VCONS_DRAW_INTR
    963  1.25  macallan static void
    964  1.25  macallan vcons_putchar_cached(void *cookie, int row, int col, u_int c, long attr)
    965  1.25  macallan {
    966  1.25  macallan 	struct rasops_info *ri = cookie;
    967  1.25  macallan 	struct vcons_screen *scr = ri->ri_hw;
    968  1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
    969  1.25  macallan 	int pos = row * ri->ri_cols + col;
    970  1.25  macallan 
    971  1.25  macallan 	if ((vd->chars == NULL) || (vd->attrs == NULL)) {
    972  1.25  macallan 		vd->putchar(cookie, row, col, c, attr);
    973  1.25  macallan 		return;
    974  1.25  macallan 	}
    975  1.25  macallan 	if ((vd->chars[pos] != c) || (vd->attrs[pos] != attr)) {
    976  1.25  macallan 		vd->attrs[pos] = attr;
    977  1.25  macallan 		vd->chars[pos] = c;
    978  1.25  macallan 		vd->putchar(cookie, row, col, c, attr);
    979  1.25  macallan 	}
    980  1.25  macallan }
    981  1.25  macallan #endif
    982  1.25  macallan 
    983   1.1  macallan static void
    984   1.1  macallan vcons_putchar(void *cookie, int row, int col, u_int c, long attr)
    985   1.1  macallan {
    986   1.1  macallan 	struct rasops_info *ri = cookie;
    987   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    988   1.1  macallan 
    989   1.1  macallan 	vcons_putchar_buffer(cookie, row, col, c, attr);
    990  1.21  jmcneill 
    991  1.21  jmcneill #if defined(VCONS_DRAW_INTR)
    992  1.21  jmcneill 	if (scr->scr_vd->use_intr)
    993  1.21  jmcneill 		return;
    994  1.21  jmcneill #endif
    995  1.21  jmcneill 
    996   1.1  macallan 	vcons_lock(scr);
    997   1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    998  1.25  macallan #ifdef VCONS_DRAW_INTR
    999  1.25  macallan 		vcons_putchar_cached(cookie, row, col, c, attr);
   1000  1.25  macallan #else
   1001  1.25  macallan 		scr->scr_vd->putchar(cookie, row, col, c, attr);
   1002  1.25  macallan #endif
   1003   1.1  macallan 	}
   1004   1.1  macallan 	vcons_unlock(scr);
   1005   1.1  macallan }
   1006   1.1  macallan 
   1007   1.1  macallan static void
   1008   1.1  macallan vcons_cursor(void *cookie, int on, int row, int col)
   1009   1.1  macallan {
   1010   1.1  macallan 	struct rasops_info *ri = cookie;
   1011   1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1012   1.1  macallan 
   1013  1.20  jmcneill 
   1014  1.20  jmcneill #if defined(VCONS_DRAW_INTR)
   1015  1.21  jmcneill 	if (scr->scr_vd->use_intr) {
   1016  1.21  jmcneill 		vcons_lock(scr);
   1017  1.21  jmcneill 		if (scr->scr_ri.ri_crow != row || scr->scr_ri.ri_ccol != col) {
   1018  1.21  jmcneill 			scr->scr_ri.ri_crow = row;
   1019  1.21  jmcneill 			scr->scr_ri.ri_ccol = col;
   1020  1.22  jmcneill 			atomic_inc_uint(&scr->scr_dirty);
   1021  1.21  jmcneill 		}
   1022  1.21  jmcneill 		vcons_unlock(scr);
   1023  1.21  jmcneill 		return;
   1024  1.20  jmcneill 	}
   1025  1.21  jmcneill #endif
   1026  1.21  jmcneill 
   1027  1.21  jmcneill 	vcons_lock(scr);
   1028  1.21  jmcneill 
   1029   1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
   1030  1.26  macallan 		scr->scr_vd->cursor(cookie, on, row, col);
   1031   1.1  macallan 	} else {
   1032   1.1  macallan 		scr->scr_ri.ri_crow = row;
   1033   1.1  macallan 		scr->scr_ri.ri_ccol = col;
   1034   1.1  macallan 	}
   1035   1.1  macallan 	vcons_unlock(scr);
   1036   1.1  macallan }
   1037   1.1  macallan 
   1038   1.1  macallan /* methods to read/write characters via ioctl() */
   1039   1.1  macallan 
   1040   1.1  macallan static int
   1041   1.6      jmmv vcons_putwschar(struct vcons_screen *scr, struct wsdisplay_char *wsc)
   1042   1.1  macallan {
   1043   1.1  macallan 	long attr;
   1044   1.6      jmmv 	struct rasops_info *ri;
   1045   1.6      jmmv 
   1046   1.6      jmmv 	KASSERT(scr != NULL && wsc != NULL);
   1047   1.6      jmmv 
   1048  1.13    rumble 	ri = &scr->scr_ri;
   1049  1.13    rumble 
   1050  1.12       mjf 	if (__predict_false((unsigned int)wsc->col > ri->ri_cols ||
   1051  1.12       mjf 	    (unsigned int)wsc->row > ri->ri_rows))
   1052  1.12       mjf 			return (EINVAL);
   1053   1.1  macallan 
   1054  1.14  macallan 	if ((wsc->row >= 0) && (wsc->row < ri->ri_rows) && (wsc->col >= 0) &&
   1055  1.14  macallan 	     (wsc->col < ri->ri_cols)) {
   1056  1.14  macallan 
   1057  1.14  macallan 		ri->ri_ops.allocattr(ri, wsc->foreground, wsc->background,
   1058  1.14  macallan 		    wsc->flags, &attr);
   1059  1.14  macallan 		vcons_putchar(ri, wsc->row, wsc->col, wsc->letter, attr);
   1060  1.14  macallan #ifdef VCONS_DEBUG
   1061  1.14  macallan 		printf("vcons_putwschar(%d, %d, %x, %lx\n", wsc->row, wsc->col,
   1062  1.14  macallan 		    wsc->letter, attr);
   1063  1.14  macallan #endif
   1064  1.14  macallan 		return 0;
   1065  1.14  macallan 	} else
   1066  1.14  macallan 		return EINVAL;
   1067   1.1  macallan }
   1068   1.1  macallan 
   1069   1.1  macallan static int
   1070   1.6      jmmv vcons_getwschar(struct vcons_screen *scr, struct wsdisplay_char *wsc)
   1071   1.1  macallan {
   1072   1.6      jmmv 	int offset;
   1073   1.1  macallan 	long attr;
   1074   1.6      jmmv 	struct rasops_info *ri;
   1075   1.6      jmmv 
   1076   1.6      jmmv 	KASSERT(scr != NULL && wsc != NULL);
   1077   1.6      jmmv 
   1078   1.6      jmmv 	ri = &scr->scr_ri;
   1079   1.1  macallan 
   1080  1.14  macallan 	if ((wsc->row >= 0) && (wsc->row < ri->ri_rows) && (wsc->col >= 0) &&
   1081  1.14  macallan 	     (wsc->col < ri->ri_cols)) {
   1082  1.14  macallan 
   1083  1.14  macallan 		offset = ri->ri_cols * wsc->row + wsc->col;
   1084  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
   1085  1.14  macallan 		offset += scr->scr_offset_to_zero;
   1086  1.14  macallan #endif
   1087  1.14  macallan 		wsc->letter = scr->scr_chars[offset];
   1088  1.14  macallan 		attr = scr->scr_attrs[offset];
   1089  1.14  macallan 
   1090  1.14  macallan 		/*
   1091  1.14  macallan 		 * this is ugly. We need to break up an attribute into colours and
   1092  1.14  macallan 		 * flags but there's no rasops method to do that so we must rely on
   1093  1.14  macallan 		 * the 'canonical' encoding.
   1094  1.14  macallan 		 */
   1095  1.14  macallan #ifdef VCONS_DEBUG
   1096  1.14  macallan 		printf("vcons_getwschar: %d, %d, %x, %lx\n", wsc->row,
   1097  1.14  macallan 		    wsc->col, wsc->letter, attr);
   1098  1.14  macallan #endif
   1099  1.14  macallan 		wsc->foreground = (attr >> 24) & 0xff;
   1100  1.14  macallan 		wsc->background = (attr >> 16) & 0xff;
   1101  1.14  macallan 		wsc->flags      = attr & 0xff;
   1102  1.14  macallan 		return 0;
   1103  1.14  macallan 	} else
   1104  1.14  macallan 		return EINVAL;
   1105  1.14  macallan }
   1106  1.14  macallan 
   1107  1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
   1108  1.14  macallan 
   1109  1.14  macallan static void
   1110  1.14  macallan vcons_scroll(void *cookie, void *vs, int where)
   1111  1.14  macallan {
   1112  1.14  macallan 	struct vcons_screen *scr = vs;
   1113  1.14  macallan 
   1114  1.14  macallan 	if (where == 0) {
   1115  1.14  macallan 		scr->scr_line_wanted = 0;
   1116  1.14  macallan 	} else {
   1117  1.14  macallan 		scr->scr_line_wanted = scr->scr_line_wanted - where;
   1118  1.14  macallan 		if (scr->scr_line_wanted < 0)
   1119  1.14  macallan 			scr->scr_line_wanted = 0;
   1120  1.14  macallan 		if (scr->scr_line_wanted > scr->scr_lines_in_buffer)
   1121  1.14  macallan 			scr->scr_line_wanted = scr->scr_lines_in_buffer;
   1122  1.14  macallan 	}
   1123  1.14  macallan 
   1124  1.14  macallan 	if (scr->scr_line_wanted != scr->scr_current_line) {
   1125  1.14  macallan 
   1126  1.14  macallan 		vcons_do_scroll(scr);
   1127  1.14  macallan 	}
   1128  1.14  macallan }
   1129  1.14  macallan 
   1130  1.14  macallan static void
   1131  1.14  macallan vcons_do_scroll(struct vcons_screen *scr)
   1132  1.14  macallan {
   1133  1.14  macallan 	int dist, from, to, num;
   1134  1.14  macallan 	int r_offset, r_start;
   1135  1.14  macallan 	int i, j;
   1136  1.14  macallan 
   1137  1.14  macallan 	if (scr->scr_line_wanted == scr->scr_current_line)
   1138  1.14  macallan 		return;
   1139  1.14  macallan 	dist = scr->scr_line_wanted - scr->scr_current_line;
   1140  1.14  macallan 	scr->scr_current_line = scr->scr_line_wanted;
   1141  1.14  macallan 	scr->scr_current_offset = scr->scr_ri.ri_cols *
   1142  1.14  macallan 	    (scr->scr_lines_in_buffer - scr->scr_current_line);
   1143  1.14  macallan 	if (abs(dist) >= scr->scr_ri.ri_rows) {
   1144  1.14  macallan 		vcons_redraw_screen(scr);
   1145  1.14  macallan 		return;
   1146  1.14  macallan 	}
   1147  1.14  macallan 	/* scroll and redraw only what we really have to */
   1148  1.14  macallan 	if (dist > 0) {
   1149  1.14  macallan 		/* we scroll down */
   1150  1.14  macallan 		from = 0;
   1151  1.14  macallan 		to = dist;
   1152  1.14  macallan 		num = scr->scr_ri.ri_rows - dist;
   1153  1.14  macallan 		/* now the redraw parameters */
   1154  1.14  macallan 		r_offset = scr->scr_current_offset;
   1155  1.14  macallan 		r_start = 0;
   1156  1.14  macallan 	} else {
   1157  1.14  macallan 		/* scrolling up */
   1158  1.14  macallan 		to = 0;
   1159  1.14  macallan 		from = -dist;
   1160  1.14  macallan 		num = scr->scr_ri.ri_rows + dist;
   1161  1.14  macallan 		r_offset = scr->scr_current_offset + num * scr->scr_ri.ri_cols;
   1162  1.14  macallan 		r_start = num;
   1163  1.14  macallan 	}
   1164  1.14  macallan 	scr->scr_vd->copyrows(scr, from, to, num);
   1165  1.14  macallan 	for (i = 0; i < abs(dist); i++) {
   1166  1.14  macallan 		for (j = 0; j < scr->scr_ri.ri_cols; j++) {
   1167  1.25  macallan #ifdef VCONS_DRAW_INTR
   1168  1.25  macallan 			vcons_putchar_cached(scr, i + r_start, j,
   1169  1.25  macallan 			    scr->scr_chars[r_offset],
   1170  1.25  macallan 			    scr->scr_attrs[r_offset]);
   1171  1.25  macallan #else
   1172  1.14  macallan 			scr->scr_vd->putchar(scr, i + r_start, j,
   1173  1.14  macallan 			    scr->scr_chars[r_offset],
   1174  1.14  macallan 			    scr->scr_attrs[r_offset]);
   1175  1.25  macallan #endif
   1176  1.14  macallan 			r_offset++;
   1177  1.14  macallan 		}
   1178  1.14  macallan 	}
   1179  1.14  macallan 
   1180  1.14  macallan 	if (scr->scr_line_wanted == 0) {
   1181  1.14  macallan 		/* this was a reset - need to draw the cursor */
   1182  1.14  macallan 		scr->scr_ri.ri_flg &= ~RI_CURSOR;
   1183  1.14  macallan 		scr->scr_vd->cursor(scr, 1, scr->scr_ri.ri_crow,
   1184  1.14  macallan 		    scr->scr_ri.ri_ccol);
   1185  1.14  macallan 	}
   1186  1.14  macallan }
   1187  1.14  macallan 
   1188  1.14  macallan #endif /* WSDISPLAY_SCROLLSUPPORT */
   1189  1.14  macallan 
   1190  1.20  jmcneill #ifdef VCONS_DRAW_INTR
   1191  1.20  jmcneill static void
   1192  1.20  jmcneill vcons_intr(void *cookie)
   1193  1.20  jmcneill {
   1194  1.20  jmcneill 	struct vcons_data *vd = cookie;
   1195  1.20  jmcneill 
   1196  1.22  jmcneill 	softint_schedule(vd->intr_softint);
   1197  1.20  jmcneill }
   1198  1.20  jmcneill 
   1199  1.20  jmcneill static void
   1200  1.22  jmcneill vcons_softintr(void *cookie)
   1201  1.20  jmcneill {
   1202  1.20  jmcneill 	struct vcons_data *vd = cookie;
   1203  1.20  jmcneill 	struct vcons_screen *scr = vd->active;
   1204  1.22  jmcneill 	unsigned int dirty;
   1205  1.20  jmcneill 
   1206  1.23  jmcneill 	if (scr && vd->use_intr == 1) {
   1207  1.22  jmcneill 		if (!SCREEN_IS_BUSY(scr)) {
   1208  1.22  jmcneill 			dirty = atomic_swap_uint(&scr->scr_dirty, 0);
   1209  1.22  jmcneill 			if (dirty > 0) {
   1210  1.22  jmcneill 				if ((scr->scr_flags & VCONS_NO_REDRAW) == 0)
   1211  1.25  macallan 					vcons_update_screen(scr);
   1212  1.22  jmcneill 			}
   1213  1.20  jmcneill 		}
   1214  1.20  jmcneill 	}
   1215  1.20  jmcneill 
   1216  1.20  jmcneill 	callout_schedule(&vd->intr, mstohz(33));
   1217  1.20  jmcneill }
   1218  1.21  jmcneill 
   1219  1.21  jmcneill static void
   1220  1.21  jmcneill vcons_intr_enable(device_t dev)
   1221  1.21  jmcneill {
   1222  1.21  jmcneill 	/* the 'dev' arg we pass to config_interrupts isn't a device_t */
   1223  1.21  jmcneill 	struct vcons_data *vd = (struct vcons_data *)dev;
   1224  1.21  jmcneill 	vd->use_intr = 1;
   1225  1.21  jmcneill 	callout_schedule(&vd->intr, mstohz(33));
   1226  1.21  jmcneill }
   1227  1.20  jmcneill #endif /* VCONS_DRAW_INTR */
   1228  1.23  jmcneill 
   1229  1.23  jmcneill void
   1230  1.23  jmcneill vcons_enable_polling(struct vcons_data *vd)
   1231  1.23  jmcneill {
   1232  1.23  jmcneill 	struct vcons_screen *scr = vd->active;
   1233  1.23  jmcneill 
   1234  1.23  jmcneill #ifdef VCONS_DRAW_INTR
   1235  1.23  jmcneill 	vd->use_intr = 0;
   1236  1.23  jmcneill #endif
   1237  1.23  jmcneill 
   1238  1.23  jmcneill 	if (scr && !SCREEN_IS_BUSY(scr)) {
   1239  1.23  jmcneill 		if ((scr->scr_flags & VCONS_NO_REDRAW) == 0)
   1240  1.23  jmcneill 			vcons_redraw_screen(scr);
   1241  1.23  jmcneill 	}
   1242  1.23  jmcneill }
   1243  1.23  jmcneill 
   1244  1.23  jmcneill void
   1245  1.23  jmcneill vcons_disable_polling(struct vcons_data *vd)
   1246  1.23  jmcneill {
   1247  1.23  jmcneill #ifdef VCONS_DRAW_INTR
   1248  1.23  jmcneill 	struct vcons_screen *scr = vd->active;
   1249  1.23  jmcneill 
   1250  1.23  jmcneill 	if (!vd->intr_valid)
   1251  1.23  jmcneill 		return;
   1252  1.23  jmcneill 
   1253  1.23  jmcneill 	vd->use_intr = 1;
   1254  1.23  jmcneill 	if (scr)
   1255  1.23  jmcneill 		atomic_inc_uint(&scr->scr_dirty);
   1256  1.23  jmcneill #endif
   1257  1.23  jmcneill }
   1258  1.24  jmcneill 
   1259  1.24  jmcneill void
   1260  1.24  jmcneill vcons_hard_switch(struct vcons_screen *scr)
   1261  1.24  jmcneill {
   1262  1.24  jmcneill 	struct vcons_data *vd = scr->scr_vd;
   1263  1.24  jmcneill 	struct vcons_screen *oldscr = vd->active;
   1264  1.24  jmcneill 
   1265  1.24  jmcneill 	if (oldscr) {
   1266  1.24  jmcneill 		SCREEN_INVISIBLE(oldscr);
   1267  1.24  jmcneill 		oldscr->scr_ri.ri_flg &= ~RI_CURSOR;
   1268  1.24  jmcneill 	}
   1269  1.24  jmcneill 	SCREEN_VISIBLE(scr);
   1270  1.24  jmcneill 	vd->active = scr;
   1271  1.24  jmcneill 	vd->wanted = NULL;
   1272  1.24  jmcneill 
   1273  1.24  jmcneill 	if (vd->show_screen_cb != NULL)
   1274  1.24  jmcneill 		vd->show_screen_cb(scr);
   1275  1.24  jmcneill }
   1276  1.25  macallan 
   1277  1.25  macallan #ifdef VCONS_DRAW_INTR
   1278  1.25  macallan void
   1279  1.25  macallan vcons_invalidate_cache(struct vcons_data *vd)
   1280  1.25  macallan {
   1281  1.25  macallan 	int i;
   1282  1.25  macallan 
   1283  1.25  macallan 	if (vd->cells == 0)
   1284  1.25  macallan 		return;
   1285  1.25  macallan 
   1286  1.25  macallan 	for (i = 0; i > vd->cells; i++) {
   1287  1.25  macallan 		vd->chars[i] = -1;
   1288  1.25  macallan 		vd->attrs[i] = -1;
   1289  1.25  macallan 	}
   1290  1.25  macallan }
   1291  1.25  macallan #endif
   1292