Statistics
| Branch: | Revision:

root / include / sysemu / char.h @ 4f953d2f

History | View | Annotate | Download (8.7 kB)

1 87ecb68b pbrook
#ifndef QEMU_CHAR_H
2 87ecb68b pbrook
#define QEMU_CHAR_H
3 87ecb68b pbrook
4 376253ec aliguori
#include "qemu-common.h"
5 1de7afc9 Paolo Bonzini
#include "qemu/queue.h"
6 1de7afc9 Paolo Bonzini
#include "qemu/option.h"
7 1de7afc9 Paolo Bonzini
#include "qemu/config-file.h"
8 737e150e Paolo Bonzini
#include "block/aio.h"
9 7b1b5d19 Paolo Bonzini
#include "qapi/qmp/qobject.h"
10 7b1b5d19 Paolo Bonzini
#include "qapi/qmp/qstring.h"
11 1de7afc9 Paolo Bonzini
#include "qemu/main-loop.h"
12 376253ec aliguori
13 87ecb68b pbrook
/* character device */
14 87ecb68b pbrook
15 2724b180 aliguori
#define CHR_EVENT_BREAK   0 /* serial break char */
16 2724b180 aliguori
#define CHR_EVENT_FOCUS   1 /* focus to this terminal (modal input needed) */
17 b6b8df56 Amit Shah
#define CHR_EVENT_OPENED  2 /* new connection established */
18 2724b180 aliguori
#define CHR_EVENT_MUX_IN  3 /* mux-focus was set to this terminal */
19 2724b180 aliguori
#define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */
20 793cbfb5 Amit Shah
#define CHR_EVENT_CLOSED  5 /* connection closed */
21 87ecb68b pbrook
22 87ecb68b pbrook
23 87ecb68b pbrook
#define CHR_IOCTL_SERIAL_SET_PARAMS   1
24 87ecb68b pbrook
typedef struct {
25 87ecb68b pbrook
    int speed;
26 87ecb68b pbrook
    int parity;
27 87ecb68b pbrook
    int data_bits;
28 87ecb68b pbrook
    int stop_bits;
29 87ecb68b pbrook
} QEMUSerialSetParams;
30 87ecb68b pbrook
31 87ecb68b pbrook
#define CHR_IOCTL_SERIAL_SET_BREAK    2
32 87ecb68b pbrook
33 87ecb68b pbrook
#define CHR_IOCTL_PP_READ_DATA        3
34 87ecb68b pbrook
#define CHR_IOCTL_PP_WRITE_DATA       4
35 87ecb68b pbrook
#define CHR_IOCTL_PP_READ_CONTROL     5
36 87ecb68b pbrook
#define CHR_IOCTL_PP_WRITE_CONTROL    6
37 87ecb68b pbrook
#define CHR_IOCTL_PP_READ_STATUS      7
38 87ecb68b pbrook
#define CHR_IOCTL_PP_EPP_READ_ADDR    8
39 87ecb68b pbrook
#define CHR_IOCTL_PP_EPP_READ         9
40 87ecb68b pbrook
#define CHR_IOCTL_PP_EPP_WRITE_ADDR  10
41 87ecb68b pbrook
#define CHR_IOCTL_PP_EPP_WRITE       11
42 563e3c6e aurel32
#define CHR_IOCTL_PP_DATA_DIR        12
43 87ecb68b pbrook
44 f0664048 aurel32
#define CHR_IOCTL_SERIAL_SET_TIOCM   13
45 f0664048 aurel32
#define CHR_IOCTL_SERIAL_GET_TIOCM   14
46 81174dae aliguori
47 81174dae aliguori
#define CHR_TIOCM_CTS        0x020
48 81174dae aliguori
#define CHR_TIOCM_CAR        0x040
49 81174dae aliguori
#define CHR_TIOCM_DSR        0x100
50 81174dae aliguori
#define CHR_TIOCM_RI        0x080
51 81174dae aliguori
#define CHR_TIOCM_DTR        0x002
52 81174dae aliguori
#define CHR_TIOCM_RTS        0x004
53 81174dae aliguori
54 87ecb68b pbrook
typedef void IOEventHandler(void *opaque, int event);
55 87ecb68b pbrook
56 87ecb68b pbrook
struct CharDriverState {
57 ceecf1d1 aurel32
    void (*init)(struct CharDriverState *s);
58 87ecb68b pbrook
    int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
59 23673ca7 Anthony Liguori
    GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond);
