Statistics
| Branch: | Revision:

root / spice-qemu-char.c @ feature-archipelago

History | View | Annotate | Download (9.5 kB)

1 cbcc6336 Alon Levy
#include "config-host.h"
2 cbcc6336 Alon Levy
#include "trace.h"
3 cbcc6336 Alon Levy
#include "ui/qemu-spice.h"
4 dccfcd0e Paolo Bonzini
#include "sysemu/char.h"
5 cbcc6336 Alon Levy
#include <spice.h>
6 cbcc6336 Alon Levy
#include <spice-experimental.h>
7 5a49d3e9 Marc-André Lureau
#include <spice/protocol.h>
8 cbcc6336 Alon Levy
9 1de7afc9 Paolo Bonzini
#include "qemu/osdep.h"
10 cbcc6336 Alon Levy
11 cbcc6336 Alon Levy
typedef struct SpiceCharDriver {
12 cbcc6336 Alon Levy
    CharDriverState*      chr;
13 cbcc6336 Alon Levy
    SpiceCharDeviceInstance     sin;
14 cbcc6336 Alon Levy
    bool                  active;
15 ae893e5e Hans de Goede
    bool                  blocked;
16 b010cec8 Alon Levy
    const uint8_t         *datapos;
17 b010cec8 Alon Levy
    int                   datalen;
18 7a5448ce Marc-André Lureau
    QLIST_ENTRY(SpiceCharDriver) next;
19 cbcc6336 Alon Levy
} SpiceCharDriver;
20 cbcc6336 Alon Levy
21 ae893e5e Hans de Goede
typedef struct SpiceCharSource {
22 ae893e5e Hans de Goede
    GSource               source;
23 ae893e5e Hans de Goede
    SpiceCharDriver       *scd;
24 ae893e5e Hans de Goede
} SpiceCharSource;
25 ae893e5e Hans de Goede
26 7a5448ce Marc-André Lureau
static QLIST_HEAD(, SpiceCharDriver) spice_chars =
27 7a5448ce Marc-André Lureau
    QLIST_HEAD_INITIALIZER(spice_chars);
