vncfb.c revision 1.6 1 1.6 reinoud /* $NetBSD: vncfb.c,v 1.6 2011/12/30 13:08:30 reinoud 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.6 reinoud __KERNEL_RCSID(0, "$NetBSD: vncfb.c,v 1.6 2011/12/30 13:08:30 reinoud 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.1 jmcneill #include <dev/wscons/wsconsio.h>
47 1.1 jmcneill
48 1.1 jmcneill #include <dev/wscons/wsdisplayvar.h>
49 1.1 jmcneill #include <dev/wsfont/wsfont.h>
50 1.1 jmcneill #include <dev/rasops/rasops.h>
51 1.1 jmcneill #include <dev/wscons/wsdisplay_vconsvar.h>
52 1.1 jmcneill
53 1.1 jmcneill #include <dev/wscons/wskbdvar.h>
54 1.1 jmcneill #include <dev/wscons/wsksymdef.h>
55 1.1 jmcneill #include <dev/wscons/wsksymvar.h>
56 1.1 jmcneill
57 1.1 jmcneill #include <machine/mainbus.h>
58 1.1 jmcneill #include <machine/thunk.h>
59 1.1 jmcneill
60 1.1 jmcneill struct vncfb_fbops {
61 1.1 jmcneill void (*copycols)(void *, int, int, int, int);
62 1.1 jmcneill void (*erasecols)(void *, int, int, int, long);
63 1.1 jmcneill void (*copyrows)(void *, int, int, int);
64 1.1 jmcneill void (*eraserows)(void *, int, int, long);
65 1.1 jmcneill void (*putchar)(void *, int, int, u_int, long);
66 1.2 jmcneill void (*cursor)(void *, int, int, int);
67 1.1 jmcneill };
68 1.1 jmcneill
69 1.1 jmcneill struct vncfb_softc {
70 1.1 jmcneill device_t sc_dev;
71 1.1 jmcneill device_t sc_wskbddev;
72 1.1 jmcneill thunk_rfb_t sc_rfb;
73 1.1 jmcneill unsigned int sc_width;
74 1.1 jmcneill unsigned int sc_height;
75 1.1 jmcneill unsigned int sc_depth;
76 1.1 jmcneill int sc_mode;
77 1.1 jmcneill uint8_t * sc_framebuf;
78 1.1 jmcneill struct vcons_data sc_vd;
79 1.1 jmcneill struct vncfb_fbops sc_ops;
80 1.1 jmcneill
81 1.1 jmcneill int sc_kbd_enable;
82 1.1 jmcneill
83 1.4 jmcneill void *sc_ih;
84 1.1 jmcneill void *sc_sih;
85 1.1 jmcneill };
86 1.1 jmcneill
87 1.1 jmcneill static int vncfb_match(device_t, cfdata_t, void *);
88 1.1 jmcneill static void vncfb_attach(device_t, device_t, void *);
89 1.1 jmcneill
90 1.1 jmcneill CFATTACH_DECL_NEW(vncfb, sizeof(struct vncfb_softc),
91 1.1 jmcneill vncfb_match, vncfb_attach, NULL, NULL);
92 1.1 jmcneill
93 1.1 jmcneill static void vncfb_putchar(void *, int, int, u_int, long);
94 1.1 jmcneill static void vncfb_copycols(void *, int, int, int, int);
95 1.1 jmcneill static void vncfb_erasecols(void *, int, int, int, long);
96 1.1 jmcneill static void vncfb_copyrows(void *, int, int, int);
97 1.1 jmcneill static void vncfb_eraserows(void *, int, int, long);
98 1.2 jmcneill static void vncfb_cursor(void *, int, int, int);
99 1.1 jmcneill
100 1.1 jmcneill static int vncfb_ioctl(void *, void *, u_long, void *, int, lwp_t *);
101 1.1 jmcneill static paddr_t vncfb_mmap(void *, void *, off_t, int);
102 1.1 jmcneill
103 1.1 jmcneill static void vncfb_init_screen(void *, struct vcons_screen *, int, long *);
104 1.1 jmcneill
105 1.1 jmcneill static void vncfb_update(struct vncfb_softc *, int, int, int, int);
106 1.6 reinoud static void vncfb_copyrect(struct vncfb_softc *sc, int, int, int, int, int, int);
107 1.4 jmcneill static int vncfb_intr(void *);
108 1.1 jmcneill static void vncfb_softintr(void *);
109 1.1 jmcneill
110 1.1 jmcneill static int vncfb_kbd_enable(void *, int);
111 1.1 jmcneill static void vncfb_kbd_set_leds(void *, int);
112 1.1 jmcneill static int vncfb_kbd_ioctl(void *, u_long, void *, int, lwp_t *);
113 1.1 jmcneill
114 1.1 jmcneill static void vncfb_kbd_cngetc(void *, u_int *, int *);
115 1.1 jmcneill static void vncfb_kbd_cnpollc(void *, int);
116 1.5 jmcneill static void vncfb_kbd_bell(void *, u_int, u_int, u_int);
117 1.1 jmcneill
118 1.1 jmcneill static struct vcons_screen vncfb_console_screen;
119 1.1 jmcneill
120 1.1 jmcneill static struct wsscreen_descr vncfb_defaultscreen = {
121 1.1 jmcneill .name = "default",
122 1.1 jmcneill .fontwidth = 8,
123 1.1 jmcneill .fontheight = 16,
124 1.1 jmcneill .capabilities = WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
125 1.1 jmcneill };
126 1.1 jmcneill
127 1.1 jmcneill static const struct wsscreen_descr *vncfb_screens[] = {
128 1.1 jmcneill &vncfb_defaultscreen,
129 1.1 jmcneill };
130 1.1 jmcneill
131 1.1 jmcneill static struct wsscreen_list vncfb_screenlist = {
132 1.1 jmcneill .screens = vncfb_screens,
133 1.1 jmcneill .nscreens = __arraycount(vncfb_screens),
134 1.1 jmcneill };
135 1.1 jmcneill
136 1.1 jmcneill static struct wsdisplay_accessops vncfb_accessops = {
137 1.1 jmcneill .ioctl = vncfb_ioctl,
138 1.1 jmcneill .mmap = vncfb_mmap,
139 1.1 jmcneill };
140 1.1 jmcneill
141 1.1 jmcneill extern const struct wscons_keydesc vnckbd_keydesctab[];
142 1.1 jmcneill
143 1.1 jmcneill static const struct wskbd_mapdata vncfb_keymapdata = {
144 1.1 jmcneill vnckbd_keydesctab,
145 1.1 jmcneill KB_US,
146 1.1 jmcneill };
147 1.1 jmcneill
148 1.1 jmcneill static struct wskbd_accessops vncfb_kbd_accessops = {
149 1.1 jmcneill vncfb_kbd_enable,
150 1.1 jmcneill vncfb_kbd_set_leds,
151 1.1 jmcneill vncfb_kbd_ioctl,
152 1.1 jmcneill };
153 1.1 jmcneill
154 1.1 jmcneill static const struct wskbd_consops vncfb_kbd_consops = {
155 1.1 jmcneill vncfb_kbd_cngetc,
156 1.1 jmcneill vncfb_kbd_cnpollc,
157 1.5 jmcneill vncfb_kbd_bell,
158 1.1 jmcneill };
159 1.1 jmcneill
160 1.1 jmcneill static int
161 1.1 jmcneill vncfb_match(device_t parent, cfdata_t match, void *priv)
162 1.1 jmcneill {
163 1.1 jmcneill struct thunkbus_attach_args *taa = priv;
164 1.1 jmcneill
165 1.1 jmcneill return taa->taa_type == THUNKBUS_TYPE_VNCFB;
166 1.1 jmcneill }
167 1.1 jmcneill
168 1.1 jmcneill static void
169 1.1 jmcneill vncfb_attach(device_t parent, device_t self, void *priv)
170 1.1 jmcneill {
171 1.1 jmcneill struct vncfb_softc *sc = device_private(self);
172 1.1 jmcneill struct thunkbus_attach_args *taa = priv;
173 1.1 jmcneill struct wsemuldisplaydev_attach_args waa;
174 1.1 jmcneill struct wskbddev_attach_args kaa;
175 1.1 jmcneill struct rasops_info *ri;
176 1.1 jmcneill unsigned long defattr;
177 1.1 jmcneill
178 1.1 jmcneill sc->sc_dev = self;
179 1.1 jmcneill sc->sc_width = taa->u.vnc.width;
180 1.1 jmcneill sc->sc_height = taa->u.vnc.height;
181 1.1 jmcneill sc->sc_depth = 32;
182 1.1 jmcneill sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
183 1.1 jmcneill #if notyet
184 1.1 jmcneill sc->sc_sockfd = thunk_vnc_open_socket(taa->u.vnc.port);
185 1.1 jmcneill if (sc->sc_sockfd == -1)
186 1.1 jmcneill panic("couldn't open VNC socket");
187 1.1 jmcneill #endif
188 1.1 jmcneill
189 1.1 jmcneill sc->sc_framebuf = kmem_zalloc(sc->sc_width * sc->sc_height *
190 1.1 jmcneill (sc->sc_depth / 8), KM_SLEEP);
191 1.1 jmcneill KASSERT(sc->sc_framebuf != NULL);
192 1.1 jmcneill
193 1.1 jmcneill aprint_naive("\n");
194 1.1 jmcneill aprint_normal(": %ux%u %ubpp (port %u)\n",
195 1.1 jmcneill sc->sc_width, sc->sc_height, sc->sc_depth, taa->u.vnc.port);
196 1.1 jmcneill
197 1.1 jmcneill sc->sc_rfb.width = sc->sc_width;
198 1.1 jmcneill sc->sc_rfb.height = sc->sc_height;
199 1.1 jmcneill sc->sc_rfb.depth = sc->sc_depth;
200 1.1 jmcneill sc->sc_rfb.framebuf = sc->sc_framebuf;
201 1.1 jmcneill snprintf(sc->sc_rfb.name, sizeof(sc->sc_rfb.name),
202 1.1 jmcneill "NetBSD/usermode %d.%d.%d",
203 1.1 jmcneill __NetBSD_Version__ / 100000000,
204 1.1 jmcneill (__NetBSD_Version__ / 1000000) % 100,
205 1.1 jmcneill (__NetBSD_Version__ / 100) % 100);
206 1.1 jmcneill if (thunk_rfb_open(&sc->sc_rfb, taa->u.vnc.port) != 0)
207 1.1 jmcneill panic("couldn't open rfb server");
208 1.1 jmcneill
209 1.1 jmcneill sc->sc_sih = softint_establish(SOFTINT_SERIAL, vncfb_softintr, sc);
210 1.4 jmcneill sc->sc_ih = sigio_intr_establish(vncfb_intr, sc);
211 1.1 jmcneill
212 1.1 jmcneill vcons_init(&sc->sc_vd, sc, &vncfb_defaultscreen, &vncfb_accessops);
213 1.1 jmcneill sc->sc_vd.init_screen = vncfb_init_screen;
214 1.1 jmcneill
215 1.1 jmcneill ri = &vncfb_console_screen.scr_ri;
216 1.1 jmcneill vcons_init_screen(&sc->sc_vd, &vncfb_console_screen, 1, &defattr);
217 1.1 jmcneill vncfb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
218 1.1 jmcneill vncfb_defaultscreen.textops = &ri->ri_ops;
219 1.1 jmcneill vncfb_defaultscreen.capabilities = ri->ri_caps;
220 1.1 jmcneill vncfb_defaultscreen.nrows = ri->ri_rows;
221 1.1 jmcneill vncfb_defaultscreen.ncols = ri->ri_cols;
222 1.1 jmcneill wsdisplay_cnattach(&vncfb_defaultscreen, ri, 0, 0, defattr);
223 1.1 jmcneill
224 1.1 jmcneill vcons_replay_msgbuf(&vncfb_console_screen);
225 1.1 jmcneill
226 1.1 jmcneill waa.console = true;
227 1.1 jmcneill waa.scrdata = &vncfb_screenlist;
228 1.1 jmcneill waa.accessops = &vncfb_accessops;
229 1.1 jmcneill waa.accesscookie = &sc->sc_vd;
230 1.1 jmcneill
231 1.1 jmcneill config_found(self, &waa, wsemuldisplaydevprint);
232 1.1 jmcneill
233 1.1 jmcneill wskbd_cnattach(&vncfb_kbd_consops, sc, &vncfb_keymapdata);
234 1.1 jmcneill
235 1.1 jmcneill kaa.console = true;
236 1.1 jmcneill kaa.keymap = &vncfb_keymapdata;
237 1.1 jmcneill kaa.accessops = &vncfb_kbd_accessops;
238 1.1 jmcneill kaa.accesscookie = sc;
239 1.1 jmcneill
240 1.1 jmcneill sc->sc_wskbddev = config_found_ia(self, "wskbddev", &kaa,
241 1.1 jmcneill wskbddevprint);
242 1.1 jmcneill }
243 1.1 jmcneill
244 1.1 jmcneill static void
245 1.1 jmcneill vncfb_init_screen(void *priv, struct vcons_screen *scr, int existing,
246 1.1 jmcneill long *defattr)
247 1.1 jmcneill {
248 1.1 jmcneill struct vncfb_softc *sc = priv;
249 1.1 jmcneill struct vncfb_fbops *ops = &sc->sc_ops;
250 1.1 jmcneill struct rasops_info *ri = &scr->scr_ri;
251 1.1 jmcneill
252 1.1 jmcneill ri->ri_width = sc->sc_width;
253 1.1 jmcneill ri->ri_height = sc->sc_height;
254 1.1 jmcneill ri->ri_depth = sc->sc_depth;
255 1.1 jmcneill ri->ri_stride = sc->sc_width * ri->ri_depth / 8;
256 1.1 jmcneill ri->ri_bits = sc->sc_framebuf;
257 1.1 jmcneill ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
258 1.1 jmcneill if (existing)
259 1.1 jmcneill ri->ri_flg |= RI_CLEAR;
260 1.1 jmcneill
261 1.1 jmcneill rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
262 1.1 jmcneill ri->ri_caps = WSSCREEN_WSCOLORS;
263 1.1 jmcneill rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
264 1.1 jmcneill sc->sc_width / ri->ri_font->fontwidth);
265 1.1 jmcneill
266 1.1 jmcneill ri->ri_hw = scr;
267 1.1 jmcneill
268 1.1 jmcneill ops->putchar = ri->ri_ops.putchar;
269 1.1 jmcneill ops->copyrows = ri->ri_ops.copyrows;
270 1.1 jmcneill ops->eraserows = ri->ri_ops.eraserows;
271 1.1 jmcneill ops->copycols = ri->ri_ops.copycols;
272 1.1 jmcneill ops->erasecols = ri->ri_ops.erasecols;
273 1.2 jmcneill ops->cursor = ri->ri_ops.cursor;
274 1.1 jmcneill
275 1.1 jmcneill ri->ri_ops.copyrows = vncfb_copyrows;
276 1.1 jmcneill ri->ri_ops.copycols = vncfb_copycols;
277 1.1 jmcneill ri->ri_ops.eraserows = vncfb_eraserows;
278 1.1 jmcneill ri->ri_ops.erasecols = vncfb_erasecols;
279 1.1 jmcneill ri->ri_ops.putchar = vncfb_putchar;
280 1.2 jmcneill ri->ri_ops.cursor = vncfb_cursor;
281 1.1 jmcneill }
282 1.1 jmcneill
283 1.1 jmcneill static void
284 1.1 jmcneill vncfb_putchar(void *priv, int row, int col, u_int c, long attr)
285 1.1 jmcneill {
286 1.1 jmcneill struct rasops_info *ri = priv;
287 1.1 jmcneill struct vcons_screen *scr = ri->ri_hw;
288 1.1 jmcneill struct vncfb_softc *sc = scr->scr_cookie;
289 1.1 jmcneill struct vncfb_fbops *ops = &sc->sc_ops;
290 1.1 jmcneill int x, y, w, h;
291 1.1 jmcneill
292 1.1 jmcneill ops->putchar(ri, row, col, c, attr);
293 1.1 jmcneill
294 1.1 jmcneill x = ri->ri_xorigin + (col * ri->ri_font->fontwidth);
295 1.1 jmcneill y = ri->ri_yorigin + (row * ri->ri_font->fontheight);
296 1.1 jmcneill w = ri->ri_font->fontwidth;
297 1.1 jmcneill h = ri->ri_font->fontheight;
298 1.1 jmcneill
299 1.1 jmcneill vncfb_update(sc, x, y, w, h);
300 1.1 jmcneill }
301 1.1 jmcneill
302 1.1 jmcneill static void
303 1.1 jmcneill vncfb_copycols(void *priv, int row, int srccol, int dstcol, int ncols)
304 1.1 jmcneill {
305 1.1 jmcneill struct rasops_info *ri = priv;
306 1.1 jmcneill struct vcons_screen *scr = ri->ri_hw;
307 1.1 jmcneill struct vncfb_softc *sc = scr->scr_cookie;
308 1.1 jmcneill struct vncfb_fbops *ops = &sc->sc_ops;
309 1.1 jmcneill int x, y, w, h;
310 1.1 jmcneill
311 1.1 jmcneill ops->copycols(ri, row, srccol, dstcol, ncols);
312 1.1 jmcneill
313 1.1 jmcneill y = ri->ri_yorigin + (row * ri->ri_font->fontheight);
314 1.1 jmcneill h = ri->ri_font->fontheight;
315 1.1 jmcneill if (srccol < dstcol) {
316 1.1 jmcneill x = ri->ri_xorigin + (srccol * ri->ri_font->fontwidth);
317 1.1 jmcneill w = (dstcol - srccol) * ri->ri_font->fontwidth;
318 1.1 jmcneill
319 1.1 jmcneill } else {
320 1.1 jmcneill x = ri->ri_xorigin + (dstcol * ri->ri_font->fontwidth);
321 1.1 jmcneill w = (srccol - dstcol) * ri->ri_font->fontwidth;
322 1.1 jmcneill }
323 1.1 jmcneill
324 1.1 jmcneill vncfb_update(sc, x, y, w, h);
325 1.1 jmcneill }
326 1.1 jmcneill
327 1.1 jmcneill static void
328 1.1 jmcneill vncfb_erasecols(void *priv, int row, int startcol, int ncols, long fillattr)
329 1.1 jmcneill {
330 1.1 jmcneill struct rasops_info *ri = priv;
331 1.1 jmcneill struct vcons_screen *scr = ri->ri_hw;
332 1.1 jmcneill struct vncfb_softc *sc = scr->scr_cookie;
333 1.1 jmcneill struct vncfb_fbops *ops = &sc->sc_ops;
334 1.1 jmcneill int x, y, w, h;
335 1.1 jmcneill
336 1.1 jmcneill ops->erasecols(ri, row, startcol, ncols, fillattr);
337 1.1 jmcneill
338 1.1 jmcneill y = ri->ri_yorigin + (row * ri->ri_font->fontheight);
339 1.1 jmcneill h = ri->ri_font->fontheight;
340 1.1 jmcneill x = ri->ri_xorigin + (startcol * ri->ri_font->fontwidth);
341 1.1 jmcneill w = ncols * ri->ri_font->fontwidth;
342 1.1 jmcneill
343 1.1 jmcneill vncfb_update(sc, x, y, w, h);
344 1.1 jmcneill }
345 1.1 jmcneill
346 1.1 jmcneill static void
347 1.1 jmcneill vncfb_copyrows(void *priv, int srcrow, int dstrow, int nrows)
348 1.1 jmcneill {
349 1.1 jmcneill struct rasops_info *ri = priv;
350 1.1 jmcneill struct vcons_screen *scr = ri->ri_hw;
351 1.1 jmcneill struct vncfb_softc *sc = scr->scr_cookie;
352 1.1 jmcneill struct vncfb_fbops *ops = &sc->sc_ops;
353 1.6 reinoud int x, y, w, h, srcx, srcy;
354 1.6 reinoud int fontheight;
355 1.1 jmcneill
356 1.1 jmcneill ops->copyrows(ri, srcrow, dstrow, nrows);
357 1.1 jmcneill
358 1.6 reinoud fontheight = ri->ri_font->fontheight;
359 1.1 jmcneill x = ri->ri_xorigin;
360 1.6 reinoud y = ri->ri_yorigin + dstrow * fontheight;
361 1.1 jmcneill w = ri->ri_width;
362 1.6 reinoud h = nrows * fontheight;
363 1.6 reinoud
364 1.6 reinoud srcx = ri->ri_xorigin;
365 1.6 reinoud srcy = ri->ri_yorigin + srcrow * fontheight;
366 1.1 jmcneill
367 1.6 reinoud vncfb_copyrect(sc, x, y, w, h, srcx, srcy);
368 1.1 jmcneill }
369 1.1 jmcneill
370 1.1 jmcneill static void
371 1.1 jmcneill vncfb_eraserows(void *priv, int row, int nrows, long fillattr)
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.1 jmcneill int x, y, w, h;
378 1.1 jmcneill
379 1.1 jmcneill ops->eraserows(ri, row, nrows, fillattr);
380 1.1 jmcneill
381 1.1 jmcneill y = ri->ri_yorigin + (row * ri->ri_font->fontheight);
382 1.1 jmcneill h = nrows * ri->ri_font->fontheight;
383 1.1 jmcneill x = ri->ri_xorigin;
384 1.1 jmcneill w = ri->ri_width;
385 1.1 jmcneill
386 1.1 jmcneill vncfb_update(sc, x, y, w, h);
387 1.1 jmcneill }
388 1.1 jmcneill
389 1.2 jmcneill static void
390 1.2 jmcneill vncfb_cursor(void *priv, int on, int row, int col)
391 1.2 jmcneill {
392 1.2 jmcneill struct rasops_info *ri = priv;
393 1.2 jmcneill struct vcons_screen *scr = ri->ri_hw;
394 1.2 jmcneill struct vncfb_softc *sc = scr->scr_cookie;
395 1.2 jmcneill struct vncfb_fbops *ops = &sc->sc_ops;
396 1.2 jmcneill int ox, oy, x, y, w, h;
397 1.2 jmcneill
398 1.2 jmcneill w = ri->ri_font->fontwidth;
399 1.2 jmcneill h = ri->ri_font->fontheight;
400 1.2 jmcneill
401 1.2 jmcneill ox = ri->ri_ccol * w + ri->ri_xorigin;
402 1.2 jmcneill oy = ri->ri_crow * h + ri->ri_yorigin;
403 1.2 jmcneill
404 1.2 jmcneill ops->cursor(ri, on, row, col);
405 1.2 jmcneill
406 1.2 jmcneill x = ri->ri_ccol * w + ri->ri_xorigin;
407 1.2 jmcneill y = ri->ri_crow * h + ri->ri_yorigin;
408 1.2 jmcneill
409 1.2 jmcneill vncfb_update(sc, ox, oy, w, h);
410 1.2 jmcneill vncfb_update(sc, x, y, w, h);
411 1.2 jmcneill }
412 1.2 jmcneill
413 1.1 jmcneill static int
414 1.1 jmcneill vncfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, lwp_t *l)
415 1.1 jmcneill {
416 1.1 jmcneill struct vcons_data *vd = v;
417 1.1 jmcneill struct vncfb_softc *sc = vd->cookie;
418 1.1 jmcneill struct wsdisplay_fbinfo *wdf;
419 1.1 jmcneill struct vcons_screen *ms = vd->active;
420 1.1 jmcneill int new_mode;
421 1.1 jmcneill
422 1.1 jmcneill switch (cmd) {
423 1.1 jmcneill case WSDISPLAYIO_GTYPE:
424 1.1 jmcneill *(u_int *)data = WSDISPLAY_TYPE_VNC;
425 1.1 jmcneill return 0;
426 1.1 jmcneill case WSDISPLAYIO_GINFO:
427 1.1 jmcneill wdf = data;
428 1.1 jmcneill wdf->height = ms->scr_ri.ri_height;
429 1.1 jmcneill wdf->width = ms->scr_ri.ri_width;
430 1.1 jmcneill wdf->depth = ms->scr_ri.ri_depth;
431 1.1 jmcneill wdf->cmsize = 256;
432 1.1 jmcneill return 0;
433 1.1 jmcneill case WSDISPLAYIO_SMODE:
434 1.1 jmcneill new_mode = *(int *)data;
435 1.1 jmcneill if (sc->sc_mode != new_mode) {
436 1.1 jmcneill sc->sc_mode = new_mode;
437 1.1 jmcneill if (new_mode == WSDISPLAYIO_MODE_EMUL)
438 1.1 jmcneill vcons_redraw_screen(ms);
439 1.1 jmcneill }
440 1.1 jmcneill return 0;
441 1.1 jmcneill default:
442 1.1 jmcneill return EPASSTHROUGH;
443 1.1 jmcneill }
444 1.1 jmcneill }
445 1.1 jmcneill
446 1.1 jmcneill static paddr_t
447 1.1 jmcneill vncfb_mmap(void *v, void *vs, off_t offset, int prot)
448 1.1 jmcneill {
449 1.1 jmcneill /* TODO */
450 1.1 jmcneill return -1;
451 1.1 jmcneill }
452 1.1 jmcneill
453 1.1 jmcneill static void
454 1.1 jmcneill vncfb_update(struct vncfb_softc *sc, int x, int y, int w, int h)
455 1.1 jmcneill {
456 1.1 jmcneill thunk_rfb_update(&sc->sc_rfb, x, y, w, h);
457 1.4 jmcneill softint_schedule(sc->sc_sih);
458 1.1 jmcneill }
459 1.1 jmcneill
460 1.6 reinoud static void
461 1.6 reinoud vncfb_copyrect(struct vncfb_softc *sc, int x, int y, int w, int h,
462 1.6 reinoud int srcx, int srcy)
463 1.6 reinoud {
464 1.6 reinoud thunk_rfb_copyrect(&sc->sc_rfb, x, y, w, h, srcx, srcy);
465 1.6 reinoud softint_schedule(sc->sc_sih);
466 1.6 reinoud }
467 1.6 reinoud
468 1.4 jmcneill static int
469 1.4 jmcneill vncfb_intr(void *priv)
470 1.1 jmcneill {
471 1.1 jmcneill struct vncfb_softc *sc = priv;
472 1.1 jmcneill
473 1.1 jmcneill softint_schedule(sc->sc_sih);
474 1.4 jmcneill
475 1.4 jmcneill return 0;
476 1.1 jmcneill }
477 1.1 jmcneill
478 1.1 jmcneill static void
479 1.1 jmcneill vncfb_softintr(void *priv)
480 1.1 jmcneill {
481 1.1 jmcneill struct vncfb_softc *sc = priv;
482 1.1 jmcneill thunk_rfb_event_t event;
483 1.1 jmcneill int s;
484 1.1 jmcneill
485 1.1 jmcneill while (thunk_rfb_poll(&sc->sc_rfb, &event) > 0) {
486 1.1 jmcneill switch (event.message_type) {
487 1.1 jmcneill case THUNK_RFB_KEY_EVENT:
488 1.1 jmcneill s = spltty();
489 1.1 jmcneill wskbd_input(sc->sc_wskbddev,
490 1.1 jmcneill event.data.key_event.down_flag ?
491 1.1 jmcneill WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP,
492 1.1 jmcneill event.data.key_event.keysym & 0xfff);
493 1.1 jmcneill splx(s);
494 1.1 jmcneill break;
495 1.1 jmcneill default:
496 1.1 jmcneill break;
497 1.1 jmcneill }
498 1.1 jmcneill }
499 1.1 jmcneill }
500 1.1 jmcneill
501 1.1 jmcneill static int
502 1.1 jmcneill vncfb_kbd_enable(void *priv, int on)
503 1.1 jmcneill {
504 1.1 jmcneill struct vncfb_softc *sc = priv;
505 1.1 jmcneill
506 1.1 jmcneill sc->sc_kbd_enable = on;
507 1.1 jmcneill
508 1.1 jmcneill return 0;
509 1.1 jmcneill }
510 1.1 jmcneill
511 1.1 jmcneill static void
512 1.1 jmcneill vncfb_kbd_set_leds(void *priv, int leds)
513 1.1 jmcneill {
514 1.1 jmcneill }
515 1.1 jmcneill
516 1.1 jmcneill static int
517 1.1 jmcneill vncfb_kbd_ioctl(void *priv, u_long cmd, void *data, int flag, lwp_t *l)
518 1.1 jmcneill {
519 1.5 jmcneill struct wskbd_bell_data *bd;
520 1.5 jmcneill
521 1.1 jmcneill switch (cmd) {
522 1.1 jmcneill case WSKBDIO_GTYPE:
523 1.1 jmcneill *(int *)data = WSKBD_TYPE_RFB;
524 1.1 jmcneill return 0;
525 1.5 jmcneill case WSKBDIO_COMPLEXBELL:
526 1.5 jmcneill bd = data;
527 1.5 jmcneill vncfb_kbd_bell(priv, bd->pitch, bd->period, bd->volume);
528 1.5 jmcneill return 0;
529 1.1 jmcneill default:
530 1.1 jmcneill return EPASSTHROUGH;
531 1.1 jmcneill }
532 1.1 jmcneill }
533 1.1 jmcneill
534 1.1 jmcneill static void
535 1.1 jmcneill vncfb_kbd_cngetc(void *priv, u_int *type, int *data)
536 1.1 jmcneill {
537 1.1 jmcneill }
538 1.1 jmcneill
539 1.1 jmcneill static void
540 1.1 jmcneill vncfb_kbd_cnpollc(void *priv, int on)
541 1.1 jmcneill {
542 1.1 jmcneill }
543 1.5 jmcneill
544 1.5 jmcneill static void
545 1.5 jmcneill vncfb_kbd_bell(void *priv, u_int pitch, u_int period, u_int volume)
546 1.5 jmcneill {
547 1.5 jmcneill struct vncfb_softc *sc = priv;
548 1.5 jmcneill
549 1.5 jmcneill thunk_rfb_bell(&sc->sc_rfb);
550 1.5 jmcneill softint_schedule(sc->sc_sih);
551 1.5 jmcneill }
552