60 87ecb68b pbrook
    void (*chr_update_read_handler)(struct CharDriverState *s);
61 87ecb68b pbrook
    int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
62 7d174059 Mark McLoughlin
    int (*get_msgfd)(struct CharDriverState *s);
63 13661089 Daniel P. Berrange
    int (*chr_add_client)(struct CharDriverState *chr, int fd);
64 87ecb68b pbrook
    IOEventHandler *chr_event;
65 7b27a769 Juan Quintela
    IOCanReadHandler *chr_can_read;
66 87ecb68b pbrook
    IOReadHandler *chr_read;
67 87ecb68b pbrook
    void *handler_opaque;
68 87ecb68b pbrook
    void (*chr_close)(struct CharDriverState *chr);
69 bd9bdce6 balrog
    void (*chr_accept_input)(struct CharDriverState *chr);
70 c48855e1 Paolo Bonzini
    void (*chr_set_echo)(struct CharDriverState *chr, bool echo);
71 574b711a Hans de Goede
    void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open);
72 87ecb68b pbrook
    void *opaque;
73 5ccfae10 aliguori
    char *label;
74 5ccfae10 aliguori
    char *filename;
75 16665b94 Hans de Goede
    int be_open;
76 c0c4bd2c Hans de Goede
    int fe_open;
77 19083228 Hans de Goede
    int explicit_fe_open;
78 bd5c51ee Michael Roth
    int explicit_be_open;
79 d5b27167 Kusanagi Kouichi
    int avail_connections;
80 7b7ab18d Michael Roth
    int is_mux;
81 2274ae9d Gerd Hoffmann
    QemuOpts *opts;
82 72cf2d4f Blue Swirl
    QTAILQ_ENTRY(CharDriverState) next;
83 87ecb68b pbrook
};
84 87ecb68b pbrook
85 2011fe56 Anthony Liguori
/**
86 2011fe56 Anthony Liguori
 * @qemu_chr_new_from_opts:
87 2011fe56 Anthony Liguori
 *
88 2011fe56 Anthony Liguori
 * Create a new character backend from a QemuOpts list.
89 2011fe56 Anthony Liguori
 *
90 2011fe56 Anthony Liguori
 * @opts see qemu-config.c for a list of valid options
91 2011fe56 Anthony Liguori
 * @init not sure..
92 2011fe56 Anthony Liguori
 *
93 2011fe56 Anthony Liguori
 * Returns: a new character backend
94 2011fe56 Anthony Liguori
 */
95 f69554b9 Anthony Liguori
CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
96 bd2d80b2 Gerd Hoffmann
                                    void (*init)(struct CharDriverState *s),
97 bd2d80b2 Gerd Hoffmann
                                    Error **errp);
98 2011fe56 Anthony Liguori
99 2011fe56 Anthony Liguori
/**
100 2011fe56 Anthony Liguori
 * @qemu_chr_new:
101 2011fe56 Anthony Liguori
 *
102 2011fe56 Anthony Liguori
 * Create a new character backend from a URI.
103 2011fe56 Anthony Liguori
 *
104 2011fe56 Anthony Liguori
 * @label the name of the backend
105 2011fe56 Anthony Liguori
 * @filename the URI
106 2011fe56 Anthony Liguori
 * @init not sure..
107 2011fe56 Anthony Liguori
 *
108 2011fe56 Anthony Liguori
 * Returns: a new character backend
109 2011fe56 Anthony Liguori
 */
110 2011fe56 Anthony Liguori
CharDriverState *qemu_chr_new(const char *label, const char *filename,
111 2011fe56 Anthony Liguori
                              void (*init)(struct CharDriverState *s));
112 2011fe56 Anthony Liguori
113 2011fe56 Anthony Liguori
/**
114 2011fe56 Anthony Liguori
 * @qemu_chr_delete:
115 2011fe56 Anthony Liguori
 *
116 2011fe56 Anthony Liguori
 * Destroy a character backend.
117 2011fe56 Anthony Liguori
 */
