[v2,68/86] ppc:prep: use memdev for RAM
diff mbox series

Message ID 1579100861-73692-69-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: hpoussin@reactos.org
CC: david@gibson.dropbear.id.au
CC: qemu-ppc@nongnu.org
---
 hw/ppc/prep.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

David Gibson Jan. 16, 2020, 4:26 a.m. UTC | #1
On Wed, Jan 15, 2020 at 04:07:23PM +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>

Although it's probably fairly pointless, since I'm looking to merge a
patch removing prep entirely soon.

> ---
> CC: hpoussin@reactos.org
> CC: david@gibson.dropbear.id.au
> CC: qemu-ppc@nongnu.org
> ---
>  hw/ppc/prep.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
> index 862345c..bf75dde 100644
> --- a/hw/ppc/prep.c
> +++ b/hw/ppc/prep.c
> @@ -400,7 +400,6 @@ static int PPC_NVRAM_set_params (Nvram *nvram, uint16_t NVRAM_size,
>  /* PowerPC PREP hardware initialisation */
>  static void ppc_prep_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;
>      const char *initrd_filename = machine->initrd_filename;
> @@ -413,7 +412,6 @@ static void ppc_prep_init(MachineState *machine)
>      MemoryRegion *xcsr = g_new(MemoryRegion, 1);
>  #endif
>      int linux_boot, i, nb_nics1;
> -    MemoryRegion *ram = g_new(MemoryRegion, 1);
>      uint32_t kernel_base, initrd_base;
>      long kernel_size, initrd_size;
>      DeviceState *dev;
> @@ -444,15 +442,14 @@ static void ppc_prep_init(MachineState *machine)
>          qemu_register_reset(ppc_prep_reset, cpu);
>      }
>  
> -    /* allocate RAM */
> -    memory_region_allocate_system_memory(ram, NULL, "ppc_prep.ram", ram_size);
> -    memory_region_add_subregion(sysmem, 0, ram);
> +    /* map RAM */
> +    memory_region_add_subregion(sysmem, 0, machine->ram);
>  
>      if (linux_boot) {
>          kernel_base = KERNEL_LOAD_ADDR;
>          /* now we can load the kernel */
>          kernel_size = load_image_targphys(kernel_filename, kernel_base,
> -                                          ram_size - kernel_base);
> +                                          machine->ram_size - kernel_base);
>          if (kernel_size < 0) {
>              error_report("could not load kernel '%s'", kernel_filename);
>              exit(1);
> @@ -461,7 +458,7 @@ static void ppc_prep_init(MachineState *machine)
>          if (initrd_filename) {
>              initrd_base = INITRD_LOAD_ADDR;
>              initrd_size = load_image_targphys(initrd_filename, initrd_base,
> -                                              ram_size - initrd_base);
> +                                              machine->ram_size - initrd_base);
>              if (initrd_size < 0) {
>                  error_report("could not load initial ram disk '%s'",
>                               initrd_filename);
> @@ -576,7 +573,7 @@ static void ppc_prep_init(MachineState *machine)
>      sysctrl->nvram = m48t59;
>  
>      /* Initialise NVRAM */
> -    PPC_NVRAM_set_params(m48t59, NVRAM_SIZE, "PREP", ram_size,
> +    PPC_NVRAM_set_params(m48t59, NVRAM_SIZE, "PREP", machine->ram_size,
>                           ppc_boot_device,
>                           kernel_base, kernel_size,
>                           kernel_cmdline,
> @@ -596,6 +593,7 @@ static void prep_machine_init(MachineClass *mc)
>      mc->default_boot_order = "cad";
>      mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("602");
>      mc->default_display = "std";
> +    mc->default_ram_id = "ppc_prep.ram";
>  }
>  
>  static int prep_set_cmos_checksum(DeviceState *dev, void *opaque)
> @@ -814,6 +812,7 @@ static void ibm_40p_machine_init(MachineClass *mc)
>      mc->init = ibm_40p_init;
>      mc->max_cpus = 1;
>      mc->default_ram_size = 128 * MiB;
> +    mc->default_ram_id = "ppc_prep.ram";
>      mc->block_default_type = IF_SCSI;
>      mc->default_boot_order = "c";
>      mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("604");
Mark Cave-Ayland Jan. 16, 2020, 8:50 a.m. UTC | #2
On 15/01/2020 15:07, 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: hpoussin@reactos.org
> CC: david@gibson.dropbear.id.au
> CC: qemu-ppc@nongnu.org
> ---
>  hw/ppc/prep.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
> index 862345c..bf75dde 100644
> --- a/hw/ppc/prep.c
> +++ b/hw/ppc/prep.c
> @@ -400,7 +400,6 @@ static int PPC_NVRAM_set_params (Nvram *nvram, uint16_t NVRAM_size,
>  /* PowerPC PREP hardware initialisation */
>  static void ppc_prep_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;
>      const char *initrd_filename = machine->initrd_filename;
> @@ -413,7 +412,6 @@ static void ppc_prep_init(MachineState *machine)
>      MemoryRegion *xcsr = g_new(MemoryRegion, 1);
>  #endif
>      int linux_boot, i, nb_nics1;
> -    MemoryRegion *ram = g_new(MemoryRegion, 1);
>      uint32_t kernel_base, initrd_base;
>      long kernel_size, initrd_size;
>      DeviceState *dev;
> @@ -444,15 +442,14 @@ static void ppc_prep_init(MachineState *machine)
>          qemu_register_reset(ppc_prep_reset, cpu);
>      }
>  
> -    /* allocate RAM */
> -    memory_region_allocate_system_memory(ram, NULL, "ppc_prep.ram", ram_size);
> -    memory_region_add_subregion(sysmem, 0, ram);
> +    /* map RAM */
> +    memory_region_add_subregion(sysmem, 0, machine->ram);
>  
>      if (linux_boot) {
>          kernel_base = KERNEL_LOAD_ADDR;
>          /* now we can load the kernel */
>          kernel_size = load_image_targphys(kernel_filename, kernel_base,
> -                                          ram_size - kernel_base);
> +                                          machine->ram_size - kernel_base);
>          if (kernel_size < 0) {
>              error_report("could not load kernel '%s'", kernel_filename);
>              exit(1);
> @@ -461,7 +458,7 @@ static void ppc_prep_init(MachineState *machine)
>          if (initrd_filename) {
>              initrd_base = INITRD_LOAD_ADDR;
>              initrd_size = load_image_targphys(initrd_filename, initrd_base,
> -                                              ram_size - initrd_base);
> +                                              machine->ram_size - initrd_base);
>              if (initrd_size < 0) {
>                  error_report("could not load initial ram disk '%s'",
>                               initrd_filename);
> @@ -576,7 +573,7 @@ static void ppc_prep_init(MachineState *machine)
>      sysctrl->nvram = m48t59;
>  
>      /* Initialise NVRAM */
> -    PPC_NVRAM_set_params(m48t59, NVRAM_SIZE, "PREP", ram_size,
> +    PPC_NVRAM_set_params(m48t59, NVRAM_SIZE, "PREP", machine->ram_size,
>                           ppc_boot_device,
>                           kernel_base, kernel_size,
>                           kernel_cmdline,
> @@ -596,6 +593,7 @@ static void prep_machine_init(MachineClass *mc)
>      mc->default_boot_order = "cad";
>      mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("602");
>      mc->default_display = "std";
> +    mc->default_ram_id = "ppc_prep.ram";
>  }
>  
>  static int prep_set_cmos_checksum(DeviceState *dev, void *opaque)
> @@ -814,6 +812,7 @@ static void ibm_40p_machine_init(MachineClass *mc)
>      mc->init = ibm_40p_init;
>      mc->max_cpus = 1;
>      mc->default_ram_size = 128 * MiB;
> +    mc->default_ram_id = "ppc_prep.ram";
>      mc->block_default_type = IF_SCSI;
>      mc->default_boot_order = "c";
>      mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("604");

Note that the prep machine is scheduled for removal soon (I believe Thomas has posted
a patch on-list for this), but the 40p part looks fine.

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


ATB,

Mark.
Igor Mammedov Jan. 16, 2020, 12:15 p.m. UTC | #3
On Thu, 16 Jan 2020 14:26:58 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Wed, Jan 15, 2020 at 04:07:23PM +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>
> 
> Although it's probably fairly pointless, since I'm looking to merge a
> patch removing prep entirely soon.

I know,
if that gets merged first, I'll just drop these on respin

> 
> > ---
> > CC: hpoussin@reactos.org
> > CC: david@gibson.dropbear.id.au
> > CC: qemu-ppc@nongnu.org
> > ---
> >  hw/ppc/prep.c | 15 +++++++--------
> >  1 file changed, 7 insertions(+), 8 deletions(-)
> > 
> > diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
> > index 862345c..bf75dde 100644
> > --- a/hw/ppc/prep.c
> > +++ b/hw/ppc/prep.c
> > @@ -400,7 +400,6 @@ static int PPC_NVRAM_set_params (Nvram *nvram, uint16_t NVRAM_size,
> >  /* PowerPC PREP hardware initialisation */
> >  static void ppc_prep_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;
> >      const char *initrd_filename = machine->initrd_filename;
> > @@ -413,7 +412,6 @@ static void ppc_prep_init(MachineState *machine)
> >      MemoryRegion *xcsr = g_new(MemoryRegion, 1);
> >  #endif
> >      int linux_boot, i, nb_nics1;
> > -    MemoryRegion *ram = g_new(MemoryRegion, 1);
> >      uint32_t kernel_base, initrd_base;
> >      long kernel_size, initrd_size;
> >      DeviceState *dev;
> > @@ -444,15 +442,14 @@ static void ppc_prep_init(MachineState *machine)
> >          qemu_register_reset(ppc_prep_reset, cpu);
> >      }
> >  
> > -    /* allocate RAM */
> > -    memory_region_allocate_system_memory(ram, NULL, "ppc_prep.ram", ram_size);
> > -    memory_region_add_subregion(sysmem, 0, ram);
> > +    /* map RAM */
> > +    memory_region_add_subregion(sysmem, 0, machine->ram);
> >  
> >      if (linux_boot) {
> >          kernel_base = KERNEL_LOAD_ADDR;
> >          /* now we can load the kernel */
> >          kernel_size = load_image_targphys(kernel_filename, kernel_base,
> > -                                          ram_size - kernel_base);
> > +                                          machine->ram_size - kernel_base);
> >          if (kernel_size < 0) {
> >              error_report("could not load kernel '%s'", kernel_filename);
> >              exit(1);
> > @@ -461,7 +458,7 @@ static void ppc_prep_init(MachineState *machine)
> >          if (initrd_filename) {
> >              initrd_base = INITRD_LOAD_ADDR;
> >              initrd_size = load_image_targphys(initrd_filename, initrd_base,
> > -                                              ram_size - initrd_base);
> > +                                              machine->ram_size - initrd_base);
> >              if (initrd_size < 0) {
> >                  error_report("could not load initial ram disk '%s'",
> >                               initrd_filename);
> > @@ -576,7 +573,7 @@ static void ppc_prep_init(MachineState *machine)
> >      sysctrl->nvram = m48t59;
> >  
> >      /* Initialise NVRAM */
> > -    PPC_NVRAM_set_params(m48t59, NVRAM_SIZE, "PREP", ram_size,
> > +    PPC_NVRAM_set_params(m48t59, NVRAM_SIZE, "PREP", machine->ram_size,
> >                           ppc_boot_device,
> >                           kernel_base, kernel_size,
> >                           kernel_cmdline,
> > @@ -596,6 +593,7 @@ static void prep_machine_init(MachineClass *mc)
> >      mc->default_boot_order = "cad";
> >      mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("602");
> >      mc->default_display = "std";
> > +    mc->default_ram_id = "ppc_prep.ram";
> >  }
> >  
> >  static int prep_set_cmos_checksum(DeviceState *dev, void *opaque)
> > @@ -814,6 +812,7 @@ static void ibm_40p_machine_init(MachineClass *mc)
> >      mc->init = ibm_40p_init;
> >      mc->max_cpus = 1;
> >      mc->default_ram_size = 128 * MiB;
> > +    mc->default_ram_id = "ppc_prep.ram";
> >      mc->block_default_type = IF_SCSI;
> >      mc->default_boot_order = "c";
> >      mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("604");  
>

Patch
diff mbox series

diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
index 862345c..bf75dde 100644
--- a/hw/ppc/prep.c
+++ b/hw/ppc/prep.c
@@ -400,7 +400,6 @@  static int PPC_NVRAM_set_params (Nvram *nvram, uint16_t NVRAM_size,
 /* PowerPC PREP hardware initialisation */
 static void ppc_prep_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;
     const char *initrd_filename = machine->initrd_filename;
@@ -413,7 +412,6 @@  static void ppc_prep_init(MachineState *machine)
     MemoryRegion *xcsr = g_new(MemoryRegion, 1);
 #endif
     int linux_boot, i, nb_nics1;
-    MemoryRegion *ram = g_new(MemoryRegion, 1);
     uint32_t kernel_base, initrd_base;
     long kernel_size, initrd_size;
     DeviceState *dev;
@@ -444,15 +442,14 @@  static void ppc_prep_init(MachineState *machine)
         qemu_register_reset(ppc_prep_reset, cpu);
     }
 
-    /* allocate RAM */
-    memory_region_allocate_system_memory(ram, NULL, "ppc_prep.ram", ram_size);
-    memory_region_add_subregion(sysmem, 0, ram);
+    /* map RAM */
+    memory_region_add_subregion(sysmem, 0, machine->ram);
 
     if (linux_boot) {
         kernel_base = KERNEL_LOAD_ADDR;
         /* now we can load the kernel */
         kernel_size = load_image_targphys(kernel_filename, kernel_base,
-                                          ram_size - kernel_base);
+                                          machine->ram_size - kernel_base);
         if (kernel_size < 0) {
             error_report("could not load kernel '%s'", kernel_filename);
             exit(1);
@@ -461,7 +458,7 @@  static void ppc_prep_init(MachineState *machine)
         if (initrd_filename) {
             initrd_base = INITRD_LOAD_ADDR;
             initrd_size = load_image_targphys(initrd_filename, initrd_base,
-                                              ram_size - initrd_base);
+                                              machine->ram_size - initrd_base);
             if (initrd_size < 0) {
                 error_report("could not load initial ram disk '%s'",
                              initrd_filename);
@@ -576,7 +573,7 @@  static void ppc_prep_init(MachineState *machine)
     sysctrl->nvram = m48t59;
 
     /* Initialise NVRAM */
-    PPC_NVRAM_set_params(m48t59, NVRAM_SIZE, "PREP", ram_size,
+    PPC_NVRAM_set_params(m48t59, NVRAM_SIZE, "PREP", machine->ram_size,
                          ppc_boot_device,
                          kernel_base, kernel_size,
                          kernel_cmdline,
@@ -596,6 +593,7 @@  static void prep_machine_init(MachineClass *mc)
     mc->default_boot_order = "cad";
     mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("602");
     mc->default_display = "std";
+    mc->default_ram_id = "ppc_prep.ram";
 }
 
 static int prep_set_cmos_checksum(DeviceState *dev, void *opaque)
@@ -814,6 +812,7 @@  static void ibm_40p_machine_init(MachineClass *mc)
     mc->init = ibm_40p_init;
     mc->max_cpus = 1;
     mc->default_ram_size = 128 * MiB;
+    mc->default_ram_id = "ppc_prep.ram";
     mc->block_default_type = IF_SCSI;
     mc->default_boot_order = "c";
     mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("604");