softfloat: Rename float*_is_nan() functions to float*_is_quiet_nan()
[qemu/agraf.git] / hw / virtio-serial.h
blobff08c406819bfa62ea63ed81cd1d32e9fe18fec4
1 /*
2 * Virtio Serial / Console Support
4 * Copyright IBM, Corp. 2008
5 * Copyright Red Hat, Inc. 2009, 2010
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 "qdev.h"
19 #include "virtio.h"
21 /* == Interface shared between the guest kernel and qemu == */
23 /* The Virtio ID for virtio console / serial ports */
24 #define VIRTIO_ID_CONSOLE 3
26 /* Features supported */
27 #define VIRTIO_CONSOLE_F_MULTIPORT 1
29 #define VIRTIO_CONSOLE_BAD_ID (~(uint32_t)0)
31 struct virtio_console_config {
33 * These two fields are used by VIRTIO_CONSOLE_F_SIZE which
34 * isn't implemented here yet
36 uint16_t cols;
37 uint16_t rows;
39 uint32_t max_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_DEVICE_READY 0
50 #define VIRTIO_CONSOLE_PORT_ADD 1
51 #define VIRTIO_CONSOLE_PORT_REMOVE 2
52 #define VIRTIO_CONSOLE_PORT_READY 3
53 #define VIRTIO_CONSOLE_CONSOLE_PORT 4
54 #define VIRTIO_CONSOLE_RESIZE 5
55 #define VIRTIO_CONSOLE_PORT_OPEN 6
56 #define VIRTIO_CONSOLE_PORT_NAME 7
58 /* == In-qemu interface == */
60 typedef struct VirtIOSerial VirtIOSerial;
61 typedef struct VirtIOSerialBus VirtIOSerialBus;
62 typedef struct VirtIOSerialPort VirtIOSerialPort;
63 typedef struct VirtIOSerialPortInfo VirtIOSerialPortInfo;
65 typedef struct VirtIOSerialDevice {
66 DeviceState qdev;
67 VirtIOSerialPortInfo *info;
68 } VirtIOSerialDevice;
71 * This is the state that's shared between all the ports. Some of the
72 * state is configurable via command-line options. Some of it can be
73 * set by individual devices in their initfn routines. Some of the
74 * state is set by the generic qdev device init routine.
76 struct VirtIOSerialPort {
77 DeviceState dev;
78 VirtIOSerialPortInfo *info;
80 QTAILQ_ENTRY(VirtIOSerialPort) next;
83 * This field gives us the virtio device as well as the qdev bus
84 * that we are associated with
86 VirtIOSerial *vser;
88 VirtQueue *ivq, *ovq;
91 * This name is sent to the guest and exported via sysfs.
92 * The guest could create symlinks based on this information.
93 * The name is in the reverse fqdn format, like org.qemu.console.0
95 char *name;
98 * This id helps identify ports between the guest and the host.
99 * The guest sends a "header" with this id with each data packet
100 * that it sends and the host can then find out which associated
101 * device to send out this data to
103 uint32_t id;
105 /* Identify if this is a port that binds with hvc in the guest */
106 uint8_t is_console;
108 /* Is the corresponding guest device open? */
109 bool guest_connected;
110 /* Is this device open for IO on the host? */
111 bool host_connected;
112 /* Do apps not want to receive data? */
113 bool throttled;
116 struct VirtIOSerialPortInfo {
117 DeviceInfo qdev;
119 * The per-port (or per-app) init function that's called when a
120 * new device is found on the bus.
122 int (*init)(VirtIOSerialDevice *dev);
124 * Per-port exit function that's called when a port gets
125 * hot-unplugged or removed.
127 int (*exit)(VirtIOSerialDevice *dev);
129 /* Callbacks for guest events */
130 /* Guest opened device. */
131 void (*guest_open)(VirtIOSerialPort *port);
132 /* Guest closed device. */
133 void (*guest_close)(VirtIOSerialPort *port);
135 /* Guest is now ready to accept data (virtqueues set up). */
136 void (*guest_ready)(VirtIOSerialPort *port);
139 * Guest wrote some data to the port. This data is handed over to
140 * the app via this callback. The app is supposed to consume all
141 * the data that is presented to it.
143 void (*have_data)(VirtIOSerialPort *port, const uint8_t *buf, size_t len);
146 /* Interface to the virtio-serial bus */
149 * Individual ports/apps should call this function to register the port
150 * with the virtio-serial bus
152 void virtio_serial_port_qdev_register(VirtIOSerialPortInfo *info);
155 * Open a connection to the port
156 * Returns 0 on success (always).
158 int virtio_serial_open(VirtIOSerialPort *port);
161 * Close the connection to the port
162 * Returns 0 on success (always).
164 int virtio_serial_close(VirtIOSerialPort *port);
167 * Send data to Guest
169 ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,
170 size_t size);
173 * Query whether a guest is ready to receive data.
175 size_t virtio_serial_guest_ready(VirtIOSerialPort *port);
178 * Flow control: Ports can signal to the virtio-serial core to stop
179 * sending data or re-start sending data, depending on the 'throttle'
180 * value here.
182 void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle);
184 #endif