qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 11/12] char: make all devices do qemu_chr_fe_open()


From: Anthony Liguori
Subject: [Qemu-devel] [PATCH 11/12] char: make all devices do qemu_chr_fe_open()
Date: Mon, 1 Aug 2011 09:23:09 -0500

The semantics of guest_open are unreliable today because they there's no way
of knowing whether a front end will ever call open.

Let's make them reliable which means making everything call open.

Signed-off-by: Anthony Liguori <address@hidden>
---
 gdbstub.c               |    1 +
 hw/ccid-card-passthru.c |    1 +
 hw/debugcon.c           |    1 +
 hw/escc.c               |    1 +
 hw/etraxfs_ser.c        |    4 +++-
 hw/grlib_apbuart.c      |    1 +
 hw/ivshmem.c            |    2 ++
 hw/lm32_juart.c         |    1 +
 hw/lm32_uart.c          |    1 +
 hw/mcf_uart.c           |    1 +
 hw/milkymist-uart.c     |    1 +
 hw/pl011.c              |    1 +
 hw/pxa2xx.c             |    4 +++-
 hw/serial.c             |    2 ++
 hw/sh_serial.c          |    4 +++-
 hw/spapr_vty.c          |    1 +
 hw/strongarm.c          |    1 +
 hw/syborg_serial.c      |    1 +
 hw/usb-serial.c         |    1 +
 hw/xen_console.c        |    8 ++++++--
 hw/xilinx_uartlite.c    |    4 +++-
 monitor.c               |    2 ++
 usb-redir.c             |    1 +
 23 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 058c626..8e0459e 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2768,6 +2768,7 @@ int gdbserver_start(const char *device)
         if (!chr)
             return -1;
 
+        qemu_chr_fe_open(chr);
         qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive,
                               gdb_chr_event, NULL);
     }
diff --git a/hw/ccid-card-passthru.c b/hw/ccid-card-passthru.c
index 082fd82..00468c9 100644
--- a/hw/ccid-card-passthru.c
+++ b/hw/ccid-card-passthru.c
@@ -281,6 +281,7 @@ static int passthru_initfn(CCIDCardState *base)
     card->vscard_in_hdr = 0;
     if (card->cs) {
         DPRINTF(card, D_INFO, "initing chardev\n");
+        qemu_chr_fe_open(card->cs);
         qemu_chr_add_handlers(card->cs,
             ccid_card_vscard_can_read,
             ccid_card_vscard_read,
diff --git a/hw/debugcon.c b/hw/debugcon.c
index c9ee6d9..1faa918 100644
--- a/hw/debugcon.c
+++ b/hw/debugcon.c
@@ -73,6 +73,7 @@ static void debugcon_init_core(DebugconState *s)
         exit(1);
     }
 
+    qemu_chr_fe_open(s->chr);
     qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
 }
 
diff --git a/hw/escc.c b/hw/escc.c
index c1460b7..9f98bba 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -911,6 +911,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_fe_open(s->chn[i].chr);
             qemu_chr_add_handlers(s->chn[i].chr, serial_can_receive,
                                   serial_receive1, serial_event, &s->chn[i]);
         }
diff --git a/hw/etraxfs_ser.c b/hw/etraxfs_ser.c
index 35f8325..ccffa3e 100644
--- a/hw/etraxfs_ser.c
+++ b/hw/etraxfs_ser.c
@@ -212,10 +212,12 @@ static int etraxfs_ser_init(SysBusDevice *dev)
                                       DEVICE_NATIVE_ENDIAN);
     sysbus_init_mmio(dev, R_MAX * 4, ser_regs);
     s->chr = qdev_init_chardev(&dev->qdev);
-    if (s->chr)
+    if (s->chr) {
+        qemu_chr_fe_open(s->chr);
         qemu_chr_add_handlers(s->chr,
                       serial_can_receive, serial_receive,
                       serial_event, s);
+    }
     return 0;
 }
 
diff --git a/hw/grlib_apbuart.c b/hw/grlib_apbuart.c
index c90b810..184a0c8 100644
--- a/hw/grlib_apbuart.c
+++ b/hw/grlib_apbuart.c
@@ -149,6 +149,7 @@ static int grlib_apbuart_init(SysBusDevice *dev)
     UART *uart      = FROM_SYSBUS(typeof(*uart), dev);
     int   uart_regs = 0;
 
