Statistics
| Branch: | Revision:

root / qemu-char.h @ c2162a8b

History | View | Annotate | Download (7.5 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 72cf2d4f Blue Swirl
#include "qemu-queue.h"
6 191bc01b Gerd Hoffmann
#include "qemu-option.h"
7 191bc01b Gerd Hoffmann
#include "qemu-config.h"
8 588b3832 Luiz Capitulino
#include "qobject.h"
9 999bd67c Luiz Capitulino
#include "qstring.h"
10 376253ec aliguori
11 87ecb68b pbrook
/* character device */
12 87ecb68b pbrook
13 2724b180 aliguori
#define CHR_EVENT_BREAK   0 /* serial break char */
14 2724b180 aliguori
#define CHR_EVENT_FOCUS   1 /* focus to this terminal (modal input needed) */
15 b6b8df56 Amit Shah
#define CHR_EVENT_OPENED  2 /* new connection established */
16 2724b180 aliguori
#define CHR_EVENT_MUX_IN  3 /* mux-focus was set to this terminal */
17 2724b180 aliguori
#define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */
18 793cbfb5 Amit Shah
#define CHR_EVENT_CLOSED  5 /* connection closed */
19 87ecb68b pbrook
20 87ecb68b pbrook
21 87ecb68b pbrook
#define CHR_IOCTL_SERIAL_SET_PARAMS   1
22 87ecb68b pbrook
typedef struct {
23 87ecb68b pbrook
    int speed;
24 87ecb68b pbrook
    int parity;
25 87ecb68b pbrook
    int data_bits;
26 87ecb68b pbrook
    int stop_bits;
27 87ecb68b pbrook
} QEMUSerialSetParams;
28 87ecb68b pbrook
29 87ecb68b pbrook
#define CHR_IOCTL_SERIAL_SET_BREAK    2
30 87ecb68b pbrook
31 87ecb68b pbrook
#define CHR_IOCTL_PP_READ_DATA        3
32 87ecb68b pbrook
#define CHR_IOCTL_PP_WRITE_DATA       4
33 87ecb68b pbrook
#define CHR_IOCTL_PP_READ_CONTROL     5
34 87ecb68b pbrook
#define CHR_IOCTL_PP_WRITE_CONTROL    6
35 87ecb68b pbrook
#define CHR_IOCTL_PP_READ_STATUS      7
36 87ecb68b pbrook
#define CHR_IOCTL_PP_EPP_READ_ADDR    8
37 87ecb68b pbrook
#define CHR_IOCTL_PP_EPP_READ         9
38 87ecb68b pbrook
#define CHR_IOCTL_PP_EPP_WRITE_ADDR  10
39 87ecb68b pbrook
#define CHR_IOCTL_PP_EPP_WRITE       11
40 563e3c6e aurel32
#define CHR_IOCTL_PP_DATA_DIR        12
41 87ecb68b pbrook
42 f0664048 aurel32
#define CHR_IOCTL_SERIAL_SET_TIOCM   13
43 f0664048 aurel32
#define CHR_IOCTL_SERIAL_GET_TIOCM   14
44 81174dae aliguori
45 81174dae aliguori
#define CHR_TIOCM_CTS        0x020
46 81174dae aliguori
#define CHR_TIOCM_CAR        0x040
47 81174dae aliguori
#define CHR_TIOCM_DSR        0x100
48 81174dae aliguori
#define CHR_TIOCM_RI        0x080
49 81174dae aliguori
#define CHR_TIOCM_DTR        0x002
50 81174dae aliguori
#define CHR_TIOCM_RTS        0x004
51 81174dae aliguori
52 87ecb68b pbrook
typedef void IOEventHandler(void *opaque, int event);
53 87ecb68b pbrook
54 87ecb68b pbrook
struct CharDriverState {
55 ceecf1d1 aurel32
    void (*init)(struct CharDriverState *s);
56 87ecb68b pbrook
    int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
57 87ecb68b pbrook
    void (*chr_update_read_handler)(struct CharDriverState *s);
58 87ecb68b pbrook
    int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
59 7d174059 Mark McLoughlin
    int (*get_msgfd)(struct CharDriverState *s);
60 13661089 Daniel P. Berrange
    int (*chr_add_client)(struct CharDriverState *chr, int fd);
61 87ecb68b pbrook
    IOEventHandler *chr_event;
62 7b27a769 Juan Quintela
    IOCanReadHandler *chr_can_read;
63 87ecb68b pbrook
    IOReadHandler *chr_read;
64 87ecb68b pbrook
    void *handler_opaque;
65 87ecb68b pbrook
    void (*chr_close)(struct CharDriverState *chr);
66 bd9bdce6 balrog
    void (*chr_accept_input)(struct CharDriverState *chr);
67 c48855e1 Paolo Bonzini
    void (*chr_set_echo)(struct CharDriverState *chr, bool echo);
68 7c32c4fe Hans de Goede
    void (*chr_guest_open)(struct CharDriverState *chr);
69 7c32c4fe Hans de Goede
    void (*chr_guest_close)(struct CharDriverState *chr);
70 87ecb68b pbrook
    void *opaque;
71 87ecb68b pbrook
    QEMUBH *bh;
72 5ccfae10 aliguori
    char *label;
73 5ccfae10 aliguori
    char *filename;
74 73cdf3f2 Alexander Graf
    int opened;
75 d5b27167 Kusanagi Kouichi
    int avail_connections;
76 72cf2d4f Blue Swirl
    QTAILQ_ENTRY(CharDriverState) next;
77 87ecb68b pbrook
};
78 87ecb68b pbrook
79 2011fe56 Anthony Liguori
/**
80 2011fe56 Anthony Liguori
 * @qemu_chr_new_from_opts:
81 2011fe56 Anthony Liguori
 *
82 2011fe56 Anthony Liguori
 * Create a new character backend from a QemuOpts list.
83 2011fe56 Anthony Liguori
 *
84 2011fe56 Anthony Liguori
 * @opts see qemu-config.c for a list of valid options
85 2011fe56 Anthony Liguori
 * @init not sure..
86 2011fe56 Anthony Liguori
 *
87 2011fe56 Anthony Liguori
 * Returns: a new character backend
88 2011fe56 Anthony Liguori
 */
89 f69554b9 Anthony Liguori
CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
90 191bc01b Gerd Hoffmann
                                    void (*init)(struct CharDriverState *s));