28 7a5448ce Marc-André Lureau
29 cbcc6336 Alon Levy
static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
30 cbcc6336 Alon Levy
{
31 cbcc6336 Alon Levy
    SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
32 cbcc6336 Alon Levy
    ssize_t out = 0;
33 cbcc6336 Alon Levy
    ssize_t last_out;
34 cbcc6336 Alon Levy
    uint8_t* p = (uint8_t*)buf;
35 cbcc6336 Alon Levy
36 cbcc6336 Alon Levy
    while (len > 0) {
37 75c439bc Hans de Goede
        int can_write = qemu_chr_be_can_write(scd->chr);
38 75c439bc Hans de Goede
        last_out = MIN(len, can_write);
39 07a54d70 Marc-André Lureau
        if (last_out <= 0) {
40 cbcc6336 Alon Levy
            break;
41 cbcc6336 Alon Levy
        }
42 fa5efccb Anthony Liguori
        qemu_chr_be_write(scd->chr, p, last_out);
43 35106c2d Hans de Goede
        out += last_out;
44 35106c2d Hans de Goede
        len -= last_out;
45 35106c2d Hans de Goede
        p += last_out;
46 cbcc6336 Alon Levy
    }
47 cbcc6336 Alon Levy
48 cbcc6336 Alon Levy
    trace_spice_vmc_write(out, len + out);
49 cbcc6336 Alon Levy
    return out;
50 cbcc6336 Alon Levy
}
51 cbcc6336 Alon Levy
52 cbcc6336 Alon Levy
static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
53 cbcc6336 Alon Levy
{
54 cbcc6336 Alon Levy
    SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
55 cbcc6336 Alon Levy
    int bytes = MIN(len, scd->datalen);
56 cbcc6336 Alon Levy
57 cbcc6336 Alon Levy
    if (bytes > 0) {
58 cbcc6336 Alon Levy
        memcpy(buf, scd->datapos, bytes);
59 cbcc6336 Alon Levy
        scd->datapos += bytes;
60 cbcc6336 Alon Levy
        scd->datalen -= bytes;
61 cbcc6336 Alon Levy
        assert(scd->datalen >= 0);
62 ae893e5e Hans de Goede
    }
63 ae893e5e Hans de Goede
    if (scd->datalen == 0) {
64 ae893e5e Hans de Goede
        scd->datapos = 0;
65 ae893e5e Hans de Goede
        scd->blocked = false;
66 cbcc6336 Alon Levy
    }
67 cbcc6336 Alon Levy
    trace_spice_vmc_read(bytes, len);
68 cbcc6336 Alon Levy
    return bytes;
69 cbcc6336 Alon Levy
}
70 cbcc6336 Alon Levy
71 5a49d3e9 Marc-André Lureau
#if SPICE_SERVER_VERSION >= 0x000c02
72 5a49d3e9 Marc-André Lureau
static void vmc_event(SpiceCharDeviceInstance *sin, uint8_t event)
73 5a49d3e9 Marc-André Lureau
{
74 5a49d3e9 Marc-André Lureau
    SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
75 5a49d3e9 Marc-André Lureau
    int chr_event;
76 5a49d3e9 Marc-André Lureau
77 5a49d3e9 Marc-André Lureau
    switch (event) {
78 5a49d3e9 Marc-André Lureau
    case SPICE_PORT_EVENT_BREAK:
79 5a49d3e9 Marc-André Lureau
        chr_event = CHR_EVENT_BREAK;
80 5a49d3e9 Marc-André Lureau
        break;
81 5a49d3e9 Marc-André Lureau
    default:
82 5a49d3e9 Marc-André Lureau
        return;
83 5a49d3e9 Marc-André Lureau
    }
84 5a49d3e9 Marc-André Lureau
85 5a49d3e9 Marc-André Lureau
    trace_spice_vmc_event(chr_event);
86 5a49d3e9 Marc-André Lureau
    qemu_chr_be_event(scd->chr, chr_event);
87 5a49d3e9 Marc-André Lureau
}
88 5a49d3e9 Marc-André Lureau
#endif
89 5a49d3e9 Marc-André Lureau
90 f76e4c7f Hans de Goede
static void vmc_state(SpiceCharDeviceInstance *sin, int connected)
91 f76e4c7f Hans de Goede
{
92 f76e4c7f Hans de Goede
    SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
93 f76e4c7f Hans de Goede
94 16665b94 Hans de Goede
    if ((scd->chr->be_open && connected) ||
95 16665b94 Hans de Goede
        (!scd->chr->be_open && !connected)) {
96 f76e4c7f Hans de Goede
        return;
97 f76e4c7f Hans de Goede
    }
98 f76e4c7f Hans de Goede
99 f76e4c7f Hans de Goede
    qemu_chr_be_event(scd->chr,
100 f76e4c7f Hans de Goede
                      connected ? CHR_EVENT_OPENED : CHR_EVENT_CLOSED);
101 f76e4c7f Hans de Goede
}
102 f76e4c7f Hans de Goede
103 cbcc6336 Alon Levy
static SpiceCharDeviceInterface vmc_interface = {
104 cbcc6336 Alon Levy
    .base.type          = SPICE_INTERFACE_CHAR_DEVICE,
105 cbcc6336 Alon Levy
    .base.description   = "spice virtual channel char device",
106 cbcc6336 Alon Levy
    .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
107 cbcc6336 Alon Levy
    .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
108 f76e4c7f Hans de Goede
    .state              = vmc_state,
109 cbcc6336 Alon Levy
    .write              = vmc_write,
110 cbcc6336 Alon Levy
    .read               = vmc_read,
111 5a49d3e9 Marc-André Lureau
#if SPICE_SERVER_VERSION >= 0x000c02
112 5a49d3e9 Marc-André Lureau
    .event              = vmc_event,
113 5a49d3e9 Marc-André Lureau
#endif
114 cbcc6336 Alon Levy
};
115 cbcc6336 Alon Levy
116 cbcc6336 Alon Levy
117 cbcc6336 Alon Levy
static void vmc_register_interface(SpiceCharDriver *scd)
118 cbcc6336 Alon Levy
{
119 cbcc6336 Alon Levy
    if (scd->active) {
120 cbcc6336 Alon Levy
        return;
121 cbcc6336 Alon Levy
    }
122 cbcc6336 Alon Levy
    scd->sin.base.sif = &vmc_interface.base;
123 cbcc6336 Alon Levy
    qemu_spice_add_interface(&scd->sin.base);
124 cbcc6336 Alon Levy
    scd->active = true;
125 cbcc6336 Alon Levy
    trace_spice_vmc_register_interface(scd);
126 cbcc6336 Alon Levy
}
127 cbcc6336 Alon Levy
128 cbcc6336 Alon Levy
static void vmc_unregister_interface(SpiceCharDriver *scd)
129 cbcc6336 Alon Levy
{
130 cbcc6336 Alon Levy
    if (!scd->active) {
131 cbcc6336 Alon Levy
        return;
132 cbcc6336 Alon Levy
    }
133 cbcc6336 Alon Levy
    spice_server_remove_interface(&scd->sin.base);
134 cbcc6336 Alon Levy
    scd->active = false;
135 cbcc6336 Alon Levy
    trace_spice_vmc_unregister_interface(scd);
136 cbcc6336 Alon Levy
}
137 cbcc6336 Alon Levy
138 ae893e5e Hans de Goede
static gboolean spice_char_source_prepare(GSource *source, gint *timeout)
139 ae893e5e Hans de Goede
{
140 ae893e5e Hans de Goede
    SpiceCharSource *src = (SpiceCharSource *)source;
141 ae893e5e Hans de Goede
142 ae893e5e Hans de Goede
    *timeout = -1;
143 ae893e5e Hans de Goede
144 ae893e5e Hans de Goede
    return !src->scd->blocked;
145 ae893e5e Hans de Goede
}
146 ae893e5e Hans de Goede
147 ae893e5e Hans de Goede
static gboolean spice_char_source_check(GSource *source)
148 ae893e5e Hans de Goede
{
149 ae893e5e Hans de Goede
    SpiceCharSource *src = (SpiceCharSource *)source;
150 ae893e5e Hans de Goede
151 ae893e5e Hans de Goede
    return !src->scd->blocked;
152 ae893e5e Hans de Goede
}
153 ae893e5e Hans de Goede
154 ae893e5e Hans de Goede
static gboolean spice_char_source_dispatch(GSource *source,
155 ae893e5e Hans de Goede
    GSourceFunc callback, gpointer user_data)