+    qemu_chr_fe_open(uart->chr);
     qemu_chr_add_handlers(uart->chr,
                           grlib_apbuart_can_receive,
                           grlib_apbuart_receive,
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index 3055dd2..6c126eb 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -326,6 +326,7 @@ static CharDriverState* create_eventfd_chr_device(void * 
opaque, int eventfd,
         exit(-1);
     }
 
+    qemu_chr_fe_open(chr);
     /* if MSI is supported we need multiple interrupts */
     if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
         s->eventfd_table[vector].pdev = &s->dev;
@@ -749,6 +750,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
 
         s->eventfd_chr = qemu_mallocz(s->vectors * sizeof(CharDriverState *));
 
+        qemu_chr_fe_open(s->server_chr);
         qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read,
                      ivshmem_event, s);
     } else {
diff --git a/hw/lm32_juart.c b/hw/lm32_juart.c
index 5454aa4..c3bf70c 100644
--- a/hw/lm32_juart.c
+++ b/hw/lm32_juart.c
@@ -116,6 +116,7 @@ static int lm32_juart_init(SysBusDevice *dev)
 
     s->chr = qdev_init_chardev(&dev->qdev);
     if (s->chr) {
+        qemu_chr_fe_open(s->chr);
         qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, juart_event, s);
     }
 
diff --git a/hw/lm32_uart.c b/hw/lm32_uart.c
index 3678545..3dbe735 100644
--- a/hw/lm32_uart.c
+++ b/hw/lm32_uart.c
@@ -255,6 +255,7 @@ static int lm32_uart_init(SysBusDevice *dev)
 
     s->chr = qdev_init_chardev(&dev->qdev);
     if (s->chr) {
+        qemu_chr_fe_open(s->chr);
         qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
     }
 
diff --git a/hw/mcf_uart.c b/hw/mcf_uart.c
index 747bc36..fcd18c7 100644
--- a/hw/mcf_uart.c
+++ b/hw/mcf_uart.c
@@ -276,6 +276,7 @@ void *mcf_uart_init(qemu_irq irq, CharDriverState *chr)
     s->chr = chr;
     s->irq = irq;
     if (chr) {
+        qemu_chr_fe_open(chr);
         qemu_chr_add_handlers(chr, mcf_uart_can_receive, mcf_uart_receive,
                               mcf_uart_event, s);
     }
diff --git a/hw/milkymist-uart.c b/hw/milkymist-uart.c
index e8e309d..0579534 100644
--- a/hw/milkymist-uart.c
+++ b/hw/milkymist-uart.c
@@ -147,6 +147,7 @@ static int milkymist_uart_init(SysBusDevice *dev)
 
     s->chr = qdev_init_chardev(&dev->qdev);
     if (s->chr) {
+        qemu_chr_fe_open(s->chr);
         qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
     }
 
diff --git a/hw/pl011.c b/hw/pl011.c
index 707a161..1d99c62 100644
--- a/hw/pl011.c
+++ b/hw/pl011.c
@@ -278,6 +278,7 @@ static int pl011_init(SysBusDevice *dev, const unsigned 
char *id)
     s->cr = 0x300;
     s->flags = 0x90;
     if (s->chr) {
+        qemu_chr_fe_open(s->chr);
         qemu_chr_add_handlers(s->chr, pl011_can_receive, pl011_receive,
                               pl011_event, s);
     }
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
index 7516454..b562b42 100644
--- a/hw/pxa2xx.c
+++ b/hw/pxa2xx.c
@@ -2038,9 +2038,11 @@ static PXA2xxFIrState 
*pxa2xx_fir_init(target_phys_addr_t base,
                     pxa2xx_fir_writefn, s, DEVICE_NATIVE_ENDIAN);
     cpu_register_physical_memory(base, 0x1000, iomemtype);
 
-    if (chr)
+    if (chr) {
+        qemu_chr_fe_open(chr);
         qemu_chr_add_handlers(chr, pxa2xx_fir_is_empty,
                         pxa2xx_fir_rx, pxa2xx_fir_event, s);
+    }
 
     register_savevm(NULL, "pxa2xx_fir", 0, 0, pxa2xx_fir_save,
                     pxa2xx_fir_load, s);
diff --git a/hw/serial.c b/hw/serial.c
index dc6d1f8..c1c2d76 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -741,6 +741,8 @@ static void serial_init_core(SerialState *s)
 
     qemu_register_reset(serial_reset, s);
 
+    qemu_chr_fe_open(s->chr);
+
     qemu_chr_add_handlers(s->chr, serial_can_receive1, serial_receive1,
                           serial_event, s);
 }
