]> git.proxmox.com Git - mirror_qemu.git/blame - hw/timer/sun4v-rtc.c
spapr_pci: Fix broken naming of PCI bus
[mirror_qemu.git] / hw / timer / sun4v-rtc.c
CommitLineData
a0e89303
AT
1/*
2 * QEMU sun4v Real Time Clock device
3 *
4 * The sun4v_rtc device (sun4v tod clock)
5 *
6 * Copyright (c) 2016 Artyom Tarasenko
7 *
8 * This code is licensed under the GNU GPL v3 or (at your option) any later
9 * version.
10 */
11
12#include "qemu/osdep.h"
13#include "hw/hw.h"
14#include "hw/sysbus.h"
15#include "qemu/timer.h"
16#include "hw/timer/sun4v-rtc.h"
252bfbde 17#include "trace.h"
a0e89303 18
a0e89303
AT
19
20#define TYPE_SUN4V_RTC "sun4v_rtc"
21#define SUN4V_RTC(obj) OBJECT_CHECK(Sun4vRtc, (obj), TYPE_SUN4V_RTC)
22
23typedef struct Sun4vRtc {
24 SysBusDevice parent_obj;
25
26 MemoryRegion iomem;
27} Sun4vRtc;
28
29static uint64_t sun4v_rtc_read(void *opaque, hwaddr addr,
30 unsigned size)
31{
fff54d22 32 uint64_t val = get_clock_realtime() / NANOSECONDS_PER_SECOND;
a0e89303
AT
33 if (!(addr & 4ULL)) {
34 /* accessing the high 32 bits */
35 val >>= 32;
36 }
252bfbde 37 trace_sun4v_rtc_read(addr, val);
a0e89303
AT
38 return val;
39}
40
41static void sun4v_rtc_write(void *opaque, hwaddr addr,
42 uint64_t val, unsigned size)
43{
51809286 44 trace_sun4v_rtc_write(addr, val);
a0e89303
AT
45}
46
47static const MemoryRegionOps sun4v_rtc_ops = {
48 .read = sun4v_rtc_read,
49 .write = sun4v_rtc_write,
50 .endianness = DEVICE_NATIVE_ENDIAN,
51};
52
53void sun4v_rtc_init(hwaddr addr)
54{
55 DeviceState *dev;
56 SysBusDevice *s;
57
58 dev = qdev_create(NULL, TYPE_SUN4V_RTC);
59 s = SYS_BUS_DEVICE(dev);
60
61 qdev_init_nofail(dev);
62
63 sysbus_mmio_map(s, 0, addr);
64}
65
e871972e 66static void sun4v_rtc_realize(DeviceState *dev, Error **errp)
a0e89303 67{
e871972e 68 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
a0e89303
AT
69 Sun4vRtc *s = SUN4V_RTC(dev);
70
71 memory_region_init_io(&s->iomem, OBJECT(s), &sun4v_rtc_ops, s,
72 "sun4v-rtc", 0x08ULL);
e871972e 73 sysbus_init_mmio(sbd, &s->iomem);
a0e89303
AT
74}
75
76static void sun4v_rtc_class_init(ObjectClass *klass, void *data)
77{
e871972e 78 DeviceClass *dc = DEVICE_CLASS(klass);
a0e89303 79
e871972e 80 dc->realize = sun4v_rtc_realize;
a0e89303
AT
81}
82
83static const TypeInfo sun4v_rtc_info = {
84 .name = TYPE_SUN4V_RTC,
85 .parent = TYPE_SYS_BUS_DEVICE,
86 .instance_size = sizeof(Sun4vRtc),
87 .class_init = sun4v_rtc_class_init,
88};
89
90static void sun4v_rtc_register_types(void)
91{
92 type_register_static(&sun4v_rtc_info);
93}
94
95type_init(sun4v_rtc_register_types)