156 ae893e5e Hans de Goede
{
157 ae893e5e Hans de Goede
    GIOFunc func = (GIOFunc)callback;
158 ae893e5e Hans de Goede
159 ae893e5e Hans de Goede
    return func(NULL, G_IO_OUT, user_data);
160 ae893e5e Hans de Goede
}
161 ae893e5e Hans de Goede
162 ae893e5e Hans de Goede
GSourceFuncs SpiceCharSourceFuncs = {
163 ae893e5e Hans de Goede
    .prepare  = spice_char_source_prepare,
164 ae893e5e Hans de Goede
    .check    = spice_char_source_check,
165 ae893e5e Hans de Goede
    .dispatch = spice_char_source_dispatch,
166 ae893e5e Hans de Goede
};
167 ae893e5e Hans de Goede
168 ae893e5e Hans de Goede
static GSource *spice_chr_add_watch(CharDriverState *chr, GIOCondition cond)
169 ae893e5e Hans de Goede
{
170 ae893e5e Hans de Goede
    SpiceCharDriver *scd = chr->opaque;
171 ae893e5e Hans de Goede
    SpiceCharSource *src;
172 ae893e5e Hans de Goede
173 ae893e5e Hans de Goede
    assert(cond == G_IO_OUT);
174 ae893e5e Hans de Goede
175 ae893e5e Hans de Goede
    src = (SpiceCharSource *)g_source_new(&SpiceCharSourceFuncs,
176 ae893e5e Hans de Goede
                                          sizeof(SpiceCharSource));
177 ae893e5e Hans de Goede
    src->scd = scd;
178 ae893e5e Hans de Goede
179 ae893e5e Hans de Goede
    return (GSource *)src;
180 ae893e5e Hans de Goede
}
181 cbcc6336 Alon Levy
182 cbcc6336 Alon Levy
static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
183 cbcc6336 Alon Levy
{
184 cbcc6336 Alon Levy
    SpiceCharDriver *s = chr->opaque;
185 ae893e5e Hans de Goede
    int read_bytes;
186 cbcc6336 Alon Levy
187 cbcc6336 Alon Levy
    assert(s->datalen == 0);
188 b010cec8 Alon Levy
    s->datapos = buf;
189 cbcc6336 Alon Levy
    s->datalen = len;
190 cbcc6336 Alon Levy
    spice_server_char_device_wakeup(&s->sin);
191 ae893e5e Hans de Goede
    read_bytes = len - s->datalen;
192 ae893e5e Hans de Goede
    if (read_bytes != len) {
193 ae893e5e Hans de Goede
        /* We'll get passed in the unconsumed data with the next call */
194 ae893e5e Hans de Goede
        s->datalen = 0;
195 ae893e5e Hans de Goede
        s->datapos = NULL;
196 ae893e5e Hans de Goede
        s->blocked = true;
197 ae893e5e Hans de Goede
    }
198 ae893e5e Hans de Goede
    return read_bytes;
199 cbcc6336 Alon Levy
}
200 cbcc6336 Alon Levy
201 cbcc6336 Alon Levy
static void spice_chr_close(struct CharDriverState *chr)
202 cbcc6336 Alon Levy
{
203 cbcc6336 Alon Levy
    SpiceCharDriver *s = chr->opaque;
204 cbcc6336 Alon Levy
205 cbcc6336 Alon Levy
    vmc_unregister_interface(s);
206 7a5448ce Marc-André Lureau
    QLIST_REMOVE(s, next);
207 5e9b473a Hans de Goede
208 5e9b473a Hans de Goede
    g_free((char *)s->sin.subtype);
209 5e9b473a Hans de Goede
#if SPICE_SERVER_VERSION >= 0x000c02
210 5e9b473a Hans de Goede
    g_free((char *)s->sin.portname);
211 5e9b473a Hans de Goede
#endif
212 7267c094 Anthony Liguori
    g_free(s);
213 cbcc6336 Alon Levy
}
214 cbcc6336 Alon Levy
215 89091146 Marc-André Lureau
static void spice_vmc_set_fe_open(struct CharDriverState *chr, int fe_open)
216 cd8f7df2 Hans de Goede
{
217 cd8f7df2 Hans de Goede
    SpiceCharDriver *s = chr->opaque;
218 574b711a Hans de Goede
    if (fe_open) {
219 574b711a Hans de Goede
        vmc_register_interface(s);
220 574b711a Hans de Goede
    } else {
221 574b711a Hans de Goede
        vmc_unregister_interface(s);
222 574b711a Hans de Goede
    }
223 cd8f7df2 Hans de Goede
}
224 cd8f7df2 Hans de Goede
225 89091146 Marc-André Lureau
static void spice_port_set_fe_open(struct CharDriverState *chr, int fe_open)
226 89091146 Marc-André Lureau
{
227 89091146 Marc-André Lureau
#if SPICE_SERVER_VERSION >= 0x000c02
228 89091146 Marc-André Lureau
    SpiceCharDriver *s = chr->opaque;
229 89091146 Marc-André Lureau
230 89091146 Marc-André Lureau
    if (fe_open) {
231 89091146 Marc-André Lureau
        spice_server_port_event(&s->sin, SPICE_PORT_EVENT_OPENED);
232 89091146 Marc-André Lureau
    } else {
233 89091146 Marc-André Lureau
        spice_server_port_event(&s->sin, SPICE_PORT_EVENT_CLOSED);
234 89091146 Marc-André Lureau
    }
235 89091146 Marc-André Lureau
#endif
236 89091146 Marc-André Lureau
}
237 89091146 Marc-André Lureau
238 be733d6d Marc-André Lureau
static void spice_chr_fe_event(struct CharDriverState *chr, int event)
239 be733d6d Marc-André Lureau
{
240 be733d6d Marc-André Lureau
#if SPICE_SERVER_VERSION >= 0x000c02
241 be733d6d Marc-André Lureau
    SpiceCharDriver *s = chr->opaque;
242 be733d6d Marc-André Lureau
243 be733d6d Marc-André Lureau
    spice_server_port_event(&s->sin, event);
244 be733d6d Marc-André Lureau
#endif
245 be733d6d Marc-André Lureau
}
246 be733d6d Marc-André Lureau
247 cbcc6336 Alon Levy
static void print_allowed_subtypes(void)
248 cbcc6336 Alon Levy
{
249 cbcc6336 Alon Levy
    const char** psubtype;
250 cbcc6336 Alon Levy
    int i;
251 cbcc6336 Alon Levy
252 cbcc6336 Alon Levy
    fprintf(stderr, "allowed names: ");
253 cbcc6336 Alon Levy
    for(i=0, psubtype = spice_server_char_device_recognized_subtypes();
254 cbcc6336 Alon Levy
        *psubtype != NULL; ++psubtype, ++i) {
255 cbcc6336 Alon Levy
        if (i == 0) {
256 cbcc6336 Alon Levy
            fprintf(stderr, "%s", *psubtype);
257 cbcc6336 Alon Levy
        } else {
258 cbcc6336 Alon Levy
            fprintf(stderr, ", %s", *psubtype);
259 cbcc6336 Alon Levy
        }
260 cbcc6336 Alon Levy
    }
261 cbcc6336 Alon Levy
    fprintf(stderr, "\n");
262 cbcc6336 Alon Levy
}
263 cbcc6336 Alon Levy
264 89091146 Marc-André Lureau
static CharDriverState *chr_open(const char *subtype,
265 89091146 Marc-André Lureau
    void (*set_fe_open)(struct CharDriverState *, int))
