blob: eebbdd8f019f611a39fe0abd70c98043c1702dac [file] [log] [blame]
pbrook87ecb682007-11-17 17:14:51 +00001#ifndef QEMU_CHAR_H
2#define QEMU_CHAR_H
3
aliguori376253e2009-03-05 23:01:23 +00004#include "qemu-common.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +00005#include "qemu-queue.h"
Gerd Hoffmann191bc012009-09-10 10:58:35 +02006#include "qemu-option.h"
7#include "qemu-config.h"
Luiz Capitulino588b3832009-12-10 17:16:08 -02008#include "qobject.h"
Luiz Capitulino999bd672010-10-22 16:09:05 -02009#include "qstring.h"
aliguori376253e2009-03-05 23:01:23 +000010
pbrook87ecb682007-11-17 17:14:51 +000011/* character device */
12
aliguori2724b182009-03-05 23:01:47 +000013#define CHR_EVENT_BREAK 0 /* serial break char */
14#define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
Amit Shahb6b8df52009-10-07 18:31:16 +053015#define CHR_EVENT_OPENED 2 /* new connection established */
aliguori2724b182009-03-05 23:01:47 +000016#define CHR_EVENT_MUX_IN 3 /* mux-focus was set to this terminal */
17#define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */
Amit Shah793cbfb2009-08-11 21:27:48 +053018#define CHR_EVENT_CLOSED 5 /* connection closed */
pbrook87ecb682007-11-17 17:14:51 +000019
20
21#define CHR_IOCTL_SERIAL_SET_PARAMS 1
22typedef struct {
23 int speed;
24 int parity;
25 int data_bits;
26 int stop_bits;
27} QEMUSerialSetParams;
28
29#define CHR_IOCTL_SERIAL_SET_BREAK 2
30
31#define CHR_IOCTL_PP_READ_DATA 3
32#define CHR_IOCTL_PP_WRITE_DATA 4
33#define CHR_IOCTL_PP_READ_CONTROL 5
34#define CHR_IOCTL_PP_WRITE_CONTROL 6
35#define CHR_IOCTL_PP_READ_STATUS 7
36#define CHR_IOCTL_PP_EPP_READ_ADDR 8
37#define CHR_IOCTL_PP_EPP_READ 9
38#define CHR_IOCTL_PP_EPP_WRITE_ADDR 10
39#define CHR_IOCTL_PP_EPP_WRITE 11
aurel32563e3c62008-08-22 08:57:09 +000040#define CHR_IOCTL_PP_DATA_DIR 12
pbrook87ecb682007-11-17 17:14:51 +000041
aurel32f0664042008-08-22 21:25:00 +000042#define CHR_IOCTL_SERIAL_SET_TIOCM 13
43#define CHR_IOCTL_SERIAL_GET_TIOCM 14
aliguori81174da2008-08-11 14:17:04 +000044
45#define CHR_TIOCM_CTS 0x020
46#define CHR_TIOCM_CAR 0x040
47#define CHR_TIOCM_DSR 0x100
48#define CHR_TIOCM_RI 0x080
49#define CHR_TIOCM_DTR 0x002
50#define CHR_TIOCM_RTS 0x004
51
pbrook87ecb682007-11-17 17:14:51 +000052typedef void IOEventHandler(void *opaque, int event);
53
54struct CharDriverState {
aurel32ceecf1d2009-01-18 14:08:04 +000055 void (*init)(struct CharDriverState *s);
pbrook87ecb682007-11-17 17:14:51 +000056 int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
57 void (*chr_update_read_handler)(struct CharDriverState *s);
58 int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
Mark McLoughlin7d174052009-07-22 09:11:39 +010059 int (*get_msgfd)(struct CharDriverState *s);
Daniel P. Berrange13661082011-06-23 13:31:42 +010060 int (*chr_add_client)(struct CharDriverState *chr, int fd);
pbrook87ecb682007-11-17 17:14:51 +000061 IOEventHandler *chr_event;
Juan Quintela7b27a762010-03-11 17:55:39 +010062 IOCanReadHandler *chr_can_read;
pbrook87ecb682007-11-17 17:14:51 +000063 IOReadHandler *chr_read;
64 void *handler_opaque;
pbrook87ecb682007-11-17 17:14:51 +000065 void (*chr_close)(struct CharDriverState *chr);
balrogbd9bdce2007-11-25 00:55:06 +000066 void (*chr_accept_input)(struct CharDriverState *chr);
Paolo Bonzinic48855e2010-12-23 13:42:48 +010067 void (*chr_set_echo)(struct CharDriverState *chr, bool echo);
Hans de Goede7c32c4f2011-03-24 11:12:02 +010068 void (*chr_guest_open)(struct CharDriverState *chr);
69 void (*chr_guest_close)(struct CharDriverState *chr);
pbrook87ecb682007-11-17 17:14:51 +000070 void *opaque;
pbrook87ecb682007-11-17 17:14:51 +000071 QEMUBH *bh;
aliguori5ccfae12008-10-31 17:31:29 +000072 char *label;
73 char *filename;
Alexander Graf73cdf3f2010-04-01 18:42:39 +020074 int opened;
Kusanagi Kouichid5b27162011-04-26 19:19:26 +090075 int avail_connections;
Blue Swirl72cf2d42009-09-12 07:36:22 +000076 QTAILQ_ENTRY(CharDriverState) next;
pbrook87ecb682007-11-17 17:14:51 +000077};
78
Anthony Liguori2011fe52011-08-15 11:17:41 -050079/**
80 * @qemu_chr_new_from_opts:
81 *
82 * Create a new character backend from a QemuOpts list.
83 *
84 * @opts see qemu-config.c for a list of valid options
85 * @init not sure..
86 *
87 * Returns: a new character backend
88 */
Anthony Liguorif69554b2011-08-15 11:17:37 -050089CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
Gerd Hoffmann191bc012009-09-10 10:58:35 +020090 void (*init)(struct CharDriverState *s));
Anthony Liguori2011fe52011-08-15 11:17:41 -050091
92/**
93 * @qemu_chr_new:
94 *
95 * Create a new character backend from a URI.
96 *
97 * @label the name of the backend
98 * @filename the URI
99 * @init not sure..
100 *
101 * Returns: a new character backend
102 */
103CharDriverState *qemu_chr_new(const char *label, const char *filename,
104 void (*init)(struct CharDriverState *s));
105
106/**
107 * @qemu_chr_delete:
108 *
109 * Destroy a character backend.
110 */
Anthony Liguori70f24fb2011-08-15 11:17:38 -0500111void qemu_chr_delete(CharDriverState *chr);
Anthony Liguori2011fe52011-08-15 11:17:41 -0500112
113/**
114 * @qemu_chr_fe_set_echo:
115 *
116 * Ask the backend to override its normal echo setting. This only really
117 * applies to the stdio backend and is used by the QMP server such that you
118 * can see what you type if you try to type QMP commands.
119 *
120 * @echo true to enable echo, false to disable echo
121 */
122void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo);
123
124/**
125 * @qemu_chr_fe_open:
126 *
127 * Open a character backend. This function call is an indication that the
128 * front end is ready to begin doing I/O.
129 */
130void qemu_chr_fe_open(struct CharDriverState *chr);
131
132/**
133 * @qemu_chr_fe_close:
134 *
135 * Close a character backend. This function call indicates that the front end
136 * no longer is able to process I/O. To process I/O again, the front end will
137 * call @qemu_chr_fe_open.
138 */
139void qemu_chr_fe_close(struct CharDriverState *chr);
140
141/**
142 * @qemu_chr_fe_printf:
143 *
144 * Write to a character backend using a printf style interface.
145 *
146 * @fmt see #printf
147 */
Anthony Liguorie7e71b02011-08-15 11:17:29 -0500148void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
Stefan Weil8b7968f2010-09-23 21:28:05 +0200149 GCC_FMT_ATTR(2, 3);
Anthony Liguori2011fe52011-08-15 11:17:41 -0500150
151/**
152 * @qemu_chr_fe_write:
153 *
154 * Write data to a character backend from the front end. This function will
155 * send data from the front end to the back end.
156 *
157 * @buf the data
158 * @len the number of bytes to send
159 *
160 * Returns: the number of bytes consumed
161 */
Anthony Liguori2cc6e0a2011-08-15 11:17:28 -0500162int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len);
Anthony Liguori2011fe52011-08-15 11:17:41 -0500163
164/**
165 * @qemu_chr_fe_ioctl:
166 *
167 * Issue a device specific ioctl to a backend.
168 *
169 * @cmd see CHR_IOCTL_*
170 * @arg the data associated with @cmd
171 *
172 * Returns: if @cmd is not supported by the backend, -ENOTSUP, otherwise the
173 * return value depends on the semantics of @cmd
174 */
175int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg);
176
177/**
178 * @qemu_chr_fe_get_msgfd:
179 *
180 * For backends capable of fd passing, return the latest file descriptor passed
181 * by a client.
182 *
183 * Returns: -1 if fd passing isn't supported or there is no pending file
184 * descriptor. If a file descriptor is returned, subsequent calls to
185 * this function will return -1 until a client sends a new file
186 * descriptor.
187 */
188int qemu_chr_fe_get_msgfd(CharDriverState *s);
189
190/**
191 * @qemu_chr_be_can_write:
192 *
193 * Determine how much data the front end can currently accept. This function
194 * returns the number of bytes the front end can accept. If it returns 0, the
195 * front end cannot receive data at the moment. The function must be polled
196 * to determine when data can be received.
197 *
198 * Returns: the number of bytes the front end can receive via @qemu_chr_be_write
199 */
200int qemu_chr_be_can_write(CharDriverState *s);
201
202/**
203 * @qemu_chr_be_write:
204 *
205 * Write data from the back end to the front end. Before issuing this call,
206 * the caller should call @qemu_chr_be_can_write to determine how much data
207 * the front end can currently accept.
208 *
209 * @buf a buffer to receive data from the front end
210 * @len the number of bytes to receive from the front end
211 */
212void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
213
pbrook87ecb682007-11-17 17:14:51 +0000214void qemu_chr_add_handlers(CharDriverState *s,
Juan Quintela7b27a762010-03-11 17:55:39 +0100215 IOCanReadHandler *fd_can_read,
pbrook87ecb682007-11-17 17:14:51 +0000216 IOReadHandler *fd_read,
217 IOEventHandler *fd_event,
218 void *opaque);
Anthony Liguori2011fe52011-08-15 11:17:41 -0500219
Amit Shah127338e2009-11-03 19:59:56 +0530220void qemu_chr_generic_open(CharDriverState *s);
balrogbd9bdce2007-11-25 00:55:06 +0000221void qemu_chr_accept_input(CharDriverState *s);
Daniel P. Berrange13661082011-06-23 13:31:42 +0100222int qemu_chr_add_client(CharDriverState *s, int fd);
Luiz Capitulino588b3832009-12-10 17:16:08 -0200223void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
224void qemu_chr_info(Monitor *mon, QObject **ret_data);
Gerd Hoffmannc845f402009-09-10 10:58:52 +0200225CharDriverState *qemu_chr_find(const char *name);
pbrook87ecb682007-11-17 17:14:51 +0000226
Anthony Liguori2011fe52011-08-15 11:17:41 -0500227QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
228
Cam Macdonell6cbf4c82010-07-27 10:54:13 -0600229/* add an eventfd to the qemu devices that are polled */
230CharDriverState *qemu_chr_open_eventfd(int eventfd);
231
aliguori0e82f342008-10-31 18:44:40 +0000232extern int term_escape_char;
233
Luiz Capitulino999bd672010-10-22 16:09:05 -0200234/* memory chardev */
235void qemu_chr_init_mem(CharDriverState *chr);
236void qemu_chr_close_mem(CharDriverState *chr);
237QString *qemu_chr_mem_to_qs(CharDriverState *chr);
238size_t qemu_chr_mem_osize(const CharDriverState *chr);
239
pbrook87ecb682007-11-17 17:14:51 +0000240/* async I/O support */
241
242int qemu_set_fd_handler2(int fd,
Juan Quintela7b27a762010-03-11 17:55:39 +0100243 IOCanReadHandler *fd_read_poll,
pbrook87ecb682007-11-17 17:14:51 +0000244 IOHandler *fd_read,
245 IOHandler *fd_write,
246 void *opaque);
247int qemu_set_fd_handler(int fd,
248 IOHandler *fd_read,
249 IOHandler *fd_write,
250 void *opaque);
pbrook87ecb682007-11-17 17:14:51 +0000251#endif