Skip to contentSkip to conversation

hw/riscv/opentitan: Correct QOM type/size of OpenTitanState

PATCH Applied Philippe Mathieu-Daudé 3 participants 17 messages May 20, 2023 – May 25, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

cover hw/riscv/opentitan: Correct QOM type/size of OpenTitanState

Hi,

This series fix a QOM issue with the OpenTitanState structure, noticed while auditing QOM relations globally.

All patches are trivial to review.

Regards,

Phil.

Philippe Mathieu-Daudé (5):
hw/riscv/opentitan: Rename machine_[class]_init() functions hw/riscv/opentitan: Declare QOM types using DEFINE_TYPES() macro hw/riscv/opentitan: Add TYPE_OPENTITAN_MACHINE definition hw/riscv/opentitan: Explicit machine type definition hw/riscv/opentitan: Correct OpenTitanState parent type/size

 include/hw/riscv/opentitan.h |  6 +++++-
 hw/riscv/opentitan.c         | 38 +++++++++++++++++++-----------------
 2 files changed, 25 insertions(+), 19 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/5 hw/riscv/opentitan: Rename machine_[class]_init() functions

Follow QOM style which declares FOO_init() as instance initializer and FOO_class_init() as class initializer:
rename the OpenTitan machine class/instance init() accordingly.

---
 hw/riscv/opentitan.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/riscv/opentitan.c +4 -4
index bc678766e7..2d21ee39c5 100644
@@ -75,7 +75,7 @@ static const MemMapEntry ibex_memmap[] = {
     [IBEX_DEV_FLASH_VIRTUAL] =  {  0x80000000,  0x80000     },
 };
 
-static void opentitan_board_init(MachineState *machine)
+static void opentitan_machine_init(MachineState *machine)
 {
     MachineClass *mc = MACHINE_GET_CLASS(machine);
     const MemMapEntry *memmap = ibex_memmap;
@@ -108,17 +108,17 @@ static void opentitan_board_init(MachineState *machine)
     }
 }
 
-static void opentitan_machine_init(MachineClass *mc)
+static void opentitan_machine_class_init(MachineClass *mc)
 {
     mc->desc = "RISC-V Board compatible with OpenTitan";
-    mc->init = opentitan_board_init;
+    mc->init = opentitan_machine_init;
     mc->max_cpus = 1;
     mc->default_cpu_type = TYPE_RISCV_CPU_IBEX;
     mc->default_ram_id = "riscv.lowrisc.ibex.ram";
     mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM].size;
 }
 
-DEFINE_MACHINE("opentitan", opentitan_machine_init)
+DEFINE_MACHINE("opentitan", opentitan_machine_class_init)
 
 static void lowrisc_ibex_soc_init(Object *obj)
 {
Signature · 1 line
2.38.1
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] hw/riscv/opentitan: Rename machine_[class]_init() functions

Quoted 7 lines · Philippe Mathieu-Daudé

Follow QOM style which declares FOO_init() as instance initializer and FOO_class_init() as class initializer:
rename the OpenTitan machine class/instance init() accordingly.

---

Quoted 37 lines
  hw/riscv/opentitan.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
hw/riscv/opentitan.c +4 -4
index bc678766e7..2d21ee39c5 100644
@@ -75,7 +75,7 @@ static const MemMapEntry ibex_memmap[] = {
      [IBEX_DEV_FLASH_VIRTUAL] =  {  0x80000000,  0x80000     },
  };
 
-static void opentitan_board_init(MachineState *machine)
+static void opentitan_machine_init(MachineState *machine)
  {
      MachineClass *mc = MACHINE_GET_CLASS(machine);
      const MemMapEntry *memmap = ibex_memmap;
@@ -108,17 +108,17 @@ static void opentitan_board_init(MachineState *machine)
      }
  }
 
-static void opentitan_machine_init(MachineClass *mc)
+static void opentitan_machine_class_init(MachineClass *mc)
  {
      mc->desc = "RISC-V Board compatible with OpenTitan";
-    mc->init = opentitan_board_init;
+    mc->init = opentitan_machine_init;
      mc->max_cpus = 1;
      mc->default_cpu_type = TYPE_RISCV_CPU_IBEX;
      mc->default_ram_id = "riscv.lowrisc.ibex.ram";
      mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM].size;
  }
 
