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.h"
8#include "qobject.h"
9#include "qstring.h"
10#include "main-loop.h"
11
12
13
14#define CHR_EVENT_BREAK 0
15#define CHR_EVENT_FOCUS 1
16#define CHR_EVENT_OPENED 2
17#define CHR_EVENT_MUX_IN 3
18#define CHR_EVENT_MUX_OUT 4
19#define CHR_EVENT_CLOSED 5
20
21
22#define CHR_IOCTL_SERIAL_SET_PARAMS 1
23typedef struct {
24 int speed;
25 int parity;
26 int data_bits;
27 int stop_bits;
28} QEMUSerialSetParams;
29
30#define CHR_IOCTL_SERIAL_SET_BREAK 2
31
32#define CHR_IOCTL_PP_READ_DATA 3
33#define CHR_IOCTL_PP_WRITE_DATA 4
34#define CHR_IOCTL_PP_READ_CONTROL 5
35#define CHR_IOCTL_PP_WRITE_CONTROL 6
36#define CHR_IOCTL_PP_READ_STATUS 7
37#define CHR_IOCTL_PP_EPP_READ_ADDR 8
38#define CHR_IOCTL_PP_EPP_READ 9
39#define CHR_IOCTL_PP_EPP_WRITE_ADDR 10
40#define CHR_IOCTL_PP_EPP_WRITE 11
41#define CHR_IOCTL_PP_DATA_DIR 12
42
43#define CHR_IOCTL_SERIAL_SET_TIOCM 13
44#define CHR_IOCTL_SERIAL_GET_TIOCM 14
45
46#define CHR_TIOCM_CTS 0x020
47#define CHR_TIOCM_CAR 0x040
48#define CHR_TIOCM_DSR 0x100
49#define CHR_TIOCM_RI 0x080
50#define CHR_TIOCM_DTR 0x002
51#define CHR_TIOCM_RTS 0x004
52
53typedef void IOEventHandler(void *opaque, int event);
54
55struct CharDriverState {
56 void (*init)(struct CharDriverState *s);
57 int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
58 void (*chr_update_read_handler)(struct CharDriverState *s);
59 int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
60 int (*get_msgfd)(struct CharDriverState *s);
61 int (*chr_add_client)(struct CharDriverState *chr, int fd);
62 IOEventHandler *chr_event;
63 IOCanReadHandler *chr_can_read;
64 IOReadHandler *chr_read;
65 void *handler_opaque;
66 void (*chr_close)(struct CharDriverState *chr);
67 void (*chr_accept_input)(struct CharDriverState *chr);
68 void (*chr_set_echo)(struct CharDriverState *chr, bool echo);
69 void (*chr_guest_open)(struct CharDriverState *chr);
70 void (*chr_guest_close)(struct CharDriverState *chr);
71 void *opaque;
72 QEMUBH *bh;
73 char *label;
74 char *filename;
75 int opened;
76 int avail_connections;
77 QTAILQ_ENTRY(CharDriverState) next;
78};
79
80
81
82
83
84
85
86
87
88
89
90CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
91 void (*init)(struct CharDriverState *s));
92
93
94
95
96
97
98
99
100
101
102
103
104CharDriverState *qemu_chr_new(const char *label, const char *filename,
105 void (*init)(struct CharDriverState *s));
106
107
108
109
110
111
112void qemu_chr_delete(CharDriverState *chr);
113
114
115
116
117
118
119
120
121
122
123void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo);
124
125
126
127
128
129
130
131void qemu_chr_fe_open(struct CharDriverState *chr);
132
133
134
135
136
137
138
139
140void qemu_chr_fe_close(struct CharDriverState *chr);
141
142
143
144
145
146
147
148
149void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
150 GCC_FMT_ATTR(2, 3);
151
152
153
154
155
156
157
158
159
160
161
162
163int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len);
164
165
166
167
168
169
170
171
172
173
174
175
176int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg);
177
178
179
180
181
182
183
184
185
186
187
188
189int qemu_chr_fe_get_msgfd(CharDriverState *s);
190
191
192
193
194
195
196
197
198
199
200
201int qemu_chr_be_can_write(CharDriverState *s);
202
203
204
205
206
207
208
209
210
211
212
213void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
214
215
216
217
218
219
220
221
222
223void qemu_chr_be_event(CharDriverState *s, int event);
224
225void qemu_chr_add_handlers(CharDriverState *s,
226 IOCanReadHandler *fd_can_read,
227 IOReadHandler *fd_read,
228 IOEventHandler *fd_event,
229 void *opaque);
230
231void qemu_chr_generic_open(CharDriverState *s);
232void qemu_chr_accept_input(CharDriverState *s);
233int qemu_chr_add_client(CharDriverState *s, int fd);
234void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
235void qemu_chr_info(Monitor *mon, QObject **ret_data);
236CharDriverState *qemu_chr_find(const char *name);
237
238QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
239
240
241CharDriverState *qemu_chr_open_eventfd(int eventfd);
242
243extern int term_escape_char;
244
245
246void qemu_chr_init_mem(CharDriverState *chr);
247void qemu_chr_close_mem(CharDriverState *chr);
248QString *qemu_chr_mem_to_qs(CharDriverState *chr);
249size_t qemu_chr_mem_osize(const CharDriverState *chr);
250
251#endif
252