hw/timer/mc146818rtc: Fix introspection problem
PATCH 1/1 hw/timer/mc146818rtc: Fix introspection problem
There is currently a funny problem with the "mc146818rtc" device:
1) Start QEMU like this:
qemu-system-ppc64 -M pseries -S
2) At the HMP monitor, enter "info qom-tree". Note that there is an entry for "/rtc (spapr-rtc)".
3) Introspect the mc146818rtc device like this:
device_add mc146818rtc,help
4) Run "info qom-tree" again. The "/rtc" entry is gone now!
The rtc_finalize() function of the mc146818rtc device has two bugs: First, it tries to remove a "rtc" property, while the rtc_realizefn() added a "rtc-time" property instead. And second, it should be done in an unrealize function, not in a finalize function, to avoid that this causes problems during introspection.
--- hw/timer/mc146818rtc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/timer/mc146818rtc.c +6 -6
@@ -1001,6 +1001,11 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)qdev_init_gpio_out (dev, &s->irq,1 ); } +static void rtc_unrealize (DeviceState *dev,Error **errp) +{ +object_property_del (qdev_get_machine (),"rtc-time" , errp); +} +ISADevice *mc146818_rtc_init (ISABus *bus,int base_year,qemu_irq intercept_irq) {DeviceState *dev;
@@ -1045,6 +1050,7 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass); dc->realize = rtc_realizefn; + dc->unrealize = rtc_unrealize; dc->reset = rtc_resetdev; dc->vmsd = &vmstate_rtc; dc->props = mc146818rtc_properties;
@@ -1052,17 +1058,11 @@ static void rtc_class_initfn(ObjectClass *klass, void *data) dc->user_creatable = false; } -static void rtc_finalize (Object *obj) -{ -object_property_del (qdev_get_machine (),"rtc" ,NULL ); -} -static const TypeInfo mc146818rtc_info = { .name =TYPE_MC146818_RTC , .parent =TYPE_ISA_DEVICE , .instance_size =sizeof (RTCState), .class_init = rtc_class_initfn, - .instance_finalize = rtc_finalize, };static void mc146818rtc_register_types (void )
Signature · 1 line
1.8.3.1
Quoted 6 lines · Thomas Huth
There is currently a funny problem with the "mc146818rtc" device:
1) Start QEMU like this:
qemu-system-ppc64 -M pseries -S
2) At the HMP monitor, enter "info qom-tree". Note that there is an entry for "/rtc (spapr-rtc)".
3) Introspect the mc146818rtc device like this:
Quoted 8 lines
device_add mc146818rtc,help4) Run "info qom-tree" again. The "/rtc" entry is gone now!
The
rtc_finalize()function of the mc146818rtc device has two bugs: First, it tries to remove a "rtc" property, while thertc_realizefn()added a "rtc-time" property instead. And second, it should be done in an unrealize function, not in a finalize function, to avoid that this causes problems during introspection.
A device that adds a property to a machine is pretty weird...
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 9 lines · Thomas Huth
There is currently a funny problem with the "mc146818rtc" device:
1) Start QEMU like this:
qemu-system-ppc64 -M pseries -S
2) At the HMP monitor, enter "info qom-tree". Note that there is an entry for "/rtc (spapr-rtc)".
3) Introspect the mc146818rtc device like this:device_add mc146818rtc,help4) Run "info qom-tree" again. The "/rtc" entry is gone now!
Quoted 7 lines
Quoted 5 lines
The
rtc_finalize()function of the mc146818rtc device has two bugs: First, it tries to remove a "rtc" property, while thertc_realizefn()added a "rtc-time" property instead. And second, it should be done in an unrealize function, not in a finalize function, to avoid that this causes problems during introspection.A device that adds a property to a machine is pretty weird...
Well, "there can be only one" RTC, since it subtractively decodes I/O ports 70h and 71h. But it's true that nowadays the RTC should present the property, and the machine should add an alias to the RTC's property.
In my defence, at the time we didn't have alias properties.
Paolo