Home | History | Annotate | Line # | Download | only in wscons
wsdisplay_vcons.c revision 1.51.6.1
      1  1.51.6.1      cjep /*	$NetBSD: wsdisplay_vcons.c,v 1.51.6.1 2021/05/31 22:15:19 cjep 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.51.6.1      cjep __KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.51.6.1 2021/05/31 22:15:19 cjep 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.32  riastrad #ifdef _KERNEL_OPT
     55      1.14  macallan #include "opt_wsemul.h"
     56      1.14  macallan #include "opt_wsdisplay_compat.h"
     57      1.14  macallan #include "opt_vcons.h"
     58      1.32  riastrad #endif
     59      1.14  macallan 
     60      1.37  macallan #ifdef VCONS_DEBUG
     61      1.37  macallan #define DPRINTF printf
     62      1.37  macallan #else
     63      1.37  macallan #define DPRINTF if (0) printf
     64      1.37  macallan #endif
     65      1.37  macallan 
     66       1.1  macallan static void vcons_dummy_init_screen(void *, struct vcons_screen *, int,
     67       1.1  macallan 	    long *);
     68       1.1  macallan 
     69      1.10  christos static int  vcons_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     70       1.1  macallan static int  vcons_alloc_screen(void *, const struct wsscreen_descr *, void **,
     71       1.1  macallan 	    int *, int *, long *);
     72       1.1  macallan static void vcons_free_screen(void *, void *);
     73       1.1  macallan static int  vcons_show_screen(void *, void *, int, void (*)(void *, int, int),
     74       1.1  macallan 	    void *);
     75      1.37  macallan static int  vcons_load_font(void *, void *, struct wsdisplay_font *);
     76       1.1  macallan 
     77      1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
     78      1.14  macallan static void vcons_scroll(void *, void *, int);
     79      1.14  macallan static void vcons_do_scroll(struct vcons_screen *);
     80      1.14  macallan #endif
     81      1.14  macallan 
     82      1.15     joerg static void vcons_do_switch(void *);
     83       1.1  macallan 
     84       1.1  macallan /* methods that work only on text buffers */
     85       1.1  macallan static void vcons_copycols_buffer(void *, int, int, int, int);
     86       1.1  macallan static void vcons_erasecols_buffer(void *, int, int, int, long);
     87       1.1  macallan static void vcons_copyrows_buffer(void *, int, int, int);
     88       1.1  macallan static void vcons_eraserows_buffer(void *, int, int, long);
     89       1.1  macallan static void vcons_putchar_buffer(void *, int, int, u_int, long);
     90       1.1  macallan 
     91       1.1  macallan /*
     92       1.1  macallan  * actual wrapper methods which call both the _buffer ones above and the
     93       1.1  macallan  * driver supplied ones to do the drawing
     94       1.1  macallan  */
     95       1.1  macallan static void vcons_copycols(void *, int, int, int, int);
     96       1.1  macallan static void vcons_erasecols(void *, int, int, int, long);
     97       1.1  macallan static void vcons_copyrows(void *, int, int, int);
     98       1.1  macallan static void vcons_eraserows(void *, int, int, long);
     99       1.1  macallan static void vcons_putchar(void *, int, int, u_int, long);
    100      1.25  macallan #ifdef VCONS_DRAW_INTR
    101      1.30   mlelstv static void vcons_erasecols_cached(void *, int, int, int, long);
    102      1.30   mlelstv static void vcons_eraserows_cached(void *, int, int, long);
    103      1.25  macallan static void vcons_putchar_cached(void *, int, int, u_int, long);
    104      1.25  macallan #endif
    105       1.1  macallan static void vcons_cursor(void *, int, int, int);
    106      1.48  macallan static void vcons_cursor_noread(void *, int, int, int);
    107       1.1  macallan 
    108      1.17  macallan /*
    109      1.17  macallan  * methods that avoid framebuffer reads
    110      1.17  macallan  */
    111      1.17  macallan static void vcons_copycols_noread(void *, int, int, int, int);
    112      1.17  macallan static void vcons_copyrows_noread(void *, int, int, int);
    113      1.17  macallan 
    114      1.17  macallan 
    115      1.14  macallan /* support for reading/writing text buffers. For wsmoused */
    116       1.6      jmmv static int  vcons_putwschar(struct vcons_screen *, struct wsdisplay_char *);
    117       1.6      jmmv static int  vcons_getwschar(struct vcons_screen *, struct wsdisplay_char *);
    118       1.1  macallan 
    119       1.1  macallan static void vcons_lock(struct vcons_screen *);
    120       1.1  macallan static void vcons_unlock(struct vcons_screen *);
    121       1.1  macallan 
    122      1.20  jmcneill #ifdef VCONS_DRAW_INTR
    123      1.20  jmcneill static void vcons_intr(void *);
    124      1.22  jmcneill static void vcons_softintr(void *);
    125      1.47  jmcneill static void vcons_init_thread(void *);
    126      1.20  jmcneill #endif
    127       1.1  macallan 
    128      1.47  jmcneill static int
    129      1.47  jmcneill vcons_init_common(struct vcons_data *vd, void *cookie,
    130      1.47  jmcneill     struct wsscreen_descr *def, struct wsdisplay_accessops *ao,
    131      1.47  jmcneill     int enable_intr)
    132       1.1  macallan {
    133       1.2  macallan 
    134       1.2  macallan 	/* zero out everything so we can rely on untouched fields being 0 */
    135       1.3  macallan 	memset(vd, 0, sizeof(struct vcons_data));
    136      1.47  jmcneill 
    137       1.1  macallan 	vd->cookie = cookie;
    138       1.1  macallan 
    139       1.1  macallan 	vd->init_screen = vcons_dummy_init_screen;
    140       1.1  macallan 	vd->show_screen_cb = NULL;
    141       1.1  macallan 
    142       1.6      jmmv 	/* keep a copy of the accessops that we replace below with our
    143       1.6      jmmv 	 * own wrappers */
    144       1.6      jmmv 	vd->ioctl = ao->ioctl;
    145       1.6      jmmv 
    146       1.6      jmmv 	/* configure the accessops */
    147       1.6      jmmv 	ao->ioctl = vcons_ioctl;
    148       1.1  macallan 	ao->alloc_screen = vcons_alloc_screen;
    149       1.1  macallan 	ao->free_screen = vcons_free_screen;
    150       1.1  macallan 	ao->show_screen = vcons_show_screen;
    151      1.37  macallan 	ao->load_font = vcons_load_font;
    152      1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    153      1.14  macallan 	ao->scroll = vcons_scroll;
    154      1.14  macallan #endif
    155       1.1  macallan 
    156       1.1  macallan 	LIST_INIT(&vd->screens);
    157       1.1  macallan 	vd->active = NULL;
    158       1.1  macallan 	vd->wanted = NULL;
    159       1.1  macallan 	vd->currenttype = def;
    160      1.37  macallan 	vd->defaulttype = def;
    161      1.42   mlelstv 	callout_init(&vd->switch_callout, 0);
    162      1.15     joerg 	callout_setfunc(&vd->switch_callout, vcons_do_switch, vd);
    163      1.25  macallan #ifdef VCONS_DRAW_INTR
    164      1.25  macallan 	vd->cells = 0;
    165      1.25  macallan 	vd->attrs = NULL;
    166      1.25  macallan 	vd->chars = NULL;
    167      1.25  macallan 	vd->cursor_offset = -1;
    168      1.25  macallan #endif
    169       1.1  macallan 
    170       1.1  macallan 	/*
    171       1.1  macallan 	 * a lock to serialize access to the framebuffer.
    172       1.1  macallan 	 * when switching screens we need to make sure there's no rasops
    173       1.1  macallan 	 * operation in progress
    174       1.1  macallan 	 */
    175       1.1  macallan #ifdef DIAGNOSTIC
    176       1.1  macallan 	vd->switch_poll_count = 0;
    177       1.1  macallan #endif
    178      1.20  jmcneill #ifdef VCONS_DRAW_INTR
    179      1.47  jmcneill 	if (enable_intr) {
    180      1.47  jmcneill 		vd->intr_softint = softint_establish(SOFTINT_SERIAL,
    181      1.47  jmcneill 		    vcons_softintr, vd);
    182      1.47  jmcneill 		callout_init(&vd->intr, CALLOUT_MPSAFE);
    183      1.47  jmcneill 		callout_setfunc(&vd->intr, vcons_intr, vd);
    184      1.47  jmcneill 		vd->intr_valid = 1;
    185      1.47  jmcneill 
    186      1.47  jmcneill 		if (kthread_create(PRI_NONE, 0, NULL, vcons_init_thread, vd,
    187      1.47  jmcneill 		    NULL, "vcons_init") != 0) {
    188      1.47  jmcneill 			printf("%s: unable to create thread.\n", __func__);
    189      1.47  jmcneill 			return -1;
    190      1.47  jmcneill 		}
    191      1.47  jmcneill 	}
    192      1.20  jmcneill #endif
    193       1.1  macallan 	return 0;
    194       1.1  macallan }
    195       1.1  macallan 
    196      1.47  jmcneill int
    197      1.47  jmcneill vcons_init(struct vcons_data *vd, void *cookie,
    198      1.47  jmcneill     struct wsscreen_descr *def, struct wsdisplay_accessops *ao)
    199      1.47  jmcneill {
    200      1.47  jmcneill 	return vcons_init_common(vd, cookie, def, ao, 1);
    201      1.47  jmcneill }
    202      1.47  jmcneill 
    203      1.47  jmcneill int
    204      1.47  jmcneill vcons_earlyinit(struct vcons_data *vd, void *cookie,
    205      1.47  jmcneill     struct wsscreen_descr *def, struct wsdisplay_accessops *ao)
    206      1.47  jmcneill {
    207      1.47  jmcneill 	return vcons_init_common(vd, cookie, def, ao, 0);
    208      1.47  jmcneill }
    209      1.47  jmcneill 
    210       1.1  macallan static void
    211       1.1  macallan vcons_lock(struct vcons_screen *scr)
    212       1.1  macallan {
    213       1.1  macallan #ifdef VCONS_PARANOIA
    214       1.1  macallan 	int s;
    215       1.1  macallan 
    216       1.1  macallan 	s = splhigh();
    217       1.1  macallan #endif
    218       1.1  macallan 	SCREEN_BUSY(scr);
    219       1.1  macallan #ifdef VCONS_PARANOIA
    220       1.1  macallan 	splx(s);
    221       1.1  macallan #endif
    222       1.1  macallan }
    223       1.1  macallan 
    224       1.1  macallan static void
    225       1.1  macallan vcons_unlock(struct vcons_screen *scr)
    226       1.1  macallan {
    227       1.1  macallan #ifdef VCONS_PARANOIA
    228       1.1  macallan 	int s;
    229       1.1  macallan 
    230       1.1  macallan 	s = splhigh();
    231       1.1  macallan #endif
    232       1.1  macallan 	SCREEN_IDLE(scr);
    233       1.1  macallan #ifdef VCONS_PARANOIA
    234       1.1  macallan 	splx(s);
    235       1.1  macallan #endif
    236       1.1  macallan }
    237       1.1  macallan 
    238       1.1  macallan static void
    239       1.9  christos vcons_dummy_init_screen(void *cookie,
    240       1.9  christos     struct vcons_screen *scr, int exists,
    241       1.9  christos     long *defattr)
    242       1.1  macallan {
    243       1.1  macallan 
    244       1.1  macallan 	/*
    245       1.1  macallan 	 * default init_screen() method.
    246       1.1  macallan 	 * Needs to be overwritten so we bitch and whine in case anyone ends
    247       1.1  macallan 	 * up in here.
    248       1.1  macallan 	 */
    249       1.1  macallan 	printf("vcons_init_screen: dummy function called. Your driver is "
    250       1.1  macallan 	       "supposed to supply a replacement for proper operation\n");
    251       1.1  macallan }
    252       1.1  macallan 
    253      1.37  macallan static int
    254      1.37  macallan vcons_alloc_buffers(struct vcons_data *vd, struct vcons_screen *scr)
    255       1.1  macallan {
    256       1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
    257       1.1  macallan 	int cnt, i;
    258      1.25  macallan #ifdef VCONS_DRAW_INTR
    259      1.25  macallan 	int size;
    260      1.25  macallan #endif
    261       1.1  macallan 
    262      1.37  macallan 	/*
    263      1.37  macallan 	 * we allocate both chars and attributes in one chunk, attributes first
    264      1.37  macallan 	 * because they have the (potentially) bigger alignment
    265      1.37  macallan 	 */
    266      1.37  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    267      1.37  macallan 	cnt = (ri->ri_rows + WSDISPLAY_SCROLLBACK_LINES) * ri->ri_cols;
    268      1.37  macallan 	scr->scr_lines_in_buffer = WSDISPLAY_SCROLLBACK_LINES;
    269      1.37  macallan 	scr->scr_current_line = 0;
    270      1.37  macallan 	scr->scr_line_wanted = 0;
    271      1.37  macallan 	scr->scr_offset_to_zero = ri->ri_cols * WSDISPLAY_SCROLLBACK_LINES;
    272      1.37  macallan 	scr->scr_current_offset = scr->scr_offset_to_zero;
    273      1.37  macallan #else
    274      1.37  macallan 	cnt = ri->ri_rows * ri->ri_cols;
    275      1.37  macallan #endif
    276      1.37  macallan 	scr->scr_attrs = malloc(cnt * (sizeof(long) +
    277      1.37  macallan 	    sizeof(uint32_t)), M_DEVBUF, M_WAITOK);
    278      1.37  macallan 	if (scr->scr_attrs == NULL)
    279      1.37  macallan 		return ENOMEM;
    280      1.37  macallan 
    281      1.37  macallan 	scr->scr_chars = (uint32_t *)&scr->scr_attrs[cnt];
    282      1.37  macallan 
    283      1.37  macallan 	/*
    284      1.37  macallan 	 * fill the attribute buffer with *defattr, chars with 0x20
    285      1.37  macallan 	 * since we don't know if the driver tries to mimic firmware output or
    286      1.37  macallan 	 * reset everything we do nothing to VRAM here, any driver that feels
    287      1.37  macallan 	 * the need to clear screen or something will have to do it on its own
    288      1.37  macallan 	 * Additional screens will start out in the background anyway so
    289      1.37  macallan 	 * cleaning or not only really affects the initial console screen
    290      1.37  macallan 	 */
    291      1.37  macallan 	for (i = 0; i < cnt; i++) {
    292      1.37  macallan 		scr->scr_attrs[i] = scr->scr_defattr;
    293      1.37  macallan 		scr->scr_chars[i] = 0x20;
    294      1.37  macallan 	}
    295      1.37  macallan 
    296      1.37  macallan #ifdef VCONS_DRAW_INTR
    297      1.37  macallan 	size = ri->ri_cols * ri->ri_rows;
    298      1.37  macallan 	if (size > vd->cells) {
    299      1.37  macallan 		if (vd->chars != NULL) free(vd->chars, M_DEVBUF);
    300      1.37  macallan 		if (vd->attrs != NULL) free(vd->attrs, M_DEVBUF);
    301      1.37  macallan 		vd->cells = size;
    302      1.37  macallan 		vd->chars = malloc(size * sizeof(uint32_t), M_DEVBUF,
    303      1.37  macallan 		    M_WAITOK|M_ZERO);
    304      1.37  macallan 		vd->attrs = malloc(size * sizeof(long), M_DEVBUF,
    305      1.37  macallan 		    M_WAITOK|M_ZERO);
    306      1.37  macallan 		vcons_invalidate_cache(vd);
    307      1.37  macallan 	} else if (SCREEN_IS_VISIBLE(scr))
    308      1.37  macallan 		vcons_invalidate_cache(vd);
    309      1.37  macallan #endif
    310      1.37  macallan 	return 0;
    311      1.37  macallan }
    312      1.37  macallan 
    313      1.37  macallan int
    314      1.37  macallan vcons_init_screen(struct vcons_data *vd, struct vcons_screen *scr,
    315      1.37  macallan     int existing, long *defattr)
    316      1.37  macallan {
    317      1.37  macallan 	struct rasops_info *ri = &scr->scr_ri;
    318      1.37  macallan 	int i;
    319      1.37  macallan 
    320       1.1  macallan 	scr->scr_cookie = vd->cookie;
    321       1.4  jmcneill 	scr->scr_vd = scr->scr_origvd = vd;
    322      1.14  macallan 	scr->scr_busy = 0;
    323      1.50  macallan 
    324      1.37  macallan 	if (scr->scr_type == NULL)
    325      1.37  macallan 		scr->scr_type = vd->defaulttype;
    326       1.2  macallan 
    327       1.1  macallan 	/*
    328       1.1  macallan 	 * call the driver-supplied init_screen function which is expected
    329       1.1  macallan 	 * to set up rasops_info, override cursor() and probably others
    330       1.1  macallan 	 */
    331       1.1  macallan 	vd->init_screen(vd->cookie, scr, existing, defattr);
    332       1.1  macallan 
    333       1.1  macallan 	/*
    334       1.1  macallan 	 * save the non virtual console aware rasops and replace them with
    335       1.1  macallan 	 * our wrappers
    336       1.1  macallan 	 */
    337       1.1  macallan 	vd->eraserows = ri->ri_ops.eraserows;
    338       1.1  macallan 	vd->erasecols = ri->ri_ops.erasecols;
    339      1.37  macallan 	scr->putchar   = ri->ri_ops.putchar;
    340       1.1  macallan 
    341      1.18  macallan 	if (scr->scr_flags & VCONS_NO_COPYCOLS) {
    342      1.19  macallan 		vd->copycols  = vcons_copycols_noread;
    343      1.18  macallan 	} else {
    344      1.19  macallan 		vd->copycols = ri->ri_ops.copycols;
    345      1.18  macallan 	}
    346      1.18  macallan 
    347      1.18  macallan 	if (scr->scr_flags & VCONS_NO_COPYROWS) {
    348      1.19  macallan 		vd->copyrows  = vcons_copyrows_noread;
    349      1.17  macallan 	} else {
    350      1.19  macallan 		vd->copyrows = ri->ri_ops.copyrows;
    351      1.17  macallan 	}
    352      1.17  macallan 
    353      1.48  macallan 	if (scr->scr_flags & VCONS_NO_CURSOR) {
    354      1.50  macallan 		vd->cursor  = vcons_cursor_noread;
    355      1.48  macallan 	} else {
    356      1.50  macallan 		vd->cursor = ri->ri_ops.cursor;
    357      1.48  macallan 	}
    358      1.48  macallan 
    359      1.50  macallan 	ri->ri_ops.eraserows = vcons_eraserows;
    360      1.50  macallan 	ri->ri_ops.erasecols = vcons_erasecols;
    361      1.50  macallan 	ri->ri_ops.putchar   = vcons_putchar;
    362      1.50  macallan 	ri->ri_ops.cursor    = vcons_cursor;
    363      1.19  macallan 	ri->ri_ops.copycols  = vcons_copycols;
    364      1.19  macallan 	ri->ri_ops.copyrows  = vcons_copyrows;
    365      1.19  macallan 
    366      1.19  macallan 
    367       1.1  macallan 	ri->ri_hw = scr;
    368       1.1  macallan 
    369      1.35  christos 	i = ri->ri_ops.allocattr(ri, WS_DEFAULT_FG, WS_DEFAULT_BG, 0, defattr);
    370      1.35  christos 	if (i != 0) {
    371      1.35  christos #ifdef DIAGNOSTIC
    372      1.35  christos 		printf("vcons: error allocating attribute %d\n", i);
    373      1.35  christos #endif
    374      1.35  christos 		scr->scr_defattr = 0;
    375      1.35  christos 	} else
    376      1.35  christos 		scr->scr_defattr = *defattr;
    377       1.1  macallan 
    378      1.37  macallan 	vcons_alloc_buffers(vd, scr);
    379      1.25  macallan 
    380       1.2  macallan 	if(vd->active == NULL) {
    381       1.2  macallan 		vd->active = scr;
    382       1.2  macallan 		SCREEN_VISIBLE(scr);
    383       1.2  macallan 	}
    384       1.2  macallan 
    385       1.1  macallan 	if (existing) {
    386       1.2  macallan 		SCREEN_VISIBLE(scr);
    387       1.2  macallan 		vd->active = scr;
    388       1.1  macallan 	} else {
    389       1.2  macallan 		SCREEN_INVISIBLE(scr);
    390       1.1  macallan 	}
    391       1.1  macallan 
    392       1.1  macallan 	LIST_INSERT_HEAD(&vd->screens, scr, next);
    393       1.1  macallan 	return 0;
    394       1.1  macallan }
    395       1.1  macallan 
    396      1.37  macallan static int
    397      1.37  macallan vcons_load_font(void *v, void *cookie, struct wsdisplay_font *f)
    398      1.37  macallan {
    399      1.37  macallan 	struct vcons_data *vd = v;
    400      1.37  macallan 	struct vcons_screen *scr = cookie;
    401      1.37  macallan 	struct rasops_info *ri;
    402      1.37  macallan 	struct wsdisplay_font *font;
    403      1.37  macallan 	int flags = WSFONT_FIND_BITMAP, fcookie;
    404      1.37  macallan 
    405      1.37  macallan 	/* see if we're asked to add a font or use it */
    406      1.37  macallan 	if (scr == NULL)
    407      1.37  macallan 		return 0;
    408      1.37  macallan 
    409      1.37  macallan 	ri = &scr->scr_ri;
    410      1.37  macallan 
    411      1.37  macallan 	/* see if the driver knows how to handle multiple fonts */
    412      1.37  macallan 	if ((scr->scr_flags & VCONS_LOADFONT) == 0) {
    413      1.37  macallan 		return EOPNOTSUPP;
    414      1.37  macallan 	}
    415      1.37  macallan 
    416      1.37  macallan 	/* now see what fonts we can use */
    417      1.37  macallan 	if (ri->ri_flg & RI_ENABLE_ALPHA) {
    418      1.37  macallan 		flags |= WSFONT_FIND_ALPHA;
    419      1.37  macallan 	}
    420      1.37  macallan 
    421      1.37  macallan 	fcookie = wsfont_find(f->name, 0, 0, 0, 0, 0, flags);
    422      1.37  macallan 	if (fcookie == -1)
    423      1.37  macallan 		return EINVAL;
    424      1.37  macallan 
    425      1.37  macallan 	wsfont_lock(fcookie, &font);
    426      1.37  macallan 	if (font == NULL)
    427      1.37  macallan 		return EINVAL;
    428      1.37  macallan 
    429      1.37  macallan 	/* ok, we got a font. Now clear the screen with the old parameters */
    430      1.37  macallan 	if (SCREEN_IS_VISIBLE(scr))
    431      1.37  macallan 		vd->eraserows(ri, 0, ri->ri_rows, scr->scr_defattr);
    432      1.37  macallan 
    433      1.37  macallan 	vcons_lock(vd->active);
    434      1.37  macallan #ifdef VCONS_DRAW_INTR
    435      1.37  macallan 	callout_halt(&vd->intr, NULL);
    436      1.37  macallan #endif
    437      1.37  macallan 	/* set the new font and re-initialize things */
    438      1.37  macallan 	ri->ri_font = font;
    439      1.37  macallan 	wsfont_unlock(ri->ri_wsfcookie);
    440      1.37  macallan 	ri->ri_wsfcookie = fcookie;
    441      1.37  macallan 
    442      1.37  macallan 	vd->init_screen(vd->cookie, scr, 1, &scr->scr_defattr);
    443      1.37  macallan 	DPRINTF("caps %x %x\n", scr->scr_type->capabilities, ri->ri_caps);
    444      1.37  macallan 	if (scr->scr_type->capabilities & WSSCREEN_RESIZE) {
    445      1.37  macallan 		scr->scr_type->nrows = ri->ri_rows;
    446      1.37  macallan 		scr->scr_type->ncols = ri->ri_cols;
    447      1.37  macallan 		DPRINTF("new size %d %d\n", ri->ri_rows, ri->ri_cols);
    448      1.37  macallan 	}
    449      1.37  macallan 
    450      1.37  macallan 
    451      1.37  macallan 	/* now, throw the old buffers away */
    452      1.37  macallan 	if (scr->scr_attrs)
    453      1.37  macallan 		free(scr->scr_attrs, M_DEVBUF);
    454      1.37  macallan 	/* allocate new buffers */
    455      1.37  macallan 	vcons_alloc_buffers(vd, scr);
    456      1.37  macallan 
    457      1.40       rin 	/* save the potentially changed ri_ops */
    458      1.40       rin 	vd->eraserows = ri->ri_ops.eraserows;
    459      1.40       rin 	vd->erasecols = ri->ri_ops.erasecols;
    460      1.37  macallan 	scr->putchar   = ri->ri_ops.putchar;
    461      1.40       rin 	vd->cursor    = ri->ri_ops.cursor;
    462      1.40       rin 
    463      1.40       rin 	if (scr->scr_flags & VCONS_NO_COPYCOLS) {
    464      1.40       rin 		vd->copycols  = vcons_copycols_noread;
    465      1.40       rin 	} else {
    466      1.40       rin 		vd->copycols = ri->ri_ops.copycols;
    467      1.40       rin 	}
    468      1.40       rin 
    469      1.40       rin 	if (scr->scr_flags & VCONS_NO_COPYROWS) {
    470      1.40       rin 		vd->copyrows  = vcons_copyrows_noread;
    471      1.40       rin 	} else {
    472      1.40       rin 		vd->copyrows = ri->ri_ops.copyrows;
    473      1.40       rin 	}
    474      1.37  macallan 
    475      1.50  macallan 	if (scr->scr_flags & VCONS_NO_CURSOR) {
    476      1.50  macallan 		vd->cursor  = vcons_cursor_noread;
    477      1.50  macallan 	} else {
    478      1.50  macallan 		vd->cursor = ri->ri_ops.cursor;
    479      1.50  macallan 	}
    480      1.50  macallan 
    481      1.37  macallan 	/* and put our wrappers back */
    482      1.37  macallan 	ri->ri_ops.eraserows = vcons_eraserows;
    483      1.37  macallan 	ri->ri_ops.erasecols = vcons_erasecols;
    484      1.37  macallan 	ri->ri_ops.putchar   = vcons_putchar;
    485      1.50  macallan 	ri->ri_ops.cursor    = vcons_cursor;
    486      1.37  macallan 	ri->ri_ops.copycols  = vcons_copycols;
    487      1.37  macallan 	ri->ri_ops.copyrows  = vcons_copyrows;
    488      1.37  macallan 	vcons_unlock(vd->active);
    489      1.38  macallan 
    490      1.38  macallan 	/* notify things that we're about to redraw */
    491      1.38  macallan 	if (vd->show_screen_cb != NULL)
    492      1.38  macallan 		vd->show_screen_cb(scr, vd->show_screen_cookie);
    493      1.38  macallan 
    494      1.37  macallan #ifdef VCONS_DRAW_INTR
    495      1.37  macallan 	/*
    496      1.37  macallan 	 * XXX
    497      1.37  macallan 	 * Something(tm) craps all over VRAM somewhere up there if we're
    498      1.37  macallan 	 * using VCONS_DRAW_INTR. Until I figure out what causes it, just
    499      1.37  macallan 	 * redraw the screen for now.
    500      1.37  macallan 	 */
    501      1.37  macallan 	vcons_redraw_screen(vd->active);
    502      1.37  macallan 	callout_schedule(&vd->intr, mstohz(33));
    503      1.37  macallan #endif
    504      1.37  macallan 	/* no need to draw anything, wsdisplay should reset the terminal */
    505      1.37  macallan 
    506      1.37  macallan 	return 0;
    507      1.37  macallan }
    508      1.37  macallan 
    509       1.1  macallan static void
    510      1.15     joerg vcons_do_switch(void *arg)
    511       1.1  macallan {
    512      1.15     joerg 	struct vcons_data *vd = arg;
    513       1.1  macallan 	struct vcons_screen *scr, *oldscr;
    514       1.1  macallan 
    515       1.1  macallan 	scr = vd->wanted;
    516       1.1  macallan 	if (!scr) {
    517       1.1  macallan 		printf("vcons_switch_screen: disappeared\n");
    518       1.1  macallan 		vd->switch_cb(vd->switch_cb_arg, EIO, 0);
    519       1.1  macallan 		return;
    520       1.1  macallan 	}
    521       1.1  macallan 	oldscr = vd->active; /* can be NULL! */
    522       1.1  macallan 
    523       1.1  macallan 	/*
    524       1.1  macallan 	 * if there's an old, visible screen we mark it invisible and wait
    525       1.1  macallan 	 * until it's not busy so we can safely switch
    526       1.1  macallan 	 */
    527       1.1  macallan 	if (oldscr != NULL) {
    528       1.1  macallan 		SCREEN_INVISIBLE(oldscr);
    529       1.1  macallan 		if (SCREEN_IS_BUSY(oldscr)) {
    530      1.15     joerg 			callout_schedule(&vd->switch_callout, 1);
    531       1.1  macallan #ifdef DIAGNOSTIC
    532       1.1  macallan 			/* bitch if we wait too long */
    533       1.1  macallan 			vd->switch_poll_count++;
    534       1.1  macallan 			if (vd->switch_poll_count > 100) {
    535       1.1  macallan 				panic("vcons: screen still busy");
    536       1.1  macallan 			}
    537       1.1  macallan #endif
    538       1.1  macallan 			return;
    539       1.1  macallan 		}
    540       1.1  macallan 		/* invisible screen -> no visible cursor image */
    541       1.1  macallan 		oldscr->scr_ri.ri_flg &= ~RI_CURSOR;
    542       1.1  macallan #ifdef DIAGNOSTIC
    543       1.1  macallan 		vd->switch_poll_count = 0;
    544       1.1  macallan #endif
    545       1.1  macallan 	}
    546       1.1  macallan 
    547       1.1  macallan 	if (scr == oldscr)
    548       1.1  macallan 		return;
    549       1.1  macallan 
    550       1.1  macallan #ifdef DIAGNOSTIC
    551       1.1  macallan 	if (SCREEN_IS_VISIBLE(scr))
    552      1.14  macallan 		printf("vcons_switch_screen: already active");
    553       1.1  macallan #endif
    554       1.1  macallan 
    555       1.1  macallan #ifdef notyet
    556       1.1  macallan 	if (vd->currenttype != type) {
    557       1.1  macallan 		vcons_set_screentype(vd, type);
    558       1.1  macallan 		vd->currenttype = type;
    559       1.1  macallan 	}
    560       1.1  macallan #endif
    561       1.1  macallan 
    562       1.1  macallan 	SCREEN_VISIBLE(scr);
    563       1.1  macallan 	vd->active = scr;
    564       1.1  macallan 	vd->wanted = NULL;
    565       1.1  macallan 
    566      1.37  macallan #ifdef VCONS_DRAW_INTR
    567      1.37  macallan 	vcons_invalidate_cache(vd);
    568      1.37  macallan #endif
    569      1.37  macallan 
    570       1.1  macallan 	if (vd->show_screen_cb != NULL)
    571      1.38  macallan 		vd->show_screen_cb(scr, vd->show_screen_cookie);
    572       1.1  macallan 
    573       1.1  macallan 	if ((scr->scr_flags & VCONS_NO_REDRAW) == 0)
    574       1.1  macallan 		vcons_redraw_screen(scr);
    575       1.1  macallan 
    576       1.1  macallan 	if (vd->switch_cb)
    577       1.1  macallan 		vd->switch_cb(vd->switch_cb_arg, 0, 0);
    578       1.1  macallan }
    579       1.1  macallan 
    580       1.1  macallan void
    581       1.1  macallan vcons_redraw_screen(struct vcons_screen *scr)
    582       1.1  macallan {
    583      1.28  macallan 	uint32_t *charptr = scr->scr_chars, c;
    584      1.28  macallan 	long *attrptr = scr->scr_attrs, a, last_a = 0, mask, cmp, acmp;
    585       1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
    586      1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
    587      1.28  macallan 	int i, j, offset, boffset = 0, start = -1;
    588       1.1  macallan 
    589      1.28  macallan 	mask = 0x00ff00ff;	/* background and flags */
    590      1.36  macallan 	cmp = 0xffffffff;	/* never match anything */
    591       1.1  macallan 	vcons_lock(scr);
    592       1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    593       1.1  macallan 
    594       1.1  macallan 		/*
    595       1.1  macallan 		 * only clear the screen when RI_FULLCLEAR is set since we're
    596       1.1  macallan 		 * going to overwrite every single character cell anyway
    597       1.1  macallan 		 */
    598       1.1  macallan 		if (ri->ri_flg & RI_FULLCLEAR) {
    599      1.25  macallan 			vd->eraserows(ri, 0, ri->ri_rows,
    600       1.1  macallan 			    scr->scr_defattr);
    601      1.28  macallan 			cmp = scr->scr_defattr & mask;
    602       1.1  macallan 		}
    603       1.1  macallan 
    604       1.1  macallan 		/* redraw the screen */
    605      1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    606      1.14  macallan 		offset = scr->scr_current_offset;
    607      1.14  macallan #else
    608       1.1  macallan 		offset = 0;
    609      1.14  macallan #endif
    610       1.1  macallan 		for (i = 0; i < ri->ri_rows; i++) {
    611      1.28  macallan 			start = -1;
    612       1.1  macallan 			for (j = 0; j < ri->ri_cols; j++) {
    613       1.1  macallan 				/*
    614       1.1  macallan 				 * no need to use the wrapper function - we
    615       1.1  macallan 				 * don't change any characters or attributes
    616       1.1  macallan 				 * and we already made sure the screen we're
    617       1.1  macallan 				 * working on is visible
    618       1.1  macallan 				 */
    619      1.28  macallan 				c = charptr[offset];
    620      1.28  macallan 				a = attrptr[offset];
    621      1.28  macallan 				acmp = a & mask;
    622      1.28  macallan 				if (c == ' ') {
    623      1.28  macallan 					/*
    624      1.28  macallan 					 * if we already erased the background
    625      1.48  macallan 					 * and if this blank uses the same
    626      1.48  macallan 					 * colour and flags we don't need to do
    627      1.28  macallan 					 * anything here
    628      1.28  macallan 					 */
    629      1.45  macallan 					if (acmp == cmp && start == -1)
    630      1.28  macallan 						goto next;
    631      1.28  macallan 					/*
    632      1.28  macallan 					 * see if we can optimize things a
    633      1.28  macallan 					 * little bit by drawing stretches of
    634      1.28  macallan 					 * blanks using erasecols
    635      1.28  macallan 					 */
    636      1.28  macallan 
    637      1.28  macallan 					if (start == -1) {
    638      1.28  macallan 						start = j;
    639      1.28  macallan 						last_a = acmp;
    640      1.28  macallan 					} else if (acmp != last_a) {
    641      1.28  macallan 						/*
    642      1.28  macallan 						 * different attr, need to
    643      1.36  macallan 						 * flush & restart
    644      1.28  macallan 						 */
    645      1.28  macallan 						vd->erasecols(ri, i, start,
    646      1.28  macallan 						    j - start, last_a);
    647      1.36  macallan 						start = j;
    648      1.36  macallan 						last_a = acmp;
    649      1.28  macallan 					}
    650      1.28  macallan 				} else {
    651      1.28  macallan 					if (start != -1) {
    652      1.28  macallan 						vd->erasecols(ri, i, start,
    653      1.28  macallan 						    j - start, last_a);
    654      1.28  macallan 						start = -1;
    655      1.28  macallan 					}
    656      1.28  macallan 
    657      1.37  macallan 					scr->putchar(ri, i, j, c, a);
    658      1.28  macallan 				}
    659      1.28  macallan next:
    660      1.25  macallan #ifdef VCONS_DRAW_INTR
    661      1.25  macallan 				vd->chars[boffset] = charptr[offset];
    662      1.25  macallan 				vd->attrs[boffset] = attrptr[offset];
    663      1.25  macallan #endif
    664      1.25  macallan 				offset++;
    665      1.25  macallan 				boffset++;
    666      1.25  macallan 			}
    667      1.28  macallan 			/* end of the line - draw all defered blanks, if any */
    668      1.28  macallan 			if (start != -1) {
    669      1.28  macallan 				vd->erasecols(ri, i, start, j - start, last_a);
    670      1.28  macallan 			}
    671      1.25  macallan 		}
    672      1.25  macallan 		ri->ri_flg &= ~RI_CURSOR;
    673      1.25  macallan 		scr->scr_vd->cursor(ri, 1, ri->ri_crow, ri->ri_ccol);
    674      1.25  macallan #ifdef VCONS_DRAW_INTR
    675      1.25  macallan 		vd->cursor_offset = ri->ri_crow * ri->ri_cols + ri->ri_ccol;
    676      1.25  macallan #endif
    677      1.25  macallan 	}
    678      1.25  macallan 	vcons_unlock(scr);
    679      1.25  macallan }
    680      1.25  macallan 
    681      1.25  macallan #ifdef VCONS_DRAW_INTR
    682      1.25  macallan void
    683      1.25  macallan vcons_update_screen(struct vcons_screen *scr)
    684      1.25  macallan {
    685      1.27  macallan 	uint32_t *charptr = scr->scr_chars;
    686      1.25  macallan 	long *attrptr = scr->scr_attrs;
    687      1.25  macallan 	struct rasops_info *ri = &scr->scr_ri;
    688      1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
    689      1.25  macallan 	int i, j, offset, boffset = 0;
    690      1.25  macallan 
    691      1.25  macallan 	vcons_lock(scr);
    692      1.25  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    693      1.25  macallan 
    694      1.25  macallan 		/* redraw the screen */
    695      1.25  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    696      1.25  macallan 		offset = scr->scr_current_offset;
    697      1.25  macallan #else
    698      1.25  macallan 		offset = 0;
    699      1.25  macallan #endif
    700      1.25  macallan 		/*
    701      1.25  macallan 		 * we mark the character cell occupied by the cursor as dirty
    702      1.25  macallan 		 * so we don't have to deal with it
    703      1.25  macallan 		 * notice that this isn't necessarily the position where rasops
    704      1.25  macallan 		 * thinks it is, just where we drew it the last time
    705      1.25  macallan 		 */
    706      1.25  macallan 		if (vd->cursor_offset >= 0)
    707      1.25  macallan 			vd->attrs[vd->cursor_offset] = 0xffffffff;
    708      1.25  macallan 
    709      1.25  macallan 		for (i = 0; i < ri->ri_rows; i++) {
    710      1.25  macallan 			for (j = 0; j < ri->ri_cols; j++) {
    711      1.25  macallan 				/*
    712      1.25  macallan 				 * no need to use the wrapper function - we
    713      1.25  macallan 				 * don't change any characters or attributes
    714      1.25  macallan 				 * and we already made sure the screen we're
    715      1.25  macallan 				 * working on is visible
    716      1.25  macallan 				 */
    717      1.25  macallan 				if ((vd->chars[boffset] != charptr[offset]) ||
    718      1.25  macallan 				    (vd->attrs[boffset] != attrptr[offset])) {
    719      1.37  macallan 					scr->putchar(ri, i, j,
    720      1.25  macallan 				 	   charptr[offset], attrptr[offset]);
    721      1.25  macallan 					vd->chars[boffset] = charptr[offset];
    722      1.25  macallan 					vd->attrs[boffset] = attrptr[offset];
    723      1.25  macallan 				}
    724       1.1  macallan 				offset++;
    725      1.25  macallan 				boffset++;
    726       1.1  macallan 			}
    727       1.1  macallan 		}
    728       1.1  macallan 		ri->ri_flg &= ~RI_CURSOR;
    729       1.1  macallan 		scr->scr_vd->cursor(ri, 1, ri->ri_crow, ri->ri_ccol);
    730      1.25  macallan 		vd->cursor_offset = ri->ri_crow * ri->ri_cols + ri->ri_ccol;
    731       1.1  macallan 	}
    732       1.1  macallan 	vcons_unlock(scr);
    733       1.1  macallan }
    734      1.25  macallan #endif
    735       1.1  macallan 
    736       1.1  macallan static int
    737      1.10  christos vcons_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    738       1.6      jmmv 	struct lwp *l)
    739       1.6      jmmv {
    740       1.6      jmmv 	struct vcons_data *vd = v;
    741      1.27  macallan 	int error = 0;
    742      1.27  macallan 
    743       1.6      jmmv 
    744       1.6      jmmv 	switch (cmd) {
    745       1.6      jmmv 	case WSDISPLAYIO_GETWSCHAR:
    746       1.6      jmmv 		error = vcons_getwschar((struct vcons_screen *)vs,
    747       1.6      jmmv 			(struct wsdisplay_char *)data);
    748       1.6      jmmv 		break;
    749       1.6      jmmv 
    750       1.6      jmmv 	case WSDISPLAYIO_PUTWSCHAR:
    751       1.6      jmmv 		error = vcons_putwschar((struct vcons_screen *)vs,
    752       1.6      jmmv 			(struct wsdisplay_char *)data);
    753       1.6      jmmv 		break;
    754       1.6      jmmv 
    755      1.27  macallan 	case WSDISPLAYIO_SET_POLLING: {
    756      1.27  macallan 		int poll = *(int *)data;
    757      1.27  macallan 
    758      1.27  macallan 		/* first call the driver's ioctl handler */
    759      1.27  macallan 		if (vd->ioctl != NULL)
    760      1.27  macallan 			error = (*vd->ioctl)(v, vs, cmd, data, flag, l);
    761      1.27  macallan 		if (poll) {
    762      1.27  macallan 			vcons_enable_polling(vd);
    763      1.27  macallan 			vcons_hard_switch(LIST_FIRST(&vd->screens));
    764      1.27  macallan 		} else
    765      1.27  macallan 			vcons_disable_polling(vd);
    766      1.27  macallan 		}
    767      1.27  macallan 		break;
    768      1.27  macallan 
    769       1.6      jmmv 	default:
    770       1.6      jmmv 		if (vd->ioctl != NULL)
    771       1.6      jmmv 			error = (*vd->ioctl)(v, vs, cmd, data, flag, l);
    772       1.6      jmmv 		else
    773       1.6      jmmv 			error = EPASSTHROUGH;
    774       1.6      jmmv 	}
    775       1.6      jmmv 
    776       1.6      jmmv 	return error;
    777       1.6      jmmv }
    778       1.6      jmmv 
    779       1.6      jmmv static int
    780       1.1  macallan vcons_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    781       1.1  macallan     int *curxp, int *curyp, long *defattrp)
    782       1.1  macallan {
    783       1.1  macallan 	struct vcons_data *vd = v;
    784       1.1  macallan 	struct vcons_screen *scr;
    785      1.37  macallan 	struct wsscreen_descr *t = __UNCONST(type);
    786       1.1  macallan 	int ret;
    787       1.1  macallan 
    788       1.1  macallan 	scr = malloc(sizeof(struct vcons_screen), M_DEVBUF, M_WAITOK | M_ZERO);
    789       1.1  macallan 	if (scr == NULL)
    790       1.1  macallan 		return ENOMEM;
    791       1.1  macallan 
    792       1.1  macallan 	scr->scr_flags = 0;
    793       1.2  macallan 	scr->scr_status = 0;
    794       1.2  macallan 	scr->scr_busy = 0;
    795      1.37  macallan 	scr->scr_type = __UNCONST(type);
    796       1.1  macallan 
    797       1.1  macallan 	ret = vcons_init_screen(vd, scr, 0, defattrp);
    798       1.1  macallan 	if (ret != 0) {
    799       1.1  macallan 		free(scr, M_DEVBUF);
    800       1.1  macallan 		return ret;
    801       1.1  macallan 	}
    802      1.37  macallan 	if (t->capabilities & WSSCREEN_RESIZE) {
    803      1.37  macallan 		t->nrows = scr->scr_ri.ri_rows;
    804      1.37  macallan 		t->ncols = scr->scr_ri.ri_cols;
    805      1.37  macallan 	}
    806       1.1  macallan 
    807       1.1  macallan 	if (vd->active == NULL) {
    808       1.1  macallan 		SCREEN_VISIBLE(scr);
    809       1.1  macallan 		vd->active = scr;
    810       1.1  macallan 		vd->currenttype = type;
    811       1.1  macallan 	}
    812       1.1  macallan 
    813       1.1  macallan 	*cookiep = scr;
    814       1.1  macallan 	*curxp = scr->scr_ri.ri_ccol;
    815       1.1  macallan 	*curyp = scr->scr_ri.ri_crow;
    816       1.1  macallan 	return 0;
    817       1.1  macallan }
    818       1.1  macallan 
    819       1.1  macallan static void
    820       1.1  macallan vcons_free_screen(void *v, void *cookie)
    821       1.1  macallan {
    822       1.1  macallan 	struct vcons_data *vd = v;
    823       1.1  macallan 	struct vcons_screen *scr = cookie;
    824       1.1  macallan 
    825       1.1  macallan 	vcons_lock(scr);
    826       1.1  macallan 	/* there should be no rasops activity here */
    827       1.1  macallan 
    828       1.1  macallan 	LIST_REMOVE(scr, next);
    829       1.1  macallan 
    830       1.1  macallan 	if ((scr->scr_flags & VCONS_SCREEN_IS_STATIC) == 0) {
    831       1.1  macallan 		free(scr->scr_attrs, M_DEVBUF);
    832       1.1  macallan 		free(scr, M_DEVBUF);
    833       1.1  macallan 	} else {
    834       1.1  macallan 		/*
    835       1.1  macallan 		 * maybe we should just restore the old rasops_info methods
    836       1.1  macallan 		 * and free the character/attribute buffer here?
    837       1.1  macallan 		 */
    838       1.1  macallan #ifdef VCONS_DEBUG
    839       1.1  macallan 		panic("vcons_free_screen: console");
    840       1.1  macallan #else
    841       1.1  macallan 		printf("vcons_free_screen: console\n");
    842       1.1  macallan #endif
    843       1.1  macallan 	}
    844       1.1  macallan 
    845       1.1  macallan 	if (vd->active == scr)
    846       1.1  macallan 		vd->active = NULL;
    847       1.1  macallan }
    848       1.1  macallan 
    849       1.1  macallan static int
    850       1.9  christos vcons_show_screen(void *v, void *cookie, int waitok,
    851       1.1  macallan     void (*cb)(void *, int, int), void *cb_arg)
    852       1.1  macallan {
    853       1.1  macallan 	struct vcons_data *vd = v;
    854       1.1  macallan 	struct vcons_screen *scr;
    855       1.1  macallan 
    856       1.1  macallan 	scr = cookie;
    857       1.1  macallan 	if (scr == vd->active)
    858       1.1  macallan 		return 0;
    859       1.1  macallan 
    860       1.1  macallan 	vd->wanted = scr;
    861       1.1  macallan 	vd->switch_cb = cb;
    862       1.1  macallan 	vd->switch_cb_arg = cb_arg;
    863       1.1  macallan 	if (cb) {
    864      1.15     joerg 		callout_schedule(&vd->switch_callout, 0);
    865       1.1  macallan 		return EAGAIN;
    866       1.1  macallan 	}
    867       1.1  macallan 
    868       1.1  macallan 	vcons_do_switch(vd);
    869       1.1  macallan 	return 0;
    870       1.1  macallan }
    871       1.1  macallan 
    872       1.1  macallan /* wrappers for rasops_info methods */
    873       1.1  macallan 
    874       1.1  macallan static void
    875       1.1  macallan vcons_copycols_buffer(void *cookie, int row, int srccol, int dstcol, int ncols)
    876       1.1  macallan {
    877       1.1  macallan 	struct rasops_info *ri = cookie;
    878       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    879       1.1  macallan 	int from = srccol + row * ri->ri_cols;
    880       1.1  macallan 	int to = dstcol + row * ri->ri_cols;
    881       1.1  macallan 
    882      1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    883      1.14  macallan 	int offset;
    884      1.14  macallan 	offset = scr->scr_offset_to_zero;
    885      1.14  macallan 
    886      1.14  macallan 	memmove(&scr->scr_attrs[offset + to], &scr->scr_attrs[offset + from],
    887      1.14  macallan 	    ncols * sizeof(long));
    888      1.14  macallan 	memmove(&scr->scr_chars[offset + to], &scr->scr_chars[offset + from],
    889      1.27  macallan 	    ncols * sizeof(uint32_t));
    890      1.14  macallan #else
    891       1.1  macallan 	memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
    892       1.1  macallan 	    ncols * sizeof(long));
    893       1.1  macallan 	memmove(&scr->scr_chars[to], &scr->scr_chars[from],
    894      1.27  macallan 	    ncols * sizeof(uint32_t));
    895      1.14  macallan #endif
    896      1.20  jmcneill 
    897      1.20  jmcneill #ifdef VCONS_DRAW_INTR
    898      1.22  jmcneill 	atomic_inc_uint(&scr->scr_dirty);
    899      1.20  jmcneill #endif
    900       1.1  macallan }
    901       1.1  macallan 
    902       1.1  macallan static void
    903       1.1  macallan vcons_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
    904       1.1  macallan {
    905       1.1  macallan 	struct rasops_info *ri = cookie;
    906       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    907       1.1  macallan 
    908       1.1  macallan 	vcons_copycols_buffer(cookie, row, srccol, dstcol, ncols);
    909       1.1  macallan 
    910      1.21  jmcneill #if defined(VCONS_DRAW_INTR)
    911      1.21  jmcneill 	if (scr->scr_vd->use_intr)
    912      1.21  jmcneill 		return;
    913      1.21  jmcneill #endif
    914      1.21  jmcneill 
    915       1.1  macallan 	vcons_lock(scr);
    916       1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    917      1.34   mlelstv #if defined(VCONS_DRAW_INTR)
    918      1.34   mlelstv 		vcons_update_screen(scr);
    919      1.34   mlelstv #else
    920      1.26  macallan 		scr->scr_vd->copycols(cookie, row, srccol, dstcol, ncols);
    921      1.30   mlelstv #endif
    922       1.1  macallan 	}
    923       1.1  macallan 	vcons_unlock(scr);
    924       1.1  macallan }
    925       1.1  macallan 
    926       1.1  macallan static void
    927      1.17  macallan vcons_copycols_noread(void *cookie, int row, int srccol, int dstcol, int ncols)
    928      1.17  macallan {
    929      1.17  macallan 	struct rasops_info *ri = cookie;
    930      1.17  macallan 	struct vcons_screen *scr = ri->ri_hw;
    931      1.37  macallan #ifdef VCONS_DRAW_INTR
    932      1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
    933      1.37  macallan #endif
    934      1.17  macallan 
    935      1.30   mlelstv 	vcons_lock(scr);
    936      1.17  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
    937      1.25  macallan 		int pos, c, offset, ppos;
    938      1.17  macallan 
    939      1.17  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    940      1.17  macallan 		offset = scr->scr_current_offset;
    941      1.17  macallan #else
    942      1.17  macallan 		offset = 0;
    943      1.17  macallan #endif
    944      1.25  macallan 		ppos = ri->ri_cols * row + dstcol;
    945      1.25  macallan 		pos = ppos + offset;
    946      1.17  macallan 		for (c = dstcol; c < (dstcol + ncols); c++) {
    947      1.25  macallan #ifdef VCONS_DRAW_INTR
    948      1.25  macallan 			if ((scr->scr_chars[pos] != vd->chars[ppos]) ||
    949      1.25  macallan 			    (scr->scr_attrs[pos] != vd->attrs[ppos])) {
    950      1.37  macallan 				scr->putchar(cookie, row, c,
    951      1.25  macallan 				   scr->scr_chars[pos], scr->scr_attrs[pos]);
    952      1.25  macallan 				vd->chars[ppos] = scr->scr_chars[pos];
    953      1.25  macallan 				vd->attrs[ppos] = scr->scr_attrs[pos];
    954      1.25  macallan 			}
    955      1.25  macallan #else
    956      1.37  macallan 			scr->putchar(cookie, row, c, scr->scr_chars[pos],
    957      1.25  macallan 			    scr->scr_attrs[pos]);
    958      1.25  macallan #endif
    959      1.17  macallan 			pos++;
    960      1.25  macallan 			ppos++;
    961      1.17  macallan 		}
    962      1.50  macallan 		if (ri->ri_crow == row &&
    963      1.50  macallan 		   (ri->ri_ccol >= dstcol && ri->ri_ccol < (dstcol + ncols )))
    964      1.50  macallan 			ri->ri_flg &= ~RI_CURSOR;
    965      1.17  macallan 	}
    966      1.30   mlelstv 	vcons_unlock(scr);
    967      1.17  macallan }
    968      1.17  macallan 
    969      1.17  macallan static void
    970       1.1  macallan vcons_erasecols_buffer(void *cookie, int row, int startcol, int ncols, long fillattr)
    971       1.1  macallan {
    972       1.1  macallan 	struct rasops_info *ri = cookie;
    973       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    974       1.1  macallan 	int start = startcol + row * ri->ri_cols;
    975       1.1  macallan 	int end = start + ncols, i;
    976       1.1  macallan 
    977      1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
    978      1.14  macallan 	int offset;
    979      1.14  macallan 	offset = scr->scr_offset_to_zero;
    980      1.14  macallan 
    981      1.14  macallan 	for (i = start; i < end; i++) {
    982      1.14  macallan 		scr->scr_attrs[offset + i] = fillattr;
    983      1.14  macallan 		scr->scr_chars[offset + i] = 0x20;
    984      1.14  macallan 	}
    985      1.14  macallan #else
    986       1.1  macallan 	for (i = start; i < end; i++) {
    987       1.1  macallan 		scr->scr_attrs[i] = fillattr;
    988       1.1  macallan 		scr->scr_chars[i] = 0x20;
    989       1.1  macallan 	}
    990      1.14  macallan #endif
    991      1.20  jmcneill 
    992      1.20  jmcneill #ifdef VCONS_DRAW_INTR
    993      1.22  jmcneill 	atomic_inc_uint(&scr->scr_dirty);
    994      1.20  jmcneill #endif
    995       1.1  macallan }
    996       1.1  macallan 
    997      1.25  macallan #ifdef VCONS_DRAW_INTR
    998      1.25  macallan static void
    999      1.25  macallan vcons_erasecols_cached(void *cookie, int row, int startcol, int ncols, long fillattr)
   1000      1.25  macallan {
   1001      1.25  macallan 	struct rasops_info *ri = cookie;
   1002      1.25  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1003      1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
   1004      1.25  macallan 	int i, pos = row * ri->ri_cols + startcol;
   1005      1.25  macallan 
   1006      1.25  macallan 	for (i = pos; i < ncols; i++) {
   1007      1.25  macallan 		vd->chars[i] = 0x20;
   1008      1.25  macallan 		vd->attrs[i] = fillattr;
   1009      1.25  macallan 	}
   1010      1.25  macallan 	vd->erasecols(cookie, row, startcol, ncols, fillattr);
   1011      1.25  macallan }
   1012      1.25  macallan #endif
   1013      1.25  macallan 
   1014       1.1  macallan static void
   1015       1.1  macallan vcons_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
   1016       1.1  macallan {
   1017       1.1  macallan 	struct rasops_info *ri = cookie;
   1018       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1019       1.1  macallan 
   1020       1.1  macallan 	vcons_erasecols_buffer(cookie, row, startcol, ncols, fillattr);
   1021       1.1  macallan 
   1022      1.21  jmcneill #if defined(VCONS_DRAW_INTR)
   1023      1.21  jmcneill 	if (scr->scr_vd->use_intr)
   1024      1.21  jmcneill 		return;
   1025      1.21  jmcneill #endif
   1026      1.21  jmcneill 
   1027       1.1  macallan 	vcons_lock(scr);
   1028       1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
   1029      1.25  macallan #ifdef VCONS_DRAW_INTR
   1030      1.30   mlelstv 		vcons_erasecols_cached(cookie, row, startcol, ncols,
   1031      1.30   mlelstv 		    fillattr);
   1032      1.25  macallan #else
   1033      1.25  macallan 		scr->scr_vd->erasecols(cookie, row, startcol, ncols, fillattr);
   1034      1.25  macallan #endif
   1035       1.1  macallan 	}
   1036       1.1  macallan 	vcons_unlock(scr);
   1037       1.1  macallan }
   1038       1.1  macallan 
   1039       1.1  macallan static void
   1040       1.1  macallan vcons_copyrows_buffer(void *cookie, int srcrow, int dstrow, int nrows)
   1041       1.1  macallan {
   1042       1.1  macallan 	struct rasops_info *ri = cookie;
   1043       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1044       1.1  macallan 	int from, to, len;
   1045       1.1  macallan 
   1046      1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
   1047      1.14  macallan 	int offset;
   1048      1.14  macallan 	offset = scr->scr_offset_to_zero;
   1049      1.14  macallan 
   1050      1.14  macallan 	/* do we need to scroll the back buffer? */
   1051      1.14  macallan 	if (dstrow == 0) {
   1052      1.14  macallan 		from = ri->ri_cols * srcrow;
   1053      1.14  macallan 		to = ri->ri_cols * dstrow;
   1054      1.14  macallan 
   1055      1.14  macallan 		memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
   1056      1.14  macallan 		    scr->scr_offset_to_zero * sizeof(long));
   1057      1.14  macallan 		memmove(&scr->scr_chars[to], &scr->scr_chars[from],
   1058      1.27  macallan 		    scr->scr_offset_to_zero * sizeof(uint32_t));
   1059      1.14  macallan 	}
   1060      1.14  macallan 	from = ri->ri_cols * srcrow + offset;
   1061      1.14  macallan 	to = ri->ri_cols * dstrow + offset;
   1062      1.14  macallan 	len = ri->ri_cols * nrows;
   1063      1.14  macallan 
   1064      1.14  macallan #else
   1065       1.1  macallan 	from = ri->ri_cols * srcrow;
   1066       1.1  macallan 	to = ri->ri_cols * dstrow;
   1067       1.1  macallan 	len = ri->ri_cols * nrows;
   1068      1.14  macallan #endif
   1069       1.1  macallan 	memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
   1070       1.1  macallan 	    len * sizeof(long));
   1071       1.1  macallan 	memmove(&scr->scr_chars[to], &scr->scr_chars[from],
   1072      1.27  macallan 	    len * sizeof(uint32_t));
   1073      1.20  jmcneill 
   1074      1.20  jmcneill #ifdef VCONS_DRAW_INTR
   1075      1.22  jmcneill 	atomic_inc_uint(&scr->scr_dirty);
   1076      1.20  jmcneill #endif
   1077       1.1  macallan }
   1078       1.1  macallan 
   1079       1.1  macallan static void
   1080       1.1  macallan vcons_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
   1081       1.1  macallan {
   1082       1.1  macallan 	struct rasops_info *ri = cookie;
   1083       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1084       1.1  macallan 
   1085       1.1  macallan 	vcons_copyrows_buffer(cookie, srcrow, dstrow, nrows);
   1086       1.1  macallan 
   1087      1.21  jmcneill #if defined(VCONS_DRAW_INTR)
   1088      1.21  jmcneill 	if (scr->scr_vd->use_intr)
   1089      1.21  jmcneill 		return;
   1090      1.21  jmcneill #endif
   1091      1.21  jmcneill 
   1092       1.1  macallan 	vcons_lock(scr);
   1093       1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
   1094      1.34   mlelstv #if defined(VCONS_DRAW_INTR)
   1095      1.34   mlelstv 		vcons_update_screen(scr);
   1096      1.34   mlelstv #else
   1097      1.26  macallan 		scr->scr_vd->copyrows(cookie, srcrow, dstrow, nrows);
   1098      1.30   mlelstv #endif
   1099       1.1  macallan 	}
   1100       1.1  macallan 	vcons_unlock(scr);
   1101       1.1  macallan }
   1102       1.1  macallan 
   1103       1.1  macallan static void
   1104      1.17  macallan vcons_copyrows_noread(void *cookie, int srcrow, int dstrow, int nrows)
   1105      1.17  macallan {
   1106      1.17  macallan 	struct rasops_info *ri = cookie;
   1107      1.17  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1108      1.37  macallan #ifdef VCONS_DRAW_INTR
   1109      1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
   1110      1.37  macallan #endif
   1111      1.30   mlelstv 	vcons_lock(scr);
   1112      1.17  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
   1113      1.25  macallan 		int pos, l, c, offset, ppos;
   1114      1.17  macallan 
   1115      1.17  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
   1116      1.17  macallan 		offset = scr->scr_current_offset;
   1117      1.17  macallan #else
   1118      1.17  macallan 		offset = 0;
   1119      1.17  macallan #endif
   1120      1.25  macallan 		ppos = ri->ri_cols * dstrow;
   1121      1.25  macallan 		pos = ppos + offset;
   1122      1.17  macallan 		for (l = dstrow; l < (dstrow + nrows); l++) {
   1123      1.17  macallan 			for (c = 0; c < ri->ri_cols; c++) {
   1124      1.25  macallan #ifdef VCONS_DRAW_INTR
   1125      1.25  macallan 				if ((scr->scr_chars[pos] != vd->chars[ppos]) ||
   1126      1.25  macallan 				    (scr->scr_attrs[pos] != vd->attrs[ppos])) {
   1127      1.37  macallan 					scr->putchar(cookie, l, c,
   1128      1.25  macallan 					   scr->scr_chars[pos], scr->scr_attrs[pos]);
   1129      1.25  macallan 					vd->chars[ppos] = scr->scr_chars[pos];
   1130      1.25  macallan 					vd->attrs[ppos] = scr->scr_attrs[pos];
   1131      1.25  macallan 				}
   1132      1.25  macallan #else
   1133      1.37  macallan 				scr->putchar(cookie, l, c, scr->scr_chars[pos],
   1134      1.25  macallan 				    scr->scr_attrs[pos]);
   1135      1.25  macallan #endif
   1136      1.17  macallan 				pos++;
   1137      1.25  macallan 				ppos++;
   1138      1.17  macallan 			}
   1139      1.17  macallan 		}
   1140      1.50  macallan 		if (ri->ri_crow >= dstrow && ri->ri_crow < (dstrow + nrows))
   1141      1.50  macallan 			ri->ri_flg &= ~RI_CURSOR;
   1142      1.17  macallan 	}
   1143      1.30   mlelstv 	vcons_unlock(scr);
   1144      1.17  macallan }
   1145      1.17  macallan 
   1146      1.17  macallan static void
   1147       1.1  macallan vcons_eraserows_buffer(void *cookie, int row, int nrows, long fillattr)
   1148       1.1  macallan {
   1149       1.1  macallan 	struct rasops_info *ri = cookie;
   1150       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1151       1.1  macallan 	int start, end, i;
   1152       1.1  macallan 
   1153      1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
   1154      1.14  macallan 	int offset;
   1155      1.14  macallan 	offset = scr->scr_offset_to_zero;
   1156      1.14  macallan 
   1157      1.14  macallan 	start = ri->ri_cols * row + offset;
   1158      1.14  macallan 	end = ri->ri_cols * (row + nrows) + offset;
   1159      1.14  macallan #else
   1160       1.1  macallan 	start = ri->ri_cols * row;
   1161       1.1  macallan 	end = ri->ri_cols * (row + nrows);
   1162      1.14  macallan #endif
   1163       1.1  macallan 
   1164       1.1  macallan 	for (i = start; i < end; i++) {
   1165       1.1  macallan 		scr->scr_attrs[i] = fillattr;
   1166       1.1  macallan 		scr->scr_chars[i] = 0x20;
   1167       1.1  macallan 	}
   1168      1.20  jmcneill 
   1169      1.20  jmcneill #ifdef VCONS_DRAW_INTR
   1170      1.22  jmcneill 	atomic_inc_uint(&scr->scr_dirty);
   1171      1.20  jmcneill #endif
   1172       1.1  macallan }
   1173       1.1  macallan 
   1174      1.30   mlelstv #ifdef VCONS_DRAW_INTR
   1175      1.30   mlelstv static void
   1176      1.30   mlelstv vcons_eraserows_cached(void *cookie, int row, int nrows, long fillattr)
   1177      1.30   mlelstv {
   1178      1.30   mlelstv 	struct rasops_info *ri = cookie;
   1179      1.30   mlelstv 	struct vcons_screen *scr = ri->ri_hw;
   1180      1.30   mlelstv 	struct vcons_data *vd = scr->scr_vd;
   1181      1.30   mlelstv 	int i, pos = row * ri->ri_cols, end = (row+nrows) * ri->ri_cols;
   1182      1.30   mlelstv 
   1183      1.30   mlelstv 	for (i = pos; i < end; i++) {
   1184      1.30   mlelstv 		vd->chars[i] = 0x20;
   1185      1.30   mlelstv 		vd->attrs[i] = fillattr;
   1186      1.30   mlelstv 	}
   1187      1.30   mlelstv 	vd->eraserows(cookie, row, nrows, fillattr);
   1188      1.30   mlelstv }
   1189      1.30   mlelstv #endif
   1190      1.30   mlelstv 
   1191       1.1  macallan static void
   1192       1.1  macallan vcons_eraserows(void *cookie, int row, int nrows, long fillattr)
   1193       1.1  macallan {
   1194       1.1  macallan 	struct rasops_info *ri = cookie;
   1195       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1196       1.1  macallan 
   1197       1.1  macallan 	vcons_eraserows_buffer(cookie, row, nrows, fillattr);
   1198       1.1  macallan 
   1199      1.21  jmcneill #if defined(VCONS_DRAW_INTR)
   1200      1.21  jmcneill 	if (scr->scr_vd->use_intr)
   1201      1.21  jmcneill 		return;
   1202      1.21  jmcneill #endif
   1203      1.21  jmcneill 
   1204       1.1  macallan 	vcons_lock(scr);
   1205       1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
   1206      1.30   mlelstv #ifdef VCONS_DRAW_INTR
   1207      1.30   mlelstv 		vcons_eraserows_cached(cookie, row, nrows, fillattr);
   1208      1.30   mlelstv #else
   1209      1.25  macallan 		scr->scr_vd->eraserows(cookie, row, nrows, fillattr);
   1210      1.30   mlelstv #endif
   1211       1.1  macallan 	}
   1212       1.1  macallan 	vcons_unlock(scr);
   1213       1.1  macallan }
   1214       1.1  macallan 
   1215       1.1  macallan static void
   1216       1.1  macallan vcons_putchar_buffer(void *cookie, int row, int col, u_int c, long attr)
   1217       1.1  macallan {
   1218       1.1  macallan 	struct rasops_info *ri = cookie;
   1219       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1220       1.1  macallan 	int pos;
   1221       1.1  macallan 
   1222      1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
   1223      1.14  macallan 	int offset;
   1224      1.14  macallan 	offset = scr->scr_offset_to_zero;
   1225      1.14  macallan 
   1226      1.14  macallan 	if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
   1227      1.14  macallan 	     (col < ri->ri_cols)) {
   1228      1.14  macallan 		pos = col + row * ri->ri_cols;
   1229      1.14  macallan 		scr->scr_attrs[pos + offset] = attr;
   1230      1.14  macallan 		scr->scr_chars[pos + offset] = c;
   1231      1.14  macallan 	}
   1232      1.14  macallan #else
   1233       1.1  macallan 	if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
   1234       1.1  macallan 	     (col < ri->ri_cols)) {
   1235       1.1  macallan 		pos = col + row * ri->ri_cols;
   1236       1.1  macallan 		scr->scr_attrs[pos] = attr;
   1237       1.1  macallan 		scr->scr_chars[pos] = c;
   1238       1.1  macallan 	}
   1239      1.14  macallan #endif
   1240      1.20  jmcneill 
   1241      1.20  jmcneill #ifdef VCONS_DRAW_INTR
   1242      1.22  jmcneill 	atomic_inc_uint(&scr->scr_dirty);
   1243      1.20  jmcneill #endif
   1244       1.1  macallan }
   1245       1.1  macallan 
   1246      1.25  macallan #ifdef VCONS_DRAW_INTR
   1247      1.25  macallan static void
   1248      1.25  macallan vcons_putchar_cached(void *cookie, int row, int col, u_int c, long attr)
   1249      1.25  macallan {
   1250      1.25  macallan 	struct rasops_info *ri = cookie;
   1251      1.25  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1252      1.25  macallan 	struct vcons_data *vd = scr->scr_vd;
   1253      1.25  macallan 	int pos = row * ri->ri_cols + col;
   1254      1.25  macallan 
   1255      1.25  macallan 	if ((vd->chars == NULL) || (vd->attrs == NULL)) {
   1256      1.37  macallan 		scr->putchar(cookie, row, col, c, attr);
   1257      1.25  macallan 		return;
   1258      1.25  macallan 	}
   1259      1.25  macallan 	if ((vd->chars[pos] != c) || (vd->attrs[pos] != attr)) {
   1260      1.25  macallan 		vd->attrs[pos] = attr;
   1261      1.25  macallan 		vd->chars[pos] = c;
   1262      1.37  macallan 		scr->putchar(cookie, row, col, c, attr);
   1263      1.25  macallan 	}
   1264      1.25  macallan }
   1265      1.25  macallan #endif
   1266      1.25  macallan 
   1267       1.1  macallan static void
   1268       1.1  macallan vcons_putchar(void *cookie, int row, int col, u_int c, long attr)
   1269       1.1  macallan {
   1270       1.1  macallan 	struct rasops_info *ri = cookie;
   1271       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1272       1.1  macallan 
   1273       1.1  macallan 	vcons_putchar_buffer(cookie, row, col, c, attr);
   1274      1.21  jmcneill 
   1275      1.21  jmcneill #if defined(VCONS_DRAW_INTR)
   1276      1.21  jmcneill 	if (scr->scr_vd->use_intr)
   1277      1.21  jmcneill 		return;
   1278      1.21  jmcneill #endif
   1279      1.21  jmcneill 
   1280       1.1  macallan 	vcons_lock(scr);
   1281       1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
   1282      1.25  macallan #ifdef VCONS_DRAW_INTR
   1283      1.25  macallan 		vcons_putchar_cached(cookie, row, col, c, attr);
   1284      1.25  macallan #else
   1285      1.49  macallan 		if (row == ri->ri_crow && col == ri->ri_ccol) {
   1286      1.49  macallan 			ri->ri_flg &= ~RI_CURSOR;
   1287      1.49  macallan 		}
   1288      1.37  macallan 		scr->putchar(cookie, row, col, c, attr);
   1289      1.25  macallan #endif
   1290       1.1  macallan 	}
   1291       1.1  macallan 	vcons_unlock(scr);
   1292       1.1  macallan }
   1293       1.1  macallan 
   1294       1.1  macallan static void
   1295       1.1  macallan vcons_cursor(void *cookie, int on, int row, int col)
   1296       1.1  macallan {
   1297       1.1  macallan 	struct rasops_info *ri = cookie;
   1298       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1299       1.1  macallan 
   1300      1.20  jmcneill 
   1301      1.20  jmcneill #if defined(VCONS_DRAW_INTR)
   1302      1.21  jmcneill 	if (scr->scr_vd->use_intr) {
   1303      1.21  jmcneill 		vcons_lock(scr);
   1304      1.21  jmcneill 		if (scr->scr_ri.ri_crow != row || scr->scr_ri.ri_ccol != col) {
   1305      1.21  jmcneill 			scr->scr_ri.ri_crow = row;
   1306      1.21  jmcneill 			scr->scr_ri.ri_ccol = col;
   1307      1.22  jmcneill 			atomic_inc_uint(&scr->scr_dirty);
   1308      1.21  jmcneill 		}
   1309      1.21  jmcneill 		vcons_unlock(scr);
   1310      1.21  jmcneill 		return;
   1311      1.20  jmcneill 	}
   1312      1.21  jmcneill #endif
   1313      1.21  jmcneill 
   1314      1.21  jmcneill 	vcons_lock(scr);
   1315      1.21  jmcneill 
   1316       1.5  macallan 	if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
   1317      1.26  macallan 		scr->scr_vd->cursor(cookie, on, row, col);
   1318       1.1  macallan 	} else {
   1319       1.1  macallan 		scr->scr_ri.ri_crow = row;
   1320       1.1  macallan 		scr->scr_ri.ri_ccol = col;
   1321       1.1  macallan 	}
   1322       1.1  macallan 	vcons_unlock(scr);
   1323       1.1  macallan }
   1324       1.1  macallan 
   1325      1.48  macallan static void
   1326      1.48  macallan vcons_cursor_noread(void *cookie, int on, int row, int col)
   1327      1.48  macallan {
   1328      1.48  macallan 	struct rasops_info *ri = cookie;
   1329      1.48  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1330      1.50  macallan 	int offset = 0, ofs;
   1331      1.48  macallan 
   1332      1.48  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
   1333      1.48  macallan 	offset = scr->scr_current_offset;
   1334      1.48  macallan #endif
   1335      1.50  macallan 	ofs = offset + ri->ri_crow * ri->ri_cols + ri->ri_ccol;
   1336      1.50  macallan 	if ((ri->ri_flg & RI_CURSOR) &&
   1337      1.51  macallan 	   (((scr->scr_flags & VCONS_DONT_READ) != VCONS_DONT_READ) || on)) {
   1338      1.50  macallan 		scr->putchar(cookie, ri->ri_crow, ri->ri_ccol,
   1339      1.50  macallan 		    scr->scr_chars[ofs], scr->scr_attrs[ofs]);
   1340      1.50  macallan 		ri->ri_flg &= ~RI_CURSOR;
   1341      1.50  macallan 	}
   1342      1.50  macallan 	ri->ri_crow = row;
   1343      1.50  macallan 	ri->ri_ccol = col;
   1344      1.50  macallan 	ofs = offset + ri->ri_crow * ri->ri_cols + ri->ri_ccol;
   1345      1.50  macallan 	if (on) {
   1346      1.50  macallan 		scr->putchar(cookie, row, col, scr->scr_chars[ofs],
   1347      1.48  macallan #ifdef VCONS_DEBUG_CURSOR_NOREAD
   1348      1.50  macallan 		/* draw a red cursor so we can tell which cursor()
   1349      1.50  macallan 		 * implementation is being used */
   1350      1.50  macallan 		    ((scr->scr_attrs[ofs] & 0xff00ffff) ^ 0x0f000000) |
   1351      1.50  macallan 		      0x00010000);
   1352      1.48  macallan #else
   1353      1.50  macallan 		    scr->scr_attrs[ofs] ^ 0x0f0f0000);
   1354      1.48  macallan #endif
   1355      1.50  macallan 		ri->ri_flg |= RI_CURSOR;
   1356      1.48  macallan 	}
   1357      1.48  macallan }
   1358      1.48  macallan 
   1359       1.1  macallan /* methods to read/write characters via ioctl() */
   1360       1.1  macallan 
   1361       1.1  macallan static int
   1362       1.6      jmmv vcons_putwschar(struct vcons_screen *scr, struct wsdisplay_char *wsc)
   1363       1.1  macallan {
   1364       1.1  macallan 	long attr;
   1365       1.6      jmmv 	struct rasops_info *ri;
   1366      1.35  christos 	int error;
   1367       1.6      jmmv 
   1368       1.6      jmmv 	KASSERT(scr != NULL && wsc != NULL);
   1369       1.6      jmmv 
   1370      1.13    rumble 	ri = &scr->scr_ri;
   1371      1.13    rumble 
   1372      1.44  macallan 	/* allow col as linear index if row == 0 */
   1373      1.44  macallan 	if (wsc->row == 0) {
   1374      1.44  macallan 		if (wsc->col < 0 || wsc->col > (ri->ri_cols * ri->ri_rows))
   1375      1.44  macallan 			return EINVAL;
   1376      1.44  macallan 	    	int rem;
   1377      1.44  macallan 	    	rem = wsc->col % ri->ri_cols;
   1378      1.44  macallan 	    	wsc->row = wsc->col / ri->ri_cols;
   1379      1.44  macallan 	    	DPRINTF("off %d -> %d, %d\n", wsc->col, rem, wsc->row);
   1380      1.44  macallan 	    	wsc->col = rem;
   1381      1.44  macallan 	} else {
   1382      1.44  macallan 		if (__predict_false(wsc->col < 0 || wsc->col >= ri->ri_cols))
   1383      1.12       mjf 			return (EINVAL);
   1384       1.1  macallan 
   1385      1.44  macallan 		if (__predict_false(wsc->row < 0 || wsc->row >= ri->ri_rows))
   1386      1.44  macallan 			return (EINVAL);
   1387      1.44  macallan 	}
   1388      1.14  macallan 
   1389      1.44  macallan 	error = ri->ri_ops.allocattr(ri, wsc->foreground,
   1390      1.44  macallan 	    wsc->background, wsc->flags, &attr);
   1391      1.44  macallan 	if (error)
   1392      1.44  macallan 		return error;
   1393      1.44  macallan 	vcons_putchar(ri, wsc->row, wsc->col, wsc->letter, attr);
   1394      1.14  macallan #ifdef VCONS_DEBUG
   1395      1.44  macallan 	printf("vcons_putwschar(%d, %d, %x, %lx\n", wsc->row, wsc->col,
   1396      1.44  macallan 	    wsc->letter, attr);
   1397      1.14  macallan #endif
   1398      1.44  macallan 	return 0;
   1399       1.1  macallan }
   1400       1.1  macallan 
   1401       1.1  macallan static int
   1402       1.6      jmmv vcons_getwschar(struct vcons_screen *scr, struct wsdisplay_char *wsc)
   1403       1.1  macallan {
   1404       1.6      jmmv 	int offset;
   1405       1.1  macallan 	long attr;
   1406       1.6      jmmv 	struct rasops_info *ri;
   1407  1.51.6.1      cjep 	int fg, bg, ul;
   1408       1.6      jmmv 
   1409       1.6      jmmv 	KASSERT(scr != NULL && wsc != NULL);
   1410       1.6      jmmv 
   1411       1.6      jmmv 	ri = &scr->scr_ri;
   1412       1.1  macallan 
   1413      1.44  macallan 	/* allow col as linear index if row == 0 */
   1414      1.44  macallan 	if (wsc->row == 0) {
   1415      1.44  macallan 		if (wsc->col < 0 || wsc->col > (ri->ri_cols * ri->ri_rows))
   1416      1.44  macallan 			return EINVAL;
   1417      1.44  macallan 	    	int rem;
   1418      1.44  macallan 	    	rem = wsc->col % ri->ri_cols;
   1419      1.44  macallan 	    	wsc->row = wsc->col / ri->ri_cols;
   1420      1.44  macallan 	    	DPRINTF("off %d -> %d, %d\n", wsc->col, rem, wsc->row);
   1421      1.44  macallan 	    	wsc->col = rem;
   1422      1.44  macallan 	} else {
   1423      1.44  macallan 		if (__predict_false(wsc->col < 0 || wsc->col >= ri->ri_cols))
   1424      1.44  macallan 			return (EINVAL);
   1425      1.44  macallan 
   1426      1.44  macallan 		if (__predict_false(wsc->row < 0 || wsc->row >= ri->ri_rows))
   1427      1.44  macallan 			return (EINVAL);
   1428      1.44  macallan 	}
   1429      1.14  macallan 
   1430      1.44  macallan 	offset = ri->ri_cols * wsc->row + wsc->col;
   1431      1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
   1432      1.44  macallan 	offset += scr->scr_offset_to_zero;
   1433      1.14  macallan #endif
   1434      1.44  macallan 	wsc->letter = scr->scr_chars[offset];
   1435      1.44  macallan 	attr = scr->scr_attrs[offset];
   1436      1.14  macallan 
   1437  1.51.6.1      cjep #ifdef VCONS_DEBUG
   1438  1.51.6.1      cjep 	printf("vcons_getwschar: %d, %d, %x, %lx\n", wsc->row,
   1439  1.51.6.1      cjep 	    wsc->col, wsc->letter, attr);
   1440  1.51.6.1      cjep #endif
   1441  1.51.6.1      cjep 
   1442      1.44  macallan 	/*
   1443      1.44  macallan 	 * this is ugly. We need to break up an attribute into colours and
   1444      1.44  macallan 	 * flags but there's no rasops method to do that so we must rely on
   1445      1.44  macallan 	 * the 'canonical' encoding.
   1446      1.44  macallan 	 */
   1447  1.51.6.1      cjep 
   1448  1.51.6.1      cjep 	/* only fetches underline attribute */
   1449  1.51.6.1      cjep 	/* rasops_unpack_attr(attr, &fg, &bg, &ul); */
   1450  1.51.6.1      cjep 	fg = (attr >> 24) & 0xf;
   1451  1.51.6.1      cjep 	bg = (attr >> 16) & 0xf;
   1452  1.51.6.1      cjep 	ul = (attr & 1);
   1453  1.51.6.1      cjep 
   1454  1.51.6.1      cjep 	wsc->foreground = fg;
   1455  1.51.6.1      cjep 	wsc->background = bg;
   1456  1.51.6.1      cjep 
   1457  1.51.6.1      cjep 	/* clear trashed bits and restore underline flag */
   1458  1.51.6.1      cjep 	attr &= ~(WSATTR_HILIT | WSATTR_BLINK | WSATTR_UNDERLINE);
   1459  1.51.6.1      cjep 	if (ul)
   1460  1.51.6.1      cjep 		attr |= WSATTR_UNDERLINE;
   1461  1.51.6.1      cjep 
   1462  1.51.6.1      cjep 	/* restore highlight boost */
   1463  1.51.6.1      cjep 	if (attr & WSATTR_HILIT)
   1464  1.51.6.1      cjep 		if (wsc->foreground >= 8)
   1465  1.51.6.1      cjep 			wsc->foreground -= 8;
   1466  1.51.6.1      cjep 
   1467  1.51.6.1      cjep 	/* we always use colors, even when not stored */
   1468  1.51.6.1      cjep 	attr |= WSATTR_WSCOLORS;
   1469      1.44  macallan 	return 0;
   1470      1.14  macallan }
   1471      1.14  macallan 
   1472      1.14  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
   1473      1.14  macallan 
   1474      1.14  macallan static void
   1475      1.14  macallan vcons_scroll(void *cookie, void *vs, int where)
   1476      1.14  macallan {
   1477      1.14  macallan 	struct vcons_screen *scr = vs;
   1478      1.14  macallan 
   1479      1.14  macallan 	if (where == 0) {
   1480      1.14  macallan 		scr->scr_line_wanted = 0;
   1481      1.14  macallan 	} else {
   1482      1.14  macallan 		scr->scr_line_wanted = scr->scr_line_wanted - where;
   1483      1.14  macallan 		if (scr->scr_line_wanted < 0)
   1484      1.14  macallan 			scr->scr_line_wanted = 0;
   1485      1.14  macallan 		if (scr->scr_line_wanted > scr->scr_lines_in_buffer)
   1486      1.14  macallan 			scr->scr_line_wanted = scr->scr_lines_in_buffer;
   1487      1.14  macallan 	}
   1488      1.14  macallan 
   1489      1.14  macallan 	if (scr->scr_line_wanted != scr->scr_current_line) {
   1490      1.14  macallan 
   1491      1.14  macallan 		vcons_do_scroll(scr);
   1492      1.14  macallan 	}
   1493      1.14  macallan }
   1494      1.14  macallan 
   1495      1.14  macallan static void
   1496      1.14  macallan vcons_do_scroll(struct vcons_screen *scr)
   1497      1.14  macallan {
   1498      1.14  macallan 	int dist, from, to, num;
   1499      1.14  macallan 	int r_offset, r_start;
   1500      1.14  macallan 	int i, j;
   1501      1.14  macallan 
   1502      1.14  macallan 	if (scr->scr_line_wanted == scr->scr_current_line)
   1503      1.14  macallan 		return;
   1504      1.14  macallan 	dist = scr->scr_line_wanted - scr->scr_current_line;
   1505      1.14  macallan 	scr->scr_current_line = scr->scr_line_wanted;
   1506      1.14  macallan 	scr->scr_current_offset = scr->scr_ri.ri_cols *
   1507      1.14  macallan 	    (scr->scr_lines_in_buffer - scr->scr_current_line);
   1508      1.14  macallan 	if (abs(dist) >= scr->scr_ri.ri_rows) {
   1509      1.14  macallan 		vcons_redraw_screen(scr);
   1510      1.14  macallan 		return;
   1511      1.14  macallan 	}
   1512      1.14  macallan 	/* scroll and redraw only what we really have to */
   1513      1.14  macallan 	if (dist > 0) {
   1514      1.14  macallan 		/* we scroll down */
   1515      1.14  macallan 		from = 0;
   1516      1.14  macallan 		to = dist;
   1517      1.14  macallan 		num = scr->scr_ri.ri_rows - dist;
   1518      1.14  macallan 		/* now the redraw parameters */
   1519      1.14  macallan 		r_offset = scr->scr_current_offset;
   1520      1.14  macallan 		r_start = 0;
   1521      1.14  macallan 	} else {
   1522      1.14  macallan 		/* scrolling up */
   1523      1.14  macallan 		to = 0;
   1524      1.14  macallan 		from = -dist;
   1525      1.14  macallan 		num = scr->scr_ri.ri_rows + dist;
   1526      1.14  macallan 		r_offset = scr->scr_current_offset + num * scr->scr_ri.ri_cols;
   1527      1.14  macallan 		r_start = num;
   1528      1.14  macallan 	}
   1529      1.14  macallan 	scr->scr_vd->copyrows(scr, from, to, num);
   1530      1.14  macallan 	for (i = 0; i < abs(dist); i++) {
   1531      1.14  macallan 		for (j = 0; j < scr->scr_ri.ri_cols; j++) {
   1532      1.25  macallan #ifdef VCONS_DRAW_INTR
   1533      1.25  macallan 			vcons_putchar_cached(scr, i + r_start, j,
   1534      1.25  macallan 			    scr->scr_chars[r_offset],
   1535      1.25  macallan 			    scr->scr_attrs[r_offset]);
   1536      1.25  macallan #else
   1537      1.37  macallan 			scr->putchar(scr, i + r_start, j,
   1538      1.14  macallan 			    scr->scr_chars[r_offset],
   1539      1.14  macallan 			    scr->scr_attrs[r_offset]);
   1540      1.25  macallan #endif
   1541      1.14  macallan 			r_offset++;
   1542      1.14  macallan 		}
   1543      1.14  macallan 	}
   1544      1.14  macallan 
   1545      1.14  macallan 	if (scr->scr_line_wanted == 0) {
   1546      1.14  macallan 		/* this was a reset - need to draw the cursor */
   1547      1.14  macallan 		scr->scr_ri.ri_flg &= ~RI_CURSOR;
   1548      1.14  macallan 		scr->scr_vd->cursor(scr, 1, scr->scr_ri.ri_crow,
   1549      1.14  macallan 		    scr->scr_ri.ri_ccol);
   1550      1.14  macallan 	}
   1551      1.14  macallan }
   1552      1.14  macallan 
   1553      1.14  macallan #endif /* WSDISPLAY_SCROLLSUPPORT */
   1554      1.14  macallan 
   1555      1.20  jmcneill #ifdef VCONS_DRAW_INTR
   1556      1.20  jmcneill static void
   1557      1.20  jmcneill vcons_intr(void *cookie)
   1558      1.20  jmcneill {
   1559      1.20  jmcneill 	struct vcons_data *vd = cookie;
   1560      1.20  jmcneill 
   1561      1.22  jmcneill 	softint_schedule(vd->intr_softint);
   1562      1.20  jmcneill }
   1563      1.20  jmcneill 
   1564      1.20  jmcneill static void
   1565      1.22  jmcneill vcons_softintr(void *cookie)
   1566      1.20  jmcneill {
   1567      1.20  jmcneill 	struct vcons_data *vd = cookie;
   1568      1.20  jmcneill 	struct vcons_screen *scr = vd->active;
   1569      1.22  jmcneill 	unsigned int dirty;
   1570      1.20  jmcneill 
   1571      1.30   mlelstv 	if (scr && vd->use_intr) {
   1572      1.22  jmcneill 		if (!SCREEN_IS_BUSY(scr)) {
   1573      1.22  jmcneill 			dirty = atomic_swap_uint(&scr->scr_dirty, 0);
   1574      1.30   mlelstv 			if (vd->use_intr == 2) {
   1575      1.30   mlelstv 				if ((scr->scr_flags & VCONS_NO_REDRAW) == 0) {
   1576      1.30   mlelstv 					vd->use_intr = 1;
   1577      1.30   mlelstv 					vcons_redraw_screen(scr);
   1578      1.30   mlelstv 				}
   1579      1.30   mlelstv 			} else if (dirty > 0) {
   1580      1.22  jmcneill 				if ((scr->scr_flags & VCONS_NO_REDRAW) == 0)
   1581      1.25  macallan 					vcons_update_screen(scr);
   1582      1.22  jmcneill 			}
   1583      1.20  jmcneill 		}
   1584      1.20  jmcneill 	}
   1585      1.20  jmcneill 
   1586      1.20  jmcneill 	callout_schedule(&vd->intr, mstohz(33));
   1587      1.20  jmcneill }
   1588      1.21  jmcneill 
   1589      1.47  jmcneill static void
   1590      1.47  jmcneill vcons_init_thread(void *cookie)
   1591      1.21  jmcneill {
   1592      1.47  jmcneill 	struct vcons_data *vd = (struct vcons_data *)cookie;
   1593      1.39   msaitoh 
   1594      1.30   mlelstv 	vd->use_intr = 2;
   1595      1.21  jmcneill 	callout_schedule(&vd->intr, mstohz(33));
   1596      1.47  jmcneill 	kthread_exit(0);
   1597      1.21  jmcneill }
   1598      1.20  jmcneill #endif /* VCONS_DRAW_INTR */
   1599      1.23  jmcneill 
   1600      1.23  jmcneill void
   1601      1.23  jmcneill vcons_enable_polling(struct vcons_data *vd)
   1602      1.23  jmcneill {
   1603      1.23  jmcneill 	struct vcons_screen *scr = vd->active;
   1604      1.23  jmcneill 
   1605      1.23  jmcneill #ifdef VCONS_DRAW_INTR
   1606      1.23  jmcneill 	vd->use_intr = 0;
   1607      1.23  jmcneill #endif
   1608      1.23  jmcneill 
   1609      1.23  jmcneill 	if (scr && !SCREEN_IS_BUSY(scr)) {
   1610      1.23  jmcneill 		if ((scr->scr_flags & VCONS_NO_REDRAW) == 0)
   1611      1.23  jmcneill 			vcons_redraw_screen(scr);
   1612      1.23  jmcneill 	}
   1613      1.23  jmcneill }
   1614      1.23  jmcneill 
   1615      1.23  jmcneill void
   1616      1.23  jmcneill vcons_disable_polling(struct vcons_data *vd)
   1617      1.23  jmcneill {
   1618      1.23  jmcneill #ifdef VCONS_DRAW_INTR
   1619      1.23  jmcneill 	struct vcons_screen *scr = vd->active;
   1620      1.23  jmcneill 
   1621      1.23  jmcneill 	if (!vd->intr_valid)
   1622      1.23  jmcneill 		return;
   1623      1.23  jmcneill 
   1624      1.30   mlelstv 	vd->use_intr = 2;
   1625      1.23  jmcneill 	if (scr)
   1626      1.23  jmcneill 		atomic_inc_uint(&scr->scr_dirty);
   1627      1.23  jmcneill #endif
   1628      1.23  jmcneill }
   1629      1.24  jmcneill 
   1630      1.24  jmcneill void
   1631      1.24  jmcneill vcons_hard_switch(struct vcons_screen *scr)
   1632      1.24  jmcneill {
   1633      1.24  jmcneill 	struct vcons_data *vd = scr->scr_vd;
   1634      1.24  jmcneill 	struct vcons_screen *oldscr = vd->active;
   1635      1.24  jmcneill 
   1636      1.24  jmcneill 	if (oldscr) {
   1637      1.24  jmcneill 		SCREEN_INVISIBLE(oldscr);
   1638      1.24  jmcneill 		oldscr->scr_ri.ri_flg &= ~RI_CURSOR;
   1639      1.24  jmcneill 	}
   1640      1.24  jmcneill 	SCREEN_VISIBLE(scr);
   1641      1.24  jmcneill 	vd->active = scr;
   1642      1.24  jmcneill 	vd->wanted = NULL;
   1643      1.24  jmcneill 
   1644      1.24  jmcneill 	if (vd->show_screen_cb != NULL)
   1645      1.38  macallan 		vd->show_screen_cb(scr, vd->show_screen_cookie);
   1646      1.24  jmcneill }
   1647      1.25  macallan 
   1648      1.25  macallan #ifdef VCONS_DRAW_INTR
   1649      1.25  macallan void
   1650      1.25  macallan vcons_invalidate_cache(struct vcons_data *vd)
   1651      1.25  macallan {
   1652      1.25  macallan 	int i;
   1653      1.25  macallan 
   1654      1.43  macallan 	for (i = 0; i < vd->cells; i++) {
   1655      1.25  macallan 		vd->chars[i] = -1;
   1656      1.25  macallan 		vd->attrs[i] = -1;
   1657      1.25  macallan 	}
   1658      1.25  macallan }
   1659      1.25  macallan #endif
   1660