91 2011fe56 Anthony Liguori
92 2011fe56 Anthony Liguori
/**
93 2011fe56 Anthony Liguori
 * @qemu_chr_new:
94 2011fe56 Anthony Liguori
 *
95 2011fe56 Anthony Liguori
 * Create a new character backend from a URI.
96 2011fe56 Anthony Liguori
 *
97 2011fe56 Anthony Liguori
 * @label the name of the backend
98 2011fe56 Anthony Liguori
 * @filename the URI
99 2011fe56 Anthony Liguori
 * @init not sure..
100 2011fe56 Anthony Liguori
 *
101 2011fe56 Anthony Liguori
 * Returns: a new character backend
102 2011fe56 Anthony Liguori
 */
103 2011fe56 Anthony Liguori
CharDriverState *qemu_chr_new(const char *label, const char *filename,
104 2011fe56 Anthony Liguori
                              void (*init)(struct CharDriverState *s));
105 2011fe56 Anthony Liguori
106 2011fe56 Anthony Liguori
/**
107 2011fe56 Anthony Liguori
 * @qemu_chr_delete:
108 2011fe56 Anthony Liguori
 *
109 2011fe56 Anthony Liguori
 * Destroy a character backend.
110 2011fe56 Anthony Liguori
 */
111 2011fe56 Anthony Liguori
void qemu_chr_delete(CharDriverState *chr);
112 2011fe56 Anthony Liguori
113 2011fe56 Anthony Liguori
/**
114 2011fe56 Anthony Liguori
 * @qemu_chr_fe_set_echo:
115 2011fe56 Anthony Liguori
 *
116 2011fe56 Anthony Liguori
 * Ask the backend to override its normal echo setting.  This only really
117 2011fe56 Anthony Liguori
 * applies to the stdio backend and is used by the QMP server such that you
118 2011fe56 Anthony Liguori
 * can see what you type if you try to type QMP commands.
119 2011fe56 Anthony Liguori
 *
120 2011fe56 Anthony Liguori
 * @echo true to enable echo, false to disable echo
121 2011fe56 Anthony Liguori
 */
122 15f31519 Anthony Liguori
void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo);
123 2011fe56 Anthony Liguori
124 2011fe56 Anthony Liguori
/**
125 2011fe56 Anthony Liguori
 * @qemu_chr_fe_open:
126 2011fe56 Anthony Liguori
 *
127 2011fe56 Anthony Liguori
 * Open a character backend.  This function call is an indication that the
128 2011fe56 Anthony Liguori
 * front end is ready to begin doing I/O.
129 2011fe56 Anthony Liguori
 */