118 2011fe56 Anthony Liguori
void qemu_chr_delete(CharDriverState *chr);
119 2011fe56 Anthony Liguori
120 2011fe56 Anthony Liguori
/**
121 2011fe56 Anthony Liguori
 * @qemu_chr_fe_set_echo:
122 2011fe56 Anthony Liguori
 *
123 2011fe56 Anthony Liguori
 * Ask the backend to override its normal echo setting.  This only really
124 2011fe56 Anthony Liguori
 * applies to the stdio backend and is used by the QMP server such that you
125 2011fe56 Anthony Liguori
 * can see what you type if you try to type QMP commands.
126 2011fe56 Anthony Liguori
 *
127 2011fe56 Anthony Liguori
 * @echo true to enable echo, false to disable echo
128 2011fe56 Anthony Liguori
 */
129 15f31519 Anthony Liguori
void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo);
130 2011fe56 Anthony Liguori
131 2011fe56 Anthony Liguori
/**
132 8e25daa8 Hans de Goede
 * @qemu_chr_fe_set_open:
133 2011fe56 Anthony Liguori
 *
134 8e25daa8 Hans de Goede
 * Set character frontend open status.  This is an indication that the
135 8e25daa8 Hans de Goede
 * front end is ready (or not) to begin doing I/O.
136 2011fe56 Anthony Liguori
 */
137 8e25daa8 Hans de Goede
void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open);
138 2011fe56 Anthony Liguori
139 2011fe56 Anthony Liguori
/**
140 2011fe56 Anthony Liguori
 * @qemu_chr_fe_printf:
141 2011fe56 Anthony Liguori
 *
142 2011fe56 Anthony Liguori
 * Write to a character backend using a printf style interface.
143 2011fe56 Anthony Liguori
 *
144 2011fe56 Anthony Liguori
 * @fmt see #printf
145 2011fe56 Anthony Liguori
 */
146 e7e71b0e Anthony Liguori
void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
147 8b7968f7 Stefan Weil
    GCC_FMT_ATTR(2, 3);
148 2011fe56 Anthony Liguori
149 2c8a5942 Kevin Wolf
int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
150 2c8a5942 Kevin Wolf
                          GIOFunc func, void *user_data);
151 23673ca7 Anthony Liguori
152 2011fe56 Anthony Liguori
/**
153 2011fe56 Anthony Liguori
 * @qemu_chr_fe_write:
154 2011fe56 Anthony Liguori
 *
155 2011fe56 Anthony Liguori
 * Write data to a character backend from the front end.  This function will
156 2011fe56 Anthony Liguori
 * send data from the front end to the back end.
157 2011fe56 Anthony Liguori
 *
158 2011fe56 Anthony Liguori
 * @buf the data
159 2011fe56 Anthony Liguori
 * @len the number of bytes to send
160 2011fe56 Anthony Liguori
 *
161 2011fe56 Anthony Liguori
 * Returns: the number of bytes consumed
162 2011fe56 Anthony Liguori
 */
163 2cc6e0a1 Anthony Liguori
int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len);
164 2011fe56 Anthony Liguori
165 2011fe56 Anthony Liguori
/**
166 cd18720a Anthony Liguori
 * @qemu_chr_fe_write_all:
167 cd18720a Anthony Liguori
 *
168 cd18720a Anthony Liguori
 * Write data to a character backend from the front end.  This function will
169 cd18720a Anthony Liguori
 * send data from the front end to the back end.  Unlike @qemu_chr_fe_write,
170 cd18720a Anthony Liguori
 * this function will block if the back end cannot consume all of the data
171 cd18720a Anthony Liguori
 * attempted to be written.
172 cd18720a Anthony Liguori
 *
173 cd18720a Anthony Liguori
 * @buf the data
174 cd18720a Anthony Liguori
 * @len the number of bytes to send
175 cd18720a Anthony Liguori
 *
176 cd18720a Anthony Liguori
 * Returns: the number of bytes consumed
177 cd18720a Anthony Liguori
 */
