diff mbox series

[1/2] hw/arm/fsl-imx8mp: Make SoC not user-creatable, derive from TYPE_SYS_BUS_DEVICE

Message ID 20250312212611.51667-2-shentey@gmail.com (mailing list archive)
State New
Headers show
Series i.MX 8M Plus EVK Fixes | expand

Commit Message

Bernhard Beschow March 12, 2025, 9:26 p.m. UTC
Fixes a crash when creating the SoC object on the command line:

  $ ./qemu-system-aarch64  -M virt -device fsl-imx8mp
  **
  ERROR:../../devel/qemu/tcg/tcg.c:1006:tcg_register_thread: assertion failed:
  (n < tcg_max_ctxs)
  Bail out! ERROR:../../devel/qemu/tcg/tcg.c:1006:tcg_register_thread:
  assertion failed: (n < tcg_max_ctxs)
  Aborted (core dumped)

Furthermore, the SoC object should be derived from TYPE_SYS_BUS_DEVICE such that
it gets properly reset.

Fixes: a4eefc69b237 "hw/arm: Add i.MX 8M Plus EVK board"
Reported-by: Thomas Huth <thuth@redhat.com>
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
 include/hw/arm/fsl-imx8mp.h | 3 ++-
 hw/arm/fsl-imx8mp.c         | 4 +++-
 hw/arm/imx8mp-evk.c         | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

Comments

