2012-12-16 23:27:22 +00:00
|
|
|
From 064e087beb96eb5b9716c9058f1d1e461421233e Mon Sep 17 00:00:00 2001
|
2012-01-13 19:46:23 +00:00
|
|
|
From: Amit Shah <amit.shah@redhat.com>
|
|
|
|
Date: Mon, 21 Mar 2011 20:31:45 +0100
|
2012-10-28 18:05:07 +00:00
|
|
|
Subject: [PATCH] char: Add a QemuChrHandlers struct to initialise chardev
|
|
|
|
handlers
|
2012-01-13 19:46:23 +00:00
|
|
|
|
|
|
|
Instead of passing each handler in the qemu_add_handlers() function,
|
|
|
|
create a struct of handlers that can be passed to the function instead.
|
|
|
|
|
|
|
|
Signed-off-by: Amit Shah <amit.shah@redhat.com>
|
2012-08-28 15:15:48 +00:00
|
|
|
Signed-off-by: Cole Robinson <crobinso@redhat.com>
|
2012-01-13 19:46:23 +00:00
|
|
|
---
|
2012-08-06 19:53:39 +00:00
|
|
|
gdbstub.c | 9 +++++++--
|
|
|
|
hw/cadence_uart.c | 9 +++++++--
|
|
|
|
hw/ccid-card-passthru.c | 11 +++++++----
|
|
|
|
hw/debugcon.c | 2 +-
|
|
|
|
hw/escc.c | 9 +++++++--
|
|
|
|
hw/etraxfs_ser.c | 13 +++++++++----
|
|
|
|
hw/exynos4210_uart.c | 9 +++++++--
|
|
|
|
hw/grlib_apbuart.c | 12 +++++++-----
|
|
|
|
hw/imx_serial.c | 9 +++++++--
|
|
|
|
hw/ivshmem.c | 28 ++++++++++++++++++++++------
|
|
|
|
hw/lm32_juart.c | 8 +++++++-
|
|
|
|
hw/lm32_uart.c | 8 +++++++-
|
|
|
|
hw/mcf_uart.c | 9 +++++++--
|
|
|
|
hw/milkymist-uart.c | 8 +++++++-
|
|
|
|
hw/pl011.c | 9 +++++++--
|
|
|
|
hw/pxa2xx.c | 13 +++++++++----
|
|
|
|
hw/qdev-properties.c | 2 +-
|
|
|
|
hw/serial.c | 9 +++++++--
|
|
|
|
hw/sh_serial.c | 12 +++++++++---
|
|
|
|
hw/spapr_vty.c | 8 ++++++--
|
|
|
|
hw/strongarm.c | 12 +++++++-----
|
|
|
|
hw/usb/dev-serial.c | 9 +++++++--
|
|
|
|
hw/usb/redirect.c | 9 +++++++--
|
|
|
|
hw/virtio-console.c | 9 +++++++--
|
|
|
|
hw/xen_console.c | 16 +++++++++++-----
|
|
|
|
hw/xilinx_uartlite.c | 11 +++++++++--
|
|
|
|
monitor.c | 18 ++++++++++++++----
|
|
|
|
net/slirp.c | 8 ++++++--
|
|
|
|
qemu-char.c | 32 ++++++++++++++++++++++----------
|
|
|
|
qemu-char.h | 13 +++++++++----
|
|
|
|
qtest.c | 9 ++++++++-
|
|
|
|
31 files changed, 255 insertions(+), 88 deletions(-)
|
2012-01-13 19:46:23 +00:00
|
|
|
|
|
|
|
diff --git a/gdbstub.c b/gdbstub.c
|
2012-10-28 18:05:07 +00:00
|
|
|
index a91709f..b905c15 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/gdbstub.c
|
|
|
|
+++ b/gdbstub.c
|
2012-10-28 18:05:07 +00:00
|
|
|
@@ -2965,6 +2965,12 @@ static void gdb_sigterm_handler(int signal)
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers gdb_handlers = {
|
|
|
|
+ .fd_can_read = gdb_chr_can_receive,
|
|
|
|
+ .fd_read = gdb_chr_receive,
|
|
|
|
+ .fd_event = gdb_chr_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
int gdbserver_start(const char *device)
|
|
|
|
{
|
|
|
|
GDBState *s;
|
2012-10-28 18:05:07 +00:00
|
|
|
@@ -2994,8 +3000,7 @@ int gdbserver_start(const char *device)
|
2012-01-13 19:46:23 +00:00
|
|
|
if (!chr)
|
|
|
|
return -1;
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
- qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive,
|
|
|
|
- gdb_chr_event, NULL);
|
|
|
|
+ qemu_chr_add_handlers(chr, &gdb_handlers, NULL);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
s = gdbserver_state;
|
2012-07-05 09:22:23 +00:00
|
|
|
diff --git a/hw/cadence_uart.c b/hw/cadence_uart.c
|
2012-10-28 18:05:07 +00:00
|
|
|
index f8afc4e..c9d3b21 100644
|
2012-07-05 09:22:23 +00:00
|
|
|
--- a/hw/cadence_uart.c
|
|
|
|
+++ b/hw/cadence_uart.c
|
|
|
|
@@ -435,6 +435,12 @@ static void cadence_uart_reset(UartState *s)
|
|
|
|
s->rx_wpos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static const QemuChrHandlers cadence_uart_handlers = {
|
|
|
|
+ .fd_can_read = uart_can_receive,
|
|
|
|
+ .fd_read = uart_receive,
|
|
|
|
+ .fd_event = uart_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int cadence_uart_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
UartState *s = FROM_SYSBUS(UartState, dev);
|
|
|
|
@@ -456,8 +462,7 @@ static int cadence_uart_init(SysBusDevice *dev)
|
|
|
|
cadence_uart_reset(s);
|
|
|
|
|
|
|
|
if (s->chr) {
|
|
|
|
- qemu_chr_add_handlers(s->chr, uart_can_receive, uart_receive,
|
|
|
|
- uart_event, s);
|
|
|
|
+ qemu_chr_add_handlers(s->chr, &cadence_uart_handlers, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-01-13 19:46:23 +00:00
|
|
|
diff --git a/hw/ccid-card-passthru.c b/hw/ccid-card-passthru.c
|
2012-07-05 09:22:23 +00:00
|
|
|
index bd6c777..fb32107 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/ccid-card-passthru.c
|
|
|
|
+++ b/hw/ccid-card-passthru.c
|
|
|
|
@@ -274,6 +274,12 @@ static const uint8_t *passthru_get_atr(CCIDCardState *base, uint32_t *len)
|
|
|
|
return card->atr;
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers passthru_handlers = {
|
|
|
|
+ .fd_can_read = ccid_card_vscard_can_read,
|
|
|
|
+ .fd_read = ccid_card_vscard_read,
|
|
|
|
+ .fd_event = ccid_card_vscard_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int passthru_initfn(CCIDCardState *base)
|
|
|
|
{
|
|
|
|
PassthruState *card = DO_UPCAST(PassthruState, base, base);
|
|
|
|
@@ -282,10 +288,7 @@ static int passthru_initfn(CCIDCardState *base)
|
|
|
|
card->vscard_in_hdr = 0;
|
|
|
|
if (card->cs) {
|
|
|
|
DPRINTF(card, D_INFO, "initing chardev\n");
|
|
|
|
- qemu_chr_add_handlers(card->cs,
|
|
|
|
- ccid_card_vscard_can_read,
|
|
|
|
- ccid_card_vscard_read,
|
|
|
|
- ccid_card_vscard_event, card);
|
|
|
|
+ qemu_chr_add_handlers(card->cs, &passthru_handlers, card);
|
|
|
|
ccid_card_vscard_send_init(card);
|
|
|
|
} else {
|
|
|
|
error_report("missing chardev");
|
|
|
|
diff --git a/hw/debugcon.c b/hw/debugcon.c
|
2012-07-05 09:22:23 +00:00
|
|
|
index 14ab326..7887fd2 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/debugcon.c
|
|
|
|
+++ b/hw/debugcon.c
|
|
|
|
@@ -73,7 +73,7 @@ static void debugcon_init_core(DebugconState *s)
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
- qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
|
|
|
|
+ qemu_chr_add_handlers(s->chr, NULL, s);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
static int debugcon_isa_initfn(ISADevice *dev)
|
|
|
|
diff --git a/hw/escc.c b/hw/escc.c
|
2012-08-06 19:53:39 +00:00
|
|
|
index e1f5e73..ff9d8b1 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/escc.c
|
|
|
|
+++ b/hw/escc.c
|
|
|
|
@@ -867,6 +867,12 @@ void slavio_serial_ms_kbd_init(target_phys_addr_t base, qemu_irq irq,
|
|
|
|
sysbus_mmio_map(s, 0, base);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers serial_handlers = {
|
|
|
|
+ .fd_can_read = serial_can_receive,
|
|
|
|
+ .fd_read = serial_receive1,
|
|
|
|
+ .fd_event = serial_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int escc_init1(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
SerialState *s = FROM_SYSBUS(SerialState, dev);
|
|
|
|
@@ -879,8 +885,7 @@ static int escc_init1(SysBusDevice *dev)
|
|
|
|
s->chn[i].chn = 1 - i;
|
|
|
|
s->chn[i].clock = s->frequency / 2;
|
|
|
|
if (s->chn[i].chr) {
|
|
|
|
- qemu_chr_add_handlers(s->chn[i].chr, serial_can_receive,
|
|
|
|
- serial_receive1, serial_event, &s->chn[i]);
|
|
|
|
+ qemu_chr_add_handlers(s->chn[i].chr, &serial_handlers, &s->chn[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s->chn[0].otherchn = &s->chn[1];
|
|
|
|
diff --git a/hw/etraxfs_ser.c b/hw/etraxfs_ser.c
|
2012-07-05 09:22:23 +00:00
|
|
|
index 5f16b17..f2571c2 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/etraxfs_ser.c
|
|
|
|
+++ b/hw/etraxfs_ser.c
|
|
|
|
@@ -208,6 +208,12 @@ static void etraxfs_ser_reset(DeviceState *d)
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers serial_handlers = {
|
|
|
|
+ .fd_can_read = serial_can_receive,
|
|
|
|
+ .fd_read = serial_receive,
|
|
|
|
+ .fd_event = serial_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int etraxfs_ser_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
struct etrax_serial *s = FROM_SYSBUS(typeof (*s), dev);
|
|
|
|
@@ -217,10 +223,9 @@ static int etraxfs_ser_init(SysBusDevice *dev)
|
2012-07-05 09:22:23 +00:00
|
|
|
sysbus_init_mmio(dev, &s->mmio);
|
|
|
|
|
|
|
|
s->chr = qemu_char_get_next_serial();
|
2012-01-13 19:46:23 +00:00
|
|
|
- if (s->chr)
|
|
|
|
- qemu_chr_add_handlers(s->chr,
|
|
|
|
- serial_can_receive, serial_receive,
|
|
|
|
- serial_event, s);
|
|
|
|
+ if (s->chr) {
|
|
|
|
+ qemu_chr_add_handlers(s->chr, &serial_handlers, s);
|
|
|
|
+ }
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
|
|
|
diff --git a/hw/exynos4210_uart.c b/hw/exynos4210_uart.c
|
|
|
|
index ccc4780..fefe400 100644
|
|
|
|
--- a/hw/exynos4210_uart.c
|
|
|
|
+++ b/hw/exynos4210_uart.c
|
|
|
|
@@ -625,6 +625,12 @@ DeviceState *exynos4210_uart_create(target_phys_addr_t addr,
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static const QemuChrHandlers exynos4210_handlers = {
|
|
|
|
+ .fd_can_read = exynos4210_uart_can_receive,
|
|
|
|
+ .fd_read = exynos4210_uart_receive,
|
|
|
|
+ .fd_event = exynos4210_uart_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int exynos4210_uart_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
Exynos4210UartState *s = FROM_SYSBUS(Exynos4210UartState, dev);
|
|
|
|
@@ -636,8 +642,7 @@ static int exynos4210_uart_init(SysBusDevice *dev)
|
|
|
|
|
|
|
|
sysbus_init_irq(dev, &s->irq);
|
|
|
|
|
|
|
|
- qemu_chr_add_handlers(s->chr, exynos4210_uart_can_receive,
|
|
|
|
- exynos4210_uart_receive, exynos4210_uart_event, s);
|
|
|
|
+ qemu_chr_add_handlers(s->chr, &exynos4210_handlers, s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-13 19:46:23 +00:00
|
|
|
diff --git a/hw/grlib_apbuart.c b/hw/grlib_apbuart.c
|
2012-07-05 09:22:23 +00:00
|
|
|
index 73fc989..fd77d52 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/grlib_apbuart.c
|
|
|
|
+++ b/hw/grlib_apbuart.c
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -222,15 +222,17 @@ static const MemoryRegionOps grlib_apbuart_ops = {
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2012-01-13 19:46:23 +00:00
|
|
|
};
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers grlib_handlers = {
|
|
|
|
+ .fd_can_read = grlib_apbuart_can_receive,
|
|
|
|
+ .fd_read = grlib_apbuart_receive,
|
|
|
|
+ .fd_event = grlib_apbuart_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int grlib_apbuart_init(SysBusDevice *dev)
|
|
|
|
{
|
2012-07-05 09:22:23 +00:00
|
|
|
UART *uart = FROM_SYSBUS(typeof(*uart), dev);
|
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
- qemu_chr_add_handlers(uart->chr,
|
|
|
|
- grlib_apbuart_can_receive,
|
|
|
|
- grlib_apbuart_receive,
|
|
|
|
- grlib_apbuart_event,
|
|
|
|
- uart);
|
|
|
|
+ qemu_chr_add_handlers(uart->chr, &grlib_handlers, uart);
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
sysbus_init_irq(dev, &uart->irq);
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-08-06 19:53:39 +00:00
|
|
|
diff --git a/hw/imx_serial.c b/hw/imx_serial.c
|
|
|
|
index d4eae43..f2304d2 100644
|
|
|
|
--- a/hw/imx_serial.c
|
|
|
|
+++ b/hw/imx_serial.c
|
|
|
|
@@ -381,6 +381,12 @@ static const struct MemoryRegionOps imx_serial_ops = {
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
|
|
|
+static const QemuChrHandlers imx_handlers = {
|
|
|
|
+ .fd_can_read = imx_can_receive,
|
|
|
|
+ .fd_read = imx_receive,
|
|
|
|
+ .fd_event = imx_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int imx_serial_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
IMXSerialState *s = FROM_SYSBUS(IMXSerialState, dev);
|
|
|
|
@@ -391,8 +397,7 @@ static int imx_serial_init(SysBusDevice *dev)
|
|
|
|
sysbus_init_irq(dev, &s->irq);
|
|
|
|
|
|
|
|
if (s->chr) {
|
|
|
|
- qemu_chr_add_handlers(s->chr, imx_can_receive, imx_receive,
|
|
|
|
- imx_event, s);
|
|
|
|
+ qemu_chr_add_handlers(s->chr, &imx_handlers, s);
|
|
|
|
} else {
|
|
|
|
DPRINTF("No char dev for uart at 0x%lx\n",
|
|
|
|
(unsigned long)s->iomem.ram_addr);
|
2012-01-13 19:46:23 +00:00
|
|
|
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
|
2012-10-28 18:05:07 +00:00
|
|
|
index 62fe53a..e90f691 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/ivshmem.c
|
|
|
|
+++ b/hw/ivshmem.c
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -273,6 +273,18 @@ static void fake_irqfd(void *opaque, const uint8_t *buf, int size) {
|
2012-01-13 19:46:23 +00:00
|
|
|
msix_notify(pdev, entry->vector);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers ivshmem_handlers = {
|
|
|
|
+ .fd_can_read = ivshmem_can_receive,
|
|
|
|
+ .fd_read = ivshmem_receive,
|
|
|
|
+ .fd_event = ivshmem_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static const QemuChrHandlers ivshmem_msi_handlers = {
|
|
|
|
+ .fd_can_read = ivshmem_can_receive,
|
|
|
|
+ .fd_read = fake_irqfd,
|
|
|
|
+ .fd_event = ivshmem_event,
|
|
|
|
+};
|
|
|
|
+
|
2012-08-06 19:53:39 +00:00
|
|
|
static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *n,
|
|
|
|
int vector)
|
2012-01-13 19:46:23 +00:00
|
|
|
{
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -293,11 +305,10 @@ static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *
|
2012-01-13 19:46:23 +00:00
|
|
|
s->eventfd_table[vector].pdev = &s->dev;
|
|
|
|
s->eventfd_table[vector].vector = vector;
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
- qemu_chr_add_handlers(chr, ivshmem_can_receive, fake_irqfd,
|
|
|
|
- ivshmem_event, &s->eventfd_table[vector]);
|
|
|
|
+ qemu_chr_add_handlers(chr, &ivshmem_msi_handlers,
|
|
|
|
+ &s->eventfd_table[vector]);
|
|
|
|
} else {
|
|
|
|
- qemu_chr_add_handlers(chr, ivshmem_can_receive, ivshmem_receive,
|
|
|
|
- ivshmem_event, s);
|
|
|
|
+ qemu_chr_add_handlers(chr, &ivshmem_handlers, s);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
return chr;
|
2012-10-28 18:05:07 +00:00
|
|
|
@@ -634,6 +645,12 @@ static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
|
2012-07-05 09:22:23 +00:00
|
|
|
msix_write_config(pci_dev, address, val, len);
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers ivshmem_server_handlers = {
|
|
|
|
+ .fd_can_read = ivshmem_can_receive,
|
|
|
|
+ .fd_read = ivshmem_read,
|
|
|
|
+ .fd_event = ivshmem_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int pci_ivshmem_init(PCIDevice *dev)
|
|
|
|
{
|
|
|
|
IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
|
2012-10-28 18:05:07 +00:00
|
|
|
@@ -720,8 +737,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
s->eventfd_chr = g_malloc0(s->vectors * sizeof(CharDriverState *));
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
- qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read,
|
|
|
|
- ivshmem_event, s);
|
|
|
|
+ qemu_chr_add_handlers(s->server_chr, &ivshmem_server_handlers, s);
|
|
|
|
} else {
|
|
|
|
/* just map the file immediately, we're not using a server */
|
|
|
|
int fd;
|
|
|
|
diff --git a/hw/lm32_juart.c b/hw/lm32_juart.c
|
2012-07-05 09:22:23 +00:00
|
|
|
index f07ed39..d4daeb8 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/lm32_juart.c
|
|
|
|
+++ b/hw/lm32_juart.c
|
|
|
|
@@ -110,13 +110,19 @@ static void juart_reset(DeviceState *d)
|
|
|
|
s->jrx = 0;
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers juart_handlers = {
|
|
|
|
+ .fd_can_read = juart_can_rx,
|
|
|
|
+ .fd_read = juart_rx,
|
|
|
|
+ .fd_event = juart_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int lm32_juart_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
LM32JuartState *s = FROM_SYSBUS(typeof(*s), dev);
|
2012-07-05 09:22:23 +00:00
|
|
|
|
|
|
|
s->chr = qemu_char_get_next_serial();
|
2012-01-13 19:46:23 +00:00
|
|
|
if (s->chr) {
|
|
|
|
- qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, juart_event, s);
|
2012-07-05 09:22:23 +00:00
|
|
|
+ qemu_chr_add_handlers(s->chr, &juart_handlers, s);
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
return 0;
|
|
|
|
diff --git a/hw/lm32_uart.c b/hw/lm32_uart.c
|
2012-07-05 09:22:23 +00:00
|
|
|
index 57066e2..4ea130b 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/lm32_uart.c
|
|
|
|
+++ b/hw/lm32_uart.c
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -243,6 +243,12 @@ static void uart_reset(DeviceState *d)
|
2012-01-13 19:46:23 +00:00
|
|
|
s->regs[R_LSR] = LSR_THRE | LSR_TEMT;
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers uart_handlers = {
|
|
|
|
+ .fd_can_read = uart_can_rx,
|
|
|
|
+ .fd_read = uart_rx,
|
|
|
|
+ .fd_event = uart_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int lm32_uart_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
LM32UartState *s = FROM_SYSBUS(typeof(*s), dev);
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -254,7 +260,7 @@ static int lm32_uart_init(SysBusDevice *dev)
|
|
|
|
|
|
|
|
s->chr = qemu_char_get_next_serial();
|
2012-01-13 19:46:23 +00:00
|
|
|
if (s->chr) {
|
|
|
|
- qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
|
2012-07-05 09:22:23 +00:00
|
|
|
+ qemu_chr_add_handlers(s->chr, &uart_handlers, s);
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
return 0;
|
|
|
|
diff --git a/hw/mcf_uart.c b/hw/mcf_uart.c
|
2012-07-05 09:22:23 +00:00
|
|
|
index ec6a87f..f52fb96 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/mcf_uart.c
|
|
|
|
+++ b/hw/mcf_uart.c
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -272,6 +272,12 @@ static void mcf_uart_receive(void *opaque, const uint8_t *buf, int size)
|
2012-01-13 19:46:23 +00:00
|
|
|
mcf_uart_push_byte(s, buf[0]);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers mcf_uart_handlers = {
|
|
|
|
+ .fd_can_read = mcf_uart_can_receive,
|
|
|
|
+ .fd_read = mcf_uart_receive,
|
|
|
|
+ .fd_event = mcf_uart_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
void *mcf_uart_init(qemu_irq irq, CharDriverState *chr)
|
|
|
|
{
|
|
|
|
mcf_uart_state *s;
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -280,8 +286,7 @@ void *mcf_uart_init(qemu_irq irq, CharDriverState *chr)
|
2012-01-13 19:46:23 +00:00
|
|
|
s->chr = chr;
|
|
|
|
s->irq = irq;
|
|
|
|
if (chr) {
|
|
|
|
- qemu_chr_add_handlers(chr, mcf_uart_can_receive, mcf_uart_receive,
|
|
|
|
- mcf_uart_event, s);
|
|
|
|
+ qemu_chr_add_handlers(chr, &mcf_uart_handlers, s);
|
|
|
|
}
|
|
|
|
mcf_uart_reset(s);
|
|
|
|
return s;
|
|
|
|
diff --git a/hw/milkymist-uart.c b/hw/milkymist-uart.c
|
2012-07-05 09:22:23 +00:00
|
|
|
index 291fe3c..2dcb41c 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/milkymist-uart.c
|
|
|
|
+++ b/hw/milkymist-uart.c
|
|
|
|
@@ -189,6 +189,12 @@ static void milkymist_uart_reset(DeviceState *d)
|
|
|
|
s->regs[R_STAT] = STAT_THRE;
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers uart_handlers = {
|
|
|
|
+ .fd_can_read = uart_can_rx,
|
|
|
|
+ .fd_read = uart_rx,
|
|
|
|
+ .fd_event = uart_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int milkymist_uart_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
MilkymistUartState *s = FROM_SYSBUS(typeof(*s), dev);
|
|
|
|
@@ -201,7 +207,7 @@ static int milkymist_uart_init(SysBusDevice *dev)
|
2012-07-05 09:22:23 +00:00
|
|
|
|
|
|
|
s->chr = qemu_char_get_next_serial();
|
2012-01-13 19:46:23 +00:00
|
|
|
if (s->chr) {
|
|
|
|
- qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
|
2012-07-05 09:22:23 +00:00
|
|
|
+ qemu_chr_add_handlers(s->chr, &uart_handlers, s);
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
return 0;
|
|
|
|
diff --git a/hw/pl011.c b/hw/pl011.c
|
2012-08-06 19:53:39 +00:00
|
|
|
index 3245702..0d620f8 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/pl011.c
|
|
|
|
+++ b/hw/pl011.c
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -258,6 +258,12 @@ static const VMStateDescription vmstate_pl011 = {
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers pl011_handlers = {
|
|
|
|
+ .fd_can_read = pl011_can_receive,
|
|
|
|
+ .fd_read = pl011_receive,
|
|
|
|
+ .fd_event = pl011_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int pl011_init(SysBusDevice *dev, const unsigned char *id)
|
|
|
|
{
|
2012-07-05 09:22:23 +00:00
|
|
|
pl011_state *s = FROM_SYSBUS(pl011_state, dev);
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -273,8 +279,7 @@ static int pl011_init(SysBusDevice *dev, const unsigned char *id)
|
2012-01-13 19:46:23 +00:00
|
|
|
s->cr = 0x300;
|
|
|
|
s->flags = 0x90;
|
|
|
|
if (s->chr) {
|
|
|
|
- qemu_chr_add_handlers(s->chr, pl011_can_receive, pl011_receive,
|
|
|
|
- pl011_event, s);
|
|
|
|
+ qemu_chr_add_handlers(s->chr, &pl011_handlers, s);
|
|
|
|
}
|
|
|
|
vmstate_register(&dev->qdev, -1, &vmstate_pl011, s);
|
|
|
|
return 0;
|
|
|
|
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
|
2012-08-06 19:53:39 +00:00
|
|
|
index d5f1420..0b308cf 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/pxa2xx.c
|
|
|
|
+++ b/hw/pxa2xx.c
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -1962,6 +1962,12 @@ static int pxa2xx_fir_load(QEMUFile *f, void *opaque, int version_id)
|
2012-01-13 19:46:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers pxa2xx_handlers = {
|
|
|
|
+ .fd_can_read = pxa2xx_fir_is_empty,
|
|
|
|
+ .fd_read = pxa2xx_fir_rx,
|
|
|
|
+ .fd_event = pxa2xx_fir_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static PXA2xxFIrState *pxa2xx_fir_init(MemoryRegion *sysmem,
|
|
|
|
target_phys_addr_t base,
|
|
|
|
qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma,
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -1980,10 +1986,9 @@ static PXA2xxFIrState *pxa2xx_fir_init(MemoryRegion *sysmem,
|
2012-01-13 19:46:23 +00:00
|
|
|
memory_region_init_io(&s->iomem, &pxa2xx_fir_ops, s, "pxa2xx-fir", 0x1000);
|
|
|
|
memory_region_add_subregion(sysmem, base, &s->iomem);
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
- if (chr)
|
|
|
|
- qemu_chr_add_handlers(chr, pxa2xx_fir_is_empty,
|
|
|
|
- pxa2xx_fir_rx, pxa2xx_fir_event, s);
|
|
|
|
-
|
|
|
|
+ if (chr) {
|
|
|
|
+ qemu_chr_add_handlers(chr, &pxa2xx_handlers, s);
|
|
|
|
+ }
|
|
|
|
register_savevm(NULL, "pxa2xx_fir", 0, 0, pxa2xx_fir_save,
|
|
|
|
pxa2xx_fir_load, s);
|
2012-07-05 09:22:23 +00:00
|
|
|
|
|
|
|
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
|
2012-08-06 19:53:39 +00:00
|
|
|
index 8aca0d4..677c665 100644
|
2012-07-05 09:22:23 +00:00
|
|
|
--- a/hw/qdev-properties.c
|
|
|
|
+++ b/hw/qdev-properties.c
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -549,7 +549,7 @@ static void release_chr(Object *obj, const char *name, void *opaque)
|
2012-07-05 09:22:23 +00:00
|
|
|
CharDriverState **ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
|
|
|
|
if (*ptr) {
|
|
|
|
- qemu_chr_add_handlers(*ptr, NULL, NULL, NULL, NULL);
|
|
|
|
+ qemu_chr_add_handlers(*ptr, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
diff --git a/hw/serial.c b/hw/serial.c
|
2012-07-05 09:22:23 +00:00
|
|
|
index a421d1e..056d823 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/serial.c
|
|
|
|
+++ b/hw/serial.c
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -736,6 +736,12 @@ static void serial_reset(void *opaque)
|
2012-01-13 19:46:23 +00:00
|
|
|
qemu_irq_lower(s->irq);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers serial_handlers = {
|
|
|
|
+ .fd_can_read = serial_can_receive1,
|
|
|
|
+ .fd_read = serial_receive1,
|
|
|
|
+ .fd_event = serial_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static void serial_init_core(SerialState *s)
|
|
|
|
{
|
|
|
|
if (!s->chr) {
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -750,8 +756,7 @@ static void serial_init_core(SerialState *s)
|
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
qemu_register_reset(serial_reset, s);
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
- qemu_chr_add_handlers(s->chr, serial_can_receive1, serial_receive1,
|
|
|
|
- serial_event, s);
|
|
|
|
+ qemu_chr_add_handlers(s->chr, &serial_handlers, s);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
/* Change the main reference oscillator frequency. */
|
|
|
|
diff --git a/hw/sh_serial.c b/hw/sh_serial.c
|
2012-08-06 19:53:39 +00:00
|
|
|
index 1d1883d..ce1c765 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/sh_serial.c
|
|
|
|
+++ b/hw/sh_serial.c
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -352,6 +352,12 @@ static const MemoryRegionOps sh_serial_ops = {
|
2012-07-05 09:22:23 +00:00
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2012-01-13 19:46:23 +00:00
|
|
|
};
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers sh_serial_handlers = {
|
|
|
|
+ .fd_can_read = sh_serial_can_receive1,
|
|
|
|
+ .fd_read = sh_serial_receive1,
|
|
|
|
+ .fd_event = sh_serial_event,
|
|
|
|
+};
|
|
|
|
+
|
2012-07-05 09:22:23 +00:00
|
|
|
void sh_serial_init(MemoryRegion *sysmem,
|
|
|
|
target_phys_addr_t base, int feat,
|
|
|
|
uint32_t freq, CharDriverState *chr,
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -396,9 +402,9 @@ void sh_serial_init(MemoryRegion *sysmem,
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
s->chr = chr;
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
- if (chr)
|
|
|
|
- qemu_chr_add_handlers(chr, sh_serial_can_receive1, sh_serial_receive1,
|
|
|
|
- sh_serial_event, s);
|
|
|
|
+ if (chr) {
|
|
|
|
+ qemu_chr_add_handlers(chr, &sh_serial_handlers, s);
|
|
|
|
+ }
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
s->eri = eri_source;
|
|
|
|
s->rxi = rxi_source;
|
|
|
|
diff --git a/hw/spapr_vty.c b/hw/spapr_vty.c
|
2012-08-28 15:15:48 +00:00
|
|
|
index 5da17a3..6c2ada1 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/spapr_vty.c
|
|
|
|
+++ b/hw/spapr_vty.c
|
|
|
|
@@ -54,6 +54,11 @@ void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
|
|
|
|
qemu_chr_fe_write(dev->chardev, buf, len);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers vty_handlers = {
|
|
|
|
+ .fd_can_read = vty_can_receive,
|
|
|
|
+ .fd_read = vty_receive,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int spapr_vty_init(VIOsPAPRDevice *sdev)
|
|
|
|
{
|
|
|
|
VIOsPAPRVTYDevice *dev = (VIOsPAPRVTYDevice *)sdev;
|
|
|
|
@@ -63,8 +68,7 @@ static int spapr_vty_init(VIOsPAPRDevice *sdev)
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
- qemu_chr_add_handlers(dev->chardev, vty_can_receive,
|
|
|
|
- vty_receive, NULL, dev);
|
2012-07-05 09:22:23 +00:00
|
|
|
+ qemu_chr_add_handlers(dev->chardev, &vty_handlers, dev);
|
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
diff --git a/hw/strongarm.c b/hw/strongarm.c
|
2012-08-06 19:53:39 +00:00
|
|
|
index 7150eeb..594cf31 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/strongarm.c
|
|
|
|
+++ b/hw/strongarm.c
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -1199,6 +1199,12 @@ static const MemoryRegionOps strongarm_uart_ops = {
|
2012-01-13 19:46:23 +00:00
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
};
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers strongarm_uart_handlers = {
|
|
|
|
+ .fd_can_read = strongarm_uart_can_receive,
|
|
|
|
+ .fd_read = strongarm_uart_receive,
|
|
|
|
+ .fd_event = strongarm_uart_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int strongarm_uart_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
StrongARMUARTState *s = FROM_SYSBUS(StrongARMUARTState, dev);
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -1211,11 +1217,7 @@ static int strongarm_uart_init(SysBusDevice *dev)
|
2012-01-13 19:46:23 +00:00
|
|
|
s->tx_timer = qemu_new_timer_ns(vm_clock, strongarm_uart_tx, s);
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
if (s->chr) {
|
|
|
|
- qemu_chr_add_handlers(s->chr,
|
|
|
|
- strongarm_uart_can_receive,
|
|
|
|
- strongarm_uart_receive,
|
|
|
|
- strongarm_uart_event,
|
|
|
|
- s);
|
|
|
|
+ qemu_chr_add_handlers(s->chr, &strongarm_uart_handlers, s);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
return 0;
|
2012-07-05 09:22:23 +00:00
|
|
|
diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
|
2012-10-28 18:05:07 +00:00
|
|
|
index 69b6e48..0ddfab6 100644
|
2012-07-05 09:22:23 +00:00
|
|
|
--- a/hw/usb/dev-serial.c
|
|
|
|
+++ b/hw/usb/dev-serial.c
|
|
|
|
@@ -475,6 +475,12 @@ static void usb_serial_event(void *opaque, int event)
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers usb_serial_handlers = {
|
|
|
|
+ .fd_can_read = usb_serial_can_read,
|
|
|
|
+ .fd_read = usb_serial_read,
|
|
|
|
+ .fd_event = usb_serial_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int usb_serial_initfn(USBDevice *dev)
|
|
|
|
{
|
|
|
|
USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -487,8 +493,7 @@ static int usb_serial_initfn(USBDevice *dev)
|
2012-01-13 19:46:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
- qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read,
|
|
|
|
- usb_serial_event, s);
|
|
|
|
+ qemu_chr_add_handlers(s->cs, &usb_serial_handlers, s);
|
|
|
|
usb_serial_handle_reset(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
|
2012-10-28 18:05:07 +00:00
|
|
|
index ab8d79a..8b22c80 100644
|
2012-07-05 09:22:23 +00:00
|
|
|
--- a/hw/usb/redirect.c
|
|
|
|
+++ b/hw/usb/redirect.c
|
2012-10-28 18:05:07 +00:00
|
|
|
@@ -867,6 +867,12 @@ static void usbredir_chardev_event(void *opaque, int event)
|
2012-07-05 09:22:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+static const QemuChrHandlers usbredir_chr_handlers = {
|
|
|
|
+ .fd_can_read = usbredir_chardev_can_read,
|
|
|
|
+ .fd_read = usbredir_chardev_read,
|
|
|
|
+ .fd_event = usbredir_chardev_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* init + destroy
|
|
|
|
*/
|
2012-10-28 18:05:07 +00:00
|
|
|
@@ -905,8 +911,7 @@ static int usbredir_initfn(USBDevice *udev)
|
2012-07-05 09:22:23 +00:00
|
|
|
|
|
|
|
/* Let the backend know we are ready */
|
|
|
|
qemu_chr_fe_open(dev->cs);
|
|
|
|
- qemu_chr_add_handlers(dev->cs, usbredir_chardev_can_read,
|
|
|
|
- usbredir_chardev_read, usbredir_chardev_event, dev);
|
|
|
|
+ qemu_chr_add_handlers(dev->cs, &usbredir_chr_handlers, dev);
|
|
|
|
|
|
|
|
add_boot_device_path(dev->bootindex, &udev->qdev, NULL);
|
|
|
|
return 0;
|
2012-01-13 19:46:23 +00:00
|
|
|
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
|
2012-07-05 09:22:23 +00:00
|
|
|
index cffee3d..066590c 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/virtio-console.c
|
|
|
|
+++ b/hw/virtio-console.c
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -106,6 +106,12 @@ static void chr_event(void *opaque, int event)
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers chr_handlers = {
|
|
|
|
+ .fd_can_read = chr_can_read,
|
|
|
|
+ .fd_read = chr_read,
|
|
|
|
+ .fd_event = chr_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int virtconsole_initfn(VirtIOSerialPort *port)
|
|
|
|
{
|
|
|
|
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -117,8 +123,7 @@ static int virtconsole_initfn(VirtIOSerialPort *port)
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
if (vcon->chr) {
|
|
|
|
- qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
|
|
|
|
- vcon);
|
|
|
|
+ qemu_chr_add_handlers(vcon->chr, &chr_handlers, vcon);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
return 0;
|
|
|
|
diff --git a/hw/xen_console.c b/hw/xen_console.c
|
2012-08-06 19:53:39 +00:00
|
|
|
index 9426d73..e9fcadc 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/xen_console.c
|
|
|
|
+++ b/hw/xen_console.c
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -211,6 +211,11 @@ out:
|
2012-01-13 19:46:23 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers xencons_handlers = {
|
|
|
|
+ .fd_can_read = xencons_can_receive,
|
|
|
|
+ .fd_read = xencons_receive,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int con_initialise(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -231,9 +236,9 @@ static int con_initialise(struct XenDevice *xendev)
|
2012-01-13 19:46:23 +00:00
|
|
|
return -1;
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
xen_be_bind_evtchn(&con->xendev);
|
|
|
|
- if (con->chr)
|
|
|
|
- qemu_chr_add_handlers(con->chr, xencons_can_receive, xencons_receive,
|
|
|
|
- NULL, con);
|
|
|
|
+ if (con->chr) {
|
|
|
|
+ qemu_chr_add_handlers(con->chr, &xencons_handlers, con);
|
|
|
|
+ }
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
xen_be_printf(xendev, 1, "ring mfn %d, remote port %d, local port %d, limit %zd\n",
|
|
|
|
con->ring_ref,
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -250,8 +255,9 @@ static void con_disconnect(struct XenDevice *xendev)
|
2012-07-05 09:22:23 +00:00
|
|
|
if (!xendev->dev) {
|
|
|
|
return;
|
|
|
|
}
|
2012-01-13 19:46:23 +00:00
|
|
|
- if (con->chr)
|
|
|
|
- qemu_chr_add_handlers(con->chr, NULL, NULL, NULL, NULL);
|
|
|
|
+ if (con->chr) {
|
|
|
|
+ qemu_chr_add_handlers(con->chr, NULL, NULL);
|
|
|
|
+ }
|
|
|
|
xen_be_unbind_evtchn(&con->xendev);
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
if (con->sring) {
|
|
|
|
diff --git a/hw/xilinx_uartlite.c b/hw/xilinx_uartlite.c
|
2012-08-06 19:53:39 +00:00
|
|
|
index d0f32db..33f0cd5 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/hw/xilinx_uartlite.c
|
|
|
|
+++ b/hw/xilinx_uartlite.c
|
|
|
|
@@ -195,6 +195,12 @@ static void uart_event(void *opaque, int event)
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers uart_handlers = {
|
|
|
|
+ .fd_can_read = uart_can_rx,
|
|
|
|
+ .fd_read = uart_rx,
|
|
|
|
+ .fd_event = uart_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int xilinx_uartlite_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
struct xlx_uartlite *s = FROM_SYSBUS(typeof (*s), dev);
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -207,8 +213,9 @@ static int xilinx_uartlite_init(SysBusDevice *dev)
|
2012-07-05 09:22:23 +00:00
|
|
|
sysbus_init_mmio(dev, &s->mmio);
|
|
|
|
|
|
|
|
s->chr = qemu_char_get_next_serial();
|
2012-01-13 19:46:23 +00:00
|
|
|
- if (s->chr)
|
|
|
|
- qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
|
|
|
|
+ if (s->chr) {
|
|
|
|
+ qemu_chr_add_handlers(s->chr, &uart_handlers, s);
|
|
|
|
+ }
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
diff --git a/monitor.c b/monitor.c
|
2012-10-28 18:05:07 +00:00
|
|
|
index f45cf92..99eee98 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/monitor.c
|
|
|
|
+++ b/monitor.c
|
2012-10-28 18:05:07 +00:00
|
|
|
@@ -4942,6 +4942,18 @@ static void sortcmdlist(void)
|
2012-01-13 19:46:23 +00:00
|
|
|
* End:
|
|
|
|
*/
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers monitor_handlers = {
|
|
|
|
+ .fd_can_read = monitor_can_read,
|
|
|
|
+ .fd_read = monitor_read,
|
|
|
|
+ .fd_event = monitor_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static const QemuChrHandlers monitor_control_handlers = {
|
|
|
|
+ .fd_can_read = monitor_can_read,
|
|
|
|
+ .fd_read = monitor_control_read,
|
|
|
|
+ .fd_event = monitor_control_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
void monitor_init(CharDriverState *chr, int flags)
|
|
|
|
{
|
|
|
|
static int is_first_init = 1;
|
2012-10-28 18:05:07 +00:00
|
|
|
@@ -4965,14 +4977,12 @@ void monitor_init(CharDriverState *chr, int flags)
|
2012-01-13 19:46:23 +00:00
|
|
|
if (monitor_ctrl_mode(mon)) {
|
|
|
|
mon->mc = g_malloc0(sizeof(MonitorControl));
|
|
|
|
/* Control mode requires special handlers */
|
|
|
|
- qemu_chr_add_handlers(chr, monitor_can_read, monitor_control_read,
|
|
|
|
- monitor_control_event, mon);
|
|
|
|
+ qemu_chr_add_handlers(chr, &monitor_control_handlers, mon);
|
|
|
|
qemu_chr_fe_set_echo(chr, true);
|
2012-08-28 15:15:48 +00:00
|
|
|
|
|
|
|
json_message_parser_init(&mon->mc->parser, handle_qmp_command);
|
2012-01-13 19:46:23 +00:00
|
|
|
} else {
|
|
|
|
- qemu_chr_add_handlers(chr, monitor_can_read, monitor_read,
|
|
|
|
- monitor_event, mon);
|
|
|
|
+ qemu_chr_add_handlers(chr, &monitor_handlers, mon);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
QLIST_INSERT_HEAD(&mon_list, mon, entry);
|
|
|
|
diff --git a/net/slirp.c b/net/slirp.c
|
2012-08-28 15:15:48 +00:00
|
|
|
index 8db66ea..63542cb 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/net/slirp.c
|
|
|
|
+++ b/net/slirp.c
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -593,6 +593,11 @@ static void guestfwd_read(void *opaque, const uint8_t *buf, int size)
|
2012-01-13 19:46:23 +00:00
|
|
|
slirp_socket_recv(fwd->slirp, fwd->server, fwd->port, buf, size);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers guestfwd_handlers = {
|
|
|
|
+ .fd_can_read = guestfwd_can_read,
|
|
|
|
+ .fd_read = guestfwd_read,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static int slirp_guestfwd(SlirpState *s, const char *config_str,
|
|
|
|
int legacy_format)
|
|
|
|
{
|
2012-08-06 19:53:39 +00:00
|
|
|
@@ -658,8 +663,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str,
|
|
|
|
fwd->port = port;
|
|
|
|
fwd->slirp = s->slirp;
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-08-06 19:53:39 +00:00
|
|
|
- qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,
|
|
|
|
- NULL, fwd);
|
|
|
|
+ qemu_chr_add_handlers(fwd->hd, &guestfwd_handlers, fwd);
|
|
|
|
}
|
2012-01-13 19:46:23 +00:00
|
|
|
return 0;
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
diff --git a/qemu-char.c b/qemu-char.c
|
2012-10-28 18:05:07 +00:00
|
|
|
index a1fdf88..bd443db 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/qemu-char.c
|
|
|
|
+++ b/qemu-char.c
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -192,19 +192,26 @@ void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
|
2012-01-13 19:46:23 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers null_handlers = {
|
|
|
|
+ /* All handlers are initialised to NULL */
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
void qemu_chr_add_handlers(CharDriverState *s,
|
|
|
|
- IOCanReadHandler *fd_can_read,
|
|
|
|
- IOReadHandler *fd_read,
|
|
|
|
- IOEventHandler *fd_event,
|
|
|
|
- void *opaque)
|
|
|
|
+ const QemuChrHandlers *handlers, void *opaque)
|
|
|
|
{
|
|
|
|
- if (!opaque && !fd_can_read && !fd_read && !fd_event) {
|
|
|
|
+ if (!s) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (!opaque && !handlers) {
|
|
|
|
/* chr driver being released. */
|
|
|
|
++s->avail_connections;
|
|
|
|
}
|
|
|
|
- s->chr_can_read = fd_can_read;
|
|
|
|
- s->chr_read = fd_read;
|
|
|
|
- s->chr_event = fd_event;
|
|
|
|
+ if (!handlers) {
|
|
|
|
+ handlers = &null_handlers;
|
|
|
|
+ }
|
|
|
|
+ s->chr_can_read = handlers->fd_can_read;
|
|
|
|
+ s->chr_read = handlers->fd_read;
|
|
|
|
+ s->chr_event = handlers->fd_event;
|
|
|
|
s->handler_opaque = opaque;
|
|
|
|
if (s->chr_update_read_handler)
|
|
|
|
s->chr_update_read_handler(s);
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -442,6 +449,12 @@ static void mux_chr_event(void *opaque, int event)
|
2012-01-13 19:46:23 +00:00
|
|
|
mux_chr_send_event(d, i, event);
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
+static const QemuChrHandlers mux_chr_handlers = {
|
|
|
|
+ .fd_can_read = mux_chr_can_read,
|
|
|
|
+ .fd_read = mux_chr_read,
|
|
|
|
+ .fd_event = mux_chr_event,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
static void mux_chr_update_read_handler(CharDriverState *chr)
|
|
|
|
{
|
|
|
|
MuxDriver *d = chr->opaque;
|
2012-07-05 09:22:23 +00:00
|
|
|
@@ -456,8 +469,7 @@ static void mux_chr_update_read_handler(CharDriverState *chr)
|
2012-01-13 19:46:23 +00:00
|
|
|
d->chr_event[d->mux_cnt] = chr->chr_event;
|
|
|
|
/* Fix up the real driver with mux routines */
|
|
|
|
if (d->mux_cnt == 0) {
|
|
|
|
- qemu_chr_add_handlers(d->drv, mux_chr_can_read, mux_chr_read,
|
|
|
|
- mux_chr_event, chr);
|
|
|
|
+ qemu_chr_add_handlers(d->drv, &mux_chr_handlers, chr);
|
|
|
|
}
|
|
|
|
if (d->focus != -1) {
|
|
|
|
mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_OUT);
|
|
|
|
diff --git a/qemu-char.h b/qemu-char.h
|
2012-07-05 09:22:23 +00:00
|
|
|
index 486644b..dfa8c2d 100644
|
2012-01-13 19:46:23 +00:00
|
|
|
--- a/qemu-char.h
|
|
|
|
+++ b/qemu-char.h
|
|
|
|
@@ -222,10 +222,15 @@ void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
|
|
|
|
*/
|
|
|
|
void qemu_chr_be_event(CharDriverState *s, int event);
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
-void qemu_chr_add_handlers(CharDriverState *s,
|
|
|
|
- IOCanReadHandler *fd_can_read,
|
|
|
|
- IOReadHandler *fd_read,
|
|
|
|
- IOEventHandler *fd_event,
|
|
|
|
+
|
|
|
|
+typedef struct QemuChrHandlers {
|
|
|
|
+ IOCanReadHandler *fd_can_read;
|
|
|
|
+ IOReadHandler *fd_read;
|
|
|
|
+ IOHandler *fd_write_unblocked;
|
|
|
|
+ IOEventHandler *fd_event;
|
|
|
|
+} QemuChrHandlers;
|
|
|
|
+
|
|
|
|
+void qemu_chr_add_handlers(CharDriverState *s, const QemuChrHandlers *handlers,
|
|
|
|
void *opaque);
|
2012-07-05 09:22:23 +00:00
|
|
|
|
2012-01-13 19:46:23 +00:00
|
|
|
void qemu_chr_generic_open(CharDriverState *s);
|
2012-07-05 09:22:23 +00:00
|
|
|
diff --git a/qtest.c b/qtest.c
|
|
|
|
index fbfab4e..4ab5b69 100644
|
|
|
|
--- a/qtest.c
|
|
|
|
+++ b/qtest.c
|
|
|
|
@@ -416,6 +416,13 @@ static void qtest_event(void *opaque, int event)
|
2012-01-13 19:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-05 09:22:23 +00:00
|
|
|
|
|
|
|
+static const QemuChrHandlers test_handlers = {
|
|
|
|
+ .fd_can_read = qtest_can_read,
|
|
|
|
+ .fd_read = qtest_read,
|
|
|
|
+ .fd_event = qtest_event,
|
2012-01-13 19:46:23 +00:00
|
|
|
+};
|
|
|
|
+
|
2012-07-05 09:22:23 +00:00
|
|
|
+
|
|
|
|
int qtest_init(void)
|
|
|
|
{
|
|
|
|
CharDriverState *chr;
|
|
|
|
@@ -425,7 +432,7 @@ int qtest_init(void)
|
|
|
|
configure_icount("0");
|
|
|
|
chr = qemu_chr_new("qtest", qtest_chrdev, NULL);
|
|
|
|
|
|
|
|
- qemu_chr_add_handlers(chr, qtest_can_read, qtest_read, qtest_event, chr);
|
|
|
|
+ qemu_chr_add_handlers(chr, &test_handlers, chr);
|
|
|
|
qemu_chr_fe_set_echo(chr, true);
|
|
|
|
|
|
|
|
inbuf = g_string_new("");
|
2012-01-13 19:46:23 +00:00
|
|
|
--
|
2012-12-16 23:27:22 +00:00
|
|
|
1.8.0.2
|
2012-01-13 19:46:23 +00:00
|
|
|
|