qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 1/6] Use correct types to enable > 2G support


From: Anthony Liguori
Subject: [Qemu-devel] [PATCH 1/6] Use correct types to enable > 2G support
Date: Thu, 31 Jan 2008 16:36:15 -0600

KVM supports more than 2GB of memory for x86_64 hosts.  The following patch
fixes a number of type related issues where int's were being used when they
shouldn't have been.  It also introduces CMOS support so the BIOS can build
the appropriate e820 tables.

Index: qemu/cpu-all.h
===================================================================
--- qemu.orig/cpu-all.h 2008-01-30 13:47:00.000000000 -0600
+++ qemu/cpu-all.h      2008-01-30 13:47:31.000000000 -0600
@@ -695,7 +695,7 @@
 
 /* page related stuff */
 
-#define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
+#define TARGET_PAGE_SIZE (1ul << TARGET_PAGE_BITS)
 #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
 #define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & 
TARGET_PAGE_MASK)
 
@@ -816,7 +816,7 @@
 
 /* memory API */
 
-extern int phys_ram_size;
+extern ram_addr_t phys_ram_size;
 extern int phys_ram_fd;
 extern uint8_t *phys_ram_base;
 extern uint8_t *phys_ram_dirty;
@@ -844,7 +844,7 @@
                                   unsigned long size,
                                   unsigned long phys_offset);
 uint32_t cpu_get_physical_page_desc(target_phys_addr_t addr);
-ram_addr_t qemu_ram_alloc(unsigned int size);
+ram_addr_t qemu_ram_alloc(unsigned long size);
 void qemu_ram_free(ram_addr_t addr);
 int cpu_register_io_memory(int io_index,
                            CPUReadMemoryFunc **mem_read,
Index: qemu/exec.c
===================================================================
--- qemu.orig/exec.c    2008-01-30 13:47:00.000000000 -0600
+++ qemu/exec.c 2008-01-30 13:47:31.000000000 -0600
@@ -73,9 +73,11 @@
 #define TARGET_VIRT_ADDR_SPACE_BITS 42
 #elif defined(TARGET_PPC64)
 #define TARGET_PHYS_ADDR_SPACE_BITS 42
-#else
+#elif USE_KQEMU
 /* Note: for compatibility with kqemu, we use 32 bits for x86_64 */
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
+#else
+#define TARGET_PHYS_ADDR_SPACE_BITS 42
 #endif
 
 TranslationBlock tbs[CODE_GEN_MAX_BLOCKS];
@@ -87,7 +89,7 @@
 uint8_t code_gen_buffer[CODE_GEN_BUFFER_SIZE] __attribute__((aligned (32)));
 uint8_t *code_gen_ptr;
 
-int phys_ram_size;
+ram_addr_t phys_ram_size;
 int phys_ram_fd;
 uint8_t *phys_ram_base;
 uint8_t *phys_ram_dirty;
@@ -112,7 +114,7 @@
 
 typedef struct PhysPageDesc {
     /* offset in host memory of the page + io_index in the low 12 bits */
-    uint32_t phys_offset;
+    ram_addr_t phys_offset;
 } PhysPageDesc;
 
 #define L2_BITS 10
@@ -2083,11 +2085,11 @@
 }
 
 /* XXX: better than nothing */
-ram_addr_t qemu_ram_alloc(unsigned int size)
+ram_addr_t qemu_ram_alloc(unsigned long size)
 {
     ram_addr_t addr;
     if ((phys_ram_alloc_offset + size) >= phys_ram_size) {
-        fprintf(stderr, "Not enough memory (requested_size = %u, max memory = 
%d)\n",
+        fprintf(stderr, "Not enough memory (requested_size = %lu, max memory = 
%d)\n",
                 size, phys_ram_size);
         abort();
     }
Index: qemu/hw/boards.h
===================================================================
--- qemu.orig/hw/boards.h       2008-01-30 13:47:00.000000000 -0600
+++ qemu/hw/boards.h    2008-01-30 13:47:31.000000000 -0600
@@ -3,7 +3,7 @@
 #ifndef HW_BOARDS_H
 #define HW_BOARDS_H
 
-typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size,
+typedef void QEMUMachineInitFunc(ram_addr_t ram_size, int vga_ram_size,
                                  const char *boot_device, DisplayState *ds,
                                  const char *kernel_filename,
                                  const char *kernel_cmdline,
Index: qemu/hw/pc.c
===================================================================
--- qemu.orig/hw/pc.c   2008-01-30 13:47:00.000000000 -0600
+++ qemu/hw/pc.c        2008-01-30 13:47:31.000000000 -0600
@@ -181,7 +181,8 @@
 }
 
 /* hd_table must contain 4 block drivers */
-static void cmos_init(int ram_size, const char *boot_device, BlockDriverState 
**hd_table)
+static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
+                     const char *boot_device, BlockDriverState **hd_table)
 {
     RTCState *s = rtc_state;
     int nbds, bds[3] = { 0, };
@@ -204,6 +205,12 @@
     rtc_set_memory(s, 0x30, val);
     rtc_set_memory(s, 0x31, val >> 8);
 
+    if (above_4g_mem_size) {
+        rtc_set_memory(s, 0x5b, (unsigned int)above_4g_mem_size >> 16);
+        rtc_set_memory(s, 0x5c, (unsigned int)above_4g_mem_size >> 24);
+        rtc_set_memory(s, 0x5d, above_4g_mem_size >> 32);
+    }
+
     if (ram_size > (16 * 1024 * 1024))
         val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536);
     else
