qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes
@ 2023-10-18 13:12 Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 1/8] hw/sd/pxa2xx: Realize sysbus device before accessing it Philippe Mathieu-Daudé
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-18 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, qemu-arm, Philippe Mathieu-Daudé

Hi,

Extracted from a bigger series which enforce QDev state machine
(qdev instance must be realized before external API is used on
it).

While here, pxa2xx i2c/intc devices received some qdev fondness.

Philippe Mathieu-Daudé (8):
  hw/sd/pxa2xx: Realize sysbus device before accessing it
  hw/sd/pxa2xx: Do not open-code sysbus_create_simple()
  hw/pcmcia/pxa2xx: Realize sysbus device before accessing it
  hw/pcmcia/pxa2xx: Do not open-code sysbus_create_simple()
  hw/pcmcia/pxa2xx: Inline pxa2xx_pcmcia_init()
  hw/intc/pxa2xx: Convert to Resettable interface
  hw/intc/pxa2xx: Pass CPU reference using QOM link property
  hw/intc/pxa2xx: Factor pxa2xx_pic_realize() out of pxa2xx_pic_init()

 include/hw/arm/pxa.h |  2 --
 hw/arm/pxa2xx.c      | 12 ++++++++----
 hw/arm/pxa2xx_pic.c  | 38 +++++++++++++++++++++++++++++---------
 hw/pcmcia/pxa2xx.c   | 15 ---------------
 hw/sd/pxa2xx_mmci.c  |  7 +------
 5 files changed, 38 insertions(+), 36 deletions(-)

-- 
2.41.0



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/8] hw/sd/pxa2xx: Realize sysbus device before accessing it
  2023-10-18 13:12 [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
@ 2023-10-18 13:12 ` Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 2/8] hw/sd/pxa2xx: Do not open-code sysbus_create_simple() Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-18 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, qemu-arm, Philippe Mathieu-Daudé

sysbus_mmio_map() and sysbus_connect_irq() should not be
called on unrealized device.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/sd/pxa2xx_mmci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
index 124fbf8bbd..9f7a880bac 100644
--- a/hw/sd/pxa2xx_mmci.c
+++ b/hw/sd/pxa2xx_mmci.c
@@ -483,11 +483,11 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
 
     dev = qdev_new(TYPE_PXA2XX_MMCI);
     sbd = SYS_BUS_DEVICE(dev);
+    sysbus_realize_and_unref(sbd, &error_fatal);
     sysbus_mmio_map(sbd, 0, base);
     sysbus_connect_irq(sbd, 0, irq);
     qdev_connect_gpio_out_named(dev, "rx-dma", 0, rx_dma);
     qdev_connect_gpio_out_named(dev, "tx-dma", 0, tx_dma);
-    sysbus_realize_and_unref(sbd, &error_fatal);
 
     return PXA2XX_MMCI(dev);
 }
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/8] hw/sd/pxa2xx: Do not open-code sysbus_create_simple()
  2023-10-18 13:12 [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 1/8] hw/sd/pxa2xx: Realize sysbus device before accessing it Philippe Mathieu-Daudé
@ 2023-10-18 13:12 ` Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 3/8] hw/pcmcia/pxa2xx: Realize sysbus device before accessing it Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-18 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, qemu-arm, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/sd/pxa2xx_mmci.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
index 9f7a880bac..4749e935d8 100644
--- a/hw/sd/pxa2xx_mmci.c
+++ b/hw/sd/pxa2xx_mmci.c
@@ -479,13 +479,8 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
                 qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma)
 {
     DeviceState *dev;
-    SysBusDevice *sbd;
 
-    dev = qdev_new(TYPE_PXA2XX_MMCI);
-    sbd = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(sbd, &error_fatal);
-    sysbus_mmio_map(sbd, 0, base);
-    sysbus_connect_irq(sbd, 0, irq);
+    dev = sysbus_create_simple(TYPE_PXA2XX_MMCI, base, irq);
     qdev_connect_gpio_out_named(dev, "rx-dma", 0, rx_dma);
     qdev_connect_gpio_out_named(dev, "tx-dma", 0, tx_dma);
 
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/8] hw/pcmcia/pxa2xx: Realize sysbus device before accessing it
  2023-10-18 13:12 [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 1/8] hw/sd/pxa2xx: Realize sysbus device before accessing it Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 2/8] hw/sd/pxa2xx: Do not open-code sysbus_create_simple() Philippe Mathieu-Daudé
