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
44#define CHR_IOCTL_SERIAL_SET_TIOCM 13
45#define CHR_IOCTL_SERIAL_GET_TIOCM 14
46
47#define CHR_TIOCM_CTS 0x020
48#define CHR_TIOCM_CAR 0x040
49#define CHR_TIOCM_DSR 0x100
50#define CHR_TIOCM_RI 0x080
51#define CHR_TIOCM_DTR 0x002
52#define CHR_TIOCM_RTS 0x004
53
54typedef void IOEventHandler(void *opaque, int event);
55
56struct CharDriverState {
57 QemuMutex chr_write_lock;
58 void (*init)(struct CharDriverState *s);
59 int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
60 int (*chr_sync_read)(struct CharDriverState *s,
61 const uint8_t *buf, int len);
62 GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond);
63 void (*chr_update_read_handler)(struct CharDriverState *s);
64 int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
65 int (*get_msgfds)(struct CharDriverState *s, int* fds, int num);
66 int (*set_msgfds)(struct CharDriverState *s, int *fds, int num);
67 int (*chr_add_client)(struct CharDriverState *chr, int fd);
68 IOEventHandler *chr_event;
69 IOCanReadHandler *chr_can_read;
70 IOReadHandler *chr_read;
71 void *handler_opaque;
72 void (*chr_close)(struct CharDriverState *chr);
73 void (*chr_accept_input)(struct CharDriverState *chr);
74 void (*chr_set_echo)(struct CharDriverState *chr, bool echo);
75 void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open);
76 void (*chr_fe_event)(struct CharDriverState *chr, int event);
77 void *opaque;
78 char *label;
79 char *filename;
80 int be_open;
81 int fe_open;
82 int explicit_fe_open;
83 int explicit_be_open;
84 int avail_connections;
85 int is_mux;
86 guint fd_in_tag;
87 QemuOpts *opts;
88 QTAILQ_ENTRY(CharDriverState) next;
89};
90
91
92
93
94
95
96
97
98CharDriverState *qemu_chr_alloc(void);
99
100
101
102
103
104
105
106
107
108
109
110CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
111 void (*init)(struct CharDriverState *s),
112 Error **errp);
113
114
115
116
117
118
119
120
121
122
123
124
125CharDriverState *qemu_chr_new(const char *label, const char *filename,
126 void (*init)(struct CharDriverState *s));
127
128
129
130
131
132
133
134void qemu_chr_delete(CharDriverState *chr);
135
136
137
138
139
140
141void qemu_chr_free(CharDriverState *chr);
142
143
144
145
146
147
148
149
150
151
152void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo);
153
154
155
156
157
158
159
160void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open);
161
162
163
164
165
166
167
168
169void qemu_chr_fe_event(CharDriverState *s, int event);
170
171
172
173
174
175
176
177
178
179void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
180 GCC_FMT_ATTR(2, 3);
181
182int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
183 GIOFunc func, void *user_data);
184
185
186
187
188
189
190
191
192
193
194
195
196
197int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len);
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len);
213
214
215
216
217
218
219
220
221
222
223
224int qemu_chr_fe_read_all(CharDriverState *s, uint8_t *buf, int len);
225
226
227
228
229
230
231
232
233
234
235
236
237int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg);
238
239
240
241
242
243
244
245
246
247
248
249
250int qemu_chr_fe_get_msgfd(CharDriverState *s);
251
252
253
254
255
256
257
258
259
260
261
262
263int qemu_chr_fe_get_msgfds(CharDriverState *s, int *fds, int num);
264
265
266
267
268
269
270
271
272
273
274
275
276int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num);
277
278
279
280
281
282
283
284
285
286
287int qemu_chr_fe_claim(CharDriverState *s);
288
289
290
291
292
293
294
295void qemu_chr_fe_claim_no_fail(CharDriverState *s);
296
297
298
299
300
301
302
303
304
305void qemu_chr_fe_release(CharDriverState *s);
306
307
308
309
310
311
312
313
314
315
316
317int qemu_chr_be_can_write(CharDriverState *s);
318
319
320
321
322
323
324
325
326
327
328
329void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
330
331
332
333
334
335
336
337
338
339void qemu_chr_be_event(CharDriverState *s, int event);
340
341void qemu_chr_add_handlers(CharDriverState *s,
342 IOCanReadHandler *fd_can_read,
343 IOReadHandler *fd_read,
344 IOEventHandler *fd_event,
345 void *opaque);
346
347void qemu_chr_be_generic_open(CharDriverState *s);
348void qemu_chr_accept_input(CharDriverState *s);
349int qemu_chr_add_client(CharDriverState *s, int fd);
350CharDriverState *qemu_chr_find(const char *name);
351bool chr_is_ringbuf(const CharDriverState *chr);
352
353QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
354
355void register_char_driver(const char *name, ChardevBackendKind kind,
356 void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp),
357 CharDriverState *(*create)(const char *id, ChardevBackend *backend,
358 ChardevReturn *ret, Error **errp));
359
360
361CharDriverState *qemu_chr_open_eventfd(int eventfd);
362
363extern int term_escape_char;
364
365CharDriverState *qemu_char_get_next_serial(void);
366
367
368typedef CharDriverState *(VcHandler)(ChardevVC *vc, Error **errp);
369void register_vc_handler(VcHandler *handler);
370
371#endif
372