178 cd18720a Anthony Liguori
int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len);
179 cd18720a Anthony Liguori
180 cd18720a Anthony Liguori
/**
181 2011fe56 Anthony Liguori
 * @qemu_chr_fe_ioctl:
182 2011fe56 Anthony Liguori
 *
183 2011fe56 Anthony Liguori
 * Issue a device specific ioctl to a backend.
184 2011fe56 Anthony Liguori
 *
185 2011fe56 Anthony Liguori
 * @cmd see CHR_IOCTL_*
186 2011fe56 Anthony Liguori
 * @arg the data associated with @cmd
187 2011fe56 Anthony Liguori
 *
188 2011fe56 Anthony Liguori
 * Returns: if @cmd is not supported by the backend, -ENOTSUP, otherwise the
189 2011fe56 Anthony Liguori
 *          return value depends on the semantics of @cmd
190 2011fe56 Anthony Liguori
 */
191 2011fe56 Anthony Liguori
int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg);
192 2011fe56 Anthony Liguori
193 2011fe56 Anthony Liguori
/**
194 2011fe56 Anthony Liguori
 * @qemu_chr_fe_get_msgfd:
195 2011fe56 Anthony Liguori
 *
196 2011fe56 Anthony Liguori
 * For backends capable of fd passing, return the latest file descriptor passed
197 2011fe56 Anthony Liguori
 * by a client.
198 2011fe56 Anthony Liguori
 *
199 2011fe56 Anthony Liguori
 * Returns: -1 if fd passing isn't supported or there is no pending file
200 2011fe56 Anthony Liguori
 *          descriptor.  If a file descriptor is returned, subsequent calls to
201 2011fe56 Anthony Liguori
 *          this function will return -1 until a client sends a new file
202 2011fe56 Anthony Liguori
 *          descriptor.
203 2011fe56 Anthony Liguori
 */
204 2011fe56 Anthony Liguori
int qemu_chr_fe_get_msgfd(CharDriverState *s);
205 2011fe56 Anthony Liguori
206 2011fe56 Anthony Liguori
/**
207 44c473de Hans de Goede
 * @qemu_chr_fe_claim:
208 44c473de Hans de Goede
 *
209 44c473de Hans de Goede
 * Claim a backend before using it, should be called before calling
210 44c473de Hans de Goede
 * qemu_chr_add_handlers(). 
211 44c473de Hans de Goede
 *
212 44c473de Hans de Goede
 * Returns: -1 if the backend is already in use by another frontend, 0 on
213 44c473de Hans de Goede
 *          success.
214 44c473de Hans de Goede
 */
215 44c473de Hans de Goede
int qemu_chr_fe_claim(CharDriverState *s);
216 44c473de Hans de Goede
217 44c473de Hans de Goede
/**
218 44c473de Hans de Goede
 * @qemu_chr_fe_claim_no_fail:
219 44c473de Hans de Goede
 *
220 44c473de Hans de Goede
 * Like qemu_chr_fe_claim, but will exit qemu with an error when the
221 44c473de Hans de Goede
 * backend is already in use.
222 44c473de Hans de Goede
 */
223 44c473de Hans de Goede
void qemu_chr_fe_claim_no_fail(CharDriverState *s);
224 44c473de Hans de Goede
225 44c473de Hans de Goede
/**
226 44c473de Hans de Goede
 * @qemu_chr_fe_claim:
227 44c473de Hans de Goede
 *
228 44c473de Hans de Goede
 * Release a backend for use by another frontend.
229 44c473de Hans de Goede
 *
230 44c473de Hans de Goede
 * Returns: -1 if the backend is already in use by another frontend, 0 on
231 44c473de Hans de Goede
 *          success.
232 44c473de Hans de Goede
 */
233 44c473de Hans de Goede
void qemu_chr_fe_release(CharDriverState *s);
234 44c473de Hans de Goede
235 44c473de Hans de Goede
/**
236 2011fe56 Anthony Liguori
 * @qemu_chr_be_can_write:
237 2011fe56 Anthony Liguori
 *
238 2011fe56 Anthony Liguori
 * Determine how much data the front end can currently accept.  This function
239 2011fe56 Anthony Liguori
 * returns the number of bytes the front end can accept.  If it returns 0, the
240 2011fe56 Anthony Liguori
 * front end cannot receive data at the moment.  The function must be polled
241 2011fe56 Anthony Liguori
 * to determine when data can be received.
242 2011fe56 Anthony Liguori
 *
243 2011fe56 Anthony Liguori
 * Returns: the number of bytes the front end can receive via @qemu_chr_be_write
244 2011fe56 Anthony Liguori
 */