@ 2023-10-18 13:12 ` Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 4/8] hw/pcmcia/pxa2xx: Do not open-code sysbus_create_simple() Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-18 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, qemu-arm, Philippe Mathieu-Daudé

sysbus_mmio_map() should not be called on unrealized device.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/pcmcia/pxa2xx.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/hw/pcmcia/pxa2xx.c b/hw/pcmcia/pxa2xx.c
index fcca7e571b..e7264feb45 100644
--- a/hw/pcmcia/pxa2xx.c
+++ b/hw/pcmcia/pxa2xx.c
@@ -142,15 +142,12 @@ PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
                                       hwaddr base)
 {
     DeviceState *dev;
-    PXA2xxPCMCIAState *s;
 
     dev = qdev_new(TYPE_PXA2XX_PCMCIA);
-    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
-    s = PXA2XX_PCMCIA(dev);
-
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
 
-    return s;
+    return PXA2XX_PCMCIA(dev);
 }
 
 static void pxa2xx_pcmcia_initfn(Object *obj)
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/8] hw/pcmcia/pxa2xx: Do not open-code sysbus_create_simple()
  2023-10-18 13:12 [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2023-10-18 13:12 ` [PATCH 3/8] hw/pcmcia/pxa2xx: Realize sysbus device before accessing it Philippe Mathieu-Daudé
@ 2023-10-18 13:12 ` Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 5/8] hw/pcmcia/pxa2xx: Inline pxa2xx_pcmcia_init() Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-18 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, qemu-arm, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/pcmcia/pxa2xx.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/hw/pcmcia/pxa2xx.c b/hw/pcmcia/pxa2xx.c
index e7264feb45..a2ab96d749 100644
--- a/hw/pcmcia/pxa2xx.c
+++ b/hw/pcmcia/pxa2xx.c
@@ -141,13 +141,7 @@ static void pxa2xx_pcmcia_set_irq(void *opaque, int line, int level)
 PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
                                       hwaddr base)
 {
-    DeviceState *dev;
-
-    dev = qdev_new(TYPE_PXA2XX_PCMCIA);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
-    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
-
-    return PXA2XX_PCMCIA(dev);
+    return PXA2XX_PCMCIA(sysbus_create_simple(TYPE_PXA2XX_PCMCIA, base, NULL));
 }
 
 static void pxa2xx_pcmcia_initfn(Object *obj)
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/8] hw/pcmcia/pxa2xx: Inline pxa2xx_pcmcia_init()
  2023-10-18 13:12 [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2023-10-18 13:12 ` [PATCH 4/8] hw/pcmcia/pxa2xx: Do not open-code sysbus_create_simple() Philippe Mathieu-Daudé
