[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/37] serial-mm: use sysbus facilities
From: |
Marc-André Lureau |
Subject: |
[PULL 15/37] serial-mm: use sysbus facilities |
Date: |
Tue, 7 Jan 2020 19:04:20 +0400 |
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 <address@hidden>
Reviewed-by: Peter Maydell <address@hidden>
---
hw/char/serial.c | 50 +++++++++++++++++++++++++++---------------------
1 file changed, 28 insertions(+), 22 deletions(-)
diff --git a/hw/char/serial.c b/hw/char/serial.c
index 1d350a851b..b3927c7198 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[] = {
--
2.25.0.rc1.20.g2443f3f80d
- [PULL 05/37] serial-pci-multi: factor out multi_serial_get_port_count(), (continued)
- [PULL 05/37] serial-pci-multi: factor out multi_serial_get_port_count(), Marc-André Lureau, 2020/01/07
- [PULL 06/37] serial: initial qom-ification, Marc-André Lureau, 2020/01/07
- [PULL 07/37] serial: register vmsd with DeviceClass, Marc-André Lureau, 2020/01/07
- [PULL 08/37] serial: add "chardev" property, Marc-André Lureau, 2020/01/07
- [PULL 09/37] serial: add "baudbase" property, Marc-André Lureau, 2020/01/07
- [PULL 10/37] serial: realize the serial device, Marc-André Lureau, 2020/01/07
- [PULL 11/37] serial: replace serial_exit_core() with unrealize, Marc-André Lureau, 2020/01/07
- [PULL 12/37] serial: start making SerialMM a sysbus device, Marc-André Lureau, 2020/01/07
- [PULL 13/37] serial-mm: add "regshift" property, Marc-André Lureau, 2020/01/07
- [PULL 14/37] serial-mm: add endianness property, Marc-André Lureau, 2020/01/07
- [PULL 15/37] serial-mm: use sysbus facilities,
Marc-André Lureau <=
- [PULL 17/37] mips: inline serial_init(), Marc-André Lureau, 2020/01/07
- [PULL 16/37] serial: make SerialIO a sysbus device, Marc-André Lureau, 2020/01/07
- [PULL 18/37] mips: baudbase is 115200 by default, Marc-André Lureau, 2020/01/07
- [PULL 19/37] mips: use sysbus_add_io(), Marc-André Lureau, 2020/01/07
- [PULL 20/37] mips: use sysbus_mmio_get_region() instead of internal fields, Marc-André Lureau, 2020/01/07
- [PULL 21/37] sm501: make SerialMM a child, export chardev property, Marc-André Lureau, 2020/01/07
- [PULL 22/37] vmmouse: replace PROP_PTR with PROP_LINK, Marc-André Lureau, 2020/01/07
- [PULL 24/37] etraxfs: remove PROP_PTR usage, Marc-André Lureau, 2020/01/07
- [PULL 23/37] lance: replace PROP_PTR with PROP_LINK, Marc-André Lureau, 2020/01/07
- [PULL 25/37] dp8393x: replace PROP_PTR with PROP_LINK, Marc-André Lureau, 2020/01/07