diff --git a/hw/sh_serial.c b/hw/sh_serial.c
index eabd726..3cf4df2 100644
--- a/hw/sh_serial.c
+++ b/hw/sh_serial.c
@@ -389,9 +389,11 @@ void sh_serial_init (target_phys_addr_t base, int feat,
 
     s->chr = chr;
 
-    if (chr)
+    if (chr) {
+        qemu_chr_fe_open(chr);
         qemu_chr_add_handlers(chr, sh_serial_can_receive1, sh_serial_receive1,
                              sh_serial_event, s);
+    }
 
     s->eri = eri_source;
     s->rxi = rxi_source;
diff --git a/hw/spapr_vty.c b/hw/spapr_vty.c
index f5046d9..fbb9dcf 100644
--- a/hw/spapr_vty.c
+++ b/hw/spapr_vty.c
@@ -58,6 +58,7 @@ static int spapr_vty_init(VIOsPAPRDevice *sdev)
 {
     VIOsPAPRVTYDevice *dev = (VIOsPAPRVTYDevice *)sdev;
 
+    qemu_chr_fe_open(dev->chardev);
     qemu_chr_add_handlers(dev->chardev, vty_can_receive,
                           vty_receive, NULL, dev);
 
diff --git a/hw/strongarm.c b/hw/strongarm.c
index 50fe0c0..cd10749 100644
--- a/hw/strongarm.c
+++ b/hw/strongarm.c
@@ -1202,6 +1202,7 @@ static int strongarm_uart_init(SysBusDevice *dev)
     s->tx_timer = qemu_new_timer_ns(vm_clock, strongarm_uart_tx, s);
 
     if (s->chr) {
+        qemu_chr_fe_open(s->chr);
         qemu_chr_add_handlers(s->chr,
                         strongarm_uart_can_receive,
                         strongarm_uart_receive,
diff --git a/hw/syborg_serial.c b/hw/syborg_serial.c
index 25c6c9d..748ec94 100644
--- a/hw/syborg_serial.c
+++ b/hw/syborg_serial.c
@@ -304,6 +304,7 @@ static int syborg_serial_init(SysBusDevice *dev)
     sysbus_init_mmio(dev, 0x1000, iomemtype);
     s->chr = qdev_init_chardev(&dev->qdev);
     if (s->chr) {
+        qemu_chr_fe_open(s->chr);
         qemu_chr_add_handlers(s->chr, syborg_serial_can_receive,
                               syborg_serial_receive, syborg_serial_event, s);
     }
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index f093d18..63b5aa3 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -487,6 +487,7 @@ static int usb_serial_initfn(USBDevice *dev)
         return -1;
     }
 
+    qemu_chr_fe_open(s->cs);
     qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read,
                           usb_serial_event, s);
     usb_serial_handle_reset(dev);
diff --git a/hw/xen_console.c b/hw/xen_console.c
index e218bb8..35975a3 100644
--- a/hw/xen_console.c
+++ b/hw/xen_console.c
@@ -232,9 +232,11 @@ static int con_connect(struct XenDevice *xendev)
        return -1;
 
     xen_be_bind_evtchn(&con->xendev);
-    if (con->chr)
+    if (con->chr) {
+        qemu_chr_fe_open(con->chr);
         qemu_chr_add_handlers(con->chr, xencons_can_receive, xencons_receive,
                               NULL, con);
+    }
 
     xen_be_printf(xendev, 1, "ring mfn %d, remote port %d, local port %d, 
limit %zd\n",
                  con->ring_ref,
@@ -248,8 +250,10 @@ static void con_disconnect(struct XenDevice *xendev)
 {
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
 
-    if (con->chr)
+    if (con->chr) {
         qemu_chr_add_handlers(con->chr, NULL, NULL, NULL, NULL);
+        qemu_chr_fe_close(con->chr);
+    }
     xen_be_unbind_evtchn(&con->xendev);
 
     if (con->sring) {
diff --git a/hw/xilinx_uartlite.c b/hw/xilinx_uartlite.c
index 467a26c..9b40d16 100644
--- a/hw/xilinx_uartlite.c
+++ b/hw/xilinx_uartlite.c
@@ -206,8 +206,10 @@ static int xilinx_uartlite_init(SysBusDevice *dev)
     sysbus_init_mmio(dev, R_MAX * 4, uart_regs);
 
     s->chr = qdev_init_chardev(&dev->qdev);
-    if (s->chr)
+    if (s->chr) {
+        qemu_chr_fe_open(s->chr);
         qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
+    }
     return 0;
 }
 
diff --git a/monitor.c b/monitor.c
index 3ca211b..413ee1e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -5276,6 +5276,8 @@ void monitor_init(CharDriverState *chr, int flags)
         monitor_read_command(mon, 0);
     }
 
+    qemu_chr_fe_open(chr);
+
     if (monitor_ctrl_mode(mon)) {
         mon->mc = qemu_mallocz(sizeof(MonitorControl));
         /* Control mode requires special handlers */
diff --git a/usb-redir.c b/usb-redir.c
index 606bc98..6b94161 100644
--- a/usb-redir.c
+++ b/usb-redir.c
@@ -807,6 +807,7 @@ static int usbredir_initfn(USBDevice *udev)
     /* We'll do the attach once we receive the speed from the usb-host */
     udev->auto_attach = 0;
 
+    qemu_chr_fe_open(dev->cs);
     qemu_chr_add_handlers(dev->cs, usbredir_chardev_can_read,
                           usbredir_chardev_read, usbredir_chardev_event, dev);
 
-- 
1.7.4.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]