@ 2023-10-18 13:12 ` Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 6/8] hw/intc/pxa2xx: Convert to Resettable interface Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-18 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, qemu-arm, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/hw/arm/pxa.h |  2 --
 hw/arm/pxa2xx.c      | 12 ++++++++----
 hw/pcmcia/pxa2xx.c   |  6 ------
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/include/hw/arm/pxa.h b/include/hw/arm/pxa.h
index 54eb895e42..4c6caee113 100644
--- a/include/hw/arm/pxa.h
+++ b/include/hw/arm/pxa.h
@@ -100,8 +100,6 @@ void pxa2xx_mmci_handlers(PXA2xxMMCIState *s, qemu_irq readonly,
 #define TYPE_PXA2XX_PCMCIA "pxa2xx-pcmcia"
 OBJECT_DECLARE_SIMPLE_TYPE(PXA2xxPCMCIAState, PXA2XX_PCMCIA)
 
-PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
-                                      hwaddr base);
 int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card);
 int pxa2xx_pcmcia_detach(void *opaque);
 void pxa2xx_pcmcia_set_irq_cb(void *opaque, qemu_irq irq, qemu_irq cd_irq);
diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c
index 07d5dd8691..601ddd8766 100644
--- a/hw/arm/pxa2xx.c
+++ b/hw/arm/pxa2xx.c
@@ -2205,8 +2205,10 @@ PXA2xxState *pxa270_init(unsigned int sdram_size, const char *cpu_type)
     sysbus_create_simple("sysbus-ohci", 0x4c000000,
                          qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
 
-    s->pcmcia[0] = pxa2xx_pcmcia_init(address_space, 0x20000000);
-    s->pcmcia[1] = pxa2xx_pcmcia_init(address_space, 0x30000000);
+    s->pcmcia[0] = PXA2XX_PCMCIA(sysbus_create_simple(TYPE_PXA2XX_PCMCIA,
+                                                      0x20000000, NULL));
+    s->pcmcia[1] = PXA2XX_PCMCIA(sysbus_create_simple(TYPE_PXA2XX_PCMCIA,
+                                                      0x30000000, NULL));
 
     sysbus_create_simple(TYPE_PXA2XX_RTC, 0x40900000,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_RTCALARM));
@@ -2338,8 +2340,10 @@ PXA2xxState *pxa255_init(unsigned int sdram_size)
         s->ssp[i] = (SSIBus *)qdev_get_child_bus(dev, "ssi");
     }
 
-    s->pcmcia[0] = pxa2xx_pcmcia_init(address_space, 0x20000000);
-    s->pcmcia[1] = pxa2xx_pcmcia_init(address_space, 0x30000000);
+    s->pcmcia[0] = PXA2XX_PCMCIA(sysbus_create_simple(TYPE_PXA2XX_PCMCIA,
+                                                      0x20000000, NULL));
+    s->pcmcia[1] = PXA2XX_PCMCIA(sysbus_create_simple(TYPE_PXA2XX_PCMCIA,
+                                                      0x30000000, NULL));
 
     sysbus_create_simple(TYPE_PXA2XX_RTC, 0x40900000,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_RTCALARM));
diff --git a/hw/pcmcia/pxa2xx.c b/hw/pcmcia/pxa2xx.c
index a2ab96d749..e3111fdf1a 100644
--- a/hw/pcmcia/pxa2xx.c
+++ b/hw/pcmcia/pxa2xx.c
@@ -138,12 +138,6 @@ static void pxa2xx_pcmcia_set_irq(void *opaque, int line, int level)
     qemu_set_irq(s->irq, level);
 }
 
-PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
-                                      hwaddr base)
-{
-    return PXA2XX_PCMCIA(sysbus_create_simple(TYPE_PXA2XX_PCMCIA, base, NULL));
-}
-
 static void pxa2xx_pcmcia_initfn(Object *obj)
 {
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/8] hw/intc/pxa2xx: Convert to Resettable interface
  2023-10-18 13:12 [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2023-10-18 13:12 ` [PATCH 5/8] hw/pcmcia/pxa2xx: Inline pxa2xx_pcmcia_init() Philippe Mathieu-Daudé
@ 2023-10-18 13:12 ` Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 7/8] hw/intc/pxa2xx: Pass CPU reference using QOM link property Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-18 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, qemu-arm, Philippe Mathieu-Daudé

Factor reset code out of the DeviceRealize() handler.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/arm/pxa2xx_pic.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/hw/arm/pxa2xx_pic.c b/hw/arm/pxa2xx_pic.c
index 47132ab982..2eb869a605 100644
--- a/hw/arm/pxa2xx_pic.c
+++ b/hw/arm/pxa2xx_pic.c
@@ -271,12 +271,9 @@ static int pxa2xx_pic_post_load(void *opaque, int version_id)
     return 0;
 }
 
-DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
+static void pxa2xx_pic_reset_hold(Object *obj)
 {
-    DeviceState *dev = qdev_new(TYPE_PXA2XX_PIC);
-    PXA2xxPICState *s = PXA2XX_PIC(dev);
-
-    s->cpu = cpu;
+    PXA2xxPICState *s = PXA2XX_PIC(obj);
 
     s->int_pending[0] = 0;
     s->int_pending[1] = 0;
@@ -284,6 +281,14 @@ DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
     s->int_enabled[1] = 0;
     s->is_fiq[0] = 0;
     s->is_fiq[1] = 0;
+}
+
+DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
+{
+    DeviceState *dev = qdev_new(TYPE_PXA2XX_PIC);
+    PXA2xxPICState *s = PXA2XX_PIC(dev);
+
+    s->cpu = cpu;
 
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
@@ -319,9 +324,11 @@ static const VMStateDescription vmstate_pxa2xx_pic_regs = {
 static void pxa2xx_pic_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->desc = "PXA2xx PIC";
     dc->vmsd = &vmstate_pxa2xx_pic_regs;
+    rc->phases.hold = pxa2xx_pic_reset_hold;
 }
 
 static const TypeInfo pxa2xx_pic_info = {
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/8] hw/intc/pxa2xx: Pass CPU reference using QOM link property
  2023-10-18 13:12 [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2023-10-18 13:12 ` [PATCH 6/8] hw/intc/pxa2xx: Convert to Resettable interface Philippe Mathieu-Daudé
