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