pckbd: remove duplicated keyboard and mouse defines
[qemu/ar7.git] / hw / rtc / sun4v-rtc.c
blobe037acd1b56d723f91fa8871f9fd491decd59c1d
1 /*
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
9 * version.
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"
18 #include "trace.h"
19 #include "qom/object.h"
22 #define TYPE_SUN4V_RTC "sun4v_rtc"
23 OBJECT_DECLARE_SIMPLE_TYPE(Sun4vRtc, SUN4V_RTC)
25 struct Sun4vRtc {
26 SysBusDevice parent_obj;
28 MemoryRegion iomem;
31 static uint64_t sun4v_rtc_read(void *opaque, hwaddr addr,
32 unsigned size)
34 uint64_t val = get_clock_realtime() / NANOSECONDS_PER_SECOND;
35 if (!(addr & 4ULL)) {
36 /* accessing the high 32 bits */
37 val >>= 32;
39 trace_sun4v_rtc_read(addr, val);
40 return val;
43 static void sun4v_rtc_write(void *opaque, hwaddr addr,
44 uint64_t val, unsigned size)
46 trace_sun4v_rtc_write(addr, val);
49 static const MemoryRegionOps sun4v_rtc_ops = {
50 .read = sun4v_rtc_read,
51 .write = sun4v_rtc_write,
52 .endianness = DEVICE_NATIVE_ENDIAN,
55 void sun4v_rtc_init(hwaddr addr)
57 DeviceState *dev;
58 SysBusDevice *s;
60 dev = qdev_new(TYPE_SUN4V_RTC);
61 s = SYS_BUS_DEVICE(dev);
63 sysbus_realize_and_unref(s, &error_fatal);
65 sysbus_mmio_map(s, 0, addr);
68 static void sun4v_rtc_realize(DeviceState *dev, Error **errp)
70 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
71 Sun4vRtc *s = SUN4V_RTC(dev);
73 memory_region_init_io(&s->iomem, OBJECT(s), &sun4v_rtc_ops, s,
74 "sun4v-rtc", 0x08ULL);
75 sysbus_init_mmio(sbd, &s->iomem);
78 static void sun4v_rtc_class_init(ObjectClass *klass, void *data)
80 DeviceClass *dc = DEVICE_CLASS(klass);
82 dc->realize = sun4v_rtc_realize;
85 static const TypeInfo sun4v_rtc_info = {
86 .name = TYPE_SUN4V_RTC,
87 .parent = TYPE_SYS_BUS_DEVICE,
88 .instance_size = sizeof(Sun4vRtc),
89 .class_init = sun4v_rtc_class_init,
92 static void sun4v_rtc_register_types(void)
94 type_register_static(&sun4v_rtc_info);
97 type_init(sun4v_rtc_register_types)