@ 2023-10-18 13:12 ` Philippe Mathieu-Daudé
  2023-10-18 13:12 ` [PATCH 8/8] hw/intc/pxa2xx: Factor pxa2xx_pic_realize() out of pxa2xx_pic_init() Philippe Mathieu-Daudé
  2023-10-18 13:13 ` [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
  8 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-18 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, qemu-arm, Philippe Mathieu-Daudé

QOM objects shouldn't access each other internals fields
except using the QOM API.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/arm/pxa2xx_pic.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/hw/arm/pxa2xx_pic.c b/hw/arm/pxa2xx_pic.c
index 2eb869a605..7e180635c2 100644
--- a/hw/arm/pxa2xx_pic.c
+++ b/hw/arm/pxa2xx_pic.c
@@ -15,6 +15,7 @@
 #include "cpu.h"
 #include "hw/arm/pxa.h"
 #include "hw/sysbus.h"
+#include "hw/qdev-properties.h"
 #include "migration/vmstate.h"
 #include "qom/object.h"
 #include "target/arm/cpregs.h"
@@ -288,7 +289,8 @@ DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
     DeviceState *dev = qdev_new(TYPE_PXA2XX_PIC);
     PXA2xxPICState *s = PXA2XX_PIC(dev);
 
-    s->cpu = cpu;
+    object_property_set_link(OBJECT(dev), "arm-cpu",
+                             OBJECT(cpu), &error_abort);
 
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
@@ -321,11 +323,18 @@ static const VMStateDescription vmstate_pxa2xx_pic_regs = {
     },
 };
 
+static Property pxa2xx_pic_properties[] = {
+    DEFINE_PROP_LINK("arm-cpu", PXA2xxPICState, cpu,
+                     TYPE_ARM_CPU, ARMCPU *),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void pxa2xx_pic_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ResettableClass *rc = RESETTABLE_CLASS(klass);
 
+    device_class_set_props(dc, pxa2xx_pic_properties);
     dc->desc = "PXA2xx PIC";
     dc->vmsd = &vmstate_pxa2xx_pic_regs;
     rc->phases.hold = pxa2xx_pic_reset_hold;
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 8/8] hw/intc/pxa2xx: Factor pxa2xx_pic_realize() out of pxa2xx_pic_init()
  2023-10-18 13:12 [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2023-10-18 13:12 ` [PATCH 7/8] hw/intc/pxa2xx: Pass CPU reference using QOM link property Philippe Mathieu-Daudé
