Statistics
| Branch: | Revision:

root / include / char / char.h @ 5cc11c46

History | View | Annotate | Download (8 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 7c32c4fe Hans de Goede
    void (*chr_guest_open)(struct CharDriverState *chr);
72 7c32c4fe Hans de Goede
    void (*chr_guest_close)(struct CharDriverState *chr);
73 87ecb68b pbrook
    void *opaque;
74 9f939df9 Anthony Liguori
    int idle_tag;
75 5ccfae10 aliguori
    char *label;
76 5ccfae10 aliguori
    char *filename;
77 73cdf3f2 Alexander Graf
    int opened;
78 d5b27167 Kusanagi Kouichi
    int avail_connections;
79 2274ae9d Gerd Hoffmann
    QemuOpts *opts;
80 72cf2d4f Blue Swirl
    QTAILQ_ENTRY(CharDriverState) next;
81 87ecb68b pbrook
};
82 87ecb68b pbrook
83 2011fe56 Anthony Liguori
/**
84 2011fe56 Anthony Liguori
 * @qemu_chr_new_from_opts:
85 2011fe56 Anthony Liguori
 *
86 2011fe56 Anthony Liguori
 * Create a new character backend from a QemuOpts list.
87 2011fe56 Anthony Liguori
 *
88 2011fe56 Anthony Liguori
 * @opts see qemu-config.c for a list of valid options
89 2011fe56 Anthony Liguori
 * @init not sure..
90 2011fe56 Anthony Liguori
 *
91 2011fe56 Anthony Liguori
 * Returns: a new character backend
92 2011fe56 Anthony Liguori
 */
93 f69554b9 Anthony Liguori
CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
94 bd2d80b2 Gerd Hoffmann
                                    void (*init)(struct CharDriverState *s),
95 bd2d80b2 Gerd Hoffmann
                                    Error **errp);
96 2011fe56 Anthony Liguori
97 2011fe56 Anthony Liguori
/**
98 2011fe56 Anthony Liguori
 * @qemu_chr_new:
99 2011fe56 Anthony Liguori
 *
100 2011fe56 Anthony Liguori
 * Create a new character backend from a URI.
101 2011fe56 Anthony Liguori
 *
102 2011fe56 Anthony Liguori
 * @label the name of the backend
103 2011fe56 Anthony Liguori
 * @filename the URI
104 2011fe56 Anthony Liguori
 * @init not sure..
105 2011fe56 Anthony Liguori
 *
106 2011fe56 Anthony Liguori
 * Returns: a new character backend
107 2011fe56 Anthony Liguori
 */
108 2011fe56 Anthony Liguori
CharDriverState *qemu_chr_new(const char *label, const char *filename,
109 2011fe56 Anthony Liguori
                              void (*init)(struct CharDriverState *s));
110 2011fe56 Anthony Liguori
111 2011fe56 Anthony Liguori
/**
112 2011fe56 Anthony Liguori
 * @qemu_chr_delete:
113 2011fe56 Anthony Liguori
 *
114 2011fe56 Anthony Liguori
 * Destroy a character backend.
115 2011fe56 Anthony Liguori
 */
116 2011fe56 Anthony Liguori
void qemu_chr_delete(CharDriverState *chr);
117 2011fe56 Anthony Liguori
118 2011fe56 Anthony Liguori
/**
119 2011fe56 Anthony Liguori
 * @qemu_chr_fe_set_echo:
120 2011fe56 Anthony Liguori
 *
121 2011fe56 Anthony Liguori
 * Ask the backend to override its normal echo setting.  This only really
122 2011fe56 Anthony Liguori
 * applies to the stdio backend and is used by the QMP server such that you
123 2011fe56 Anthony Liguori
 * can see what you type if you try to type QMP commands.
124 2011fe56 Anthony Liguori
 *
125 2011fe56 Anthony Liguori
 * @echo true to enable echo, false to disable echo
126 2011fe56 Anthony Liguori
 */
127 15f31519 Anthony Liguori
void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo);
128 2011fe56 Anthony Liguori
129 2011fe56 Anthony Liguori
/**
130 2011fe56 Anthony Liguori
 * @qemu_chr_fe_open:
131 2011fe56 Anthony Liguori
 *
132 2011fe56 Anthony Liguori
 * Open a character backend.  This function call is an indication that the
133 2011fe56 Anthony Liguori
 * front end is ready to begin doing I/O.
134 2011fe56 Anthony Liguori
 */
