diff mbox series

[v4,31/33] hw/nios2: Introduce Nios2MachineState

Message ID 20220308072005.307955-32-richard.henderson@linaro.org
State New
Headers show
Series target/nios2: Shadow register set, EIC and VIC | expand

Commit Message

Richard Henderson March 8, 2022, 7:20 a.m. UTC
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(-)

Comments

Mark Cave-Ayland March 8, 2022, 8:39 a.m. UTC | #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.
Richard Henderson March 8, 2022, 7:55 p.m. UTC | #2
On 3/7/22 22:39, Mark Cave-Ayland wrote:
>>   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.

Ok.

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

Ok.  This is a leftover from an intermediate when Nios2MachineClass existed.


r~
diff mbox series

Patch

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);
 }
 
-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),
+    .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);