diff mbox series

[v4,32/33] hw/nios2: Move memory regions into Nios2Machine

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

Commit Message

Richard Henderson March 8, 2022, 7:20 a.m. UTC
Convert to contiguous allocation, as much as possible so far.
The two timer objects are not exposed for subobject allocation.

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

Comments

Mark Cave-Ayland March 8, 2022, 8:39 a.m. UTC | #1
On 08/03/2022 07:20, Richard Henderson wrote:

> Convert to contiguous allocation, as much as possible so far.
> The two timer objects are not exposed for subobject allocation.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   hw/nios2/10m50_devboard.c | 29 +++++++++++++++--------------
>   1 file changed, 15 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
> index f245e0baa8..f4931b8a67 100644
> --- a/hw/nios2/10m50_devboard.c
> +++ b/hw/nios2/10m50_devboard.c
> @@ -38,6 +38,11 @@
>   
>   struct Nios2MachineState {
>       MachineState parent_obj;
> +
> +    MemoryRegion phys_tcm;
> +    MemoryRegion phys_tcm_alias;
> +    MemoryRegion phys_ram;
> +    MemoryRegion phys_ram_alias;
>   };
>   
>   #define TYPE_NIOS2_MACHINE  MACHINE_TYPE_NAME("10m50-ghrd")
> @@ -51,10 +56,6 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
>       Nios2CPU *cpu;
>       DeviceState *dev;
>       MemoryRegion *address_space_mem = get_system_memory();
> -    MemoryRegion *phys_tcm = g_new(MemoryRegion, 1);
> -    MemoryRegion *phys_tcm_alias = g_new(MemoryRegion, 1);
> -    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
> -    MemoryRegion *phys_ram_alias = g_new(MemoryRegion, 1);
>       ram_addr_t tcm_base = 0x0;
>       ram_addr_t tcm_size = 0x1000;    /* 1 kiB, but QEMU limit is 4 kiB */
>       ram_addr_t ram_base = 0x08000000;
> @@ -63,22 +64,22 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
>       int i;
>   
>       /* Physical TCM (tb_ram_1k) with alias at 0xc0000000 */
> -    memory_region_init_ram(phys_tcm, NULL, "nios2.tcm", tcm_size,
> +    memory_region_init_ram(&nms->phys_tcm, NULL, "nios2.tcm", tcm_size,
>                              &error_abort);
> -    memory_region_init_alias(phys_tcm_alias, NULL, "nios2.tcm.alias",
> -                             phys_tcm, 0, tcm_size);
> -    memory_region_add_subregion(address_space_mem, tcm_base, phys_tcm);
> +    memory_region_init_alias(&nms->phys_tcm_alias, NULL, "nios2.tcm.alias",
> +                             &nms->phys_tcm, 0, tcm_size);
> +    memory_region_add_subregion(address_space_mem, tcm_base, &nms->phys_tcm);
>       memory_region_add_subregion(address_space_mem, 0xc0000000 + tcm_base,
> -                                phys_tcm_alias);
> +                                &nms->phys_tcm_alias);
>   
>       /* Physical DRAM with alias at 0xc0000000 */
> -    memory_region_init_ram(phys_ram, NULL, "nios2.ram", ram_size,
> +    memory_region_init_ram(&nms->phys_ram, NULL, "nios2.ram", ram_size,
>                              &error_abort);
> -    memory_region_init_alias(phys_ram_alias, NULL, "nios2.ram.alias",
> -                             phys_ram, 0, ram_size);
> -    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
> +    memory_region_init_alias(&nms->phys_ram_alias, NULL, "nios2.ram.alias",
> +                             &nms->phys_ram, 0, ram_size);
> +    memory_region_add_subregion(address_space_mem, ram_base, &nms->phys_ram);
>       memory_region_add_subregion(address_space_mem, 0xc0000000 + ram_base,
> -                                phys_ram_alias);
> +                                &nms->phys_ram_alias);
>   
>       /* Create CPU -- FIXME */
>       cpu = NIOS2_CPU(cpu_create(TYPE_NIOS2_CPU));

Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.
diff mbox series

Patch

diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
index f245e0baa8..f4931b8a67 100644
--- a/hw/nios2/10m50_devboard.c
+++ b/hw/nios2/10m50_devboard.c
@@ -38,6 +38,11 @@ 
 
 struct Nios2MachineState {
     MachineState parent_obj;
+
+    MemoryRegion phys_tcm;
+    MemoryRegion phys_tcm_alias;
+    MemoryRegion phys_ram;
+    MemoryRegion phys_ram_alias;
 };
 
 #define TYPE_NIOS2_MACHINE  MACHINE_TYPE_NAME("10m50-ghrd")
@@ -51,10 +56,6 @@  static void nios2_10m50_ghrd_init(MachineState *machine)
     Nios2CPU *cpu;
     DeviceState *dev;
     MemoryRegion *address_space_mem = get_system_memory();
-    MemoryRegion *phys_tcm = g_new(MemoryRegion, 1);
-    MemoryRegion *phys_tcm_alias = g_new(MemoryRegion, 1);
-    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
-    MemoryRegion *phys_ram_alias = g_new(MemoryRegion, 1);
     ram_addr_t tcm_base = 0x0;
     ram_addr_t tcm_size = 0x1000;    /* 1 kiB, but QEMU limit is 4 kiB */
     ram_addr_t ram_base = 0x08000000;
@@ -63,22 +64,22 @@  static void nios2_10m50_ghrd_init(MachineState *machine)
     int i;
 
     /* Physical TCM (tb_ram_1k) with alias at 0xc0000000 */
-    memory_region_init_ram(phys_tcm, NULL, "nios2.tcm", tcm_size,
+    memory_region_init_ram(&nms->phys_tcm, NULL, "nios2.tcm", tcm_size,
                            &error_abort);
-    memory_region_init_alias(phys_tcm_alias, NULL, "nios2.tcm.alias",
-                             phys_tcm, 0, tcm_size);
-    memory_region_add_subregion(address_space_mem, tcm_base, phys_tcm);
+    memory_region_init_alias(&nms->phys_tcm_alias, NULL, "nios2.tcm.alias",
+                             &nms->phys_tcm, 0, tcm_size);
+    memory_region_add_subregion(address_space_mem, tcm_base, &nms->phys_tcm);
     memory_region_add_subregion(address_space_mem, 0xc0000000 + tcm_base,
-                                phys_tcm_alias);
+                                &nms->phys_tcm_alias);
 
     /* Physical DRAM with alias at 0xc0000000 */
-    memory_region_init_ram(phys_ram, NULL, "nios2.ram", ram_size,
+    memory_region_init_ram(&nms->phys_ram, NULL, "nios2.ram", ram_size,
                            &error_abort);
-    memory_region_init_alias(phys_ram_alias, NULL, "nios2.ram.alias",
-                             phys_ram, 0, ram_size);
-    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
+    memory_region_init_alias(&nms->phys_ram_alias, NULL, "nios2.ram.alias",
+                             &nms->phys_ram, 0, ram_size);
+    memory_region_add_subregion(address_space_mem, ram_base, &nms->phys_ram);
     memory_region_add_subregion(address_space_mem, 0xc0000000 + ram_base,
-                                phys_ram_alias);
+                                &nms->phys_ram_alias);
 
     /* Create CPU -- FIXME */
     cpu = NIOS2_CPU(cpu_create(TYPE_NIOS2_CPU));