All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v5 0/4] QOM'ify hw/char devices
@ 2016-05-23 10:24 xiaoqiang zhao
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 1/4] hw/char: QOM'ify escc.c xiaoqiang zhao
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: xiaoqiang zhao @ 2016-05-23 10:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: pbonzini, michael, peter.maydell, edgar.iglesias, agraf, armbru

This patch set trys to QOM'ify hw/char files, see commit messages 
for more details

Thanks Paolo <pbonzini@redhat.com> for your suggestions.

Note:
* CRIS axis_dev88 broad related test is passed and looks ok. 
* lm32 test cases by Michael <michael@walle.cc> is passed and looks good.

Changes in v5:
  drop the call of qemu_char_get_next_serial in board code and
  direct access serial_hds array

Changes in v4: 
* add wrapper functions to create char device
* drop the sysbus_create_simple function and 
  use the new qdev_create stuff

Changes in v3: 
* use chardev property instead of qemu_char_get_next_serial
* call the functions that touch globals in the realize callback


xiaoqiang zhao (4):
  hw/char: QOM'ify escc.c
  hw/char: QOM'ify etraxfs_ser.c
  hw/char: QOM'ify lm32_juart.c
  hw/char: QOM'ify lm32_uart.c

 hw/char/escc.c            | 30 +++++++++++++++++++-----------
 hw/char/etraxfs_ser.c     | 27 +++++++++++++++++----------
 hw/char/lm32_juart.c      | 17 ++++++++---------
 hw/char/lm32_uart.c       | 28 +++++++++++++++++-----------
 hw/cris/axis_dev88.c      |  4 ++--
 hw/lm32/lm32.h            | 18 ++++++++++++++++++
 hw/lm32/lm32_boards.c     |  4 ++--
 include/hw/cris/etraxfs.h | 16 ++++++++++++++++
 8 files changed, 99 insertions(+), 45 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v5 1/4] hw/char: QOM'ify escc.c
  2016-05-23 10:24 [Qemu-devel] [PATCH v5 0/4] QOM'ify hw/char devices xiaoqiang zhao
@ 2016-05-23 10:24 ` xiaoqiang zhao
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 2/4] hw/char: QOM'ify etraxfs_ser.c xiaoqiang zhao
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: xiaoqiang zhao @ 2016-05-23 10:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: pbonzini, michael, peter.maydell, edgar.iglesias, agraf, armbru

* Drop the old SysBus init function and use instance_init
* Call qemu_chr_add_handlers in the realize callback

Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
---
 hw/char/escc.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/hw/char/escc.c b/hw/char/escc.c
index 7bf09a0..8e6a7df 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -983,9 +983,10 @@ void slavio_serial_ms_kbd_init(hwaddr base, qemu_irq irq,
     sysbus_mmio_map(s, 0, base);
 }
 
-static int escc_init1(SysBusDevice *dev)
+static void escc_init1(Object *obj)
 {
-    ESCCState *s = ESCC(dev);
+    ESCCState *s = ESCC(obj);
+    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
     unsigned int i;
 
     s->chn[0].disabled = s->disabled;
@@ -994,17 +995,26 @@ static int escc_init1(SysBusDevice *dev)
         sysbus_init_irq(dev, &s->chn[i].irq);
         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]);
-        }
     }
     s->chn[0].otherchn = &s->chn[1];
     s->chn[1].otherchn = &s->chn[0];
 
-    memory_region_init_io(&s->mmio, OBJECT(s), &escc_mem_ops, s, "escc",
+    memory_region_init_io(&s->mmio, obj, &escc_mem_ops, s, "escc",
                           ESCC_SIZE << s->it_shift);
     sysbus_init_mmio(dev, &s->mmio);
+}
+
+static void escc_realize(DeviceState *dev, Error **errp)
+{
+    ESCCState *s = ESCC(dev);
+    unsigned int i;
+
+    for (i = 0; i < 2; i++) {
+        if (s->chn[i].chr) {
+            qemu_chr_add_handlers(s->chn[i].chr, serial_can_receive,
+                                  serial_receive1, serial_event, &s->chn[i]);
+        }
+    }
 
     if (s->chn[0].type == mouse) {
         qemu_add_mouse_event_handler(sunmouse_event, &s->chn[0], 0,
@@ -1014,8 +1024,6 @@ static int escc_init1(SysBusDevice *dev)
         s->chn[1].hs = qemu_input_handler_register((DeviceState *)(&s->chn[1]),
                                                    &sunkbd_handler);
     }
-
-    return 0;
 }
 
 static Property escc_properties[] = {
@@ -1032,10 +1040,9 @@ static Property escc_properties[] = {
 static void escc_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = escc_init1;
     dc->reset = escc_reset;
+    dc->realize = escc_realize;
     dc->vmsd = &vmstate_escc;
     dc->props = escc_properties;
     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
@@ -1045,6 +1052,7 @@ static const TypeInfo escc_info = {
     .name          = TYPE_ESCC,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(ESCCState),
+    .instance_init = escc_init1,
     .class_init    = escc_class_init,
 };
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v5 2/4] hw/char: QOM'ify etraxfs_ser.c
  2016-05-23 10:24 [Qemu-devel] [PATCH v5 0/4] QOM'ify hw/char devices xiaoqiang zhao
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 1/4] hw/char: QOM'ify escc.c xiaoqiang zhao
@ 2016-05-23 10:24 ` xiaoqiang zhao
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 3/4] hw/char: QOM'ify lm32_juart.c xiaoqiang zhao
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 4/4] hw/char: QOM'ify lm32_uart.c xiaoqiang zhao
  3 siblings, 0 replies; 8+ messages in thread
