[IA64] Clean up VTi memory initialization logic
authorawilliam@xenbuild2.aw <awilliam@xenbuild2.aw>
Wed, 10 Jan 2007 15:00:50 +0000 (08:00 -0700)
committerawilliam@xenbuild2.aw <awilliam@xenbuild2.aw>
Wed, 10 Jan 2007 15:00:50 +0000 (08:00 -0700)
This patch makes the logic in setup_guest() more clear.
domain_translate_gpfn_list() is now gone, so we can make
memory initializtion code simple.
Xend passes memory size which is a sum of normal memory
size and GFW memory to QEMU and Libxc. This patch fixes
this issue.

Signed-off-by: Zhang Xin <xing.z.zhang@intel.com>
tools/ioemu/vl.c
tools/libxc/ia64/xc_ia64_hvm_build.c
tools/python/xen/xend/image.py

index 6fc10c818792659d6158bb749e0e9447ac23b8cf..ffce41d1737986ac952c2ef338b2e659222bcf71 100644 (file)
@@ -6464,10 +6464,6 @@ int main(int argc, char **argv)
     }
 
 #if defined (__ia64__)
-    /* ram_size passed from xend has added on GFW memory,
-       so we must subtract it here */
-    ram_size -= 16 * MEM_M;
-
     if (ram_size > MMIO_START)
         ram_size += 1 * MEM_G; /* skip 3G-4G MMIO, LEGACY_IO_SPACE etc. */
 #endif