-DEFINE_MACHINE("opentitan", opentitan_machine_init)
+DEFINE_MACHINE("opentitan", opentitan_machine_class_init)
 
  static void lowrisc_ibex_soc_init(Object *obj)
  {
Reviewed-by on v1 1/5
#3 lore raw

Re: [PATCH 1/5] hw/riscv/opentitan: Rename machine_[class]_init() functions

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Follow QOM style which declares FOO_init() as instance initializer and FOO_class_init() as class initializer:
rename the OpenTitan machine class/instance init() accordingly.

Alistair

Quoted 42 lines
---
 hw/riscv/opentitan.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/riscv/opentitan.c +4 -5
index bc678766e7..2d21ee39c5 100644
@@ -75,7 +75,7 @@ static const MemMapEntry ibex_memmap[] = {
     [IBEX_DEV_FLASH_VIRTUAL] =  {  0x80000000,  0x80000     },
 };
 
-static void opentitan_board_init(MachineState *machine)
+static void opentitan_machine_init(MachineState *machine)
 {
     MachineClass *mc = MACHINE_GET_CLASS(machine);
     const MemMapEntry *memmap = ibex_memmap;
@@ -108,17 +108,17 @@ static void opentitan_board_init(MachineState *machine)
     }
 }
 
-static void opentitan_machine_init(MachineClass *mc)
+static void opentitan_machine_class_init(MachineClass *mc)
 {
     mc->desc = "RISC-V Board compatible with OpenTitan";
-    mc->init = opentitan_board_init;
+    mc->init = opentitan_machine_init;
     mc->max_cpus = 1;
     mc->default_cpu_type = TYPE_RISCV_CPU_IBEX;
     mc->default_ram_id = "riscv.lowrisc.ibex.ram";
     mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM].size;
 }
 
-DEFINE_MACHINE("opentitan", opentitan_machine_init)
+DEFINE_MACHINE("opentitan", opentitan_machine_class_init)
 
 static void lowrisc_ibex_soc_init(Object *obj)
 {
--

2.38.1

#4 lore raw

PATCH 2/5 hw/riscv/opentitan: Declare QOM types using DEFINE_TYPES() macro

In reply to Philippe Mathieu-Daudé

When multiple QOM types are registered in the same file, it is simpler to use the the DEFINE_TYPES() macro. Replace the type_init() / type_register_static() combination. This is in preparation of adding the OpenTitan machine type to this array in a pair of commits.

---
 hw/riscv/opentitan.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
hw/riscv/opentitan.c +9 -12
index 2d21ee39c5..294955eeea 100644
@@ -320,17 +320,14 @@ static void lowrisc_ibex_soc_class_init(ObjectClass *oc, void *data)
     dc->user_creatable = false;
 }
 
-static const TypeInfo lowrisc_ibex_soc_type_info = {
-    .name = TYPE_RISCV_IBEX_SOC,
-    .parent = TYPE_DEVICE,
-    .instance_size = sizeof(LowRISCIbexSoCState),
-    .instance_init = lowrisc_ibex_soc_init,
-    .class_init = lowrisc_ibex_soc_class_init,
+static const TypeInfo open_titan_types[] = {
+    {
+        .name           = TYPE_RISCV_IBEX_SOC,
+        .parent         = TYPE_DEVICE,
+        .instance_size  = sizeof(LowRISCIbexSoCState),
+        .instance_init  = lowrisc_ibex_soc_init,
+        .class_init     = lowrisc_ibex_soc_class_init,
+    }
 };
 
-static void lowrisc_ibex_soc_register_types(void)
-{
-    type_register_static(&lowrisc_ibex_soc_type_info);
-}
-
-type_init(lowrisc_ibex_soc_register_types)
+DEFINE_TYPES(open_titan_types)
Signature · 1 line
2.38.1
Reviewed-by on v1 2/5
#5 lore raw

Re: [PATCH 2/5] hw/riscv/opentitan: Declare QOM types using DEFINE_TYPES() macro

Quoted 5 lines · Philippe Mathieu-Daudé

When multiple QOM types are registered in the same file, it is simpler to use the the DEFINE_TYPES() macro. Replace the type_init() / type_register_static() combination. This is in preparation of adding the OpenTitan machine type to this array in a pair of commits.

I wonder whether we should forbid type_init()/type_register_static() and force everyone to use DEFINE_TYPES(). We need less options when dealing with QOM.

Quoted 37 lines
---
  hw/riscv/opentitan.c | 21 +++++++++------------
  1 file changed, 9 insertions(+), 12 deletions(-)
hw/riscv/opentitan.c +9 -12
index 2d21ee39c5..294955eeea 100644
@@ -320,17 +320,14 @@ static void lowrisc_ibex_soc_class_init(ObjectClass *oc, void *data)
      dc->user_creatable = false;
  }
 