From: xiaoqiang zhao @ 2016-05-23 10:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: pbonzini, michael, peter.maydell, edgar.iglesias, agraf, armbru

* Drop the old SysBus init function and use instance_init
* Call qemu_chr_add_handlers in the realize callback
* Use qdev chardev prop instead of qemu_char_get_next_serial
* Add etraxfs_ser_create function to create etraxfs serial device

Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
---
 hw/char/etraxfs_ser.c     | 27 +++++++++++++++++----------
 hw/cris/axis_dev88.c      |  4 ++--
 include/hw/cris/etraxfs.h | 16 ++++++++++++++++
 3 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/hw/char/etraxfs_ser.c b/hw/char/etraxfs_ser.c
index 146b387..04ca04f 100644
--- a/hw/char/etraxfs_ser.c
+++ b/hw/char/etraxfs_ser.c
@@ -159,6 +159,11 @@ static const MemoryRegionOps ser_ops = {
     }
 };
 
+static Property etraxfs_ser_properties[] = {
+    DEFINE_PROP_CHR("chardev", ETRAXSerial, chr),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void serial_receive(void *opaque, const uint8_t *buf, int size)
 {
     ETRAXSerial *s = opaque;
@@ -209,40 +214,42 @@ static void etraxfs_ser_reset(DeviceState *d)
 
 }
 
-static int etraxfs_ser_init(SysBusDevice *dev)
+static void etraxfs_ser_init(Object *obj)
 {
-    ETRAXSerial *s = ETRAX_SERIAL(dev);
+    ETRAXSerial *s = ETRAX_SERIAL(obj);
+    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
 
     sysbus_init_irq(dev, &s->irq);
-    memory_region_init_io(&s->mmio, OBJECT(s), &ser_ops, s,
+    memory_region_init_io(&s->mmio, obj, &ser_ops, s,
                           "etraxfs-serial", R_MAX * 4);
     sysbus_init_mmio(dev, &s->mmio);
+}
+
+static void etraxfs_ser_realize(DeviceState *dev, Error **errp)
+{
+    ETRAXSerial *s = ETRAX_SERIAL(dev);
 
-    /* FIXME use a qdev chardev prop instead of qemu_char_get_next_serial() */
-    s->chr = qemu_char_get_next_serial();
     if (s->chr) {
         qemu_chr_add_handlers(s->chr,
                               serial_can_receive, serial_receive,
                               serial_event, s);
     }
-    return 0;
 }
 
 static void etraxfs_ser_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = etraxfs_ser_init;
     dc->reset = etraxfs_ser_reset;
-    /* Reason: init() method uses qemu_char_get_next_serial() */
-    dc->cannot_instantiate_with_device_add_yet = true;
+    dc->props = etraxfs_ser_properties;
+    dc->realize = etraxfs_ser_realize;
 }
 
 static const TypeInfo etraxfs_ser_info = {
     .name          = TYPE_ETRAX_FS_SERIAL,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(ETRAXSerial),
+    .instance_init = etraxfs_ser_init,
     .class_init    = etraxfs_ser_class_init,
 };
 
diff --git a/hw/cris/axis_dev88.c b/hw/cris/axis_dev88.c
index 9f58658..60df887 100644
--- a/hw/cris/axis_dev88.c
+++ b/hw/cris/axis_dev88.c
@@ -37,6 +37,7 @@
 #include "sysemu/block-backend.h"
 #include "exec/address-spaces.h"
 #include "sysemu/qtest.h"
+#include "sysemu/sysemu.h"
 
 #define D(x)
 #define DNAND(x)
@@ -341,8 +342,7 @@ void axisdev88_init(MachineState *machine)
     sysbus_create_varargs("etraxfs,timer", 0x3005e000, irq[0x1b], nmi[1], NULL);
 
     for (i = 0; i < 4; i++) {
-        sysbus_create_simple("etraxfs,serial", 0x30026000 + i * 0x2000,
-                             irq[0x14 + i]);
+        etraxfs_ser_create(0x30026000 + i * 0x2000, irq[0x14 + i], serial_hds[i]);
     }
 
     if (kernel_filename) {
diff --git a/include/hw/cris/etraxfs.h b/include/hw/cris/etraxfs.h
index 73a6134..eb66418 100644
--- a/include/hw/cris/etraxfs.h
+++ b/include/hw/cris/etraxfs.h
@@ -46,4 +46,20 @@ etraxfs_eth_init(NICInfo *nd, hwaddr base, int phyaddr,
     return dev;
 }
 
+static inline DeviceState *etraxfs_ser_create(hwaddr addr,
+                                              qemu_irq irq,
+                                              CharDriverState *chr)
+{
+    DeviceState *dev;
+    SysBusDevice *s;
+
+    dev = qdev_create(NULL, "etraxfs,serial");
+    s = SYS_BUS_DEVICE(dev);
+    qdev_prop_set_chr(dev, "chardev", chr);
+    qdev_init_nofail(dev);
+    sysbus_mmio_map(s, 0, addr);
+    sysbus_connect_irq(s, 0, irq);
+    return dev;
+}
+
 #endif
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v5 3/4] hw/char: QOM'ify lm32_juart.c
  2016-05-23 10:24 [Qemu-devel] [PATCH v5 0/4] QOM'ify hw/char devices xiaoqiang zhao
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 1/4] hw/char: QOM'ify escc.c xiaoqiang zhao
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 2/4] hw/char: QOM'ify etraxfs_ser.c xiaoqiang zhao
@ 2016-05-23 10:24 ` xiaoqiang zhao
  2016-05-23 11:18   ` Michael Walle
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 4/4] hw/char: QOM'ify lm32_uart.c xiaoqiang zhao
  3 siblings, 1 reply; 8+ messages in thread
