Patchwork [v2,19/26] scsi esp: use realize for scsi esp

login
register
mail settings
Submitter Hu Tao
Date July 1, 2013, 10:18 a.m.
Message ID <7da0c8dce11d32c300df10dade5e099b3aae7114.1372673778.git.hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/256071/
State New
Headers show

Comments

Hu Tao - July 1, 2013, 10:18 a.m.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 hw/scsi/esp.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
Andreas Färber - July 21, 2013, 9:47 a.m.
Am 01.07.2013 12:18, schrieb Hu Tao:
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
>  hw/scsi/esp.c | 30 ++++++++++++++++++++----------
>  1 file changed, 20 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
> index f7d6389..714d2fd 100644
> --- a/hw/scsi/esp.c
> +++ b/hw/scsi/esp.c
> @@ -668,23 +668,33 @@ static void sysbus_esp_gpio_demux(void *opaque, int irq, int level)
>      }
>  }
>  
> -static int sysbus_esp_init(SysBusDevice *dev)
> +static void sysbus_esp_init(Object *obj)
> +{
> +    SysBusESPState *sysbus = ESP(obj);
> +
> +    memory_region_init_io(&sysbus->iomem, &sysbus_esp_mem_ops, sysbus,
> +                          "esp", ESP_REGS << sysbus->it_shift);

it_shift is a field set after initialization, so moving this back into
realizefn.

> +}
> +
> +static void sysbus_esp_realize(DeviceState *dev, Error **errp)
>  {
>      SysBusESPState *sysbus = ESP(dev);
> +    SysBusDevice *b = SYS_BUS_DEVICE(dev);

Please try to order variables from DeviceState to specific type, also
renaming to sbd for clarity.

>      ESPState *s = &sysbus->esp;
>  
> -    sysbus_init_irq(dev, &s->irq);
> +    sysbus_init_irq(b, &s->irq);
>      assert(sysbus->it_shift != -1);
>  
>      s->chip_id = TCHI_FAS100A;
> -    memory_region_init_io(&sysbus->iomem, &sysbus_esp_mem_ops, sysbus,
> -                          "esp", ESP_REGS << sysbus->it_shift);
> -    sysbus_init_mmio(dev, &sysbus->iomem);
> +    sysbus_init_mmio(b, &sysbus->iomem);
>  
> -    qdev_init_gpio_in(&dev->qdev, sysbus_esp_gpio_demux, 2);
> +    qdev_init_gpio_in(dev, sysbus_esp_gpio_demux, 2);
>  
> -    scsi_bus_new(&s->bus, &dev->qdev, &esp_scsi_info, NULL);
> -    return scsi_bus_legacy_handle_cmdline(&s->bus);
> +    scsi_bus_new(&s->bus, dev, &esp_scsi_info, NULL);
> +    if (scsi_bus_legacy_handle_cmdline(&s->bus) < 0) {
> +        error_setg(errp, "handling scsi bus failed");
> +        return;
> +    }

scsi_bus_legacy_handle_cmdline() is calling for better error
propagation, will post a follow-up.

Andreas

>  }
>  
>  static void sysbus_esp_hard_reset(DeviceState *dev)
> @@ -707,9 +717,8 @@ static const VMStateDescription vmstate_sysbus_esp_scsi = {
>  static void sysbus_esp_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
> -    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
>  
> -    k->init = sysbus_esp_init;
> +    dc->realize = sysbus_esp_realize;
>      dc->reset = sysbus_esp_hard_reset;
>      dc->vmsd = &vmstate_sysbus_esp_scsi;
>  }
> @@ -718,6 +727,7 @@ static const TypeInfo sysbus_esp_info = {
>      .name          = TYPE_ESP,
>      .parent        = TYPE_SYS_BUS_DEVICE,
>      .instance_size = sizeof(SysBusESPState),
> +    .instance_init = sysbus_esp_init,
>      .class_init    = sysbus_esp_class_init,
>  };
>  
>

Patch

diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index f7d6389..714d2fd 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -668,23 +668,33 @@  static void sysbus_esp_gpio_demux(void *opaque, int irq, int level)
     }
 }
 
-static int sysbus_esp_init(SysBusDevice *dev)
+static void sysbus_esp_init(Object *obj)
+{
+    SysBusESPState *sysbus = ESP(obj);
+
+    memory_region_init_io(&sysbus->iomem, &sysbus_esp_mem_ops, sysbus,
+                          "esp", ESP_REGS << sysbus->it_shift);
+}
+
+static void sysbus_esp_realize(DeviceState *dev, Error **errp)
 {
     SysBusESPState *sysbus = ESP(dev);
+    SysBusDevice *b = SYS_BUS_DEVICE(dev);
     ESPState *s = &sysbus->esp;
 
-    sysbus_init_irq(dev, &s->irq);
+    sysbus_init_irq(b, &s->irq);
     assert(sysbus->it_shift != -1);
 
     s->chip_id = TCHI_FAS100A;
-    memory_region_init_io(&sysbus->iomem, &sysbus_esp_mem_ops, sysbus,
-                          "esp", ESP_REGS << sysbus->it_shift);
-    sysbus_init_mmio(dev, &sysbus->iomem);
+    sysbus_init_mmio(b, &sysbus->iomem);
 
-    qdev_init_gpio_in(&dev->qdev, sysbus_esp_gpio_demux, 2);
+    qdev_init_gpio_in(dev, sysbus_esp_gpio_demux, 2);
 
-    scsi_bus_new(&s->bus, &dev->qdev, &esp_scsi_info, NULL);
-    return scsi_bus_legacy_handle_cmdline(&s->bus);
+    scsi_bus_new(&s->bus, dev, &esp_scsi_info, NULL);
+    if (scsi_bus_legacy_handle_cmdline(&s->bus) < 0) {
+        error_setg(errp, "handling scsi bus failed");
+        return;
+    }
 }
 
 static void sysbus_esp_hard_reset(DeviceState *dev)
@@ -707,9 +717,8 @@  static const VMStateDescription vmstate_sysbus_esp_scsi = {
 static void sysbus_esp_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = sysbus_esp_init;
+    dc->realize = sysbus_esp_realize;
     dc->reset = sysbus_esp_hard_reset;
     dc->vmsd = &vmstate_sysbus_esp_scsi;
 }
@@ -718,6 +727,7 @@  static const TypeInfo sysbus_esp_info = {
     .name          = TYPE_ESP,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(SysBusESPState),
+    .instance_init = sysbus_esp_init,
     .class_init    = sysbus_esp_class_init,
 };