serial: make SerialIO a sysbus device

Make serial IO a proper sysbus device, similar to serial MM.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
This commit is contained in:
Marc-André Lureau 2019-10-23 18:37:33 +02:00
parent 9bc7176c8c
commit 10315a7089
2 changed files with 64 additions and 13 deletions

View File

@ -985,22 +985,63 @@ const MemoryRegionOps serial_io_ops = {
.endianness = DEVICE_LITTLE_ENDIAN, .endianness = DEVICE_LITTLE_ENDIAN,
}; };
SerialState *serial_init(int base, qemu_irq irq, int baudbase, static void serial_io_realize(DeviceState *dev, Error **errp)
Chardev *chr, MemoryRegion *system_io)
{ {
DeviceState *dev = DEVICE(object_new(TYPE_SERIAL)); SerialIO *sio = SERIAL_IO(dev);
SerialState *s = SERIAL(dev); SerialState *s = &sio->serial;
Error *local_err = NULL;
s->irq = irq; object_property_set_bool(OBJECT(s), true, "realized", &local_err);
qdev_prop_set_uint32(dev, "baudbase", baudbase); if (local_err) {
qdev_prop_set_chr(dev, "chardev", chr); error_propagate(errp, local_err);
qdev_set_legacy_instance_id(dev, base, 2); return;
qdev_init_nofail(dev); }
memory_region_init_io(&s->io, NULL, &serial_io_ops, s, "serial", 8); memory_region_init_io(&s->io, NULL, &serial_io_ops, s, "serial", 8);
memory_region_add_subregion(system_io, base, &s->io); sysbus_init_irq(SYS_BUS_DEVICE(sio), &s->irq);
}
return s; static void serial_io_class_init(ObjectClass *klass, void* data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
dc->realize = serial_io_realize;
/* No dc->vmsd: class has no migratable state */
}
static void serial_io_instance_init(Object *o)
{
SerialIO *sio = SERIAL_IO(o);
object_initialize_child(o, "serial", &sio->serial, sizeof(sio->serial),
TYPE_SERIAL, &error_abort, NULL);
qdev_alias_all_properties(DEVICE(&sio->serial), o);
}
static const TypeInfo serial_io_info = {
.name = TYPE_SERIAL_IO,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(SerialIO),
.instance_init = serial_io_instance_init,
.class_init = serial_io_class_init,
};
SerialIO *serial_init(int base, qemu_irq irq, int baudbase,
Chardev *chr, MemoryRegion *system_io)
{
SerialIO *sio = SERIAL_IO(qdev_create(NULL, TYPE_SERIAL_IO));
qdev_prop_set_uint32(DEVICE(sio), "baudbase", baudbase);
qdev_prop_set_chr(DEVICE(sio), "chardev", chr);
qdev_set_legacy_instance_id(DEVICE(sio), base, 2);
qdev_init_nofail(DEVICE(sio));
sysbus_connect_irq(SYS_BUS_DEVICE(sio), 0, irq);
memory_region_add_subregion(system_io, base, &sio->serial.io);
return sio;
} }
static Property serial_properties[] = { static Property serial_properties[] = {
@ -1149,6 +1190,7 @@ static const TypeInfo serial_mm_info = {
static void serial_register_types(void) static void serial_register_types(void)
{ {
type_register_static(&serial_info); type_register_static(&serial_info);
type_register_static(&serial_io_info);
type_register_static(&serial_mm_info); type_register_static(&serial_mm_info);
} }

View File

@ -88,6 +88,12 @@ typedef struct SerialMM {
uint8_t endianness; uint8_t endianness;
} SerialMM; } SerialMM;
typedef struct SerialIO {
SysBusDevice parent;
SerialState serial;
} SerialIO;
extern const VMStateDescription vmstate_serial; extern const VMStateDescription vmstate_serial;
extern const MemoryRegionOps serial_io_ops; extern const MemoryRegionOps serial_io_ops;
@ -99,7 +105,10 @@ void serial_set_frequency(SerialState *s, uint32_t frequency);
#define TYPE_SERIAL_MM "serial-mm" #define TYPE_SERIAL_MM "serial-mm"
#define SERIAL_MM(s) OBJECT_CHECK(SerialMM, (s), TYPE_SERIAL_MM) #define SERIAL_MM(s) OBJECT_CHECK(SerialMM, (s), TYPE_SERIAL_MM)
SerialState *serial_init(int base, qemu_irq irq, int baudbase, #define TYPE_SERIAL_IO "serial-io"
#define SERIAL_IO(s) OBJECT_CHECK(SerialIO, (s), TYPE_SERIAL_IO)
SerialIO *serial_init(int base, qemu_irq irq, int baudbase,
Chardev *chr, MemoryRegion *system_io); Chardev *chr, MemoryRegion *system_io);
SerialMM *serial_mm_init(MemoryRegion *address_space, SerialMM *serial_mm_init(MemoryRegion *address_space,
hwaddr base, int regshift, hwaddr base, int regshift,