aboutsummaryrefslogtreecommitdiff
path: root/hw/char/serial.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2019-11-20 12:28:15 +0400
committerMarc-André Lureau <marcandre.lureau@redhat.com>2020-01-07 17:24:29 +0400
commit9bc7176c8c30760d2dc0e5b560a6c14f5f9aa08d (patch)
tree52a047c2a021ff5ac874720ee2e97ae1affbddc1 /hw/char/serial.c
parent80b2eed95dd6397541cc4d7ec36db0e182a8f402 (diff)
downloadqemu-9bc7176c8c30760d2dc0e5b560a6c14f5f9aa08d.zip
qemu-9bc7176c8c30760d2dc0e5b560a6c14f5f9aa08d.tar.gz
qemu-9bc7176c8c30760d2dc0e5b560a6c14f5f9aa08d.tar.bz2
serial-mm: use sysbus facilities
Make SerialMM a regular sysbus device, by registering the irq, and the mmio region. Reexport the internal serial properties. 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.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/hw/char/serial.c b/hw/char/serial.c
index 1d350a8..b3927c7 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -1044,18 +1044,6 @@ static void serial_mm_write(void *opaque, hwaddr addr,
serial_ioport_write(&s->serial, addr >> s->regshift, 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] = {
[DEVICE_NATIVE_ENDIAN] = {
.read = serial_mm_read,
@@ -1080,26 +1068,42 @@ static const MemoryRegionOps serial_mm_ops[3] = {
},
};
+static void serial_mm_realize(DeviceState *dev, Error **errp)
+{
+ SerialMM *smm = SERIAL_MM(dev);
+ SerialState *s = &smm->serial;
+ Error *local_err = NULL;
+
+ object_property_set_bool(OBJECT(s), true, "realized", &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ memory_region_init_io(&s->io, NULL, &serial_mm_ops[smm->endianness], smm,
+ "serial", 8 << smm->regshift);
+ sysbus_init_mmio(SYS_BUS_DEVICE(smm), &s->io);
+ sysbus_init_irq(SYS_BUS_DEVICE(smm), &smm->serial.irq);
+}
+
SerialMM *serial_mm_init(MemoryRegion *address_space,
hwaddr base, int regshift,
qemu_irq irq, int baudbase,
Chardev *chr, enum device_endian end)
{
SerialMM *smm = SERIAL_MM(qdev_create(NULL, TYPE_SERIAL_MM));
- SerialState *s = &smm->serial;
+ MemoryRegion *mr;
qdev_prop_set_uint8(DEVICE(smm), "regshift", regshift);
- s->irq = irq;
- 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);
- qdev_prop_set_uint8(DEVICE(self), "endianness", end);
-
+ qdev_prop_set_uint32(DEVICE(smm), "baudbase", baudbase);
+ qdev_prop_set_chr(DEVICE(smm), "chardev", chr);
+ qdev_set_legacy_instance_id(DEVICE(smm), base, 2);
+ qdev_prop_set_uint8(DEVICE(smm), "endianness", end);
qdev_init_nofail(DEVICE(smm));
- memory_region_init_io(&s->io, NULL, &serial_mm_ops[end], smm,
- "serial", 8 << regshift);
- memory_region_add_subregion(address_space, base, &s->io);
+ sysbus_connect_irq(SYS_BUS_DEVICE(smm), 0, irq);
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(smm), 0);
+ memory_region_add_subregion(address_space, base, mr);
return smm;
}
@@ -1110,6 +1114,8 @@ static void serial_mm_instance_init(Object *o)
object_initialize_child(o, "serial", &smm->serial, sizeof(smm->serial),
TYPE_SERIAL, &error_abort, NULL);
+
+ qdev_alias_all_properties(DEVICE(&smm->serial), o);
}
static Property serial_mm_properties[] = {