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