chardev: add vc support to qapi

This patch adds 'vc' support to qapi and also switches over the
vc chardev initialization to the new qapi code path.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2013-02-25 15:52:32 +01:00
parent cd153e2aa2
commit 702ec69cc1
5 changed files with 74 additions and 16 deletions

View File

@ -450,9 +450,9 @@ void qemu_console_resize(DisplayState *ds, int width, int height);
void qemu_console_copy(DisplayState *ds, int src_x, int src_y, void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
int dst_x, int dst_y, int w, int h); int dst_x, int dst_y, int w, int h);
typedef CharDriverState *(VcHandler)(QemuOpts *); typedef CharDriverState *(VcHandler)(ChardevVC *vc);
CharDriverState *vc_init(QemuOpts *opts); CharDriverState *vc_init(ChardevVC *vc);
void register_vc_handler(VcHandler *handler); void register_vc_handler(VcHandler *handler);
/* sdl.c */ /* sdl.c */

View File

@ -3230,6 +3230,23 @@
## ##
{ 'type': 'ChardevSpicePort', 'data': { 'fqdn' : 'str' } } { 'type': 'ChardevSpicePort', 'data': { 'fqdn' : 'str' } }
##
# @ChardevVC:
#
# Configuration info for virtual console chardevs.
#
# @width: console width, in pixels
# @height: console height, in pixels
# @cols: console width, in chars
# @rows: console height, in chars
#
# Since: 1.5
##
{ 'type': 'ChardevVC', 'data': { '*width' : 'int',
'*height' : 'int',
'*cols' : 'int',
'*rows' : 'int' } }
## ##
# @ChardevBackend: # @ChardevBackend:
# #
@ -3252,7 +3269,8 @@
'stdio' : 'ChardevStdio', 'stdio' : 'ChardevStdio',
'console': 'ChardevDummy', 'console': 'ChardevDummy',
'spicevmc' : 'ChardevSpiceChannel', 'spicevmc' : 'ChardevSpiceChannel',
'spiceport' : 'ChardevSpicePort' } } 'spiceport' : 'ChardevSpicePort',
'vc' : 'ChardevVC' } }
## ##
# @ChardevReturn: # @ChardevReturn:

View File

@ -3737,6 +3737,9 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
chr = qemu_chr_open_spice_port(backend->spiceport->fqdn); chr = qemu_chr_open_spice_port(backend->spiceport->fqdn);
break; break;
#endif #endif
case CHARDEV_BACKEND_KIND_VC:
chr = vc_init(backend->vc);
break;
default: default:
error_setg(errp, "unknown chardev backend (%d)", backend->kind); error_setg(errp, "unknown chardev backend (%d)", backend->kind);
break; break;

View File

@ -1537,22 +1537,26 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds)
chr->init(chr); chr->init(chr);
} }
static CharDriverState *text_console_init(QemuOpts *opts) static CharDriverState *text_console_init(ChardevVC *vc)
{ {
CharDriverState *chr; CharDriverState *chr;
QemuConsole *s; QemuConsole *s;
unsigned width; unsigned width = 0;
unsigned height; unsigned height = 0;
chr = g_malloc0(sizeof(CharDriverState)); chr = g_malloc0(sizeof(CharDriverState));
width = qemu_opt_get_number(opts, "width", 0); if (vc->has_width) {
if (width == 0) width = vc->width;
width = qemu_opt_get_number(opts, "cols", 0) * FONT_WIDTH; } else if (vc->has_cols) {
width = vc->cols * FONT_WIDTH;
}
height = qemu_opt_get_number(opts, "height", 0); if (vc->has_height) {
if (height == 0) height = vc->height;
height = qemu_opt_get_number(opts, "rows", 0) * FONT_HEIGHT; } else if (vc->has_rows) {
height = vc->rows * FONT_HEIGHT;
}
if (width == 0 || height == 0) { if (width == 0 || height == 0) {
s = new_console(NULL, TEXT_CONSOLE); s = new_console(NULL, TEXT_CONSOLE);
@ -1575,9 +1579,9 @@ static CharDriverState *text_console_init(QemuOpts *opts)
static VcHandler *vc_handler = text_console_init; static VcHandler *vc_handler = text_console_init;
CharDriverState *vc_init(QemuOpts *opts) CharDriverState *vc_init(ChardevVC *vc)
{ {
return vc_handler(opts); return vc_handler(vc);
} }
void register_vc_handler(VcHandler *handler) void register_vc_handler(VcHandler *handler)
@ -1740,9 +1744,42 @@ PixelFormat qemu_default_pixelformat(int bpp)
return pf; return pf;
} }
static void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend,
Error **errp)
{
int val;
backend->vc = g_new0(ChardevVC, 1);
val = qemu_opt_get_number(opts, "width", 0);
if (val != 0) {
backend->vc->has_width = true;
backend->vc->width = val;
}
val = qemu_opt_get_number(opts, "height", 0);
if (val != 0) {
backend->vc->has_height = true;
backend->vc->height = val;
}
val = qemu_opt_get_number(opts, "cols", 0);
if (val != 0) {
backend->vc->has_cols = true;
backend->vc->cols = val;
}
val = qemu_opt_get_number(opts, "rows", 0);
if (val != 0) {
backend->vc->has_rows = true;
backend->vc->rows = val;
}
}
static void register_types(void) static void register_types(void)
{ {
register_char_driver("vc", text_console_init); register_char_driver_qapi("vc", CHARDEV_BACKEND_KIND_VC,
qemu_chr_parse_vc);
} }
type_init(register_types); type_init(register_types);

View File

@ -991,7 +991,7 @@ static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
static int nb_vcs; static int nb_vcs;
static CharDriverState *vcs[MAX_VCS]; static CharDriverState *vcs[MAX_VCS];
static CharDriverState *gd_vc_handler(QemuOpts *opts) static CharDriverState *gd_vc_handler(ChardevVC *unused)
{ {
CharDriverState *chr; CharDriverState *chr;