qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups
@ 2024-02-13 15:52 Philippe Mathieu-Daudé
  2024-02-13 15:52 ` [PATCH v2 1/4] hw/arm/stellaris: Convert ADC controller to Resettable interface Philippe Mathieu-Daudé
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-13 15:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Gustavo Romero, qemu-arm,
	Philippe Mathieu-Daudé

Since v1:
- Rebased
- Split I2C reset as enter/hold/exit (Peter)
- Added R-b tags

Gustavo wants to access the QOM path of an input IRQ line
from the NVIC, but since the device is orphan he ends up
with this nasty path [*]:

  -device ivshmem-flat,chardev=ivshmem_flat,x-irq-qompath='/machine/unattached/device[1]/nvic/unnamed-gpio-in[0]',x-bus-qompath='/sysbus'

Add the missing parent so the tree is now:

(qemu) info qom-tree
/machine (lm3s6965evb-machine)
  /gamepad (stellaris-gamepad)
  /oled (ssd0323)
  /peripheral (container)
  /peripheral-anon (container)
  /soc (container)
    /v7m (armv7m)
      /cpu (cortex-m3-arm-cpu)
        /unnamed-gpio-in[0] (irq)
        /unnamed-gpio-in[1] (irq)
        /unnamed-gpio-in[2] (irq)
        /unnamed-gpio-in[3] (irq)
      /cpuclk (clock)
      /nvic (armv7m_nvic)
        /NMI[0] (irq)
        /nvic_sysregs[0] (memory-region)
        /systick-trigger[0] (irq)
        /systick-trigger[1] (irq)
        /unnamed-gpio-in[0] (irq)
        ...

[*] https://lore.kernel.org/qemu-devel/20231127052024.435743-1-gustavo.romero@linaro.org/

Philippe Mathieu-Daudé (4):
  hw/arm/stellaris: Convert ADC controller to Resettable interface
  hw/arm/stellaris: Convert I2C controller to Resettable interface
  hw/arm/stellaris: Add missing QOM 'machine' parent
  hw/arm/stellaris: Add missing QOM 'SoC' parent

 hw/arm/stellaris.c | 47 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 7 deletions(-)

-- 
2.41.0



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

* [PATCH v2 1/4] hw/arm/stellaris: Convert ADC controller to Resettable interface
  2024-02-13 15:52 [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups Philippe Mathieu-Daudé
@ 2024-02-13 15:52 ` Philippe Mathieu-Daudé
  2024-02-13 15:52 ` [PATCH v2 2/4] hw/arm/stellaris: Convert I2C " Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-13 15:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Gustavo Romero, qemu-arm,
	Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/arm/stellaris.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index 34c5a86ac2..4fa857970b 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -773,8 +773,9 @@ static void stellaris_adc_trigger(void *opaque, int irq, int level)
     }
 }
 
-static void stellaris_adc_reset(StellarisADCState *s)
+static void stellaris_adc_reset_hold(Object *obj)
 {
+    StellarisADCState *s = STELLARIS_ADC(obj);
     int n;
 
     for (n = 0; n < 4; n++) {
@@ -946,7 +947,6 @@ static void stellaris_adc_init(Object *obj)
     memory_region_init_io(&s->iomem, obj, &stellaris_adc_ops, s,
                           "adc", 0x1000);
     sysbus_init_mmio(sbd, &s->iomem);
-    stellaris_adc_reset(s);
     qdev_init_gpio_in(dev, stellaris_adc_trigger, 1);
 }
 
@@ -1411,7 +1411,9 @@ static const TypeInfo stellaris_i2c_info = {
 static void stellaris_adc_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
+    rc->phases.hold = stellaris_adc_reset_hold;
     dc->vmsd = &vmstate_stellaris_adc;
 }
 
-- 
2.41.0



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

* [PATCH v2 2/4] hw/arm/stellaris: Convert I2C controller to Resettable interface
  2024-02-13 15:52 [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups Philippe Mathieu-Daudé
  2024-02-13 15:52 ` [PATCH v2 1/4] hw/arm/stellaris: Convert ADC controller to Resettable interface Philippe Mathieu-Daudé
