ia64/xen-unstable

changeset 18569:0cc0252e74e1

[IA64] hvm builder: more precisely use of memory size.

So far, VGA io size is ignored and memory size which assigned to
domain is smaller than what user specified by VGA io size.
This patch take VGA io size into consideration when memory population.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Thu Oct 02 17:27:57 2008 +0900 (2008-10-02)
parents c383ae0b803d
children 6208fcb4082f
files tools/libxc/ia64/xc_ia64_hvm_build.c
line diff
     1.1 --- a/tools/libxc/ia64/xc_ia64_hvm_build.c	Thu Oct 02 17:27:57 2008 +0900
     1.2 +++ b/tools/libxc/ia64/xc_ia64_hvm_build.c	Thu Oct 02 17:27:57 2008 +0900
     1.3 @@ -90,8 +90,7 @@ static int add_nvram_hob(void* hob_buf, 
     1.4  static int build_hob(void* hob_buf, unsigned long hob_buf_size,
     1.5                       unsigned long dom_mem_size, unsigned long vcpus,
     1.6                       unsigned long nvram_addr);
     1.7 -static int load_hob(int xc_handle,uint32_t dom, void *hob_buf,
     1.8 -                    unsigned long dom_mem_size);
     1.9 +static int load_hob(int xc_handle,uint32_t dom, void *hob_buf);
    1.10  
    1.11  static int
    1.12  xc_ia64_build_hob(int xc_handle, uint32_t dom,
    1.13 @@ -112,7 +111,7 @@ xc_ia64_build_hob(int xc_handle, uint32_
    1.14          return -1;
    1.15      }
    1.16  
    1.17 -    if (load_hob(xc_handle, dom, hob_buf, memsize) < 0) {
    1.18 +    if (load_hob(xc_handle, dom, hob_buf) < 0) {
    1.19          free(hob_buf);
    1.20          PERROR("Could not load hob");
    1.21          return -1;
    1.22 @@ -240,8 +239,7 @@ err_out:
    1.23  }
    1.24  
    1.25  static int
    1.26 -load_hob(int xc_handle, uint32_t dom, void *hob_buf,
    1.27 -         unsigned long dom_mem_size)
    1.28 +load_hob(int xc_handle, uint32_t dom, void *hob_buf)
    1.29  {
    1.30      // hob_buf should be page aligned
    1.31      int hob_size;
    1.32 @@ -264,15 +262,18 @@ load_hob(int xc_handle, uint32_t dom, vo
    1.33                                          GFW_HOB_START >> PAGE_SHIFT, nr_pages);
    1.34  }
    1.35  
    1.36 -#define MIN(x, y) ((x) < (y)) ? (x) : (y)
    1.37 +#define MIN(x, y) (((x) < (y)) ? (x) : (y))
    1.38  static int
    1.39  add_mem_hob(void* hob_buf, unsigned long dom_mem_size)
    1.40  {
    1.41      hob_mem_t memhob;
    1.42  
    1.43 -    // less than 3G
    1.44 +    // less than 3G accounting VGA RAM hole
    1.45      memhob.start = 0;
    1.46 -    memhob.size = MIN(dom_mem_size, 0xC0000000);
    1.47 +    if (dom_mem_size < VGA_IO_START)
    1.48 +        memhob.size = dom_mem_size;
    1.49 +    else
    1.50 +        memhob.size = MIN(dom_mem_size + VGA_IO_SIZE, 0xC0000000);
    1.51  
    1.52      if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0)
    1.53          return -1;
    1.54 @@ -280,7 +281,7 @@ add_mem_hob(void* hob_buf, unsigned long
    1.55      if (dom_mem_size > 0xC0000000) {
    1.56          // 4G ~ 4G+remain
    1.57          memhob.start = 0x100000000; //4G
    1.58 -        memhob.size = dom_mem_size - 0xC0000000;
    1.59 +        memhob.size = dom_mem_size + VGA_IO_SIZE - 0xC0000000;
    1.60          if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0)
    1.61              return -1;
    1.62      }
    1.63 @@ -819,9 +820,10 @@ xc_ia64_setup_memmap_info(int xc_handle,
    1.64      md = (efi_memory_desc_t*)&memmap_info->memdesc;
    1.65      xc_ia64_setup_md(md, 0, min(VGA_IO_START, dom_memsize));
    1.66      md++;
    1.67 -    if (dom_memsize > (VGA_IO_START + VGA_IO_SIZE)) {
    1.68 +
    1.69 +    if (dom_memsize > VGA_IO_START) {
    1.70          xc_ia64_setup_md(md, VGA_IO_START + VGA_IO_SIZE,
    1.71 -                         min(MMIO_START, dom_memsize));
    1.72 +                         min(MMIO_START, dom_memsize + VGA_IO_SIZE));
    1.73          md++;
    1.74      }
    1.75      xc_ia64_setup_md(md, IO_PAGE_START, IO_PAGE_START + IO_PAGE_SIZE);
    1.76 @@ -840,8 +842,8 @@ xc_ia64_setup_memmap_info(int xc_handle,
    1.77      md++;
    1.78      xc_ia64_setup_md(md, GFW_START, GFW_START + GFW_SIZE);
    1.79      md++;
    1.80 -    if (dom_memsize > MMIO_START) {
    1.81 -        xc_ia64_setup_md(md, 4 * MEM_G, dom_memsize + (1 * MEM_G));
    1.82 +    if (dom_memsize + VGA_IO_SIZE > MMIO_START) {
    1.83 +        xc_ia64_setup_md(md, 4 * MEM_G, dom_memsize + VGA_IO_SIZE + (1 * MEM_G));
    1.84          md++;
    1.85      }
    1.86      nr_mds = md - (efi_memory_desc_t*)&memmap_info->memdesc;
    1.87 @@ -901,7 +903,8 @@ setup_guest(int xc_handle, uint32_t dom,
    1.88      unsigned long memmap_info_num_pages;
    1.89      unsigned long nvram_start = NVRAM_START, nvram_fd = 0; 
    1.90      int rc;
    1.91 -    long i;
    1.92 +    unsigned long i;
    1.93 +    unsigned long pfn;
    1.94      const struct hvm_special_page {
    1.95          int             param;
    1.96          xen_pfn_t       pfn;
    1.97 @@ -926,26 +929,28 @@ setup_guest(int xc_handle, uint32_t dom,
    1.98          return -1;
    1.99      }
   1.100  
   1.101 -    // Allocate pfn for normal memory
   1.102 -    for (i = 0; i < dom_memsize >> PAGE_SHIFT; i++)
   1.103 -        pfn_list[i] = i;
   1.104 -
   1.105 -    // If normal memory > 3G. Reserve 3G ~ 4G for MMIO, GFW and others.
   1.106 -    for (i = (MMIO_START >> PAGE_SHIFT); i < (dom_memsize >> PAGE_SHIFT); i++)
   1.107 -        pfn_list[i] += ((1 * MEM_G) >> PAGE_SHIFT);
   1.108 +    //
   1.109 +    // Populate
   1.110 +    // [0, VGA_IO_START) (VGA_IO_SIZE hole)
   1.111 +    // [VGA_IO_START + VGA_IO_SIZE, MMIO_START) (1GB hole)
   1.112 +    // [4GB, end)
   1.113 +    //                     
   1.114 +    i = 0;
   1.115 +    for (pfn = 0;
   1.116 +         pfn < MIN((dom_memsize >> PAGE_SHIFT), VGA_START_PAGE);
   1.117 +         pfn++)
   1.118 +        pfn_list[i++] = pfn;
   1.119 +    for (pfn = VGA_END_PAGE;
   1.120 +         pfn < (MIN(dom_memsize + VGA_IO_SIZE, MMIO_START) >> PAGE_SHIFT);
   1.121 +         pfn++)
   1.122 +        pfn_list[i++] = pfn;
   1.123 +    for (pfn = ((4 * MEM_G) >> PAGE_SHIFT); 
   1.124 +         pfn < ((dom_memsize + VGA_IO_SIZE + 1 * MEM_G) >> PAGE_SHIFT);
   1.125 +         pfn++)
   1.126 +        pfn_list[i++] = pfn;
   1.127  
   1.128 -    // Allocate memory for VTI guest, up to VGA hole from 0xA0000-0xC0000. 
   1.129 -    rc = xc_domain_memory_populate_physmap(xc_handle, dom,
   1.130 -                                           (nr_pages > VGA_START_PAGE) ?
   1.131 -                                           VGA_START_PAGE : nr_pages,
   1.132 -                                           0, 0, &pfn_list[0]);
   1.133 -
   1.134 -    // We're not likely to attempt to create a domain with less than
   1.135 -    // 640k of memory, but test for completeness
   1.136 -    if (rc == 0 && nr_pages > VGA_END_PAGE)
   1.137 -        rc = xc_domain_memory_populate_physmap(xc_handle, dom,
   1.138 -                                               nr_pages - VGA_END_PAGE,
   1.139 -                                               0, 0, &pfn_list[VGA_END_PAGE]);
   1.140 +    rc = xc_domain_memory_populate_physmap(xc_handle, dom, nr_pages, 0, 0,
   1.141 +                                           &pfn_list[0]);
   1.142      if (rc != 0) {
   1.143          PERROR("Could not allocate normal memory for Vti guest.\n");
   1.144          goto error_out;
   1.145 @@ -983,8 +988,8 @@ setup_guest(int xc_handle, uint32_t dom,
   1.146      domctl.u.arch_setup.flags = 0;
   1.147      domctl.u.arch_setup.bp = 0;
   1.148      domctl.u.arch_setup.maxmem = GFW_START + GFW_SIZE;
   1.149 -    if (dom_memsize > MMIO_START)
   1.150 -        domctl.u.arch_setup.maxmem = dom_memsize + 1 * MEM_G;
   1.151 +    if (dom_memsize + VGA_IO_SIZE > MMIO_START)
   1.152 +        domctl.u.arch_setup.maxmem = dom_memsize + VGA_IO_SIZE + 1 * MEM_G;
   1.153      domctl.cmd = XEN_DOMCTL_arch_setup;
   1.154      domctl.domain = (domid_t)dom;
   1.155      if (xc_domctl(xc_handle, &domctl))