-static const TypeInfo lowrisc_ibex_soc_type_info = {
-    .name = TYPE_RISCV_IBEX_SOC,
-    .parent = TYPE_DEVICE,
-    .instance_size = sizeof(LowRISCIbexSoCState),
-    .instance_init = lowrisc_ibex_soc_init,
-    .class_init = lowrisc_ibex_soc_class_init,
+static const TypeInfo open_titan_types[] = {
+    {
+        .name           = TYPE_RISCV_IBEX_SOC,
+        .parent         = TYPE_DEVICE,
+        .instance_size  = sizeof(LowRISCIbexSoCState),
+        .instance_init  = lowrisc_ibex_soc_init,
+        .class_init     = lowrisc_ibex_soc_class_init,
+    }
  };
 
-static void lowrisc_ibex_soc_register_types(void)
-{
-    type_register_static(&lowrisc_ibex_soc_type_info);
-}
-
-type_init(lowrisc_ibex_soc_register_types)
+DEFINE_TYPES(open_titan_types)
Reviewed-by on v1 2/5
#6 lore raw

Re: [PATCH 2/5] hw/riscv/opentitan: Declare QOM types using DEFINE_TYPES() macro

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

When multiple QOM types are registered in the same file, it is simpler to use the the DEFINE_TYPES() macro. Replace the type_init() / type_register_static() combination. This is in preparation of adding the OpenTitan machine type to this array in a pair of commits.

Alistair

Quoted 39 lines
---
 hw/riscv/opentitan.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
hw/riscv/opentitan.c +9 -13
index 2d21ee39c5..294955eeea 100644
@@ -320,17 +320,14 @@ static void lowrisc_ibex_soc_class_init(ObjectClass *oc, void *data)
     dc->user_creatable = false;
 }
 
-static const TypeInfo lowrisc_ibex_soc_type_info = {
-    .name = TYPE_RISCV_IBEX_SOC,
-    .parent = TYPE_DEVICE,
-    .instance_size = sizeof(LowRISCIbexSoCState),
-    .instance_init = lowrisc_ibex_soc_init,
-    .class_init = lowrisc_ibex_soc_class_init,
+static const TypeInfo open_titan_types[] = {
+    {
+        .name           = TYPE_RISCV_IBEX_SOC,
+        .parent         = TYPE_DEVICE,
+        .instance_size  = sizeof(LowRISCIbexSoCState),
+        .instance_init  = lowrisc_ibex_soc_init,
+        .class_init     = lowrisc_ibex_soc_class_init,
+    }
 };
 
-static void lowrisc_ibex_soc_register_types(void)
-{
-    type_register_static(&lowrisc_ibex_soc_type_info);
-}
-
-type_init(lowrisc_ibex_soc_register_types)
+DEFINE_TYPES(open_titan_types)
--

2.38.1

#7 lore raw

PATCH 3/5 hw/riscv/opentitan: Add TYPE_OPENTITAN_MACHINE definition

In reply to Philippe Mathieu-Daudé

QOM type names are usually defined as TYPE_FOO.

---
 include/hw/riscv/opentitan.h | 2 ++
 hw/riscv/opentitan.c         | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
include/hw/riscv/opentitan.h +2 -0
index c40b05052a..fd70226ed8 100644
@@ -53,6 +53,8 @@ struct LowRISCIbexSoCState {
     MemoryRegion flash_alias;
 };
 
+#define TYPE_OPENTITAN_MACHINE "opentitan"
+
 typedef struct OpenTitanState {
     /*< private >*/
     SysBusDevice parent_obj;
hw/riscv/opentitan.c +1 -1
index 294955eeea..7d7159ea30 100644
@@ -118,7 +118,7 @@ static void opentitan_machine_class_init(MachineClass *mc)
     mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM].size;
 }
 