@ 2024-02-13 15:52 ` Philippe Mathieu-Daudé
  2024-02-13 15:52 ` [PATCH v2 3/4] hw/arm/stellaris: Add missing QOM 'machine' parent Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-13 15:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Gustavo Romero, qemu-arm,
	Philippe Mathieu-Daudé

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/arm/stellaris.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index 4fa857970b..d3a12fe51c 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -462,7 +462,10 @@ static void stellaris_sys_instance_init(Object *obj)
     s->sysclk = qdev_init_clock_out(DEVICE(s), "SYSCLK");
 }
 
-/* I2C controller.  */
+/*
+ * I2C controller.
+ * ??? For now we only implement the master interface.
+ */
 
 #define TYPE_STELLARIS_I2C "stellaris-i2c"
 OBJECT_DECLARE_SIMPLE_TYPE(stellaris_i2c_state, STELLARIS_I2C)
@@ -607,10 +610,17 @@ static void stellaris_i2c_write(void *opaque, hwaddr offset,
     stellaris_i2c_update(s);
 }
 
-static void stellaris_i2c_reset(stellaris_i2c_state *s)
+static void stellaris_i2c_reset_enter(Object *obj, ResetType type)
 {
+    stellaris_i2c_state *s = STELLARIS_I2C(obj);
+
     if (s->mcs & STELLARIS_I2C_MCS_BUSBSY)
         i2c_end_transfer(s->bus);
+}
+
+static void stellaris_i2c_reset_hold(Object *obj)
+{
+    stellaris_i2c_state *s = STELLARIS_I2C(obj);
 
     s->msa = 0;
     s->mcs = 0;
@@ -619,6 +629,12 @@ static void stellaris_i2c_reset(stellaris_i2c_state *s)
     s->mimr = 0;
     s->mris = 0;
     s->mcr = 0;
+}
+
+static void stellaris_i2c_reset_exit(Object *obj)
+{
+    stellaris_i2c_state *s = STELLARIS_I2C(obj);
+
     stellaris_i2c_update(s);
 }
 
@@ -658,8 +674,6 @@ static void stellaris_i2c_init(Object *obj)
     memory_region_init_io(&s->iomem, obj, &stellaris_i2c_ops, s,
                           "i2c", 0x1000);
     sysbus_init_mmio(sbd, &s->iomem);
