qemu-devel
[Top][All Lists]
Advanced

[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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]