245 2011fe56 Anthony Liguori
int qemu_chr_be_can_write(CharDriverState *s);
246 2011fe56 Anthony Liguori
247 2011fe56 Anthony Liguori
/**
248 2011fe56 Anthony Liguori
 * @qemu_chr_be_write:
249 2011fe56 Anthony Liguori
 *
250 2011fe56 Anthony Liguori
 * Write data from the back end to the front end.  Before issuing this call,
251 2011fe56 Anthony Liguori
 * the caller should call @qemu_chr_be_can_write to determine how much data
252 2011fe56 Anthony Liguori
 * the front end can currently accept.
253 2011fe56 Anthony Liguori
 *
254 2011fe56 Anthony Liguori
 * @buf a buffer to receive data from the front end
255 2011fe56 Anthony Liguori
 * @len the number of bytes to receive from the front end
256 2011fe56 Anthony Liguori
 */
257 2011fe56 Anthony Liguori
void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
258 2011fe56 Anthony Liguori
259 a425d23f Hans de Goede
260 a425d23f Hans de Goede
/**
261 a425d23f Hans de Goede
 * @qemu_chr_be_event:
262 a425d23f Hans de Goede
 *
263 a425d23f Hans de Goede
 * Send an event from the back end to the front end.
264 a425d23f Hans de Goede
 *
265 a425d23f Hans de Goede
 * @event the event to send
266 a425d23f Hans de Goede
 */
267 a425d23f Hans de Goede
void qemu_chr_be_event(CharDriverState *s, int event);
268 a425d23f Hans de Goede
269 87ecb68b pbrook
void qemu_chr_add_handlers(CharDriverState *s,
270 7b27a769 Juan Quintela
                           IOCanReadHandler *fd_can_read,
271 87ecb68b pbrook
                           IOReadHandler *fd_read,
272 87ecb68b pbrook
                           IOEventHandler *fd_event,
273 87ecb68b pbrook
                           void *opaque);
274 2011fe56 Anthony Liguori
275 fee204fd Hans de Goede
void qemu_chr_be_generic_open(CharDriverState *s);
276 bd9bdce6 balrog
void qemu_chr_accept_input(CharDriverState *s);
277 13661089 Daniel P. Berrange
int qemu_chr_add_client(CharDriverState *s, int fd);
278 588b3832 Luiz Capitulino
void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
279 588b3832 Luiz Capitulino
void qemu_chr_info(Monitor *mon, QObject **ret_data);
280 c845f401 Gerd Hoffmann
CharDriverState *qemu_chr_find(const char *name);
281 87ecb68b pbrook
282 2011fe56 Anthony Liguori
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
283 2011fe56 Anthony Liguori
284 d654f34e Anthony Liguori
void register_char_driver(const char *name, CharDriverState *(*open)(QemuOpts *));
285 99aec012 Gerd Hoffmann
void register_char_driver_qapi(const char *name, ChardevBackendKind kind,
286 2c5f4882 Gerd Hoffmann
        void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp));
287 d654f34e Anthony Liguori
288 6cbf4c8c Cam Macdonell
/* add an eventfd to the qemu devices that are polled */
289 6cbf4c8c Cam Macdonell
CharDriverState *qemu_chr_open_eventfd(int eventfd);
290 6cbf4c8c Cam Macdonell
291 0e82f34d aliguori
extern int term_escape_char;
292 0e82f34d aliguori
293 0beb4942 Anthony Liguori
CharDriverState *qemu_char_get_next_serial(void);
294 0beb4942 Anthony Liguori
295 f5a51cab Gerd Hoffmann
/* msmouse */
296 f5a51cab Gerd Hoffmann
CharDriverState *qemu_chr_open_msmouse(void);
297 f5a51cab Gerd Hoffmann
298 2d57286d Gerd Hoffmann
/* baum.c */
299 2d57286d Gerd Hoffmann
CharDriverState *chr_baum_init(void);
300 2d57286d Gerd Hoffmann
301 87ecb68b pbrook
#endif