wsdisplay_vcons.c revision 1.7.6.5 1 1.7.6.5 yamt /* $NetBSD: wsdisplay_vcons.c,v 1.7.6.5 2007/10/27 11:34:50 yamt Exp $ */
2 1.7.6.2 yamt
3 1.7.6.2 yamt /*-
4 1.7.6.2 yamt * Copyright (c) 2005, 2006 Michael Lorenz
5 1.7.6.2 yamt * All rights reserved.
6 1.7.6.2 yamt *
7 1.7.6.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.7.6.2 yamt * modification, are permitted provided that the following conditions
9 1.7.6.2 yamt * are met:
10 1.7.6.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.7.6.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.7.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.7.6.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.7.6.2 yamt * documentation and/or other materials provided with the distribution.
15 1.7.6.2 yamt * 3. All advertising materials mentioning features or use of this software
16 1.7.6.2 yamt * must display the following acknowledgement:
17 1.7.6.2 yamt * This product includes software developed by the NetBSD
18 1.7.6.2 yamt * Foundation, Inc. and its contributors.
19 1.7.6.2 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.7.6.2 yamt * contributors may be used to endorse or promote products derived
21 1.7.6.2 yamt * from this software without specific prior written permission.
22 1.7.6.2 yamt *
23 1.7.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.7.6.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.7.6.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.7.6.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.7.6.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.7.6.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.7.6.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.7.6.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.7.6.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.7.6.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.7.6.2 yamt * POSSIBILITY OF SUCH DAMAGE.
34 1.7.6.2 yamt */
35 1.7.6.2 yamt
36 1.7.6.2 yamt #include <sys/cdefs.h>
37 1.7.6.5 yamt __KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.7.6.5 2007/10/27 11:34:50 yamt Exp $");
38 1.7.6.2 yamt
39 1.7.6.2 yamt #include <sys/param.h>
40 1.7.6.2 yamt #include <sys/systm.h>
41 1.7.6.2 yamt #include <sys/kernel.h>
42 1.7.6.2 yamt #include <sys/buf.h>
43 1.7.6.2 yamt #include <sys/device.h>
44 1.7.6.2 yamt #include <sys/ioctl.h>
45 1.7.6.2 yamt #include <sys/malloc.h>
46 1.7.6.2 yamt #include <sys/mman.h>
47 1.7.6.2 yamt #include <sys/tty.h>
48 1.7.6.2 yamt #include <sys/conf.h>
49 1.7.6.2 yamt #include <sys/proc.h>
50 1.7.6.2 yamt #include <sys/kthread.h>
51 1.7.6.2 yamt #include <sys/tprintf.h>
52 1.7.6.2 yamt
53 1.7.6.2 yamt #include <dev/wscons/wsdisplayvar.h>
54 1.7.6.2 yamt #include <dev/wscons/wsconsio.h>
55 1.7.6.2 yamt #include <dev/wsfont/wsfont.h>
56 1.7.6.2 yamt #include <dev/rasops/rasops.h>
57 1.7.6.2 yamt
58 1.7.6.2 yamt #include <dev/wscons/wsdisplay_vconsvar.h>
59 1.7.6.2 yamt
60 1.7.6.4 yamt #include "opt_wsemul.h"
61 1.7.6.4 yamt #include "opt_wsdisplay_compat.h"
62 1.7.6.4 yamt #include "opt_vcons.h"
63 1.7.6.4 yamt
64 1.7.6.2 yamt static void vcons_dummy_init_screen(void *, struct vcons_screen *, int,
65 1.7.6.2 yamt long *);
66 1.7.6.2 yamt
67 1.7.6.4 yamt static int vcons_ioctl(void *, void *, u_long, void *, int, struct lwp *);
68 1.7.6.2 yamt static int vcons_alloc_screen(void *, const struct wsscreen_descr *, void **,
69 1.7.6.2 yamt int *, int *, long *);
70 1.7.6.2 yamt static void vcons_free_screen(void *, void *);
71 1.7.6.2 yamt static int vcons_show_screen(void *, void *, int, void (*)(void *, int, int),
72 1.7.6.2 yamt void *);
73 1.7.6.2 yamt
74 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
75 1.7.6.4 yamt static void vcons_scroll(void *, void *, int);
76 1.7.6.4 yamt static void vcons_do_scroll(struct vcons_screen *);
77 1.7.6.4 yamt #endif
78 1.7.6.4 yamt
79 1.7.6.5 yamt static void vcons_do_switch(void *);
80 1.7.6.2 yamt
81 1.7.6.2 yamt /* methods that work only on text buffers */
82 1.7.6.2 yamt static void vcons_copycols_buffer(void *, int, int, int, int);
83 1.7.6.2 yamt static void vcons_erasecols_buffer(void *, int, int, int, long);
84 1.7.6.2 yamt static void vcons_copyrows_buffer(void *, int, int, int);
85 1.7.6.2 yamt static void vcons_eraserows_buffer(void *, int, int, long);
86 1.7.6.2 yamt static void vcons_putchar_buffer(void *, int, int, u_int, long);
87 1.7.6.2 yamt
88 1.7.6.2 yamt /*
89 1.7.6.2 yamt * actual wrapper methods which call both the _buffer ones above and the
90 1.7.6.2 yamt * driver supplied ones to do the drawing
91 1.7.6.2 yamt */
92 1.7.6.2 yamt static void vcons_copycols(void *, int, int, int, int);
93 1.7.6.2 yamt static void vcons_erasecols(void *, int, int, int, long);
94 1.7.6.2 yamt static void vcons_copyrows(void *, int, int, int);
95 1.7.6.2 yamt static void vcons_eraserows(void *, int, int, long);
96 1.7.6.2 yamt static void vcons_putchar(void *, int, int, u_int, long);
97 1.7.6.2 yamt static void vcons_cursor(void *, int, int, int);
98 1.7.6.2 yamt
99 1.7.6.4 yamt /* support for reading/writing text buffers. For wsmoused */
100 1.7.6.2 yamt static int vcons_putwschar(struct vcons_screen *, struct wsdisplay_char *);
101 1.7.6.2 yamt static int vcons_getwschar(struct vcons_screen *, struct wsdisplay_char *);
102 1.7.6.2 yamt
103 1.7.6.2 yamt static void vcons_lock(struct vcons_screen *);
104 1.7.6.2 yamt static void vcons_unlock(struct vcons_screen *);
105 1.7.6.2 yamt
106 1.7.6.4 yamt #ifdef VCONS_SWITCH_ASYNC
107 1.7.6.4 yamt static void vcons_kthread(void *);
108 1.7.6.4 yamt #endif
109 1.7.6.2 yamt
110 1.7.6.2 yamt int
111 1.7.6.2 yamt vcons_init(struct vcons_data *vd, void *cookie, struct wsscreen_descr *def,
112 1.7.6.2 yamt struct wsdisplay_accessops *ao)
113 1.7.6.2 yamt {
114 1.7.6.2 yamt
115 1.7.6.2 yamt /* zero out everything so we can rely on untouched fields being 0 */
116 1.7.6.2 yamt memset(vd, 0, sizeof(struct vcons_data));
117 1.7.6.2 yamt
118 1.7.6.2 yamt vd->cookie = cookie;
119 1.7.6.2 yamt
120 1.7.6.2 yamt vd->init_screen = vcons_dummy_init_screen;
121 1.7.6.2 yamt vd->show_screen_cb = NULL;
122 1.7.6.2 yamt
123 1.7.6.2 yamt /* keep a copy of the accessops that we replace below with our
124 1.7.6.2 yamt * own wrappers */
125 1.7.6.2 yamt vd->ioctl = ao->ioctl;
126 1.7.6.2 yamt
127 1.7.6.2 yamt /* configure the accessops */
128 1.7.6.2 yamt ao->ioctl = vcons_ioctl;
129 1.7.6.2 yamt ao->alloc_screen = vcons_alloc_screen;
130 1.7.6.2 yamt ao->free_screen = vcons_free_screen;
131 1.7.6.2 yamt ao->show_screen = vcons_show_screen;
132 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
133 1.7.6.4 yamt ao->scroll = vcons_scroll;
134 1.7.6.4 yamt #endif
135 1.7.6.2 yamt
136 1.7.6.2 yamt LIST_INIT(&vd->screens);
137 1.7.6.2 yamt vd->active = NULL;
138 1.7.6.2 yamt vd->wanted = NULL;
139 1.7.6.2 yamt vd->currenttype = def;
140 1.7.6.4 yamt callout_init(&vd->switch_callout, 0);
141 1.7.6.5 yamt callout_setfunc(&vd->switch_callout, vcons_do_switch, vd);
142 1.7.6.2 yamt
143 1.7.6.2 yamt /*
144 1.7.6.2 yamt * a lock to serialize access to the framebuffer.
145 1.7.6.2 yamt * when switching screens we need to make sure there's no rasops
146 1.7.6.2 yamt * operation in progress
147 1.7.6.2 yamt */
148 1.7.6.2 yamt #ifdef DIAGNOSTIC
149 1.7.6.2 yamt vd->switch_poll_count = 0;
150 1.7.6.2 yamt #endif
151 1.7.6.4 yamt #ifdef VCONS_SWITCH_ASYNC
152 1.7.6.4 yamt kthread_create(PRI_NONE, 0, NULL, vcons_kthread, vd,
153 1.7.6.4 yamt &vd->redraw_thread, "vcons_draw");
154 1.7.6.4 yamt #endif
155 1.7.6.2 yamt return 0;
156 1.7.6.2 yamt }
157 1.7.6.2 yamt
158 1.7.6.2 yamt static void
159 1.7.6.2 yamt vcons_lock(struct vcons_screen *scr)
160 1.7.6.2 yamt {
161 1.7.6.2 yamt #ifdef VCONS_PARANOIA
162 1.7.6.2 yamt int s;
163 1.7.6.2 yamt
164 1.7.6.2 yamt s = splhigh();
165 1.7.6.2 yamt #endif
166 1.7.6.2 yamt SCREEN_BUSY(scr);
167 1.7.6.2 yamt #ifdef VCONS_PARANOIA
168 1.7.6.2 yamt splx(s);
169 1.7.6.2 yamt #endif
170 1.7.6.2 yamt }
171 1.7.6.2 yamt
172 1.7.6.2 yamt static void
173 1.7.6.2 yamt vcons_unlock(struct vcons_screen *scr)
174 1.7.6.2 yamt {
175 1.7.6.2 yamt #ifdef VCONS_PARANOIA
176 1.7.6.2 yamt int s;
177 1.7.6.2 yamt
178 1.7.6.2 yamt s = splhigh();
179 1.7.6.2 yamt #endif
180 1.7.6.2 yamt SCREEN_IDLE(scr);
181 1.7.6.2 yamt #ifdef VCONS_PARANOIA
182 1.7.6.2 yamt splx(s);
183 1.7.6.2 yamt #endif
184 1.7.6.4 yamt #ifdef VCONS_SWITCH_ASYNC
185 1.7.6.4 yamt wakeup(&scr->scr_vd->done_drawing);
186 1.7.6.4 yamt #endif
187 1.7.6.2 yamt }
188 1.7.6.2 yamt
189 1.7.6.2 yamt static void
190 1.7.6.3 yamt vcons_dummy_init_screen(void *cookie,
191 1.7.6.3 yamt struct vcons_screen *scr, int exists,
192 1.7.6.3 yamt long *defattr)
193 1.7.6.2 yamt {
194 1.7.6.2 yamt
195 1.7.6.2 yamt /*
196 1.7.6.2 yamt * default init_screen() method.
197 1.7.6.2 yamt * Needs to be overwritten so we bitch and whine in case anyone ends
198 1.7.6.2 yamt * up in here.
199 1.7.6.2 yamt */
200 1.7.6.2 yamt printf("vcons_init_screen: dummy function called. Your driver is "
201 1.7.6.2 yamt "supposed to supply a replacement for proper operation\n");
202 1.7.6.2 yamt }
203 1.7.6.2 yamt
204 1.7.6.2 yamt int
205 1.7.6.2 yamt vcons_init_screen(struct vcons_data *vd, struct vcons_screen *scr,
206 1.7.6.2 yamt int existing, long *defattr)
207 1.7.6.2 yamt {
208 1.7.6.2 yamt struct rasops_info *ri = &scr->scr_ri;
209 1.7.6.2 yamt int cnt, i;
210 1.7.6.2 yamt
211 1.7.6.2 yamt scr->scr_cookie = vd->cookie;
212 1.7.6.2 yamt scr->scr_vd = scr->scr_origvd = vd;
213 1.7.6.4 yamt scr->scr_busy = 0;
214 1.7.6.2 yamt
215 1.7.6.2 yamt /*
216 1.7.6.2 yamt * call the driver-supplied init_screen function which is expected
217 1.7.6.2 yamt * to set up rasops_info, override cursor() and probably others
218 1.7.6.2 yamt */
219 1.7.6.2 yamt vd->init_screen(vd->cookie, scr, existing, defattr);
220 1.7.6.2 yamt
221 1.7.6.2 yamt /*
222 1.7.6.2 yamt * save the non virtual console aware rasops and replace them with
223 1.7.6.2 yamt * our wrappers
224 1.7.6.2 yamt */
225 1.7.6.2 yamt vd->eraserows = ri->ri_ops.eraserows;
226 1.7.6.2 yamt vd->copyrows = ri->ri_ops.copyrows;
227 1.7.6.2 yamt vd->erasecols = ri->ri_ops.erasecols;
228 1.7.6.2 yamt vd->copycols = ri->ri_ops.copycols;
229 1.7.6.2 yamt vd->putchar = ri->ri_ops.putchar;
230 1.7.6.2 yamt vd->cursor = ri->ri_ops.cursor;
231 1.7.6.2 yamt
232 1.7.6.2 yamt ri->ri_ops.eraserows = vcons_eraserows;
233 1.7.6.2 yamt ri->ri_ops.copyrows = vcons_copyrows;
234 1.7.6.2 yamt ri->ri_ops.erasecols = vcons_erasecols;
235 1.7.6.2 yamt ri->ri_ops.copycols = vcons_copycols;
236 1.7.6.2 yamt ri->ri_ops.putchar = vcons_putchar;
237 1.7.6.2 yamt ri->ri_ops.cursor = vcons_cursor;
238 1.7.6.2 yamt ri->ri_hw = scr;
239 1.7.6.2 yamt
240 1.7.6.2 yamt /*
241 1.7.6.2 yamt * we allocate both chars and attributes in one chunk, attributes first
242 1.7.6.2 yamt * because they have the (potentially) bigger alignment
243 1.7.6.2 yamt */
244 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
245 1.7.6.4 yamt cnt = (ri->ri_rows + WSDISPLAY_SCROLLBACK_LINES) * ri->ri_cols;
246 1.7.6.4 yamt scr->scr_lines_in_buffer = WSDISPLAY_SCROLLBACK_LINES;
247 1.7.6.4 yamt scr->scr_current_line = 0;
248 1.7.6.4 yamt scr->scr_line_wanted = 0;
249 1.7.6.4 yamt scr->scr_offset_to_zero = ri->ri_cols * WSDISPLAY_SCROLLBACK_LINES;
250 1.7.6.4 yamt scr->scr_current_offset = scr->scr_offset_to_zero;
251 1.7.6.4 yamt #else
252 1.7.6.2 yamt cnt = ri->ri_rows * ri->ri_cols;
253 1.7.6.4 yamt #endif
254 1.7.6.2 yamt scr->scr_attrs = (long *)malloc(cnt * (sizeof(long) +
255 1.7.6.2 yamt sizeof(uint16_t)), M_DEVBUF, M_WAITOK);
256 1.7.6.2 yamt if (scr->scr_attrs == NULL)
257 1.7.6.2 yamt return ENOMEM;
258 1.7.6.2 yamt
259 1.7.6.2 yamt scr->scr_chars = (uint16_t *)&scr->scr_attrs[cnt];
260 1.7.6.2 yamt
261 1.7.6.2 yamt ri->ri_ops.allocattr(ri, WS_DEFAULT_FG, WS_DEFAULT_BG, 0, defattr);
262 1.7.6.2 yamt scr->scr_defattr = *defattr;
263 1.7.6.2 yamt
264 1.7.6.2 yamt /*
265 1.7.6.2 yamt * fill the attribute buffer with *defattr, chars with 0x20
266 1.7.6.2 yamt * since we don't know if the driver tries to mimic firmware output or
267 1.7.6.2 yamt * reset everything we do nothing to VRAM here, any driver that feels
268 1.7.6.2 yamt * the need to clear screen or something will have to do it on its own
269 1.7.6.2 yamt * Additional screens will start out in the background anyway so
270 1.7.6.2 yamt * cleaning or not only really affects the initial console screen
271 1.7.6.2 yamt */
272 1.7.6.2 yamt for (i = 0; i < cnt; i++) {
273 1.7.6.2 yamt scr->scr_attrs[i] = *defattr;
274 1.7.6.2 yamt scr->scr_chars[i] = 0x20;
275 1.7.6.2 yamt }
276 1.7.6.2 yamt
277 1.7.6.2 yamt if(vd->active == NULL) {
278 1.7.6.2 yamt vd->active = scr;
279 1.7.6.2 yamt SCREEN_VISIBLE(scr);
280 1.7.6.2 yamt }
281 1.7.6.2 yamt
282 1.7.6.2 yamt if (existing) {
283 1.7.6.2 yamt SCREEN_VISIBLE(scr);
284 1.7.6.2 yamt vd->active = scr;
285 1.7.6.2 yamt } else {
286 1.7.6.2 yamt SCREEN_INVISIBLE(scr);
287 1.7.6.2 yamt }
288 1.7.6.2 yamt
289 1.7.6.2 yamt LIST_INSERT_HEAD(&vd->screens, scr, next);
290 1.7.6.2 yamt return 0;
291 1.7.6.2 yamt }
292 1.7.6.2 yamt
293 1.7.6.2 yamt static void
294 1.7.6.5 yamt vcons_do_switch(void *arg)
295 1.7.6.2 yamt {
296 1.7.6.5 yamt struct vcons_data *vd = arg;
297 1.7.6.2 yamt struct vcons_screen *scr, *oldscr;
298 1.7.6.2 yamt
299 1.7.6.2 yamt scr = vd->wanted;
300 1.7.6.2 yamt if (!scr) {
301 1.7.6.2 yamt printf("vcons_switch_screen: disappeared\n");
302 1.7.6.2 yamt vd->switch_cb(vd->switch_cb_arg, EIO, 0);
303 1.7.6.2 yamt return;
304 1.7.6.2 yamt }
305 1.7.6.2 yamt oldscr = vd->active; /* can be NULL! */
306 1.7.6.2 yamt
307 1.7.6.2 yamt /*
308 1.7.6.2 yamt * if there's an old, visible screen we mark it invisible and wait
309 1.7.6.2 yamt * until it's not busy so we can safely switch
310 1.7.6.2 yamt */
311 1.7.6.2 yamt if (oldscr != NULL) {
312 1.7.6.2 yamt SCREEN_INVISIBLE(oldscr);
313 1.7.6.2 yamt if (SCREEN_IS_BUSY(oldscr)) {
314 1.7.6.5 yamt callout_schedule(&vd->switch_callout, 1);
315 1.7.6.2 yamt #ifdef DIAGNOSTIC
316 1.7.6.2 yamt /* bitch if we wait too long */
317 1.7.6.2 yamt vd->switch_poll_count++;
318 1.7.6.2 yamt if (vd->switch_poll_count > 100) {
319 1.7.6.2 yamt panic("vcons: screen still busy");
320 1.7.6.2 yamt }
321 1.7.6.2 yamt #endif
322 1.7.6.2 yamt return;
323 1.7.6.2 yamt }
324 1.7.6.2 yamt /* invisible screen -> no visible cursor image */
325 1.7.6.2 yamt oldscr->scr_ri.ri_flg &= ~RI_CURSOR;
326 1.7.6.2 yamt #ifdef DIAGNOSTIC
327 1.7.6.2 yamt vd->switch_poll_count = 0;
328 1.7.6.2 yamt #endif
329 1.7.6.2 yamt }
330 1.7.6.2 yamt
331 1.7.6.2 yamt if (scr == oldscr)
332 1.7.6.2 yamt return;
333 1.7.6.2 yamt
334 1.7.6.2 yamt #ifdef DIAGNOSTIC
335 1.7.6.2 yamt if (SCREEN_IS_VISIBLE(scr))
336 1.7.6.4 yamt printf("vcons_switch_screen: already active");
337 1.7.6.2 yamt #endif
338 1.7.6.2 yamt
339 1.7.6.2 yamt #ifdef notyet
340 1.7.6.2 yamt if (vd->currenttype != type) {
341 1.7.6.2 yamt vcons_set_screentype(vd, type);
342 1.7.6.2 yamt vd->currenttype = type;
343 1.7.6.2 yamt }
344 1.7.6.2 yamt #endif
345 1.7.6.2 yamt
346 1.7.6.2 yamt SCREEN_VISIBLE(scr);
347 1.7.6.2 yamt vd->active = scr;
348 1.7.6.2 yamt vd->wanted = NULL;
349 1.7.6.2 yamt
350 1.7.6.2 yamt if (vd->show_screen_cb != NULL)
351 1.7.6.2 yamt vd->show_screen_cb(scr);
352 1.7.6.2 yamt
353 1.7.6.2 yamt if ((scr->scr_flags & VCONS_NO_REDRAW) == 0)
354 1.7.6.2 yamt vcons_redraw_screen(scr);
355 1.7.6.2 yamt
356 1.7.6.2 yamt if (vd->switch_cb)
357 1.7.6.2 yamt vd->switch_cb(vd->switch_cb_arg, 0, 0);
358 1.7.6.2 yamt }
359 1.7.6.2 yamt
360 1.7.6.2 yamt void
361 1.7.6.2 yamt vcons_redraw_screen(struct vcons_screen *scr)
362 1.7.6.2 yamt {
363 1.7.6.2 yamt uint16_t *charptr = scr->scr_chars;
364 1.7.6.2 yamt long *attrptr = scr->scr_attrs;
365 1.7.6.2 yamt struct rasops_info *ri = &scr->scr_ri;
366 1.7.6.2 yamt int i, j, offset;
367 1.7.6.2 yamt
368 1.7.6.2 yamt vcons_lock(scr);
369 1.7.6.2 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
370 1.7.6.2 yamt
371 1.7.6.2 yamt /*
372 1.7.6.2 yamt * only clear the screen when RI_FULLCLEAR is set since we're
373 1.7.6.2 yamt * going to overwrite every single character cell anyway
374 1.7.6.2 yamt */
375 1.7.6.2 yamt if (ri->ri_flg & RI_FULLCLEAR) {
376 1.7.6.2 yamt scr->scr_vd->eraserows(ri, 0, ri->ri_rows,
377 1.7.6.2 yamt scr->scr_defattr);
378 1.7.6.2 yamt }
379 1.7.6.2 yamt
380 1.7.6.2 yamt /* redraw the screen */
381 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
382 1.7.6.4 yamt offset = scr->scr_current_offset;
383 1.7.6.4 yamt #else
384 1.7.6.2 yamt offset = 0;
385 1.7.6.4 yamt #endif
386 1.7.6.2 yamt for (i = 0; i < ri->ri_rows; i++) {
387 1.7.6.2 yamt for (j = 0; j < ri->ri_cols; j++) {
388 1.7.6.2 yamt /*
389 1.7.6.2 yamt * no need to use the wrapper function - we
390 1.7.6.2 yamt * don't change any characters or attributes
391 1.7.6.2 yamt * and we already made sure the screen we're
392 1.7.6.2 yamt * working on is visible
393 1.7.6.2 yamt */
394 1.7.6.2 yamt scr->scr_vd->putchar(ri, i, j,
395 1.7.6.2 yamt charptr[offset], attrptr[offset]);
396 1.7.6.2 yamt offset++;
397 1.7.6.2 yamt }
398 1.7.6.2 yamt }
399 1.7.6.2 yamt ri->ri_flg &= ~RI_CURSOR;
400 1.7.6.2 yamt scr->scr_vd->cursor(ri, 1, ri->ri_crow, ri->ri_ccol);
401 1.7.6.2 yamt }
402 1.7.6.2 yamt vcons_unlock(scr);
403 1.7.6.2 yamt }
404 1.7.6.2 yamt
405 1.7.6.2 yamt static int
406 1.7.6.4 yamt vcons_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
407 1.7.6.2 yamt struct lwp *l)
408 1.7.6.2 yamt {
409 1.7.6.2 yamt struct vcons_data *vd = v;
410 1.7.6.2 yamt int error;
411 1.7.6.2 yamt
412 1.7.6.2 yamt switch (cmd) {
413 1.7.6.2 yamt case WSDISPLAYIO_GETWSCHAR:
414 1.7.6.2 yamt error = vcons_getwschar((struct vcons_screen *)vs,
415 1.7.6.2 yamt (struct wsdisplay_char *)data);
416 1.7.6.2 yamt break;
417 1.7.6.2 yamt
418 1.7.6.2 yamt case WSDISPLAYIO_PUTWSCHAR:
419 1.7.6.2 yamt error = vcons_putwschar((struct vcons_screen *)vs,
420 1.7.6.2 yamt (struct wsdisplay_char *)data);
421 1.7.6.2 yamt break;
422 1.7.6.2 yamt
423 1.7.6.2 yamt default:
424 1.7.6.2 yamt if (vd->ioctl != NULL)
425 1.7.6.2 yamt error = (*vd->ioctl)(v, vs, cmd, data, flag, l);
426 1.7.6.2 yamt else
427 1.7.6.2 yamt error = EPASSTHROUGH;
428 1.7.6.2 yamt }
429 1.7.6.2 yamt
430 1.7.6.2 yamt return error;
431 1.7.6.2 yamt }
432 1.7.6.2 yamt
433 1.7.6.2 yamt static int
434 1.7.6.2 yamt vcons_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
435 1.7.6.2 yamt int *curxp, int *curyp, long *defattrp)
436 1.7.6.2 yamt {
437 1.7.6.2 yamt struct vcons_data *vd = v;
438 1.7.6.2 yamt struct vcons_screen *scr;
439 1.7.6.2 yamt int ret;
440 1.7.6.2 yamt
441 1.7.6.2 yamt scr = malloc(sizeof(struct vcons_screen), M_DEVBUF, M_WAITOK | M_ZERO);
442 1.7.6.2 yamt if (scr == NULL)
443 1.7.6.2 yamt return ENOMEM;
444 1.7.6.2 yamt
445 1.7.6.2 yamt scr->scr_flags = 0;
446 1.7.6.2 yamt scr->scr_status = 0;
447 1.7.6.2 yamt scr->scr_busy = 0;
448 1.7.6.2 yamt scr->scr_type = type;
449 1.7.6.2 yamt
450 1.7.6.2 yamt ret = vcons_init_screen(vd, scr, 0, defattrp);
451 1.7.6.2 yamt if (ret != 0) {
452 1.7.6.2 yamt free(scr, M_DEVBUF);
453 1.7.6.2 yamt return ret;
454 1.7.6.2 yamt }
455 1.7.6.2 yamt
456 1.7.6.2 yamt if (vd->active == NULL) {
457 1.7.6.2 yamt SCREEN_VISIBLE(scr);
458 1.7.6.2 yamt vd->active = scr;
459 1.7.6.2 yamt vd->currenttype = type;
460 1.7.6.2 yamt }
461 1.7.6.2 yamt
462 1.7.6.2 yamt *cookiep = scr;
463 1.7.6.2 yamt *curxp = scr->scr_ri.ri_ccol;
464 1.7.6.2 yamt *curyp = scr->scr_ri.ri_crow;
465 1.7.6.2 yamt return 0;
466 1.7.6.2 yamt }
467 1.7.6.2 yamt
468 1.7.6.2 yamt static void
469 1.7.6.2 yamt vcons_free_screen(void *v, void *cookie)
470 1.7.6.2 yamt {
471 1.7.6.2 yamt struct vcons_data *vd = v;
472 1.7.6.2 yamt struct vcons_screen *scr = cookie;
473 1.7.6.2 yamt
474 1.7.6.2 yamt vcons_lock(scr);
475 1.7.6.2 yamt /* there should be no rasops activity here */
476 1.7.6.2 yamt
477 1.7.6.2 yamt LIST_REMOVE(scr, next);
478 1.7.6.2 yamt
479 1.7.6.2 yamt if ((scr->scr_flags & VCONS_SCREEN_IS_STATIC) == 0) {
480 1.7.6.2 yamt free(scr->scr_attrs, M_DEVBUF);
481 1.7.6.2 yamt free(scr, M_DEVBUF);
482 1.7.6.2 yamt } else {
483 1.7.6.2 yamt /*
484 1.7.6.2 yamt * maybe we should just restore the old rasops_info methods
485 1.7.6.2 yamt * and free the character/attribute buffer here?
486 1.7.6.2 yamt */
487 1.7.6.2 yamt #ifdef VCONS_DEBUG
488 1.7.6.2 yamt panic("vcons_free_screen: console");
489 1.7.6.2 yamt #else
490 1.7.6.2 yamt printf("vcons_free_screen: console\n");
491 1.7.6.2 yamt #endif
492 1.7.6.2 yamt }
493 1.7.6.2 yamt
494 1.7.6.2 yamt if (vd->active == scr)
495 1.7.6.2 yamt vd->active = NULL;
496 1.7.6.2 yamt }
497 1.7.6.2 yamt
498 1.7.6.2 yamt static int
499 1.7.6.2 yamt vcons_show_screen(void *v, void *cookie, int waitok,
500 1.7.6.2 yamt void (*cb)(void *, int, int), void *cb_arg)
501 1.7.6.2 yamt {
502 1.7.6.2 yamt struct vcons_data *vd = v;
503 1.7.6.2 yamt struct vcons_screen *scr;
504 1.7.6.2 yamt
505 1.7.6.2 yamt scr = cookie;
506 1.7.6.2 yamt if (scr == vd->active)
507 1.7.6.2 yamt return 0;
508 1.7.6.2 yamt
509 1.7.6.2 yamt vd->wanted = scr;
510 1.7.6.2 yamt vd->switch_cb = cb;
511 1.7.6.2 yamt vd->switch_cb_arg = cb_arg;
512 1.7.6.4 yamt #ifdef VCONS_SWITCH_ASYNC
513 1.7.6.4 yamt wakeup(&vd->start_drawing);
514 1.7.6.4 yamt return EAGAIN;
515 1.7.6.4 yamt #else
516 1.7.6.2 yamt if (cb) {
517 1.7.6.5 yamt callout_schedule(&vd->switch_callout, 0);
518 1.7.6.2 yamt return EAGAIN;
519 1.7.6.2 yamt }
520 1.7.6.2 yamt
521 1.7.6.2 yamt vcons_do_switch(vd);
522 1.7.6.2 yamt return 0;
523 1.7.6.4 yamt #endif
524 1.7.6.2 yamt }
525 1.7.6.2 yamt
526 1.7.6.2 yamt /* wrappers for rasops_info methods */
527 1.7.6.2 yamt
528 1.7.6.2 yamt static void
529 1.7.6.2 yamt vcons_copycols_buffer(void *cookie, int row, int srccol, int dstcol, int ncols)
530 1.7.6.2 yamt {
531 1.7.6.2 yamt struct rasops_info *ri = cookie;
532 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
533 1.7.6.2 yamt int from = srccol + row * ri->ri_cols;
534 1.7.6.2 yamt int to = dstcol + row * ri->ri_cols;
535 1.7.6.2 yamt
536 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
537 1.7.6.4 yamt int offset;
538 1.7.6.4 yamt offset = scr->scr_offset_to_zero;
539 1.7.6.4 yamt
540 1.7.6.4 yamt memmove(&scr->scr_attrs[offset + to], &scr->scr_attrs[offset + from],
541 1.7.6.4 yamt ncols * sizeof(long));
542 1.7.6.4 yamt memmove(&scr->scr_chars[offset + to], &scr->scr_chars[offset + from],
543 1.7.6.4 yamt ncols * sizeof(uint16_t));
544 1.7.6.4 yamt #else
545 1.7.6.2 yamt memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
546 1.7.6.2 yamt ncols * sizeof(long));
547 1.7.6.2 yamt memmove(&scr->scr_chars[to], &scr->scr_chars[from],
548 1.7.6.2 yamt ncols * sizeof(uint16_t));
549 1.7.6.4 yamt #endif
550 1.7.6.2 yamt }
551 1.7.6.2 yamt
552 1.7.6.2 yamt static void
553 1.7.6.2 yamt vcons_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
554 1.7.6.2 yamt {
555 1.7.6.2 yamt struct rasops_info *ri = cookie;
556 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
557 1.7.6.2 yamt
558 1.7.6.2 yamt vcons_copycols_buffer(cookie, row, srccol, dstcol, ncols);
559 1.7.6.2 yamt
560 1.7.6.2 yamt vcons_lock(scr);
561 1.7.6.2 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
562 1.7.6.2 yamt scr->scr_vd->copycols(cookie, row, srccol, dstcol, ncols);
563 1.7.6.2 yamt }
564 1.7.6.2 yamt vcons_unlock(scr);
565 1.7.6.2 yamt }
566 1.7.6.2 yamt
567 1.7.6.2 yamt static void
568 1.7.6.2 yamt vcons_erasecols_buffer(void *cookie, int row, int startcol, int ncols, long fillattr)
569 1.7.6.2 yamt {
570 1.7.6.2 yamt struct rasops_info *ri = cookie;
571 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
572 1.7.6.2 yamt int start = startcol + row * ri->ri_cols;
573 1.7.6.2 yamt int end = start + ncols, i;
574 1.7.6.2 yamt
575 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
576 1.7.6.4 yamt int offset;
577 1.7.6.4 yamt offset = scr->scr_offset_to_zero;
578 1.7.6.4 yamt
579 1.7.6.4 yamt for (i = start; i < end; i++) {
580 1.7.6.4 yamt scr->scr_attrs[offset + i] = fillattr;
581 1.7.6.4 yamt scr->scr_chars[offset + i] = 0x20;
582 1.7.6.4 yamt }
583 1.7.6.4 yamt #else
584 1.7.6.2 yamt for (i = start; i < end; i++) {
585 1.7.6.2 yamt scr->scr_attrs[i] = fillattr;
586 1.7.6.2 yamt scr->scr_chars[i] = 0x20;
587 1.7.6.2 yamt }
588 1.7.6.4 yamt #endif
589 1.7.6.2 yamt }
590 1.7.6.2 yamt
591 1.7.6.2 yamt static void
592 1.7.6.2 yamt vcons_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
593 1.7.6.2 yamt {
594 1.7.6.2 yamt struct rasops_info *ri = cookie;
595 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
596 1.7.6.2 yamt
597 1.7.6.2 yamt vcons_erasecols_buffer(cookie, row, startcol, ncols, fillattr);
598 1.7.6.2 yamt
599 1.7.6.2 yamt vcons_lock(scr);
600 1.7.6.2 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
601 1.7.6.2 yamt scr->scr_vd->erasecols(cookie, row, startcol, ncols,
602 1.7.6.2 yamt fillattr);
603 1.7.6.2 yamt }
604 1.7.6.2 yamt vcons_unlock(scr);
605 1.7.6.2 yamt }
606 1.7.6.2 yamt
607 1.7.6.2 yamt static void
608 1.7.6.2 yamt vcons_copyrows_buffer(void *cookie, int srcrow, int dstrow, int nrows)
609 1.7.6.2 yamt {
610 1.7.6.2 yamt struct rasops_info *ri = cookie;
611 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
612 1.7.6.2 yamt int from, to, len;
613 1.7.6.2 yamt
614 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
615 1.7.6.4 yamt int offset;
616 1.7.6.4 yamt offset = scr->scr_offset_to_zero;
617 1.7.6.4 yamt
618 1.7.6.4 yamt /* do we need to scroll the back buffer? */
619 1.7.6.4 yamt if (dstrow == 0) {
620 1.7.6.4 yamt from = ri->ri_cols * srcrow;
621 1.7.6.4 yamt to = ri->ri_cols * dstrow;
622 1.7.6.4 yamt
623 1.7.6.4 yamt memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
624 1.7.6.4 yamt scr->scr_offset_to_zero * sizeof(long));
625 1.7.6.4 yamt memmove(&scr->scr_chars[to], &scr->scr_chars[from],
626 1.7.6.4 yamt scr->scr_offset_to_zero * sizeof(uint16_t));
627 1.7.6.4 yamt }
628 1.7.6.4 yamt from = ri->ri_cols * srcrow + offset;
629 1.7.6.4 yamt to = ri->ri_cols * dstrow + offset;
630 1.7.6.4 yamt len = ri->ri_cols * nrows;
631 1.7.6.4 yamt
632 1.7.6.4 yamt #else
633 1.7.6.2 yamt from = ri->ri_cols * srcrow;
634 1.7.6.2 yamt to = ri->ri_cols * dstrow;
635 1.7.6.2 yamt len = ri->ri_cols * nrows;
636 1.7.6.4 yamt #endif
637 1.7.6.2 yamt memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
638 1.7.6.2 yamt len * sizeof(long));
639 1.7.6.2 yamt memmove(&scr->scr_chars[to], &scr->scr_chars[from],
640 1.7.6.2 yamt len * sizeof(uint16_t));
641 1.7.6.2 yamt }
642 1.7.6.2 yamt
643 1.7.6.2 yamt static void
644 1.7.6.2 yamt vcons_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
645 1.7.6.2 yamt {
646 1.7.6.2 yamt struct rasops_info *ri = cookie;
647 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
648 1.7.6.2 yamt
649 1.7.6.2 yamt vcons_copyrows_buffer(cookie, srcrow, dstrow, nrows);
650 1.7.6.2 yamt
651 1.7.6.2 yamt vcons_lock(scr);
652 1.7.6.2 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
653 1.7.6.2 yamt scr->scr_vd->copyrows(cookie, srcrow, dstrow, nrows);
654 1.7.6.2 yamt }
655 1.7.6.2 yamt vcons_unlock(scr);
656 1.7.6.2 yamt }
657 1.7.6.2 yamt
658 1.7.6.2 yamt static void
659 1.7.6.2 yamt vcons_eraserows_buffer(void *cookie, int row, int nrows, long fillattr)
660 1.7.6.2 yamt {
661 1.7.6.2 yamt struct rasops_info *ri = cookie;
662 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
663 1.7.6.2 yamt int start, end, i;
664 1.7.6.2 yamt
665 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
666 1.7.6.4 yamt int offset;
667 1.7.6.4 yamt offset = scr->scr_offset_to_zero;
668 1.7.6.4 yamt
669 1.7.6.4 yamt start = ri->ri_cols * row + offset;
670 1.7.6.4 yamt end = ri->ri_cols * (row + nrows) + offset;
671 1.7.6.4 yamt #else
672 1.7.6.2 yamt start = ri->ri_cols * row;
673 1.7.6.2 yamt end = ri->ri_cols * (row + nrows);
674 1.7.6.4 yamt #endif
675 1.7.6.2 yamt
676 1.7.6.2 yamt for (i = start; i < end; i++) {
677 1.7.6.2 yamt scr->scr_attrs[i] = fillattr;
678 1.7.6.2 yamt scr->scr_chars[i] = 0x20;
679 1.7.6.2 yamt }
680 1.7.6.2 yamt }
681 1.7.6.2 yamt
682 1.7.6.2 yamt static void
683 1.7.6.2 yamt vcons_eraserows(void *cookie, int row, int nrows, long fillattr)
684 1.7.6.2 yamt {
685 1.7.6.2 yamt struct rasops_info *ri = cookie;
686 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
687 1.7.6.2 yamt
688 1.7.6.2 yamt vcons_eraserows_buffer(cookie, row, nrows, fillattr);
689 1.7.6.2 yamt
690 1.7.6.2 yamt vcons_lock(scr);
691 1.7.6.2 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
692 1.7.6.2 yamt scr->scr_vd->eraserows(cookie, row, nrows, fillattr);
693 1.7.6.2 yamt }
694 1.7.6.2 yamt vcons_unlock(scr);
695 1.7.6.2 yamt }
696 1.7.6.2 yamt
697 1.7.6.2 yamt static void
698 1.7.6.2 yamt vcons_putchar_buffer(void *cookie, int row, int col, u_int c, long attr)
699 1.7.6.2 yamt {
700 1.7.6.2 yamt struct rasops_info *ri = cookie;
701 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
702 1.7.6.2 yamt int pos;
703 1.7.6.2 yamt
704 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
705 1.7.6.4 yamt int offset;
706 1.7.6.4 yamt offset = scr->scr_offset_to_zero;
707 1.7.6.4 yamt
708 1.7.6.4 yamt if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
709 1.7.6.4 yamt (col < ri->ri_cols)) {
710 1.7.6.4 yamt pos = col + row * ri->ri_cols;
711 1.7.6.4 yamt scr->scr_attrs[pos + offset] = attr;
712 1.7.6.4 yamt scr->scr_chars[pos + offset] = c;
713 1.7.6.4 yamt }
714 1.7.6.4 yamt #else
715 1.7.6.2 yamt if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
716 1.7.6.2 yamt (col < ri->ri_cols)) {
717 1.7.6.2 yamt pos = col + row * ri->ri_cols;
718 1.7.6.2 yamt scr->scr_attrs[pos] = attr;
719 1.7.6.2 yamt scr->scr_chars[pos] = c;
720 1.7.6.2 yamt }
721 1.7.6.4 yamt #endif
722 1.7.6.2 yamt }
723 1.7.6.2 yamt
724 1.7.6.2 yamt static void
725 1.7.6.2 yamt vcons_putchar(void *cookie, int row, int col, u_int c, long attr)
726 1.7.6.2 yamt {
727 1.7.6.2 yamt struct rasops_info *ri = cookie;
728 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
729 1.7.6.2 yamt
730 1.7.6.2 yamt vcons_putchar_buffer(cookie, row, col, c, attr);
731 1.7.6.2 yamt
732 1.7.6.2 yamt vcons_lock(scr);
733 1.7.6.2 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
734 1.7.6.2 yamt scr->scr_vd->putchar(cookie, row, col, c, attr);
735 1.7.6.2 yamt }
736 1.7.6.2 yamt vcons_unlock(scr);
737 1.7.6.2 yamt }
738 1.7.6.2 yamt
739 1.7.6.2 yamt static void
740 1.7.6.2 yamt vcons_cursor(void *cookie, int on, int row, int col)
741 1.7.6.2 yamt {
742 1.7.6.2 yamt struct rasops_info *ri = cookie;
743 1.7.6.2 yamt struct vcons_screen *scr = ri->ri_hw;
744 1.7.6.2 yamt
745 1.7.6.2 yamt vcons_lock(scr);
746 1.7.6.2 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
747 1.7.6.2 yamt scr->scr_vd->cursor(cookie, on, row, col);
748 1.7.6.2 yamt } else {
749 1.7.6.2 yamt scr->scr_ri.ri_crow = row;
750 1.7.6.2 yamt scr->scr_ri.ri_ccol = col;
751 1.7.6.2 yamt }
752 1.7.6.2 yamt vcons_unlock(scr);
753 1.7.6.2 yamt }
754 1.7.6.2 yamt
755 1.7.6.2 yamt /* methods to read/write characters via ioctl() */
756 1.7.6.2 yamt
757 1.7.6.2 yamt static int
758 1.7.6.2 yamt vcons_putwschar(struct vcons_screen *scr, struct wsdisplay_char *wsc)
759 1.7.6.2 yamt {
760 1.7.6.2 yamt long attr;
761 1.7.6.2 yamt struct rasops_info *ri;
762 1.7.6.2 yamt
763 1.7.6.2 yamt KASSERT(scr != NULL && wsc != NULL);
764 1.7.6.2 yamt
765 1.7.6.2 yamt ri = &scr->scr_ri;
766 1.7.6.4 yamt
767 1.7.6.4 yamt if (__predict_false((unsigned int)wsc->col > ri->ri_cols ||
768 1.7.6.4 yamt (unsigned int)wsc->row > ri->ri_rows))
769 1.7.6.4 yamt return (EINVAL);
770 1.7.6.2 yamt
771 1.7.6.4 yamt if ((wsc->row >= 0) && (wsc->row < ri->ri_rows) && (wsc->col >= 0) &&
772 1.7.6.4 yamt (wsc->col < ri->ri_cols)) {
773 1.7.6.4 yamt
774 1.7.6.4 yamt ri->ri_ops.allocattr(ri, wsc->foreground, wsc->background,
775 1.7.6.4 yamt wsc->flags, &attr);
776 1.7.6.4 yamt vcons_putchar(ri, wsc->row, wsc->col, wsc->letter, attr);
777 1.7.6.4 yamt #ifdef VCONS_DEBUG
778 1.7.6.4 yamt printf("vcons_putwschar(%d, %d, %x, %lx\n", wsc->row, wsc->col,
779 1.7.6.4 yamt wsc->letter, attr);
780 1.7.6.4 yamt #endif
781 1.7.6.4 yamt return 0;
782 1.7.6.4 yamt } else
783 1.7.6.4 yamt return EINVAL;
784 1.7.6.2 yamt }
785 1.7.6.2 yamt
786 1.7.6.2 yamt static int
787 1.7.6.2 yamt vcons_getwschar(struct vcons_screen *scr, struct wsdisplay_char *wsc)
788 1.7.6.2 yamt {
789 1.7.6.2 yamt int offset;
790 1.7.6.2 yamt long attr;
791 1.7.6.2 yamt struct rasops_info *ri;
792 1.7.6.2 yamt
793 1.7.6.2 yamt KASSERT(scr != NULL && wsc != NULL);
794 1.7.6.2 yamt
795 1.7.6.2 yamt ri = &scr->scr_ri;
796 1.7.6.2 yamt
797 1.7.6.4 yamt if ((wsc->row >= 0) && (wsc->row < ri->ri_rows) && (wsc->col >= 0) &&
798 1.7.6.4 yamt (wsc->col < ri->ri_cols)) {
799 1.7.6.4 yamt
800 1.7.6.4 yamt offset = ri->ri_cols * wsc->row + wsc->col;
801 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
802 1.7.6.4 yamt offset += scr->scr_offset_to_zero;
803 1.7.6.4 yamt #endif
804 1.7.6.4 yamt wsc->letter = scr->scr_chars[offset];
805 1.7.6.4 yamt attr = scr->scr_attrs[offset];
806 1.7.6.4 yamt
807 1.7.6.4 yamt /*
808 1.7.6.4 yamt * this is ugly. We need to break up an attribute into colours and
809 1.7.6.4 yamt * flags but there's no rasops method to do that so we must rely on
810 1.7.6.4 yamt * the 'canonical' encoding.
811 1.7.6.4 yamt */
812 1.7.6.4 yamt #ifdef VCONS_DEBUG
813 1.7.6.4 yamt printf("vcons_getwschar: %d, %d, %x, %lx\n", wsc->row,
814 1.7.6.4 yamt wsc->col, wsc->letter, attr);
815 1.7.6.4 yamt #endif
816 1.7.6.4 yamt wsc->foreground = (attr >> 24) & 0xff;
817 1.7.6.4 yamt wsc->background = (attr >> 16) & 0xff;
818 1.7.6.4 yamt wsc->flags = attr & 0xff;
819 1.7.6.4 yamt return 0;
820 1.7.6.4 yamt } else
821 1.7.6.4 yamt return EINVAL;
822 1.7.6.4 yamt }
823 1.7.6.4 yamt
824 1.7.6.4 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
825 1.7.6.4 yamt
826 1.7.6.4 yamt static void
827 1.7.6.4 yamt vcons_scroll(void *cookie, void *vs, int where)
828 1.7.6.4 yamt {
829 1.7.6.4 yamt struct vcons_screen *scr = vs;
830 1.7.6.4 yamt
831 1.7.6.4 yamt if (where == 0) {
832 1.7.6.4 yamt scr->scr_line_wanted = 0;
833 1.7.6.4 yamt } else {
834 1.7.6.4 yamt scr->scr_line_wanted = scr->scr_line_wanted - where;
835 1.7.6.4 yamt if (scr->scr_line_wanted < 0)
836 1.7.6.4 yamt scr->scr_line_wanted = 0;
837 1.7.6.4 yamt if (scr->scr_line_wanted > scr->scr_lines_in_buffer)
838 1.7.6.4 yamt scr->scr_line_wanted = scr->scr_lines_in_buffer;
839 1.7.6.4 yamt }
840 1.7.6.4 yamt
841 1.7.6.4 yamt if (scr->scr_line_wanted != scr->scr_current_line) {
842 1.7.6.4 yamt
843 1.7.6.4 yamt vcons_do_scroll(scr);
844 1.7.6.4 yamt }
845 1.7.6.4 yamt }
846 1.7.6.4 yamt
847 1.7.6.4 yamt static void
848 1.7.6.4 yamt vcons_do_scroll(struct vcons_screen *scr)
849 1.7.6.4 yamt {
850 1.7.6.4 yamt int dist, from, to, num;
851 1.7.6.4 yamt int r_offset, r_start;
852 1.7.6.4 yamt int i, j;
853 1.7.6.4 yamt
854 1.7.6.4 yamt if (scr->scr_line_wanted == scr->scr_current_line)
855 1.7.6.4 yamt return;
856 1.7.6.4 yamt dist = scr->scr_line_wanted - scr->scr_current_line;
857 1.7.6.4 yamt scr->scr_current_line = scr->scr_line_wanted;
858 1.7.6.4 yamt scr->scr_current_offset = scr->scr_ri.ri_cols *
859 1.7.6.4 yamt (scr->scr_lines_in_buffer - scr->scr_current_line);
860 1.7.6.4 yamt if (abs(dist) >= scr->scr_ri.ri_rows) {
861 1.7.6.4 yamt vcons_redraw_screen(scr);
862 1.7.6.4 yamt return;
863 1.7.6.4 yamt }
864 1.7.6.4 yamt /* scroll and redraw only what we really have to */
865 1.7.6.4 yamt if (dist > 0) {
866 1.7.6.4 yamt /* we scroll down */
867 1.7.6.4 yamt from = 0;
868 1.7.6.4 yamt to = dist;
869 1.7.6.4 yamt num = scr->scr_ri.ri_rows - dist;
870 1.7.6.4 yamt /* now the redraw parameters */
871 1.7.6.4 yamt r_offset = scr->scr_current_offset;
872 1.7.6.4 yamt r_start = 0;
873 1.7.6.4 yamt } else {
874 1.7.6.4 yamt /* scrolling up */
875 1.7.6.4 yamt to = 0;
876 1.7.6.4 yamt from = -dist;
877 1.7.6.4 yamt num = scr->scr_ri.ri_rows + dist;
878 1.7.6.4 yamt r_offset = scr->scr_current_offset + num * scr->scr_ri.ri_cols;
879 1.7.6.4 yamt r_start = num;
880 1.7.6.4 yamt }
881 1.7.6.4 yamt scr->scr_vd->copyrows(scr, from, to, num);
882 1.7.6.4 yamt for (i = 0; i < abs(dist); i++) {
883 1.7.6.4 yamt for (j = 0; j < scr->scr_ri.ri_cols; j++) {
884 1.7.6.4 yamt scr->scr_vd->putchar(scr, i + r_start, j,
885 1.7.6.4 yamt scr->scr_chars[r_offset],
886 1.7.6.4 yamt scr->scr_attrs[r_offset]);
887 1.7.6.4 yamt r_offset++;
888 1.7.6.4 yamt }
889 1.7.6.4 yamt }
890 1.7.6.4 yamt
891 1.7.6.4 yamt if (scr->scr_line_wanted == 0) {
892 1.7.6.4 yamt /* this was a reset - need to draw the cursor */
893 1.7.6.4 yamt scr->scr_ri.ri_flg &= ~RI_CURSOR;
894 1.7.6.4 yamt scr->scr_vd->cursor(scr, 1, scr->scr_ri.ri_crow,
895 1.7.6.4 yamt scr->scr_ri.ri_ccol);
896 1.7.6.4 yamt }
897 1.7.6.4 yamt }
898 1.7.6.4 yamt
899 1.7.6.4 yamt #endif /* WSDISPLAY_SCROLLSUPPORT */
900 1.7.6.4 yamt
901 1.7.6.4 yamt /* async drawing using a kernel thread */
902 1.7.6.4 yamt
903 1.7.6.4 yamt #ifdef VCONS_SWITCH_ASYNC
904 1.7.6.4 yamt static void
905 1.7.6.4 yamt vcons_kthread(void *cookie)
906 1.7.6.4 yamt {
907 1.7.6.4 yamt struct vcons_data *vd = cookie;
908 1.7.6.4 yamt struct vcons_screen *scr;
909 1.7.6.4 yamt int sec = hz;
910 1.7.6.4 yamt
911 1.7.6.4 yamt while (1) {
912 1.7.6.4 yamt
913 1.7.6.4 yamt tsleep(&vd->start_drawing, 0, "vc_idle", sec);
914 1.7.6.4 yamt if ((vd->wanted != vd->active) && (vd->wanted != NULL)) {
915 1.7.6.4 yamt /*
916 1.7.6.4 yamt * we need to switch screens
917 1.7.6.4 yamt * so first we mark the active screen as invisible
918 1.7.6.4 yamt * and wait until it's idle
919 1.7.6.4 yamt */
920 1.7.6.4 yamt scr = vd->wanted;
921 1.7.6.4 yamt SCREEN_INVISIBLE(vd->active);
922 1.7.6.4 yamt while (SCREEN_IS_BUSY(vd->active)) {
923 1.7.6.4 yamt
924 1.7.6.4 yamt tsleep(&vd->done_drawing, 0, "vc_wait", sec);
925 1.7.6.4 yamt }
926 1.7.6.4 yamt /*
927 1.7.6.4 yamt * now we mark the wanted screen busy so nobody
928 1.7.6.4 yamt * messes around while we redraw it
929 1.7.6.4 yamt */
930 1.7.6.4 yamt vd->active = scr;
931 1.7.6.4 yamt vd->wanted = NULL;
932 1.7.6.4 yamt SCREEN_VISIBLE(scr);
933 1.7.6.4 yamt
934 1.7.6.4 yamt if (vd->show_screen_cb != NULL)
935 1.7.6.4 yamt vd->show_screen_cb(scr);
936 1.7.6.4 yamt
937 1.7.6.4 yamt if ((scr->scr_flags & VCONS_NO_REDRAW) == 0)
938 1.7.6.4 yamt vcons_redraw_screen(scr);
939 1.7.6.4 yamt
940 1.7.6.4 yamt if (vd->switch_cb)
941 1.7.6.4 yamt vd->switch_cb(vd->switch_cb_arg, 0, 0);
942 1.7.6.4 yamt }
943 1.7.6.4 yamt }
944 1.7.6.2 yamt }
945 1.7.6.4 yamt #endif /* VCONS_SWITCH_ASYNC */
946