1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _QEMU_VIRTIO_SERIAL_H
16#define _QEMU_VIRTIO_SERIAL_H
17
18#include "hw/qdev.h"
19#include "hw/virtio/virtio.h"
20
21
22
23
24#define VIRTIO_ID_CONSOLE 3
25
26
27#define VIRTIO_CONSOLE_F_MULTIPORT 1
28
29#define VIRTIO_CONSOLE_BAD_ID (~(uint32_t)0)
30
31struct virtio_console_config {
32
33
34
35
36 uint16_t cols;
37 uint16_t rows;
38
39 uint32_t max_nr_ports;
40} QEMU_PACKED;
41
42struct virtio_console_control {
43 uint32_t id;
44 uint16_t event;
45 uint16_t value;
46};
47
48struct virtio_serial_conf {
49
50 uint32_t max_virtserial_ports;
51};
52
53
54#define VIRTIO_CONSOLE_DEVICE_READY 0
55#define VIRTIO_CONSOLE_PORT_ADD 1
56#define VIRTIO_CONSOLE_PORT_REMOVE 2
57#define VIRTIO_CONSOLE_PORT_READY 3
58#define VIRTIO_CONSOLE_CONSOLE_PORT 4
59#define VIRTIO_CONSOLE_RESIZE 5
60#define VIRTIO_CONSOLE_PORT_OPEN 6
61#define VIRTIO_CONSOLE_PORT_NAME 7
62
63
64
65#define TYPE_VIRTIO_SERIAL_PORT "virtio-serial-port"
66#define VIRTIO_SERIAL_PORT(obj) \
67 OBJECT_CHECK(VirtIOSerialPort, (obj), TYPE_VIRTIO_SERIAL_PORT)
68#define VIRTIO_SERIAL_PORT_CLASS(klass) \
69 OBJECT_CLASS_CHECK(VirtIOSerialPortClass, (klass), TYPE_VIRTIO_SERIAL_PORT)
70#define VIRTIO_SERIAL_PORT_GET_CLASS(obj) \
71 OBJECT_GET_CLASS(VirtIOSerialPortClass, (obj), TYPE_VIRTIO_SERIAL_PORT)
72
73typedef struct VirtIOSerial VirtIOSerial;
74typedef struct VirtIOSerialBus VirtIOSerialBus;
75typedef struct VirtIOSerialPort VirtIOSerialPort;
76
77typedef struct VirtIOSerialPortClass {
78 DeviceClass parent_class;
79
80
81 bool is_console;
82
83
84
85
86
87 int (*init)(VirtIOSerialPort *port);
88
89
90
91
92 int (*exit)(VirtIOSerialPort *port);
93
94
95
96 void (*set_guest_connected)(VirtIOSerialPort *port, int guest_connected);
97
98
99 void (*guest_ready)(VirtIOSerialPort *port);
100
101
102
103
104
105
106 ssize_t (*have_data)(VirtIOSerialPort *port, const uint8_t *buf,
107 ssize_t len);
108} VirtIOSerialPortClass;
109
110
111
112
113
114
115
116struct VirtIOSerialPort {
117 DeviceState dev;
118
119 QTAILQ_ENTRY(VirtIOSerialPort) next;
120
121
122
123
124
125 VirtIOSerial *vser;
126
127 VirtQueue *ivq, *ovq;
128
129
130
131
132
133
134 char *name;
135
136
137
138
139
140
141
142 uint32_t id;
143
144
145
146
147
148
149
150
151
152 VirtQueueElement elem;
153
154
155
156
157
158 uint32_t iov_idx;
159 uint64_t iov_offset;
160
161
162
163
164 QEMUBH *bh;
165
166
167 bool guest_connected;
168
169 bool host_connected;
170
171 bool throttled;
172};
173
174
175struct VirtIOSerialBus {
176 BusState qbus;
177
178
179 VirtIOSerial *vser;
180
181
182 uint32_t max_nr_ports;
183};
184
185typedef struct VirtIOSerialPostLoad {
186 QEMUTimer *timer;
187 uint32_t nr_active_ports;
188 struct {
189 VirtIOSerialPort *port;
190 uint8_t host_connected;
191 } *connected;
192} VirtIOSerialPostLoad;
193
194struct VirtIOSerial {
195 VirtIODevice parent_obj;
196
197 VirtQueue *c_ivq, *c_ovq;
198
199 VirtQueue **ivqs, **ovqs;
200
201 VirtIOSerialBus bus;
202
203 QTAILQ_HEAD(, VirtIOSerialPort) ports;
204
205
206 uint32_t *ports_map;
207
208 struct virtio_console_config config;
209
210 struct VirtIOSerialPostLoad *post_load;
211
212 virtio_serial_conf serial;
213};
214
215
216
217
218
219
220
221int virtio_serial_open(VirtIOSerialPort *port);
222
223
224
225
226
227int virtio_serial_close(VirtIOSerialPort *port);
228
229
230
231
232ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,
233 size_t size);
234
235
236
237
238size_t virtio_serial_guest_ready(VirtIOSerialPort *port);
239
240
241
242
243
244
245void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle);
246
247#define TYPE_VIRTIO_SERIAL "virtio-serial-device"
248#define VIRTIO_SERIAL(obj) \
249 OBJECT_CHECK(VirtIOSerial, (obj), TYPE_VIRTIO_SERIAL)
250
251#define DEFINE_VIRTIO_SERIAL_PROPERTIES(_state, _field) \
252 DEFINE_PROP_UINT32("max_ports", _state, _field.max_virtserial_ports, 31)
253
254#endif
255