266 89091146 Marc-André Lureau
267 cbcc6336 Alon Levy
{
268 cbcc6336 Alon Levy
    CharDriverState *chr;
269 cbcc6336 Alon Levy
    SpiceCharDriver *s;
270 71b423f4 Marc-André Lureau
271 71b423f4 Marc-André Lureau
    chr = g_malloc0(sizeof(CharDriverState));
272 71b423f4 Marc-André Lureau
    s = g_malloc0(sizeof(SpiceCharDriver));
273 71b423f4 Marc-André Lureau
    s->chr = chr;
274 71b423f4 Marc-André Lureau
    s->active = false;
275 5e9b473a Hans de Goede
    s->sin.subtype = g_strdup(subtype);
276 71b423f4 Marc-André Lureau
    chr->opaque = s;
277 71b423f4 Marc-André Lureau
    chr->chr_write = spice_chr_write;
278 ae893e5e Hans de Goede
    chr->chr_add_watch = spice_chr_add_watch;
279 71b423f4 Marc-André Lureau
    chr->chr_close = spice_chr_close;
280 89091146 Marc-André Lureau
    chr->chr_set_fe_open = set_fe_open;
281 bd5c51ee Michael Roth
    chr->explicit_be_open = true;
282 be733d6d Marc-André Lureau
    chr->chr_fe_event = spice_chr_fe_event;
283 71b423f4 Marc-André Lureau
284 7a5448ce Marc-André Lureau
    QLIST_INSERT_HEAD(&spice_chars, s, next);
285 7a5448ce Marc-André Lureau
286 71b423f4 Marc-André Lureau
    return chr;
287 71b423f4 Marc-André Lureau
}
288 71b423f4 Marc-André Lureau
289 cd153e2a Gerd Hoffmann
CharDriverState *qemu_chr_open_spice_vmc(const char *type)
290 71b423f4 Marc-André Lureau
{
291 71b423f4 Marc-André Lureau
    const char **psubtype = spice_server_char_device_recognized_subtypes();
292 cbcc6336 Alon Levy
293 cd153e2a Gerd Hoffmann
    if (type == NULL) {
294 cbcc6336 Alon Levy
        fprintf(stderr, "spice-qemu-char: missing name parameter\n");
295 cbcc6336 Alon Levy
        print_allowed_subtypes();
296 1f51470d Markus Armbruster
        return NULL;
297 cbcc6336 Alon Levy
    }
298 cd153e2a Gerd Hoffmann
    for (; *psubtype != NULL; ++psubtype) {
299 cd153e2a Gerd Hoffmann
        if (strcmp(type, *psubtype) == 0) {
300 cbcc6336 Alon Levy
            break;
301 cbcc6336 Alon Levy
        }
302 cbcc6336 Alon Levy
    }
303 cd153e2a Gerd Hoffmann
    if (*psubtype == NULL) {
304 cd153e2a Gerd Hoffmann
        fprintf(stderr, "spice-qemu-char: unsupported type: %s\n", type);
305 cbcc6336 Alon Levy
        print_allowed_subtypes();
306 1f51470d Markus Armbruster
        return NULL;
307 cbcc6336 Alon Levy
    }
308 cbcc6336 Alon Levy
309 89091146 Marc-André Lureau
    return chr_open(type, spice_vmc_set_fe_open);
310 cbcc6336 Alon Levy
}
311 5a49d3e9 Marc-André Lureau
312 5a49d3e9 Marc-André Lureau
#if SPICE_SERVER_VERSION >= 0x000c02
313 cd153e2a Gerd Hoffmann
CharDriverState *qemu_chr_open_spice_port(const char *name)
314 5a49d3e9 Marc-André Lureau
{
315 5a49d3e9 Marc-André Lureau
    CharDriverState *chr;
316 5a49d3e9 Marc-André Lureau
    SpiceCharDriver *s;
317 5a49d3e9 Marc-André Lureau
318 5a49d3e9 Marc-André Lureau
    if (name == NULL) {
319 5a49d3e9 Marc-André Lureau
        fprintf(stderr, "spice-qemu-char: missing name parameter\n");
320 5a49d3e9 Marc-André Lureau
        return NULL;
321 5a49d3e9 Marc-André Lureau
    }
322 5a49d3e9 Marc-André Lureau
323 89091146 Marc-André Lureau
    chr = chr_open("port", spice_port_set_fe_open);
324 5a49d3e9 Marc-André Lureau
    s = chr->opaque;
325 5e9b473a Hans de Goede
    s->sin.portname = g_strdup(name);
326 5a49d3e9 Marc-André Lureau
327 5a49d3e9 Marc-André Lureau
    return chr;
328 5a49d3e9 Marc-André Lureau
}
329 afd0b409 Marc-André Lureau
330 afd0b409 Marc-André Lureau
void qemu_spice_register_ports(void)
331 afd0b409 Marc-André Lureau
{
332 afd0b409 Marc-André Lureau
    SpiceCharDriver *s;
333 afd0b409 Marc-André Lureau
334 afd0b409 Marc-André Lureau
    QLIST_FOREACH(s, &spice_chars, next) {
335 afd0b409 Marc-André Lureau
        if (s->sin.portname == NULL) {
336 afd0b409 Marc-André Lureau
            continue;
337 afd0b409 Marc-André Lureau
        }
338 afd0b409 Marc-André Lureau
        vmc_register_interface(s);
339 afd0b409 Marc-André Lureau
    }
340 afd0b409 Marc-André Lureau
}
341 5a49d3e9 Marc-André Lureau
#endif
342 26c60614 Anthony Liguori
343 cd153e2a Gerd Hoffmann
static void qemu_chr_parse_spice_vmc(QemuOpts *opts, ChardevBackend *backend,
344 cd153e2a Gerd Hoffmann
                                     Error **errp)
