2 * QEMU sun4v Real Time Clock device
4 * The sun4v_rtc device (sun4v tod clock)
6 * Copyright (c) 2016 Artyom Tarasenko
8 * This code is licensed under the GNU GPL v3 or (at your option) any later
12 #include "qemu/osdep.h"
13 #include "hw/sysbus.h"
14 #include "qapi/error.h"
15 #include "qemu/module.h"
16 #include "qemu/timer.h"
17 #include "hw/rtc/sun4v-rtc.h"
19 #include "qom/object.h"
22 #define TYPE_SUN4V_RTC "sun4v_rtc"
23 typedef struct Sun4vRtc Sun4vRtc
;
24 DECLARE_INSTANCE_CHECKER(Sun4vRtc
, SUN4V_RTC
,
28 SysBusDevice parent_obj
;
33 static uint64_t sun4v_rtc_read(void *opaque
, hwaddr addr
,
36 uint64_t val
= get_clock_realtime() / NANOSECONDS_PER_SECOND
;
38 /* accessing the high 32 bits */
41 trace_sun4v_rtc_read(addr
, val
);
45 static void sun4v_rtc_write(void *opaque
, hwaddr addr
,
46 uint64_t val
, unsigned size
)
48 trace_sun4v_rtc_write(addr
, val
);
51 static const MemoryRegionOps sun4v_rtc_ops
= {
52 .read
= sun4v_rtc_read
,
53 .write
= sun4v_rtc_write
,
54 .endianness
= DEVICE_NATIVE_ENDIAN
,
57 void sun4v_rtc_init(hwaddr addr
)
62 dev
= qdev_new(TYPE_SUN4V_RTC
);
63 s
= SYS_BUS_DEVICE(dev
);
65 sysbus_realize_and_unref(s
, &error_fatal
);
67 sysbus_mmio_map(s
, 0, addr
);
70 static void sun4v_rtc_realize(DeviceState
*dev
, Error
**errp
)
72 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
73 Sun4vRtc
*s
= SUN4V_RTC(dev
);
75 memory_region_init_io(&s
->iomem
, OBJECT(s
), &sun4v_rtc_ops
, s
,
76 "sun4v-rtc", 0x08ULL
);
77 sysbus_init_mmio(sbd
, &s
->iomem
);
80 static void sun4v_rtc_class_init(ObjectClass
*klass
, void *data
)
82 DeviceClass
*dc
= DEVICE_CLASS(klass
);
84 dc
->realize
= sun4v_rtc_realize
;
87 static const TypeInfo sun4v_rtc_info
= {
88 .name
= TYPE_SUN4V_RTC
,
89 .parent
= TYPE_SYS_BUS_DEVICE
,
90 .instance_size
= sizeof(Sun4vRtc
),
91 .class_init
= sun4v_rtc_class_init
,
94 static void sun4v_rtc_register_types(void)
96 type_register_static(&sun4v_rtc_info
);
99 type_init(sun4v_rtc_register_types
)