@ 2023-10-18 13:12 ` Philippe Mathieu-Daudé
  2023-10-18 13:13 ` [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
  8 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-18 13:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, qemu-arm, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/arm/pxa2xx_pic.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/hw/arm/pxa2xx_pic.c b/hw/arm/pxa2xx_pic.c
index 7e180635c2..1373a0d275 100644
--- a/hw/arm/pxa2xx_pic.c
+++ b/hw/arm/pxa2xx_pic.c
@@ -287,12 +287,18 @@ static void pxa2xx_pic_reset_hold(Object *obj)
 DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
 {
     DeviceState *dev = qdev_new(TYPE_PXA2XX_PIC);
-    PXA2xxPICState *s = PXA2XX_PIC(dev);
 
     object_property_set_link(OBJECT(dev), "arm-cpu",
                              OBJECT(cpu), &error_abort);
-
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
+
+    return dev;
+}
+
+static void pxa2xx_pic_realize(DeviceState *dev, Error **errp)
+{
+    PXA2xxPICState *s = PXA2XX_PIC(dev);
 
     qdev_init_gpio_in(dev, pxa2xx_pic_set_irq, PXA2XX_PIC_SRCS);
 
@@ -300,12 +306,9 @@ DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
     memory_region_init_io(&s->iomem, OBJECT(s), &pxa2xx_pic_ops, s,
                           "pxa2xx-pic", 0x00100000);
     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
-    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
 
     /* Enable IC coprocessor access.  */
-    define_arm_cp_regs_with_opaque(cpu, pxa_pic_cp_reginfo, s);
-
-    return dev;
+    define_arm_cp_regs_with_opaque(s->cpu, pxa_pic_cp_reginfo, s);
 }
 
 static const VMStateDescription vmstate_pxa2xx_pic_regs = {
@@ -335,6 +338,7 @@ static void pxa2xx_pic_class_init(ObjectClass *klass, void *data)
     ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     device_class_set_props(dc, pxa2xx_pic_properties);
+    dc->realize = pxa2xx_pic_realize;
     dc->desc = "PXA2xx PIC";
     dc->vmsd = &vmstate_pxa2xx_pic_regs;
     rc->phases.hold = pxa2xx_pic_reset_hold;
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes
  2023-10-18 13:12 [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2023-10-18 13:12 ` [PATCH 8/8] hw/intc/pxa2xx: Factor pxa2xx_pic_realize() out of pxa2xx_pic_init() Philippe Mathieu-Daudé
@ 2023-10-18 13:13 ` Philippe Mathieu-Daudé
  8 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-18 13:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, qemu-arm

On 18/10/23 15:12, Philippe Mathieu-Daudé wrote:
> Hi,
> 
> Extracted from a bigger series which enforce QDev state machine
> (qdev instance must be realized before external API is used on
> it).
> 
> While here, pxa2xx i2c/intc devices received some qdev fondness.

Forgot to mention, there is still an issue in pxa2xx_i2c_init()
where an odd 'dummy' i2c bus is created *after* the device is
realized.

> Philippe Mathieu-Daudé (8):
>    hw/sd/pxa2xx: Realize sysbus device before accessing it
>    hw/sd/pxa2xx: Do not open-code sysbus_create_simple()
>    hw/pcmcia/pxa2xx: Realize sysbus device before accessing it
>    hw/pcmcia/pxa2xx: Do not open-code sysbus_create_simple()
>    hw/pcmcia/pxa2xx: Inline pxa2xx_pcmcia_init()
>    hw/intc/pxa2xx: Convert to Resettable interface
>    hw/intc/pxa2xx: Pass CPU reference using QOM link property
>    hw/intc/pxa2xx: Factor pxa2xx_pic_realize() out of pxa2xx_pic_init()



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-10-18 13:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-18 13:12 [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé
2023-10-18 13:12 ` [PATCH 1/8] hw/sd/pxa2xx: Realize sysbus device before accessing it Philippe Mathieu-Daudé
2023-10-18 13:12 ` [PATCH 2/8] hw/sd/pxa2xx: Do not open-code sysbus_create_simple() Philippe Mathieu-Daudé
2023-10-18 13:12 ` [PATCH 3/8] hw/pcmcia/pxa2xx: Realize sysbus device before accessing it Philippe Mathieu-Daudé
2023-10-18 13:12 ` [PATCH 4/8] hw/pcmcia/pxa2xx: Do not open-code sysbus_create_simple() Philippe Mathieu-Daudé
2023-10-18 13:12 ` [PATCH 5/8] hw/pcmcia/pxa2xx: Inline pxa2xx_pcmcia_init() Philippe Mathieu-Daudé
2023-10-18 13:12 ` [PATCH 6/8] hw/intc/pxa2xx: Convert to Resettable interface Philippe Mathieu-Daudé
2023-10-18 13:12 ` [PATCH 7/8] hw/intc/pxa2xx: Pass CPU reference using QOM link property Philippe Mathieu-Daudé
2023-10-18 13:12 ` [PATCH 8/8] hw/intc/pxa2xx: Factor pxa2xx_pic_realize() out of pxa2xx_pic_init() Philippe Mathieu-Daudé
2023-10-18 13:13 ` [PATCH 0/8] hw/arm/pxa2xx: SysBus/QDev fixes Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).