diff options
author | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2004-07-14 17:28:13 +0000 |
---|---|---|
committer | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2004-07-14 17:28:13 +0000 |
commit | 82c643ff50dfdd82b89e9c5361fd132c79e0872c (patch) | |
tree | 9b22a47e17a69e6fc024d7fe047dc05498a53b3c /hw/serial.c | |
parent | 457831f4bcf20d1fd5d80d7a0b946bdaf6f56059 (diff) | |
download | qemu-82c643ff50dfdd82b89e9c5361fd132c79e0872c.zip |
char device support
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1023 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'hw/serial.c')
-rw-r--r-- | hw/serial.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/hw/serial.c b/hw/serial.c index 3cf43f4d16..0fc1ccb9d0 100644 --- a/hw/serial.c +++ b/hw/serial.c @@ -84,7 +84,7 @@ struct SerialState { it can be reset while reading iir */ int thr_ipending; int irq; - int out_fd; + CharDriverState *chr; }; static void serial_update_irq(SerialState *s) @@ -107,7 +107,6 @@ static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val) { SerialState *s = opaque; unsigned char ch; - int ret; addr &= 7; #ifdef DEBUG_SERIAL @@ -122,13 +121,8 @@ static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val) s->thr_ipending = 0; s->lsr &= ~UART_LSR_THRE; serial_update_irq(s); - - if (s->out_fd >= 0) { - ch = val; - do { - ret = write(s->out_fd, &ch, 1); - } while (ret != 1); - } + ch = val; + qemu_chr_write(s->chr, &ch, 1); s->thr_ipending = 1; s->lsr |= UART_LSR_THRE; s->lsr |= UART_LSR_TEMT; @@ -223,19 +217,19 @@ static uint32_t serial_ioport_read(void *opaque, uint32_t addr) return ret; } -int serial_can_receive(SerialState *s) +static int serial_can_receive(SerialState *s) { return !(s->lsr & UART_LSR_DR); } -void serial_receive_byte(SerialState *s, int ch) +static void serial_receive_byte(SerialState *s, int ch) { s->rbr = ch; s->lsr |= UART_LSR_DR; serial_update_irq(s); } -void serial_receive_break(SerialState *s) +static void serial_receive_break(SerialState *s) { s->rbr = 0; s->lsr |= UART_LSR_BI | UART_LSR_DR; @@ -254,8 +248,15 @@ static void serial_receive1(void *opaque, const uint8_t *buf, int size) serial_receive_byte(s, buf[0]); } +static void serial_event(void *opaque, int event) +{ + SerialState *s = opaque; + if (event == CHR_EVENT_BREAK) + serial_receive_break(s); +} + /* If fd is zero, it means that the serial device uses the console */ -SerialState *serial_init(int base, int irq, int fd) +SerialState *serial_init(int base, int irq, CharDriverState *chr) { SerialState *s; @@ -268,16 +269,8 @@ SerialState *serial_init(int base, int irq, int fd) register_ioport_write(base, 8, 1, serial_ioport_write, s); register_ioport_read(base, 8, 1, serial_ioport_read, s); - - if (fd < 0) { - /* no associated device */ - s->out_fd = -1; - } else if (fd != 0) { - qemu_add_fd_read_handler(fd, serial_can_receive1, serial_receive1, s); - s->out_fd = fd; - } else { - serial_console = s; - s->out_fd = 1; - } + s->chr = chr; + qemu_chr_add_read_handler(chr, serial_can_receive1, serial_receive1, s); + qemu_chr_add_event_handler(chr, serial_event); return s; } |