-DEFINE_MACHINE("opentitan", opentitan_machine_class_init)
+DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init)
 
 static void lowrisc_ibex_soc_init(Object *obj)
 {
Signature · 1 line
2.38.1
Reviewed-by on v1 3/5
#8 lore raw

Re: [PATCH 3/5] hw/riscv/opentitan: Add TYPE_OPENTITAN_MACHINE definition

Quoted 4 lines · Philippe Mathieu-Daudé

QOM type names are usually defined as TYPE_FOO.

---

Quoted 30 lines
  include/hw/riscv/opentitan.h | 2 ++
  hw/riscv/opentitan.c         | 2 +-
  2 files changed, 3 insertions(+), 1 deletion(-)
include/hw/riscv/opentitan.h +2 -0
index c40b05052a..fd70226ed8 100644
@@ -53,6 +53,8 @@ struct LowRISCIbexSoCState {
      MemoryRegion flash_alias;
  };
 
+#define TYPE_OPENTITAN_MACHINE "opentitan"
+
  typedef struct OpenTitanState {
      /*< private >*/
      SysBusDevice parent_obj;
hw/riscv/opentitan.c +1 -1
index 294955eeea..7d7159ea30 100644
@@ -118,7 +118,7 @@ static void opentitan_machine_class_init(MachineClass *mc)
      mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM].size;
  }
 
-DEFINE_MACHINE("opentitan", opentitan_machine_class_init)
+DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init)
 
  static void lowrisc_ibex_soc_init(Object *obj)
  {
Reviewed-by on v1 3/5
#9 lore raw

Re: [PATCH 3/5] hw/riscv/opentitan: Add TYPE_OPENTITAN_MACHINE definition

In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

QOM type names are usually defined as TYPE_FOO.

Alistair

Quoted 35 lines
---
 include/hw/riscv/opentitan.h | 2 ++
 hw/riscv/opentitan.c         | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
include/hw/riscv/opentitan.h +2 -0
index c40b05052a..fd70226ed8 100644
@@ -53,6 +53,8 @@ struct LowRISCIbexSoCState {
     MemoryRegion flash_alias;
 };
 
+#define TYPE_OPENTITAN_MACHINE "opentitan"
+
 typedef struct OpenTitanState {
     /*< private >*/
     SysBusDevice parent_obj;
hw/riscv/opentitan.c +1 -2
index 294955eeea..7d7159ea30 100644
@@ -118,7 +118,7 @@ static void opentitan_machine_class_init(MachineClass *mc)
     mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM].size;
 }
 
-DEFINE_MACHINE("opentitan", opentitan_machine_class_init)
+DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init)
 
 static void lowrisc_ibex_soc_init(Object *obj)
 {
--

2.38.1

#10 lore raw

PATCH 4/5 hw/riscv/opentitan: Explicit machine type definition

In reply to Philippe Mathieu-Daudé

Expand the DEFINE_MACHINE() macro, converting the class_init() handler.

---
 include/hw/riscv/opentitan.h |  3 ++-
 hw/riscv/opentitan.c         | 10 +++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)
include/hw/riscv/opentitan.h +2 -1
index fd70226ed8..806ff73528 100644
@@ -24,6 +24,7 @@
 #include "hw/char/ibex_uart.h"
 #include "hw/timer/ibex_timer.h"
 #include "hw/ssi/ibex_spi_host.h"
+#include "hw/boards.h"
 #include "qom/object.h"
 
 #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc"
@@ -53,7 +54,7 @@ struct LowRISCIbexSoCState {
     MemoryRegion flash_alias;
 };
 
-#define TYPE_OPENTITAN_MACHINE "opentitan"
+#define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan")
 
 typedef struct OpenTitanState {
     /*< private >*/
hw/riscv/opentitan.c +7 -3
index 7d7159ea30..9535308197 100644
@@ -108,8 +108,10 @@ static void opentitan_machine_init(MachineState *machine)
     }
 }
 
-static void opentitan_machine_class_init(MachineClass *mc)
+static void opentitan_machine_class_init(ObjectClass *oc, void *data)
 {
+    MachineClass *mc = MACHINE_CLASS(oc);
+
     mc->desc = "RISC-V Board compatible with OpenTitan";
     mc->init = opentitan_machine_init;
     mc->max_cpus = 1;
@@ -118,8 +120,6 @@ static void opentitan_machine_class_init(MachineClass *mc)
     mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM].size;
 }
 
-DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init)
-
 static void lowrisc_ibex_soc_init(Object *obj)
 {
     LowRISCIbexSoCState *s = RISCV_IBEX_SOC(obj);
@@ -327,6 +327,10 @@ static const TypeInfo open_titan_types[] = {
         .instance_size  = sizeof(LowRISCIbexSoCState),
         .instance_init  = lowrisc_ibex_soc_init,
         .class_init     = lowrisc_ibex_soc_class_init,
+    }, {
+        .name           = TYPE_OPENTITAN_MACHINE,
+        .parent         = TYPE_MACHINE,
+        .class_init     = opentitan_machine_class_init,
     }
 };
 
Signature · 1 line
2.38.1
Reviewed-by on v1 4/5
#11 lore raw

Re: [PATCH 4/5] hw/riscv/opentitan: Explicit machine type definition

Quoted 5 lines · Philippe Mathieu-Daudé

Expand the DEFINE_MACHINE() macro, converting the class_init() handler.

---

Quoted 61 lines
  include/hw/riscv/opentitan.h |  3 ++-
  hw/riscv/opentitan.c         | 10 +++++++---
  2 files changed, 9 insertions(+), 4 deletions(-)
include/hw/riscv/opentitan.h +2 -1
index fd70226ed8..806ff73528 100644
@@ -24,6 +24,7 @@
  #include "hw/char/ibex_uart.h"
  #include "hw/timer/ibex_timer.h"
  #include "hw/ssi/ibex_spi_host.h"
+#include "hw/boards.h"
  #include "qom/object.h"
 
  #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc"
@@ -53,7 +54,7 @@ struct LowRISCIbexSoCState {
      MemoryRegion flash_alias;
  };
 
-#define TYPE_OPENTITAN_MACHINE "opentitan"
+#define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan")
 
  typedef struct OpenTitanState {
      /*< private >*/
hw/riscv/opentitan.c +7 -3
index 7d7159ea30..9535308197 100644
@@ -108,8 +108,10 @@ static void opentitan_machine_init(MachineState *machine)
      }
  }
 
-static void opentitan_machine_class_init(MachineClass *mc)
+static void opentitan_machine_class_init(ObjectClass *oc, void *data)
  {
+    MachineClass *mc = MACHINE_CLASS(oc);
+
      mc->desc = "RISC-V Board compatible with OpenTitan";
      mc->init = opentitan_machine_init;
      mc->max_cpus = 1;
@@ -118,8 +120,6 @@ static void opentitan_machine_class_init(MachineClass *mc)
      mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM].size;
  }
 
-DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init)
-
  static void lowrisc_ibex_soc_init(Object *obj)
  {
      LowRISCIbexSoCState *s = RISCV_IBEX_SOC(obj);
@@ -327,6 +327,10 @@ static const TypeInfo open_titan_types[] = {
          .instance_size  = sizeof(LowRISCIbexSoCState),
          .instance_init  = lowrisc_ibex_soc_init,
          .class_init     = lowrisc_ibex_soc_class_init,
+    }, {
+        .name           = TYPE_OPENTITAN_MACHINE,
+        .parent         = TYPE_MACHINE,
+        .class_init     = opentitan_machine_class_init,
      }
  };
 
Reviewed-by on v1 4/5
#12 lore raw

Re: [PATCH 4/5] hw/riscv/opentitan: Explicit machine type definition

In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

Expand the DEFINE_MACHINE() macro, converting the class_init() handler.

Alistair

Quoted 66 lines
---
 include/hw/riscv/opentitan.h |  3 ++-
 hw/riscv/opentitan.c         | 10 +++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)
include/hw/riscv/opentitan.h +2 -1
index fd70226ed8..806ff73528 100644
@@ -24,6 +24,7 @@
 #include "hw/char/ibex_uart.h"
 #include "hw/timer/ibex_timer.h"
 #include "hw/ssi/ibex_spi_host.h"
+#include "hw/boards.h"
 #include "qom/object.h"
 
 #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc"
@@ -53,7 +54,7 @@ struct LowRISCIbexSoCState {
     MemoryRegion flash_alias;
 };
 
-#define TYPE_OPENTITAN_MACHINE "opentitan"
+#define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan")
 
 typedef struct OpenTitanState {
     /*< private >*/
hw/riscv/opentitan.c +7 -4
index 7d7159ea30..9535308197 100644
@@ -108,8 +108,10 @@ static void opentitan_machine_init(MachineState *machine)
     }
 }
 
