[v2,71/86] ppc:virtex_ml507: use memdev for RAM
diff mbox series

Message ID 1579100861-73692-72-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.

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

Comments

Philippe Mathieu-Daudé Jan. 15, 2020, 6:37 p.m. UTC | #1
On 1/15/20 4:07 PM, 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.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: david@gibson.dropbear.id.au
> CC: qemu-ppc@nongnu.org
> CC: edgar.iglesias@gmail.com
> ---
>   hw/ppc/virtex_ml507.c | 12 +++++-------
>   1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
> index 651d8db..b74a269 100644
> --- a/hw/ppc/virtex_ml507.c
> +++ b/hw/ppc/virtex_ml507.c
> @@ -193,7 +193,6 @@ static int xilinx_load_device_tree(hwaddr addr,
>   
>   static void virtex_init(MachineState *machine)
>   {
> -    ram_addr_t ram_size = machine->ram_size;
>       const char *kernel_filename = machine->kernel_filename;
>       const char *kernel_cmdline = machine->kernel_cmdline;
>       hwaddr initrd_base = 0;
> @@ -204,7 +203,6 @@ static void virtex_init(MachineState *machine)
>       CPUPPCState *env;
>       hwaddr ram_base = 0;
>       DriveInfo *dinfo;
> -    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
>       qemu_irq irq[32], *cpu_irq;
>       int kernel_size;
>       int i;
> @@ -221,8 +219,7 @@ static void virtex_init(MachineState *machine)
>   
>       qemu_register_reset(main_cpu_reset, cpu);
>   
> -    memory_region_allocate_system_memory(phys_ram, NULL, "ram", ram_size);
> -    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
> +    memory_region_add_subregion(address_space_mem, ram_base, machine->ram);
>   
>       dinfo = drive_get(IF_PFLASH, 0, 0);
>       pflash_cfi01_register(PFLASH_BASEADDR, "virtex.flash", FLASH_SIZE,
> @@ -265,7 +262,7 @@ static void virtex_init(MachineState *machine)
>               /* If we failed loading ELF's try a raw image.  */
>               kernel_size = load_image_targphys(kernel_filename,
>                                                 boot_offset,
> -                                              ram_size);
> +                                              machine->ram_size);
>               boot_info.bootstrap_pc = boot_offset;
>               high = boot_info.bootstrap_pc + kernel_size + 8192;
>           }
> @@ -276,7 +273,7 @@ static void virtex_init(MachineState *machine)
>           if (machine->initrd_filename) {
>               initrd_base = high = ROUND_UP(high, 4);
>               initrd_size = load_image_targphys(machine->initrd_filename,
> -                                              high, ram_size - high);
> +                                              high, machine->ram_size - high);
>   
>               if (initrd_size < 0) {
>                   error_report("couldn't load ram disk '%s'",
> @@ -290,7 +287,7 @@ static void virtex_init(MachineState *machine)
>           boot_info.fdt = high + (8192 * 2);
>           boot_info.fdt &= ~8191;
>   
> -        xilinx_load_device_tree(boot_info.fdt, ram_size,
> +        xilinx_load_device_tree(boot_info.fdt, machine->ram_size,
>                                   initrd_base, initrd_size,
>                                   kernel_cmdline);
>       }
> @@ -302,6 +299,7 @@ static void virtex_machine_init(MachineClass *mc)
>       mc->desc = "Xilinx Virtex ML507 reference design";
>       mc->init = virtex_init;
>       mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("440-xilinx");
> +    mc->default_ram_id = "ram";
>   }
>   
>   DEFINE_MACHINE("virtex-ml507", virtex_machine_init)
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
David Gibson Jan. 16, 2020, 4:31 a.m. UTC | #2
On Wed, Jan 15, 2020 at 04:07:26PM +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.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

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

Since this is (AFAICT) independent of the main purpose of your series,
I've also applied it to my ppc-for-5.0 tree.  If we get a conflict
because of that it should be easy to resolve.

> ---
> CC: david@gibson.dropbear.id.au
> CC: qemu-ppc@nongnu.org
> CC: edgar.iglesias@gmail.com
> ---
>  hw/ppc/virtex_ml507.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
> index 651d8db..b74a269 100644
> --- a/hw/ppc/virtex_ml507.c
> +++ b/hw/ppc/virtex_ml507.c
> @@ -193,7 +193,6 @@ static int xilinx_load_device_tree(hwaddr addr,
>  
>  static void virtex_init(MachineState *machine)
>  {
> -    ram_addr_t ram_size = machine->ram_size;
>      const char *kernel_filename = machine->kernel_filename;
>      const char *kernel_cmdline = machine->kernel_cmdline;
>      hwaddr initrd_base = 0;
> @@ -204,7 +203,6 @@ static void virtex_init(MachineState *machine)
>      CPUPPCState *env;
>      hwaddr ram_base = 0;
>      DriveInfo *dinfo;
> -    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
>      qemu_irq irq[32], *cpu_irq;
>      int kernel_size;
>      int i;
> @@ -221,8 +219,7 @@ static void virtex_init(MachineState *machine)
>  
>      qemu_register_reset(main_cpu_reset, cpu);
>  
> -    memory_region_allocate_system_memory(phys_ram, NULL, "ram", ram_size);
> -    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
> +    memory_region_add_subregion(address_space_mem, ram_base, machine->ram);
>  
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      pflash_cfi01_register(PFLASH_BASEADDR, "virtex.flash", FLASH_SIZE,
> @@ -265,7 +262,7 @@ static void virtex_init(MachineState *machine)
>              /* If we failed loading ELF's try a raw image.  */
>              kernel_size = load_image_targphys(kernel_filename,
>                                                boot_offset,
> -                                              ram_size);
> +                                              machine->ram_size);
>              boot_info.bootstrap_pc = boot_offset;
>              high = boot_info.bootstrap_pc + kernel_size + 8192;
>          }
> @@ -276,7 +273,7 @@ static void virtex_init(MachineState *machine)
>          if (machine->initrd_filename) {
>              initrd_base = high = ROUND_UP(high, 4);
>              initrd_size = load_image_targphys(machine->initrd_filename,
> -                                              high, ram_size - high);
> +                                              high, machine->ram_size - high);
>  
>              if (initrd_size < 0) {
>                  error_report("couldn't load ram disk '%s'",
> @@ -290,7 +287,7 @@ static void virtex_init(MachineState *machine)
>          boot_info.fdt = high + (8192 * 2);
>          boot_info.fdt &= ~8191;
>  
> -        xilinx_load_device_tree(boot_info.fdt, ram_size,
> +        xilinx_load_device_tree(boot_info.fdt, machine->ram_size,
>                                  initrd_base, initrd_size,
>                                  kernel_cmdline);
>      }
> @@ -302,6 +299,7 @@ static void virtex_machine_init(MachineClass *mc)
>      mc->desc = "Xilinx Virtex ML507 reference design";
>      mc->init = virtex_init;
>      mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("440-xilinx");
> +    mc->default_ram_id = "ram";
>  }
>  
>  DEFINE_MACHINE("virtex-ml507", virtex_machine_init)
David Gibson Jan. 16, 2020, 4:35 a.m. UTC | #3
On Wed, Jan 15, 2020 at 04:07:26PM +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.
> 
> 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
> CC: edgar.iglesias@gmail.com
> ---
>  hw/ppc/virtex_ml507.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
> index 651d8db..b74a269 100644
> --- a/hw/ppc/virtex_ml507.c
> +++ b/hw/ppc/virtex_ml507.c
> @@ -193,7 +193,6 @@ static int xilinx_load_device_tree(hwaddr addr,
>  
>  static void virtex_init(MachineState *machine)
>  {
> -    ram_addr_t ram_size = machine->ram_size;
>      const char *kernel_filename = machine->kernel_filename;
>      const char *kernel_cmdline = machine->kernel_cmdline;
>      hwaddr initrd_base = 0;
> @@ -204,7 +203,6 @@ static void virtex_init(MachineState *machine)
>      CPUPPCState *env;
>      hwaddr ram_base = 0;
>      DriveInfo *dinfo;
> -    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
>      qemu_irq irq[32], *cpu_irq;
>      int kernel_size;
>      int i;
> @@ -221,8 +219,7 @@ static void virtex_init(MachineState *machine)
>  
>      qemu_register_reset(main_cpu_reset, cpu);
>  
> -    memory_region_allocate_system_memory(phys_ram, NULL, "ram", ram_size);
> -    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
> +    memory_region_add_subregion(address_space_mem, ram_base, machine->ram);
>  
>      dinfo = drive_get(IF_PFLASH, 0, 0);
>      pflash_cfi01_register(PFLASH_BASEADDR, "virtex.flash", FLASH_SIZE,
> @@ -265,7 +262,7 @@ static void virtex_init(MachineState *machine)
>              /* If we failed loading ELF's try a raw image.  */
>              kernel_size = load_image_targphys(kernel_filename,
>                                                boot_offset,
> -                                              ram_size);
> +                                              machine->ram_size);
>              boot_info.bootstrap_pc = boot_offset;
>              high = boot_info.bootstrap_pc + kernel_size + 8192;
>          }
> @@ -276,7 +273,7 @@ static void virtex_init(MachineState *machine)
>          if (machine->initrd_filename) {
>              initrd_base = high = ROUND_UP(high, 4);
>              initrd_size = load_image_targphys(machine->initrd_filename,
> -                                              high, ram_size - high);
> +                                              high, machine->ram_size - high);
>  
>              if (initrd_size < 0) {
>                  error_report("couldn't load ram disk '%s'",
> @@ -290,7 +287,7 @@ static void virtex_init(MachineState *machine)
>          boot_info.fdt = high + (8192 * 2);
>          boot_info.fdt &= ~8191;
>  
> -        xilinx_load_device_tree(boot_info.fdt, ram_size,
> +        xilinx_load_device_tree(boot_info.fdt, machine->ram_size,
>                                  initrd_base, initrd_size,
>                                  kernel_cmdline);
>      }
> @@ -302,6 +299,7 @@ static void virtex_machine_init(MachineClass *mc)
>      mc->desc = "Xilinx Virtex ML507 reference design";
>      mc->init = virtex_init;
>      mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("440-xilinx");
> +    mc->default_ram_id = "ram";
>  }
>  
>  DEFINE_MACHINE("virtex-ml507", virtex_machine_init)
Igor Mammedov Jan. 16, 2020, 12:12 p.m. UTC | #4
On Thu, 16 Jan 2020 14:31:57 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Wed, Jan 15, 2020 at 04:07:26PM +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.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>  
> 
> Acked-by: David Gibson <david@gibson.dropbear.id.au>
> 
> Since this is (AFAICT) independent of the main purpose of your series,
> I've also applied it to my ppc-for-5.0 tree.  If we get a conflict
> because of that it should be easy to resolve.

this patch depends on 1-5/86 as prerequsites,
so pls drop it from your queue.

What could be merged independently is patches with following
phrases in title:
 "drop RAM size fixup"
 "add RAM size checks"
that should help by reducing size of this series a bit.


> > ---
> > CC: david@gibson.dropbear.id.au
> > CC: qemu-ppc@nongnu.org
> > CC: edgar.iglesias@gmail.com
> > ---
> >  hw/ppc/virtex_ml507.c | 12 +++++-------
> >  1 file changed, 5 insertions(+), 7 deletions(-)
> > 
> > diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
> > index 651d8db..b74a269 100644
> > --- a/hw/ppc/virtex_ml507.c
> > +++ b/hw/ppc/virtex_ml507.c
> > @@ -193,7 +193,6 @@ static int xilinx_load_device_tree(hwaddr addr,
> >  
> >  static void virtex_init(MachineState *machine)
> >  {
> > -    ram_addr_t ram_size = machine->ram_size;
> >      const char *kernel_filename = machine->kernel_filename;
> >      const char *kernel_cmdline = machine->kernel_cmdline;
> >      hwaddr initrd_base = 0;
> > @@ -204,7 +203,6 @@ static void virtex_init(MachineState *machine)
> >      CPUPPCState *env;
> >      hwaddr ram_base = 0;
> >      DriveInfo *dinfo;
> > -    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
> >      qemu_irq irq[32], *cpu_irq;
> >      int kernel_size;
> >      int i;
> > @@ -221,8 +219,7 @@ static void virtex_init(MachineState *machine)
> >  
> >      qemu_register_reset(main_cpu_reset, cpu);
> >  
> > -    memory_region_allocate_system_memory(phys_ram, NULL, "ram", ram_size);
> > -    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
> > +    memory_region_add_subregion(address_space_mem, ram_base, machine->ram);
> >  
> >      dinfo = drive_get(IF_PFLASH, 0, 0);
> >      pflash_cfi01_register(PFLASH_BASEADDR, "virtex.flash", FLASH_SIZE,
> > @@ -265,7 +262,7 @@ static void virtex_init(MachineState *machine)
> >              /* If we failed loading ELF's try a raw image.  */
> >              kernel_size = load_image_targphys(kernel_filename,
> >                                                boot_offset,
> > -                                              ram_size);
> > +                                              machine->ram_size);
> >              boot_info.bootstrap_pc = boot_offset;
> >              high = boot_info.bootstrap_pc + kernel_size + 8192;
> >          }
> > @@ -276,7 +273,7 @@ static void virtex_init(MachineState *machine)
> >          if (machine->initrd_filename) {
> >              initrd_base = high = ROUND_UP(high, 4);
> >              initrd_size = load_image_targphys(machine->initrd_filename,
> > -                                              high, ram_size - high);
> > +                                              high, machine->ram_size - high);
> >  
> >              if (initrd_size < 0) {
> >                  error_report("couldn't load ram disk '%s'",
> > @@ -290,7 +287,7 @@ static void virtex_init(MachineState *machine)
> >          boot_info.fdt = high + (8192 * 2);
> >          boot_info.fdt &= ~8191;
> >  
> > -        xilinx_load_device_tree(boot_info.fdt, ram_size,
> > +        xilinx_load_device_tree(boot_info.fdt, machine->ram_size,
> >                                  initrd_base, initrd_size,
> >                                  kernel_cmdline);
> >      }
> > @@ -302,6 +299,7 @@ static void virtex_machine_init(MachineClass *mc)
> >      mc->desc = "Xilinx Virtex ML507 reference design";
> >      mc->init = virtex_init;
> >      mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("440-xilinx");
> > +    mc->default_ram_id = "ram";
> >  }
> >  
> >  DEFINE_MACHINE("virtex-ml507", virtex_machine_init)  
>

Patch
diff mbox series

diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
index 651d8db..b74a269 100644
--- a/hw/ppc/virtex_ml507.c
+++ b/hw/ppc/virtex_ml507.c
@@ -193,7 +193,6 @@  static int xilinx_load_device_tree(hwaddr addr,
 
 static void virtex_init(MachineState *machine)
 {
-    ram_addr_t ram_size = machine->ram_size;
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     hwaddr initrd_base = 0;
@@ -204,7 +203,6 @@  static void virtex_init(MachineState *machine)
     CPUPPCState *env;
     hwaddr ram_base = 0;
     DriveInfo *dinfo;
-    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
     qemu_irq irq[32], *cpu_irq;
     int kernel_size;
     int i;
@@ -221,8 +219,7 @@  static void virtex_init(MachineState *machine)
 
     qemu_register_reset(main_cpu_reset, cpu);
 
-    memory_region_allocate_system_memory(phys_ram, NULL, "ram", ram_size);
-    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
+    memory_region_add_subregion(address_space_mem, ram_base, machine->ram);
 
     dinfo = drive_get(IF_PFLASH, 0, 0);
     pflash_cfi01_register(PFLASH_BASEADDR, "virtex.flash", FLASH_SIZE,
@@ -265,7 +262,7 @@  static void virtex_init(MachineState *machine)
             /* If we failed loading ELF's try a raw image.  */
             kernel_size = load_image_targphys(kernel_filename,
                                               boot_offset,
-                                              ram_size);
+                                              machine->ram_size);
             boot_info.bootstrap_pc = boot_offset;
             high = boot_info.bootstrap_pc + kernel_size + 8192;
         }
@@ -276,7 +273,7 @@  static void virtex_init(MachineState *machine)
         if (machine->initrd_filename) {
             initrd_base = high = ROUND_UP(high, 4);
             initrd_size = load_image_targphys(machine->initrd_filename,
-                                              high, ram_size - high);
+                                              high, machine->ram_size - high);
 
             if (initrd_size < 0) {
                 error_report("couldn't load ram disk '%s'",
@@ -290,7 +287,7 @@  static void virtex_init(MachineState *machine)
         boot_info.fdt = high + (8192 * 2);
         boot_info.fdt &= ~8191;
 
-        xilinx_load_device_tree(boot_info.fdt, ram_size,
+        xilinx_load_device_tree(boot_info.fdt, machine->ram_size,
                                 initrd_base, initrd_size,
                                 kernel_cmdline);
     }
@@ -302,6 +299,7 @@  static void virtex_machine_init(MachineClass *mc)
     mc->desc = "Xilinx Virtex ML507 reference design";
     mc->init = virtex_init;
     mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("440-xilinx");
+    mc->default_ram_id = "ram";
 }
 
 DEFINE_MACHINE("virtex-ml507", virtex_machine_init)