-    /* ??? For now we only implement the master interface.  */
-    stellaris_i2c_reset(s);
 }
 
 /* Analogue to Digital Converter.  This is only partially implemented,
@@ -1396,7 +1410,11 @@ type_init(stellaris_machine_init)
 static void stellaris_i2c_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
+    rc->phases.enter = stellaris_i2c_reset_enter;
+    rc->phases.hold = stellaris_i2c_reset_hold;
+    rc->phases.exit = stellaris_i2c_reset_exit;
     dc->vmsd = &vmstate_stellaris_i2c;
 }
 
-- 
2.41.0



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

* [PATCH v2 3/4] hw/arm/stellaris: Add missing QOM 'machine' parent
  2024-02-13 15:52 [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups Philippe Mathieu-Daudé
  2024-02-13 15:52 ` [PATCH v2 1/4] hw/arm/stellaris: Convert ADC controller to Resettable interface Philippe Mathieu-Daudé
  2024-02-13 15:52 ` [PATCH v2 2/4] hw/arm/stellaris: Convert I2C " Philippe Mathieu-Daudé
@ 2024-02-13 15:52 ` Philippe Mathieu-Daudé
  2024-02-13 15:52 ` [PATCH v2 4/4] hw/arm/stellaris: Add missing QOM 'SoC' parent Philippe Mathieu-Daudé
  2024-02-15 13:50 ` [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-13 15:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Gustavo Romero, qemu-arm,
	Philippe Mathieu-Daudé

QDev objects created with qdev_new() need to manually add
their parent relationship with object_property_add_child().

This commit plug the devices which aren't part of the SoC;
they will be plugged into a SoC container in the next one.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/arm/stellaris.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index d3a12fe51c..d9884286b3 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -1271,10 +1271,13 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
                                    &error_fatal);
 
             ssddev = qdev_new("ssd0323");
+            object_property_add_child(OBJECT(ms), "oled", OBJECT(ssddev));
             qdev_prop_set_uint8(ssddev, "cs", 1);
             qdev_realize_and_unref(ssddev, bus, &error_fatal);
 
             gpio_d_splitter = qdev_new(TYPE_SPLIT_IRQ);
+            object_property_add_child(OBJECT(ms), "splitter",
+                                      OBJECT(gpio_d_splitter));
             qdev_prop_set_uint32(gpio_d_splitter, "num-lines", 2);
             qdev_realize_and_unref(gpio_d_splitter, NULL, &error_fatal);
             qdev_connect_gpio_out(
@@ -1314,6 +1317,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
         DeviceState *gpad;
 
         gpad = qdev_new(TYPE_STELLARIS_GAMEPAD);
+        object_property_add_child(OBJECT(ms), "gamepad", OBJECT(gpad));
         for (i = 0; i < ARRAY_SIZE(gpad_keycode); i++) {
             qlist_append_int(gpad_keycode_list, gpad_keycode[i]);
         }
-- 
2.41.0



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

* [PATCH v2 4/4] hw/arm/stellaris: Add missing QOM 'SoC' parent
  2024-02-13 15:52 [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2024-02-13 15:52 ` [PATCH v2 3/4] hw/arm/stellaris: Add missing QOM 'machine' parent Philippe Mathieu-Daudé
@ 2024-02-13 15:52 ` Philippe Mathieu-Daudé
  2024-02-15 13:50 ` [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-13 15:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Gustavo Romero, qemu-arm,
	Philippe Mathieu-Daudé

QDev objects created with qdev_new() need to manually add
their parent relationship with object_property_add_child().

Since we don't model the SoC, just use a QOM container.

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

diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index d9884286b3..a2f998bf9e 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -1031,6 +1031,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
      * 400fe000 system control
      */
 
+    Object *soc_container;
     DeviceState *gpio_dev[7], *nvic;
     qemu_irq gpio_in[7][8];
     qemu_irq gpio_out[7][8];
@@ -1052,6 +1053,9 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     flash_size = (((board->dc0 & 0xffff) + 1) << 1) * 1024;
     sram_size = ((board->dc0 >> 18) + 1) * 1024;
 
+    soc_container = object_new("container");
+    object_property_add_child(OBJECT(ms), "soc", soc_container);
+
     /* Flash programming is done via the SCU, so pretend it is ROM.  */
     memory_region_init_rom(flash, NULL, "stellaris.flash", flash_size,
                            &error_fatal);
@@ -1066,6 +1070,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
      * need its sysclk output.
      */
     ssys_dev = qdev_new(TYPE_STELLARIS_SYS);
+    object_property_add_child(soc_container, "sys", OBJECT(ssys_dev));
 
     /*
      * Most devices come preprogrammed with a MAC address in the user data.
@@ -1092,6 +1097,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     sysbus_realize_and_unref(SYS_BUS_DEVICE(ssys_dev), &error_fatal);
 
     nvic = qdev_new(TYPE_ARMV7M);
+    object_property_add_child(soc_container, "v7m", OBJECT(nvic));
     qdev_prop_set_uint32(nvic, "num-irq", NUM_IRQ_LINES);
     qdev_prop_set_uint8(nvic, "num-prio-bits", NUM_PRIO_BITS);
     qdev_prop_set_string(nvic, "cpu-type", ms->cpu_type);
@@ -1125,6 +1131,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
 
             dev = qdev_new(TYPE_STELLARIS_GPTM);
             sbd = SYS_BUS_DEVICE(dev);
+            object_property_add_child(soc_container, "gptm[*]", OBJECT(dev));
             qdev_connect_clock_in(dev, "clk",
                                   qdev_get_clock_out(ssys_dev, "SYSCLK"));
             sysbus_realize_and_unref(sbd, &error_fatal);
@@ -1138,7 +1145,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
 
     if (board->dc1 & (1 << 3)) { /* watchdog present */
         dev = qdev_new(TYPE_LUMINARY_WATCHDOG);
