aboutsummaryrefslogtreecommitdiff
path: root/hw/char/serial.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2019-10-23 17:50:06 +0200
committerMarc-André Lureau <marcandre.lureau@redhat.com>2020-01-07 17:23:30 +0400
commit490a9d9b36bfa22a6b46b27e6e9e84e1bac44c68 (patch)
tree43f06f0768176835bf5eff8911687c9721e3fb1e /hw/char/serial.c
parentb9975000a008c5b0801e3d24ed113a1bd2767ed5 (diff)
serial: start making SerialMM a sysbus device
Memory mapped serial device is in fact a sysbus device. The following patches will make use of sysbus facilities for resource and registration. In particular, "serial-mm: use sysbus facilities" will move internal serial realization to serial_mm_realize callback to follow qdev best practices. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/char/serial.c')
-rw-r--r--hw/char/serial.c72
1 files changed, 55 insertions, 17 deletions
diff --git a/hw/char/serial.c b/hw/char/serial.c
index ec388f3876..824390817c 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -1032,16 +1032,28 @@ static const TypeInfo serial_info = {
static uint64_t serial_mm_read(void *opaque, hwaddr addr,
unsigned size)
{
- SerialState *s = opaque;
- return serial_ioport_read(s, addr >> s->it_shift, 1);
+ SerialMM *s = SERIAL_MM(opaque);
+ return serial_ioport_read(&s->serial, addr >> s->it_shift, 1);
}
static void serial_mm_write(void *opaque, hwaddr addr,
uint64_t value, unsigned size)
{
- SerialState *s = opaque;
+ SerialMM *s = SERIAL_MM(opaque);
value &= 255;
- serial_ioport_write(s, addr >> s->it_shift, value, 1);
+ serial_ioport_write(&s->serial, addr >> s->it_shift, value, 1);
+}
+
+static void serial_mm_realize(DeviceState *dev, Error **errp)
+{
+ SerialMM *s = SERIAL_MM(dev);
+ Error *local_err = NULL;
+
+ object_property_set_bool(OBJECT(&s->serial), true, "realized", &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
}
static const MemoryRegionOps serial_mm_ops[3] = {
@@ -1068,30 +1080,56 @@ static const MemoryRegionOps serial_mm_ops[3] = {
},
};
-SerialState *serial_mm_init(MemoryRegion *address_space,
- hwaddr base, int it_shift,
- qemu_irq irq, int baudbase,
- Chardev *chr, enum device_endian end)
+SerialMM *serial_mm_init(MemoryRegion *address_space,
+ hwaddr base, int it_shift,
+ qemu_irq irq, int baudbase,
+ Chardev *chr, enum device_endian end)
{
- DeviceState *dev = DEVICE(object_new(TYPE_SERIAL));
- SerialState *s = SERIAL(dev);
+ SerialMM *smm = SERIAL_MM(qdev_create(NULL, TYPE_SERIAL_MM));
+ SerialState *s = &smm->serial;
- s->it_shift = it_shift;
+ smm->it_shift = it_shift;
s->irq = irq;
- qdev_prop_set_uint32(dev, "baudbase", baudbase);
- qdev_prop_set_chr(dev, "chardev", chr);
- qdev_set_legacy_instance_id(dev, base, 2);
- qdev_init_nofail(dev);
+ qdev_prop_set_uint32(DEVICE(s), "baudbase", baudbase);
+ qdev_prop_set_chr(DEVICE(s), "chardev", chr);
+ qdev_set_legacy_instance_id(DEVICE(s), base, 2);
- memory_region_init_io(&s->io, NULL, &serial_mm_ops[end], s,
+ qdev_init_nofail(DEVICE(smm));
+
+ memory_region_init_io(&s->io, NULL, &serial_mm_ops[end], smm,
"serial", 8 << it_shift);
memory_region_add_subregion(address_space, base, &s->io);
- return s;
+
+ return smm;
+}
+
+static void serial_mm_instance_init(Object *o)
+{
+ SerialMM *smm = SERIAL_MM(o);
+
+ object_initialize_child(o, "serial", &smm->serial, sizeof(smm->serial),
+ TYPE_SERIAL, &error_abort, NULL);
}
+static void serial_mm_class_init(ObjectClass *oc, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(oc);
+
+ dc->realize = serial_mm_realize;
+}
+
+static const TypeInfo serial_mm_info = {
+ .name = TYPE_SERIAL_MM,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .class_init = serial_mm_class_init,
+ .instance_init = serial_mm_instance_init,
+ .instance_size = sizeof(SerialMM),
+};
+
static void serial_register_types(void)
{
type_register_static(&serial_info);
+ type_register_static(&serial_mm_info);
}
type_init(serial_register_types)