qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 7/8] hw/mips/fuloong2e: Add highmem support


From: Huacai Chen
Subject: Re: [PATCH v2 7/8] hw/mips/fuloong2e: Add highmem support
Date: Tue, 22 Dec 2020 09:13:35 +0800

Reviewed-by: Huacai Chen <chenhuacai@kernel.org>

On Tue, Dec 22, 2020 at 4:35 AM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> On 12/19/20 8:23 AM, Jiaxun Yang wrote:
> > highmem started from 0x20000000.
>
> "started from" -> "starts at"?
>
> > Now we can have up to 2G RAM.
> >
> > Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> > ---
> > v2: Handle SPD for dual DIMM correctly.
> > ---
> >  hw/mips/fuloong2e.c | 61 ++++++++++++++++++++++++++++++++++++---------
> >  1 file changed, 49 insertions(+), 12 deletions(-)
> >
> > diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c
> > index 2744b211fd..8a4bebe066 100644
> > --- a/hw/mips/fuloong2e.c
> > +++ b/hw/mips/fuloong2e.c
> > @@ -56,6 +56,7 @@
> >  /* Fuloong 2e has a 512k flash: Winbond W39L040AP70Z */
> >  #define BIOS_SIZE               (512 * KiB)
> >  #define MAX_IDE_BUS             2
> > +#define HIGHMEM_START           0x20000000
> >
> >  /*
> >   * PMON is not part of qemu and released with BSD license, anyone
> > @@ -71,7 +72,8 @@
> >  #define FULOONG2E_RTL8139_SLOT    7
> >
> >  static struct _loaderparams {
> > -    int ram_size;
> > +    int ram_low_size;
> > +    int ram_high_size;
> >      const char *kernel_filename;
> >      const char *kernel_cmdline;
> >      const char *initrd_filename;
> > @@ -128,14 +130,14 @@ static uint64_t load_kernel(MIPSCPU *cpu)
> >          initrd_size = get_image_size(loaderparams.initrd_filename);
> >          if (initrd_size > 0) {
> >              initrd_offset = ROUND_UP(kernel_high, INITRD_PAGE_SIZE);
> > -            if (initrd_offset + initrd_size > loaderparams.ram_size) {
> > +            if (initrd_offset + initrd_size > loaderparams.ram_low_size) {
> >                  error_report("memory too small for initial ram disk '%s'",
> >                               loaderparams.initrd_filename);
> >                  exit(1);
> >              }
> >              initrd_size = load_image_targphys(loaderparams.initrd_filename,
> >                                                initrd_offset,
> > -                                              loaderparams.ram_size - 
> > initrd_offset);
> > +                                              loaderparams.ram_low_size - 
> > initrd_offset);
> >          }
> >          if (initrd_size == (target_ulong) -1) {
> >              error_report("could not load initial ram disk '%s'",
> > @@ -160,7 +162,11 @@ static uint64_t load_kernel(MIPSCPU *cpu)
> >
> >      /* Setup minimum environment variables */
> >      prom_set(prom_buf, index++, "cpuclock=%u", clock_get_hz(cpu->clock));
> > -    prom_set(prom_buf, index++, "memsize=%"PRIi64, loaderparams.ram_size / 
> > MiB);
> > +    prom_set(prom_buf, index++, "memsize=%"PRIi64, 
> > loaderparams.ram_low_size / MiB);
> > +    if (loaderparams.ram_high_size > 0) {
> > +            prom_set(prom_buf, index++, "highmemsize=%"PRIi64,
> > +                    loaderparams.ram_high_size / MiB);
> > +    }
> >      prom_set(prom_buf, index++, NULL);
> >
> >      rom_add_blob_fixed("prom", prom_buf, prom_size, ENVP_PADDR);
> > @@ -186,7 +192,7 @@ static void write_bootloader(CPUMIPSState *env, uint8_t 
> > *base,
> >      p = (uint32_t *)(base + 0x040);
> >
> >      bl_gen_jump_kernel(&p, ENVP_VADDR - 64, 2, ENVP_VADDR,
> > -                       ENVP_VADDR + 8, loaderparams.ram_size,
> > +                       ENVP_VADDR + 8, loaderparams.ram_low_size,
> >                         kernel_addr);
> >  }
> >
> > @@ -258,8 +264,11 @@ static void mips_fuloong2e_init(MachineState *machine)
> >      const char *kernel_filename = machine->kernel_filename;
> >      const char *kernel_cmdline = machine->kernel_cmdline;
> >      const char *initrd_filename = machine->initrd_filename;
> > +    ram_addr_t ram_low_size, ram_high_size = 0;
> >      char *filename;
> >      MemoryRegion *address_space_mem = get_system_memory();
> > +    MemoryRegion *ram_low_alias = g_new(MemoryRegion, 1);
> > +    MemoryRegion *ram_high_alias;
> >      MemoryRegion *bios = g_new(MemoryRegion, 1);
> >      long bios_size;
> >      uint8_t *spd_data;
> > @@ -282,12 +291,31 @@ static void mips_fuloong2e_init(MachineState *machine)
> >
> >      qemu_register_reset(main_cpu_reset, cpu);
> >
> > -    /* TODO: support more than 256M RAM as highmem */
> > -    if (machine->ram_size != 256 * MiB) {
> > -        error_report("Invalid RAM size, should be 256MB");
> > +    if (machine->ram_size > 2 * GiB) {
> > +        error_report("Too much memory for this machine: %" PRId64 "MB,"
> > +                     " maximum 2048MB", machine->ram_size / MiB);
> >          exit(EXIT_FAILURE);
> >      }
> > -    memory_region_add_subregion(address_space_mem, 0, machine->ram);
> > +
> > +    ram_low_size = MIN(machine->ram_size, 256 * MiB);
> > +
> > +    memory_region_init_alias(ram_low_alias, NULL,
> > +                            "ram_low_alias",
> > +                            machine->ram, 0,
> > +                            ram_low_size);
> > +    memory_region_add_subregion(address_space_mem, 0,
> > +                                ram_low_alias);
> > +
> > +    if (machine->ram_size > 256 * MiB) {
> > +        ram_high_alias = g_new(MemoryRegion, 1);
> > +        ram_high_size = machine->ram_size - ram_low_size;
> > +        memory_region_init_alias(ram_high_alias, NULL,
> > +                                "ram_high_alias",
> > +                                machine->ram, ram_low_size,
> > +                                ram_high_size);
> > +        memory_region_add_subregion(address_space_mem, HIGHMEM_START,
> > +                                    ram_high_alias);
>
> Cool, I've been using the same patch for one year. It works fine with
> a Linux kernel which doesn't change the northbridge mapping. As there
> is no plan for using another bootloader than PMON with this machine,
> that is fine.
>
> > +    }
> >
> >      /* Boot ROM */
> >      memory_region_init_rom(bios, NULL, "fuloong2e.bios", BIOS_SIZE,
> > @@ -300,7 +328,8 @@ static void mips_fuloong2e_init(MachineState *machine)
> >       */
> >
> >      if (kernel_filename) {
> > -        loaderparams.ram_size = machine->ram_size;
> > +        loaderparams.ram_low_size = ram_low_size;
> > +        loaderparams.ram_high_size = ram_high_size;
> >          loaderparams.kernel_filename = kernel_filename;
> >          loaderparams.kernel_cmdline = kernel_cmdline;
> >          loaderparams.initrd_filename = initrd_filename;
> > @@ -345,8 +374,16 @@ static void mips_fuloong2e_init(MachineState *machine)
> >      }
> >
> >      /* Populate SPD eeprom data */
> > -    spd_data = spd_data_generate(DDR, machine->ram_size);
> > -    smbus_eeprom_init_one(smbus, 0x50, spd_data);
> > +    if (machine->ram_size <= 1 * GiB) {
> > +        /* It supports maxium of 1 GiB per DIMM */
>
> Typo "maximum".
>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
> > +        spd_data = spd_data_generate(DDR, machine->ram_size);
> > +        smbus_eeprom_init_one(smbus, 0x50, spd_data);
> > +    } else {
> > +        /* Split to dual DIMM for more than 1 GiB  */
> > +        spd_data = spd_data_generate(DDR, machine->ram_size / 2);
> > +        smbus_eeprom_init_one(smbus, 0x50, spd_data);
> > +        smbus_eeprom_init_one(smbus, 0x51, spd_data);
> > +    }
> >
> >      mc146818_rtc_init(isa_bus, 2000, NULL);
> >
> >



reply via email to

[Prev in Thread] Current Thread [Next in Thread]