135 c9d830ed Anthony Liguori
void qemu_chr_fe_open(struct CharDriverState *chr);
136 2011fe56 Anthony Liguori
137 2011fe56 Anthony Liguori
/**
138 2011fe56 Anthony Liguori
 * @qemu_chr_fe_close:
139 2011fe56 Anthony Liguori
 *
140 2011fe56 Anthony Liguori
 * Close a character backend.  This function call indicates that the front end
141 2011fe56 Anthony Liguori
 * no longer is able to process I/O.  To process I/O again, the front end will
142 2011fe56 Anthony Liguori
 * call @qemu_chr_fe_open.
143 2011fe56 Anthony Liguori
 */
144 2817822d Anthony Liguori
void qemu_chr_fe_close(struct CharDriverState *chr);
145 2011fe56 Anthony Liguori
146 2011fe56 Anthony Liguori
/**
147 2011fe56 Anthony Liguori
 * @qemu_chr_fe_printf:
148 2011fe56 Anthony Liguori
 *
149 2011fe56 Anthony Liguori
 * Write to a character backend using a printf style interface.
150 2011fe56 Anthony Liguori
 *
151 2011fe56 Anthony Liguori
 * @fmt see #printf
152 2011fe56 Anthony Liguori
 */
153 e7e71b0e Anthony Liguori
void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
154 8b7968f7 Stefan Weil
    GCC_FMT_ATTR(2, 3);
155 2011fe56 Anthony Liguori
156 2c8a5942 Kevin Wolf
int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
157 2c8a5942 Kevin Wolf
                          GIOFunc func, void *user_data);
158 23673ca7 Anthony Liguori
159 2011fe56 Anthony Liguori
/**
160 2011fe56 Anthony Liguori
 * @qemu_chr_fe_write:
161 2011fe56 Anthony Liguori
 *
162 2011fe56 Anthony Liguori
 * Write data to a character backend from the front end.  This function will
163 2011fe56 Anthony Liguori
 * send data from the front end to the back end.
164 2011fe56 Anthony Liguori
 *
165 2011fe56 Anthony Liguori
 * @buf the data
166 2011fe56 Anthony Liguori
 * @len the number of bytes to send
167 2011fe56 Anthony Liguori
 *
168 2011fe56 Anthony Liguori
 * Returns: the number of bytes consumed
169 2011fe56 Anthony Liguori
 */
170 2cc6e0a1 Anthony Liguori
int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len);
171 2011fe56 Anthony Liguori
172 2011fe56 Anthony Liguori
/**
173 2011fe56 Anthony Liguori
 * @qemu_chr_fe_ioctl:
174 2011fe56 Anthony Liguori
 *
175 2011fe56 Anthony Liguori
 * Issue a device specific ioctl to a backend.
176 2011fe56 Anthony Liguori
 *
177 2011fe56 Anthony Liguori
 * @cmd see CHR_IOCTL_*
178 2011fe56 Anthony Liguori
 * @arg the data associated with @cmd
179 2011fe56 Anthony Liguori
 *
180 2011fe56 Anthony Liguori
 * Returns: if @cmd is not supported by the backend, -ENOTSUP, otherwise the
181 2011fe56 Anthony Liguori
 *          return value depends on the semantics of @cmd
182 2011fe56 Anthony Liguori
 */
183 2011fe56 Anthony Liguori
int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg);
184 2011fe56 Anthony Liguori
185 2011fe56 Anthony Liguori
/**
186 2011fe56 Anthony Liguori
 * @qemu_chr_fe_get_msgfd:
187 2011fe56 Anthony Liguori
 *
188 2011fe56 Anthony Liguori
 * For backends capable of fd passing, return the latest file descriptor passed
189 2011fe56 Anthony Liguori
 * by a client.
190 2011fe56 Anthony Liguori
 *
191 2011fe56 Anthony Liguori
 * Returns: -1 if fd passing isn't supported or there is no pending file
192 2011fe56 Anthony Liguori
 *          descriptor.  If a file descriptor is returned, subsequent calls to
193 2011fe56 Anthony Liguori
 *          this function will return -1 until a client sends a new file
194 2011fe56 Anthony Liguori
 *          descriptor.
195 2011fe56 Anthony Liguori
 */
196 2011fe56 Anthony Liguori
int qemu_chr_fe_get_msgfd(CharDriverState *s);
197 2011fe56 Anthony Liguori
198 2011fe56 Anthony Liguori
/**
199 2011fe56 Anthony Liguori
 * @qemu_chr_be_can_write:
200 2011fe56 Anthony Liguori
 *
201 2011fe56 Anthony Liguori
 * Determine how much data the front end can currently accept.  This function
202 2011fe56 Anthony Liguori
 * returns the number of bytes the front end can accept.  If it returns 0, the
203 2011fe56 Anthony Liguori
 * front end cannot receive data at the moment.  The function must be polled
204 2011fe56 Anthony Liguori
 * to determine when data can be received.
205 2011fe56 Anthony Liguori
 *
206 2011fe56 Anthony Liguori
 * Returns: the number of bytes the front end can receive via @qemu_chr_be_write
207 2011fe56 Anthony Liguori
 */
