1#ifndef QEMU_CHAR_H
2#define QEMU_CHAR_H
3
4#include "qemu-common.h"
5#include "qemu/queue.h"
6#include "qemu/option.h"
7#include "qemu/config-file.h"
8#include "block/aio.h"
9#include "qapi/qmp/qobject.h"
10#include "qapi/qmp/qstring.h"
11#include "qemu/main-loop.h"
12
13
14
15#define CHR_EVENT_BREAK 0
16#define CHR_EVENT_FOCUS 1
17#define CHR_EVENT_OPENED 2
18#define CHR_EVENT_MUX_IN 3
19#define CHR_EVENT_MUX_OUT 4
20#define CHR_EVENT_CLOSED 5
21
22
23#define CHR_IOCTL_SERIAL_SET_PARAMS 1
24typedef struct {
25 int speed;
26 int parity;
27 int data_bits;
28 int stop_bits;
29} QEMUSerialSetParams;
30
31#define CHR_IOCTL_SERIAL_SET_BREAK 2
32
33#define CHR_IOCTL_PP_READ_DATA 3
34#define CHR_IOCTL_PP_WRITE_DATA 4
35#define CHR_IOCTL_PP_READ_CONTROL 5
36#define CHR_IOCTL_PP_WRITE_CONTROL 6
37#define CHR_IOCTL_PP_READ_STATUS 7
38#define CHR_IOCTL_PP_EPP_READ_ADDR 8
39#define CHR_IOCTL_PP_EPP_READ 9
40#define CHR_IOCTL_PP_EPP_WRITE_ADDR 10
41#define CHR_IOCTL_PP_EPP_WRITE 11
42#define CHR_IOCTL_PP_DATA_DIR 12
43
44struct ParallelIOArg {
45 void *buffer;
46 int count;
47};
48
49#define CHR_IOCTL_SERIAL_SET_TIOCM 13
50#define CHR_IOCTL_SERIAL_GET_TIOCM 14
51
52#define CHR_TIOCM_CTS 0x020
53#define CHR_TIOCM_CAR 0x040
54#define CHR_TIOCM_DSR 0x100
55#define CHR_TIOCM_RI 0x080
56#define CHR_TIOCM_DTR 0x002
57#define CHR_TIOCM_RTS 0x004
58
59typedef void IOEventHandler(void *opaque, int event);
60
61struct CharDriverState {
62 QemuMutex chr_write_lock;
63 void (*init)(struct CharDriverState *s);
64 int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
65 int (*chr_sync_read)(struct CharDriverState *s,
66 const uint8_t *buf, int len);
67 GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond);
68 void (*chr_update_read_handler)(struct CharDriverState *s);
69 int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
70 int (*get_msgfds)(struct CharDriverState *s, int* fds, int num);
71 int (*set_msgfds)(struct CharDriverState *s, int *fds, int num);
72 int (*chr_add_client)(struct CharDriverState *chr, int fd);
73 IOEventHandler *chr_event;
74 IOCanReadHandler *chr_can_read;
75 IOReadHandler *chr_read;
76 void *handler_opaque;
77 void (*chr_close)(struct CharDriverState *chr);
78 void (*chr_accept_input)(struct CharDriverState *chr);
79 void (*chr_set_echo)(struct CharDriverState *chr, bool echo);
80 void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open);
81 void (*chr_fe_event)(struct CharDriverState *chr, int event);
82 void *opaque;
83 char *label;
84 char *filename;
85 int logfd;
86 int be_open;
87 int fe_open;
88 int explicit_fe_open;
89 int explicit_be_open;
90 int avail_connections;
91 int is_mux;
92 guint fd_in_tag;
93 QemuOpts *opts;
94 bool replay;
95 QTAILQ_ENTRY(CharDriverState) next;
96};
97
98
99
100
101
102
103
104
105
106
107CharDriverState *qemu_chr_alloc(ChardevCommon *backend, Error **errp);
108
109
110
111
112
113
114
115
116
117
118
119CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
120 void (*init)(struct CharDriverState *s),
121 Error **errp);
122
123
124
125
126
127
128
129
130
131void qemu_chr_parse_common(QemuOpts *opts, ChardevCommon *backend);
132
133
134
135
136
137
138
139
140
141
142
143
144CharDriverState *qemu_chr_new(const char *label, const char *filename,
145 void (*init)(struct CharDriverState *s));
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160CharDriverState *qemu_chr_new_noreplay(const char *label, const char *filename,
161 void (*init)(struct CharDriverState *s));
162
163
164
165
166
167
168
169void qemu_chr_delete(CharDriverState *chr);
170
171
172
173
174
175
176void qemu_chr_free(CharDriverState *chr);
177
178
179
180
181
182
183
184
185
186
187void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo);
188
189
190
191
192
193
194
195void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open);
196
197
198
199
200
201
202
203
204void qemu_chr_fe_event(CharDriverState *s, int event);
205
206
207
208
209
210
211
212
213
214void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
215 GCC_FMT_ATTR(2, 3);
216
217int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
218 GIOFunc func, void *user_data);
219
220
221
222
223
224
225
226
227
228
229
230
231
232int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len);
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len);
248
249
250
251
252
253
254
255
256
257
258
259int qemu_chr_fe_read_all(CharDriverState *s, uint8_t *buf, int len);
260
261
262
263
264
265
266
267
268
269
270
271
272int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg);
273
274
275
276
277
278
279
280
281
282
283
284
285int qemu_chr_fe_get_msgfd(CharDriverState *s);
286
287
288
289
290
291
292
293
294
295
296
297
298int qemu_chr_fe_get_msgfds(CharDriverState *s, int *fds, int num);
299
300
301
302
303
304
305
306
307
308
309
310
311int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num);
312
313
314
315
316
317
318
319
320
321
322int qemu_chr_fe_claim(CharDriverState *s);
323
324
325
326
327
328
329
330void qemu_chr_fe_claim_no_fail(CharDriverState *s);
331
332
333
334
335
336
337
338
339
340void qemu_chr_fe_release(CharDriverState *s);
341
342
343
344
345
346
347
348
349
350
351
352int qemu_chr_be_can_write(CharDriverState *s);
353
354
355
356
357
358
359
360
361
362
363
364void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
365
366
367
368
369
370
371
372
373
374void qemu_chr_be_write_impl(CharDriverState *s, uint8_t *buf, int len);
375
376
377
378
379
380
381
382
383void qemu_chr_be_event(CharDriverState *s, int event);
384
385void qemu_chr_add_handlers(CharDriverState *s,
386 IOCanReadHandler *fd_can_read,
387 IOReadHandler *fd_read,
388 IOEventHandler *fd_event,
389 void *opaque);
390
391void qemu_chr_be_generic_open(CharDriverState *s);
392void qemu_chr_accept_input(CharDriverState *s);
393int qemu_chr_add_client(CharDriverState *s, int fd);
394CharDriverState *qemu_chr_find(const char *name);
395bool chr_is_ringbuf(const CharDriverState *chr);
396
397QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
398
399void register_char_driver(const char *name, ChardevBackendKind kind,
400 void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp),
401 CharDriverState *(*create)(const char *id, ChardevBackend *backend,
402 ChardevReturn *ret, Error **errp));
403
404extern int term_escape_char;
405
406CharDriverState *qemu_char_get_next_serial(void);
407
408
409typedef CharDriverState *(VcHandler)(ChardevVC *vc, Error **errp);
410void register_vc_handler(VcHandler *handler);
411
412#endif
413