Home | History | Annotate | Line # | Download | only in dev
vncfb.c revision 1.9
      1  1.9  jmcneill /* $NetBSD: vncfb.c,v 1.9 2011/12/30 19:32:32 jmcneill Exp $ */
      2  1.1  jmcneill 
      3  1.1  jmcneill /*-
      4  1.1  jmcneill  * Copyright (c) 2011 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  1.1  jmcneill  * All rights reserved.
      6  1.1  jmcneill  *
      7  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8  1.1  jmcneill  * modification, are permitted provided that the following conditions
      9  1.1  jmcneill  * are met:
     10  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12  1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15  1.1  jmcneill  * 3. All advertising materials mentioning features or use of this software
     16  1.1  jmcneill  *    must display the following acknowledgement:
     17  1.1  jmcneill  *        This product includes software developed by Jared D. McNeill.
     18  1.1  jmcneill  * 4. Neither the name of The NetBSD Foundation nor the names of its
     19  1.1  jmcneill  *    contributors may be used to endorse or promote products derived
     20  1.1  jmcneill  *    from this software without specific prior written permission.
     21  1.1  jmcneill  *
     22  1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     23  1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     24  1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     25  1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     26  1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27  1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28  1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29  1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30  1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31  1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32  1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     33  1.1  jmcneill  */
     34  1.1  jmcneill 
     35  1.1  jmcneill #include "opt_wsemul.h"
     36  1.1  jmcneill 
     37  1.1  jmcneill #include <sys/cdefs.h>
     38  1.9  jmcneill __KERNEL_RCSID(0, "$NetBSD: vncfb.c,v 1.9 2011/12/30 19:32:32 jmcneill Exp $");
     39  1.1  jmcneill 
     40  1.1  jmcneill #include <sys/param.h>
     41  1.1  jmcneill #include <sys/systm.h>
     42  1.1  jmcneill #include <sys/kernel.h>
     43  1.1  jmcneill #include <sys/device.h>
     44  1.1  jmcneill #include <sys/kmem.h>
     45  1.1  jmcneill 
     46  1.9  jmcneill #include <uvm/uvm_extern.h>
     47  1.9  jmcneill 
     48  1.1  jmcneill #include <dev/wscons/wsconsio.h>
     49  1.1  jmcneill 
     50  1.1  jmcneill #include <dev/wscons/wsdisplayvar.h>
     51  1.1  jmcneill #include <dev/wsfont/wsfont.h>
     52  1.1  jmcneill #include <dev/rasops/rasops.h>
     53  1.1  jmcneill #include <dev/wscons/wsdisplay_vconsvar.h>
     54  1.1  jmcneill 
     55  1.1  jmcneill #include <dev/wscons/wskbdvar.h>
     56  1.1  jmcneill #include <dev/wscons/wsksymdef.h>
     57  1.1  jmcneill #include <dev/wscons/wsksymvar.h>
     58  1.1  jmcneill 
     59  1.1  jmcneill #include <machine/mainbus.h>
     60  1.1  jmcneill #include <machine/thunk.h>
     61  1.1  jmcneill 
     62  1.9  jmcneill #define VNCFB_REFRESH_INTERVAL	33	/* fb refresh interval when mapped */
     63  1.9  jmcneill 
     64  1.1  jmcneill struct vncfb_fbops {
     65  1.1  jmcneill 	void	(*copycols)(void *, int, int, int, int);
     66  1.1  jmcneill 	void	(*erasecols)(void *, int, int, int, long);
     67  1.1  jmcneill 	void	(*copyrows)(void *, int, int, int);
     68  1.1  jmcneill 	void	(*eraserows)(void *, int, int, long);
     69  1.1  jmcneill 	void	(*putchar)(void *, int, int, u_int, long);
     70  1.2  jmcneill 	void	(*cursor)(void *, int, int, int);
     71  1.1  jmcneill };
     72  1.1  jmcneill 
     73  1.1  jmcneill struct vncfb_softc {
     74  1.1  jmcneill 	device_t		sc_dev;
     75  1.1  jmcneill 	device_t		sc_wskbddev;
     76  1.1  jmcneill 	thunk_rfb_t		sc_rfb;
     77  1.1  jmcneill 	unsigned int		sc_width;
     78  1.1  jmcneill 	unsigned int		sc_height;
     79  1.1  jmcneill 	unsigned int		sc_depth;
     80  1.1  jmcneill 	int			sc_mode;
     81  1.9  jmcneill 	uint8_t *		sc_mem;
     82  1.9  jmcneill 	size_t			sc_memsize;
     83  1.1  jmcneill 	uint8_t *		sc_framebuf;
     84  1.9  jmcneill 	size_t			sc_framebufsize;
     85  1.1  jmcneill 	struct vcons_data	sc_vd;
     86  1.1  jmcneill 	struct vncfb_fbops	sc_ops;
     87  1.1  jmcneill 
     88  1.1  jmcneill 	int			sc_kbd_enable;
     89  1.1  jmcneill 
     90  1.4  jmcneill 	void			*sc_ih;
     91  1.1  jmcneill 	void			*sc_sih;
     92  1.9  jmcneill 
     93  1.9  jmcneill 	callout_t		sc_callout;
     94  1.9  jmcneill 	void			*sc_refresh_sih;
     95  1.1  jmcneill };
     96  1.1  jmcneill 
     97  1.1  jmcneill static int	vncfb_match(device_t, cfdata_t, void *);
     98  1.1  jmcneill static void	vncfb_attach(device_t, device_t, void *);
     99  1.1  jmcneill 
    100  1.1  jmcneill CFATTACH_DECL_NEW(vncfb, sizeof(struct vncfb_softc),
    101  1.1  jmcneill     vncfb_match, vncfb_attach, NULL, NULL);
    102  1.1  jmcneill 
    103  1.1  jmcneill static void	vncfb_putchar(void *, int, int, u_int, long);
    104  1.1  jmcneill static void	vncfb_copycols(void *, int, int, int, int);
    105  1.1  jmcneill static void	vncfb_erasecols(void *, int, int, int, long);
    106  1.1  jmcneill static void	vncfb_copyrows(void *, int, int, int);
    107  1.1  jmcneill static void	vncfb_eraserows(void *, int, int, long);
    108  1.2  jmcneill static void	vncfb_cursor(void *, int, int, int);
    109  1.1  jmcneill 
    110  1.1  jmcneill static int	vncfb_ioctl(void *, void *, u_long, void *, int, lwp_t *);
    111  1.1  jmcneill static paddr_t	vncfb_mmap(void *, void *, off_t, int);
    112  1.1  jmcneill 
    113  1.1  jmcneill static void	vncfb_init_screen(void *, struct vcons_screen *, int, long *);
    114  1.1  jmcneill 
    115  1.1  jmcneill static void	vncfb_update(struct vncfb_softc *, int, int, int, int);
    116  1.7  jmcneill static void	vncfb_copyrect(struct vncfb_softc *, int, int, int, int, int, int);
    117  1.7  jmcneill static void	vncfb_fillrect(struct vncfb_softc *, int, int, int, int, uint32_t);
    118  1.4  jmcneill static int	vncfb_intr(void *);
    119  1.1  jmcneill static void	vncfb_softintr(void *);
    120  1.9  jmcneill static void	vncfb_refresh(void *);
    121  1.9  jmcneill static void	vncfb_softrefresh(void *);
    122  1.1  jmcneill 
    123  1.1  jmcneill static int	vncfb_kbd_enable(void *, int);
    124  1.1  jmcneill static void	vncfb_kbd_set_leds(void *, int);
    125  1.1  jmcneill static int	vncfb_kbd_ioctl(void *, u_long, void *, int, lwp_t *);
    126  1.1  jmcneill 
    127  1.1  jmcneill static void	vncfb_kbd_cngetc(void *, u_int *, int *);
    128  1.1  jmcneill static void	vncfb_kbd_cnpollc(void *, int);
    129  1.5  jmcneill static void	vncfb_kbd_bell(void *, u_int, u_int, u_int);
    130  1.1  jmcneill 
    131  1.1  jmcneill static struct vcons_screen vncfb_console_screen;
    132  1.1  jmcneill 
    133  1.1  jmcneill static struct wsscreen_descr vncfb_defaultscreen = {
    134  1.1  jmcneill 	.name = "default",
    135  1.1  jmcneill 	.fontwidth = 8,
    136  1.1  jmcneill 	.fontheight = 16,
    137  1.1  jmcneill 	.capabilities = WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    138  1.1  jmcneill };
    139  1.1  jmcneill 
    140  1.1  jmcneill static const struct wsscreen_descr *vncfb_screens[] = {
    141  1.1  jmcneill 	&vncfb_defaultscreen,
    142  1.1  jmcneill };
    143  1.1  jmcneill 
    144  1.1  jmcneill static struct wsscreen_list vncfb_screenlist = {
    145  1.1  jmcneill 	.screens = vncfb_screens,
    146  1.1  jmcneill 	.nscreens = __arraycount(vncfb_screens),
    147  1.1  jmcneill };
    148  1.1  jmcneill 
    149  1.1  jmcneill static struct wsdisplay_accessops vncfb_accessops = {
    150  1.1  jmcneill 	.ioctl = vncfb_ioctl,
    151  1.1  jmcneill 	.mmap = vncfb_mmap,
    152  1.1  jmcneill };
    153  1.1  jmcneill 
    154  1.1  jmcneill extern const struct wscons_keydesc vnckbd_keydesctab[];
    155  1.1  jmcneill 
    156  1.1  jmcneill static const struct wskbd_mapdata vncfb_keymapdata = {
    157  1.1  jmcneill 	vnckbd_keydesctab,
    158  1.1  jmcneill 	KB_US,
    159  1.1  jmcneill };
    160  1.1  jmcneill 
    161  1.1  jmcneill static struct wskbd_accessops vncfb_kbd_accessops = {
    162  1.1  jmcneill 	vncfb_kbd_enable,
    163  1.1  jmcneill 	vncfb_kbd_set_leds,
    164  1.1  jmcneill 	vncfb_kbd_ioctl,
    165  1.1  jmcneill };
    166  1.1  jmcneill 
    167  1.1  jmcneill static const struct wskbd_consops vncfb_kbd_consops = {
    168  1.1  jmcneill 	vncfb_kbd_cngetc,
    169  1.1  jmcneill 	vncfb_kbd_cnpollc,
    170  1.5  jmcneill 	vncfb_kbd_bell,
    171  1.1  jmcneill };
    172  1.1  jmcneill 
    173  1.1  jmcneill static int
    174  1.1  jmcneill vncfb_match(device_t parent, cfdata_t match, void *priv)
    175  1.1  jmcneill {
    176  1.1  jmcneill 	struct thunkbus_attach_args *taa = priv;
    177  1.1  jmcneill 
    178  1.1  jmcneill 	return taa->taa_type == THUNKBUS_TYPE_VNCFB;
    179  1.1  jmcneill }
    180  1.1  jmcneill 
    181  1.1  jmcneill static void
    182  1.1  jmcneill vncfb_attach(device_t parent, device_t self, void *priv)
    183  1.1  jmcneill {
    184  1.1  jmcneill 	struct vncfb_softc *sc = device_private(self);
    185  1.1  jmcneill 	struct thunkbus_attach_args *taa = priv;
    186  1.1  jmcneill 	struct wsemuldisplaydev_attach_args waa;
    187  1.1  jmcneill 	struct wskbddev_attach_args kaa;
    188  1.1  jmcneill 	struct rasops_info *ri;
    189  1.1  jmcneill 	unsigned long defattr;
    190  1.1  jmcneill 
    191  1.1  jmcneill 	sc->sc_dev = self;
    192  1.1  jmcneill 	sc->sc_width = taa->u.vnc.width;
    193  1.1  jmcneill 	sc->sc_height = taa->u.vnc.height;
    194  1.1  jmcneill 	sc->sc_depth = 32;
    195  1.1  jmcneill 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    196  1.1  jmcneill #if notyet
    197  1.1  jmcneill 	sc->sc_sockfd = thunk_vnc_open_socket(taa->u.vnc.port);
    198  1.1  jmcneill 	if (sc->sc_sockfd == -1)
    199  1.1  jmcneill 		panic("couldn't open VNC socket");
    200  1.1  jmcneill #endif
    201  1.1  jmcneill 
    202  1.9  jmcneill 	sc->sc_framebufsize = sc->sc_width * sc->sc_height * (sc->sc_depth / 8);
    203  1.9  jmcneill 	sc->sc_memsize = sc->sc_framebufsize + PAGE_SIZE;
    204  1.9  jmcneill 
    205  1.9  jmcneill 	sc->sc_mem = kmem_zalloc(sc->sc_memsize, KM_SLEEP);
    206  1.9  jmcneill 	sc->sc_framebuf = (void *)round_page((vaddr_t)sc->sc_mem);
    207  1.1  jmcneill 
    208  1.1  jmcneill 	aprint_naive("\n");
    209  1.1  jmcneill 	aprint_normal(": %ux%u %ubpp (port %u)\n",
    210  1.1  jmcneill 	    sc->sc_width, sc->sc_height, sc->sc_depth, taa->u.vnc.port);
    211  1.9  jmcneill 	aprint_normal_dev(self, "mem @ %p\n", sc->sc_mem);
    212  1.9  jmcneill 	aprint_normal_dev(self, "fb  @ %p\n", sc->sc_framebuf);
    213  1.1  jmcneill 
    214  1.1  jmcneill 	sc->sc_rfb.width = sc->sc_width;
    215  1.1  jmcneill 	sc->sc_rfb.height = sc->sc_height;
    216  1.1  jmcneill 	sc->sc_rfb.depth = sc->sc_depth;
    217  1.1  jmcneill 	sc->sc_rfb.framebuf = sc->sc_framebuf;
    218  1.1  jmcneill 	snprintf(sc->sc_rfb.name, sizeof(sc->sc_rfb.name),
    219  1.1  jmcneill 	    "NetBSD/usermode %d.%d.%d",
    220  1.1  jmcneill 	    __NetBSD_Version__ / 100000000,
    221  1.1  jmcneill 	    (__NetBSD_Version__ / 1000000) % 100,
    222  1.1  jmcneill 	    (__NetBSD_Version__ / 100) % 100);
    223  1.1  jmcneill 	if (thunk_rfb_open(&sc->sc_rfb, taa->u.vnc.port) != 0)
    224  1.1  jmcneill 		panic("couldn't open rfb server");
    225  1.1  jmcneill 
    226  1.1  jmcneill 	sc->sc_sih = softint_establish(SOFTINT_SERIAL, vncfb_softintr, sc);
    227  1.4  jmcneill 	sc->sc_ih = sigio_intr_establish(vncfb_intr, sc);
    228  1.1  jmcneill 
    229  1.9  jmcneill 	sc->sc_refresh_sih = softint_establish(SOFTINT_SERIAL,
    230  1.9  jmcneill 	    vncfb_softrefresh, sc);
    231  1.9  jmcneill 
    232  1.9  jmcneill 	callout_init(&sc->sc_callout, 0);
    233  1.9  jmcneill 	callout_setfunc(&sc->sc_callout, vncfb_refresh, sc);
    234  1.9  jmcneill 
    235  1.1  jmcneill 	vcons_init(&sc->sc_vd, sc, &vncfb_defaultscreen, &vncfb_accessops);
    236  1.1  jmcneill 	sc->sc_vd.init_screen = vncfb_init_screen;
    237  1.1  jmcneill 
    238  1.1  jmcneill 	ri = &vncfb_console_screen.scr_ri;
    239  1.1  jmcneill 	vcons_init_screen(&sc->sc_vd, &vncfb_console_screen, 1, &defattr);
    240  1.1  jmcneill 	vncfb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    241  1.1  jmcneill 	vncfb_defaultscreen.textops = &ri->ri_ops;
    242  1.1  jmcneill 	vncfb_defaultscreen.capabilities = ri->ri_caps;
    243  1.1  jmcneill 	vncfb_defaultscreen.nrows = ri->ri_rows;
    244  1.1  jmcneill 	vncfb_defaultscreen.ncols = ri->ri_cols;
    245  1.1  jmcneill 	wsdisplay_cnattach(&vncfb_defaultscreen, ri, 0, 0, defattr);
    246  1.1  jmcneill 
    247  1.1  jmcneill 	vcons_replay_msgbuf(&vncfb_console_screen);
    248  1.1  jmcneill 
    249  1.1  jmcneill 	waa.console = true;
    250  1.1  jmcneill 	waa.scrdata = &vncfb_screenlist;
    251  1.1  jmcneill 	waa.accessops = &vncfb_accessops;
    252  1.1  jmcneill 	waa.accesscookie = &sc->sc_vd;
    253  1.1  jmcneill 
    254  1.1  jmcneill 	config_found(self, &waa, wsemuldisplaydevprint);
    255  1.1  jmcneill 
    256  1.1  jmcneill 	wskbd_cnattach(&vncfb_kbd_consops, sc, &vncfb_keymapdata);
    257  1.1  jmcneill 
    258  1.1  jmcneill 	kaa.console = true;
    259  1.1  jmcneill 	kaa.keymap = &vncfb_keymapdata;
    260  1.1  jmcneill 	kaa.accessops = &vncfb_kbd_accessops;
    261  1.1  jmcneill 	kaa.accesscookie = sc;
    262  1.1  jmcneill 
    263  1.1  jmcneill 	sc->sc_wskbddev = config_found_ia(self, "wskbddev", &kaa,
    264  1.1  jmcneill 	    wskbddevprint);
    265  1.1  jmcneill }
    266  1.1  jmcneill 
    267  1.1  jmcneill static void
    268  1.1  jmcneill vncfb_init_screen(void *priv, struct vcons_screen *scr, int existing,
    269  1.1  jmcneill     long *defattr)
    270  1.1  jmcneill {
    271  1.1  jmcneill 	struct vncfb_softc *sc = priv;
    272  1.1  jmcneill 	struct vncfb_fbops *ops = &sc->sc_ops;
    273  1.1  jmcneill 	struct rasops_info *ri = &scr->scr_ri;
    274  1.1  jmcneill 
    275  1.1  jmcneill 	ri->ri_width = sc->sc_width;
    276  1.1  jmcneill 	ri->ri_height = sc->sc_height;
    277  1.1  jmcneill 	ri->ri_depth = sc->sc_depth;
    278  1.1  jmcneill 	ri->ri_stride = sc->sc_width * ri->ri_depth / 8;
    279  1.1  jmcneill 	ri->ri_bits = sc->sc_framebuf;
    280  1.1  jmcneill 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
    281  1.1  jmcneill 	if (existing)
    282  1.1  jmcneill 		ri->ri_flg |= RI_CLEAR;
    283  1.1  jmcneill 
    284  1.1  jmcneill 	rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
    285  1.1  jmcneill 	ri->ri_caps = WSSCREEN_WSCOLORS;
    286  1.1  jmcneill 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    287  1.1  jmcneill 	    sc->sc_width / ri->ri_font->fontwidth);
    288  1.1  jmcneill 
    289  1.1  jmcneill 	ri->ri_hw = scr;
    290  1.1  jmcneill 
    291  1.1  jmcneill 	ops->putchar = ri->ri_ops.putchar;
    292  1.1  jmcneill 	ops->copyrows = ri->ri_ops.copyrows;
    293  1.1  jmcneill 	ops->eraserows = ri->ri_ops.eraserows;
    294  1.1  jmcneill 	ops->copycols = ri->ri_ops.copycols;
    295  1.1  jmcneill 	ops->erasecols = ri->ri_ops.erasecols;
    296  1.2  jmcneill 	ops->cursor = ri->ri_ops.cursor;
    297  1.1  jmcneill 
    298  1.1  jmcneill 	ri->ri_ops.copyrows = vncfb_copyrows;
    299  1.1  jmcneill 	ri->ri_ops.copycols = vncfb_copycols;
    300  1.1  jmcneill 	ri->ri_ops.eraserows = vncfb_eraserows;
    301  1.1  jmcneill 	ri->ri_ops.erasecols = vncfb_erasecols;
    302  1.1  jmcneill 	ri->ri_ops.putchar = vncfb_putchar;
    303  1.2  jmcneill 	ri->ri_ops.cursor = vncfb_cursor;
    304  1.1  jmcneill }
    305  1.1  jmcneill 
    306  1.1  jmcneill static void
    307  1.1  jmcneill vncfb_putchar(void *priv, int row, int col, u_int c, long attr)
    308  1.1  jmcneill {
    309  1.1  jmcneill 	struct rasops_info *ri = priv;
    310  1.1  jmcneill 	struct vcons_screen *scr = ri->ri_hw;
    311  1.1  jmcneill 	struct vncfb_softc *sc = scr->scr_cookie;
    312  1.1  jmcneill 	struct vncfb_fbops *ops = &sc->sc_ops;
    313  1.1  jmcneill 	int x, y, w, h;
    314  1.1  jmcneill 
    315  1.1  jmcneill 	ops->putchar(ri, row, col, c, attr);
    316  1.1  jmcneill 
    317  1.1  jmcneill 	x = ri->ri_xorigin + (col * ri->ri_font->fontwidth);
    318  1.1  jmcneill 	y = ri->ri_yorigin + (row * ri->ri_font->fontheight);
    319  1.1  jmcneill 	w = ri->ri_font->fontwidth;
    320  1.1  jmcneill 	h = ri->ri_font->fontheight;
    321  1.1  jmcneill 
    322  1.1  jmcneill 	vncfb_update(sc, x, y, w, h);
    323  1.1  jmcneill }
    324  1.1  jmcneill 
    325  1.1  jmcneill static void
    326  1.1  jmcneill vncfb_copycols(void *priv, int row, int srccol, int dstcol, int ncols)
    327  1.1  jmcneill {
    328  1.1  jmcneill 	struct rasops_info *ri = priv;
    329  1.1  jmcneill 	struct vcons_screen *scr = ri->ri_hw;
    330  1.1  jmcneill 	struct vncfb_softc *sc = scr->scr_cookie;
    331  1.1  jmcneill 	struct vncfb_fbops *ops = &sc->sc_ops;
    332  1.1  jmcneill 	int x, y, w, h;
    333  1.1  jmcneill 
    334  1.1  jmcneill 	ops->copycols(ri, row, srccol, dstcol, ncols);
    335  1.1  jmcneill 
    336  1.1  jmcneill 	y = ri->ri_yorigin + (row * ri->ri_font->fontheight);
    337  1.1  jmcneill 	h = ri->ri_font->fontheight;
    338  1.1  jmcneill 	if (srccol < dstcol) {
    339  1.1  jmcneill 		x = ri->ri_xorigin + (srccol * ri->ri_font->fontwidth);
    340  1.1  jmcneill 		w = (dstcol - srccol) * ri->ri_font->fontwidth;
    341  1.1  jmcneill 
    342  1.1  jmcneill 	} else {
    343  1.1  jmcneill 		x = ri->ri_xorigin + (dstcol * ri->ri_font->fontwidth);
    344  1.1  jmcneill 		w = (srccol - dstcol) * ri->ri_font->fontwidth;
    345  1.1  jmcneill 	}
    346  1.1  jmcneill 
    347  1.1  jmcneill 	vncfb_update(sc, x, y, w, h);
    348  1.1  jmcneill }
    349  1.1  jmcneill 
    350  1.1  jmcneill static void
    351  1.1  jmcneill vncfb_erasecols(void *priv, int row, int startcol, int ncols, long fillattr)
    352  1.1  jmcneill {
    353  1.1  jmcneill 	struct rasops_info *ri = priv;
    354  1.1  jmcneill 	struct vcons_screen *scr = ri->ri_hw;
    355  1.1  jmcneill 	struct vncfb_softc *sc = scr->scr_cookie;
    356  1.1  jmcneill 	struct vncfb_fbops *ops = &sc->sc_ops;
    357  1.7  jmcneill 	int x, y, w, h, c;
    358  1.1  jmcneill 
    359  1.1  jmcneill 	ops->erasecols(ri, row, startcol, ncols, fillattr);
    360  1.1  jmcneill 
    361  1.1  jmcneill 	y = ri->ri_yorigin + (row * ri->ri_font->fontheight);
    362  1.1  jmcneill 	h = ri->ri_font->fontheight;
    363  1.1  jmcneill 	x = ri->ri_xorigin + (startcol * ri->ri_font->fontwidth);
    364  1.1  jmcneill 	w = ncols * ri->ri_font->fontwidth;
    365  1.7  jmcneill 	c = ri->ri_devcmap[(fillattr >> 16) & 0xf] & 0xffffff;
    366  1.1  jmcneill 
    367  1.7  jmcneill 	vncfb_fillrect(sc, x, y, w, h, c);
    368  1.1  jmcneill }
    369  1.1  jmcneill 
    370  1.1  jmcneill static void
    371  1.1  jmcneill vncfb_copyrows(void *priv, int srcrow, int dstrow, int nrows)
    372  1.1  jmcneill {
    373  1.1  jmcneill 	struct rasops_info *ri = priv;
    374  1.1  jmcneill 	struct vcons_screen *scr = ri->ri_hw;
    375  1.1  jmcneill 	struct vncfb_softc *sc = scr->scr_cookie;
    376  1.1  jmcneill 	struct vncfb_fbops *ops = &sc->sc_ops;
    377  1.6   reinoud 	int x, y, w, h, srcx, srcy;
    378  1.6   reinoud 	int fontheight;
    379  1.1  jmcneill 
    380  1.7  jmcneill 	/* barrier */
    381  1.7  jmcneill 	while (sc->sc_rfb.nupdates > 0)
    382  1.8  jmcneill 		if (thunk_rfb_poll(&sc->sc_rfb, NULL) == -1)
    383  1.8  jmcneill 			break;
    384  1.7  jmcneill 
    385  1.1  jmcneill 	ops->copyrows(ri, srcrow, dstrow, nrows);
    386  1.1  jmcneill 
    387  1.6   reinoud 	fontheight = ri->ri_font->fontheight;
    388  1.1  jmcneill 	x = ri->ri_xorigin;
    389  1.6   reinoud 	y = ri->ri_yorigin + dstrow * fontheight;
    390  1.1  jmcneill 	w = ri->ri_width;
    391  1.6   reinoud 	h = nrows * fontheight;
    392  1.6   reinoud 
    393  1.6   reinoud 	srcx = ri->ri_xorigin;
    394  1.6   reinoud 	srcy = ri->ri_yorigin + srcrow * fontheight;
    395  1.1  jmcneill 
    396  1.6   reinoud 	vncfb_copyrect(sc, x, y, w, h, srcx, srcy);
    397  1.1  jmcneill }
    398  1.1  jmcneill 
    399  1.1  jmcneill static void
    400  1.1  jmcneill vncfb_eraserows(void *priv, int row, int nrows, long fillattr)
    401  1.1  jmcneill {
    402  1.1  jmcneill 	struct rasops_info *ri = priv;
    403  1.1  jmcneill 	struct vcons_screen *scr = ri->ri_hw;
    404  1.1  jmcneill 	struct vncfb_softc *sc = scr->scr_cookie;
    405  1.1  jmcneill 	struct vncfb_fbops *ops = &sc->sc_ops;
    406  1.7  jmcneill 	int x, y, w, h, c;
    407  1.1  jmcneill 
    408  1.1  jmcneill 	ops->eraserows(ri, row, nrows, fillattr);
    409  1.1  jmcneill 
    410  1.1  jmcneill 	y = ri->ri_yorigin + (row * ri->ri_font->fontheight);
    411  1.1  jmcneill 	h = nrows * ri->ri_font->fontheight;
    412  1.1  jmcneill 	x = ri->ri_xorigin;
    413  1.1  jmcneill 	w = ri->ri_width;
    414  1.7  jmcneill 	c = ri->ri_devcmap[(fillattr >> 16) & 0xf] & 0xffffff;
    415  1.1  jmcneill 
    416  1.7  jmcneill 	vncfb_fillrect(sc, x, y, w, h, c);
    417  1.1  jmcneill }
    418  1.1  jmcneill 
    419  1.2  jmcneill static void
    420  1.2  jmcneill vncfb_cursor(void *priv, int on, int row, int col)
    421  1.2  jmcneill {
    422  1.2  jmcneill 	struct rasops_info *ri = priv;
    423  1.2  jmcneill 	struct vcons_screen *scr = ri->ri_hw;
    424  1.2  jmcneill 	struct vncfb_softc *sc = scr->scr_cookie;
    425  1.2  jmcneill 	struct vncfb_fbops *ops = &sc->sc_ops;
    426  1.2  jmcneill 	int ox, oy, x, y, w, h;
    427  1.2  jmcneill 
    428  1.2  jmcneill 	w = ri->ri_font->fontwidth;
    429  1.2  jmcneill 	h = ri->ri_font->fontheight;
    430  1.2  jmcneill 
    431  1.2  jmcneill 	ox = ri->ri_ccol * w + ri->ri_xorigin;
    432  1.2  jmcneill 	oy = ri->ri_crow * h + ri->ri_yorigin;
    433  1.2  jmcneill 
    434  1.2  jmcneill 	ops->cursor(ri, on, row, col);
    435  1.2  jmcneill 
    436  1.2  jmcneill 	x = ri->ri_ccol * w + ri->ri_xorigin;
    437  1.2  jmcneill 	y = ri->ri_crow * h + ri->ri_yorigin;
    438  1.2  jmcneill 
    439  1.2  jmcneill 	vncfb_update(sc, ox, oy, w, h);
    440  1.2  jmcneill 	vncfb_update(sc, x, y, w, h);
    441  1.2  jmcneill }
    442  1.2  jmcneill 
    443  1.1  jmcneill static int
    444  1.1  jmcneill vncfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, lwp_t *l)
    445  1.1  jmcneill {
    446  1.1  jmcneill 	struct vcons_data *vd = v;
    447  1.1  jmcneill 	struct vncfb_softc *sc = vd->cookie;
    448  1.1  jmcneill 	struct wsdisplay_fbinfo *wdf;
    449  1.1  jmcneill 	struct vcons_screen *ms = vd->active;
    450  1.1  jmcneill 	int new_mode;
    451  1.1  jmcneill 
    452  1.1  jmcneill 	switch (cmd) {
    453  1.1  jmcneill 	case WSDISPLAYIO_GTYPE:
    454  1.1  jmcneill 		*(u_int *)data = WSDISPLAY_TYPE_VNC;
    455  1.1  jmcneill 		return 0;
    456  1.1  jmcneill 	case WSDISPLAYIO_GINFO:
    457  1.1  jmcneill 		wdf = data;
    458  1.1  jmcneill 		wdf->height = ms->scr_ri.ri_height;
    459  1.1  jmcneill 		wdf->width = ms->scr_ri.ri_width;
    460  1.1  jmcneill 		wdf->depth = ms->scr_ri.ri_depth;
    461  1.1  jmcneill 		wdf->cmsize = 256;
    462  1.1  jmcneill 		return 0;
    463  1.9  jmcneill 	case WSDISPLAYIO_LINEBYTES:
    464  1.9  jmcneill 		*(u_int *)data = sc->sc_width * (sc->sc_depth / 8);
    465  1.9  jmcneill 		return 0;
    466  1.1  jmcneill 	case WSDISPLAYIO_SMODE:
    467  1.1  jmcneill 		new_mode = *(int *)data;
    468  1.1  jmcneill 		if (sc->sc_mode != new_mode) {
    469  1.1  jmcneill 			sc->sc_mode = new_mode;
    470  1.9  jmcneill 			if (new_mode == WSDISPLAYIO_MODE_EMUL) {
    471  1.9  jmcneill 				callout_halt(&sc->sc_callout, NULL);
    472  1.1  jmcneill 				vcons_redraw_screen(ms);
    473  1.9  jmcneill 			} else {
    474  1.9  jmcneill 				callout_schedule(&sc->sc_callout, 1);
    475  1.9  jmcneill 			}
    476  1.1  jmcneill 		}
    477  1.1  jmcneill 		return 0;
    478  1.1  jmcneill 	default:
    479  1.1  jmcneill 		return EPASSTHROUGH;
    480  1.1  jmcneill 	}
    481  1.1  jmcneill }
    482  1.1  jmcneill 
    483  1.1  jmcneill static paddr_t
    484  1.1  jmcneill vncfb_mmap(void *v, void *vs, off_t offset, int prot)
    485  1.1  jmcneill {
    486  1.9  jmcneill 	struct vcons_data *vd = v;
    487  1.9  jmcneill 	struct vncfb_softc *sc = vd->cookie;
    488  1.9  jmcneill 	paddr_t pa;
    489  1.9  jmcneill 	vaddr_t va;
    490  1.9  jmcneill 
    491  1.9  jmcneill 	if (offset < 0 || offset + PAGE_SIZE > sc->sc_framebufsize) {
    492  1.9  jmcneill 		device_printf(sc->sc_dev, "mmap: offset 0x%x, fbsize 0x%x"
    493  1.9  jmcneill 		    " out of range!\n",
    494  1.9  jmcneill 		    (unsigned int)offset, (unsigned int)sc->sc_framebufsize);
    495  1.9  jmcneill 		return -1;
    496  1.9  jmcneill 	}
    497  1.9  jmcneill 
    498  1.9  jmcneill 	va = trunc_page((vaddr_t)sc->sc_framebuf + offset);
    499  1.9  jmcneill 
    500  1.9  jmcneill 	if (pmap_extract(pmap_kernel(), va, &pa) == false) {
    501  1.9  jmcneill 		device_printf(sc->sc_dev, "mmap: pmap_extract failed!\n");
    502  1.9  jmcneill 		return -1;
    503  1.9  jmcneill 	}
    504  1.9  jmcneill 
    505  1.9  jmcneill 	return atop(pa);
    506  1.1  jmcneill }
    507  1.1  jmcneill 
    508  1.1  jmcneill static void
    509  1.1  jmcneill vncfb_update(struct vncfb_softc *sc, int x, int y, int w, int h)
    510  1.1  jmcneill {
    511  1.1  jmcneill 	thunk_rfb_update(&sc->sc_rfb, x, y, w, h);
    512  1.4  jmcneill 	softint_schedule(sc->sc_sih);
    513  1.1  jmcneill }
    514  1.1  jmcneill 
    515  1.6   reinoud static void
    516  1.6   reinoud vncfb_copyrect(struct vncfb_softc *sc, int x, int y, int w, int h,
    517  1.6   reinoud 	int srcx, int srcy)
    518  1.6   reinoud {
    519  1.6   reinoud 	thunk_rfb_copyrect(&sc->sc_rfb, x, y, w, h, srcx, srcy);
    520  1.6   reinoud 	softint_schedule(sc->sc_sih);
    521  1.6   reinoud }
    522  1.6   reinoud 
    523  1.7  jmcneill static void
    524  1.7  jmcneill vncfb_fillrect(struct vncfb_softc *sc, int x, int y, int w, int h, uint32_t c)
    525  1.7  jmcneill {
    526  1.7  jmcneill 
    527  1.7  jmcneill 	thunk_rfb_fillrect(&sc->sc_rfb, x, y, w, h, (uint8_t *)&c);
    528  1.7  jmcneill 	softint_schedule(sc->sc_sih);
    529  1.7  jmcneill }
    530  1.7  jmcneill 
    531  1.4  jmcneill static int
    532  1.4  jmcneill vncfb_intr(void *priv)
    533  1.1  jmcneill {
    534  1.1  jmcneill 	struct vncfb_softc *sc = priv;
    535  1.1  jmcneill 
    536  1.1  jmcneill 	softint_schedule(sc->sc_sih);
    537  1.4  jmcneill 
    538  1.4  jmcneill 	return 0;
    539  1.1  jmcneill }
    540  1.1  jmcneill 
    541  1.1  jmcneill static void
    542  1.1  jmcneill vncfb_softintr(void *priv)
    543  1.1  jmcneill {
    544  1.1  jmcneill 	struct vncfb_softc *sc = priv;
    545  1.1  jmcneill 	thunk_rfb_event_t event;
    546  1.1  jmcneill 	int s;
    547  1.1  jmcneill 
    548  1.1  jmcneill 	while (thunk_rfb_poll(&sc->sc_rfb, &event) > 0) {
    549  1.1  jmcneill 		switch (event.message_type) {
    550  1.1  jmcneill 		case THUNK_RFB_KEY_EVENT:
    551  1.1  jmcneill 			s = spltty();
    552  1.1  jmcneill 			wskbd_input(sc->sc_wskbddev,
    553  1.1  jmcneill 			    event.data.key_event.down_flag ?
    554  1.1  jmcneill 			     WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP,
    555  1.1  jmcneill 			    event.data.key_event.keysym & 0xfff);
    556  1.1  jmcneill 			splx(s);
    557  1.1  jmcneill 			break;
    558  1.1  jmcneill 		default:
    559  1.1  jmcneill 			break;
    560  1.1  jmcneill 		}
    561  1.1  jmcneill 	}
    562  1.1  jmcneill }
    563  1.1  jmcneill 
    564  1.9  jmcneill static void
    565  1.9  jmcneill vncfb_refresh(void *priv)
    566  1.9  jmcneill {
    567  1.9  jmcneill 	struct vncfb_softc *sc = priv;
    568  1.9  jmcneill 
    569  1.9  jmcneill 	softint_schedule(sc->sc_refresh_sih);
    570  1.9  jmcneill }
    571  1.9  jmcneill 
    572  1.9  jmcneill static void
    573  1.9  jmcneill vncfb_softrefresh(void *priv)
    574  1.9  jmcneill {
    575  1.9  jmcneill 	struct vncfb_softc *sc = priv;
    576  1.9  jmcneill 
    577  1.9  jmcneill 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)
    578  1.9  jmcneill 		return;
    579  1.9  jmcneill 
    580  1.9  jmcneill 	/* update the screen */
    581  1.9  jmcneill 	vncfb_update(sc, 0, 0, sc->sc_width, sc->sc_height);
    582  1.9  jmcneill 
    583  1.9  jmcneill 	/* flush the pending drawing op */
    584  1.9  jmcneill 	while (thunk_rfb_poll(&sc->sc_rfb, NULL) > 0)
    585  1.9  jmcneill 		;
    586  1.9  jmcneill 
    587  1.9  jmcneill 	callout_schedule(&sc->sc_callout, mstohz(VNCFB_REFRESH_INTERVAL));
    588  1.9  jmcneill }
    589  1.9  jmcneill 
    590  1.1  jmcneill static int
    591  1.1  jmcneill vncfb_kbd_enable(void *priv, int on)
    592  1.1  jmcneill {
    593  1.1  jmcneill 	struct vncfb_softc *sc = priv;
    594  1.1  jmcneill 
    595  1.1  jmcneill 	sc->sc_kbd_enable = on;
    596  1.1  jmcneill 
    597  1.1  jmcneill 	return 0;
    598  1.1  jmcneill }
    599  1.1  jmcneill 
    600  1.1  jmcneill static void
    601  1.1  jmcneill vncfb_kbd_set_leds(void *priv, int leds)
    602  1.1  jmcneill {
    603  1.1  jmcneill }
    604  1.1  jmcneill 
    605  1.1  jmcneill static int
    606  1.1  jmcneill vncfb_kbd_ioctl(void *priv, u_long cmd, void *data, int flag, lwp_t *l)
    607  1.1  jmcneill {
    608  1.5  jmcneill 	struct wskbd_bell_data *bd;
    609  1.5  jmcneill 
    610  1.1  jmcneill 	switch (cmd) {
    611  1.1  jmcneill 	case WSKBDIO_GTYPE:
    612  1.1  jmcneill 		*(int *)data = WSKBD_TYPE_RFB;
    613  1.1  jmcneill 		return 0;
    614  1.5  jmcneill 	case WSKBDIO_COMPLEXBELL:
    615  1.5  jmcneill 		bd = data;
    616  1.5  jmcneill 		vncfb_kbd_bell(priv, bd->pitch, bd->period, bd->volume);
    617  1.5  jmcneill 		return 0;
    618  1.1  jmcneill 	default:
    619  1.1  jmcneill 		return EPASSTHROUGH;
    620  1.1  jmcneill 	}
    621  1.1  jmcneill }
    622  1.1  jmcneill 
    623  1.1  jmcneill static void
    624  1.1  jmcneill vncfb_kbd_cngetc(void *priv, u_int *type, int *data)
    625  1.1  jmcneill {
    626  1.1  jmcneill }
    627  1.1  jmcneill 
    628  1.1  jmcneill static void
    629  1.1  jmcneill vncfb_kbd_cnpollc(void *priv, int on)
    630  1.1  jmcneill {
    631  1.1  jmcneill }
    632  1.5  jmcneill 
    633  1.5  jmcneill static void
    634  1.5  jmcneill vncfb_kbd_bell(void *priv, u_int pitch, u_int period, u_int volume)
    635  1.5  jmcneill {
    636  1.5  jmcneill 	struct vncfb_softc *sc = priv;
    637  1.5  jmcneill 
    638  1.5  jmcneill 	thunk_rfb_bell(&sc->sc_rfb);
    639  1.5  jmcneill 	softint_schedule(sc->sc_sih);
    640  1.5  jmcneill }
    641