[v2,65/86] ppc:ppc405_boards: use memdev for RAM
diff mbox series

Message ID 1579100861-73692-66-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:07 p.m. UTC
memory_region_allocate_system_memory() API is going away, so
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.

PS:
in ref405ep alias RAM into ram_memories[] to avoid re-factoring
its user ppc405ep_init(), which would be invasive and out of
scope this patch.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: david@gibson.dropbear.id.au
CC: qemu-ppc@nongnu.org
---
 hw/ppc/ppc405_boards.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Comments

David Gibson Jan. 16, 2020, 4:21 a.m. UTC | #1
On Wed, Jan 15, 2020 at 04:07:20PM +0100, Igor Mammedov wrote:
> memory_region_allocate_system_memory() API is going away, so
> 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.
> 
> PS:
> in ref405ep alias RAM into ram_memories[] to avoid re-factoring
> its user ppc405ep_init(), which would be invasive and out of
> scope this patch.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
> CC: david@gibson.dropbear.id.au
> CC: qemu-ppc@nongnu.org
> ---
>  hw/ppc/ppc405_boards.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
> index a7a432d..f447e6e 100644
> --- a/hw/ppc/ppc405_boards.c
> +++ b/hw/ppc/ppc405_boards.c
> @@ -168,8 +168,8 @@ static void ref405ep_init(MachineState *machine)
>      }
>  
>      /* XXX: fix this */
> -    memory_region_allocate_system_memory(&ram_memories[0], NULL, "ef405ep.ram",
> -                                         machine->ram_size);
> +    memory_region_init_alias(&ram_memories[0], NULL, "ef405ep.ram.alias",
> +                             machine->ram, 0, machine->ram_size);
>      ram_bases[0] = 0;
>      ram_sizes[0] = machine->ram_size;
>      memory_region_init(&ram_memories[1], NULL, "ef405ep.ram1", 0);
> @@ -310,6 +310,7 @@ static void ref405ep_class_init(ObjectClass *oc, void *data)
>      mc->desc = "ref405ep";
>      mc->init = ref405ep_init;
>      mc->default_ram_size = 0x08000000;
> +    mc->default_ram_id = "ef405ep.ram";
>  }
>  
>  static const TypeInfo ref405ep_type = {
> @@ -422,7 +423,6 @@ static void taihu_405ep_init(MachineState *machine)
>      MemoryRegion *sysmem = get_system_memory();
>      MemoryRegion *bios;
>      MemoryRegion *ram_memories = g_new(MemoryRegion, 2);
> -    MemoryRegion *ram = g_malloc0(sizeof(*ram));
>      hwaddr ram_bases[2], ram_sizes[2];
>      long bios_size;
>      target_ulong kernel_base, initrd_base;
> @@ -436,18 +436,16 @@ static void taihu_405ep_init(MachineState *machine)
>                       mc->default_ram_size);
>          exit(EXIT_FAILURE);
>      }
> -    memory_region_allocate_system_memory(ram, NULL, "taihu_405ep.ram",
> -                                         machine->ram_size);
>  
>      ram_bases[0] = 0;
>      ram_sizes[0] = 0x04000000;
>      memory_region_init_alias(&ram_memories[0], NULL,
> -                             "taihu_405ep.ram-0", ram, ram_bases[0],
> +                             "taihu_405ep.ram-0", machine->ram, ram_bases[0],
>                               ram_sizes[0]);
>      ram_bases[1] = 0x04000000;
>      ram_sizes[1] = 0x04000000;
>      memory_region_init_alias(&ram_memories[1], NULL,
> -                             "taihu_405ep.ram-1", ram, ram_bases[1],
> +                             "taihu_405ep.ram-1", machine->ram, ram_bases[1],
>                               ram_sizes[1]);
>      ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes,
>                    33333333, &pic, kernel_filename == NULL ? 0 : 1);
> @@ -543,6 +541,7 @@ static void taihu_class_init(ObjectClass *oc, void *data)
>      mc->desc = "taihu";
>      mc->init = taihu_405ep_init;
>      mc->default_ram_size = 0x08000000;
> +    mc->default_ram_id = "ef405ep.ram";
>  }
>  
>  static const TypeInfo taihu_type = {

Patch
diff mbox series

diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
index a7a432d..f447e6e 100644
--- a/hw/ppc/ppc405_boards.c
+++ b/hw/ppc/ppc405_boards.c
@@ -168,8 +168,8 @@  static void ref405ep_init(MachineState *machine)
     }
 
     /* XXX: fix this */
-    memory_region_allocate_system_memory(&ram_memories[0], NULL, "ef405ep.ram",
-                                         machine->ram_size);
+    memory_region_init_alias(&ram_memories[0], NULL, "ef405ep.ram.alias",
+                             machine->ram, 0, machine->ram_size);
     ram_bases[0] = 0;
     ram_sizes[0] = machine->ram_size;
     memory_region_init(&ram_memories[1], NULL, "ef405ep.ram1", 0);
@@ -310,6 +310,7 @@  static void ref405ep_class_init(ObjectClass *oc, void *data)
     mc->desc = "ref405ep";
     mc->init = ref405ep_init;
     mc->default_ram_size = 0x08000000;
+    mc->default_ram_id = "ef405ep.ram";
 }
 
 static const TypeInfo ref405ep_type = {
@@ -422,7 +423,6 @@  static void taihu_405ep_init(MachineState *machine)
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *bios;
     MemoryRegion *ram_memories = g_new(MemoryRegion, 2);
-    MemoryRegion *ram = g_malloc0(sizeof(*ram));
     hwaddr ram_bases[2], ram_sizes[2];
     long bios_size;
     target_ulong kernel_base, initrd_base;
@@ -436,18 +436,16 @@  static void taihu_405ep_init(MachineState *machine)
                      mc->default_ram_size);
         exit(EXIT_FAILURE);
     }
-    memory_region_allocate_system_memory(ram, NULL, "taihu_405ep.ram",
-                                         machine->ram_size);
 
     ram_bases[0] = 0;
     ram_sizes[0] = 0x04000000;
     memory_region_init_alias(&ram_memories[0], NULL,
-                             "taihu_405ep.ram-0", ram, ram_bases[0],
+                             "taihu_405ep.ram-0", machine->ram, ram_bases[0],
                              ram_sizes[0]);
     ram_bases[1] = 0x04000000;
     ram_sizes[1] = 0x04000000;
     memory_region_init_alias(&ram_memories[1], NULL,
-                             "taihu_405ep.ram-1", ram, ram_bases[1],
+                             "taihu_405ep.ram-1", machine->ram, ram_bases[1],
                              ram_sizes[1]);
     ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes,
                   33333333, &pic, kernel_filename == NULL ? 0 : 1);
@@ -543,6 +541,7 @@  static void taihu_class_init(ObjectClass *oc, void *data)
     mc->desc = "taihu";
     mc->init = taihu_405ep_init;
     mc->default_ram_size = 0x08000000;
+    mc->default_ram_id = "ef405ep.ram";
 }
 
 static const TypeInfo taihu_type = {