All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiaxun Yang <jiaxun.yang@flygoat.com>
To: qemu-devel@nongnu.org
Cc: chenhuacai@kernel.org, f4bug@amsat.org, wainersm@redhat.com,
	crosa@redhat.com
Subject: [PATCH v2 7/8] hw/mips/fuloong2e: Add highmem support
Date: Sat, 19 Dec 2020 15:23:25 +0800	[thread overview]
Message-ID: <20201219072326.40157-1-jiaxun.yang@flygoat.com> (raw)
In-Reply-To: <20201219071235.35040-1-jiaxun.yang@flygoat.com>

highmem started from 0x20000000.
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);
+    }
 
     /* 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 */
+        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);
 
-- 
2.29.2


  parent reply	other threads:[~2020-12-19  7:25 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-19  7:12 [PATCH v2 0/8] hm/mips/fuloong2e fixes Jiaxun Yang
2020-12-19  7:12 ` [PATCH v2 1/8] hw/mips/fuloong2e: Remove define DEBUG_FULOONG2E_INIT Jiaxun Yang
2020-12-22  0:26   ` Huacai Chen
2020-12-19  7:12 ` [PATCH v2 2/8] hw/mips/fuloong2e: Relpace fault links Jiaxun Yang
2020-12-19 17:52   ` Philippe Mathieu-Daudé
2020-12-22  0:30     ` Huacai Chen
2020-12-19  7:18 ` [PATCH v2 3/8] hw/pci-host/bonito: Fixup IRQ mapping Jiaxun Yang
2020-12-21 21:06   ` Philippe Mathieu-Daudé
2020-12-19  7:18 ` [PATCH v2 4/8] hw/pci-host/bonito: Fixup pci.lomem mapping Jiaxun Yang
2020-12-21 20:45   ` Philippe Mathieu-Daudé
2020-12-22  0:36     ` Jiaxun Yang
2020-12-22 12:13       ` Philippe Mathieu-Daudé
2020-12-19  7:21 ` [PATCH v2 5/8] hw/mips/fuloong2e: Remove unused env entry Jiaxun Yang
2020-12-22  0:27   ` Huacai Chen
2020-12-22 14:42   ` Philippe Mathieu-Daudé
2020-12-19  7:21 ` [PATCH v2 6/8] hw/mips/fuloong2e: Correct cpuclock env Jiaxun Yang
2020-12-19 18:22   ` Philippe Mathieu-Daudé
2020-12-22  0:28     ` Huacai Chen
2020-12-19  7:23 ` Jiaxun Yang [this message]
2020-12-19 19:02   ` [PATCH v2 7/8] hw/mips/fuloong2e: Add highmem support Philippe Mathieu-Daudé
2020-12-21 20:34   ` Philippe Mathieu-Daudé
2020-12-22  1:13     ` Huacai Chen
2020-12-19  7:23 ` [PATCH v2 8/8] tests/acceptance: Test boot_linux_console for fuloong2e Jiaxun Yang
2020-12-19 18:57   ` Philippe Mathieu-Daudé
2020-12-21 21:17   ` Wainer dos Santos Moschetta
2020-12-21 21:35   ` Willian Rampazzo
2020-12-22  0:24     ` Huacai Chen
2020-12-19 12:13 ` [PATCH v2 0/8] hm/mips/fuloong2e fixes BALATON Zoltan via
2020-12-19 12:37   ` Jiaxun Yang
2020-12-19 16:03     ` BALATON Zoltan via
2020-12-21  9:52       ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201219072326.40157-1-jiaxun.yang@flygoat.com \
    --to=jiaxun.yang@flygoat.com \
    --cc=chenhuacai@kernel.org \
    --cc=crosa@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wainersm@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.