wsdisplay_vcons.c revision 1.3.2.3 1 1.3.2.3 yamt /* $NetBSD: wsdisplay_vcons.c,v 1.3.2.3 2006/03/01 09:28:41 yamt Exp $ */
2 1.3.2.2 yamt
3 1.3.2.2 yamt /*-
4 1.3.2.2 yamt * Copyright (c) 2005, 2006 Michael Lorenz
5 1.3.2.2 yamt * All rights reserved.
6 1.3.2.2 yamt *
7 1.3.2.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.3.2.2 yamt * modification, are permitted provided that the following conditions
9 1.3.2.2 yamt * are met:
10 1.3.2.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.3.2.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.3.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.3.2.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.3.2.2 yamt * documentation and/or other materials provided with the distribution.
15 1.3.2.2 yamt * 3. All advertising materials mentioning features or use of this software
16 1.3.2.2 yamt * must display the following acknowledgement:
17 1.3.2.2 yamt * This product includes software developed by the NetBSD
18 1.3.2.2 yamt * Foundation, Inc. and its contributors.
19 1.3.2.2 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.3.2.2 yamt * contributors may be used to endorse or promote products derived
21 1.3.2.2 yamt * from this software without specific prior written permission.
22 1.3.2.2 yamt *
23 1.3.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.3.2.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.3.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.3.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.3.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.3.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.3.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.3.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.3.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.3.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.3.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
34 1.3.2.2 yamt */
35 1.3.2.2 yamt
36 1.3.2.2 yamt #include <sys/cdefs.h>
37 1.3.2.3 yamt __KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.3.2.3 2006/03/01 09:28:41 yamt Exp $");
38 1.3.2.2 yamt
39 1.3.2.2 yamt #include <sys/param.h>
40 1.3.2.2 yamt #include <sys/systm.h>
41 1.3.2.2 yamt #include <sys/kernel.h>
42 1.3.2.2 yamt #include <sys/buf.h>
43 1.3.2.2 yamt #include <sys/device.h>
44 1.3.2.2 yamt #include <sys/ioctl.h>
45 1.3.2.2 yamt #include <sys/malloc.h>
46 1.3.2.2 yamt #include <sys/mman.h>
47 1.3.2.2 yamt #include <sys/tty.h>
48 1.3.2.2 yamt #include <sys/conf.h>
49 1.3.2.2 yamt #include <sys/proc.h>
50 1.3.2.2 yamt #include <sys/kthread.h>
51 1.3.2.2 yamt #include <sys/tprintf.h>
52 1.3.2.2 yamt
53 1.3.2.2 yamt #include <dev/wscons/wsdisplayvar.h>
54 1.3.2.2 yamt #include <dev/wscons/wsconsio.h>
55 1.3.2.2 yamt #include <dev/wsfont/wsfont.h>
56 1.3.2.2 yamt #include <dev/rasops/rasops.h>
57 1.3.2.2 yamt
58 1.3.2.2 yamt #include <dev/wscons/wsdisplay_vconsvar.h>
59 1.3.2.2 yamt
60 1.3.2.2 yamt static void vcons_dummy_init_screen(void *, struct vcons_screen *, int,
61 1.3.2.2 yamt long *);
62 1.3.2.2 yamt
63 1.3.2.2 yamt static int vcons_alloc_screen(void *, const struct wsscreen_descr *, void **,
64 1.3.2.2 yamt int *, int *, long *);
65 1.3.2.2 yamt static void vcons_free_screen(void *, void *);
66 1.3.2.2 yamt static int vcons_show_screen(void *, void *, int, void (*)(void *, int, int),
67 1.3.2.2 yamt void *);
68 1.3.2.2 yamt
69 1.3.2.2 yamt static void vcons_do_switch(struct vcons_data *);
70 1.3.2.2 yamt
71 1.3.2.2 yamt /* methods that work only on text buffers */
72 1.3.2.2 yamt static void vcons_copycols_buffer(void *, int, int, int, int);
73 1.3.2.2 yamt static void vcons_erasecols_buffer(void *, int, int, int, long);
74 1.3.2.2 yamt static void vcons_copyrows_buffer(void *, int, int, int);
75 1.3.2.2 yamt static void vcons_eraserows_buffer(void *, int, int, long);
76 1.3.2.2 yamt static void vcons_putchar_buffer(void *, int, int, u_int, long);
77 1.3.2.2 yamt
78 1.3.2.2 yamt /*
79 1.3.2.2 yamt * actual wrapper methods which call both the _buffer ones above and the
80 1.3.2.2 yamt * driver supplied ones to do the drawing
81 1.3.2.2 yamt */
82 1.3.2.2 yamt static void vcons_copycols(void *, int, int, int, int);
83 1.3.2.2 yamt static void vcons_erasecols(void *, int, int, int, long);
84 1.3.2.2 yamt static void vcons_copyrows(void *, int, int, int);
85 1.3.2.2 yamt static void vcons_eraserows(void *, int, int, long);
86 1.3.2.2 yamt static void vcons_putchar(void *, int, int, u_int, long);
87 1.3.2.2 yamt static void vcons_cursor(void *, int, int, int);
88 1.3.2.2 yamt
89 1.3.2.2 yamt /* support for readin/writing text buffers. For wsmoused */
90 1.3.2.2 yamt static int vcons_putwschar(void *, struct wsdisplay_char *);
91 1.3.2.2 yamt static int vcons_getwschar(void *, struct wsdisplay_char *);
92 1.3.2.2 yamt
93 1.3.2.2 yamt static void vcons_lock(struct vcons_screen *);
94 1.3.2.2 yamt static void vcons_unlock(struct vcons_screen *);
95 1.3.2.2 yamt
96 1.3.2.2 yamt
97 1.3.2.2 yamt int
98 1.3.2.2 yamt vcons_init(struct vcons_data *vd, void *cookie, struct wsscreen_descr *def,
99 1.3.2.2 yamt struct wsdisplay_accessops *ao)
100 1.3.2.2 yamt {
101 1.3.2.2 yamt
102 1.3.2.2 yamt /* zero out everything so we can rely on untouched fields being 0 */
103 1.3.2.2 yamt memset(vd, 0, sizeof(struct vcons_data));
104 1.3.2.2 yamt
105 1.3.2.2 yamt vd->cookie = cookie;
106 1.3.2.2 yamt
107 1.3.2.2 yamt vd->init_screen = vcons_dummy_init_screen;
108 1.3.2.2 yamt vd->show_screen_cb = NULL;
109 1.3.2.2 yamt
110 1.3.2.2 yamt ao->alloc_screen = vcons_alloc_screen;
111 1.3.2.2 yamt ao->free_screen = vcons_free_screen;
112 1.3.2.2 yamt ao->show_screen = vcons_show_screen;
113 1.3.2.2 yamt ao->getwschar = vcons_getwschar;
114 1.3.2.2 yamt ao->putwschar = vcons_putwschar;
115 1.3.2.2 yamt
116 1.3.2.2 yamt LIST_INIT(&vd->screens);
117 1.3.2.2 yamt vd->active = NULL;
118 1.3.2.2 yamt vd->wanted = NULL;
119 1.3.2.2 yamt vd->currenttype = def;
120 1.3.2.2 yamt callout_init(&vd->switch_callout);
121 1.3.2.2 yamt
122 1.3.2.2 yamt /*
123 1.3.2.2 yamt * a lock to serialize access to the framebuffer.
124 1.3.2.2 yamt * when switching screens we need to make sure there's no rasops
125 1.3.2.2 yamt * operation in progress
126 1.3.2.2 yamt */
127 1.3.2.2 yamt #ifdef DIAGNOSTIC
128 1.3.2.2 yamt vd->switch_poll_count = 0;
129 1.3.2.2 yamt #endif
130 1.3.2.2 yamt return 0;
131 1.3.2.2 yamt }
132 1.3.2.2 yamt
133 1.3.2.2 yamt static void
134 1.3.2.2 yamt vcons_lock(struct vcons_screen *scr)
135 1.3.2.2 yamt {
136 1.3.2.2 yamt #ifdef VCONS_PARANOIA
137 1.3.2.2 yamt int s;
138 1.3.2.2 yamt
139 1.3.2.2 yamt s = splhigh();
140 1.3.2.2 yamt #endif
141 1.3.2.2 yamt SCREEN_BUSY(scr);
142 1.3.2.2 yamt #ifdef VCONS_PARANOIA
143 1.3.2.2 yamt splx(s);
144 1.3.2.2 yamt #endif
145 1.3.2.2 yamt }
146 1.3.2.2 yamt
147 1.3.2.2 yamt static void
148 1.3.2.2 yamt vcons_unlock(struct vcons_screen *scr)
149 1.3.2.2 yamt {
150 1.3.2.2 yamt #ifdef VCONS_PARANOIA
151 1.3.2.2 yamt int s;
152 1.3.2.2 yamt
153 1.3.2.2 yamt s = splhigh();
154 1.3.2.2 yamt #endif
155 1.3.2.2 yamt SCREEN_IDLE(scr);
156 1.3.2.2 yamt #ifdef VCONS_PARANOIA
157 1.3.2.2 yamt splx(s);
158 1.3.2.2 yamt #endif
159 1.3.2.2 yamt }
160 1.3.2.2 yamt
161 1.3.2.2 yamt static void
162 1.3.2.2 yamt vcons_dummy_init_screen(void *cookie, struct vcons_screen *scr, int exists,
163 1.3.2.2 yamt long *defattr)
164 1.3.2.2 yamt {
165 1.3.2.2 yamt
166 1.3.2.2 yamt /*
167 1.3.2.2 yamt * default init_screen() method.
168 1.3.2.2 yamt * Needs to be overwritten so we bitch and whine in case anyone ends
169 1.3.2.2 yamt * up in here.
170 1.3.2.2 yamt */
171 1.3.2.2 yamt printf("vcons_init_screen: dummy function called. Your driver is "
172 1.3.2.2 yamt "supposed to supply a replacement for proper operation\n");
173 1.3.2.2 yamt }
174 1.3.2.2 yamt
175 1.3.2.2 yamt int
176 1.3.2.2 yamt vcons_init_screen(struct vcons_data *vd, struct vcons_screen *scr,
177 1.3.2.2 yamt int existing, long *defattr)
178 1.3.2.2 yamt {
179 1.3.2.2 yamt struct rasops_info *ri = &scr->scr_ri;
180 1.3.2.2 yamt int cnt, i;
181 1.3.2.2 yamt
182 1.3.2.2 yamt scr->scr_cookie = vd->cookie;
183 1.3.2.3 yamt scr->scr_vd = scr->scr_origvd = vd;
184 1.3.2.2 yamt SCREEN_IDLE(scr);
185 1.3.2.2 yamt
186 1.3.2.2 yamt /*
187 1.3.2.2 yamt * call the driver-supplied init_screen function which is expected
188 1.3.2.2 yamt * to set up rasops_info, override cursor() and probably others
189 1.3.2.2 yamt */
190 1.3.2.2 yamt vd->init_screen(vd->cookie, scr, existing, defattr);
191 1.3.2.2 yamt
192 1.3.2.2 yamt /*
193 1.3.2.2 yamt * save the non virtual console aware rasops and replace them with
194 1.3.2.2 yamt * our wrappers
195 1.3.2.2 yamt */
196 1.3.2.2 yamt vd->eraserows = ri->ri_ops.eraserows;
197 1.3.2.2 yamt vd->copyrows = ri->ri_ops.copyrows;
198 1.3.2.2 yamt vd->erasecols = ri->ri_ops.erasecols;
199 1.3.2.2 yamt vd->copycols = ri->ri_ops.copycols;
200 1.3.2.2 yamt vd->putchar = ri->ri_ops.putchar;
201 1.3.2.2 yamt vd->cursor = ri->ri_ops.cursor;
202 1.3.2.2 yamt
203 1.3.2.2 yamt ri->ri_ops.eraserows = vcons_eraserows;
204 1.3.2.2 yamt ri->ri_ops.copyrows = vcons_copyrows;
205 1.3.2.2 yamt ri->ri_ops.erasecols = vcons_erasecols;
206 1.3.2.2 yamt ri->ri_ops.copycols = vcons_copycols;
207 1.3.2.2 yamt ri->ri_ops.putchar = vcons_putchar;
208 1.3.2.2 yamt ri->ri_ops.cursor = vcons_cursor;
209 1.3.2.2 yamt ri->ri_hw = scr;
210 1.3.2.2 yamt
211 1.3.2.2 yamt /*
212 1.3.2.2 yamt * we allocate both chars and attributes in one chunk, attributes first
213 1.3.2.2 yamt * because they have the (potentially) bigger alignment
214 1.3.2.2 yamt */
215 1.3.2.2 yamt cnt = ri->ri_rows * ri->ri_cols;
216 1.3.2.2 yamt scr->scr_attrs = (long *)malloc(cnt * (sizeof(long) +
217 1.3.2.2 yamt sizeof(uint16_t)), M_DEVBUF, M_WAITOK);
218 1.3.2.2 yamt if (scr->scr_attrs == NULL)
219 1.3.2.2 yamt return ENOMEM;
220 1.3.2.2 yamt
221 1.3.2.2 yamt scr->scr_chars = (uint16_t *)&scr->scr_attrs[cnt];
222 1.3.2.2 yamt
223 1.3.2.2 yamt ri->ri_ops.allocattr(ri, WS_DEFAULT_FG, WS_DEFAULT_BG, 0, defattr);
224 1.3.2.2 yamt scr->scr_defattr = *defattr;
225 1.3.2.2 yamt
226 1.3.2.2 yamt /*
227 1.3.2.2 yamt * fill the attribute buffer with *defattr, chars with 0x20
228 1.3.2.2 yamt * since we don't know if the driver tries to mimic firmware output or
229 1.3.2.2 yamt * reset everything we do nothing to VRAM here, any driver that feels
230 1.3.2.2 yamt * the need to clear screen or something will have to do it on its own
231 1.3.2.2 yamt * Additional screens will start out in the background anyway so
232 1.3.2.2 yamt * cleaning or not only really affects the initial console screen
233 1.3.2.2 yamt */
234 1.3.2.2 yamt for (i = 0; i < cnt; i++) {
235 1.3.2.2 yamt scr->scr_attrs[i] = *defattr;
236 1.3.2.2 yamt scr->scr_chars[i] = 0x20;
237 1.3.2.2 yamt }
238 1.3.2.2 yamt
239 1.3.2.2 yamt if(vd->active == NULL) {
240 1.3.2.2 yamt vd->active = scr;
241 1.3.2.2 yamt SCREEN_VISIBLE(scr);
242 1.3.2.2 yamt }
243 1.3.2.2 yamt
244 1.3.2.2 yamt if (existing) {
245 1.3.2.2 yamt SCREEN_VISIBLE(scr);
246 1.3.2.2 yamt vd->active = scr;
247 1.3.2.2 yamt } else {
248 1.3.2.2 yamt SCREEN_INVISIBLE(scr);
249 1.3.2.2 yamt }
250 1.3.2.2 yamt
251 1.3.2.2 yamt LIST_INSERT_HEAD(&vd->screens, scr, next);
252 1.3.2.2 yamt return 0;
253 1.3.2.2 yamt }
254 1.3.2.2 yamt
255 1.3.2.2 yamt static void
256 1.3.2.2 yamt vcons_do_switch(struct vcons_data *vd)
257 1.3.2.2 yamt {
258 1.3.2.2 yamt struct vcons_screen *scr, *oldscr;
259 1.3.2.2 yamt
260 1.3.2.2 yamt scr = vd->wanted;
261 1.3.2.2 yamt if (!scr) {
262 1.3.2.2 yamt printf("vcons_switch_screen: disappeared\n");
263 1.3.2.2 yamt vd->switch_cb(vd->switch_cb_arg, EIO, 0);
264 1.3.2.2 yamt return;
265 1.3.2.2 yamt }
266 1.3.2.2 yamt oldscr = vd->active; /* can be NULL! */
267 1.3.2.2 yamt
268 1.3.2.2 yamt /*
269 1.3.2.2 yamt * if there's an old, visible screen we mark it invisible and wait
270 1.3.2.2 yamt * until it's not busy so we can safely switch
271 1.3.2.2 yamt */
272 1.3.2.2 yamt if (oldscr != NULL) {
273 1.3.2.2 yamt SCREEN_INVISIBLE(oldscr);
274 1.3.2.2 yamt if (SCREEN_IS_BUSY(oldscr)) {
275 1.3.2.2 yamt callout_reset(&vd->switch_callout, 1,
276 1.3.2.2 yamt (void(*)(void *))vcons_do_switch, vd);
277 1.3.2.2 yamt #ifdef DIAGNOSTIC
278 1.3.2.2 yamt /* bitch if we wait too long */
279 1.3.2.2 yamt vd->switch_poll_count++;
280 1.3.2.2 yamt if (vd->switch_poll_count > 100) {
281 1.3.2.2 yamt panic("vcons: screen still busy");
282 1.3.2.2 yamt }
283 1.3.2.2 yamt #endif
284 1.3.2.2 yamt return;
285 1.3.2.2 yamt }
286 1.3.2.2 yamt /* invisible screen -> no visible cursor image */
287 1.3.2.2 yamt oldscr->scr_ri.ri_flg &= ~RI_CURSOR;
288 1.3.2.2 yamt #ifdef DIAGNOSTIC
289 1.3.2.2 yamt vd->switch_poll_count = 0;
290 1.3.2.2 yamt #endif
291 1.3.2.2 yamt }
292 1.3.2.2 yamt
293 1.3.2.2 yamt if (scr == oldscr)
294 1.3.2.2 yamt return;
295 1.3.2.2 yamt
296 1.3.2.2 yamt #ifdef DIAGNOSTIC
297 1.3.2.2 yamt if (SCREEN_IS_VISIBLE(scr))
298 1.3.2.2 yamt panic("vcons_switch_screen: already active");
299 1.3.2.2 yamt #endif
300 1.3.2.2 yamt
301 1.3.2.2 yamt #ifdef notyet
302 1.3.2.2 yamt if (vd->currenttype != type) {
303 1.3.2.2 yamt vcons_set_screentype(vd, type);
304 1.3.2.2 yamt vd->currenttype = type;
305 1.3.2.2 yamt }
306 1.3.2.2 yamt #endif
307 1.3.2.2 yamt
308 1.3.2.2 yamt SCREEN_VISIBLE(scr);
309 1.3.2.2 yamt vd->active = scr;
310 1.3.2.2 yamt vd->wanted = NULL;
311 1.3.2.2 yamt
312 1.3.2.2 yamt if (vd->show_screen_cb != NULL)
313 1.3.2.2 yamt vd->show_screen_cb(scr);
314 1.3.2.2 yamt
315 1.3.2.2 yamt if ((scr->scr_flags & VCONS_NO_REDRAW) == 0)
316 1.3.2.2 yamt vcons_redraw_screen(scr);
317 1.3.2.2 yamt
318 1.3.2.2 yamt if (vd->switch_cb)
319 1.3.2.2 yamt vd->switch_cb(vd->switch_cb_arg, 0, 0);
320 1.3.2.2 yamt }
321 1.3.2.2 yamt
322 1.3.2.2 yamt void
323 1.3.2.2 yamt vcons_redraw_screen(struct vcons_screen *scr)
324 1.3.2.2 yamt {
325 1.3.2.2 yamt uint16_t *charptr = scr->scr_chars;
326 1.3.2.2 yamt long *attrptr = scr->scr_attrs;
327 1.3.2.2 yamt struct rasops_info *ri = &scr->scr_ri;
328 1.3.2.2 yamt int i, j, offset;
329 1.3.2.2 yamt
330 1.3.2.2 yamt vcons_lock(scr);
331 1.3.2.3 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
332 1.3.2.2 yamt
333 1.3.2.2 yamt /*
334 1.3.2.2 yamt * only clear the screen when RI_FULLCLEAR is set since we're
335 1.3.2.2 yamt * going to overwrite every single character cell anyway
336 1.3.2.2 yamt */
337 1.3.2.2 yamt if (ri->ri_flg & RI_FULLCLEAR) {
338 1.3.2.2 yamt scr->scr_vd->eraserows(ri, 0, ri->ri_rows,
339 1.3.2.2 yamt scr->scr_defattr);
340 1.3.2.2 yamt }
341 1.3.2.2 yamt
342 1.3.2.2 yamt /* redraw the screen */
343 1.3.2.2 yamt offset = 0;
344 1.3.2.2 yamt for (i = 0; i < ri->ri_rows; i++) {
345 1.3.2.2 yamt for (j = 0; j < ri->ri_cols; j++) {
346 1.3.2.2 yamt /*
347 1.3.2.2 yamt * no need to use the wrapper function - we
348 1.3.2.2 yamt * don't change any characters or attributes
349 1.3.2.2 yamt * and we already made sure the screen we're
350 1.3.2.2 yamt * working on is visible
351 1.3.2.2 yamt */
352 1.3.2.2 yamt scr->scr_vd->putchar(ri, i, j,
353 1.3.2.2 yamt charptr[offset], attrptr[offset]);
354 1.3.2.2 yamt offset++;
355 1.3.2.2 yamt }
356 1.3.2.2 yamt }
357 1.3.2.2 yamt ri->ri_flg &= ~RI_CURSOR;
358 1.3.2.2 yamt scr->scr_vd->cursor(ri, 1, ri->ri_crow, ri->ri_ccol);
359 1.3.2.2 yamt }
360 1.3.2.2 yamt vcons_unlock(scr);
361 1.3.2.2 yamt }
362 1.3.2.2 yamt
363 1.3.2.2 yamt static int
364 1.3.2.2 yamt vcons_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
365 1.3.2.2 yamt int *curxp, int *curyp, long *defattrp)
366 1.3.2.2 yamt {
367 1.3.2.2 yamt struct vcons_data *vd = v;
368 1.3.2.2 yamt struct vcons_screen *scr;
369 1.3.2.2 yamt int ret;
370 1.3.2.2 yamt
371 1.3.2.2 yamt scr = malloc(sizeof(struct vcons_screen), M_DEVBUF, M_WAITOK | M_ZERO);
372 1.3.2.2 yamt if (scr == NULL)
373 1.3.2.2 yamt return ENOMEM;
374 1.3.2.2 yamt
375 1.3.2.2 yamt scr->scr_flags = 0;
376 1.3.2.2 yamt scr->scr_status = 0;
377 1.3.2.2 yamt scr->scr_busy = 0;
378 1.3.2.2 yamt scr->scr_type = type;
379 1.3.2.2 yamt
380 1.3.2.2 yamt ret = vcons_init_screen(vd, scr, 0, defattrp);
381 1.3.2.2 yamt if (ret != 0) {
382 1.3.2.2 yamt free(scr, M_DEVBUF);
383 1.3.2.2 yamt return ret;
384 1.3.2.2 yamt }
385 1.3.2.2 yamt
386 1.3.2.2 yamt if (vd->active == NULL) {
387 1.3.2.2 yamt SCREEN_VISIBLE(scr);
388 1.3.2.2 yamt vd->active = scr;
389 1.3.2.2 yamt vd->currenttype = type;
390 1.3.2.2 yamt }
391 1.3.2.2 yamt
392 1.3.2.2 yamt *cookiep = scr;
393 1.3.2.2 yamt *curxp = scr->scr_ri.ri_ccol;
394 1.3.2.2 yamt *curyp = scr->scr_ri.ri_crow;
395 1.3.2.2 yamt return 0;
396 1.3.2.2 yamt }
397 1.3.2.2 yamt
398 1.3.2.2 yamt static void
399 1.3.2.2 yamt vcons_free_screen(void *v, void *cookie)
400 1.3.2.2 yamt {
401 1.3.2.2 yamt struct vcons_data *vd = v;
402 1.3.2.2 yamt struct vcons_screen *scr = cookie;
403 1.3.2.2 yamt
404 1.3.2.2 yamt vcons_lock(scr);
405 1.3.2.2 yamt /* there should be no rasops activity here */
406 1.3.2.2 yamt
407 1.3.2.2 yamt LIST_REMOVE(scr, next);
408 1.3.2.2 yamt
409 1.3.2.2 yamt if ((scr->scr_flags & VCONS_SCREEN_IS_STATIC) == 0) {
410 1.3.2.2 yamt free(scr->scr_attrs, M_DEVBUF);
411 1.3.2.2 yamt free(scr, M_DEVBUF);
412 1.3.2.2 yamt } else {
413 1.3.2.2 yamt /*
414 1.3.2.2 yamt * maybe we should just restore the old rasops_info methods
415 1.3.2.2 yamt * and free the character/attribute buffer here?
416 1.3.2.2 yamt */
417 1.3.2.2 yamt #ifdef VCONS_DEBUG
418 1.3.2.2 yamt panic("vcons_free_screen: console");
419 1.3.2.2 yamt #else
420 1.3.2.2 yamt printf("vcons_free_screen: console\n");
421 1.3.2.2 yamt #endif
422 1.3.2.2 yamt }
423 1.3.2.2 yamt
424 1.3.2.2 yamt if (vd->active == scr)
425 1.3.2.2 yamt vd->active = NULL;
426 1.3.2.2 yamt }
427 1.3.2.2 yamt
428 1.3.2.2 yamt static int
429 1.3.2.2 yamt vcons_show_screen(void *v, void *cookie, int waitok,
430 1.3.2.2 yamt void (*cb)(void *, int, int), void *cb_arg)
431 1.3.2.2 yamt {
432 1.3.2.2 yamt struct vcons_data *vd = v;
433 1.3.2.2 yamt struct vcons_screen *scr;
434 1.3.2.2 yamt
435 1.3.2.2 yamt scr = cookie;
436 1.3.2.2 yamt if (scr == vd->active)
437 1.3.2.2 yamt return 0;
438 1.3.2.2 yamt
439 1.3.2.2 yamt vd->wanted = scr;
440 1.3.2.2 yamt vd->switch_cb = cb;
441 1.3.2.2 yamt vd->switch_cb_arg = cb_arg;
442 1.3.2.2 yamt if (cb) {
443 1.3.2.2 yamt callout_reset(&vd->switch_callout, 0,
444 1.3.2.2 yamt (void(*)(void *))vcons_do_switch, vd);
445 1.3.2.2 yamt return EAGAIN;
446 1.3.2.2 yamt }
447 1.3.2.2 yamt
448 1.3.2.2 yamt vcons_do_switch(vd);
449 1.3.2.2 yamt return 0;
450 1.3.2.2 yamt }
451 1.3.2.2 yamt
452 1.3.2.2 yamt /* wrappers for rasops_info methods */
453 1.3.2.2 yamt
454 1.3.2.2 yamt static void
455 1.3.2.2 yamt vcons_copycols_buffer(void *cookie, int row, int srccol, int dstcol, int ncols)
456 1.3.2.2 yamt {
457 1.3.2.2 yamt struct rasops_info *ri = cookie;
458 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
459 1.3.2.2 yamt int from = srccol + row * ri->ri_cols;
460 1.3.2.2 yamt int to = dstcol + row * ri->ri_cols;
461 1.3.2.2 yamt
462 1.3.2.2 yamt memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
463 1.3.2.2 yamt ncols * sizeof(long));
464 1.3.2.2 yamt memmove(&scr->scr_chars[to], &scr->scr_chars[from],
465 1.3.2.2 yamt ncols * sizeof(uint16_t));
466 1.3.2.2 yamt }
467 1.3.2.2 yamt
468 1.3.2.2 yamt static void
469 1.3.2.2 yamt vcons_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
470 1.3.2.2 yamt {
471 1.3.2.2 yamt struct rasops_info *ri = cookie;
472 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
473 1.3.2.2 yamt
474 1.3.2.2 yamt vcons_copycols_buffer(cookie, row, srccol, dstcol, ncols);
475 1.3.2.2 yamt
476 1.3.2.2 yamt vcons_lock(scr);
477 1.3.2.3 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
478 1.3.2.2 yamt scr->scr_vd->copycols(cookie, row, srccol, dstcol, ncols);
479 1.3.2.2 yamt }
480 1.3.2.2 yamt vcons_unlock(scr);
481 1.3.2.2 yamt }
482 1.3.2.2 yamt
483 1.3.2.2 yamt static void
484 1.3.2.2 yamt vcons_erasecols_buffer(void *cookie, int row, int startcol, int ncols, long fillattr)
485 1.3.2.2 yamt {
486 1.3.2.2 yamt struct rasops_info *ri = cookie;
487 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
488 1.3.2.2 yamt int start = startcol + row * ri->ri_cols;
489 1.3.2.2 yamt int end = start + ncols, i;
490 1.3.2.2 yamt
491 1.3.2.2 yamt for (i = start; i < end; i++) {
492 1.3.2.2 yamt scr->scr_attrs[i] = fillattr;
493 1.3.2.2 yamt scr->scr_chars[i] = 0x20;
494 1.3.2.2 yamt }
495 1.3.2.2 yamt }
496 1.3.2.2 yamt
497 1.3.2.2 yamt static void
498 1.3.2.2 yamt vcons_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
499 1.3.2.2 yamt {
500 1.3.2.2 yamt struct rasops_info *ri = cookie;
501 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
502 1.3.2.2 yamt
503 1.3.2.2 yamt vcons_erasecols_buffer(cookie, row, startcol, ncols, fillattr);
504 1.3.2.2 yamt
505 1.3.2.2 yamt vcons_lock(scr);
506 1.3.2.3 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
507 1.3.2.2 yamt scr->scr_vd->erasecols(cookie, row, startcol, ncols,
508 1.3.2.2 yamt fillattr);
509 1.3.2.2 yamt }
510 1.3.2.2 yamt vcons_unlock(scr);
511 1.3.2.2 yamt }
512 1.3.2.2 yamt
513 1.3.2.2 yamt static void
514 1.3.2.2 yamt vcons_copyrows_buffer(void *cookie, int srcrow, int dstrow, int nrows)
515 1.3.2.2 yamt {
516 1.3.2.2 yamt struct rasops_info *ri = cookie;
517 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
518 1.3.2.2 yamt int from, to, len;
519 1.3.2.2 yamt
520 1.3.2.2 yamt from = ri->ri_cols * srcrow;
521 1.3.2.2 yamt to = ri->ri_cols * dstrow;
522 1.3.2.2 yamt len = ri->ri_cols * nrows;
523 1.3.2.2 yamt
524 1.3.2.2 yamt memmove(&scr->scr_attrs[to], &scr->scr_attrs[from],
525 1.3.2.2 yamt len * sizeof(long));
526 1.3.2.2 yamt memmove(&scr->scr_chars[to], &scr->scr_chars[from],
527 1.3.2.2 yamt len * sizeof(uint16_t));
528 1.3.2.2 yamt }
529 1.3.2.2 yamt
530 1.3.2.2 yamt static void
531 1.3.2.2 yamt vcons_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
532 1.3.2.2 yamt {
533 1.3.2.2 yamt struct rasops_info *ri = cookie;
534 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
535 1.3.2.2 yamt
536 1.3.2.2 yamt vcons_copyrows_buffer(cookie, srcrow, dstrow, nrows);
537 1.3.2.2 yamt
538 1.3.2.2 yamt vcons_lock(scr);
539 1.3.2.3 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
540 1.3.2.2 yamt scr->scr_vd->copyrows(cookie, srcrow, dstrow, nrows);
541 1.3.2.2 yamt }
542 1.3.2.2 yamt vcons_unlock(scr);
543 1.3.2.2 yamt }
544 1.3.2.2 yamt
545 1.3.2.2 yamt static void
546 1.3.2.2 yamt vcons_eraserows_buffer(void *cookie, int row, int nrows, long fillattr)
547 1.3.2.2 yamt {
548 1.3.2.2 yamt struct rasops_info *ri = cookie;
549 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
550 1.3.2.2 yamt int start, end, i;
551 1.3.2.2 yamt
552 1.3.2.2 yamt start = ri->ri_cols * row;
553 1.3.2.2 yamt end = ri->ri_cols * (row + nrows);
554 1.3.2.2 yamt
555 1.3.2.2 yamt for (i = start; i < end; i++) {
556 1.3.2.2 yamt scr->scr_attrs[i] = fillattr;
557 1.3.2.2 yamt scr->scr_chars[i] = 0x20;
558 1.3.2.2 yamt }
559 1.3.2.2 yamt }
560 1.3.2.2 yamt
561 1.3.2.2 yamt static void
562 1.3.2.2 yamt vcons_eraserows(void *cookie, int row, int nrows, long fillattr)
563 1.3.2.2 yamt {
564 1.3.2.2 yamt struct rasops_info *ri = cookie;
565 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
566 1.3.2.2 yamt
567 1.3.2.2 yamt vcons_eraserows_buffer(cookie, row, nrows, fillattr);
568 1.3.2.2 yamt
569 1.3.2.2 yamt vcons_lock(scr);
570 1.3.2.3 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
571 1.3.2.2 yamt scr->scr_vd->eraserows(cookie, row, nrows, fillattr);
572 1.3.2.2 yamt }
573 1.3.2.2 yamt vcons_unlock(scr);
574 1.3.2.2 yamt }
575 1.3.2.2 yamt
576 1.3.2.2 yamt static void
577 1.3.2.2 yamt vcons_putchar_buffer(void *cookie, int row, int col, u_int c, long attr)
578 1.3.2.2 yamt {
579 1.3.2.2 yamt struct rasops_info *ri = cookie;
580 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
581 1.3.2.2 yamt int pos;
582 1.3.2.2 yamt
583 1.3.2.2 yamt if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
584 1.3.2.2 yamt (col < ri->ri_cols)) {
585 1.3.2.2 yamt pos = col + row * ri->ri_cols;
586 1.3.2.2 yamt scr->scr_attrs[pos] = attr;
587 1.3.2.2 yamt scr->scr_chars[pos] = c;
588 1.3.2.2 yamt }
589 1.3.2.2 yamt }
590 1.3.2.2 yamt
591 1.3.2.2 yamt static void
592 1.3.2.2 yamt vcons_putchar(void *cookie, int row, int col, u_int c, long attr)
593 1.3.2.2 yamt {
594 1.3.2.2 yamt struct rasops_info *ri = cookie;
595 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
596 1.3.2.2 yamt
597 1.3.2.2 yamt vcons_putchar_buffer(cookie, row, col, c, attr);
598 1.3.2.2 yamt
599 1.3.2.2 yamt vcons_lock(scr);
600 1.3.2.3 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
601 1.3.2.2 yamt scr->scr_vd->putchar(cookie, row, col, c, attr);
602 1.3.2.2 yamt }
603 1.3.2.2 yamt vcons_unlock(scr);
604 1.3.2.2 yamt }
605 1.3.2.2 yamt
606 1.3.2.2 yamt static void
607 1.3.2.2 yamt vcons_cursor(void *cookie, int on, int row, int col)
608 1.3.2.2 yamt {
609 1.3.2.2 yamt struct rasops_info *ri = cookie;
610 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
611 1.3.2.2 yamt
612 1.3.2.2 yamt vcons_lock(scr);
613 1.3.2.3 yamt if (SCREEN_IS_VISIBLE(scr) && SCREEN_CAN_DRAW(scr)) {
614 1.3.2.2 yamt scr->scr_vd->cursor(cookie, on, row, col);
615 1.3.2.2 yamt } else {
616 1.3.2.2 yamt scr->scr_ri.ri_crow = row;
617 1.3.2.2 yamt scr->scr_ri.ri_ccol = col;
618 1.3.2.2 yamt }
619 1.3.2.2 yamt vcons_unlock(scr);
620 1.3.2.2 yamt }
621 1.3.2.2 yamt
622 1.3.2.2 yamt /* methods to read/write characters via ioctl() */
623 1.3.2.2 yamt
624 1.3.2.2 yamt static int
625 1.3.2.2 yamt vcons_putwschar(void *cookie, struct wsdisplay_char *wsc)
626 1.3.2.2 yamt {
627 1.3.2.2 yamt struct rasops_info *ri = cookie;
628 1.3.2.2 yamt long attr;
629 1.3.2.2 yamt
630 1.3.2.2 yamt ri->ri_ops.allocattr(ri, wsc->foreground, wsc->background,
631 1.3.2.2 yamt wsc->flags, &attr);
632 1.3.2.2 yamt vcons_putchar(ri, wsc->row, wsc->col, wsc->letter, attr);
633 1.3.2.2 yamt return 0;
634 1.3.2.2 yamt }
635 1.3.2.2 yamt
636 1.3.2.2 yamt static int
637 1.3.2.2 yamt vcons_getwschar(void *cookie, struct wsdisplay_char *wsc)
638 1.3.2.2 yamt {
639 1.3.2.2 yamt struct rasops_info *ri = cookie;
640 1.3.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
641 1.3.2.2 yamt long attr;
642 1.3.2.2 yamt int offset = ri->ri_cols * wsc->row + wsc->col;
643 1.3.2.2 yamt
644 1.3.2.2 yamt wsc->letter = scr->scr_chars[offset];
645 1.3.2.2 yamt attr = scr->scr_attrs[offset];
646 1.3.2.2 yamt
647 1.3.2.2 yamt /*
648 1.3.2.2 yamt * this is ugly. We need to break up an attribute into colours and
649 1.3.2.2 yamt * flags but there's no rasops method to do that so we must rely on
650 1.3.2.2 yamt * the 'canonical' encoding.
651 1.3.2.2 yamt */
652 1.3.2.2 yamt wsc->foreground = (attr & 0xff000000) >> 24;
653 1.3.2.2 yamt wsc->background = (attr & 0x00ff0000) >> 16;
654 1.3.2.2 yamt wsc->flags = (attr & 0x0000ff00) >> 8;
655 1.3.2.2 yamt return 0;
656 1.3.2.2 yamt }
657