qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 31/33] hw/nios2: Introduce Nios2MachineState


From: Mark Cave-Ayland
Subject: Re: [PATCH v4 31/33] hw/nios2: Introduce Nios2MachineState
Date: Tue, 8 Mar 2022 08:39:07 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1

On 08/03/2022 07:20, Richard Henderson wrote:

We want to move data from the heap into Nios2MachineState,
which is not possible with DEFINE_MACHINE.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
  hw/nios2/10m50_devboard.c | 28 +++++++++++++++++++++++++---
  1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
index 3d1205b8bd..f245e0baa8 100644
--- a/hw/nios2/10m50_devboard.c
+++ b/hw/nios2/10m50_devboard.c
@@ -36,10 +36,18 @@
#include "boot.h" +struct Nios2MachineState {
+    MachineState parent_obj;
+};
+
+#define TYPE_NIOS2_MACHINE  MACHINE_TYPE_NAME("10m50-ghrd")
+OBJECT_DECLARE_TYPE(Nios2MachineState, MachineClass, NIOS2_MACHINE)
+
  #define BINARY_DEVICE_TREE_FILE    "10m50-devboard.dtb"
static void nios2_10m50_ghrd_init(MachineState *machine)
  {
+    Nios2MachineState *nms = NIOS2_MACHINE(machine);
      Nios2CPU *cpu;
      DeviceState *dev;
      MemoryRegion *address_space_mem = get_system_memory();
@@ -101,15 +109,29 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
      cpu->exception_addr = 0xc8000120;
      cpu->fast_tlb_miss_addr = 0xc0000100;
- nios2_load_kernel(cpu, ram_base, ram_size, machine->initrd_filename,
+    nios2_load_kernel(cpu, ram_base, ram_size, nms->parent_obj.initrd_filename,
                        BINARY_DEVICE_TREE_FILE, NULL);

I think you should be able to keep this as machine->initrd_filename? Certainly there should be no direct access to parent_obj here, and if you did need it a QOM cast macro would be the way to do this.

  }
-static void nios2_10m50_ghrd_machine_init(struct MachineClass *mc)
+static void nios2_10m50_ghrd_class_init(ObjectClass *oc, void *data)
  {
+    MachineClass *mc = MACHINE_CLASS(oc);
+
      mc->desc = "Altera 10M50 GHRD Nios II design";
      mc->init = nios2_10m50_ghrd_init;
      mc->is_default = true;
  }
-DEFINE_MACHINE("10m50-ghrd", nios2_10m50_ghrd_machine_init);
+static const TypeInfo nios2_10m50_ghrd_type_info = {
+    .name          = TYPE_NIOS2_MACHINE,
+    .parent        = TYPE_MACHINE,
+    .instance_size = sizeof(Nios2MachineState),
+    .class_size    = sizeof(MachineClass),

Technically you can drop .class_size here since this should be inherited automatically from MachineClass.

+    .class_init    = nios2_10m50_ghrd_class_init,
+};
+
+static void nios2_10m50_ghrd_type_init(void)
+{
+    type_register_static(&nios2_10m50_ghrd_type_info);
+}
+type_init(nios2_10m50_ghrd_type_init);


ATB,

Mark.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]