root / hw / virtio-serial.h @ a43f9c90
History | View | Annotate | Download (5.5 kB)
1 |
/*
|
---|---|
2 |
* Virtio Serial / Console Support
|
3 |
*
|
4 |
* Copyright IBM, Corp. 2008
|
5 |
* Copyright Red Hat, Inc. 2009, 2010
|
6 |
*
|
7 |
* Authors:
|
8 |
* Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
|
9 |
* Amit Shah <amit.shah@redhat.com>
|
10 |
*
|
11 |
* This work is licensed under the terms of the GNU GPL, version 2. See
|
12 |
* the COPYING file in the top-level directory.
|
13 |
*
|
14 |
*/
|
15 |
#ifndef _QEMU_VIRTIO_SERIAL_H
|
16 |
#define _QEMU_VIRTIO_SERIAL_H
|
17 |
|
18 |
#include "qdev.h" |
19 |
#include "virtio.h" |
20 |
|
21 |
/* == Interface shared between the guest kernel and qemu == */
|
22 |
|
23 |
/* The Virtio ID for virtio console / serial ports */
|
24 |
#define VIRTIO_ID_CONSOLE 3 |
25 |
|
26 |
/* Features supported */
|
27 |
#define VIRTIO_CONSOLE_F_MULTIPORT 1 |
28 |
|
29 |
#define VIRTIO_CONSOLE_BAD_ID (~(uint32_t)0) |
30 |
|
31 |
struct virtio_console_config {
|
32 |
/*
|
33 |
* These two fields are used by VIRTIO_CONSOLE_F_SIZE which
|
34 |
* isn't implemented here yet
|
35 |
*/
|
36 |
uint16_t cols; |
37 |
uint16_t rows; |
38 |
|
39 |
uint32_t max_nr_ports; |
40 |
} __attribute__((packed)); |
41 |
|
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 */
|
46 |
}; |
47 |
|
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 |
57 |
|
58 |
/* == In-qemu interface == */
|
59 |
|
60 |
typedef struct VirtIOSerial VirtIOSerial; |
61 |
typedef struct VirtIOSerialBus VirtIOSerialBus; |
62 |
typedef struct VirtIOSerialPort VirtIOSerialPort; |
63 |
typedef struct VirtIOSerialPortInfo VirtIOSerialPortInfo; |
64 |
|
65 |
/*
|
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.
|
70 |
*/
|
71 |
struct VirtIOSerialPort {
|
72 |
DeviceState dev; |
73 |
VirtIOSerialPortInfo *info; |
74 |
|
75 |
QTAILQ_ENTRY(VirtIOSerialPort) next; |
76 |
|
77 |
/*
|
78 |
* This field gives us the virtio device as well as the qdev bus
|
79 |
* that we are associated with
|
80 |
*/
|
81 |
VirtIOSerial *vser; |
82 |
|
83 |
VirtQueue *ivq, *ovq; |
84 |
|
85 |
/*
|
86 |
* This name is sent to the guest and exported via sysfs.
|
87 |
* The guest could create symlinks based on this information.
|
88 |
* The name is in the reverse fqdn format, like org.qemu.console.0
|
89 |
*/
|
90 |
char *name;
|
91 |
|
92 |
/*
|
93 |
* This id helps identify ports between the guest and the host.
|
94 |
* The guest sends a "header" with this id with each data packet
|
95 |
* that it sends and the host can then find out which associated
|
96 |
* device to send out this data to
|
97 |
*/
|
98 |
uint32_t id; |
99 |
|
100 |
/*
|
101 |
* This is the elem that we pop from the virtqueue. A slow
|
102 |
* backend that consumes guest data (e.g. the file backend for
|
103 |
* qemu chardevs) can cause the guest to block till all the output
|
104 |
* is flushed. This isn't desired, so we keep a note of the last
|
105 |
* element popped and continue consuming it once the backend
|
106 |
* becomes writable again.
|
107 |
*/
|
108 |
VirtQueueElement elem; |
109 |
|
110 |
/*
|
111 |
* The index and the offset into the iov buffer that was popped in
|
112 |
* elem above.
|
113 |
*/
|
114 |
uint32_t iov_idx; |
115 |
uint64_t iov_offset; |
116 |
|
117 |
/* Identify if this is a port that binds with hvc in the guest */
|
118 |
uint8_t is_console; |
119 |
|
120 |
/* Is the corresponding guest device open? */
|
121 |
bool guest_connected;
|
122 |
/* Is this device open for IO on the host? */
|
123 |
bool host_connected;
|
124 |
/* Do apps not want to receive data? */
|
125 |
bool throttled;
|
126 |
}; |
127 |
|
128 |
struct VirtIOSerialPortInfo {
|
129 |
DeviceInfo qdev; |
130 |
/*
|
131 |
* The per-port (or per-app) init function that's called when a
|
132 |
* new device is found on the bus.
|
133 |
*/
|
134 |
int (*init)(VirtIOSerialPort *port);
|
135 |
/*
|
136 |
* Per-port exit function that's called when a port gets
|
137 |
* hot-unplugged or removed.
|
138 |
*/
|
139 |
int (*exit)(VirtIOSerialPort *port);
|
140 |
|
141 |
/* Callbacks for guest events */
|
142 |
/* Guest opened device. */
|
143 |
void (*guest_open)(VirtIOSerialPort *port);
|
144 |
/* Guest closed device. */
|
145 |
void (*guest_close)(VirtIOSerialPort *port);
|
146 |
|
147 |
/* Guest is now ready to accept data (virtqueues set up). */
|
148 |
void (*guest_ready)(VirtIOSerialPort *port);
|
149 |
|
150 |
/*
|
151 |
* Guest wrote some data to the port. This data is handed over to
|
152 |
* the app via this callback. The app can return a size less than
|
153 |
* 'len'. In this case, throttling will be enabled for this port.
|
154 |
*/
|
155 |
ssize_t (*have_data)(VirtIOSerialPort *port, const uint8_t *buf,
|
156 |
size_t len); |
157 |
}; |
158 |
|
159 |
/* Interface to the virtio-serial bus */
|
160 |
|
161 |
/*
|
162 |
* Individual ports/apps should call this function to register the port
|
163 |
* with the virtio-serial bus
|
164 |
*/
|
165 |
void virtio_serial_port_qdev_register(VirtIOSerialPortInfo *info);
|
166 |
|
167 |
/*
|
168 |
* Open a connection to the port
|
169 |
* Returns 0 on success (always).
|
170 |
*/
|
171 |
int virtio_serial_open(VirtIOSerialPort *port);
|
172 |
|
173 |
/*
|
174 |
* Close the connection to the port
|
175 |
* Returns 0 on success (always).
|
176 |
*/
|
177 |
int virtio_serial_close(VirtIOSerialPort *port);
|
178 |
|
179 |
/*
|
180 |
* Send data to Guest
|
181 |
*/
|
182 |
ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,
|
183 |
size_t size); |
184 |
|
185 |
/*
|
186 |
* Query whether a guest is ready to receive data.
|
187 |
*/
|
188 |
size_t virtio_serial_guest_ready(VirtIOSerialPort *port); |
189 |
|
190 |
/*
|
191 |
* Flow control: Ports can signal to the virtio-serial core to stop
|
192 |
* sending data or re-start sending data, depending on the 'throttle'
|
193 |
* value here.
|
194 |
*/
|
195 |
void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle); |
196 |
|
197 |
#endif
|