From: xiaoqiang zhao @ 2016-05-23 10:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: pbonzini, michael, peter.maydell, edgar.iglesias, agraf, armbru

* Drop the old SysBus init function
* Call qemu_chr_add_handlers in the realize callback
* Use qdev chardev prop instead of qemu_char_get_next_serial

Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
---
 hw/char/lm32_juart.c | 17 ++++++++---------
 hw/lm32/lm32.h       |  2 ++
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/hw/char/lm32_juart.c b/hw/char/lm32_juart.c
index 5bf8acf..28c2cf7 100644
--- a/hw/char/lm32_juart.c
+++ b/hw/char/lm32_juart.c
@@ -114,17 +114,13 @@ static void juart_reset(DeviceState *d)
     s->jrx = 0;
 }
 
-static int lm32_juart_init(SysBusDevice *dev)
+static void lm32_juart_realize(DeviceState *dev, Error **errp)
 {
     LM32JuartState *s = LM32_JUART(dev);
 
-    /* FIXME use a qdev chardev prop instead of qemu_char_get_next_serial() */
-    s->chr = qemu_char_get_next_serial();
     if (s->chr) {
         qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, juart_event, s);
     }
-
-    return 0;
 }
 
 static const VMStateDescription vmstate_lm32_juart = {
@@ -138,16 +134,19 @@ static const VMStateDescription vmstate_lm32_juart = {
     }
 };
 