index 3bfa274293ff15c155dd1cced099cef37a80807f..270a6f67a27191e91f57edfef3ee08ca23260909 100644 (file)
@@ -569,18 +569,13 @@ setup_guest(int xc_handle, uint32_t dom, unsigned long memsize,
     xen_pfn_t *pfn_list;
     shared_iopage_t *sp;
     void *ioreq_buffer_page;
-    // memsize equal to normal memory size(in configure file) + 16M
-    // dom_memsize will pass to xc_ia64_build_hob(), so must be subbed 16M 
-    unsigned long dom_memsize = ((memsize - 16) << 20);
-    unsigned long nr_pages = (unsigned long)memsize << (20 - PAGE_SHIFT);
-    unsigned long normal_pages = nr_pages - GFW_PAGES;
+    unsigned long dom_memsize = memsize << 20;
+    unsigned long nr_pages = memsize << (20 - PAGE_SHIFT);
     unsigned long vcpus;
     int rc;
-    long i, j;
+    long i;
     DECLARE_DOMCTL;
 
-    // ROM size for guest firmware, ioreq page and xenstore page
-    nr_pages += 3; 
 
     if ((image_size > 12 * MEM_M) || (image_size & (PAGE_SIZE - 1))) {
         PERROR("Guest firmware size is incorrect [%ld]?", image_size);
@@ -598,20 +593,20 @@ setup_guest(int xc_handle, uint32_t dom, unsigned long memsize,
         pfn_list[i] = i;
 
     // If normal memory > 3G. Reserve 3G ~ 4G for MMIO, GFW and others.
-    for (j = (MMIO_START >> PAGE_SHIFT); j < (dom_memsize >> PAGE_SHIFT); j++)
-        pfn_list[j] += ((1 * MEM_G) >> PAGE_SHIFT);
+    for (i = (MMIO_START >> PAGE_SHIFT); i < (dom_memsize >> PAGE_SHIFT); i++)
+        pfn_list[i] += ((1 * MEM_G) >> PAGE_SHIFT);
 
     // Allocate memory for VTI guest, up to VGA hole from 0xA0000-0xC0000. 
     rc = xc_domain_memory_populate_physmap(xc_handle, dom,
-                                           (normal_pages > VGA_START_PAGE) ?
-                                           VGA_START_PAGE : normal_pages,
+                                           (nr_pages > VGA_START_PAGE) ?
+                                           VGA_START_PAGE : nr_pages,
                                            0, 0, &pfn_list[0]);
 
     // We're not likely to attempt to create a domain with less than
     // 640k of memory, but test for completeness
     if (rc == 0 && nr_pages > VGA_END_PAGE)
         rc = xc_domain_memory_populate_physmap(xc_handle, dom,
-                                               normal_pages - VGA_END_PAGE,
+                                               nr_pages - VGA_END_PAGE,
                                                0, 0, &pfn_list[VGA_END_PAGE]);
     if (rc != 0) {
         PERROR("Could not allocate normal memory for Vti guest.\n");
@@ -621,24 +616,22 @@ setup_guest(int xc_handle, uint32_t dom, unsigned long memsize,
     // We allocate additional pfn for GFW and other three pages, so
     // the pfn_list is not contiguous.  Due to this we must support
     // old interface xc_ia64_get_pfn_list().
-    // Here i = (dom_memsize >> PAGE_SHIFT)
-    for (j = 0; i < nr_pages - 3; i++, j++) 
-        pfn_list[i] = (GFW_START >> PAGE_SHIFT) + j;
+    for (i = 0; i < GFW_PAGES; i++) 
+        pfn_list[i] = (GFW_START >> PAGE_SHIFT) + i;
 
     rc = xc_domain_memory_populate_physmap(xc_handle, dom, GFW_PAGES,
-                                           0, 0, &pfn_list[normal_pages]);
+                                           0, 0, &pfn_list[0]);
     if (rc != 0) {
         PERROR("Could not allocate GFW memory for Vti guest.\n");
         goto error_out;
     }
 
-    // Here i = (dom_memsize >> PAGE_SHIFT) + GFW_PAGES
-    pfn_list[i] = IO_PAGE_START >> PAGE_SHIFT;
-    pfn_list[i+1] = STORE_PAGE_START >> PAGE_SHIFT;
-    pfn_list[i+2] = BUFFER_IO_PAGE_START >> PAGE_SHIFT; 
+    pfn_list[0] = IO_PAGE_START >> PAGE_SHIFT;
+    pfn_list[1] = STORE_PAGE_START >> PAGE_SHIFT;
+    pfn_list[2] = BUFFER_IO_PAGE_START >> PAGE_SHIFT; 
 
     rc = xc_domain_memory_populate_physmap(xc_handle, dom, 3,
-                                           0, 0, &pfn_list[nr_pages - 3]);
+                                           0, 0, &pfn_list[0]);
     if (rc != 0) {
         PERROR("Could not allocate IO page or store page or buffer io page.\n");
         goto error_out;
@@ -675,13 +668,12 @@ setup_guest(int xc_handle, uint32_t dom, unsigned long memsize,
         goto error_out;
     }
 
-    xc_set_hvm_param(xc_handle, dom,
-                     HVM_PARAM_STORE_PFN, pfn_list[nr_pages - 2]);
+    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_STORE_PFN, pfn_list[1]);
 
     // Retrieve special pages like io, xenstore, etc. 
     sp = (shared_iopage_t *)xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
                                                  PROT_READ | PROT_WRITE,
-                                                 pfn_list[nr_pages - 3]);
+                                                 pfn_list[0]);
     if (sp == 0)
         goto error_out;
 
@@ -689,7 +681,7 @@ setup_guest(int xc_handle, uint32_t dom, unsigned long memsize,
     munmap(sp, PAGE_SIZE);
     ioreq_buffer_page = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
                                              PROT_READ | PROT_WRITE,
-                                             pfn_list[nr_pages - 1]); 
+                                             pfn_list[2]); 
     memset(ioreq_buffer_page,0,PAGE_SIZE);
     munmap(ioreq_buffer_page, PAGE_SIZE);
     free(pfn_list);
index d3876e27492071384dc68db0d5757111aa331e9d..982feea1145817e80cf7822cb0aacf3a425386d6 100644 (file)
@@ -591,6 +591,9 @@ class IA64_HVM_ImageHandler(HVMImageHandler):
         extra_pages = 1024 + 3
         return mem_kb + extra_pages * page_kb
 
+    def getRequiredInitialReservation(self):
+        return self.vm.getMemoryTarget()
+
     def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
         # Explicit shadow memory is not a concept 
         return 0