aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2011-12-12 14:29:39 -0600
committerAnthony Liguori <aliguori@us.ibm.com>2011-12-15 09:20:49 -0600
commit182970509bd79635a5b16a06d2e918d3f5187486 (patch)
tree84f13081446ffee885c144ce017b7d565962094d /hw
parentd0c5be58704640850fad02c0ff38135f2e9aa589 (diff)
rtc: add a dynamic property for retrieving the date
This really shows the power of dynamic object properties compared to qdev static properties. This property represents a complex structure who's format is preserved over the wire. This is enabled by visitors. It also shows an entirely synthetic property that is not tied to device state. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/mc146818rtc.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 2aaca2ff41..0c23cb0dba 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -614,6 +614,29 @@ static const MemoryRegionOps cmos_ops = {
.old_portio = cmos_portio
};
+// FIXME add int32 visitor
+static void visit_type_int32(Visitor *v, int *value, const char *name, Error **errp)
+{
+ int64_t val = *value;
+ visit_type_int(v, &val, name, errp);
+}
+
+static void rtc_get_date(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ ISADevice *isa = DO_UPCAST(ISADevice, qdev, dev);
+ RTCState *s = DO_UPCAST(RTCState, dev, isa);
+
+ visit_start_struct(v, NULL, "struct tm", name, 0, errp);
+ visit_type_int32(v, &s->current_tm.tm_year, "tm_year", errp);
+ visit_type_int32(v, &s->current_tm.tm_mon, "tm_mon", errp);
+ visit_type_int32(v, &s->current_tm.tm_mday, "tm_mday", errp);
+ visit_type_int32(v, &s->current_tm.tm_hour, "tm_hour", errp);
+ visit_type_int32(v, &s->current_tm.tm_min, "tm_min", errp);
+ visit_type_int32(v, &s->current_tm.tm_sec, "tm_sec", errp);
+ visit_end_struct(v, errp);
+}
+
static int rtc_initfn(ISADevice *dev)
{
RTCState *s = DO_UPCAST(RTCState, dev, dev);
@@ -647,6 +670,10 @@ static int rtc_initfn(ISADevice *dev)
qdev_set_legacy_instance_id(&dev->qdev, base, 2);
qemu_register_reset(rtc_reset, s);
+
+ qdev_property_add(&s->dev.qdev, "date", "struct tm",
+ rtc_get_date, NULL, NULL, s, NULL);
+
return 0;
}