+static Property lm32_juart_properties[] = {
+    DEFINE_PROP_CHR("chardev", LM32JuartState, chr),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void lm32_juart_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = lm32_juart_init;
     dc->reset = juart_reset;
     dc->vmsd = &vmstate_lm32_juart;
-    /* Reason: init() method uses qemu_char_get_next_serial() */
-    dc->cannot_instantiate_with_device_add_yet = true;
+    dc->props = lm32_juart_properties;
+    dc->realize = lm32_juart_realize;
 }
 
 static const TypeInfo lm32_juart_info = {
diff --git a/hw/lm32/lm32.h b/hw/lm32/lm32.h
index 18aa6fd..6761518 100644
--- a/hw/lm32/lm32.h
+++ b/hw/lm32/lm32.h
@@ -2,6 +2,7 @@
 #define HW_LM32_H 1
 
 #include "hw/char/lm32_juart.h"
+#include "sysemu/sysemu.h"
 
 static inline DeviceState *lm32_pic_init(qemu_irq cpu_irq)
 {
@@ -21,6 +22,7 @@ static inline DeviceState *lm32_juart_init(void)
     DeviceState *dev;
 
     dev = qdev_create(NULL, TYPE_LM32_JUART);
+    qdev_prop_set_chr(dev, "chardev", serial_hds[1]);
     qdev_init_nofail(dev);
 
     return dev;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v5 4/4] hw/char: QOM'ify lm32_uart.c
  2016-05-23 10:24 [Qemu-devel] [PATCH v5 0/4] QOM'ify hw/char devices xiaoqiang zhao
                   ` (2 preceding siblings ...)
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 3/4] hw/char: QOM'ify lm32_juart.c xiaoqiang zhao
@ 2016-05-23 10:24 ` xiaoqiang zhao
  2016-05-23 11:09   ` Michael Walle
  3 siblings, 1 reply; 8+ messages in thread
From: xiaoqiang zhao @ 2016-05-23 10:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: pbonzini, michael, peter.maydell, edgar.iglesias, agraf, armbru

* Drop the old SysBus init function and use instance_init
* Call qemu_chr_add_handlers in the realize callback
* Use qdev chardev prop instead of qemu_char_get_next_serial
* Add lm32_uart_create function to create lm32 uart device

Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
---
 hw/char/lm32_uart.c   | 28 +++++++++++++++++-----------
 hw/lm32/lm32.h        | 16 ++++++++++++++++
 hw/lm32/lm32_boards.c |  4 ++--
 3 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/hw/char/lm32_uart.c b/hw/char/lm32_uart.c
index 036813d..b5c760d 100644
--- a/hw/char/lm32_uart.c
+++ b/hw/char/lm32_uart.c
@@ -249,23 +249,25 @@ static void uart_reset(DeviceState *d)
     s->regs[R_LSR] = LSR_THRE | LSR_TEMT;
 }
 
-static int lm32_uart_init(SysBusDevice *dev)
+static void lm32_uart_init(Object *obj)
 {
-    LM32UartState *s = LM32_UART(dev);
+    LM32UartState *s = LM32_UART(obj);
+    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
 
     sysbus_init_irq(dev, &s->irq);
 
-    memory_region_init_io(&s->iomem, OBJECT(s), &uart_ops, s,
+    memory_region_init_io(&s->iomem, obj, &uart_ops, s,
                           "uart", R_MAX * 4);
     sysbus_init_mmio(dev, &s->iomem);
+}
+
+static void lm32_uart_realize(DeviceState *dev, Error **errp)
+{
+    LM32UartState *s = LM32_UART(dev);
 
-    /* FIXME use a qdev chardev prop instead of qemu_char_get_next_serial() */
-    s->chr = qemu_char_get_next_serial();
     if (s->chr) {
         qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
     }
-
-    return 0;
 }
 
 static const VMStateDescription vmstate_lm32_uart = {
@@ -278,22 +280,26 @@ static const VMStateDescription vmstate_lm32_uart = {
     }
 };
 
+static Property lm32_uart_properties[] = {
+    DEFINE_PROP_CHR("chardev", LM32UartState, chr),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void lm32_uart_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = lm32_uart_init;
     dc->reset = uart_reset;
     dc->vmsd = &vmstate_lm32_uart;
-    /* Reason: init() method uses qemu_char_get_next_serial() */
-    dc->cannot_instantiate_with_device_add_yet = true;
+    dc->props = lm32_uart_properties;
+    dc->realize = lm32_uart_realize;
 }
 
 static const TypeInfo lm32_uart_info = {
     .name          = TYPE_LM32_UART,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(LM32UartState),
+    .instance_init = lm32_uart_init,
     .class_init    = lm32_uart_class_init,
 };
 
diff --git a/hw/lm32/lm32.h b/hw/lm32/lm32.h
index 6761518..9d35d88 100644
--- a/hw/lm32/lm32.h
+++ b/hw/lm32/lm32.h
@@ -28,4 +28,20 @@ static inline DeviceState *lm32_juart_init(void)
     return dev;
 }
 
+static inline DeviceState *lm32_uart_create(hwaddr addr,
+                                            qemu_irq irq,
+                                            CharDriverState *chr)
+{
+    DeviceState *dev;
+    SysBusDevice *s;
+
+    dev = qdev_create(NULL, "lm32-uart");
+    s = SYS_BUS_DEVICE(dev);
+    qdev_prop_set_chr(dev, "chardev", chr);
+    qdev_init_nofail(dev);
+    sysbus_mmio_map(s, 0, addr);
+    sysbus_connect_irq(s, 0, irq);
+    return dev;
+}
+
 #endif
diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
index c029056..9f5de67 100644
--- a/hw/lm32/lm32_boards.c
+++ b/hw/lm32/lm32_boards.c
@@ -131,7 +131,7 @@ static void lm32_evr_init(MachineState *machine)
         irq[i] = qdev_get_gpio_in(env->pic_state, i);
     }
 
-    sysbus_create_simple("lm32-uart", uart0_base, irq[uart0_irq]);
+    lm32_uart_create(uart0_base, irq[uart0_irq], serial_hds[0]);
     sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
     sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
 
@@ -232,7 +232,7 @@ static void lm32_uclinux_init(MachineState *machine)
         irq[i] = qdev_get_gpio_in(env->pic_state, i);
     }
 
-    sysbus_create_simple("lm32-uart", uart0_base, irq[uart0_irq]);
+    lm32_uart_create(uart0_base, irq[uart0_irq], serial_hds[0]);
     sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
     sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
     sysbus_create_simple("lm32-timer", timer2_base, irq[timer2_irq]);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v5 4/4] hw/char: QOM'ify lm32_uart.c
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 4/4] hw/char: QOM'ify lm32_uart.c xiaoqiang zhao
@ 2016-05-23 11:09   ` Michael Walle
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Walle @ 2016-05-23 11:09 UTC (permalink / raw)
  To: xiaoqiang zhao
  Cc: qemu-devel, pbonzini, peter.maydell, edgar.iglesias, agraf, armbru

Am 2016-05-23 12:24, schrieb xiaoqiang zhao:
> * Drop the old SysBus init function and use instance_init
> * Call qemu_chr_add_handlers in the realize callback
> * Use qdev chardev prop instead of qemu_char_get_next_serial
> * Add lm32_uart_create function to create lm32 uart device
> 
> Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>

Tested-by: Michael Walle <michael@walle.cc>
Acked-by: Michael Walle <michael@walle.cc>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v5 3/4] hw/char: QOM'ify lm32_juart.c
  2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 3/4] hw/char: QOM'ify lm32_juart.c xiaoqiang zhao
