blob: e3a07838a4d8c31c900ae8764d1a6cda73390660 [file] [log] [blame]
pbrook87ecb682007-11-17 17:14:51 +00001#ifndef QEMU_CHAR_H
2#define QEMU_CHAR_H
3
aliguori376253e2009-03-05 23:01:23 +00004#include "qemu-common.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +00005#include "qemu-queue.h"
Gerd Hoffmann191bc012009-09-10 10:58:35 +02006#include "qemu-option.h"
7#include "qemu-config.h"
Luiz Capitulino588b3832009-12-10 17:16:08 -02008#include "qobject.h"
aliguori376253e2009-03-05 23:01:23 +00009
pbrook87ecb682007-11-17 17:14:51 +000010/* character device */
11
aliguori2724b182009-03-05 23:01:47 +000012#define CHR_EVENT_BREAK 0 /* serial break char */
13#define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
Amit Shahb6b8df52009-10-07 18:31:16 +053014#define CHR_EVENT_OPENED 2 /* new connection established */
aliguori2724b182009-03-05 23:01:47 +000015#define CHR_EVENT_MUX_IN 3 /* mux-focus was set to this terminal */
16#define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */
Amit Shah793cbfb2009-08-11 21:27:48 +053017#define CHR_EVENT_CLOSED 5 /* connection closed */
pbrook87ecb682007-11-17 17:14:51 +000018
19
20#define CHR_IOCTL_SERIAL_SET_PARAMS 1
21typedef struct {
22 int speed;
23 int parity;
24 int data_bits;
25 int stop_bits;
26} QEMUSerialSetParams;
27
28#define CHR_IOCTL_SERIAL_SET_BREAK 2
29
30#define CHR_IOCTL_PP_READ_DATA 3
31#define CHR_IOCTL_PP_WRITE_DATA 4
32#define CHR_IOCTL_PP_READ_CONTROL 5
33#define CHR_IOCTL_PP_WRITE_CONTROL 6
34#define CHR_IOCTL_PP_READ_STATUS 7
35#define CHR_IOCTL_PP_EPP_READ_ADDR 8
36#define CHR_IOCTL_PP_EPP_READ 9
37#define CHR_IOCTL_PP_EPP_WRITE_ADDR 10
38#define CHR_IOCTL_PP_EPP_WRITE 11
aurel32563e3c62008-08-22 08:57:09 +000039#define CHR_IOCTL_PP_DATA_DIR 12
pbrook87ecb682007-11-17 17:14:51 +000040
aurel32f0664042008-08-22 21:25:00 +000041#define CHR_IOCTL_SERIAL_SET_TIOCM 13
42#define CHR_IOCTL_SERIAL_GET_TIOCM 14
aliguori81174da2008-08-11 14:17:04 +000043
44#define CHR_TIOCM_CTS 0x020
45#define CHR_TIOCM_CAR 0x040
46#define CHR_TIOCM_DSR 0x100
47#define CHR_TIOCM_RI 0x080
48#define CHR_TIOCM_DTR 0x002
49#define CHR_TIOCM_RTS 0x004
50
pbrook87ecb682007-11-17 17:14:51 +000051typedef void IOEventHandler(void *opaque, int event);
52
53struct CharDriverState {
aurel32ceecf1d2009-01-18 14:08:04 +000054 void (*init)(struct CharDriverState *s);
pbrook87ecb682007-11-17 17:14:51 +000055 int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
56 void (*chr_update_read_handler)(struct CharDriverState *s);
57 int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
Mark McLoughlin7d174052009-07-22 09:11:39 +010058 int (*get_msgfd)(struct CharDriverState *s);
pbrook87ecb682007-11-17 17:14:51 +000059 IOEventHandler *chr_event;
Juan Quintela7b27a762010-03-11 17:55:39 +010060 IOCanReadHandler *chr_can_read;
pbrook87ecb682007-11-17 17:14:51 +000061 IOReadHandler *chr_read;
62 void *handler_opaque;
63 void (*chr_send_event)(struct CharDriverState *chr, int event);
64 void (*chr_close)(struct CharDriverState *chr);
balrogbd9bdce2007-11-25 00:55:06 +000065 void (*chr_accept_input)(struct CharDriverState *chr);
pbrook87ecb682007-11-17 17:14:51 +000066 void *opaque;
pbrook87ecb682007-11-17 17:14:51 +000067 QEMUBH *bh;
aliguori5ccfae12008-10-31 17:31:29 +000068 char *label;
69 char *filename;
Alexander Graf73cdf3f2010-04-01 18:42:39 +020070 int opened;
Blue Swirl72cf2d42009-09-12 07:36:22 +000071 QTAILQ_ENTRY(CharDriverState) next;
pbrook87ecb682007-11-17 17:14:51 +000072};
73
Gerd Hoffmann33521632009-12-08 13:11:49 +010074QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
Gerd Hoffmann191bc012009-09-10 10:58:35 +020075CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
76 void (*init)(struct CharDriverState *s));
aurel32ceecf1d2009-01-18 14:08:04 +000077CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*init)(struct CharDriverState *s));
pbrook9596ebb2007-11-18 01:44:38 +000078void qemu_chr_close(CharDriverState *chr);
pbrook87ecb682007-11-17 17:14:51 +000079void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
80int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
81void qemu_chr_send_event(CharDriverState *s, int event);
82void qemu_chr_add_handlers(CharDriverState *s,
Juan Quintela7b27a762010-03-11 17:55:39 +010083 IOCanReadHandler *fd_can_read,
pbrook87ecb682007-11-17 17:14:51 +000084 IOReadHandler *fd_read,
85 IOEventHandler *fd_event,
86 void *opaque);
87int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg);
Amit Shah127338e2009-11-03 19:59:56 +053088void qemu_chr_generic_open(CharDriverState *s);
pbrook87ecb682007-11-17 17:14:51 +000089int qemu_chr_can_read(CharDriverState *s);
90void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);
Mark McLoughlin7d174052009-07-22 09:11:39 +010091int qemu_chr_get_msgfd(CharDriverState *s);
balrogbd9bdce2007-11-25 00:55:06 +000092void qemu_chr_accept_input(CharDriverState *s);
Luiz Capitulino588b3832009-12-10 17:16:08 -020093void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
94void qemu_chr_info(Monitor *mon, QObject **ret_data);
Gerd Hoffmannc845f402009-09-10 10:58:52 +020095CharDriverState *qemu_chr_find(const char *name);
pbrook87ecb682007-11-17 17:14:51 +000096
aliguori0e82f342008-10-31 18:44:40 +000097extern int term_escape_char;
98
pbrook87ecb682007-11-17 17:14:51 +000099/* async I/O support */
100
101int qemu_set_fd_handler2(int fd,
Juan Quintela7b27a762010-03-11 17:55:39 +0100102 IOCanReadHandler *fd_read_poll,
pbrook87ecb682007-11-17 17:14:51 +0000103 IOHandler *fd_read,
104 IOHandler *fd_write,
105 void *opaque);
106int qemu_set_fd_handler(int fd,
107 IOHandler *fd_read,
108 IOHandler *fd_write,
109 void *opaque);
pbrook87ecb682007-11-17 17:14:51 +0000110#endif