ditto hw/xilinx_uartlite.c
[qemu/aliguori.git] / qemu-char.h
blobd36ff9cfedc10a423220b4b276f1e835eb283e2f
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 IOEventHandler *chr_event;
71 IOHandler *fe_read;
72 IOHandler *fe_write;
73 void *handler_opaque;
74 void (*chr_close)(struct CharDriverState *chr);
75 void (*chr_guest_open)(struct CharDriverState *chr);
76 void (*chr_guest_close)(struct CharDriverState *chr);
77 void *opaque;
78 QEMUBH *bh;
79 char *label;
80 char *filename;
81 int opened;
82 int avail_connections;
84 int fe_opened;
86 CharQueue fe_tx;
87 CharQueue be_tx;
89 QTAILQ_ENTRY(CharDriverState) next;
92 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
93 CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
94 void (*init)(struct CharDriverState *s));
95 CharDriverState *qemu_chr_new(const char *label, const char *filename, void (*init)(struct CharDriverState *s));
97 void qemu_chr_fe_open(struct CharDriverState *chr);
98 void qemu_chr_fe_close(struct CharDriverState *chr);
99 void qemu_chr_fe_delete(CharDriverState *chr);
100 void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
101 GCC_FMT_ATTR(2, 3);
102 int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len);
103 int qemu_chr_fe_read(CharDriverState *s, uint8_t *buf, int len);
105 void qemu_chr_fe_set_handlers(CharDriverState *s,
106 IOHandler *chr_read,
107 IOHandler *chr_write,
108 IOEventHandler *chr_event,
109 void *opaque);
111 int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg);
113 void qemu_chr_generic_open(CharDriverState *s);
115 int qemu_chr_be_can_write(CharDriverState *s);
116 int qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
117 int qemu_chr_be_read(CharDriverState *s, uint8_t *buf, int len);
119 void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
120 void qemu_chr_info(Monitor *mon, QObject **ret_data);
121 CharDriverState *qemu_chr_find(const char *name);
123 static inline int qemu_chr_fe_get_msgfd(CharDriverState *s)
125 int fd = -1;
126 int ret;
128 ret = qemu_chr_fe_ioctl(s, CHR_GET_MSGFD, &fd);
129 if (ret == 0) {
130 ret = fd;
133 return ret;
136 static inline void qemu_chr_fe_set_echo(CharDriverState *chr, bool echo)
138 qemu_chr_fe_ioctl(chr, CHR_SET_ECHO, &echo);
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