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