ia64/xen-unstable

changeset 13664:d1710eb35385

[HVM] Allow HVM guest to request invalidation of foreign mappings via
an I/O port write.
Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
author kaf24@localhost.localdomain
date Sat Jan 27 13:32:27 2007 +0000 (2007-01-27)
parents 271ffb1c12eb
children 140afd7a5462 4e7bda043cce
files tools/ioemu/hw/xen_platform.c tools/ioemu/target-i386-dm/exec-dm.c tools/ioemu/vl.c tools/ioemu/vl.h unmodified_drivers/linux-2.6/platform-pci/platform-pci.c
line diff
     1.1 --- a/tools/ioemu/hw/xen_platform.c	Fri Jan 26 18:38:40 2007 +0000
     1.2 +++ b/tools/ioemu/hw/xen_platform.c	Sat Jan 27 13:32:27 2007 +0000
     1.3 @@ -31,19 +31,14 @@ extern FILE *logfile;
     1.4  
     1.5  static void platform_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     1.6  {
     1.7 -    return;
     1.8 -}
     1.9 -
    1.10 -static uint32_t platform_ioport_read(void *opaque, uint32_t addr)
    1.11 -{
    1.12 -    return 0;
    1.13 +    if (val == 0)
    1.14 +        qemu_invalidate_map_cache();
    1.15  }
    1.16  
    1.17  static void platform_ioport_map(PCIDevice *pci_dev, int region_num,
    1.18                                  uint32_t addr, uint32_t size, int type)
    1.19  {
    1.20 -    register_ioport_write(addr, 16, 4, platform_ioport_write, NULL);
    1.21 -    register_ioport_read(addr, 16, 1, platform_ioport_read, NULL);
    1.22 +    register_ioport_write(addr, 1, 1, platform_ioport_write, NULL);
    1.23  }
    1.24  
    1.25  static uint32_t platform_mmio_read(void *opaque, target_phys_addr_t addr)
     2.1 --- a/tools/ioemu/target-i386-dm/exec-dm.c	Fri Jan 26 18:38:40 2007 +0000
     2.2 +++ b/tools/ioemu/target-i386-dm/exec-dm.c	Sat Jan 27 13:32:27 2007 +0000
     2.3 @@ -129,18 +129,8 @@ FILE *logfile;
     2.4  int loglevel;
     2.5  
     2.6  
     2.7 -#if defined(__i386__) || defined(__x86_64__)
     2.8 -#define MAPCACHE
     2.9 -#endif
    2.10 -
    2.11  #ifdef MAPCACHE
    2.12 -#include <pthread.h>
    2.13 -static pthread_mutex_t mapcache_mutex;
    2.14 -#define mapcache_lock() pthread_mutex_lock(&mapcache_mutex)
    2.15 -#define mapcache_unlock() pthread_mutex_unlock(&mapcache_mutex)
    2.16 -#else 
    2.17 -#define mapcache_lock() ( (void)0 )
    2.18 -#define mapcache_unlock() ( (void)0 )
    2.19 +pthread_mutex_t mapcache_mutex;
    2.20  #endif
    2.21  
    2.22  
     3.1 --- a/tools/ioemu/vl.c	Fri Jan 26 18:38:40 2007 +0000
     3.2 +++ b/tools/ioemu/vl.c	Sat Jan 27 13:32:27 2007 +0000
     3.3 @@ -285,7 +285,7 @@ int register_ioport_write(int start, int
     3.4      for(i = start; i < start + length; i += size) {
     3.5          ioport_write_table[bsize][i] = func;
     3.6          if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque)
     3.7 -            hw_error("register_ioport_read: invalid opaque");
     3.8 +            hw_error("register_ioport_write: invalid opaque");
     3.9          ioport_opaque[i] = opaque;
    3.10      }
    3.11      return 0;
    3.12 @@ -5826,6 +5826,10 @@ void suspend(int sig)
    3.13  static struct map_cache *mapcache_entry;
    3.14  static unsigned long nr_buckets;
    3.15  
    3.16 +/* For most cases (>99.9%), the page address is the same. */
    3.17 +static unsigned long last_address_index = ~0UL;
    3.18 +static uint8_t      *last_address_vaddr;
    3.19 +
    3.20  static int qemu_map_cache_init(unsigned long nr_pages)
    3.21  {
    3.22      unsigned long max_pages = MAX_MCACHE_SIZE >> PAGE_SHIFT;
    3.23 @@ -5862,10 +5866,6 @@ uint8_t *qemu_map_cache(target_phys_addr
    3.24      unsigned long address_index  = phys_addr >> MCACHE_BUCKET_SHIFT;
    3.25      unsigned long address_offset = phys_addr & (MCACHE_BUCKET_SIZE-1);
    3.26  
    3.27 -    /* For most cases (>99.9%), the page address is the same. */
    3.28 -    static unsigned long last_address_index = ~0UL;
    3.29 -    static uint8_t      *last_address_vaddr;
    3.30 -
    3.31      if (address_index == last_address_index)
    3.32          return last_address_vaddr + address_offset;
    3.33  
    3.34 @@ -5905,6 +5905,34 @@ uint8_t *qemu_map_cache(target_phys_addr
    3.35  
    3.36      return last_address_vaddr + address_offset;
    3.37  }
    3.38 +
    3.39 +void qemu_invalidate_map_cache(void)
    3.40 +{
    3.41 +    unsigned long i;
    3.42 +
    3.43 +    mapcache_lock();
    3.44 +
    3.45 +    for (i = 0; i < nr_buckets; i++) {
    3.46 +        struct map_cache *entry = &mapcache_entry[i];
    3.47 +
    3.48 +        if (entry->vaddr_base == NULL)
    3.49 +            continue;
    3.50 +
    3.51 +        errno = munmap(entry->vaddr_base, MCACHE_BUCKET_SIZE);
    3.52 +        if (errno) {
    3.53 +            fprintf(logfile, "unmap fails %d\n", errno);
    3.54 +            exit(-1);
    3.55 +        }
    3.56 +
    3.57 +        entry->paddr_index = 0;
    3.58 +        entry->vaddr_base  = NULL;
    3.59 +    }
    3.60 +
    3.61 +    last_address_index =  ~0UL;
    3.62 +    last_address_vaddr = NULL;
    3.63 +
    3.64 +    mapcache_unlock();
    3.65 +}
    3.66  #endif
    3.67  
    3.68  int main(int argc, char **argv)
     4.1 --- a/tools/ioemu/vl.h	Fri Jan 26 18:38:40 2007 +0000
     4.2 +++ b/tools/ioemu/vl.h	Sat Jan 27 13:32:27 2007 +0000
     4.3 @@ -158,6 +158,9 @@ extern FILE *logfile;
     4.4  
     4.5  
     4.6  #if defined(__i386__) || defined(__x86_64__)
     4.7 +
     4.8 +#define MAPCACHE
     4.9 +
    4.10  #if defined(__i386__) 
    4.11  #define MAX_MCACHE_SIZE    0x40000000 /* 1GB max for x86 */
    4.12  #define MCACHE_BUCKET_SHIFT 16
    4.13 @@ -174,6 +177,20 @@ struct map_cache {
    4.14  };
    4.15  
    4.16  uint8_t *qemu_map_cache(target_phys_addr_t phys_addr);
    4.17 +void     qemu_invalidate_map_cache(void);
    4.18 +
    4.19 +#include <pthread.h>
    4.20 +extern  pthread_mutex_t mapcache_mutex;
    4.21 +#define mapcache_lock() pthread_mutex_lock(&mapcache_mutex)
    4.22 +#define mapcache_unlock() pthread_mutex_unlock(&mapcache_mutex)
    4.23 +
    4.24 +#else 
    4.25 +
    4.26 +#define qemu_invalidate_map_cache() ((void)0)
    4.27 +
    4.28 +#define mapcache_lock()   ((void)0)
    4.29 +#define mapcache_unlock() ((void)0)
    4.30 +
    4.31  #endif
    4.32  
    4.33  extern int xc_handle;
     5.1 --- a/unmodified_drivers/linux-2.6/platform-pci/platform-pci.c	Fri Jan 26 18:38:40 2007 +0000
     5.2 +++ b/unmodified_drivers/linux-2.6/platform-pci/platform-pci.c	Sat Jan 27 13:32:27 2007 +0000
     5.3 @@ -214,6 +214,14 @@ static uint64_t get_callback_via(struct 
     5.4  #endif
     5.5  }
     5.6  
     5.7 +/* Invalidate foreign mappings (e.g., in qemu-based device model). */
     5.8 +static uint16_t invlmap_port;
     5.9 +void xen_invalidate_foreign_mappings(void)
    5.10 +{
    5.11 +	outb(0, invlmap_port);
    5.12 +}
    5.13 +EXPORT_SYMBOL(xen_invalidate_foreign_mappings);
    5.14 +
    5.15  static int __devinit platform_pci_init(struct pci_dev *pdev,
    5.16  				       const struct pci_device_id *ent)
    5.17  {
    5.18 @@ -239,6 +247,8 @@ static int __devinit platform_pci_init(s
    5.19  		return -ENOENT;
    5.20  	}
    5.21  
    5.22 +	invlmap_port = ioaddr;
    5.23 +
    5.24  	if (request_mem_region(mmio_addr, mmio_len, DRV_NAME) == NULL)
    5.25  	{
    5.26  		printk(KERN_ERR ":MEM I/O resource 0x%lx @ 0x%lx busy\n",