11
#include "qemu/osdep.h"
12
#include "qapi/error.h"
13
#include "hw/s390x/tod.h"
14
#include "qemu/timer.h"
15
#include "qemu/cutils.h"
16
#include "qemu/module.h"
18
#include "tcg/tcg_s390x.h"
19
#include "sysemu/rtc.h"
21
static void qemu_s390_tod_get(const S390TODState *td, S390TOD *tod,
26
tod->low += time2tod(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
27
if (tod->low < td->base.low) {
32
static void qemu_s390_tod_set(S390TODState *td, const S390TOD *tod,
39
td->base.low -= time2tod(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
40
if (td->base.low > tod->low) {
51
async_run_on_cpu(cpu, tcg_s390_tod_updated, RUN_ON_CPU_NULL);
55
static void qemu_s390_tod_class_init(ObjectClass *oc, void *data)
57
S390TODClass *tdc = S390_TOD_CLASS(oc);
59
tdc->get = qemu_s390_tod_get;
60
tdc->set = qemu_s390_tod_set;
63
static void qemu_s390_tod_init(Object *obj)
65
S390TODState *td = S390_TOD(obj);
68
qemu_get_timedate(&tm, 0);
70
td->base.low = TOD_UNIX_EPOCH + (time2tod(mktimegm(&tm)) * 1000000000ULL);
71
if (td->base.low < TOD_UNIX_EPOCH) {
76
static const TypeInfo qemu_s390_tod_info = {
77
.name = TYPE_QEMU_S390_TOD,
78
.parent = TYPE_S390_TOD,
79
.instance_size = sizeof(S390TODState),
80
.instance_init = qemu_s390_tod_init,
81
.class_init = qemu_s390_tod_class_init,
82
.class_size = sizeof(S390TODClass),
85
static void register_types(void)
87
type_register_static(&qemu_s390_tod_info);
89
type_init(register_types);