[v2,32/86] arm:vexpress: use memdev for RAM
diff mbox series

Message ID 1579100861-73692-33-git-send-email-imammedo@redhat.com
State New
Headers show
Series
  • refactor main RAM allocation to use hostmem backend
Related show

Commit Message

Igor Mammedov Jan. 15, 2020, 3:06 p.m. UTC
replace it with memdev allocated MemoryRegion. The later is
initialized by generic code, so board only needs to opt in
to memdev scheme by providing
  MachineClass::default_ram_id
and using MachineState::ram instead of manually initializing
RAM memory region.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: peter.maydell@linaro.org
CC: qemu-arm@nongnu.org
---
 hw/arm/vexpress.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

Comments

Philippe Mathieu-Daudé Jan. 15, 2020, 7:21 p.m. UTC | #1
On 1/15/20 4:06 PM, Igor Mammedov wrote:
> replace it with memdev allocated MemoryRegion. The later is
> initialized by generic code, so board only needs to opt in
> to memdev scheme by providing
>    MachineClass::default_ram_id
> and using MachineState::ram instead of manually initializing
> RAM memory region.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: peter.maydell@linaro.org
> CC: qemu-arm@nongnu.org
> ---
>   hw/arm/vexpress.c | 14 +++++---------
>   1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
> index 4673a88..ed683ee 100644
> --- a/hw/arm/vexpress.c
> +++ b/hw/arm/vexpress.c
> @@ -273,7 +273,6 @@ static void a9_daughterboard_init(const VexpressMachineState *vms,
>   {
>       MachineState *machine = MACHINE(vms);
>       MemoryRegion *sysmem = get_system_memory();
> -    MemoryRegion *ram = g_new(MemoryRegion, 1);
>       MemoryRegion *lowram = g_new(MemoryRegion, 1);
>       ram_addr_t low_ram_size;
>   
> @@ -283,8 +282,6 @@ static void a9_daughterboard_init(const VexpressMachineState *vms,
>           exit(1);
>       }
>   
> -    memory_region_allocate_system_memory(ram, NULL, "vexpress.highmem",
> -                                         ram_size);
>       low_ram_size = ram_size;
>       if (low_ram_size > 0x4000000) {
>           low_ram_size = 0x4000000;
> @@ -293,9 +290,10 @@ static void a9_daughterboard_init(const VexpressMachineState *vms,
>        * address space should in theory be remappable to various
>        * things including ROM or RAM; we always map the RAM there.
>        */
> -    memory_region_init_alias(lowram, NULL, "vexpress.lowmem", ram, 0, low_ram_size);
> +    memory_region_init_alias(lowram, NULL, "vexpress.lowmem", machine->ram,
> +                             0, low_ram_size);
>       memory_region_add_subregion(sysmem, 0x0, lowram);
> -    memory_region_add_subregion(sysmem, 0x60000000, ram);
> +    memory_region_add_subregion(sysmem, 0x60000000, machine->ram);
>   
>       /* 0x1e000000 A9MPCore (SCU) private memory region */
>       init_cpus(machine, cpu_type, TYPE_A9MPCORE_PRIV, 0x1e000000, pic,
> @@ -360,7 +358,6 @@ static void a15_daughterboard_init(const VexpressMachineState *vms,
>   {
>       MachineState *machine = MACHINE(vms);
>       MemoryRegion *sysmem = get_system_memory();
> -    MemoryRegion *ram = g_new(MemoryRegion, 1);
>       MemoryRegion *sram = g_new(MemoryRegion, 1);
>   
>       {
> @@ -375,10 +372,8 @@ static void a15_daughterboard_init(const VexpressMachineState *vms,
>           }
>       }
>   
> -    memory_region_allocate_system_memory(ram, NULL, "vexpress.highmem",
> -                                         ram_size);
>       /* RAM is from 0x80000000 upwards; there is no low-memory alias for it. */
> -    memory_region_add_subregion(sysmem, 0x80000000, ram);
> +    memory_region_add_subregion(sysmem, 0x80000000, machine->ram);
>   
>       /* 0x2c000000 A15MPCore private memory region (GIC) */
>       init_cpus(machine, cpu_type, TYPE_A15MPCORE_PRIV,
> @@ -795,6 +790,7 @@ static void vexpress_class_init(ObjectClass *oc, void *data)
>       mc->init = vexpress_common_init;
>       mc->max_cpus = 4;
>       mc->ignore_memory_transaction_failures = true;
> +    mc->default_ram_id = "vexpress.highmem";
>   }
>   
>   static void vexpress_a9_class_init(ObjectClass *oc, void *data)
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Patch
diff mbox series

diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
index 4673a88..ed683ee 100644
--- a/hw/arm/vexpress.c
+++ b/hw/arm/vexpress.c
@@ -273,7 +273,6 @@  static void a9_daughterboard_init(const VexpressMachineState *vms,
 {
     MachineState *machine = MACHINE(vms);
     MemoryRegion *sysmem = get_system_memory();
-    MemoryRegion *ram = g_new(MemoryRegion, 1);
     MemoryRegion *lowram = g_new(MemoryRegion, 1);
     ram_addr_t low_ram_size;
 
@@ -283,8 +282,6 @@  static void a9_daughterboard_init(const VexpressMachineState *vms,
         exit(1);
     }
 
-    memory_region_allocate_system_memory(ram, NULL, "vexpress.highmem",
-                                         ram_size);
     low_ram_size = ram_size;
     if (low_ram_size > 0x4000000) {
         low_ram_size = 0x4000000;
@@ -293,9 +290,10 @@  static void a9_daughterboard_init(const VexpressMachineState *vms,
      * address space should in theory be remappable to various
      * things including ROM or RAM; we always map the RAM there.
      */
-    memory_region_init_alias(lowram, NULL, "vexpress.lowmem", ram, 0, low_ram_size);
+    memory_region_init_alias(lowram, NULL, "vexpress.lowmem", machine->ram,
+                             0, low_ram_size);
     memory_region_add_subregion(sysmem, 0x0, lowram);
-    memory_region_add_subregion(sysmem, 0x60000000, ram);
+    memory_region_add_subregion(sysmem, 0x60000000, machine->ram);
 
     /* 0x1e000000 A9MPCore (SCU) private memory region */
     init_cpus(machine, cpu_type, TYPE_A9MPCORE_PRIV, 0x1e000000, pic,
@@ -360,7 +358,6 @@  static void a15_daughterboard_init(const VexpressMachineState *vms,
 {
     MachineState *machine = MACHINE(vms);
     MemoryRegion *sysmem = get_system_memory();
-    MemoryRegion *ram = g_new(MemoryRegion, 1);
     MemoryRegion *sram = g_new(MemoryRegion, 1);
 
     {
@@ -375,10 +372,8 @@  static void a15_daughterboard_init(const VexpressMachineState *vms,
         }
     }
 
-    memory_region_allocate_system_memory(ram, NULL, "vexpress.highmem",
-                                         ram_size);
     /* RAM is from 0x80000000 upwards; there is no low-memory alias for it. */
-    memory_region_add_subregion(sysmem, 0x80000000, ram);
+    memory_region_add_subregion(sysmem, 0x80000000, machine->ram);
 
     /* 0x2c000000 A15MPCore private memory region (GIC) */
     init_cpus(machine, cpu_type, TYPE_A15MPCORE_PRIV,
@@ -795,6 +790,7 @@  static void vexpress_class_init(ObjectClass *oc, void *data)
     mc->init = vexpress_common_init;
     mc->max_cpus = 4;
     mc->ignore_memory_transaction_failures = true;
+    mc->default_ram_id = "vexpress.highmem";
 }
 
 static void vexpress_a9_class_init(ObjectClass *oc, void *data)