[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/38] Generalize QOM publishing of date and time fro
From: |
Alexander Graf |
Subject: |
[Qemu-devel] [PULL 06/38] Generalize QOM publishing of date and time from mc146818rtc.c |
Date: |
Sun, 8 Mar 2015 09:44:25 +0100 |
From: David Gibson <address@hidden>
The mc146818rtc driver exposes the current RTC date and time via the "date"
property in QOM (which is also aliased to the machine's "rtc-time"
property). Currently it uses a custom visitor function rtc_get_date to
do this.
This patch introduces new helpers to the QOM core to expose struct tm
valued properties via a getter function, so that this functionality can be
more easily duplicated in other RTC implementations.
Signed-off-by: David Gibson <address@hidden>
Signed-off-by: Alexander Graf <address@hidden>
---
hw/timer/mc146818rtc.c | 44 ++--------------------------
include/qom/object.h | 14 +++++++++
qom/object.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 96 insertions(+), 41 deletions(-)
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 0600c9a..f2b77fa 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -831,49 +831,12 @@ static const MemoryRegionOps cmos_ops = {
.endianness = DEVICE_LITTLE_ENDIAN,
};
-static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
- const char *name, Error **errp)
+static void rtc_get_date(Object *obj, struct tm *current_tm, Error **errp)
{
- Error *err = NULL;
RTCState *s = MC146818_RTC(obj);
- struct tm current_tm;
rtc_update_time(s);
- rtc_get_time(s, ¤t_tm);
- visit_start_struct(v, NULL, "struct tm", name, 0, &err);
- if (err) {
- goto out;
- }
- visit_type_int32(v, ¤t_tm.tm_year, "tm_year", &err);
- if (err) {
- goto out_end;
- }
- visit_type_int32(v, ¤t_tm.tm_mon, "tm_mon", &err);
- if (err) {
- goto out_end;
- }
- visit_type_int32(v, ¤t_tm.tm_mday, "tm_mday", &err);
- if (err) {
- goto out_end;
- }
- visit_type_int32(v, ¤t_tm.tm_hour, "tm_hour", &err);
- if (err) {
- goto out_end;
- }
- visit_type_int32(v, ¤t_tm.tm_min, "tm_min", &err);
- if (err) {
- goto out_end;
- }
- visit_type_int32(v, ¤t_tm.tm_sec, "tm_sec", &err);
- if (err) {
- goto out_end;
- }
-out_end:
- error_propagate(errp, err);
- err = NULL;
- visit_end_struct(v, errp);
-out:
- error_propagate(errp, err);
+ rtc_get_time(s, current_tm);
}
static void rtc_realizefn(DeviceState *dev, Error **errp)
@@ -932,8 +895,7 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)
qdev_set_legacy_instance_id(dev, base, 3);
qemu_register_reset(rtc_reset, s);
- object_property_add(OBJECT(s), "date", "struct tm",
- rtc_get_date, NULL, NULL, s, NULL);
+ object_property_add_tm(OBJECT(s), "date", rtc_get_date, NULL);
object_property_add_alias(qdev_get_machine(), "rtc-time",
OBJECT(s), "date", NULL);
diff --git a/include/qom/object.h b/include/qom/object.h
index 8757573..d2d7748 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1204,6 +1204,20 @@ void object_property_add_bool(Object *obj, const char
*name,
Error **errp);
/**
+ * object_property_add_tm:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @get: the getter or NULL if the property is write-only.
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add a read-only struct tm valued property using a getter function.
+ * This function will add a property of type 'struct tm'.
+ */
+void object_property_add_tm(Object *obj, const char *name,
+ void (*get)(Object *, struct tm *, Error **),
+ Error **errp);
+
+/**
* object_property_add_uint8_ptr:
* @obj: the object to add a property to
* @name: the name of the property
diff --git a/qom/object.c b/qom/object.c
index 1812c73..d167038 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1543,6 +1543,85 @@ void object_property_add_bool(Object *obj, const char
*name,
}
}
+typedef struct TMProperty {
+ void (*get)(Object *, struct tm *, Error **);
+} TMProperty;
+
+static void property_get_tm(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ TMProperty *prop = opaque;
+ Error *err = NULL;
+ struct tm value;
+
+ prop->get(obj, &value, &err);
+ if (err) {
+ goto out;
+ }
+
+ visit_start_struct(v, NULL, "struct tm", name, 0, &err);
+ if (err) {
+ goto out;
+ }
+ visit_type_int32(v, &value.tm_year, "tm_year", &err);
+ if (err) {
+ goto out_end;
+ }
+ visit_type_int32(v, &value.tm_mon, "tm_mon", &err);
+ if (err) {
+ goto out_end;
+ }
+ visit_type_int32(v, &value.tm_mday, "tm_mday", &err);
+ if (err) {
+ goto out_end;
+ }
+ visit_type_int32(v, &value.tm_hour, "tm_hour", &err);
+ if (err) {
+ goto out_end;
+ }
+ visit_type_int32(v, &value.tm_min, "tm_min", &err);
+ if (err) {
+ goto out_end;
+ }
+ visit_type_int32(v, &value.tm_sec, "tm_sec", &err);
+ if (err) {
+ goto out_end;
+ }
+out_end:
+ error_propagate(errp, err);
+ err = NULL;
+ visit_end_struct(v, errp);
+out:
+ error_propagate(errp, err);
+
+}
+
+static void property_release_tm(Object *obj, const char *name,
+ void *opaque)
+{
+ TMProperty *prop = opaque;
+ g_free(prop);
+}
+
+void object_property_add_tm(Object *obj, const char *name,
+ void (*get)(Object *, struct tm *, Error **),
+ Error **errp)
+{
+ Error *local_err = NULL;
+ TMProperty *prop = g_malloc0(sizeof(*prop));
+
+ prop->get = get;
+
+ object_property_add(obj, name, "struct tm",
+ get ? property_get_tm : NULL, NULL,
+ property_release_tm,
+ prop, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ g_free(prop);
+ }
+}
+
static char *qdev_get_type(Object *obj, Error **errp)
{
return g_strdup(object_get_typename(obj));
--
1.8.1.4
- [Qemu-devel] [PULL 2.3 00/38] ppc patch queue 2015-03-08, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 02/38] target-ppc: Use right page size with hash table lookup, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 15/38] PPC: Clean up misuse of qdev_init() in kvm-openpic creation, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 09/38] pseries: Add more parameter validation in RTAS time of day functions, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 01/38] spapr_vio/spapr_iommu: Move VIO bypass where it belongs, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 05/38] spapr-pci: Enable huge BARs, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 22/38] adb.c: include ADBDevice parent state in KBDState and MouseState, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 23/38] cuda.c: include adb_poll_timer in VMStateDescription, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 16/38] spapr: Clean up misuse of qdev_init() in xics-kvm creation, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 13/38] pseries: Move rtc_offset into RTC device's state structure, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 06/38] Generalize QOM publishing of date and time from mc146818rtc.c,
Alexander Graf <=
- [Qemu-devel] [PULL 24/38] target-ppc: move sdr1 value change detection logic to helper_store_sdr1(), Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 33/38] ppc64-softmmu: Remove duplicated OPENPIC from config, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 25/38] target-ppc: force update of msr bits in cpu_post_load, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 38/38] sPAPR: Implement sPAPRPHBClass EEH callbacks, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 14/38] pseries: Export RTC time via QOM, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 11/38] pseries: Make RTAS time of day functions respect -rtc options, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 20/38] display cpu id dump state, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 04/38] spapr: Add pseries-2.3 machine, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 08/38] pseries: Move sPAPR RTC code into its own file, Alexander Graf, 2015/03/08
- [Qemu-devel] [PULL 31/38] Revert "default-configs/ppc64: add all components of i82378 SuperIO chip used by prep", Alexander Graf, 2015/03/08