2016-03-02 17:26:08 +03:00
|
|
|
/*
|
|
|
|
* QEMU sun4v Real Time Clock device
|
|
|
|
*
|
|
|
|
* The sun4v_rtc device (sun4v tod clock)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Artyom Tarasenko
|
|
|
|
*
|
|
|
|
* This code is licensed under the GNU GPL v3 or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "hw/sysbus.h"
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:31:58 +03:00
|
|
|
#include "qapi/error.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2016-03-02 17:26:08 +03:00
|
|
|
#include "qemu/timer.h"
|
2019-10-04 02:03:56 +03:00
|
|
|
#include "hw/rtc/sun4v-rtc.h"
|
2018-10-03 00:25:11 +03:00
|
|
|
#include "trace.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2016-03-02 17:26:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
#define TYPE_SUN4V_RTC "sun4v_rtc"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(Sun4vRtc, SUN4V_RTC)
|
2016-03-02 17:26:08 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct Sun4vRtc {
|
2016-03-02 17:26:08 +03:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
|
|
|
MemoryRegion iomem;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2016-03-02 17:26:08 +03:00
|
|
|
|
|
|
|
static uint64_t sun4v_rtc_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
|
|
|
{
|
2016-09-29 15:02:19 +03:00
|
|
|
uint64_t val = get_clock_realtime() / NANOSECONDS_PER_SECOND;
|
2016-03-02 17:26:08 +03:00
|
|
|
if (!(addr & 4ULL)) {
|
|
|
|
/* accessing the high 32 bits */
|
|
|
|
val >>= 32;
|
|
|
|
}
|
2018-10-03 00:25:11 +03:00
|
|
|
trace_sun4v_rtc_read(addr, val);
|
2016-03-02 17:26:08 +03:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sun4v_rtc_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
|
|
|
{
|
2018-10-31 03:18:43 +03:00
|
|
|
trace_sun4v_rtc_write(addr, val);
|
2016-03-02 17:26:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps sun4v_rtc_ops = {
|
|
|
|
.read = sun4v_rtc_read,
|
|
|
|
.write = sun4v_rtc_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
|
|
|
void sun4v_rtc_init(hwaddr addr)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
SysBusDevice *s;
|
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:31:58 +03:00
|
|
|
dev = qdev_new(TYPE_SUN4V_RTC);
|
2016-03-02 17:26:08 +03:00
|
|
|
s = SYS_BUS_DEVICE(dev);
|
|
|
|
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:32:34 +03:00
|
|
|
sysbus_realize_and_unref(s, &error_fatal);
|
2016-03-02 17:26:08 +03:00
|
|
|
|
|
|
|
sysbus_mmio_map(s, 0, addr);
|
|
|
|
}
|
|
|
|
|
2018-10-03 00:25:12 +03:00
|
|
|
static void sun4v_rtc_realize(DeviceState *dev, Error **errp)
|
2016-03-02 17:26:08 +03:00
|
|
|
{
|
2018-10-03 00:25:12 +03:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
2016-03-02 17:26:08 +03:00
|
|
|
Sun4vRtc *s = SUN4V_RTC(dev);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &sun4v_rtc_ops, s,
|
|
|
|
"sun4v-rtc", 0x08ULL);
|
2018-10-03 00:25:12 +03:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2016-03-02 17:26:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sun4v_rtc_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2018-10-03 00:25:12 +03:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2016-03-02 17:26:08 +03:00
|
|
|
|
2018-10-03 00:25:12 +03:00
|
|
|
dc->realize = sun4v_rtc_realize;
|
2016-03-02 17:26:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo sun4v_rtc_info = {
|
|
|
|
.name = TYPE_SUN4V_RTC,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(Sun4vRtc),
|
|
|
|
.class_init = sun4v_rtc_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sun4v_rtc_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&sun4v_rtc_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(sun4v_rtc_register_types)
|