2 * QEMU graphical console
4 * Copyright (c) 2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "ui/console.h"
27 #include "hw/qdev-core.h"
28 #include "qapi/error.h"
29 #include "qapi/qapi-commands-ui.h"
30 #include "qemu/fifo8.h"
31 #include "qemu/main-loop.h"
32 #include "qemu/module.h"
33 #include "qemu/option.h"
34 #include "qemu/timer.h"
35 #include "chardev/char.h"
37 #include "exec/memory.h"
38 #include "io/channel-file.h"
39 #include "qom/object.h"
41 #define DEFAULT_BACKSCROLL 512
42 #define CONSOLE_CURSOR_PERIOD 500
44 typedef struct TextAttributes
{
54 typedef struct TextCell
{
56 TextAttributes t_attrib
;
59 #define MAX_ESC_PARAMS 3
70 TEXT_CONSOLE_FIXED_SIZE
77 console_type_t console_type
;
79 DisplaySurface
*surface
;
80 DisplayScanout scanout
;
84 QEMUTimer
*gl_unblock_timer
;
87 /* Graphic console state. */
92 const GraphicHwOps
*hw_ops
;
95 /* Text console state */
99 int backscroll_height
;
101 int x_saved
, y_saved
;
104 TextAttributes t_attrib_default
; /* default text attributes */
105 TextAttributes t_attrib
; /* currently active text attributes */
107 int text_x
[2], text_y
[2], cursor_invalidate
;
116 int esc_params
[MAX_ESC_PARAMS
];
120 /* fifo for key pressed */
124 QTAILQ_ENTRY(QemuConsole
) next
;
127 struct DisplayState
{
128 QEMUTimer
*gui_timer
;
129 uint64_t last_update
;
130 uint64_t update_interval
;
135 QLIST_HEAD(, DisplayChangeListener
) listeners
;
138 static DisplayState
*display_state
;
139 static QemuConsole
*active_console
;
140 static QTAILQ_HEAD(, QemuConsole
) consoles
=
141 QTAILQ_HEAD_INITIALIZER(consoles
);
142 static bool cursor_visible_phase
;
143 static QEMUTimer
*cursor_timer
;
145 static void text_console_do_init(Chardev
*chr
, DisplayState
*ds
);
146 static void dpy_refresh(DisplayState
*s
);
147 static DisplayState
*get_alloc_displaystate(void);
148 static void text_console_update_cursor_timer(void);
149 static void text_console_update_cursor(void *opaque
);
150 static bool displaychangelistener_has_dmabuf(DisplayChangeListener
*dcl
);
152 static void gui_update(void *opaque
)
154 uint64_t interval
= GUI_REFRESH_INTERVAL_IDLE
;
155 uint64_t dcl_interval
;
156 DisplayState
*ds
= opaque
;
157 DisplayChangeListener
*dcl
;
160 ds
->refreshing
= true;
162 ds
->refreshing
= false;
164 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
165 dcl_interval
= dcl
->update_interval
?
166 dcl
->update_interval
: GUI_REFRESH_INTERVAL_DEFAULT
;
167 if (interval
> dcl_interval
) {
168 interval
= dcl_interval
;
171 if (ds
->update_interval
!= interval
) {
172 ds
->update_interval
= interval
;
173 QTAILQ_FOREACH(con
, &consoles
, next
) {
174 if (con
->hw_ops
->update_interval
) {
175 con
->hw_ops
->update_interval(con
->hw
, interval
);
178 trace_console_refresh(interval
);
180 ds
->last_update
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
181 timer_mod(ds
->gui_timer
, ds
->last_update
+ interval
);
184 static void gui_setup_refresh(DisplayState
*ds
)
186 DisplayChangeListener
*dcl
;
187 bool need_timer
= false;
188 bool have_gfx
= false;
189 bool have_text
= false;
191 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
192 if (dcl
->ops
->dpy_refresh
!= NULL
) {
195 if (dcl
->ops
->dpy_gfx_update
!= NULL
) {
198 if (dcl
->ops
->dpy_text_update
!= NULL
) {
203 if (need_timer
&& ds
->gui_timer
== NULL
) {
204 ds
->gui_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, gui_update
, ds
);
205 timer_mod(ds
->gui_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
207 if (!need_timer
&& ds
->gui_timer
!= NULL
) {
208 timer_free(ds
->gui_timer
);
209 ds
->gui_timer
= NULL
;
212 ds
->have_gfx
= have_gfx
;
213 ds
->have_text
= have_text
;
216 void graphic_hw_update_done(QemuConsole
*con
)
219 qemu_co_queue_restart_all(&con
->dump_queue
);
223 void graphic_hw_update(QemuConsole
*con
)
226 con
= con
? con
: active_console
;
230 if (con
->hw_ops
->gfx_update
) {
231 con
->hw_ops
->gfx_update(con
->hw
);
232 async
= con
->hw_ops
->gfx_update_async
;
235 graphic_hw_update_done(con
);
239 static void graphic_hw_gl_unblock_timer(void *opaque
)
241 warn_report("console: no gl-unblock within one second");
244 void graphic_hw_gl_block(QemuConsole
*con
, bool block
)
254 assert(con
->gl_block
>= 0);
255 if (!con
->hw_ops
->gl_block
) {
258 if ((block
&& con
->gl_block
!= 1) || (!block
&& con
->gl_block
!= 0)) {
261 con
->hw_ops
->gl_block(con
->hw
, block
);
264 timeout
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
265 timeout
+= 1000; /* one sec */
266 timer_mod(con
->gl_unblock_timer
, timeout
);
268 timer_del(con
->gl_unblock_timer
);
272 int qemu_console_get_window_id(QemuConsole
*con
)
274 return con
->window_id
;
277 void qemu_console_set_window_id(QemuConsole
*con
, int window_id
)
279 con
->window_id
= window_id
;
282 void graphic_hw_invalidate(QemuConsole
*con
)
285 con
= active_console
;
287 if (con
&& con
->hw_ops
->invalidate
) {
288 con
->hw_ops
->invalidate(con
->hw
);
292 static bool ppm_save(int fd
, pixman_image_t
*image
, Error
**errp
)
294 int width
= pixman_image_get_width(image
);
295 int height
= pixman_image_get_height(image
);
296 g_autoptr(Object
) ioc
= OBJECT(qio_channel_file_new_fd(fd
));
297 g_autofree
char *header
= NULL
;
298 g_autoptr(pixman_image_t
) linebuf
= NULL
;
301 trace_ppm_save(fd
, image
);
303 header
= g_strdup_printf("P6\n%d %d\n%d\n", width
, height
, 255);
304 if (qio_channel_write_all(QIO_CHANNEL(ioc
),
305 header
, strlen(header
), errp
) < 0) {
309 linebuf
= qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8
, width
);
310 for (y
= 0; y
< height
; y
++) {
311 qemu_pixman_linebuf_fill(linebuf
, image
, width
, 0, y
);
312 if (qio_channel_write_all(QIO_CHANNEL(ioc
),
313 (char *)pixman_image_get_data(linebuf
),
314 pixman_image_get_stride(linebuf
), errp
) < 0) {
322 static void graphic_hw_update_bh(void *con
)
324 graphic_hw_update(con
);
327 /* Safety: coroutine-only, concurrent-coroutine safe, main thread only */
329 qmp_screendump(const char *filename
, bool has_device
, const char *device
,
330 bool has_head
, int64_t head
, Error
**errp
)
332 g_autoptr(pixman_image_t
) image
= NULL
;
334 DisplaySurface
*surface
;
338 con
= qemu_console_lookup_by_device_name(device
, has_head
? head
: 0,
345 error_setg(errp
, "'head' must be specified together with 'device'");
348 con
= qemu_console_lookup_by_index(0);
350 error_setg(errp
, "There is no console to take a screendump from");
355 if (qemu_co_queue_empty(&con
->dump_queue
)) {
356 /* Defer the update, it will restart the pending coroutines */
357 aio_bh_schedule_oneshot(qemu_get_aio_context(),
358 graphic_hw_update_bh
, con
);
360 qemu_co_queue_wait(&con
->dump_queue
, NULL
);
363 * All pending coroutines are woken up, while the BQL is held. No
364 * further graphic update are possible until it is released. Take
365 * an image ref before that.
367 surface
= qemu_console_surface(con
);
369 error_setg(errp
, "no surface");
372 image
= pixman_image_ref(surface
->image
);
374 fd
= qemu_open_old(filename
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, 0666);
376 error_setg(errp
, "failed to open file '%s': %s", filename
,
382 * The image content could potentially be updated as the coroutine
383 * yields and releases the BQL. It could produce corrupted dump, but
384 * it should be otherwise safe.
386 if (!ppm_save(fd
, image
, errp
)) {
387 qemu_unlink(filename
);
391 void graphic_hw_text_update(QemuConsole
*con
, console_ch_t
*chardata
)
394 con
= active_console
;
396 if (con
&& con
->hw_ops
->text_update
) {
397 con
->hw_ops
->text_update(con
->hw
, chardata
);
401 static void vga_fill_rect(QemuConsole
*con
,
402 int posx
, int posy
, int width
, int height
,
403 pixman_color_t color
)
405 DisplaySurface
*surface
= qemu_console_surface(con
);
406 pixman_rectangle16_t rect
= {
407 .x
= posx
, .y
= posy
, .width
= width
, .height
= height
410 pixman_image_fill_rectangles(PIXMAN_OP_SRC
, surface
->image
,
414 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
415 static void vga_bitblt(QemuConsole
*con
,
416 int xs
, int ys
, int xd
, int yd
, int w
, int h
)
418 DisplaySurface
*surface
= qemu_console_surface(con
);
420 pixman_image_composite(PIXMAN_OP_SRC
,
421 surface
->image
, NULL
, surface
->image
,
422 xs
, ys
, 0, 0, xd
, yd
, w
, h
);
425 /***********************************************************/
426 /* basic char display */
428 #define FONT_HEIGHT 16
433 #define QEMU_RGB(r, g, b) \
434 { .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
436 static const pixman_color_t color_table_rgb
[2][8] = {
438 [QEMU_COLOR_BLACK
] = QEMU_RGB(0x00, 0x00, 0x00), /* black */
439 [QEMU_COLOR_BLUE
] = QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
440 [QEMU_COLOR_GREEN
] = QEMU_RGB(0x00, 0xaa, 0x00), /* green */
441 [QEMU_COLOR_CYAN
] = QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
442 [QEMU_COLOR_RED
] = QEMU_RGB(0xaa, 0x00, 0x00), /* red */
443 [QEMU_COLOR_MAGENTA
] = QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
444 [QEMU_COLOR_YELLOW
] = QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
445 [QEMU_COLOR_WHITE
] = QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
448 [QEMU_COLOR_BLACK
] = QEMU_RGB(0x00, 0x00, 0x00), /* black */
449 [QEMU_COLOR_BLUE
] = QEMU_RGB(0x00, 0x00, 0xff), /* blue */
450 [QEMU_COLOR_GREEN
] = QEMU_RGB(0x00, 0xff, 0x00), /* green */
451 [QEMU_COLOR_CYAN
] = QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
452 [QEMU_COLOR_RED
] = QEMU_RGB(0xff, 0x00, 0x00), /* red */
453 [QEMU_COLOR_MAGENTA
] = QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
454 [QEMU_COLOR_YELLOW
] = QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
455 [QEMU_COLOR_WHITE
] = QEMU_RGB(0xff, 0xff, 0xff), /* white */
459 static void vga_putcharxy(QemuConsole
*s
, int x
, int y
, int ch
,
460 TextAttributes
*t_attrib
)
462 static pixman_image_t
*glyphs
[256];
463 DisplaySurface
*surface
= qemu_console_surface(s
);
464 pixman_color_t fgcol
, bgcol
;
466 if (t_attrib
->invers
) {
467 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
468 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
470 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
471 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
475 glyphs
[ch
] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, ch
);
477 qemu_pixman_glyph_render(glyphs
[ch
], surface
->image
,
478 &fgcol
, &bgcol
, x
, y
, FONT_WIDTH
, FONT_HEIGHT
);
481 static void text_console_resize(QemuConsole
*s
)
483 TextCell
*cells
, *c
, *c1
;
484 int w1
, x
, y
, last_width
;
486 assert(s
->scanout
.kind
== SCANOUT_SURFACE
);
488 last_width
= s
->width
;
489 s
->width
= surface_width(s
->surface
) / FONT_WIDTH
;
490 s
->height
= surface_height(s
->surface
) / FONT_HEIGHT
;
496 cells
= g_new(TextCell
, s
->width
* s
->total_height
+ 1);
497 for(y
= 0; y
< s
->total_height
; y
++) {
498 c
= &cells
[y
* s
->width
];
500 c1
= &s
->cells
[y
* last_width
];
501 for(x
= 0; x
< w1
; x
++) {
505 for(x
= w1
; x
< s
->width
; x
++) {
507 c
->t_attrib
= s
->t_attrib_default
;
515 static inline void text_update_xy(QemuConsole
*s
, int x
, int y
)
517 s
->text_x
[0] = MIN(s
->text_x
[0], x
);
518 s
->text_x
[1] = MAX(s
->text_x
[1], x
);
519 s
->text_y
[0] = MIN(s
->text_y
[0], y
);
520 s
->text_y
[1] = MAX(s
->text_y
[1], y
);
523 static void invalidate_xy(QemuConsole
*s
, int x
, int y
)
525 if (!qemu_console_is_visible(s
)) {
528 if (s
->update_x0
> x
* FONT_WIDTH
)
529 s
->update_x0
= x
* FONT_WIDTH
;
530 if (s
->update_y0
> y
* FONT_HEIGHT
)
531 s
->update_y0
= y
* FONT_HEIGHT
;
532 if (s
->update_x1
< (x
+ 1) * FONT_WIDTH
)
533 s
->update_x1
= (x
+ 1) * FONT_WIDTH
;
534 if (s
->update_y1
< (y
+ 1) * FONT_HEIGHT
)
535 s
->update_y1
= (y
+ 1) * FONT_HEIGHT
;
538 static void update_xy(QemuConsole
*s
, int x
, int y
)
543 if (s
->ds
->have_text
) {
544 text_update_xy(s
, x
, y
);
547 y1
= (s
->y_base
+ y
) % s
->total_height
;
548 y2
= y1
- s
->y_displayed
;
550 y2
+= s
->total_height
;
552 if (y2
< s
->height
) {
556 c
= &s
->cells
[y1
* s
->width
+ x
];
557 vga_putcharxy(s
, x
, y2
, c
->ch
,
559 invalidate_xy(s
, x
, y2
);
563 static void console_show_cursor(QemuConsole
*s
, int show
)
569 if (s
->ds
->have_text
) {
570 s
->cursor_invalidate
= 1;
576 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
577 y
= y1
- s
->y_displayed
;
579 y
+= s
->total_height
;
582 c
= &s
->cells
[y1
* s
->width
+ x
];
583 if (show
&& cursor_visible_phase
) {
584 TextAttributes t_attrib
= s
->t_attrib_default
;
585 t_attrib
.invers
= !(t_attrib
.invers
); /* invert fg and bg */
586 vga_putcharxy(s
, x
, y
, c
->ch
, &t_attrib
);
588 vga_putcharxy(s
, x
, y
, c
->ch
, &(c
->t_attrib
));
590 invalidate_xy(s
, x
, y
);
594 static void console_refresh(QemuConsole
*s
)
596 DisplaySurface
*surface
= qemu_console_surface(s
);
600 if (s
->ds
->have_text
) {
603 s
->text_x
[1] = s
->width
- 1;
604 s
->text_y
[1] = s
->height
- 1;
605 s
->cursor_invalidate
= 1;
608 vga_fill_rect(s
, 0, 0, surface_width(surface
), surface_height(surface
),
609 color_table_rgb
[0][QEMU_COLOR_BLACK
]);
611 for (y
= 0; y
< s
->height
; y
++) {
612 c
= s
->cells
+ y1
* s
->width
;
613 for (x
= 0; x
< s
->width
; x
++) {
614 vga_putcharxy(s
, x
, y
, c
->ch
,
618 if (++y1
== s
->total_height
) {
622 console_show_cursor(s
, 1);
623 dpy_gfx_update(s
, 0, 0,
624 surface_width(surface
), surface_height(surface
));
627 static void console_scroll(QemuConsole
*s
, int ydelta
)
632 for(i
= 0; i
< ydelta
; i
++) {
633 if (s
->y_displayed
== s
->y_base
)
635 if (++s
->y_displayed
== s
->total_height
)
640 i
= s
->backscroll_height
;
641 if (i
> s
->total_height
- s
->height
)
642 i
= s
->total_height
- s
->height
;
645 y1
+= s
->total_height
;
646 for(i
= 0; i
< ydelta
; i
++) {
647 if (s
->y_displayed
== y1
)
649 if (--s
->y_displayed
< 0)
650 s
->y_displayed
= s
->total_height
- 1;
656 static void console_put_lf(QemuConsole
*s
)
662 if (s
->y
>= s
->height
) {
663 s
->y
= s
->height
- 1;
665 if (s
->y_displayed
== s
->y_base
) {
666 if (++s
->y_displayed
== s
->total_height
)
669 if (++s
->y_base
== s
->total_height
)
671 if (s
->backscroll_height
< s
->total_height
)
672 s
->backscroll_height
++;
673 y1
= (s
->y_base
+ s
->height
- 1) % s
->total_height
;
674 c
= &s
->cells
[y1
* s
->width
];
675 for(x
= 0; x
< s
->width
; x
++) {
677 c
->t_attrib
= s
->t_attrib_default
;
680 if (s
->y_displayed
== s
->y_base
) {
681 if (s
->ds
->have_text
) {
684 s
->text_x
[1] = s
->width
- 1;
685 s
->text_y
[1] = s
->height
- 1;
688 vga_bitblt(s
, 0, FONT_HEIGHT
, 0, 0,
689 s
->width
* FONT_WIDTH
,
690 (s
->height
- 1) * FONT_HEIGHT
);
691 vga_fill_rect(s
, 0, (s
->height
- 1) * FONT_HEIGHT
,
692 s
->width
* FONT_WIDTH
, FONT_HEIGHT
,
693 color_table_rgb
[0][s
->t_attrib_default
.bgcol
]);
696 s
->update_x1
= s
->width
* FONT_WIDTH
;
697 s
->update_y1
= s
->height
* FONT_HEIGHT
;
702 /* Set console attributes depending on the current escape codes.
703 * NOTE: I know this code is not very efficient (checking every color for it
704 * self) but it is more readable and better maintainable.
706 static void console_handle_escape(QemuConsole
*s
)
710 for (i
=0; i
<s
->nb_esc_params
; i
++) {
711 switch (s
->esc_params
[i
]) {
712 case 0: /* reset all console attributes to default */
713 s
->t_attrib
= s
->t_attrib_default
;
716 s
->t_attrib
.bold
= 1;
719 s
->t_attrib
.uline
= 1;
722 s
->t_attrib
.blink
= 1;
725 s
->t_attrib
.invers
= 1;
728 s
->t_attrib
.unvisible
= 1;
731 s
->t_attrib
.bold
= 0;
734 s
->t_attrib
.uline
= 0;
737 s
->t_attrib
.blink
= 0;
740 s
->t_attrib
.invers
= 0;
743 s
->t_attrib
.unvisible
= 0;
745 /* set foreground color */
747 s
->t_attrib
.fgcol
= QEMU_COLOR_BLACK
;
750 s
->t_attrib
.fgcol
= QEMU_COLOR_RED
;
753 s
->t_attrib
.fgcol
= QEMU_COLOR_GREEN
;
756 s
->t_attrib
.fgcol
= QEMU_COLOR_YELLOW
;
759 s
->t_attrib
.fgcol
= QEMU_COLOR_BLUE
;
762 s
->t_attrib
.fgcol
= QEMU_COLOR_MAGENTA
;
765 s
->t_attrib
.fgcol
= QEMU_COLOR_CYAN
;
768 s
->t_attrib
.fgcol
= QEMU_COLOR_WHITE
;
770 /* set background color */
772 s
->t_attrib
.bgcol
= QEMU_COLOR_BLACK
;
775 s
->t_attrib
.bgcol
= QEMU_COLOR_RED
;
778 s
->t_attrib
.bgcol
= QEMU_COLOR_GREEN
;
781 s
->t_attrib
.bgcol
= QEMU_COLOR_YELLOW
;
784 s
->t_attrib
.bgcol
= QEMU_COLOR_BLUE
;
787 s
->t_attrib
.bgcol
= QEMU_COLOR_MAGENTA
;
790 s
->t_attrib
.bgcol
= QEMU_COLOR_CYAN
;
793 s
->t_attrib
.bgcol
= QEMU_COLOR_WHITE
;
799 static void console_clear_xy(QemuConsole
*s
, int x
, int y
)
801 int y1
= (s
->y_base
+ y
) % s
->total_height
;
805 TextCell
*c
= &s
->cells
[y1
* s
->width
+ x
];
807 c
->t_attrib
= s
->t_attrib_default
;
811 static void console_put_one(QemuConsole
*s
, int ch
)
815 if (s
->x
>= s
->width
) {
820 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
821 c
= &s
->cells
[y1
* s
->width
+ s
->x
];
823 c
->t_attrib
= s
->t_attrib
;
824 update_xy(s
, s
->x
, s
->y
);
828 static void console_respond_str(QemuConsole
*s
, const char *buf
)
831 console_put_one(s
, *buf
);
836 /* set cursor, checking bounds */
837 static void set_cursor(QemuConsole
*s
, int x
, int y
)
845 if (y
>= s
->height
) {
856 static void console_putchar(QemuConsole
*s
, int ch
)
865 case '\r': /* carriage return */
868 case '\n': /* newline */
871 case '\b': /* backspace */
875 case '\t': /* tabspace */
876 if (s
->x
+ (8 - (s
->x
% 8)) > s
->width
) {
880 s
->x
= s
->x
+ (8 - (s
->x
% 8));
883 case '\a': /* alert aka. bell */
884 /* TODO: has to be implemented */
887 /* SI (shift in), character set 0 (ignored) */
890 /* SO (shift out), character set 1 (ignored) */
892 case 27: /* esc (introducing an escape sequence) */
893 s
->state
= TTY_STATE_ESC
;
896 console_put_one(s
, ch
);
900 case TTY_STATE_ESC
: /* check if it is a terminal escape sequence */
902 for(i
=0;i
<MAX_ESC_PARAMS
;i
++)
903 s
->esc_params
[i
] = 0;
904 s
->nb_esc_params
= 0;
905 s
->state
= TTY_STATE_CSI
;
907 s
->state
= TTY_STATE_NORM
;
910 case TTY_STATE_CSI
: /* handle escape sequence parameters */
911 if (ch
>= '0' && ch
<= '9') {
912 if (s
->nb_esc_params
< MAX_ESC_PARAMS
) {
913 int *param
= &s
->esc_params
[s
->nb_esc_params
];
914 int digit
= (ch
- '0');
916 *param
= (*param
<= (INT_MAX
- digit
) / 10) ?
917 *param
* 10 + digit
: INT_MAX
;
920 if (s
->nb_esc_params
< MAX_ESC_PARAMS
)
922 if (ch
== ';' || ch
== '?') {
925 trace_console_putchar_csi(s
->esc_params
[0], s
->esc_params
[1],
926 ch
, s
->nb_esc_params
);
927 s
->state
= TTY_STATE_NORM
;
931 if (s
->esc_params
[0] == 0) {
932 s
->esc_params
[0] = 1;
934 set_cursor(s
, s
->x
, s
->y
- s
->esc_params
[0]);
937 /* move cursor down */
938 if (s
->esc_params
[0] == 0) {
939 s
->esc_params
[0] = 1;
941 set_cursor(s
, s
->x
, s
->y
+ s
->esc_params
[0]);
944 /* move cursor right */
945 if (s
->esc_params
[0] == 0) {
946 s
->esc_params
[0] = 1;
948 set_cursor(s
, s
->x
+ s
->esc_params
[0], s
->y
);
951 /* move cursor left */
952 if (s
->esc_params
[0] == 0) {
953 s
->esc_params
[0] = 1;
955 set_cursor(s
, s
->x
- s
->esc_params
[0], s
->y
);
958 /* move cursor to column */
959 set_cursor(s
, s
->esc_params
[0] - 1, s
->y
);
963 /* move cursor to row, column */
964 set_cursor(s
, s
->esc_params
[1] - 1, s
->esc_params
[0] - 1);
967 switch (s
->esc_params
[0]) {
969 /* clear to end of screen */
970 for (y
= s
->y
; y
< s
->height
; y
++) {
971 for (x
= 0; x
< s
->width
; x
++) {
972 if (y
== s
->y
&& x
< s
->x
) {
975 console_clear_xy(s
, x
, y
);
980 /* clear from beginning of screen */
981 for (y
= 0; y
<= s
->y
; y
++) {
982 for (x
= 0; x
< s
->width
; x
++) {
983 if (y
== s
->y
&& x
> s
->x
) {
986 console_clear_xy(s
, x
, y
);
991 /* clear entire screen */
992 for (y
= 0; y
<= s
->height
; y
++) {
993 for (x
= 0; x
< s
->width
; x
++) {
994 console_clear_xy(s
, x
, y
);
1001 switch (s
->esc_params
[0]) {
1004 for(x
= s
->x
; x
< s
->width
; x
++) {
1005 console_clear_xy(s
, x
, s
->y
);
1009 /* clear from beginning of line */
1010 for (x
= 0; x
<= s
->x
&& x
< s
->width
; x
++) {
1011 console_clear_xy(s
, x
, s
->y
);
1015 /* clear entire line */
1016 for(x
= 0; x
< s
->width
; x
++) {
1017 console_clear_xy(s
, x
, s
->y
);
1023 console_handle_escape(s
);
1026 switch (s
->esc_params
[0]) {
1028 /* report console status (always succeed)*/
1029 console_respond_str(s
, "\033[0n");
1032 /* report cursor position */
1033 sprintf(response
, "\033[%d;%dR",
1034 (s
->y_base
+ s
->y
) % s
->total_height
+ 1,
1036 console_respond_str(s
, response
);
1041 /* save cursor position */
1046 /* restore cursor position */
1051 trace_console_putchar_unhandled(ch
);
1059 static void displaychangelistener_display_console(DisplayChangeListener
*dcl
,
1062 static const char nodev
[] =
1063 "This VM has no graphic display device.";
1064 static DisplaySurface
*dummy
;
1067 if (!dcl
->ops
->dpy_gfx_switch
) {
1071 dummy
= qemu_create_placeholder_surface(640, 480, nodev
);
1073 dcl
->ops
->dpy_gfx_switch(dcl
, dummy
);
1077 if (con
->scanout
.kind
== SCANOUT_DMABUF
&&
1078 displaychangelistener_has_dmabuf(dcl
)) {
1079 dcl
->ops
->dpy_gl_scanout_dmabuf(dcl
, con
->scanout
.dmabuf
);
1080 } else if (con
->scanout
.kind
== SCANOUT_TEXTURE
&&
1081 dcl
->ops
->dpy_gl_scanout_texture
) {
1082 dcl
->ops
->dpy_gl_scanout_texture(dcl
,
1083 con
->scanout
.texture
.backing_id
,
1084 con
->scanout
.texture
.backing_y_0_top
,
1085 con
->scanout
.texture
.backing_width
,
1086 con
->scanout
.texture
.backing_height
,
1087 con
->scanout
.texture
.x
,
1088 con
->scanout
.texture
.y
,
1089 con
->scanout
.texture
.width
,
1090 con
->scanout
.texture
.height
);
1091 } else if (con
->scanout
.kind
== SCANOUT_SURFACE
&&
1092 dcl
->ops
->dpy_gfx_switch
) {
1093 dcl
->ops
->dpy_gfx_switch(dcl
, con
->surface
);
1096 dcl
->ops
->dpy_gfx_update(dcl
, 0, 0,
1097 qemu_console_get_width(con
, 0),
1098 qemu_console_get_height(con
, 0));
1101 void console_select(unsigned int index
)
1103 DisplayChangeListener
*dcl
;
1106 trace_console_select(index
);
1107 s
= qemu_console_lookup_by_index(index
);
1109 DisplayState
*ds
= s
->ds
;
1113 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1114 if (dcl
->con
!= NULL
) {
1117 displaychangelistener_display_console(dcl
, s
);
1120 if (ds
->have_text
) {
1121 dpy_text_resize(s
, s
->width
, s
->height
);
1123 text_console_update_cursor(NULL
);
1129 QemuConsole
*console
;
1131 typedef struct VCChardev VCChardev
;
1133 #define TYPE_CHARDEV_VC "chardev-vc"
1134 DECLARE_INSTANCE_CHECKER(VCChardev
, VC_CHARDEV
,
1137 static int vc_chr_write(Chardev
*chr
, const uint8_t *buf
, int len
)
1139 VCChardev
*drv
= VC_CHARDEV(chr
);
1140 QemuConsole
*s
= drv
->console
;
1147 s
->update_x0
= s
->width
* FONT_WIDTH
;
1148 s
->update_y0
= s
->height
* FONT_HEIGHT
;
1151 console_show_cursor(s
, 0);
1152 for(i
= 0; i
< len
; i
++) {
1153 console_putchar(s
, buf
[i
]);
1155 console_show_cursor(s
, 1);
1156 if (s
->ds
->have_gfx
&& s
->update_x0
< s
->update_x1
) {
1157 dpy_gfx_update(s
, s
->update_x0
, s
->update_y0
,
1158 s
->update_x1
- s
->update_x0
,
1159 s
->update_y1
- s
->update_y0
);
1164 static void kbd_send_chars(QemuConsole
*s
)
1166 uint32_t len
, avail
;
1168 len
= qemu_chr_be_can_write(s
->chr
);
1169 avail
= fifo8_num_used(&s
->out_fifo
);
1170 while (len
> 0 && avail
> 0) {
1174 buf
= fifo8_pop_buf(&s
->out_fifo
, MIN(len
, avail
), &size
);
1175 qemu_chr_be_write(s
->chr
, (uint8_t *)buf
, size
);
1176 len
= qemu_chr_be_can_write(s
->chr
);
1181 /* called when an ascii key is pressed */
1182 void kbd_put_keysym_console(QemuConsole
*s
, int keysym
)
1184 uint8_t buf
[16], *q
;
1188 if (!s
|| (s
->console_type
== GRAPHIC_CONSOLE
))
1192 case QEMU_KEY_CTRL_UP
:
1193 console_scroll(s
, -1);
1195 case QEMU_KEY_CTRL_DOWN
:
1196 console_scroll(s
, 1);
1198 case QEMU_KEY_CTRL_PAGEUP
:
1199 console_scroll(s
, -10);
1201 case QEMU_KEY_CTRL_PAGEDOWN
:
1202 console_scroll(s
, 10);
1205 /* convert the QEMU keysym to VT100 key string */
1207 if (keysym
>= 0xe100 && keysym
<= 0xe11f) {
1210 c
= keysym
- 0xe100;
1212 *q
++ = '0' + (c
/ 10);
1213 *q
++ = '0' + (c
% 10);
1215 } else if (keysym
>= 0xe120 && keysym
<= 0xe17f) {
1218 *q
++ = keysym
& 0xff;
1219 } else if (s
->echo
&& (keysym
== '\r' || keysym
== '\n')) {
1220 vc_chr_write(s
->chr
, (const uint8_t *) "\r", 1);
1226 vc_chr_write(s
->chr
, buf
, q
- buf
);
1228 num_free
= fifo8_num_free(&s
->out_fifo
);
1229 fifo8_push_all(&s
->out_fifo
, buf
, MIN(num_free
, q
- buf
));
1235 static const int qcode_to_keysym
[Q_KEY_CODE__MAX
] = {
1236 [Q_KEY_CODE_UP
] = QEMU_KEY_UP
,
1237 [Q_KEY_CODE_DOWN
] = QEMU_KEY_DOWN
,
1238 [Q_KEY_CODE_RIGHT
] = QEMU_KEY_RIGHT
,
1239 [Q_KEY_CODE_LEFT
] = QEMU_KEY_LEFT
,
1240 [Q_KEY_CODE_HOME
] = QEMU_KEY_HOME
,
1241 [Q_KEY_CODE_END
] = QEMU_KEY_END
,
1242 [Q_KEY_CODE_PGUP
] = QEMU_KEY_PAGEUP
,
1243 [Q_KEY_CODE_PGDN
] = QEMU_KEY_PAGEDOWN
,
1244 [Q_KEY_CODE_DELETE
] = QEMU_KEY_DELETE
,
1245 [Q_KEY_CODE_BACKSPACE
] = QEMU_KEY_BACKSPACE
,
1248 static const int ctrl_qcode_to_keysym
[Q_KEY_CODE__MAX
] = {
1249 [Q_KEY_CODE_UP
] = QEMU_KEY_CTRL_UP
,
1250 [Q_KEY_CODE_DOWN
] = QEMU_KEY_CTRL_DOWN
,
1251 [Q_KEY_CODE_RIGHT
] = QEMU_KEY_CTRL_RIGHT
,
1252 [Q_KEY_CODE_LEFT
] = QEMU_KEY_CTRL_LEFT
,
1253 [Q_KEY_CODE_HOME
] = QEMU_KEY_CTRL_HOME
,
1254 [Q_KEY_CODE_END
] = QEMU_KEY_CTRL_END
,
1255 [Q_KEY_CODE_PGUP
] = QEMU_KEY_CTRL_PAGEUP
,
1256 [Q_KEY_CODE_PGDN
] = QEMU_KEY_CTRL_PAGEDOWN
,
1259 bool kbd_put_qcode_console(QemuConsole
*s
, int qcode
, bool ctrl
)
1263 keysym
= ctrl
? ctrl_qcode_to_keysym
[qcode
] : qcode_to_keysym
[qcode
];
1267 kbd_put_keysym_console(s
, keysym
);
1271 void kbd_put_string_console(QemuConsole
*s
, const char *str
, int len
)
1275 for (i
= 0; i
< len
&& str
[i
]; i
++) {
1276 kbd_put_keysym_console(s
, str
[i
]);
1280 void kbd_put_keysym(int keysym
)
1282 kbd_put_keysym_console(active_console
, keysym
);
1285 static void text_console_invalidate(void *opaque
)
1287 QemuConsole
*s
= (QemuConsole
*) opaque
;
1289 if (s
->ds
->have_text
&& s
->console_type
== TEXT_CONSOLE
) {
1290 text_console_resize(s
);
1295 static void text_console_update(void *opaque
, console_ch_t
*chardata
)
1297 QemuConsole
*s
= (QemuConsole
*) opaque
;
1300 if (s
->text_x
[0] <= s
->text_x
[1]) {
1301 src
= (s
->y_base
+ s
->text_y
[0]) * s
->width
;
1302 chardata
+= s
->text_y
[0] * s
->width
;
1303 for (i
= s
->text_y
[0]; i
<= s
->text_y
[1]; i
++)
1304 for (j
= 0; j
< s
->width
; j
++, src
++) {
1305 console_write_ch(chardata
++,
1306 ATTR2CHTYPE(s
->cells
[src
].ch
,
1307 s
->cells
[src
].t_attrib
.fgcol
,
1308 s
->cells
[src
].t_attrib
.bgcol
,
1309 s
->cells
[src
].t_attrib
.bold
));
1311 dpy_text_update(s
, s
->text_x
[0], s
->text_y
[0],
1312 s
->text_x
[1] - s
->text_x
[0], i
- s
->text_y
[0]);
1313 s
->text_x
[0] = s
->width
;
1314 s
->text_y
[0] = s
->height
;
1318 if (s
->cursor_invalidate
) {
1319 dpy_text_cursor(s
, s
->x
, s
->y
);
1320 s
->cursor_invalidate
= 0;
1324 static QemuConsole
*new_console(DisplayState
*ds
, console_type_t console_type
,
1331 obj
= object_new(TYPE_QEMU_CONSOLE
);
1332 s
= QEMU_CONSOLE(obj
);
1333 qemu_co_queue_init(&s
->dump_queue
);
1335 object_property_add_link(obj
, "device", TYPE_DEVICE
,
1336 (Object
**)&s
->device
,
1337 object_property_allow_set_link
,
1338 OBJ_PROP_LINK_STRONG
);
1339 object_property_add_uint32_ptr(obj
, "head", &s
->head
,
1340 OBJ_PROP_FLAG_READ
);
1342 if (!active_console
|| ((active_console
->console_type
!= GRAPHIC_CONSOLE
) &&
1343 (console_type
== GRAPHIC_CONSOLE
))) {
1347 s
->console_type
= console_type
;
1350 if (QTAILQ_EMPTY(&consoles
)) {
1352 QTAILQ_INSERT_TAIL(&consoles
, s
, next
);
1353 } else if (console_type
!= GRAPHIC_CONSOLE
|| phase_check(PHASE_MACHINE_READY
)) {
1354 QemuConsole
*last
= QTAILQ_LAST(&consoles
);
1355 s
->index
= last
->index
+ 1;
1356 QTAILQ_INSERT_TAIL(&consoles
, s
, next
);
1359 * HACK: Put graphical consoles before text consoles.
1361 * Only do that for coldplugged devices. After initial device
1362 * initialization we will not renumber the consoles any more.
1364 QemuConsole
*c
= QTAILQ_FIRST(&consoles
);
1366 while (QTAILQ_NEXT(c
, next
) != NULL
&&
1367 c
->console_type
== GRAPHIC_CONSOLE
) {
1368 c
= QTAILQ_NEXT(c
, next
);
1370 if (c
->console_type
== GRAPHIC_CONSOLE
) {
1371 /* have no text consoles */
1372 s
->index
= c
->index
+ 1;
1373 QTAILQ_INSERT_AFTER(&consoles
, c
, s
, next
);
1375 s
->index
= c
->index
;
1376 QTAILQ_INSERT_BEFORE(c
, s
, next
);
1377 /* renumber text consoles */
1378 for (i
= s
->index
+ 1; c
!= NULL
; c
= QTAILQ_NEXT(c
, next
), i
++) {
1386 DisplaySurface
*qemu_create_displaysurface(int width
, int height
)
1388 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1390 trace_displaysurface_create(surface
, width
, height
);
1391 surface
->format
= PIXMAN_x8r8g8b8
;
1392 surface
->image
= pixman_image_create_bits(surface
->format
,
1395 assert(surface
->image
!= NULL
);
1396 surface
->flags
= QEMU_ALLOCATED_FLAG
;
1401 DisplaySurface
*qemu_create_displaysurface_from(int width
, int height
,
1402 pixman_format_code_t format
,
1403 int linesize
, uint8_t *data
)
1405 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1407 trace_displaysurface_create_from(surface
, width
, height
, format
);
1408 surface
->format
= format
;
1409 surface
->image
= pixman_image_create_bits(surface
->format
,
1411 (void *)data
, linesize
);
1412 assert(surface
->image
!= NULL
);
1417 DisplaySurface
*qemu_create_displaysurface_pixman(pixman_image_t
*image
)
1419 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1421 trace_displaysurface_create_pixman(surface
);
1422 surface
->format
= pixman_image_get_format(image
);
1423 surface
->image
= pixman_image_ref(image
);
1428 DisplaySurface
*qemu_create_placeholder_surface(int w
, int h
,
1431 DisplaySurface
*surface
= qemu_create_displaysurface(w
, h
);
1432 pixman_color_t bg
= color_table_rgb
[0][QEMU_COLOR_BLACK
];
1433 pixman_color_t fg
= color_table_rgb
[0][QEMU_COLOR_WHITE
];
1434 pixman_image_t
*glyph
;
1438 x
= (w
/ FONT_WIDTH
- len
) / 2;
1439 y
= (h
/ FONT_HEIGHT
- 1) / 2;
1440 for (i
= 0; i
< len
; i
++) {
1441 glyph
= qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, msg
[i
]);
1442 qemu_pixman_glyph_render(glyph
, surface
->image
, &fg
, &bg
,
1443 x
+i
, y
, FONT_WIDTH
, FONT_HEIGHT
);
1444 qemu_pixman_image_unref(glyph
);
1446 surface
->flags
|= QEMU_PLACEHOLDER_FLAG
;
1450 void qemu_free_displaysurface(DisplaySurface
*surface
)
1452 if (surface
== NULL
) {
1455 trace_displaysurface_free(surface
);
1456 qemu_pixman_image_unref(surface
->image
);
1460 bool console_has_gl(QemuConsole
*con
)
1462 return con
->gl
!= NULL
;
1465 static bool displaychangelistener_has_dmabuf(DisplayChangeListener
*dcl
)
1467 if (dcl
->ops
->dpy_has_dmabuf
) {
1468 return dcl
->ops
->dpy_has_dmabuf(dcl
);
1471 if (dcl
->ops
->dpy_gl_scanout_dmabuf
) {
1478 static bool dpy_compatible_with(QemuConsole
*con
,
1479 DisplayChangeListener
*dcl
, Error
**errp
)
1483 flags
= con
->hw_ops
->get_flags
? con
->hw_ops
->get_flags(con
->hw
) : 0;
1485 if (console_has_gl(con
) && con
->gl
->ops
->compatible_dcl
!= dcl
->ops
) {
1486 error_setg(errp
, "Display %s is incompatible with the GL context",
1487 dcl
->ops
->dpy_name
);
1491 if (flags
& GRAPHIC_FLAGS_GL
&&
1492 !console_has_gl(con
)) {
1493 error_setg(errp
, "The console requires a GL context.");
1498 if (flags
& GRAPHIC_FLAGS_DMABUF
&&
1499 !displaychangelistener_has_dmabuf(dcl
)) {
1500 error_setg(errp
, "The console requires display DMABUF support.");
1507 void qemu_console_set_display_gl_ctx(QemuConsole
*con
, DisplayGLCtx
*gl
)
1509 /* display has opengl support */
1512 error_report("The console already has an OpenGL context.");
1518 void register_displaychangelistener(DisplayChangeListener
*dcl
)
1525 dpy_compatible_with(dcl
->con
, dcl
, &error_fatal
);
1528 trace_displaychangelistener_register(dcl
, dcl
->ops
->dpy_name
);
1529 dcl
->ds
= get_alloc_displaystate();
1530 QLIST_INSERT_HEAD(&dcl
->ds
->listeners
, dcl
, next
);
1531 gui_setup_refresh(dcl
->ds
);
1536 con
= active_console
;
1538 displaychangelistener_display_console(dcl
, con
);
1539 text_console_update_cursor(NULL
);
1542 void update_displaychangelistener(DisplayChangeListener
*dcl
,
1545 DisplayState
*ds
= dcl
->ds
;
1547 dcl
->update_interval
= interval
;
1548 if (!ds
->refreshing
&& ds
->update_interval
> interval
) {
1549 timer_mod(ds
->gui_timer
, ds
->last_update
+ interval
);
1553 void unregister_displaychangelistener(DisplayChangeListener
*dcl
)
1555 DisplayState
*ds
= dcl
->ds
;
1556 trace_displaychangelistener_unregister(dcl
, dcl
->ops
->dpy_name
);
1560 QLIST_REMOVE(dcl
, next
);
1562 gui_setup_refresh(ds
);
1565 static void dpy_set_ui_info_timer(void *opaque
)
1567 QemuConsole
*con
= opaque
;
1569 con
->hw_ops
->ui_info(con
->hw
, con
->head
, &con
->ui_info
);
1572 bool dpy_ui_info_supported(QemuConsole
*con
)
1575 con
= active_console
;
1578 return con
->hw_ops
->ui_info
!= NULL
;
1581 const QemuUIInfo
*dpy_get_ui_info(const QemuConsole
*con
)
1584 con
= active_console
;
1587 return &con
->ui_info
;
1590 int dpy_set_ui_info(QemuConsole
*con
, QemuUIInfo
*info
, bool delay
)
1593 con
= active_console
;
1596 if (!dpy_ui_info_supported(con
)) {
1599 if (memcmp(&con
->ui_info
, info
, sizeof(con
->ui_info
)) == 0) {
1600 /* nothing changed -- ignore */
1605 * Typically we get a flood of these as the user resizes the window.
1606 * Wait until the dust has settled (one second without updates), then
1607 * go notify the guest.
1609 con
->ui_info
= *info
;
1610 timer_mod(con
->ui_timer
,
1611 qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + (delay
? 1000 : 0));
1615 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1617 DisplayState
*s
= con
->ds
;
1618 DisplayChangeListener
*dcl
;
1619 int width
= qemu_console_get_width(con
, x
+ w
);
1620 int height
= qemu_console_get_height(con
, y
+ h
);
1626 w
= MIN(w
, width
- x
);
1627 h
= MIN(h
, height
- y
);
1629 if (!qemu_console_is_visible(con
)) {
1632 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1633 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1636 if (dcl
->ops
->dpy_gfx_update
) {
1637 dcl
->ops
->dpy_gfx_update(dcl
, x
, y
, w
, h
);
1642 void dpy_gfx_update_full(QemuConsole
*con
)
1644 int w
= qemu_console_get_width(con
, 0);
1645 int h
= qemu_console_get_height(con
, 0);
1647 dpy_gfx_update(con
, 0, 0, w
, h
);
1650 void dpy_gfx_replace_surface(QemuConsole
*con
,
1651 DisplaySurface
*surface
)
1653 static const char placeholder_msg
[] = "Display output is not active.";
1654 DisplayState
*s
= con
->ds
;
1655 DisplaySurface
*old_surface
= con
->surface
;
1656 DisplayChangeListener
*dcl
;
1662 width
= surface_width(old_surface
);
1663 height
= surface_height(old_surface
);
1669 surface
= qemu_create_placeholder_surface(width
, height
, placeholder_msg
);
1672 assert(old_surface
!= surface
);
1674 con
->scanout
.kind
= SCANOUT_SURFACE
;
1675 con
->surface
= surface
;
1676 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1677 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1680 if (dcl
->ops
->dpy_gfx_switch
) {
1681 dcl
->ops
->dpy_gfx_switch(dcl
, surface
);
1684 qemu_free_displaysurface(old_surface
);
1687 bool dpy_gfx_check_format(QemuConsole
*con
,
1688 pixman_format_code_t format
)
1690 DisplayChangeListener
*dcl
;
1691 DisplayState
*s
= con
->ds
;
1693 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1694 if (dcl
->con
&& dcl
->con
!= con
) {
1695 /* dcl bound to another console -> skip */
1698 if (dcl
->ops
->dpy_gfx_check_format
) {
1699 if (!dcl
->ops
->dpy_gfx_check_format(dcl
, format
)) {
1703 /* default is to allow native 32 bpp only */
1704 if (format
!= qemu_default_pixman_format(32, true)) {
1712 static void dpy_refresh(DisplayState
*s
)
1714 DisplayChangeListener
*dcl
;
1716 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1717 if (dcl
->ops
->dpy_refresh
) {
1718 dcl
->ops
->dpy_refresh(dcl
);
1723 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
)
1725 DisplayState
*s
= con
->ds
;
1726 DisplayChangeListener
*dcl
;
1728 if (!qemu_console_is_visible(con
)) {
1731 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1732 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1735 if (dcl
->ops
->dpy_text_cursor
) {
1736 dcl
->ops
->dpy_text_cursor(dcl
, x
, y
);
1741 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1743 DisplayState
*s
= con
->ds
;
1744 DisplayChangeListener
*dcl
;
1746 if (!qemu_console_is_visible(con
)) {
1749 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1750 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1753 if (dcl
->ops
->dpy_text_update
) {
1754 dcl
->ops
->dpy_text_update(dcl
, x
, y
, w
, h
);
1759 void dpy_text_resize(QemuConsole
*con
, int w
, int h
)
1761 DisplayState
*s
= con
->ds
;
1762 DisplayChangeListener
*dcl
;
1764 if (!qemu_console_is_visible(con
)) {
1767 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1768 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1771 if (dcl
->ops
->dpy_text_resize
) {
1772 dcl
->ops
->dpy_text_resize(dcl
, w
, h
);
1777 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, int on
)
1779 DisplayState
*s
= con
->ds
;
1780 DisplayChangeListener
*dcl
;
1782 if (!qemu_console_is_visible(con
)) {
1785 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1786 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1789 if (dcl
->ops
->dpy_mouse_set
) {
1790 dcl
->ops
->dpy_mouse_set(dcl
, x
, y
, on
);
1795 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
)
1797 DisplayState
*s
= con
->ds
;
1798 DisplayChangeListener
*dcl
;
1800 if (!qemu_console_is_visible(con
)) {
1803 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1804 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1807 if (dcl
->ops
->dpy_cursor_define
) {
1808 dcl
->ops
->dpy_cursor_define(dcl
, cursor
);
1813 bool dpy_cursor_define_supported(QemuConsole
*con
)
1815 DisplayState
*s
= con
->ds
;
1816 DisplayChangeListener
*dcl
;
1818 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1819 if (dcl
->ops
->dpy_cursor_define
) {
1826 QEMUGLContext
dpy_gl_ctx_create(QemuConsole
*con
,
1827 struct QEMUGLParams
*qparams
)
1830 return con
->gl
->ops
->dpy_gl_ctx_create(con
->gl
, qparams
);
1833 void dpy_gl_ctx_destroy(QemuConsole
*con
, QEMUGLContext ctx
)
1836 con
->gl
->ops
->dpy_gl_ctx_destroy(con
->gl
, ctx
);
1839 int dpy_gl_ctx_make_current(QemuConsole
*con
, QEMUGLContext ctx
)
1842 return con
->gl
->ops
->dpy_gl_ctx_make_current(con
->gl
, ctx
);
1845 void dpy_gl_scanout_disable(QemuConsole
*con
)
1847 DisplayState
*s
= con
->ds
;
1848 DisplayChangeListener
*dcl
;
1850 if (con
->scanout
.kind
!= SCANOUT_SURFACE
) {
1851 con
->scanout
.kind
= SCANOUT_NONE
;
1853 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1854 if (dcl
->ops
->dpy_gl_scanout_disable
) {
1855 dcl
->ops
->dpy_gl_scanout_disable(dcl
);
1860 void dpy_gl_scanout_texture(QemuConsole
*con
,
1861 uint32_t backing_id
,
1862 bool backing_y_0_top
,
1863 uint32_t backing_width
,
1864 uint32_t backing_height
,
1865 uint32_t x
, uint32_t y
,
1866 uint32_t width
, uint32_t height
)
1868 DisplayState
*s
= con
->ds
;
1869 DisplayChangeListener
*dcl
;
1871 con
->scanout
.kind
= SCANOUT_TEXTURE
;
1872 con
->scanout
.texture
= (ScanoutTexture
) {
1873 backing_id
, backing_y_0_top
, backing_width
, backing_height
,
1876 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1877 if (dcl
->ops
->dpy_gl_scanout_texture
) {
1878 dcl
->ops
->dpy_gl_scanout_texture(dcl
, backing_id
,
1880 backing_width
, backing_height
,
1881 x
, y
, width
, height
);
1886 void dpy_gl_scanout_dmabuf(QemuConsole
*con
,
1889 DisplayState
*s
= con
->ds
;
1890 DisplayChangeListener
*dcl
;
1892 con
->scanout
.kind
= SCANOUT_DMABUF
;
1893 con
->scanout
.dmabuf
= dmabuf
;
1894 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1895 if (dcl
->ops
->dpy_gl_scanout_dmabuf
) {
1896 dcl
->ops
->dpy_gl_scanout_dmabuf(dcl
, dmabuf
);
1901 void dpy_gl_cursor_dmabuf(QemuConsole
*con
, QemuDmaBuf
*dmabuf
,
1902 bool have_hot
, uint32_t hot_x
, uint32_t hot_y
)
1904 DisplayState
*s
= con
->ds
;
1905 DisplayChangeListener
*dcl
;
1907 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1908 if (dcl
->ops
->dpy_gl_cursor_dmabuf
) {
1909 dcl
->ops
->dpy_gl_cursor_dmabuf(dcl
, dmabuf
,
1910 have_hot
, hot_x
, hot_y
);
1915 void dpy_gl_cursor_position(QemuConsole
*con
,
1916 uint32_t pos_x
, uint32_t pos_y
)
1918 DisplayState
*s
= con
->ds
;
1919 DisplayChangeListener
*dcl
;
1921 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1922 if (dcl
->ops
->dpy_gl_cursor_position
) {
1923 dcl
->ops
->dpy_gl_cursor_position(dcl
, pos_x
, pos_y
);
1928 void dpy_gl_release_dmabuf(QemuConsole
*con
,
1931 DisplayState
*s
= con
->ds
;
1932 DisplayChangeListener
*dcl
;
1934 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1935 if (dcl
->ops
->dpy_gl_release_dmabuf
) {
1936 dcl
->ops
->dpy_gl_release_dmabuf(dcl
, dmabuf
);
1941 void dpy_gl_update(QemuConsole
*con
,
1942 uint32_t x
, uint32_t y
, uint32_t w
, uint32_t h
)
1944 DisplayState
*s
= con
->ds
;
1945 DisplayChangeListener
*dcl
;
1949 graphic_hw_gl_block(con
, true);
1950 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1951 if (dcl
->ops
->dpy_gl_update
) {
1952 dcl
->ops
->dpy_gl_update(dcl
, x
, y
, w
, h
);
1955 graphic_hw_gl_block(con
, false);
1958 /***********************************************************/
1959 /* register display */
1961 /* console.c internal use only */
1962 static DisplayState
*get_alloc_displaystate(void)
1964 if (!display_state
) {
1965 display_state
= g_new0(DisplayState
, 1);
1966 cursor_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
,
1967 text_console_update_cursor
, NULL
);
1969 return display_state
;
1973 * Called by main(), after creating QemuConsoles
1974 * and before initializing ui (sdl/vnc/...).
1976 DisplayState
*init_displaystate(void)
1981 get_alloc_displaystate();
1982 QTAILQ_FOREACH(con
, &consoles
, next
) {
1983 if (con
->console_type
!= GRAPHIC_CONSOLE
&&
1985 text_console_do_init(con
->chr
, display_state
);
1988 /* Hook up into the qom tree here (not in new_console()), once
1989 * all QemuConsoles are created and the order / numbering
1990 * doesn't change any more */
1991 name
= g_strdup_printf("console[%d]", con
->index
);
1992 object_property_add_child(container_get(object_get_root(), "/backend"),
1997 return display_state
;
2000 void graphic_console_set_hwops(QemuConsole
*con
,
2001 const GraphicHwOps
*hw_ops
,
2004 con
->hw_ops
= hw_ops
;
2008 QemuConsole
*graphic_console_init(DeviceState
*dev
, uint32_t head
,
2009 const GraphicHwOps
*hw_ops
,
2012 static const char noinit
[] =
2013 "Guest has not initialized the display (yet).";
2018 DisplaySurface
*surface
;
2020 ds
= get_alloc_displaystate();
2021 s
= qemu_console_lookup_unused();
2023 trace_console_gfx_reuse(s
->index
);
2024 width
= qemu_console_get_width(s
, 0);
2025 height
= qemu_console_get_height(s
, 0);
2027 trace_console_gfx_new();
2028 s
= new_console(ds
, GRAPHIC_CONSOLE
, head
);
2029 s
->ui_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
,
2030 dpy_set_ui_info_timer
, s
);
2032 graphic_console_set_hwops(s
, hw_ops
, opaque
);
2034 object_property_set_link(OBJECT(s
), "device", OBJECT(dev
),
2038 surface
= qemu_create_placeholder_surface(width
, height
, noinit
);
2039 dpy_gfx_replace_surface(s
, surface
);
2040 s
->gl_unblock_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
,
2041 graphic_hw_gl_unblock_timer
, s
);
2045 static const GraphicHwOps unused_ops
= {
2049 void graphic_console_close(QemuConsole
*con
)
2051 static const char unplugged
[] =
2052 "Guest display has been unplugged";
2053 DisplaySurface
*surface
;
2054 int width
= qemu_console_get_width(con
, 640);
2055 int height
= qemu_console_get_height(con
, 480);
2057 trace_console_gfx_close(con
->index
);
2058 object_property_set_link(OBJECT(con
), "device", NULL
, &error_abort
);
2059 graphic_console_set_hwops(con
, &unused_ops
, NULL
);
2062 dpy_gl_scanout_disable(con
);
2064 surface
= qemu_create_placeholder_surface(width
, height
, unplugged
);
2065 dpy_gfx_replace_surface(con
, surface
);
2068 QemuConsole
*qemu_console_lookup_by_index(unsigned int index
)
2072 QTAILQ_FOREACH(con
, &consoles
, next
) {
2073 if (con
->index
== index
) {
2080 QemuConsole
*qemu_console_lookup_by_device(DeviceState
*dev
, uint32_t head
)
2086 QTAILQ_FOREACH(con
, &consoles
, next
) {
2087 obj
= object_property_get_link(OBJECT(con
),
2088 "device", &error_abort
);
2089 if (DEVICE(obj
) != dev
) {
2092 h
= object_property_get_uint(OBJECT(con
),
2093 "head", &error_abort
);
2102 QemuConsole
*qemu_console_lookup_by_device_name(const char *device_id
,
2103 uint32_t head
, Error
**errp
)
2108 dev
= qdev_find_recursive(sysbus_get_default(), device_id
);
2110 error_set(errp
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2111 "Device '%s' not found", device_id
);
2115 con
= qemu_console_lookup_by_device(dev
, head
);
2117 error_setg(errp
, "Device %s (head %d) is not bound to a QemuConsole",
2125 QemuConsole
*qemu_console_lookup_unused(void)
2130 QTAILQ_FOREACH(con
, &consoles
, next
) {
2131 if (con
->hw_ops
!= &unused_ops
) {
2134 obj
= object_property_get_link(OBJECT(con
),
2135 "device", &error_abort
);
2144 bool qemu_console_is_visible(QemuConsole
*con
)
2146 return (con
== active_console
) || (con
->dcls
> 0);
2149 bool qemu_console_is_graphic(QemuConsole
*con
)
2152 con
= active_console
;
2154 return con
&& (con
->console_type
== GRAPHIC_CONSOLE
);
2157 bool qemu_console_is_fixedsize(QemuConsole
*con
)
2160 con
= active_console
;
2162 return con
&& (con
->console_type
!= TEXT_CONSOLE
);
2165 bool qemu_console_is_gl_blocked(QemuConsole
*con
)
2167 assert(con
!= NULL
);
2168 return con
->gl_block
;
2171 char *qemu_console_get_label(QemuConsole
*con
)
2173 if (con
->console_type
== GRAPHIC_CONSOLE
) {
2175 return g_strdup(object_get_typename(con
->device
));
2177 return g_strdup("VGA");
2179 if (con
->chr
&& con
->chr
->label
) {
2180 return g_strdup(con
->chr
->label
);
2182 return g_strdup_printf("vc%d", con
->index
);
2186 int qemu_console_get_index(QemuConsole
*con
)
2189 con
= active_console
;
2191 return con
? con
->index
: -1;
2194 uint32_t qemu_console_get_head(QemuConsole
*con
)
2197 con
= active_console
;
2199 return con
? con
->head
: -1;
2202 int qemu_console_get_width(QemuConsole
*con
, int fallback
)
2205 con
= active_console
;
2210 switch (con
->scanout
.kind
) {
2211 case SCANOUT_DMABUF
:
2212 return con
->scanout
.dmabuf
->width
;
2213 case SCANOUT_TEXTURE
:
2214 return con
->scanout
.texture
.width
;
2215 case SCANOUT_SURFACE
:
2216 return surface_width(con
->surface
);
2222 int qemu_console_get_height(QemuConsole
*con
, int fallback
)
2225 con
= active_console
;
2230 switch (con
->scanout
.kind
) {
2231 case SCANOUT_DMABUF
:
2232 return con
->scanout
.dmabuf
->height
;
2233 case SCANOUT_TEXTURE
:
2234 return con
->scanout
.texture
.height
;
2235 case SCANOUT_SURFACE
:
2236 return surface_height(con
->surface
);
2242 static void vc_chr_accept_input(Chardev
*chr
)
2244 VCChardev
*drv
= VC_CHARDEV(chr
);
2245 QemuConsole
*s
= drv
->console
;
2250 static void vc_chr_set_echo(Chardev
*chr
, bool echo
)
2252 VCChardev
*drv
= VC_CHARDEV(chr
);
2253 QemuConsole
*s
= drv
->console
;
2258 static void text_console_update_cursor_timer(void)
2260 timer_mod(cursor_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
)
2261 + CONSOLE_CURSOR_PERIOD
/ 2);
2264 static void text_console_update_cursor(void *opaque
)
2269 cursor_visible_phase
= !cursor_visible_phase
;
2271 QTAILQ_FOREACH(s
, &consoles
, next
) {
2272 if (qemu_console_is_graphic(s
) ||
2273 !qemu_console_is_visible(s
)) {
2277 graphic_hw_invalidate(s
);
2281 text_console_update_cursor_timer();
2285 static const GraphicHwOps text_console_ops
= {
2286 .invalidate
= text_console_invalidate
,
2287 .text_update
= text_console_update
,
2290 static void text_console_do_init(Chardev
*chr
, DisplayState
*ds
)
2292 VCChardev
*drv
= VC_CHARDEV(chr
);
2293 QemuConsole
*s
= drv
->console
;
2294 int g_width
= 80 * FONT_WIDTH
;
2295 int g_height
= 24 * FONT_HEIGHT
;
2297 fifo8_create(&s
->out_fifo
, 16);
2302 s
->total_height
= DEFAULT_BACKSCROLL
;
2305 if (s
->scanout
.kind
!= SCANOUT_SURFACE
) {
2306 if (active_console
&& active_console
->scanout
.kind
== SCANOUT_SURFACE
) {
2307 g_width
= qemu_console_get_width(active_console
, g_width
);
2308 g_height
= qemu_console_get_height(active_console
, g_height
);
2310 s
->surface
= qemu_create_displaysurface(g_width
, g_height
);
2311 s
->scanout
.kind
= SCANOUT_SURFACE
;
2314 s
->hw_ops
= &text_console_ops
;
2317 /* Set text attribute defaults */
2318 s
->t_attrib_default
.bold
= 0;
2319 s
->t_attrib_default
.uline
= 0;
2320 s
->t_attrib_default
.blink
= 0;
2321 s
->t_attrib_default
.invers
= 0;
2322 s
->t_attrib_default
.unvisible
= 0;
2323 s
->t_attrib_default
.fgcol
= QEMU_COLOR_WHITE
;
2324 s
->t_attrib_default
.bgcol
= QEMU_COLOR_BLACK
;
2325 /* set current text attributes to default */
2326 s
->t_attrib
= s
->t_attrib_default
;
2327 text_console_resize(s
);
2332 s
->t_attrib
.bgcol
= QEMU_COLOR_BLUE
;
2333 msg
= g_strdup_printf("%s console\r\n", chr
->label
);
2334 vc_chr_write(chr
, (uint8_t *)msg
, strlen(msg
));
2336 s
->t_attrib
= s
->t_attrib_default
;
2339 qemu_chr_be_event(chr
, CHR_EVENT_OPENED
);
2342 static void vc_chr_open(Chardev
*chr
,
2343 ChardevBackend
*backend
,
2347 ChardevVC
*vc
= backend
->u
.vc
.data
;
2348 VCChardev
*drv
= VC_CHARDEV(chr
);
2351 unsigned height
= 0;
2353 if (vc
->has_width
) {
2355 } else if (vc
->has_cols
) {
2356 width
= vc
->cols
* FONT_WIDTH
;
2359 if (vc
->has_height
) {
2360 height
= vc
->height
;
2361 } else if (vc
->has_rows
) {
2362 height
= vc
->rows
* FONT_HEIGHT
;
2365 trace_console_txt_new(width
, height
);
2366 if (width
== 0 || height
== 0) {
2367 s
= new_console(NULL
, TEXT_CONSOLE
, 0);
2369 s
= new_console(NULL
, TEXT_CONSOLE_FIXED_SIZE
, 0);
2370 s
->scanout
.kind
= SCANOUT_SURFACE
;
2371 s
->surface
= qemu_create_displaysurface(width
, height
);
2375 error_setg(errp
, "cannot create text console");
2382 if (display_state
) {
2383 text_console_do_init(chr
, display_state
);
2386 /* console/chardev init sometimes completes elsewhere in a 2nd
2387 * stage, so defer OPENED events until they are fully initialized
2392 void qemu_console_resize(QemuConsole
*s
, int width
, int height
)
2394 DisplaySurface
*surface
;
2396 assert(s
->console_type
== GRAPHIC_CONSOLE
);
2398 if (qemu_console_get_width(s
, -1) == width
&&
2399 qemu_console_get_height(s
, -1) == height
) {
2403 surface
= qemu_create_displaysurface(width
, height
);
2404 dpy_gfx_replace_surface(s
, surface
);
2407 DisplaySurface
*qemu_console_surface(QemuConsole
*console
)
2409 switch (console
->scanout
.kind
) {
2410 case SCANOUT_SURFACE
:
2411 return console
->surface
;
2417 PixelFormat
qemu_default_pixelformat(int bpp
)
2419 pixman_format_code_t fmt
= qemu_default_pixman_format(bpp
, true);
2420 PixelFormat pf
= qemu_pixelformat_from_pixman(fmt
);
2424 static QemuDisplay
*dpys
[DISPLAY_TYPE__MAX
];
2426 void qemu_display_register(QemuDisplay
*ui
)
2428 assert(ui
->type
< DISPLAY_TYPE__MAX
);
2429 dpys
[ui
->type
] = ui
;
2432 bool qemu_display_find_default(DisplayOptions
*opts
)
2434 static DisplayType prio
[] = {
2435 #if defined(CONFIG_GTK)
2438 #if defined(CONFIG_SDL)
2441 #if defined(CONFIG_COCOA)
2447 for (i
= 0; i
< (int)ARRAY_SIZE(prio
); i
++) {
2448 if (dpys
[prio
[i
]] == NULL
) {
2449 ui_module_load_one(DisplayType_str(prio
[i
]));
2451 if (dpys
[prio
[i
]] == NULL
) {
2454 opts
->type
= prio
[i
];
2460 void qemu_display_early_init(DisplayOptions
*opts
)
2462 assert(opts
->type
< DISPLAY_TYPE__MAX
);
2463 if (opts
->type
== DISPLAY_TYPE_NONE
) {
2466 if (dpys
[opts
->type
] == NULL
) {
2467 ui_module_load_one(DisplayType_str(opts
->type
));
2469 if (dpys
[opts
->type
] == NULL
) {
2470 error_report("Display '%s' is not available.",
2471 DisplayType_str(opts
->type
));
2474 if (dpys
[opts
->type
]->early_init
) {
2475 dpys
[opts
->type
]->early_init(opts
);
2479 void qemu_display_init(DisplayState
*ds
, DisplayOptions
*opts
)
2481 assert(opts
->type
< DISPLAY_TYPE__MAX
);
2482 if (opts
->type
== DISPLAY_TYPE_NONE
) {
2485 assert(dpys
[opts
->type
] != NULL
);
2486 dpys
[opts
->type
]->init(ds
, opts
);
2489 void qemu_display_help(void)
2493 printf("Available display backend types:\n");
2495 for (idx
= DISPLAY_TYPE_NONE
; idx
< DISPLAY_TYPE__MAX
; idx
++) {
2497 ui_module_load_one(DisplayType_str(idx
));
2500 printf("%s\n", DisplayType_str(dpys
[idx
]->type
));
2505 void qemu_chr_parse_vc(QemuOpts
*opts
, ChardevBackend
*backend
, Error
**errp
)
2510 backend
->type
= CHARDEV_BACKEND_KIND_VC
;
2511 vc
= backend
->u
.vc
.data
= g_new0(ChardevVC
, 1);
2512 qemu_chr_parse_common(opts
, qapi_ChardevVC_base(vc
));
2514 val
= qemu_opt_get_number(opts
, "width", 0);
2516 vc
->has_width
= true;
2520 val
= qemu_opt_get_number(opts
, "height", 0);
2522 vc
->has_height
= true;
2526 val
= qemu_opt_get_number(opts
, "cols", 0);
2528 vc
->has_cols
= true;
2532 val
= qemu_opt_get_number(opts
, "rows", 0);
2534 vc
->has_rows
= true;
2539 static const TypeInfo qemu_console_info
= {
2540 .name
= TYPE_QEMU_CONSOLE
,
2541 .parent
= TYPE_OBJECT
,
2542 .instance_size
= sizeof(QemuConsole
),
2543 .class_size
= sizeof(QemuConsoleClass
),
2546 static void char_vc_class_init(ObjectClass
*oc
, void *data
)
2548 ChardevClass
*cc
= CHARDEV_CLASS(oc
);
2550 cc
->parse
= qemu_chr_parse_vc
;
2551 cc
->open
= vc_chr_open
;
2552 cc
->chr_write
= vc_chr_write
;
2553 cc
->chr_accept_input
= vc_chr_accept_input
;
2554 cc
->chr_set_echo
= vc_chr_set_echo
;
2557 static const TypeInfo char_vc_type_info
= {
2558 .name
= TYPE_CHARDEV_VC
,
2559 .parent
= TYPE_CHARDEV
,
2560 .instance_size
= sizeof(VCChardev
),
2561 .class_init
= char_vc_class_init
,
2564 void qemu_console_early_init(void)
2566 /* set the default vc driver */
2567 if (!object_class_by_name(TYPE_CHARDEV_VC
)) {
2568 type_register(&char_vc_type_info
);
2572 static void register_types(void)
2574 type_register_static(&qemu_console_info
);
2577 type_init(register_types
);