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