]> git.proxmox.com Git - qemu.git/blame - qemu-char.h
VMDK: enable twoGbMaxExtentFlat
[qemu.git] / qemu-char.h
CommitLineData
87ecb68b
PB
1#ifndef QEMU_CHAR_H
2#define QEMU_CHAR_H
3
376253ec 4#include "qemu-common.h"
72cf2d4f 5#include "qemu-queue.h"
191bc01b
GH
6#include "qemu-option.h"
7#include "qemu-config.h"
588b3832 8#include "qobject.h"
999bd67c 9#include "qstring.h"
376253ec 10
87ecb68b
PB
11/* character device */
12
2724b180
AL
13#define CHR_EVENT_BREAK 0 /* serial break char */
14#define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
b6b8df56 15#define CHR_EVENT_OPENED 2 /* new connection established */
2724b180
AL
16#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 */
793cbfb5 18#define CHR_EVENT_CLOSED 5 /* connection closed */
87ecb68b
PB
19
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
563e3c6e 40#define CHR_IOCTL_PP_DATA_DIR 12
87ecb68b 41
f0664048
AJ
42#define CHR_IOCTL_SERIAL_SET_TIOCM 13
43#define CHR_IOCTL_SERIAL_GET_TIOCM 14
81174dae
AL
44
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
87ecb68b
PB
52typedef void IOEventHandler(void *opaque, int event);
53
54struct CharDriverState {
ceecf1d1 55 void (*init)(struct CharDriverState *s);
87ecb68b
PB
56 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);
7d174059 59 int (*get_msgfd)(struct CharDriverState *s);
13661089 60 int (*chr_add_client)(struct CharDriverState *chr, int fd);
87ecb68b 61 IOEventHandler *chr_event;
7b27a769 62 IOCanReadHandler *chr_can_read;
87ecb68b
PB
63 IOReadHandler *chr_read;
64 void *handler_opaque;
87ecb68b 65 void (*chr_close)(struct CharDriverState *chr);
bd9bdce6 66 void (*chr_accept_input)(struct CharDriverState *chr);
c48855e1 67 void (*chr_set_echo)(struct CharDriverState *chr, bool echo);
7c32c4fe
HG
68 void (*chr_guest_open)(struct CharDriverState *chr);
69 void (*chr_guest_close)(struct CharDriverState *chr);
87ecb68b 70 void *opaque;
87ecb68b 71 QEMUBH *bh;
5ccfae10
AL
72 char *label;
73 char *filename;
73cdf3f2 74 int opened;
d5b27167 75 int avail_connections;
72cf2d4f 76 QTAILQ_ENTRY(CharDriverState) next;
87ecb68b
PB
77};
78
2011fe56
AL
79/**
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 */
f69554b9 89CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
191bc01b 90 void (*init)(struct CharDriverState *s));
2011fe56
AL
91
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 */
111void qemu_chr_delete(CharDriverState *chr);
112
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 */
15f31519 122void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo);
2011fe56
AL
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 */
c9d830ed 130void qemu_chr_fe_open(struct CharDriverState *chr);
2011fe56
AL
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 */
2817822d 139void qemu_chr_fe_close(struct CharDriverState *chr);
2011fe56
AL
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 */
e7e71b0e 148void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
8b7968f7 149 GCC_FMT_ATTR(2, 3);
2011fe56
AL
150
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 */
2cc6e0a1 162int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len);
2011fe56
AL
163
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
87ecb68b 214void qemu_chr_add_handlers(CharDriverState *s,
7b27a769 215 IOCanReadHandler *fd_can_read,
87ecb68b
PB
216 IOReadHandler *fd_read,
217 IOEventHandler *fd_event,
218 void *opaque);
2011fe56 219
127338e6 220void qemu_chr_generic_open(CharDriverState *s);
bd9bdce6 221void qemu_chr_accept_input(CharDriverState *s);
13661089 222int qemu_chr_add_client(CharDriverState *s, int fd);
588b3832
LC
223void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
224void qemu_chr_info(Monitor *mon, QObject **ret_data);
c845f401 225CharDriverState *qemu_chr_find(const char *name);
87ecb68b 226
2011fe56
AL
227QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
228
6cbf4c8c
CM
229/* add an eventfd to the qemu devices that are polled */
230CharDriverState *qemu_chr_open_eventfd(int eventfd);
231
0e82f34d
AL
232extern int term_escape_char;
233
999bd67c
LC
234/* 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
87ecb68b
PB
240/* async I/O support */
241
242int qemu_set_fd_handler2(int fd,
7b27a769 243 IOCanReadHandler *fd_read_poll,
87ecb68b
PB
244 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);
87ecb68b 251#endif