208 2011fe56 Anthony Liguori
int qemu_chr_be_can_write(CharDriverState *s);
209 2011fe56 Anthony Liguori
210 2011fe56 Anthony Liguori
/**
211 2011fe56 Anthony Liguori
 * @qemu_chr_be_write:
212 2011fe56 Anthony Liguori
 *
213 2011fe56 Anthony Liguori
 * Write data from the back end to the front end.  Before issuing this call,
214 2011fe56 Anthony Liguori
 * the caller should call @qemu_chr_be_can_write to determine how much data
215 2011fe56 Anthony Liguori
 * the front end can currently accept.
216 2011fe56 Anthony Liguori
 *
217 2011fe56 Anthony Liguori
 * @buf a buffer to receive data from the front end
218 2011fe56 Anthony Liguori
 * @len the number of bytes to receive from the front end
219 2011fe56 Anthony Liguori
 */
220 2011fe56 Anthony Liguori
void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
221 2011fe56 Anthony Liguori
222 a425d23f Hans de Goede
223 a425d23f Hans de Goede
/**
224 a425d23f Hans de Goede
 * @qemu_chr_be_event:
225 a425d23f Hans de Goede
 *
226 a425d23f Hans de Goede
 * Send an event from the back end to the front end.
227 a425d23f Hans de Goede
 *
228 a425d23f Hans de Goede
 * @event the event to send
229 a425d23f Hans de Goede
 */
230 a425d23f Hans de Goede
void qemu_chr_be_event(CharDriverState *s, int event);
231 a425d23f Hans de Goede
232 87ecb68b pbrook
void qemu_chr_add_handlers(CharDriverState *s,
233 7b27a769 Juan Quintela
                           IOCanReadHandler *fd_can_read,
234 87ecb68b pbrook
                           IOReadHandler *fd_read,
235 87ecb68b pbrook
                           IOEventHandler *fd_event,
236 87ecb68b pbrook
                           void *opaque);
237 2011fe56 Anthony Liguori
238 127338e6 Amit Shah
void qemu_chr_generic_open(CharDriverState *s);
239 bd9bdce6 balrog
void qemu_chr_accept_input(CharDriverState *s);
240 13661089 Daniel P. Berrange
int qemu_chr_add_client(CharDriverState *s, int fd);
241 588b3832 Luiz Capitulino
void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
242 588b3832 Luiz Capitulino
void qemu_chr_info(Monitor *mon, QObject **ret_data);
243 c845f401 Gerd Hoffmann
CharDriverState *qemu_chr_find(const char *name);
244 87ecb68b pbrook
245 2011fe56 Anthony Liguori
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
246 2011fe56 Anthony Liguori
247 d654f34e Anthony Liguori
void register_char_driver(const char *name, CharDriverState *(*open)(QemuOpts *));
248 2c5f4882 Gerd Hoffmann
void register_char_driver_qapi(const char *name, int kind,
249 2c5f4882 Gerd Hoffmann
        void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp));
250 d654f34e Anthony Liguori
251 6cbf4c8c Cam Macdonell
/* add an eventfd to the qemu devices that are polled */
252 6cbf4c8c Cam Macdonell
CharDriverState *qemu_chr_open_eventfd(int eventfd);
253 6cbf4c8c Cam Macdonell
254 0e82f34d aliguori
extern int term_escape_char;
255 0e82f34d aliguori
256 999bd67c Luiz Capitulino
/* memory chardev */
257 999bd67c Luiz Capitulino
void qemu_chr_init_mem(CharDriverState *chr);
258 999bd67c Luiz Capitulino
void qemu_chr_close_mem(CharDriverState *chr);
259 999bd67c Luiz Capitulino
QString *qemu_chr_mem_to_qs(CharDriverState *chr);
260 999bd67c Luiz Capitulino
size_t qemu_chr_mem_osize(const CharDriverState *chr);
261 999bd67c Luiz Capitulino
262 0beb4942 Anthony Liguori
CharDriverState *qemu_char_get_next_serial(void);
263 0beb4942 Anthony Liguori
264 f5a51cab Gerd Hoffmann
/* msmouse */
265 f5a51cab Gerd Hoffmann
CharDriverState *qemu_chr_open_msmouse(void);
266 f5a51cab Gerd Hoffmann
267 2d57286d Gerd Hoffmann
/* baum.c */
268 2d57286d Gerd Hoffmann
CharDriverState *chr_baum_init(void);
269 2d57286d Gerd Hoffmann
270 87ecb68b pbrook
#endif