zap update_read_handler
[qemu/aliguori.git] / qemu-char.h
blob886cfb1309e0e92a5f67f0b640e8b2192bf3504b
1 #ifndef QEMU_CHAR_H
2 #define QEMU_CHAR_H
4 #include "qemu-common.h"
5 #include "qemu-queue.h"
6 #include "qemu-option.h"
7 #include "qemu-config.h"
8 #include "qobject.h"
9 #include "qstring.h"
11 /* character device */
13 #define CHR_EVENT_BREAK 0 /* serial break char */
14 #define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
15 #define CHR_EVENT_OPENED 2 /* new connection established */
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 */
18 #define CHR_EVENT_CLOSED 5 /* connection closed */
19 #define CHR_IOCTL_SERIAL_SET_PARAMS 6
20 typedef struct {
21 int speed;
22 int parity;
23 int data_bits;
24 int stop_bits;
25 } QEMUSerialSetParams;
27 #define CHR_IOCTL_SERIAL_SET_BREAK 7
29 #define CHR_IOCTL_PP_READ_DATA 8
30 #define CHR_IOCTL_PP_WRITE_DATA 9
31 #define CHR_IOCTL_PP_READ_CONTROL 10
32 #define CHR_IOCTL_PP_WRITE_CONTROL 11
33 #define CHR_IOCTL_PP_READ_STATUS 12
34 #define CHR_IOCTL_PP_EPP_READ_ADDR 13
35 #define CHR_IOCTL_PP_EPP_READ 14
36 #define CHR_IOCTL_PP_EPP_WRITE_ADDR 15
37 #define CHR_IOCTL_PP_EPP_WRITE 16
38 #define CHR_IOCTL_PP_DATA_DIR 17
40 #define CHR_IOCTL_SERIAL_SET_TIOCM 18
41 #define CHR_IOCTL_SERIAL_GET_TIOCM 19
43 #define CHR_GET_MSGFD 20
44 #define CHR_SET_ECHO 21
46 #define CHR_TIOCM_CTS 0x020
47 #define CHR_TIOCM_CAR 0x040
48 #define CHR_TIOCM_DSR 0x100
49 #define CHR_TIOCM_RI 0x080
50 #define CHR_TIOCM_DTR 0x002
51 #define CHR_TIOCM_RTS 0x004
53 typedef int IOEventHandler(void *opaque, int event, void *data);
55 #define MAX_CHAR_QUEUE_RING 1024
57 typedef struct CharQueue
59 uint32_t prod;
60 uint32_t cons;
61 uint8_t ring[MAX_CHAR_QUEUE_RING];
62 } CharQueue;
64 struct CharDriverState {
65 void (*init)(struct CharDriverState *s);
66 int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
67 IOEventHandler *chr_ioctl;
68 IOHandler *be_read;
69 IOHandler *be_write;
70 int (*chr_add_client)(struct CharDriverState *chr, int fd);
71 IOEventHandler *chr_event;
72 IOHandler *fe_read;
73 IOHandler *fe_write;
74 void *handler_opaque;
75 void (*chr_close)(struct CharDriverState *chr);
76 void (*chr_guest_open)(struct CharDriverState *chr);
77 void (*chr_guest_close)(struct CharDriverState *chr);
78 void *opaque;
79 QEMUBH *bh;
80 char *label;
81 char *filename;
82 int opened;
83 int avail_connections;
85 int fe_opened;
87 CharQueue fe_tx;
88 CharQueue be_tx;
90 QTAILQ_ENTRY(CharDriverState) next;
93 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
94 CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
95 void (*init)(struct CharDriverState *s));
96 CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*init)(struct CharDriverState *s));
98 void qemu_chr_fe_open(struct CharDriverState *chr);
99 void qemu_chr_fe_close(struct CharDriverState *chr);
100 void qemu_chr_close(CharDriverState *chr);
101 void qemu_chr_printf(CharDriverState *s, const char *fmt, ...)
102 GCC_FMT_ATTR(2, 3);
103 int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len);
104 int qemu_chr_fe_read(CharDriverState *s, uint8_t *buf, int len);
106 void qemu_chr_fe_set_handlers(CharDriverState *s,
107 IOHandler *chr_read,
108 IOHandler *chr_write,
109 IOEventHandler *chr_event,
110 void *opaque);
112 int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg);
113 void qemu_chr_generic_open(CharDriverState *s);
114 int qemu_chr_be_can_write(CharDriverState *s);
115 int qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
116 int qemu_chr_be_read(CharDriverState *s, uint8_t *buf, int len);
118 static inline int qemu_chr_fe_get_msgfd(CharDriverState *s)
120 int fd = -1;
121 int ret;
123 ret = qemu_chr_fe_ioctl(s, CHR_GET_MSGFD, &fd);
124 if (ret == 0) {
125 ret = fd;
128 return ret;
131 static inline void qemu_chr_fe_set_echo(CharDriverState *chr, bool echo)
133 qemu_chr_fe_ioctl(chr, CHR_SET_ECHO, &echo);
136 int qemu_chr_add_client(CharDriverState *s, int fd);
137 void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
138 void qemu_chr_info(Monitor *mon, QObject **ret_data);
139 CharDriverState *qemu_chr_find(const char *name);
141 /* add an eventfd to the qemu devices that are polled */
142 CharDriverState *qemu_chr_open_eventfd(int eventfd);
144 extern int term_escape_char;
146 /* memory chardev */
147 void qemu_chr_init_mem(CharDriverState *chr);
148 void qemu_chr_close_mem(CharDriverState *chr);
149 QString *qemu_chr_mem_to_qs(CharDriverState *chr);
150 size_t qemu_chr_mem_osize(const CharDriverState *chr);
152 /* async I/O support */
154 int qemu_set_fd_handler2(int fd,
155 IOCanReadHandler *fd_read_poll,
156 IOHandler *fd_read,
157 IOHandler *fd_write,
158 void *opaque);
159 int qemu_set_fd_handler(int fd,
160 IOHandler *fd_read,
161 IOHandler *fd_write,
162 void *opaque);
163 #endif