-static void opentitan_machine_class_init(MachineClass *mc)
+static void opentitan_machine_class_init(ObjectClass *oc, void *data)
 {
+    MachineClass *mc = MACHINE_CLASS(oc);
+
     mc->desc = "RISC-V Board compatible with OpenTitan";
     mc->init = opentitan_machine_init;
     mc->max_cpus = 1;
@@ -118,8 +120,6 @@ static void opentitan_machine_class_init(MachineClass *mc)
     mc->default_ram_size = ibex_memmap[IBEX_DEV_RAM].size;
 }
 
-DEFINE_MACHINE(TYPE_OPENTITAN_MACHINE, opentitan_machine_class_init)
-
 static void lowrisc_ibex_soc_init(Object *obj)
 {
     LowRISCIbexSoCState *s = RISCV_IBEX_SOC(obj);
@@ -327,6 +327,10 @@ static const TypeInfo open_titan_types[] = {
         .instance_size  = sizeof(LowRISCIbexSoCState),
         .instance_init  = lowrisc_ibex_soc_init,
         .class_init     = lowrisc_ibex_soc_class_init,
+    }, {
+        .name           = TYPE_OPENTITAN_MACHINE,
+        .parent         = TYPE_MACHINE,
+        .class_init     = opentitan_machine_class_init,
     }
 };
 
--

2.38.1

#13 lore raw

PATCH 5/5 hw/riscv/opentitan: Correct OpenTitanState parent type/size

In reply to Philippe Mathieu-Daudé

OpenTitanState is the 'machine' (or 'board') state: it isn't a SysBus device, but inherits from the MachineState type. Correct the instance size.
Doing so we avoid leaking an OpenTitanState pointer in opentitan_machine_init().

Fixes fe0fe4735e ("riscv: Initial commit of OpenTitan machine")
---
 include/hw/riscv/opentitan.h | 3 ++-
 hw/riscv/opentitan.c         | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
include/hw/riscv/opentitan.h +2 -1
index 806ff73528..609473d07b 100644
@@ -55,10 +55,11 @@ struct LowRISCIbexSoCState {
 };
 
 #define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan")
