[Qemu-devel] [PATCH] sysbus: convert init() to realize()

Philippe Mathieu-Daudé posted 1 patch 6 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180114025234.29436-1-f4bug@amsat.org
Test checkpatch passed
Test docker passed
Test ppc passed
Test s390x passed
hw/core/sysbus.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
[Qemu-devel] [PATCH] sysbus: convert init() to realize()
Posted by Philippe Mathieu-Daudé 6 years, 2 months ago
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/core/sysbus.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 5d0887f499..0531eb60ce 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "hw/sysbus.h"
 #include "monitor/monitor.h"
 #include "exec/address-spaces.h"
@@ -200,15 +201,15 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size)
     }
 }
 
-static int sysbus_device_init(DeviceState *dev)
+static void sysbus_device_realize(DeviceState *dev, Error **errp)
 {
     SysBusDevice *sd = SYS_BUS_DEVICE(dev);
     SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
 
-    if (!sbc->init) {
-        return 0;
+    if (sbc->init && sbc->init(sd)) {
+        error_setg(errp, "sysbus device initialization failed");
+        return;
     }
-    return sbc->init(sd);
 }
 
 DeviceState *sysbus_create_varargs(const char *name,
@@ -324,7 +325,7 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev)
 static void sysbus_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
-    k->init = sysbus_device_init;
+    k->realize = sysbus_device_realize;
     k->bus_type = TYPE_SYSTEM_BUS;
     /*
      * device_add plugs devices into a suitable bus.  For "real" buses,
-- 
2.15.1


Re: [Qemu-devel] [PATCH] sysbus: convert init() to realize()
Posted by Peter Maydell 6 years, 2 months ago
On 14 January 2018 at 02:52, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  hw/core/sysbus.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
> index 5d0887f499..0531eb60ce 100644
> --- a/hw/core/sysbus.c
> +++ b/hw/core/sysbus.c
> @@ -18,6 +18,7 @@
>   */
>
>  #include "qemu/osdep.h"
> +#include "qapi/error.h"
>  #include "hw/sysbus.h"
>  #include "monitor/monitor.h"
>  #include "exec/address-spaces.h"
> @@ -200,15 +201,15 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size)
>      }
>  }
>
> -static int sysbus_device_init(DeviceState *dev)
> +static void sysbus_device_realize(DeviceState *dev, Error **errp)
>  {
>      SysBusDevice *sd = SYS_BUS_DEVICE(dev);
>      SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
>
> -    if (!sbc->init) {
> -        return 0;
> +    if (sbc->init && sbc->init(sd)) {
> +        error_setg(errp, "sysbus device initialization failed");
> +        return;
>      }
> -    return sbc->init(sd);
>  }
>
>  DeviceState *sysbus_create_varargs(const char *name,
> @@ -324,7 +325,7 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev)
>  static void sysbus_device_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *k = DEVICE_CLASS(klass);
> -    k->init = sysbus_device_init;
> +    k->realize = sysbus_device_realize;
>      k->bus_type = TYPE_SYSTEM_BUS;
>      /*
>       * device_add plugs devices into a suitable bus.  For "real" buses,

This doesn't look right. SysBus::init is something we're trying
to deprecate, I think, so we should be looking to complete
that process, not changing its semantics so it isn't called
until Device::realize.

thanks
-- PMM

Re: [Qemu-devel] [PATCH] sysbus: convert init() to realize()
Posted by Philippe Mathieu-Daudé 6 years, 2 months ago
On 01/14/2018 12:32 PM, Peter Maydell wrote:
> On 14 January 2018 at 02:52, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>>  hw/core/sysbus.c | 11 ++++++-----
>>  1 file changed, 6 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
>> index 5d0887f499..0531eb60ce 100644
>> --- a/hw/core/sysbus.c
>> +++ b/hw/core/sysbus.c
>> @@ -18,6 +18,7 @@
>>   */
>>
>>  #include "qemu/osdep.h"
>> +#include "qapi/error.h"
>>  #include "hw/sysbus.h"
>>  #include "monitor/monitor.h"
>>  #include "exec/address-spaces.h"
>> @@ -200,15 +201,15 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size)
>>      }
>>  }
>>
>> -static int sysbus_device_init(DeviceState *dev)
>> +static void sysbus_device_realize(DeviceState *dev, Error **errp)
>>  {
>>      SysBusDevice *sd = SYS_BUS_DEVICE(dev);
>>      SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
>>
>> -    if (!sbc->init) {
>> -        return 0;
>> +    if (sbc->init && sbc->init(sd)) {
>> +        error_setg(errp, "sysbus device initialization failed");
>> +        return;
>>      }
>> -    return sbc->init(sd);
>>  }
>>
>>  DeviceState *sysbus_create_varargs(const char *name,
>> @@ -324,7 +325,7 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev)
>>  static void sysbus_device_class_init(ObjectClass *klass, void *data)
>>  {
>>      DeviceClass *k = DEVICE_CLASS(klass);
>> -    k->init = sysbus_device_init;
>> +    k->realize = sysbus_device_realize;
>>      k->bus_type = TYPE_SYSTEM_BUS;
>>      /*
>>       * device_add plugs devices into a suitable bus.  For "real" buses,
> 
> This doesn't look right. SysBus::init is something we're trying
> to deprecate, I think, so we should be looking to complete
> that process, not changing its semantics so it isn't called
> until Device::realize.

Ok, I think if I put all those related patches altogether in the same
series this will make more sens.