Statistics
| Branch: | Revision:

root / qemu-char.h @ 6f06f178

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