@@ -697,7 +704,7 @@
 }
 
 /* PC hardware initialisation */
-static void pc_init1(int ram_size, int vga_ram_size,
+static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
                      const char *boot_device, DisplayState *ds,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename,
@@ -706,6 +713,7 @@
     char buf[1024];
     int ret, linux_boot, i;
     ram_addr_t ram_addr, vga_ram_addr, bios_offset, vga_bios_offset;
+    ram_addr_t above_4g_mem_size = 0;
     int bios_size, isa_bios_size, vga_bios_size;
     PCIBus *pci_bus;
     int piix3_devfn = -1;
@@ -717,6 +725,11 @@
     BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     BlockDriverState *fd[MAX_FD];
 
+    if (ram_size >= 0xe0000000 ) {
+        above_4g_mem_size = ram_size - 0xe0000000;
+        ram_size = 0xe0000000;
+    }
+
     linux_boot = (kernel_filename != NULL);
 
     /* init CPUs */
@@ -790,6 +803,12 @@
         exit(1);
     }
 
+    /* above 4giga memory allocation */
+    if (above_4g_mem_size > 0) {
+        ram_addr = qemu_ram_alloc(above_4g_mem_size);
+        cpu_register_physical_memory(0x100000000, above_4g_mem_size, ram_addr);
+    }
+
     /* setup basic memory access */
     cpu_register_physical_memory(0xc0000, 0x10000,
                                  vga_bios_offset | IO_MEM_ROM);
@@ -970,7 +989,7 @@
     }
     floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
 
-    cmos_init(ram_size, boot_device, hd);
+    cmos_init(ram_size, above_4g_mem_size, boot_device, hd);
 
     if (pci_enabled && usb_enabled) {
         usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
@@ -1010,7 +1029,7 @@
     }
 }
 
-static void pc_init_pci(int ram_size, int vga_ram_size,
+static void pc_init_pci(ram_addr_t ram_size, int vga_ram_size,
                         const char *boot_device, DisplayState *ds,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
@@ -1022,7 +1041,7 @@
              initrd_filename, 1, cpu_model);
 }
 
-static void pc_init_isa(int ram_size, int vga_ram_size,
+static void pc_init_isa(ram_addr_t ram_size, int vga_ram_size,
                         const char *boot_device, DisplayState *ds,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
Index: qemu/osdep.c
===================================================================
--- qemu.orig/osdep.c   2008-01-30 13:47:00.000000000 -0600
+++ qemu/osdep.c        2008-01-30 13:47:31.000000000 -0600
@@ -113,7 +113,7 @@
             int64_t free_space;
             int ram_mb;
 
-            extern int ram_size;
+            extern int64_t ram_size;
             free_space = (int64_t)stfs.f_bavail * stfs.f_bsize;
             if ((ram_size + 8192 * 1024) >= free_space) {
                 ram_mb = (ram_size / (1024 * 1024));
@@ -202,7 +202,7 @@
 #ifdef _BSD
     return valloc(size);
 #else
-    return memalign(4096, size);
+    return memalign(TARGET_PAGE_SIZE, size);
 #endif
 }
 
Index: qemu/sysemu.h
===================================================================
--- qemu.orig/sysemu.h  2008-01-30 13:47:00.000000000 -0600
+++ qemu/sysemu.h       2008-01-30 13:47:31.000000000 -0600
@@ -69,7 +69,7 @@
 /* SLIRP */
 void do_info_slirp(void);
 
-extern int ram_size;
+extern int64_t ram_size;
 extern int bios_size;
 extern int rtc_utc;
 extern int rtc_start_date;
Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c      2008-01-30 13:47:00.000000000 -0600
+++ qemu/vl.c   2008-01-30 13:47:31.000000000 -0600
@@ -142,7 +142,11 @@
 //#define DEBUG_UNUSED_IOPORT
 //#define DEBUG_IOPORT
 
+#if HOST_LONG_BITS < 64
 #define PHYS_RAM_MAX_SIZE (2047 * 1024 * 1024)
+#else
+#define PHYS_RAM_MAX_SIZE (2047 * 1024 * 1024 * 1024ULL)
+#endif
 
 #ifdef TARGET_PPC
 #define DEFAULT_RAM_SIZE 144
@@ -174,7 +178,7 @@
 int nographic;
 const char* keyboard_layout = NULL;
 int64_t ticks_per_sec;
-int ram_size;
+int64_t ram_size;
 int pit_min_timer_count = 0;
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
@@ -8460,7 +8464,7 @@
                 help(0);
                 break;
             case QEMU_OPTION_m:
-                ram_size = atoi(optarg) * 1024 * 1024;
+                ram_size = (int64_t)atoi(optarg) * 1024 * 1024;
                 if (ram_size <= 0)
                     help(1);
                 if (ram_size > PHYS_RAM_MAX_SIZE) {




reply via email to

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