130 c9d830ed Anthony Liguori
void qemu_chr_fe_open(struct CharDriverState *chr);
131 2011fe56 Anthony Liguori
132 2011fe56 Anthony Liguori
/**
133 2011fe56 Anthony Liguori
 * @qemu_chr_fe_close:
134 2011fe56 Anthony Liguori
 *
135 2011fe56 Anthony Liguori
 * Close a character backend.  This function call indicates that the front end
136 2011fe56 Anthony Liguori
 * no longer is able to process I/O.  To process I/O again, the front end will
137 2011fe56 Anthony Liguori
 * call @qemu_chr_fe_open.
138 2011fe56 Anthony Liguori
 */
139 2817822d Anthony Liguori
void qemu_chr_fe_close(struct CharDriverState *chr);
140 2011fe56 Anthony Liguori
141 2011fe56 Anthony Liguori
/**
142 2011fe56 Anthony Liguori
 * @qemu_chr_fe_printf:
143 2011fe56 Anthony Liguori
 *
144 2011fe56 Anthony Liguori
 * Write to a character backend using a printf style interface.
145 2011fe56 Anthony Liguori
 *
146 2011fe56 Anthony Liguori
 * @fmt see #printf
147 2011fe56 Anthony Liguori
 */
148 e7e71b0e Anthony Liguori
void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
149 8b7968f7 Stefan Weil
    GCC_FMT_ATTR(2, 3);
150 2011fe56 Anthony Liguori
151 2011fe56 Anthony Liguori
/**
152 2011fe56 Anthony Liguori
 * @qemu_chr_fe_write:
153 2011fe56 Anthony Liguori
 *
154 2011fe56 Anthony Liguori
 * Write data to a character backend from the front end.  This function will
155 2011fe56 Anthony Liguori
 * send data from the front end to the back end.
156 2011fe56 Anthony Liguori
 *
157 2011fe56 Anthony Liguori
 * @buf the data
158 2011fe56 Anthony Liguori
 * @len the number of bytes to send
159 2011fe56 Anthony Liguori
 *
160 2011fe56 Anthony Liguori
 * Returns: the number of bytes consumed
161 2011fe56 Anthony Liguori
 */
162 2cc6e0a1 Anthony Liguori
int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len);
163 2011fe56 Anthony Liguori
164 2011fe56 Anthony Liguori
/**
165 2011fe56 Anthony Liguori
 * @qemu_chr_fe_ioctl:
166 2011fe56 Anthony Liguori
 *
167 2011fe56 Anthony Liguori
 * Issue a device specific ioctl to a backend.
168 2011fe56 Anthony Liguori
 *
169 2011fe56 Anthony Liguori
 * @cmd see CHR_IOCTL_*
170 2011fe56 Anthony Liguori
 * @arg the data associated with @cmd
171 2011fe56 Anthony Liguori
 *
172 2011fe56 Anthony Liguori
 * Returns: if @cmd is not supported by the backend, -ENOTSUP, otherwise the
173 2011fe56 Anthony Liguori
 *          return value depends on the semantics of @cmd
174 2011fe56 Anthony Liguori
 */
175 2011fe56 Anthony Liguori
int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg);
176 2011fe56 Anthony Liguori
177 2011fe56 Anthony Liguori
/**
178 2011fe56 Anthony Liguori
 * @qemu_chr_fe_get_msgfd:
179 2011fe56 Anthony Liguori
 *
180 2011fe56 Anthony Liguori
 * For backends capable of fd passing, return the latest file descriptor passed
181 2011fe56 Anthony Liguori
 * by a client.
182 2011fe56 Anthony Liguori
 *
183 2011fe56 Anthony Liguori
 * Returns: -1 if fd passing isn't supported or there is no pending file
184 2011fe56 Anthony Liguori
 *          descriptor.  If a file descriptor is returned, subsequent calls to
185 2011fe56 Anthony Liguori
 *          this function will return -1 until a client sends a new file
186 2011fe56 Anthony Liguori
 *          descriptor.
187 2011fe56 Anthony Liguori
 */
