pl031: support rtc-timer property for pl031
This patch adds the rtc-timer property for pl031, we can get the rtc time (UTC) through qmp command "qom-get date" with this property. Signed-off-by: Haibin Wang <wanghaibin.wang@huawei.com> Reviewed-by: Shannon Zhao <shanon.Zhaosl@gmail.com> Reviewed-by: Ying Fang <fangying1@huawei.com> Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> Signed-off-by: Jinhao Gao <gaojinhao@huawei.com>
This commit is contained in:
parent
3e2685401c
commit
472d8c2cb0
70
pl031-support-rtc-timer-property-for-pl031.patch
Normal file
70
pl031-support-rtc-timer-property-for-pl031.patch
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
From f8e5f099c5b6665e3ed9f397ddca9283148938a4 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jinhao Gao <gaojinhao@huawei.com>
|
||||||
|
Date: Tue, 15 Feb 2022 17:02:08 +0800
|
||||||
|
Subject: [PATCH] pl031: support rtc-timer property for pl031
|
||||||
|
|
||||||
|
This patch adds the rtc-timer property for pl031, we can get the
|
||||||
|
rtc time (UTC) through qmp command "qom-get date" with this property.
|
||||||
|
|
||||||
|
Signed-off-by: Haibin Wang <wanghaibin.wang@huawei.com>
|
||||||
|
Reviewed-by: Shannon Zhao <shanon.Zhaosl@gmail.com>
|
||||||
|
Reviewed-by: Ying Fang <fangying1@huawei.com>
|
||||||
|
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
|
||||||
|
Signed-off-by: Jinhao Gao <gaojinhao@huawei.com>
|
||||||
|
---
|
||||||
|
hw/rtc/pl031.c | 25 +++++++++++++++++++++++++
|
||||||
|
1 file changed, 25 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/hw/rtc/pl031.c b/hw/rtc/pl031.c
|
||||||
|
index da8b061e91..61a2948f77 100644
|
||||||
|
--- a/hw/rtc/pl031.c
|
||||||
|
+++ b/hw/rtc/pl031.c
|
||||||
|
@@ -63,6 +63,15 @@ static uint32_t pl031_get_count(PL031State *s)
|
||||||
|
return s->tick_offset + now / NANOSECONDS_PER_SECOND;
|
||||||
|
}
|
||||||
|
|
||||||
|
+static void pl031_get_date(Object *obj, struct tm *current_tm, Error **errp)
|
||||||
|
+{
|
||||||
|
+ PL031State *s = PL031(obj);
|
||||||
|
+ time_t ti = pl031_get_count(s);
|
||||||
|
+
|
||||||
|
+ /* Changed to UTC time */
|
||||||
|
+ gmtime_r(&ti, current_tm);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
static void pl031_set_alarm(PL031State *s)
|
||||||
|
{
|
||||||
|
uint32_t ticks;
|
||||||
|
@@ -201,6 +210,20 @@ static void pl031_init(Object *obj)
|
||||||
|
qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;
|
||||||
|
|
||||||
|
s->timer = timer_new_ns(rtc_clock, pl031_interrupt, s);
|
||||||
|
+ object_property_add_tm(OBJECT(s), "date", pl031_get_date);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static void pl031_realize(DeviceState *d, Error **errp)
|
||||||
|
+{
|
||||||
|
+ object_property_add_alias(qdev_get_machine(), "rtc-time",
|
||||||
|
+ OBJECT(d), "date");
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static void pl031_unrealize(DeviceState *d)
|
||||||
|
+{
|
||||||
|
+ if (object_property_find(qdev_get_machine(), "rtc-time")) {
|
||||||
|
+ object_property_del(qdev_get_machine(), "rtc-time");
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pl031_finalize(Object *obj)
|
||||||
|
@@ -337,6 +360,8 @@ static void pl031_class_init(ObjectClass *klass, void *data)
|
||||||
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||||
|
|
||||||
|
dc->vmsd = &vmstate_pl031;
|
||||||
|
+ dc->realize = pl031_realize;
|
||||||
|
+ dc->unrealize = pl031_unrealize;
|
||||||
|
device_class_set_props(dc, pl031_properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user