summaryrefslogtreecommitdiffstats
path: root/hw/display/sm501.c
diff options
context:
space:
mode:
authorMarc-André Lureau2019-10-23 16:06:23 +0200
committerMarc-André Lureau2020-01-07 14:24:29 +0100
commit0ed40f16a17eaa3a53d62cc871779fa9d5b4447d (patch)
treeb56563dacdf9daf19adb8aac6d869f14d5a16028 /hw/display/sm501.c
parentmips: use sysbus_mmio_get_region() instead of internal fields (diff)
downloadqemu-0ed40f16a17eaa3a53d62cc871779fa9d5b4447d.tar.gz
qemu-0ed40f16a17eaa3a53d62cc871779fa9d5b4447d.tar.xz
qemu-0ed40f16a17eaa3a53d62cc871779fa9d5b4447d.zip
sm501: make SerialMM a child, export chardev property
Embed the SerialMM sybus device, and re-export its "chardev" property. That way, we can get rid of PROP_PTR "chr-state" and better track devices relationship. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/display/sm501.c')
-rw-r--r--hw/display/sm501.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/hw/display/sm501.c b/hw/display/sm501.c
index 79bd7bc2d1..66a1bfbe60 100644
--- a/hw/display/sm501.c
+++ b/hw/display/sm501.c
@@ -1930,7 +1930,7 @@ typedef struct {
SM501State state;
uint32_t vram_size;
uint32_t base;
- void *chr_state;
+ SerialMM serial;
} SM501SysBusState;
static void sm501_realize_sysbus(DeviceState *dev, Error **errp)
@@ -1938,6 +1938,7 @@ static void sm501_realize_sysbus(DeviceState *dev, Error **errp)
SM501SysBusState *s = SYSBUS_SM501(dev);
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
DeviceState *usb_dev;
+ MemoryRegion *mr;
sm501_init(&s->state, dev, s->vram_size);
if (get_local_mem_size(&s->state) != s->vram_size) {
@@ -1958,15 +1959,15 @@ static void sm501_realize_sysbus(DeviceState *dev, Error **errp)
sysbus_pass_irq(sbd, SYS_BUS_DEVICE(usb_dev));
/* bridge to serial emulation module */
- serial_mm_init(&s->state.mmio_region, SM501_UART0, 2,
- NULL, /* TODO : chain irq to IRL */
- 115200, s->chr_state, DEVICE_LITTLE_ENDIAN);
+ qdev_init_nofail(DEVICE(&s->serial));
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->serial), 0);
+ memory_region_add_subregion(&s->state.mmio_region, SM501_UART0, mr);
+ /* TODO : chain irq to IRL */
}
static Property sm501_sysbus_properties[] = {
DEFINE_PROP_UINT32("vram-size", SM501SysBusState, vram_size, 0),
DEFINE_PROP_UINT32("base", SM501SysBusState, base, 0),
- DEFINE_PROP_PTR("chr-state", SM501SysBusState, chr_state),
DEFINE_PROP_END_OF_LIST(),
};
@@ -1997,9 +1998,20 @@ static void sm501_sysbus_class_init(ObjectClass *klass, void *data)
dc->props = sm501_sysbus_properties;
dc->reset = sm501_reset_sysbus;
dc->vmsd = &vmstate_sm501_sysbus;
- /* Note: pointer property "chr-state" may remain null, thus
- * no need for dc->user_creatable = false;
- */
+}
+
+static void sm501_sysbus_init(Object *o)
+{
+ SM501SysBusState *sm501 = SYSBUS_SM501(o);
+ SerialMM *smm = &sm501->serial;
+
+ sysbus_init_child_obj(o, "serial", smm, sizeof(SerialMM), TYPE_SERIAL_MM);
+ qdev_set_legacy_instance_id(DEVICE(smm), SM501_UART0, 2);
+ qdev_prop_set_uint8(DEVICE(smm), "regshift", 2);
+ qdev_prop_set_uint8(DEVICE(smm), "endianness", DEVICE_LITTLE_ENDIAN);
+
+ object_property_add_alias(o, "chardev",
+ OBJECT(smm), "chardev", &error_abort);
}
static const TypeInfo sm501_sysbus_info = {
@@ -2007,6 +2019,7 @@ static const TypeInfo sm501_sysbus_info = {
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(SM501SysBusState),
.class_init = sm501_sysbus_class_init,
+ .instance_init = sm501_sysbus_init,
};
#define TYPE_PCI_SM501 "sm501"