From 7e83a77f96ee18cb891f309dc617caa5e07ff51e Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Tue, 22 Oct 2019 19:18:12 +0200 Subject: sysbus: remove unused sysbus_try_create* Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell --- include/hw/sysbus.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'include/hw') diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h index 27e80881da..2eb0484388 100644 --- a/include/hw/sysbus.h +++ b/include/hw/sysbus.h @@ -117,8 +117,7 @@ void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque); /* Legacy helper function for creating devices. */ DeviceState *sysbus_create_varargs(const char *name, hwaddr addr, ...); -DeviceState *sysbus_try_create_varargs(const char *name, - hwaddr addr, ...); + static inline DeviceState *sysbus_create_simple(const char *name, hwaddr addr, qemu_irq irq) @@ -126,11 +125,5 @@ static inline DeviceState *sysbus_create_simple(const char *name, return sysbus_create_varargs(name, addr, irq, NULL); } -static inline DeviceState *sysbus_try_create_simple(const char *name, - hwaddr addr, - qemu_irq irq) -{ - return sysbus_try_create_varargs(name, addr, irq, NULL); -} #endif /* HW_SYSBUS_H */ -- cgit v1.2.3-55-g7522 From a35c6ccc06536e076d5a23c51d67458e3546672c Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Wed, 23 Oct 2019 12:56:31 +0200 Subject: sysbus: remove outdated comment The init callback is no more since commit 817a17fc60f44e29a1944b60d32f45ea127f0cf9 ("core/sysbus: remove the SysBusDeviceClass::init path") Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé --- include/hw/sysbus.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'include/hw') diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h index 2eb0484388..c4a1c0adfa 100644 --- a/include/hw/sysbus.h +++ b/include/hw/sysbus.h @@ -24,10 +24,6 @@ typedef struct SysBusDevice SysBusDevice; /** * SysBusDeviceClass: - * @init: Callback function invoked when the #DeviceState.realized property - * is changed to %true. Deprecated, new types inheriting directly from - * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf - * types should consult their respective parent type. * * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived * classes overriding it are not required to invoke its implementation. -- cgit v1.2.3-55-g7522 From 7781b88ee458ff933459503ade0b0a6ddaad08de Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Mon, 21 Oct 2019 23:32:12 +0200 Subject: serial: initial qom-ification Make SerialState a device (the following patches will introduce IO/MM sysbus serial devices) None of the serial_{,mm}_init() callers actually free the returned value (even if they did, it would be quite harmless), so we can change the object allocation at will. However, the devices that embed SerialState must now have their field QOM-initialized manually (isa, pci, pci-multi). Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell --- hw/char/serial-isa.c | 9 +++++++++ hw/char/serial-pci-multi.c | 15 +++++++++++++++ hw/char/serial-pci.c | 13 ++++++++++++- hw/char/serial.c | 34 ++++++++++++++++++++++++++++------ include/hw/char/serial.h | 7 ++++++- 5 files changed, 70 insertions(+), 8 deletions(-) (limited to 'include/hw') diff --git a/hw/char/serial-isa.c b/hw/char/serial-isa.c index 9e31c51bb6..9a5928b3ee 100644 --- a/hw/char/serial-isa.c +++ b/hw/char/serial-isa.c @@ -111,10 +111,19 @@ static void serial_isa_class_initfn(ObjectClass *klass, void *data) set_bit(DEVICE_CATEGORY_INPUT, dc->categories); } +static void serial_isa_initfn(Object *o) +{ + ISASerialState *self = ISA_SERIAL(o); + + object_initialize_child(o, "serial", &self->state, sizeof(self->state), + TYPE_SERIAL, &error_abort, NULL); +} + static const TypeInfo serial_isa_info = { .name = TYPE_ISA_SERIAL, .parent = TYPE_ISA_DEVICE, .instance_size = sizeof(ISASerialState), + .instance_init = serial_isa_initfn, .class_init = serial_isa_class_initfn, }; diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c index 5c553c30d0..edfbfdca9e 100644 --- a/hw/char/serial-pci-multi.c +++ b/hw/char/serial-pci-multi.c @@ -181,10 +181,24 @@ static void multi_4x_serial_pci_class_initfn(ObjectClass *klass, void *data) set_bit(DEVICE_CATEGORY_INPUT, dc->categories); } +static void multi_serial_init(Object *o) +{ + PCIDevice *dev = PCI_DEVICE(o); + PCIMultiSerialState *pms = DO_UPCAST(PCIMultiSerialState, dev, dev); + size_t i, nports = multi_serial_get_port_count(PCI_DEVICE_GET_CLASS(dev)); + + for (i = 0; i < nports; i++) { + object_initialize_child(o, "serial[*]", &pms->state[i], + sizeof(pms->state[i]), + TYPE_SERIAL, &error_abort, NULL); + } +} + static const TypeInfo multi_2x_serial_pci_info = { .name = "pci-serial-2x", .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCIMultiSerialState), + .instance_init = multi_serial_init, .class_init = multi_2x_serial_pci_class_initfn, .interfaces = (InterfaceInfo[]) { { INTERFACE_CONVENTIONAL_PCI_DEVICE }, @@ -196,6 +210,7 @@ static const TypeInfo multi_4x_serial_pci_info = { .name = "pci-serial-4x", .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCIMultiSerialState), + .instance_init = multi_serial_init, .class_init = multi_4x_serial_pci_class_initfn, .interfaces = (InterfaceInfo[]) { { INTERFACE_CONVENTIONAL_PCI_DEVICE }, diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c index cb9b76e22b..f99b6c19e0 100644 --- a/hw/char/serial-pci.c +++ b/hw/char/serial-pci.c @@ -40,6 +40,8 @@ typedef struct PCISerialState { uint8_t prog_if; } PCISerialState; +#define TYPE_PCI_SERIAL "pci-serial" +#define PCI_SERIAL(s) OBJECT_CHECK(PCISerialState, (s), TYPE_PCI_SERIAL) static void serial_pci_realize(PCIDevice *dev, Error **errp) { @@ -103,10 +105,19 @@ static void serial_pci_class_initfn(ObjectClass *klass, void *data) set_bit(DEVICE_CATEGORY_INPUT, dc->categories); } +static void serial_pci_init(Object *o) +{ + PCISerialState *ps = PCI_SERIAL(o); + + object_initialize_child(o, "serial", &ps->state, sizeof(ps->state), + TYPE_SERIAL, &error_abort, NULL); +} + static const TypeInfo serial_pci_info = { - .name = "pci-serial", + .name = TYPE_PCI_SERIAL, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCISerialState), + .instance_init = serial_pci_init, .class_init = serial_pci_class_initfn, .interfaces = (InterfaceInfo[]) { { INTERFACE_CONVENTIONAL_PCI_DEVICE }, diff --git a/hw/char/serial.c b/hw/char/serial.c index b4aa250950..233a9e2076 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -983,9 +983,8 @@ const MemoryRegionOps serial_io_ops = { SerialState *serial_init(int base, qemu_irq irq, int baudbase, Chardev *chr, MemoryRegion *system_io) { - SerialState *s; - - s = g_malloc0(sizeof(SerialState)); + DeviceState *dev = DEVICE(object_new(TYPE_SERIAL)); + SerialState *s = SERIAL(dev); s->irq = irq; s->baudbase = baudbase; @@ -993,6 +992,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase, serial_realize_core(s, &error_fatal); vmstate_register(NULL, base, &vmstate_serial, s); + qdev_init_nofail(dev); memory_region_init_io(&s->io, NULL, &serial_io_ops, s, "serial", 8); memory_region_add_subregion(system_io, base, &s->io); @@ -1000,6 +1000,21 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase, return s; } +static void serial_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + /* internal device for serialio/serialmm, not user-creatable */ + dc->user_creatable = false; +} + +static const TypeInfo serial_info = { + .name = TYPE_SERIAL, + .parent = TYPE_DEVICE, + .instance_size = sizeof(SerialState), + .class_init = serial_class_init, +}; + /* Memory mapped interface */ static uint64_t serial_mm_read(void *opaque, hwaddr addr, unsigned size) @@ -1045,9 +1060,8 @@ SerialState *serial_mm_init(MemoryRegion *address_space, qemu_irq irq, int baudbase, Chardev *chr, enum device_endian end) { - SerialState *s; - - s = g_malloc0(sizeof(SerialState)); + DeviceState *dev = DEVICE(object_new(TYPE_SERIAL)); + SerialState *s = SERIAL(dev); s->it_shift = it_shift; s->irq = irq; @@ -1056,9 +1070,17 @@ SerialState *serial_mm_init(MemoryRegion *address_space, serial_realize_core(s, &error_fatal); vmstate_register(NULL, base, &vmstate_serial, s); + qdev_init_nofail(dev); memory_region_init_io(&s->io, NULL, &serial_mm_ops[end], s, "serial", 8 << it_shift); memory_region_add_subregion(address_space, base, &s->io); return s; } + +static void serial_register_types(void) +{ + type_register_static(&serial_info); +} + +type_init(serial_register_types) diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 8be3d8a4f9..180cc7c24e 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -30,10 +30,13 @@ #include "exec/memory.h" #include "qemu/fifo8.h" #include "chardev/char.h" +#include "hw/sysbus.h" #define UART_FIFO_LENGTH 16 /* 16550A Fifo Length */ typedef struct SerialState { + DeviceState parent; + uint16_t divider; uint8_t rbr; /* receive register */ uint8_t thr; /* transmit holding register */ @@ -84,7 +87,9 @@ void serial_realize_core(SerialState *s, Error **errp); void serial_exit_core(SerialState *s); void serial_set_frequency(SerialState *s, uint32_t frequency); -/* legacy pre qom */ +#define TYPE_SERIAL "serial" +#define SERIAL(s) OBJECT_CHECK(SerialState, (s), TYPE_SERIAL) + SerialState *serial_init(int base, qemu_irq irq, int baudbase, Chardev *chr, MemoryRegion *system_io); SerialState *serial_mm_init(MemoryRegion *address_space, -- cgit v1.2.3-55-g7522 From 96651db423a0a25466629d35c775531f5145a66a Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Tue, 22 Oct 2019 00:35:36 +0200 Subject: serial: add "baudbase" property Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell --- hw/char/serial-isa.c | 1 - hw/char/serial-pci-multi.c | 1 - hw/char/serial-pci.c | 1 - hw/char/serial.c | 5 +++-- include/hw/char/serial.h | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) (limited to 'include/hw') diff --git a/hw/char/serial-isa.c b/hw/char/serial-isa.c index 9a5928b3ee..2a4c8de1bf 100644 --- a/hw/char/serial-isa.c +++ b/hw/char/serial-isa.c @@ -73,7 +73,6 @@ static void serial_isa_realizefn(DeviceState *dev, Error **errp) } index++; - s->baudbase = 115200; isa_init_irq(isadev, &s->irq, isa->isairq); serial_realize_core(s, errp); qdev_set_legacy_instance_id(dev, isa->iobase, 3); diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c index edfbfdca9e..4891f32230 100644 --- a/hw/char/serial-pci-multi.c +++ b/hw/char/serial-pci-multi.c @@ -106,7 +106,6 @@ static void multi_serial_pci_realize(PCIDevice *dev, Error **errp) for (i = 0; i < nports; i++) { s = pci->state + i; - s->baudbase = 115200; serial_realize_core(s, &err); if (err != NULL) { error_propagate(errp, err); diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c index f99b6c19e0..db2c17aafd 100644 --- a/hw/char/serial-pci.c +++ b/hw/char/serial-pci.c @@ -49,7 +49,6 @@ static void serial_pci_realize(PCIDevice *dev, Error **errp) SerialState *s = &pci->state; Error *err = NULL; - s->baudbase = 115200; serial_realize_core(s, &err); if (err != NULL) { error_propagate(errp, err); diff --git a/hw/char/serial.c b/hw/char/serial.c index 1746dbc1c4..a4f0566865 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -988,7 +988,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase, SerialState *s = SERIAL(dev); s->irq = irq; - s->baudbase = baudbase; + qdev_prop_set_uint32(dev, "baudbase", baudbase); qdev_prop_set_chr(dev, "chardev", chr); serial_realize_core(s, &error_fatal); qdev_set_legacy_instance_id(dev, base, 2); @@ -1002,6 +1002,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase, static Property serial_properties[] = { DEFINE_PROP_CHR("chardev", SerialState, chr), + DEFINE_PROP_UINT32("baudbase", SerialState, baudbase, 115200), DEFINE_PROP_END_OF_LIST(), }; @@ -1072,7 +1073,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space, s->it_shift = it_shift; s->irq = irq; - s->baudbase = baudbase; + qdev_prop_set_uint32(dev, "baudbase", baudbase); qdev_prop_set_chr(dev, "chardev", chr); serial_realize_core(s, &error_fatal); diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 180cc7c24e..3dc618598e 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -58,7 +58,7 @@ typedef struct SerialState { CharBackend chr; int last_break_enable; int it_shift; - int baudbase; + uint32_t baudbase; uint32_t tsr_retry; guint watch_tag; uint32_t wakeup; -- cgit v1.2.3-55-g7522 From c9808d602813bce4fada7bf9ecc463aa779b73f7 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Tue, 22 Oct 2019 01:02:50 +0200 Subject: serial: realize the serial device Instead of calling serial_realize_core(), use the QDev realize callback. Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé --- hw/char/serial-isa.c | 2 +- hw/char/serial-pci-multi.c | 2 +- hw/char/serial-pci.c | 2 +- hw/char/serial.c | 8 ++++---- include/hw/char/serial.h | 1 - 5 files changed, 7 insertions(+), 8 deletions(-) (limited to 'include/hw') diff --git a/hw/char/serial-isa.c b/hw/char/serial-isa.c index 2a4c8de1bf..db8644551e 100644 --- a/hw/char/serial-isa.c +++ b/hw/char/serial-isa.c @@ -74,7 +74,7 @@ static void serial_isa_realizefn(DeviceState *dev, Error **errp) index++; isa_init_irq(isadev, &s->irq, isa->isairq); - serial_realize_core(s, errp); + object_property_set_bool(OBJECT(s), true, "realized", errp); qdev_set_legacy_instance_id(dev, isa->iobase, 3); memory_region_init_io(&s->io, OBJECT(isa), &serial_io_ops, s, "serial", 8); diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c index 4891f32230..0e1fdb75d2 100644 --- a/hw/char/serial-pci-multi.c +++ b/hw/char/serial-pci-multi.c @@ -106,7 +106,7 @@ static void multi_serial_pci_realize(PCIDevice *dev, Error **errp) for (i = 0; i < nports; i++) { s = pci->state + i; - serial_realize_core(s, &err); + object_property_set_bool(OBJECT(s), true, "realized", &err); if (err != NULL) { error_propagate(errp, err); multi_serial_pci_exit(dev); diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c index db2c17aafd..4b6a217365 100644 --- a/hw/char/serial-pci.c +++ b/hw/char/serial-pci.c @@ -49,7 +49,7 @@ static void serial_pci_realize(PCIDevice *dev, Error **errp) SerialState *s = &pci->state; Error *err = NULL; - serial_realize_core(s, &err); + object_property_set_bool(OBJECT(s), true, "realized", &err); if (err != NULL) { error_propagate(errp, err); return; diff --git a/hw/char/serial.c b/hw/char/serial.c index a4f0566865..8328cc62c3 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -934,8 +934,10 @@ static int serial_be_change(void *opaque) return 0; } -void serial_realize_core(SerialState *s, Error **errp) +static void serial_realize(DeviceState *dev, Error **errp) { + SerialState *s = SERIAL(dev); + s->modem_status_poll = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) serial_update_msl, s); s->fifo_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) fifo_timeout_int, s); @@ -990,7 +992,6 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase, s->irq = irq; qdev_prop_set_uint32(dev, "baudbase", baudbase); qdev_prop_set_chr(dev, "chardev", chr); - serial_realize_core(s, &error_fatal); qdev_set_legacy_instance_id(dev, base, 2); qdev_init_nofail(dev); @@ -1012,6 +1013,7 @@ static void serial_class_init(ObjectClass *klass, void* data) /* internal device for serialio/serialmm, not user-creatable */ dc->user_creatable = false; + dc->realize = serial_realize; dc->vmsd = &vmstate_serial; dc->props = serial_properties; } @@ -1075,8 +1077,6 @@ SerialState *serial_mm_init(MemoryRegion *address_space, s->irq = irq; qdev_prop_set_uint32(dev, "baudbase", baudbase); qdev_prop_set_chr(dev, "chardev", chr); - - serial_realize_core(s, &error_fatal); qdev_set_legacy_instance_id(dev, base, 2); qdev_init_nofail(dev); diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 3dc618598e..571aab97c8 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -83,7 +83,6 @@ typedef struct SerialState { extern const VMStateDescription vmstate_serial; extern const MemoryRegionOps serial_io_ops; -void serial_realize_core(SerialState *s, Error **errp); void serial_exit_core(SerialState *s); void serial_set_frequency(SerialState *s, uint32_t frequency); -- cgit v1.2.3-55-g7522 From b9975000a008c5b0801e3d24ed113a1bd2767ed5 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Tue, 22 Oct 2019 01:14:43 +0200 Subject: serial: replace serial_exit_core() with unrealize Instead of calling serial_exit_core() directly, use the QDev unrealize callback. Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/char/serial-pci-multi.c | 2 +- hw/char/serial-pci.c | 2 +- hw/char/serial.c | 5 ++++- include/hw/char/serial.h | 1 - 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'include/hw') diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c index 0e1fdb75d2..e343a1235c 100644 --- a/hw/char/serial-pci-multi.c +++ b/hw/char/serial-pci-multi.c @@ -56,7 +56,7 @@ static void multi_serial_pci_exit(PCIDevice *dev) for (i = 0; i < pci->ports; i++) { s = pci->state + i; - serial_exit_core(s); + object_property_set_bool(OBJECT(s), false, "realized", NULL); memory_region_del_subregion(&pci->iobar, &s->io); g_free(pci->name[i]); } diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c index 4b6a217365..b6a73c65a9 100644 --- a/hw/char/serial-pci.c +++ b/hw/char/serial-pci.c @@ -68,7 +68,7 @@ static void serial_pci_exit(PCIDevice *dev) PCISerialState *pci = DO_UPCAST(PCISerialState, dev, dev); SerialState *s = &pci->state; - serial_exit_core(s); + object_property_set_bool(OBJECT(s), false, "realized", NULL); qemu_free_irq(s->irq); } diff --git a/hw/char/serial.c b/hw/char/serial.c index 8328cc62c3..ec388f3876 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -950,8 +950,10 @@ static void serial_realize(DeviceState *dev, Error **errp) serial_reset(s); } -void serial_exit_core(SerialState *s) +static void serial_unrealize(DeviceState *dev, Error **errp) { + SerialState *s = SERIAL(dev); + qemu_chr_fe_deinit(&s->chr, false); timer_del(s->modem_status_poll); @@ -1014,6 +1016,7 @@ static void serial_class_init(ObjectClass *klass, void* data) /* internal device for serialio/serialmm, not user-creatable */ dc->user_creatable = false; dc->realize = serial_realize; + dc->unrealize = serial_unrealize; dc->vmsd = &vmstate_serial; dc->props = serial_properties; } diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 571aab97c8..548944b06a 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -83,7 +83,6 @@ typedef struct SerialState { extern const VMStateDescription vmstate_serial; extern const MemoryRegionOps serial_io_ops; -void serial_exit_core(SerialState *s); void serial_set_frequency(SerialState *s, uint32_t frequency); #define TYPE_SERIAL "serial" -- cgit v1.2.3-55-g7522 From 490a9d9b36bfa22a6b46b27e6e9e84e1bac44c68 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Wed, 23 Oct 2019 17:50:06 +0200 Subject: serial: start making SerialMM a sysbus device Memory mapped serial device is in fact a sysbus device. The following patches will make use of sysbus facilities for resource and registration. In particular, "serial-mm: use sysbus facilities" will move internal serial realization to serial_mm_realize callback to follow qdev best practices. Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell --- hw/char/omap_uart.c | 2 +- hw/char/serial.c | 72 ++++++++++++++++++++++++++++++++++++------------ hw/mips/boston.c | 2 +- hw/mips/mips_malta.c | 2 +- include/hw/char/serial.h | 20 ++++++++++---- 5 files changed, 73 insertions(+), 25 deletions(-) (limited to 'include/hw') diff --git a/hw/char/omap_uart.c b/hw/char/omap_uart.c index 13e4f43c4c..e8da933378 100644 --- a/hw/char/omap_uart.c +++ b/hw/char/omap_uart.c @@ -27,7 +27,7 @@ struct omap_uart_s { MemoryRegion iomem; hwaddr base; - SerialState *serial; /* TODO */ + SerialMM *serial; /* TODO */ struct omap_target_agent_s *ta; omap_clk fclk; qemu_irq irq; diff --git a/hw/char/serial.c b/hw/char/serial.c index ec388f3876..824390817c 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -1032,16 +1032,28 @@ static const TypeInfo serial_info = { static uint64_t serial_mm_read(void *opaque, hwaddr addr, unsigned size) { - SerialState *s = opaque; - return serial_ioport_read(s, addr >> s->it_shift, 1); + SerialMM *s = SERIAL_MM(opaque); + return serial_ioport_read(&s->serial, addr >> s->it_shift, 1); } static void serial_mm_write(void *opaque, hwaddr addr, uint64_t value, unsigned size) { - SerialState *s = opaque; + SerialMM *s = SERIAL_MM(opaque); value &= 255; - serial_ioport_write(s, addr >> s->it_shift, value, 1); + serial_ioport_write(&s->serial, addr >> s->it_shift, 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] = { @@ -1068,30 +1080,56 @@ static const MemoryRegionOps serial_mm_ops[3] = { }, }; -SerialState *serial_mm_init(MemoryRegion *address_space, - hwaddr base, int it_shift, - qemu_irq irq, int baudbase, - Chardev *chr, enum device_endian end) +SerialMM *serial_mm_init(MemoryRegion *address_space, + hwaddr base, int it_shift, + qemu_irq irq, int baudbase, + Chardev *chr, enum device_endian end) { - DeviceState *dev = DEVICE(object_new(TYPE_SERIAL)); - SerialState *s = SERIAL(dev); + SerialMM *smm = SERIAL_MM(qdev_create(NULL, TYPE_SERIAL_MM)); + SerialState *s = &smm->serial; - s->it_shift = it_shift; + smm->it_shift = it_shift; s->irq = irq; - qdev_prop_set_uint32(dev, "baudbase", baudbase); - qdev_prop_set_chr(dev, "chardev", chr); - qdev_set_legacy_instance_id(dev, base, 2); - qdev_init_nofail(dev); + 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); - memory_region_init_io(&s->io, NULL, &serial_mm_ops[end], s, + qdev_init_nofail(DEVICE(smm)); + + memory_region_init_io(&s->io, NULL, &serial_mm_ops[end], smm, "serial", 8 << it_shift); memory_region_add_subregion(address_space, base, &s->io); - return s; + + return smm; +} + +static void serial_mm_instance_init(Object *o) +{ + SerialMM *smm = SERIAL_MM(o); + + object_initialize_child(o, "serial", &smm->serial, sizeof(smm->serial), + TYPE_SERIAL, &error_abort, NULL); } +static void serial_mm_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + dc->realize = serial_mm_realize; +} + +static const TypeInfo serial_mm_info = { + .name = TYPE_SERIAL_MM, + .parent = TYPE_SYS_BUS_DEVICE, + .class_init = serial_mm_class_init, + .instance_init = serial_mm_instance_init, + .instance_size = sizeof(SerialMM), +}; + static void serial_register_types(void) { type_register_static(&serial_info); + type_register_static(&serial_mm_info); } type_init(serial_register_types) diff --git a/hw/mips/boston.c b/hw/mips/boston.c index ca7d813a52..23fdd5ec6a 100644 --- a/hw/mips/boston.c +++ b/hw/mips/boston.c @@ -50,7 +50,7 @@ typedef struct { MachineState *mach; MIPSCPSState cps; - SerialState *uart; + SerialMM *uart; CharBackend lcd_display; char lcd_content[8]; diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index 783cd99848..ea92e5e27d 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -83,7 +83,7 @@ typedef struct { uint32_t i2csel; CharBackend display; char display_text[9]; - SerialState *uart; + SerialMM *uart; bool display_inited; } MaltaFPGAState; diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 548944b06a..730165347c 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -57,7 +57,6 @@ typedef struct SerialState { qemu_irq irq; CharBackend chr; int last_break_enable; - int it_shift; uint32_t baudbase; uint32_t tsr_retry; guint watch_tag; @@ -80,6 +79,14 @@ typedef struct SerialState { MemoryRegion io; } SerialState; +typedef struct SerialMM { + SysBusDevice parent; + + SerialState serial; + + int it_shift; +} SerialMM; + extern const VMStateDescription vmstate_serial; extern const MemoryRegionOps serial_io_ops; @@ -88,12 +95,15 @@ void serial_set_frequency(SerialState *s, uint32_t frequency); #define TYPE_SERIAL "serial" #define SERIAL(s) OBJECT_CHECK(SerialState, (s), TYPE_SERIAL) +#define TYPE_SERIAL_MM "serial-mm" +#define SERIAL_MM(s) OBJECT_CHECK(SerialMM, (s), TYPE_SERIAL_MM) + SerialState *serial_init(int base, qemu_irq irq, int baudbase, Chardev *chr, MemoryRegion *system_io); -SerialState *serial_mm_init(MemoryRegion *address_space, - hwaddr base, int it_shift, - qemu_irq irq, int baudbase, - Chardev *chr, enum device_endian end); +SerialMM *serial_mm_init(MemoryRegion *address_space, + hwaddr base, int it_shift, + qemu_irq irq, int baudbase, + Chardev *chr, enum device_endian end); /* serial-isa.c */ -- cgit v1.2.3-55-g7522 From 17fd1a6490b1d66cdfa60c67060e63da71a43a51 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Mon, 21 Oct 2019 20:14:02 +0200 Subject: serial-mm: add "regshift" property And a property and rename "it_shift" field to "regshift", as it seems to be more popular (and I don't know what "it" stands for). Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell --- hw/char/serial.c | 22 +++++++++++++++++----- include/hw/char/serial.h | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'include/hw') diff --git a/hw/char/serial.c b/hw/char/serial.c index 824390817c..f11f2cdbf3 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -1033,7 +1033,7 @@ static uint64_t serial_mm_read(void *opaque, hwaddr addr, unsigned size) { SerialMM *s = SERIAL_MM(opaque); - return serial_ioport_read(&s->serial, addr >> s->it_shift, 1); + return serial_ioport_read(&s->serial, addr >> s->regshift, 1); } static void serial_mm_write(void *opaque, hwaddr addr, @@ -1041,7 +1041,7 @@ static void serial_mm_write(void *opaque, hwaddr addr, { SerialMM *s = SERIAL_MM(opaque); value &= 255; - serial_ioport_write(&s->serial, addr >> s->it_shift, value, 1); + serial_ioport_write(&s->serial, addr >> s->regshift, value, 1); } static void serial_mm_realize(DeviceState *dev, Error **errp) @@ -1081,14 +1081,14 @@ static const MemoryRegionOps serial_mm_ops[3] = { }; SerialMM *serial_mm_init(MemoryRegion *address_space, - hwaddr base, int it_shift, + 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; - smm->it_shift = it_shift; + 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); @@ -1097,7 +1097,7 @@ SerialMM *serial_mm_init(MemoryRegion *address_space, qdev_init_nofail(DEVICE(smm)); memory_region_init_io(&s->io, NULL, &serial_mm_ops[end], smm, - "serial", 8 << it_shift); + "serial", 8 << regshift); memory_region_add_subregion(address_space, base, &s->io); return smm; @@ -1111,10 +1111,21 @@ static void serial_mm_instance_init(Object *o) TYPE_SERIAL, &error_abort, NULL); } +static Property serial_mm_properties[] = { + /* + * Set the spacing between adjacent memory-mapped UART registers. + * Each register will be at (1 << regshift) bytes after the + * previous one. + */ + DEFINE_PROP_UINT8("regshift", SerialMM, regshift, 0), + DEFINE_PROP_END_OF_LIST(), +}; + static void serial_mm_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); + dc->props = serial_mm_properties; dc->realize = serial_mm_realize; } @@ -1124,6 +1135,7 @@ static const TypeInfo serial_mm_info = { .class_init = serial_mm_class_init, .instance_init = serial_mm_instance_init, .instance_size = sizeof(SerialMM), + .class_init = serial_mm_class_init, }; static void serial_register_types(void) diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 730165347c..eaeda62698 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -84,7 +84,7 @@ typedef struct SerialMM { SerialState serial; - int it_shift; + uint8_t regshift; } SerialMM; extern const VMStateDescription vmstate_serial; @@ -101,7 +101,7 @@ void serial_set_frequency(SerialState *s, uint32_t frequency); SerialState *serial_init(int base, qemu_irq irq, int baudbase, Chardev *chr, MemoryRegion *system_io); SerialMM *serial_mm_init(MemoryRegion *address_space, - hwaddr base, int it_shift, + hwaddr base, int regshift, qemu_irq irq, int baudbase, Chardev *chr, enum device_endian end); -- cgit v1.2.3-55-g7522 From 80b2eed95dd6397541cc4d7ec36db0e182a8f402 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Wed, 23 Oct 2019 18:07:03 +0200 Subject: serial-mm: add endianness property Add a qdev property for endianness, so memory region setup can be done in realize. Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/char/serial.c | 2 ++ include/hw/char/serial.h | 1 + 2 files changed, 3 insertions(+) (limited to 'include/hw') diff --git a/hw/char/serial.c b/hw/char/serial.c index f11f2cdbf3..1d350a851b 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -1093,6 +1093,7 @@ SerialMM *serial_mm_init(MemoryRegion *address_space, 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_init_nofail(DEVICE(smm)); @@ -1118,6 +1119,7 @@ static Property serial_mm_properties[] = { * previous one. */ DEFINE_PROP_UINT8("regshift", SerialMM, regshift, 0), + DEFINE_PROP_UINT8("endianness", SerialMM, endianness, DEVICE_NATIVE_ENDIAN), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index eaeda62698..d586924937 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -85,6 +85,7 @@ typedef struct SerialMM { SerialState serial; uint8_t regshift; + uint8_t endianness; } SerialMM; extern const VMStateDescription vmstate_serial; -- cgit v1.2.3-55-g7522 From 10315a70896fb82000cc4b2a1198b70c775c7a59 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Wed, 23 Oct 2019 18:37:33 +0200 Subject: serial: make SerialIO a sysbus device Make serial IO a proper sysbus device, similar to serial MM. Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé --- hw/char/serial.c | 64 +++++++++++++++++++++++++++++++++++++++--------- include/hw/char/serial.h | 13 ++++++++-- 2 files changed, 64 insertions(+), 13 deletions(-) (limited to 'include/hw') diff --git a/hw/char/serial.c b/hw/char/serial.c index b3927c7198..3bcb7a6268 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -985,22 +985,63 @@ const MemoryRegionOps serial_io_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -SerialState *serial_init(int base, qemu_irq irq, int baudbase, - Chardev *chr, MemoryRegion *system_io) +static void serial_io_realize(DeviceState *dev, Error **errp) { - DeviceState *dev = DEVICE(object_new(TYPE_SERIAL)); - SerialState *s = SERIAL(dev); + SerialIO *sio = SERIAL_IO(dev); + SerialState *s = &sio->serial; + Error *local_err = NULL; - s->irq = irq; - qdev_prop_set_uint32(dev, "baudbase", baudbase); - qdev_prop_set_chr(dev, "chardev", chr); - qdev_set_legacy_instance_id(dev, base, 2); - qdev_init_nofail(dev); + 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_io_ops, s, "serial", 8); - memory_region_add_subregion(system_io, base, &s->io); + sysbus_init_irq(SYS_BUS_DEVICE(sio), &s->irq); +} + +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 s; + return sio; } static Property serial_properties[] = { @@ -1149,6 +1190,7 @@ static const TypeInfo serial_mm_info = { static void serial_register_types(void) { type_register_static(&serial_info); + type_register_static(&serial_io_info); type_register_static(&serial_mm_info); } diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index d586924937..d356ba838c 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -88,6 +88,12 @@ typedef struct SerialMM { uint8_t endianness; } SerialMM; +typedef struct SerialIO { + SysBusDevice parent; + + SerialState serial; +} SerialIO; + extern const VMStateDescription vmstate_serial; extern const MemoryRegionOps serial_io_ops; @@ -99,8 +105,11 @@ void serial_set_frequency(SerialState *s, uint32_t frequency); #define TYPE_SERIAL_MM "serial-mm" #define SERIAL_MM(s) OBJECT_CHECK(SerialMM, (s), TYPE_SERIAL_MM) -SerialState *serial_init(int base, qemu_irq irq, int baudbase, - Chardev *chr, MemoryRegion *system_io); +#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); SerialMM *serial_mm_init(MemoryRegion *address_space, hwaddr base, int regshift, qemu_irq irq, int baudbase, -- cgit v1.2.3-55-g7522 From 9fac5d88ee1a81dca643a62bfce5a2364b437bfa Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Wed, 23 Oct 2019 15:29:55 +0200 Subject: mips: inline serial_init() The function is specific to mipssim, let's inline it. (when inlining, we use a DeviceState variable instead of SerialIO, as it is the most common type used, and avoids having too many casts) Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Aleksandar Markovic --- hw/char/serial.c | 16 ---------------- hw/mips/mips_mipssim.c | 15 ++++++++++++--- include/hw/char/serial.h | 2 -- 3 files changed, 12 insertions(+), 21 deletions(-) (limited to 'include/hw') diff --git a/hw/char/serial.c b/hw/char/serial.c index 3bcb7a6268..7746dfcee8 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -1028,22 +1028,6 @@ static const TypeInfo serial_io_info = { .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[] = { DEFINE_PROP_CHR("chardev", SerialState, chr), DEFINE_PROP_UINT32("baudbase", SerialState, baudbase, 115200), diff --git a/hw/mips/mips_mipssim.c b/hw/mips/mips_mipssim.c index 282bbecb24..5ee26108f5 100644 --- a/hw/mips/mips_mipssim.c +++ b/hw/mips/mips_mipssim.c @@ -40,6 +40,7 @@ #include "hw/loader.h" #include "elf.h" #include "hw/sysbus.h" +#include "hw/qdev-properties.h" #include "exec/address-spaces.h" #include "qemu/error-report.h" #include "sysemu/qtest.h" @@ -219,9 +220,17 @@ mips_mipssim_init(MachineState *machine) * A single 16450 sits at offset 0x3f8. It is attached to * MIPS CPU INT2, which is interrupt 4. */ - if (serial_hd(0)) - serial_init(0x3f8, env->irq[4], 115200, serial_hd(0), - get_system_io()); + if (serial_hd(0)) { + DeviceState *dev = qdev_create(NULL, TYPE_SERIAL_IO); + + qdev_prop_set_uint32(dev, "baudbase", 115200); + qdev_prop_set_chr(dev, "chardev", serial_hd(0)); + qdev_set_legacy_instance_id(dev, 0x3f8, 2); + qdev_init_nofail(dev); + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, env->irq[4]); + memory_region_add_subregion(get_system_io(), 0x3f8, + &SERIAL_IO(dev)->serial.io); + } if (nd_table[0].used) /* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */ diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index d356ba838c..535fa23a2b 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -108,8 +108,6 @@ void serial_set_frequency(SerialState *s, uint32_t frequency); #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); SerialMM *serial_mm_init(MemoryRegion *address_space, hwaddr base, int regshift, qemu_irq irq, int baudbase, -- cgit v1.2.3-55-g7522 From 0fe4bb3241110fc9fbd1c5c457d58191fcdca5d3 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Thu, 17 Oct 2019 17:06:05 +0200 Subject: vmmouse: replace PROP_PTR with PROP_LINK While at it, use the expected type. Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/i386/pc.c | 6 +++--- hw/i386/vmmouse.c | 8 +++----- hw/input/pckbd.c | 8 +++----- include/hw/input/i8042.h | 4 +++- 4 files changed, 12 insertions(+), 14 deletions(-) (limited to 'include/hw') diff --git a/hw/i386/pc.c b/hw/i386/pc.c index a4fda69b49..8054bc4147 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1156,9 +1156,9 @@ static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl, bool no_vmport) vmmouse = NULL; } if (vmmouse) { - DeviceState *dev = DEVICE(vmmouse); - qdev_prop_set_ptr(dev, "ps2_mouse", i8042); - qdev_init_nofail(dev); + object_property_set_link(OBJECT(vmmouse), OBJECT(i8042), + "i8042", &error_abort); + qdev_init_nofail(DEVICE(vmmouse)); } port92 = isa_create_simple(isa_bus, TYPE_PORT92); diff --git a/hw/i386/vmmouse.c b/hw/i386/vmmouse.c index 41ad91ad53..c0c329f817 100644 --- a/hw/i386/vmmouse.c +++ b/hw/i386/vmmouse.c @@ -66,7 +66,7 @@ typedef struct VMMouseState uint16_t status; uint8_t absolute; QEMUPutMouseEntry *entry; - void *ps2_mouse; + ISAKBDState *i8042; } VMMouseState; static uint32_t vmmouse_get_status(VMMouseState *s) @@ -105,7 +105,7 @@ static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int buttons_ /* need to still generate PS2 events to notify driver to read from queue */ - i8042_isa_mouse_fake_event(s->ps2_mouse); + i8042_isa_mouse_fake_event(s->i8042); } static void vmmouse_remove_handler(VMMouseState *s) @@ -275,7 +275,7 @@ static void vmmouse_realizefn(DeviceState *dev, Error **errp) } static Property vmmouse_properties[] = { - DEFINE_PROP_PTR("ps2_mouse", VMMouseState, ps2_mouse), + DEFINE_PROP_LINK("i8042", VMMouseState, i8042, TYPE_I8042, ISAKBDState *), DEFINE_PROP_END_OF_LIST(), }; @@ -287,8 +287,6 @@ static void vmmouse_class_initfn(ObjectClass *klass, void *data) dc->reset = vmmouse_reset; dc->vmsd = &vmstate_vmmouse; dc->props = vmmouse_properties; - /* Reason: pointer property "ps2_mouse" */ - dc->user_creatable = false; } static const TypeInfo vmmouse_info = { diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index 2f09f780ba..60a4130320 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -482,17 +482,15 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq, #define I8042(obj) OBJECT_CHECK(ISAKBDState, (obj), TYPE_I8042) -typedef struct ISAKBDState { +struct ISAKBDState { ISADevice parent_obj; KBDState kbd; MemoryRegion io[2]; -} ISAKBDState; +}; -void i8042_isa_mouse_fake_event(void *opaque) +void i8042_isa_mouse_fake_event(ISAKBDState *isa) { - ISADevice *dev = opaque; - ISAKBDState *isa = I8042(dev); KBDState *s = &isa->kbd; ps2_mouse_fake_event(s->mouse); diff --git a/include/hw/input/i8042.h b/include/hw/input/i8042.h index 246e6f3335..8eaebf50ce 100644 --- a/include/hw/input/i8042.h +++ b/include/hw/input/i8042.h @@ -14,10 +14,12 @@ #define I8042_A20_LINE "a20" +typedef struct ISAKBDState ISAKBDState; + void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq, MemoryRegion *region, ram_addr_t size, hwaddr mask); -void i8042_isa_mouse_fake_event(void *opaque); +void i8042_isa_mouse_fake_event(ISAKBDState *isa); void i8042_setup_a20_line(ISADevice *dev, qemu_irq a20_out); #endif /* HW_INPUT_I8042_H */ -- cgit v1.2.3-55-g7522 From 3af6eb8f9b489c72a1f540e752d8d5f1503b9a87 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Thu, 17 Oct 2019 17:49:22 +0200 Subject: etraxfs: remove PROP_PTR usage etraxfs_dma_client are not Object, so can't be exposed to user with QOM path. Let's remove property usage and move the constructor to the .c unit, simplifying some code on the way. Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell --- hw/net/etraxfs_eth.c | 44 +++++++++++++++++++++++++++++++++----------- include/hw/cris/etraxfs.h | 20 +++----------------- 2 files changed, 36 insertions(+), 28 deletions(-) (limited to 'include/hw') diff --git a/hw/net/etraxfs_eth.c b/hw/net/etraxfs_eth.c index 4cfbf1135a..f30d963487 100644 --- a/hw/net/etraxfs_eth.c +++ b/hw/net/etraxfs_eth.c @@ -338,14 +338,8 @@ typedef struct ETRAXFSEthState uint8_t macaddr[2][6]; uint32_t regs[FS_ETH_MAX_REGS]; - union { - void *vdma_out; - struct etraxfs_dma_client *dma_out; - }; - union { - void *vdma_in; - struct etraxfs_dma_client *dma_in; - }; + struct etraxfs_dma_client *dma_out; + struct etraxfs_dma_client *dma_in; /* MDIO bus. */ struct qemu_mdio mdio_bus; @@ -635,8 +629,6 @@ static void etraxfs_eth_realize(DeviceState *dev, Error **errp) static Property etraxfs_eth_properties[] = { DEFINE_PROP_UINT32("phyaddr", ETRAXFSEthState, phyaddr, 1), - DEFINE_PROP_PTR("dma_out", ETRAXFSEthState, vdma_out), - DEFINE_PROP_PTR("dma_in", ETRAXFSEthState, vdma_in), DEFINE_NIC_PROPERTIES(ETRAXFSEthState, conf), DEFINE_PROP_END_OF_LIST(), }; @@ -648,10 +640,40 @@ static void etraxfs_eth_class_init(ObjectClass *klass, void *data) dc->realize = etraxfs_eth_realize; dc->reset = etraxfs_eth_reset; dc->props = etraxfs_eth_properties; - /* Reason: pointer properties "dma_out", "dma_in" */ + /* Reason: dma_out, dma_in are not user settable */ dc->user_creatable = false; } + +/* Instantiate an ETRAXFS Ethernet MAC. */ +DeviceState * +etraxfs_eth_init(NICInfo *nd, hwaddr base, int phyaddr, + struct etraxfs_dma_client *dma_out, + struct etraxfs_dma_client *dma_in) +{ + DeviceState *dev; + qemu_check_nic_model(nd, "fseth"); + + dev = qdev_create(NULL, "etraxfs-eth"); + qdev_set_nic_properties(dev, nd); + qdev_prop_set_uint32(dev, "phyaddr", phyaddr); + + /* + * TODO: QOM design, define a QOM interface for "I am an etraxfs + * DMA client" (which replaces the current 'struct + * etraxfs_dma_client' ad-hoc interface), implement it on the + * ethernet device, and then have QOM link properties on the DMA + * controller device so that you can pass the interface + * implementations to it. + */ + ETRAX_FS_ETH(dev)->dma_out = dma_out; + ETRAX_FS_ETH(dev)->dma_in = dma_in; + qdev_init_nofail(dev); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + + return dev; +} + static const TypeInfo etraxfs_eth_info = { .name = TYPE_ETRAX_FS_ETH, .parent = TYPE_SYS_BUS_DEVICE, diff --git a/include/hw/cris/etraxfs.h b/include/hw/cris/etraxfs.h index aa146a2cd8..403e7f95e6 100644 --- a/include/hw/cris/etraxfs.h +++ b/include/hw/cris/etraxfs.h @@ -30,23 +30,9 @@ #include "hw/qdev-properties.h" #include "hw/sysbus.h" -/* Instantiate an ETRAXFS Ethernet MAC. */ -static inline DeviceState * -etraxfs_eth_init(NICInfo *nd, hwaddr base, int phyaddr, - void *dma_out, void *dma_in) -{ - DeviceState *dev; - qemu_check_nic_model(nd, "fseth"); - - dev = qdev_create(NULL, "etraxfs-eth"); - qdev_set_nic_properties(dev, nd); - qdev_prop_set_uint32(dev, "phyaddr", phyaddr); - qdev_prop_set_ptr(dev, "dma_out", dma_out); - qdev_prop_set_ptr(dev, "dma_in", dma_in); - qdev_init_nofail(dev); - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); - return dev; -} +DeviceState *etraxfs_eth_init(NICInfo *nd, hwaddr base, int phyaddr, + struct etraxfs_dma_client *dma_out, + struct etraxfs_dma_client *dma_in); static inline DeviceState *etraxfs_ser_create(hwaddr addr, qemu_irq irq, -- cgit v1.2.3-55-g7522 From bab592a259a6603922a4f54caedb6e52da692e35 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 18 Oct 2019 14:42:57 +0200 Subject: omap-intc: remove PROP_PTR Since clocks are not QOM objects, replace PROP_PTR of clocks with setters methods. (in theory there should probably be different methods for omap1 & omap2 intc, but this is left as a future improvement) Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/arm/omap1.c | 4 ++-- hw/arm/omap2.c | 4 ++-- hw/intc/omap_intc.c | 17 ++++++++++------- include/hw/arm/omap.h | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 11 deletions(-) (limited to 'include/hw') diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c index 6ce038a453..1afd1d3d7f 100644 --- a/hw/arm/omap1.c +++ b/hw/arm/omap1.c @@ -3889,7 +3889,7 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *dram, s->ih[0] = qdev_create(NULL, "omap-intc"); qdev_prop_set_uint32(s->ih[0], "size", 0x100); - qdev_prop_set_ptr(s->ih[0], "clk", omap_findclk(s, "arminth_ck")); + omap_intc_set_iclk(OMAP_INTC(s->ih[0]), omap_findclk(s, "arminth_ck")); qdev_init_nofail(s->ih[0]); busdev = SYS_BUS_DEVICE(s->ih[0]); sysbus_connect_irq(busdev, 0, @@ -3899,7 +3899,7 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *dram, sysbus_mmio_map(busdev, 0, 0xfffecb00); s->ih[1] = qdev_create(NULL, "omap-intc"); qdev_prop_set_uint32(s->ih[1], "size", 0x800); - qdev_prop_set_ptr(s->ih[1], "clk", omap_findclk(s, "arminth_ck")); + omap_intc_set_iclk(OMAP_INTC(s->ih[1]), omap_findclk(s, "arminth_ck")); qdev_init_nofail(s->ih[1]); busdev = SYS_BUS_DEVICE(s->ih[1]); sysbus_connect_irq(busdev, 0, diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c index 457f152bac..1d7cc435ef 100644 --- a/hw/arm/omap2.c +++ b/hw/arm/omap2.c @@ -2308,8 +2308,8 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sdram, /* Actually mapped at any 2K boundary in the ARM11 private-peripheral if */ s->ih[0] = qdev_create(NULL, "omap2-intc"); qdev_prop_set_uint8(s->ih[0], "revision", 0x21); - qdev_prop_set_ptr(s->ih[0], "fclk", omap_findclk(s, "mpu_intc_fclk")); - qdev_prop_set_ptr(s->ih[0], "iclk", omap_findclk(s, "mpu_intc_iclk")); + omap_intc_set_fclk(OMAP_INTC(s->ih[0]), omap_findclk(s, "mpu_intc_fclk")); + omap_intc_set_iclk(OMAP_INTC(s->ih[0]), omap_findclk(s, "mpu_intc_iclk")); qdev_init_nofail(s->ih[0]); busdev = SYS_BUS_DEVICE(s->ih[0]); sysbus_connect_irq(busdev, 0, diff --git a/hw/intc/omap_intc.c b/hw/intc/omap_intc.c index 854b709ca0..73bb1c2af4 100644 --- a/hw/intc/omap_intc.c +++ b/hw/intc/omap_intc.c @@ -38,10 +38,6 @@ struct omap_intr_handler_bank_s { unsigned char priority[32]; }; -#define TYPE_OMAP_INTC "common-omap-intc" -#define OMAP_INTC(obj) \ - OBJECT_CHECK(struct omap_intr_handler_s, (obj), TYPE_OMAP_INTC) - struct omap_intr_handler_s { SysBusDevice parent_obj; @@ -391,9 +387,18 @@ static void omap_intc_realize(DeviceState *dev, Error **errp) } } +void omap_intc_set_iclk(omap_intr_handler *intc, omap_clk clk) +{ + intc->iclk = clk; +} + +void omap_intc_set_fclk(omap_intr_handler *intc, omap_clk clk) +{ + intc->fclk = clk; +} + static Property omap_intc_properties[] = { DEFINE_PROP_UINT32("size", struct omap_intr_handler_s, size, 0x100), - DEFINE_PROP_PTR("clk", struct omap_intr_handler_s, iclk), DEFINE_PROP_END_OF_LIST(), }; @@ -647,8 +652,6 @@ static void omap2_intc_realize(DeviceState *dev, Error **errp) static Property omap2_intc_properties[] = { DEFINE_PROP_UINT8("revision", struct omap_intr_handler_s, revision, 0x21), - DEFINE_PROP_PTR("iclk", struct omap_intr_handler_s, iclk), - DEFINE_PROP_PTR("fclk", struct omap_intr_handler_s, fclk), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h index f3aa670036..bcecf19f89 100644 --- a/include/hw/arm/omap.h +++ b/include/hw/arm/omap.h @@ -67,6 +67,20 @@ void omap_clk_setrate(omap_clk clk, int divide, int multiply); int64_t omap_clk_getrate(omap_clk clk); void omap_clk_reparent(omap_clk clk, omap_clk parent); +/* omap_intc.c */ +#define TYPE_OMAP_INTC "common-omap-intc" +#define OMAP_INTC(obj) \ + OBJECT_CHECK(omap_intr_handler, (obj), TYPE_OMAP_INTC) + +typedef struct omap_intr_handler_s omap_intr_handler; + +/* + * TODO: Ideally we should have a clock framework that + * let us wire these clocks up with QOM properties or links. + */ +void omap_intc_set_iclk(omap_intr_handler *intc, omap_clk clk); +void omap_intc_set_fclk(omap_intr_handler *intc, omap_clk clk); + /* OMAP2 l4 Interconnect */ struct omap_l4_s; struct omap_l4_region_s { -- cgit v1.2.3-55-g7522 From 0fd20c532faa6d5ebed8a43763f96a4829b33be2 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 18 Oct 2019 14:56:44 +0200 Subject: omap-i2c: remove PROP_PTR Since clocks are not QOM objects, replace PROP_PTR of clocks with setters methods. Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell Reviewed-by: Corey Minyard Reviewed-by: Philippe Mathieu-Daudé --- hw/arm/omap1.c | 2 +- hw/arm/omap2.c | 8 ++++---- hw/i2c/omap_i2c.c | 19 ++++++++++++------- include/hw/arm/omap.h | 13 +++++++++++++ 4 files changed, 30 insertions(+), 12 deletions(-) (limited to 'include/hw') diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c index 1afd1d3d7f..807e5f70d1 100644 --- a/hw/arm/omap1.c +++ b/hw/arm/omap1.c @@ -4030,7 +4030,7 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *dram, s->i2c[0] = qdev_create(NULL, "omap_i2c"); qdev_prop_set_uint8(s->i2c[0], "revision", 0x11); - qdev_prop_set_ptr(s->i2c[0], "fclk", omap_findclk(s, "mpuper_ck")); + omap_i2c_set_fclk(OMAP_I2C(s->i2c[0]), omap_findclk(s, "mpuper_ck")); qdev_init_nofail(s->i2c[0]); busdev = SYS_BUS_DEVICE(s->i2c[0]); sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(s->ih[1], OMAP_INT_I2C)); diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c index 1d7cc435ef..171e2d0472 100644 --- a/hw/arm/omap2.c +++ b/hw/arm/omap2.c @@ -2425,8 +2425,8 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sdram, s->i2c[0] = qdev_create(NULL, "omap_i2c"); qdev_prop_set_uint8(s->i2c[0], "revision", 0x34); - qdev_prop_set_ptr(s->i2c[0], "iclk", omap_findclk(s, "i2c1.iclk")); - qdev_prop_set_ptr(s->i2c[0], "fclk", omap_findclk(s, "i2c1.fclk")); + omap_i2c_set_iclk(OMAP_I2C(s->i2c[0]), omap_findclk(s, "i2c1.iclk")); + omap_i2c_set_fclk(OMAP_I2C(s->i2c[0]), omap_findclk(s, "i2c1.fclk")); qdev_init_nofail(s->i2c[0]); busdev = SYS_BUS_DEVICE(s->i2c[0]); sysbus_connect_irq(busdev, 0, @@ -2437,8 +2437,8 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sdram, s->i2c[1] = qdev_create(NULL, "omap_i2c"); qdev_prop_set_uint8(s->i2c[1], "revision", 0x34); - qdev_prop_set_ptr(s->i2c[1], "iclk", omap_findclk(s, "i2c2.iclk")); - qdev_prop_set_ptr(s->i2c[1], "fclk", omap_findclk(s, "i2c2.fclk")); + omap_i2c_set_iclk(OMAP_I2C(s->i2c[1]), omap_findclk(s, "i2c2.iclk")); + omap_i2c_set_fclk(OMAP_I2C(s->i2c[1]), omap_findclk(s, "i2c2.fclk")); qdev_init_nofail(s->i2c[1]); busdev = SYS_BUS_DEVICE(s->i2c[1]); sysbus_connect_irq(busdev, 0, diff --git a/hw/i2c/omap_i2c.c b/hw/i2c/omap_i2c.c index 3ba965a58f..3ccbd5cc2c 100644 --- a/hw/i2c/omap_i2c.c +++ b/hw/i2c/omap_i2c.c @@ -28,10 +28,7 @@ #include "qemu/error-report.h" #include "qapi/error.h" -#define TYPE_OMAP_I2C "omap_i2c" -#define OMAP_I2C(obj) OBJECT_CHECK(OMAPI2CState, (obj), TYPE_OMAP_I2C) - -typedef struct OMAPI2CState { +struct OMAPI2CState { SysBusDevice parent_obj; MemoryRegion iomem; @@ -56,7 +53,7 @@ typedef struct OMAPI2CState { uint8_t divider; uint8_t times[2]; uint16_t test; -} OMAPI2CState; +}; #define OMAP2_INTR_REV 0x34 #define OMAP2_GC_REV 0x34 @@ -504,10 +501,18 @@ static void omap_i2c_realize(DeviceState *dev, Error **errp) } } +void omap_i2c_set_iclk(OMAPI2CState *i2c, omap_clk clk) +{ + i2c->iclk = clk; +} + +void omap_i2c_set_fclk(OMAPI2CState *i2c, omap_clk clk) +{ + i2c->fclk = clk; +} + static Property omap_i2c_properties[] = { DEFINE_PROP_UINT8("revision", OMAPI2CState, revision, 0), - DEFINE_PROP_PTR("iclk", OMAPI2CState, iclk), - DEFINE_PROP_PTR("fclk", OMAPI2CState, fclk), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h index bcecf19f89..39a295ba20 100644 --- a/include/hw/arm/omap.h +++ b/include/hw/arm/omap.h @@ -81,6 +81,19 @@ typedef struct omap_intr_handler_s omap_intr_handler; void omap_intc_set_iclk(omap_intr_handler *intc, omap_clk clk); void omap_intc_set_fclk(omap_intr_handler *intc, omap_clk clk); +/* omap_i2c.c */ +#define TYPE_OMAP_I2C "omap_i2c" +#define OMAP_I2C(obj) OBJECT_CHECK(OMAPI2CState, (obj), TYPE_OMAP_I2C) + +typedef struct OMAPI2CState OMAPI2CState; + +/* + * TODO: Ideally we should have a clock framework that + * let us wire these clocks up with QOM properties or links. + */ +void omap_i2c_set_iclk(OMAPI2CState *i2c, omap_clk clk); +void omap_i2c_set_fclk(OMAPI2CState *i2c, omap_clk clk); + /* OMAP2 l4 Interconnect */ struct omap_l4_s; struct omap_l4_region_s { -- cgit v1.2.3-55-g7522 From ba2aba8370e33a44ff5619844b90bb7119c5cebf Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 18 Oct 2019 15:26:19 +0200 Subject: omap-gpio: remove PROP_PTR Since clocks are not QOM objects, replace PROP_PTR of clocks with setters methods. Move/adapt the existing TODO comment about a clock framework. Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/arm/omap1.c | 2 +- hw/arm/omap2.c | 13 +++++++------ hw/gpio/omap_gpio.c | 42 +++++++++++++++--------------------------- include/hw/arm/omap.h | 33 +++++++++++++++++++++++++++++---- 4 files changed, 52 insertions(+), 38 deletions(-) (limited to 'include/hw') diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c index 807e5f70d1..761cc17ea9 100644 --- a/hw/arm/omap1.c +++ b/hw/arm/omap1.c @@ -4012,7 +4012,7 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *dram, s->gpio = qdev_create(NULL, "omap-gpio"); qdev_prop_set_int32(s->gpio, "mpu_model", s->mpu_model); - qdev_prop_set_ptr(s->gpio, "clk", omap_findclk(s, "arm_gpio_ck")); + omap_gpio_set_clk(OMAP1_GPIO(s->gpio), omap_findclk(s, "arm_gpio_ck")); qdev_init_nofail(s->gpio); sysbus_connect_irq(SYS_BUS_DEVICE(s->gpio), 0, qdev_get_gpio_in(s->ih[0], OMAP_INT_GPIO_BANK1)); diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c index 171e2d0472..e1c11de5ce 100644 --- a/hw/arm/omap2.c +++ b/hw/arm/omap2.c @@ -2449,13 +2449,14 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sdram, s->gpio = qdev_create(NULL, "omap2-gpio"); qdev_prop_set_int32(s->gpio, "mpu_model", s->mpu_model); - qdev_prop_set_ptr(s->gpio, "iclk", omap_findclk(s, "gpio_iclk")); - qdev_prop_set_ptr(s->gpio, "fclk0", omap_findclk(s, "gpio1_dbclk")); - qdev_prop_set_ptr(s->gpio, "fclk1", omap_findclk(s, "gpio2_dbclk")); - qdev_prop_set_ptr(s->gpio, "fclk2", omap_findclk(s, "gpio3_dbclk")); - qdev_prop_set_ptr(s->gpio, "fclk3", omap_findclk(s, "gpio4_dbclk")); + omap2_gpio_set_iclk(OMAP2_GPIO(s->gpio), omap_findclk(s, "gpio_iclk")); + omap2_gpio_set_fclk(OMAP2_GPIO(s->gpio), 0, omap_findclk(s, "gpio1_dbclk")); + omap2_gpio_set_fclk(OMAP2_GPIO(s->gpio), 1, omap_findclk(s, "gpio2_dbclk")); + omap2_gpio_set_fclk(OMAP2_GPIO(s->gpio), 2, omap_findclk(s, "gpio3_dbclk")); + omap2_gpio_set_fclk(OMAP2_GPIO(s->gpio), 3, omap_findclk(s, "gpio4_dbclk")); if (s->mpu_model == omap2430) { - qdev_prop_set_ptr(s->gpio, "fclk4", omap_findclk(s, "gpio5_dbclk")); + omap2_gpio_set_fclk(OMAP2_GPIO(s->gpio), 4, + omap_findclk(s, "gpio5_dbclk")); } qdev_init_nofail(s->gpio); busdev = SYS_BUS_DEVICE(s->gpio); diff --git a/hw/gpio/omap_gpio.c b/hw/gpio/omap_gpio.c index 41e1aa798c..85c16897ae 100644 --- a/hw/gpio/omap_gpio.c +++ b/hw/gpio/omap_gpio.c @@ -40,10 +40,6 @@ struct omap_gpio_s { uint16_t pins; }; -#define TYPE_OMAP1_GPIO "omap-gpio" -#define OMAP1_GPIO(obj) \ - OBJECT_CHECK(struct omap_gpif_s, (obj), TYPE_OMAP1_GPIO) - struct omap_gpif_s { SysBusDevice parent_obj; @@ -212,10 +208,6 @@ struct omap2_gpio_s { uint8_t delay; }; -#define TYPE_OMAP2_GPIO "omap2-gpio" -#define OMAP2_GPIO(obj) \ - OBJECT_CHECK(struct omap2_gpif_s, (obj), TYPE_OMAP2_GPIO) - struct omap2_gpif_s { SysBusDevice parent_obj; @@ -747,21 +739,13 @@ static void omap2_gpio_realize(DeviceState *dev, Error **errp) } } -/* Using qdev pointer properties for the clocks is not ideal. - * qdev should support a generic means of defining a 'port' with - * an arbitrary interface for connecting two devices. Then we - * could reframe the omap clock API in terms of clock ports, - * and get some type safety. For now the best qdev provides is - * passing an arbitrary pointer. - * (It's not possible to pass in the string which is the clock - * name, because this device does not have the necessary information - * (ie the struct omap_mpu_state_s*) to do the clockname to pointer - * translation.) - */ +void omap_gpio_set_clk(omap_gpif *gpio, omap_clk clk) +{ + gpio->clk = clk; +} static Property omap_gpio_properties[] = { DEFINE_PROP_INT32("mpu_model", struct omap_gpif_s, mpu_model, 0), - DEFINE_PROP_PTR("clk", struct omap_gpif_s, clk), DEFINE_PROP_END_OF_LIST(), }; @@ -784,15 +768,19 @@ static const TypeInfo omap_gpio_info = { .class_init = omap_gpio_class_init, }; +void omap2_gpio_set_iclk(omap2_gpif *gpio, omap_clk clk) +{ + gpio->iclk = clk; +} + +void omap2_gpio_set_fclk(omap2_gpif *gpio, uint8_t i, omap_clk clk) +{ + assert(i <= 5); + gpio->fclk[i] = clk; +} + static Property omap2_gpio_properties[] = { DEFINE_PROP_INT32("mpu_model", struct omap2_gpif_s, mpu_model, 0), - DEFINE_PROP_PTR("iclk", struct omap2_gpif_s, iclk), - DEFINE_PROP_PTR("fclk0", struct omap2_gpif_s, fclk[0]), - DEFINE_PROP_PTR("fclk1", struct omap2_gpif_s, fclk[1]), - DEFINE_PROP_PTR("fclk2", struct omap2_gpif_s, fclk[2]), - DEFINE_PROP_PTR("fclk3", struct omap2_gpif_s, fclk[3]), - DEFINE_PROP_PTR("fclk4", struct omap2_gpif_s, fclk[4]), - DEFINE_PROP_PTR("fclk5", struct omap2_gpif_s, fclk[5]), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h index 39a295ba20..6be386d0e2 100644 --- a/include/hw/arm/omap.h +++ b/include/hw/arm/omap.h @@ -77,6 +77,16 @@ typedef struct omap_intr_handler_s omap_intr_handler; /* * TODO: Ideally we should have a clock framework that * let us wire these clocks up with QOM properties or links. + * + * qdev should support a generic means of defining a 'port' with + * an arbitrary interface for connecting two devices. Then we + * could reframe the omap clock API in terms of clock ports, + * and get some type safety. For now the best qdev provides is + * passing an arbitrary pointer. + * (It's not possible to pass in the string which is the clock + * name, because this device does not have the necessary information + * (ie the struct omap_mpu_state_s*) to do the clockname to pointer + * translation.) */ void omap_intc_set_iclk(omap_intr_handler *intc, omap_clk clk); void omap_intc_set_fclk(omap_intr_handler *intc, omap_clk clk); @@ -87,13 +97,28 @@ void omap_intc_set_fclk(omap_intr_handler *intc, omap_clk clk); typedef struct OMAPI2CState OMAPI2CState; -/* - * TODO: Ideally we should have a clock framework that - * let us wire these clocks up with QOM properties or links. - */ +/* TODO: clock framework (see above) */ void omap_i2c_set_iclk(OMAPI2CState *i2c, omap_clk clk); void omap_i2c_set_fclk(OMAPI2CState *i2c, omap_clk clk); +/* omap_gpio.c */ +#define TYPE_OMAP1_GPIO "omap-gpio" +#define OMAP1_GPIO(obj) \ + OBJECT_CHECK(struct omap_gpif_s, (obj), TYPE_OMAP1_GPIO) + +#define TYPE_OMAP2_GPIO "omap2-gpio" +#define OMAP2_GPIO(obj) \ + OBJECT_CHECK(struct omap2_gpif_s, (obj), TYPE_OMAP2_GPIO) + +typedef struct omap_gpif_s omap_gpif; +typedef struct omap2_gpif_s omap2_gpif; + +/* TODO: clock framework (see above) */ +void omap_gpio_set_clk(omap_gpif *gpio, omap_clk clk); + +void omap2_gpio_set_iclk(omap2_gpif *gpio, omap_clk clk); +void omap2_gpio_set_fclk(omap2_gpif *gpio, uint8_t i, omap_clk clk); + /* OMAP2 l4 Interconnect */ struct omap_l4_s; struct omap_l4_region_s { -- cgit v1.2.3-55-g7522 From 5c4d910f2d5bbf28c44e0f4dad1857c2cd9f77f4 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 18 Oct 2019 15:52:40 +0200 Subject: qdev: remove PROP_MEMORY_REGION PROP_MEMORY_REGION was a derivative of PROP_PTR, added in commit ed03d749f3f513b8fb0287757cfda2cb6825f063 (qdev: add MemoryRegion property) and thankfully no longer needed since commit 3eff40dbf44896a8180c86c84dbdefb2eb173fbe (hw/misc: Remove mmio_interface device). Signed-off-by: Marc-André Lureau Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- include/hw/qdev-properties.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include/hw') diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index c6a8cb5516..16837ab5dd 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -216,8 +216,6 @@ extern const PropertyInfo qdev_prop_pcie_link_width; DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t) #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress) -#define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *) #define DEFINE_PROP_OFF_AUTO_PCIBAR(_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_off_auto_pcibar, \ OffAutoPCIBAR) -- cgit v1.2.3-55-g7522 From 70f3d674bc2daac865fb75878030c063697fd16a Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 18 Oct 2019 15:50:10 +0200 Subject: qdev: remove QDEV_PROP_PTR No longer used in the tree. The comment about user_creatable is still quite relevant, but there is already a similar comment in qdev-core.h. Reviewed-by: Peter Maydell Signed-off-by: Marc-André Lureau --- hw/core/qdev-properties.c | 18 ------------------ include/hw/qdev-properties.h | 22 ---------------------- 2 files changed, 40 deletions(-) (limited to 'include/hw') diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index ac28890e5a..6ca7697599 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -501,13 +501,6 @@ const PropertyInfo qdev_prop_string = { .set = set_string, }; -/* --- pointer --- */ - -/* Not a proper property, just for dirty hacks. TODO Remove it! */ -const PropertyInfo qdev_prop_ptr = { - .name = "ptr", -}; - /* --- mac address --- */ /* @@ -1165,17 +1158,6 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value) name, &error_abort); } -void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) -{ - Property *prop; - void **ptr; - - prop = qdev_prop_find(dev, name); - assert(prop && prop->info == &qdev_prop_ptr); - ptr = qdev_get_prop_ptr(dev, prop); - *ptr = value; -} - static GPtrArray *global_props(void) { static GPtrArray *gp; diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 16837ab5dd..a90a9cec80 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -18,7 +18,6 @@ extern const PropertyInfo qdev_prop_size; extern const PropertyInfo qdev_prop_string; extern const PropertyInfo qdev_prop_chr; extern const PropertyInfo qdev_prop_tpm; -extern const PropertyInfo qdev_prop_ptr; extern const PropertyInfo qdev_prop_macaddr; extern const PropertyInfo qdev_prop_on_off_auto; extern const PropertyInfo qdev_prop_losttickpolicy; @@ -171,25 +170,6 @@ extern const PropertyInfo qdev_prop_pcie_link_width; #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t) -/* - * Please avoid pointer properties. If you must use them, you must - * cover them in their device's class init function as follows: - * - * - If the property must be set, the device cannot be used with - * device_add, so add code like this: - * |* Reason: pointer property "NAME-OF-YOUR-PROP" *| - * DeviceClass *dc = DEVICE_CLASS(class); - * dc->user_creatable = false; - * - * - If the property may safely remain null, document it like this: - * |* - * * Note: pointer property "interrupt_vector" may remain null, thus - * * no need for dc->user_creatable = false; - * *| - */ -#define DEFINE_PROP_PTR(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*) - #define DEFINE_PROP_CHR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharBackend) #define DEFINE_PROP_STRING(_n, _s, _f) \ @@ -262,8 +242,6 @@ void qdev_prop_set_drive(DeviceState *dev, const char *name, void qdev_prop_set_macaddr(DeviceState *dev, const char *name, const uint8_t *value); void qdev_prop_set_enum(DeviceState *dev, const char *name, int value); -/* FIXME: Remove opaque pointer properties. */ -void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); void qdev_prop_register_global(GlobalProperty *prop); int qdev_prop_check_globals(void); -- cgit v1.2.3-55-g7522