ia64/xen-unstable

changeset 16228:65b961265093

pv-qemu 1/10: Add a QEMU machine type for fullvirt guests

This patch does a (no functional change) re-arrangement of the code
for starting up a fully virtualized guest. In particular it creates a
new QEMU machine type for Xen fullyvirt guests which can be specified
with '-M xenfv'. For compatibility this is in fact made to be the
default. The code for setting up memory maps is moved out of vl.c, and
into hw/xen_machine_fv.c. This is basically to ensure that it can be
easily skipped when we add a paravirt machine type in the next patch.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author Keir Fraser <keir@xensource.com>
date Thu Oct 25 14:33:01 2007 +0100 (2007-10-25)
parents 168beb9a27a5
children 290b460838a8
files tools/ioemu/Makefile.target tools/ioemu/hw/xen_machine_fv.c tools/ioemu/vl.c tools/ioemu/vl.h
line diff
     1.1 --- a/tools/ioemu/Makefile.target	Thu Oct 25 14:24:52 2007 +0100
     1.2 +++ b/tools/ioemu/Makefile.target	Thu Oct 25 14:33:01 2007 +0100
     1.3 @@ -409,6 +409,7 @@ VL_OBJS+= usb-uhci.o smbus_eeprom.o
     1.4  VL_OBJS+= piix4acpi.o
     1.5  VL_OBJS+= xenstore.o
     1.6  VL_OBJS+= xen_platform.o
     1.7 +VL_OBJS+= xen_machine_fv.o
     1.8  VL_OBJS+= tpm_tis.o
     1.9  CPPFLAGS += -DHAS_AUDIO
    1.10  endif
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/ioemu/hw/xen_machine_fv.c	Thu Oct 25 14:33:01 2007 +0100
     2.3 @@ -0,0 +1,295 @@
     2.4 +/*
     2.5 + * QEMU Xen FV Machine
     2.6 + *
     2.7 + * Copyright (c) 2003-2007 Fabrice Bellard
     2.8 + * Copyright (c) 2007 Red Hat
     2.9 + *
    2.10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
    2.11 + * of this software and associated documentation files (the "Software"), to deal
    2.12 + * in the Software without restriction, including without limitation the rights
    2.13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    2.14 + * copies of the Software, and to permit persons to whom the Software is
    2.15 + * furnished to do so, subject to the following conditions:
    2.16 + *
    2.17 + * The above copyright notice and this permission notice shall be included in
    2.18 + * all copies or substantial portions of the Software.
    2.19 + *
    2.20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    2.21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    2.22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    2.23 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    2.24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    2.25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    2.26 + * THE SOFTWARE.
    2.27 + */
    2.28 +
    2.29 +#include "vl.h"
    2.30 +#include <xen/hvm/params.h>
    2.31 +#include <sys/mman.h>
    2.32 +
    2.33 +#ifndef PAGE_SIZE
    2.34 +#define PAGE_SIZE XC_PAGE_SIZE
    2.35 +#endif
    2.36 +#ifndef PAGE_SHIFT
    2.37 +#define PAGE_SHIFT XC_PAGE_SHIFT
    2.38 +#endif
    2.39 +
    2.40 +#if defined(MAPCACHE)
    2.41 +
    2.42 +#if defined(__i386__) 
    2.43 +#define MAX_MCACHE_SIZE    0x40000000 /* 1GB max for x86 */
    2.44 +#define MCACHE_BUCKET_SHIFT 16
    2.45 +#elif defined(__x86_64__)
    2.46 +#define MAX_MCACHE_SIZE    0x1000000000 /* 64GB max for x86_64 */
    2.47 +#define MCACHE_BUCKET_SHIFT 20
    2.48 +#endif
    2.49 +
    2.50 +#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)
    2.51 +
    2.52 +#define BITS_PER_LONG (sizeof(long)*8)
    2.53 +#define BITS_TO_LONGS(bits) \
    2.54 +    (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
    2.55 +#define DECLARE_BITMAP(name,bits) \
    2.56 +    unsigned long name[BITS_TO_LONGS(bits)]
    2.57 +#define test_bit(bit,map) \
    2.58 +    (!!((map)[(bit)/BITS_PER_LONG] & (1UL << ((bit)%BITS_PER_LONG))))
    2.59 +
    2.60 +struct map_cache {
    2.61 +    unsigned long paddr_index;
    2.62 +    uint8_t      *vaddr_base;
    2.63 +    DECLARE_BITMAP(valid_mapping, MCACHE_BUCKET_SIZE>>PAGE_SHIFT);
    2.64 +};
    2.65 +
    2.66 +static struct map_cache *mapcache_entry;
    2.67 +static unsigned long nr_buckets;
    2.68 +
    2.69 +/* For most cases (>99.9%), the page address is the same. */
    2.70 +static unsigned long last_address_index = ~0UL;
    2.71 +static uint8_t      *last_address_vaddr;
    2.72 +
    2.73 +static int qemu_map_cache_init(void)
    2.74 +{
    2.75 +    unsigned long size;
    2.76 +
    2.77 +    nr_buckets = (((MAX_MCACHE_SIZE >> PAGE_SHIFT) +
    2.78 +                   (1UL << (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)) - 1) >>
    2.79 +                  (MCACHE_BUCKET_SHIFT - PAGE_SHIFT));
    2.80 +
    2.81 +    /*
    2.82 +     * Use mmap() directly: lets us allocate a big hash table with no up-front
    2.83 +     * cost in storage space. The OS will allocate memory only for the buckets
    2.84 +     * that we actually use. All others will contain all zeroes.
    2.85 +     */
    2.86 +    size = nr_buckets * sizeof(struct map_cache);
    2.87 +    size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
    2.88 +    fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx size %lu\n", nr_buckets, size);
    2.89 +    mapcache_entry = mmap(NULL, size, PROT_READ|PROT_WRITE,
    2.90 +                          MAP_SHARED|MAP_ANON, -1, 0);
    2.91 +    if (mapcache_entry == MAP_FAILED) {
    2.92 +        errno = ENOMEM;
    2.93 +        return -1;
    2.94 +    }
    2.95 +
    2.96 +    return 0;
    2.97 +}
    2.98 +
    2.99 +static void qemu_remap_bucket(struct map_cache *entry,
   2.100 +                              unsigned long address_index)
   2.101 +{
   2.102 +    uint8_t *vaddr_base;
   2.103 +    unsigned long pfns[MCACHE_BUCKET_SIZE >> PAGE_SHIFT];
   2.104 +    unsigned int i, j;
   2.105 +
   2.106 +    if (entry->vaddr_base != NULL) {
   2.107 +        errno = munmap(entry->vaddr_base, MCACHE_BUCKET_SIZE);
   2.108 +        if (errno) {
   2.109 +            fprintf(logfile, "unmap fails %d\n", errno);
   2.110 +            exit(-1);
   2.111 +        }
   2.112 +    }
   2.113 +
   2.114 +    for (i = 0; i < MCACHE_BUCKET_SIZE >> PAGE_SHIFT; i++)
   2.115 +        pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-PAGE_SHIFT)) + i;
   2.116 +
   2.117 +    vaddr_base = xc_map_foreign_batch(xc_handle, domid, PROT_READ|PROT_WRITE,
   2.118 +                                      pfns, MCACHE_BUCKET_SIZE >> PAGE_SHIFT);
   2.119 +    if (vaddr_base == NULL) {
   2.120 +        fprintf(logfile, "xc_map_foreign_batch error %d\n", errno);
   2.121 +        exit(-1);
   2.122 +    }
   2.123 +
   2.124 +    entry->vaddr_base  = vaddr_base;
   2.125 +    entry->paddr_index = address_index;
   2.126 +
   2.127 +    for (i = 0; i < MCACHE_BUCKET_SIZE >> PAGE_SHIFT; i += BITS_PER_LONG) {
   2.128 +        unsigned long word = 0;
   2.129 +        j = ((i + BITS_PER_LONG) > (MCACHE_BUCKET_SIZE >> PAGE_SHIFT)) ?
   2.130 +            (MCACHE_BUCKET_SIZE >> PAGE_SHIFT) % BITS_PER_LONG : BITS_PER_LONG;
   2.131 +        while (j > 0)
   2.132 +            word = (word << 1) | (((pfns[i + --j] >> 28) & 0xf) != 0xf);
   2.133 +        entry->valid_mapping[i / BITS_PER_LONG] = word;
   2.134 +    }
   2.135 +}
   2.136 +
   2.137 +uint8_t *qemu_map_cache(target_phys_addr_t phys_addr)
   2.138 +{
   2.139 +    struct map_cache *entry;
   2.140 +    unsigned long address_index  = phys_addr >> MCACHE_BUCKET_SHIFT;
   2.141 +    unsigned long address_offset = phys_addr & (MCACHE_BUCKET_SIZE-1);
   2.142 +
   2.143 +    if (address_index == last_address_index)
   2.144 +        return last_address_vaddr + address_offset;
   2.145 +
   2.146 +    entry = &mapcache_entry[address_index % nr_buckets];
   2.147 +
   2.148 +    if (entry->vaddr_base == NULL || entry->paddr_index != address_index ||
   2.149 +        !test_bit(address_offset>>PAGE_SHIFT, entry->valid_mapping))
   2.150 +        qemu_remap_bucket(entry, address_index);
   2.151 +
   2.152 +    if (!test_bit(address_offset>>PAGE_SHIFT, entry->valid_mapping))
   2.153 +        return NULL;
   2.154 +
   2.155 +    last_address_index = address_index;
   2.156 +    last_address_vaddr = entry->vaddr_base;
   2.157 +
   2.158 +    return last_address_vaddr + address_offset;
   2.159 +}
   2.160 +
   2.161 +void qemu_invalidate_map_cache(void)
   2.162 +{
   2.163 +    unsigned long i;
   2.164 +
   2.165 +    mapcache_lock();
   2.166 +
   2.167 +    for (i = 0; i < nr_buckets; i++) {
   2.168 +        struct map_cache *entry = &mapcache_entry[i];
   2.169 +
   2.170 +        if (entry->vaddr_base == NULL)
   2.171 +            continue;
   2.172 +
   2.173 +        errno = munmap(entry->vaddr_base, MCACHE_BUCKET_SIZE);
   2.174 +        if (errno) {
   2.175 +            fprintf(logfile, "unmap fails %d\n", errno);
   2.176 +            exit(-1);
   2.177 +        }
   2.178 +
   2.179 +        entry->paddr_index = 0;
   2.180 +        entry->vaddr_base  = NULL;
   2.181 +    }
   2.182 +
   2.183 +    last_address_index =  ~0UL;
   2.184 +    last_address_vaddr = NULL;
   2.185 +
   2.186 +    mapcache_unlock();
   2.187 +}
   2.188 +
   2.189 +#endif /* defined(MAPCACHE) */
   2.190 +
   2.191 +
   2.192 +static void xen_init_fv(uint64_t ram_size, int vga_ram_size, char *boot_device,
   2.193 +                        DisplayState *ds, const char **fd_filename,
   2.194 +                        int snapshot,
   2.195 +                        const char *kernel_filename,
   2.196 +                        const char *kernel_cmdline,
   2.197 +                        const char *initrd_filename,
   2.198 +                        const char *direct_pci)
   2.199 +{
   2.200 +    unsigned long ioreq_pfn;
   2.201 +    extern void *shared_page;
   2.202 +    extern void *buffered_io_page;
   2.203 +#ifdef __ia64__
   2.204 +    unsigned long nr_pages;
   2.205 +    xen_pfn_t *page_array;
   2.206 +    extern void *buffered_pio_page;
   2.207 +#endif
   2.208 +
   2.209 +#if defined(__i386__) || defined(__x86_64__)
   2.210 +
   2.211 +    if (qemu_map_cache_init()) {
   2.212 +        fprintf(logfile, "qemu_map_cache_init returned: error %d\n", errno);
   2.213 +        exit(-1);
   2.214 +    }
   2.215 +
   2.216 +    xc_get_hvm_param(xc_handle, domid, HVM_PARAM_IOREQ_PFN, &ioreq_pfn);
   2.217 +    fprintf(logfile, "shared page at pfn %lx\n", ioreq_pfn);
   2.218 +    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   2.219 +                                       PROT_READ|PROT_WRITE, ioreq_pfn);
   2.220 +    if (shared_page == NULL) {
   2.221 +        fprintf(logfile, "map shared IO page returned error %d\n", errno);
   2.222 +        exit(-1);
   2.223 +    }
   2.224 +
   2.225 +    xc_get_hvm_param(xc_handle, domid, HVM_PARAM_BUFIOREQ_PFN, &ioreq_pfn);
   2.226 +    fprintf(logfile, "buffered io page at pfn %lx\n", ioreq_pfn);
   2.227 +    buffered_io_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   2.228 +                                            PROT_READ|PROT_WRITE, ioreq_pfn);
   2.229 +    if (buffered_io_page == NULL) {
   2.230 +        fprintf(logfile, "map buffered IO page returned error %d\n", errno);
   2.231 +        exit(-1);
   2.232 +    }
   2.233 +
   2.234 +#elif defined(__ia64__)
   2.235 +
   2.236 +    nr_pages = ram_size/PAGE_SIZE;
   2.237 +
   2.238 +    page_array = (xen_pfn_t *)malloc(nr_pages * sizeof(xen_pfn_t));
   2.239 +    if (page_array == NULL) {
   2.240 +        fprintf(logfile, "malloc returned error %d\n", errno);
   2.241 +        exit(-1);
   2.242 +    }
   2.243 +
   2.244 +    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   2.245 +                                       PROT_READ|PROT_WRITE,
   2.246 +                                       IO_PAGE_START >> PAGE_SHIFT);
   2.247 +
   2.248 +    buffered_io_page =xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   2.249 +                                       PROT_READ|PROT_WRITE,
   2.250 +                                       BUFFER_IO_PAGE_START >> PAGE_SHIFT);
   2.251 +
   2.252 +    buffered_pio_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   2.253 +                                       PROT_READ|PROT_WRITE,
   2.254 +                                       BUFFER_PIO_PAGE_START >> PAGE_SHIFT);
   2.255 +
   2.256 +    for (i = 0; i < nr_pages; i++)
   2.257 +        page_array[i] = i;
   2.258 +	
   2.259 +    /* VTI will not use memory between 3G~4G, so we just pass a legal pfn
   2.260 +       to make QEMU map continuous virtual memory space */
   2.261 +    if (ram_size > MMIO_START) {	
   2.262 +        for (i = 0 ; i < (MEM_G >> PAGE_SHIFT); i++)
   2.263 +            page_array[(MMIO_START >> PAGE_SHIFT) + i] =
   2.264 +                (STORE_PAGE_START >> PAGE_SHIFT); 
   2.265 +    }
   2.266 +
   2.267 +    phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
   2.268 +                                         PROT_READ|PROT_WRITE,
   2.269 +                                         page_array, nr_pages);
   2.270 +    if (phys_ram_base == 0) {
   2.271 +        fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
   2.272 +        exit(-1);
   2.273 +    }
   2.274 +    free(page_array);
   2.275 +#endif
   2.276 +
   2.277 +    timeoffset_get();
   2.278 +
   2.279 +
   2.280 +    pc_machine.init(ram_size, vga_ram_size, boot_device, ds, fd_filename,
   2.281 +                    snapshot, kernel_filename, kernel_cmdline, initrd_filename,
   2.282 +                    direct_pci);
   2.283 +}
   2.284 +
   2.285 +QEMUMachine xenfv_machine = {
   2.286 +    "xenfv",
   2.287 +    "Xen Fully-virtualized PC",
   2.288 +    xen_init_fv,
   2.289 +};
   2.290 +
   2.291 +/*
   2.292 + * Local variables:
   2.293 + *  indent-tabs-mode: nil
   2.294 + *  c-indent-level: 4
   2.295 + *  c-basic-offset: 4
   2.296 + *  tab-width: 4
   2.297 + * End:
   2.298 + */
     3.1 --- a/tools/ioemu/vl.c	Thu Oct 25 14:24:52 2007 +0100
     3.2 +++ b/tools/ioemu/vl.c	Thu Oct 25 14:33:01 2007 +0100
     3.3 @@ -96,7 +96,6 @@
     3.4  
     3.5  #include "exec-all.h"
     3.6  
     3.7 -#include <xen/hvm/params.h>
     3.8  #define DEFAULT_NETWORK_SCRIPT "/etc/xen/qemu-ifup"
     3.9  #ifdef _BSD
    3.10  #define DEFAULT_BRIDGE "bridge0"
    3.11 @@ -6696,8 +6695,12 @@ static void read_passwords(void)
    3.12  void register_machines(void)
    3.13  {
    3.14  #if defined(TARGET_I386)
    3.15 +#ifndef CONFIG_DM
    3.16      qemu_register_machine(&pc_machine);
    3.17      qemu_register_machine(&isapc_machine);
    3.18 +#else
    3.19 +    qemu_register_machine(&xenfv_machine);
    3.20 +#endif
    3.21  #elif defined(TARGET_PPC)
    3.22      qemu_register_machine(&heathrow_machine);
    3.23      qemu_register_machine(&core99_machine);
    3.24 @@ -6905,156 +6908,6 @@ int set_mm_mapping(int xc_handle, uint32
    3.25      return 0;
    3.26  }
    3.27  
    3.28 -#if defined(MAPCACHE)
    3.29 -
    3.30 -#if defined(__i386__) 
    3.31 -#define MAX_MCACHE_SIZE    0x40000000 /* 1GB max for x86 */
    3.32 -#define MCACHE_BUCKET_SHIFT 16
    3.33 -#elif defined(__x86_64__)
    3.34 -#define MAX_MCACHE_SIZE    0x1000000000 /* 64GB max for x86_64 */
    3.35 -#define MCACHE_BUCKET_SHIFT 20
    3.36 -#endif
    3.37 -
    3.38 -#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)
    3.39 -
    3.40 -#define BITS_PER_LONG (sizeof(long)*8)
    3.41 -#define BITS_TO_LONGS(bits) \
    3.42 -    (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
    3.43 -#define DECLARE_BITMAP(name,bits) \
    3.44 -    unsigned long name[BITS_TO_LONGS(bits)]
    3.45 -#define test_bit(bit,map) \
    3.46 -    (!!((map)[(bit)/BITS_PER_LONG] & (1UL << ((bit)%BITS_PER_LONG))))
    3.47 -
    3.48 -struct map_cache {
    3.49 -    unsigned long paddr_index;
    3.50 -    uint8_t      *vaddr_base;
    3.51 -    DECLARE_BITMAP(valid_mapping, MCACHE_BUCKET_SIZE>>PAGE_SHIFT);
    3.52 -};
    3.53 -
    3.54 -static struct map_cache *mapcache_entry;
    3.55 -static unsigned long nr_buckets;
    3.56 -
    3.57 -/* For most cases (>99.9%), the page address is the same. */
    3.58 -static unsigned long last_address_index = ~0UL;
    3.59 -static uint8_t      *last_address_vaddr;
    3.60 -
    3.61 -static int qemu_map_cache_init(void)
    3.62 -{
    3.63 -    unsigned long size;
    3.64 -
    3.65 -    nr_buckets = (((MAX_MCACHE_SIZE >> PAGE_SHIFT) +
    3.66 -                   (1UL << (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)) - 1) >>
    3.67 -                  (MCACHE_BUCKET_SHIFT - PAGE_SHIFT));
    3.68 -
    3.69 -    /*
    3.70 -     * Use mmap() directly: lets us allocate a big hash table with no up-front
    3.71 -     * cost in storage space. The OS will allocate memory only for the buckets
    3.72 -     * that we actually use. All others will contain all zeroes.
    3.73 -     */
    3.74 -    size = nr_buckets * sizeof(struct map_cache);
    3.75 -    size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
    3.76 -    fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx size %lu\n", nr_buckets, size);
    3.77 -    mapcache_entry = mmap(NULL, size, PROT_READ|PROT_WRITE,
    3.78 -                          MAP_SHARED|MAP_ANON, -1, 0);
    3.79 -    if (mapcache_entry == MAP_FAILED) {
    3.80 -        errno = ENOMEM;
    3.81 -        return -1;
    3.82 -    }
    3.83 -
    3.84 -    return 0;
    3.85 -}
    3.86 -
    3.87 -static void qemu_remap_bucket(struct map_cache *entry,
    3.88 -                              unsigned long address_index)
    3.89 -{
    3.90 -    uint8_t *vaddr_base;
    3.91 -    unsigned long pfns[MCACHE_BUCKET_SIZE >> PAGE_SHIFT];
    3.92 -    unsigned int i, j;
    3.93 -
    3.94 -    if (entry->vaddr_base != NULL) {
    3.95 -        errno = munmap(entry->vaddr_base, MCACHE_BUCKET_SIZE);
    3.96 -        if (errno) {
    3.97 -            fprintf(logfile, "unmap fails %d\n", errno);
    3.98 -            exit(-1);
    3.99 -        }
   3.100 -    }
   3.101 -
   3.102 -    for (i = 0; i < MCACHE_BUCKET_SIZE >> PAGE_SHIFT; i++)
   3.103 -        pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-PAGE_SHIFT)) + i;
   3.104 -
   3.105 -    vaddr_base = xc_map_foreign_batch(xc_handle, domid, PROT_READ|PROT_WRITE,
   3.106 -                                      pfns, MCACHE_BUCKET_SIZE >> PAGE_SHIFT);
   3.107 -    if (vaddr_base == NULL) {
   3.108 -        fprintf(logfile, "xc_map_foreign_batch error %d\n", errno);
   3.109 -        exit(-1);
   3.110 -    }
   3.111 -
   3.112 -    entry->vaddr_base  = vaddr_base;
   3.113 -    entry->paddr_index = address_index;
   3.114 -
   3.115 -    for (i = 0; i < MCACHE_BUCKET_SIZE >> PAGE_SHIFT; i += BITS_PER_LONG) {
   3.116 -        unsigned long word = 0;
   3.117 -        j = ((i + BITS_PER_LONG) > (MCACHE_BUCKET_SIZE >> PAGE_SHIFT)) ?
   3.118 -            (MCACHE_BUCKET_SIZE >> PAGE_SHIFT) % BITS_PER_LONG : BITS_PER_LONG;
   3.119 -        while (j > 0)
   3.120 -            word = (word << 1) | (((pfns[i + --j] >> 28) & 0xf) != 0xf);
   3.121 -        entry->valid_mapping[i / BITS_PER_LONG] = word;
   3.122 -    }
   3.123 -}
   3.124 -
   3.125 -uint8_t *qemu_map_cache(target_phys_addr_t phys_addr)
   3.126 -{
   3.127 -    struct map_cache *entry;
   3.128 -    unsigned long address_index  = phys_addr >> MCACHE_BUCKET_SHIFT;
   3.129 -    unsigned long address_offset = phys_addr & (MCACHE_BUCKET_SIZE-1);
   3.130 -
   3.131 -    if (address_index == last_address_index)
   3.132 -        return last_address_vaddr + address_offset;
   3.133 -
   3.134 -    entry = &mapcache_entry[address_index % nr_buckets];
   3.135 -
   3.136 -    if (entry->vaddr_base == NULL || entry->paddr_index != address_index ||
   3.137 -        !test_bit(address_offset>>PAGE_SHIFT, entry->valid_mapping))
   3.138 -        qemu_remap_bucket(entry, address_index);
   3.139 -
   3.140 -    if (!test_bit(address_offset>>PAGE_SHIFT, entry->valid_mapping))
   3.141 -        return NULL;
   3.142 -
   3.143 -    last_address_index = address_index;
   3.144 -    last_address_vaddr = entry->vaddr_base;
   3.145 -
   3.146 -    return last_address_vaddr + address_offset;
   3.147 -}
   3.148 -
   3.149 -void qemu_invalidate_map_cache(void)
   3.150 -{
   3.151 -    unsigned long i;
   3.152 -
   3.153 -    mapcache_lock();
   3.154 -
   3.155 -    for (i = 0; i < nr_buckets; i++) {
   3.156 -        struct map_cache *entry = &mapcache_entry[i];
   3.157 -
   3.158 -        if (entry->vaddr_base == NULL)
   3.159 -            continue;
   3.160 -
   3.161 -        errno = munmap(entry->vaddr_base, MCACHE_BUCKET_SIZE);
   3.162 -        if (errno) {
   3.163 -            fprintf(logfile, "unmap fails %d\n", errno);
   3.164 -            exit(-1);
   3.165 -        }
   3.166 -
   3.167 -        entry->paddr_index = 0;
   3.168 -        entry->vaddr_base  = NULL;
   3.169 -    }
   3.170 -
   3.171 -    last_address_index =  ~0UL;
   3.172 -    last_address_vaddr = NULL;
   3.173 -
   3.174 -    mapcache_unlock();
   3.175 -}
   3.176 -
   3.177 -#endif /* defined(MAPCACHE) */
   3.178  
   3.179  int main(int argc, char **argv)
   3.180  {
   3.181 @@ -7089,15 +6942,7 @@ int main(int argc, char **argv)
   3.182      char usb_devices[MAX_USB_CMDLINE][128];
   3.183      int usb_devices_index;
   3.184      int fds[2];
   3.185 -    unsigned long ioreq_pfn;
   3.186 -    extern void *shared_page;
   3.187 -    extern void *buffered_io_page;
   3.188      struct rlimit rl;
   3.189 -#ifdef __ia64__
   3.190 -    unsigned long nr_pages;
   3.191 -    xen_pfn_t *page_array;
   3.192 -    extern void *buffered_pio_page;
   3.193 -#endif
   3.194      sigset_t set;
   3.195      char qemu_dm_logfilename[128];
   3.196      const char *direct_pci = NULL;
   3.197 @@ -7681,6 +7526,7 @@ int main(int argc, char **argv)
   3.198  
   3.199  #ifdef CONFIG_DM
   3.200      bdrv_init();
   3.201 +    xc_handle = xc_interface_open();
   3.202      xenstore_parse_domain_config(domid);
   3.203  #endif /* CONFIG_DM */
   3.204  
   3.205 @@ -7774,83 +7620,6 @@ int main(int argc, char **argv)
   3.206  	}
   3.207  	phys_ram_size += ret;
   3.208      }
   3.209 -#endif /* !CONFIG_DM */
   3.210 -
   3.211 -#ifdef CONFIG_DM
   3.212 -
   3.213 -    xc_handle = xc_interface_open();
   3.214 -
   3.215 -#if defined(__i386__) || defined(__x86_64__)
   3.216 -
   3.217 -    if (qemu_map_cache_init()) {
   3.218 -        fprintf(logfile, "qemu_map_cache_init returned: error %d\n", errno);
   3.219 -        exit(-1);
   3.220 -    }
   3.221 -
   3.222 -    xc_get_hvm_param(xc_handle, domid, HVM_PARAM_IOREQ_PFN, &ioreq_pfn);
   3.223 -    fprintf(logfile, "shared page at pfn %lx\n", ioreq_pfn);
   3.224 -    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   3.225 -                                       PROT_READ|PROT_WRITE, ioreq_pfn);
   3.226 -    if (shared_page == NULL) {
   3.227 -        fprintf(logfile, "map shared IO page returned error %d\n", errno);
   3.228 -        exit(-1);
   3.229 -    }
   3.230 -
   3.231 -    xc_get_hvm_param(xc_handle, domid, HVM_PARAM_BUFIOREQ_PFN, &ioreq_pfn);
   3.232 -    fprintf(logfile, "buffered io page at pfn %lx\n", ioreq_pfn);
   3.233 -    buffered_io_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   3.234 -                                            PROT_READ|PROT_WRITE, ioreq_pfn);
   3.235 -    if (buffered_io_page == NULL) {
   3.236 -        fprintf(logfile, "map buffered IO page returned error %d\n", errno);
   3.237 -        exit(-1);
   3.238 -    }
   3.239 -
   3.240 -#elif defined(__ia64__)
   3.241 -
   3.242 -    nr_pages = ram_size/PAGE_SIZE;
   3.243 -
   3.244 -    page_array = (xen_pfn_t *)malloc(nr_pages * sizeof(xen_pfn_t));
   3.245 -    if (page_array == NULL) {
   3.246 -        fprintf(logfile, "malloc returned error %d\n", errno);
   3.247 -        exit(-1);
   3.248 -    }
   3.249 -
   3.250 -    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   3.251 -                                       PROT_READ|PROT_WRITE,
   3.252 -                                       IO_PAGE_START >> PAGE_SHIFT);
   3.253 -
   3.254 -    buffered_io_page =xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   3.255 -                                       PROT_READ|PROT_WRITE,
   3.256 -                                       BUFFER_IO_PAGE_START >> PAGE_SHIFT);
   3.257 -
   3.258 -    buffered_pio_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   3.259 -                                       PROT_READ|PROT_WRITE,
   3.260 -                                       BUFFER_PIO_PAGE_START >> PAGE_SHIFT);
   3.261 -
   3.262 -    for (i = 0; i < nr_pages; i++)
   3.263 -        page_array[i] = i;
   3.264 -	
   3.265 -    /* VTI will not use memory between 3G~4G, so we just pass a legal pfn
   3.266 -       to make QEMU map continuous virtual memory space */
   3.267 -    if (ram_size > MMIO_START) {	
   3.268 -        for (i = 0 ; i < (MEM_G >> PAGE_SHIFT); i++)
   3.269 -            page_array[(MMIO_START >> PAGE_SHIFT) + i] =
   3.270 -                (STORE_PAGE_START >> PAGE_SHIFT); 
   3.271 -    }
   3.272 -
   3.273 -    phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
   3.274 -                                         PROT_READ|PROT_WRITE,
   3.275 -                                         page_array, nr_pages);
   3.276 -    if (phys_ram_base == 0) {
   3.277 -        fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
   3.278 -        exit(-1);
   3.279 -    }
   3.280 -    free(page_array);
   3.281 -#endif
   3.282 -
   3.283 -    timeoffset_get();
   3.284 -
   3.285 -#else  /* !CONFIG_DM */
   3.286  
   3.287      phys_ram_base = qemu_vmalloc(phys_ram_size);
   3.288      if (!phys_ram_base) {
   3.289 @@ -7858,9 +7627,6 @@ int main(int argc, char **argv)
   3.290          exit(1);
   3.291      }
   3.292  
   3.293 -#endif /* !CONFIG_DM */
   3.294 -
   3.295 -#ifndef CONFIG_DM
   3.296      /* we always create the cdrom drive, even if no disk is there */
   3.297      bdrv_init();
   3.298      if (cdrom_index >= 0) {
     4.1 --- a/tools/ioemu/vl.h	Thu Oct 25 14:24:52 2007 +0100
     4.2 +++ b/tools/ioemu/vl.h	Thu Oct 25 14:33:01 2007 +0100
     4.3 @@ -1108,6 +1108,9 @@ extern void pci_piix4_acpi_init(PCIBus *
     4.4  /* pc.c */
     4.5  extern QEMUMachine pc_machine;
     4.6  extern QEMUMachine isapc_machine;
     4.7 +#ifdef CONFIG_DM
     4.8 +extern QEMUMachine xenfv_machine;
     4.9 +#endif
    4.10  extern int fd_bootchk;
    4.11  
    4.12  void ioport_set_a20(int enable);