]>
Commit | Line | Data |
---|---|---|
98b19252 AS |
1 | /* |
2 | * A bus for connecting virtio serial and console ports | |
3 | * | |
71c092e9 | 4 | * Copyright (C) 2009, 2010 Red Hat, Inc. |
98b19252 AS |
5 | * |
6 | * Author(s): | |
7 | * Amit Shah <amit.shah@redhat.com> | |
8 | * | |
9 | * Some earlier parts are: | |
10 | * Copyright IBM, Corp. 2008 | |
11 | * authored by | |
12 | * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com> | |
13 | * | |
14 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
15 | * the COPYING file in the top-level directory. | |
6b620ca3 PB |
16 | * |
17 | * Contributions after 2012-01-13 are licensed under the terms of the | |
18 | * GNU GPL, version 2 or (at your option) any later version. | |
98b19252 AS |
19 | */ |
20 | ||
e4d5639d | 21 | #include "iov.h" |
98b19252 AS |
22 | #include "monitor.h" |
23 | #include "qemu-queue.h" | |
24 | #include "sysbus.h" | |
49e3fdd7 | 25 | #include "trace.h" |
98b19252 AS |
26 | #include "virtio-serial.h" |
27 | ||
28 | /* The virtio-serial bus on top of which the ports will ride as devices */ | |
29 | struct VirtIOSerialBus { | |
30 | BusState qbus; | |
31 | ||
32 | /* This is the parent device that provides the bus for ports. */ | |
33 | VirtIOSerial *vser; | |
34 | ||
35 | /* The maximum number of ports that can ride on top of this bus */ | |
36 | uint32_t max_nr_ports; | |
37 | }; | |
38 | ||
39 | struct VirtIOSerial { | |
40 | VirtIODevice vdev; | |
41 | ||
42 | VirtQueue *c_ivq, *c_ovq; | |
43 | /* Arrays of ivqs and ovqs: one per port */ | |
44 | VirtQueue **ivqs, **ovqs; | |
45 | ||
5e52e5f9 | 46 | VirtIOSerialBus bus; |
98b19252 | 47 | |
8b53a865 AS |
48 | DeviceState *qdev; |
49 | ||
98b19252 | 50 | QTAILQ_HEAD(, VirtIOSerialPort) ports; |
055b889f AS |
51 | |
52 | /* bitmap for identifying active ports */ | |
53 | uint32_t *ports_map; | |
54 | ||
98b19252 | 55 | struct virtio_console_config config; |
80dcfb85 AL |
56 | |
57 | struct { | |
58 | QEMUTimer *timer; | |
c3587ca1 | 59 | uint32_t nr_active_ports; |
80dcfb85 AL |
60 | struct { |
61 | VirtIOSerialPort *port; | |
62 | uint8_t host_connected; | |
63 | } *connected; | |
64 | } post_load; | |
98b19252 AS |
65 | }; |
66 | ||
67 | static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id) | |
68 | { | |
69 | VirtIOSerialPort *port; | |
70 | ||
055b889f AS |
71 | if (id == VIRTIO_CONSOLE_BAD_ID) { |
72 | return NULL; | |
73 | } | |
74 | ||
98b19252 AS |
75 | QTAILQ_FOREACH(port, &vser->ports, next) { |
76 | if (port->id == id) | |
77 | return port; | |
78 | } | |
79 | return NULL; | |
80 | } | |
81 | ||
82 | static VirtIOSerialPort *find_port_by_vq(VirtIOSerial *vser, VirtQueue *vq) | |
83 | { | |
84 | VirtIOSerialPort *port; | |
85 | ||
86 | QTAILQ_FOREACH(port, &vser->ports, next) { | |
87 | if (port->ivq == vq || port->ovq == vq) | |
88 | return port; | |
89 | } | |
90 | return NULL; | |
91 | } | |
92 | ||
6663a195 AS |
93 | static bool use_multiport(VirtIOSerial *vser) |
94 | { | |
95 | return vser->vdev.guest_features & (1 << VIRTIO_CONSOLE_F_MULTIPORT); | |
96 | } | |
97 | ||
98b19252 AS |
98 | static size_t write_to_port(VirtIOSerialPort *port, |
99 | const uint8_t *buf, size_t size) | |
100 | { | |
101 | VirtQueueElement elem; | |
102 | VirtQueue *vq; | |
e4d5639d | 103 | size_t offset; |
98b19252 AS |
104 | |
105 | vq = port->ivq; | |
106 | if (!virtio_queue_ready(vq)) { | |
107 | return 0; | |
108 | } | |
98b19252 | 109 | |
e4d5639d | 110 | offset = 0; |
98b19252 | 111 | while (offset < size) { |
e4d5639d | 112 | size_t len; |
98b19252 AS |
113 | |
114 | if (!virtqueue_pop(vq, &elem)) { | |
115 | break; | |
116 | } | |
117 | ||
dcf6f5e1 MT |
118 | len = iov_from_buf(elem.in_sg, elem.in_num, 0, |
119 | buf + offset, size - offset); | |
e4d5639d | 120 | offset += len; |
98b19252 | 121 | |
98b19252 AS |
122 | virtqueue_push(vq, &elem, len); |
123 | } | |
124 | ||
125 | virtio_notify(&port->vser->vdev, vq); | |
126 | return offset; | |
127 | } | |
128 | ||
6bff8656 | 129 | static void discard_vq_data(VirtQueue *vq, VirtIODevice *vdev) |
a69c7600 AS |
130 | { |
131 | VirtQueueElement elem; | |
132 | ||
7185f931 AS |
133 | if (!virtio_queue_ready(vq)) { |
134 | return; | |
135 | } | |
6bff8656 AS |
136 | while (virtqueue_pop(vq, &elem)) { |
137 | virtqueue_push(vq, &elem, 0); | |
138 | } | |
139 | virtio_notify(vdev, vq); | |
140 | } | |
141 | ||
9ed7b059 | 142 | static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, |
6bff8656 | 143 | VirtIODevice *vdev) |
a69c7600 | 144 | { |
f82e35e3 | 145 | VirtIOSerialPortClass *vsc; |
a15bb0d6 | 146 | |
6bff8656 | 147 | assert(port); |
fd11a78b | 148 | assert(virtio_queue_ready(vq)); |
a69c7600 | 149 | |
f82e35e3 | 150 | vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); |
a15bb0d6 | 151 | |
f1925dff | 152 | while (!port->throttled) { |
471344db | 153 | unsigned int i; |
a69c7600 | 154 | |
f1925dff AS |
155 | /* Pop an elem only if we haven't left off a previous one mid-way */ |
156 | if (!port->elem.out_num) { | |
157 | if (!virtqueue_pop(vq, &port->elem)) { | |
158 | break; | |
159 | } | |
160 | port->iov_idx = 0; | |
161 | port->iov_offset = 0; | |
162 | } | |
a69c7600 | 163 | |
f1925dff AS |
164 | for (i = port->iov_idx; i < port->elem.out_num; i++) { |
165 | size_t buf_size; | |
166 | ssize_t ret; | |
167 | ||
168 | buf_size = port->elem.out_sg[i].iov_len - port->iov_offset; | |
f82e35e3 | 169 | ret = vsc->have_data(port, |
a15bb0d6 MA |
170 | port->elem.out_sg[i].iov_base |
171 | + port->iov_offset, | |
172 | buf_size); | |
f1925dff AS |
173 | if (ret < 0 && ret != -EAGAIN) { |
174 | /* We don't handle any other type of errors here */ | |
175 | abort(); | |
176 | } | |
177 | if (ret == -EAGAIN || (ret >= 0 && ret < buf_size)) { | |
ed8e5a85 CB |
178 | /* |
179 | * this is a temporary check until chardevs can signal to | |
180 | * frontends that they are writable again. This prevents | |
181 | * the console from going into throttled mode (forever) | |
182 | * if virtio-console is connected to a pty without a | |
183 | * listener. Otherwise the guest spins forever. | |
184 | * We can revert this if | |
185 | * 1: chardevs can notify frondends | |
186 | * 2: the guest driver does not spin in these cases | |
187 | */ | |
f82e35e3 | 188 | if (!vsc->is_console) { |
ed8e5a85 CB |
189 | virtio_serial_throttle_port(port, true); |
190 | } | |
f1925dff AS |
191 | port->iov_idx = i; |
192 | if (ret > 0) { | |
193 | port->iov_offset += ret; | |
194 | } | |
195 | break; | |
196 | } | |
197 | port->iov_offset = 0; | |
a69c7600 | 198 | } |
f1925dff AS |
199 | if (port->throttled) { |
200 | break; | |
201 | } | |
202 | virtqueue_push(vq, &port->elem, 0); | |
203 | port->elem.out_num = 0; | |
a69c7600 AS |
204 | } |
205 | virtio_notify(vdev, vq); | |
206 | } | |
207 | ||
6bff8656 | 208 | static void flush_queued_data(VirtIOSerialPort *port) |
9ed7b059 | 209 | { |
a1c59752 | 210 | assert(port); |
9ed7b059 | 211 | |
6b611d3a AS |
212 | if (!virtio_queue_ready(port->ovq)) { |
213 | return; | |
214 | } | |
6bff8656 | 215 | do_flush_queued_data(port, port->ovq, &port->vser->vdev); |
9ed7b059 AS |
216 | } |
217 | ||
98b19252 AS |
218 | static size_t send_control_msg(VirtIOSerialPort *port, void *buf, size_t len) |
219 | { | |
220 | VirtQueueElement elem; | |
221 | VirtQueue *vq; | |
222 | struct virtio_console_control *cpkt; | |
223 | ||
224 | vq = port->vser->c_ivq; | |
225 | if (!virtio_queue_ready(vq)) { | |
226 | return 0; | |
227 | } | |
228 | if (!virtqueue_pop(vq, &elem)) { | |
229 | return 0; | |
230 | } | |
231 | ||
232 | cpkt = (struct virtio_console_control *)buf; | |
233 | stl_p(&cpkt->id, port->id); | |
234 | memcpy(elem.in_sg[0].iov_base, buf, len); | |
235 | ||
236 | virtqueue_push(vq, &elem, len); | |
237 | virtio_notify(&port->vser->vdev, vq); | |
238 | return len; | |
239 | } | |
240 | ||
241 | static size_t send_control_event(VirtIOSerialPort *port, uint16_t event, | |
242 | uint16_t value) | |
243 | { | |
244 | struct virtio_console_control cpkt; | |
245 | ||
246 | stw_p(&cpkt.event, event); | |
247 | stw_p(&cpkt.value, value); | |
248 | ||
49e3fdd7 | 249 | trace_virtio_serial_send_control_event(port->id, event, value); |
98b19252 AS |
250 | return send_control_msg(port, &cpkt, sizeof(cpkt)); |
251 | } | |
252 | ||
253 | /* Functions for use inside qemu to open and read from/write to ports */ | |
254 | int virtio_serial_open(VirtIOSerialPort *port) | |
255 | { | |
6663a195 AS |
256 | /* Don't allow opening an already-open port */ |
257 | if (port->host_connected) { | |
258 | return 0; | |
259 | } | |
260 | /* Send port open notification to the guest */ | |
261 | port->host_connected = true; | |
262 | send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 1); | |
263 | ||
98b19252 AS |
264 | return 0; |
265 | } | |
266 | ||
267 | int virtio_serial_close(VirtIOSerialPort *port) | |
268 | { | |
6663a195 | 269 | port->host_connected = false; |
9ed7b059 AS |
270 | /* |
271 | * If there's any data the guest sent which the app didn't | |
272 | * consume, reset the throttling flag and discard the data. | |
273 | */ | |
274 | port->throttled = false; | |
6bff8656 | 275 | discard_vq_data(port->ovq, &port->vser->vdev); |
9ed7b059 | 276 | |
6663a195 AS |
277 | send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 0); |
278 | ||
98b19252 AS |
279 | return 0; |
280 | } | |
281 | ||
282 | /* Individual ports/apps call this function to write to the guest. */ | |
283 | ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf, | |
284 | size_t size) | |
285 | { | |
6663a195 AS |
286 | if (!port || !port->host_connected || !port->guest_connected) { |
287 | return 0; | |
288 | } | |
98b19252 AS |
289 | return write_to_port(port, buf, size); |
290 | } | |
291 | ||
292 | /* | |
293 | * Readiness of the guest to accept data on a port. | |
294 | * Returns max. data the guest can receive | |
295 | */ | |
296 | size_t virtio_serial_guest_ready(VirtIOSerialPort *port) | |
297 | { | |
298 | VirtQueue *vq = port->ivq; | |
ad3005ad | 299 | unsigned int bytes; |
98b19252 AS |
300 | |
301 | if (!virtio_queue_ready(vq) || | |
302 | !(port->vser->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK) || | |
303 | virtio_queue_empty(vq)) { | |
304 | return 0; | |
305 | } | |
6663a195 AS |
306 | if (use_multiport(port->vser) && !port->guest_connected) { |
307 | return 0; | |
308 | } | |
e1f7b481 | 309 | virtqueue_get_avail_bytes(vq, &bytes, NULL, 4096, 0); |
ad3005ad | 310 | return bytes; |
98b19252 AS |
311 | } |
312 | ||
199646d8 AL |
313 | static void flush_queued_data_bh(void *opaque) |
314 | { | |
315 | VirtIOSerialPort *port = opaque; | |
316 | ||
317 | flush_queued_data(port); | |
318 | } | |
319 | ||
9ed7b059 AS |
320 | void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle) |
321 | { | |
322 | if (!port) { | |
323 | return; | |
324 | } | |
325 | ||
49e3fdd7 | 326 | trace_virtio_serial_throttle_port(port->id, throttle); |
9ed7b059 AS |
327 | port->throttled = throttle; |
328 | if (throttle) { | |
329 | return; | |
330 | } | |
199646d8 | 331 | qemu_bh_schedule(port->bh); |
9ed7b059 AS |
332 | } |
333 | ||
98b19252 | 334 | /* Guest wants to notify us of some event */ |
e61da14d | 335 | static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len) |
98b19252 AS |
336 | { |
337 | struct VirtIOSerialPort *port; | |
f82e35e3 | 338 | VirtIOSerialPortClass *vsc; |
98b19252 | 339 | struct virtio_console_control cpkt, *gcpkt; |
160600fd AS |
340 | uint8_t *buffer; |
341 | size_t buffer_len; | |
98b19252 AS |
342 | |
343 | gcpkt = buf; | |
98b19252 | 344 | |
e61da14d AS |
345 | if (len < sizeof(cpkt)) { |
346 | /* The guest sent an invalid control packet */ | |
347 | return; | |
348 | } | |
349 | ||
98b19252 AS |
350 | cpkt.event = lduw_p(&gcpkt->event); |
351 | cpkt.value = lduw_p(&gcpkt->value); | |
352 | ||
49e3fdd7 AS |
353 | trace_virtio_serial_handle_control_message(cpkt.event, cpkt.value); |
354 | ||
d2e4d08b | 355 | if (cpkt.event == VIRTIO_CONSOLE_DEVICE_READY) { |
4048c7c3 | 356 | if (!cpkt.value) { |
6daf194d | 357 | error_report("virtio-serial-bus: Guest failure in adding device %s", |
5e52e5f9 | 358 | vser->bus.qbus.name); |
d2e4d08b | 359 | return; |
4048c7c3 | 360 | } |
055b889f AS |
361 | /* |
362 | * The device is up, we can now tell the device about all the | |
363 | * ports we have here. | |
364 | */ | |
365 | QTAILQ_FOREACH(port, &vser->ports, next) { | |
366 | send_control_event(port, VIRTIO_CONSOLE_PORT_ADD, 1); | |
367 | } | |
d2e4d08b LC |
368 | return; |
369 | } | |
055b889f | 370 | |
d2e4d08b LC |
371 | port = find_port_by_id(vser, ldl_p(&gcpkt->id)); |
372 | if (!port) { | |
95c9cde2 | 373 | error_report("virtio-serial-bus: Unexpected port id %u for device %s", |
d2e4d08b LC |
374 | ldl_p(&gcpkt->id), vser->bus.qbus.name); |
375 | return; | |
376 | } | |
377 | ||
49e3fdd7 AS |
378 | trace_virtio_serial_handle_control_message_port(port->id); |
379 | ||
f82e35e3 | 380 | vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); |
d2e4d08b LC |
381 | |
382 | switch(cpkt.event) { | |
98b19252 | 383 | case VIRTIO_CONSOLE_PORT_READY: |
4048c7c3 | 384 | if (!cpkt.value) { |
6daf194d | 385 | error_report("virtio-serial-bus: Guest failure in adding port %u for device %s", |
5e52e5f9 | 386 | port->id, vser->bus.qbus.name); |
4048c7c3 AS |
387 | break; |
388 | } | |
98b19252 AS |
389 | /* |
390 | * Now that we know the guest asked for the port name, we're | |
391 | * sure the guest has initialised whatever state is necessary | |
392 | * for this port. Now's a good time to let the guest know if | |
393 | * this port is a console port so that the guest can hook it | |
394 | * up to hvc. | |
395 | */ | |
f82e35e3 | 396 | if (vsc->is_console) { |
98b19252 AS |
397 | send_control_event(port, VIRTIO_CONSOLE_CONSOLE_PORT, 1); |
398 | } | |
6663a195 | 399 | |
160600fd AS |
400 | if (port->name) { |
401 | stw_p(&cpkt.event, VIRTIO_CONSOLE_PORT_NAME); | |
402 | stw_p(&cpkt.value, 1); | |
403 | ||
404 | buffer_len = sizeof(cpkt) + strlen(port->name) + 1; | |
7267c094 | 405 | buffer = g_malloc(buffer_len); |
160600fd AS |
406 | |
407 | memcpy(buffer, &cpkt, sizeof(cpkt)); | |
408 | memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name)); | |
409 | buffer[buffer_len - 1] = 0; | |
410 | ||
411 | send_control_msg(port, buffer, buffer_len); | |
7267c094 | 412 | g_free(buffer); |
160600fd AS |
413 | } |
414 | ||
6663a195 AS |
415 | if (port->host_connected) { |
416 | send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 1); | |
417 | } | |
418 | ||
98b19252 AS |
419 | /* |
420 | * When the guest has asked us for this information it means | |
421 | * the guest is all setup and has its virtqueues | |
422 | * initialised. If some app is interested in knowing about | |
423 | * this event, let it know. | |
424 | */ | |
f82e35e3 AL |
425 | if (vsc->guest_ready) { |
426 | vsc->guest_ready(port); | |
98b19252 AS |
427 | } |
428 | break; | |
6663a195 AS |
429 | |
430 | case VIRTIO_CONSOLE_PORT_OPEN: | |
431 | port->guest_connected = cpkt.value; | |
f82e35e3 | 432 | if (cpkt.value && vsc->guest_open) { |
6663a195 | 433 | /* Send the guest opened notification if an app is interested */ |
f82e35e3 | 434 | vsc->guest_open(port); |
6663a195 AS |
435 | } |
436 | ||
f82e35e3 | 437 | if (!cpkt.value && vsc->guest_close) { |
6663a195 | 438 | /* Send the guest closed notification if an app is interested */ |
f82e35e3 | 439 | vsc->guest_close(port); |
6663a195 AS |
440 | } |
441 | break; | |
98b19252 AS |
442 | } |
443 | } | |
444 | ||
445 | static void control_in(VirtIODevice *vdev, VirtQueue *vq) | |
446 | { | |
447 | } | |
448 | ||
449 | static void control_out(VirtIODevice *vdev, VirtQueue *vq) | |
450 | { | |
451 | VirtQueueElement elem; | |
452 | VirtIOSerial *vser; | |
e61da14d AS |
453 | uint8_t *buf; |
454 | size_t len; | |
98b19252 AS |
455 | |
456 | vser = DO_UPCAST(VirtIOSerial, vdev, vdev); | |
457 | ||
e61da14d AS |
458 | len = 0; |
459 | buf = NULL; | |
98b19252 | 460 | while (virtqueue_pop(vq, &elem)) { |
45270ad8 | 461 | size_t cur_len; |
e61da14d AS |
462 | |
463 | cur_len = iov_size(elem.out_sg, elem.out_num); | |
464 | /* | |
465 | * Allocate a new buf only if we didn't have one previously or | |
466 | * if the size of the buf differs | |
467 | */ | |
468 | if (cur_len > len) { | |
7267c094 | 469 | g_free(buf); |
e61da14d | 470 | |
7267c094 | 471 | buf = g_malloc(cur_len); |
e61da14d AS |
472 | len = cur_len; |
473 | } | |
dcf6f5e1 | 474 | iov_to_buf(elem.out_sg, elem.out_num, 0, buf, cur_len); |
e61da14d | 475 | |
45270ad8 | 476 | handle_control_message(vser, buf, cur_len); |
1e4476aa | 477 | virtqueue_push(vq, &elem, 0); |
98b19252 | 478 | } |
7267c094 | 479 | g_free(buf); |
98b19252 AS |
480 | virtio_notify(vdev, vq); |
481 | } | |
482 | ||
483 | /* Guest wrote something to some port. */ | |
484 | static void handle_output(VirtIODevice *vdev, VirtQueue *vq) | |
485 | { | |
486 | VirtIOSerial *vser; | |
a69c7600 | 487 | VirtIOSerialPort *port; |
98b19252 AS |
488 | |
489 | vser = DO_UPCAST(VirtIOSerial, vdev, vdev); | |
a69c7600 | 490 | port = find_port_by_vq(vser, vq); |
98b19252 | 491 | |
03ecd2c8 | 492 | if (!port || !port->host_connected) { |
6bff8656 AS |
493 | discard_vq_data(vq, vdev); |
494 | return; | |
495 | } | |
e9b382b0 AS |
496 | |
497 | if (!port->throttled) { | |
498 | do_flush_queued_data(port, vq, vdev); | |
9ed7b059 AS |
499 | return; |
500 | } | |
98b19252 AS |
501 | } |
502 | ||
503 | static void handle_input(VirtIODevice *vdev, VirtQueue *vq) | |
504 | { | |
505 | } | |
506 | ||
507 | static uint32_t get_features(VirtIODevice *vdev, uint32_t features) | |
508 | { | |
306eb457 AS |
509 | VirtIOSerial *vser; |
510 | ||
511 | vser = DO_UPCAST(VirtIOSerial, vdev, vdev); | |
512 | ||
5e52e5f9 | 513 | if (vser->bus.max_nr_ports > 1) { |
ee4d45be MT |
514 | features |= (1 << VIRTIO_CONSOLE_F_MULTIPORT); |
515 | } | |
98b19252 AS |
516 | return features; |
517 | } | |
518 | ||
519 | /* Guest requested config info */ | |
520 | static void get_config(VirtIODevice *vdev, uint8_t *config_data) | |
521 | { | |
522 | VirtIOSerial *vser; | |
523 | ||
524 | vser = DO_UPCAST(VirtIOSerial, vdev, vdev); | |
525 | memcpy(config_data, &vser->config, sizeof(struct virtio_console_config)); | |
526 | } | |
527 | ||
528 | static void set_config(VirtIODevice *vdev, const uint8_t *config_data) | |
529 | { | |
530 | struct virtio_console_config config; | |
531 | ||
532 | memcpy(&config, config_data, sizeof(config)); | |
533 | } | |
534 | ||
43997225 AS |
535 | static void guest_reset(VirtIOSerial *vser) |
536 | { | |
537 | VirtIOSerialPort *port; | |
538 | VirtIOSerialPortClass *vsc; | |
539 | ||
540 | QTAILQ_FOREACH(port, &vser->ports, next) { | |
541 | vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); | |
542 | if (port->guest_connected) { | |
543 | port->guest_connected = false; | |
544 | ||
545 | if (vsc->guest_close) | |
546 | vsc->guest_close(port); | |
547 | } | |
548 | } | |
549 | } | |
550 | ||
62a9fbf7 AL |
551 | static void set_status(VirtIODevice *vdev, uint8_t status) |
552 | { | |
553 | VirtIOSerial *vser; | |
554 | VirtIOSerialPort *port; | |
555 | ||
556 | vser = DO_UPCAST(VirtIOSerial, vdev, vdev); | |
557 | port = find_port_by_id(vser, 0); | |
558 | ||
559 | if (port && !use_multiport(port->vser) | |
560 | && (status & VIRTIO_CONFIG_S_DRIVER_OK)) { | |
561 | /* | |
562 | * Non-multiport guests won't be able to tell us guest | |
563 | * open/close status. Such guests can only have a port at id | |
564 | * 0, so set guest_connected for such ports as soon as guest | |
565 | * is up. | |
566 | */ | |
567 | port->guest_connected = true; | |
568 | } | |
43997225 AS |
569 | if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) { |
570 | guest_reset(vser); | |
571 | } | |
572 | } | |
573 | ||
574 | static void vser_reset(VirtIODevice *vdev) | |
575 | { | |
576 | VirtIOSerial *vser; | |
577 | ||
578 | vser = DO_UPCAST(VirtIOSerial, vdev, vdev); | |
579 | guest_reset(vser); | |
62a9fbf7 AL |
580 | } |
581 | ||
98b19252 AS |
582 | static void virtio_serial_save(QEMUFile *f, void *opaque) |
583 | { | |
584 | VirtIOSerial *s = opaque; | |
6663a195 AS |
585 | VirtIOSerialPort *port; |
586 | uint32_t nr_active_ports; | |
5c1c9bb2 | 587 | unsigned int i, max_nr_ports; |
98b19252 AS |
588 | |
589 | /* The virtio device */ | |
590 | virtio_save(&s->vdev, f); | |
591 | ||
592 | /* The config space */ | |
593 | qemu_put_be16s(f, &s->config.cols); | |
594 | qemu_put_be16s(f, &s->config.rows); | |
6663a195 | 595 | |
055b889f AS |
596 | qemu_put_be32s(f, &s->config.max_nr_ports); |
597 | ||
598 | /* The ports map */ | |
5c1c9bb2 AK |
599 | max_nr_ports = tswap32(s->config.max_nr_ports); |
600 | for (i = 0; i < (max_nr_ports + 31) / 32; i++) { | |
055b889f AS |
601 | qemu_put_be32s(f, &s->ports_map[i]); |
602 | } | |
6663a195 | 603 | |
055b889f | 604 | /* Ports */ |
e245795b | 605 | |
6663a195 | 606 | nr_active_ports = 0; |
e245795b | 607 | QTAILQ_FOREACH(port, &s->ports, next) { |
6663a195 | 608 | nr_active_ports++; |
e245795b | 609 | } |
6663a195 AS |
610 | |
611 | qemu_put_be32s(f, &nr_active_ports); | |
612 | ||
613 | /* | |
614 | * Items in struct VirtIOSerialPort. | |
615 | */ | |
616 | QTAILQ_FOREACH(port, &s->ports, next) { | |
37f95bf3 AS |
617 | uint32_t elem_popped; |
618 | ||
6663a195 AS |
619 | qemu_put_be32s(f, &port->id); |
620 | qemu_put_byte(f, port->guest_connected); | |
31abe21f | 621 | qemu_put_byte(f, port->host_connected); |
37f95bf3 AS |
622 | |
623 | elem_popped = 0; | |
624 | if (port->elem.out_num) { | |
625 | elem_popped = 1; | |
626 | } | |
627 | qemu_put_be32s(f, &elem_popped); | |
628 | if (elem_popped) { | |
629 | qemu_put_be32s(f, &port->iov_idx); | |
630 | qemu_put_be64s(f, &port->iov_offset); | |
631 | ||
632 | qemu_put_buffer(f, (unsigned char *)&port->elem, | |
633 | sizeof(port->elem)); | |
634 | } | |
6663a195 | 635 | } |
98b19252 AS |
636 | } |
637 | ||
80dcfb85 AL |
638 | static void virtio_serial_post_load_timer_cb(void *opaque) |
639 | { | |
c3587ca1 | 640 | uint32_t i; |
80dcfb85 AL |
641 | VirtIOSerial *s = opaque; |
642 | VirtIOSerialPort *port; | |
643 | uint8_t host_connected; | |
644 | ||
645 | for (i = 0 ; i < s->post_load.nr_active_ports; ++i) { | |
646 | port = s->post_load.connected[i].port; | |
647 | host_connected = s->post_load.connected[i].host_connected; | |
648 | if (host_connected != port->host_connected) { | |
649 | /* | |
650 | * We have to let the guest know of the host connection | |
651 | * status change | |
652 | */ | |
653 | send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, | |
654 | port->host_connected); | |
655 | } | |
656 | } | |
657 | g_free(s->post_load.connected); | |
658 | s->post_load.connected = NULL; | |
659 | } | |
660 | ||
2e575a86 AS |
661 | static int fetch_active_ports_list(QEMUFile *f, int version_id, |
662 | VirtIOSerial *s, uint32_t nr_active_ports) | |
663 | { | |
664 | uint32_t i; | |
665 | ||
666 | s->post_load.nr_active_ports = nr_active_ports; | |
667 | s->post_load.connected = | |
668 | g_malloc0(sizeof(*s->post_load.connected) * nr_active_ports); | |
669 | ||
670 | /* Items in struct VirtIOSerialPort */ | |
671 | for (i = 0; i < nr_active_ports; i++) { | |
672 | VirtIOSerialPort *port; | |
673 | uint32_t id; | |
674 | ||
675 | id = qemu_get_be32(f); | |
676 | port = find_port_by_id(s, id); | |
677 | if (!port) { | |
678 | return -EINVAL; | |
679 | } | |
680 | ||
681 | port->guest_connected = qemu_get_byte(f); | |
682 | s->post_load.connected[i].port = port; | |
683 | s->post_load.connected[i].host_connected = qemu_get_byte(f); | |
684 | ||
685 | if (version_id > 2) { | |
686 | uint32_t elem_popped; | |
687 | ||
688 | qemu_get_be32s(f, &elem_popped); | |
689 | if (elem_popped) { | |
690 | qemu_get_be32s(f, &port->iov_idx); | |
691 | qemu_get_be64s(f, &port->iov_offset); | |
692 | ||
693 | qemu_get_buffer(f, (unsigned char *)&port->elem, | |
694 | sizeof(port->elem)); | |
695 | virtqueue_map_sg(port->elem.in_sg, port->elem.in_addr, | |
696 | port->elem.in_num, 1); | |
697 | virtqueue_map_sg(port->elem.out_sg, port->elem.out_addr, | |
698 | port->elem.out_num, 1); | |
699 | ||
700 | /* | |
701 | * Port was throttled on source machine. Let's | |
702 | * unthrottle it here so data starts flowing again. | |
703 | */ | |
704 | virtio_serial_throttle_port(port, false); | |
705 | } | |
706 | } | |
707 | } | |
708 | qemu_mod_timer(s->post_load.timer, 1); | |
709 | return 0; | |
710 | } | |
711 | ||
98b19252 AS |
712 | static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id) |
713 | { | |
714 | VirtIOSerial *s = opaque; | |
f83ccb3e | 715 | uint32_t max_nr_ports, nr_active_ports, ports_map; |
6663a195 | 716 | unsigned int i; |
2a633c46 | 717 | int ret; |
98b19252 | 718 | |
37f95bf3 | 719 | if (version_id > 3) { |
98b19252 AS |
720 | return -EINVAL; |
721 | } | |
6663a195 | 722 | |
98b19252 | 723 | /* The virtio device */ |
2a633c46 OW |
724 | ret = virtio_load(&s->vdev, f); |
725 | if (ret) { | |
726 | return ret; | |
727 | } | |
98b19252 AS |
728 | |
729 | if (version_id < 2) { | |
730 | return 0; | |
731 | } | |
732 | ||
733 | /* The config space */ | |
734 | qemu_get_be16s(f, &s->config.cols); | |
735 | qemu_get_be16s(f, &s->config.rows); | |
295587f7 | 736 | |
055b889f | 737 | qemu_get_be32s(f, &max_nr_ports); |
5c1c9bb2 AK |
738 | tswap32s(&max_nr_ports); |
739 | if (max_nr_ports > tswap32(s->config.max_nr_ports)) { | |
055b889f | 740 | /* Source could have had more ports than us. Fail migration. */ |
295587f7 AS |
741 | return -EINVAL; |
742 | } | |
98b19252 | 743 | |
055b889f | 744 | for (i = 0; i < (max_nr_ports + 31) / 32; i++) { |
f83ccb3e | 745 | qemu_get_be32s(f, &ports_map); |
055b889f | 746 | |
f83ccb3e | 747 | if (ports_map != s->ports_map[i]) { |
055b889f AS |
748 | /* |
749 | * Ports active on source and destination don't | |
750 | * match. Fail migration. | |
751 | */ | |
055b889f AS |
752 | return -EINVAL; |
753 | } | |
e245795b AS |
754 | } |
755 | ||
6663a195 AS |
756 | qemu_get_be32s(f, &nr_active_ports); |
757 | ||
2e575a86 AS |
758 | if (nr_active_ports) { |
759 | ret = fetch_active_ports_list(f, version_id, s, nr_active_ports); | |
760 | if (ret) { | |
761 | return ret; | |
37f95bf3 | 762 | } |
6663a195 | 763 | } |
98b19252 AS |
764 | return 0; |
765 | } | |
766 | ||
767 | static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); | |
768 | ||
3cb75a7c PB |
769 | static Property virtser_props[] = { |
770 | DEFINE_PROP_UINT32("nr", VirtIOSerialPort, id, VIRTIO_CONSOLE_BAD_ID), | |
771 | DEFINE_PROP_STRING("name", VirtIOSerialPort, name), | |
772 | DEFINE_PROP_END_OF_LIST() | |
773 | }; | |
774 | ||
0d936928 AL |
775 | #define TYPE_VIRTIO_SERIAL_BUS "virtio-serial-bus" |
776 | #define VIRTIO_SERIAL_BUS(obj) \ | |
777 | OBJECT_CHECK(VirtIOSerialBus, (obj), TYPE_VIRTIO_SERIAL_BUS) | |
778 | ||
779 | static void virtser_bus_class_init(ObjectClass *klass, void *data) | |
780 | { | |
781 | BusClass *k = BUS_CLASS(klass); | |
782 | k->print_dev = virtser_bus_dev_print; | |
783 | } | |
784 | ||
785 | static const TypeInfo virtser_bus_info = { | |
786 | .name = TYPE_VIRTIO_SERIAL_BUS, | |
787 | .parent = TYPE_BUS, | |
788 | .instance_size = sizeof(VirtIOSerialBus), | |
789 | .class_init = virtser_bus_class_init, | |
98b19252 AS |
790 | }; |
791 | ||
98b19252 AS |
792 | static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent) |
793 | { | |
a43f9c90 | 794 | VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev); |
98b19252 | 795 | |
021a1318 MA |
796 | monitor_printf(mon, "%*sport %d, guest %s, host %s, throttle %s\n", |
797 | indent, "", port->id, | |
798 | port->guest_connected ? "on" : "off", | |
799 | port->host_connected ? "on" : "off", | |
800 | port->throttled ? "on" : "off"); | |
98b19252 AS |
801 | } |
802 | ||
055b889f AS |
803 | /* This function is only used if a port id is not provided by the user */ |
804 | static uint32_t find_free_port_id(VirtIOSerial *vser) | |
805 | { | |
5c1c9bb2 | 806 | unsigned int i, max_nr_ports; |
055b889f | 807 | |
5c1c9bb2 AK |
808 | max_nr_ports = tswap32(vser->config.max_nr_ports); |
809 | for (i = 0; i < (max_nr_ports + 31) / 32; i++) { | |
055b889f AS |
810 | uint32_t map, bit; |
811 | ||
812 | map = vser->ports_map[i]; | |
813 | bit = ffs(~map); | |
814 | if (bit) { | |
815 | return (bit - 1) + i * 32; | |
816 | } | |
817 | } | |
818 | return VIRTIO_CONSOLE_BAD_ID; | |
819 | } | |
820 | ||
821 | static void mark_port_added(VirtIOSerial *vser, uint32_t port_id) | |
822 | { | |
823 | unsigned int i; | |
824 | ||
825 | i = port_id / 32; | |
826 | vser->ports_map[i] |= 1U << (port_id % 32); | |
827 | } | |
828 | ||
829 | static void add_port(VirtIOSerial *vser, uint32_t port_id) | |
830 | { | |
831 | mark_port_added(vser, port_id); | |
832 | ||
833 | send_control_event(find_port_by_id(vser, port_id), | |
834 | VIRTIO_CONSOLE_PORT_ADD, 1); | |
835 | } | |
836 | ||
837 | static void remove_port(VirtIOSerial *vser, uint32_t port_id) | |
838 | { | |
9ed7b059 | 839 | VirtIOSerialPort *port; |
055b889f AS |
840 | unsigned int i; |
841 | ||
842 | i = port_id / 32; | |
843 | vser->ports_map[i] &= ~(1U << (port_id % 32)); | |
844 | ||
9ed7b059 AS |
845 | port = find_port_by_id(vser, port_id); |
846 | /* Flush out any unconsumed buffers first */ | |
6bff8656 | 847 | discard_vq_data(port->ovq, &port->vser->vdev); |
9ed7b059 AS |
848 | |
849 | send_control_event(port, VIRTIO_CONSOLE_PORT_REMOVE, 1); | |
055b889f AS |
850 | } |
851 | ||
d307af79 | 852 | static int virtser_port_qdev_init(DeviceState *qdev) |
98b19252 | 853 | { |
a43f9c90 | 854 | VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev); |
f82e35e3 | 855 | VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); |
98b19252 | 856 | VirtIOSerialBus *bus = DO_UPCAST(VirtIOSerialBus, qbus, qdev->parent_bus); |
5c1c9bb2 | 857 | int ret, max_nr_ports; |
98b19252 AS |
858 | bool plugging_port0; |
859 | ||
860 | port->vser = bus->vser; | |
199646d8 | 861 | port->bh = qemu_bh_new(flush_queued_data_bh, port); |
98b19252 | 862 | |
f82e35e3 | 863 | assert(vsc->have_data); |
03ecd2c8 | 864 | |
98b19252 AS |
865 | /* |
866 | * Is the first console port we're seeing? If so, put it up at | |
867 | * location 0. This is done for backward compatibility (old | |
868 | * kernel, new qemu). | |
869 | */ | |
f82e35e3 | 870 | plugging_port0 = vsc->is_console && !find_port_by_id(port->vser, 0); |
98b19252 | 871 | |
055b889f | 872 | if (find_port_by_id(port->vser, port->id)) { |
6daf194d | 873 | error_report("virtio-serial-bus: A port already exists at id %u", |
055b889f | 874 | port->id); |
98b19252 AS |
875 | return -1; |
876 | } | |
98b19252 | 877 | |
055b889f AS |
878 | if (port->id == VIRTIO_CONSOLE_BAD_ID) { |
879 | if (plugging_port0) { | |
880 | port->id = 0; | |
881 | } else { | |
882 | port->id = find_free_port_id(port->vser); | |
883 | if (port->id == VIRTIO_CONSOLE_BAD_ID) { | |
6daf194d | 884 | error_report("virtio-serial-bus: Maximum port limit for this device reached"); |
055b889f AS |
885 | return -1; |
886 | } | |
887 | } | |
888 | } | |
889 | ||
5c1c9bb2 AK |
890 | max_nr_ports = tswap32(port->vser->config.max_nr_ports); |
891 | if (port->id >= max_nr_ports) { | |
6daf194d | 892 | error_report("virtio-serial-bus: Out-of-range port id specified, max. allowed: %u", |
5c1c9bb2 | 893 | max_nr_ports - 1); |
055b889f AS |
894 | return -1; |
895 | } | |
896 | ||
f82e35e3 | 897 | ret = vsc->init(port); |
98b19252 AS |
898 | if (ret) { |
899 | return ret; | |
900 | } | |
901 | ||
f1925dff AS |
902 | port->elem.out_num = 0; |
903 | ||
98b19252 AS |
904 | QTAILQ_INSERT_TAIL(&port->vser->ports, port, next); |
905 | port->ivq = port->vser->ivqs[port->id]; | |
906 | port->ovq = port->vser->ovqs[port->id]; | |
907 | ||
055b889f AS |
908 | add_port(port->vser, port->id); |
909 | ||
98b19252 AS |
910 | /* Send an update to the guest about this new port added */ |
911 | virtio_notify_config(&port->vser->vdev); | |
912 | ||
913 | return ret; | |
914 | } | |
915 | ||
916 | static int virtser_port_qdev_exit(DeviceState *qdev) | |
917 | { | |
a43f9c90 | 918 | VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev); |
f82e35e3 | 919 | VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); |
98b19252 AS |
920 | VirtIOSerial *vser = port->vser; |
921 | ||
199646d8 | 922 | qemu_bh_delete(port->bh); |
055b889f | 923 | remove_port(port->vser, port->id); |
f146ec9a | 924 | |
98b19252 AS |
925 | QTAILQ_REMOVE(&vser->ports, port, next); |
926 | ||
f82e35e3 AL |
927 | if (vsc->exit) { |
928 | vsc->exit(port); | |
a15bb0d6 | 929 | } |
98b19252 AS |
930 | return 0; |
931 | } | |
932 | ||
6b331efb | 933 | VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf) |
98b19252 AS |
934 | { |
935 | VirtIOSerial *vser; | |
936 | VirtIODevice *vdev; | |
5ab4bb59 | 937 | uint32_t i, max_supported_ports; |
98b19252 | 938 | |
6b331efb | 939 | if (!conf->max_virtserial_ports) |
98b19252 AS |
940 | return NULL; |
941 | ||
5ab4bb59 AS |
942 | /* Each port takes 2 queues, and one pair is for the control queue */ |
943 | max_supported_ports = VIRTIO_PCI_QUEUE_MAX / 2 - 1; | |
944 | ||
6b331efb | 945 | if (conf->max_virtserial_ports > max_supported_ports) { |
5ab4bb59 AS |
946 | error_report("maximum ports supported: %u", max_supported_ports); |
947 | return NULL; | |
948 | } | |
949 | ||
98b19252 AS |
950 | vdev = virtio_common_init("virtio-serial", VIRTIO_ID_CONSOLE, |
951 | sizeof(struct virtio_console_config), | |
952 | sizeof(VirtIOSerial)); | |
953 | ||
954 | vser = DO_UPCAST(VirtIOSerial, vdev, vdev); | |
955 | ||
956 | /* Spawn a new virtio-serial bus on which the ports will ride as devices */ | |
0d936928 | 957 | qbus_create_inplace(&vser->bus.qbus, TYPE_VIRTIO_SERIAL_BUS, dev, NULL); |
5e52e5f9 MA |
958 | vser->bus.qbus.allow_hotplug = 1; |
959 | vser->bus.vser = vser; | |
98b19252 AS |
960 | QTAILQ_INIT(&vser->ports); |
961 | ||
5e52e5f9 | 962 | vser->bus.max_nr_ports = conf->max_virtserial_ports; |
7267c094 AL |
963 | vser->ivqs = g_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *)); |
964 | vser->ovqs = g_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *)); | |
98b19252 AS |
965 | |
966 | /* Add a queue for host to guest transfers for port 0 (backward compat) */ | |
967 | vser->ivqs[0] = virtio_add_queue(vdev, 128, handle_input); | |
968 | /* Add a queue for guest to host transfers for port 0 (backward compat) */ | |
969 | vser->ovqs[0] = virtio_add_queue(vdev, 128, handle_output); | |
970 | ||
a01a9cb8 AS |
971 | /* TODO: host to guest notifications can get dropped |
972 | * if the queue fills up. Implement queueing in host, | |
973 | * this might also make it possible to reduce the control | |
974 | * queue size: as guest preposts buffers there, | |
975 | * this will save 4Kbyte of guest memory per entry. */ | |
976 | ||
98b19252 | 977 | /* control queue: host to guest */ |
a01a9cb8 | 978 | vser->c_ivq = virtio_add_queue(vdev, 32, control_in); |
98b19252 | 979 | /* control queue: guest to host */ |
a01a9cb8 | 980 | vser->c_ovq = virtio_add_queue(vdev, 32, control_out); |
98b19252 | 981 | |
5e52e5f9 | 982 | for (i = 1; i < vser->bus.max_nr_ports; i++) { |
98b19252 AS |
983 | /* Add a per-port queue for host to guest transfers */ |
984 | vser->ivqs[i] = virtio_add_queue(vdev, 128, handle_input); | |
985 | /* Add a per-per queue for guest to host transfers */ | |
986 | vser->ovqs[i] = virtio_add_queue(vdev, 128, handle_output); | |
987 | } | |
988 | ||
5c1c9bb2 | 989 | vser->config.max_nr_ports = tswap32(conf->max_virtserial_ports); |
7267c094 | 990 | vser->ports_map = g_malloc0(((conf->max_virtserial_ports + 31) / 32) |
a132a679 | 991 | * sizeof(vser->ports_map[0])); |
98b19252 AS |
992 | /* |
993 | * Reserve location 0 for a console port for backward compat | |
994 | * (old kernel, new qemu) | |
995 | */ | |
055b889f | 996 | mark_port_added(vser, 0); |
98b19252 AS |
997 | |
998 | vser->vdev.get_features = get_features; | |
999 | vser->vdev.get_config = get_config; | |
1000 | vser->vdev.set_config = set_config; | |
62a9fbf7 | 1001 | vser->vdev.set_status = set_status; |
43997225 | 1002 | vser->vdev.reset = vser_reset; |
98b19252 | 1003 | |
8b53a865 AS |
1004 | vser->qdev = dev; |
1005 | ||
98b19252 AS |
1006 | /* |
1007 | * Register for the savevm section with the virtio-console name | |
1008 | * to preserve backward compat | |
1009 | */ | |
37f95bf3 | 1010 | register_savevm(dev, "virtio-console", -1, 3, virtio_serial_save, |
98b19252 AS |
1011 | virtio_serial_load, vser); |
1012 | ||
80dcfb85 AL |
1013 | vser->post_load.timer = qemu_new_timer_ns(vm_clock, |
1014 | virtio_serial_post_load_timer_cb, vser); | |
1015 | ||
98b19252 AS |
1016 | return vdev; |
1017 | } | |
8b53a865 AS |
1018 | |
1019 | void virtio_serial_exit(VirtIODevice *vdev) | |
1020 | { | |
1021 | VirtIOSerial *vser = DO_UPCAST(VirtIOSerial, vdev, vdev); | |
1022 | ||
1023 | unregister_savevm(vser->qdev, "virtio-console", vser); | |
1024 | ||
7267c094 AL |
1025 | g_free(vser->ivqs); |
1026 | g_free(vser->ovqs); | |
1027 | g_free(vser->ports_map); | |
80dcfb85 AL |
1028 | g_free(vser->post_load.connected); |
1029 | qemu_free_timer(vser->post_load.timer); | |
8b53a865 AS |
1030 | |
1031 | virtio_cleanup(vdev); | |
1032 | } | |
f82e35e3 | 1033 | |
39bffca2 AL |
1034 | static void virtio_serial_port_class_init(ObjectClass *klass, void *data) |
1035 | { | |
1036 | DeviceClass *k = DEVICE_CLASS(klass); | |
1037 | k->init = virtser_port_qdev_init; | |
0d936928 | 1038 | k->bus_type = TYPE_VIRTIO_SERIAL_BUS; |
39bffca2 AL |
1039 | k->exit = virtser_port_qdev_exit; |
1040 | k->unplug = qdev_simple_unplug_cb; | |
bce54474 | 1041 | k->props = virtser_props; |
39bffca2 AL |
1042 | } |
1043 | ||
f82e35e3 AL |
1044 | static TypeInfo virtio_serial_port_type_info = { |
1045 | .name = TYPE_VIRTIO_SERIAL_PORT, | |
1046 | .parent = TYPE_DEVICE, | |
1047 | .instance_size = sizeof(VirtIOSerialPort), | |
1048 | .abstract = true, | |
1049 | .class_size = sizeof(VirtIOSerialPortClass), | |
39bffca2 | 1050 | .class_init = virtio_serial_port_class_init, |
f82e35e3 AL |
1051 | }; |
1052 | ||
83f7d43a | 1053 | static void virtio_serial_register_types(void) |
f82e35e3 | 1054 | { |
0d936928 | 1055 | type_register_static(&virtser_bus_info); |
f82e35e3 AL |
1056 | type_register_static(&virtio_serial_port_type_info); |
1057 | } | |
1058 | ||
83f7d43a | 1059 | type_init(virtio_serial_register_types) |