diff mbox series

[08/11] net: smc91c111: convert SysBus init method to a realize method

Message ID 20180928135003.8650-9-clg@kaod.org (mailing list archive)
State New, archived
Headers show
Series net: convert SysBus init method to a realize method | expand

Commit Message

Cédric Le Goater Sept. 28, 2018, 1:50 p.m. UTC
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/net/smc91c111.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

Comments

Peter Maydell Sept. 28, 2018, 2:45 p.m. UTC | #1
On 28 September 2018 at 14:50, Cédric Le Goater <clg@kaod.org> wrote:
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---
>  hw/net/smc91c111.c | 22 +++++++++-------------
>  1 file changed, 9 insertions(+), 13 deletions(-)
>
> diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c
> index d2fd2040e81c..5a43afc0d3c2 100644
> --- a/hw/net/smc91c111.c
> +++ b/hw/net/smc91c111.c
> @@ -766,9 +766,9 @@ static NetClientInfo net_smc91c111_info = {
>      .receive = smc91c111_receive,
>  };
>
> -static int smc91c111_init1(SysBusDevice *sbd)
> +static void smc91c111_realize(DeviceState *dev, Error **errp)
>  {
> -    DeviceState *dev = DEVICE(sbd);
> +    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
>      smc91c111_state *s = SMC91C111(dev);
>
>      memory_region_init_io(&s->mmio, OBJECT(s), &smc91c111_mem_ops, s,
> @@ -780,7 +780,6 @@ static int smc91c111_init1(SysBusDevice *sbd)
>                            object_get_typename(OBJECT(dev)), dev->id, s);
>      qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
>      /* ??? Save/restore.  */

(Incidentally, this comment is out of date and should be deleted,
since we have a vmstate for the device, but that's an unrelated change.)

> -    return 0;
>  }
>
>  static Property smc91c111_properties[] = {
> @@ -791,9 +790,8 @@ static Property smc91c111_properties[] = {
>  static void smc91c111_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
> -    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
>
> -    k->init = smc91c111_init1;
> +    dc->realize = smc91c111_realize;
>      dc->reset = smc91c111_reset;
>      dc->vmsd = &vmstate_smc91c111;
>      dc->props = smc91c111_properties;
> @@ -815,16 +813,14 @@ static void smc91c111_register_types(void)
>     implemented.  */
>  void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
>  {
> -    DeviceState *dev;
> -    SysBusDevice *s;
> +    Object *obj;
>
>      qemu_check_nic_model(nd, "smc91c111");
> -    dev = qdev_create(NULL, TYPE_SMC91C111);
> -    qdev_set_nic_properties(dev, nd);
> -    qdev_init_nofail(dev);
> -    s = SYS_BUS_DEVICE(dev);
> -    sysbus_mmio_map(s, 0, base);
> -    sysbus_connect_irq(s, 0, irq);
> +    obj = object_new(TYPE_SMC91C111);
> +    qdev_set_nic_properties(DEVICE(obj), nd);
> +    qdev_init_nofail(DEVICE(obj));
> +    sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, base);
> +    sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0, irq);

I'm not sure why you've changed this function as well?

>  }
>
>  type_init(smc91c111_register_types)


thanks
-- PMM
Cédric Le Goater Sept. 28, 2018, 3:10 p.m. UTC | #2
On 9/28/18 4:45 PM, Peter Maydell wrote:
> On 28 September 2018 at 14:50, Cédric Le Goater <clg@kaod.org> wrote:
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>> ---
>>  hw/net/smc91c111.c | 22 +++++++++-------------
>>  1 file changed, 9 insertions(+), 13 deletions(-)
>>
>> diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c
>> index d2fd2040e81c..5a43afc0d3c2 100644
>> --- a/hw/net/smc91c111.c
>> +++ b/hw/net/smc91c111.c
>> @@ -766,9 +766,9 @@ static NetClientInfo net_smc91c111_info = {
>>      .receive = smc91c111_receive,
>>  };
>>
>> -static int smc91c111_init1(SysBusDevice *sbd)
>> +static void smc91c111_realize(DeviceState *dev, Error **errp)
>>  {
>> -    DeviceState *dev = DEVICE(sbd);
>> +    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
>>      smc91c111_state *s = SMC91C111(dev);
>>
>>      memory_region_init_io(&s->mmio, OBJECT(s), &smc91c111_mem_ops, s,
>> @@ -780,7 +780,6 @@ static int smc91c111_init1(SysBusDevice *sbd)
>>                            object_get_typename(OBJECT(dev)), dev->id, s);
>>      qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
>>      /* ??? Save/restore.  */
> 
> (Incidentally, this comment is out of date and should be deleted,
> since we have a vmstate for the device, but that's an unrelated change.)

ok ok. I will make that change in another patch and not with a 'Also' 
in the same commit log :) 
 
> 
>> -    return 0;
>>  }
>>
>>  static Property smc91c111_properties[] = {
>> @@ -791,9 +790,8 @@ static Property smc91c111_properties[] = {
>>  static void smc91c111_class_init(ObjectClass *klass, void *data)
>>  {
>>      DeviceClass *dc = DEVICE_CLASS(klass);
>> -    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
>>
>> -    k->init = smc91c111_init1;
>> +    dc->realize = smc91c111_realize;
>>      dc->reset = smc91c111_reset;
>>      dc->vmsd = &vmstate_smc91c111;
>>      dc->props = smc91c111_properties;
>> @@ -815,16 +813,14 @@ static void smc91c111_register_types(void)
>>     implemented.  */
>>  void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
>>  {
>> -    DeviceState *dev;
>> -    SysBusDevice *s;
>> +    Object *obj;
>>
>>      qemu_check_nic_model(nd, "smc91c111");
>> -    dev = qdev_create(NULL, TYPE_SMC91C111);
>> -    qdev_set_nic_properties(dev, nd);
>> -    qdev_init_nofail(dev);
>> -    s = SYS_BUS_DEVICE(dev);
>> -    sysbus_mmio_map(s, 0, base);
>> -    sysbus_connect_irq(s, 0, irq);
>> +    obj = object_new(TYPE_SMC91C111);
>> +    qdev_set_nic_properties(DEVICE(obj), nd);
>> +    qdev_init_nofail(DEVICE(obj));
>> +    sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, base);
>> +    sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0, irq);
> 
> I'm not sure why you've changed this function as well?

Initially to stop using the qdev_ routines but I ended up rewriting them
with object_ routines and only kept the object_new() call.  

Shall I drop the change then ? 

Thanks,

C.

> 
>>  }
>>
>>  type_init(smc91c111_register_types)
> 
> 
> thanks
> -- PMM
>
Peter Maydell Sept. 28, 2018, 3:53 p.m. UTC | #3
On 28 September 2018 at 16:10, Cédric Le Goater <clg@kaod.org> wrote:
> On 9/28/18 4:45 PM, Peter Maydell wrote:
>> On 28 September 2018 at 14:50, Cédric Le Goater <clg@kaod.org> wrote:
>>>  void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
>>>  {
>>> -    DeviceState *dev;
>>> -    SysBusDevice *s;
>>> +    Object *obj;
>>>
>>>      qemu_check_nic_model(nd, "smc91c111");
>>> -    dev = qdev_create(NULL, TYPE_SMC91C111);
>>> -    qdev_set_nic_properties(dev, nd);
>>> -    qdev_init_nofail(dev);
>>> -    s = SYS_BUS_DEVICE(dev);
>>> -    sysbus_mmio_map(s, 0, base);
>>> -    sysbus_connect_irq(s, 0, irq);
>>> +    obj = object_new(TYPE_SMC91C111);
>>> +    qdev_set_nic_properties(DEVICE(obj), nd);
>>> +    qdev_init_nofail(DEVICE(obj));
>>> +    sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, base);
>>> +    sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0, irq);
>>
>> I'm not sure why you've changed this function as well?
>
> Initially to stop using the qdev_ routines but I ended up rewriting them
> with object_ routines and only kept the object_new() call.
>
> Shall I drop the change then ?

I would drop it, I think -- we're not really trying to get
rid of the qdev APIs. (I'm tending towards a style of not using
this sort of helper function and instead just embedding
devices directly in their users, but when we have a helper
function there's no particular need to avoid qdev_ calls in it.)

thanks
-- PMM
diff mbox series

Patch

diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c
index d2fd2040e81c..5a43afc0d3c2 100644
--- a/hw/net/smc91c111.c
+++ b/hw/net/smc91c111.c
@@ -766,9 +766,9 @@  static NetClientInfo net_smc91c111_info = {
     .receive = smc91c111_receive,
 };
 
-static int smc91c111_init1(SysBusDevice *sbd)
+static void smc91c111_realize(DeviceState *dev, Error **errp)
 {
-    DeviceState *dev = DEVICE(sbd);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     smc91c111_state *s = SMC91C111(dev);
 
     memory_region_init_io(&s->mmio, OBJECT(s), &smc91c111_mem_ops, s,
@@ -780,7 +780,6 @@  static int smc91c111_init1(SysBusDevice *sbd)
                           object_get_typename(OBJECT(dev)), dev->id, s);
     qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
     /* ??? Save/restore.  */
-    return 0;
 }
 
 static Property smc91c111_properties[] = {
@@ -791,9 +790,8 @@  static Property smc91c111_properties[] = {
 static void smc91c111_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = smc91c111_init1;
+    dc->realize = smc91c111_realize;
     dc->reset = smc91c111_reset;
     dc->vmsd = &vmstate_smc91c111;
     dc->props = smc91c111_properties;
@@ -815,16 +813,14 @@  static void smc91c111_register_types(void)
    implemented.  */
 void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
 {
-    DeviceState *dev;
-    SysBusDevice *s;
+    Object *obj;
 
     qemu_check_nic_model(nd, "smc91c111");
-    dev = qdev_create(NULL, TYPE_SMC91C111);
-    qdev_set_nic_properties(dev, nd);
-    qdev_init_nofail(dev);
-    s = SYS_BUS_DEVICE(dev);
-    sysbus_mmio_map(s, 0, base);
-    sysbus_connect_irq(s, 0, irq);
+    obj = object_new(TYPE_SMC91C111);
+    qdev_set_nic_properties(DEVICE(obj), nd);
+    qdev_init_nofail(DEVICE(obj));
+    sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, base);
+    sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0, irq);
 }
 
 type_init(smc91c111_register_types)