virtio-console: qdev conversion, new virtio-serial-bus
[qemu/cris-port.git] / hw / virtio-serial.h
blobfe8e357a75fb27c984ca2263460828f50416441c
1 /*
2 * Virtio Serial / Console Support
4 * Copyright IBM, Corp. 2008
5 * Copyright Red Hat, Inc. 2009
7 * Authors:
8 * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
9 * Amit Shah <amit.shah@redhat.com>
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
15 #ifndef _QEMU_VIRTIO_SERIAL_H
16 #define _QEMU_VIRTIO_SERIAL_H
18 #include <stdbool.h>
19 #include "qdev.h"
20 #include "virtio.h"
22 /* == Interface shared between the guest kernel and qemu == */
24 /* The Virtio ID for virtio console / serial ports */
25 #define VIRTIO_ID_CONSOLE 3
27 /* Features supported */
28 #define VIRTIO_CONSOLE_F_MULTIPORT 1
30 struct virtio_console_config {
32 * These two fields are used by VIRTIO_CONSOLE_F_SIZE which
33 * isn't implemented here yet
35 uint16_t cols;
36 uint16_t rows;
38 uint32_t max_nr_ports;
39 uint32_t nr_ports;
40 } __attribute__((packed));
42 struct virtio_console_control {
43 uint32_t id; /* Port number */
44 uint16_t event; /* The kind of control event (see below) */
45 uint16_t value; /* Extra information for the key */
48 /* Some events for the internal messages (control packets) */
49 #define VIRTIO_CONSOLE_PORT_READY 0
50 #define VIRTIO_CONSOLE_CONSOLE_PORT 1
51 #define VIRTIO_CONSOLE_RESIZE 2
53 /* == In-qemu interface == */
55 typedef struct VirtIOSerial VirtIOSerial;
56 typedef struct VirtIOSerialBus VirtIOSerialBus;
57 typedef struct VirtIOSerialPort VirtIOSerialPort;
58 typedef struct VirtIOSerialPortInfo VirtIOSerialPortInfo;
60 typedef struct VirtIOSerialDevice {
61 DeviceState qdev;
62 VirtIOSerialPortInfo *info;
63 } VirtIOSerialDevice;
66 * This is the state that's shared between all the ports. Some of the
67 * state is configurable via command-line options. Some of it can be
68 * set by individual devices in their initfn routines. Some of the
69 * state is set by the generic qdev device init routine.
71 struct VirtIOSerialPort {
72 DeviceState dev;
73 VirtIOSerialPortInfo *info;
75 QTAILQ_ENTRY(VirtIOSerialPort) next;
78 * This field gives us the virtio device as well as the qdev bus
79 * that we are associated with
81 VirtIOSerial *vser;
83 VirtQueue *ivq, *ovq;
86 * This id helps identify ports between the guest and the host.
87 * The guest sends a "header" with this id with each data packet
88 * that it sends and the host can then find out which associated
89 * device to send out this data to
91 uint32_t id;
93 /* Identify if this is a port that binds with hvc in the guest */
94 uint8_t is_console;
97 struct VirtIOSerialPortInfo {
98 DeviceInfo qdev;
100 * The per-port (or per-app) init function that's called when a
101 * new device is found on the bus.
103 int (*init)(VirtIOSerialDevice *dev);
105 * Per-port exit function that's called when a port gets
106 * hot-unplugged or removed.
108 int (*exit)(VirtIOSerialDevice *dev);
110 /* Callbacks for guest events */
111 /* Guest opened device. */
112 void (*guest_open)(VirtIOSerialPort *port);
113 /* Guest closed device. */
114 void (*guest_close)(VirtIOSerialPort *port);
116 /* Guest is now ready to accept data (virtqueues set up). */
117 void (*guest_ready)(VirtIOSerialPort *port);
120 * Guest wrote some data to the port. This data is handed over to
121 * the app via this callback. The app should return the number of
122 * bytes it successfully consumed.
124 size_t (*have_data)(VirtIOSerialPort *port, const uint8_t *buf, size_t len);
127 /* Interface to the virtio-serial bus */
130 * Individual ports/apps should call this function to register the port
131 * with the virtio-serial bus
133 void virtio_serial_port_qdev_register(VirtIOSerialPortInfo *info);
136 * Open a connection to the port
137 * Returns 0 on success (always).
139 int virtio_serial_open(VirtIOSerialPort *port);
142 * Close the connection to the port
143 * Returns 0 on success (always).
145 int virtio_serial_close(VirtIOSerialPort *port);
148 * Send data to Guest
150 ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,
151 size_t size);
154 * Query whether a guest is ready to receive data.
156 size_t virtio_serial_guest_ready(VirtIOSerialPort *port);
158 #endif