345 cd153e2a Gerd Hoffmann
{
346 cd153e2a Gerd Hoffmann
    const char *name = qemu_opt_get(opts, "name");
347 cd153e2a Gerd Hoffmann
348 cd153e2a Gerd Hoffmann
    if (name == NULL) {
349 cd153e2a Gerd Hoffmann
        error_setg(errp, "chardev: spice channel: no name given");
350 cd153e2a Gerd Hoffmann
        return;
351 cd153e2a Gerd Hoffmann
    }
352 cd153e2a Gerd Hoffmann
    backend->spicevmc = g_new0(ChardevSpiceChannel, 1);
353 cd153e2a Gerd Hoffmann
    backend->spicevmc->type = g_strdup(name);
354 cd153e2a Gerd Hoffmann
}
355 cd153e2a Gerd Hoffmann
356 cd153e2a Gerd Hoffmann
static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,
357 cd153e2a Gerd Hoffmann
                                      Error **errp)
358 cd153e2a Gerd Hoffmann
{
359 cd153e2a Gerd Hoffmann
    const char *name = qemu_opt_get(opts, "name");
360 cd153e2a Gerd Hoffmann
361 cd153e2a Gerd Hoffmann
    if (name == NULL) {
362 cd153e2a Gerd Hoffmann
        error_setg(errp, "chardev: spice port: no name given");
363 cd153e2a Gerd Hoffmann
        return;
364 cd153e2a Gerd Hoffmann
    }
365 cd153e2a Gerd Hoffmann
    backend->spiceport = g_new0(ChardevSpicePort, 1);
366 cd153e2a Gerd Hoffmann
    backend->spiceport->fqdn = g_strdup(name);
367 cd153e2a Gerd Hoffmann
}
368 cd153e2a Gerd Hoffmann
369 26c60614 Anthony Liguori
static void register_types(void)
370 26c60614 Anthony Liguori
{
371 cd153e2a Gerd Hoffmann
    register_char_driver_qapi("spicevmc", CHARDEV_BACKEND_KIND_SPICEVMC,
372 cd153e2a Gerd Hoffmann
                              qemu_chr_parse_spice_vmc);
373 cd153e2a Gerd Hoffmann
    register_char_driver_qapi("spiceport", CHARDEV_BACKEND_KIND_SPICEPORT,
374 cd153e2a Gerd Hoffmann
                              qemu_chr_parse_spice_port);
375 26c60614 Anthony Liguori
}
376 26c60614 Anthony Liguori
377 26c60614 Anthony Liguori
type_init(register_types);