Philippe Mathieu-Daudé March 12, 2025, 11:41 p.m. UTC | #1
On 12/3/25 22:26, Bernhard Beschow wrote:
> Fixes a crash when creating the SoC object on the command line:
> 
>    $ ./qemu-system-aarch64  -M virt -device fsl-imx8mp
>    **
>    ERROR:../../devel/qemu/tcg/tcg.c:1006:tcg_register_thread: assertion failed:
>    (n < tcg_max_ctxs)
>    Bail out! ERROR:../../devel/qemu/tcg/tcg.c:1006:tcg_register_thread:
>    assertion failed: (n < tcg_max_ctxs)
>    Aborted (core dumped)
> 
> Furthermore, the SoC object should be derived from TYPE_SYS_BUS_DEVICE such that
> it gets properly reset.
> 
> Fixes: a4eefc69b237 "hw/arm: Add i.MX 8M Plus EVK board"
> Reported-by: Thomas Huth <thuth@redhat.com>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
> ---
>   include/hw/arm/fsl-imx8mp.h | 3 ++-
>   hw/arm/fsl-imx8mp.c         | 4 +++-
>   hw/arm/imx8mp-evk.c         | 2 +-
>   3 files changed, 6 insertions(+), 3 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
BALATON Zoltan March 12, 2025, 11:58 p.m. UTC | #2
On Wed, 12 Mar 2025, Bernhard Beschow wrote:
> Fixes a crash when creating the SoC object on the command line:
>
>  $ ./qemu-system-aarch64  -M virt -device fsl-imx8mp
>  **
>  ERROR:../../devel/qemu/tcg/tcg.c:1006:tcg_register_thread: assertion failed:
>  (n < tcg_max_ctxs)
>  Bail out! ERROR:../../devel/qemu/tcg/tcg.c:1006:tcg_register_thread:
>  assertion failed: (n < tcg_max_ctxs)
>  Aborted (core dumped)
>
> Furthermore, the SoC object should be derived from TYPE_SYS_BUS_DEVICE such that
> it gets properly reset.
>
> Fixes: a4eefc69b237 "hw/arm: Add i.MX 8M Plus EVK board"
> Reported-by: Thomas Huth <thuth@redhat.com>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
> ---
> include/hw/arm/fsl-imx8mp.h | 3 ++-
> hw/arm/fsl-imx8mp.c         | 4 +++-
> hw/arm/imx8mp-evk.c         | 2 +-
> 3 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h
> index bc97fc416e..22fdc0d67c 100644
> --- a/include/hw/arm/fsl-imx8mp.h
> +++ b/include/hw/arm/fsl-imx8mp.h
> @@ -26,6 +26,7 @@
> #include "hw/timer/imx_gpt.h"
> #include "hw/usb/hcd-dwc3.h"
> #include "hw/watchdog/wdt_imx2.h"
> +#include "hw/sysbus.h"
> #include "qom/object.h"
> #include "qemu/units.h"
>
> @@ -49,7 +50,7 @@ enum FslImx8mpConfiguration {
> };
>
> struct FslImx8mpState {
> -    DeviceState    parent_obj;
> +    SysBusDevice   parent_obj;
>
>     ARMCPU             cpu[FSL_IMX8MP_NUM_CPUS];
>     GICv3State         gic;
> diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c
> index 1ea98e1463..9133d49383 100644
> --- a/hw/arm/fsl-imx8mp.c
> +++ b/hw/arm/fsl-imx8mp.c
> @@ -698,13 +698,15 @@ static void fsl_imx8mp_class_init(ObjectClass *oc, void *data)
>     device_class_set_props(dc, fsl_imx8mp_properties);
>     dc->realize = fsl_imx8mp_realize;
>
> +    /* Reason: SoC can only be instantiated from a board */
> +    dc->user_creatable = false;

I think sysbus devices are not user creatable by default (that's why 
dynamic sysbus device was introduced) so either this or the .parent change 
below is enough. You can have both just in case but maybe not necessary as 
other sysbus devices usually don't set user_createble either.

Regards,
BALATON Zoltan

>     dc->desc = "i.MX 8M Plus SoC";
> }
>
> static const TypeInfo fsl_imx8mp_types[] = {
>     {
>         .name = TYPE_FSL_IMX8MP,
> -        .parent = TYPE_DEVICE,
> +        .parent = TYPE_SYS_BUS_DEVICE,
>         .instance_size = sizeof(FslImx8mpState),
>         .instance_init = fsl_imx8mp_init,
>         .class_init = fsl_imx8mp_class_init,
> diff --git a/hw/arm/imx8mp-evk.c b/hw/arm/imx8mp-evk.c
> index e1a7892fd7..f17d5db466 100644
> --- a/hw/arm/imx8mp-evk.c
> +++ b/hw/arm/imx8mp-evk.c
> @@ -37,7 +37,7 @@ static void imx8mp_evk_init(MachineState *machine)
>     s = FSL_IMX8MP(object_new(TYPE_FSL_IMX8MP));
>     object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
>     object_property_set_uint(OBJECT(s), "fec1-phy-num", 1, &error_fatal);
> -    qdev_realize(DEVICE(s), NULL, &error_fatal);
> +    sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal);
>
>     memory_region_add_subregion(get_system_memory(), FSL_IMX8MP_RAM_START,
>                                 machine->ram);
>
diff mbox series

Patch

diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h
index bc97fc416e..22fdc0d67c 100644
--- a/include/hw/arm/fsl-imx8mp.h
+++ b/include/hw/arm/fsl-imx8mp.h
@@ -26,6 +26,7 @@ 
 #include "hw/timer/imx_gpt.h"
 #include "hw/usb/hcd-dwc3.h"
 #include "hw/watchdog/wdt_imx2.h"
+#include "hw/sysbus.h"
 #include "qom/object.h"
 #include "qemu/units.h"
 
@@ -49,7 +50,7 @@  enum FslImx8mpConfiguration {
 };
 
 struct FslImx8mpState {
-    DeviceState    parent_obj;
+    SysBusDevice   parent_obj;
 
     ARMCPU             cpu[FSL_IMX8MP_NUM_CPUS];
     GICv3State         gic;
diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c
index 1ea98e1463..9133d49383 100644
--- a/hw/arm/fsl-imx8mp.c
+++ b/hw/arm/fsl-imx8mp.c
@@ -698,13 +698,15 @@  static void fsl_imx8mp_class_init(ObjectClass *oc, void *data)
     device_class_set_props(dc, fsl_imx8mp_properties);
     dc->realize = fsl_imx8mp_realize;
 
+    /* Reason: SoC can only be instantiated from a board */
+    dc->user_creatable = false;
     dc->desc = "i.MX 8M Plus SoC";
 }
 
 static const TypeInfo fsl_imx8mp_types[] = {
     {
         .name = TYPE_FSL_IMX8MP,
-        .parent = TYPE_DEVICE,
+        .parent = TYPE_SYS_BUS_DEVICE,
         .instance_size = sizeof(FslImx8mpState),
         .instance_init = fsl_imx8mp_init,
         .class_init = fsl_imx8mp_class_init,
diff --git a/hw/arm/imx8mp-evk.c b/hw/arm/imx8mp-evk.c
index e1a7892fd7..f17d5db466 100644
--- a/hw/arm/imx8mp-evk.c
+++ b/hw/arm/imx8mp-evk.c
@@ -37,7 +37,7 @@  static void imx8mp_evk_init(MachineState *machine)
     s = FSL_IMX8MP(object_new(TYPE_FSL_IMX8MP));
     object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
     object_property_set_uint(OBJECT(s), "fec1-phy-num", 1, &error_fatal);
-    qdev_realize(DEVICE(s), NULL, &error_fatal);
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal);
 
     memory_region_add_subregion(get_system_memory(), FSL_IMX8MP_RAM_START,
                                 machine->ram);