direct-io.hg

changeset 15305:fc49dbce4868

[IA64] memmap: ia64 domVTi memmap info support

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Alex Williamson <alex.williamson@hp.com>
date Mon May 21 14:08:19 2007 -0600 (2007-05-21)
parents 81861796b5bb
children 6450f6287898
files tools/libxc/ia64/xc_ia64_hvm_build.c tools/python/xen/xend/image.py xen/arch/ia64/xen/dom0_ops.c
line diff
     1.1 --- a/tools/libxc/ia64/xc_ia64_hvm_build.c	Mon May 21 14:05:08 2007 -0600
     1.2 +++ b/tools/libxc/ia64/xc_ia64_hvm_build.c	Mon May 21 14:08:19 2007 -0600
     1.3 @@ -2,7 +2,9 @@
     1.4  #include "xenguest.h"
     1.5  #include "xc_private.h"
     1.6  #include "xc_elf.h"
     1.7 +#include "xc_efi.h"
     1.8  #include <stdlib.h>
     1.9 +#include <assert.h>
    1.10  #include <zlib.h>
    1.11  #include "xen/arch-ia64.h"
    1.12  #include <xen/hvm/ioreq.h>
    1.13 @@ -554,12 +556,129 @@ add_pal_hob(void* hob_buf)
    1.14  #define GFW_PAGES (GFW_SIZE >> PAGE_SHIFT)
    1.15  #define VGA_START_PAGE (VGA_IO_START >> PAGE_SHIFT)
    1.16  #define VGA_END_PAGE ((VGA_IO_START + VGA_IO_SIZE) >> PAGE_SHIFT)
    1.17 +
    1.18 +static void
    1.19 +xc_ia64_setup_md(efi_memory_desc_t *md,
    1.20 +                 unsigned long start, unsigned long end)
    1.21 +{
    1.22 +    md->type = EFI_CONVENTIONAL_MEMORY;
    1.23 +    md->pad = 0;
    1.24 +    md->phys_addr = start;
    1.25 +    md->virt_addr = 0;
    1.26 +    md->num_pages = (end - start) >> EFI_PAGE_SHIFT;
    1.27 +    md->attribute = EFI_MEMORY_WB;
    1.28 +}
    1.29 +
    1.30 +static inline unsigned long 
    1.31 +min(unsigned long lhs, unsigned long rhs)
    1.32 +{
    1.33 +    return (lhs < rhs)? lhs: rhs;
    1.34 +}
    1.35 +
    1.36 +static int
    1.37 +xc_ia64_setup_memmap_info(int xc_handle, uint32_t dom,
    1.38 +                          unsigned long dom_memsize, /* in bytes */
    1.39 +                          unsigned long *pfns_special_pages, 
    1.40 +                          unsigned long nr_special_pages,
    1.41 +                          unsigned long memmap_info_pfn,
    1.42 +                          unsigned long memmap_info_num_pages)
    1.43 +{
    1.44 +    xen_ia64_memmap_info_t* memmap_info;
    1.45 +    efi_memory_desc_t *md;
    1.46 +    uint64_t nr_mds;
    1.47 +    
    1.48 +    memmap_info = xc_map_foreign_range(xc_handle, dom,
    1.49 +                                       PAGE_SIZE * memmap_info_num_pages,
    1.50 +                                       PROT_READ | PROT_WRITE,
    1.51 +                                       memmap_info_pfn);
    1.52 +    if (memmap_info == NULL) {
    1.53 +        PERROR("Could not map memmmap_info page.\n");
    1.54 +        return -1;
    1.55 +    }
    1.56 +    memset(memmap_info, 0, PAGE_SIZE * memmap_info_num_pages);
    1.57 +
    1.58 +    /*
    1.59 +     * [0, VGA_IO_START = 0xA0000)
    1.60 +     * [VGA_IO_START + VGA_IO_SIZE = 0xC0000, MMIO_START = 3GB)
    1.61 +     * [IO_PAGE_START (> 3GB), IO_PAGE_START + IO_PAGE_SIZE)
    1.62 +     * [STORE_PAGE_START, STORE_PAGE_START + STORE_PAGE_SIZE)
    1.63 +     * [BUFFER_IO_PAGE_START, BUFFER_IO_PAGE_START + BUFFER_IO_PAGE_SIZE)
    1.64 +     * [BUFFER_PIO_PAGE_START, BUFFER_PIO_PAGE_START + BUFFER_PIO_PAGE_SIZE)
    1.65 +     * [memmap_info_pfn << PAGE_SHIFT,
    1.66 +     *                          (memmap_info_pfn << PAGE_SHIFT) + PAGE_SIZE)
    1.67 +     * [GFW_START=4GB - GFW_SIZE, GFW_START + GFW_SIZE = 4GB)
    1.68 +     * [4GB, ...)
    1.69 +     */ 
    1.70 +    md = (efi_memory_desc_t*)&memmap_info->memdesc;
    1.71 +    xc_ia64_setup_md(md, 0, min(VGA_IO_START, dom_memsize));
    1.72 +    md++;
    1.73 +    if (dom_memsize > (VGA_IO_START + VGA_IO_SIZE)) {
    1.74 +        xc_ia64_setup_md(md, VGA_IO_START + VGA_IO_SIZE,
    1.75 +                         min(MMIO_START, dom_memsize));
    1.76 +        md++;
    1.77 +    }
    1.78 +    xc_ia64_setup_md(md, IO_PAGE_START, IO_PAGE_START + IO_PAGE_SIZE);
    1.79 +    md++;
    1.80 +    xc_ia64_setup_md(md, STORE_PAGE_START, STORE_PAGE_START + STORE_PAGE_SIZE);
    1.81 +    md++;
    1.82 +    xc_ia64_setup_md(md, BUFFER_IO_PAGE_START,
    1.83 +                     BUFFER_IO_PAGE_START + BUFFER_IO_PAGE_SIZE);
    1.84 +    md++;
    1.85 +    xc_ia64_setup_md(md, BUFFER_PIO_PAGE_START,
    1.86 +                     BUFFER_PIO_PAGE_START + BUFFER_PIO_PAGE_SIZE);
    1.87 +    md++;
    1.88 +    xc_ia64_setup_md(md, memmap_info_pfn << PAGE_SHIFT,
    1.89 +                     (memmap_info_pfn << PAGE_SHIFT) +
    1.90 +                     PAGE_SIZE * memmap_info_num_pages);
    1.91 +    md++;
    1.92 +    xc_ia64_setup_md(md, GFW_START, GFW_START + GFW_SIZE);
    1.93 +    md++;
    1.94 +    if (dom_memsize > MMIO_START) {
    1.95 +        xc_ia64_setup_md(md, 4 * MEM_G, dom_memsize + (1 * MEM_G));
    1.96 +        md++;
    1.97 +    }
    1.98 +    nr_mds = md - (efi_memory_desc_t*)&memmap_info->memdesc;
    1.99 +    
   1.100 +    assert(nr_mds <=
   1.101 +           (PAGE_SIZE * memmap_info_num_pages -
   1.102 +            offsetof(*memmap_info, memdesc))/sizeof(*md));
   1.103 +    memmap_info->efi_memmap_size = nr_mds * sizeof(*md);
   1.104 +    memmap_info->efi_memdesc_size = sizeof(*md);
   1.105 +    memmap_info->efi_memdesc_version = EFI_MEMORY_DESCRIPTOR_VERSION;
   1.106 +
   1.107 +    munmap(memmap_info, PAGE_SIZE * memmap_info_num_pages);
   1.108 +    return 0;
   1.109 +}
   1.110 +
   1.111 +/* setup shared_info page */
   1.112 +static int
   1.113 +xc_ia64_setup_shared_info(int xc_handle, uint32_t dom,
   1.114 +                          unsigned long shared_info_pfn,
   1.115 +                          unsigned long memmap_info_pfn,
   1.116 +                          unsigned long memmap_info_num_pages)
   1.117 +{
   1.118 +    shared_info_t *shared_info;
   1.119 +
   1.120 +    shared_info = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   1.121 +                                       PROT_READ | PROT_WRITE,
   1.122 +                                       shared_info_pfn);
   1.123 +    if (shared_info == NULL) {
   1.124 +        PERROR("Could not map shared_info");
   1.125 +        return -1;
   1.126 +    }
   1.127 +    memset(shared_info, 0, sizeof(*shared_info));
   1.128 +    shared_info->arch.memmap_info_num_pages = memmap_info_num_pages;
   1.129 +    shared_info->arch.memmap_info_pfn = memmap_info_pfn;
   1.130 +    munmap(shared_info, PAGE_SIZE);
   1.131 +    return 0;
   1.132 +}
   1.133 +
   1.134  /*
   1.135   * In this function, we will allocate memory and build P2M/M2P table for VTI
   1.136   * guest.  Frist, a pfn list will be initialized discontiguous, normal memory
   1.137 - * begins with 0, GFW memory and other three pages at their place defined in
   1.138 + * begins with 0, GFW memory and other five pages at their place defined in
   1.139   * xen/include/public/arch-ia64.h xc_domain_memory_populate_physmap() called
   1.140 - * three times, to set parameter 'extent_order' to different value, this is
   1.141 + * five times, to set parameter 'extent_order' to different value, this is
   1.142   * convenient to allocate discontiguous memory with different size.
   1.143   */
   1.144  static int
   1.145 @@ -573,6 +692,11 @@ setup_guest(int xc_handle, uint32_t dom,
   1.146      unsigned long dom_memsize = memsize << 20;
   1.147      unsigned long nr_pages = memsize << (20 - PAGE_SHIFT);
   1.148      unsigned long vcpus;
   1.149 +
   1.150 +    unsigned long nr_special_pages;
   1.151 +    unsigned long memmap_info_pfn;
   1.152 +    unsigned long memmap_info_num_pages;
   1.153 +
   1.154      int rc;
   1.155      long i;
   1.156      DECLARE_DOMCTL;
   1.157 @@ -614,7 +738,7 @@ setup_guest(int xc_handle, uint32_t dom,
   1.158          goto error_out;
   1.159      }
   1.160  
   1.161 -    // We allocate additional pfn for GFW and other three pages, so
   1.162 +    // We allocate additional pfn for GFW and other five pages, so
   1.163      // the pfn_list is not contiguous.  Due to this we must support
   1.164      // old interface xc_ia64_get_pfn_list().
   1.165      for (i = 0; i < GFW_PAGES; i++) 
   1.166 @@ -627,12 +751,22 @@ setup_guest(int xc_handle, uint32_t dom,
   1.167          goto error_out;
   1.168      }
   1.169  
   1.170 -    pfn_list[0] = IO_PAGE_START >> PAGE_SHIFT;
   1.171 -    pfn_list[1] = STORE_PAGE_START >> PAGE_SHIFT;
   1.172 -    pfn_list[2] = BUFFER_IO_PAGE_START >> PAGE_SHIFT;
   1.173 -    pfn_list[3] = BUFFER_PIO_PAGE_START >> PAGE_SHIFT;
   1.174 +    nr_special_pages = 0;
   1.175 +    pfn_list[nr_special_pages] = IO_PAGE_START >> PAGE_SHIFT;
   1.176 +    nr_special_pages++;
   1.177 +    pfn_list[nr_special_pages] = STORE_PAGE_START >> PAGE_SHIFT;
   1.178 +    nr_special_pages++;
   1.179 +    pfn_list[nr_special_pages] = BUFFER_IO_PAGE_START >> PAGE_SHIFT;
   1.180 +    nr_special_pages++;
   1.181 +    pfn_list[nr_special_pages] = BUFFER_PIO_PAGE_START >> PAGE_SHIFT;
   1.182  
   1.183 -    rc = xc_domain_memory_populate_physmap(xc_handle, dom, 4,
   1.184 +    memmap_info_pfn = pfn_list[nr_special_pages] + 1;
   1.185 +    memmap_info_num_pages = 1;
   1.186 +    nr_special_pages++;
   1.187 +    pfn_list[nr_special_pages] = memmap_info_pfn;
   1.188 +    nr_special_pages++;
   1.189 +
   1.190 +    rc = xc_domain_memory_populate_physmap(xc_handle, dom, nr_special_pages,
   1.191                                             0, 0, &pfn_list[0]);
   1.192      if (rc != 0) {
   1.193          PERROR("Could not allocate IO page or store page or buffer io page.\n");
   1.194 @@ -662,6 +796,19 @@ setup_guest(int xc_handle, uint32_t dom,
   1.195          goto error_out;
   1.196      }
   1.197  
   1.198 +    if (xc_ia64_setup_memmap_info(xc_handle, dom, dom_memsize,
   1.199 +                                  pfn_list, nr_special_pages,
   1.200 +                                  memmap_info_pfn, memmap_info_num_pages)) {
   1.201 +        PERROR("Could not build memmap info\n");
   1.202 +        goto error_out;
   1.203 +    }
   1.204 +    if (xc_ia64_setup_shared_info(xc_handle, dom,
   1.205 +                                  domctl.u.getdomaininfo.shared_info_frame,
   1.206 +                                  memmap_info_pfn, memmap_info_num_pages)) {
   1.207 +        PERROR("Could not setup shared_info\n");
   1.208 +        goto error_out;
   1.209 +    }
   1.210 +
   1.211      vcpus = domctl.u.getdomaininfo.max_vcpu_id + 1;
   1.212  
   1.213      // Hand-off state passed to guest firmware 
     2.1 --- a/tools/python/xen/xend/image.py	Mon May 21 14:05:08 2007 -0600
     2.2 +++ b/tools/python/xen/xend/image.py	Mon May 21 14:08:19 2007 -0600
     2.3 @@ -471,8 +471,9 @@ class IA64_HVM_ImageHandler(HVMImageHand
     2.4  
     2.5      def getRequiredAvailableMemory(self, mem_kb):
     2.6          page_kb = 16
     2.7 -        # ROM size for guest firmware, ioreq page, pio page and xenstore page
     2.8 -        extra_pages = 1024 + 4
     2.9 +        # ROM size for guest firmware, io page, xenstore page
    2.10 +        # buffer io page, buffer pio page and memmap info page
    2.11 +        extra_pages = 1024 + 5
    2.12          return mem_kb + extra_pages * page_kb
    2.13  
    2.14      def getRequiredInitialReservation(self):
     3.1 --- a/xen/arch/ia64/xen/dom0_ops.c	Mon May 21 14:05:08 2007 -0600
     3.2 +++ b/xen/arch/ia64/xen/dom0_ops.c	Mon May 21 14:08:19 2007 -0600
     3.3 @@ -117,19 +117,19 @@ long arch_do_domctl(xen_domctl_t *op, XE
     3.4                  if (ds->xsi_va)
     3.5                      d->arch.shared_info_va = ds->xsi_va;
     3.6                  ret = dom_fw_setup(d, ds->bp, ds->maxmem);
     3.7 -                {
     3.8 -                    /*
     3.9 -                     * XXX IA64_SHARED_INFO_PADDR
    3.10 -                     * assign these pages into guest psudo physical address
    3.11 -                     * space for dom0 to map this page by gmfn.
    3.12 -                     * this is necessary for domain build, save, restore and 
    3.13 -                     * dump-core.
    3.14 -                     */
    3.15 -                    unsigned long i;
    3.16 -                    for (i = 0; i < XSI_SIZE; i += PAGE_SIZE)
    3.17 -                        assign_domain_page(d, IA64_SHARED_INFO_PADDR + i,
    3.18 -                                           virt_to_maddr(d->shared_info + i));
    3.19 -                }
    3.20 +            }
    3.21 +            if (ret == 0) {
    3.22 +                /*
    3.23 +                 * XXX IA64_SHARED_INFO_PADDR
    3.24 +                 * assign these pages into guest psudo physical address
    3.25 +                 * space for dom0 to map this page by gmfn.
    3.26 +                 * this is necessary for domain build, save, restore and 
    3.27 +                 * dump-core.
    3.28 +                 */
    3.29 +                unsigned long i;
    3.30 +                for (i = 0; i < XSI_SIZE; i += PAGE_SIZE)
    3.31 +                    assign_domain_page(d, IA64_SHARED_INFO_PADDR + i,
    3.32 +                                       virt_to_maddr(d->shared_info + i));
    3.33              }
    3.34          }
    3.35