4 #include "qemu-common.h"
5 #include "qemu/option.h"
6 #include "qemu/main-loop.h"
7 #include "qemu/bitmap.h"
8 #include "qom/object.h"
18 /* character device */
19 typedef struct CharBackend CharBackend
;
22 CHR_EVENT_BREAK
, /* serial break char */
23 CHR_EVENT_OPENED
, /* new connection established */
24 CHR_EVENT_MUX_IN
, /* mux-focus was set to this terminal */
25 CHR_EVENT_MUX_OUT
, /* mux-focus will move on */
26 CHR_EVENT_CLOSED
/* connection closed */
29 #define CHR_READ_BUF_LEN 4096
32 /* Whether the chardev peer is able to close and
33 * reopen the data channel, thus requiring support
34 * for qemu_chr_wait_connected() to wait for a
36 QEMU_CHAR_FEATURE_RECONNECTABLE
,
37 /* Whether it is possible to send/recv file descriptors
38 * over the data channel */
39 QEMU_CHAR_FEATURE_FD_PASS
,
40 /* Whether replay or record mode is enabled */
41 QEMU_CHAR_FEATURE_REPLAY
,
43 QEMU_CHAR_FEATURE_LAST
,
46 #define qemu_chr_replay(chr) qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_REPLAY)
51 QemuMutex chr_write_lock
;
58 DECLARE_BITMAP(features
, QEMU_CHAR_FEATURE_LAST
);
62 * @qemu_chr_new_from_opts:
64 * Create a new character backend from a QemuOpts list.
66 * @opts see qemu-config.c for a list of valid options
68 * Returns: a new character backend
70 Chardev
*qemu_chr_new_from_opts(QemuOpts
*opts
,
74 * @qemu_chr_parse_common:
76 * Parse the common options available to all character backends.
78 * @opts the options that still need parsing
79 * @backend a new backend
81 void qemu_chr_parse_common(QemuOpts
*opts
, ChardevCommon
*backend
);
86 * Create a new character backend from a URI.
88 * @label the name of the backend
91 * Returns: a new character backend
93 Chardev
*qemu_chr_new(const char *label
, const char *filename
);
98 * Delete all chardevs (when leaving qemu)
100 void qemu_chr_cleanup(void);
103 * @qemu_chr_new_noreplay:
105 * Create a new character backend from a URI.
106 * Character device communications are not written
107 * into the replay log.
109 * @label the name of the backend
112 * Returns: a new character backend
114 Chardev
*qemu_chr_new_noreplay(const char *label
, const char *filename
);
117 * @qemu_chr_be_can_write:
119 * Determine how much data the front end can currently accept. This function
120 * returns the number of bytes the front end can accept. If it returns 0, the
121 * front end cannot receive data at the moment. The function must be polled
122 * to determine when data can be received.
124 * Returns: the number of bytes the front end can receive via @qemu_chr_be_write
126 int qemu_chr_be_can_write(Chardev
*s
);
129 * @qemu_chr_be_write:
131 * Write data from the back end to the front end. Before issuing this call,
132 * the caller should call @qemu_chr_be_can_write to determine how much data
133 * the front end can currently accept.
135 * @buf a buffer to receive data from the front end
136 * @len the number of bytes to receive from the front end
138 void qemu_chr_be_write(Chardev
*s
, uint8_t *buf
, int len
);
141 * @qemu_chr_be_write_impl:
143 * Implementation of back end writing. Used by replay module.
145 * @buf a buffer to receive data from the front end
146 * @len the number of bytes to receive from the front end
148 void qemu_chr_be_write_impl(Chardev
*s
, uint8_t *buf
, int len
);
151 * @qemu_chr_be_event:
153 * Send an event from the back end to the front end.
155 * @event the event to send
157 void qemu_chr_be_event(Chardev
*s
, int event
);
159 int qemu_chr_add_client(Chardev
*s
, int fd
);
160 Chardev
*qemu_chr_find(const char *name
);
162 bool qemu_chr_has_feature(Chardev
*chr
,
163 ChardevFeature feature
);
164 void qemu_chr_set_feature(Chardev
*chr
,
165 ChardevFeature feature
);
166 QemuOpts
*qemu_chr_parse_compat(const char *label
, const char *filename
);
167 int qemu_chr_write(Chardev
*s
, const uint8_t *buf
, int len
, bool write_all
);
168 #define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len, true)
169 int qemu_chr_wait_connected(Chardev
*chr
, Error
**errp
);
171 #define TYPE_CHARDEV "chardev"
172 #define CHARDEV(obj) OBJECT_CHECK(Chardev, (obj), TYPE_CHARDEV)
173 #define CHARDEV_CLASS(klass) \
174 OBJECT_CLASS_CHECK(ChardevClass, (klass), TYPE_CHARDEV)
175 #define CHARDEV_GET_CLASS(obj) \
176 OBJECT_GET_CLASS(ChardevClass, (obj), TYPE_CHARDEV)
178 #define TYPE_CHARDEV_NULL "chardev-null"
179 #define TYPE_CHARDEV_MUX "chardev-mux"
180 #define TYPE_CHARDEV_RINGBUF "chardev-ringbuf"
181 #define TYPE_CHARDEV_PTY "chardev-pty"
182 #define TYPE_CHARDEV_CONSOLE "chardev-console"
183 #define TYPE_CHARDEV_STDIO "chardev-stdio"
184 #define TYPE_CHARDEV_PIPE "chardev-pipe"
185 #define TYPE_CHARDEV_MEMORY "chardev-memory"
186 #define TYPE_CHARDEV_PARALLEL "chardev-parallel"
187 #define TYPE_CHARDEV_FILE "chardev-file"
188 #define TYPE_CHARDEV_SERIAL "chardev-serial"
189 #define TYPE_CHARDEV_SOCKET "chardev-socket"
190 #define TYPE_CHARDEV_UDP "chardev-udp"
192 #define CHARDEV_IS_RINGBUF(chr) \
193 object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_RINGBUF)
194 #define CHARDEV_IS_PTY(chr) \
195 object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_PTY)
197 typedef struct ChardevClass
{
198 ObjectClass parent_class
;
200 bool internal
; /* TODO: eventually use TYPE_USER_CREATABLE */
201 void (*parse
)(QemuOpts
*opts
, ChardevBackend
*backend
, Error
**errp
);
203 void (*open
)(Chardev
*chr
, ChardevBackend
*backend
,
204 bool *be_opened
, Error
**errp
);
206 int (*chr_write
)(Chardev
*s
, const uint8_t *buf
, int len
);
207 int (*chr_sync_read
)(Chardev
*s
, const uint8_t *buf
, int len
);
208 GSource
*(*chr_add_watch
)(Chardev
*s
, GIOCondition cond
);
209 void (*chr_update_read_handler
)(Chardev
*s
, GMainContext
*context
);
210 int (*chr_ioctl
)(Chardev
*s
, int cmd
, void *arg
);
211 int (*get_msgfds
)(Chardev
*s
, int* fds
, int num
);
212 int (*set_msgfds
)(Chardev
*s
, int *fds
, int num
);
213 int (*chr_add_client
)(Chardev
*chr
, int fd
);
214 int (*chr_wait_connected
)(Chardev
*chr
, Error
**errp
);
215 void (*chr_disconnect
)(Chardev
*chr
);
216 void (*chr_accept_input
)(Chardev
*chr
);
217 void (*chr_set_echo
)(Chardev
*chr
, bool echo
);
218 void (*chr_set_fe_open
)(Chardev
*chr
, int fe_open
);
221 Chardev
*qemu_chardev_new(const char *id
, const char *typename
,
222 ChardevBackend
*backend
, Error
**errp
);
224 extern int term_escape_char
;
227 void qemu_chr_parse_vc(QemuOpts
*opts
, ChardevBackend
*backend
, Error
**errp
);