@ 2016-05-23 11:18   ` Michael Walle
  2016-05-23 11:34     ` xiaoqiang zhao
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Walle @ 2016-05-23 11:18 UTC (permalink / raw)
  To: xiaoqiang zhao
  Cc: qemu-devel, pbonzini, peter.maydell, edgar.iglesias, agraf, armbru

Am 2016-05-23 12:24, schrieb xiaoqiang zhao:
> * Drop the old SysBus init function
> * Call qemu_chr_add_handlers in the realize callback
> * Use qdev chardev prop instead of qemu_char_get_next_serial
> 
> Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
> ---
>  hw/char/lm32_juart.c | 17 ++++++++---------
>  hw/lm32/lm32.h       |  2 ++
>  2 files changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/char/lm32_juart.c b/hw/char/lm32_juart.c
> index 5bf8acf..28c2cf7 100644
> --- a/hw/char/lm32_juart.c
> +++ b/hw/char/lm32_juart.c
> @@ -114,17 +114,13 @@ static void juart_reset(DeviceState *d)
>      s->jrx = 0;
>  }
> 
> -static int lm32_juart_init(SysBusDevice *dev)
> +static void lm32_juart_realize(DeviceState *dev, Error **errp)
>  {
>      LM32JuartState *s = LM32_JUART(dev);
> 
> -    /* FIXME use a qdev chardev prop instead of 
> qemu_char_get_next_serial() */
> -    s->chr = qemu_char_get_next_serial();
>      if (s->chr) {
>          qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, 
> juart_event, s);
>      }
> -
> -    return 0;
>  }
> 
>  static const VMStateDescription vmstate_lm32_juart = {
> @@ -138,16 +134,19 @@ static const VMStateDescription 
> vmstate_lm32_juart = {
>      }
>  };
> 
> +static Property lm32_juart_properties[] = {
> +    DEFINE_PROP_CHR("chardev", LM32JuartState, chr),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
>  static void lm32_juart_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
> -    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
> 
> -    k->init = lm32_juart_init;
>      dc->reset = juart_reset;
>      dc->vmsd = &vmstate_lm32_juart;
> -    /* Reason: init() method uses qemu_char_get_next_serial() */
> -    dc->cannot_instantiate_with_device_add_yet = true;
> +    dc->props = lm32_juart_properties;
> +    dc->realize = lm32_juart_realize;
>  }
> 
>  static const TypeInfo lm32_juart_info = {
> diff --git a/hw/lm32/lm32.h b/hw/lm32/lm32.h
> index 18aa6fd..6761518 100644
> --- a/hw/lm32/lm32.h
> +++ b/hw/lm32/lm32.h
> @@ -2,6 +2,7 @@
>  #define HW_LM32_H 1
> 
>  #include "hw/char/lm32_juart.h"
> +#include "sysemu/sysemu.h"
> 
>  static inline DeviceState *lm32_pic_init(qemu_irq cpu_irq)
>  {
> @@ -21,6 +22,7 @@ static inline DeviceState *lm32_juart_init(void)
>      DeviceState *dev;
> 
>      dev = qdev_create(NULL, TYPE_LM32_JUART);
> +    qdev_prop_set_chr(dev, "chardev", serial_hds[1]);

Please make the serial_hds[1] a parameter to this function, like you did 
with the lm32_uart_create(). Then the serial_hds[] assignements will be 
in one place in lm32_boards.c.

Mhh, i guess for this to work with the milkymist board, milkymist-uart 
(hw/char/milkymist-uart.c) has to be converted too, because it still 
uses the qemu_char_get_next_serial() function. So if you like you may 
also convert this model. If not, I'll do it myself after picking your 
patches.

>      qdev_init_nofail(dev);
> 
>      return dev;

-michael

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v5 3/4] hw/char: QOM'ify lm32_juart.c
  2016-05-23 11:18   ` Michael Walle
@ 2016-05-23 11:34     ` xiaoqiang zhao
  0 siblings, 0 replies; 8+ messages in thread
From: xiaoqiang zhao @ 2016-05-23 11:34 UTC (permalink / raw)
  To: Michael Walle
  Cc: qemu-devel, pbonzini, peter.maydell, edgar.iglesias, agraf, armbru



> 在 2016年5月23日,19:18,Michael Walle <michael@walle.cc> 写道:
> 
> Am 2016-05-23 12:24, schrieb xiaoqiang zhao:
>> * Drop the old SysBus init function
>> * Call qemu_chr_add_handlers in the realize callback
>> * Use qdev chardev prop instead of qemu_char_get_next_serial
>> Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
>> ---
>> hw/char/lm32_juart.c | 17 ++++++++---------
>> hw/lm32/lm32.h       |  2 ++
>> 2 files changed, 10 insertions(+), 9 deletions(-)
>> diff --git a/hw/char/lm32_juart.c b/hw/char/lm32_juart.c
>> index 5bf8acf..28c2cf7 100644
>> --- a/hw/char/lm32_juart.c
>> +++ b/hw/char/lm32_juart.c
>> @@ -114,17 +114,13 @@ static void juart_reset(DeviceState *d)
>>     s->jrx = 0;
>> }
>> -static int lm32_juart_init(SysBusDevice *dev)
>> +static void lm32_juart_realize(DeviceState *dev, Error **errp)
>> {
>>     LM32JuartState *s = LM32_JUART(dev);
>> -    /* FIXME use a qdev chardev prop instead of qemu_char_get_next_serial() */
>> -    s->chr = qemu_char_get_next_serial();
>>     if (s->chr) {
>>         qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, juart_event, s);
>>     }
>> -
>> -    return 0;
>> }
>> static const VMStateDescription vmstate_lm32_juart = {
>> @@ -138,16 +134,19 @@ static const VMStateDescription vmstate_lm32_juart = {
>>     }
>> };
>> +static Property lm32_juart_properties[] = {
>> +    DEFINE_PROP_CHR("chardev", LM32JuartState, chr),
>> +    DEFINE_PROP_END_OF_LIST(),
>> +};
>> +
>> static void lm32_juart_class_init(ObjectClass *klass, void *data)
>> {
>>     DeviceClass *dc = DEVICE_CLASS(klass);
>> -    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
>> -    k->init = lm32_juart_init;
>>     dc->reset = juart_reset;
>>     dc->vmsd = &vmstate_lm32_juart;
>> -    /* Reason: init() method uses qemu_char_get_next_serial() */
>> -    dc->cannot_instantiate_with_device_add_yet = true;
>> +    dc->props = lm32_juart_properties;
>> +    dc->realize = lm32_juart_realize;
>> }
>> static const TypeInfo lm32_juart_info = {
>> diff --git a/hw/lm32/lm32.h b/hw/lm32/lm32.h
>> index 18aa6fd..6761518 100644
>> --- a/hw/lm32/lm32.h
>> +++ b/hw/lm32/lm32.h
>> @@ -2,6 +2,7 @@
>> #define HW_LM32_H 1
>> #include "hw/char/lm32_juart.h"
>> +#include "sysemu/sysemu.h"
>> static inline DeviceState *lm32_pic_init(qemu_irq cpu_irq)
>> {
>> @@ -21,6 +22,7 @@ static inline DeviceState *lm32_juart_init(void)
>>     DeviceState *dev;
>>     dev = qdev_create(NULL, TYPE_LM32_JUART);
>> +    qdev_prop_set_chr(dev, "chardev", serial_hds[1]);
> 
> Please make the serial_hds[1] a parameter to this function, like you did with the lm32_uart_create(). Then the serial_hds[] assignements will be in one place in lm32_boards.c.
> 
> Mhh, i guess for this to work with the milkymist board, milkymist-uart (hw/char/milkymist-uart.c) has to be converted too, because it still uses the qemu_char_get_next_serial() function. So if you like you may also convert this model. If not, I'll do it myself after picking your patches.
> 
>>     qdev_init_nofail(dev);
>>     return dev;
> 
> -michael

Yes, i will do it.  Happy to contribute ;-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-05-23 11:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-23 10:24 [Qemu-devel] [PATCH v5 0/4] QOM'ify hw/char devices xiaoqiang zhao
2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 1/4] hw/char: QOM'ify escc.c xiaoqiang zhao
2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 2/4] hw/char: QOM'ify etraxfs_ser.c xiaoqiang zhao
2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 3/4] hw/char: QOM'ify lm32_juart.c xiaoqiang zhao
2016-05-23 11:18   ` Michael Walle
2016-05-23 11:34     ` xiaoqiang zhao
2016-05-23 10:24 ` [Qemu-devel] [PATCH v5 4/4] hw/char: QOM'ify lm32_uart.c xiaoqiang zhao
2016-05-23 11:09   ` Michael Walle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.