-
+        object_property_add_child(soc_container, "wdg", OBJECT(dev));
         qdev_connect_clock_in(dev, "WDOGCLK",
                               qdev_get_clock_out(ssys_dev, "SYSCLK"));
 
@@ -1178,6 +1185,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
             SysBusDevice *sbd;
 
             dev = qdev_new("pl011_luminary");
+            object_property_add_child(soc_container, "uart[*]", OBJECT(dev));
             sbd = SYS_BUS_DEVICE(dev);
             qdev_prop_set_chr(dev, "chardev", serial_hd(i));
             sysbus_realize_and_unref(sbd, &error_fatal);
@@ -1298,6 +1306,7 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
         DeviceState *enet;
 
         enet = qdev_new("stellaris_enet");
+        object_property_add_child(soc_container, "enet", OBJECT(enet));
         if (nd) {
             qdev_set_nic_properties(enet, nd);
         } else {
-- 
2.41.0



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

* Re: [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups
  2024-02-13 15:52 [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2024-02-13 15:52 ` [PATCH v2 4/4] hw/arm/stellaris: Add missing QOM 'SoC' parent Philippe Mathieu-Daudé
@ 2024-02-15 13:50 ` Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2024-02-15 13:50 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-devel, Gustavo Romero, qemu-arm

On Tue, 13 Feb 2024 at 15:52, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Since v1:
> - Rebased
> - Split I2C reset as enter/hold/exit (Peter)
> - Added R-b tags
>
> Gustavo wants to access the QOM path of an input IRQ line
> from the NVIC, but since the device is orphan he ends up
> with this nasty path [*]:
>
>   -device ivshmem-flat,chardev=ivshmem_flat,x-irq-qompath='/machine/unattached/device[1]/nvic/unnamed-gpio-in[0]',x-bus-qompath='/sysbus'
>
> Add the missing parent so the tree is now:
>
> (qemu) info qom-tree
> /machine (lm3s6965evb-machine)
>   /gamepad (stellaris-gamepad)
>   /oled (ssd0323)
>   /peripheral (container)
>   /peripheral-anon (container)
>   /soc (container)
>     /v7m (armv7m)
>       /cpu (cortex-m3-arm-cpu)
>         /unnamed-gpio-in[0] (irq)
>         /unnamed-gpio-in[1] (irq)
>         /unnamed-gpio-in[2] (irq)
>         /unnamed-gpio-in[3] (irq)
>       /cpuclk (clock)
>       /nvic (armv7m_nvic)
>         /NMI[0] (irq)
>         /nvic_sysregs[0] (memory-region)
>         /systick-trigger[0] (irq)
>         /systick-trigger[1] (irq)
>         /unnamed-gpio-in[0] (irq)
>         ...
>
> [*] https://lore.kernel.org/qemu-devel/20231127052024.435743-1-gustavo.romero@linaro.org/
>
> Philippe Mathieu-Daudé (4):
>   hw/arm/stellaris: Convert ADC controller to Resettable interface
>   hw/arm/stellaris: Convert I2C controller to Resettable interface
>   hw/arm/stellaris: Add missing QOM 'machine' parent
>   hw/arm/stellaris: Add missing QOM 'SoC' parent



Applied to target-arm.next, thanks.

-- PMM


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

end of thread, other threads:[~2024-02-15 13:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-13 15:52 [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups Philippe Mathieu-Daudé
2024-02-13 15:52 ` [PATCH v2 1/4] hw/arm/stellaris: Convert ADC controller to Resettable interface Philippe Mathieu-Daudé
2024-02-13 15:52 ` [PATCH v2 2/4] hw/arm/stellaris: Convert I2C " Philippe Mathieu-Daudé
2024-02-13 15:52 ` [PATCH v2 3/4] hw/arm/stellaris: Add missing QOM 'machine' parent Philippe Mathieu-Daudé
2024-02-13 15:52 ` [PATCH v2 4/4] hw/arm/stellaris: Add missing QOM 'SoC' parent Philippe Mathieu-Daudé
2024-02-15 13:50 ` [PATCH v2 0/4] hw/arm/stellaris: QOM/QDev cleanups Peter Maydell

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).