diff mbox

[v3,04/16] mc146818rtc: always register rtc to rtc list

Message ID 20171229142922.31701-5-hpoussin@reactos.org (mailing list archive)
State New, archived
Headers show

Commit Message

Hervé Poussineau Dec. 29, 2017, 2:29 p.m. UTC
We are not required anymore to use rtc_init() function.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/timer/mc146818rtc.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Marcel Apfelbaum Jan. 4, 2018, 2:30 p.m. UTC | #1
On 29/12/2017 16:29, Hervé Poussineau wrote:
> We are not required anymore to use rtc_init() function.
> 
> Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
> ---
>   hw/timer/mc146818rtc.c | 13 ++++++++-----
>   1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
> index 3e8c0b7d33..0b0da691cc 100644
> --- a/hw/timer/mc146818rtc.c
> +++ b/hw/timer/mc146818rtc.c
> @@ -905,6 +905,13 @@ static void rtc_get_date(Object *obj, struct tm *current_tm, Error **errp)
>       rtc_get_time(s, current_tm);
>   }
>   
> +static int rtc_initfn(DeviceState *dev)
> +{
> +    RTCState *s = MC146818_RTC(dev);
> +    QLIST_INSERT_HEAD(&rtc_devices, s, link);
> +    return 0;
> +}
> +
>   static void rtc_realizefn(DeviceState *dev, Error **errp)
>   {
>       ISADevice *isadev = ISA_DEVICE(dev);
> @@ -973,11 +980,9 @@ ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
>   {
>       DeviceState *dev;
>       ISADevice *isadev;
> -    RTCState *s;
>   
>       isadev = isa_create(bus, TYPE_MC146818_RTC);
>       dev = DEVICE(isadev);
> -    s = MC146818_RTC(isadev);
>       qdev_prop_set_int32(dev, "base_year", base_year);
>       qdev_init_nofail(dev);
>       if (intercept_irq) {
> @@ -985,7 +990,6 @@ ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
>       } else {
>           isa_connect_gpio_out(isadev, 0, RTC_ISA_IRQ);
>       }
> -    QLIST_INSERT_HEAD(&rtc_devices, s, link);
>   
>       return isadev;
>   }
> @@ -1012,12 +1016,11 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
>   {
>       DeviceClass *dc = DEVICE_CLASS(klass);
>   
> +    dc->init = rtc_initfn;

I am not sure you want to use dc->init function.

I think you need TypeInfo's instance_init.

Thanks,
Marcel

>       dc->realize = rtc_realizefn;
>       dc->reset = rtc_resetdev;
>       dc->vmsd = &vmstate_rtc;
>       dc->props = mc146818rtc_properties;
> -    /* Reason: needs to be wired up by rtc_init() */
> -    dc->user_creatable = false;
>   }
>   
>   static void rtc_finalize(Object *obj)
>
Hervé Poussineau Jan. 4, 2018, 8:34 p.m. UTC | #2
Le 04/01/2018 à 15:30, Marcel Apfelbaum a écrit :
> On 29/12/2017 16:29, Hervé Poussineau wrote:
>> We are not required anymore to use rtc_init() function.
>>
>> Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
>> ---
>>   hw/timer/mc146818rtc.c | 13 ++++++++-----
>>   1 file changed, 8 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
>> index 3e8c0b7d33..0b0da691cc 100644
>> --- a/hw/timer/mc146818rtc.c
>> +++ b/hw/timer/mc146818rtc.c
>> @@ -905,6 +905,13 @@ static void rtc_get_date(Object *obj, struct tm *current_tm, Error **errp)
>>       rtc_get_time(s, current_tm);
>>   }
>> +static int rtc_initfn(DeviceState *dev)
>> +{
>> +    RTCState *s = MC146818_RTC(dev);
>> +    QLIST_INSERT_HEAD(&rtc_devices, s, link);
>> +    return 0;
>> +}
>> +
>>   static void rtc_realizefn(DeviceState *dev, Error **errp)
>>   {
>>       ISADevice *isadev = ISA_DEVICE(dev);
>> @@ -973,11 +980,9 @@ ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
>>   {
>>       DeviceState *dev;
>>       ISADevice *isadev;
>> -    RTCState *s;
>>       isadev = isa_create(bus, TYPE_MC146818_RTC);
>>       dev = DEVICE(isadev);
>> -    s = MC146818_RTC(isadev);
>>       qdev_prop_set_int32(dev, "base_year", base_year);
>>       qdev_init_nofail(dev);
>>       if (intercept_irq) {
>> @@ -985,7 +990,6 @@ ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
>>       } else {
>>           isa_connect_gpio_out(isadev, 0, RTC_ISA_IRQ);
>>       }
>> -    QLIST_INSERT_HEAD(&rtc_devices, s, link);
>>       return isadev;
>>   }
>> @@ -1012,12 +1016,11 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
>>   {
>>       DeviceClass *dc = DEVICE_CLASS(klass);
>> +    dc->init = rtc_initfn;
> 
> I am not sure you want to use dc->init function.
> 
> I think you need TypeInfo's instance_init.

OK, I will move list insertion to existing function rtc_realizefn.

> 
> Thanks,
> Marcel
> 
>>       dc->realize = rtc_realizefn;
>>       dc->reset = rtc_resetdev;
>>       dc->vmsd = &vmstate_rtc;
>>       dc->props = mc146818rtc_properties;
>> -    /* Reason: needs to be wired up by rtc_init() */
>> -    dc->user_creatable = false;
>>   }
>>   static void rtc_finalize(Object *obj)
>>
> 
>
diff mbox

Patch

diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 3e8c0b7d33..0b0da691cc 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -905,6 +905,13 @@  static void rtc_get_date(Object *obj, struct tm *current_tm, Error **errp)
     rtc_get_time(s, current_tm);
 }
 
+static int rtc_initfn(DeviceState *dev)
+{
+    RTCState *s = MC146818_RTC(dev);
+    QLIST_INSERT_HEAD(&rtc_devices, s, link);
+    return 0;
+}
+
 static void rtc_realizefn(DeviceState *dev, Error **errp)
 {
     ISADevice *isadev = ISA_DEVICE(dev);
@@ -973,11 +980,9 @@  ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
 {
     DeviceState *dev;
     ISADevice *isadev;
-    RTCState *s;
 
     isadev = isa_create(bus, TYPE_MC146818_RTC);
     dev = DEVICE(isadev);
-    s = MC146818_RTC(isadev);
     qdev_prop_set_int32(dev, "base_year", base_year);
     qdev_init_nofail(dev);
     if (intercept_irq) {
@@ -985,7 +990,6 @@  ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
     } else {
         isa_connect_gpio_out(isadev, 0, RTC_ISA_IRQ);
     }
-    QLIST_INSERT_HEAD(&rtc_devices, s, link);
 
     return isadev;
 }
@@ -1012,12 +1016,11 @@  static void rtc_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
+    dc->init = rtc_initfn;
     dc->realize = rtc_realizefn;
     dc->reset = rtc_resetdev;
     dc->vmsd = &vmstate_rtc;
     dc->props = mc146818rtc_properties;
-    /* Reason: needs to be wired up by rtc_init() */
-    dc->user_creatable = false;
 }
 
 static void rtc_finalize(Object *obj)