188 2011fe56 Anthony Liguori
int qemu_chr_fe_get_msgfd(CharDriverState *s);
189 2011fe56 Anthony Liguori
190 2011fe56 Anthony Liguori
/**
191 2011fe56 Anthony Liguori
 * @qemu_chr_be_can_write:
192 2011fe56 Anthony Liguori
 *
193 2011fe56 Anthony Liguori
 * Determine how much data the front end can currently accept.  This function
194 2011fe56 Anthony Liguori
 * returns the number of bytes the front end can accept.  If it returns 0, the
195 2011fe56 Anthony Liguori
 * front end cannot receive data at the moment.  The function must be polled
196 2011fe56 Anthony Liguori
 * to determine when data can be received.
197 2011fe56 Anthony Liguori
 *
198 2011fe56 Anthony Liguori
 * Returns: the number of bytes the front end can receive via @qemu_chr_be_write
199 2011fe56 Anthony Liguori
 */
200 2011fe56 Anthony Liguori
int qemu_chr_be_can_write(CharDriverState *s);
201 2011fe56 Anthony Liguori
202 2011fe56 Anthony Liguori
/**
203 2011fe56 Anthony Liguori
 * @qemu_chr_be_write:
204 2011fe56 Anthony Liguori
 *
205 2011fe56 Anthony Liguori
 * Write data from the back end to the front end.  Before issuing this call,
206 2011fe56 Anthony Liguori
 * the caller should call @qemu_chr_be_can_write to determine how much data
207 2011fe56 Anthony Liguori
 * the front end can currently accept.
208 2011fe56 Anthony Liguori
 *
209 2011fe56 Anthony Liguori
 * @buf a buffer to receive data from the front end
210 2011fe56 Anthony Liguori
 * @len the number of bytes to receive from the front end
211 2011fe56 Anthony Liguori
 */
212 2011fe56 Anthony Liguori
void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
213 2011fe56 Anthony Liguori
214 87ecb68b pbrook
void qemu_chr_add_handlers(CharDriverState *s,
215 7b27a769 Juan Quintela
                           IOCanReadHandler *fd_can_read,
216 87ecb68b pbrook
                           IOReadHandler *fd_read,
217 87ecb68b pbrook
                           IOEventHandler *fd_event,
218 87ecb68b pbrook
                           void *opaque);
219 2011fe56 Anthony Liguori
220 127338e6 Amit Shah
void qemu_chr_generic_open(CharDriverState *s);
221 bd9bdce6 balrog
void qemu_chr_accept_input(CharDriverState *s);
222 13661089 Daniel P. Berrange
int qemu_chr_add_client(CharDriverState *s, int fd);
223 588b3832 Luiz Capitulino
void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
224 588b3832 Luiz Capitulino
void qemu_chr_info(Monitor *mon, QObject **ret_data);
225 c845f401 Gerd Hoffmann
CharDriverState *qemu_chr_find(const char *name);
226 87ecb68b pbrook
227 2011fe56 Anthony Liguori
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
228 2011fe56 Anthony Liguori
229 6cbf4c8c Cam Macdonell
/* add an eventfd to the qemu devices that are polled */
230 6cbf4c8c Cam Macdonell
CharDriverState *qemu_chr_open_eventfd(int eventfd);
231 6cbf4c8c Cam Macdonell
232 0e82f34d aliguori
extern int term_escape_char;
233 0e82f34d aliguori
234 999bd67c Luiz Capitulino
/* memory chardev */
235 999bd67c Luiz Capitulino
void qemu_chr_init_mem(CharDriverState *chr);
236 999bd67c Luiz Capitulino
void qemu_chr_close_mem(CharDriverState *chr);
237 999bd67c Luiz Capitulino
QString *qemu_chr_mem_to_qs(CharDriverState *chr);
238 999bd67c Luiz Capitulino
size_t qemu_chr_mem_osize(const CharDriverState *chr);
239 999bd67c Luiz Capitulino
240 87ecb68b pbrook
/* async I/O support */
241 87ecb68b pbrook
242 87ecb68b pbrook
int qemu_set_fd_handler2(int fd,
243 7b27a769 Juan Quintela
                         IOCanReadHandler *fd_read_poll,
244 87ecb68b pbrook
                         IOHandler *fd_read,
245 87ecb68b pbrook
                         IOHandler *fd_write,
246 87ecb68b pbrook
                         void *opaque);
247 87ecb68b pbrook
int qemu_set_fd_handler(int fd,
248 87ecb68b pbrook
                        IOHandler *fd_read,
249 87ecb68b pbrook
                        IOHandler *fd_write,
250 87ecb68b pbrook
                        void *opaque);
251 87ecb68b pbrook
#endif