+OBJECT_DECLARE_SIMPLE_TYPE(OpenTitanState, OPENTITAN_MACHINE)
 
 typedef struct OpenTitanState {
     /*< private >*/
-    SysBusDevice parent_obj;
+    MachineState parent_obj;
 
     /*< public >*/
     LowRISCIbexSoCState soc;
hw/riscv/opentitan.c +2 -1
index 9535308197..6a2fcc4ade 100644
@@ -78,8 +78,8 @@ static const MemMapEntry ibex_memmap[] = {
 static void opentitan_machine_init(MachineState *machine)
 {
     MachineClass *mc = MACHINE_GET_CLASS(machine);
+    OpenTitanState *s = OPENTITAN_MACHINE(machine);
     const MemMapEntry *memmap = ibex_memmap;
-    OpenTitanState *s = g_new0(OpenTitanState, 1);
     MemoryRegion *sys_mem = get_system_memory();
 
     if (machine->ram_size != mc->default_ram_size) {
@@ -330,6 +330,7 @@ static const TypeInfo open_titan_types[] = {
     }, {
         .name           = TYPE_OPENTITAN_MACHINE,
         .parent         = TYPE_MACHINE,
+        .instance_size  = sizeof(OpenTitanState),
         .class_init     = opentitan_machine_class_init,
     }
 };
Signature · 1 line
2.38.1
Reviewed-by on v1 5/5
#14 lore raw

Re: [PATCH 5/5] hw/riscv/opentitan: Correct OpenTitanState parent type/size

Quoted 9 lines · Philippe Mathieu-Daudé

OpenTitanState is the 'machine' (or 'board') state: it isn't a SysBus device, but inherits from the MachineState type. Correct the instance size.
Doing so we avoid leaking an OpenTitanState pointer in opentitan_machine_init().

Fixes fe0fe4735e ("riscv: Initial commit of OpenTitan machine")

---

Quoted 43 lines
  include/hw/riscv/opentitan.h | 3 ++-
  hw/riscv/opentitan.c         | 3 ++-
  2 files changed, 4 insertions(+), 2 deletions(-)
include/hw/riscv/opentitan.h +2 -1
index 806ff73528..609473d07b 100644
@@ -55,10 +55,11 @@ struct LowRISCIbexSoCState {
  };
 
  #define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan")
+OBJECT_DECLARE_SIMPLE_TYPE(OpenTitanState, OPENTITAN_MACHINE)
 
  typedef struct OpenTitanState {
      /*< private >*/
-    SysBusDevice parent_obj;
+    MachineState parent_obj;
 
      /*< public >*/
      LowRISCIbexSoCState soc;
hw/riscv/opentitan.c +2 -1
index 9535308197..6a2fcc4ade 100644
@@ -78,8 +78,8 @@ static const MemMapEntry ibex_memmap[] = {
  static void opentitan_machine_init(MachineState *machine)
  {
      MachineClass *mc = MACHINE_GET_CLASS(machine);
+    OpenTitanState *s = OPENTITAN_MACHINE(machine);
      const MemMapEntry *memmap = ibex_memmap;
-    OpenTitanState *s = g_new0(OpenTitanState, 1);
      MemoryRegion *sys_mem = get_system_memory();
 
      if (machine->ram_size != mc->default_ram_size) {
@@ -330,6 +330,7 @@ static const TypeInfo open_titan_types[] = {
      }, {
          .name           = TYPE_OPENTITAN_MACHINE,
          .parent         = TYPE_MACHINE,
+        .instance_size  = sizeof(OpenTitanState),
          .class_init     = opentitan_machine_class_init,
      }
  };
Reviewed-by on v1 5/5
#15 lore raw

Re: [PATCH 5/5] hw/riscv/opentitan: Correct OpenTitanState parent type/size

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

OpenTitanState is the 'machine' (or 'board') state: it isn't a SysBus device, but inherits from the MachineState type. Correct the instance size.
Doing so we avoid leaking an OpenTitanState pointer in opentitan_machine_init().

Fixes fe0fe4735e ("riscv: Initial commit of OpenTitan machine")

Alistair

Quoted 48 lines
---
 include/hw/riscv/opentitan.h | 3 ++-
 hw/riscv/opentitan.c         | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
include/hw/riscv/opentitan.h +2 -1
index 806ff73528..609473d07b 100644
@@ -55,10 +55,11 @@ struct LowRISCIbexSoCState {
 };
 
 #define TYPE_OPENTITAN_MACHINE MACHINE_TYPE_NAME("opentitan")
+OBJECT_DECLARE_SIMPLE_TYPE(OpenTitanState, OPENTITAN_MACHINE)
 
 typedef struct OpenTitanState {
     /*< private >*/
-    SysBusDevice parent_obj;
+    MachineState parent_obj;
 
     /*< public >*/
     LowRISCIbexSoCState soc;
hw/riscv/opentitan.c +2 -2
index 9535308197..6a2fcc4ade 100644
@@ -78,8 +78,8 @@ static const MemMapEntry ibex_memmap[] = {
 static void opentitan_machine_init(MachineState *machine)
 {
     MachineClass *mc = MACHINE_GET_CLASS(machine);
+    OpenTitanState *s = OPENTITAN_MACHINE(machine);
     const MemMapEntry *memmap = ibex_memmap;
-    OpenTitanState *s = g_new0(OpenTitanState, 1);
     MemoryRegion *sys_mem = get_system_memory();
 
     if (machine->ram_size != mc->default_ram_size) {
@@ -330,6 +330,7 @@ static const TypeInfo open_titan_types[] = {
     }, {
         .name           = TYPE_OPENTITAN_MACHINE,
         .parent         = TYPE_MACHINE,
+        .instance_size  = sizeof(OpenTitanState),
         .class_init     = opentitan_machine_class_init,
     }
 };
--

2.38.1

#16 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

Hi,

This series fix a QOM issue with the OpenTitanState structure, noticed while auditing QOM relations globally.

All patches are trivial to review.

Regards,

Quoted 8 lines

Phil.

Philippe Mathieu-Daudé (5):
hw/riscv/opentitan: Rename machine_[class]_init() functions hw/riscv/opentitan: Declare QOM types using DEFINE_TYPES() macro hw/riscv/opentitan: Add TYPE_OPENTITAN_MACHINE definition hw/riscv/opentitan: Explicit machine type definition hw/riscv/opentitan: Correct OpenTitanState parent type/size

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 9 lines
 include/hw/riscv/opentitan.h |  6 +++++-
 hw/riscv/opentitan.c         | 38 +++++++++++++++++++-----------------
 2 files changed, 25 insertions(+), 19 deletions(-)

--
2.38.1