syscons - sc_set_pixel_mode() returned without releasing tty_token
[dragonfly.git] / sys / dev / misc / syscons / scvidctl.c
CommitLineData
984263bc 1/*-
22ff886e
AH
2 * (MPSAFE)
3 *
984263bc
MD
4 * Copyright (c) 1998 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * All rights reserved.
6 *
2a85d763
MD
7 * This code is derived from software contributed to The DragonFly Project
8 * by Sascha Wildner <saw@online.de>
9 *
984263bc
MD
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer as
15 * the first lines of this file unmodified.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * $FreeBSD: src/sys/dev/syscons/scvidctl.c,v 1.19.2.2 2000/05/05 09:16:08 nyan Exp $
bb2c2021 32 * $DragonFly: src/sys/dev/misc/syscons/scvidctl.c,v 1.16 2007/08/19 11:39:11 swildner Exp $
984263bc
MD
33 */
34
35#include "opt_syscons.h"
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/conf.h>
40#include <sys/signalvar.h>
41#include <sys/tty.h>
42#include <sys/kernel.h>
6bc31f17 43#include <sys/thread2.h>
984263bc
MD
44
45#include <machine/console.h>
46
1f2de5d4
MD
47#include <dev/video/fb/fbreg.h>
48#include "syscons.h"
984263bc 49
dc62b251
MD
50SET_DECLARE(scrndr_set, const sc_renderer_t);
51
984263bc
MD
52int
53sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize,
54 int fontsize)
55{
56 video_info_t info;
57 u_char *font;
58 int prev_ysize;
e1026969 59 int new_ysize;
984263bc 60 int error;
984263bc 61
22ff886e
AH
62 lwkt_gettoken(&tty_token);
63 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info)) {
64 lwkt_reltoken(&tty_token);
984263bc 65 return ENODEV;
22ff886e
AH
66 }
67 lwkt_reltoken(&tty_token);
984263bc
MD
68
69 /* adjust argument values */
70 if (fontsize <= 0)
71 fontsize = info.vi_cheight;
72 if (fontsize < 14) {
73 fontsize = 8;
74#ifndef SC_NO_FONT_LOADING
75 if (!(scp->sc->fonts_loaded & FONT_8))
76 return EINVAL;
77 font = scp->sc->font_8;
78#else
79 font = NULL;
80#endif
81 } else if (fontsize >= 16) {
82 fontsize = 16;
83#ifndef SC_NO_FONT_LOADING
84 if (!(scp->sc->fonts_loaded & FONT_16))
85 return EINVAL;
86 font = scp->sc->font_16;
87#else
88 font = NULL;
89#endif
90 } else {
91 fontsize = 14;
92#ifndef SC_NO_FONT_LOADING
93 if (!(scp->sc->fonts_loaded & FONT_14))
94 return EINVAL;
95 font = scp->sc->font_14;
96#else
97 font = NULL;
98#endif
99 }
100 if ((xsize <= 0) || (xsize > info.vi_width))
101 xsize = info.vi_width;
102 if ((ysize <= 0) || (ysize > info.vi_height))
103 ysize = info.vi_height;
104
105 /* stop screen saver, etc */
6bc31f17 106 crit_enter();
984263bc 107 if ((error = sc_clean_up(scp))) {
6bc31f17 108 crit_exit();
984263bc
MD
109 return error;
110 }
111
21343892 112 if (sc_render_match(scp, scp->sc->adp->va_name, V_INFO_MM_TEXT) == NULL) {
6bc31f17 113 crit_exit();
984263bc
MD
114 return ENODEV;
115 }
116
117 /* set up scp */
e1026969 118 new_ysize = 0;
984263bc 119#ifndef SC_NO_HISTORY
e1026969 120 if (scp->history != NULL) {
984263bc 121 sc_hist_save(scp);
e1026969
MD
122 new_ysize = sc_vtb_rows(scp->history);
123 }
984263bc
MD
124#endif
125 prev_ysize = scp->ysize;
126 /*
127 * This is a kludge to fend off scrn_update() while we
128 * muck around with scp. XXX
129 */
130 scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
131 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE | MOUSE_VISIBLE);
132 scp->mode = mode;
21343892 133 scp->model = V_INFO_MM_TEXT;
984263bc
MD
134 scp->xsize = xsize;
135 scp->ysize = ysize;
136 scp->xoff = 0;
137 scp->yoff = 0;
138 scp->xpixel = scp->xsize*8;
139 scp->ypixel = scp->ysize*fontsize;
140 scp->font = font;
141 scp->font_size = fontsize;
142
143 /* allocate buffers */
144 sc_alloc_scr_buffer(scp, TRUE, TRUE);
145 sc_init_emulator(scp, NULL);
146#ifndef SC_NO_CUTPASTE
147 sc_alloc_cut_buffer(scp, FALSE);
148#endif
149#ifndef SC_NO_HISTORY
e1026969 150 sc_alloc_history_buffer(scp, new_ysize, prev_ysize, FALSE);
984263bc 151#endif
6bc31f17 152 crit_exit();
984263bc
MD
153
154 if (scp == scp->sc->cur_scp)
155 set_mode(scp);
156 scp->status &= ~UNKNOWN_MODE;
157
158 if (tp == NULL)
159 return 0;
160 DPRINTF(5, ("ws_*size (%d,%d), size (%d,%d)\n",
161 tp->t_winsize.ws_col, tp->t_winsize.ws_row, scp->xsize, scp->ysize));
162 if (tp->t_winsize.ws_col != scp->xsize
163 || tp->t_winsize.ws_row != scp->ysize) {
164 tp->t_winsize.ws_col = scp->xsize;
165 tp->t_winsize.ws_row = scp->ysize;
166 pgsignal(tp->t_pgrp, SIGWINCH, 1);
167 }
168
169 return 0;
170}
171
172int
173sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode)
174{
175#ifdef SC_NO_MODE_CHANGE
176 return ENODEV;
177#else
178 video_info_t info;
179 int error;
984263bc 180
22ff886e
AH
181 lwkt_gettoken(&tty_token);
182 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info)) {
183 lwkt_reltoken(&tty_token);
984263bc 184 return ENODEV;
22ff886e
AH
185 }
186 lwkt_reltoken(&tty_token);
984263bc
MD
187
188 /* stop screen saver, etc */
6bc31f17 189 crit_enter();
984263bc 190 if ((error = sc_clean_up(scp))) {
6bc31f17 191 crit_exit();
984263bc
MD
192 return error;
193 }
194
21343892 195 if (sc_render_match(scp, scp->sc->adp->va_name, V_INFO_MM_OTHER) == NULL) {
6bc31f17 196 crit_exit();
984263bc
MD
197 return ENODEV;
198 }
199
200 /* set up scp */
201 scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE | MOUSE_HIDDEN);
202 scp->status &= ~(PIXEL_MODE | MOUSE_VISIBLE);
203 scp->mode = mode;
21343892 204 scp->model = V_INFO_MM_OTHER;
984263bc
MD
205 /*
206 * Don't change xsize and ysize; preserve the previous vty
207 * and history buffers.
208 */
209 scp->xoff = 0;
210 scp->yoff = 0;
211 scp->xpixel = info.vi_width;
212 scp->ypixel = info.vi_height;
213 scp->font = NULL;
214 scp->font_size = 0;
215#ifndef SC_NO_SYSMOUSE
216 /* move the mouse cursor at the center of the screen */
217 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
218#endif
219 sc_init_emulator(scp, NULL);
6bc31f17 220 crit_exit();
984263bc
MD
221
222 if (scp == scp->sc->cur_scp)
223 set_mode(scp);
224 /* clear_graphics();*/
a5eb78ad 225 refresh_ega_palette(scp);
984263bc
MD
226 scp->status &= ~UNKNOWN_MODE;
227
228 if (tp == NULL)
229 return 0;
230 if (tp->t_winsize.ws_xpixel != scp->xpixel
231 || tp->t_winsize.ws_ypixel != scp->ypixel) {
232 tp->t_winsize.ws_xpixel = scp->xpixel;
233 tp->t_winsize.ws_ypixel = scp->ypixel;
234 pgsignal(tp->t_pgrp, SIGWINCH, 1);
235 }
236
237 return 0;
238#endif /* SC_NO_MODE_CHANGE */
239}
240
241int
242sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
243 int fontsize)
244{
245#ifndef SC_PIXEL_MODE
246 return ENODEV;
247#else
248 video_info_t info;
249 u_char *font;
250 int prev_ysize;
e1026969 251 int new_ysize;
984263bc 252 int error;
984263bc 253
22ff886e
AH
254 lwkt_gettoken(&tty_token);
255 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info)) {
256 lwkt_reltoken(&tty_token);
984263bc 257 return ENODEV; /* this shouldn't happen */
22ff886e 258 }
70b455d0 259 lwkt_reltoken(&tty_token);
984263bc
MD
260
261 /* adjust argument values */
262 if (fontsize <= 0)
263 fontsize = info.vi_cheight;
264 if (fontsize < 14) {
265 fontsize = 8;
266#ifndef SC_NO_FONT_LOADING
267 if (!(scp->sc->fonts_loaded & FONT_8))
268 return EINVAL;
269 font = scp->sc->font_8;
270#else
271 font = NULL;
272#endif
273 } else if (fontsize >= 16) {
274 fontsize = 16;
275#ifndef SC_NO_FONT_LOADING
276 if (!(scp->sc->fonts_loaded & FONT_16))
277 return EINVAL;
278 font = scp->sc->font_16;
279#else
280 font = NULL;
281#endif
282 } else {
283 fontsize = 14;
284#ifndef SC_NO_FONT_LOADING
285 if (!(scp->sc->fonts_loaded & FONT_14))
286 return EINVAL;
287 font = scp->sc->font_14;
288#else
289 font = NULL;
290#endif
291 }
292 if (xsize <= 0)
293 xsize = info.vi_width/8;
294 if (ysize <= 0)
295 ysize = info.vi_height/fontsize;
296
297 if ((info.vi_width < xsize*8) || (info.vi_height < ysize*fontsize))
298 return EINVAL;
299
984263bc 300 /*
2a85d763
MD
301 * We currently support the following graphic modes:
302 *
303 * - 4 bpp planar modes whose memory size does not exceed 64K
771006e1 304 * - 8 bbp packed pixel modes
0c4611ed 305 * - 15, 16, 24 and 32 bpp direct modes with linear frame buffer
984263bc 306 */
2a85d763
MD
307
308 if (info.vi_mem_model == V_INFO_MM_PLANAR) {
309 if (info.vi_planes != 4)
310 return ENODEV;
311
312 /*
313 * A memory size >64K requires bank switching to access the entire
314 * screen. XXX
315 */
316
317 if (info.vi_width * info.vi_height / 8 > info.vi_window_size)
318 return ENODEV;
771006e1
SW
319 } else if (info.vi_mem_model == V_INFO_MM_PACKED) {
320 if (info.vi_depth != 8)
321 return ENODEV;
2a85d763 322 } else if (info.vi_mem_model == V_INFO_MM_DIRECT) {
0c4611ed
SW
323 if (!(info.vi_flags & V_INFO_LINEAR) &&
324 (info.vi_depth != 15) && (info.vi_depth != 16) &&
2a85d763
MD
325 (info.vi_depth != 24) && (info.vi_depth != 32))
326 return ENODEV;
327 } else
984263bc
MD
328 return ENODEV;
329
330 /* stop screen saver, etc */
6bc31f17 331 crit_enter();
984263bc 332 if ((error = sc_clean_up(scp))) {
6bc31f17 333 crit_exit();
984263bc
MD
334 return error;
335 }
336
21343892 337 if (sc_render_match(scp, scp->sc->adp->va_name, info.vi_mem_model) == NULL) {
6bc31f17 338 crit_exit();
984263bc
MD
339 return ENODEV;
340 }
341
342#if 0
343 if (scp->tsw)
344 (*scp->tsw->te_term)(scp, scp->ts);
345 scp->tsw = NULL;
346 scp->ts = NULL;
347#endif
348
349 /* set up scp */
e1026969 350 new_ysize = 0;
984263bc 351#ifndef SC_NO_HISTORY
e1026969 352 if (scp->history != NULL) {
984263bc 353 sc_hist_save(scp);
e1026969
MD
354 new_ysize = sc_vtb_rows(scp->history);
355 }
984263bc
MD
356#endif
357 prev_ysize = scp->ysize;
358 scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
359 scp->status &= ~(GRAPHICS_MODE | MOUSE_VISIBLE);
21343892 360 scp->model = info.vi_mem_model;
984263bc
MD
361 scp->xsize = xsize;
362 scp->ysize = ysize;
363 scp->xoff = (scp->xpixel/8 - xsize)/2;
364 scp->yoff = (scp->ypixel/fontsize - ysize)/2;
365 scp->font = font;
366 scp->font_size = fontsize;
367
368 /* allocate buffers */
369 sc_alloc_scr_buffer(scp, TRUE, TRUE);
370 sc_init_emulator(scp, NULL);
371#ifndef SC_NO_CUTPASTE
372 sc_alloc_cut_buffer(scp, FALSE);
373#endif
374#ifndef SC_NO_HISTORY
e1026969 375 sc_alloc_history_buffer(scp, new_ysize, prev_ysize, FALSE);
984263bc 376#endif
6bc31f17 377 crit_exit();
984263bc
MD
378
379 if (scp == scp->sc->cur_scp) {
380 sc_set_border(scp, scp->border);
381 sc_set_cursor_image(scp);
382 }
383
384 scp->status &= ~UNKNOWN_MODE;
385
386 if (tp == NULL)
387 return 0;
388 if (tp->t_winsize.ws_col != scp->xsize
389 || tp->t_winsize.ws_row != scp->ysize) {
390 tp->t_winsize.ws_col = scp->xsize;
391 tp->t_winsize.ws_row = scp->ysize;
392 pgsignal(tp->t_pgrp, SIGWINCH, 1);
393 }
394
395 return 0;
396#endif /* SC_PIXEL_MODE */
397}
398
399#define fb_ioctl(a, c, d) \
400 (((a) == NULL) ? ENODEV : \
401 (*vidsw[(a)->va_index]->ioctl)((a), (c), (caddr_t)(d)))
402
403int
fef8985e 404sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag)
984263bc
MD
405{
406 scr_stat *scp;
407 video_adapter_t *adp;
408 video_info_t info;
22ff886e 409 int error, ret;
984263bc 410
cd29885a
MD
411 KKASSERT(tp->t_dev);
412
984263bc
MD
413 scp = SC_STAT(tp->t_dev);
414 if (scp == NULL) /* tp == SC_MOUSE */
cd29885a 415 return ENOIOCTL;
984263bc
MD
416 adp = scp->sc->adp;
417 if (adp == NULL) /* shouldn't happen??? */
cd29885a 418 return ENODEV;
984263bc 419
22ff886e 420 lwkt_gettoken(&tty_token);
984263bc
MD
421 switch (cmd) {
422
423 case CONS_CURRENTADP: /* get current adapter index */
424 case FBIO_ADAPTER:
22ff886e
AH
425 ret = fb_ioctl(adp, FBIO_ADAPTER, data);
426 lwkt_reltoken(&tty_token);
427 return ret;
984263bc
MD
428
429 case CONS_CURRENT: /* get current adapter type */
430 case FBIO_ADPTYPE:
22ff886e
AH
431 ret = fb_ioctl(adp, FBIO_ADPTYPE, data);
432 lwkt_reltoken(&tty_token);
433 return ret;
984263bc 434
984263bc
MD
435 case CONS_ADPINFO: /* adapter information */
436 case FBIO_ADPINFO:
437 if (((video_adapter_info_t *)data)->va_index >= 0) {
438 adp = vid_get_adapter(((video_adapter_info_t *)data)->va_index);
22ff886e
AH
439 if (adp == NULL) {
440 lwkt_reltoken(&tty_token);
984263bc 441 return ENODEV;
22ff886e 442 }
984263bc 443 }
22ff886e
AH
444 ret = fb_ioctl(adp, FBIO_ADPINFO, data);
445 lwkt_reltoken(&tty_token);
446 return ret;
984263bc
MD
447
448 case CONS_GET: /* get current video mode */
449 case FBIO_GETMODE:
450 *(int *)data = scp->mode;
22ff886e 451 lwkt_reltoken(&tty_token);
984263bc
MD
452 return 0;
453
454#ifndef SC_NO_MODE_CHANGE
bb2c2021 455 case CONS_SET:
984263bc 456 case FBIO_SETMODE: /* set video mode */
22ff886e
AH
457 if (!(adp->va_flags & V_ADP_MODECHANGE)) {
458 lwkt_reltoken(&tty_token);
984263bc 459 return ENODEV;
22ff886e 460 }
984263bc
MD
461 info.vi_mode = *(int *)data;
462 error = fb_ioctl(adp, FBIO_MODEINFO, &info);
22ff886e
AH
463 if (error) {
464 lwkt_reltoken(&tty_token);
984263bc 465 return error;
22ff886e
AH
466 }
467 if (info.vi_flags & V_INFO_GRAPHICS) {
468 lwkt_reltoken(&tty_token);
984263bc 469 return sc_set_graphics_mode(scp, tp, *(int *)data);
22ff886e
AH
470 } else {
471 lwkt_reltoken(&tty_token);
984263bc 472 return sc_set_text_mode(scp, tp, *(int *)data, 0, 0, 0);
22ff886e 473 }
984263bc
MD
474#endif /* SC_NO_MODE_CHANGE */
475
984263bc
MD
476 case CONS_MODEINFO: /* get mode information */
477 case FBIO_MODEINFO:
22ff886e
AH
478 ret = fb_ioctl(adp, FBIO_MODEINFO, data);
479 lwkt_reltoken(&tty_token);
480 return ret;
984263bc 481
984263bc
MD
482 case CONS_FINDMODE: /* find a matching video mode */
483 case FBIO_FINDMODE:
22ff886e
AH
484 ret = fb_ioctl(adp, FBIO_FINDMODE, data);
485 lwkt_reltoken(&tty_token);
486 return ret;
984263bc
MD
487
488 case CONS_SETWINORG: /* set frame buffer window origin */
489 case FBIO_SETWINORG:
22ff886e
AH
490 if (scp != scp->sc->cur_scp) {
491 lwkt_reltoken(&tty_token);
984263bc 492 return ENODEV; /* XXX */
22ff886e
AH
493 }
494 ret = fb_ioctl(adp, FBIO_SETWINORG, data);
495 lwkt_reltoken(&tty_token);
496 return ret;
984263bc
MD
497
498 case FBIO_GETWINORG: /* get frame buffer window origin */
22ff886e
AH
499 if (scp != scp->sc->cur_scp) {
500 lwkt_reltoken(&tty_token);
984263bc 501 return ENODEV; /* XXX */
22ff886e
AH
502 }
503 ret = fb_ioctl(adp, FBIO_GETWINORG, data);
504 lwkt_reltoken(&tty_token);
505 return ret;
984263bc
MD
506
507 case FBIO_GETDISPSTART:
508 case FBIO_SETDISPSTART:
509 case FBIO_GETLINEWIDTH:
510 case FBIO_SETLINEWIDTH:
22ff886e
AH
511 if (scp != scp->sc->cur_scp) {
512 lwkt_reltoken(&tty_token);
984263bc 513 return ENODEV; /* XXX */
22ff886e
AH
514 }
515 ret = fb_ioctl(adp, cmd, data);
516 lwkt_reltoken(&tty_token);
517 return ret;
984263bc
MD
518
519 case FBIO_GETPALETTE:
520 case FBIO_SETPALETTE:
521 case FBIOPUTCMAP:
522 case FBIOGETCMAP:
523 case FBIOGTYPE:
524 case FBIOGATTR:
525 case FBIOSVIDEO:
526 case FBIOGVIDEO:
527 case FBIOSCURSOR:
528 case FBIOGCURSOR:
529 case FBIOSCURPOS:
530 case FBIOGCURPOS:
531 case FBIOGCURMAX:
22ff886e
AH
532 if (scp != scp->sc->cur_scp) {
533 lwkt_reltoken(&tty_token);
984263bc 534 return ENODEV; /* XXX */
22ff886e
AH
535 }
536 ret = fb_ioctl(adp, cmd, data);
537 lwkt_reltoken(&tty_token);
538 return ret;
984263bc 539
984263bc
MD
540 case KDSETMODE: /* set current mode of this (virtual) console */
541 switch (*(int *)data) {
542 case KD_TEXT: /* switch to TEXT (known) mode */
543 /*
544 * If scp->mode is of graphics modes, we don't know which
545 * text mode to switch back to...
546 */
22ff886e
AH
547 if (scp->status & GRAPHICS_MODE) {
548 lwkt_reltoken(&tty_token);
984263bc 549 return EINVAL;
22ff886e 550 }
984263bc
MD
551 /* restore fonts & palette ! */
552#if 0
553#ifndef SC_NO_FONT_LOADING
554 if (ISFONTAVAIL(adp->va_flags)
555 && !(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
556 /*
557 * FONT KLUDGE
558 * Don't load fonts for now... XXX
559 */
560 if (scp->sc->fonts_loaded & FONT_8)
561 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
562 if (scp->sc->fonts_loaded & FONT_14)
563 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
564 if (scp->sc->fonts_loaded & FONT_16)
565 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
566 }
567#endif /* SC_NO_FONT_LOADING */
568#endif
569
570#ifndef SC_NO_PALETTE_LOADING
571 load_palette(adp, scp->sc->palette);
572#endif
573
984263bc
MD
574 /* move hardware cursor out of the way */
575 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
984263bc
MD
576 /* FALL THROUGH */
577
578 case KD_TEXT1: /* switch to TEXT (known) mode */
579 /*
580 * If scp->mode is of graphics modes, we don't know which
581 * text/pixel mode to switch back to...
582 */
22ff886e
AH
583 if (scp->status & GRAPHICS_MODE) {
584 lwkt_reltoken(&tty_token);
984263bc 585 return EINVAL;
22ff886e 586 }
6bc31f17 587 crit_enter();
984263bc 588 if ((error = sc_clean_up(scp))) {
6bc31f17 589 crit_exit();
22ff886e 590 lwkt_reltoken(&tty_token);
984263bc
MD
591 return error;
592 }
984263bc 593 scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
6bc31f17 594 crit_exit();
984263bc
MD
595 /* no restore fonts & palette */
596 if (scp == scp->sc->cur_scp)
597 set_mode(scp);
598 sc_clear_screen(scp);
599 scp->status &= ~UNKNOWN_MODE;
22ff886e 600 lwkt_reltoken(&tty_token);
984263bc
MD
601 return 0;
602
603#ifdef SC_PIXEL_MODE
604 case KD_PIXEL: /* pixel (raster) display */
22ff886e
AH
605 if (!(scp->status & (GRAPHICS_MODE | PIXEL_MODE))) {
606 lwkt_reltoken(&tty_token);
984263bc 607 return EINVAL;
22ff886e
AH
608 }
609 if (scp->status & GRAPHICS_MODE) {
610 lwkt_reltoken(&tty_token);
984263bc
MD
611 return sc_set_pixel_mode(scp, tp, scp->xsize, scp->ysize,
612 scp->font_size);
22ff886e 613 }
6bc31f17 614 crit_enter();
984263bc 615 if ((error = sc_clean_up(scp))) {
6bc31f17 616 crit_exit();
22ff886e 617 lwkt_reltoken(&tty_token);
984263bc
MD
618 return error;
619 }
620 scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
6bc31f17 621 crit_exit();
984263bc
MD
622 if (scp == scp->sc->cur_scp) {
623 set_mode(scp);
624#ifndef SC_NO_PALETTE_LOADING
625 load_palette(adp, scp->sc->palette);
626#endif
627 }
628 sc_clear_screen(scp);
629 scp->status &= ~UNKNOWN_MODE;
22ff886e 630 lwkt_reltoken(&tty_token);
984263bc
MD
631 return 0;
632#endif /* SC_PIXEL_MODE */
633
634 case KD_GRAPHICS: /* switch to GRAPHICS (unknown) mode */
6bc31f17 635 crit_enter();
984263bc 636 if ((error = sc_clean_up(scp))) {
6bc31f17 637 crit_exit();
22ff886e 638 lwkt_reltoken(&tty_token);
984263bc
MD
639 return error;
640 }
641 scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
6bc31f17 642 crit_exit();
22ff886e 643 lwkt_reltoken(&tty_token);
984263bc
MD
644 return 0;
645
646 default:
22ff886e 647 lwkt_reltoken(&tty_token);
984263bc
MD
648 return EINVAL;
649 }
650 /* NOT REACHED */
651
652#ifdef SC_PIXEL_MODE
653 case KDRASTER: /* set pixel (raster) display mode */
22ff886e
AH
654 if (ISUNKNOWNSC(scp) || ISTEXTSC(scp)) {
655 lwkt_reltoken(&tty_token);
984263bc 656 return ENODEV;
22ff886e
AH
657 }
658 lwkt_reltoken(&tty_token);
984263bc
MD
659 return sc_set_pixel_mode(scp, tp, ((int *)data)[0], ((int *)data)[1],
660 ((int *)data)[2]);
661#endif /* SC_PIXEL_MODE */
662
663 case KDGETMODE: /* get current mode of this (virtual) console */
664 /*
665 * From the user program's point of view, KD_PIXEL is the same
666 * as KD_TEXT...
667 */
668 *data = ISGRAPHSC(scp) ? KD_GRAPHICS : KD_TEXT;
22ff886e 669 lwkt_reltoken(&tty_token);
984263bc
MD
670 return 0;
671
672 case KDSBORDER: /* set border color of this (virtual) console */
673 scp->border = *data;
674 if (scp == scp->sc->cur_scp)
675 sc_set_border(scp, scp->border);
22ff886e 676 lwkt_reltoken(&tty_token);
984263bc
MD
677 return 0;
678 }
679
22ff886e 680 lwkt_reltoken(&tty_token);
984263bc
MD
681 return ENOIOCTL;
682}
683
684static LIST_HEAD(, sc_renderer) sc_rndr_list =
685 LIST_HEAD_INITIALIZER(sc_rndr_list);
686
687int
688sc_render_add(sc_renderer_t *rndr)
689{
690 LIST_INSERT_HEAD(&sc_rndr_list, rndr, link);
691 return 0;
692}
693
694int
695sc_render_remove(sc_renderer_t *rndr)
696{
697 /*
698 LIST_REMOVE(rndr, link);
699 */
700 return EBUSY; /* XXX */
701}
702
dc98d15f 703sc_rndr_sw_t *
21343892 704sc_render_match(scr_stat *scp, char *name, int model)
984263bc
MD
705{
706 const sc_renderer_t **list;
707 const sc_renderer_t *p;
708
709 if (!LIST_EMPTY(&sc_rndr_list)) {
710 LIST_FOREACH(p, &sc_rndr_list, link) {
21343892
SW
711 if ((strcmp(p->name, name) == 0) &&
712 (model == p->model)) {
984263bc
MD
713 scp->status &=
714 ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
715 return p->rndrsw;
716 }
717 }
718 } else {
dc62b251
MD
719 SET_FOREACH(list, scrndr_set) {
720 p = *list;
21343892
SW
721 if ((strcmp(p->name, name) == 0) &&
722 (model == p->model)) {
984263bc
MD
723 scp->status &=
724 ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
725 return p->rndrsw;
726 }
727 }
728 }
729
730 return NULL;
731}