ia64/xen-unstable

changeset 17287:42f6c206c951

merge with xen-unstable.hg
author Alex Williamson <alex.williamson@hp.com>
date Thu Mar 20 12:35:40 2008 -0600 (2008-03-20)
parents 8c921adf4833 c8c8b5c5f6d7
children c7a58a81c4b8
files xen/arch/x86/hvm/iommu.c xen/drivers/passthrough/vtd/io.c xen/include/acpi/actbl2.h xen/include/asm-x86/hvm/iommu.h xen/include/asm-x86/hvm/vmx/intel-iommu.h xen/include/asm-x86/iommu.h
line diff
     1.1 --- a/config/StdGNU.mk	Fri Mar 14 15:07:45 2008 -0600
     1.2 +++ b/config/StdGNU.mk	Thu Mar 20 12:35:40 2008 -0600
     1.3 @@ -41,9 +41,8 @@ SONAME_LDFLAG = -soname
     1.4  SHLIB_CFLAGS = -shared
     1.5  
     1.6  ifneq ($(debug),y)
     1.7 -# Optimisation flags are overridable
     1.8 -CFLAGS ?= -O2 -fomit-frame-pointer
     1.9 +CFLAGS += -O2 -fomit-frame-pointer
    1.10  else
    1.11  # Less than -O1 produces bad code and large stack frames
    1.12 -CFLAGS ?= -O1 -fno-omit-frame-pointer
    1.13 +CFLAGS += -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls
    1.14  endif
     2.1 --- a/config/SunOS.mk	Fri Mar 14 15:07:45 2008 -0600
     2.2 +++ b/config/SunOS.mk	Thu Mar 20 12:35:40 2008 -0600
     2.3 @@ -45,11 +45,10 @@ SONAME_LDFLAG = -h
     2.4  SHLIB_CFLAGS = -R $(SunOS_LIBDIR) -shared
     2.5  
     2.6  ifneq ($(debug),y)
     2.7 -# Optimisation flags are overridable
     2.8 -CFLAGS ?= -O2 -fno-omit-frame-pointer
     2.9 +CFLAGS += -O2 -fno-omit-frame-pointer
    2.10  else
    2.11  # Less than -O1 produces bad code and large stack frames
    2.12 -CFLAGS ?= -O1 -fno-omit-frame-pointer
    2.13 +CFLAGS += -O1 -fno-omit-frame-pointer
    2.14  endif
    2.15  
    2.16  CFLAGS += -Wa,--divide -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__
     3.1 --- a/docs/src/interface.tex	Fri Mar 14 15:07:45 2008 -0600
     3.2 +++ b/docs/src/interface.tex	Thu Mar 20 12:35:40 2008 -0600
     3.3 @@ -1,6 +1,6 @@
     3.4 -\documentclass[11pt,twoside,final,openright]{report}
     3.5 -\usepackage{a4,graphicx,html,setspace,times}
     3.6 -\usepackage{comment,parskip}
     3.7 +\documentclass[11pt,twoside,final,openright,a4paper]{report}
     3.8 +\usepackage{graphicx,html,setspace,times}
     3.9 +\usepackage{parskip}
    3.10  \setstretch{1.15}
    3.11  
    3.12  % LIBRARY FUNCTIONS
     4.1 --- a/extras/mini-os/Makefile	Fri Mar 14 15:07:45 2008 -0600
     4.2 +++ b/extras/mini-os/Makefile	Thu Mar 20 12:35:40 2008 -0600
     4.3 @@ -88,6 +88,11 @@ OBJS += $(QEMUDIR)/i386-dm-stubdom/qemu.
     4.4  CFLAGS += -DCONFIG_QEMU
     4.5  endif
     4.6  
     4.7 +ifneq ($(CDIR),)
     4.8 +OBJS += $(CDIR)/main.a
     4.9 +LDLIBS += 
    4.10 +endif
    4.11 +
    4.12  ifeq ($(libc),y)
    4.13  LDLIBS += -L$(XEN_ROOT)/stubdom/libxc -lxenctrl -lxenguest
    4.14  LDLIBS += -lpci
    4.15 @@ -95,7 +100,7 @@ LDLIBS += -lz
    4.16  LDLIBS += -lc
    4.17  endif
    4.18  
    4.19 -ifneq ($(caml)-$(qemu)-$(lwip),--y)
    4.20 +ifneq ($(caml)-$(qemu)-$(CDIR)-$(lwip),---y)
    4.21  OBJS := $(filter-out daytime.o, $(OBJS))
    4.22  endif
    4.23  
     5.1 --- a/extras/mini-os/README	Fri Mar 14 15:07:45 2008 -0600
     5.2 +++ b/extras/mini-os/README	Thu Mar 20 12:35:40 2008 -0600
     5.3 @@ -13,18 +13,34 @@ This includes:
     5.4   * registering virtual interrupt handlers (for timer interrupts)
     5.5   * a simple page and memory allocator
     5.6   * minimal libc support
     5.7 -
     5.8 -Stuff it doesn't show:
     5.9 - 
    5.10 - * modifying page tables
    5.11 - * network code
    5.12 - * block-device code
    5.13 -
    5.14 + * minimal Copy-on-Write support
    5.15 + * network, block, framebuffer support
    5.16 + * transparent access to FileSystem exports (see tools/fs-back)
    5.17  
    5.18  - to build it just type make.
    5.19  
    5.20 +- to build it with TCP/IP support, download LWIP 1.3 source code and type
    5.21 +
    5.22 +  make LWIPDIR=/path/to/lwip/source
    5.23 +
    5.24 +- to build it with much better libc support, see the stubdom/ directory
    5.25 +
    5.26  - to start it do the following in domain0 (assuming xend is running)
    5.27    # xm create domain_config
    5.28  
    5.29 -this starts the kernel and prints out a bunch of stuff and then once
    5.30 -every second the system time.
    5.31 +This starts the kernel and prints out a bunch of stuff and then once every
    5.32 +second the system time.
    5.33 +
    5.34 +If you have setup a disk in the config file (e.g.
    5.35 +disk = [ 'file:/tmp/foo,hda,r' ] ), it will loop reading it.  If that disk is
    5.36 +writable (e.g. disk = [ 'file:/tmp/foo,hda,w' ] ), it will write data patterns
    5.37 +and re-read them.
    5.38 +
    5.39 +If you have setup a network in the config file (e.g. vif = [''] ), it will
    5.40 +print incoming packets.
    5.41 +
    5.42 +If you have setup a VFB in the config file (e.g. vfb = ['type=sdl'] ), it will
    5.43 +show a mouse with which you can draw color squares.
    5.44 +
    5.45 +If you have compiled it with TCP/IP support, it will run a daytime server on
    5.46 +TCP port 13.
     6.1 --- a/extras/mini-os/arch/ia64/time.c	Fri Mar 14 15:07:45 2008 -0600
     6.2 +++ b/extras/mini-os/arch/ia64/time.c	Thu Mar 20 12:35:40 2008 -0600
     6.3 @@ -246,7 +246,7 @@ init_time(void)
     6.4  {
     6.5  	uint64_t new;
     6.6  	efi_time_t tm;
     6.7 -	int err = 0;
     6.8 +	evtchn_port_t port = 0;
     6.9  
    6.10  	printk("Initialising time\n");
    6.11  	calculate_frequencies();
    6.12 @@ -267,11 +267,12 @@ init_time(void)
    6.13  	} else
    6.14  		printk("efi_get_time() failed\n");
    6.15  
    6.16 -	err = bind_virq(VIRQ_ITC, timer_interrupt, NULL);
    6.17 -	if (err == -1) {
    6.18 -		printk("XEN timer request chn bind failed %i\n", err);
    6.19 +	port = bind_virq(VIRQ_ITC, timer_interrupt, NULL);
    6.20 +	if (port == -1) {
    6.21 +		printk("XEN timer request chn bind failed %i\n", port);
    6.22  		return;
    6.23  	}
    6.24 +        unmask_evtchn(port);
    6.25  	itc_alt = ia64_get_itc();
    6.26  	itc_at_boot = itc_alt;
    6.27  	new = ia64_get_itc() + itm_val;
     7.1 --- a/extras/mini-os/arch/x86/time.c	Fri Mar 14 15:07:45 2008 -0600
     7.2 +++ b/extras/mini-os/arch/x86/time.c	Thu Mar 20 12:35:40 2008 -0600
     7.3 @@ -222,6 +222,8 @@ static void timer_handler(evtchn_port_t 
     7.4  
     7.5  void init_time(void)
     7.6  {
     7.7 +    evtchn_port_t port;
     7.8      printk("Initialising timer interface\n");
     7.9 -    bind_virq(VIRQ_TIMER, &timer_handler, NULL);
    7.10 +    port = bind_virq(VIRQ_TIMER, &timer_handler, NULL);
    7.11 +    unmask_evtchn(port);
    7.12  }
     8.1 --- a/extras/mini-os/blkfront.c	Fri Mar 14 15:07:45 2008 -0600
     8.2 +++ b/extras/mini-os/blkfront.c	Thu Mar 20 12:35:40 2008 -0600
     8.3 @@ -43,7 +43,7 @@ struct blkfront_dev {
     8.4  
     8.5      struct blkif_front_ring ring;
     8.6      grant_ref_t ring_ref;
     8.7 -    evtchn_port_t evtchn, local_port;
     8.8 +    evtchn_port_t evtchn;
     8.9      blkif_vdev_t handle;
    8.10  
    8.11      char *nodename;
    8.12 @@ -70,7 +70,7 @@ void blkfront_handler(evtchn_port_t port
    8.13      wake_up(&blkfront_queue);
    8.14  }
    8.15  
    8.16 -struct blkfront_dev *init_blkfront(char *nodename, uint64_t *sectors, unsigned *sector_size, int *mode)
    8.17 +struct blkfront_dev *init_blkfront(char *nodename, uint64_t *sectors, unsigned *sector_size, int *mode, int *info)
    8.18  {
    8.19      xenbus_transaction_t xbt;
    8.20      char* err;
    8.21 @@ -92,14 +92,9 @@ struct blkfront_dev *init_blkfront(char 
    8.22      dev = malloc(sizeof(*dev));
    8.23      dev->nodename = strdup(nodename);
    8.24  
    8.25 -    evtchn_alloc_unbound_t op;
    8.26 -    op.dom = DOMID_SELF;
    8.27      snprintf(path, sizeof(path), "%s/backend-id", nodename);
    8.28 -    dev->dom = op.remote_dom = xenbus_read_integer(path); 
    8.29 -    HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
    8.30 -    clear_evtchn(op.port);        /* Without, handler gets invoked now! */
    8.31 -    dev->local_port = bind_evtchn(op.port, blkfront_handler, dev);
    8.32 -    dev->evtchn=op.port;
    8.33 +    dev->dom = xenbus_read_integer(path); 
    8.34 +    evtchn_alloc_unbound(dev->dom, blkfront_handler, dev, &dev->evtchn);
    8.35  
    8.36      s = (struct blkif_sring*) alloc_page();
    8.37      memset(s,0,PAGE_SIZE);
    8.38 @@ -181,6 +176,9 @@ done:
    8.39  
    8.40          xenbus_unwatch_path(XBT_NIL, path);
    8.41  
    8.42 +        snprintf(path, sizeof(path), "%s/info", dev->backend);
    8.43 +        *info = xenbus_read_integer(path);
    8.44 +
    8.45          snprintf(path, sizeof(path), "%s/sectors", dev->backend);
    8.46          // FIXME: read_integer returns an int, so disk size limited to 1TB for now
    8.47          *sectors = dev->sectors = xenbus_read_integer(path);
    8.48 @@ -194,6 +192,7 @@ done:
    8.49          snprintf(path, sizeof(path), "%s/feature-flush-cache", dev->backend);
    8.50          dev->flush = xenbus_read_integer(path);
    8.51      }
    8.52 +    unmask_evtchn(dev->evtchn);
    8.53  
    8.54      printk("%u sectors of %u bytes\n", dev->sectors, dev->sector_size);
    8.55      printk("**************************\n");
    8.56 @@ -219,7 +218,7 @@ void shutdown_blkfront(struct blkfront_d
    8.57      err = xenbus_printf(XBT_NIL, nodename, "state", "%u", 6);
    8.58      xenbus_wait_for_value(path,"6");
    8.59  
    8.60 -    unbind_evtchn(dev->local_port);
    8.61 +    unbind_evtchn(dev->evtchn);
    8.62  
    8.63      free(nodename);
    8.64      free(dev->backend);
     9.1 --- a/extras/mini-os/console/xencons_ring.c	Fri Mar 14 15:07:45 2008 -0600
     9.2 +++ b/extras/mini-os/console/xencons_ring.c	Thu Mar 20 12:35:40 2008 -0600
     9.3 @@ -86,6 +86,7 @@ int xencons_ring_init(void)
     9.4  		printk("XEN console request chn bind failed %i\n", err);
     9.5  		return err;
     9.6  	}
     9.7 +        unmask_evtchn(start_info.console.domU.evtchn);
     9.8  
     9.9  	/* In case we have in-flight data after save/restore... */
    9.10  	notify_daemon();
    10.1 --- a/extras/mini-os/daytime.c	Fri Mar 14 15:07:45 2008 -0600
    10.2 +++ b/extras/mini-os/daytime.c	Thu Mar 20 12:35:40 2008 -0600
    10.3 @@ -15,16 +15,19 @@ static char message[29];
    10.4  void run_server(void *p)
    10.5  {
    10.6      struct ip_addr listenaddr = { 0 };
    10.7 -    struct ip_addr ipaddr = { htonl(0x0a000001) };
    10.8 -    struct ip_addr netmask = { htonl(0xff000000) };
    10.9 -    struct ip_addr gw = { 0 };
   10.10      struct netconn *listener;
   10.11      struct netconn *session;
   10.12      struct timeval tv;
   10.13      err_t rc;
   10.14  
   10.15      start_networking();
   10.16 -    networking_set_addr(&ipaddr, &netmask, &gw);
   10.17 +
   10.18 +    if (0) {
   10.19 +        struct ip_addr ipaddr = { htonl(0x0a000001) };
   10.20 +        struct ip_addr netmask = { htonl(0xff000000) };
   10.21 +        struct ip_addr gw = { 0 };
   10.22 +        networking_set_addr(&ipaddr, &netmask, &gw);
   10.23 +    }
   10.24  
   10.25      tprintk("Opening connection\n");
   10.26  
    11.1 --- a/extras/mini-os/events.c	Fri Mar 14 15:07:45 2008 -0600
    11.2 +++ b/extras/mini-os/events.c	Thu Mar 20 12:35:40 2008 -0600
    11.3 @@ -87,9 +87,6 @@ evtchn_port_t bind_evtchn(evtchn_port_t 
    11.4  	wmb();
    11.5  	ev_actions[port].handler = handler;
    11.6  
    11.7 -	/* Finally unmask the port */
    11.8 -	unmask_evtchn(port);
    11.9 -
   11.10  	return port;
   11.11  }
   11.12  
   11.13 @@ -191,8 +188,7 @@ int evtchn_bind_interdomain(domid_t pal,
   11.14      if (err)
   11.15  		return err;
   11.16      set_bit(op.local_port,bound_ports);
   11.17 -	evtchn_port_t port = op.local_port;
   11.18 -    clear_evtchn(port);	      /* Without, handler gets invoked now! */
   11.19 +    evtchn_port_t port = op.local_port;
   11.20      *local_port = bind_evtchn(port, handler, data);
   11.21      return err;
   11.22  }
    12.1 --- a/extras/mini-os/fbfront.c	Fri Mar 14 15:07:45 2008 -0600
    12.2 +++ b/extras/mini-os/fbfront.c	Thu Mar 20 12:35:40 2008 -0600
    12.3 @@ -26,7 +26,7 @@ struct kbdfront_dev {
    12.4      domid_t dom;
    12.5  
    12.6      struct xenkbd_page *page;
    12.7 -    evtchn_port_t evtchn, local_port;
    12.8 +    evtchn_port_t evtchn;
    12.9  
   12.10      char *nodename;
   12.11      char *backend;
   12.12 @@ -68,14 +68,9 @@ struct kbdfront_dev *init_kbdfront(char 
   12.13      dev = malloc(sizeof(*dev));
   12.14      dev->nodename = strdup(nodename);
   12.15  
   12.16 -    evtchn_alloc_unbound_t op;
   12.17 -    op.dom = DOMID_SELF;
   12.18      snprintf(path, sizeof(path), "%s/backend-id", nodename);
   12.19 -    dev->dom = op.remote_dom = xenbus_read_integer(path); 
   12.20 -    HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
   12.21 -    clear_evtchn(op.port);        /* Without, handler gets invoked now! */
   12.22 -    dev->local_port = bind_evtchn(op.port, kbdfront_handler, dev);
   12.23 -    dev->evtchn=op.port;
   12.24 +    dev->dom = xenbus_read_integer(path); 
   12.25 +    evtchn_alloc_unbound(dev->dom, kbdfront_handler, dev, &dev->evtchn);
   12.26  
   12.27      dev->page = s = (struct xenkbd_page*) alloc_page();
   12.28      memset(s,0,PAGE_SIZE);
   12.29 @@ -151,6 +146,7 @@ done:
   12.30  
   12.31          err = xenbus_printf(XBT_NIL, nodename, "state", "%u", 4); /* connected */
   12.32      }
   12.33 +    unmask_evtchn(dev->evtchn);
   12.34  
   12.35      printk("************************** KBDFRONT\n");
   12.36  
   12.37 @@ -208,7 +204,7 @@ void shutdown_kbdfront(struct kbdfront_d
   12.38      err = xenbus_printf(XBT_NIL, nodename, "state", "%u", 6);
   12.39      xenbus_wait_for_value(path,"6");
   12.40  
   12.41 -    unbind_evtchn(dev->local_port);
   12.42 +    unbind_evtchn(dev->evtchn);
   12.43  
   12.44      free_pages(dev->page,0);
   12.45      free(nodename);
   12.46 @@ -241,7 +237,7 @@ struct fbfront_dev {
   12.47      domid_t dom;
   12.48  
   12.49      struct xenfb_page *page;
   12.50 -    evtchn_port_t evtchn, local_port;
   12.51 +    evtchn_port_t evtchn;
   12.52  
   12.53      char *nodename;
   12.54      char *backend;
   12.55 @@ -281,14 +277,9 @@ struct fbfront_dev *init_fbfront(char *n
   12.56      dev = malloc(sizeof(*dev));
   12.57      dev->nodename = strdup(nodename);
   12.58  
   12.59 -    evtchn_alloc_unbound_t op;
   12.60 -    op.dom = DOMID_SELF;
   12.61      snprintf(path, sizeof(path), "%s/backend-id", nodename);
   12.62 -    dev->dom = op.remote_dom = xenbus_read_integer(path); 
   12.63 -    HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
   12.64 -    clear_evtchn(op.port);        /* Without, handler gets invoked now! */
   12.65 -    dev->local_port = bind_evtchn(op.port, fbfront_handler, dev);
   12.66 -    dev->evtchn=op.port;
   12.67 +    dev->dom = xenbus_read_integer(path); 
   12.68 +    evtchn_alloc_unbound(dev->dom, fbfront_handler, dev, &dev->evtchn);
   12.69  
   12.70      dev->page = s = (struct xenfb_page*) alloc_page();
   12.71      memset(s,0,PAGE_SIZE);
   12.72 @@ -397,6 +388,7 @@ done:
   12.73  
   12.74          err = xenbus_printf(XBT_NIL, nodename, "state", "%u", 4); /* connected */
   12.75      }
   12.76 +    unmask_evtchn(dev->evtchn);
   12.77  
   12.78      printk("************************** FBFRONT\n");
   12.79  
   12.80 @@ -462,7 +454,7 @@ void shutdown_fbfront(struct fbfront_dev
   12.81      err = xenbus_printf(XBT_NIL, nodename, "state", "%u", 6);
   12.82      xenbus_wait_for_value(path,"6");
   12.83  
   12.84 -    unbind_evtchn(dev->local_port);
   12.85 +    unbind_evtchn(dev->evtchn);
   12.86  
   12.87      free_pages(dev->page,0);
   12.88      free(nodename);
    13.1 --- a/extras/mini-os/fs-front.c	Fri Mar 14 15:07:45 2008 -0600
    13.2 +++ b/extras/mini-os/fs-front.c	Thu Mar 20 12:35:40 2008 -0600
    13.3 @@ -943,6 +943,7 @@ static int init_fs_import(struct fs_impo
    13.4                                  //ANY_CPU, 
    13.5                                  import, 
    13.6                                  &import->local_port));
    13.7 +    unmask_evtchn(import->local_port);
    13.8  
    13.9      
   13.10      self_id = get_self_id(); 
    14.1 --- a/extras/mini-os/include/blkfront.h	Fri Mar 14 15:07:45 2008 -0600
    14.2 +++ b/extras/mini-os/include/blkfront.h	Thu Mar 20 12:35:40 2008 -0600
    14.3 @@ -15,7 +15,7 @@ struct blkfront_aiocb
    14.4  
    14.5      void (*aio_cb)(struct blkfront_aiocb *aiocb, int ret);
    14.6  };
    14.7 -struct blkfront_dev *init_blkfront(char *nodename, uint64_t *sectors, unsigned *sector_size, int *mode);
    14.8 +struct blkfront_dev *init_blkfront(char *nodename, uint64_t *sectors, unsigned *sector_size, int *mode, int *info);
    14.9  #ifdef HAVE_LIBC
   14.10  int blkfront_open(struct blkfront_dev *dev);
   14.11  #endif
    15.1 --- a/extras/mini-os/include/fcntl.h	Fri Mar 14 15:07:45 2008 -0600
    15.2 +++ b/extras/mini-os/include/fcntl.h	Thu Mar 20 12:35:40 2008 -0600
    15.3 @@ -1,6 +1,10 @@
    15.4  #ifndef _I386_FCNTL_H
    15.5  #define _I386_FCNTL_H
    15.6  
    15.7 +#ifdef HAVE_LIBC
    15.8 +#include_next <fcntl.h>
    15.9 +#else
   15.10 +
   15.11  /* open/fcntl - O_SYNC is only implemented on blocks devices and on files
   15.12     located on an ext2 file system */
   15.13  #define O_ACCMODE	   0003
   15.14 @@ -90,3 +94,5 @@ struct flock64 {
   15.15  int open(const char *path, int flags, ...);
   15.16  int fcntl(int fd, int cmd, ...);
   15.17  #endif
   15.18 +
   15.19 +#endif
    16.1 --- a/extras/mini-os/include/netfront.h	Fri Mar 14 15:07:45 2008 -0600
    16.2 +++ b/extras/mini-os/include/netfront.h	Thu Mar 20 12:35:40 2008 -0600
    16.3 @@ -3,7 +3,7 @@
    16.4  #include <lwip/netif.h>
    16.5  #endif
    16.6  struct netfront_dev;
    16.7 -struct netfront_dev *init_netfront(char *nodename, void (*netif_rx)(unsigned char *data, int len), unsigned char rawmac[6]);
    16.8 +struct netfront_dev *init_netfront(char *nodename, void (*netif_rx)(unsigned char *data, int len), unsigned char rawmac[6], char **ip);
    16.9  void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len);
   16.10  void shutdown_netfront(struct netfront_dev *dev);
   16.11  #ifdef HAVE_LIBC
    17.1 --- a/extras/mini-os/kernel.c	Fri Mar 14 15:07:45 2008 -0600
    17.2 +++ b/extras/mini-os/kernel.c	Thu Mar 20 12:35:40 2008 -0600
    17.3 @@ -87,7 +87,7 @@ static void periodic_thread(void *p)
    17.4  
    17.5  static void netfront_thread(void *p)
    17.6  {
    17.7 -    init_netfront(NULL, NULL, NULL);
    17.8 +    init_netfront(NULL, NULL, NULL, NULL);
    17.9  }
   17.10  
   17.11  static struct blkfront_dev *blk_dev;
   17.12 @@ -207,10 +207,19 @@ static void blk_write_sector(uint64_t se
   17.13  static void blkfront_thread(void *p)
   17.14  {
   17.15      time_t lasttime = 0;
   17.16 -    blk_dev = init_blkfront(NULL, &blk_sectors, &blk_sector_size, &blk_mode);
   17.17 +    int blk_info;
   17.18 +
   17.19 +    blk_dev = init_blkfront(NULL, &blk_sectors, &blk_sector_size, &blk_mode, &blk_info);
   17.20      if (!blk_dev)
   17.21          return;
   17.22  
   17.23 +    if (blk_info & VDISK_CDROM)
   17.24 +        printk("Block device is a CDROM\n");
   17.25 +    if (blk_info & VDISK_REMOVABLE)
   17.26 +        printk("Block device is removable\n");
   17.27 +    if (blk_info & VDISK_READONLY)
   17.28 +        printk("Block device is read-only\n");
   17.29 +
   17.30  #ifdef BLKTEST_WRITE
   17.31      if (blk_mode == O_RDWR) {
   17.32          blk_write_sector(0);
    18.1 --- a/extras/mini-os/lib/sys.c	Fri Mar 14 15:07:45 2008 -0600
    18.2 +++ b/extras/mini-os/lib/sys.c	Thu Mar 20 12:35:40 2008 -0600
    18.3 @@ -171,8 +171,25 @@ int open(const char *pathname, int flags
    18.4          printk("open(%s) -> %d\n", pathname, fd);
    18.5          return fd;
    18.6      }
    18.7 -    printk("open(%s)", pathname);
    18.8 -    fs_fd = fs_open(fs_import, (void *) pathname);
    18.9 +    printk("open(%s, %x)", pathname, flags);
   18.10 +    switch (flags & ~O_ACCMODE) {
   18.11 +        case 0:
   18.12 +            fs_fd = fs_open(fs_import, (void *) pathname);
   18.13 +            break;
   18.14 +        case O_CREAT|O_TRUNC:
   18.15 +        {
   18.16 +            va_list ap;
   18.17 +            mode_t mode;
   18.18 +            va_start(ap, flags);
   18.19 +            mode = va_arg(ap, mode_t);
   18.20 +            va_end(ap);
   18.21 +            fs_fd = fs_create(fs_import, (void *) pathname, 0, mode);
   18.22 +            break;
   18.23 +        }
   18.24 +        default:
   18.25 +            printk(" unsupported flags\n");
   18.26 +            do_exit();
   18.27 +    }
   18.28      if (fs_fd < 0) {
   18.29  	errno = EIO;
   18.30  	return -1;
   18.31 @@ -819,9 +836,19 @@ int select(int nfds, fd_set *readfds, fd
   18.32      add_waiter(w4, xenbus_watch_queue);
   18.33      add_waiter(w5, kbdfront_queue);
   18.34  
   18.35 -    myread = *readfds;
   18.36 -    mywrite = *writefds;
   18.37 -    myexcept = *exceptfds;
   18.38 +    if (readfds)
   18.39 +        myread = *readfds;
   18.40 +    else
   18.41 +        FD_ZERO(&myread);
   18.42 +    if (writefds)
   18.43 +        mywrite = *writefds;
   18.44 +    else
   18.45 +        FD_ZERO(&mywrite);
   18.46 +    if (exceptfds)
   18.47 +        myexcept = *exceptfds;
   18.48 +    else
   18.49 +        FD_ZERO(&myexcept);
   18.50 +
   18.51      DEBUG("polling ");
   18.52      dump_set(nfds, &myread, &mywrite, &myexcept, timeout);
   18.53      DEBUG("\n");
   18.54 @@ -860,9 +887,19 @@ int select(int nfds, fd_set *readfds, fd
   18.55  	thread->wakeup_time = stop;
   18.56      schedule();
   18.57  
   18.58 -    myread = *readfds;
   18.59 -    mywrite = *writefds;
   18.60 -    myexcept = *exceptfds;
   18.61 +    if (readfds)
   18.62 +        myread = *readfds;
   18.63 +    else
   18.64 +        FD_ZERO(&myread);
   18.65 +    if (writefds)
   18.66 +        mywrite = *writefds;
   18.67 +    else
   18.68 +        FD_ZERO(&mywrite);
   18.69 +    if (exceptfds)
   18.70 +        myexcept = *exceptfds;
   18.71 +    else
   18.72 +        FD_ZERO(&myexcept);
   18.73 +
   18.74      n = select_poll(nfds, &myread, &mywrite, &myexcept);
   18.75  
   18.76      if (n) {
    19.1 --- a/extras/mini-os/lwip-net.c	Fri Mar 14 15:07:45 2008 -0600
    19.2 +++ b/extras/mini-os/lwip-net.c	Thu Mar 20 12:35:40 2008 -0600
    19.3 @@ -339,10 +339,25 @@ void start_networking(void)
    19.4    struct ip_addr ipaddr = { htonl(IF_IPADDR) };
    19.5    struct ip_addr netmask = { htonl(IF_NETMASK) };
    19.6    struct ip_addr gw = { 0 };
    19.7 +  char *ip;
    19.8  
    19.9    tprintk("Waiting for network.\n");
   19.10  
   19.11 -  dev = init_netfront(NULL, NULL, rawmac);
   19.12 +  dev = init_netfront(NULL, NULL, rawmac, &ip);
   19.13 +  
   19.14 +  if (ip) {
   19.15 +    ipaddr.addr = inet_addr(ip);
   19.16 +    if (IN_CLASSA(ntohl(ipaddr.addr)))
   19.17 +      netmask.addr = htonl(IN_CLASSA_NET);
   19.18 +    else if (IN_CLASSB(ntohl(ipaddr.addr)))
   19.19 +      netmask.addr = htonl(IN_CLASSB_NET);
   19.20 +    else if (IN_CLASSC(ntohl(ipaddr.addr)))
   19.21 +      netmask.addr = htonl(IN_CLASSC_NET);
   19.22 +    else
   19.23 +      tprintk("Strange IP %s, leaving netmask to 0.\n", ip);
   19.24 +  }
   19.25 +  tprintk("IP %x netmask %x gateway %x.\n",
   19.26 +          ntohl(ipaddr.addr), ntohl(netmask.addr), ntohl(gw.addr));
   19.27    
   19.28    tprintk("TCP/IP bringup begins.\n");
   19.29    
    20.1 --- a/extras/mini-os/main.c	Fri Mar 14 15:07:45 2008 -0600
    20.2 +++ b/extras/mini-os/main.c	Thu Mar 20 12:35:40 2008 -0600
    20.3 @@ -42,6 +42,9 @@ void _fini(void)
    20.4  static void call_main(void *p)
    20.5  {
    20.6      char *args, /**path,*/ *msg, *c;
    20.7 +#ifdef CONFIG_QEMU
    20.8 +    char *domargs;
    20.9 +#endif
   20.10      int argc;
   20.11      char **argv;
   20.12      char *envp[] = { NULL };
   20.13 @@ -63,14 +66,12 @@ static void call_main(void *p)
   20.14      }
   20.15  
   20.16      /* Fetch argc, argv from XenStore */
   20.17 -    char domid_s[10];
   20.18      int domid;
   20.19      domid = xenbus_read_integer("target");
   20.20      if (domid == -1) {
   20.21          printk("Couldn't read target\n");
   20.22          do_exit();
   20.23      }
   20.24 -    snprintf(domid_s, sizeof(domid_s), "%d", domid);
   20.25  
   20.26      snprintf(path, sizeof(path), "/local/domain/%d/vm", domid);
   20.27      msg = xenbus_read(XBT_NIL, path, &vm);
   20.28 @@ -78,59 +79,64 @@ static void call_main(void *p)
   20.29          printk("Couldn't read vm path\n");
   20.30          do_exit();
   20.31      }
   20.32 -    printk("vm is at %s\n", vm);
   20.33 -#else
   20.34 +    printk("dom vm is at %s\n", vm);
   20.35 +
   20.36 +    snprintf(path, sizeof(path), "%s/image/dmargs", vm);
   20.37 +    free(vm);
   20.38 +    msg = xenbus_read(XBT_NIL, path, &domargs);
   20.39 +
   20.40 +    if (msg) {
   20.41 +        printk("Couldn't get stubdom args: %s\n", msg);
   20.42 +        domargs = strdup("");
   20.43 +    }
   20.44 +#endif
   20.45 +
   20.46      msg = xenbus_read(XBT_NIL, "vm", &vm);
   20.47      if (msg) {
   20.48          printk("Couldn't read vm path\n");
   20.49          do_exit();
   20.50      }
   20.51 -#endif
   20.52  
   20.53 -    snprintf(path, sizeof(path), "%s/image/dmargs", vm);
   20.54 +    printk("my vm is at %s\n", vm);
   20.55 +    snprintf(path, sizeof(path), "%s/image/cmdline", vm);
   20.56      free(vm);
   20.57      msg = xenbus_read(XBT_NIL, path, &args);
   20.58  
   20.59      if (msg) {
   20.60 -        printk("Couldn't get stubdom args: %s\n", msg);
   20.61 +        printk("Couldn't get my args: %s\n", msg);
   20.62          args = strdup("");
   20.63      }
   20.64  
   20.65      argc = 1;
   20.66 +
   20.67 +#define PARSE_ARGS(ARGS,START,END) \
   20.68 +    c = ARGS; \
   20.69 +    while (*c) { \
   20.70 +	if (*c != ' ') { \
   20.71 +	    START; \
   20.72 +	    while (*c && *c != ' ') \
   20.73 +		c++; \
   20.74 +	} else { \
   20.75 +            END; \
   20.76 +	    while (*c == ' ') \
   20.77 +		c++; \
   20.78 +	} \
   20.79 +    }
   20.80 +
   20.81 +    PARSE_ARGS(args, argc++, );
   20.82  #ifdef CONFIG_QEMU
   20.83 -    argc += 2;
   20.84 +    PARSE_ARGS(domargs, argc++, );
   20.85  #endif
   20.86 -    c = args;
   20.87 -    while (*c) {
   20.88 -	if (*c != ' ') {
   20.89 -	    argc++;
   20.90 -	    while (*c && *c != ' ')
   20.91 -		c++;
   20.92 -	} else {
   20.93 -	    while (*c == ' ')
   20.94 -		c++;
   20.95 -	}
   20.96 -    }
   20.97 +
   20.98      argv = alloca((argc + 1) * sizeof(char *));
   20.99      argv[0] = "main";
  20.100      argc = 1;
  20.101 +
  20.102 +    PARSE_ARGS(args, argv[argc++] = c, *c++ = 0)
  20.103  #ifdef CONFIG_QEMU
  20.104 -    argv[1] = "-d";
  20.105 -    argv[2] = domid_s;
  20.106 -    argc += 2;
  20.107 +    PARSE_ARGS(domargs, argv[argc++] = c, *c++ = 0)
  20.108  #endif
  20.109 -    c = args;
  20.110 -    while (*c) {
  20.111 -	if (*c != ' ') {
  20.112 -	    argv[argc++] = c;
  20.113 -	    while (*c && *c != ' ')
  20.114 -		c++;
  20.115 -	} else {
  20.116 -	    *c++ = 0;
  20.117 -	    while (*c == ' ')
  20.118 -		c++;
  20.119 -	}
  20.120 -    }
  20.121 +
  20.122      argv[argc] = NULL;
  20.123  
  20.124      for (i = 0; i < argc; i++)
    21.1 --- a/extras/mini-os/netfront.c	Fri Mar 14 15:07:45 2008 -0600
    21.2 +++ b/extras/mini-os/netfront.c	Thu Mar 20 12:35:40 2008 -0600
    21.3 @@ -48,7 +48,7 @@ struct netfront_dev {
    21.4      struct netif_rx_front_ring rx;
    21.5      grant_ref_t tx_ring_ref;
    21.6      grant_ref_t rx_ring_ref;
    21.7 -    evtchn_port_t evtchn, local_port;
    21.8 +    evtchn_port_t evtchn;
    21.9  
   21.10      char *nodename;
   21.11      char *backend;
   21.12 @@ -259,7 +259,7 @@ void netfront_select_handler(evtchn_port
   21.13  }
   21.14  #endif
   21.15  
   21.16 -struct netfront_dev *init_netfront(char *nodename, void (*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6])
   21.17 +struct netfront_dev *init_netfront(char *nodename, void (*thenetif_rx)(unsigned char* data, int len), unsigned char rawmac[6], char **ip)
   21.18  {
   21.19      xenbus_transaction_t xbt;
   21.20      char* err;
   21.21 @@ -301,19 +301,14 @@ struct netfront_dev *init_netfront(char 
   21.22          dev->rx_buffers[i].page = (char*)alloc_page();
   21.23      }
   21.24  
   21.25 -    evtchn_alloc_unbound_t op;
   21.26 -    op.dom = DOMID_SELF;
   21.27      snprintf(path, sizeof(path), "%s/backend-id", nodename);
   21.28 -    dev->dom = op.remote_dom = xenbus_read_integer(path);
   21.29 -    HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
   21.30 -    clear_evtchn(op.port);        /* Without, handler gets invoked now! */
   21.31 +    dev->dom = xenbus_read_integer(path);
   21.32  #ifdef HAVE_LIBC
   21.33      if (thenetif_rx == NETIF_SELECT_RX)
   21.34 -	dev->local_port = bind_evtchn(op.port, netfront_select_handler, dev);
   21.35 +        evtchn_alloc_unbound(dev->dom, netfront_select_handler, dev, &dev->evtchn);
   21.36      else
   21.37  #endif
   21.38 -	dev->local_port = bind_evtchn(op.port, netfront_handler, dev);
   21.39 -    dev->evtchn=op.port;
   21.40 +        evtchn_alloc_unbound(dev->dom, netfront_handler, dev, &dev->evtchn);
   21.41  
   21.42      txs = (struct netif_tx_sring*) alloc_page();
   21.43      rxs = (struct netif_rx_sring *) alloc_page();
   21.44 @@ -388,9 +383,9 @@ done:
   21.45      msg = xenbus_read(XBT_NIL, path, &mac);
   21.46  
   21.47      if ((dev->backend == NULL) || (mac == NULL)) {
   21.48 -        struct evtchn_close op = { dev->local_port };
   21.49 +        struct evtchn_close op = { dev->evtchn };
   21.50          printk("%s: backend/mac failed\n", __func__);
   21.51 -        unbind_evtchn(dev->local_port);
   21.52 +        unbind_evtchn(dev->evtchn);
   21.53          HYPERVISOR_event_channel_op(EVTCHNOP_close, &op);
   21.54          return NULL;
   21.55      }
   21.56 @@ -407,11 +402,17 @@ done:
   21.57          xenbus_wait_for_value(path,"4");
   21.58  
   21.59          xenbus_unwatch_path(XBT_NIL, path);
   21.60 +
   21.61 +        if (ip) {
   21.62 +            snprintf(path, sizeof(path), "%s/ip", dev->backend);
   21.63 +            xenbus_read(XBT_NIL, path, ip);
   21.64 +        }
   21.65      }
   21.66  
   21.67      printk("**************************\n");
   21.68  
   21.69      init_rx_buffers(dev);
   21.70 +    unmask_evtchn(dev->evtchn);
   21.71  
   21.72          /* Special conversion specifier 'hh' needed for __ia64__. Without
   21.73             this mini-os panics with 'Unaligned reference'. */
   21.74 @@ -431,7 +432,7 @@ done:
   21.75  int netfront_tap_open(char *nodename) {
   21.76      struct netfront_dev *dev;
   21.77  
   21.78 -    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL);
   21.79 +    dev = init_netfront(nodename, NETIF_SELECT_RX, NULL, NULL);
   21.80      if (!dev) {
   21.81  	printk("TAP open failed\n");
   21.82  	errno = EIO;
   21.83 @@ -460,7 +461,7 @@ void shutdown_netfront(struct netfront_d
   21.84      err = xenbus_printf(XBT_NIL, nodename, "state", "%u", 6);
   21.85      xenbus_wait_for_value(path,"6");
   21.86  
   21.87 -    unbind_evtchn(dev->local_port);
   21.88 +    unbind_evtchn(dev->evtchn);
   21.89  
   21.90      free(nodename);
   21.91      free(dev->backend);
    22.1 --- a/extras/mini-os/xenbus/xenbus.c	Fri Mar 14 15:07:45 2008 -0600
    22.2 +++ b/extras/mini-os/xenbus/xenbus.c	Thu Mar 20 12:35:40 2008 -0600
    22.3 @@ -257,6 +257,7 @@ void init_xenbus(void)
    22.4      err = bind_evtchn(start_info.store_evtchn,
    22.5  		      xenbus_evtchn_handler,
    22.6                NULL);
    22.7 +    unmask_evtchn(start_info.store_evtchn);
    22.8      DEBUG("xenbus on irq %d\n", err);
    22.9  }
   22.10  
   22.11 @@ -452,7 +453,7 @@ char *xenbus_write(xenbus_transaction_t 
   22.12  {
   22.13      struct write_req req[] = { 
   22.14  	{path, strlen(path) + 1},
   22.15 -	{value, strlen(value) + 1},
   22.16 +	{value, strlen(value)},
   22.17      };
   22.18      struct xsd_sockmsg *rep;
   22.19      rep = xenbus_msg_reply(XS_WRITE, xbt, req, ARRAY_SIZE(req));
    23.1 --- a/stubdom/Makefile	Fri Mar 14 15:07:45 2008 -0600
    23.2 +++ b/stubdom/Makefile	Thu Mar 20 12:35:40 2008 -0600
    23.3 @@ -201,6 +201,14 @@ ioemu: cross-zlib cross-libpci mk-symlin
    23.4  caml:
    23.5  	$(MAKE) -C $@
    23.6  
    23.7 +###
    23.8 +# C
    23.9 +###
   23.10 +
   23.11 +.PHONY: c
   23.12 +c:
   23.13 +	$(MAKE) -C $@
   23.14 +
   23.15  ########
   23.16  # minios
   23.17  ########
   23.18 @@ -211,7 +219,11 @@ qemu-stubdom: mk-symlinks lwip-cvs libxc
   23.19  
   23.20  .PHONY: caml-stubdom
   23.21  caml-stubdom: mk-symlinks lwip-cvs libxc cross-libpci caml
   23.22 -	$(MAKE) -C mini-os LWIPDIR=$(CURDIR)/lwia-cvs CAMLDIR=$(CURDIR)/caml
   23.23 +	$(MAKE) -C mini-os LWIPDIR=$(CURDIR)/lwip-cvs CAMLDIR=$(CURDIR)/caml
   23.24 +
   23.25 +.PHONY: c-stubdom
   23.26 +c-stubdom: mk-symlinks lwip-cvs libxc cross-libpci c
   23.27 +	$(MAKE) -C mini-os LWIPDIR=$(CURDIR)/lwip-cvs CDIR=$(CURDIR)/c
   23.28  
   23.29  #########
   23.30  # install
    24.1 --- a/stubdom/README	Fri Mar 14 15:07:45 2008 -0600
    24.2 +++ b/stubdom/README	Thu Mar 20 12:35:40 2008 -0600
    24.3 @@ -78,6 +78,8 @@ To run
    24.4  
    24.5  mkdir -p /exports/usr/share/qemu
    24.6  ln -s /usr/share/qemu/keymaps /exports/usr/share/qemu
    24.7 +mkdir -p /exports/var/lib
    24.8 +ln -s /var/lib/xen /exports/var/lib
    24.9  /usr/sbin/fs-backend &
   24.10  
   24.11  xm create hvmconfig
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/stubdom/c/Makefile	Thu Mar 20 12:35:40 2008 -0600
    25.3 @@ -0,0 +1,9 @@
    25.4 +XEN_ROOT = ../..
    25.5 +
    25.6 +include $(XEN_ROOT)/Config.mk
    25.7 +
    25.8 +main.a: main.o
    25.9 +	$(AR) cr $@ $^
   25.10 +
   25.11 +clean:
   25.12 +	rm -f *.a *.o
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/stubdom/c/main.c	Thu Mar 20 12:35:40 2008 -0600
    26.3 @@ -0,0 +1,6 @@
    26.4 +#include <stdio.h>
    26.5 +int main(void) {
    26.6 +        sleep(2);
    26.7 +        printf("Hello, world!\n");
    26.8 +        return 0;
    26.9 +}
    27.1 --- a/stubdom/stubdom-dm	Fri Mar 14 15:07:45 2008 -0600
    27.2 +++ b/stubdom/stubdom-dm	Thu Mar 20 12:35:40 2008 -0600
    27.3 @@ -14,18 +14,30 @@ domid=
    27.4  domname=
    27.5  vncviewer=0
    27.6  vncpid=
    27.7 +extra=
    27.8  while [ "$#" -gt 0 ];
    27.9  do
   27.10      if [ "$#" -ge 2 ];
   27.11      then
   27.12  	case "$1" in
   27.13 -	    -d) domid=$2; shift ;;
   27.14 -	    -domain-name) domname=$2; shift ;;
   27.15 +	    -d)
   27.16 +                domid=$2;
   27.17 +                extra="$extra -d $domid";
   27.18 +                shift
   27.19 +                ;;
   27.20 +	    -domain-name)
   27.21 +                domname=$2;
   27.22 +                shift
   27.23 +                ;;
   27.24  	    -vnc)
   27.25  		ip=${2%:*};
   27.26  		vnc_port=${2#*:};
   27.27  		shift
   27.28  		;;
   27.29 +            -loadvm)
   27.30 +                extra="$extra -loadvm $2";
   27.31 +                shift
   27.32 +                ;;
   27.33  	esac
   27.34      fi
   27.35      case "$1" in
   27.36 @@ -60,7 +72,7 @@ do
   27.37  	sleep 1
   27.38  done
   27.39  
   27.40 -creation="xm create -c stubdom-$domname target=$domid memory=32"
   27.41 +creation="xm create -c stubdom-$domname target=$domid memory=32 extra=\"$extra\""
   27.42  
   27.43  (while true ; do sleep 60 ; done) | $creation &
   27.44  #xterm -geometry +0+0 -e /bin/sh -c "$creation ; echo ; echo press ENTER to shut down ; read" &
    28.1 --- a/tools/blktap/drivers/Makefile	Fri Mar 14 15:07:45 2008 -0600
    28.2 +++ b/tools/blktap/drivers/Makefile	Thu Mar 20 12:35:40 2008 -0600
    28.3 @@ -1,26 +1,24 @@
    28.4  XEN_ROOT = ../../..
    28.5  include $(XEN_ROOT)/tools/Rules.mk
    28.6  
    28.7 -INCLUDES += -I.. -I../lib -I$(XEN_INCLUDE)
    28.8 -
    28.9  IBIN         = blktapctrl tapdisk
   28.10  QCOW_UTIL    = img2qcow qcow2raw qcow-create
   28.11  LIBAIO_DIR   = ../../libaio/src
   28.12  
   28.13  CFLAGS   += -Werror
   28.14  CFLAGS   += -Wno-unused
   28.15 -CFLAGS   += $(CFLAGS_libxenctrl) -I $(LIBAIO_DIR)
   28.16 -CFLAGS   += $(INCLUDES) -I. -I../../xenstore 
   28.17 +CFLAGS   += -I../lib
   28.18 +CFLAGS   += $(CFLAGS_libxenctrl)
   28.19 +CFLAGS   += $(CFLAGS_libxenstore)
   28.20 +CFLAGS   += -I $(LIBAIO_DIR)
   28.21  CFLAGS   += -D_GNU_SOURCE
   28.22  
   28.23  # Get gcc to generate the dependencies for us.
   28.24  CFLAGS   += -Wp,-MD,.$(@F).d
   28.25  DEPS      = .*.d
   28.26  
   28.27 -LIBS      := -L. -L.. -L../lib
   28.28 -LIBS      += -Wl,-rpath-link,$(XEN_XENSTORE)
   28.29 -
   28.30 -LIBS_IMG  := $(LIBAIO_DIR)/libaio.a -lcrypto -lpthread -lz
   28.31 +LDFLAGS_blktapctrl := $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenstore) -L../lib -lblktap
   28.32 +LDFLAGS_img := $(LIBAIO_DIR)/libaio.a -lcrypto -lpthread -lz
   28.33  
   28.34  BLK-OBJS-y  := block-aio.o
   28.35  BLK-OBJS-y  += block-sync.o
   28.36 @@ -34,17 +32,17 @@ BLK-OBJS-$(CONFIG_Linux) += blk_linux.c
   28.37  
   28.38  all: $(IBIN) qcow-util
   28.39  
   28.40 -blktapctrl: blktapctrl.c
   28.41 -	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) -lblktap $(LDFLAGS_libxenctrl)
   28.42 +blktapctrl: blktapctrl.o
   28.43 +	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDFLAGS_blktapctrl)
   28.44  
   28.45 -tapdisk: tapdisk.c $(BLK-OBJS-y) tapdisk.c
   28.46 -	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_IMG)
   28.47 +tapdisk: tapdisk.o $(BLK-OBJS-y)
   28.48 +	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDFLAGS_img)
   28.49  
   28.50  .PHONY: qcow-util
   28.51  qcow-util: img2qcow qcow2raw qcow-create
   28.52  
   28.53 -img2qcow qcow2raw qcow-create: %: $(BLK-OBJS-y)
   28.54 -	$(CC) $(CFLAGS) -o $* $(BLK-OBJS-y) $*.c $(LDFLAGS) $(LIBS_IMG)
   28.55 +img2qcow qcow2raw qcow-create: %: %.o $(BLK-OBJS-y)
   28.56 +	$(CC) $(CFLAGS) -o $* $^ $(LDFLAGS) $(LDFLAGS_img)
   28.57  
   28.58  install: all
   28.59  	$(INSTALL_PROG) $(IBIN) $(QCOW_UTIL) $(VHD_UTIL) $(DESTDIR)$(SBINDIR)
    29.1 --- a/tools/blktap/drivers/blktapctrl.c	Fri Mar 14 15:07:45 2008 -0600
    29.2 +++ b/tools/blktap/drivers/blktapctrl.c	Thu Mar 20 12:35:40 2008 -0600
    29.3 @@ -501,6 +501,80 @@ int launch_tapdisk(char *wrctldev, char 
    29.4  	return 0;
    29.5  }
    29.6  
    29.7 +/* Connect to qemu-dm */
    29.8 +static int connect_qemu(blkif_t *blkif)
    29.9 +{
   29.10 +	char *rdctldev, *wrctldev;
   29.11 +	
   29.12 +	if (asprintf(&rdctldev, BLKTAP_CTRL_DIR "/qemu-read-%d", 
   29.13 +			blkif->domid) < 0)
   29.14 +		return -1;
   29.15 +
   29.16 +	if (asprintf(&wrctldev, BLKTAP_CTRL_DIR "/qemu-write-%d", 
   29.17 +			blkif->domid) < 0) {
   29.18 +		free(rdctldev);
   29.19 +		return -1;
   29.20 +	}
   29.21 +
   29.22 +	DPRINTF("Using qemu blktap pipe: %s\n", rdctldev);
   29.23 +	
   29.24 +	blkif->fds[READ] = open_ctrl_socket(wrctldev);
   29.25 +	blkif->fds[WRITE] = open_ctrl_socket(rdctldev);
   29.26 +	
   29.27 +	free(rdctldev);
   29.28 +	free(wrctldev);
   29.29 +	
   29.30 +	if (blkif->fds[READ] == -1 || blkif->fds[WRITE] == -1)
   29.31 +		return -1;
   29.32 +
   29.33 +	DPRINTF("Attached to qemu blktap pipes\n");
   29.34 +	return 0;
   29.35 +}
   29.36 +
   29.37 +/* Launch tapdisk instance */
   29.38 +static int connect_tapdisk(blkif_t *blkif, int minor)
   29.39 +{
   29.40 +	char *rdctldev = NULL, *wrctldev = NULL;
   29.41 +	int ret = -1;
   29.42 +
   29.43 +	DPRINTF("tapdisk process does not exist:\n");
   29.44 +
   29.45 +	if (asprintf(&rdctldev,
   29.46 +		     "%s/tapctrlread%d", BLKTAP_CTRL_DIR, minor) == -1)
   29.47 +		goto fail;
   29.48 +
   29.49 +	if (asprintf(&wrctldev,
   29.50 +		     "%s/tapctrlwrite%d", BLKTAP_CTRL_DIR, minor) == -1)
   29.51 +		goto fail;
   29.52 +	
   29.53 +	blkif->fds[READ] = open_ctrl_socket(rdctldev);
   29.54 +	blkif->fds[WRITE] = open_ctrl_socket(wrctldev);
   29.55 +	
   29.56 +	if (blkif->fds[READ] == -1 || blkif->fds[WRITE] == -1)
   29.57 +		goto fail;
   29.58 +
   29.59 +	/*launch the new process*/
   29.60 +	DPRINTF("Launching process, CMDLINE [tapdisk %s %s]\n",
   29.61 +			wrctldev, rdctldev);
   29.62 +
   29.63 +	if (launch_tapdisk(wrctldev, rdctldev) == -1) {
   29.64 +		DPRINTF("Unable to fork, cmdline: [tapdisk %s %s]\n",
   29.65 +				wrctldev, rdctldev);
   29.66 +		goto fail;
   29.67 +	}
   29.68 +
   29.69 +	ret = 0;
   29.70 +	
   29.71 +fail:
   29.72 +	if (rdctldev)
   29.73 +		free(rdctldev);
   29.74 +
   29.75 +	if (wrctldev)
   29.76 +		free(wrctldev);
   29.77 +
   29.78 +	return ret;
   29.79 +}
   29.80 +
   29.81  int blktapctrl_new_blkif(blkif_t *blkif)
   29.82  {
   29.83  	blkif_info_t *blk;
   29.84 @@ -524,30 +598,14 @@ int blktapctrl_new_blkif(blkif_t *blkif)
   29.85  		blkif->cookie = next_cookie++;
   29.86  
   29.87  		if (!exist) {
   29.88 -			DPRINTF("Process does not exist:\n");
   29.89 -			if (asprintf(&rdctldev,
   29.90 -				     "%s/tapctrlread%d", BLKTAP_CTRL_DIR, minor) == -1)
   29.91 -				goto fail;
   29.92 -			if (asprintf(&wrctldev,
   29.93 -				     "%s/tapctrlwrite%d", BLKTAP_CTRL_DIR, minor) == -1) {
   29.94 -				free(rdctldev);
   29.95 -				goto fail;
   29.96 -			}
   29.97 -			blkif->fds[READ] = open_ctrl_socket(rdctldev);
   29.98 -			blkif->fds[WRITE] = open_ctrl_socket(wrctldev);
   29.99 -			
  29.100 -			if (blkif->fds[READ] == -1 || blkif->fds[WRITE] == -1) 
  29.101 -				goto fail;
  29.102 -
  29.103 -			/*launch the new process*/
  29.104 - 			DPRINTF("Launching process, CMDLINE [tapdisk %s %s]\n",wrctldev, rdctldev);
  29.105 - 			if (launch_tapdisk(wrctldev, rdctldev) == -1) {
  29.106 - 				DPRINTF("Unable to fork, cmdline: [tapdisk %s %s]\n",wrctldev, rdctldev);
  29.107 -				goto fail;
  29.108 +			if (type == DISK_TYPE_IOEMU) {
  29.109 +				if (connect_qemu(blkif))
  29.110 +					goto fail;
  29.111 +			} else {
  29.112 +				if (connect_tapdisk(blkif, minor))
  29.113 +					goto fail;
  29.114  			}
  29.115  
  29.116 -			free(rdctldev);
  29.117 -			free(wrctldev);
  29.118  		} else {
  29.119  			DPRINTF("Process exists!\n");
  29.120  			blkif->fds[READ] = exist->fds[READ];
    30.1 --- a/tools/blktap/drivers/block-qcow2.c	Fri Mar 14 15:07:45 2008 -0600
    30.2 +++ b/tools/blktap/drivers/block-qcow2.c	Thu Mar 20 12:35:40 2008 -0600
    30.3 @@ -45,6 +45,11 @@
    30.4  #define O_BINARY 0
    30.5  #endif
    30.6  
    30.7 +/* *BSD has no O_LARGEFILE */
    30.8 +#ifndef O_LARGEFILE
    30.9 +#define O_LARGEFILE     0 
   30.10 +#endif
   30.11 +
   30.12  #define BLOCK_FLAG_ENCRYPT 1
   30.13  
   30.14  /*
    31.1 --- a/tools/blktap/drivers/tapaio.c	Fri Mar 14 15:07:45 2008 -0600
    31.2 +++ b/tools/blktap/drivers/tapaio.c	Thu Mar 20 12:35:40 2008 -0600
    31.3 @@ -82,6 +82,7 @@ tap_aio_completion_thread(void *arg)
    31.4  			}
    31.5  		} while (!rc);
    31.6  	}
    31.7 +	return NULL;
    31.8  }
    31.9  
   31.10  void
    32.1 --- a/tools/blktap/drivers/tapdisk.h	Fri Mar 14 15:07:45 2008 -0600
    32.2 +++ b/tools/blktap/drivers/tapdisk.h	Thu Mar 20 12:35:40 2008 -0600
    32.3 @@ -167,6 +167,7 @@ extern struct tap_disk tapdisk_qcow2;
    32.4  #define DISK_TYPE_RAM      3
    32.5  #define DISK_TYPE_QCOW     4
    32.6  #define DISK_TYPE_QCOW2    5
    32.7 +#define DISK_TYPE_IOEMU    6
    32.8  
    32.9  
   32.10  /*Define Individual Disk Parameters here */
   32.11 @@ -230,6 +231,16 @@ static disk_info_t qcow2_disk = {
   32.12  #endif
   32.13  };
   32.14  
   32.15 +static disk_info_t ioemu_disk = {
   32.16 +	DISK_TYPE_IOEMU,
   32.17 +	"ioemu disk",
   32.18 +	"ioemu",
   32.19 +	0,
   32.20 +#ifdef TAPDISK
   32.21 +	NULL
   32.22 +#endif
   32.23 +};
   32.24 +
   32.25  /*Main disk info array */
   32.26  static disk_info_t *dtypes[] = {
   32.27  	&aio_disk,
   32.28 @@ -238,6 +249,7 @@ static disk_info_t *dtypes[] = {
   32.29  	&ram_disk,
   32.30  	&qcow_disk,
   32.31  	&qcow2_disk,
   32.32 +	&ioemu_disk,
   32.33  };
   32.34  
   32.35  typedef struct driver_list_entry {
    33.1 --- a/tools/blktap/lib/Makefile	Fri Mar 14 15:07:45 2008 -0600
    33.2 +++ b/tools/blktap/lib/Makefile	Thu Mar 20 12:35:40 2008 -0600
    33.3 @@ -5,8 +5,9 @@ MAJOR    = 3.0
    33.4  MINOR    = 0
    33.5  SONAME   = libblktap.so.$(MAJOR)
    33.6  
    33.7 -INCLUDES += -I. -I.. -I $(XEN_LIBXC) -I$(XEN_INCLUDE) $(CFLAGS_libxenstore)
    33.8 -
    33.9 +CFLAGS   += -I.
   33.10 +CFLAGS   += $(CFLAGS_libxenctrl)
   33.11 +CFLAGS   += $(CFLAGS_libxenstore)
   33.12  LDFLAGS  += $(LDFLAGS_libxenstore)
   33.13  
   33.14  SRCS     :=
   33.15 @@ -20,23 +21,18 @@ CFLAGS   += -D _GNU_SOURCE
   33.16  
   33.17  # Get gcc to generate the dependencies for us.
   33.18  CFLAGS   += -Wp,-MD,.$(@F).d
   33.19 -CFLAGS   += $(INCLUDES) 
   33.20  DEPS     = .*.d
   33.21  
   33.22 -OBJS     = $(patsubst %.c,%.o,$(SRCS))
   33.23 +OBJS     = $(SRCS:.c=.o)
   33.24 +OBJS_PIC = $(SRCS:.c=.opic)
   33.25  IBINS   :=
   33.26  
   33.27  LIB      = libblktap.a libblktap.so.$(MAJOR).$(MINOR)
   33.28  
   33.29  .PHONY: all
   33.30 -all: build
   33.31 +all: $(LIB)
   33.32  
   33.33 -.PHONY: build
   33.34 -build: libblktap.a
   33.35 -
   33.36 -.PHONY: libblktap
   33.37 -libblktap: libblktap.a
   33.38 -
   33.39 +.PHONY: install
   33.40  install: all
   33.41  	$(INSTALL_DIR) $(DESTDIR)$(LIBDIR)
   33.42  	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)
   33.43 @@ -45,19 +41,20 @@ install: all
   33.44  	ln -sf libblktap.so.$(MAJOR) $(DESTDIR)$(LIBDIR)/libblktap.so
   33.45  	$(INSTALL_DATA) blktaplib.h $(DESTDIR)$(INCLUDEDIR)
   33.46  
   33.47 +.PHONY: clean
   33.48  clean:
   33.49  	rm -rf *.a *.so* *.o *.rpm $(LIB) *~ $(DEPS) xen TAGS
   33.50  
   33.51 -libblktap.a: $(OBJS) 
   33.52 +libblktap.so.$(MAJOR).$(MINOR): $(OBJS_PIC) 
   33.53  	$(CC) $(CFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,$(SONAME) $(SHLIB_CFLAGS) \
   33.54 -	      -L$(XEN_XENSTORE) $(LDFLAGS)                                 \
   33.55 -	      -o libblktap.so.$(MAJOR).$(MINOR) $^ $(LIBS)
   33.56 +	      $(LDFLAGS) -o $@ $^
   33.57  	ln -sf libblktap.so.$(MAJOR).$(MINOR) libblktap.so.$(MAJOR)
   33.58  	ln -sf libblktap.so.$(MAJOR) libblktap.so
   33.59 -	$(AR) rc $@ libblktap.so
   33.60  
   33.61 -.PHONY: TAGS all build clean install libblktap
   33.62 +libblktap.a: $(OBJS) 
   33.63 +	$(AR) rc $@ $^
   33.64  
   33.65 +.PHONY: TAGS
   33.66  TAGS:
   33.67  	etags -t $(SRCS) *.h
   33.68  
    34.1 --- a/tools/blktap/lib/blktaplib.h	Fri Mar 14 15:07:45 2008 -0600
    34.2 +++ b/tools/blktap/lib/blktaplib.h	Thu Mar 20 12:35:40 2008 -0600
    34.3 @@ -221,15 +221,5 @@ int xs_fire_next_watch(struct xs_handle 
    34.4       ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * getpagesize()) +    \
    34.5       ((_seg) * getpagesize()))
    34.6  
    34.7 -/* Defines that are only used by library clients */
    34.8 -
    34.9 -#ifndef __COMPILING_BLKTAP_LIB
   34.10 -
   34.11 -static char *blkif_op_name[] = {
   34.12 -	[BLKIF_OP_READ]       = "READ",
   34.13 -	[BLKIF_OP_WRITE]      = "WRITE",
   34.14 -};
   34.15 -
   34.16 -#endif /* __COMPILING_BLKTAP_LIB */
   34.17  
   34.18  #endif /* __BLKTAPLIB_H__ */
    35.1 --- a/tools/examples/xmexample.hvm	Fri Mar 14 15:07:45 2008 -0600
    35.2 +++ b/tools/examples/xmexample.hvm	Thu Mar 20 12:35:40 2008 -0600
    35.3 @@ -135,6 +135,11 @@ device_model = '/usr/' + arch_libdir + '
    35.4  sdl=0
    35.5  
    35.6  #----------------------------------------------------------------------------
    35.7 +# enable OpenGL for texture rendering inside the SDL window, default = 1
    35.8 +# valid only if sdl is enabled.
    35.9 +opengl=1
   35.10 +
   35.11 +#----------------------------------------------------------------------------
   35.12  # enable VNC library for graphics, default = 1
   35.13  vnc=1
   35.14  
    36.1 --- a/tools/firmware/rombios/rombios.c	Fri Mar 14 15:07:45 2008 -0600
    36.2 +++ b/tools/firmware/rombios/rombios.c	Thu Mar 20 12:35:40 2008 -0600
    36.3 @@ -779,8 +779,8 @@ typedef struct {
    36.4      Bit32u  sector_count1;
    36.5      Bit32u  sector_count2;
    36.6      Bit16u  blksize;
    36.7 +    Bit16u  dpte_offset;
    36.8      Bit16u  dpte_segment;
    36.9 -    Bit16u  dpte_offset;
   36.10      Bit16u  key;
   36.11      Bit8u   dpi_length;
   36.12      Bit8u   reserved1;
    37.1 --- a/tools/include/Makefile	Fri Mar 14 15:07:45 2008 -0600
    37.2 +++ b/tools/include/Makefile	Thu Mar 20 12:35:40 2008 -0600
    37.3 @@ -22,6 +22,7 @@ xen/.dir:
    37.4  install: all
    37.5  	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)/xen/arch-ia64
    37.6  	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)/xen/arch-x86
    37.7 +	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)/xen/arch-x86/hvm
    37.8  	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)/xen/foreign
    37.9  	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)/xen/hvm
   37.10  	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)/xen/io
   37.11 @@ -31,6 +32,7 @@ install: all
   37.12  	$(INSTALL_DATA) xen/*.h $(DESTDIR)$(INCLUDEDIR)/xen
   37.13  	$(INSTALL_DATA) xen/arch-ia64/*.h $(DESTDIR)$(INCLUDEDIR)/xen/arch-ia64
   37.14  	$(INSTALL_DATA) xen/arch-x86/*.h $(DESTDIR)$(INCLUDEDIR)/xen/arch-x86
   37.15 +	$(INSTALL_DATA) xen/arch-x86/hvm/*.h $(DESTDIR)$(INCLUDEDIR)/xen/arch-x86/hvm
   37.16  	$(INSTALL_DATA) xen/foreign/*.h $(DESTDIR)$(INCLUDEDIR)/xen/foreign
   37.17  	$(INSTALL_DATA) xen/hvm/*.h $(DESTDIR)$(INCLUDEDIR)/xen/hvm
   37.18  	$(INSTALL_DATA) xen/io/*.h $(DESTDIR)$(INCLUDEDIR)/xen/io
    38.1 --- a/tools/include/xen-sys/Linux/gntdev.h	Fri Mar 14 15:07:45 2008 -0600
    38.2 +++ b/tools/include/xen-sys/Linux/gntdev.h	Thu Mar 20 12:35:40 2008 -0600
    38.3 @@ -102,4 +102,18 @@ struct ioctl_gntdev_get_offset_for_vaddr
    38.4  	uint32_t pad;
    38.5  };
    38.6  
    38.7 +/*
    38.8 + * Sets the maximum number of grants that may mapped at once by this gntdev
    38.9 + * instance.
   38.10 + *
   38.11 + * N.B. This must be called before any other ioctl is performed on the device.
   38.12 + */
   38.13 +#define IOCTL_GNTDEV_SET_MAX_GRANTS \
   38.14 +_IOC(_IOC_NONE, 'G', 3, sizeof(struct ioctl_gntdev_set_max_grants))
   38.15 +struct ioctl_gntdev_set_max_grants {
   38.16 +	/* IN parameter */
   38.17 +	/* The maximum number of grants that may be mapped at once. */
   38.18 +	uint32_t count;
   38.19 +};
   38.20 +
   38.21  #endif /* __LINUX_PUBLIC_GNTDEV_H__ */
    39.1 --- a/tools/ioemu/Makefile.target	Fri Mar 14 15:07:45 2008 -0600
    39.2 +++ b/tools/ioemu/Makefile.target	Thu Mar 20 12:35:40 2008 -0600
    39.3 @@ -17,6 +17,7 @@ TARGET_PATH=$(SRC_PATH)/target-$(TARGET_
    39.4  VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/audio
    39.5  CPPFLAGS+=-I. -I.. -I$(TARGET_PATH) -I$(SRC_PATH)
    39.6  CPPFLAGS+= -I$(XEN_ROOT)/tools/libxc
    39.7 +CPPFLAGS+= -I$(XEN_ROOT)/tools/blktap/lib
    39.8  CPPFLAGS+= -I$(XEN_ROOT)/tools/xenstore
    39.9  CPPFLAGS+= -I$(XEN_ROOT)/tools/include
   39.10  ifdef CONFIG_DARWIN_USER
   39.11 @@ -429,6 +430,9 @@ VL_OBJS+= cirrus_vga.o parallel.o acpi.o
   39.12  VL_OBJS+= usb-uhci.o smbus_eeprom.o
   39.13  VL_OBJS+= piix4acpi.o
   39.14  VL_OBJS+= xenstore.o
   39.15 +ifndef CONFIG_STUBDOM
   39.16 +VL_OBJS+= xen_blktap.o
   39.17 +endif
   39.18  VL_OBJS+= xen_platform.o
   39.19  VL_OBJS+= xen_machine_fv.o
   39.20  VL_OBJS+= xen_machine_pv.o
    40.1 --- a/tools/ioemu/block-vbd.c	Fri Mar 14 15:07:45 2008 -0600
    40.2 +++ b/tools/ioemu/block-vbd.c	Thu Mar 20 12:35:40 2008 -0600
    40.3 @@ -51,6 +51,7 @@ typedef struct BDRVVbdState {
    40.4      int fd;
    40.5      int type;
    40.6      int mode;
    40.7 +    int info;
    40.8      uint64_t sectors;
    40.9      unsigned sector_size;
   40.10      QEMU_LIST_ENTRY(BDRVVbdState) list;
   40.11 @@ -80,7 +81,7 @@ static int vbd_open(BlockDriverState *bs
   40.12      //handy to test posix access
   40.13      //return -EIO;
   40.14  
   40.15 -    s->dev = init_blkfront((char *) filename, &s->sectors, &s->sector_size, &s->mode);
   40.16 +    s->dev = init_blkfront((char *) filename, &s->sectors, &s->sector_size, &s->mode, &s->info);
   40.17  
   40.18      if (!s->dev)
   40.19  	return -EIO;
   40.20 @@ -271,6 +272,7 @@ static void vbd_close(BlockDriverState *
   40.21      BDRVVbdState *s = bs->opaque;
   40.22      bs->total_sectors = 0;
   40.23      if (s->fd >= 0) {
   40.24 +        qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
   40.25          close(s->fd);
   40.26          s->fd = -1;
   40.27      }
    41.1 --- a/tools/ioemu/configure	Fri Mar 14 15:07:45 2008 -0600
    41.2 +++ b/tools/ioemu/configure	Thu Mar 20 12:35:40 2008 -0600
    41.3 @@ -190,6 +190,8 @@ for opt do
    41.4    ;;
    41.5    --disable-sdl) sdl="no"
    41.6    ;;
    41.7 +  --disable-opengl) opengl="no"
    41.8 +  ;;
    41.9    --enable-coreaudio) coreaudio="yes"
   41.10    ;;
   41.11    --enable-alsa) alsa="yes"
   41.12 @@ -539,6 +541,26 @@ else
   41.13  fi # -z $sdl
   41.14  
   41.15  ##########################################
   41.16 +# OpenGL test
   41.17 +
   41.18 +if test -z "$opengl" && test "$sdl" = "yes"
   41.19 +then
   41.20 +cat > $TMPC << EOF
   41.21 +#include <SDL_opengl.h>
   41.22 +#ifndef GL_TEXTURE_RECTANGLE_ARB
   41.23 +#error "Opengl doesn't support GL_TEXTURE_RECTANGLE_ARB"
   41.24 +#endif
   41.25 +int main( void ) { return (int) glGetString(GL_EXTENSIONS); }
   41.26 +EOF
   41.27 +if $cc -o $TMPE `$sdl_config --cflags --libs 2> /dev/null` -I/usr/include/GL $TMPC -lXext -lGL 2> /dev/null
   41.28 +then
   41.29 +opengl="yes"
   41.30 +else
   41.31 +opengl="no"
   41.32 +fi
   41.33 +fi
   41.34 +
   41.35 +##########################################
   41.36  # alsa sound support libraries
   41.37  
   41.38  if test "$alsa" = "yes" ; then
   41.39 @@ -612,6 +634,7 @@ echo "SDL support       $sdl"
   41.40  if test "$sdl" != "no" ; then
   41.41      echo "SDL static link   $sdl_static"
   41.42  fi
   41.43 +echo "OpenGL support    $opengl"
   41.44  echo "mingw32 support   $mingw32"
   41.45  echo "Adlib support     $adlib"
   41.46  echo "CoreAudio support $coreaudio"
   41.47 @@ -995,6 +1018,15 @@ if test "$target_user_only" = "no"; then
   41.48      fi
   41.49  fi
   41.50  
   41.51 +if test $opengl = "yes"
   41.52 +then
   41.53 +    echo "#define CONFIG_OPENGL 1" >> $config_h
   41.54 +    echo "CONFIG_OPENGL=yes" >> $config_mak
   41.55 +    echo "SDL_CFLAGS+=-I/usr/include/GL" >> $config_mak
   41.56 +    echo "SDL_LIBS+=-lXext" >> $config_mak
   41.57 +    echo "SDL_LIBS+=-lGL" >> $config_mak
   41.58 +fi
   41.59 +
   41.60  if test "$cocoa" = "yes" ; then
   41.61      echo "#define CONFIG_COCOA 1" >> $config_h
   41.62      echo "CONFIG_COCOA=yes" >> $config_mak
    42.1 --- a/tools/ioemu/hw/ide.c	Fri Mar 14 15:07:45 2008 -0600
    42.2 +++ b/tools/ioemu/hw/ide.c	Thu Mar 20 12:35:40 2008 -0600
    42.3 @@ -189,6 +189,15 @@
    42.4  
    42.5  /* set to 1 set disable mult support */
    42.6  #define MAX_MULT_SECTORS 16
    42.7 +#ifdef CONFIG_STUBDOM
    42.8 +#include <xen/io/blkif.h>
    42.9 +#define IDE_DMA_BUF_SIZE (BLKIF_MAX_SEGMENTS_PER_REQUEST * TARGET_PAGE_SIZE)
   42.10 +#else
   42.11 +#define IDE_DMA_BUF_SIZE 131072
   42.12 +#endif
   42.13 +#if (IDE_DMA_BUF_SIZE < MAX_MULT_SECTORS * 512)
   42.14 +#error "IDE_DMA_BUF_SIZE must be bigger or equal to MAX_MULT_SECTORS * 512"
   42.15 +#endif
   42.16  
   42.17  /* ATAPI defines */
   42.18  
   42.19 @@ -932,8 +941,8 @@ static void ide_read_dma_cb(void *opaque
   42.20  
   42.21      /* launch next transfer */
   42.22      n = s->nsector;
   42.23 -    if (n > MAX_MULT_SECTORS)
   42.24 -        n = MAX_MULT_SECTORS;
   42.25 +    if (n > IDE_DMA_BUF_SIZE / 512)
   42.26 +        n = IDE_DMA_BUF_SIZE / 512;
   42.27      s->io_buffer_index = 0;
   42.28      s->io_buffer_size = n * 512;
   42.29  #ifdef DEBUG_AIO
   42.30 @@ -1041,8 +1050,8 @@ static void ide_write_dma_cb(void *opaqu
   42.31  
   42.32      /* launch next transfer */
   42.33      n = s->nsector;
   42.34 -    if (n > MAX_MULT_SECTORS)
   42.35 -        n = MAX_MULT_SECTORS;
   42.36 +    if (n > IDE_DMA_BUF_SIZE / 512)
   42.37 +        n = IDE_DMA_BUF_SIZE / 512;
   42.38      s->io_buffer_index = 0;
   42.39      s->io_buffer_size = n * 512;
   42.40  
   42.41 @@ -1336,8 +1345,8 @@ static void ide_atapi_cmd_read_dma_cb(vo
   42.42          data_offset = 16;
   42.43      } else {
   42.44          n = s->packet_transfer_size >> 11;
   42.45 -        if (n > (MAX_MULT_SECTORS / 4))
   42.46 -            n = (MAX_MULT_SECTORS / 4);
   42.47 +        if (n > (IDE_DMA_BUF_SIZE / 2048))
   42.48 +            n = (IDE_DMA_BUF_SIZE / 2048);
   42.49          s->io_buffer_size = n * 2048;
   42.50          data_offset = 0;
   42.51      }
   42.52 @@ -1823,7 +1832,6 @@ static void ide_ioport_write(void *opaqu
   42.53              break;
   42.54          case WIN_SETMULT:
   42.55              if (s->nsector > MAX_MULT_SECTORS || 
   42.56 -                s->nsector == 0 ||
   42.57                  (s->nsector & (s->nsector - 1)) != 0) {
   42.58                  ide_abort_command(s);
   42.59              } else {
   42.60 @@ -2306,7 +2314,7 @@ static void ide_init2(IDEState *ide_stat
   42.61  
   42.62      for(i = 0; i < 2; i++) {
   42.63          s = ide_state + i;
   42.64 -        s->io_buffer = qemu_memalign(getpagesize(), MAX_MULT_SECTORS*512 + 4);
   42.65 +        s->io_buffer = qemu_memalign(getpagesize(), IDE_DMA_BUF_SIZE + 4);
   42.66          if (i == 0)
   42.67              s->bs = hd0;
   42.68          else
    43.1 --- a/tools/ioemu/hw/ne2000.c	Fri Mar 14 15:07:45 2008 -0600
    43.2 +++ b/tools/ioemu/hw/ne2000.c	Thu Mar 20 12:35:40 2008 -0600
    43.3 @@ -834,6 +834,10 @@ void pci_ne2000_init(PCIBus *bus, NICInf
    43.4      pci_conf[0x0a] = 0x00; // ethernet network controller 
    43.5      pci_conf[0x0b] = 0x02;
    43.6      pci_conf[0x0e] = 0x00; // header_type
    43.7 +    pci_conf[0x2c] = 0x53; /* subsystem vendor: XenSource */
    43.8 +    pci_conf[0x2d] = 0x58;
    43.9 +    pci_conf[0x2e] = 0x01; /* subsystem device */
   43.10 +    pci_conf[0x2f] = 0x00;
   43.11      pci_conf[0x3d] = 1; // interrupt pin 0
   43.12      
   43.13      pci_register_io_region(&d->dev, 0, 0x100, 
    44.1 --- a/tools/ioemu/hw/scsi-disk.c	Fri Mar 14 15:07:45 2008 -0600
    44.2 +++ b/tools/ioemu/hw/scsi-disk.c	Thu Mar 20 12:35:40 2008 -0600
    44.3 @@ -34,9 +34,10 @@ do { fprintf(stderr, "scsi-disk: " fmt ,
    44.4  #define SENSE_ILLEGAL_REQUEST 5
    44.5  
    44.6  #ifdef CONFIG_STUBDOM
    44.7 -#define SCSI_DMA_BUF_SIZE    32768
    44.8 +#include <xen/io/blkif.h>
    44.9 +#define SCSI_DMA_BUF_SIZE    (BLKIF_MAX_SEGMENTS_PER_REQUEST * TARGET_PAGE_SIZE)
   44.10  #else
   44.11 -#define SCSI_DMA_BUF_SIZE    65536
   44.12 +#define SCSI_DMA_BUF_SIZE    131072
   44.13  #endif
   44.14  
   44.15  typedef struct SCSIRequest {
    45.1 --- a/tools/ioemu/hw/vga.c	Fri Mar 14 15:07:45 2008 -0600
    45.2 +++ b/tools/ioemu/hw/vga.c	Thu Mar 20 12:35:40 2008 -0600
    45.3 @@ -1148,7 +1148,7 @@ static void vga_draw_text(VGAState *s, i
    45.4          cw != s->last_cw || cheight != s->last_ch) {
    45.5          s->last_scr_width = width * cw;
    45.6          s->last_scr_height = height * cheight;
    45.7 -        dpy_resize(s->ds, s->last_scr_width, s->last_scr_height, s->last_scr_width * (depth / 8));
    45.8 +        dpy_resize(s->ds, s->last_scr_width, s->last_scr_height, s->last_scr_width * (s->ds->depth / 8));
    45.9          s->last_width = width;
   45.10          s->last_height = height;
   45.11          s->last_ch = cheight;
   45.12 @@ -1571,7 +1571,7 @@ static void vga_draw_graphic(VGAState *s
   45.13      vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
   45.14      if (disp_width != s->last_width ||
   45.15          height != s->last_height) {
   45.16 -        dpy_resize(s->ds, disp_width, height, disp_width * (depth / 8));
   45.17 +        dpy_resize(s->ds, disp_width, height, s->line_offset);
   45.18          s->last_scr_width = disp_width;
   45.19          s->last_scr_height = height;
   45.20          s->last_width = disp_width;
    46.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.2 +++ b/tools/ioemu/hw/xen_blktap.c	Thu Mar 20 12:35:40 2008 -0600
    46.3 @@ -0,0 +1,686 @@
    46.4 +/* xen_blktap.c
    46.5 + *
    46.6 + * Interface to blktapctrl to allow use of qemu block drivers with blktap.
    46.7 + * This file is based on tools/blktap/drivers/tapdisk.c
    46.8 + * 
    46.9 + * Copyright (c) 2005 Julian Chesterfield and Andrew Warfield.
   46.10 + * Copyright (c) 2008 Kevin Wolf
   46.11 + */
   46.12 +
   46.13 +/*
   46.14 + * There are several communication channels which are used by this interface:
   46.15 + *
   46.16 + *   - A pair of pipes for receiving and sending general control messages
   46.17 + *     (qemu-read-N and qemu-writeN in /var/run/tap, where N is the domain ID).
   46.18 + *     These control messages are handled by handle_blktap_ctrlmsg().
   46.19 + *
   46.20 + *   - One file descriptor per attached disk (/dev/xen/blktapN) for disk
   46.21 + *     specific control messages. A callback is triggered on this fd if there
   46.22 + *     is a new IO request. The callback function is handle_blktap_iomsg().
   46.23 + *
   46.24 + *   - A shared ring for each attached disk containing the actual IO requests 
   46.25 + *     and responses. Whenever handle_blktap_iomsg() is triggered it processes
   46.26 + *     the requests on this ring.
   46.27 + */
   46.28 +
   46.29 +#include <sys/stat.h>
   46.30 +#include <sys/types.h>
   46.31 +#include <sys/mman.h>
   46.32 +#include <sys/ioctl.h>
   46.33 +#include <fcntl.h>
   46.34 +#include <stdio.h>
   46.35 +#include <errno.h>
   46.36 +#include <stdlib.h>
   46.37 +
   46.38 +#include "vl.h"
   46.39 +#include "blktaplib.h"
   46.40 +#include "xen_blktap.h"
   46.41 +#include "block_int.h"
   46.42 +
   46.43 +#define MSG_SIZE 4096
   46.44 +
   46.45 +#define BLKTAP_CTRL_DIR "/var/run/tap"
   46.46 +
   46.47 +/* If enabled, print debug messages to stderr */
   46.48 +#if 1
   46.49 +#define DPRINTF(_f, _a...) fprintf(stderr, __FILE__ ":%d: " _f, __LINE__, ##_a)
   46.50 +#else
   46.51 +#define DPRINTF(_f, _a...) ((void)0)
   46.52 +#endif
   46.53 +
   46.54 +#if 1                                                                        
   46.55 +#define ASSERT(_p) \
   46.56 +    if ( !(_p) ) { DPRINTF("Assertion '%s' failed, line %d, file %s\n", #_p , \
   46.57 +        __LINE__, __FILE__); *(int*)0=0; }
   46.58 +#else
   46.59 +#define ASSERT(_p) ((void)0)
   46.60 +#endif 
   46.61 +
   46.62 +
   46.63 +extern int domid;
   46.64 +
   46.65 +int read_fd;
   46.66 +int write_fd;
   46.67 +
   46.68 +static pid_t process;
   46.69 +fd_list_entry_t *fd_start = NULL;
   46.70 +
   46.71 +static void handle_blktap_iomsg(void* private);
   46.72 +
   46.73 +struct aiocb_info {
   46.74 +	struct td_state	*s;
   46.75 +	uint64_t sector;
   46.76 +	int nr_secs;
   46.77 +	int idx;
   46.78 +	long i;
   46.79 +};
   46.80 +
   46.81 +static void unmap_disk(struct td_state *s)
   46.82 +{
   46.83 +	tapdev_info_t *info = s->ring_info;
   46.84 +	fd_list_entry_t *entry;
   46.85 +	
   46.86 +	bdrv_close(s->bs);
   46.87 +
   46.88 +	if (info != NULL && info->mem > 0)
   46.89 +	        munmap(info->mem, getpagesize() * BLKTAP_MMAP_REGION_SIZE);
   46.90 +
   46.91 +	entry = s->fd_entry;
   46.92 +	*entry->pprev = entry->next;
   46.93 +	if (entry->next)
   46.94 +		entry->next->pprev = entry->pprev;
   46.95 +
   46.96 +	qemu_set_fd_handler2(info->fd, NULL, NULL, NULL, NULL);
   46.97 +	close(info->fd);
   46.98 +
   46.99 +	free(s->fd_entry);
  46.100 +	free(s->blkif);
  46.101 +	free(s->ring_info);
  46.102 +	free(s);
  46.103 +
  46.104 +	return;
  46.105 +}
  46.106 +
  46.107 +static inline fd_list_entry_t *add_fd_entry(int tap_fd, struct td_state *s)
  46.108 +{
  46.109 +	fd_list_entry_t **pprev, *entry;
  46.110 +
  46.111 +	DPRINTF("Adding fd_list_entry\n");
  46.112 +
  46.113 +	/*Add to linked list*/
  46.114 +	s->fd_entry   = entry = malloc(sizeof(fd_list_entry_t));
  46.115 +	entry->tap_fd = tap_fd;
  46.116 +	entry->s      = s;
  46.117 +	entry->next   = NULL;
  46.118 +
  46.119 +	pprev = &fd_start;
  46.120 +	while (*pprev != NULL)
  46.121 +		pprev = &(*pprev)->next;
  46.122 +
  46.123 +	*pprev = entry;
  46.124 +	entry->pprev = pprev;
  46.125 +
  46.126 +	return entry;
  46.127 +}
  46.128 +
  46.129 +static inline struct td_state *get_state(int cookie)
  46.130 +{
  46.131 +	fd_list_entry_t *ptr;
  46.132 +
  46.133 +	ptr = fd_start;
  46.134 +	while (ptr != NULL) {
  46.135 +		if (ptr->cookie == cookie) return ptr->s;
  46.136 +		ptr = ptr->next;
  46.137 +	}
  46.138 +	return NULL;
  46.139 +}
  46.140 +
  46.141 +static struct td_state *state_init(void)
  46.142 +{
  46.143 +	int i;
  46.144 +	struct td_state *s;
  46.145 +	blkif_t *blkif;
  46.146 +
  46.147 +	s = malloc(sizeof(struct td_state));
  46.148 +	blkif = s->blkif = malloc(sizeof(blkif_t));
  46.149 +	s->ring_info = calloc(1, sizeof(tapdev_info_t));
  46.150 +
  46.151 +	for (i = 0; i < MAX_REQUESTS; i++) {
  46.152 +		blkif->pending_list[i].secs_pending = 0;
  46.153 +		blkif->pending_list[i].submitting = 0;
  46.154 +	}
  46.155 +
  46.156 +	return s;
  46.157 +}
  46.158 +
  46.159 +static int map_new_dev(struct td_state *s, int minor)
  46.160 +{
  46.161 +	int tap_fd;
  46.162 +	tapdev_info_t *info = s->ring_info;
  46.163 +	char *devname;
  46.164 +	fd_list_entry_t *ptr;
  46.165 +	int page_size;
  46.166 +
  46.167 +	if (asprintf(&devname,"%s/%s%d", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, minor) == -1)
  46.168 +		return -1;
  46.169 +	tap_fd = open(devname, O_RDWR);
  46.170 +	if (tap_fd == -1) 
  46.171 +	{
  46.172 +		DPRINTF("open failed on dev %s!\n",devname);
  46.173 +		goto fail;
  46.174 +	} 
  46.175 +	info->fd = tap_fd;
  46.176 +
  46.177 +	/*Map the shared memory*/
  46.178 +	page_size = getpagesize();
  46.179 +	info->mem = mmap(0, page_size * BLKTAP_MMAP_REGION_SIZE, 
  46.180 +			  PROT_READ | PROT_WRITE, MAP_SHARED, info->fd, 0);
  46.181 +	if ((long int)info->mem == -1) 
  46.182 +	{
  46.183 +		DPRINTF("mmap failed on dev %s!\n",devname);
  46.184 +		goto fail;
  46.185 +	}
  46.186 +
  46.187 +	/* assign the rings to the mapped memory */ 
  46.188 +	info->sring = (blkif_sring_t *)((unsigned long)info->mem);
  46.189 +	BACK_RING_INIT(&info->fe_ring, info->sring, page_size);
  46.190 +	
  46.191 +	info->vstart = 
  46.192 +	        (unsigned long)info->mem + (BLKTAP_RING_PAGES * page_size);
  46.193 +
  46.194 +	ioctl(info->fd, BLKTAP_IOCTL_SENDPID, process );
  46.195 +	ioctl(info->fd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE );
  46.196 +	free(devname);
  46.197 +
  46.198 +	/*Update the fd entry*/
  46.199 +	ptr = fd_start;
  46.200 +	while (ptr != NULL) {
  46.201 +		if (s == ptr->s) {
  46.202 +			ptr->tap_fd = tap_fd;
  46.203 +
  46.204 +			/* Setup fd_handler for qemu main loop */
  46.205 +			DPRINTF("set tap_fd = %d\n", tap_fd);
  46.206 +			qemu_set_fd_handler2(tap_fd, NULL, &handle_blktap_iomsg, NULL, s);
  46.207 +
  46.208 +			break;
  46.209 +		}
  46.210 +		ptr = ptr->next;
  46.211 +	}	
  46.212 +
  46.213 +
  46.214 +	DPRINTF("map_new_dev = %d\n", minor);
  46.215 +	return minor;
  46.216 +
  46.217 + fail:
  46.218 +	free(devname);
  46.219 +	return -1;
  46.220 +}
  46.221 +
  46.222 +static int open_disk(struct td_state *s, char *path, int readonly)
  46.223 +{
  46.224 +	struct disk_id id;
  46.225 +	BlockDriverState* bs;
  46.226 +
  46.227 +	DPRINTF("Opening %s\n", path);
  46.228 +	bs = calloc(1, sizeof(*bs));
  46.229 +
  46.230 +	memset(&id, 0, sizeof(struct disk_id));
  46.231 +
  46.232 +	if (bdrv_open(bs, path, 0) != 0) {
  46.233 +		fprintf(stderr, "Could not open image file %s\n", path);
  46.234 +		return -ENOMEM;
  46.235 +	}
  46.236 +
  46.237 +	s->bs = bs;
  46.238 +	s->flags = readonly ? TD_RDONLY : 0;
  46.239 +	s->size = bs->total_sectors;
  46.240 +	s->sector_size = 512;
  46.241 +
  46.242 +	s->info = ((s->flags & TD_RDONLY) ? VDISK_READONLY : 0);
  46.243 +
  46.244 +	return 0;
  46.245 +}
  46.246 +
  46.247 +static inline void write_rsp_to_ring(struct td_state *s, blkif_response_t *rsp)
  46.248 +{
  46.249 +	tapdev_info_t *info = s->ring_info;
  46.250 +	blkif_response_t *rsp_d;
  46.251 +	
  46.252 +	rsp_d = RING_GET_RESPONSE(&info->fe_ring, info->fe_ring.rsp_prod_pvt);
  46.253 +	memcpy(rsp_d, rsp, sizeof(blkif_response_t));
  46.254 +	info->fe_ring.rsp_prod_pvt++;
  46.255 +}
  46.256 +
  46.257 +static inline void kick_responses(struct td_state *s)
  46.258 +{
  46.259 +	tapdev_info_t *info = s->ring_info;
  46.260 +
  46.261 +	if (info->fe_ring.rsp_prod_pvt != info->fe_ring.sring->rsp_prod) 
  46.262 +	{
  46.263 +		RING_PUSH_RESPONSES(&info->fe_ring);
  46.264 +		ioctl(info->fd, BLKTAP_IOCTL_KICK_FE);
  46.265 +	}
  46.266 +}
  46.267 +
  46.268 +static int send_responses(struct td_state *s, int res, 
  46.269 +		   uint64_t sector, int nr_secs, int idx, void *private)
  46.270 +{
  46.271 +	pending_req_t   *preq;
  46.272 +	blkif_request_t *req;
  46.273 +	int responses_queued = 0;
  46.274 +	blkif_t *blkif = s->blkif;
  46.275 +	int secs_done = nr_secs;
  46.276 +
  46.277 +	if ( (idx > MAX_REQUESTS-1) )
  46.278 +	{
  46.279 +		DPRINTF("invalid index returned(%u)!\n", idx);
  46.280 +		return 0;
  46.281 +	}
  46.282 +	preq = &blkif->pending_list[idx];
  46.283 +	req  = &preq->req;
  46.284 +
  46.285 +	preq->secs_pending -= secs_done;
  46.286 +
  46.287 +	if (res == -EBUSY && preq->submitting) 
  46.288 +		return -EBUSY;  /* propagate -EBUSY back to higher layers */
  46.289 +	if (res) 
  46.290 +		preq->status = BLKIF_RSP_ERROR;
  46.291 +	
  46.292 +	if (!preq->submitting && preq->secs_pending == 0) 
  46.293 +	{
  46.294 +		blkif_request_t tmp;
  46.295 +		blkif_response_t *rsp;
  46.296 +
  46.297 +		tmp = preq->req;
  46.298 +		rsp = (blkif_response_t *)req;
  46.299 +		
  46.300 +		rsp->id = tmp.id;
  46.301 +		rsp->operation = tmp.operation;
  46.302 +		rsp->status = preq->status;
  46.303 +		
  46.304 +		write_rsp_to_ring(s, rsp);
  46.305 +		responses_queued++;
  46.306 +
  46.307 +		kick_responses(s);
  46.308 +	}
  46.309 +	
  46.310 +	return responses_queued;
  46.311 +}
  46.312 +
  46.313 +static void qemu_send_responses(void* opaque, int ret)
  46.314 +{
  46.315 +	struct aiocb_info* info = opaque;
  46.316 +
  46.317 +	if (ret != 0) {
  46.318 +		DPRINTF("ERROR: ret = %d (%s)\n", ret, strerror(-ret));
  46.319 +	}
  46.320 +
  46.321 +	send_responses(info->s, ret, info->sector, info->nr_secs, 
  46.322 +		info->idx, (void*) info->i);
  46.323 +	free(info);
  46.324 +}
  46.325 +
  46.326 +/**
  46.327 + * Callback function for the IO message pipe. Reads requests from the ring
  46.328 + * and processes them (call qemu read/write functions).
  46.329 + *
  46.330 + * The private parameter points to the struct td_state representing the
  46.331 + * disk the request is targeted at.
  46.332 + */
  46.333 +static void handle_blktap_iomsg(void* private)
  46.334 +{
  46.335 +	struct td_state* s = private;
  46.336 +
  46.337 +	RING_IDX          rp, j, i;
  46.338 +	blkif_request_t  *req;
  46.339 +	int idx, nsects, ret;
  46.340 +	uint64_t sector_nr;
  46.341 +	uint8_t *page;
  46.342 +	blkif_t *blkif = s->blkif;
  46.343 +	tapdev_info_t *info = s->ring_info;
  46.344 +	int page_size = getpagesize();
  46.345 +
  46.346 +	struct aiocb_info *aiocb_info;
  46.347 +
  46.348 +	if (info->fe_ring.sring == NULL) {
  46.349 +		DPRINTF("  sring == NULL, ignoring IO request\n");
  46.350 +		return;
  46.351 +	}
  46.352 +
  46.353 +	rp = info->fe_ring.sring->req_prod; 
  46.354 +	xen_rmb();
  46.355 +
  46.356 +	for (j = info->fe_ring.req_cons; j != rp; j++)
  46.357 +	{
  46.358 +		int start_seg = 0; 
  46.359 +
  46.360 +		req = NULL;
  46.361 +		req = RING_GET_REQUEST(&info->fe_ring, j);
  46.362 +		++info->fe_ring.req_cons;
  46.363 +		
  46.364 +		if (req == NULL)
  46.365 +			continue;
  46.366 +
  46.367 +		idx = req->id;
  46.368 +
  46.369 +		ASSERT(blkif->pending_list[idx].secs_pending == 0);
  46.370 +		memcpy(&blkif->pending_list[idx].req, req, sizeof(*req));
  46.371 +		blkif->pending_list[idx].status = BLKIF_RSP_OKAY;
  46.372 +		blkif->pending_list[idx].submitting = 1;
  46.373 +		sector_nr = req->sector_number;
  46.374 +
  46.375 +		/* Don't allow writes on readonly devices */
  46.376 +		if ((s->flags & TD_RDONLY) && 
  46.377 +		    (req->operation == BLKIF_OP_WRITE)) {
  46.378 +			blkif->pending_list[idx].status = BLKIF_RSP_ERROR;
  46.379 +			goto send_response;
  46.380 +		}
  46.381 +
  46.382 +		for (i = start_seg; i < req->nr_segments; i++) {
  46.383 +			nsects = req->seg[i].last_sect - 
  46.384 +				 req->seg[i].first_sect + 1;
  46.385 +	
  46.386 +			if ((req->seg[i].last_sect >= page_size >> 9) ||
  46.387 +					(nsects <= 0))
  46.388 +				continue;
  46.389 +
  46.390 +			page  = (uint8_t*) MMAP_VADDR(info->vstart, 
  46.391 +						   (unsigned long)req->id, i);
  46.392 +			page += (req->seg[i].first_sect << SECTOR_SHIFT);
  46.393 +
  46.394 +			if (sector_nr >= s->size) {
  46.395 +				DPRINTF("Sector request failed:\n");
  46.396 +				DPRINTF("%s request, idx [%d,%d] size [%llu], "
  46.397 +					"sector [%llu,%llu]\n",
  46.398 +					(req->operation == BLKIF_OP_WRITE ? 
  46.399 +					 "WRITE" : "READ"),
  46.400 +					idx,i,
  46.401 +					(long long unsigned) 
  46.402 +						nsects<<SECTOR_SHIFT,
  46.403 +					(long long unsigned) 
  46.404 +						sector_nr<<SECTOR_SHIFT,
  46.405 +					(long long unsigned) sector_nr);
  46.406 +				continue;
  46.407 +			}
  46.408 +
  46.409 +			blkif->pending_list[idx].secs_pending += nsects;
  46.410 +
  46.411 +			switch (req->operation) 
  46.412 +			{
  46.413 +			case BLKIF_OP_WRITE:
  46.414 +				aiocb_info = malloc(sizeof(*aiocb_info));
  46.415 +
  46.416 +				aiocb_info->s = s;
  46.417 +				aiocb_info->sector = sector_nr;
  46.418 +				aiocb_info->nr_secs = nsects;
  46.419 +				aiocb_info->idx = idx;
  46.420 +				aiocb_info->i = i;
  46.421 +
  46.422 +				ret = (NULL == bdrv_aio_write(s->bs, sector_nr,
  46.423 +							  page, nsects,
  46.424 +							  qemu_send_responses,
  46.425 +							  aiocb_info));
  46.426 +
  46.427 +				if (ret) {
  46.428 +					blkif->pending_list[idx].status = BLKIF_RSP_ERROR;
  46.429 +					DPRINTF("ERROR: bdrv_write() == NULL\n");
  46.430 +					goto send_response;
  46.431 +				}
  46.432 +				break;
  46.433 +
  46.434 +			case BLKIF_OP_READ:
  46.435 +				aiocb_info = malloc(sizeof(*aiocb_info));
  46.436 +
  46.437 +				aiocb_info->s = s;
  46.438 +				aiocb_info->sector = sector_nr;
  46.439 +				aiocb_info->nr_secs = nsects;
  46.440 +				aiocb_info->idx = idx;
  46.441 +				aiocb_info->i = i;
  46.442 +
  46.443 +				ret = (NULL == bdrv_aio_read(s->bs, sector_nr,
  46.444 +							 page, nsects,
  46.445 +							 qemu_send_responses,
  46.446 +							 aiocb_info));
  46.447 +
  46.448 +				if (ret) {
  46.449 +					blkif->pending_list[idx].status = BLKIF_RSP_ERROR;
  46.450 +					DPRINTF("ERROR: bdrv_read() == NULL\n");
  46.451 +					goto send_response;
  46.452 +				}
  46.453 +				break;
  46.454 +
  46.455 +			default:
  46.456 +				DPRINTF("Unknown block operation\n");
  46.457 +				break;
  46.458 +			}
  46.459 +			sector_nr += nsects;
  46.460 +		}
  46.461 +	send_response:
  46.462 +		blkif->pending_list[idx].submitting = 0;
  46.463 +
  46.464 +		/* force write_rsp_to_ring for synchronous case */
  46.465 +		if (blkif->pending_list[idx].secs_pending == 0)
  46.466 +			send_responses(s, 0, 0, 0, idx, (void *)(long)0);
  46.467 +	}
  46.468 +}
  46.469 +
  46.470 +/**
  46.471 + * Callback function for the qemu-read pipe. Reads and processes control 
  46.472 + * message from the pipe.
  46.473 + *
  46.474 + * The parameter private is unused.
  46.475 + */
  46.476 +static void handle_blktap_ctrlmsg(void* private)
  46.477 +{
  46.478 +	int length, len, msglen;
  46.479 +	char *ptr, *path;
  46.480 +	image_t *img;
  46.481 +	msg_hdr_t *msg;
  46.482 +	msg_newdev_t *msg_dev;
  46.483 +	msg_pid_t *msg_pid;
  46.484 +	int ret = -1;
  46.485 +	struct td_state *s = NULL;
  46.486 +	fd_list_entry_t *entry;
  46.487 +
  46.488 +	char buf[MSG_SIZE];
  46.489 +
  46.490 +	length = read(read_fd, buf, MSG_SIZE);
  46.491 +
  46.492 +	if (length > 0 && length >= sizeof(msg_hdr_t)) 
  46.493 +	{
  46.494 +		msg = (msg_hdr_t *)buf;
  46.495 +		DPRINTF("blktap: Received msg, len %d, type %d, UID %d\n",
  46.496 +			length,msg->type,msg->cookie);
  46.497 +
  46.498 +		switch (msg->type) {
  46.499 +		case CTLMSG_PARAMS: 			
  46.500 +			ptr = buf + sizeof(msg_hdr_t);
  46.501 +			len = (length - sizeof(msg_hdr_t));
  46.502 +			path = calloc(1, len + 1);
  46.503 +			
  46.504 +			memcpy(path, ptr, len); 
  46.505 +			DPRINTF("Received CTLMSG_PARAMS: [%s]\n", path);
  46.506 +
  46.507 +			/* Allocate the disk structs */
  46.508 +			s = state_init();
  46.509 +
  46.510 +			/*Open file*/
  46.511 +			if (s == NULL || open_disk(s, path, msg->readonly)) {
  46.512 +				msglen = sizeof(msg_hdr_t);
  46.513 +				msg->type = CTLMSG_IMG_FAIL;
  46.514 +				msg->len = msglen;
  46.515 +			} else {
  46.516 +				entry = add_fd_entry(0, s);
  46.517 +				entry->cookie = msg->cookie;
  46.518 +				DPRINTF("Entered cookie %d\n", entry->cookie);
  46.519 +				
  46.520 +				memset(buf, 0x00, MSG_SIZE); 
  46.521 +			
  46.522 +				msglen = sizeof(msg_hdr_t) + sizeof(image_t);
  46.523 +				msg->type = CTLMSG_IMG;
  46.524 +				img = (image_t *)(buf + sizeof(msg_hdr_t));
  46.525 +				img->size = s->size;
  46.526 +				img->secsize = s->sector_size;
  46.527 +				img->info = s->info;
  46.528 +				DPRINTF("Writing (size, secsize, info) = "
  46.529 +					"(%#" PRIx64 ", %#" PRIx64 ", %d)\n",
  46.530 +					s->size, s->sector_size, s->info);
  46.531 +			}
  46.532 +			len = write(write_fd, buf, msglen);
  46.533 +			free(path);
  46.534 +			break;
  46.535 +			
  46.536 +		case CTLMSG_NEWDEV:
  46.537 +			msg_dev = (msg_newdev_t *)(buf + sizeof(msg_hdr_t));
  46.538 +
  46.539 +			s = get_state(msg->cookie);
  46.540 +			DPRINTF("Retrieving state, cookie %d.....[%s]\n",
  46.541 +				msg->cookie, (s == NULL ? "FAIL":"OK"));
  46.542 +			if (s != NULL) {
  46.543 +				ret = ((map_new_dev(s, msg_dev->devnum) 
  46.544 +					== msg_dev->devnum ? 0: -1));
  46.545 +			}	
  46.546 +
  46.547 +			memset(buf, 0x00, MSG_SIZE); 
  46.548 +			msglen = sizeof(msg_hdr_t);
  46.549 +			msg->type = (ret == 0 ? CTLMSG_NEWDEV_RSP 
  46.550 +				              : CTLMSG_NEWDEV_FAIL);
  46.551 +			msg->len = msglen;
  46.552 +
  46.553 +			len = write(write_fd, buf, msglen);
  46.554 +			break;
  46.555 +
  46.556 +		case CTLMSG_CLOSE:
  46.557 +			s = get_state(msg->cookie);
  46.558 +			if (s) unmap_disk(s);
  46.559 +			break;			
  46.560 +
  46.561 +		case CTLMSG_PID:
  46.562 +			memset(buf, 0x00, MSG_SIZE);
  46.563 +			msglen = sizeof(msg_hdr_t) + sizeof(msg_pid_t);
  46.564 +			msg->type = CTLMSG_PID_RSP;
  46.565 +			msg->len = msglen;
  46.566 +
  46.567 +			msg_pid = (msg_pid_t *)(buf + sizeof(msg_hdr_t));
  46.568 +			process = getpid();
  46.569 +			msg_pid->pid = process;
  46.570 +
  46.571 +			len = write(write_fd, buf, msglen);
  46.572 +			break;
  46.573 +
  46.574 +		default:
  46.575 +			break;
  46.576 +		}
  46.577 +	}
  46.578 +}
  46.579 +
  46.580 +/**
  46.581 + * Opens a control socket, i.e. a pipe to communicate with blktapctrl.
  46.582 + *
  46.583 + * Returns the file descriptor number for the pipe; -1 in error case
  46.584 + */
  46.585 +static int open_ctrl_socket(char *devname)
  46.586 +{
  46.587 +	int ret;
  46.588 +	int ipc_fd;
  46.589 +
  46.590 +	if (mkdir(BLKTAP_CTRL_DIR, 0755) == 0)
  46.591 +		DPRINTF("Created %s directory\n", BLKTAP_CTRL_DIR);
  46.592 +
  46.593 +	ret = mkfifo(devname,S_IRWXU|S_IRWXG|S_IRWXO);
  46.594 +	if ( (ret != 0) && (errno != EEXIST) ) {
  46.595 +		DPRINTF("ERROR: pipe failed (%d)\n", errno);
  46.596 +		return -1;
  46.597 +	}
  46.598 +
  46.599 +	ipc_fd = open(devname,O_RDWR|O_NONBLOCK);
  46.600 +
  46.601 +	if (ipc_fd < 0) {
  46.602 +		DPRINTF("FD open failed\n");
  46.603 +		return -1;
  46.604 +	}
  46.605 +
  46.606 +	return ipc_fd;
  46.607 +}
  46.608 +
  46.609 +/**
  46.610 + * Unmaps all disks and closes their pipes
  46.611 + */
  46.612 +void shutdown_blktap(void)
  46.613 +{
  46.614 +	fd_list_entry_t *ptr;
  46.615 +	struct td_state *s;
  46.616 +	char *devname;
  46.617 +
  46.618 +	DPRINTF("Shutdown blktap\n");
  46.619 +
  46.620 +	/* Unmap all disks */
  46.621 +	ptr = fd_start;
  46.622 +	while (ptr != NULL) {
  46.623 +		s = ptr->s;
  46.624 +		unmap_disk(s);
  46.625 +		close(ptr->tap_fd);
  46.626 +		ptr = ptr->next;
  46.627 +	}
  46.628 +
  46.629 +	/* Delete control pipes */
  46.630 +	if (asprintf(&devname, BLKTAP_CTRL_DIR "/qemu-read-%d", domid) >= 0) {
  46.631 +		DPRINTF("Delete %s\n", devname);
  46.632 +		if (unlink(devname))
  46.633 +			DPRINTF("Could not delete: %s\n", strerror(errno));
  46.634 +		free(devname);
  46.635 +	}
  46.636 +	
  46.637 +	if (asprintf(&devname, BLKTAP_CTRL_DIR "/qemu-write-%d", domid) >= 0) {	
  46.638 +		DPRINTF("Delete %s\n", devname);
  46.639 +		if (unlink(devname))
  46.640 +			DPRINTF("Could not delete: %s\n", strerror(errno));
  46.641 +		free(devname);
  46.642 +	}
  46.643 +}
  46.644 +
  46.645 +/**
  46.646 + * Initialize the blktap interface, i.e. open a pair of pipes in /var/run/tap
  46.647 + * and register a fd handler.
  46.648 + *
  46.649 + * Returns 0 on success.
  46.650 + */
  46.651 +int init_blktap(void)
  46.652 +{
  46.653 +	char* devname;	
  46.654 +
  46.655 +	DPRINTF("Init blktap pipes\n");
  46.656 +
  46.657 +	/* Open the read pipe */
  46.658 +	if (asprintf(&devname, BLKTAP_CTRL_DIR "/qemu-read-%d", domid) >= 0) {	
  46.659 +		read_fd = open_ctrl_socket(devname);		
  46.660 +		free(devname);
  46.661 +		
  46.662 +		if (read_fd == -1) {
  46.663 +			fprintf(stderr, "Could not open %s/qemu-read-%d\n",
  46.664 +				BLKTAP_CTRL_DIR, domid);
  46.665 +			return -1;
  46.666 +		}
  46.667 +	}
  46.668 +	
  46.669 +	/* Open the write pipe */
  46.670 +	if (asprintf(&devname, BLKTAP_CTRL_DIR "/qemu-write-%d", domid) >= 0) {
  46.671 +		write_fd = open_ctrl_socket(devname);
  46.672 +		free(devname);
  46.673 +		
  46.674 +		if (write_fd == -1) {
  46.675 +			fprintf(stderr, "Could not open %s/qemu-write-%d\n",
  46.676 +				BLKTAP_CTRL_DIR, domid);
  46.677 +			close(read_fd);
  46.678 +			return -1;
  46.679 +		}
  46.680 +	}
  46.681 +
  46.682 +	/* Attach a handler to the read pipe (called from qemu main loop) */
  46.683 +	qemu_set_fd_handler2(read_fd, NULL, &handle_blktap_ctrlmsg, NULL, NULL);
  46.684 +
  46.685 +	/* Register handler to clean up when the domain is destroyed */
  46.686 +	atexit(&shutdown_blktap);
  46.687 +
  46.688 +	return 0;
  46.689 +}
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/tools/ioemu/hw/xen_blktap.h	Thu Mar 20 12:35:40 2008 -0600
    47.3 @@ -0,0 +1,57 @@
    47.4 +/* xen_blktap.h
    47.5 + *
    47.6 + * Generic disk interface for blktap-based image adapters.
    47.7 + *
    47.8 + * (c) 2006 Andrew Warfield and Julian Chesterfield
    47.9 + */
   47.10 +
   47.11 +#ifndef XEN_BLKTAP_H_ 
   47.12 +#define XEN_BLKTAP_H_
   47.13 +
   47.14 +#include <stdint.h>
   47.15 +#include <syslog.h>
   47.16 +#include <stdio.h>
   47.17 +
   47.18 +#include "block_int.h"
   47.19 +
   47.20 +/* Things disks need to know about, these should probably be in a higher-level
   47.21 + * header. */
   47.22 +#define MAX_SEGMENTS_PER_REQ    11
   47.23 +#define SECTOR_SHIFT             9
   47.24 +#define DEFAULT_SECTOR_SIZE    512
   47.25 +
   47.26 +#define MAX_IOFD                 2
   47.27 +
   47.28 +#define BLK_NOT_ALLOCATED       99
   47.29 +#define TD_NO_PARENT             1
   47.30 +
   47.31 +typedef uint32_t td_flag_t;
   47.32 +
   47.33 +#define TD_RDONLY                1
   47.34 +
   47.35 +struct disk_id {
   47.36 +	char *name;
   47.37 +	int drivertype;
   47.38 +};
   47.39 +
   47.40 +/* This structure represents the state of an active virtual disk.           */
   47.41 +struct td_state {
   47.42 +	BlockDriverState* bs;
   47.43 +	td_flag_t flags;
   47.44 +	void *blkif;
   47.45 +	void *image;
   47.46 +	void *ring_info;
   47.47 +	void *fd_entry;
   47.48 +	uint64_t sector_size;
   47.49 +	uint64_t size;
   47.50 +	unsigned int       info;
   47.51 +};
   47.52 +
   47.53 +typedef struct fd_list_entry {
   47.54 +	int cookie;
   47.55 +	int  tap_fd;
   47.56 +	struct td_state *s;
   47.57 +	struct fd_list_entry **pprev, *next;
   47.58 +} fd_list_entry_t;
   47.59 +
   47.60 +#endif /*XEN_BLKTAP_H_*/
    48.1 --- a/tools/ioemu/hw/xen_machine_pv.c	Fri Mar 14 15:07:45 2008 -0600
    48.2 +++ b/tools/ioemu/hw/xen_machine_pv.c	Thu Mar 20 12:35:40 2008 -0600
    48.3 @@ -26,6 +26,9 @@
    48.4  #include "xen_console.h"
    48.5  #include "xenfb.h"
    48.6  
    48.7 +extern void init_blktap(void);
    48.8 +
    48.9 +
   48.10  /* The Xen PV machine currently provides
   48.11   *   - a virtual framebuffer
   48.12   *   - ....
   48.13 @@ -41,6 +44,12 @@ static void xen_init_pv(uint64_t ram_siz
   48.14      struct xenfb *xenfb;
   48.15      extern int domid;
   48.16  
   48.17 +
   48.18 +#ifndef CONFIG_STUBDOM
   48.19 +    /* Initialize tapdisk client */
   48.20 +    init_blktap();
   48.21 +#endif
   48.22 +
   48.23      /* Connect to text console */
   48.24      if (serial_hds[0]) {
   48.25          if (xencons_init(domid, serial_hds[0]) < 0) {
    49.1 --- a/tools/ioemu/sdl.c	Fri Mar 14 15:07:45 2008 -0600
    49.2 +++ b/tools/ioemu/sdl.c	Thu Mar 20 12:35:40 2008 -0600
    49.3 @@ -29,6 +29,10 @@
    49.4  #include <signal.h>
    49.5  #endif
    49.6  
    49.7 +#ifdef CONFIG_OPENGL
    49.8 +#include <SDL_opengl.h>
    49.9 +#endif
   49.10 +
   49.11  static SDL_Surface *screen;
   49.12  static SDL_Surface *shared = NULL;
   49.13  static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
   49.14 @@ -44,6 +48,99 @@ static int width, height;
   49.15  static SDL_Cursor *sdl_cursor_normal;
   49.16  static SDL_Cursor *sdl_cursor_hidden;
   49.17  static int absolute_enabled = 0;
   49.18 +static int opengl_enabled;
   49.19 +
   49.20 +#ifdef CONFIG_OPENGL
   49.21 +static GLint tex_format;
   49.22 +static GLint tex_type;
   49.23 +static GLuint texture_ref = 0;
   49.24 +static GLint gl_format;
   49.25 +
   49.26 +static void opengl_setdata(DisplayState *ds, void *pixels)
   49.27 +{
   49.28 +    glEnable(GL_TEXTURE_RECTANGLE_ARB);
   49.29 +    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
   49.30 +    glClearColor(0, 0, 0, 0);
   49.31 +    glDisable(GL_BLEND);
   49.32 +    glDisable(GL_LIGHTING);
   49.33 +    glDisable(GL_DEPTH_TEST);
   49.34 +    glDepthMask(GL_FALSE);
   49.35 +    glDisable(GL_CULL_FACE);
   49.36 +    glViewport( 0, 0, screen->w, screen->h);
   49.37 +    glMatrixMode(GL_PROJECTION);
   49.38 +    glLoadIdentity();
   49.39 +    glOrtho(0, screen->w, screen->h, 0, -1,1);
   49.40 +    glMatrixMode(GL_MODELVIEW);
   49.41 +    glLoadIdentity();
   49.42 +    glClear(GL_COLOR_BUFFER_BIT);
   49.43 +    ds->data = pixels;
   49.44 +
   49.45 +    if (texture_ref) {
   49.46 +        glDeleteTextures(1, &texture_ref);
   49.47 +        texture_ref = 0;
   49.48 +    }
   49.49 +
   49.50 +    glGenTextures(1, &texture_ref);
   49.51 +    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_ref);
   49.52 +    glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
   49.53 +    switch (ds->depth) {
   49.54 +        case 8:
   49.55 +            tex_format = GL_RGB;
   49.56 +            tex_type = GL_UNSIGNED_BYTE_3_3_2;
   49.57 +            glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
   49.58 +            break;
   49.59 +        case 16:
   49.60 +            tex_format = GL_RGB;
   49.61 +            tex_type = GL_UNSIGNED_SHORT_5_6_5;
   49.62 +            glPixelStorei (GL_UNPACK_ALIGNMENT, 2);
   49.63 +            break;
   49.64 +        case 24:
   49.65 +            tex_format = GL_BGR;
   49.66 +            tex_type = GL_UNSIGNED_BYTE;
   49.67 +            glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
   49.68 +            break;
   49.69 +        case 32:
   49.70 +            if (!ds->bgr) {
   49.71 +                tex_format = GL_BGRA;
   49.72 +                tex_type = GL_UNSIGNED_BYTE;
   49.73 +            } else {
   49.74 +                tex_format = GL_RGBA;
   49.75 +                tex_type = GL_UNSIGNED_BYTE;                
   49.76 +            }
   49.77 +            glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
   49.78 +            break;
   49.79 +    }   
   49.80 +    glPixelStorei(GL_UNPACK_ROW_LENGTH, (ds->linesize * 8) / ds->depth);
   49.81 +    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, gl_format, ds->width, ds->height, 0, tex_format, tex_type, pixels);
   49.82 +    glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_PRIORITY, 1.0);
   49.83 +    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   49.84 +    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   49.85 +    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   49.86 +    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   49.87 +    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
   49.88 +}
   49.89 +
   49.90 +static void opengl_update(DisplayState *ds, int x, int y, int w, int h)
   49.91 +{  
   49.92 +    int bpp = ds->depth / 8;
   49.93 +    GLvoid *pixels = ds->data + y * ds->linesize + x * bpp;
   49.94 +    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_ref);
   49.95 +    glPixelStorei(GL_UNPACK_ROW_LENGTH, ds->linesize / bpp);
   49.96 +    glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, x, y, w, h, tex_format, tex_type, pixels);
   49.97 +    glBegin(GL_QUADS);
   49.98 +        glTexCoord2d(0, 0);
   49.99 +        glVertex2d(0, 0);
  49.100 +        glTexCoord2d(ds->width, 0);
  49.101 +        glVertex2d(screen->w, 0);
  49.102 +        glTexCoord2d(ds->width, ds->height);
  49.103 +        glVertex2d(screen->w, screen->h);
  49.104 +        glTexCoord2d(0, ds->height);
  49.105 +        glVertex2d(0, screen->h);
  49.106 +    glEnd();
  49.107 +    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
  49.108 +    SDL_GL_SwapBuffers();
  49.109 +}
  49.110 +#endif
  49.111  
  49.112  static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
  49.113  {
  49.114 @@ -96,17 +193,26 @@ static void sdl_resize(DisplayState *ds,
  49.115  
  49.116      //    printf("resizing to %d %d\n", w, h);
  49.117  
  49.118 -    flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_DOUBLEBUF|SDL_HWPALETTE;
  49.119 -    if (gui_fullscreen)
  49.120 +#ifdef CONFIG_OPENGL
  49.121 +    if (ds->shared_buf && opengl_enabled)
  49.122 +        flags = SDL_OPENGL|SDL_RESIZABLE;
  49.123 +    else
  49.124 +#endif
  49.125 +        flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_DOUBLEBUF|SDL_HWPALETTE;
  49.126 +
  49.127 +    if (gui_fullscreen) {
  49.128          flags |= SDL_FULLSCREEN;
  49.129 -
  49.130 +        flags &= ~SDL_RESIZABLE;
  49.131 +    }
  49.132 +    
  49.133      width = w;
  49.134      height = h;
  49.135  
  49.136   again:
  49.137      screen = SDL_SetVideoMode(w, h, 0, flags);
  49.138 +#ifndef CONFIG_OPENGL
  49.139      if (!screen) {
  49.140 -        fprintf(stderr, "Could not open SDL display\n");
  49.141 +        fprintf(stderr, "Could not open SDL display: %s\n", SDL_GetError());
  49.142          exit(1);
  49.143      }
  49.144      if (!screen->pixels && (flags & SDL_HWSURFACE) && (flags & SDL_FULLSCREEN)) {
  49.145 @@ -115,9 +221,10 @@ static void sdl_resize(DisplayState *ds,
  49.146      }
  49.147  
  49.148      if (!screen->pixels) {
  49.149 -        fprintf(stderr, "Could not open SDL display\n");
  49.150 +        fprintf(stderr, "Could not open SDL display: %s\n", SDL_GetError());
  49.151          exit(1);
  49.152      }
  49.153 +#endif
  49.154      ds->width = w;
  49.155      ds->height = h;
  49.156      if (!ds->shared_buf) {
  49.157 @@ -131,6 +238,25 @@ static void sdl_resize(DisplayState *ds,
  49.158          ds->linesize = screen->pitch;
  49.159      } else {
  49.160          ds->linesize = linesize;
  49.161 +#ifdef CONFIG_OPENGL
  49.162 +        switch(screen->format->BitsPerPixel) {
  49.163 +        case 8:
  49.164 +            gl_format = GL_RGB;
  49.165 +            break;
  49.166 +        case 16:
  49.167 +            gl_format = GL_RGB;
  49.168 +            break;
  49.169 +        case 24:
  49.170 +            gl_format = GL_RGB;
  49.171 +            break;
  49.172 +        case 32:
  49.173 +            if (!screen->format->Rshift)
  49.174 +                gl_format = GL_BGRA;
  49.175 +            else
  49.176 +                gl_format = GL_RGBA;
  49.177 +            break;
  49.178 +        };
  49.179 +#endif
  49.180      }
  49.181  }
  49.182  
  49.183 @@ -139,7 +265,13 @@ static void sdl_colourdepth(DisplayState
  49.184      if (!depth || !ds->depth) return;
  49.185      ds->shared_buf = 1;
  49.186      ds->depth = depth;
  49.187 -    ds->linesize = width * depth / 8; 
  49.188 +    ds->linesize = width * depth / 8;
  49.189 +#ifdef CONFIG_OPENGL
  49.190 +    if (opengl_enabled) {
  49.191 +        ds->dpy_update = opengl_update;
  49.192 +        ds->dpy_setdata = opengl_setdata;
  49.193 +    }
  49.194 +#endif
  49.195  }
  49.196  
  49.197  /* generic keyboard conversion */
  49.198 @@ -331,8 +463,8 @@ static void sdl_send_mouse_event(int dx,
  49.199  	}
  49.200  
  49.201  	SDL_GetMouseState(&dx, &dy);
  49.202 -        dx = dx * 0x7FFF / (width - 1);
  49.203 -        dy = dy * 0x7FFF / (height - 1);
  49.204 +        dx = dx * 0x7FFF / (screen->w - 1);
  49.205 +        dy = dy * 0x7FFF / (screen->h - 1);
  49.206      } else if (absolute_enabled) {
  49.207  	sdl_show_cursor();
  49.208  	absolute_enabled = 0;
  49.209 @@ -344,7 +476,8 @@ static void sdl_send_mouse_event(int dx,
  49.210  static void toggle_full_screen(DisplayState *ds)
  49.211  {
  49.212      gui_fullscreen = !gui_fullscreen;
  49.213 -    sdl_resize(ds, screen->w, screen->h, ds->linesize);
  49.214 +    sdl_resize(ds, ds->width, ds->height, ds->linesize);
  49.215 +    ds->dpy_setdata(ds, ds->data);
  49.216      if (gui_fullscreen) {
  49.217          gui_saved_grab = gui_grab;
  49.218          sdl_grab_start();
  49.219 @@ -371,7 +504,7 @@ static void sdl_refresh(DisplayState *ds
  49.220      while (SDL_PollEvent(ev)) {
  49.221          switch (ev->type) {
  49.222          case SDL_VIDEOEXPOSE:
  49.223 -            sdl_update(ds, 0, 0, screen->w, screen->h);
  49.224 +            ds->dpy_update(ds, 0, 0, ds->width, ds->height);
  49.225              break;
  49.226          case SDL_KEYDOWN:
  49.227          case SDL_KEYUP:
  49.228 @@ -528,6 +661,18 @@ static void sdl_refresh(DisplayState *ds
  49.229  		}
  49.230  	    }
  49.231              break;
  49.232 +#ifdef CONFIG_OPENGL
  49.233 +        case SDL_VIDEORESIZE:
  49.234 +        {
  49.235 +            if (ds->shared_buf && opengl_enabled) {
  49.236 +                SDL_ResizeEvent *rev = &ev->resize;
  49.237 +                screen = SDL_SetVideoMode(rev->w, rev->h, 0, SDL_OPENGL|SDL_RESIZABLE);
  49.238 +                opengl_setdata(ds, ds->data);
  49.239 +                opengl_update(ds, 0, 0, ds->width, ds->height);
  49.240 +            }
  49.241 +            break;
  49.242 +        }
  49.243 +#endif
  49.244          default:
  49.245              break;
  49.246          }
  49.247 @@ -536,13 +681,17 @@ static void sdl_refresh(DisplayState *ds
  49.248  
  49.249  static void sdl_cleanup(void) 
  49.250  {
  49.251 +#ifdef CONFIG_OPENGL
  49.252 +    if (texture_ref) glDeleteTextures(1, &texture_ref);
  49.253 +#endif
  49.254      SDL_Quit();
  49.255  }
  49.256  
  49.257 -void sdl_display_init(DisplayState *ds, int full_screen)
  49.258 +void sdl_display_init(DisplayState *ds, int full_screen, int opengl)
  49.259  {
  49.260      int flags;
  49.261      uint8_t data = 0;
  49.262 +    opengl_enabled = opengl;
  49.263  
  49.264  #if defined(__APPLE__)
  49.265      /* always use generic keymaps */
    50.1 --- a/tools/ioemu/vl.c	Fri Mar 14 15:07:45 2008 -0600
    50.2 +++ b/tools/ioemu/vl.c	Thu Mar 20 12:35:40 2008 -0600
    50.3 @@ -174,6 +174,11 @@ int graphic_height = 600;
    50.4  #endif
    50.5  int graphic_depth = 15;
    50.6  int full_screen = 0;
    50.7 +#ifdef CONFIG_OPENGL
    50.8 +int opengl_enabled = 1;
    50.9 +#else
   50.10 +int opengl_enabled = 0;
   50.11 +#endif
   50.12  int no_quit = 0;
   50.13  CharDriverState *serial_hds[MAX_SERIAL_PORTS];
   50.14  CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
   50.15 @@ -276,9 +281,9 @@ void default_ioport_writel(void *opaque,
   50.16  
   50.17  void init_ioports(void)
   50.18  {
   50.19 -    ioport_opaque = malloc(MAX_IOPORTS * sizeof(*ioport_opaque));
   50.20 -    ioport_read_table = malloc(3 * MAX_IOPORTS * sizeof(**ioport_read_table));
   50.21 -    ioport_write_table = malloc(3 * MAX_IOPORTS * sizeof(**ioport_write_table));
   50.22 +    ioport_opaque = calloc(MAX_IOPORTS, sizeof(*ioport_opaque));
   50.23 +    ioport_read_table = calloc(3 * MAX_IOPORTS, sizeof(**ioport_read_table));
   50.24 +    ioport_write_table = calloc(3 * MAX_IOPORTS, sizeof(**ioport_write_table));
   50.25  }
   50.26  
   50.27  /* size is the word size in byte */
   50.28 @@ -6272,6 +6277,12 @@ void qemu_system_powerdown_request(void)
   50.29          cpu_interrupt(cpu_single_env, CPU_INTERRUPT_EXIT);
   50.30  }
   50.31  
   50.32 +static void qemu_sighup_handler(int signal)
   50.33 +{
   50.34 +    fprintf(stderr, "Received SIGHUP, terminating.\n");
   50.35 +    exit(0);
   50.36 +}
   50.37 +
   50.38  void main_loop_wait(int timeout)
   50.39  {
   50.40      IOHandlerRecord *ioh;
   50.41 @@ -6482,6 +6493,9 @@ void help(void)
   50.42  #ifdef CONFIG_SDL
   50.43             "-no-quit        disable SDL window close capability\n"
   50.44  #endif
   50.45 +#ifdef CONFIG_OPENGL
   50.46 +           "-disable-opengl disable OpenGL rendering, using SDL"
   50.47 +#endif
   50.48  #ifdef TARGET_I386
   50.49             "-no-fd-bootchk  disable boot signature checking for floppy disks\n"
   50.50  #endif
   50.51 @@ -6660,6 +6674,7 @@ enum {
   50.52      QEMU_OPTION_loadvm,
   50.53      QEMU_OPTION_full_screen,
   50.54      QEMU_OPTION_no_quit,
   50.55 +    QEMU_OPTION_disable_opengl,
   50.56      QEMU_OPTION_pidfile,
   50.57      QEMU_OPTION_no_kqemu,
   50.58      QEMU_OPTION_kernel_kqemu,
   50.59 @@ -6757,6 +6772,7 @@ const QEMUOption qemu_options[] = {
   50.60  #ifdef CONFIG_SDL
   50.61      { "no-quit", 0, QEMU_OPTION_no_quit },
   50.62  #endif
   50.63 +    { "disable-opengl", 0, QEMU_OPTION_disable_opengl },
   50.64      { "pidfile", HAS_ARG, QEMU_OPTION_pidfile },
   50.65      { "win2k-hack", 0, QEMU_OPTION_win2k_hack },
   50.66      { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
   50.67 @@ -7528,6 +7544,9 @@ int main(int argc, char **argv)
   50.68                  no_quit = 1;
   50.69                  break;
   50.70  #endif
   50.71 +            case QEMU_OPTION_disable_opengl:
   50.72 +                opengl_enabled = 0;
   50.73 +                break;
   50.74              case QEMU_OPTION_pidfile:
   50.75                  create_pidfile(optarg);
   50.76                  break;
   50.77 @@ -7854,7 +7873,7 @@ int main(int argc, char **argv)
   50.78  	xenstore_write_vncport(vnc_display_port);
   50.79      } else {
   50.80  #if defined(CONFIG_SDL)
   50.81 -        sdl_display_init(ds, full_screen);
   50.82 +        sdl_display_init(ds, full_screen, opengl_enabled);
   50.83  #elif defined(CONFIG_COCOA)
   50.84          cocoa_display_init(ds, full_screen);
   50.85  #else
   50.86 @@ -7980,7 +7999,7 @@ int main(int argc, char **argv)
   50.87  
   50.88  #ifndef CONFIG_STUBDOM
   50.89      /* Unblock SIGTERM and SIGHUP, which may have been blocked by the caller */
   50.90 -    signal(SIGHUP, SIG_DFL);
   50.91 +    signal(SIGHUP, qemu_sighup_handler);
   50.92      sigemptyset(&set);
   50.93      sigaddset(&set, SIGTERM);
   50.94      sigaddset(&set, SIGHUP);
    51.1 --- a/tools/ioemu/vl.h	Fri Mar 14 15:07:45 2008 -0600
    51.2 +++ b/tools/ioemu/vl.h	Thu Mar 20 12:35:40 2008 -0600
    51.3 @@ -982,7 +982,7 @@ void isa_cirrus_vga_init(DisplayState *d
    51.4                           unsigned long vga_ram_offset, int vga_ram_size);
    51.5  
    51.6  /* sdl.c */
    51.7 -void sdl_display_init(DisplayState *ds, int full_screen);
    51.8 +void sdl_display_init(DisplayState *ds, int full_screen, int opengl_enable);
    51.9  
   51.10  /* cocoa.m */
   51.11  void cocoa_display_init(DisplayState *ds, int full_screen);
    52.1 --- a/tools/ioemu/vnc.c	Fri Mar 14 15:07:45 2008 -0600
    52.2 +++ b/tools/ioemu/vnc.c	Thu Mar 20 12:35:40 2008 -0600
    52.3 @@ -369,20 +369,21 @@ static void vnc_dpy_resize(DisplayState 
    52.4      VncState *vs = ds->opaque;
    52.5      int o;
    52.6  
    52.7 -    if (linesize != w * vs->depth)
    52.8 -        ds->shared_buf = 0;
    52.9 -
   52.10      if (!ds->shared_buf) {
   52.11 +        ds->linesize = w * vs->depth;
   52.12          if (allocated)
   52.13 -            ds->data = realloc(ds->data, w * h * vs->depth);
   52.14 +            ds->data = realloc(ds->data,  h * ds->linesize);
   52.15          else
   52.16 -            ds->data = malloc(w * h * vs->depth);
   52.17 +            ds->data = malloc(h * ds->linesize);
   52.18          allocated = 1;
   52.19 -    } else if (allocated) {
   52.20 -        free(ds->data);
   52.21 -        allocated = 0;
   52.22 +    } else {
   52.23 +        ds->linesize = linesize;
   52.24 +        if (allocated) {
   52.25 +            free(ds->data);
   52.26 +            allocated = 0;
   52.27 +        }
   52.28      }
   52.29 -    vs->old_data = realloc(vs->old_data, w * h * vs->depth);
   52.30 +    vs->old_data = realloc(vs->old_data, h * ds->linesize);
   52.31      vs->dirty_row = realloc(vs->dirty_row, h * sizeof(vs->dirty_row[0]));
   52.32      vs->update_row = realloc(vs->update_row, h * sizeof(vs->dirty_row[0]));
   52.33  
   52.34 @@ -399,7 +400,6 @@ static void vnc_dpy_resize(DisplayState 
   52.35      size_changed = ds->width != w || ds->height != h;
   52.36      ds->width = w;
   52.37      ds->height = h;
   52.38 -    ds->linesize = w * vs->depth;
   52.39      if (vs->csock != -1 && vs->has_resize && size_changed) {
   52.40          vs->width = ds->width;
   52.41          vs->height = ds->height;
   52.42 @@ -2494,6 +2494,7 @@ void vnc_display_init(DisplayState *ds)
   52.43  
   52.44      vs->ds->width = 640;
   52.45      vs->ds->height = 400;
   52.46 +    vs->ds->linesize = 640 * 4;
   52.47      vnc_dpy_colourdepth(vs->ds, 24);
   52.48  }
   52.49  
    53.1 --- a/tools/ioemu/xenstore.c	Fri Mar 14 15:07:45 2008 -0600
    53.2 +++ b/tools/ioemu/xenstore.c	Thu Mar 20 12:35:40 2008 -0600
    53.3 @@ -81,7 +81,7 @@ static void waitForDevice(char *fn)
    53.4  
    53.5  #define DIRECT_PCI_STR_LEN 160
    53.6  char direct_pci_str[DIRECT_PCI_STR_LEN];
    53.7 -void xenstore_parse_domain_config(int domid)
    53.8 +void xenstore_parse_domain_config(int hvm_domid)
    53.9  {
   53.10      char **e = NULL;
   53.11      char *buf = NULL, *path;
   53.12 @@ -100,7 +100,7 @@ void xenstore_parse_domain_config(int do
   53.13          return;
   53.14      }
   53.15  
   53.16 -    path = xs_get_domain_path(xsh, domid);
   53.17 +    path = xs_get_domain_path(xsh, hvm_domid);
   53.18      if (path == NULL) {
   53.19          fprintf(logfile, "xs_get_domain_path() error\n");
   53.20          goto out;
    54.1 --- a/tools/libxc/ia64/dom_fw_acpi.c	Fri Mar 14 15:07:45 2008 -0600
    54.2 +++ b/tools/libxc/ia64/dom_fw_acpi.c	Thu Mar 20 12:35:40 2008 -0600
    54.3 @@ -1,4 +1,5 @@
    54.4  #include <inttypes.h>
    54.5 +#include "xc_dom_ia64_util.h"
    54.6  #include <xen/acpi.h>
    54.7  
    54.8  uint8_t
    55.1 --- a/tools/libxc/ia64/xc_dom_ia64_util.h	Fri Mar 14 15:07:45 2008 -0600
    55.2 +++ b/tools/libxc/ia64/xc_dom_ia64_util.h	Thu Mar 20 12:35:40 2008 -0600
    55.3 @@ -23,4 +23,8 @@ extern int shared_info_ia64(struct xc_do
    55.4  #define FW_MEM_BASE 0xff000000UL
    55.5  #define FW_MEM_SIZE 0x01000000UL
    55.6  
    55.7 +#ifdef __XEN_TOOLS__
    55.8 +/* Necessary for including the acpi header chain when not in kernel context */
    55.9 +typedef struct { } spinlock_t;
   55.10 +#endif
   55.11  #endif /* XC_IA64_DOM_IA64_UTIL_H */
    56.1 --- a/tools/libxc/xc_domain_save.c	Fri Mar 14 15:07:45 2008 -0600
    56.2 +++ b/tools/libxc/xc_domain_save.c	Thu Mar 20 12:35:40 2008 -0600
    56.3 @@ -125,36 +125,6 @@ static inline int count_bits ( int nr, v
    56.4      return count;
    56.5  }
    56.6  
    56.7 -static inline int permute( int i, int nr, int order_nr  )
    56.8 -{
    56.9 -    /* Need a simple permutation function so that we scan pages in a
   56.10 -       pseudo random order, enabling us to get a better estimate of
   56.11 -       the domain's page dirtying rate as we go (there are often
   56.12 -       contiguous ranges of pfns that have similar behaviour, and we
   56.13 -       want to mix them up. */
   56.14 -
   56.15 -    /* e.g. nr->oder 15->4 16->4 17->5 */
   56.16 -    /* 512MB domain, 128k pages, order 17 */
   56.17 -
   56.18 -    /*
   56.19 -      QPONMLKJIHGFEDCBA
   56.20 -             QPONMLKJIH
   56.21 -      GFEDCBA
   56.22 -     */
   56.23 -
   56.24 -    /*
   56.25 -      QPONMLKJIHGFEDCBA
   56.26 -                  EDCBA
   56.27 -             QPONM
   56.28 -      LKJIHGF
   56.29 -      */
   56.30 -
   56.31 -    do { i = ((i>>(order_nr-10)) | ( i<<10 ) ) & ((1<<order_nr)-1); }
   56.32 -    while ( i >= nr ); /* this won't ever loop if nr is a power of 2 */
   56.33 -
   56.34 -    return i;
   56.35 -}
   56.36 -
   56.37  static uint64_t tv_to_us(struct timeval *new)
   56.38  {
   56.39      return (new->tv_sec * 1000000) + new->tv_usec;
   56.40 @@ -859,9 +829,6 @@ int xc_domain_save(int xc_handle, int io
   56.41      /* base of the region in which domain memory is mapped */
   56.42      unsigned char *region_base = NULL;
   56.43  
   56.44 -    /* power of 2 order of p2m_size */
   56.45 -    int order_nr;
   56.46 -
   56.47      /* bitmap of pages:
   56.48         - that should be sent this iteration (unless later marked as skip);
   56.49         - to skip this iteration because already dirty;
   56.50 @@ -971,11 +938,6 @@ int xc_domain_save(int xc_handle, int io
   56.51      /* pretend we sent all the pages last iteration */
   56.52      sent_last_iter = p2m_size;
   56.53  
   56.54 -    /* calculate the power of 2 order of p2m_size, e.g.
   56.55 -       15->4 16->4 17->5 */
   56.56 -    for ( i = p2m_size-1, order_nr = 0; i ; i >>= 1, order_nr++ )
   56.57 -        continue;
   56.58 -
   56.59      /* Setup to_send / to_fix and to_skip bitmaps */
   56.60      to_send = malloc(BITMAP_SIZE);
   56.61      to_fix  = calloc(1, BITMAP_SIZE);
   56.62 @@ -1126,7 +1088,7 @@ int xc_domain_save(int xc_handle, int io
   56.63                     (batch < MAX_BATCH_SIZE) && (N < p2m_size);
   56.64                     N++ )
   56.65              {
   56.66 -                int n = permute(N, p2m_size, order_nr);
   56.67 +                int n = N;
   56.68  
   56.69                  if ( debug )
   56.70                  {
    57.1 --- a/tools/libxc/xc_linux.c	Fri Mar 14 15:07:45 2008 -0600
    57.2 +++ b/tools/libxc/xc_linux.c	Thu Mar 20 12:35:40 2008 -0600
    57.3 @@ -4,7 +4,7 @@
    57.4   * Use is subject to license terms.
    57.5   *
    57.6   * xc_gnttab functions:
    57.7 - * Copyright (c) 2007, D G Murray <Derek.Murray@cl.cam.ac.uk>
    57.8 + * Copyright (c) 2007-2008, D G Murray <Derek.Murray@cl.cam.ac.uk>
    57.9   *
   57.10   * This program is free software; you can redistribute it and/or
   57.11   * modify it under the terms of the GNU General Public License as
   57.12 @@ -505,6 +505,19 @@ int xc_gnttab_munmap(int xcg_handle,
   57.13      return 0;
   57.14  }
   57.15  
   57.16 +int xc_gnttab_set_max_grants(int xcg_handle,
   57.17 +                             uint32_t count)
   57.18 +{
   57.19 +    struct ioctl_gntdev_set_max_grants set_max;
   57.20 +    int rc;
   57.21 +
   57.22 +    set_max.count = count;
   57.23 +    if ( (rc = ioctl(xcg_handle, IOCTL_GNTDEV_SET_MAX_GRANTS, &set_max)) )
   57.24 +        return rc;
   57.25 +
   57.26 +    return 0;
   57.27 +}
   57.28 +
   57.29  /*
   57.30   * Local variables:
   57.31   * mode: C
    58.1 --- a/tools/libxc/xc_minios.c	Fri Mar 14 15:07:45 2008 -0600
    58.2 +++ b/tools/libxc/xc_minios.c	Thu Mar 20 12:35:40 2008 -0600
    58.3 @@ -165,14 +165,6 @@ static int port_alloc(int xce_handle) {
    58.4      return i;
    58.5  }
    58.6  
    58.7 -static void poke_port(int xce_handle, evtchn_port_t port)
    58.8 -{
    58.9 -    shared_info_t *s = HYPERVISOR_shared_info;
   58.10 -    printk("poking port %d\n", port);
   58.11 -    synch_set_bit(port, &s->evtchn_pending[0]);
   58.12 -    xc_evtchn_unmask(xce_handle, port);
   58.13 -}
   58.14 -
   58.15  static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
   58.16  {
   58.17      int xce_handle = (intptr_t) data;
   58.18 @@ -211,6 +203,7 @@ evtchn_port_or_error_t xc_evtchn_bind_un
   58.19      }
   58.20      files[xce_handle].evtchn.ports[i].bound = 1;
   58.21      files[xce_handle].evtchn.ports[i].port = port;
   58.22 +    unmask_evtchn(port);
   58.23      return port;
   58.24  }
   58.25  
   58.26 @@ -235,9 +228,7 @@ evtchn_port_or_error_t xc_evtchn_bind_in
   58.27      }
   58.28      files[xce_handle].evtchn.ports[i].bound = 1;
   58.29      files[xce_handle].evtchn.ports[i].port = local_port;
   58.30 -/* Poke port on start: HVM won't send an event for the very first request since
   58.31 - * we were not ready yet */
   58.32 -    poke_port(xce_handle, local_port);
   58.33 +    unmask_evtchn(local_port);
   58.34      return local_port;
   58.35  }
   58.36  
   58.37 @@ -275,6 +266,7 @@ evtchn_port_or_error_t xc_evtchn_bind_vi
   58.38      }
   58.39      files[xce_handle].evtchn.ports[i].bound = 1;
   58.40      files[xce_handle].evtchn.ports[i].port = port;
   58.41 +    unmask_evtchn(port);
   58.42      return port;
   58.43  }
   58.44  
    59.1 --- a/tools/libxc/xenctrl.h	Fri Mar 14 15:07:45 2008 -0600
    59.2 +++ b/tools/libxc/xenctrl.h	Thu Mar 20 12:35:40 2008 -0600
    59.3 @@ -6,7 +6,7 @@
    59.4   * Copyright (c) 2003-2004, K A Fraser.
    59.5   *
    59.6   * xc_gnttab functions:
    59.7 - * Copyright (c) 2007, D G Murray <Derek.Murray@cl.cam.ac.uk>
    59.8 + * Copyright (c) 2007-2008, D G Murray <Derek.Murray@cl.cam.ac.uk>
    59.9   */
   59.10  
   59.11  #ifndef XENCTRL_H
   59.12 @@ -832,6 +832,20 @@ int xc_gnttab_munmap(int xcg_handle,
   59.13                       void *start_address,
   59.14                       uint32_t count);
   59.15  
   59.16 +/*
   59.17 + * Sets the maximum number of grants that may be mapped by the given instance
   59.18 + * to @count.
   59.19 + *
   59.20 + * N.B. This function must be called after opening the handle, and before any
   59.21 + *      other functions are invoked on it.
   59.22 + *
   59.23 + * N.B. When variable-length grants are mapped, fragmentation may be observed,
   59.24 + *      and it may not be possible to satisfy requests up to the maximum number
   59.25 + *      of grants.
   59.26 + */
   59.27 +int xc_gnttab_set_max_grants(int xcg_handle,
   59.28 +			     uint32_t count);
   59.29 +
   59.30  int xc_hvm_set_pci_intx_level(
   59.31      int xc_handle, domid_t dom,
   59.32      uint8_t domain, uint8_t bus, uint8_t device, uint8_t intx,
    60.1 --- a/tools/python/xen/xend/XendConfig.py	Fri Mar 14 15:07:45 2008 -0600
    60.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu Mar 20 12:35:40 2008 -0600
    60.3 @@ -123,19 +123,49 @@ XENAPI_CFG_TO_LEGACY_CFG = {
    60.4  
    60.5  LEGACY_CFG_TO_XENAPI_CFG = reverse_dict(XENAPI_CFG_TO_LEGACY_CFG)
    60.6  
    60.7 -# Platform configuration keys.
    60.8 -XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'boot', 'device_model', 'loader', 'display', 
    60.9 -                        'fda', 'fdb', 'keymap', 'isa', 'localtime', 'monitor', 
   60.10 -                        'nographic', 'pae', 'rtc_timeoffset', 'serial', 'sdl',
   60.11 -                        'soundhw','stdvga', 'usb', 'usbdevice', 'hpet', 'vnc',
   60.12 -                        'vncconsole', 'vncdisplay', 'vnclisten', 'timer_mode',
   60.13 -                        'vncpasswd', 'vncunused', 'xauthority', 'pci', 'vhpt',
   60.14 -                        'guest_os_type', 'hap']
   60.15 +# Platform configuration keys and their types.
   60.16 +XENAPI_PLATFORM_CFG_TYPES = {
   60.17 +    'acpi': int,
   60.18 +    'apic': int,
   60.19 +    'boot': str,
   60.20 +    'device_model': str,
   60.21 +    'loader': str,
   60.22 +    'display' : str,
   60.23 +    'fda': str,
   60.24 +    'fdb': str,
   60.25 +    'keymap': str,
   60.26 +    'isa' : int,
   60.27 +    'localtime': int,
   60.28 +    'monitor': int,
   60.29 +    'nographic': int,
   60.30 +    'pae' : int,
   60.31 +    'rtc_timeoffset': int,
   60.32 +    'serial': str,
   60.33 +    'sdl': int,
   60.34 +    'opengl': int,
   60.35 +    'soundhw': str,
   60.36 +    'stdvga': int,
   60.37 +    'usb': int,
   60.38 +    'usbdevice': str,
   60.39 +    'hpet': int,
   60.40 +    'vnc': int,
   60.41 +    'vncconsole': int,
   60.42 +    'vncdisplay': int,
   60.43 +    'vnclisten': str,
   60.44 +    'timer_mode': int,
   60.45 +    'vncpasswd': str,
   60.46 +    'vncunused': int,
   60.47 +    'xauthority': str,
   60.48 +    'pci': str,
   60.49 +    'vhpt': int,
   60.50 +    'guest_os_type': str,
   60.51 +    'hap': int,
   60.52 +}
   60.53  
   60.54  # Xen API console 'other_config' keys.
   60.55  XENAPI_CONSOLE_OTHER_CFG = ['vncunused', 'vncdisplay', 'vnclisten',
   60.56                              'vncpasswd', 'type', 'display', 'xauthority',
   60.57 -                            'keymap']
   60.58 +                            'keymap', 'opengl']
   60.59  
   60.60  # List of XendConfig configuration keys that have no direct equivalent
   60.61  # in the old world.
   60.62 @@ -405,6 +435,12 @@ class XendConfig(dict):
   60.63                  self['platform']['device_model'] = xen.util.auxbin.pathTo("qemu-dm")
   60.64  
   60.65          if self.is_hvm():
   60.66 +            if 'timer_mode' not in self['platform']:
   60.67 +                self['platform']['timer_mode'] = 0
   60.68 +            if 'rtc_timeoffset' not in self['platform']:
   60.69 +                self['platform']['rtc_timeoffset'] = 0
   60.70 +            if 'hpet' not in self['platform']:
   60.71 +                self['platform']['hpet'] = 0
   60.72              if 'loader' not in self['platform']:
   60.73                  # Old configs may have hvmloader set as PV_kernel param
   60.74                  if self.has_key('PV_kernel') and re.search('hvmloader', self['PV_kernel']):
   60.75 @@ -534,7 +570,7 @@ class XendConfig(dict):
   60.76              cfg['platform']['localtime'] = localtime
   60.77  
   60.78          # Compatibility hack -- can go soon.
   60.79 -        for key in XENAPI_PLATFORM_CFG:
   60.80 +        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
   60.81              val = sxp.child_value(sxp_cfg, "platform_" + key, None)
   60.82              if val is not None:
   60.83                  self['platform'][key] = val
   60.84 @@ -713,7 +749,7 @@ class XendConfig(dict):
   60.85              self.update_with_image_sxp(image_sxp)
   60.86  
   60.87          # Convert Legacy HVM parameters to Xen API configuration
   60.88 -        for key in XENAPI_PLATFORM_CFG:
   60.89 +        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
   60.90              if key in cfg:
   60.91                  self['platform'][key] = cfg[key]
   60.92  
   60.93 @@ -763,7 +799,7 @@ class XendConfig(dict):
   60.94              if image_type != 'hvm' and image_type != 'linux':
   60.95                  self['platform']['image_type'] = image_type
   60.96              
   60.97 -            for key in XENAPI_PLATFORM_CFG:
   60.98 +            for key in XENAPI_PLATFORM_CFG_TYPES.keys():
   60.99                  val = sxp.child_value(image_sxp, key, None)
  60.100                  if val is not None and val != '':
  60.101                      self['platform'][key] = val
  60.102 @@ -847,6 +883,19 @@ class XendConfig(dict):
  60.103                  self[key] = type_conv(val)
  60.104              else:
  60.105                  self[key] = val
  60.106 +
  60.107 +        # XenAPI defines platform as a string-string map.  If platform
  60.108 +        # configuration exists, convert values to appropriate type.
  60.109 +        if 'platform' in xapi:
  60.110 +            for key, val in xapi['platform'].items():
  60.111 +                type_conv = XENAPI_PLATFORM_CFG_TYPES.get(key)
  60.112 +                if type_conv is None:
  60.113 +                    key = key.lower()
  60.114 +                    type_conv = XENAPI_PLATFORM_CFG_TYPES.get(key)
  60.115 +                    if callable(type_conv):
  60.116 +                        self['platform'][key] = type_conv(val)
  60.117 +                    else:
  60.118 +                        self['platform'][key] = val
  60.119                  
  60.120          self['vcpus_params']['weight'] = \
  60.121              int(self['vcpus_params'].get('weight', 256))
  60.122 @@ -942,6 +991,7 @@ class XendConfig(dict):
  60.123                                      dev_type, dev_cfg = self['devices'][dev_uuid]
  60.124                                      is_bootable = dev_cfg.get('bootable', 0)
  60.125                                      config.append(['bootable', int(is_bootable)])
  60.126 +                                    config.append(['VDI', dev_cfg.get('VDI', '')])
  60.127  
  60.128                                  sxpr.append(['device', config])
  60.129  
  60.130 @@ -1276,6 +1326,12 @@ class XendConfig(dict):
  60.131                      target['devices'][dev_uuid] = ('vfb', dev_info)
  60.132                      target['console_refs'].append(dev_uuid)
  60.133  
  60.134 +                    # if console is rfb, set device_model ensuring qemu
  60.135 +                    # is invoked for pvfb services
  60.136 +                    if 'device_model' not in target['platform']:
  60.137 +                        target['platform']['device_model'] = \
  60.138 +                            xen.util.auxbin.pathTo("qemu-dm")
  60.139 +
  60.140                      # Finally, if we are a pvfb, we need to make a vkbd
  60.141                      # as well that is not really exposed to Xen API
  60.142                      vkbd_uuid = uuid.createString()
  60.143 @@ -1407,6 +1463,23 @@ class XendConfig(dict):
  60.144                  config = cfg_sxp
  60.145  
  60.146              dev_type, dev_info = self['devices'][dev_uuid]
  60.147 +
  60.148 +            if dev_type == 'pci': # Special case for pci
  60.149 +                pci_devs = []
  60.150 +                for pci_dev in sxp.children(config, 'dev'):
  60.151 +                    pci_dev_info = {}
  60.152 +                    for opt_val in pci_dev[1:]:
  60.153 +                        try:
  60.154 +                            opt, val = opt_val
  60.155 +                            pci_dev_info[opt] = val
  60.156 +                        except TypeError:
  60.157 +                            pass
  60.158 +                    pci_devs.append(pci_dev_info)
  60.159 +                self['devices'][dev_uuid] = (dev_type,
  60.160 +                                             {'devs': pci_devs,
  60.161 +                                              'uuid': dev_uuid})
  60.162 +                return True
  60.163 +                
  60.164              for opt_val in config[1:]:
  60.165                  try:
  60.166                      opt, val = opt_val
  60.167 @@ -1519,7 +1592,7 @@ class XendConfig(dict):
  60.168          if self.has_key('PV_args') and self['PV_args']:
  60.169              image.append(['args', self['PV_args']])
  60.170  
  60.171 -        for key in XENAPI_PLATFORM_CFG:
  60.172 +        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
  60.173              if key in self['platform']:
  60.174                  image.append([key, self['platform'][key]])
  60.175  
  60.176 @@ -1555,7 +1628,7 @@ class XendConfig(dict):
  60.177              self['PV_ramdisk'] = sxp.child_value(image_sxp, 'ramdisk','')
  60.178              self['PV_args'] = kernel_args
  60.179  
  60.180 -        for key in XENAPI_PLATFORM_CFG:
  60.181 +        for key in XENAPI_PLATFORM_CFG_TYPES.keys():
  60.182              val = sxp.child_value(image_sxp, key, None)
  60.183              if val is not None and val != '':
  60.184                  self['platform'][key] = val
    61.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Mar 14 15:07:45 2008 -0600
    61.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 20 12:35:40 2008 -0600
    61.3 @@ -558,18 +558,17 @@ class XendDomainInfo:
    61.4              count += 1
    61.5  
    61.6  
    61.7 -    def pci_device_create(self, dev_config):
    61.8 -        log.debug("XendDomainInfo.pci_device_create: %s" % scrub_password(dev_config))
    61.9 +    def hvm_pci_device_create(self, dev_config):
   61.10 +        log.debug("XendDomainInfo.hvm_pci_device_create: %s"
   61.11 +                  % scrub_password(dev_config))
   61.12  
   61.13          if not self.info.is_hvm():
   61.14 -            raise VmError("only HVM guest support pci attach")
   61.15 +            raise VmError("hvm_pci_device_create called on non-HVM guest")
   61.16  
   61.17          #all the PCI devs share one conf node
   61.18          devid = '0'
   61.19  
   61.20 -        dev_type = sxp.name(dev_config)
   61.21 -        new_devs = sxp.child_value(dev_config, 'devs')
   61.22 -        new_dev = new_devs[0]
   61.23 +        new_dev = dev_config['devs'][0]
   61.24          dev_info = self._getDeviceInfo_pci(devid)#from self.info['devices']
   61.25  
   61.26          #check conflict before trigger hotplug event
   61.27 @@ -611,35 +610,6 @@ class XendDomainInfo:
   61.28                  new_dev['vslt'])
   61.29          self.image.signalDeviceModel('pci-ins', 'pci-inserted', bdf_str)
   61.30  
   61.31 -        # update the virtual pci slot
   61.32 -        vslt = xstransact.Read("/local/domain/0/device-model/%i/parameter"
   61.33 -                          % self.getDomid())
   61.34 -        new_dev['vslt'] = vslt
   61.35 -
   61.36 -        if dev_info is None:
   61.37 -            # create a new one from scrach
   61.38 -            dev_cfg_sxp = [dev_type,
   61.39 -                ['dev',
   61.40 -                  ['domain', new_dev['domain']],
   61.41 -                  ['bus',    new_dev['bus']],
   61.42 -                  ['slot',   new_dev['slot']],
   61.43 -                  ['func',   new_dev['func']],
   61.44 -                  ['vslt',   new_dev['vslt']]
   61.45 -                ]]
   61.46 -            dev_uuid = self.info.device_add(dev_type, cfg_sxp = dev_cfg_sxp)
   61.47 -            dev_config_dict = self.info['devices'][dev_uuid][1]
   61.48 -            try:
   61.49 -                dev_config_dict['devid'] = devid = \
   61.50 -                    self._createDevice(dev_type, dev_config_dict)
   61.51 -                self._waitForDevice(dev_type, devid)
   61.52 -            except VmError, ex:
   61.53 -                raise ex
   61.54 -        else:
   61.55 -            # update the pci config to add the new dev
   61.56 -            pci_devs.extend(new_devs)
   61.57 -            self._reconfigureDevice('pci', devid, pci_conf)
   61.58 -
   61.59 -        return self.getDeviceController('pci').sxpr(devid)
   61.60  
   61.61      def device_create(self, dev_config):
   61.62          """Create a new device.
   61.63 @@ -649,11 +619,6 @@ class XendDomainInfo:
   61.64          """
   61.65          log.debug("XendDomainInfo.device_create: %s" % scrub_password(dev_config))
   61.66          dev_type = sxp.name(dev_config)
   61.67 -
   61.68 -        if dev_type == 'pci':
   61.69 -            rc = self.pci_device_create(dev_config)
   61.70 -            return rc
   61.71 -
   61.72          dev_uuid = self.info.device_add(dev_type, cfg_sxp = dev_config)
   61.73          dev_config_dict = self.info['devices'][dev_uuid][1]
   61.74          log.debug("XendDomainInfo.device_create: %s" % scrub_password(dev_config_dict))
   61.75 @@ -676,6 +641,151 @@ class XendDomainInfo:
   61.76          xen.xend.XendDomain.instance().managed_config_save(self)
   61.77          return self.getDeviceController(dev_type).sxpr(devid)
   61.78  
   61.79 +    def pci_convert_sxp_to_dict(self, dev_sxp):
   61.80 +        """Convert pci device sxp to dict
   61.81 +        @param dev_sxp: device configuration
   61.82 +        @type  dev_sxp: SXP object (parsed config)
   61.83 +        @return: dev_config
   61.84 +        @rtype: dictionary
   61.85 +        """
   61.86 +        # In reconfigure phase, config of PCI device looks like below:
   61.87 +        #
   61.88 +        # sxp:
   61.89 +        # [device, [pci, [dev, [domain, '0x0'], [bus, '0x0'], [slot, '0x0'],
   61.90 +        #                      [func, '0x0'], [vslt, '0x0']],
   61.91 +        #                [state, 'Initialising']]]
   61.92 +        #
   61.93 +        # dict:
   61.94 +        # {devs: [{domain: '0x0', bus: '0x0', slot: '0x0', func: '0x0',
   61.95 +        #          vslt: '0x0'}],
   61.96 +        #  states: ['Initialising']}
   61.97 +        #
   61.98 +        # state 'Initialising' means the device is being attached.
   61.99 +        # state 'Closing' means the device is being detached.
  61.100 +
  61.101 +        dev_config = {}
  61.102 +        pci_devs = []
  61.103 +        for pci_dev in sxp.children(dev_sxp, 'dev'):
  61.104 +            pci_dev_info = {}
  61.105 +            for opt_val in pci_dev[1:]:
  61.106 +                try:
  61.107 +                    opt, val = opt_val
  61.108 +                    pci_dev_info[opt] = val
  61.109 +                except TypeError:
  61.110 +                    pass
  61.111 +            pci_devs.append(pci_dev_info)
  61.112 +        dev_config['devs'] = pci_devs 
  61.113 +        pci_states = []
  61.114 +        for pci_state in sxp.children(dev_sxp, 'state'):
  61.115 +            try:
  61.116 +                pci_states.append(pci_state[1])
  61.117 +            except IndexError:
  61.118 +                raise XendError("Error reading state while parsing pci sxp")
  61.119 +        dev_config['states'] = pci_states
  61.120 +        
  61.121 +        return dev_config
  61.122 + 
  61.123 +    def pci_device_configure(self, dev_sxp, devid = 0):
  61.124 +        """Configure an existing pci device.
  61.125 +        
  61.126 +        @param dev_sxp: device configuration
  61.127 +        @type  dev_sxp: SXP object (parsed config)
  61.128 +        @param devid:      device id
  61.129 +        @type  devid:      int
  61.130 +        @return: Returns True if successfully updated device
  61.131 +        @rtype: boolean
  61.132 +        """
  61.133 +        log.debug("XendDomainInfo.pci_device_configure: %s"
  61.134 +                  % scrub_password(dev_sxp))
  61.135 +
  61.136 +        dev_class = sxp.name(dev_sxp)
  61.137 +
  61.138 +        if dev_class != 'pci':
  61.139 +            return False
  61.140 +
  61.141 +        pci_state = sxp.child_value(dev_sxp, 'state')
  61.142 +        existing_dev_info = self._getDeviceInfo_pci(devid)
  61.143 +
  61.144 +        if existing_dev_info is None and pci_state != 'Initialising':
  61.145 +            raise XendError("Cannot detach when pci platform does not exist")
  61.146 +
  61.147 +        pci_dev = sxp.children(dev_sxp, 'dev')[0]
  61.148 +        dev_config = self.pci_convert_sxp_to_dict(dev_sxp)
  61.149 +        dev = dev_config['devs'][0]
  61.150 +                
  61.151 +        # Do HVM specific processing
  61.152 +        if self.info.is_hvm():
  61.153 +            if pci_state == 'Initialising':
  61.154 +                # HVM PCI device attachment
  61.155 +                self.hvm_pci_device_create(dev_config)
  61.156 +                # Update vslt
  61.157 +                vslt = xstransact.Read("/local/domain/0/device-model/%i/parameter"
  61.158 +                                       % self.getDomid())
  61.159 +                dev['vslt'] = vslt
  61.160 +                for n in sxp.children(pci_dev):
  61.161 +                    if(n[0] == 'vslt'):
  61.162 +                        n[1] = vslt
  61.163 +            else:
  61.164 +                # HVM PCI device detachment
  61.165 +                existing_dev_uuid = sxp.child_value(existing_dev_info, 'uuid')
  61.166 +                existing_pci_conf = self.info['devices'][existing_dev_uuid][1]
  61.167 +                existing_pci_devs = existing_pci_conf['devs']
  61.168 +                vslt = '0x0'
  61.169 +                for x in existing_pci_devs:
  61.170 +                    if ( int(x['domain'], 16) == int(dev['domain'], 16) and
  61.171 +                         int(x['bus'], 16) == int(dev['bus'], 16) and
  61.172 +                         int(x['slot'], 16) == int(dev['slot'], 16) and
  61.173 +                         int(x['func'], 16) == int(dev['func'], 16) ):
  61.174 +                        vslt = x['vslt']
  61.175 +                        break
  61.176 +                if vslt == '0x0':
  61.177 +                    raise VmError("Device %04x:%02x:%02x.%02x is not connected"
  61.178 +                                  % (int(dev['domain'],16), int(dev['bus'],16),
  61.179 +                                     int(dev['slot'],16), int(dev['func'],16)))
  61.180 +                self.hvm_destroyPCIDevice(int(vslt, 16))
  61.181 +                # Update vslt
  61.182 +                dev['vslt'] = vslt
  61.183 +                for n in sxp.children(pci_dev):
  61.184 +                    if(n[0] == 'vslt'):
  61.185 +                        n[1] = vslt
  61.186 +
  61.187 +        # If pci platform does not exist, create and exit.
  61.188 +        if existing_dev_info is None:
  61.189 +            self.device_create(dev_sxp)
  61.190 +            return True
  61.191 +
  61.192 +        # use DevController.reconfigureDevice to change device config
  61.193 +        dev_control = self.getDeviceController(dev_class)
  61.194 +        dev_uuid = dev_control.reconfigureDevice(devid, dev_config)
  61.195 +        if not self.info.is_hvm():
  61.196 +            # in PV case, wait until backend state becomes connected.
  61.197 +            dev_control.waitForDevice_reconfigure(devid)
  61.198 +        num_devs = dev_control.cleanupDevice(devid)
  61.199 +
  61.200 +        # update XendConfig with new device info
  61.201 +        if dev_uuid:
  61.202 +            new_dev_sxp = dev_control.configuration(devid)
  61.203 +            self.info.device_update(dev_uuid, new_dev_sxp)
  61.204 +
  61.205 +        # If there is no device left, destroy pci and remove config.
  61.206 +        if num_devs == 0:
  61.207 +            if self.info.is_hvm():
  61.208 +                self.destroyDevice('pci', devid, True)
  61.209 +                del self.info['devices'][dev_uuid]
  61.210 +                platform = self.info['platform']
  61.211 +                orig_dev_num = len(platform['pci'])
  61.212 +                # TODO: can use this to keep some info to ask high level
  61.213 +                # management tools to hot insert a new passthrough dev
  61.214 +                # after migration
  61.215 +                if orig_dev_num != 0:
  61.216 +                    #platform['pci'] = ["%dDEVs" % orig_dev_num]
  61.217 +                    platform['pci'] = []
  61.218 +            else:
  61.219 +                self.destroyDevice('pci', devid)
  61.220 +                del self.info['devices'][dev_uuid]
  61.221 +
  61.222 +        return True
  61.223 +
  61.224      def device_configure(self, dev_sxp, devid = None):
  61.225          """Configure an existing device.
  61.226          
  61.227 @@ -690,6 +800,10 @@ class XendDomainInfo:
  61.228          # convert device sxp to a dict
  61.229          dev_class = sxp.name(dev_sxp)
  61.230          dev_config = {}
  61.231 +
  61.232 +        if dev_class == 'pci':
  61.233 +            return self.pci_device_configure(dev_sxp)
  61.234 +
  61.235          for opt_val in dev_sxp[1:]:
  61.236              try:
  61.237                  dev_config[opt_val[0]] = opt_val[1]
  61.238 @@ -714,11 +828,11 @@ class XendDomainInfo:
  61.239          for devclass in XendDevices.valid_devices():
  61.240              self.getDeviceController(devclass).waitForDevices()
  61.241  
  61.242 -    def destroyPCIDevice(self, vslot):
  61.243 -        log.debug("destroyPCIDevice called %s", vslot)
  61.244 +    def hvm_destroyPCIDevice(self, vslot):
  61.245 +        log.debug("hvm_destroyPCIDevice called %s", vslot)
  61.246  
  61.247          if not self.info.is_hvm():
  61.248 -            raise VmError("only HVM guest support pci detach")
  61.249 +            raise VmError("hvm_destroyPCIDevice called on non-HVM guest")
  61.250  
  61.251          #all the PCI devs share one conf node
  61.252          devid = '0'
  61.253 @@ -744,35 +858,16 @@ class XendDomainInfo:
  61.254              raise VmError("Device @ vslot 0x%x do not support hotplug." % (vslot))
  61.255  
  61.256          bdf_str = "%s:%s:%s.%s" % (x['domain'], x['bus'], x['slot'], x['func'])
  61.257 -        log.info("destroyPCIDevice:%s:%s!", x, bdf_str)
  61.258 +        log.info("hvm_destroyPCIDevice:%s:%s!", x, bdf_str)
  61.259  
  61.260          self.image.signalDeviceModel('pci-rem', 'pci-removed', bdf_str)
  61.261  
  61.262 -        if pci_len > 1:
  61.263 -            del pci_conf['devs'][devnum]
  61.264 -            self._reconfigureDevice('pci', devid, pci_conf)
  61.265 -        else:
  61.266 -            self.getDeviceController('pci').destroyDevice(devid, True)
  61.267 -            del self.info['devices'][dev_uuid]
  61.268 -            platform = self.info['platform']
  61.269 -            orig_dev_num = len(platform['pci'])
  61.270 -
  61.271 -            #need remove the pci config
  61.272 -            #TODO:can use this to keep some info to ask high level management tools to hot insert a new passthrough dev after migration
  61.273 -            if orig_dev_num != 0:
  61.274 -#                platform['pci'] = ["%dDEVs" % orig_dev_num]
  61.275 -                platform['pci'] = []
  61.276 -
  61.277          return 0
  61.278  
  61.279      def destroyDevice(self, deviceClass, devid, force = False, rm_cfg = False):
  61.280          log.debug("XendDomainInfo.destroyDevice: deviceClass = %s, device = %s",
  61.281                    deviceClass, devid)
  61.282  
  61.283 -        if deviceClass == 'dpci':
  61.284 -            rc = self.destroyPCIDevice(devid)
  61.285 -            return rc
  61.286 -
  61.287          if rm_cfg:
  61.288              # Convert devid to device number.  A device number is
  61.289              # needed to remove its configuration.
  61.290 @@ -1967,36 +2062,44 @@ class XendDomainInfo:
  61.291                  for v in range(0, self.info['VCPUs_max']):
  61.292                      xc.vcpu_setaffinity(self.domid, v, self.info['cpus'])
  61.293              else:
  61.294 +                def find_relaxed_node(node_list):
  61.295 +                    import sys 
  61.296 +                    if node_list is None:
  61.297 +                        node_list = range(0, info['nr_nodes'])
  61.298 +                    nodeload = [0]
  61.299 +                    nodeload = nodeload * info['nr_nodes']
  61.300 +                    from xen.xend import XendDomain
  61.301 +                    doms = XendDomain.instance().list('all')
  61.302 +                    for dom in doms:
  61.303 +                        cpuinfo = dom.getVCPUInfo()
  61.304 +                        for vcpu in sxp.children(cpuinfo, 'vcpu'):
  61.305 +                            def vinfo(n, t):
  61.306 +                                return t(sxp.child_value(vcpu, n))
  61.307 +                            cpumap = vinfo('cpumap', list)
  61.308 +                            for i in node_list:
  61.309 +                                node_cpumask = info['node_to_cpu'][i]
  61.310 +                                for j in node_cpumask:
  61.311 +                                    if j in cpumap:
  61.312 +                                        nodeload[i] += 1
  61.313 +                                        break
  61.314 +                    for i in node_list:
  61.315 +                        if len(info['node_to_cpu'][i]) > 0:
  61.316 +                            nodeload[i] = int(nodeload[i] / len(info['node_to_cpu'][i]))
  61.317 +                        else:
  61.318 +                            nodeload[i] = sys.maxint
  61.319 +                    index = nodeload.index( min(nodeload) )    
  61.320 +                    return index
  61.321 +
  61.322                  info = xc.physinfo()
  61.323                  if info['nr_nodes'] > 1:
  61.324                      node_memory_list = info['node_to_memory']
  61.325                      needmem = self.image.getRequiredAvailableMemory(self.info['memory_dynamic_max']) / 1024
  61.326                      candidate_node_list = []
  61.327                      for i in range(0, info['nr_nodes']):
  61.328 -                        if node_memory_list[i] >= needmem:
  61.329 +                        if node_memory_list[i] >= needmem and len(info['node_to_cpu'][i]) > 0:
  61.330                              candidate_node_list.append(i)
  61.331 -                    if candidate_node_list is None or len(candidate_node_list) == 1:
  61.332 -                        index = node_memory_list.index( max(node_memory_list) )
  61.333 -                        cpumask = info['node_to_cpu'][index]
  61.334 -                    else:
  61.335 -                        nodeload = [0]
  61.336 -                        nodeload = nodeload * info['nr_nodes']
  61.337 -                        from xen.xend import XendDomain
  61.338 -                        doms = XendDomain.instance().list('all')
  61.339 -                        for dom in doms:
  61.340 -                            cpuinfo = dom.getVCPUInfo()
  61.341 -                            for vcpu in sxp.children(cpuinfo, 'vcpu'):
  61.342 -                                def vinfo(n, t):
  61.343 -                                    return t(sxp.child_value(vcpu, n))
  61.344 -                                cpumap = vinfo('cpumap', list)
  61.345 -                                for i in candidate_node_list:
  61.346 -                                    node_cpumask = info['node_to_cpu'][i]
  61.347 -                                    for j in node_cpumask:
  61.348 -                                        if j in cpumap:
  61.349 -                                            nodeload[i] += 1
  61.350 -                                            break
  61.351 -                        index = nodeload.index( min(nodeload) )
  61.352 -                        cpumask = info['node_to_cpu'][index]
  61.353 +                    index = find_relaxed_node(candidate_node_list)
  61.354 +                    cpumask = info['node_to_cpu'][index]
  61.355                      for v in range(0, self.info['VCPUs_max']):
  61.356                          xc.vcpu_setaffinity(self.domid, v, cpumask)
  61.357  
  61.358 @@ -2104,7 +2207,7 @@ class XendDomainInfo:
  61.359          self.state_updated.acquire()
  61.360          try:
  61.361              while self._stateGet() in (DOM_STATE_RUNNING,DOM_STATE_PAUSED):
  61.362 -                self.state_updated.wait()
  61.363 +                self.state_updated.wait(timeout=1.0)
  61.364          finally:
  61.365              self.state_updated.release()
  61.366  
    62.1 --- a/tools/python/xen/xend/image.py	Fri Mar 14 15:07:45 2008 -0600
    62.2 +++ b/tools/python/xen/xend/image.py	Thu Mar 20 12:35:40 2008 -0600
    62.3 @@ -90,6 +90,7 @@ class ImageHandler:
    62.4                          ("image/kernel", self.kernel),
    62.5                          ("image/cmdline", self.cmdline),
    62.6                          ("image/ramdisk", self.ramdisk))
    62.7 +        self.vm.permissionsVm("image/cmdline", { 'dom': self.vm.getDomid(), 'read': True } )
    62.8  
    62.9          self.device_model = vmConfig['platform'].get('device_model')
   62.10  
   62.11 @@ -201,6 +202,7 @@ class ImageHandler:
   62.12          vnc_config = {}
   62.13          has_vnc = int(vmConfig['platform'].get('vnc', 0)) != 0
   62.14          has_sdl = int(vmConfig['platform'].get('sdl', 0)) != 0
   62.15 +        opengl = 1
   62.16          for dev_uuid in vmConfig['console_refs']:
   62.17              dev_type, dev_info = vmConfig['devices'][dev_uuid]
   62.18              if dev_type == 'vfb':
   62.19 @@ -208,6 +210,7 @@ class ImageHandler:
   62.20                  if vfb_type == 'sdl':
   62.21                      self.display = dev_info.get('display', {})
   62.22                      self.xauthority = dev_info.get('xauthority', {})
   62.23 +                    opengl = int(dev_info.get('opengl', opengl))
   62.24                      has_sdl = True
   62.25                  else:
   62.26                      vnc_config = dev_info.get('other_config', {})
   62.27 @@ -262,7 +265,8 @@ class ImageHandler:
   62.28  
   62.29          elif has_sdl:
   62.30              # SDL is default in QEMU.
   62.31 -            pass
   62.32 +            if int(vmConfig['platform'].get('opengl', opengl)) != 1 :
   62.33 +                ret.append('-disable-opengl')
   62.34          else:
   62.35              ret.append('-nographic')
   62.36  
   62.37 @@ -580,7 +584,8 @@ class HVMImageHandler(ImageHandler):
   62.38              ret.append("nic,vlan=%d,macaddr=%s,model=%s" %
   62.39                         (nics, mac, model))
   62.40              ret.append("-net")
   62.41 -            ret.append("tap,vlan=%d,bridge=%s" % (nics, bridge))
   62.42 +            ret.append("tap,vlan=%d,ifname=tap%d.%d,bridge=%s" %
   62.43 +                       (nics, self.vm.getDomid(), nics-1, bridge))
   62.44  
   62.45          return ret
   62.46  
    63.1 --- a/tools/python/xen/xend/server/BlktapController.py	Fri Mar 14 15:07:45 2008 -0600
    63.2 +++ b/tools/python/xen/xend/server/BlktapController.py	Thu Mar 20 12:35:40 2008 -0600
    63.3 @@ -13,7 +13,9 @@ blktap_disk_types = [
    63.4      'vmdk',
    63.5      'ram',
    63.6      'qcow',
    63.7 -    'qcow2'
    63.8 +    'qcow2',
    63.9 +
   63.10 +    'ioemu'
   63.11      ]
   63.12  
   63.13  class BlktapController(BlkifController):
    64.1 --- a/tools/python/xen/xend/server/DevController.py	Fri Mar 14 15:07:45 2008 -0600
    64.2 +++ b/tools/python/xen/xend/server/DevController.py	Thu Mar 20 12:35:40 2008 -0600
    64.3 @@ -51,6 +51,8 @@ xenbusState = {
    64.4      'Connected'    : 4,
    64.5      'Closing'      : 5,
    64.6      'Closed'       : 6,
    64.7 +    'Reconfiguring': 7,
    64.8 +    'Reconfigured' : 8,
    64.9      }
   64.10  
   64.11  xoptions = XendOptions.instance()
   64.12 @@ -89,6 +91,8 @@ class DevController:
   64.13          if devid is None:
   64.14              return 0
   64.15  
   64.16 +        self.setupDevice(config)
   64.17 +
   64.18          (backpath, frontpath) = self.addStoreEntries(config, devid, back,
   64.19                                                       front)
   64.20  
   64.21 @@ -200,6 +204,15 @@ class DevController:
   64.22              raise VmError("Device %s (%s) could not be disconnected. " %
   64.23                            (devid, self.deviceClass))
   64.24  
   64.25 +    def waitForDevice_reconfigure(self, devid):
   64.26 +        log.debug("Waiting for %s - reconfigureDevice.", devid)
   64.27 +
   64.28 +        (status, err) = self.waitForBackend_reconfigure(devid)
   64.29 +
   64.30 +        if status == Timeout:
   64.31 +            raise VmError("Device %s (%s) could not be reconfigured. " %
   64.32 +                          (devid, self.deviceClass))
   64.33 +
   64.34  
   64.35      def reconfigureDevice(self, devid, config):
   64.36          """Reconfigure the specified device.
   64.37 @@ -326,6 +339,11 @@ class DevController:
   64.38  
   64.39          raise NotImplementedError()
   64.40  
   64.41 +    def setupDevice(self, config):
   64.42 +        """ Setup device from config.
   64.43 +        """
   64.44 +        return
   64.45 +
   64.46      def migrate(self, deviceConfig, network, dst, step, domName):
   64.47          """ Migration of a device. The 'network' parameter indicates
   64.48              whether the device is network-migrated (True). 'dst' then gives
   64.49 @@ -569,6 +587,22 @@ class DevController:
   64.50  
   64.51          return result['status']
   64.52  
   64.53 +    def waitForBackend_reconfigure(self, devid):
   64.54 +        frontpath = self.frontendPath(devid)
   64.55 +        backpath = xstransact.Read(frontpath, "backend")
   64.56 +        if backpath:
   64.57 +            statusPath = backpath + '/' + "state"
   64.58 +            ev = Event()
   64.59 +            result = { 'status': Timeout }
   64.60 +
   64.61 +            xswatch(statusPath, xenbusStatusCallback, ev, result)
   64.62 +
   64.63 +            ev.wait(DEVICE_CREATE_TIMEOUT)
   64.64 +
   64.65 +            return (result['status'], None)
   64.66 +        else:
   64.67 +            return (Missing, None)
   64.68 +
   64.69  
   64.70      def backendPath(self, backdom, devid):
   64.71          """Construct backend path given the backend domain and device id.
   64.72 @@ -634,3 +668,19 @@ def deviceDestroyCallback(statusPath, ev
   64.73  
   64.74      ev.set()
   64.75      return 0
   64.76 +
   64.77 +
   64.78 +def xenbusStatusCallback(statusPath, ev, result):
   64.79 +    log.debug("xenbusStatusCallback %s.", statusPath)
   64.80 +
   64.81 +    status = xstransact.Read(statusPath)
   64.82 +
   64.83 +    if status == str(xenbusState['Connected']):
   64.84 +        result['status'] = Connected
   64.85 +    else:
   64.86 +        return 1
   64.87 +
   64.88 +    log.debug("xenbusStatusCallback %d.", result['status'])
   64.89 +
   64.90 +    ev.set()
   64.91 +    return 0
    65.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Fri Mar 14 15:07:45 2008 -0600
    65.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Thu Mar 20 12:35:40 2008 -0600
    65.3 @@ -121,10 +121,10 @@ class SrvDomain(SrvDir):
    65.4  
    65.5      def op_pincpu(self, _, req):
    65.6          fn = FormFn(self.xd.domain_pincpu,
    65.7 -                    [['dom', 'int'],
    65.8 +                    [['dom', 'str'],
    65.9                       ['vcpu', 'str'],
   65.10                       ['cpumap', 'str']])
   65.11 -        val = fn(req.args, {'dom': self.dom.domid})
   65.12 +        val = fn(req.args, {'dom': self.dom.getName()})
   65.13          return val
   65.14  
   65.15      def op_cpu_sedf_get(self, _, req):
   65.16 @@ -147,17 +147,17 @@ class SrvDomain(SrvDir):
   65.17      
   65.18      def op_domain_sched_credit_get(self, _, req):
   65.19          fn = FormFn(self.xd.domain_sched_credit_get,
   65.20 -                    [['dom', 'int']])
   65.21 -        val = fn(req.args, {'dom': self.dom.domid})
   65.22 +                    [['dom', 'str']])
   65.23 +        val = fn(req.args, {'dom': self.dom.getName()})
   65.24          return val
   65.25  
   65.26  
   65.27      def op_domain_sched_credit_set(self, _, req):
   65.28          fn = FormFn(self.xd.domain_sched_credit_set,
   65.29 -                    [['dom', 'int'],
   65.30 +                    [['dom', 'str'],
   65.31                       ['weight', 'int'],
   65.32                       ['cap', 'int']])
   65.33 -        val = fn(req.args, {'dom': self.dom.domid})
   65.34 +        val = fn(req.args, {'dom': self.dom.getName()})
   65.35          return val
   65.36  
   65.37      def op_maxmem_set(self, _, req):
   65.38 @@ -187,7 +187,9 @@ class SrvDomain(SrvDir):
   65.39      def op_device_destroy(self, _, req):
   65.40          return self.call(self.dom.destroyDevice,
   65.41                           [['type', 'str'],
   65.42 -                          ['dev',  'str']],
   65.43 +                          ['dev',  'str'],
   65.44 +                          ['force',  'int'],
   65.45 +                          ['rm_cfg',  'int']],
   65.46                           req)
   65.47                  
   65.48      def op_device_configure(self, _, req):
    66.1 --- a/tools/python/xen/xend/server/pciif.py	Fri Mar 14 15:07:45 2008 -0600
    66.2 +++ b/tools/python/xen/xend/server/pciif.py	Thu Mar 20 12:35:40 2008 -0600
    66.3 @@ -24,7 +24,7 @@ from xen.xend import sxp
    66.4  from xen.xend.XendError import VmError
    66.5  from xen.xend.XendLogging import log
    66.6  
    66.7 -from xen.xend.server.DevController import DevController
    66.8 +from xen.xend.server.DevController import DevController, xenbusState
    66.9  
   66.10  import xen.lowlevel.xc
   66.11  
   66.12 @@ -44,6 +44,15 @@ while not (t&1):
   66.13      t>>=1
   66.14      PAGE_SHIFT+=1
   66.15  
   66.16 +def parse_hex(val):
   66.17 +    try:
   66.18 +        if isinstance(val, types.StringTypes):
   66.19 +            return int(val, 16)
   66.20 +        else:
   66.21 +            return val
   66.22 +    except ValueError:
   66.23 +        return None
   66.24 +
   66.25  class PciController(DevController):
   66.26  
   66.27      def __init__(self, vm):
   66.28 @@ -52,15 +61,6 @@ class PciController(DevController):
   66.29  
   66.30      def getDeviceDetails(self, config):
   66.31          """@see DevController.getDeviceDetails"""
   66.32 -        def parse_hex(val):
   66.33 -            try:
   66.34 -                if isinstance(val, types.StringTypes):
   66.35 -                    return int(val, 16)
   66.36 -                else:
   66.37 -                    return val
   66.38 -            except ValueError:
   66.39 -                return None
   66.40 -            
   66.41          back = {}
   66.42          pcidevid = 0
   66.43          vslots = ""
   66.44 @@ -74,7 +74,6 @@ class PciController(DevController):
   66.45              if vslt is not None:
   66.46                  vslots = vslots + vslt + ";"
   66.47  
   66.48 -            self.setupDevice(domain, bus, slot, func)
   66.49              back['dev-%i' % pcidevid] = "%04x:%02x:%02x.%02x" % \
   66.50                                          (domain, bus, slot, func)
   66.51              pcidevid += 1
   66.52 @@ -86,27 +85,80 @@ class PciController(DevController):
   66.53          back['uuid'] = config.get('uuid','')
   66.54          return (0, back, {})
   66.55  
   66.56 +
   66.57      def reconfigureDevice(self, _, config):
   66.58          """@see DevController.reconfigureDevice"""
   66.59 -        #currently only support config changes by hot insert/remove pass-through dev
   66.60 -        #delete all the devices in xenstore
   66.61 -        (devid, new_back, new_front) = self.getDeviceDetails(config)
   66.62 -        num_devs = self.readBackend(devid, 'num_devs')
   66.63 -        for i in range(int(num_devs)):
   66.64 -            self.removeBackend(devid, 'dev-%d' % i)
   66.65 -        self.removeBackend(devid, 'num_devs')
   66.66 +        (devid, back, front) = self.getDeviceDetails(config)
   66.67 +        num_devs = int(back['num_devs'])
   66.68 +        states = config.get('states', [])
   66.69 +
   66.70 +        old_vslots = self.readBackend(devid, 'vslots')
   66.71 +        if old_vslots is None:
   66.72 +            old_vslots = ''
   66.73 +        num_olddevs = int(self.readBackend(devid, 'num_devs'))
   66.74 +
   66.75 +        for i in range(num_devs):
   66.76 +            try:
   66.77 +                dev = back['dev-%i' % i]
   66.78 +                state = states[i]
   66.79 +            except:
   66.80 +                raise XendError('Error reading config')
   66.81 +
   66.82 +            if state == 'Initialising':
   66.83 +                # PCI device attachment
   66.84 +                for j in range(num_olddevs):
   66.85 +                    if dev == self.readBackend(devid, 'dev-%i' % j):
   66.86 +                        raise XendError('Device %s is already connected.' % dev)
   66.87 +                log.debug('Attaching PCI device %s.' % dev)
   66.88 +                (domain, bus, slotfunc) = dev.split(':')
   66.89 +                (slot, func) = slotfunc.split('.')
   66.90 +                domain = parse_hex(domain)
   66.91 +                bus = parse_hex(bus)
   66.92 +                slot = parse_hex(slot)
   66.93 +                func = parse_hex(func)
   66.94 +                self.setupOneDevice(domain, bus, slot, func)
   66.95 +
   66.96 +                self.writeBackend(devid, 'dev-%i' % (num_olddevs + i), dev)
   66.97 +                self.writeBackend(devid, 'state-%i' % (num_olddevs + i),
   66.98 +                                  str(xenbusState['Initialising']))
   66.99 +                self.writeBackend(devid, 'num_devs', str(num_olddevs + i + 1))
  66.100  
  66.101 -        #create new devices config
  66.102 -        num_devs = new_back['num_devs']
  66.103 -        for i in range(int(num_devs)):
  66.104 -            dev_no = 'dev-%d' % i
  66.105 -            self.writeBackend(devid, dev_no, new_back[dev_no])
  66.106 -        self.writeBackend(devid, 'num_devs', num_devs)
  66.107 +                # Update vslots
  66.108 +                if back['vslots'] is not None:
  66.109 +                    vslots = old_vslots + back['vslots']
  66.110 +                    self.writeBackend(devid, 'vslots', vslots)
  66.111 +
  66.112 +            elif state == 'Closing':
  66.113 +                # PCI device detachment
  66.114 +                found = False
  66.115 +                for j in range(num_olddevs):
  66.116 +                    if dev == self.readBackend(devid, 'dev-%i' % j):
  66.117 +                        found = True
  66.118 +                        log.debug('Detaching device %s' % dev)
  66.119 +                        self.writeBackend(devid, 'state-%i' % j,
  66.120 +                                          str(xenbusState['Closing']))
  66.121 +                if not found:
  66.122 +                    raise XendError('Device %s is not connected' % dev)
  66.123  
  66.124 -        if new_back['vslots'] is not None:
  66.125 -            self.writeBackend(devid, 'vslots', new_back['vslots'])
  66.126 +                # Update vslots
  66.127 +                if back['vslots'] is not None:
  66.128 +                    vslots = old_vslots
  66.129 +                    for vslt in back['vslots'].split(';'):
  66.130 +                        if vslt != '':
  66.131 +                            vslots = vslots.replace(vslt + ';', '', 1)
  66.132 +                    if vslots == '':
  66.133 +                        self.removeBackend(devid, 'vslots')
  66.134 +                    else:
  66.135 +                        self.writeBackend(devid, 'vslots', vslots)
  66.136  
  66.137 -        return new_back.get('uuid')
  66.138 +            else:
  66.139 +                raise XendError('Error configuring device %s: invalid state %s'
  66.140 +                                % (dev,state))
  66.141 +
  66.142 +        self.writeBackend(devid, 'state', str(xenbusState['Reconfiguring']))
  66.143 +
  66.144 +        return self.readBackend(devid, 'uuid')
  66.145 +
  66.146  
  66.147      def getDeviceConfiguration(self, devid, transaction = None):
  66.148          result = DevController.getDeviceConfiguration(self, devid, transaction)
  66.149 @@ -125,7 +177,7 @@ class PciController(DevController):
  66.150              pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" +
  66.151                                   r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + 
  66.152                                   r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + 
  66.153 -                                 r"(?P<func>[0-9a-fA-F]{1,2})", dev_config)
  66.154 +                                 r"(?P<func>[0-7]{1,2})$", dev_config)
  66.155              
  66.156              if pci_match!=None:
  66.157                  pci_dev_info = pci_match.groupdict()
  66.158 @@ -136,7 +188,10 @@ class PciController(DevController):
  66.159  
  66.160                  #append vslot info
  66.161                  if vslots is not None:
  66.162 -                    dev_dict['vslt'] = slot_list[i]
  66.163 +                    try:
  66.164 +                        dev_dict['vslt'] = slot_list[i]
  66.165 +                    except IndexError:
  66.166 +                        dev_dict['vslt'] = '0x0'
  66.167  
  66.168                  pci_devs.append(dev_dict)
  66.169  
  66.170 @@ -171,7 +226,7 @@ class PciController(DevController):
  66.171  
  66.172          return sxpr    
  66.173  
  66.174 -    def setupDevice(self, domain, bus, slot, func):
  66.175 +    def setupOneDevice(self, domain, bus, slot, func):
  66.176          """ Attach I/O resources for device to frontend domain
  66.177          """
  66.178          fe_domid = self.getDomid()
  66.179 @@ -225,6 +280,116 @@ class PciController(DevController):
  66.180                  raise VmError(('pci: failed to configure irq on device '+
  66.181                              '%s - errno=%d')%(dev.name,rc))
  66.182  
  66.183 +    def setupDevice(self, config):
  66.184 +        """Setup devices from config
  66.185 +        """
  66.186 +        for pci_config in config.get('devs', []):
  66.187 +            domain = parse_hex(pci_config.get('domain', 0))
  66.188 +            bus = parse_hex(pci_config.get('bus', 0))
  66.189 +            slot = parse_hex(pci_config.get('slot', 0))
  66.190 +            func = parse_hex(pci_config.get('func', 0))            
  66.191 +            self.setupOneDevice(domain, bus, slot, func)
  66.192 +
  66.193 +        return
  66.194 +
  66.195 +    def cleanupOneDevice(self, domain, bus, slot, func):
  66.196 +        """ Detach I/O resources for device from frontend domain
  66.197 +        """
  66.198 +        fe_domid = self.getDomid()
  66.199 +
  66.200 +        try:
  66.201 +            dev = PciDevice(domain, bus, slot, func)
  66.202 +        except Exception, e:
  66.203 +            raise VmError("pci: failed to locate device and "+
  66.204 +                    "parse it's resources - "+str(e))
  66.205 +
  66.206 +        if dev.driver!='pciback':
  66.207 +            raise VmError(("pci: PCI Backend does not own device "+ \
  66.208 +                    "%s\n"+ \
  66.209 +                    "See the pciback.hide kernel "+ \
  66.210 +                    "command-line parameter or\n"+ \
  66.211 +                    "bind your slot/device to the PCI backend using sysfs" \
  66.212 +                    )%(dev.name))
  66.213 +
  66.214 +        for (start, size) in dev.ioports:
  66.215 +            log.debug('pci: disabling ioport 0x%x/0x%x'%(start,size))
  66.216 +            rc = xc.domain_ioport_permission(domid = fe_domid, first_port = start,
  66.217 +                    nr_ports = size, allow_access = False)
  66.218 +            if rc<0:
  66.219 +                raise VmError(('pci: failed to configure I/O ports on device '+
  66.220 +                            '%s - errno=%d')%(dev.name,rc))
  66.221 +
  66.222 +        for (start, size) in dev.iomem:
  66.223 +            # Convert start/size from bytes to page frame sizes
  66.224 +            start_pfn = start>>PAGE_SHIFT
  66.225 +            # Round number of pages up to nearest page boundary (if not on one)
  66.226 +            nr_pfns = (size+(PAGE_SIZE-1))>>PAGE_SHIFT
  66.227 +
  66.228 +            log.debug('pci: disabling iomem 0x%x/0x%x pfn 0x%x/0x%x'% \
  66.229 +                    (start,size,start_pfn,nr_pfns))
  66.230 +            rc = xc.domain_iomem_permission(domid =  fe_domid,
  66.231 +                    first_pfn = start_pfn,
  66.232 +                    nr_pfns = nr_pfns,
  66.233 +                    allow_access = False)
  66.234 +            if rc<0:
  66.235 +                raise VmError(('pci: failed to configure I/O memory on device '+
  66.236 +                            '%s - errno=%d')%(dev.name,rc))
  66.237 +
  66.238 +        if dev.irq>0:
  66.239 +            log.debug('pci: disabling irq %d'%dev.irq)
  66.240 +            rc = xc.domain_irq_permission(domid =  fe_domid, pirq = dev.irq,
  66.241 +                    allow_access = False)
  66.242 +            if rc<0:
  66.243 +                raise VmError(('pci: failed to configure irq on device '+
  66.244 +                            '%s - errno=%d')%(dev.name,rc))
  66.245 +
  66.246 +    def cleanupDevice(self, devid):
  66.247 +        """ Detach I/O resources for device and cleanup xenstore nodes
  66.248 +        after reconfigure.
  66.249 +
  66.250 +        @param devid: The device ID
  66.251 +        @type devid:  int
  66.252 +        @return:      Return the number of devices connected
  66.253 +        @rtype:       int
  66.254 +        """
  66.255 +        num_devs = int(self.readBackend(devid, 'num_devs'))
  66.256 +        new_num_devs = 0
  66.257 +        for i in range(num_devs):
  66.258 +            state = int(self.readBackend(devid, 'state-%i' % i))
  66.259 +            if state == xenbusState['Closing']:
  66.260 +                # Detach I/O resources.
  66.261 +                dev = self.readBackend(devid, 'dev-%i' % i)
  66.262 +                (domain, bus, slotfunc) = dev.split(':')
  66.263 +                (slot, func) = slotfunc.split('.')
  66.264 +                domain = parse_hex(domain)
  66.265 +                bus = parse_hex(bus)
  66.266 +                slot = parse_hex(slot)
  66.267 +                func = parse_hex(func)            
  66.268 +                # In HVM case, I/O resources are disabled in ioemu.
  66.269 +                self.cleanupOneDevice(domain, bus, slot, func)
  66.270 +                # Remove xenstore nodes.
  66.271 +                self.removeBackend(devid, 'dev-%i' % i)
  66.272 +                self.removeBackend(devid, 'vdev-%i' % i)
  66.273 +                self.removeBackend(devid, 'state-%i' % i)
  66.274 +            else:
  66.275 +                if new_num_devs != i:
  66.276 +                    tmpdev = self.readBackend(devid, 'dev-%i' % i)
  66.277 +                    self.writeBackend(devid, 'dev-%i' % new_num_devs, tmpdev)
  66.278 +                    self.removeBackend(devid, 'dev-%i' % i)
  66.279 +                    tmpvdev = self.readBackend(devid, 'vdev-%i' % i)
  66.280 +                    if tmpvdev is not None:
  66.281 +                        self.writeBackend(devid, 'vdev-%i' % new_num_devs,
  66.282 +                                          tmpvdev)
  66.283 +                    self.removeBackend(devid, 'vdev-%i' % i)
  66.284 +                    tmpstate = self.readBackend(devid, 'state-%i' % i)
  66.285 +                    self.writeBackend(devid, 'state-%i' % new_num_devs, tmpstate)
  66.286 +                    self.removeBackend(devid, 'state-%i' % i)
  66.287 +                new_num_devs = new_num_devs + 1
  66.288 +
  66.289 +        self.writeBackend(devid, 'num_devs', str(new_num_devs))
  66.290 +
  66.291 +        return new_num_devs
  66.292 +
  66.293      def waitForBackend(self,devid):
  66.294          return (0, "ok - no hotplug")
  66.295  
    67.1 --- a/tools/python/xen/xend/server/vfbif.py	Fri Mar 14 15:07:45 2008 -0600
    67.2 +++ b/tools/python/xen/xend/server/vfbif.py	Thu Mar 20 12:35:40 2008 -0600
    67.3 @@ -7,7 +7,7 @@ import os
    67.4  
    67.5  CONFIG_ENTRIES = ['type', 'vncdisplay', 'vnclisten', 'vncpasswd', 'vncunused',
    67.6                    'display', 'xauthority', 'keymap',
    67.7 -                  'uuid', 'location', 'protocol']
    67.8 +                  'uuid', 'location', 'protocol', 'opengl']
    67.9  
   67.10  class VfbifController(DevController):
   67.11      """Virtual frame buffer controller. Handles all vfb devices for a domain.
    68.1 --- a/tools/python/xen/xm/create.py	Fri Mar 14 15:07:45 2008 -0600
    68.2 +++ b/tools/python/xen/xm/create.py	Thu Mar 20 12:35:40 2008 -0600
    68.3 @@ -304,7 +304,7 @@ gopts.var('disk', val='phy:DEV,VDEV,MODE
    68.4  gopts.var('pci', val='BUS:DEV.FUNC',
    68.5            fn=append_value, default=[],
    68.6            use="""Add a PCI device to a domain, using given params (in hex).
    68.7 -         For example 'pci=c0:02.1a'.
    68.8 +         For example 'pci=c0:02.1'.
    68.9           The option may be repeated to add more than one pci device.""")
   68.10  
   68.11  gopts.var('ioports', val='FROM[-TO]',
   68.12 @@ -319,7 +319,7 @@ gopts.var('irq', val='IRQ',
   68.13           For example 'irq=7'.
   68.14           This option may be repeated to add more than one IRQ.""")
   68.15  
   68.16 -gopts.var('vfb', val="type={vnc,sdl},vncunused=1,vncdisplay=N,vnclisten=ADDR,display=DISPLAY,xauthority=XAUTHORITY,vncpasswd=PASSWORD",
   68.17 +gopts.var('vfb', val="type={vnc,sdl},vncunused=1,vncdisplay=N,vnclisten=ADDR,display=DISPLAY,xauthority=XAUTHORITY,vncpasswd=PASSWORD,opengl=1",
   68.18            fn=append_value, default=[],
   68.19            use="""Make the domain a framebuffer backend.
   68.20            The backend type should be either sdl or vnc.
   68.21 @@ -330,7 +330,7 @@ gopts.var('vfb', val="type={vnc,sdl},vnc
   68.22            default password.
   68.23            For type=sdl, a viewer will be started automatically using the
   68.24            given DISPLAY and XAUTHORITY, which default to the current user's
   68.25 -          ones.""")
   68.26 +          ones.  OpenGL will be used by default unless opengl is set to 0.""")
   68.27  
   68.28  gopts.var('vif', val="type=TYPE,mac=MAC,bridge=BRIDGE,ip=IPADDR,script=SCRIPT," + \
   68.29            "backend=DOM,vifname=NAME,rate=RATE,model=MODEL,accel=ACCEL",
   68.30 @@ -504,6 +504,10 @@ gopts.var('sdl', val='',
   68.31            fn=set_value, default=None,
   68.32            use="""Should the device model use SDL?""")
   68.33  
   68.34 +gopts.var('opengl', val='',
   68.35 +          fn=set_value, default=None,
   68.36 +          use="""Enable\Disable OpenGL""")
   68.37 +
   68.38  gopts.var('display', val='DISPLAY',
   68.39            fn=set_value, default=None,
   68.40            use="X11 display to use")
   68.41 @@ -641,7 +645,7 @@ def configure_vfbs(config_devs, vals):
   68.42              d['type'] = 'sdl'
   68.43          for (k,v) in d.iteritems():
   68.44              if not k in [ 'vnclisten', 'vncunused', 'vncdisplay', 'display',
   68.45 -                          'xauthority', 'type', 'vncpasswd' ]:
   68.46 +                          'xauthority', 'type', 'vncpasswd', 'opengl' ]:
   68.47                  err("configuration option %s unknown to vfbs" % k)
   68.48              config.append([k,v])
   68.49          if not d.has_key("keymap"):
   68.50 @@ -745,7 +749,7 @@ def configure_hvm(config_image, vals):
   68.51               'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
   68.52               'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',
   68.53               'acpi', 'apic', 'usb', 'usbdevice', 'keymap', 'pci', 'hpet',
   68.54 -             'guest_os_type', 'hap']
   68.55 +             'guest_os_type', 'hap', 'opengl']
   68.56  
   68.57      for a in args:
   68.58          if a in vals.__dict__ and vals.__dict__[a] is not None:
   68.59 @@ -840,7 +844,7 @@ def preprocess_pci(vals):
   68.60          pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" + \
   68.61                  r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + \
   68.62                  r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + \
   68.63 -                r"(?P<func>[0-9a-fA-F])", pci_dev_str)
   68.64 +                r"(?P<func>[0-7])$", pci_dev_str)
   68.65          if pci_match!=None:
   68.66              pci_dev_info = pci_match.groupdict('0')
   68.67              try:
    69.1 --- a/tools/python/xen/xm/main.py	Fri Mar 14 15:07:45 2008 -0600
    69.2 +++ b/tools/python/xen/xm/main.py	Thu Mar 20 12:35:40 2008 -0600
    69.3 @@ -175,11 +175,11 @@ SUBCOMMAND_HELP = {
    69.4      'vnet-delete'   :  ('<VnetId>', 'Delete a Vnet.'),
    69.5      'vnet-list'     :  ('[-l|--long]', 'List Vnets.'),
    69.6      'vtpm-list'     :  ('<Domain> [--long]', 'List virtual TPM devices.'),
    69.7 -    'pci-attach '   :  ('<Domain> <dom> <bus> <slot> <func> [virtual slot]',
    69.8 +    'pci-attach'    :  ('<Domain> <domain:bus:slot.func> [virtual slot]',
    69.9                          'Insert a new pass-through pci device.'),
   69.10 -    'pci-detach '   :  ('<Domain> <virtual slot>',
   69.11 +    'pci-detach'    :  ('<Domain> <domain:bus:slot.func>',
   69.12                          'Remove a domain\'s pass-through pci device.'),
   69.13 -    'pci-list'     :  ('<Domain>',
   69.14 +    'pci-list'      :  ('<Domain>',
   69.15                          'List pass-through pci devices for a domain.'),
   69.16  
   69.17      # security
   69.18 @@ -626,8 +626,11 @@ class Shell(cmd.Cmd):
   69.19  
   69.20      def preloop(self):
   69.21          cmd.Cmd.preloop(self)
   69.22 -        import readline
   69.23 -        readline.set_completer_delims(' ')
   69.24 +        try:
   69.25 +            import readline
   69.26 +            readline.set_completer_delims(' ')
   69.27 +        except ImportError:
   69.28 +            pass
   69.29  
   69.30      def default(self, line):
   69.31          words = shlex.split(line)
   69.32 @@ -2229,29 +2232,37 @@ def xm_network_attach(args):
   69.33              vif.append(vif_param)
   69.34          server.xend.domain.device_create(dom, vif)
   69.35  
   69.36 -def parse_pci_configuration(args):
   69.37 +def parse_pci_configuration(args, state):
   69.38      dom = args[0]
   69.39 -
   69.40 -    if len(args) == 6:
   69.41 -        vslt = args[5]
   69.42 +    pci_dev_str = args[1]
   69.43 +    if len(args) == 3:
   69.44 +        vslt = args[2]
   69.45      else:
   69.46          vslt = '0x0' #chose a free virtual PCI slot
   69.47 -
   69.48 -    pci = ['pci',
   69.49 -          ['devs',
   69.50 -            [{'domain': "0x%x" % int(args[1], 16),
   69.51 -              'bus':    "0x%x" % int(args[2], 16),
   69.52 -              'slot':   "0x%x" % int(args[3], 16),
   69.53 -              'func':   "0x%x" % int(args[4], 16),
   69.54 -              'vslt':   "0x%x" % int(vslt,    16)}]
   69.55 -          ]]
   69.56 +    pci=['pci']
   69.57 +    pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" + \
   69.58 +            r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + \
   69.59 +            r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + \
   69.60 +            r"(?P<func>[0-7])$", pci_dev_str)
   69.61 +    if pci_match == None:
   69.62 +        raise OptionError("Invalid argument: %s %s" % (pci_dev_str,vslt))
   69.63 +    pci_dev_info = pci_match.groupdict('0')
   69.64 +    try:
   69.65 +        pci.append(['dev', ['domain', '0x'+ pci_dev_info['domain']], \
   69.66 +                ['bus', '0x'+ pci_dev_info['bus']],
   69.67 +                ['slot', '0x'+ pci_dev_info['slot']],
   69.68 +                ['func', '0x'+ pci_dev_info['func']],
   69.69 +                ['vslt', '0x%x' % int(vslt, 16)]])
   69.70 +    except:
   69.71 +        raise OptionError("Invalid argument: %s %s" % (pci_dev_str,vslt))
   69.72 +    pci.append(['state', state])
   69.73  
   69.74      return (dom, pci)
   69.75  
   69.76  def xm_pci_attach(args):
   69.77 -    arg_check(args, 'pci-attach', 5, 6)
   69.78 -    (dom, pci) = parse_pci_configuration(args)
   69.79 -    server.xend.domain.device_create(dom, pci)
   69.80 +    arg_check(args, 'pci-attach', 2, 3)
   69.81 +    (dom, pci) = parse_pci_configuration(args, 'Initialising')
   69.82 +    server.xend.domain.device_configure(dom, pci)
   69.83  
   69.84  def detach(args, deviceClass):
   69.85      rm_cfg = True
   69.86 @@ -2316,12 +2327,11 @@ def xm_network_detach(args):
   69.87          arg_check(args, 'network-detach', 2, 3)
   69.88          detach(args, 'vif')
   69.89  
   69.90 -
   69.91  def xm_pci_detach(args):
   69.92      arg_check(args, 'pci-detach', 2)
   69.93 -    dom = args[0]
   69.94 -    dev = args[1]
   69.95 -    server.xend.domain.destroyDevice(dom, 'dpci', dev)
   69.96 +    (dom, pci) = parse_pci_configuration(args, 'Closing')
   69.97 +    server.xend.domain.device_configure(dom, pci)
   69.98 +
   69.99  
  69.100  def xm_vnet_list(args):
  69.101      xenapi_unsupported()
    70.1 --- a/tools/python/xen/xm/xenapi_create.py	Fri Mar 14 15:07:45 2008 -0600
    70.2 +++ b/tools/python/xen/xm/xenapi_create.py	Thu Mar 20 12:35:40 2008 -0600
    70.3 @@ -810,7 +810,7 @@ class sxp2xml:
    70.4                  get_child_by_name(image, "vxauthority", "127.0.0.1"),
    70.5                  document))
    70.6              console.appendChild(self.mk_other_config(
    70.7 -                "vncpasswd", get_child_by_name(image, "vncpasswd", ""),
    70.8 +                "opengl", get_child_by_name(image, "opengl", "1"),
    70.9                  document))
   70.10              consoles.append(console)
   70.11              
    71.1 --- a/tools/xcutils/xc_save.c	Fri Mar 14 15:07:45 2008 -0600
    71.2 +++ b/tools/xcutils/xc_save.c	Thu Mar 20 12:35:40 2008 -0600
    71.3 @@ -17,6 +17,7 @@
    71.4  #include <sys/types.h>
    71.5  #include <sys/stat.h>
    71.6  #include <fcntl.h>
    71.7 +#include <err.h>
    71.8  
    71.9  #include <xs.h>
   71.10  #include <xenctrl.h>
    72.1 --- a/tools/xenstat/xentop/xentop.c	Fri Mar 14 15:07:45 2008 -0600
    72.2 +++ b/tools/xenstat/xentop/xentop.c	Thu Mar 20 12:35:40 2008 -0600
    72.3 @@ -1121,6 +1121,7 @@ int main(int argc, char **argv)
    72.4  		do {
    72.5  			gettimeofday(&curtime, NULL);
    72.6  			top();
    72.7 +			fflush(stdout);
    72.8  			oldtime = curtime;
    72.9  			if ((!loop) && !(--iterations))
   72.10  				break;
    73.1 --- a/tools/xenstore/Makefile	Fri Mar 14 15:07:45 2008 -0600
    73.2 +++ b/tools/xenstore/Makefile	Thu Mar 20 12:35:40 2008 -0600
    73.3 @@ -1,21 +1,16 @@
    73.4  XEN_ROOT=../..
    73.5  include $(XEN_ROOT)/tools/Rules.mk
    73.6 -XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
    73.7  
    73.8  MAJOR = 3.0
    73.9  MINOR = 0
   73.10  
   73.11 -PROFILE=#-pg
   73.12 -BASECFLAGS=-Werror
   73.13 +CFLAGS += -Werror
   73.14 +CFLAGS += -I.
   73.15 +CFLAGS += $(CFLAGS_libxenctrl)
   73.16 +
   73.17  # Make gcc generate dependencies.
   73.18 -BASECFLAGS += -Wp,-MD,.$(@F).d
   73.19 -PROG_DEP = .*.d
   73.20 -BASECFLAGS+= $(PROFILE)
   73.21 -BASECFLAGS+= $(CFLAGS_libxenctrl)
   73.22 -BASECFLAGS+= -I.
   73.23 -
   73.24 -CFLAGS  += $(BASECFLAGS)
   73.25 -LDFLAGS += $(PROFILE)
   73.26 +CFLAGS += -Wp,-MD,.$(@F).d
   73.27 +DEP    = .*.d
   73.28  
   73.29  CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod
   73.30  CLIENTS += xenstore-write
   73.31 @@ -45,22 +40,22 @@ CFLAGS += -DHAVE_DTRACE=1
   73.32  endif
   73.33   
   73.34  xenstored: $(XENSTORED_OBJS)
   73.35 -	$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) $(LDFLAGS_libxenctrl) $(SOCKET_LIBS) -o $@
   73.36 +	$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDFLAGS_libxenctrl) $(SOCKET_LIBS) -o $@
   73.37  
   73.38  $(CLIENTS): xenstore-%: xenstore_%.o libxenstore.so
   73.39 -	$(CC) $(CFLAGS) $(LDFLAGS) $< $(LOADLIBES) $(LDLIBS) -L. -lxenstore $(SOCKET_LIBS) -o $@
   73.40 +	$(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@
   73.41  
   73.42  $(CLIENTS_OBJS): xenstore_%.o: xenstore_client.c
   73.43  	$(COMPILE.c) -DCLIENT_$(*F) -o $@ $<
   73.44  
   73.45  xenstore-control: xenstore_control.o libxenstore.so
   73.46 -	$(CC) $(CFLAGS) $(LDFLAGS) $< $(LOADLIBES) $(LDLIBS) -L. -lxenstore $(SOCKET_LIBS) -o $@
   73.47 +	$(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@
   73.48  
   73.49  xenstore-ls: xsls.o libxenstore.so
   73.50 -	$(CC) $(CFLAGS) $(LDFLAGS) $< $(LOADLIBES) $(LDLIBS) -L. -lxenstore $(SOCKET_LIBS) -o $@
   73.51 +	$(CC) $(CFLAGS) $(LDFLAGS) $< -L. -lxenstore $(SOCKET_LIBS) -o $@
   73.52  
   73.53  xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o
   73.54 -	$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
   73.55 +	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
   73.56  
   73.57  libxenstore.so: libxenstore.so.$(MAJOR)
   73.58  	ln -sf $< $@
   73.59 @@ -71,7 +66,7 @@ libxenstore.so.$(MAJOR).$(MINOR): xs.opi
   73.60  	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenstore.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $^ $(SOCKET_LIBS) -lpthread
   73.61  
   73.62  libxenstore.a: xs.o xs_lib.o
   73.63 -	$(AR) rcs libxenstore.a $^
   73.64 +	$(AR) rcs $@ $^
   73.65  
   73.66  .PHONY: clean
   73.67  clean:
   73.68 @@ -79,7 +74,7 @@ clean:
   73.69  	rm -f xenstored xs_random xs_stress xs_crashme
   73.70  	rm -f xs_tdb_dump xenstore-control xenstore-ls
   73.71  	rm -f $(CLIENTS)
   73.72 -	$(RM) $(PROG_DEP)
   73.73 +	$(RM) $(DEP)
   73.74  
   73.75  .PHONY: TAGS
   73.76  TAGS:
   73.77 @@ -108,7 +103,7 @@ install: all
   73.78  	$(INSTALL_DATA) xs.h $(DESTDIR)$(INCLUDEDIR)
   73.79  	$(INSTALL_DATA) xs_lib.h $(DESTDIR)$(INCLUDEDIR)
   73.80  
   73.81 --include $(PROG_DEP)
   73.82 +-include $(DEP)
   73.83  
   73.84  # never delete any intermediate files.
   73.85  .SECONDARY:
    74.1 --- a/xen/arch/ia64/linux-xen/setup.c	Fri Mar 14 15:07:45 2008 -0600
    74.2 +++ b/xen/arch/ia64/linux-xen/setup.c	Thu Mar 20 12:35:40 2008 -0600
    74.3 @@ -358,7 +358,7 @@ acpi_oem_console_setup(void)
    74.4  	extern struct ns16550_defaults ns16550_com1;
    74.5  	efi_system_table_t *systab;
    74.6  	efi_config_table_t *tables;
    74.7 -	struct acpi20_table_rsdp *rsdp = NULL;
    74.8 +	struct acpi_table_rsdp *rsdp = NULL;
    74.9  	struct acpi_table_xsdt *xsdt;
   74.10  	struct acpi_table_header *hdr;
   74.11  	int i;
   74.12 @@ -378,16 +378,17 @@ acpi_oem_console_setup(void)
   74.13  	for (i = 0 ; i < (int)systab->nr_tables && !rsdp ; i++) {
   74.14  		if (efi_guidcmp(tables[i].guid, ACPI_20_TABLE_GUID) == 0)
   74.15  			rsdp =
   74.16 -			     (struct acpi20_table_rsdp *)__va(tables[i].table);
   74.17 +			     (struct acpi_table_rsdp *)__va(tables[i].table);
   74.18  	}
   74.19  
   74.20 -	if (!rsdp || strncmp(rsdp->signature, RSDP_SIG, sizeof(RSDP_SIG) - 1))
   74.21 +	if (!rsdp ||
   74.22 +	    strncmp(rsdp->signature, ACPI_SIG_RSDP, sizeof(ACPI_SIG_RSDP) - 1))
   74.23  		return -ENODEV;
   74.24  
   74.25 -	xsdt = (struct acpi_table_xsdt *)__va(rsdp->xsdt_address);
   74.26 +	xsdt = (struct acpi_table_xsdt *)__va(rsdp->xsdt_physical_address);
   74.27  	hdr = &xsdt->header;
   74.28  
   74.29 -	if (strncmp(hdr->signature, XSDT_SIG, sizeof(XSDT_SIG) - 1))
   74.30 +	if (strncmp(hdr->signature, ACPI_SIG_XSDT, sizeof(ACPI_SIG_XSDT) - 1))
   74.31  		return -ENODEV;
   74.32  
   74.33  	/* Looking for Fujitsu PRIMEQUEST systems */
    75.1 --- a/xen/arch/ia64/xen/acpi.c	Fri Mar 14 15:07:45 2008 -0600
    75.2 +++ b/xen/arch/ia64/xen/acpi.c	Thu Mar 20 12:35:40 2008 -0600
    75.3 @@ -74,7 +74,7 @@ acpi_get_sysname (void)
    75.4  {
    75.5  /* #ifdef CONFIG_IA64_GENERIC */
    75.6  	unsigned long rsdp_phys;
    75.7 -	struct acpi20_table_rsdp *rsdp;
    75.8 +	struct acpi_table_rsdp *rsdp;
    75.9  	struct acpi_table_xsdt *xsdt;
   75.10  	struct acpi_table_header *hdr;
   75.11  
   75.12 @@ -84,15 +84,15 @@ acpi_get_sysname (void)
   75.13  		return "dig";
   75.14  	}
   75.15  
   75.16 -	rsdp = (struct acpi20_table_rsdp *) __va(rsdp_phys);
   75.17 -	if (strncmp(rsdp->signature, RSDP_SIG, sizeof(RSDP_SIG) - 1)) {
   75.18 +	rsdp = (struct acpi_table_rsdp *) __va(rsdp_phys);
   75.19 +	if (strncmp(rsdp->signature, ACPI_SIG_RSDP, sizeof(ACPI_SIG_RSDP) - 1)) {
   75.20  		printk(KERN_ERR "ACPI 2.0 RSDP signature incorrect, default to \"dig\"\n");
   75.21  		return "dig";
   75.22  	}
   75.23  
   75.24 -	xsdt = (struct acpi_table_xsdt *) __va(rsdp->xsdt_address);
   75.25 +	xsdt = (struct acpi_table_xsdt *) __va(rsdp->xsdt_physical_address);
   75.26  	hdr = &xsdt->header;
   75.27 -	if (strncmp(hdr->signature, XSDT_SIG, sizeof(XSDT_SIG) - 1)) {
   75.28 +	if (strncmp(hdr->signature, ACPI_SIG_XSDT, sizeof(ACPI_SIG_XSDT) - 1)) {
   75.29  		printk(KERN_ERR "ACPI 2.0 XSDT signature incorrect, default to \"dig\"\n");
   75.30  		return "dig";
   75.31  	}
   75.32 @@ -356,14 +356,14 @@ acpi_parse_madt (unsigned long phys_addr
   75.33  #ifdef CONFIG_ITANIUM
   75.34  	has_8259 = 1; /* Firmware on old Itanium systems is broken */
   75.35  #else
   75.36 -	has_8259 = acpi_madt->flags.pcat_compat;
   75.37 +	has_8259 = acpi_madt->flags & ACPI_MADT_PCAT_COMPAT;
   75.38  #endif
   75.39  	iosapic_system_init(has_8259);
   75.40  
   75.41  	/* Get base address of IPI Message Block */
   75.42  
   75.43 -	if (acpi_madt->lapic_address)
   75.44 -		ipi_base_addr = (void __iomem *) ioremap(acpi_madt->lapic_address, 0);
   75.45 +	if (acpi_madt->address)
   75.46 +		ipi_base_addr = (void __iomem *)ioremap(acpi_madt->address, 0);
   75.47  
   75.48  	printk(KERN_INFO PREFIX "Local APIC address %p\n", ipi_base_addr);
   75.49  
   75.50 @@ -416,7 +416,7 @@ acpi_numa_slit_init (struct acpi_table_s
   75.51  	u32 len;
   75.52  
   75.53  	len = sizeof(struct acpi_table_header) + 8
   75.54 -		+ slit->localities * slit->localities;
   75.55 +		+ slit->locality_count * slit->locality_count;
   75.56  	if (slit->header.length != len) {
   75.57  		printk(KERN_ERR "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
   75.58  		       len, slit->header.length);
   75.59 @@ -519,21 +519,24 @@ acpi_numa_arch_fixup (void)
   75.60  	for (i = 0; i < srat_num_cpus; i++)
   75.61  		node_cpuid[i].nid = pxm_to_nid_map[node_cpuid[i].nid];
   75.62  
   75.63 -	printk(KERN_INFO "Number of logical nodes in system = %d\n", numnodes);
   75.64 -	printk(KERN_INFO "Number of memory chunks in system = %d\n", num_node_memblks);
   75.65 +	printk(KERN_INFO "Number of logical nodes in system = %d\n",
   75.66 +	       numnodes);
   75.67 +	printk(KERN_INFO "Number of memory chunks in system = %d\n",
   75.68 +	       num_node_memblks);
   75.69  
   75.70 -	if (!slit_table) return;
   75.71 +	if (!slit_table)
   75.72 +		return;
   75.73  	memset(numa_slit, -1, sizeof(numa_slit));
   75.74 -	for (i=0; i<slit_table->localities; i++) {
   75.75 +	for (i = 0; i < slit_table->locality_count; i++) {
   75.76  		if (!pxm_bit_test(i))
   75.77  			continue;
   75.78  		node_from = pxm_to_nid_map[i];
   75.79 -		for (j=0; j<slit_table->localities; j++) {
   75.80 +		for (j=0; j < slit_table->locality_count; j++) {
   75.81  			if (!pxm_bit_test(j))
   75.82  				continue;
   75.83  			node_to = pxm_to_nid_map[j];
   75.84  			node_distance(node_from, node_to) =
   75.85 -				slit_table->entry[i*slit_table->localities + j];
   75.86 +			    slit_table->entry[i * slit_table->locality_count + j];
   75.87  		}
   75.88  	}
   75.89  
   75.90 @@ -560,7 +563,7 @@ static int __init
   75.91  acpi_parse_fadt (unsigned long phys_addr, unsigned long size)
   75.92  {
   75.93  	struct acpi_table_header *fadt_header;
   75.94 -	struct fadt_descriptor_rev2 *fadt;
   75.95 +	struct acpi_table_fadt *fadt;
   75.96  
   75.97  	if (!phys_addr || !size)
   75.98  		return -EINVAL;
   75.99 @@ -569,16 +572,16 @@ acpi_parse_fadt (unsigned long phys_addr
  75.100  	if (fadt_header->revision != 3)
  75.101  		return -ENODEV;		/* Only deal with ACPI 2.0 FADT */
  75.102  
  75.103 -	fadt = (struct fadt_descriptor_rev2 *) fadt_header;
  75.104 +	fadt = (struct acpi_table_fadt *) fadt_header;
  75.105  
  75.106 -	if (!(fadt->iapc_boot_arch & BAF_8042_KEYBOARD_CONTROLLER))
  75.107 +	if (!(fadt->boot_flags & BAF_8042_KEYBOARD_CONTROLLER))
  75.108  		acpi_kbd_controller_present = 0;
  75.109  
  75.110 -	if (fadt->iapc_boot_arch & BAF_LEGACY_DEVICES)
  75.111 +	if (fadt->boot_flags & BAF_LEGACY_DEVICES)
  75.112  		acpi_legacy_devices = 1;
  75.113  
  75.114  #if 0
  75.115 -	acpi_register_gsi(fadt->sci_int, ACPI_ACTIVE_LOW, ACPI_LEVEL_SENSITIVE);
  75.116 +	acpi_register_gsi(fadt->sci_interrupt, ACPI_ACTIVE_LOW, ACPI_LEVEL_SENSITIVE);
  75.117  #endif
  75.118  	return 0;
  75.119  }
    76.1 --- a/xen/arch/ia64/xen/dom_fw_common.c	Fri Mar 14 15:07:45 2008 -0600
    76.2 +++ b/xen/arch/ia64/xen/dom_fw_common.c	Thu Mar 20 12:35:40 2008 -0600
    76.3 @@ -208,18 +208,18 @@ print_md(efi_memory_desc_t *md)
    76.4  }
    76.5  
    76.6  struct fake_acpi_tables {
    76.7 -	struct acpi20_table_rsdp rsdp;
    76.8 -	struct xsdt_descriptor_rev2 xsdt;
    76.9 +	struct acpi_table_rsdp rsdp;
   76.10 +	struct acpi_table_xsdt xsdt;
   76.11  	uint64_t madt_ptr;
   76.12 -	struct fadt_descriptor_rev2 fadt;
   76.13 -	struct facs_descriptor_rev2 facs;
   76.14 +	struct acpi_table_fadt fadt;
   76.15 +	struct acpi_table_facs facs;
   76.16  	struct acpi_table_header dsdt;
   76.17  	uint8_t aml[8 + 11 * MAX_VIRT_CPUS];
   76.18  	struct acpi_table_madt madt;
   76.19  	struct acpi_table_lsapic lsapic[MAX_VIRT_CPUS];
   76.20 -	uint8_t pm1a_evt_blk[4];
   76.21 -	uint8_t pm1a_cnt_blk[1];
   76.22 -	uint8_t pm_tmr_blk[4];
   76.23 +	uint8_t pm1a_event_block[4];
   76.24 +	uint8_t pm1a_control_block[1];
   76.25 +	uint8_t pm_timer_block[4];
   76.26  };
   76.27  #define ACPI_TABLE_MPA(field)                                       \
   76.28      FW_ACPI_BASE_PADDR + offsetof(struct fake_acpi_tables, field);
   76.29 @@ -228,10 +228,10 @@ struct fake_acpi_tables {
   76.30  void
   76.31  dom_fw_fake_acpi(domain_t *d, struct fake_acpi_tables *tables)
   76.32  {
   76.33 -	struct acpi20_table_rsdp *rsdp = &tables->rsdp;
   76.34 -	struct xsdt_descriptor_rev2 *xsdt = &tables->xsdt;
   76.35 -	struct fadt_descriptor_rev2 *fadt = &tables->fadt;
   76.36 -	struct facs_descriptor_rev2 *facs = &tables->facs;
   76.37 +	struct acpi_table_rsdp *rsdp = &tables->rsdp;
   76.38 +	struct acpi_table_xsdt *xsdt = &tables->xsdt;
   76.39 +	struct acpi_table_fadt *fadt = &tables->fadt;
   76.40 +	struct acpi_table_facs *facs = &tables->facs;
   76.41  	struct acpi_table_header *dsdt = &tables->dsdt;
   76.42  	struct acpi_table_madt *madt = &tables->madt;
   76.43  	struct acpi_table_lsapic *lsapic = tables->lsapic;
   76.44 @@ -245,34 +245,37 @@ dom_fw_fake_acpi(domain_t *d, struct fak
   76.45  	memset(tables, 0, sizeof(struct fake_acpi_tables));
   76.46  
   76.47  	/* setup XSDT (64bit version of RSDT) */
   76.48 -	memcpy(xsdt->signature, XSDT_SIG, sizeof(xsdt->signature));
   76.49 +	memcpy(xsdt->header.signature, ACPI_SIG_XSDT,
   76.50 +	       sizeof(xsdt->header.signature));
   76.51  	/* XSDT points to both the FADT and the MADT, so add one entry */
   76.52 -	xsdt->length = sizeof(struct xsdt_descriptor_rev2) + sizeof(uint64_t);
   76.53 -	xsdt->revision = 1;
   76.54 -	memcpy(xsdt->oem_id, "XEN", 3);
   76.55 -	memcpy(xsdt->oem_table_id, "Xen/ia64", 8);
   76.56 -	memcpy(xsdt->asl_compiler_id, "XEN", 3);
   76.57 -	xsdt->asl_compiler_revision = xen_ia64_version(d);
   76.58 +	xsdt->header.length = sizeof(struct acpi_table_xsdt) + sizeof(uint64_t);
   76.59 +	xsdt->header.revision = 1;
   76.60 +	memcpy(xsdt->header.oem_id, "XEN", 3);
   76.61 +	memcpy(xsdt->header.oem_table_id, "Xen/ia64", 8);
   76.62 +	memcpy(xsdt->header.asl_compiler_id, "XEN", 3);
   76.63 +	xsdt->header.asl_compiler_revision = xen_ia64_version(d);
   76.64  
   76.65  	xsdt->table_offset_entry[0] = ACPI_TABLE_MPA(fadt);
   76.66  	tables->madt_ptr = ACPI_TABLE_MPA(madt);
   76.67  
   76.68 -	xsdt->checksum = generate_acpi_checksum(xsdt, xsdt->length);
   76.69 +	xsdt->header.checksum = generate_acpi_checksum(xsdt,
   76.70 +	                                               xsdt->header.length);
   76.71  
   76.72  	/* setup FADT */
   76.73 -	memcpy(fadt->signature, FADT_SIG, sizeof(fadt->signature));
   76.74 -	fadt->length = sizeof(struct fadt_descriptor_rev2);
   76.75 -	fadt->revision = FADT2_REVISION_ID;
   76.76 -	memcpy(fadt->oem_id, "XEN", 3);
   76.77 -	memcpy(fadt->oem_table_id, "Xen/ia64", 8);
   76.78 -	memcpy(fadt->asl_compiler_id, "XEN", 3);
   76.79 -	fadt->asl_compiler_revision = xen_ia64_version(d);
   76.80 +	memcpy(fadt->header.signature, ACPI_SIG_FADT,
   76.81 +	       sizeof(fadt->header.signature));
   76.82 +	fadt->header.length = sizeof(struct acpi_table_fadt);
   76.83 +	fadt->header.revision = FADT2_REVISION_ID;
   76.84 +	memcpy(fadt->header.oem_id, "XEN", 3);
   76.85 +	memcpy(fadt->header.oem_table_id, "Xen/ia64", 8);
   76.86 +	memcpy(fadt->header.asl_compiler_id, "XEN", 3);
   76.87 +	fadt->header.asl_compiler_revision = xen_ia64_version(d);
   76.88  
   76.89 -	memcpy(facs->signature, FACS_SIG, sizeof(facs->signature));
   76.90 +	memcpy(facs->signature, ACPI_SIG_FACS, sizeof(facs->signature));
   76.91  	facs->version = 1;
   76.92 -	facs->length = sizeof(struct facs_descriptor_rev2);
   76.93 +	facs->length = sizeof(struct acpi_table_facs);
   76.94  
   76.95 -	fadt->xfirmware_ctrl = ACPI_TABLE_MPA(facs);
   76.96 +	fadt->Xfacs = ACPI_TABLE_MPA(facs);
   76.97  	fadt->Xdsdt = ACPI_TABLE_MPA(dsdt);
   76.98  
   76.99  	/*
  76.100 @@ -280,34 +283,35 @@ dom_fw_fake_acpi(domain_t *d, struct fak
  76.101  	 * from sanity checks in the ACPI CA.  Emulate required ACPI hardware
  76.102  	 * registers in system memory.
  76.103  	 */
  76.104 -	fadt->pm1_evt_len = 4;
  76.105 -	fadt->xpm1a_evt_blk.address_space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
  76.106 -	fadt->xpm1a_evt_blk.register_bit_width = 8;
  76.107 -	fadt->xpm1a_evt_blk.address = ACPI_TABLE_MPA(pm1a_evt_blk);
  76.108 -	fadt->pm1_cnt_len = 1;
  76.109 -	fadt->xpm1a_cnt_blk.address_space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
  76.110 -	fadt->xpm1a_cnt_blk.register_bit_width = 8;
  76.111 -	fadt->xpm1a_cnt_blk.address = ACPI_TABLE_MPA(pm1a_cnt_blk);
  76.112 -	fadt->pm_tm_len = 4;
  76.113 -	fadt->xpm_tmr_blk.address_space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
  76.114 -	fadt->xpm_tmr_blk.register_bit_width = 8;
  76.115 -	fadt->xpm_tmr_blk.address = ACPI_TABLE_MPA(pm_tmr_blk);
  76.116 +	fadt->pm1_event_length = 4;
  76.117 +	fadt->xpm1a_event_block.space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
  76.118 +	fadt->xpm1a_event_block.bit_width = 8;
  76.119 +	fadt->xpm1a_event_block.address = ACPI_TABLE_MPA(pm1a_event_block);
  76.120 +	fadt->pm1_control_length = 1;
  76.121 +	fadt->xpm1a_control_block.space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
  76.122 +	fadt->xpm1a_control_block.bit_width = 8;
  76.123 +	fadt->xpm1a_control_block.address = ACPI_TABLE_MPA(pm1a_control_block);
  76.124 +	fadt->pm_timer_length = 4;
  76.125 +	fadt->xpm_timer_block.space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
  76.126 +	fadt->xpm_timer_block.bit_width = 8;
  76.127 +	fadt->xpm_timer_block.address = ACPI_TABLE_MPA(pm_timer_block);
  76.128  
  76.129 -	fadt->checksum = generate_acpi_checksum(fadt, fadt->length);
  76.130 +	fadt->header.checksum = generate_acpi_checksum(fadt,
  76.131 +	                                               fadt->header.length);
  76.132  
  76.133  	/* setup RSDP */
  76.134 -	memcpy(rsdp->signature, RSDP_SIG, strlen(RSDP_SIG));
  76.135 +	memcpy(rsdp->signature, ACPI_SIG_RSDP, strlen(ACPI_SIG_RSDP));
  76.136  	memcpy(rsdp->oem_id, "XEN", 3);
  76.137  	rsdp->revision = 2; /* ACPI 2.0 includes XSDT */
  76.138 -	rsdp->length = sizeof(struct acpi20_table_rsdp);
  76.139 -	rsdp->xsdt_address = ACPI_TABLE_MPA(xsdt);
  76.140 +	rsdp->length = sizeof(struct acpi_table_rsdp);
  76.141 +	rsdp->xsdt_physical_address = ACPI_TABLE_MPA(xsdt);
  76.142  
  76.143  	rsdp->checksum = generate_acpi_checksum(rsdp,
  76.144  	                                        ACPI_RSDP_CHECKSUM_LENGTH);
  76.145 -	rsdp->ext_checksum = generate_acpi_checksum(rsdp, rsdp->length);
  76.146 +	rsdp->extended_checksum = generate_acpi_checksum(rsdp, rsdp->length);
  76.147  
  76.148  	/* setup DSDT with trivial namespace. */ 
  76.149 -	memcpy(dsdt->signature, DSDT_SIG, strlen(DSDT_SIG));
  76.150 +	memcpy(dsdt->signature, ACPI_SIG_DSDT, strlen(ACPI_SIG_DSDT));
  76.151  	dsdt->revision = 1;
  76.152  	memcpy(dsdt->oem_id, "XEN", 3);
  76.153  	memcpy(dsdt->oem_table_id, "Xen/ia64", 8);
  76.154 @@ -346,7 +350,8 @@ dom_fw_fake_acpi(domain_t *d, struct fak
  76.155  	dsdt->checksum = generate_acpi_checksum(dsdt, dsdt->length);
  76.156  
  76.157  	/* setup MADT */
  76.158 -	memcpy(madt->header.signature, APIC_SIG, sizeof(madt->header.signature));
  76.159 +	memcpy(madt->header.signature, ACPI_SIG_MADT,
  76.160 +	       sizeof(madt->header.signature));
  76.161  	madt->header.revision = 2;
  76.162  	memcpy(madt->header.oem_id, "XEN", 3);
  76.163  	memcpy(madt->header.oem_table_id, "Xen/ia64", 8);
    77.1 --- a/xen/arch/ia64/xen/pcdp.c	Fri Mar 14 15:07:45 2008 -0600
    77.2 +++ b/xen/arch/ia64/xen/pcdp.c	Thu Mar 20 12:35:40 2008 -0600
    77.3 @@ -43,7 +43,7 @@ pcdp_hp_irq_fixup(struct pcdp *pcdp, str
    77.4  {
    77.5  	efi_system_table_t *systab;
    77.6  	efi_config_table_t *tables;
    77.7 -	struct acpi20_table_rsdp *rsdp = NULL;
    77.8 +	struct acpi_table_rsdp *rsdp = NULL;
    77.9  	struct acpi_table_xsdt *xsdt;
   77.10  	struct acpi_table_header *hdr;
   77.11  	int i;
   77.12 @@ -66,16 +66,17 @@ pcdp_hp_irq_fixup(struct pcdp *pcdp, str
   77.13  	for (i = 0 ; i < (int)systab->nr_tables && !rsdp ; i++) {
   77.14  		if (efi_guidcmp(tables[i].guid, ACPI_20_TABLE_GUID) == 0)
   77.15  			rsdp =
   77.16 -			     (struct acpi20_table_rsdp *)__va(tables[i].table);
   77.17 +			     (struct acpi_table_rsdp *)__va(tables[i].table);
   77.18  	}
   77.19  
   77.20 -	if (!rsdp || strncmp(rsdp->signature, RSDP_SIG, sizeof(RSDP_SIG) - 1))
   77.21 +	if (!rsdp ||
   77.22 +	    strncmp(rsdp->signature, ACPI_SIG_RSDP, sizeof(ACPI_SIG_RSDP) - 1))
   77.23  		return;
   77.24  
   77.25 -	xsdt = (struct acpi_table_xsdt *)__va(rsdp->xsdt_address);
   77.26 +	xsdt = (struct acpi_table_xsdt *)__va(rsdp->xsdt_physical_address);
   77.27  	hdr = &xsdt->header;
   77.28  
   77.29 -	if (strncmp(hdr->signature, XSDT_SIG, sizeof(XSDT_SIG) - 1))
   77.30 +	if (strncmp(hdr->signature, ACPI_SIG_XSDT, sizeof(ACPI_SIG_XSDT) - 1))
   77.31  		return;
   77.32  
   77.33  	/* Sanity check; are we still looking at HP firmware tables? */
    78.1 --- a/xen/arch/x86/acpi/boot.c	Fri Mar 14 15:07:45 2008 -0600
    78.2 +++ b/xen/arch/x86/acpi/boot.c	Thu Mar 20 12:35:40 2008 -0600
    78.3 @@ -63,7 +63,7 @@ int acpi_ioapic;
    78.4  int acpi_strict;
    78.5  EXPORT_SYMBOL(acpi_strict);
    78.6  
    78.7 -acpi_interrupt_flags acpi_sci_flags __initdata;
    78.8 +u8 acpi_sci_flags __initdata;
    78.9  int acpi_sci_override_gsi __initdata;
   78.10  int acpi_skip_timer_override __initdata;
   78.11  
   78.12 @@ -148,11 +148,11 @@ static int __init acpi_parse_madt(unsign
   78.13  		return -ENODEV;
   78.14  	}
   78.15  
   78.16 -	if (madt->lapic_address) {
   78.17 -		acpi_lapic_addr = (u64) madt->lapic_address;
   78.18 +	if (madt->address) {
   78.19 +		acpi_lapic_addr = (u64) madt->address;
   78.20  
   78.21  		printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
   78.22 -		       madt->lapic_address);
   78.23 +		       madt->address);
   78.24  	}
   78.25  
   78.26  	acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
   78.27 @@ -342,23 +342,22 @@ static int __init acpi_parse_hpet(unsign
   78.28  		return -ENODEV;
   78.29  	}
   78.30  
   78.31 -	if (hpet_tbl->addr.space_id != ACPI_SPACE_MEM) {
   78.32 +	if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
   78.33  		printk(KERN_WARNING PREFIX "HPET timers must be located in "
   78.34  		       "memory.\n");
   78.35  		return -1;
   78.36  	}
   78.37  
   78.38  #if 0/*def	CONFIG_X86_64*/
   78.39 -        vxtime.hpet_address = hpet_tbl->addr.addrl |
   78.40 -                ((long) hpet_tbl->addr.addrh << 32);
   78.41 +	vxtime.hpet_address = hpet_tbl->address.address;
   78.42  
   78.43 -        printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
   78.44 -               hpet_tbl->id, vxtime.hpet_address);
   78.45 +	printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
   78.46 +	       hpet_tbl->id, vxtime.hpet_address);
   78.47  #else	/* X86 */
   78.48  	{
   78.49  		extern unsigned long hpet_address;
   78.50  
   78.51 -		hpet_address = hpet_tbl->addr.addrl;
   78.52 +		hpet_address = hpet_tbl->address.address;
   78.53  		printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
   78.54  		       hpet_tbl->id, hpet_address);
   78.55  	}
   78.56 @@ -377,11 +376,11 @@ extern u32 pmtmr_ioport;
   78.57  #ifdef CONFIG_ACPI_SLEEP
   78.58  /* Get pm1x_cnt and pm1x_evt information for ACPI sleep */
   78.59  static void __init
   78.60 -acpi_fadt_parse_sleep_info(struct fadt_descriptor_rev2 *fadt)
   78.61 +acpi_fadt_parse_sleep_info(struct acpi_table_fadt *fadt)
   78.62  {
   78.63  	struct acpi_table_rsdp *rsdp;
   78.64  	unsigned long rsdp_phys;
   78.65 -	struct facs_descriptor_rev2 *facs = NULL;
   78.66 +	struct acpi_table_facs *facs = NULL;
   78.67  	uint64_t facs_pa;
   78.68  
   78.69  	rsdp_phys = acpi_find_rsdp();
   78.70 @@ -389,41 +388,46 @@ acpi_fadt_parse_sleep_info(struct fadt_d
   78.71  		goto bad;
   78.72  	rsdp = __va(rsdp_phys);
   78.73  
   78.74 -	if (fadt->revision >= FADT2_REVISION_ID) {
   78.75 -		/* Sanity check on FADT Rev. 2 */
   78.76 -		if ((fadt->xpm1a_cnt_blk.address_space_id !=
   78.77 -		     ACPI_ADR_SPACE_SYSTEM_IO) ||
   78.78 -		    (fadt->xpm1b_cnt_blk.address_space_id !=
   78.79 -		     ACPI_ADR_SPACE_SYSTEM_IO) ||
   78.80 -		    (fadt->xpm1a_evt_blk.address_space_id !=
   78.81 -		     ACPI_ADR_SPACE_SYSTEM_IO) ||
   78.82 -		    (fadt->xpm1b_evt_blk.address_space_id !=
   78.83 -		     ACPI_ADR_SPACE_SYSTEM_IO))
   78.84 -			goto bad; 
   78.85 -
   78.86 -		acpi_sinfo.pm1a_cnt = (uint16_t)fadt->xpm1a_cnt_blk.address;
   78.87 -		acpi_sinfo.pm1b_cnt = (uint16_t)fadt->xpm1b_cnt_blk.address;
   78.88 -		acpi_sinfo.pm1a_evt = (uint16_t)fadt->xpm1a_evt_blk.address;
   78.89 -		acpi_sinfo.pm1b_evt = (uint16_t)fadt->xpm1b_evt_blk.address;
   78.90 +	if (fadt->header.revision >= FADT2_REVISION_ID) {
   78.91 +		memcpy(&acpi_sinfo.pm1a_cnt_blk, &fadt->xpm1a_control_block,
   78.92 +			sizeof(struct acpi_generic_address));
   78.93 +		memcpy(&acpi_sinfo.pm1b_cnt_blk, &fadt->xpm1b_control_block,
   78.94 +			sizeof(struct acpi_generic_address));
   78.95 +		memcpy(&acpi_sinfo.pm1a_evt_blk, &fadt->xpm1a_event_block,
   78.96 +			sizeof(struct acpi_generic_address));
   78.97 +		memcpy(&acpi_sinfo.pm1b_evt_blk, &fadt->xpm1b_event_block,
   78.98 +			sizeof(struct acpi_generic_address));
   78.99 +	} else {
  78.100 +		acpi_sinfo.pm1a_cnt_blk.address = fadt->pm1a_control_block;
  78.101 +		acpi_sinfo.pm1b_cnt_blk.address = fadt->pm1b_control_block;
  78.102 +		acpi_sinfo.pm1a_evt_blk.address = fadt->pm1a_event_block;
  78.103 +		acpi_sinfo.pm1b_evt_blk.address = fadt->pm1b_event_block;
  78.104 +		acpi_sinfo.pm1a_cnt_blk.space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  78.105 +		acpi_sinfo.pm1b_cnt_blk.space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  78.106 +		acpi_sinfo.pm1a_evt_blk.space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  78.107 +		acpi_sinfo.pm1b_evt_blk.space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  78.108 +		acpi_sinfo.pm1a_cnt_blk.bit_width = 16;
  78.109 +		acpi_sinfo.pm1b_cnt_blk.bit_width = 16;
  78.110 +		acpi_sinfo.pm1a_evt_blk.bit_width = 16;
  78.111 +		acpi_sinfo.pm1b_evt_blk.bit_width = 16;
  78.112 +		acpi_sinfo.pm1a_cnt_blk.bit_offset = 0;
  78.113 +		acpi_sinfo.pm1b_cnt_blk.bit_offset = 0;
  78.114 +		acpi_sinfo.pm1a_evt_blk.bit_offset = 0;
  78.115 +		acpi_sinfo.pm1b_evt_blk.bit_offset = 0;
  78.116 +		acpi_sinfo.pm1a_cnt_blk.access_width = 0;
  78.117 +		acpi_sinfo.pm1b_cnt_blk.access_width = 0;
  78.118 +		acpi_sinfo.pm1a_evt_blk.access_width = 0;
  78.119 +		acpi_sinfo.pm1b_evt_blk.access_width = 0;
  78.120  	}
  78.121  
  78.122 -	if (!acpi_sinfo.pm1a_cnt)
  78.123 -		acpi_sinfo.pm1a_cnt = (uint16_t)fadt->V1_pm1a_cnt_blk;
  78.124 -	if (!acpi_sinfo.pm1b_cnt)
  78.125 -		acpi_sinfo.pm1b_cnt = (uint16_t)fadt->V1_pm1b_cnt_blk;
  78.126 -	if (!acpi_sinfo.pm1a_evt)
  78.127 -		acpi_sinfo.pm1a_evt = (uint16_t)fadt->V1_pm1a_evt_blk;
  78.128 -	if (!acpi_sinfo.pm1b_evt)
  78.129 -		acpi_sinfo.pm1b_evt = (uint16_t)fadt->V1_pm1b_evt_blk;
  78.130 +	/* Now FACS... */
  78.131 +	if (fadt->header.revision >= FADT2_REVISION_ID)
  78.132 +		facs_pa = fadt->Xfacs;
  78.133 +	else
  78.134 +		facs_pa = (uint64_t)fadt->facs;
  78.135  
  78.136 -	/* Now FACS... */
  78.137 -	if (fadt->revision >= FADT2_REVISION_ID)
  78.138 -		facs_pa = fadt->xfirmware_ctrl;
  78.139 -	else
  78.140 -		facs_pa = (uint64_t)fadt->V1_firmware_ctrl;
  78.141 -
  78.142 -	facs = (struct facs_descriptor_rev2 *)
  78.143 -		__acpi_map_table(facs_pa, sizeof(struct facs_descriptor_rev2));
  78.144 +	facs = (struct acpi_table_facs *)
  78.145 +		__acpi_map_table(facs_pa, sizeof(struct acpi_table_facs));
  78.146  	if (!facs)
  78.147  		goto bad;
  78.148  
  78.149 @@ -446,20 +450,23 @@ acpi_fadt_parse_sleep_info(struct fadt_d
  78.150  
  78.151  	if ((rsdp->revision < 2) || (facs->length < 32)) {
  78.152  		acpi_sinfo.wakeup_vector = facs_pa + 
  78.153 -			offsetof(struct facs_descriptor_rev2,
  78.154 +			offsetof(struct acpi_table_facs,
  78.155  				 firmware_waking_vector);
  78.156  		acpi_sinfo.vector_width = 32;
  78.157  	} else {
  78.158  		acpi_sinfo.wakeup_vector = facs_pa +
  78.159 -			offsetof(struct facs_descriptor_rev2,
  78.160 +			offsetof(struct acpi_table_facs,
  78.161  				 xfirmware_waking_vector);
  78.162  		acpi_sinfo.vector_width = 64;
  78.163  	}
  78.164  
  78.165  	printk(KERN_INFO PREFIX
  78.166 -	       "ACPI SLEEP INFO: pm1x_cnt[%x,%x], pm1x_evt[%x,%x]\n",
  78.167 -	       acpi_sinfo.pm1a_cnt, acpi_sinfo.pm1b_cnt,
  78.168 -	       acpi_sinfo.pm1a_evt, acpi_sinfo.pm1b_cnt);
  78.169 +	       "ACPI SLEEP INFO: pm1x_cnt[%"PRIx64",%"PRIx64"], "
  78.170 +	       "pm1x_evt[%"PRIx64",%"PRIx64"]\n",
  78.171 +	       acpi_sinfo.pm1a_cnt_blk.address,
  78.172 +	       acpi_sinfo.pm1b_cnt_blk.address,
  78.173 +	       acpi_sinfo.pm1a_evt_blk.address,
  78.174 +	       acpi_sinfo.pm1b_evt_blk.address);
  78.175  	printk(KERN_INFO PREFIX
  78.176  	       "                 wakeup_vec[%"PRIx64"], vec_size[%x]\n",
  78.177  	       acpi_sinfo.wakeup_vector, acpi_sinfo.vector_width);
  78.178 @@ -471,9 +478,9 @@ bad:
  78.179  
  78.180  static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
  78.181  {
  78.182 -	struct fadt_descriptor_rev2 *fadt = NULL;
  78.183 +	struct acpi_table_fadt *fadt = NULL;
  78.184  
  78.185 -	fadt = (struct fadt_descriptor_rev2 *)__acpi_map_table(phys, size);
  78.186 +	fadt = (struct acpi_table_fadt *)__acpi_map_table(phys, size);
  78.187  	if (!fadt) {
  78.188  		printk(KERN_WARNING PREFIX "Unable to map FADT\n");
  78.189  		return 0;
  78.190 @@ -491,28 +498,28 @@ static int __init acpi_parse_fadt(unsign
  78.191  
  78.192  #ifdef CONFIG_X86_PM_TIMER
  78.193  	/* detect the location of the ACPI PM Timer */
  78.194 -	if (fadt->revision >= FADT2_REVISION_ID) {
  78.195 +	if (fadt->header.revision >= FADT2_REVISION_ID) {
  78.196  		/* FADT rev. 2 */
  78.197 -		if (fadt->xpm_tmr_blk.address_space_id ==
  78.198 +		if (fadt->xpm_timer_block.space_id ==
  78.199  		    ACPI_ADR_SPACE_SYSTEM_IO)
  78.200 -			pmtmr_ioport = fadt->xpm_tmr_blk.address;
  78.201 +			pmtmr_ioport = fadt->xpm_timer_block.address;
  78.202  		/*
  78.203  		 * "X" fields are optional extensions to the original V1.0
  78.204  		 * fields, so we must selectively expand V1.0 fields if the
  78.205  		 * corresponding X field is zero.
  78.206  	 	 */
  78.207  		if (!pmtmr_ioport)
  78.208 -			pmtmr_ioport = fadt->V1_pm_tmr_blk;
  78.209 +			pmtmr_ioport = fadt->pm_timer_block;
  78.210  	} else {
  78.211  		/* FADT rev. 1 */
  78.212 -		pmtmr_ioport = fadt->V1_pm_tmr_blk;
  78.213 +		pmtmr_ioport = fadt->pm_timer_block;
  78.214  	}
  78.215  	if (pmtmr_ioport)
  78.216  		printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
  78.217  		       pmtmr_ioport);
  78.218  #endif
  78.219  
  78.220 -	acpi_smi_cmd       = fadt->smi_cmd;
  78.221 +	acpi_smi_cmd       = fadt->smi_command;
  78.222  	acpi_enable_value  = fadt->acpi_enable;
  78.223  	acpi_disable_value = fadt->acpi_disable;
  78.224  
    79.1 --- a/xen/arch/x86/acpi/power.c	Fri Mar 14 15:07:45 2008 -0600
    79.2 +++ b/xen/arch/x86/acpi/power.c	Thu Mar 20 12:35:40 2008 -0600
    79.3 @@ -106,7 +106,7 @@ static void acpi_sleep_prepare(u32 state
    79.4              *(uint64_t *)wakeup_vector_va =
    79.5                  tboot_in_measured_env() ?
    79.6                  (uint64_t)g_tboot_shared->s3_tb_wakeup_entry :
    79.7 -	        (uint64_t)bootsym_phys(wakeup_start);
    79.8 +                (uint64_t)bootsym_phys(wakeup_start);
    79.9      }
   79.10  }
   79.11  
   79.12 @@ -198,7 +198,7 @@ static long enter_state_helper(void *dat
   79.13   */
   79.14  int acpi_enter_sleep(struct xenpf_enter_acpi_sleep *sleep)
   79.15  {
   79.16 -    if ( !IS_PRIV(current->domain) || !acpi_sinfo.pm1a_cnt )
   79.17 +    if ( !IS_PRIV(current->domain) || !acpi_sinfo.pm1a_cnt_blk.address )
   79.18          return -EPERM;
   79.19  
   79.20      /* Sanity check */
   79.21 @@ -222,10 +222,14 @@ int acpi_enter_sleep(struct xenpf_enter_
   79.22  
   79.23  static int acpi_get_wake_status(void)
   79.24  {
   79.25 -    uint16_t val;
   79.26 +    uint32_t val;
   79.27 +    acpi_status status;
   79.28  
   79.29      /* Wake status is the 15th bit of PM1 status register. (ACPI spec 3.0) */
   79.30 -    val = inw(acpi_sinfo.pm1a_evt) | inw(acpi_sinfo.pm1b_evt);
   79.31 +    status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS, &val);
   79.32 +    if ( ACPI_FAILURE(status) )
   79.33 +        return 0;
   79.34 +
   79.35      val &= ACPI_BITMASK_WAKE_STATUS;
   79.36      val >>= ACPI_BITPOSITION_WAKE_STATUS;
   79.37      return val;
   79.38 @@ -243,7 +247,7 @@ static void tboot_sleep(u8 sleep_state)
   79.39         case ACPI_STATE_S3:
   79.40             shutdown_type = TB_SHUTDOWN_S3;
   79.41             g_tboot_shared->s3_k_wakeup_entry =
   79.42 -	       (uint32_t)bootsym_phys(wakeup_start);
   79.43 +               (uint32_t)bootsym_phys(wakeup_start);
   79.44             break;
   79.45         case ACPI_STATE_S4:
   79.46             shutdown_type = TB_SHUTDOWN_S4;
   79.47 @@ -261,6 +265,8 @@ static void tboot_sleep(u8 sleep_state)
   79.48  /* System is really put into sleep state by this stub */
   79.49  acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
   79.50  {
   79.51 +    acpi_status status;
   79.52 +
   79.53      if ( tboot_in_measured_env() )
   79.54      {
   79.55          tboot_sleep(sleep_state);
   79.56 @@ -270,9 +276,18 @@ acpi_status asmlinkage acpi_enter_sleep_
   79.57  
   79.58      ACPI_FLUSH_CPU_CACHE();
   79.59  
   79.60 -    outw((u16)acpi_sinfo.pm1a_cnt_val, acpi_sinfo.pm1a_cnt);
   79.61 -    if ( acpi_sinfo.pm1b_cnt )
   79.62 -        outw((u16)acpi_sinfo.pm1b_cnt_val, acpi_sinfo.pm1b_cnt);
   79.63 +    status = acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, 
   79.64 +                                    acpi_sinfo.pm1a_cnt_val);
   79.65 +    if ( ACPI_FAILURE(status) )
   79.66 +        return_ACPI_STATUS(AE_ERROR);
   79.67 +
   79.68 +    if ( acpi_sinfo.pm1b_cnt_blk.address )
   79.69 +    {
   79.70 +        status = acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, 
   79.71 +                                        acpi_sinfo.pm1b_cnt_val);
   79.72 +        if ( ACPI_FAILURE(status) )
   79.73 +            return_ACPI_STATUS(AE_ERROR);
   79.74 +    }
   79.75  
   79.76      /* Wait until we enter sleep state, and spin until we wake */
   79.77      while ( !acpi_get_wake_status() )
    80.1 --- a/xen/arch/x86/domain.c	Fri Mar 14 15:07:45 2008 -0600
    80.2 +++ b/xen/arch/x86/domain.c	Thu Mar 20 12:35:40 2008 -0600
    80.3 @@ -46,7 +46,7 @@
    80.4  #include <asm/debugreg.h>
    80.5  #include <asm/msr.h>
    80.6  #include <asm/nmi.h>
    80.7 -#include <asm/iommu.h>
    80.8 +#include <xen/iommu.h>
    80.9  #ifdef CONFIG_COMPAT
   80.10  #include <compat/vcpu.h>
   80.11  #endif
   80.12 @@ -830,7 +830,7 @@ unmap_vcpu_info(struct vcpu *v)
   80.13      mfn = v->arch.vcpu_info_mfn;
   80.14      unmap_domain_page_global(v->vcpu_info);
   80.15  
   80.16 -    v->vcpu_info = shared_info_addr(d, vcpu_info[v->vcpu_id]);
   80.17 +    v->vcpu_info = (void *)&shared_info(d, vcpu_info[v->vcpu_id]);
   80.18      v->arch.vcpu_info_mfn = INVALID_MFN;
   80.19  
   80.20      put_page_and_type(mfn_to_page(mfn));
   80.21 @@ -888,7 +888,7 @@ map_vcpu_info(struct vcpu *v, unsigned l
   80.22       */
   80.23      vcpu_info(v, evtchn_upcall_pending) = 1;
   80.24      for ( i = 0; i < BITS_PER_GUEST_LONG(d); i++ )
   80.25 -        set_bit(i, vcpu_info_addr(v, evtchn_pending_sel));
   80.26 +        set_bit(i, &vcpu_info(v, evtchn_pending_sel));
   80.27  
   80.28      /*
   80.29       * Only bother to update time for the current vcpu.  If we're
   80.30 @@ -961,8 +961,9 @@ arch_do_vcpu_op(
   80.31          if ( !v->domain->is_pinned )
   80.32              break;
   80.33  
   80.34 -        cpu_id.phys_id = (x86_cpu_to_apicid[v->vcpu_id] |
   80.35 -                          (acpi_get_processor_id(v->vcpu_id) << 8));
   80.36 +        cpu_id.phys_id =
   80.37 +            (uint64_t)x86_cpu_to_apicid[v->vcpu_id] |
   80.38 +            ((uint64_t)acpi_get_processor_id(v->vcpu_id) << 32);
   80.39  
   80.40          rc = -EFAULT;
   80.41          if ( copy_to_guest(arg, &cpu_id, 1) )
    81.1 --- a/xen/arch/x86/domctl.c	Fri Mar 14 15:07:45 2008 -0600
    81.2 +++ b/xen/arch/x86/domctl.c	Thu Mar 20 12:35:40 2008 -0600
    81.3 @@ -26,7 +26,7 @@
    81.4  #include <asm/hvm/cacheattr.h>
    81.5  #include <asm/processor.h>
    81.6  #include <xsm/xsm.h>
    81.7 -#include <asm/iommu.h>
    81.8 +#include <xen/iommu.h>
    81.9  
   81.10  long arch_do_domctl(
   81.11      struct xen_domctl *domctl,
    82.1 --- a/xen/arch/x86/hvm/Makefile	Fri Mar 14 15:07:45 2008 -0600
    82.2 +++ b/xen/arch/x86/hvm/Makefile	Thu Mar 20 12:35:40 2008 -0600
    82.3 @@ -6,7 +6,6 @@ obj-y += hvm.o
    82.4  obj-y += i8254.o
    82.5  obj-y += intercept.o
    82.6  obj-y += io.o
    82.7 -obj-y += iommu.o
    82.8  obj-y += irq.o
    82.9  obj-y += mtrr.o
   82.10  obj-y += pmtimer.o
    83.1 --- a/xen/arch/x86/hvm/hvm.c	Fri Mar 14 15:07:45 2008 -0600
    83.2 +++ b/xen/arch/x86/hvm/hvm.c	Thu Mar 20 12:35:40 2008 -0600
    83.3 @@ -59,8 +59,8 @@ integer_param("hvm_debug", opt_hvm_debug
    83.4  struct hvm_function_table hvm_funcs __read_mostly;
    83.5  
    83.6  /* I/O permission bitmap is globally shared by all HVM guests. */
    83.7 -char __attribute__ ((__section__ (".bss.page_aligned")))
    83.8 -    hvm_io_bitmap[3*PAGE_SIZE];
    83.9 +unsigned long __attribute__ ((__section__ (".bss.page_aligned")))
   83.10 +    hvm_io_bitmap[3*PAGE_SIZE/BYTES_PER_LONG];
   83.11  
   83.12  void hvm_enable(struct hvm_function_table *fns)
   83.13  {
    84.1 --- a/xen/arch/x86/hvm/intercept.c	Fri Mar 14 15:07:45 2008 -0600
    84.2 +++ b/xen/arch/x86/hvm/intercept.c	Thu Mar 20 12:35:40 2008 -0600
    84.3 @@ -30,7 +30,7 @@
    84.4  #include <asm/current.h>
    84.5  #include <io_ports.h>
    84.6  #include <xen/event.h>
    84.7 -#include <asm/iommu.h>
    84.8 +#include <xen/iommu.h>
    84.9  
   84.10  extern struct hvm_mmio_handler hpet_mmio_handler;
   84.11  extern struct hvm_mmio_handler vlapic_mmio_handler;
    85.1 --- a/xen/arch/x86/hvm/iommu.c	Fri Mar 14 15:07:45 2008 -0600
    85.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    85.3 @@ -1,145 +0,0 @@
    85.4 -/*
    85.5 - * This program is free software; you can redistribute it and/or modify it
    85.6 - * under the terms and conditions of the GNU General Public License,
    85.7 - * version 2, as published by the Free Software Foundation.
    85.8 - *
    85.9 - * This program is distributed in the hope it will be useful, but WITHOUT
   85.10 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   85.11 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   85.12 - * more details.
   85.13 - *
   85.14 - * You should have received a copy of the GNU General Public License along with
   85.15 - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
   85.16 - * Place - Suite 330, Boston, MA 02111-1307 USA.
   85.17 - */
   85.18 -
   85.19 -#include <xen/init.h>
   85.20 -#include <xen/irq.h>
   85.21 -#include <xen/spinlock.h>
   85.22 -#include <xen/sched.h>
   85.23 -#include <xen/xmalloc.h>
   85.24 -#include <xen/domain_page.h>
   85.25 -#include <asm/delay.h>
   85.26 -#include <asm/string.h>
   85.27 -#include <asm/mm.h>
   85.28 -#include <asm/iommu.h>
   85.29 -#include <asm/hvm/vmx/intel-iommu.h>
   85.30 -
   85.31 -extern struct iommu_ops intel_iommu_ops;
   85.32 -extern struct iommu_ops amd_iommu_ops;
   85.33 -
   85.34 -int iommu_domain_init(struct domain *domain)
   85.35 -{
   85.36 -    struct hvm_iommu *hd = domain_hvm_iommu(domain);
   85.37 -
   85.38 -    spin_lock_init(&hd->mapping_lock);
   85.39 -    spin_lock_init(&hd->iommu_list_lock);
   85.40 -    INIT_LIST_HEAD(&hd->pdev_list);
   85.41 -    INIT_LIST_HEAD(&hd->g2m_ioport_list);
   85.42 -
   85.43 -    if ( !iommu_enabled )
   85.44 -        return 0;
   85.45 -
   85.46 -    switch ( boot_cpu_data.x86_vendor )
   85.47 -    {
   85.48 -    case X86_VENDOR_INTEL:
   85.49 -        hd->platform_ops = &intel_iommu_ops;
   85.50 -        break;
   85.51 -    case X86_VENDOR_AMD:
   85.52 -        hd->platform_ops = &amd_iommu_ops;
   85.53 -        break;
   85.54 -    default:
   85.55 -        BUG();
   85.56 -    }
   85.57 -
   85.58 -    return hd->platform_ops->init(domain);
   85.59 -}
   85.60 -
   85.61 -int assign_device(struct domain *d, u8 bus, u8 devfn)
   85.62 -{
   85.63 -    struct hvm_iommu *hd = domain_hvm_iommu(d);
   85.64 -
   85.65 -    if ( !iommu_enabled || !hd->platform_ops)
   85.66 -        return 0;
   85.67 -
   85.68 -    return hd->platform_ops->assign_device(d, bus, devfn);
   85.69 -}
   85.70 -
   85.71 -void iommu_domain_destroy(struct domain *d)
   85.72 -{
   85.73 -    struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
   85.74 -    uint32_t i;
   85.75 -    struct hvm_iommu *hd  = domain_hvm_iommu(d);
   85.76 -    struct list_head *ioport_list, *digl_list, *tmp;
   85.77 -    struct g2m_ioport *ioport;
   85.78 -    struct dev_intx_gsi_link *digl;
   85.79 -
   85.80 -    if ( !iommu_enabled || !hd->platform_ops)
   85.81 -        return;
   85.82 -
   85.83 -    if ( hvm_irq_dpci != NULL )
   85.84 -    {
   85.85 -        for ( i = 0; i < NR_IRQS; i++ )
   85.86 -        {
   85.87 -            if ( !hvm_irq_dpci->mirq[i].valid )
   85.88 -                continue;
   85.89 -
   85.90 -            pirq_guest_unbind(d, i);
   85.91 -            kill_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(i)]);
   85.92 -
   85.93 -            list_for_each_safe ( digl_list, tmp,
   85.94 -                                 &hvm_irq_dpci->mirq[i].digl_list )
   85.95 -            {
   85.96 -                digl = list_entry(digl_list,
   85.97 -                                  struct dev_intx_gsi_link, list);
   85.98 -                list_del(&digl->list);
   85.99 -                xfree(digl);
  85.100 -            }
  85.101 -        }
  85.102 -
  85.103 -        d->arch.hvm_domain.irq.dpci = NULL;
  85.104 -        xfree(hvm_irq_dpci);
  85.105 -    }
  85.106 -
  85.107 -    if ( hd )
  85.108 -    {
  85.109 -        list_for_each_safe ( ioport_list, tmp, &hd->g2m_ioport_list )
  85.110 -        {
  85.111 -            ioport = list_entry(ioport_list, struct g2m_ioport, list);
  85.112 -            list_del(&ioport->list);
  85.113 -            xfree(ioport);
  85.114 -        }
  85.115 -    }
  85.116 -
  85.117 -    return hd->platform_ops->teardown(d);
  85.118 -}
  85.119 -
  85.120 -int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn)
  85.121 -{
  85.122 -    struct hvm_iommu *hd = domain_hvm_iommu(d);
  85.123 -
  85.124 -    if ( !iommu_enabled || !hd->platform_ops)
  85.125 -        return 0;
  85.126 -
  85.127 -    return hd->platform_ops->map_page(d, gfn, mfn);
  85.128 -}
  85.129 -
  85.130 -int iommu_unmap_page(struct domain *d, unsigned long gfn)
  85.131 -{
  85.132 -    struct hvm_iommu *hd = domain_hvm_iommu(d);
  85.133 -
  85.134 -    if ( !iommu_enabled || !hd->platform_ops)
  85.135 -        return 0;
  85.136 -
  85.137 -    return hd->platform_ops->unmap_page(d, gfn);
  85.138 -}
  85.139 -
  85.140 -void deassign_device(struct domain *d, u8 bus, u8 devfn)
  85.141 -{
  85.142 -    struct hvm_iommu *hd = domain_hvm_iommu(d);
  85.143 -
  85.144 -    if ( !iommu_enabled || !hd->platform_ops)
  85.145 -        return;
  85.146 -
  85.147 -    return hd->platform_ops->reassign_device(d, dom0, bus, devfn);
  85.148 -}
    86.1 --- a/xen/arch/x86/hvm/svm/emulate.c	Fri Mar 14 15:07:45 2008 -0600
    86.2 +++ b/xen/arch/x86/hvm/svm/emulate.c	Thu Mar 20 12:35:40 2008 -0600
    86.3 @@ -117,7 +117,9 @@ int __get_instruction_length_from_list(s
    86.4      }
    86.5      else
    86.6      {
    86.7 -        inst_copy_from_guest(buffer, svm_rip2pointer(v), MAX_INST_LEN);
    86.8 +        if ( inst_copy_from_guest(buffer, svm_rip2pointer(v), MAX_INST_LEN)
    86.9 +             != MAX_INST_LEN )
   86.10 +            return 0;
   86.11          buf = buffer;
   86.12      }
   86.13  
    87.1 --- a/xen/arch/x86/hvm/svm/svm.c	Fri Mar 14 15:07:45 2008 -0600
    87.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Thu Mar 20 12:35:40 2008 -0600
    87.3 @@ -495,6 +495,7 @@ static void svm_get_segment_register(str
    87.4          break;
    87.5      case x86_seg_ss:
    87.6          memcpy(reg, &vmcb->ss, sizeof(*reg));
    87.7 +        reg->attr.fields.dpl = vmcb->cpl;
    87.8          break;
    87.9      case x86_seg_tr:
   87.10          svm_sync_vmcb(v);
   87.11 @@ -943,6 +944,10 @@ static void svm_vmexit_do_cpuid(struct c
   87.12  {
   87.13      unsigned int eax, ebx, ecx, edx, inst_len;
   87.14  
   87.15 +    inst_len = __get_instruction_length(current, INSTR_CPUID, NULL);
   87.16 +    if ( inst_len == 0 ) 
   87.17 +        return;
   87.18 +
   87.19      eax = regs->eax;
   87.20      ebx = regs->ebx;
   87.21      ecx = regs->ecx;
   87.22 @@ -955,7 +960,6 @@ static void svm_vmexit_do_cpuid(struct c
   87.23      regs->ecx = ecx;
   87.24      regs->edx = edx;
   87.25  
   87.26 -    inst_len = __get_instruction_length(current, INSTR_CPUID, NULL);
   87.27      __update_guest_eip(regs, inst_len);
   87.28  }
   87.29  
   87.30 @@ -1166,6 +1170,8 @@ static void svm_vmexit_do_hlt(struct vmc
   87.31      unsigned int inst_len;
   87.32  
   87.33      inst_len = __get_instruction_length(curr, INSTR_HLT, NULL);
   87.34 +    if ( inst_len == 0 )
   87.35 +        return;
   87.36      __update_guest_eip(regs, inst_len);
   87.37  
   87.38      /* Check for pending exception or new interrupt. */
   87.39 @@ -1354,6 +1360,8 @@ asmlinkage void svm_vmexit_handler(struc
   87.40  
   87.41      case VMEXIT_VMMCALL:
   87.42          inst_len = __get_instruction_length(v, INSTR_VMCALL, NULL);
   87.43 +        if ( inst_len == 0 )
   87.44 +            break;
   87.45          HVMTRACE_1D(VMMCALL, v, regs->eax);
   87.46          rc = hvm_do_hypercall(regs);
   87.47          if ( rc != HVM_HCALL_preempted )
    88.1 --- a/xen/arch/x86/hvm/svm/vmcb.c	Fri Mar 14 15:07:45 2008 -0600
    88.2 +++ b/xen/arch/x86/hvm/svm/vmcb.c	Thu Mar 20 12:35:40 2008 -0600
    88.3 @@ -80,27 +80,27 @@ struct host_save_area *alloc_host_save_a
    88.4  
    88.5  void svm_disable_intercept_for_msr(struct vcpu *v, u32 msr)
    88.6  {
    88.7 -    char *msr_bitmap = v->arch.hvm_svm.msrpm;
    88.8 +    unsigned long *msr_bitmap = v->arch.hvm_svm.msrpm;
    88.9  
   88.10      /*
   88.11       * See AMD64 Programmers Manual, Vol 2, Section 15.10 (MSR-Bitmap Address).
   88.12       */
   88.13      if ( msr <= 0x1fff )
   88.14      {
   88.15 -        __clear_bit(msr*2, msr_bitmap + 0x000); 
   88.16 -        __clear_bit(msr*2+1, msr_bitmap + 0x000); 
   88.17 +        __clear_bit(msr*2, msr_bitmap + 0x000/BYTES_PER_LONG); 
   88.18 +        __clear_bit(msr*2+1, msr_bitmap + 0x000/BYTES_PER_LONG); 
   88.19      }
   88.20      else if ( (msr >= 0xc0000000) && (msr <= 0xc0001fff) )
   88.21      {
   88.22          msr &= 0x1fff;
   88.23 -        __clear_bit(msr*2, msr_bitmap + 0x800);
   88.24 -        __clear_bit(msr*2+1, msr_bitmap + 0x800);
   88.25 +        __clear_bit(msr*2, msr_bitmap + 0x800/BYTES_PER_LONG);
   88.26 +        __clear_bit(msr*2+1, msr_bitmap + 0x800/BYTES_PER_LONG);
   88.27      } 
   88.28      else if ( (msr >= 0xc001000) && (msr <= 0xc0011fff) )
   88.29      {
   88.30          msr &= 0x1fff;
   88.31 -        __clear_bit(msr*2, msr_bitmap + 0x1000);
   88.32 -        __clear_bit(msr*2+1, msr_bitmap + 0x1000);
   88.33 +        __clear_bit(msr*2, msr_bitmap + 0x1000/BYTES_PER_LONG);
   88.34 +        __clear_bit(msr*2+1, msr_bitmap + 0x1000/BYTES_PER_LONG);
   88.35      }
   88.36  }
   88.37  
    89.1 --- a/xen/arch/x86/hvm/vlapic.c	Fri Mar 14 15:07:45 2008 -0600
    89.2 +++ b/xen/arch/x86/hvm/vlapic.c	Thu Mar 20 12:35:40 2008 -0600
    89.3 @@ -83,15 +83,17 @@ static unsigned int vlapic_lvt_mask[VLAP
    89.4   */
    89.5  
    89.6  #define VEC_POS(v) ((v)%32)
    89.7 -#define REG_POS(v) (((v)/32)* 0x10)
    89.8 -#define vlapic_test_and_set_vector(vec, bitmap)                 \
    89.9 -    test_and_set_bit(VEC_POS(vec), (bitmap) + REG_POS(vec))
   89.10 -#define vlapic_test_and_clear_vector(vec, bitmap)               \
   89.11 -    test_and_clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec))
   89.12 -#define vlapic_set_vector(vec, bitmap)                          \
   89.13 -    set_bit(VEC_POS(vec), (bitmap) + REG_POS(vec))
   89.14 -#define vlapic_clear_vector(vec, bitmap)                        \
   89.15 -    clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec))
   89.16 +#define REG_POS(v) (((v)/32) * 0x10)
   89.17 +#define vlapic_test_and_set_vector(vec, bitmap)                         \
   89.18 +    test_and_set_bit(VEC_POS(vec),                                      \
   89.19 +                     (unsigned long *)((bitmap) + REG_POS(vec)))
   89.20 +#define vlapic_test_and_clear_vector(vec, bitmap)                       \
   89.21 +    test_and_clear_bit(VEC_POS(vec),                                    \
   89.22 +                       (unsigned long *)((bitmap) + REG_POS(vec)))
   89.23 +#define vlapic_set_vector(vec, bitmap)                                  \
   89.24 +    set_bit(VEC_POS(vec), (unsigned long *)((bitmap) + REG_POS(vec)))
   89.25 +#define vlapic_clear_vector(vec, bitmap)                                \
   89.26 +    clear_bit(VEC_POS(vec), (unsigned long *)((bitmap) + REG_POS(vec)))
   89.27  
   89.28  static int vlapic_find_highest_vector(void *bitmap)
   89.29  {
    90.1 --- a/xen/arch/x86/hvm/vmx/vmcs.c	Fri Mar 14 15:07:45 2008 -0600
    90.2 +++ b/xen/arch/x86/hvm/vmx/vmcs.c	Thu Mar 20 12:35:40 2008 -0600
    90.3 @@ -413,7 +413,7 @@ static void vmx_set_host_env(struct vcpu
    90.4  
    90.5  void vmx_disable_intercept_for_msr(struct vcpu *v, u32 msr)
    90.6  {
    90.7 -    char *msr_bitmap = v->arch.hvm_vmx.msr_bitmap;
    90.8 +    unsigned long *msr_bitmap = v->arch.hvm_vmx.msr_bitmap;
    90.9  
   90.10      /* VMX MSR bitmap supported? */
   90.11      if ( msr_bitmap == NULL )
   90.12 @@ -426,14 +426,14 @@ void vmx_disable_intercept_for_msr(struc
   90.13       */
   90.14      if ( msr <= 0x1fff )
   90.15      {
   90.16 -        __clear_bit(msr, msr_bitmap + 0x000); /* read-low */
   90.17 -        __clear_bit(msr, msr_bitmap + 0x800); /* write-low */
   90.18 +        __clear_bit(msr, msr_bitmap + 0x000/BYTES_PER_LONG); /* read-low */
   90.19 +        __clear_bit(msr, msr_bitmap + 0x800/BYTES_PER_LONG); /* write-low */
   90.20      }
   90.21      else if ( (msr >= 0xc0000000) && (msr <= 0xc0001fff) )
   90.22      {
   90.23          msr &= 0x1fff;
   90.24 -        __clear_bit(msr, msr_bitmap + 0x400); /* read-high */
   90.25 -        __clear_bit(msr, msr_bitmap + 0xc00); /* write-high */
   90.26 +        __clear_bit(msr, msr_bitmap + 0x400/BYTES_PER_LONG); /* read-high */
   90.27 +        __clear_bit(msr, msr_bitmap + 0xc00/BYTES_PER_LONG); /* write-high */
   90.28      }
   90.29  }
   90.30  
   90.31 @@ -456,7 +456,7 @@ static int construct_vmcs(struct vcpu *v
   90.32      /* MSR access bitmap. */
   90.33      if ( cpu_has_vmx_msr_bitmap )
   90.34      {
   90.35 -        char *msr_bitmap = alloc_xenheap_page();
   90.36 +        unsigned long *msr_bitmap = alloc_xenheap_page();
   90.37  
   90.38          if ( msr_bitmap == NULL )
   90.39              return -ENOMEM;
   90.40 @@ -870,7 +870,7 @@ void vmcs_dump_vcpu(struct vcpu *v)
   90.41      x  = (unsigned long long)vmr(TSC_OFFSET_HIGH) << 32;
   90.42      x |= (uint32_t)vmr(TSC_OFFSET);
   90.43      printk("TSC Offset = %016llx\n", x);
   90.44 -    x  = (unsigned long long)vmr(GUEST_IA32_DEBUGCTL) << 32;
   90.45 +    x  = (unsigned long long)vmr(GUEST_IA32_DEBUGCTL_HIGH) << 32;
   90.46      x |= (uint32_t)vmr(GUEST_IA32_DEBUGCTL);
   90.47      printk("DebugCtl=%016llx DebugExceptions=%016llx\n", x,
   90.48             (unsigned long long)vmr(GUEST_PENDING_DBG_EXCEPTIONS));
    91.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Fri Mar 14 15:07:45 2008 -0600
    91.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Thu Mar 20 12:35:40 2008 -0600
    91.3 @@ -1512,8 +1512,10 @@ static int vmx_msr_read_intercept(struct
    91.4          msr_content = var_range_base[index];
    91.5          break;
    91.6      case MSR_IA32_DEBUGCTLMSR:
    91.7 -        if ( vmx_read_guest_msr(v, ecx, &msr_content) != 0 )
    91.8 -            msr_content = 0;
    91.9 +        msr_content = __vmread(GUEST_IA32_DEBUGCTL);
   91.10 +#ifdef __i386__
   91.11 +        msr_content |= (u64)__vmread(GUEST_IA32_DEBUGCTL_HIGH) << 32;
   91.12 +#endif
   91.13          break;
   91.14      case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_PROCBASED_CTLS2:
   91.15          goto gp_fault;
   91.16 @@ -1732,11 +1734,15 @@ static int vmx_msr_write_intercept(struc
   91.17          }
   91.18  
   91.19          if ( (rc < 0) ||
   91.20 -             (vmx_add_guest_msr(v, ecx) < 0) ||
   91.21               (vmx_add_host_load_msr(v, ecx) < 0) )
   91.22              vmx_inject_hw_exception(v, TRAP_machine_check, 0);
   91.23          else
   91.24 -            vmx_write_guest_msr(v, ecx, msr_content);
   91.25 +        {
   91.26 +            __vmwrite(GUEST_IA32_DEBUGCTL, msr_content);
   91.27 +#ifdef __i386__
   91.28 +            __vmwrite(GUEST_IA32_DEBUGCTL_HIGH, msr_content >> 32);
   91.29 +#endif
   91.30 +        }
   91.31  
   91.32          break;
   91.33      }
    92.1 --- a/xen/arch/x86/hvm/vmx/vpmu_core2.c	Fri Mar 14 15:07:45 2008 -0600
    92.2 +++ b/xen/arch/x86/hvm/vmx/vpmu_core2.c	Thu Mar 20 12:35:40 2008 -0600
    92.3 @@ -101,7 +101,7 @@ static int is_core2_vpmu_msr(u32 msr_ind
    92.4      return 0;
    92.5  }
    92.6  
    92.7 -static void core2_vpmu_set_msr_bitmap(char *msr_bitmap)
    92.8 +static void core2_vpmu_set_msr_bitmap(unsigned long *msr_bitmap)
    92.9  {
   92.10      int i;
   92.11  
   92.12 @@ -109,12 +109,14 @@ static void core2_vpmu_set_msr_bitmap(ch
   92.13      for ( i = 0; i < core2_counters.num; i++ )
   92.14      {
   92.15          clear_bit(msraddr_to_bitpos(core2_counters.msr[i]), msr_bitmap);
   92.16 -        clear_bit(msraddr_to_bitpos(core2_counters.msr[i]), msr_bitmap+0x800);
   92.17 +        clear_bit(msraddr_to_bitpos(core2_counters.msr[i]),
   92.18 +                  msr_bitmap + 0x800/BYTES_PER_LONG);
   92.19      }
   92.20      for ( i = 0; i < core2_get_pmc_count(); i++ )
   92.21      {
   92.22          clear_bit(msraddr_to_bitpos(MSR_IA32_PERFCTR0+i), msr_bitmap);
   92.23 -        clear_bit(msraddr_to_bitpos(MSR_IA32_PERFCTR0+i), msr_bitmap+0x800);
   92.24 +        clear_bit(msraddr_to_bitpos(MSR_IA32_PERFCTR0+i),
   92.25 +                  msr_bitmap + 0x800/BYTES_PER_LONG);
   92.26      }
   92.27  
   92.28      /* Allow Read PMU Non-global Controls Directly. */
   92.29 @@ -124,19 +126,21 @@ static void core2_vpmu_set_msr_bitmap(ch
   92.30          clear_bit(msraddr_to_bitpos(MSR_P6_EVNTSEL0+i), msr_bitmap);
   92.31  }
   92.32  
   92.33 -static void core2_vpmu_unset_msr_bitmap(char *msr_bitmap)
   92.34 +static void core2_vpmu_unset_msr_bitmap(unsigned long *msr_bitmap)
   92.35  {
   92.36      int i;
   92.37  
   92.38      for ( i = 0; i < core2_counters.num; i++ )
   92.39      {
   92.40          set_bit(msraddr_to_bitpos(core2_counters.msr[i]), msr_bitmap);
   92.41 -        set_bit(msraddr_to_bitpos(core2_counters.msr[i]), msr_bitmap+0x800);
   92.42 +        set_bit(msraddr_to_bitpos(core2_counters.msr[i]),
   92.43 +                msr_bitmap + 0x800/BYTES_PER_LONG);
   92.44      }
   92.45      for ( i = 0; i < core2_get_pmc_count(); i++ )
   92.46      {
   92.47          set_bit(msraddr_to_bitpos(MSR_IA32_PERFCTR0+i), msr_bitmap);
   92.48 -        set_bit(msraddr_to_bitpos(MSR_IA32_PERFCTR0+i), msr_bitmap+0x800);
   92.49 +        set_bit(msraddr_to_bitpos(MSR_IA32_PERFCTR0+i),
   92.50 +                msr_bitmap + 0x800/BYTES_PER_LONG);
   92.51      }
   92.52      for ( i = 0; i < core2_ctrls.num; i++ )
   92.53          set_bit(msraddr_to_bitpos(core2_ctrls.msr[i]), msr_bitmap);
    93.1 --- a/xen/arch/x86/irq.c	Fri Mar 14 15:07:45 2008 -0600
    93.2 +++ b/xen/arch/x86/irq.c	Thu Mar 20 12:35:40 2008 -0600
    93.3 @@ -15,7 +15,7 @@
    93.4  #include <xen/keyhandler.h>
    93.5  #include <xen/compat.h>
    93.6  #include <asm/current.h>
    93.7 -#include <asm/iommu.h>
    93.8 +#include <xen/iommu.h>
    93.9  
   93.10  /* opt_noirqbalance: If true, software IRQ balancing/affinity is disabled. */
   93.11  int opt_noirqbalance = 0;
   93.12 @@ -362,13 +362,12 @@ int pirq_guest_eoi(struct domain *d, int
   93.13  int pirq_guest_unmask(struct domain *d)
   93.14  {
   93.15      unsigned int   irq;
   93.16 -    shared_info_t *s = d->shared_info;
   93.17  
   93.18      for ( irq = find_first_bit(d->pirq_mask, NR_IRQS);
   93.19            irq < NR_IRQS;
   93.20            irq = find_next_bit(d->pirq_mask, NR_IRQS, irq+1) )
   93.21      {
   93.22 -        if ( !test_bit(d->pirq_to_evtchn[irq], __shared_info_addr(d, s, evtchn_mask)) )
   93.23 +        if ( !test_bit(d->pirq_to_evtchn[irq], &shared_info(d, evtchn_mask)) )
   93.24              __pirq_guest_eoi(d, irq);
   93.25      }
   93.26  
   93.27 @@ -660,13 +659,13 @@ static void dump_irqs(unsigned char key)
   93.28                  printk("%u(%c%c%c%c)",
   93.29                         d->domain_id,
   93.30                         (test_bit(d->pirq_to_evtchn[irq],
   93.31 -                                 shared_info_addr(d, evtchn_pending)) ?
   93.32 +                                 &shared_info(d, evtchn_pending)) ?
   93.33                          'P' : '-'),
   93.34                         (test_bit(d->pirq_to_evtchn[irq]/BITS_PER_GUEST_LONG(d),
   93.35 -                                 vcpu_info_addr(d->vcpu[0], evtchn_pending_sel)) ?
   93.36 +                                 &vcpu_info(d->vcpu[0], evtchn_pending_sel)) ?
   93.37                          'S' : '-'),
   93.38                         (test_bit(d->pirq_to_evtchn[irq],
   93.39 -                                 shared_info_addr(d, evtchn_mask)) ?
   93.40 +                                 &shared_info(d, evtchn_mask)) ?
   93.41                          'M' : '-'),
   93.42                         (test_bit(irq, d->pirq_mask) ?
   93.43                          'M' : '-'));
    94.1 --- a/xen/arch/x86/mm.c	Fri Mar 14 15:07:45 2008 -0600
    94.2 +++ b/xen/arch/x86/mm.c	Thu Mar 20 12:35:40 2008 -0600
    94.3 @@ -645,6 +645,7 @@ get_page_from_l1e(
    94.4      struct page_info *page = mfn_to_page(mfn);
    94.5      uint32_t l1f = l1e_get_flags(l1e);
    94.6      struct vcpu *curr = current;
    94.7 +    struct domain *owner;
    94.8      int okay;
    94.9  
   94.10      if ( !(l1f & _PAGE_PRESENT) )
   94.11 @@ -673,6 +674,17 @@ get_page_from_l1e(
   94.12          return 1;
   94.13      }
   94.14  
   94.15 +    /*
   94.16 +     * Let privileged domains transfer the right to map their target
   94.17 +     * domain's pages. This is used to allow stub-domain pvfb export to dom0,
   94.18 +     * until pvfb supports granted mappings. At that time this minor hack
   94.19 +     * can go away.
   94.20 +     */
   94.21 +    owner = page_get_owner(page);
   94.22 +    if ( unlikely(d != owner) && (owner != NULL) &&
   94.23 +         (d != curr->domain) && IS_PRIV_FOR(d, owner) )
   94.24 +        d = owner;
   94.25 +
   94.26      /* Foreign mappings into guests in shadow external mode don't
   94.27       * contribute to writeable mapping refcounts.  (This allows the
   94.28       * qemu-dm helper process in dom0 to map the domain's memory without
    95.1 --- a/xen/arch/x86/mm/p2m.c	Fri Mar 14 15:07:45 2008 -0600
    95.2 +++ b/xen/arch/x86/mm/p2m.c	Thu Mar 20 12:35:40 2008 -0600
    95.3 @@ -27,7 +27,7 @@
    95.4  #include <asm/page.h>
    95.5  #include <asm/paging.h>
    95.6  #include <asm/p2m.h>
    95.7 -#include <asm/iommu.h>
    95.8 +#include <xen/iommu.h>
    95.9  
   95.10  /* Debugging and auditing of the P2M code? */
   95.11  #define P2M_AUDIT     0
   95.12 @@ -229,7 +229,7 @@ set_p2m_entry(struct domain *d, unsigned
   95.13      if ( !p2m_next_level(d, &table_mfn, &table, &gfn_remainder, gfn,
   95.14                           L3_PAGETABLE_SHIFT - PAGE_SHIFT,
   95.15                           ((CONFIG_PAGING_LEVELS == 3)
   95.16 -                          ? (hvm_funcs.hap_supported ? 4 : 8)
   95.17 +                          ? (d->arch.hvm_domain.hap_enabled ? 4 : 8)
   95.18                            : L3_PAGETABLE_ENTRIES),
   95.19                           PGT_l2_page_table) )
   95.20          goto out;
    96.1 --- a/xen/arch/x86/mm/paging.c	Fri Mar 14 15:07:45 2008 -0600
    96.2 +++ b/xen/arch/x86/mm/paging.c	Thu Mar 20 12:35:40 2008 -0600
    96.3 @@ -114,7 +114,8 @@ static mfn_t paging_new_log_dirty_page(s
    96.4      return mfn;
    96.5  }
    96.6  
    96.7 -static mfn_t paging_new_log_dirty_leaf(struct domain *d, uint8_t **leaf_p)
    96.8 +static mfn_t paging_new_log_dirty_leaf(
    96.9 +    struct domain *d, unsigned long **leaf_p)
   96.10  {
   96.11      mfn_t mfn = paging_new_log_dirty_page(d, (void **)leaf_p);
   96.12      if ( mfn_valid(mfn) )
   96.13 @@ -264,7 +265,7 @@ void paging_mark_dirty(struct domain *d,
   96.14      mfn_t gmfn;
   96.15      int changed;
   96.16      mfn_t mfn, *l4, *l3, *l2;
   96.17 -    uint8_t *l1;
   96.18 +    unsigned long *l1;
   96.19      int i1, i2, i3, i4;
   96.20  
   96.21      gmfn = _mfn(guest_mfn);
   96.22 @@ -341,7 +342,7 @@ int paging_log_dirty_op(struct domain *d
   96.23      int rv = 0, clean = 0, peek = 1;
   96.24      unsigned long pages = 0;
   96.25      mfn_t *l4, *l3, *l2;
   96.26 -    uint8_t *l1;
   96.27 +    unsigned long *l1;
   96.28      int i4, i3, i2;
   96.29  
   96.30      domain_pause(d);
   96.31 @@ -399,7 +400,7 @@ int paging_log_dirty_op(struct domain *d
   96.32                    (pages < sc->pages) && (i2 < LOGDIRTY_NODE_ENTRIES);
   96.33                    i2++ )
   96.34              {
   96.35 -                static uint8_t zeroes[PAGE_SIZE];
   96.36 +                static unsigned long zeroes[PAGE_SIZE/BYTES_PER_LONG];
   96.37                  unsigned int bytes = PAGE_SIZE;
   96.38                  l1 = ((l2 && mfn_valid(l2[i2])) ?
   96.39                        map_domain_page(mfn_x(l2[i2])) : zeroes);
   96.40 @@ -408,7 +409,7 @@ int paging_log_dirty_op(struct domain *d
   96.41                  if ( likely(peek) )
   96.42                  {
   96.43                      if ( copy_to_guest_offset(sc->dirty_bitmap, pages >> 3,
   96.44 -                                              l1, bytes) != 0 )
   96.45 +                                              (uint8_t *)l1, bytes) != 0 )
   96.46                      {
   96.47                          rv = -EFAULT;
   96.48                          goto out;
    97.1 --- a/xen/arch/x86/mm/shadow/private.h	Fri Mar 14 15:07:45 2008 -0600
    97.2 +++ b/xen/arch/x86/mm/shadow/private.h	Thu Mar 20 12:35:40 2008 -0600
    97.3 @@ -483,7 +483,7 @@ sh_mfn_is_dirty(struct domain *d, mfn_t 
    97.4  {
    97.5      unsigned long pfn;
    97.6      mfn_t mfn, *l4, *l3, *l2;
    97.7 -    uint8_t *l1;
    97.8 +    unsigned long *l1;
    97.9      int rv;
   97.10  
   97.11      ASSERT(shadow_mode_log_dirty(d));
    98.1 --- a/xen/arch/x86/numa.c	Fri Mar 14 15:07:45 2008 -0600
    98.2 +++ b/xen/arch/x86/numa.c	Thu Mar 20 12:35:40 2008 -0600
    98.3 @@ -57,7 +57,7 @@ populate_memnodemap(const struct node *n
    98.4  {
    98.5  	int i; 
    98.6  	int res = -1;
    98.7 -	unsigned long addr, end;
    98.8 +	paddr_t addr, end;
    98.9  
   98.10  	if (shift >= 64)
   98.11  		return -1;
   98.12 @@ -286,13 +286,13 @@ static void dump_numa(unsigned char key)
   98.13  		  (u32)(now>>32), (u32)now);
   98.14  
   98.15  	for_each_online_node(i) {
   98.16 -		unsigned long pa = (NODE_DATA(i)->node_start_pfn + 1)<< PAGE_SHIFT;
   98.17 +		paddr_t pa = (NODE_DATA(i)->node_start_pfn + 1)<< PAGE_SHIFT;
   98.18  		printk("idx%d -> NODE%d start->%lu size->%lu\n",
   98.19  			  i, NODE_DATA(i)->node_id,
   98.20  			  NODE_DATA(i)->node_start_pfn,
   98.21  			  NODE_DATA(i)->node_spanned_pages);
   98.22  		/* sanity check phys_to_nid() */
   98.23 -		printk("phys_to_nid(%lx) -> %d should be %d\n", pa, phys_to_nid(pa),
   98.24 +		printk("phys_to_nid(%"PRIpaddr") -> %d should be %d\n", pa, phys_to_nid(pa),
   98.25  			  NODE_DATA(i)->node_id);
   98.26  	}
   98.27  	for_each_online_cpu(i)
    99.1 --- a/xen/arch/x86/srat.c	Fri Mar 14 15:07:45 2008 -0600
    99.2 +++ b/xen/arch/x86/srat.c	Thu Mar 20 12:35:40 2008 -0600
    99.3 @@ -106,7 +106,7 @@ static __init inline int srat_disabled(v
    99.4  static __init int slit_valid(struct acpi_table_slit *slit)
    99.5  {
    99.6  	int i, j;
    99.7 -	int d = slit->localities;
    99.8 +	int d = slit->locality_count;
    99.9  	for (i = 0; i < d; i++) {
   99.10  		for (j = 0; j < d; j++)  {
   99.11  			u8 val = slit->entry[d*i + j];
   99.12 @@ -308,7 +308,7 @@ int __node_distance(int a, int b)
   99.13  
   99.14  	if (!acpi_slit)
   99.15  		return a == b ? 10 : 20;
   99.16 -	index = acpi_slit->localities * node_to_pxm(a);
   99.17 +	index = acpi_slit->locality_count * node_to_pxm(a);
   99.18  	return acpi_slit->entry[index + node_to_pxm(b)];
   99.19  }
   99.20  
   100.1 --- a/xen/arch/x86/traps.c	Fri Mar 14 15:07:45 2008 -0600
   100.2 +++ b/xen/arch/x86/traps.c	Thu Mar 20 12:35:40 2008 -0600
   100.3 @@ -677,32 +677,75 @@ static int emulate_forced_invalid_op(str
   100.4          : "=a" (a), "=b" (b), "=c" (c), "=d" (d)
   100.5          : "0" (a), "1" (b), "2" (c), "3" (d) );
   100.6  
   100.7 -    if ( regs->eax == 1 )
   100.8 +    if ( (regs->eax & 0x7fffffff) == 1 )
   100.9      {
  100.10          /* Modify Feature Information. */
  100.11          __clear_bit(X86_FEATURE_VME, &d);
  100.12          __clear_bit(X86_FEATURE_PSE, &d);
  100.13          __clear_bit(X86_FEATURE_PGE, &d);
  100.14 +        __clear_bit(X86_FEATURE_MCE, &d);
  100.15 +        __clear_bit(X86_FEATURE_MCA, &d);
  100.16 +        if ( !IS_PRIV(current->domain) )
  100.17 +            __clear_bit(X86_FEATURE_MTRR, &d);
  100.18 +        __clear_bit(X86_FEATURE_PSE36, &d);
  100.19 +    }
  100.20 +    switch ( (uint32_t)regs->eax )
  100.21 +    {
  100.22 +    case 1:
  100.23 +        /* Modify Feature Information. */
  100.24          if ( !cpu_has_sep )
  100.25              __clear_bit(X86_FEATURE_SEP, &d);
  100.26  #ifdef __i386__
  100.27          if ( !supervisor_mode_kernel )
  100.28              __clear_bit(X86_FEATURE_SEP, &d);
  100.29  #endif
  100.30 -        if ( !IS_PRIV(current->domain) )
  100.31 -            __clear_bit(X86_FEATURE_MTRR, &d);
  100.32 -    }
  100.33 -    else if ( regs->eax == 0x80000001 )
  100.34 -    {
  100.35 +        __clear_bit(X86_FEATURE_DS, &d);
  100.36 +        __clear_bit(X86_FEATURE_ACC, &d);
  100.37 +        __clear_bit(X86_FEATURE_PBE, &d);
  100.38 +
  100.39 +        __clear_bit(X86_FEATURE_DTES64 % 32, &c);
  100.40 +        __clear_bit(X86_FEATURE_MWAIT % 32, &c);
  100.41 +        __clear_bit(X86_FEATURE_DSCPL % 32, &c);
  100.42 +        __clear_bit(X86_FEATURE_VMXE % 32, &c);
  100.43 +        __clear_bit(X86_FEATURE_SMXE % 32, &c);
  100.44 +        __clear_bit(X86_FEATURE_EST % 32, &c);
  100.45 +        __clear_bit(X86_FEATURE_TM2 % 32, &c);
  100.46 +        if ( is_pv_32bit_vcpu(current) )
  100.47 +            __clear_bit(X86_FEATURE_CX16 % 32, &c);
  100.48 +        __clear_bit(X86_FEATURE_XTPR % 32, &c);
  100.49 +        __clear_bit(X86_FEATURE_PDCM % 32, &c);
  100.50 +        __clear_bit(X86_FEATURE_DCA % 32, &c);
  100.51 +        break;
  100.52 +    case 0x80000001:
  100.53          /* Modify Feature Information. */
  100.54 -#ifdef __i386__
  100.55 -        __clear_bit(X86_FEATURE_SYSCALL % 32, &d);
  100.56 +        if ( is_pv_32bit_vcpu(current) )
  100.57 +        {
  100.58 +            __clear_bit(X86_FEATURE_LM % 32, &d);
  100.59 +            __clear_bit(X86_FEATURE_LAHF_LM % 32, &c);
  100.60 +        }
  100.61 +#ifndef __i386__
  100.62 +        if ( is_pv_32on64_vcpu(current) &&
  100.63 +             boot_cpu_data.x86_vendor != X86_VENDOR_AMD )
  100.64  #endif
  100.65 +            __clear_bit(X86_FEATURE_SYSCALL % 32, &d);
  100.66 +        __clear_bit(X86_FEATURE_PAGE1GB % 32, &d);
  100.67          __clear_bit(X86_FEATURE_RDTSCP % 32, &d);
  100.68 -    }
  100.69 -    else
  100.70 -    {
  100.71 +
  100.72 +        __clear_bit(X86_FEATURE_SVME % 32, &c);
  100.73 +        __clear_bit(X86_FEATURE_OSVW % 32, &c);
  100.74 +        __clear_bit(X86_FEATURE_IBS % 32, &c);
  100.75 +        __clear_bit(X86_FEATURE_SKINIT % 32, &c);
  100.76 +        __clear_bit(X86_FEATURE_WDT % 32, &c);
  100.77 +        break;
  100.78 +    case 5: /* MONITOR/MWAIT */
  100.79 +    case 0xa: /* Architectural Performance Monitor Features */
  100.80 +    case 0x8000000a: /* SVM revision and features */
  100.81 +    case 0x8000001b: /* Instruction Based Sampling */
  100.82 +        a = b = c = d = 0;
  100.83 +        break;
  100.84 +    default:
  100.85          (void)cpuid_hypervisor_leaves(regs->eax, &a, &b, &c, &d);
  100.86 +        break;
  100.87      }
  100.88  
  100.89      regs->eax = a;
  100.90 @@ -1801,6 +1844,8 @@ static int emulate_privileged_op(struct 
  100.91  
  100.92      case 0x20: /* MOV CR?,<reg> */
  100.93          opcode = insn_fetch(u8, code_base, eip, code_limit);
  100.94 +        if ( opcode < 0xc0 )
  100.95 +            goto fail;
  100.96          modrm_reg += ((opcode >> 3) & 7) + (lock << 3);
  100.97          modrm_rm  |= (opcode >> 0) & 7;
  100.98          reg = decode_register(modrm_rm, regs, 0);
  100.99 @@ -1841,6 +1886,8 @@ static int emulate_privileged_op(struct 
 100.100  
 100.101      case 0x21: /* MOV DR?,<reg> */
 100.102          opcode = insn_fetch(u8, code_base, eip, code_limit);
 100.103 +        if ( opcode < 0xc0 )
 100.104 +            goto fail;
 100.105          modrm_reg += ((opcode >> 3) & 7) + (lock << 3);
 100.106          modrm_rm  |= (opcode >> 0) & 7;
 100.107          reg = decode_register(modrm_rm, regs, 0);
 100.108 @@ -1851,6 +1898,8 @@ static int emulate_privileged_op(struct 
 100.109  
 100.110      case 0x22: /* MOV <reg>,CR? */
 100.111          opcode = insn_fetch(u8, code_base, eip, code_limit);
 100.112 +        if ( opcode < 0xc0 )
 100.113 +            goto fail;
 100.114          modrm_reg += ((opcode >> 3) & 7) + (lock << 3);
 100.115          modrm_rm  |= (opcode >> 0) & 7;
 100.116          reg = decode_register(modrm_rm, regs, 0);
 100.117 @@ -1897,6 +1946,8 @@ static int emulate_privileged_op(struct 
 100.118  
 100.119      case 0x23: /* MOV <reg>,DR? */
 100.120          opcode = insn_fetch(u8, code_base, eip, code_limit);
 100.121 +        if ( opcode < 0xc0 )
 100.122 +            goto fail;
 100.123          modrm_reg += ((opcode >> 3) & 7) + (lock << 3);
 100.124          modrm_rm  |= (opcode >> 0) & 7;
 100.125          reg = decode_register(modrm_rm, regs, 0);
 100.126 @@ -2027,6 +2078,15 @@ static int emulate_privileged_op(struct 
 100.127              if ( rdmsr_safe(regs->ecx, regs->eax, regs->edx) )
 100.128                  goto fail;
 100.129              break;
 100.130 +        case MSR_IA32_MISC_ENABLE:
 100.131 +            if ( rdmsr_safe(regs->ecx, regs->eax, regs->edx) )
 100.132 +                goto fail;
 100.133 +            regs->eax &= ~(MSR_IA32_MISC_ENABLE_PERF_AVAIL |
 100.134 +                           MSR_IA32_MISC_ENABLE_MONITOR_ENABLE);
 100.135 +            regs->eax |= MSR_IA32_MISC_ENABLE_BTS_UNAVAIL |
 100.136 +                         MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL |
 100.137 +                         MSR_IA32_MISC_ENABLE_XTPR_DISABLE;
 100.138 +            break;
 100.139          default:
 100.140              if ( rdmsr_hypervisor_regs(regs->ecx, &l, &h) )
 100.141              {
   101.1 --- a/xen/arch/x86/x86_emulate.c	Fri Mar 14 15:07:45 2008 -0600
   101.2 +++ b/xen/arch/x86/x86_emulate.c	Thu Mar 20 12:35:40 2008 -0600
   101.3 @@ -785,11 +785,21 @@ static int
   101.4      struct x86_emulate_ops  *ops)
   101.5  {
   101.6      int cpl = get_cpl(ctxt, ops);
   101.7 +    if ( cpl == -1 )
   101.8 +        return -1;
   101.9      return ((cpl >= 0) && (cpl <= ((ctxt->regs->eflags >> 12) & 3)));
  101.10  }
  101.11  
  101.12 -#define mode_ring0() (get_cpl(ctxt, ops) == 0)
  101.13 -#define mode_iopl()  _mode_iopl(ctxt, ops)
  101.14 +#define mode_ring0() ({                         \
  101.15 +    int _cpl = get_cpl(ctxt, ops);              \
  101.16 +    fail_if(_cpl < 0);                          \
  101.17 +    (_cpl == 0);                                \
  101.18 +})
  101.19 +#define mode_iopl() ({                          \
  101.20 +    int _iopl = _mode_iopl(ctxt, ops);          \
  101.21 +    fail_if(_iopl < 0);                         \
  101.22 +    _iopl;                                      \
  101.23 +})
  101.24  
  101.25  static int
  101.26  in_realmode(
  101.27 @@ -2255,7 +2265,6 @@ x86_emulate(
  101.28  
  101.29      case 0x6c ... 0x6d: /* ins %dx,%es:%edi */ {
  101.30          unsigned long nr_reps = get_rep_prefix();
  101.31 -        generate_exception_if(!mode_iopl(), EXC_GP, 0);
  101.32          dst.bytes = !(b & 1) ? 1 : (op_bytes == 8) ? 4 : op_bytes;
  101.33          dst.mem.seg = x86_seg_es;
  101.34          dst.mem.off = truncate_ea(_regs.edi);
  101.35 @@ -2285,7 +2294,6 @@ x86_emulate(
  101.36  
  101.37      case 0x6e ... 0x6f: /* outs %esi,%dx */ {
  101.38          unsigned long nr_reps = get_rep_prefix();
  101.39 -        generate_exception_if(!mode_iopl(), EXC_GP, 0);
  101.40          dst.bytes = !(b & 1) ? 1 : (op_bytes == 8) ? 4 : op_bytes;
  101.41          if ( (nr_reps > 1) && (ops->rep_outs != NULL) &&
  101.42               ((rc = ops->rep_outs(ea.mem.seg, truncate_ea(_regs.esi),
  101.43 @@ -2394,8 +2402,10 @@ x86_emulate(
  101.44  
  101.45      case 0x9d: /* popf */ {
  101.46          uint32_t mask = EFLG_VIP | EFLG_VIF | EFLG_VM;
  101.47 +        if ( !mode_ring0() )
  101.48 +            mask |= EFLG_IOPL;
  101.49          if ( !mode_iopl() )
  101.50 -            mask |= EFLG_IOPL;
  101.51 +            mask |= EFLG_IF;
  101.52          /* 64-bit mode: POP defaults to a 64-bit operand. */
  101.53          if ( mode_64bit() && (op_bytes == 4) )
  101.54              op_bytes = 8;
  101.55 @@ -2640,8 +2650,10 @@ x86_emulate(
  101.56      case 0xcf: /* iret */ {
  101.57          unsigned long cs, eip, eflags;
  101.58          uint32_t mask = EFLG_VIP | EFLG_VIF | EFLG_VM;
  101.59 +        if ( !mode_ring0() )
  101.60 +            mask |= EFLG_IOPL;
  101.61          if ( !mode_iopl() )
  101.62 -            mask |= EFLG_IOPL;
  101.63 +            mask |= EFLG_IF;
  101.64          fail_if(!in_realmode(ctxt, ops));
  101.65          if ( (rc = ops->read(x86_seg_ss, sp_post_inc(op_bytes),
  101.66                               &eip, op_bytes, ctxt)) ||
  101.67 @@ -2818,7 +2830,6 @@ x86_emulate(
  101.68          unsigned int port = ((b < 0xe8)
  101.69                               ? insn_fetch_type(uint8_t)
  101.70                               : (uint16_t)_regs.edx);
  101.71 -        generate_exception_if(!mode_iopl(), EXC_GP, 0);
  101.72          op_bytes = !(b & 1) ? 1 : (op_bytes == 8) ? 4 : op_bytes;
  101.73          if ( b & 2 )
  101.74          {
  101.75 @@ -3219,8 +3230,8 @@ x86_emulate(
  101.76      case 0x21: /* mov dr,reg */
  101.77      case 0x22: /* mov reg,cr */
  101.78      case 0x23: /* mov reg,dr */
  101.79 +        generate_exception_if(ea.type != OP_REG, EXC_UD, -1);
  101.80          generate_exception_if(!mode_ring0(), EXC_GP, 0);
  101.81 -        modrm_rm  |= (rex_prefix & 1) << 3;
  101.82          modrm_reg |= lock_prefix << 3;
  101.83          if ( b & 2 )
  101.84          {
   102.1 --- a/xen/common/domain.c	Fri Mar 14 15:07:45 2008 -0600
   102.2 +++ b/xen/common/domain.c	Thu Mar 20 12:35:40 2008 -0600
   102.3 @@ -110,10 +110,6 @@ static void __domain_finalise_shutdown(s
   102.4              return;
   102.5  
   102.6      d->is_shut_down = 1;
   102.7 -
   102.8 -    for_each_vcpu ( d, v )
   102.9 -        vcpu_sleep_nosync(v);
  102.10 -
  102.11      send_guest_global_virq(dom0, VIRQ_DOM_EXC);
  102.12  }
  102.13  
  102.14 @@ -126,7 +122,7 @@ static void vcpu_check_shutdown(struct v
  102.15      if ( d->is_shutting_down )
  102.16      {
  102.17          if ( !v->paused_for_shutdown )
  102.18 -            atomic_inc(&v->pause_count);
  102.19 +            vcpu_pause_nosync(v);
  102.20          v->paused_for_shutdown = 1;
  102.21          v->defer_shutdown = 0;
  102.22          __domain_finalise_shutdown(d);
  102.23 @@ -154,7 +150,7 @@ struct vcpu *alloc_vcpu(
  102.24      if ( !is_idle_domain(d) )
  102.25      {
  102.26          set_bit(_VPF_down, &v->pause_flags);
  102.27 -        v->vcpu_info = shared_info_addr(d, vcpu_info[vcpu_id]);
  102.28 +        v->vcpu_info = (void *)&shared_info(d, vcpu_info[vcpu_id]);
  102.29      }
  102.30  
  102.31      if ( sched_init_vcpu(v, cpu_id) != 0 )
  102.32 @@ -426,7 +422,7 @@ void domain_shutdown(struct domain *d, u
  102.33      {
  102.34          if ( v->defer_shutdown )
  102.35              continue;
  102.36 -        atomic_inc(&v->pause_count);
  102.37 +        vcpu_pause_nosync(v);
  102.38          v->paused_for_shutdown = 1;
  102.39      }
  102.40  
   103.1 --- a/xen/common/event_channel.c	Fri Mar 14 15:07:45 2008 -0600
   103.2 +++ b/xen/common/event_channel.c	Thu Mar 20 12:35:40 2008 -0600
   103.3 @@ -539,7 +539,6 @@ out:
   103.4  void evtchn_set_pending(struct vcpu *v, int port)
   103.5  {
   103.6      struct domain *d = v->domain;
   103.7 -    shared_info_t *s = d->shared_info;
   103.8  
   103.9      /*
  103.10       * The following bit operations must happen in strict order.
  103.11 @@ -548,12 +547,12 @@ void evtchn_set_pending(struct vcpu *v, 
  103.12       * others may require explicit memory barriers.
  103.13       */
  103.14  
  103.15 -    if ( test_and_set_bit(port, __shared_info_addr(d, s, evtchn_pending)) )
  103.16 +    if ( test_and_set_bit(port, &shared_info(d, evtchn_pending)) )
  103.17          return;
  103.18  
  103.19 -    if ( !test_bit        (port, __shared_info_addr(d, s, evtchn_mask)) &&
  103.20 +    if ( !test_bit        (port, &shared_info(d, evtchn_mask)) &&
  103.21           !test_and_set_bit(port / BITS_PER_GUEST_LONG(d),
  103.22 -                           vcpu_info_addr(v, evtchn_pending_sel)) )
  103.23 +                           &vcpu_info(v, evtchn_pending_sel)) )
  103.24      {
  103.25          vcpu_mark_events_pending(v);
  103.26      }
  103.27 @@ -750,7 +749,6 @@ long evtchn_bind_vcpu(unsigned int port,
  103.28  static long evtchn_unmask(evtchn_unmask_t *unmask)
  103.29  {
  103.30      struct domain *d = current->domain;
  103.31 -    shared_info_t *s = d->shared_info;
  103.32      int            port = unmask->port;
  103.33      struct vcpu   *v;
  103.34  
  103.35 @@ -768,10 +766,10 @@ static long evtchn_unmask(evtchn_unmask_
  103.36       * These operations must happen in strict order. Based on
  103.37       * include/xen/event.h:evtchn_set_pending(). 
  103.38       */
  103.39 -    if ( test_and_clear_bit(port, __shared_info_addr(d, s, evtchn_mask)) &&
  103.40 -         test_bit          (port, __shared_info_addr(d, s, evtchn_pending)) &&
  103.41 +    if ( test_and_clear_bit(port, &shared_info(d, evtchn_mask)) &&
  103.42 +         test_bit          (port, &shared_info(d, evtchn_pending)) &&
  103.43           !test_and_set_bit (port / BITS_PER_GUEST_LONG(d),
  103.44 -                            vcpu_info_addr(v, evtchn_pending_sel)) )
  103.45 +                            &vcpu_info(v, evtchn_pending_sel)) )
  103.46      {
  103.47          vcpu_mark_events_pending(v);
  103.48      }
   104.1 --- a/xen/common/keyhandler.c	Fri Mar 14 15:07:45 2008 -0600
   104.2 +++ b/xen/common/keyhandler.c	Thu Mar 20 12:35:40 2008 -0600
   104.3 @@ -201,12 +201,12 @@ static void dump_domains(unsigned char k
   104.4              printk("    Notifying guest (virq %d, port %d, stat %d/%d/%d)\n",
   104.5                     VIRQ_DEBUG, v->virq_to_evtchn[VIRQ_DEBUG],
   104.6                     test_bit(v->virq_to_evtchn[VIRQ_DEBUG], 
   104.7 -                            shared_info_addr(d, evtchn_pending)),
   104.8 +                            &shared_info(d, evtchn_pending)),
   104.9                     test_bit(v->virq_to_evtchn[VIRQ_DEBUG], 
  104.10 -                            shared_info_addr(d, evtchn_mask)),
  104.11 +                            &shared_info(d, evtchn_mask)),
  104.12                     test_bit(v->virq_to_evtchn[VIRQ_DEBUG] /
  104.13                              BITS_PER_GUEST_LONG(d),
  104.14 -                            vcpu_info_addr(v, evtchn_pending_sel)));
  104.15 +                            &vcpu_info(v, evtchn_pending_sel)));
  104.16              send_guest_vcpu_virq(v, VIRQ_DEBUG);
  104.17          }
  104.18      }
   105.1 --- a/xen/common/schedule.c	Fri Mar 14 15:07:45 2008 -0600
   105.2 +++ b/xen/common/schedule.c	Thu Mar 20 12:35:40 2008 -0600
   105.3 @@ -365,7 +365,7 @@ static long do_poll(struct sched_poll *s
   105.4              goto out;
   105.5  
   105.6          rc = 0;
   105.7 -        if ( test_bit(port, shared_info_addr(d, evtchn_pending)) )
   105.8 +        if ( test_bit(port, &shared_info(d, evtchn_pending)) )
   105.9              goto out;
  105.10      }
  105.11  
   106.1 --- a/xen/drivers/acpi/Makefile	Fri Mar 14 15:07:45 2008 -0600
   106.2 +++ b/xen/drivers/acpi/Makefile	Thu Mar 20 12:35:40 2008 -0600
   106.3 @@ -1,2 +1,5 @@
   106.4  obj-y += tables.o
   106.5  obj-y += numa.o
   106.6 +obj-y += osl.o
   106.7 +
   106.8 +obj-$(x86) += hwregs.o
   107.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   107.2 +++ b/xen/drivers/acpi/hwregs.c	Thu Mar 20 12:35:40 2008 -0600
   107.3 @@ -0,0 +1,385 @@
   107.4 +
   107.5 +/*******************************************************************************
   107.6 + *
   107.7 + * Module Name: hwregs - Read/write access functions for the various ACPI
   107.8 + *                       control and status registers.
   107.9 + *
  107.10 + ******************************************************************************/
  107.11 +
  107.12 +/*
  107.13 + * Copyright (C) 2000 - 2006, R. Byron Moore
  107.14 + * All rights reserved.
  107.15 + *
  107.16 + * Redistribution and use in source and binary forms, with or without
  107.17 + * modification, are permitted provided that the following conditions
  107.18 + * are met:
  107.19 + * 1. Redistributions of source code must retain the above copyright
  107.20 + *    notice, this list of conditions, and the following disclaimer,
  107.21 + *    without modification.
  107.22 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  107.23 + *    substantially similar to the "NO WARRANTY" disclaimer below
  107.24 + *    ("Disclaimer") and any redistribution must be conditioned upon
  107.25 + *    including a substantially similar Disclaimer requirement for further
  107.26 + *    binary redistribution.
  107.27 + * 3. Neither the names of the above-listed copyright holders nor the names
  107.28 + *    of any contributors may be used to endorse or promote products derived
  107.29 + *    from this software without specific prior written permission.
  107.30 + *
  107.31 + * Alternatively, this software may be distributed under the terms of the
  107.32 + * GNU General Public License ("GPL") version 2 as published by the Free
  107.33 + * Software Foundation.
  107.34 + *
  107.35 + * NO WARRANTY
  107.36 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  107.37 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  107.38 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  107.39 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  107.40 + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  107.41 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  107.42 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  107.43 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  107.44 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  107.45 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  107.46 + * POSSIBILITY OF SUCH DAMAGES.
  107.47 + */
  107.48 +
  107.49 +#include <asm/io.h>
  107.50 +#include <xen/config.h>
  107.51 +#include <xen/init.h>
  107.52 +#include <xen/types.h>
  107.53 +#include <xen/errno.h>
  107.54 +#include <acpi/acpi.h>
  107.55 +
  107.56 +#define _COMPONENT          ACPI_HARDWARE
  107.57 +ACPI_MODULE_NAME("hwregs")
  107.58 +
  107.59 +/******************************************************************************
  107.60 + *
  107.61 + * FUNCTION:    acpi_hw_register_read
  107.62 + *
  107.63 + * PARAMETERS:  register_id         - ACPI Register ID
  107.64 + *              return_value        - Where the register value is returned
  107.65 + *
  107.66 + * RETURN:      Status and the value read.
  107.67 + *
  107.68 + * DESCRIPTION: Read from the specified ACPI register
  107.69 + *
  107.70 + ******************************************************************************/
  107.71 +acpi_status
  107.72 +acpi_hw_register_read(u32 register_id, u32 * return_value)
  107.73 +{
  107.74 +	u32 value1 = 0;
  107.75 +	u32 value2 = 0;
  107.76 +	acpi_status status;
  107.77 +
  107.78 +	ACPI_FUNCTION_TRACE(hw_register_read);
  107.79 +
  107.80 +	switch (register_id) {
  107.81 +	case ACPI_REGISTER_PM1_STATUS:	/* 16-bit access */
  107.82 +
  107.83 +		status =
  107.84 +		    acpi_hw_low_level_read(16, &value1,
  107.85 +					   &acpi_sinfo.pm1a_evt_blk);
  107.86 +		if (ACPI_FAILURE(status)) {
  107.87 +			goto exit;
  107.88 +		}
  107.89 +
  107.90 +		/* PM1B is optional */
  107.91 +
  107.92 +		status =
  107.93 +		    acpi_hw_low_level_read(16, &value2,
  107.94 +					   &acpi_sinfo.pm1b_evt_blk);
  107.95 +		value1 |= value2;
  107.96 +		break;
  107.97 +
  107.98 +
  107.99 +	case ACPI_REGISTER_PM1_CONTROL:	/* 16-bit access */
 107.100 +
 107.101 +		status =
 107.102 +		    acpi_hw_low_level_read(16, &value1,
 107.103 +					   &acpi_sinfo.pm1a_cnt_blk);
 107.104 +		if (ACPI_FAILURE(status)) {
 107.105 +			goto exit;
 107.106 +		}
 107.107 +
 107.108 +		status =
 107.109 +		    acpi_hw_low_level_read(16, &value2,
 107.110 +					   &acpi_sinfo.pm1b_cnt_blk);
 107.111 +		value1 |= value2;
 107.112 +		break;
 107.113 +
 107.114 +
 107.115 +	default:
 107.116 +		status = AE_BAD_PARAMETER;
 107.117 +		break;
 107.118 +	}
 107.119 +
 107.120 +      exit:
 107.121 +
 107.122 +	if (ACPI_SUCCESS(status)) {
 107.123 +		*return_value = value1;
 107.124 +	}
 107.125 +
 107.126 +	return_ACPI_STATUS(status);
 107.127 +}
 107.128 +
 107.129 +/******************************************************************************
 107.130 + *
 107.131 + * FUNCTION:    acpi_hw_register_write
 107.132 + *
 107.133 + * PARAMETERS:  register_id         - ACPI Register ID 
 107.134 + *              Value               - The value to write
 107.135 + *
 107.136 + * RETURN:      Status
 107.137 + *
 107.138 + * DESCRIPTION: Write to the specified ACPI register
 107.139 + *
 107.140 + * NOTE: In accordance with the ACPI specification, this function automatically
 107.141 + * preserves the value of the following bits, meaning that these bits cannot be
 107.142 + * changed via this interface:
 107.143 + *
 107.144 + * PM1_CONTROL[0] = SCI_EN
 107.145 + * PM1_CONTROL[9]
 107.146 + * PM1_STATUS[11]
 107.147 + *
 107.148 + * ACPI References:
 107.149 + * 1) Hardware Ignored Bits: When software writes to a register with ignored
 107.150 + *      bit fields, it preserves the ignored bit fields
 107.151 + * 2) SCI_EN: OSPM always preserves this bit position
 107.152 + *
 107.153 + ******************************************************************************/
 107.154 +
 107.155 +acpi_status acpi_hw_register_write(u32 register_id, u32 value)
 107.156 +{
 107.157 +	acpi_status status;
 107.158 +	u32 read_value;
 107.159 +
 107.160 +	ACPI_FUNCTION_TRACE(hw_register_write);
 107.161 +
 107.162 +	switch (register_id) {   //By now we just need handle PM1 status/PM1 control
 107.163 +	case ACPI_REGISTER_PM1_STATUS:	/* 16-bit access */
 107.164 +
 107.165 +		/* Perform a read first to preserve certain bits (per ACPI spec) */
 107.166 +
 107.167 +		status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS,
 107.168 +					       &read_value);
 107.169 +		if (ACPI_FAILURE(status)) {
 107.170 +			goto exit;
 107.171 +		}
 107.172 +
 107.173 +		/* Insert the bits to be preserved */
 107.174 +
 107.175 +		ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
 107.176 +				 read_value);
 107.177 +
 107.178 +		/* Now we can write the data */
 107.179 +
 107.180 +		status =
 107.181 +		    acpi_hw_low_level_write(16, value,
 107.182 +					    &acpi_sinfo.pm1a_evt_blk);
 107.183 +		if (ACPI_FAILURE(status)) {
 107.184 +			goto exit;
 107.185 +		}
 107.186 +
 107.187 +		/* PM1B is optional */
 107.188 +
 107.189 +		status =
 107.190 +		    acpi_hw_low_level_write(16, value,
 107.191 +					    &acpi_sinfo.pm1b_evt_blk);
 107.192 +		break;
 107.193 +
 107.194 +
 107.195 +	case ACPI_REGISTER_PM1_CONTROL:	/* 16-bit access */
 107.196 +
 107.197 +		/*
 107.198 +		 * Perform a read first to preserve certain bits (per ACPI spec)
 107.199 +		 *
 107.200 +		 * Note: This includes SCI_EN, we never want to change this bit
 107.201 +		 */
 107.202 +		status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
 107.203 +					       &read_value);
 107.204 +		if (ACPI_FAILURE(status)) {
 107.205 +			goto exit;
 107.206 +		}
 107.207 +
 107.208 +		/* Insert the bits to be preserved */
 107.209 +
 107.210 +		ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
 107.211 +				 read_value);
 107.212 +
 107.213 +		/* Now we can write the data */
 107.214 +
 107.215 +		status =
 107.216 +		    acpi_hw_low_level_write(16, value,
 107.217 +					    &acpi_sinfo.pm1a_cnt_blk);
 107.218 +		if (ACPI_FAILURE(status)) {
 107.219 +			goto exit;
 107.220 +		}
 107.221 +
 107.222 +		status =
 107.223 +		    acpi_hw_low_level_write(16, value,
 107.224 +					    &acpi_sinfo.pm1b_cnt_blk);
 107.225 +		break;
 107.226 +
 107.227 +	case ACPI_REGISTER_PM1A_CONTROL:	/* 16-bit access */
 107.228 +
 107.229 +		status =
 107.230 +		    acpi_hw_low_level_write(16, value,
 107.231 +					    &acpi_sinfo.pm1a_cnt_blk);
 107.232 +		break;
 107.233 +
 107.234 +	case ACPI_REGISTER_PM1B_CONTROL:	/* 16-bit access */
 107.235 +
 107.236 +		status =
 107.237 +		    acpi_hw_low_level_write(16, value,
 107.238 +					    &acpi_sinfo.pm1b_cnt_blk);
 107.239 +		break;
 107.240 +
 107.241 +
 107.242 +	default:
 107.243 +		status = AE_BAD_PARAMETER;
 107.244 +		break;
 107.245 +	}
 107.246 +
 107.247 +      exit:
 107.248 +
 107.249 +	return_ACPI_STATUS(status);
 107.250 +}
 107.251 +
 107.252 +/******************************************************************************
 107.253 + *
 107.254 + * FUNCTION:    acpi_hw_low_level_read
 107.255 + *
 107.256 + * PARAMETERS:  Width               - 8, 16, or 32
 107.257 + *              Value               - Where the value is returned
 107.258 + *              Reg                 - GAS register structure
 107.259 + *
 107.260 + * RETURN:      Status
 107.261 + *
 107.262 + * DESCRIPTION: Read from either memory or IO space.
 107.263 + *
 107.264 + ******************************************************************************/
 107.265 +
 107.266 +acpi_status
 107.267 +acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
 107.268 +{
 107.269 +	u64 address;
 107.270 +	acpi_status status;
 107.271 +
 107.272 +	ACPI_FUNCTION_NAME(hw_low_level_read);
 107.273 +
 107.274 +	/*
 107.275 +	 * Must have a valid pointer to a GAS structure, and
 107.276 +	 * a non-zero address within. However, don't return an error
 107.277 +	 * because the PM1A/B code must not fail if B isn't present.
 107.278 +	 */
 107.279 +	if (!reg) {
 107.280 +		return (AE_OK);
 107.281 +	}
 107.282 +
 107.283 +	/* Get a local copy of the address. Handles possible alignment issues */
 107.284 +
 107.285 +	ACPI_MOVE_64_TO_64(&address, &reg->address);
 107.286 +	if (!address) {
 107.287 +		return (AE_OK);
 107.288 +	}
 107.289 +	*value = 0;
 107.290 +
 107.291 +	/*
 107.292 +	 * Two address spaces supported: Memory or IO.
 107.293 +	 * PCI_Config is not supported here because the GAS struct is insufficient
 107.294 +	 */
 107.295 +	switch (reg->space_id) {
 107.296 +	case ACPI_ADR_SPACE_SYSTEM_MEMORY:
 107.297 +
 107.298 +		status = acpi_os_read_memory((acpi_physical_address) address,
 107.299 +					     value, width);
 107.300 +		break;
 107.301 +
 107.302 +	case ACPI_ADR_SPACE_SYSTEM_IO:
 107.303 +
 107.304 +		status = acpi_os_read_port((acpi_io_address) address,
 107.305 +					   value, width);
 107.306 +		break;
 107.307 +
 107.308 +	default:
 107.309 +
 107.310 +		return (AE_BAD_PARAMETER);
 107.311 +	}
 107.312 +
 107.313 +	ACPI_DEBUG_PRINT((ACPI_DB_IO,
 107.314 +			  "Read:  %8.8X width %2d from %8.8X%8.8X (%s)\n",
 107.315 +			  *value, width,
 107.316 +			  ACPI_FORMAT_UINT64(address),
 107.317 +			  acpi_ut_get_region_name(reg->address_space_id)));
 107.318 +
 107.319 +	return (status);
 107.320 +}
 107.321 +
 107.322 +/******************************************************************************
 107.323 + *
 107.324 + * FUNCTION:    acpi_hw_low_level_write
 107.325 + *
 107.326 + * PARAMETERS:  Width               - 8, 16, or 32
 107.327 + *              Value               - To be written
 107.328 + *              Reg                 - GAS register structure
 107.329 + *
 107.330 + * RETURN:      Status
 107.331 + *
 107.332 + * DESCRIPTION: Write to either memory or IO space.
 107.333 + *
 107.334 + ******************************************************************************/
 107.335 +
 107.336 +acpi_status
 107.337 +acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
 107.338 +{
 107.339 +	u64 address;
 107.340 +	acpi_status status;
 107.341 +
 107.342 +	ACPI_FUNCTION_NAME(hw_low_level_write);
 107.343 +
 107.344 +	/*
 107.345 +	 * Must have a valid pointer to a GAS structure, and
 107.346 +	 * a non-zero address within. However, don't return an error
 107.347 +	 * because the PM1A/B code must not fail if B isn't present.
 107.348 +	 */
 107.349 +	if (!reg) {
 107.350 +		return (AE_OK);
 107.351 +	}
 107.352 +
 107.353 +	/* Get a local copy of the address. Handles possible alignment issues */
 107.354 +
 107.355 +	ACPI_MOVE_64_TO_64(&address, &reg->address);
 107.356 +	if (!address) {
 107.357 +		return (AE_OK);
 107.358 +	}
 107.359 +
 107.360 +	/*
 107.361 +	 * Two address spaces supported: Memory or IO.
 107.362 +	 * PCI_Config is not supported here because the GAS struct is insufficient
 107.363 +	 */
 107.364 +	switch (reg->space_id) {
 107.365 +	case ACPI_ADR_SPACE_SYSTEM_MEMORY:
 107.366 +
 107.367 +		status = acpi_os_write_memory((acpi_physical_address) address,
 107.368 +					      value, width);
 107.369 +		break;
 107.370 +
 107.371 +	case ACPI_ADR_SPACE_SYSTEM_IO:
 107.372 +
 107.373 +		status = acpi_os_write_port((acpi_io_address) address,
 107.374 +					    value, width);
 107.375 +		break;
 107.376 +
 107.377 +	default:
 107.378 +		return (AE_BAD_PARAMETER);
 107.379 +	}
 107.380 +
 107.381 +	ACPI_DEBUG_PRINT((ACPI_DB_IO,
 107.382 +			  "Wrote: %8.8X width %2d   to %8.8X%8.8X (%s)\n",
 107.383 +			  value, width,
 107.384 +			  ACPI_FORMAT_UINT64(address),
 107.385 +			  acpi_ut_get_region_name(reg->address_space_id)));
 107.386 +
 107.387 +	return (status);
 107.388 +}
   108.1 --- a/xen/drivers/acpi/numa.c	Fri Mar 14 15:07:45 2008 -0600
   108.2 +++ b/xen/drivers/acpi/numa.c	Thu Mar 20 12:35:40 2008 -0600
   108.3 @@ -104,7 +104,7 @@ static int __init acpi_parse_slit(unsign
   108.4  	slit = (struct acpi_table_slit *)__acpi_map_table(phys_addr, size);
   108.5  
   108.6  	/* downcast just for %llu vs %lu for i386/ia64  */
   108.7 -	localities = (u32) slit->localities;
   108.8 +	localities = (u32) slit->locality_count;
   108.9  
  108.10  	acpi_numa_slit_init(slit);
  108.11  
   109.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   109.2 +++ b/xen/drivers/acpi/osl.c	Thu Mar 20 12:35:40 2008 -0600
   109.3 @@ -0,0 +1,183 @@
   109.4 +/*
   109.5 + *  acpi_osl.c - OS-dependent functions ($Revision: 83 $)
   109.6 + *
   109.7 + *  Copyright (C) 2000       Andrew Henroid
   109.8 + *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
   109.9 + *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  109.10 + *
  109.11 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  109.12 + *
  109.13 + *  This program is free software; you can redistribute it and/or modify
  109.14 + *  it under the terms of the GNU General Public License as published by
  109.15 + *  the Free Software Foundation; either version 2 of the License, or
  109.16 + *  (at your option) any later version.
  109.17 + *
  109.18 + *  This program is distributed in the hope that it will be useful,
  109.19 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  109.20 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  109.21 + *  GNU General Public License for more details.
  109.22 + *
  109.23 + *  You should have received a copy of the GNU General Public License
  109.24 + *  along with this program; if not, write to the Free Software
  109.25 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  109.26 + *
  109.27 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  109.28 + *
  109.29 + */
  109.30 +#include <asm/io.h>
  109.31 +#include <xen/config.h>
  109.32 +#include <xen/init.h>
  109.33 +#include <xen/types.h>
  109.34 +#include <xen/errno.h>
  109.35 +#include <xen/acpi.h>
  109.36 +#include <xen/numa.h>
  109.37 +#include <acpi/acpi_bus.h>
  109.38 +#include <acpi/acmacros.h>
  109.39 +#include <acpi/acpiosxf.h>
  109.40 +#include <acpi/platform/aclinux.h>
  109.41 +#include <xen/spinlock.h>
  109.42 +#include <xen/domain_page.h>
  109.43 +
  109.44 +#define _COMPONENT		ACPI_OS_SERVICES
  109.45 +ACPI_MODULE_NAME("osl")
  109.46 +#define PREFIX		"ACPI: "
  109.47 +struct acpi_os_dpc {
  109.48 +	acpi_osd_exec_callback function;
  109.49 +	void *context;
  109.50 +};
  109.51 +
  109.52 +#ifdef CONFIG_ACPI_CUSTOM_DSDT
  109.53 +#include CONFIG_ACPI_CUSTOM_DSDT_FILE
  109.54 +#endif
  109.55 +
  109.56 +#ifdef ENABLE_DEBUGGER
  109.57 +#include <linux/kdb.h>
  109.58 +
  109.59 +/* stuff for debugger support */
  109.60 +int acpi_in_debugger;
  109.61 +EXPORT_SYMBOL(acpi_in_debugger);
  109.62 +
  109.63 +extern char line_buf[80];
  109.64 +#endif				/*ENABLE_DEBUGGER */
  109.65 +
  109.66 +int acpi_specific_hotkey_enabled = TRUE;
  109.67 +EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
  109.68 +
  109.69 +
  109.70 +acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
  109.71 +{
  109.72 +	u32 dummy;
  109.73 +
  109.74 +	if (!value)
  109.75 +		value = &dummy;
  109.76 +
  109.77 +	*value = 0;
  109.78 +	if (width <= 8) {
  109.79 +		*(u8 *) value = inb(port);
  109.80 +	} else if (width <= 16) {
  109.81 +		*(u16 *) value = inw(port);
  109.82 +	} else if (width <= 32) {
  109.83 +		*(u32 *) value = inl(port);
  109.84 +	} else {
  109.85 +		BUG();
  109.86 +	}
  109.87 +
  109.88 +	return AE_OK;
  109.89 +}
  109.90 +
  109.91 +EXPORT_SYMBOL(acpi_os_read_port);
  109.92 +
  109.93 +acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
  109.94 +{
  109.95 +	if (width <= 8) {
  109.96 +		outb(value, port);
  109.97 +	} else if (width <= 16) {
  109.98 +		outw(value, port);
  109.99 +	} else if (width <= 32) {
 109.100 +		outl(value, port);
 109.101 +	} else {
 109.102 +		BUG();
 109.103 +	}
 109.104 +
 109.105 +	return AE_OK;
 109.106 +}
 109.107 +
 109.108 +EXPORT_SYMBOL(acpi_os_write_port);
 109.109 +
 109.110 +acpi_status
 109.111 +acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
 109.112 +{
 109.113 +	u32 dummy;
 109.114 +	void __iomem *virt_addr;
 109.115 +
 109.116 +	virt_addr = map_domain_page(phys_addr>>PAGE_SHIFT);
 109.117 +	if (!value)
 109.118 +		value = &dummy;
 109.119 +
 109.120 +	switch (width) {
 109.121 +	case 8:
 109.122 +		*(u8 *) value = readb(virt_addr);
 109.123 +		break;
 109.124 +	case 16:
 109.125 +		*(u16 *) value = readw(virt_addr);
 109.126 +		break;
 109.127 +	case 32:
 109.128 +		*(u32 *) value = readl(virt_addr);
 109.129 +		break;
 109.130 +	default:
 109.131 +		BUG();
 109.132 +	}
 109.133 +
 109.134 +	unmap_domain_page(virt_addr);
 109.135 +
 109.136 +	return AE_OK;
 109.137 +}
 109.138 +
 109.139 +acpi_status
 109.140 +acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
 109.141 +{
 109.142 +	void __iomem *virt_addr;
 109.143 +
 109.144 +	virt_addr = map_domain_page(phys_addr>>PAGE_SHIFT);
 109.145 +
 109.146 +	switch (width) {
 109.147 +	case 8:
 109.148 +		writeb(value, virt_addr);
 109.149 +		break;
 109.150 +	case 16:
 109.151 +		writew(value, virt_addr);
 109.152 +		break;
 109.153 +	case 32:
 109.154 +		writel(value, virt_addr);
 109.155 +		break;
 109.156 +	default:
 109.157 +		BUG();
 109.158 +	}
 109.159 +
 109.160 +	unmap_domain_page(virt_addr);
 109.161 +
 109.162 +	return AE_OK;
 109.163 +}
 109.164 +
 109.165 +/*
 109.166 + * Acquire a spinlock.
 109.167 + *
 109.168 + * handle is a pointer to the spinlock_t.
 109.169 + */
 109.170 +
 109.171 +acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
 109.172 +{
 109.173 +	acpi_cpu_flags flags;
 109.174 +	spin_lock_irqsave(lockp, flags);
 109.175 +	return flags;
 109.176 +}
 109.177 +
 109.178 +/*
 109.179 + * Release a spinlock. See above.
 109.180 + */
 109.181 +
 109.182 +void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
 109.183 +{
 109.184 +	spin_unlock_irqrestore(lockp, flags);
 109.185 +}
 109.186 +
   110.1 --- a/xen/drivers/acpi/tables.c	Fri Mar 14 15:07:45 2008 -0600
   110.2 +++ b/xen/drivers/acpi/tables.c	Thu Mar 20 12:35:40 2008 -0600
   110.3 @@ -295,15 +295,15 @@ acpi_get_table_header_early(enum acpi_ta
   110.4  
   110.5  	/* Map the DSDT header via the pointer in the FADT */
   110.6  	if (id == ACPI_DSDT) {
   110.7 -		struct fadt_descriptor_rev2 *fadt =
   110.8 -		    (struct fadt_descriptor_rev2 *)*header;
   110.9 +		struct acpi_table_fadt *fadt =
  110.10 +			(struct acpi_table_fadt *)*header;
  110.11  
  110.12 -		if (fadt->revision == 3 && fadt->Xdsdt) {
  110.13 +		if (fadt->header.revision == 3 && fadt->Xdsdt) {
  110.14  			*header = (void *)__acpi_map_table(fadt->Xdsdt,
  110.15  							   sizeof(struct
  110.16  								  acpi_table_header));
  110.17 -		} else if (fadt->V1_dsdt) {
  110.18 -			*header = (void *)__acpi_map_table(fadt->V1_dsdt,
  110.19 +		} else if (fadt->dsdt) {
  110.20 +			*header = (void *)__acpi_map_table(fadt->dsdt,
  110.21  							   sizeof(struct
  110.22  								  acpi_table_header));
  110.23  		} else
  110.24 @@ -424,12 +424,11 @@ static int __init acpi_table_get_sdt(str
  110.25  
  110.26  	/* First check XSDT (but only on ACPI 2.0-compatible systems) */
  110.27  
  110.28 -	if ((rsdp->revision >= 2) &&
  110.29 -	    (((struct acpi20_table_rsdp *)rsdp)->xsdt_address)) {
  110.30 +	if ((rsdp->revision >= 2) && rsdp->xsdt_physical_address) {
  110.31  
  110.32  		struct acpi_table_xsdt *mapped_xsdt = NULL;
  110.33  
  110.34 -		sdt_pa = ((struct acpi20_table_rsdp *)rsdp)->xsdt_address;
  110.35 +		sdt_pa = rsdp->xsdt_physical_address;
  110.36  
  110.37  		/* map in just the header */
  110.38  		header = (struct acpi_table_header *)
  110.39 @@ -471,16 +470,16 @@ static int __init acpi_table_get_sdt(str
  110.40  		}
  110.41  
  110.42  		for (i = 0; i < sdt_count; i++)
  110.43 -			sdt_entry[i].pa = (unsigned long)mapped_xsdt->entry[i];
  110.44 +			sdt_entry[i].pa = (unsigned long)mapped_xsdt->table_offset_entry[i];
  110.45  	}
  110.46  
  110.47  	/* Then check RSDT */
  110.48  
  110.49 -	else if (rsdp->rsdt_address) {
  110.50 +	else if (rsdp->rsdt_physical_address) {
  110.51  
  110.52  		struct acpi_table_rsdt *mapped_rsdt = NULL;
  110.53  
  110.54 -		sdt_pa = rsdp->rsdt_address;
  110.55 +		sdt_pa = rsdp->rsdt_physical_address;
  110.56  
  110.57  		/* map in just the header */
  110.58  		header = (struct acpi_table_header *)
  110.59 @@ -521,7 +520,7 @@ static int __init acpi_table_get_sdt(str
  110.60  		}
  110.61  
  110.62  		for (i = 0; i < sdt_count; i++)
  110.63 -			sdt_entry[i].pa = (unsigned long)mapped_rsdt->entry[i];
  110.64 +			sdt_entry[i].pa = (unsigned long)mapped_rsdt->table_offset_entry[i];
  110.65  	}
  110.66  
  110.67  	else {
  110.68 @@ -613,13 +612,10 @@ int __init acpi_table_init(void)
  110.69  
  110.70  	if (rsdp->revision < 2)
  110.71  		result =
  110.72 -		    acpi_table_compute_checksum(rsdp,
  110.73 -						sizeof(struct acpi_table_rsdp));
  110.74 +		    acpi_table_compute_checksum(rsdp, 20);
  110.75  	else
  110.76  		result =
  110.77 -		    acpi_table_compute_checksum(rsdp,
  110.78 -						((struct acpi20_table_rsdp *)
  110.79 -						 rsdp)->length);
  110.80 +		    acpi_table_compute_checksum(rsdp, rsdp->length);
  110.81  
  110.82  	if (result) {
  110.83  		printk(KERN_WARNING "  >>> ERROR: Invalid checksum\n");
  110.84 @@ -663,12 +659,11 @@ acpi_table_disable(enum acpi_table_id ta
  110.85  
  110.86  	/* First check XSDT (but only on ACPI 2.0-compatible systems) */
  110.87  
  110.88 -	if ((rsdp->revision >= 2) &&
  110.89 -	    (((struct acpi20_table_rsdp *)rsdp)->xsdt_address)) {
  110.90 +	if ((rsdp->revision >= 2) && rsdp->xsdt_physical_address) {
  110.91  
  110.92  		struct acpi_table_xsdt *mapped_xsdt = NULL;
  110.93  
  110.94 -		sdt_pa = ((struct acpi20_table_rsdp *)rsdp)->xsdt_address;
  110.95 +		sdt_pa = rsdp->xsdt_physical_address;
  110.96  
  110.97  		/* map in just the header */
  110.98  		header = (struct acpi_table_header *)
  110.99 @@ -702,7 +697,7 @@ acpi_table_disable(enum acpi_table_id ta
 110.100  
 110.101  		if (id < sdt_count) {
 110.102  			header = (struct acpi_table_header *)
 110.103 -			   __acpi_map_table(mapped_xsdt->entry[id], sizeof(struct acpi_table_header));
 110.104 +			   __acpi_map_table(mapped_xsdt->table_offset_entry[id], sizeof(struct acpi_table_header));
 110.105  		} else {
 110.106  			printk(KERN_WARNING PREFIX
 110.107  			       "Unable to disable entry %d\n",
 110.108 @@ -713,11 +708,11 @@ acpi_table_disable(enum acpi_table_id ta
 110.109  
 110.110  	/* Then check RSDT */
 110.111  
 110.112 -	else if (rsdp->rsdt_address) {
 110.113 +	else if (rsdp->rsdt_physical_address) {
 110.114  
 110.115  		struct acpi_table_rsdt *mapped_rsdt = NULL;
 110.116  
 110.117 -		sdt_pa = rsdp->rsdt_address;
 110.118 +		sdt_pa = rsdp->rsdt_physical_address;
 110.119  
 110.120  		/* map in just the header */
 110.121  		header = (struct acpi_table_header *)
 110.122 @@ -749,7 +744,7 @@ acpi_table_disable(enum acpi_table_id ta
 110.123  		}
 110.124  		if (id < sdt_count) {
 110.125  			header = (struct acpi_table_header *)
 110.126 -			   __acpi_map_table(mapped_rsdt->entry[id], sizeof(struct acpi_table_header));
 110.127 +			   __acpi_map_table(mapped_rsdt->table_offset_entry[id], sizeof(struct acpi_table_header));
 110.128  		} else {
 110.129  			printk(KERN_WARNING PREFIX
 110.130  			       "Unable to disable entry %d\n",
   111.1 --- a/xen/drivers/passthrough/Makefile	Fri Mar 14 15:07:45 2008 -0600
   111.2 +++ b/xen/drivers/passthrough/Makefile	Thu Mar 20 12:35:40 2008 -0600
   111.3 @@ -1,2 +1,5 @@
   111.4  subdir-$(x86) += vtd
   111.5  subdir-$(x86) += amd
   111.6 +
   111.7 +obj-y += iommu.o
   111.8 +obj-y += io.o
   112.1 --- a/xen/drivers/passthrough/amd/iommu_acpi.c	Fri Mar 14 15:07:45 2008 -0600
   112.2 +++ b/xen/drivers/passthrough/amd/iommu_acpi.c	Thu Mar 20 12:35:40 2008 -0600
   112.3 @@ -29,12 +29,12 @@ extern unsigned short ivrs_bdf_entries;
   112.4  extern struct ivrs_mappings *ivrs_mappings;
   112.5  
   112.6  static struct amd_iommu * __init find_iommu_from_bdf_cap(
   112.7 -           u16 bdf, u8 cap_offset)
   112.8 +    u16 bdf, u8 cap_offset)
   112.9  {
  112.10      struct amd_iommu *iommu;
  112.11  
  112.12 -    for_each_amd_iommu( iommu )
  112.13 -        if ( iommu->bdf == bdf && iommu->cap_offset == cap_offset )
  112.14 +    for_each_amd_iommu ( iommu )
  112.15 +        if ( (iommu->bdf == bdf) && (iommu->cap_offset == cap_offset) )
  112.16              return iommu;
  112.17  
  112.18      return NULL;
  112.19 @@ -57,15 +57,17 @@ static void __init reserve_iommu_exclusi
  112.20      iommu->exclusion_limit = limit;
  112.21  }
  112.22  
  112.23 -static void __init reserve_iommu_exclusion_range_all(struct amd_iommu *iommu,
  112.24 -           unsigned long base, unsigned long limit)
  112.25 +static void __init reserve_iommu_exclusion_range_all(
  112.26 +    struct amd_iommu *iommu,
  112.27 +    unsigned long base, unsigned long limit)
  112.28  {
  112.29      reserve_iommu_exclusion_range(iommu, base, limit);
  112.30      iommu->exclusion_allow_all = IOMMU_CONTROL_ENABLED;
  112.31  }
  112.32  
  112.33 -static void __init reserve_unity_map_for_device(u16 bdf, unsigned long base,
  112.34 -           unsigned long length, u8 iw, u8 ir)
  112.35 +static void __init reserve_unity_map_for_device(
  112.36 +    u16 bdf, unsigned long base,
  112.37 +    unsigned long length, u8 iw, u8 ir)
  112.38  {
  112.39      unsigned long old_top, new_top;
  112.40  
  112.41 @@ -80,7 +82,7 @@ static void __init reserve_unity_map_for
  112.42          if ( ivrs_mappings[bdf].addr_range_start < base )
  112.43              base = ivrs_mappings[bdf].addr_range_start;
  112.44          length = new_top - base;
  112.45 -   }
  112.46 +    }
  112.47  
  112.48      /* extend r/w permissioms and keep aggregate */
  112.49      if ( iw )
  112.50 @@ -93,7 +95,7 @@ static void __init reserve_unity_map_for
  112.51  }
  112.52  
  112.53  static int __init register_exclusion_range_for_all_devices(
  112.54 -           unsigned long base, unsigned long limit, u8 iw, u8 ir)
  112.55 +    unsigned long base, unsigned long limit, u8 iw, u8 ir)
  112.56  {
  112.57      unsigned long range_top, iommu_top, length;
  112.58      struct amd_iommu *iommu;
  112.59 @@ -105,7 +107,7 @@ static int __init register_exclusion_ran
  112.60      iommu_top = max_page * PAGE_SIZE;
  112.61      if ( base < iommu_top )
  112.62      {
  112.63 -        if (range_top > iommu_top)
  112.64 +        if ( range_top > iommu_top )
  112.65              range_top = iommu_top;
  112.66          length = range_top - base;
  112.67          /* reserve r/w unity-mapped page entries for devices */
  112.68 @@ -116,7 +118,7 @@ static int __init register_exclusion_ran
  112.69          base = iommu_top;
  112.70      }
  112.71      /* register IOMMU exclusion range settings */
  112.72 -    if (limit >= iommu_top)
  112.73 +    if ( limit >= iommu_top )
  112.74      {
  112.75          for_each_amd_iommu( iommu )
  112.76              reserve_iommu_exclusion_range_all(iommu, base, limit);
  112.77 @@ -125,8 +127,8 @@ static int __init register_exclusion_ran
  112.78      return 0;
  112.79  }
  112.80  
  112.81 -static int __init register_exclusion_range_for_device(u16 bdf,
  112.82 -           unsigned long base, unsigned long limit, u8 iw, u8 ir)
  112.83 +static int __init register_exclusion_range_for_device(
  112.84 +    u16 bdf, unsigned long base, unsigned long limit, u8 iw, u8 ir)
  112.85  {
  112.86      unsigned long range_top, iommu_top, length;
  112.87      struct amd_iommu *iommu;
  112.88 @@ -147,7 +149,7 @@ static int __init register_exclusion_ran
  112.89      iommu_top = max_page * PAGE_SIZE;
  112.90      if ( base < iommu_top )
  112.91      {
  112.92 -        if (range_top > iommu_top)
  112.93 +        if ( range_top > iommu_top )
  112.94              range_top = iommu_top;
  112.95          length = range_top - base;
  112.96          /* reserve unity-mapped page entries for device */
  112.97 @@ -159,8 +161,8 @@ static int __init register_exclusion_ran
  112.98          base = iommu_top;
  112.99      }
 112.100  
 112.101 -   /* register IOMMU exclusion range settings for device */
 112.102 -   if ( limit >= iommu_top  )
 112.103 +    /* register IOMMU exclusion range settings for device */
 112.104 +    if ( limit >= iommu_top  )
 112.105      {
 112.106          reserve_iommu_exclusion_range(iommu, base, limit);
 112.107          ivrs_mappings[bdf].dte_allow_exclusion = IOMMU_CONTROL_ENABLED;
 112.108 @@ -171,8 +173,8 @@ static int __init register_exclusion_ran
 112.109  }
 112.110  
 112.111  static int __init register_exclusion_range_for_iommu_devices(
 112.112 -           struct amd_iommu *iommu,
 112.113 -           unsigned long base, unsigned long limit, u8 iw, u8 ir)
 112.114 +    struct amd_iommu *iommu,
 112.115 +    unsigned long base, unsigned long limit, u8 iw, u8 ir)
 112.116  {
 112.117      unsigned long range_top, iommu_top, length;
 112.118      u16 bus, devfn, bdf, req;
 112.119 @@ -183,7 +185,7 @@ static int __init register_exclusion_ran
 112.120      iommu_top = max_page * PAGE_SIZE;
 112.121      if ( base < iommu_top )
 112.122      {
 112.123 -        if (range_top > iommu_top)
 112.124 +        if ( range_top > iommu_top )
 112.125              range_top = iommu_top;
 112.126          length = range_top - base;
 112.127          /* reserve r/w unity-mapped page entries for devices */
 112.128 @@ -205,19 +207,19 @@ static int __init register_exclusion_ran
 112.129      }
 112.130  
 112.131      /* register IOMMU exclusion range settings */
 112.132 -    if (limit >= iommu_top)
 112.133 +    if ( limit >= iommu_top )
 112.134          reserve_iommu_exclusion_range_all(iommu, base, limit);
 112.135      return 0;
 112.136  }
 112.137  
 112.138  static int __init parse_ivmd_device_select(
 112.139 -           struct acpi_ivmd_block_header *ivmd_block,
 112.140 -           unsigned long base, unsigned long limit, u8 iw, u8 ir)
 112.141 +    struct acpi_ivmd_block_header *ivmd_block,
 112.142 +    unsigned long base, unsigned long limit, u8 iw, u8 ir)
 112.143  {
 112.144      u16 bdf;
 112.145  
 112.146      bdf = ivmd_block->header.dev_id;
 112.147 -    if (bdf >= ivrs_bdf_entries)
 112.148 +    if ( bdf >= ivrs_bdf_entries )
 112.149      {
 112.150          dprintk(XENLOG_ERR, "IVMD Error: Invalid Dev_Id 0x%x\n", bdf);
 112.151          return -ENODEV;
 112.152 @@ -227,44 +229,41 @@ static int __init parse_ivmd_device_sele
 112.153  }
 112.154  
 112.155  static int __init parse_ivmd_device_range(
 112.156 -           struct acpi_ivmd_block_header *ivmd_block,
 112.157 -           unsigned long base, unsigned long limit, u8 iw, u8 ir)
 112.158 +    struct acpi_ivmd_block_header *ivmd_block,
 112.159 +    unsigned long base, unsigned long limit, u8 iw, u8 ir)
 112.160  {
 112.161      u16 first_bdf, last_bdf, bdf;
 112.162      int error;
 112.163  
 112.164      first_bdf = ivmd_block->header.dev_id;
 112.165 -    if (first_bdf >= ivrs_bdf_entries)
 112.166 -    {
 112.167 -       dprintk(XENLOG_ERR, "IVMD Error: "
 112.168 -                    "Invalid Range_First Dev_Id 0x%x\n", first_bdf);
 112.169 -       return -ENODEV;
 112.170 -    }
 112.171 -
 112.172 -    last_bdf = ivmd_block->last_dev_id;
 112.173 -    if (last_bdf >= ivrs_bdf_entries || last_bdf <= first_bdf)
 112.174 +    if ( first_bdf >= ivrs_bdf_entries )
 112.175      {
 112.176          dprintk(XENLOG_ERR, "IVMD Error: "
 112.177 -                    "Invalid Range_Last Dev_Id 0x%x\n", last_bdf);
 112.178 +                "Invalid Range_First Dev_Id 0x%x\n", first_bdf);
 112.179          return -ENODEV;
 112.180      }
 112.181  
 112.182 -      dprintk(XENLOG_ERR, " Dev_Id Range: 0x%x -> 0x%x\n",
 112.183 -                    first_bdf, last_bdf);
 112.184 -
 112.185 -    for ( bdf = first_bdf, error = 0;
 112.186 -       bdf <= last_bdf && !error; ++bdf )
 112.187 +    last_bdf = ivmd_block->last_dev_id;
 112.188 +    if ( (last_bdf >= ivrs_bdf_entries) || (last_bdf <= first_bdf) )
 112.189      {
 112.190 -       error = register_exclusion_range_for_device(
 112.191 -                     bdf, base, limit, iw, ir);
 112.192 +        dprintk(XENLOG_ERR, "IVMD Error: "
 112.193 +                "Invalid Range_Last Dev_Id 0x%x\n", last_bdf);
 112.194 +        return -ENODEV;
 112.195      }
 112.196  
 112.197 -   return error;
 112.198 +    dprintk(XENLOG_ERR, " Dev_Id Range: 0x%x -> 0x%x\n",
 112.199 +            first_bdf, last_bdf);
 112.200 +
 112.201 +    for ( bdf = first_bdf, error = 0; (bdf <= last_bdf) && !error; bdf++ )
 112.202 +        error = register_exclusion_range_for_device(
 112.203 +            bdf, base, limit, iw, ir);
 112.204 +
 112.205 +    return error;
 112.206  }
 112.207  
 112.208  static int __init parse_ivmd_device_iommu(
 112.209 -           struct acpi_ivmd_block_header *ivmd_block,
 112.210 -           unsigned long base, unsigned long limit, u8 iw, u8 ir)
 112.211 +    struct acpi_ivmd_block_header *ivmd_block,
 112.212 +    unsigned long base, unsigned long limit, u8 iw, u8 ir)
 112.213  {
 112.214      struct amd_iommu *iommu;
 112.215  
 112.216 @@ -273,14 +272,14 @@ static int __init parse_ivmd_device_iomm
 112.217                                      ivmd_block->cap_offset);
 112.218      if ( !iommu )
 112.219      {
 112.220 -       dprintk(XENLOG_ERR,
 112.221 -           "IVMD Error: No IOMMU for Dev_Id 0x%x  Cap 0x%x\n",
 112.222 -            ivmd_block->header.dev_id, ivmd_block->cap_offset);
 112.223 -       return -ENODEV;
 112.224 +        dprintk(XENLOG_ERR,
 112.225 +                "IVMD Error: No IOMMU for Dev_Id 0x%x  Cap 0x%x\n",
 112.226 +                ivmd_block->header.dev_id, ivmd_block->cap_offset);
 112.227 +        return -ENODEV;
 112.228      }
 112.229  
 112.230      return register_exclusion_range_for_iommu_devices(
 112.231 -                 iommu, base, limit, iw, ir);
 112.232 +        iommu, base, limit, iw, ir);
 112.233  }
 112.234  
 112.235  static int __init parse_ivmd_block(struct acpi_ivmd_block_header *ivmd_block)
 112.236 @@ -288,11 +287,11 @@ static int __init parse_ivmd_block(struc
 112.237      unsigned long start_addr, mem_length, base, limit;
 112.238      u8 iw, ir;
 112.239  
 112.240 -    if (ivmd_block->header.length <
 112.241 -       sizeof(struct acpi_ivmd_block_header))
 112.242 +    if ( ivmd_block->header.length <
 112.243 +         sizeof(struct acpi_ivmd_block_header) )
 112.244      {
 112.245 -       dprintk(XENLOG_ERR, "IVMD Error: Invalid Block Length!\n");
 112.246 -       return -ENODEV;
 112.247 +        dprintk(XENLOG_ERR, "IVMD Error: Invalid Block Length!\n");
 112.248 +        return -ENODEV;
 112.249      }
 112.250  
 112.251      start_addr = (unsigned long)ivmd_block->start_addr;
 112.252 @@ -301,7 +300,7 @@ static int __init parse_ivmd_block(struc
 112.253      limit = (start_addr + mem_length - 1) & PAGE_MASK;
 112.254  
 112.255      dprintk(XENLOG_INFO, "IVMD Block: Type 0x%x\n",
 112.256 -                  ivmd_block->header.type);
 112.257 +            ivmd_block->header.type);
 112.258      dprintk(XENLOG_INFO, " Start_Addr_Phys 0x%lx\n", start_addr);
 112.259      dprintk(XENLOG_INFO, " Mem_Length 0x%lx\n", mem_length);
 112.260  
 112.261 @@ -322,27 +321,27 @@ static int __init parse_ivmd_block(struc
 112.262      }
 112.263      else
 112.264      {
 112.265 -       dprintk(KERN_ERR, "IVMD Error: Invalid Flag Field!\n");
 112.266 -       return -ENODEV;
 112.267 +        dprintk(KERN_ERR, "IVMD Error: Invalid Flag Field!\n");
 112.268 +        return -ENODEV;
 112.269      }
 112.270  
 112.271      switch( ivmd_block->header.type )
 112.272      {
 112.273      case AMD_IOMMU_ACPI_IVMD_ALL_TYPE:
 112.274          return register_exclusion_range_for_all_devices(
 112.275 -           base, limit, iw, ir);
 112.276 +            base, limit, iw, ir);
 112.277  
 112.278      case AMD_IOMMU_ACPI_IVMD_ONE_TYPE:
 112.279          return parse_ivmd_device_select(ivmd_block,
 112.280 -           base, limit, iw, ir);
 112.281 +                                        base, limit, iw, ir);
 112.282  
 112.283      case AMD_IOMMU_ACPI_IVMD_RANGE_TYPE:
 112.284          return parse_ivmd_device_range(ivmd_block,
 112.285 -            base, limit, iw, ir);
 112.286 +                                       base, limit, iw, ir);
 112.287  
 112.288      case AMD_IOMMU_ACPI_IVMD_IOMMU_TYPE:
 112.289          return parse_ivmd_device_iommu(ivmd_block,
 112.290 -           base, limit, iw, ir);
 112.291 +                                       base, limit, iw, ir);
 112.292  
 112.293      default:
 112.294          dprintk(XENLOG_ERR, "IVMD Error: Invalid Block Type!\n");
 112.295 @@ -350,8 +349,8 @@ static int __init parse_ivmd_block(struc
 112.296      }
 112.297  }
 112.298  
 112.299 -static u16 __init parse_ivhd_device_padding(u16 pad_length,
 112.300 -           u16 header_length, u16 block_length)
 112.301 +static u16 __init parse_ivhd_device_padding(
 112.302 +    u16 pad_length, u16 header_length, u16 block_length)
 112.303  {
 112.304      if ( header_length < (block_length + pad_length) )
 112.305      {
 112.306 @@ -363,7 +362,7 @@ static u16 __init parse_ivhd_device_padd
 112.307  }
 112.308  
 112.309  static u16 __init parse_ivhd_device_select(
 112.310 -           union acpi_ivhd_device *ivhd_device)
 112.311 +    union acpi_ivhd_device *ivhd_device)
 112.312  {
 112.313      u16 bdf;
 112.314  
 112.315 @@ -385,8 +384,8 @@ static u16 __init parse_ivhd_device_sele
 112.316  }
 112.317  
 112.318  static u16 __init parse_ivhd_device_range(
 112.319 -           union acpi_ivhd_device *ivhd_device,
 112.320 -           u16 header_length, u16 block_length)
 112.321 +    union acpi_ivhd_device *ivhd_device,
 112.322 +    u16 header_length, u16 block_length)
 112.323  {
 112.324      u16 dev_length, first_bdf, last_bdf, bdf;
 112.325      u8 sys_mgt;
 112.326 @@ -399,7 +398,8 @@ static u16 __init parse_ivhd_device_rang
 112.327      }
 112.328  
 112.329      if ( ivhd_device->range.trailer.type !=
 112.330 -        AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END) {
 112.331 +         AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END )
 112.332 +    {
 112.333          dprintk(XENLOG_ERR, "IVHD Error: "
 112.334                  "Invalid Range: End_Type 0x%x\n",
 112.335                  ivhd_device->range.trailer.type);
 112.336 @@ -409,35 +409,35 @@ static u16 __init parse_ivhd_device_rang
 112.337      first_bdf = ivhd_device->header.dev_id;
 112.338      if ( first_bdf >= ivrs_bdf_entries )
 112.339      {
 112.340 -       dprintk(XENLOG_ERR, "IVHD Error: "
 112.341 -           "Invalid Range: First Dev_Id 0x%x\n", first_bdf);
 112.342 -       return 0;
 112.343 +        dprintk(XENLOG_ERR, "IVHD Error: "
 112.344 +                "Invalid Range: First Dev_Id 0x%x\n", first_bdf);
 112.345 +        return 0;
 112.346      }
 112.347  
 112.348      last_bdf = ivhd_device->range.trailer.dev_id;
 112.349 -    if ( last_bdf >= ivrs_bdf_entries || last_bdf <= first_bdf )
 112.350 +    if ( (last_bdf >= ivrs_bdf_entries) || (last_bdf <= first_bdf) )
 112.351      {
 112.352 -       dprintk(XENLOG_ERR, "IVHD Error: "
 112.353 -           "Invalid Range: Last Dev_Id 0x%x\n", last_bdf);
 112.354 -       return 0;
 112.355 +        dprintk(XENLOG_ERR, "IVHD Error: "
 112.356 +                "Invalid Range: Last Dev_Id 0x%x\n", last_bdf);
 112.357 +        return 0;
 112.358      }
 112.359  
 112.360      dprintk(XENLOG_INFO, " Dev_Id Range: 0x%x -> 0x%x\n",
 112.361 -        first_bdf, last_bdf);
 112.362 +            first_bdf, last_bdf);
 112.363  
 112.364      /* override flags for range of devices */
 112.365      sys_mgt = get_field_from_byte(ivhd_device->header.flags,
 112.366 -                                 AMD_IOMMU_ACPI_SYS_MGT_MASK,
 112.367 -                                 AMD_IOMMU_ACPI_SYS_MGT_SHIFT);
 112.368 -    for ( bdf = first_bdf; bdf <= last_bdf; ++bdf )
 112.369 +                                  AMD_IOMMU_ACPI_SYS_MGT_MASK,
 112.370 +                                  AMD_IOMMU_ACPI_SYS_MGT_SHIFT);
 112.371 +    for ( bdf = first_bdf; bdf <= last_bdf; bdf++ )
 112.372          ivrs_mappings[bdf].dte_sys_mgt_enable = sys_mgt;
 112.373  
 112.374      return dev_length;
 112.375  }
 112.376  
 112.377  static u16 __init parse_ivhd_device_alias(
 112.378 -           union acpi_ivhd_device *ivhd_device,
 112.379 -           u16 header_length, u16 block_length)
 112.380 +    union acpi_ivhd_device *ivhd_device,
 112.381 +    u16 header_length, u16 block_length)
 112.382  {
 112.383      u16 dev_length, alias_id, bdf;
 112.384  
 112.385 @@ -445,7 +445,7 @@ static u16 __init parse_ivhd_device_alia
 112.386      if ( header_length < (block_length + dev_length) )
 112.387      {
 112.388          dprintk(XENLOG_ERR, "IVHD Error: "
 112.389 -            "Invalid Device_Entry Length!\n");
 112.390 +                "Invalid Device_Entry Length!\n");
 112.391          return 0;
 112.392      }
 112.393  
 112.394 @@ -460,9 +460,9 @@ static u16 __init parse_ivhd_device_alia
 112.395      alias_id = ivhd_device->alias.dev_id;
 112.396      if ( alias_id >= ivrs_bdf_entries )
 112.397      {
 112.398 -       dprintk(XENLOG_ERR, "IVHD Error: "
 112.399 -               "Invalid Alias Dev_Id 0x%x\n", alias_id);
 112.400 -       return 0;
 112.401 +        dprintk(XENLOG_ERR, "IVHD Error: "
 112.402 +                "Invalid Alias Dev_Id 0x%x\n", alias_id);
 112.403 +        return 0;
 112.404      }
 112.405  
 112.406      dprintk(XENLOG_INFO, " Dev_Id Alias: 0x%x\n", alias_id);
 112.407 @@ -470,18 +470,18 @@ static u16 __init parse_ivhd_device_alia
 112.408      /* override requestor_id and flags for device */
 112.409      ivrs_mappings[bdf].dte_requestor_id = alias_id;
 112.410      ivrs_mappings[bdf].dte_sys_mgt_enable =
 112.411 -            get_field_from_byte(ivhd_device->header.flags,
 112.412 -                                AMD_IOMMU_ACPI_SYS_MGT_MASK,
 112.413 -                                AMD_IOMMU_ACPI_SYS_MGT_SHIFT);
 112.414 +        get_field_from_byte(ivhd_device->header.flags,
 112.415 +                            AMD_IOMMU_ACPI_SYS_MGT_MASK,
 112.416 +                            AMD_IOMMU_ACPI_SYS_MGT_SHIFT);
 112.417      ivrs_mappings[alias_id].dte_sys_mgt_enable =
 112.418 -            ivrs_mappings[bdf].dte_sys_mgt_enable;
 112.419 +        ivrs_mappings[bdf].dte_sys_mgt_enable;
 112.420  
 112.421      return dev_length;
 112.422  }
 112.423  
 112.424  static u16 __init parse_ivhd_device_alias_range(
 112.425 -           union acpi_ivhd_device *ivhd_device,
 112.426 -           u16 header_length, u16 block_length)
 112.427 +    union acpi_ivhd_device *ivhd_device,
 112.428 +    u16 header_length, u16 block_length)
 112.429  {
 112.430  
 112.431      u16 dev_length, first_bdf, last_bdf, alias_id, bdf;
 112.432 @@ -496,7 +496,7 @@ static u16 __init parse_ivhd_device_alia
 112.433      }
 112.434  
 112.435      if ( ivhd_device->alias_range.trailer.type !=
 112.436 -       AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END )
 112.437 +         AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END )
 112.438      {
 112.439          dprintk(XENLOG_ERR, "IVHD Error: "
 112.440                  "Invalid Range: End_Type 0x%x\n",
 112.441 @@ -536,7 +536,7 @@ static u16 __init parse_ivhd_device_alia
 112.442      sys_mgt = get_field_from_byte(ivhd_device->header.flags,
 112.443                                    AMD_IOMMU_ACPI_SYS_MGT_MASK,
 112.444                                    AMD_IOMMU_ACPI_SYS_MGT_SHIFT);
 112.445 -    for ( bdf = first_bdf; bdf <= last_bdf; ++bdf )
 112.446 +    for ( bdf = first_bdf; bdf <= last_bdf; bdf++ )
 112.447      {
 112.448          ivrs_mappings[bdf].dte_requestor_id = alias_id;
 112.449          ivrs_mappings[bdf].dte_sys_mgt_enable = sys_mgt;
 112.450 @@ -547,8 +547,8 @@ static u16 __init parse_ivhd_device_alia
 112.451  }
 112.452  
 112.453  static u16 __init parse_ivhd_device_extended(
 112.454 -           union acpi_ivhd_device *ivhd_device,
 112.455 -           u16 header_length, u16 block_length)
 112.456 +    union acpi_ivhd_device *ivhd_device,
 112.457 +    u16 header_length, u16 block_length)
 112.458  {
 112.459      u16 dev_length, bdf;
 112.460  
 112.461 @@ -578,8 +578,8 @@ static u16 __init parse_ivhd_device_exte
 112.462  }
 112.463  
 112.464  static u16 __init parse_ivhd_device_extended_range(
 112.465 -           union acpi_ivhd_device *ivhd_device,
 112.466 -           u16 header_length, u16 block_length)
 112.467 +    union acpi_ivhd_device *ivhd_device,
 112.468 +    u16 header_length, u16 block_length)
 112.469  {
 112.470      u16 dev_length, first_bdf, last_bdf, bdf;
 112.471      u8 sys_mgt;
 112.472 @@ -593,7 +593,7 @@ static u16 __init parse_ivhd_device_exte
 112.473      }
 112.474  
 112.475      if ( ivhd_device->extended_range.trailer.type !=
 112.476 -        AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END )
 112.477 +         AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END )
 112.478      {
 112.479          dprintk(XENLOG_ERR, "IVHD Error: "
 112.480                  "Invalid Range: End_Type 0x%x\n",
 112.481 @@ -604,13 +604,13 @@ static u16 __init parse_ivhd_device_exte
 112.482      first_bdf = ivhd_device->header.dev_id;
 112.483      if ( first_bdf >= ivrs_bdf_entries )
 112.484      {
 112.485 -       dprintk(XENLOG_ERR, "IVHD Error: "
 112.486 -           "Invalid Range: First Dev_Id 0x%x\n", first_bdf);
 112.487 -       return 0;
 112.488 +        dprintk(XENLOG_ERR, "IVHD Error: "
 112.489 +                "Invalid Range: First Dev_Id 0x%x\n", first_bdf);
 112.490 +        return 0;
 112.491      }
 112.492  
 112.493      last_bdf = ivhd_device->extended_range.trailer.dev_id;
 112.494 -    if ( last_bdf >= ivrs_bdf_entries || last_bdf <= first_bdf )
 112.495 +    if ( (last_bdf >= ivrs_bdf_entries) || (last_bdf <= first_bdf) )
 112.496      {
 112.497          dprintk(XENLOG_ERR, "IVHD Error: "
 112.498                  "Invalid Range: Last Dev_Id 0x%x\n", last_bdf);
 112.499 @@ -624,7 +624,7 @@ static u16 __init parse_ivhd_device_exte
 112.500      sys_mgt = get_field_from_byte(ivhd_device->header.flags,
 112.501                                    AMD_IOMMU_ACPI_SYS_MGT_MASK,
 112.502                                    AMD_IOMMU_ACPI_SYS_MGT_SHIFT);
 112.503 -    for ( bdf = first_bdf; bdf <= last_bdf; ++bdf )
 112.504 +    for ( bdf = first_bdf; bdf <= last_bdf; bdf++ )
 112.505          ivrs_mappings[bdf].dte_sys_mgt_enable = sys_mgt;
 112.506  
 112.507      return dev_length;
 112.508 @@ -637,20 +637,20 @@ static int __init parse_ivhd_block(struc
 112.509      struct amd_iommu *iommu;
 112.510  
 112.511      if ( ivhd_block->header.length <
 112.512 -        sizeof(struct acpi_ivhd_block_header) )
 112.513 +         sizeof(struct acpi_ivhd_block_header) )
 112.514      {
 112.515          dprintk(XENLOG_ERR, "IVHD Error: Invalid Block Length!\n");
 112.516          return -ENODEV;
 112.517      }
 112.518  
 112.519      iommu = find_iommu_from_bdf_cap(ivhd_block->header.dev_id,
 112.520 -            ivhd_block->cap_offset);
 112.521 +                                    ivhd_block->cap_offset);
 112.522      if ( !iommu )
 112.523      {
 112.524          dprintk(XENLOG_ERR,
 112.525                  "IVHD Error: No IOMMU for Dev_Id 0x%x  Cap 0x%x\n",
 112.526                  ivhd_block->header.dev_id, ivhd_block->cap_offset);
 112.527 -       return -ENODEV;
 112.528 +        return -ENODEV;
 112.529      }
 112.530  
 112.531      dprintk(XENLOG_INFO, "IVHD Block:\n");
 112.532 @@ -668,29 +668,29 @@ static int __init parse_ivhd_block(struc
 112.533                                            AMD_IOMMU_ACPI_COHERENT_MASK,
 112.534                                            AMD_IOMMU_ACPI_COHERENT_SHIFT);
 112.535      iommu->iotlb_support = get_field_from_byte(ivhd_block->header.flags,
 112.536 -                                          AMD_IOMMU_ACPI_IOTLB_SUP_MASK,
 112.537 -                                          AMD_IOMMU_ACPI_IOTLB_SUP_SHIFT);
 112.538 +                                               AMD_IOMMU_ACPI_IOTLB_SUP_MASK,
 112.539 +                                               AMD_IOMMU_ACPI_IOTLB_SUP_SHIFT);
 112.540      iommu->isochronous = get_field_from_byte(ivhd_block->header.flags,
 112.541 -                                          AMD_IOMMU_ACPI_ISOC_MASK,
 112.542 -                                          AMD_IOMMU_ACPI_ISOC_SHIFT);
 112.543 +                                             AMD_IOMMU_ACPI_ISOC_MASK,
 112.544 +                                             AMD_IOMMU_ACPI_ISOC_SHIFT);
 112.545      iommu->res_pass_pw = get_field_from_byte(ivhd_block->header.flags,
 112.546 -                                          AMD_IOMMU_ACPI_RES_PASS_PW_MASK,
 112.547 -                                          AMD_IOMMU_ACPI_RES_PASS_PW_SHIFT);
 112.548 +                                             AMD_IOMMU_ACPI_RES_PASS_PW_MASK,
 112.549 +                                             AMD_IOMMU_ACPI_RES_PASS_PW_SHIFT);
 112.550      iommu->pass_pw = get_field_from_byte(ivhd_block->header.flags,
 112.551 -                                          AMD_IOMMU_ACPI_PASS_PW_MASK,
 112.552 -                                          AMD_IOMMU_ACPI_PASS_PW_SHIFT);
 112.553 +                                         AMD_IOMMU_ACPI_PASS_PW_MASK,
 112.554 +                                         AMD_IOMMU_ACPI_PASS_PW_SHIFT);
 112.555      iommu->ht_tunnel_enable = get_field_from_byte(
 112.556 -                                          ivhd_block->header.flags,
 112.557 -                                          AMD_IOMMU_ACPI_HT_TUN_ENB_MASK,
 112.558 -                                          AMD_IOMMU_ACPI_HT_TUN_ENB_SHIFT);
 112.559 +        ivhd_block->header.flags,
 112.560 +        AMD_IOMMU_ACPI_HT_TUN_ENB_MASK,
 112.561 +        AMD_IOMMU_ACPI_HT_TUN_ENB_SHIFT);
 112.562  
 112.563      /* parse Device Entries */
 112.564      block_length = sizeof(struct acpi_ivhd_block_header);
 112.565 -    while( ivhd_block->header.length >=
 112.566 -       (block_length + sizeof(struct acpi_ivhd_device_header)) )
 112.567 +    while ( ivhd_block->header.length >=
 112.568 +            (block_length + sizeof(struct acpi_ivhd_device_header)) )
 112.569      {
 112.570          ivhd_device = (union acpi_ivhd_device *)
 112.571 -                ((u8 *)ivhd_block + block_length);
 112.572 +            ((u8 *)ivhd_block + block_length);
 112.573  
 112.574          dprintk(XENLOG_INFO, "IVHD Device Entry:\n");
 112.575          dprintk(XENLOG_INFO, " Type 0x%x\n",
 112.576 @@ -700,7 +700,7 @@ static int __init parse_ivhd_block(struc
 112.577          dprintk(XENLOG_INFO, " Flags 0x%x\n",
 112.578                  ivhd_device->header.flags);
 112.579  
 112.580 -        switch( ivhd_device->header.type )
 112.581 +        switch ( ivhd_device->header.type )
 112.582          {
 112.583          case AMD_IOMMU_ACPI_IVHD_DEV_U32_PAD:
 112.584              dev_length = parse_ivhd_device_padding(
 112.585 @@ -716,7 +716,8 @@ static int __init parse_ivhd_block(struc
 112.586              dev_length = parse_ivhd_device_select(ivhd_device);
 112.587              break;
 112.588          case AMD_IOMMU_ACPI_IVHD_DEV_RANGE_START:
 112.589 -            dev_length = parse_ivhd_device_range(ivhd_device,
 112.590 +            dev_length = parse_ivhd_device_range(
 112.591 +                ivhd_device,
 112.592                  ivhd_block->header.length, block_length);
 112.593              break;
 112.594          case AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_SELECT:
 112.595 @@ -741,7 +742,7 @@ static int __init parse_ivhd_block(struc
 112.596              break;
 112.597          default:
 112.598              dprintk(XENLOG_ERR, "IVHD Error: "
 112.599 -                "Invalid Device Type!\n");
 112.600 +                    "Invalid Device Type!\n");
 112.601              dev_length = 0;
 112.602              break;
 112.603          }
 112.604 @@ -759,7 +760,7 @@ static int __init parse_ivrs_block(struc
 112.605      struct acpi_ivhd_block_header *ivhd_block;
 112.606      struct acpi_ivmd_block_header *ivmd_block;
 112.607  
 112.608 -    switch(ivrs_block->type)
 112.609 +    switch ( ivrs_block->type )
 112.610      {
 112.611      case AMD_IOMMU_ACPI_IVHD_TYPE:
 112.612          ivhd_block = (struct acpi_ivhd_block_header *)ivrs_block;
 112.613 @@ -786,7 +787,7 @@ void __init dump_acpi_table_header(struc
 112.614  
 112.615      printk(XENLOG_INFO "AMD IOMMU: ACPI Table:\n");
 112.616      printk(XENLOG_INFO " Signature ");
 112.617 -    for ( i = 0; i < ACPI_NAME_SIZE; ++i )
 112.618 +    for ( i = 0; i < ACPI_NAME_SIZE; i++ )
 112.619          printk("%c", table->signature[i]);
 112.620      printk("\n");
 112.621  
 112.622 @@ -795,28 +796,27 @@ void __init dump_acpi_table_header(struc
 112.623      printk(" CheckSum 0x%x\n", table->checksum);
 112.624  
 112.625      printk(" OEM_Id ");
 112.626 -    for ( i = 0; i < ACPI_OEM_ID_SIZE; ++i )
 112.627 +    for ( i = 0; i < ACPI_OEM_ID_SIZE; i++ )
 112.628          printk("%c", table->oem_id[i]);
 112.629      printk("\n");
 112.630  
 112.631      printk(" OEM_Table_Id ");
 112.632 -    for ( i = 0; i < ACPI_OEM_TABLE_ID_SIZE; ++i )
 112.633 +    for ( i = 0; i < ACPI_OEM_TABLE_ID_SIZE; i++ )
 112.634          printk("%c", table->oem_table_id[i]);
 112.635      printk("\n");
 112.636  
 112.637      printk(" OEM_Revision 0x%x\n", table->oem_revision);
 112.638  
 112.639      printk(" Creator_Id ");
 112.640 -    for ( i = 0; i < ACPI_NAME_SIZE; ++i )
 112.641 +    for ( i = 0; i < ACPI_NAME_SIZE; i++ )
 112.642          printk("%c", table->asl_compiler_id[i]);
 112.643      printk("\n");
 112.644  
 112.645      printk(" Creator_Revision 0x%x\n",
 112.646 -       table->asl_compiler_revision);
 112.647 +           table->asl_compiler_revision);
 112.648  }
 112.649  
 112.650 -int __init parse_ivrs_table(unsigned long phys_addr,
 112.651 -                                  unsigned long size)
 112.652 +int __init parse_ivrs_table(unsigned long phys_addr, unsigned long size)
 112.653  {
 112.654      struct acpi_ivrs_block_header *ivrs_block;
 112.655      unsigned long length, i;
 112.656 @@ -834,7 +834,7 @@ int __init parse_ivrs_table(unsigned lon
 112.657      /* validate checksum: sum of entire table == 0 */
 112.658      checksum = 0;
 112.659      raw_table = (u8 *)table;
 112.660 -    for ( i = 0; i < table->length; ++i )
 112.661 +    for ( i = 0; i < table->length; i++ )
 112.662          checksum += raw_table[i];
 112.663      if ( checksum )
 112.664      {
 112.665 @@ -845,11 +845,10 @@ int __init parse_ivrs_table(unsigned lon
 112.666  
 112.667      /* parse IVRS blocks */
 112.668      length = sizeof(struct acpi_ivrs_table_header);
 112.669 -    while( error == 0 && table->length >
 112.670 -       (length + sizeof(struct acpi_ivrs_block_header)) )
 112.671 +    while ( (error == 0) && (table->length > (length + sizeof(*ivrs_block))) )
 112.672      {
 112.673          ivrs_block = (struct acpi_ivrs_block_header *)
 112.674 -                ((u8 *)table + length);
 112.675 +            ((u8 *)table + length);
 112.676  
 112.677          dprintk(XENLOG_INFO, "IVRS Block:\n");
 112.678          dprintk(XENLOG_INFO, " Type 0x%x\n", ivrs_block->type);
 112.679 @@ -857,16 +856,16 @@ int __init parse_ivrs_table(unsigned lon
 112.680          dprintk(XENLOG_INFO, " Length 0x%x\n", ivrs_block->length);
 112.681          dprintk(XENLOG_INFO, " Dev_Id 0x%x\n", ivrs_block->dev_id);
 112.682  
 112.683 -        if (table->length >= (length + ivrs_block->length))
 112.684 -           error = parse_ivrs_block(ivrs_block);
 112.685 -        else
 112.686 +        if ( table->length < (length + ivrs_block->length) )
 112.687          {
 112.688 -           dprintk(XENLOG_ERR, "IVRS Error: "
 112.689 -               "Table Length Exceeded: 0x%x -> 0x%lx\n",
 112.690 -               table->length,
 112.691 -               (length + ivrs_block->length));
 112.692 -           return -ENODEV;
 112.693 +            dprintk(XENLOG_ERR, "IVRS Error: "
 112.694 +                    "Table Length Exceeded: 0x%x -> 0x%lx\n",
 112.695 +                    table->length,
 112.696 +                    (length + ivrs_block->length));
 112.697 +            return -ENODEV;
 112.698          }
 112.699 +
 112.700 +        error = parse_ivrs_block(ivrs_block);
 112.701          length += ivrs_block->length;
 112.702      }
 112.703  
   113.1 --- a/xen/drivers/passthrough/amd/iommu_detect.c	Fri Mar 14 15:07:45 2008 -0600
   113.2 +++ b/xen/drivers/passthrough/amd/iommu_detect.c	Thu Mar 20 12:35:40 2008 -0600
   113.3 @@ -20,14 +20,14 @@
   113.4  
   113.5  #include <xen/config.h>
   113.6  #include <xen/errno.h>
   113.7 -#include <asm/iommu.h>
   113.8 +#include <xen/iommu.h>
   113.9  #include <asm/amd-iommu.h>
  113.10  #include <asm/hvm/svm/amd-iommu-proto.h>
  113.11  #include "../pci-direct.h"
  113.12  #include "../pci_regs.h"
  113.13  
  113.14 -static int __init valid_bridge_bus_config(int bus, int dev, int func,
  113.15 -            int *sec_bus, int *sub_bus)
  113.16 +static int __init valid_bridge_bus_config(
  113.17 +    int bus, int dev, int func, int *sec_bus, int *sub_bus)
  113.18  {
  113.19      int pri_bus;
  113.20  
  113.21 @@ -35,7 +35,7 @@ static int __init valid_bridge_bus_confi
  113.22      *sec_bus = read_pci_config_byte(bus, dev, func, PCI_SECONDARY_BUS);
  113.23      *sub_bus = read_pci_config_byte(bus, dev, func, PCI_SUBORDINATE_BUS);
  113.24  
  113.25 -    return ( pri_bus == bus && *sec_bus > bus && *sub_bus >= *sec_bus );
  113.26 +    return ((pri_bus == bus) && (*sec_bus > bus) && (*sub_bus >= *sec_bus));
  113.27  }
  113.28  
  113.29  int __init get_iommu_last_downstream_bus(struct amd_iommu *iommu)
  113.30 @@ -49,9 +49,11 @@ int __init get_iommu_last_downstream_bus
  113.31      iommu->downstream_bus_present[bus] = 1;
  113.32      dev = PCI_SLOT(iommu->first_devfn);
  113.33      multi_func = PCI_FUNC(iommu->first_devfn) > 0;
  113.34 -    for ( devfn = iommu->first_devfn; devfn <= iommu->last_devfn; ++devfn ) {
  113.35 +    for ( devfn = iommu->first_devfn; devfn <= iommu->last_devfn; devfn++ )
  113.36 +    {
  113.37          /* skipping to next device#? */
  113.38 -        if ( dev != PCI_SLOT(devfn) ) {
  113.39 +        if ( dev != PCI_SLOT(devfn) )
  113.40 +        {
  113.41              dev = PCI_SLOT(devfn);
  113.42              multi_func = 0;
  113.43          }
  113.44 @@ -62,14 +64,15 @@ int __init get_iommu_last_downstream_bus
  113.45              continue;
  113.46  
  113.47          hdr_type = read_pci_config_byte(bus, dev, func,
  113.48 -                PCI_HEADER_TYPE);
  113.49 +                                        PCI_HEADER_TYPE);
  113.50          if ( func == 0 )
  113.51              multi_func = IS_PCI_MULTI_FUNCTION(hdr_type);
  113.52  
  113.53          if ( (func == 0 || multi_func) &&
  113.54 -            IS_PCI_TYPE1_HEADER(hdr_type) ) {
  113.55 -            if (!valid_bridge_bus_config(bus, dev, func,
  113.56 -                &sec_bus, &sub_bus))
  113.57 +             IS_PCI_TYPE1_HEADER(hdr_type) )
  113.58 +        {
  113.59 +            if ( !valid_bridge_bus_config(bus, dev, func,
  113.60 +                                          &sec_bus, &sub_bus) )
  113.61                  return -ENODEV;
  113.62  
  113.63              if ( sub_bus > iommu->last_downstream_bus )
  113.64 @@ -84,18 +87,18 @@ int __init get_iommu_last_downstream_bus
  113.65  }
  113.66  
  113.67  int __init get_iommu_capabilities(u8 bus, u8 dev, u8 func, u8 cap_ptr,
  113.68 -            struct amd_iommu *iommu)
  113.69 +                                  struct amd_iommu *iommu)
  113.70  {
  113.71      u32 cap_header, cap_range, misc_info;
  113.72      u64 mmio_bar;
  113.73  
  113.74 -    mmio_bar = (u64)read_pci_config(bus, dev, func,
  113.75 -            cap_ptr + PCI_CAP_MMIO_BAR_HIGH_OFFSET) << 32;
  113.76 +    mmio_bar = (u64)read_pci_config(
  113.77 +        bus, dev, func, cap_ptr + PCI_CAP_MMIO_BAR_HIGH_OFFSET) << 32;
  113.78      mmio_bar |= read_pci_config(bus, dev, func,
  113.79 -            cap_ptr + PCI_CAP_MMIO_BAR_LOW_OFFSET); 
  113.80 +                                cap_ptr + PCI_CAP_MMIO_BAR_LOW_OFFSET);
  113.81      iommu->mmio_base_phys = mmio_bar & (u64)~0x3FFF;
  113.82  
  113.83 -    if ( (mmio_bar & 0x1) == 0 || iommu->mmio_base_phys == 0 )
  113.84 +    if ( ((mmio_bar & 0x1) == 0) || (iommu->mmio_base_phys == 0) )
  113.85      {
  113.86          dprintk(XENLOG_ERR ,
  113.87                  "AMD IOMMU: Invalid MMIO_BAR = 0x%"PRIx64"\n", mmio_bar);
  113.88 @@ -106,42 +109,37 @@ int __init get_iommu_capabilities(u8 bus
  113.89      iommu->cap_offset = cap_ptr;
  113.90  
  113.91      cap_header = read_pci_config(bus, dev, func, cap_ptr);
  113.92 -    iommu->revision = get_field_from_reg_u32(cap_header,
  113.93 -                  PCI_CAP_REV_MASK, PCI_CAP_REV_SHIFT);
  113.94 -    iommu->iotlb_support = get_field_from_reg_u32(cap_header,
  113.95 -                PCI_CAP_IOTLB_MASK, PCI_CAP_IOTLB_SHIFT);
  113.96 -    iommu->ht_tunnel_support = get_field_from_reg_u32(cap_header,
  113.97 -                    PCI_CAP_HT_TUNNEL_MASK,
  113.98 -                    PCI_CAP_HT_TUNNEL_SHIFT);
  113.99 -    iommu->pte_not_present_cached = get_field_from_reg_u32(cap_header,
 113.100 -                    PCI_CAP_NP_CACHE_MASK,
 113.101 -                    PCI_CAP_NP_CACHE_SHIFT);
 113.102 +    iommu->revision = get_field_from_reg_u32(
 113.103 +        cap_header, PCI_CAP_REV_MASK, PCI_CAP_REV_SHIFT);
 113.104 +    iommu->iotlb_support = get_field_from_reg_u32(
 113.105 +        cap_header, PCI_CAP_IOTLB_MASK, PCI_CAP_IOTLB_SHIFT);
 113.106 +    iommu->ht_tunnel_support = get_field_from_reg_u32(
 113.107 +        cap_header, PCI_CAP_HT_TUNNEL_MASK, PCI_CAP_HT_TUNNEL_SHIFT);
 113.108 +    iommu->pte_not_present_cached = get_field_from_reg_u32(
 113.109 +        cap_header, PCI_CAP_NP_CACHE_MASK, PCI_CAP_NP_CACHE_SHIFT);
 113.110  
 113.111      cap_range = read_pci_config(bus, dev, func,
 113.112 -            cap_ptr + PCI_CAP_RANGE_OFFSET);
 113.113 -    iommu->unit_id = get_field_from_reg_u32(cap_range,
 113.114 -                PCI_CAP_UNIT_ID_MASK,
 113.115 -                PCI_CAP_UNIT_ID_SHIFT);
 113.116 -    iommu->root_bus = get_field_from_reg_u32(cap_range,
 113.117 -                PCI_CAP_BUS_NUMBER_MASK,
 113.118 -                PCI_CAP_BUS_NUMBER_SHIFT);
 113.119 -    iommu->first_devfn = get_field_from_reg_u32(cap_range,
 113.120 -                PCI_CAP_FIRST_DEVICE_MASK,
 113.121 -                PCI_CAP_FIRST_DEVICE_SHIFT);
 113.122 -    iommu->last_devfn = get_field_from_reg_u32(cap_range,
 113.123 -                PCI_CAP_LAST_DEVICE_MASK,
 113.124 -                PCI_CAP_LAST_DEVICE_SHIFT);
 113.125 +                                cap_ptr + PCI_CAP_RANGE_OFFSET);
 113.126 +    iommu->unit_id = get_field_from_reg_u32(
 113.127 +        cap_range, PCI_CAP_UNIT_ID_MASK, PCI_CAP_UNIT_ID_SHIFT);
 113.128 +    iommu->root_bus = get_field_from_reg_u32(
 113.129 +        cap_range, PCI_CAP_BUS_NUMBER_MASK, PCI_CAP_BUS_NUMBER_SHIFT);
 113.130 +    iommu->first_devfn = get_field_from_reg_u32(
 113.131 +        cap_range, PCI_CAP_FIRST_DEVICE_MASK, PCI_CAP_FIRST_DEVICE_SHIFT);
 113.132 +    iommu->last_devfn = get_field_from_reg_u32(
 113.133 +        cap_range, PCI_CAP_LAST_DEVICE_MASK, PCI_CAP_LAST_DEVICE_SHIFT);
 113.134  
 113.135      misc_info = read_pci_config(bus, dev, func,
 113.136 -            cap_ptr + PCI_MISC_INFO_OFFSET);
 113.137 -    iommu->msi_number = get_field_from_reg_u32(misc_info,
 113.138 -                PCI_CAP_MSI_NUMBER_MASK,
 113.139 -                PCI_CAP_MSI_NUMBER_SHIFT);
 113.140 +                                cap_ptr + PCI_MISC_INFO_OFFSET);
 113.141 +    iommu->msi_number = get_field_from_reg_u32(
 113.142 +        misc_info, PCI_CAP_MSI_NUMBER_MASK, PCI_CAP_MSI_NUMBER_SHIFT);
 113.143 +
 113.144      return 0;
 113.145  }
 113.146  
 113.147 -static int __init scan_caps_for_iommu(int bus, int dev, int func,
 113.148 -            iommu_detect_callback_ptr_t iommu_detect_callback)
 113.149 +static int __init scan_caps_for_iommu(
 113.150 +    int bus, int dev, int func,
 113.151 +    iommu_detect_callback_ptr_t iommu_detect_callback)
 113.152  {
 113.153      int cap_ptr, cap_id, cap_type;
 113.154      u32 cap_header;
 113.155 @@ -149,32 +147,35 @@ static int __init scan_caps_for_iommu(in
 113.156  
 113.157      count = 0;
 113.158      cap_ptr = read_pci_config_byte(bus, dev, func,
 113.159 -            PCI_CAPABILITY_LIST);
 113.160 -    while ( cap_ptr >= PCI_MIN_CAP_OFFSET &&
 113.161 -        count < PCI_MAX_CAP_BLOCKS && !error ) {
 113.162 +                                   PCI_CAPABILITY_LIST);
 113.163 +    while ( (cap_ptr >= PCI_MIN_CAP_OFFSET) &&
 113.164 +            (count < PCI_MAX_CAP_BLOCKS) &&
 113.165 +            !error )
 113.166 +    {
 113.167          cap_ptr &= PCI_CAP_PTR_MASK;
 113.168          cap_header = read_pci_config(bus, dev, func, cap_ptr);
 113.169 -        cap_id = get_field_from_reg_u32(cap_header,
 113.170 -                PCI_CAP_ID_MASK, PCI_CAP_ID_SHIFT);
 113.171 +        cap_id = get_field_from_reg_u32(
 113.172 +            cap_header, PCI_CAP_ID_MASK, PCI_CAP_ID_SHIFT);
 113.173  
 113.174 -        if ( cap_id == PCI_CAP_ID_SECURE_DEVICE ) {
 113.175 -            cap_type = get_field_from_reg_u32(cap_header,
 113.176 -                    PCI_CAP_TYPE_MASK, PCI_CAP_TYPE_SHIFT);
 113.177 -            if ( cap_type == PCI_CAP_TYPE_IOMMU ) {
 113.178 +        if ( cap_id == PCI_CAP_ID_SECURE_DEVICE )
 113.179 +        {
 113.180 +            cap_type = get_field_from_reg_u32(
 113.181 +                cap_header, PCI_CAP_TYPE_MASK, PCI_CAP_TYPE_SHIFT);
 113.182 +            if ( cap_type == PCI_CAP_TYPE_IOMMU )
 113.183                  error = iommu_detect_callback(
 113.184 -                        bus, dev, func, cap_ptr);
 113.185 -            }
 113.186 +                    bus, dev, func, cap_ptr);
 113.187          }
 113.188  
 113.189 -        cap_ptr = get_field_from_reg_u32(cap_header,
 113.190 -                PCI_CAP_NEXT_PTR_MASK, PCI_CAP_NEXT_PTR_SHIFT);
 113.191 -        ++count;    }
 113.192 +        cap_ptr = get_field_from_reg_u32(
 113.193 +            cap_header, PCI_CAP_NEXT_PTR_MASK, PCI_CAP_NEXT_PTR_SHIFT);
 113.194 +        count++;
 113.195 +    }
 113.196  
 113.197      return error;
 113.198  }
 113.199  
 113.200 -static int __init scan_functions_for_iommu(int bus, int dev,
 113.201 -            iommu_detect_callback_ptr_t iommu_detect_callback)
 113.202 +static int __init scan_functions_for_iommu(
 113.203 +    int bus, int dev, iommu_detect_callback_ptr_t iommu_detect_callback)
 113.204  {
 113.205      int func, hdr_type;
 113.206      int count, error = 0;
 113.207 @@ -182,19 +183,20 @@ static int __init scan_functions_for_iom
 113.208      func = 0;
 113.209      count = 1;
 113.210      while ( VALID_PCI_VENDOR_ID(read_pci_config_16(bus, dev, func,
 113.211 -            PCI_VENDOR_ID)) && !error && func < count ) {
 113.212 +                                                   PCI_VENDOR_ID)) &&
 113.213 +            !error && (func < count) )
 113.214 +    {
 113.215          hdr_type = read_pci_config_byte(bus, dev, func,
 113.216 -                PCI_HEADER_TYPE);
 113.217 +                                        PCI_HEADER_TYPE);
 113.218  
 113.219          if ( func == 0 && IS_PCI_MULTI_FUNCTION(hdr_type) )
 113.220              count = PCI_MAX_FUNC_COUNT;
 113.221  
 113.222          if ( IS_PCI_TYPE0_HEADER(hdr_type) ||
 113.223 -            IS_PCI_TYPE1_HEADER(hdr_type) ) {
 113.224 -            error =  scan_caps_for_iommu(bus, dev, func,
 113.225 -                    iommu_detect_callback);
 113.226 -        }
 113.227 -        ++func;
 113.228 +             IS_PCI_TYPE1_HEADER(hdr_type) )
 113.229 +            error = scan_caps_for_iommu(bus, dev, func,
 113.230 +                                        iommu_detect_callback);
 113.231 +        func++;
 113.232      }
 113.233  
 113.234      return error;
 113.235 @@ -205,12 +207,10 @@ int __init scan_for_iommu(iommu_detect_c
 113.236  {
 113.237      int bus, dev, error = 0;
 113.238  
 113.239 -    for ( bus = 0; bus < PCI_MAX_BUS_COUNT && !error; ++bus ) {
 113.240 -        for ( dev = 0; dev < PCI_MAX_DEV_COUNT && !error; ++dev ) {
 113.241 -            error =  scan_functions_for_iommu(bus, dev,
 113.242 -                  iommu_detect_callback);
 113.243 -        }
 113.244 -    }
 113.245 +    for ( bus = 0; bus < PCI_MAX_BUS_COUNT && !error; ++bus )
 113.246 +        for ( dev = 0; dev < PCI_MAX_DEV_COUNT && !error; ++dev )
 113.247 +            error = scan_functions_for_iommu(bus, dev,
 113.248 +                                             iommu_detect_callback);
 113.249  
 113.250      return error;
 113.251  }
   114.1 --- a/xen/drivers/passthrough/amd/iommu_init.c	Fri Mar 14 15:07:45 2008 -0600
   114.2 +++ b/xen/drivers/passthrough/amd/iommu_init.c	Thu Mar 20 12:35:40 2008 -0600
   114.3 @@ -32,26 +32,28 @@ int __init map_iommu_mmio_region(struct 
   114.4  {
   114.5      unsigned long mfn;
   114.6  
   114.7 -    if ( nr_amd_iommus > MAX_AMD_IOMMUS ) {
   114.8 +    if ( nr_amd_iommus > MAX_AMD_IOMMUS )
   114.9 +    {
  114.10          gdprintk(XENLOG_ERR,
  114.11 -            "IOMMU: nr_amd_iommus %d > MAX_IOMMUS\n", nr_amd_iommus);
  114.12 +                 "IOMMU: nr_amd_iommus %d > MAX_IOMMUS\n", nr_amd_iommus);
  114.13          return -ENOMEM;
  114.14      }
  114.15  
  114.16 -    iommu->mmio_base = (void *) fix_to_virt(FIX_IOMMU_MMIO_BASE_0 +
  114.17 -                       nr_amd_iommus * MMIO_PAGES_PER_IOMMU);
  114.18 -    mfn = (unsigned long)iommu->mmio_base_phys >> PAGE_SHIFT;
  114.19 +    iommu->mmio_base = (void *)fix_to_virt(
  114.20 +        FIX_IOMMU_MMIO_BASE_0 + nr_amd_iommus * MMIO_PAGES_PER_IOMMU);
  114.21 +    mfn = (unsigned long)(iommu->mmio_base_phys >> PAGE_SHIFT);
  114.22      map_pages_to_xen((unsigned long)iommu->mmio_base, mfn,
  114.23 -                    MMIO_PAGES_PER_IOMMU, PAGE_HYPERVISOR_NOCACHE);
  114.24 +                     MMIO_PAGES_PER_IOMMU, PAGE_HYPERVISOR_NOCACHE);
  114.25  
  114.26 -    memset((u8*)iommu->mmio_base, 0, IOMMU_MMIO_REGION_LENGTH);
  114.27 +    memset(iommu->mmio_base, 0, IOMMU_MMIO_REGION_LENGTH);
  114.28  
  114.29      return 0;
  114.30  }
  114.31  
  114.32  void __init unmap_iommu_mmio_region(struct amd_iommu *iommu)
  114.33  {
  114.34 -    if ( iommu->mmio_base ) {
  114.35 +    if ( iommu->mmio_base )
  114.36 +    {
  114.37          iounmap(iommu->mmio_base);
  114.38          iommu->mmio_base = NULL;
  114.39      }
  114.40 @@ -67,16 +69,16 @@ void __init register_iommu_dev_table_in_
  114.41      addr_hi = addr_64 >> 32;
  114.42  
  114.43      set_field_in_reg_u32((u32)addr_lo >> PAGE_SHIFT, 0,
  114.44 -        IOMMU_DEV_TABLE_BASE_LOW_MASK,
  114.45 -        IOMMU_DEV_TABLE_BASE_LOW_SHIFT, &entry);
  114.46 +                         IOMMU_DEV_TABLE_BASE_LOW_MASK,
  114.47 +                         IOMMU_DEV_TABLE_BASE_LOW_SHIFT, &entry);
  114.48      set_field_in_reg_u32((iommu->dev_table.alloc_size / PAGE_SIZE) - 1,
  114.49 -        entry, IOMMU_DEV_TABLE_SIZE_MASK,
  114.50 -        IOMMU_DEV_TABLE_SIZE_SHIFT, &entry);
  114.51 +                         entry, IOMMU_DEV_TABLE_SIZE_MASK,
  114.52 +                         IOMMU_DEV_TABLE_SIZE_SHIFT, &entry);
  114.53      writel(entry, iommu->mmio_base + IOMMU_DEV_TABLE_BASE_LOW_OFFSET);
  114.54  
  114.55      set_field_in_reg_u32((u32)addr_hi, 0,
  114.56 -        IOMMU_DEV_TABLE_BASE_HIGH_MASK,
  114.57 -        IOMMU_DEV_TABLE_BASE_HIGH_SHIFT, &entry);
  114.58 +                         IOMMU_DEV_TABLE_BASE_HIGH_MASK,
  114.59 +                         IOMMU_DEV_TABLE_BASE_HIGH_SHIFT, &entry);
  114.60      writel(entry, iommu->mmio_base + IOMMU_DEV_TABLE_BASE_HIGH_OFFSET);
  114.61  }
  114.62  
  114.63 @@ -91,49 +93,49 @@ void __init register_iommu_cmd_buffer_in
  114.64      addr_hi = addr_64 >> 32;
  114.65  
  114.66      set_field_in_reg_u32((u32)addr_lo >> PAGE_SHIFT, 0,
  114.67 -        IOMMU_CMD_BUFFER_BASE_LOW_MASK,
  114.68 -        IOMMU_CMD_BUFFER_BASE_LOW_SHIFT, &entry);
  114.69 +                         IOMMU_CMD_BUFFER_BASE_LOW_MASK,
  114.70 +                         IOMMU_CMD_BUFFER_BASE_LOW_SHIFT, &entry);
  114.71      writel(entry, iommu->mmio_base + IOMMU_CMD_BUFFER_BASE_LOW_OFFSET);
  114.72  
  114.73      power_of2_entries = get_order_from_bytes(iommu->cmd_buffer.alloc_size) +
  114.74          IOMMU_CMD_BUFFER_POWER_OF2_ENTRIES_PER_PAGE;
  114.75  
  114.76      set_field_in_reg_u32((u32)addr_hi, 0,
  114.77 -        IOMMU_CMD_BUFFER_BASE_HIGH_MASK,
  114.78 -        IOMMU_CMD_BUFFER_BASE_HIGH_SHIFT, &entry);
  114.79 +                         IOMMU_CMD_BUFFER_BASE_HIGH_MASK,
  114.80 +                         IOMMU_CMD_BUFFER_BASE_HIGH_SHIFT, &entry);
  114.81      set_field_in_reg_u32(power_of2_entries, entry,
  114.82 -        IOMMU_CMD_BUFFER_LENGTH_MASK,
  114.83 -        IOMMU_CMD_BUFFER_LENGTH_SHIFT, &entry);
  114.84 +                         IOMMU_CMD_BUFFER_LENGTH_MASK,
  114.85 +                         IOMMU_CMD_BUFFER_LENGTH_SHIFT, &entry);
  114.86      writel(entry, iommu->mmio_base+IOMMU_CMD_BUFFER_BASE_HIGH_OFFSET);
  114.87  }
  114.88  
  114.89  static void __init set_iommu_translation_control(struct amd_iommu *iommu,
  114.90 -            int enable)
  114.91 +                                                 int enable)
  114.92  {
  114.93      u32 entry;
  114.94  
  114.95      entry = readl(iommu->mmio_base+IOMMU_CONTROL_MMIO_OFFSET);
  114.96      set_field_in_reg_u32(iommu->ht_tunnel_support ? IOMMU_CONTROL_ENABLED :
  114.97 -        IOMMU_CONTROL_ENABLED, entry,
  114.98 -        IOMMU_CONTROL_HT_TUNNEL_TRANSLATION_MASK,
  114.99 -        IOMMU_CONTROL_HT_TUNNEL_TRANSLATION_SHIFT, &entry);
 114.100 +                         IOMMU_CONTROL_ENABLED, entry,
 114.101 +                         IOMMU_CONTROL_HT_TUNNEL_TRANSLATION_MASK,
 114.102 +                         IOMMU_CONTROL_HT_TUNNEL_TRANSLATION_SHIFT, &entry);
 114.103      set_field_in_reg_u32(enable ? IOMMU_CONTROL_ENABLED :
 114.104 -        IOMMU_CONTROL_ENABLED, entry,
 114.105 -        IOMMU_CONTROL_TRANSLATION_ENABLE_MASK,
 114.106 -        IOMMU_CONTROL_TRANSLATION_ENABLE_SHIFT, &entry);
 114.107 +                         IOMMU_CONTROL_ENABLED, entry,
 114.108 +                         IOMMU_CONTROL_TRANSLATION_ENABLE_MASK,
 114.109 +                         IOMMU_CONTROL_TRANSLATION_ENABLE_SHIFT, &entry);
 114.110      writel(entry, iommu->mmio_base+IOMMU_CONTROL_MMIO_OFFSET);
 114.111  }
 114.112  
 114.113  static void __init set_iommu_command_buffer_control(struct amd_iommu *iommu,
 114.114 -            int enable)
 114.115 +                                                    int enable)
 114.116  {
 114.117      u32 entry;
 114.118  
 114.119      entry = readl(iommu->mmio_base+IOMMU_CONTROL_MMIO_OFFSET);
 114.120      set_field_in_reg_u32(enable ? IOMMU_CONTROL_ENABLED :
 114.121 -        IOMMU_CONTROL_ENABLED, entry,
 114.122 -        IOMMU_CONTROL_COMMAND_BUFFER_ENABLE_MASK,
 114.123 -        IOMMU_CONTROL_COMMAND_BUFFER_ENABLE_SHIFT, &entry);
 114.124 +                         IOMMU_CONTROL_ENABLED, entry,
 114.125 +                         IOMMU_CONTROL_COMMAND_BUFFER_ENABLE_MASK,
 114.126 +                         IOMMU_CONTROL_COMMAND_BUFFER_ENABLE_SHIFT, &entry);
 114.127      writel(entry, iommu->mmio_base+IOMMU_CONTROL_MMIO_OFFSET);
 114.128  }
 114.129  
 114.130 @@ -146,34 +148,34 @@ static void __init register_iommu_exclus
 114.131      addr_hi = iommu->exclusion_limit >> 32;
 114.132  
 114.133      set_field_in_reg_u32((u32)addr_hi, 0,
 114.134 -        IOMMU_EXCLUSION_LIMIT_HIGH_MASK,
 114.135 -        IOMMU_EXCLUSION_LIMIT_HIGH_SHIFT, &entry);
 114.136 +                         IOMMU_EXCLUSION_LIMIT_HIGH_MASK,
 114.137 +                         IOMMU_EXCLUSION_LIMIT_HIGH_SHIFT, &entry);
 114.138      writel(entry, iommu->mmio_base+IOMMU_EXCLUSION_LIMIT_HIGH_OFFSET);
 114.139  
 114.140      set_field_in_reg_u32((u32)addr_lo >> PAGE_SHIFT, 0,
 114.141 -        IOMMU_EXCLUSION_LIMIT_LOW_MASK,
 114.142 -        IOMMU_EXCLUSION_LIMIT_LOW_SHIFT, &entry);
 114.143 +                         IOMMU_EXCLUSION_LIMIT_LOW_MASK,
 114.144 +                         IOMMU_EXCLUSION_LIMIT_LOW_SHIFT, &entry);
 114.145      writel(entry, iommu->mmio_base+IOMMU_EXCLUSION_LIMIT_LOW_OFFSET);
 114.146  
 114.147      addr_lo = iommu->exclusion_base & DMA_32BIT_MASK;
 114.148      addr_hi = iommu->exclusion_base >> 32;
 114.149  
 114.150      set_field_in_reg_u32((u32)addr_hi, 0,
 114.151 -        IOMMU_EXCLUSION_BASE_HIGH_MASK,
 114.152 -        IOMMU_EXCLUSION_BASE_HIGH_SHIFT, &entry);
 114.153 +                         IOMMU_EXCLUSION_BASE_HIGH_MASK,
 114.154 +                         IOMMU_EXCLUSION_BASE_HIGH_SHIFT, &entry);
 114.155      writel(entry, iommu->mmio_base+IOMMU_EXCLUSION_BASE_HIGH_OFFSET);
 114.156  
 114.157      set_field_in_reg_u32((u32)addr_lo >> PAGE_SHIFT, 0,
 114.158 -        IOMMU_EXCLUSION_BASE_LOW_MASK,
 114.159 -        IOMMU_EXCLUSION_BASE_LOW_SHIFT, &entry);
 114.160 +                         IOMMU_EXCLUSION_BASE_LOW_MASK,
 114.161 +                         IOMMU_EXCLUSION_BASE_LOW_SHIFT, &entry);
 114.162  
 114.163      set_field_in_reg_u32(iommu->exclusion_allow_all, entry,
 114.164 -        IOMMU_EXCLUSION_ALLOW_ALL_MASK,
 114.165 -        IOMMU_EXCLUSION_ALLOW_ALL_SHIFT, &entry);
 114.166 +                         IOMMU_EXCLUSION_ALLOW_ALL_MASK,
 114.167 +                         IOMMU_EXCLUSION_ALLOW_ALL_SHIFT, &entry);
 114.168  
 114.169      set_field_in_reg_u32(iommu->exclusion_enable, entry,
 114.170 -        IOMMU_EXCLUSION_RANGE_ENABLE_MASK,
 114.171 -        IOMMU_EXCLUSION_RANGE_ENABLE_SHIFT, &entry);
 114.172 +                         IOMMU_EXCLUSION_RANGE_ENABLE_MASK,
 114.173 +                         IOMMU_EXCLUSION_RANGE_ENABLE_SHIFT, &entry);
 114.174      writel(entry, iommu->mmio_base+IOMMU_EXCLUSION_BASE_LOW_OFFSET);
 114.175  }
 114.176  
 114.177 @@ -184,5 +186,3 @@ void __init enable_iommu(struct amd_iomm
 114.178      set_iommu_translation_control(iommu, IOMMU_CONTROL_ENABLED);
 114.179      printk("AMD IOMMU %d: Enabled\n", nr_amd_iommus);
 114.180  }
 114.181 -
 114.182 -
   115.1 --- a/xen/drivers/passthrough/amd/iommu_map.c	Fri Mar 14 15:07:45 2008 -0600
   115.2 +++ b/xen/drivers/passthrough/amd/iommu_map.c	Thu Mar 20 12:35:40 2008 -0600
   115.3 @@ -19,7 +19,7 @@
   115.4   */
   115.5  
   115.6  #include <xen/sched.h>
   115.7 -#include <asm/hvm/iommu.h>
   115.8 +#include <xen/hvm/iommu.h>
   115.9  #include <asm/amd-iommu.h>
  115.10  #include <asm/hvm/svm/amd-iommu-proto.h>
  115.11  
  115.12 @@ -132,7 +132,8 @@ void flush_command_buffer(struct amd_iom
  115.13      send_iommu_command(iommu, cmd);
  115.14  
  115.15      /* wait for 'ComWaitInt' to signal comp#endifletion? */
  115.16 -    if ( amd_iommu_poll_comp_wait ) {
  115.17 +    if ( amd_iommu_poll_comp_wait )
  115.18 +    {
  115.19          loop_count = amd_iommu_poll_comp_wait;
  115.20          do {
  115.21              status = readl(iommu->mmio_base +
  115.22 @@ -152,8 +153,10 @@ void flush_command_buffer(struct amd_iom
  115.23                     IOMMU_STATUS_MMIO_OFFSET);
  115.24          }
  115.25          else
  115.26 +        {
  115.27              dprintk(XENLOG_WARNING, "AMD IOMMU: Warning:"
  115.28                      " ComWaitInt bit did not assert!\n");
  115.29 +        }
  115.30      }
  115.31  }
  115.32  
  115.33 @@ -234,7 +237,7 @@ static void amd_iommu_set_page_directory
  115.34  }
  115.35  
  115.36  void amd_iommu_set_dev_table_entry(u32 *dte, u64 root_ptr, u16 domain_id,
  115.37 -           u8 sys_mgt, u8 dev_ex, u8 paging_mode)
  115.38 +                                   u8 sys_mgt, u8 dev_ex, u8 paging_mode)
  115.39  {
  115.40      u64 addr_hi, addr_lo;
  115.41      u32 entry;
  115.42 @@ -397,7 +400,7 @@ int amd_iommu_map_page(struct domain *d,
  115.43      spin_lock_irqsave(&hd->mapping_lock, flags);
  115.44  
  115.45      pte = get_pte_from_page_tables(hd->root_table, hd->paging_mode, gfn);
  115.46 -    if ( pte == 0 )
  115.47 +    if ( pte == NULL )
  115.48      {
  115.49          dprintk(XENLOG_ERR,
  115.50                  "AMD IOMMU: Invalid IO pagetable entry gfn = %lx\n", gfn);
  115.51 @@ -428,7 +431,7 @@ int amd_iommu_unmap_page(struct domain *
  115.52      spin_lock_irqsave(&hd->mapping_lock, flags);
  115.53  
  115.54      pte = get_pte_from_page_tables(hd->root_table, hd->paging_mode, gfn);
  115.55 -    if ( pte == 0 )
  115.56 +    if ( pte == NULL )
  115.57      {
  115.58          dprintk(XENLOG_ERR,
  115.59                  "AMD IOMMU: Invalid IO pagetable entry gfn = %lx\n", gfn);
  115.60 @@ -441,7 +444,7 @@ int amd_iommu_unmap_page(struct domain *
  115.61      spin_unlock_irqrestore(&hd->mapping_lock, flags);
  115.62  
  115.63      /* send INVALIDATE_IOMMU_PAGES command */
  115.64 -    for_each_amd_iommu(iommu)
  115.65 +    for_each_amd_iommu ( iommu )
  115.66      {
  115.67          spin_lock_irqsave(&iommu->lock, flags);
  115.68          invalidate_iommu_page(iommu, io_addr, requestor_id);
  115.69 @@ -453,9 +456,9 @@ int amd_iommu_unmap_page(struct domain *
  115.70  }
  115.71  
  115.72  int amd_iommu_reserve_domain_unity_map(
  115.73 -           struct domain *domain,
  115.74 -           unsigned long phys_addr,
  115.75 -           unsigned long size, int iw, int ir)
  115.76 +    struct domain *domain,
  115.77 +    unsigned long phys_addr,
  115.78 +    unsigned long size, int iw, int ir)
  115.79  {
  115.80      unsigned long flags, npages, i;
  115.81      void *pte;
  115.82 @@ -466,17 +469,18 @@ int amd_iommu_reserve_domain_unity_map(
  115.83      spin_lock_irqsave(&hd->mapping_lock, flags);
  115.84      for ( i = 0; i < npages; ++i )
  115.85      {
  115.86 -        pte = get_pte_from_page_tables(hd->root_table,
  115.87 -           hd->paging_mode, phys_addr>>PAGE_SHIFT);
  115.88 -        if ( pte == 0 )
  115.89 +        pte = get_pte_from_page_tables(
  115.90 +            hd->root_table, hd->paging_mode, phys_addr >> PAGE_SHIFT);
  115.91 +        if ( pte == NULL )
  115.92          {
  115.93              dprintk(XENLOG_ERR,
  115.94 -                    "AMD IOMMU: Invalid IO pagetable entry phys_addr = %lx\n", phys_addr);
  115.95 +                    "AMD IOMMU: Invalid IO pagetable entry "
  115.96 +                    "phys_addr = %lx\n", phys_addr);
  115.97              spin_unlock_irqrestore(&hd->mapping_lock, flags);
  115.98              return -EFAULT;
  115.99          }
 115.100          set_page_table_entry_present((u32 *)pte,
 115.101 -           phys_addr, iw, ir);
 115.102 +                                     phys_addr, iw, ir);
 115.103          phys_addr += PAGE_SIZE;
 115.104      }
 115.105      spin_unlock_irqrestore(&hd->mapping_lock, flags);
   116.1 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c	Fri Mar 14 15:07:45 2008 -0600
   116.2 +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c	Thu Mar 20 12:35:40 2008 -0600
   116.3 @@ -168,7 +168,7 @@ int iommu_detect_callback(u8 bus, u8 dev
   116.4      list_add_tail(&iommu->list, &amd_iommu_head);
   116.5  
   116.6      /* allocate resources for this IOMMU */
   116.7 -    if (allocate_iommu_resources(iommu) != 0)
   116.8 +    if ( allocate_iommu_resources(iommu) != 0 )
   116.9          goto error_out;
  116.10  
  116.11      return 0;
  116.12 @@ -208,7 +208,7 @@ static int __init amd_iommu_init(void)
  116.13      }
  116.14  
  116.15      /* assign default values for device entries */
  116.16 -    for ( bdf = 0; bdf < ivrs_bdf_entries; ++bdf )
  116.17 +    for ( bdf = 0; bdf < ivrs_bdf_entries; bdf++ )
  116.18      {
  116.19          ivrs_mappings[bdf].dte_requestor_id = bdf;
  116.20          ivrs_mappings[bdf].dte_sys_mgt_enable =
  116.21 @@ -288,7 +288,8 @@ void amd_iommu_setup_domain_device(
  116.22          sys_mgt = ivrs_mappings[req_id].dte_sys_mgt_enable;
  116.23          dev_ex = ivrs_mappings[req_id].dte_allow_exclusion;
  116.24          amd_iommu_set_dev_table_entry((u32 *)dte, root_ptr,
  116.25 -            req_id, sys_mgt, dev_ex, hd->paging_mode);
  116.26 +                                      req_id, sys_mgt, dev_ex,
  116.27 +                                      hd->paging_mode);
  116.28  
  116.29          invalidate_dev_table_entry(iommu, req_id);
  116.30          flush_command_buffer(iommu);
  116.31 @@ -317,8 +318,8 @@ void __init amd_iommu_setup_dom0_devices
  116.32              {
  116.33                  l = read_pci_config(bus, dev, func, PCI_VENDOR_ID);
  116.34                  /* some broken boards return 0 or ~0 if a slot is empty: */
  116.35 -                if ( l == 0xffffffff || l == 0x00000000 ||
  116.36 -                     l == 0x0000ffff || l == 0xffff0000 )
  116.37 +                if ( (l == 0xffffffff) || (l == 0x00000000) ||
  116.38 +                     (l == 0x0000ffff) || (l == 0xffff0000) )
  116.39                      continue;
  116.40  
  116.41                  pdev = xmalloc(struct pci_dev);
  116.42 @@ -368,22 +369,22 @@ int amd_iommu_detect(void)
  116.43          /* allocate 'ivrs mappings' table */
  116.44          /* note: the table has entries to accomodate all IOMMUs */
  116.45          last_bus = 0;
  116.46 -        for_each_amd_iommu (iommu)
  116.47 -           if (iommu->last_downstream_bus > last_bus)
  116.48 -               last_bus = iommu->last_downstream_bus;
  116.49 +        for_each_amd_iommu ( iommu )
  116.50 +            if ( iommu->last_downstream_bus > last_bus )
  116.51 +                last_bus = iommu->last_downstream_bus;
  116.52  
  116.53          ivrs_bdf_entries = (last_bus + 1) *
  116.54 -                IOMMU_DEV_TABLE_ENTRIES_PER_BUS;
  116.55 +            IOMMU_DEV_TABLE_ENTRIES_PER_BUS;
  116.56          ivrs_mappings = xmalloc_array( struct ivrs_mappings, ivrs_bdf_entries);
  116.57  
  116.58          if ( !ivrs_mappings )
  116.59          {
  116.60              dprintk(XENLOG_ERR, "AMD IOMMU:"
  116.61 -                        " Error allocating IVRS DevMappings table\n");
  116.62 +                    " Error allocating IVRS DevMappings table\n");
  116.63              goto error_out;
  116.64          }
  116.65          memset(ivrs_mappings, 0,
  116.66 -            ivrs_bdf_entries * sizeof(struct ivrs_mappings));
  116.67 +               ivrs_bdf_entries * sizeof(struct ivrs_mappings));
  116.68      }
  116.69  
  116.70      if ( amd_iommu_init() != 0 )
  116.71 @@ -424,6 +425,7 @@ static int allocate_domain_resources(str
  116.72      spin_unlock_irqrestore(&hd->mapping_lock, flags);
  116.73  
  116.74      return 0;
  116.75 +
  116.76   error_out:
  116.77      spin_unlock_irqrestore(&hd->mapping_lock, flags);
  116.78      return -ENOMEM;
  116.79 @@ -433,7 +435,7 @@ static int get_paging_mode(unsigned long
  116.80  {
  116.81      int level = 1;
  116.82  
  116.83 -    BUG_ON ( !max_page );
  116.84 +    BUG_ON(!max_page);
  116.85  
  116.86      if ( entries > max_page )
  116.87          entries = max_page;
  116.88 @@ -441,8 +443,7 @@ static int get_paging_mode(unsigned long
  116.89      while ( entries > PTE_PER_TABLE_SIZE )
  116.90      {
  116.91          entries = PTE_PER_TABLE_ALIGN(entries) >> PTE_PER_TABLE_SHIFT;
  116.92 -        ++level;
  116.93 -        if ( level > 6 )
  116.94 +        if ( ++level > 6 )
  116.95              return -ENOMEM;
  116.96      }
  116.97  
  116.98 @@ -509,7 +510,7 @@ static int reassign_device( struct domai
  116.99      int bdf;
 116.100      unsigned long flags;
 116.101  
 116.102 -    for_each_pdev( source, pdev )
 116.103 +    for_each_pdev ( source, pdev )
 116.104      {
 116.105          if ( (pdev->bus != bus) || (pdev->devfn != devfn) )
 116.106              continue;
 116.107 @@ -522,23 +523,7 @@ static int reassign_device( struct domai
 116.108          iommu = (bdf < ivrs_bdf_entries) ?
 116.109              find_iommu_for_device(bus, pdev->devfn) : NULL;
 116.110  
 116.111 -        if ( iommu )
 116.112 -        {
 116.113 -            amd_iommu_disable_domain_device(source, iommu, bdf);
 116.114 -            /* Move pci device from the source domain to target domain. */
 116.115 -            spin_lock_irqsave(&source_hd->iommu_list_lock, flags);
 116.116 -            spin_lock_irqsave(&target_hd->iommu_list_lock, flags);
 116.117 -            list_move(&pdev->list, &target_hd->pdev_list);
 116.118 -            spin_unlock_irqrestore(&target_hd->iommu_list_lock, flags);
 116.119 -            spin_unlock_irqrestore(&source_hd->iommu_list_lock, flags);
 116.120 -
 116.121 -            amd_iommu_setup_domain_device(target, iommu, bdf);
 116.122 -            gdprintk(XENLOG_INFO ,
 116.123 -                     "AMD IOMMU: reassign %x:%x.%x domain %d -> domain %d\n",
 116.124 -                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
 116.125 -                     source->domain_id, target->domain_id);
 116.126 -        }
 116.127 -        else
 116.128 +        if ( !iommu )
 116.129          {
 116.130              gdprintk(XENLOG_ERR , "AMD IOMMU: fail to find iommu."
 116.131                       " %x:%x.%x cannot be assigned to domain %d\n", 
 116.132 @@ -546,6 +531,20 @@ static int reassign_device( struct domai
 116.133              return -ENODEV;
 116.134          }
 116.135  
 116.136 +        amd_iommu_disable_domain_device(source, iommu, bdf);
 116.137 +        /* Move pci device from the source domain to target domain. */
 116.138 +        spin_lock_irqsave(&source_hd->iommu_list_lock, flags);
 116.139 +        spin_lock_irqsave(&target_hd->iommu_list_lock, flags);
 116.140 +        list_move(&pdev->list, &target_hd->pdev_list);
 116.141 +        spin_unlock_irqrestore(&target_hd->iommu_list_lock, flags);
 116.142 +        spin_unlock_irqrestore(&source_hd->iommu_list_lock, flags);
 116.143 +
 116.144 +        amd_iommu_setup_domain_device(target, iommu, bdf);
 116.145 +        gdprintk(XENLOG_INFO ,
 116.146 +                 "AMD IOMMU: reassign %x:%x.%x domain %d -> domain %d\n",
 116.147 +                 bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
 116.148 +                 source->domain_id, target->domain_id);
 116.149 +
 116.150          break;
 116.151      }
 116.152      return 0;
 116.153 @@ -557,9 +556,10 @@ int amd_iommu_assign_device(struct domai
 116.154      int req_id;
 116.155      req_id = ivrs_mappings[bdf].dte_requestor_id;
 116.156  
 116.157 -    if (ivrs_mappings[req_id].unity_map_enable)
 116.158 +    if ( ivrs_mappings[req_id].unity_map_enable )
 116.159      {
 116.160 -        amd_iommu_reserve_domain_unity_map(d,
 116.161 +        amd_iommu_reserve_domain_unity_map(
 116.162 +            d,
 116.163              ivrs_mappings[req_id].addr_range_start,
 116.164              ivrs_mappings[req_id].addr_range_length,
 116.165              ivrs_mappings[req_id].write_permission,
 116.166 @@ -606,7 +606,7 @@ static void deallocate_next_page_table(v
 116.167              {
 116.168                  deallocate_next_page_table(next_table,
 116.169                                             next_index, next_level);
 116.170 -                ++next_index;
 116.171 +                next_index++;
 116.172              } while (next_index < PTE_PER_TABLE_SIZE);
 116.173          }
 116.174  
 116.175 @@ -622,11 +622,12 @@ static void deallocate_iommu_page_tables
 116.176      if ( hd ->root_table )
 116.177      {
 116.178          index = 0;
 116.179 +
 116.180          do
 116.181          {
 116.182              deallocate_next_page_table(hd->root_table,
 116.183                                         index, hd->paging_mode);
 116.184 -            ++index;
 116.185 +            index++;
 116.186          } while ( index < PTE_PER_TABLE_SIZE );
 116.187  
 116.188          free_xenheap_page(hd ->root_table);
 116.189 @@ -644,7 +645,8 @@ void amd_iommu_domain_destroy(struct dom
 116.190      release_domain_devices(d);
 116.191  }
 116.192  
 116.193 -void amd_iommu_return_device(struct domain *s, struct domain *t, u8 bus, u8 devfn)
 116.194 +void amd_iommu_return_device(
 116.195 +    struct domain *s, struct domain *t, u8 bus, u8 devfn)
 116.196  {
 116.197      pdev_flr(bus, devfn);
 116.198      reassign_device(s, t, bus, devfn);
   117.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   117.2 +++ b/xen/drivers/passthrough/io.c	Thu Mar 20 12:35:40 2008 -0600
   117.3 @@ -0,0 +1,272 @@
   117.4 +/*
   117.5 + * Copyright (c) 2006, Intel Corporation.
   117.6 + *
   117.7 + * This program is free software; you can redistribute it and/or modify it
   117.8 + * under the terms and conditions of the GNU General Public License,
   117.9 + * version 2, as published by the Free Software Foundation.
  117.10 + *
  117.11 + * This program is distributed in the hope it will be useful, but WITHOUT
  117.12 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  117.13 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  117.14 + * more details.
  117.15 + *
  117.16 + * You should have received a copy of the GNU General Public License along with
  117.17 + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  117.18 + * Place - Suite 330, Boston, MA 02111-1307 USA.
  117.19 + *
  117.20 + * Copyright (C) Allen Kay <allen.m.kay@intel.com>
  117.21 + * Copyright (C) Xiaohui Xin <xiaohui.xin@intel.com>
  117.22 + */
  117.23 +
  117.24 +#include <xen/event.h>
  117.25 +#include <xen/iommu.h>
  117.26 +
  117.27 +static void pt_irq_time_out(void *data)
  117.28 +{
  117.29 +    struct hvm_mirq_dpci_mapping *irq_map = data;
  117.30 +    unsigned int guest_gsi, machine_gsi = 0;
  117.31 +    struct hvm_irq_dpci *dpci = irq_map->dom->arch.hvm_domain.irq.dpci;
  117.32 +    struct dev_intx_gsi_link *digl;
  117.33 +    uint32_t device, intx;
  117.34 +
  117.35 +    list_for_each_entry ( digl, &irq_map->digl_list, list )
  117.36 +    {
  117.37 +        guest_gsi = digl->gsi;
  117.38 +        machine_gsi = dpci->girq[guest_gsi].machine_gsi;
  117.39 +        device = digl->device;
  117.40 +        intx = digl->intx;
  117.41 +        hvm_pci_intx_deassert(irq_map->dom, device, intx);
  117.42 +    }
  117.43 +
  117.44 +    clear_bit(machine_gsi, dpci->dirq_mask);
  117.45 +    stop_timer(&dpci->hvm_timer[irq_to_vector(machine_gsi)]);
  117.46 +    spin_lock(&dpci->dirq_lock);
  117.47 +    dpci->mirq[machine_gsi].pending = 0;
  117.48 +    spin_unlock(&dpci->dirq_lock);
  117.49 +    pirq_guest_eoi(irq_map->dom, machine_gsi);
  117.50 +}
  117.51 +
  117.52 +int pt_irq_create_bind_vtd(
  117.53 +    struct domain *d, xen_domctl_bind_pt_irq_t *pt_irq_bind)
  117.54 +{
  117.55 +    struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
  117.56 +    uint32_t machine_gsi, guest_gsi;
  117.57 +    uint32_t device, intx, link;
  117.58 +    struct dev_intx_gsi_link *digl;
  117.59 +
  117.60 +    if ( hvm_irq_dpci == NULL )
  117.61 +    {
  117.62 +        hvm_irq_dpci = xmalloc(struct hvm_irq_dpci);
  117.63 +        if ( hvm_irq_dpci == NULL )
  117.64 +            return -ENOMEM;
  117.65 +
  117.66 +        memset(hvm_irq_dpci, 0, sizeof(*hvm_irq_dpci));
  117.67 +        spin_lock_init(&hvm_irq_dpci->dirq_lock);
  117.68 +        for ( int i = 0; i < NR_IRQS; i++ )
  117.69 +            INIT_LIST_HEAD(&hvm_irq_dpci->mirq[i].digl_list);
  117.70 +
  117.71 +        if ( cmpxchg((unsigned long *)&d->arch.hvm_domain.irq.dpci,
  117.72 +                     0, (unsigned long)hvm_irq_dpci) != 0 )
  117.73 +            xfree(hvm_irq_dpci);
  117.74 +
  117.75 +        hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
  117.76 +    }
  117.77 +
  117.78 +    machine_gsi = pt_irq_bind->machine_irq;
  117.79 +    device = pt_irq_bind->u.pci.device;
  117.80 +    intx = pt_irq_bind->u.pci.intx;
  117.81 +    guest_gsi = hvm_pci_intx_gsi(device, intx);
  117.82 +    link = hvm_pci_intx_link(device, intx);
  117.83 +    hvm_irq_dpci->link_cnt[link]++;
  117.84 +
  117.85 +    digl = xmalloc(struct dev_intx_gsi_link);
  117.86 +    if ( !digl )
  117.87 +        return -ENOMEM;
  117.88 +
  117.89 +    digl->device = device;
  117.90 +    digl->intx = intx;
  117.91 +    digl->gsi = guest_gsi;
  117.92 +    digl->link = link;
  117.93 +    list_add_tail(&digl->list,
  117.94 +                  &hvm_irq_dpci->mirq[machine_gsi].digl_list);
  117.95 +
  117.96 +    hvm_irq_dpci->girq[guest_gsi].valid = 1;
  117.97 +    hvm_irq_dpci->girq[guest_gsi].device = device;
  117.98 +    hvm_irq_dpci->girq[guest_gsi].intx = intx;
  117.99 +    hvm_irq_dpci->girq[guest_gsi].machine_gsi = machine_gsi;
 117.100 +
 117.101 +    /* Bind the same mirq once in the same domain */
 117.102 +    if ( !hvm_irq_dpci->mirq[machine_gsi].valid )
 117.103 +    {
 117.104 +        hvm_irq_dpci->mirq[machine_gsi].valid = 1;
 117.105 +        hvm_irq_dpci->mirq[machine_gsi].dom = d;
 117.106 +
 117.107 +        init_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(machine_gsi)],
 117.108 +                   pt_irq_time_out, &hvm_irq_dpci->mirq[machine_gsi], 0);
 117.109 +        /* Deal with gsi for legacy devices */
 117.110 +        pirq_guest_bind(d->vcpu[0], machine_gsi, BIND_PIRQ__WILL_SHARE);
 117.111 +    }
 117.112 +
 117.113 +    gdprintk(XENLOG_INFO VTDPREFIX,
 117.114 +             "VT-d irq bind: m_irq = %x device = %x intx = %x\n",
 117.115 +             machine_gsi, device, intx);
 117.116 +    return 0;
 117.117 +}
 117.118 +
 117.119 +int pt_irq_destroy_bind_vtd(
 117.120 +    struct domain *d, xen_domctl_bind_pt_irq_t *pt_irq_bind)
 117.121 +{
 117.122 +    struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
 117.123 +    uint32_t machine_gsi, guest_gsi;
 117.124 +    uint32_t device, intx, link;
 117.125 +    struct list_head *digl_list, *tmp;
 117.126 +    struct dev_intx_gsi_link *digl;
 117.127 +
 117.128 +    if ( hvm_irq_dpci == NULL )
 117.129 +        return 0;
 117.130 +
 117.131 +    machine_gsi = pt_irq_bind->machine_irq;
 117.132 +    device = pt_irq_bind->u.pci.device;
 117.133 +    intx = pt_irq_bind->u.pci.intx;
 117.134 +    guest_gsi = hvm_pci_intx_gsi(device, intx);
 117.135 +    link = hvm_pci_intx_link(device, intx);
 117.136 +    hvm_irq_dpci->link_cnt[link]--;
 117.137 +
 117.138 +    gdprintk(XENLOG_INFO,
 117.139 +            "pt_irq_destroy_bind_vtd: machine_gsi=%d, guest_gsi=%d, device=%d, intx=%d.\n",
 117.140 +            machine_gsi, guest_gsi, device, intx);
 117.141 +    memset(&hvm_irq_dpci->girq[guest_gsi], 0, sizeof(struct hvm_girq_dpci_mapping));
 117.142 +
 117.143 +    /* clear the mirq info */
 117.144 +    if ( hvm_irq_dpci->mirq[machine_gsi].valid )
 117.145 +    {
 117.146 +
 117.147 +        list_for_each_safe ( digl_list, tmp,
 117.148 +                &hvm_irq_dpci->mirq[machine_gsi].digl_list )
 117.149 +        {
 117.150 +            digl = list_entry(digl_list,
 117.151 +                    struct dev_intx_gsi_link, list);
 117.152 +            if ( digl->device == device &&
 117.153 +                 digl->intx   == intx &&
 117.154 +                 digl->link   == link &&
 117.155 +                 digl->gsi    == guest_gsi )
 117.156 +            {
 117.157 +                list_del(&digl->list);
 117.158 +                xfree(digl);
 117.159 +            }
 117.160 +        }
 117.161 +
 117.162 +        if ( list_empty(&hvm_irq_dpci->mirq[machine_gsi].digl_list) )
 117.163 +        {
 117.164 +            pirq_guest_unbind(d, machine_gsi);
 117.165 +            kill_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(machine_gsi)]);
 117.166 +            hvm_irq_dpci->mirq[machine_gsi].dom   = NULL;
 117.167 +            hvm_irq_dpci->mirq[machine_gsi].valid = 0;
 117.168 +        }
 117.169 +    }
 117.170 +
 117.171 +    gdprintk(XENLOG_INFO,
 117.172 +             "XEN_DOMCTL_irq_unmapping: m_irq = %x device = %x intx = %x\n",
 117.173 +             machine_gsi, device, intx);
 117.174 +
 117.175 +    return 0;
 117.176 +}
 117.177 +
 117.178 +int hvm_do_IRQ_dpci(struct domain *d, unsigned int mirq)
 117.179 +{
 117.180 +    struct hvm_irq *hvm_irq = &d->arch.hvm_domain.irq;
 117.181 +
 117.182 +    if ( !iommu_enabled || (d == dom0) || (hvm_irq->dpci == NULL) ||
 117.183 +         !hvm_irq->dpci->mirq[mirq].valid )
 117.184 +        return 0;
 117.185 +
 117.186 +    /*
 117.187 +     * Set a timer here to avoid situations where the IRQ line is shared, and
 117.188 +     * the device belonging to the pass-through guest is not yet active. In
 117.189 +     * this case the guest may not pick up the interrupt (e.g., masked at the
 117.190 +     * PIC) and we need to detect that.
 117.191 +     */
 117.192 +    set_bit(mirq, hvm_irq->dpci->dirq_mask);
 117.193 +    set_timer(&hvm_irq->dpci->hvm_timer[irq_to_vector(mirq)],
 117.194 +              NOW() + PT_IRQ_TIME_OUT);
 117.195 +    vcpu_kick(d->vcpu[0]);
 117.196 +
 117.197 +    return 1;
 117.198 +}
 117.199 +
 117.200 +static void hvm_dpci_isairq_eoi(struct domain *d, unsigned int isairq)
 117.201 +{
 117.202 +    struct hvm_irq *hvm_irq = &d->arch.hvm_domain.irq;
 117.203 +    struct hvm_irq_dpci *dpci = hvm_irq->dpci;
 117.204 +    struct dev_intx_gsi_link *digl, *tmp;
 117.205 +    int i;
 117.206 +
 117.207 +    ASSERT(isairq < NR_ISAIRQS);
 117.208 +    if ( !iommu_enabled || !dpci ||
 117.209 +         !test_bit(isairq, dpci->isairq_map) )
 117.210 +        return;
 117.211 +
 117.212 +    /* Multiple mirq may be mapped to one isa irq */
 117.213 +    for ( i = 0; i < NR_IRQS; i++ )
 117.214 +    {
 117.215 +        if ( !dpci->mirq[i].valid )
 117.216 +            continue;
 117.217 +
 117.218 +        list_for_each_entry_safe ( digl, tmp,
 117.219 +            &dpci->mirq[i].digl_list, list )
 117.220 +        {
 117.221 +            if ( hvm_irq->pci_link.route[digl->link] == isairq )
 117.222 +            {
 117.223 +                hvm_pci_intx_deassert(d, digl->device, digl->intx);
 117.224 +                spin_lock(&dpci->dirq_lock);
 117.225 +                if ( --dpci->mirq[i].pending == 0 )
 117.226 +                {
 117.227 +                    spin_unlock(&dpci->dirq_lock);
 117.228 +                    gdprintk(XENLOG_INFO VTDPREFIX,
 117.229 +                             "hvm_dpci_isairq_eoi:: mirq = %x\n", i);
 117.230 +                    stop_timer(&dpci->hvm_timer[irq_to_vector(i)]);
 117.231 +                    pirq_guest_eoi(d, i);
 117.232 +                }
 117.233 +                else
 117.234 +                    spin_unlock(&dpci->dirq_lock);
 117.235 +            }
 117.236 +        }
 117.237 +    }
 117.238 +}
 117.239 +
 117.240 +void hvm_dpci_eoi(struct domain *d, unsigned int guest_gsi,
 117.241 +                  union vioapic_redir_entry *ent)
 117.242 +{
 117.243 +    struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
 117.244 +    uint32_t device, intx, machine_gsi;
 117.245 +
 117.246 +    if ( !iommu_enabled || (hvm_irq_dpci == NULL) ||
 117.247 +         (guest_gsi >= NR_ISAIRQS &&
 117.248 +          !hvm_irq_dpci->girq[guest_gsi].valid) )
 117.249 +        return;
 117.250 +
 117.251 +    if ( guest_gsi < NR_ISAIRQS )
 117.252 +    {
 117.253 +        hvm_dpci_isairq_eoi(d, guest_gsi);
 117.254 +        return;
 117.255 +    }
 117.256 +
 117.257 +    machine_gsi = hvm_irq_dpci->girq[guest_gsi].machine_gsi;
 117.258 +    device = hvm_irq_dpci->girq[guest_gsi].device;
 117.259 +    intx = hvm_irq_dpci->girq[guest_gsi].intx;
 117.260 +    hvm_pci_intx_deassert(d, device, intx);
 117.261 +
 117.262 +    spin_lock(&hvm_irq_dpci->dirq_lock);
 117.263 +    if ( --hvm_irq_dpci->mirq[machine_gsi].pending == 0 )
 117.264 +    {
 117.265 +        spin_unlock(&hvm_irq_dpci->dirq_lock);
 117.266 +
 117.267 +        gdprintk(XENLOG_INFO VTDPREFIX,
 117.268 +                 "hvm_dpci_eoi:: mirq = %x\n", machine_gsi);
 117.269 +        stop_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(machine_gsi)]);
 117.270 +        if ( (ent == NULL) || !ent->fields.mask )
 117.271 +            pirq_guest_eoi(d, machine_gsi);
 117.272 +    }
 117.273 +    else
 117.274 +        spin_unlock(&hvm_irq_dpci->dirq_lock);
 117.275 +}
   118.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   118.2 +++ b/xen/drivers/passthrough/iommu.c	Thu Mar 20 12:35:40 2008 -0600
   118.3 @@ -0,0 +1,136 @@
   118.4 +/*
   118.5 + * This program is free software; you can redistribute it and/or modify it
   118.6 + * under the terms and conditions of the GNU General Public License,
   118.7 + * version 2, as published by the Free Software Foundation.
   118.8 + *
   118.9 + * This program is distributed in the hope it will be useful, but WITHOUT
  118.10 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  118.11 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  118.12 + * more details.
  118.13 + *
  118.14 + * You should have received a copy of the GNU General Public License along with
  118.15 + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  118.16 + * Place - Suite 330, Boston, MA 02111-1307 USA.
  118.17 + */
  118.18 +
  118.19 +#include <xen/sched.h>
  118.20 +#include <xen/iommu.h>
  118.21 +
  118.22 +extern struct iommu_ops intel_iommu_ops;
  118.23 +extern struct iommu_ops amd_iommu_ops;
  118.24 +
  118.25 +int iommu_domain_init(struct domain *domain)
  118.26 +{
  118.27 +    struct hvm_iommu *hd = domain_hvm_iommu(domain);
  118.28 +
  118.29 +    spin_lock_init(&hd->mapping_lock);
  118.30 +    spin_lock_init(&hd->iommu_list_lock);
  118.31 +    INIT_LIST_HEAD(&hd->pdev_list);
  118.32 +    INIT_LIST_HEAD(&hd->g2m_ioport_list);
  118.33 +
  118.34 +    if ( !iommu_enabled )
  118.35 +        return 0;
  118.36 +
  118.37 +    switch ( boot_cpu_data.x86_vendor )
  118.38 +    {
  118.39 +    case X86_VENDOR_INTEL:
  118.40 +        hd->platform_ops = &intel_iommu_ops;
  118.41 +        break;
  118.42 +    case X86_VENDOR_AMD:
  118.43 +        hd->platform_ops = &amd_iommu_ops;
  118.44 +        break;
  118.45 +    default:
  118.46 +        BUG();
  118.47 +    }
  118.48 +
  118.49 +    return hd->platform_ops->init(domain);
  118.50 +}
  118.51 +
  118.52 +int assign_device(struct domain *d, u8 bus, u8 devfn)
  118.53 +{
  118.54 +    struct hvm_iommu *hd = domain_hvm_iommu(d);
  118.55 +
  118.56 +    if ( !iommu_enabled || !hd->platform_ops )
  118.57 +        return 0;
  118.58 +
  118.59 +    return hd->platform_ops->assign_device(d, bus, devfn);
  118.60 +}
  118.61 +
  118.62 +void iommu_domain_destroy(struct domain *d)
  118.63 +{
  118.64 +    struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
  118.65 +    uint32_t i;
  118.66 +    struct hvm_iommu *hd  = domain_hvm_iommu(d);
  118.67 +    struct list_head *ioport_list, *digl_list, *tmp;
  118.68 +    struct g2m_ioport *ioport;
  118.69 +    struct dev_intx_gsi_link *digl;
  118.70 +
  118.71 +    if ( !iommu_enabled || !hd->platform_ops )
  118.72 +        return;
  118.73 +
  118.74 +    if ( hvm_irq_dpci != NULL )
  118.75 +    {
  118.76 +        for ( i = 0; i < NR_IRQS; i++ )
  118.77 +        {
  118.78 +            if ( !hvm_irq_dpci->mirq[i].valid )
  118.79 +                continue;
  118.80 +
  118.81 +            pirq_guest_unbind(d, i);
  118.82 +            kill_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(i)]);
  118.83 +
  118.84 +            list_for_each_safe ( digl_list, tmp,
  118.85 +                                 &hvm_irq_dpci->mirq[i].digl_list )
  118.86 +            {
  118.87 +                digl = list_entry(digl_list,
  118.88 +                                  struct dev_intx_gsi_link, list);
  118.89 +                list_del(&digl->list);
  118.90 +                xfree(digl);
  118.91 +            }
  118.92 +        }
  118.93 +
  118.94 +        d->arch.hvm_domain.irq.dpci = NULL;
  118.95 +        xfree(hvm_irq_dpci);
  118.96 +    }
  118.97 +
  118.98 +    if ( hd )
  118.99 +    {
 118.100 +        list_for_each_safe ( ioport_list, tmp, &hd->g2m_ioport_list )
 118.101 +        {
 118.102 +            ioport = list_entry(ioport_list, struct g2m_ioport, list);
 118.103 +            list_del(&ioport->list);
 118.104 +            xfree(ioport);
 118.105 +        }
 118.106 +    }
 118.107 +
 118.108 +    return hd->platform_ops->teardown(d);
 118.109 +}
 118.110 +
 118.111 +int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn)
 118.112 +{
 118.113 +    struct hvm_iommu *hd = domain_hvm_iommu(d);
 118.114 +
 118.115 +    if ( !iommu_enabled || !hd->platform_ops )
 118.116 +        return 0;
 118.117 +
 118.118 +    return hd->platform_ops->map_page(d, gfn, mfn);
 118.119 +}
 118.120 +
 118.121 +int iommu_unmap_page(struct domain *d, unsigned long gfn)
 118.122 +{
 118.123 +    struct hvm_iommu *hd = domain_hvm_iommu(d);
 118.124 +
 118.125 +    if ( !iommu_enabled || !hd->platform_ops )
 118.126 +        return 0;
 118.127 +
 118.128 +    return hd->platform_ops->unmap_page(d, gfn);
 118.129 +}
 118.130 +
 118.131 +void deassign_device(struct domain *d, u8 bus, u8 devfn)
 118.132 +{
 118.133 +    struct hvm_iommu *hd = domain_hvm_iommu(d);
 118.134 +
 118.135 +    if ( !iommu_enabled || !hd->platform_ops )
 118.136 +        return;
 118.137 +
 118.138 +    return hd->platform_ops->reassign_device(d, dom0, bus, devfn);
 118.139 +}
   119.1 --- a/xen/drivers/passthrough/vtd/Makefile	Fri Mar 14 15:07:45 2008 -0600
   119.2 +++ b/xen/drivers/passthrough/vtd/Makefile	Thu Mar 20 12:35:40 2008 -0600
   119.3 @@ -1,6 +1,5 @@
   119.4  obj-y += iommu.o
   119.5  obj-y += dmar.o
   119.6  obj-y += utils.o
   119.7 -obj-y += io.o
   119.8  obj-y += qinval.o
   119.9  obj-y += intremap.o
   120.1 --- a/xen/drivers/passthrough/vtd/dmar.c	Fri Mar 14 15:07:45 2008 -0600
   120.2 +++ b/xen/drivers/passthrough/vtd/dmar.c	Thu Mar 20 12:35:40 2008 -0600
   120.3 @@ -555,13 +555,13 @@ static int __init acpi_parse_dmar(unsign
   120.4          return -ENODEV;
   120.5      }
   120.6  
   120.7 -    if ( !dmar->haw )
   120.8 +    if ( !dmar->width )
   120.9      {
  120.10 -        dprintk(XENLOG_WARNING VTDPREFIX, "Zero: Invalid DMAR haw\n");
  120.11 +        dprintk(XENLOG_WARNING VTDPREFIX, "Zero: Invalid DMAR width\n");
  120.12          return -EINVAL;
  120.13      }
  120.14  
  120.15 -    dmar_host_address_width = dmar->haw;
  120.16 +    dmar_host_address_width = dmar->width;
  120.17      dprintk(XENLOG_INFO VTDPREFIX, "Host address width %d\n",
  120.18              dmar_host_address_width);
  120.19  
   121.1 --- a/xen/drivers/passthrough/vtd/dmar.h	Fri Mar 14 15:07:45 2008 -0600
   121.2 +++ b/xen/drivers/passthrough/vtd/dmar.h	Thu Mar 20 12:35:40 2008 -0600
   121.3 @@ -22,7 +22,7 @@
   121.4  #define _DMAR_H_
   121.5  
   121.6  #include <xen/list.h>
   121.7 -#include <asm/iommu.h>
   121.8 +#include <xen/iommu.h>
   121.9  
  121.10  extern u8 dmar_host_address_width;
  121.11  
  121.12 @@ -100,5 +100,6 @@ struct acpi_rmrr_unit * acpi_find_matche
  121.13  
  121.14  int vtd_hw_check(void);
  121.15  void disable_pmr(struct iommu *iommu);
  121.16 +int is_usb_device(struct pci_dev *pdev);
  121.17  
  121.18  #endif // _DMAR_H_
   122.1 --- a/xen/drivers/passthrough/vtd/extern.h	Fri Mar 14 15:07:45 2008 -0600
   122.2 +++ b/xen/drivers/passthrough/vtd/extern.h	Thu Mar 20 12:35:40 2008 -0600
   122.3 @@ -42,8 +42,6 @@ int queue_invalidate_iec(struct iommu *i
   122.4  int invalidate_sync(struct iommu *iommu);
   122.5  int iommu_flush_iec_global(struct iommu *iommu);
   122.6  int iommu_flush_iec_index(struct iommu *iommu, u8 im, u16 iidx);
   122.7 -void print_iommu_regs(struct acpi_drhd_unit *drhd);
   122.8 -int vtd_hw_check(void);
   122.9  struct iommu * ioapic_to_iommu(unsigned int apic_id);
  122.10  struct acpi_drhd_unit * ioapic_to_drhd(unsigned int apic_id);
  122.11  void clear_fault_bits(struct iommu *iommu);
   123.1 --- a/xen/drivers/passthrough/vtd/intremap.c	Fri Mar 14 15:07:45 2008 -0600
   123.2 +++ b/xen/drivers/passthrough/vtd/intremap.c	Thu Mar 20 12:35:40 2008 -0600
   123.3 @@ -18,28 +18,10 @@
   123.4   * Copyright (C) Xiaohui Xin <xiaohui.xin@intel.com>
   123.5   */
   123.6  
   123.7 -#include <xen/config.h>
   123.8 -#include <xen/lib.h>
   123.9 -#include <xen/init.h>
  123.10  #include <xen/irq.h>
  123.11 -#include <xen/delay.h>
  123.12  #include <xen/sched.h>
  123.13 -#include <xen/acpi.h>
  123.14 -#include <xen/keyhandler.h>
  123.15 -#include <xen/spinlock.h>
  123.16 -#include <asm/io.h>
  123.17 -#include <asm/mc146818rtc.h>
  123.18 -#include <asm/smp.h>
  123.19 -#include <asm/desc.h>
  123.20 -#include <mach_apic.h>
  123.21 -#include <io_ports.h>
  123.22 -
  123.23 -#include <xen/spinlock.h>
  123.24 -#include <xen/xmalloc.h>
  123.25 -#include <xen/domain_page.h>
  123.26 -#include <asm/delay.h>
  123.27 -#include <asm/string.h>
  123.28 -#include <asm/iommu.h>
  123.29 +#include <xen/iommu.h>
  123.30 +#include "iommu.h"
  123.31  #include "dmar.h"
  123.32  #include "vtd.h"
  123.33  #include "../pci-direct.h"
  123.34 @@ -172,7 +154,7 @@ io_apic_read_remap_rte(
  123.35      struct iommu *iommu = ioapic_to_iommu(mp_ioapics[apic].mpc_apicid);
  123.36      struct ir_ctrl *ir_ctrl = iommu_ir_ctrl(iommu);
  123.37  
  123.38 -    if ( !iommu || !(ir_ctrl->iremap) )
  123.39 +    if ( !iommu || !ir_ctrl || !(ir_ctrl->iremap) )
  123.40      {
  123.41          *IO_APIC_BASE(apic) = reg;
  123.42          return *(IO_APIC_BASE(apic)+4);
  123.43 @@ -218,7 +200,7 @@ io_apic_write_remap_rte(
  123.44      struct iommu *iommu = ioapic_to_iommu(mp_ioapics[apic].mpc_apicid);
  123.45      struct ir_ctrl *ir_ctrl = iommu_ir_ctrl(iommu);
  123.46  
  123.47 -    if ( !iommu || !(ir_ctrl->iremap) )
  123.48 +    if ( !iommu || !ir_ctrl || !(ir_ctrl->iremap) )
  123.49      {
  123.50          *IO_APIC_BASE(apic) = reg;
  123.51          *(IO_APIC_BASE(apic)+4) = value;
   124.1 --- a/xen/drivers/passthrough/vtd/io.c	Fri Mar 14 15:07:45 2008 -0600
   124.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   124.3 @@ -1,296 +0,0 @@
   124.4 -/*
   124.5 - * Copyright (c) 2006, Intel Corporation.
   124.6 - *
   124.7 - * This program is free software; you can redistribute it and/or modify it
   124.8 - * under the terms and conditions of the GNU General Public License,
   124.9 - * version 2, as published by the Free Software Foundation.
  124.10 - *
  124.11 - * This program is distributed in the hope it will be useful, but WITHOUT
  124.12 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  124.13 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  124.14 - * more details.
  124.15 - *
  124.16 - * You should have received a copy of the GNU General Public License along with
  124.17 - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  124.18 - * Place - Suite 330, Boston, MA 02111-1307 USA.
  124.19 - *
  124.20 - * Copyright (C) Allen Kay <allen.m.kay@intel.com>
  124.21 - * Copyright (C) Xiaohui Xin <xiaohui.xin@intel.com>
  124.22 - */
  124.23 -
  124.24 -#include <xen/init.h>
  124.25 -#include <xen/config.h>
  124.26 -#include <xen/init.h>
  124.27 -#include <xen/mm.h>
  124.28 -#include <xen/lib.h>
  124.29 -#include <xen/errno.h>
  124.30 -#include <xen/trace.h>
  124.31 -#include <xen/event.h>
  124.32 -#include <xen/hypercall.h>
  124.33 -#include <asm/current.h>
  124.34 -#include <asm/cpufeature.h>
  124.35 -#include <asm/processor.h>
  124.36 -#include <asm/msr.h>
  124.37 -#include <asm/apic.h>
  124.38 -#include <asm/paging.h>
  124.39 -#include <asm/shadow.h>
  124.40 -#include <asm/p2m.h>
  124.41 -#include <asm/hvm/hvm.h>
  124.42 -#include <asm/hvm/support.h>
  124.43 -#include <asm/hvm/vpt.h>
  124.44 -#include <asm/hvm/vpic.h>
  124.45 -#include <asm/hvm/vlapic.h>
  124.46 -#include <public/sched.h>
  124.47 -#include <xen/iocap.h>
  124.48 -#include <public/hvm/ioreq.h>
  124.49 -#include <public/domctl.h>
  124.50 -
  124.51 -static void pt_irq_time_out(void *data)
  124.52 -{
  124.53 -    struct hvm_mirq_dpci_mapping *irq_map = data;
  124.54 -    unsigned int guest_gsi, machine_gsi = 0;
  124.55 -    struct hvm_irq_dpci *dpci = irq_map->dom->arch.hvm_domain.irq.dpci;
  124.56 -    struct dev_intx_gsi_link *digl;
  124.57 -    uint32_t device, intx;
  124.58 -
  124.59 -    list_for_each_entry ( digl, &irq_map->digl_list, list )
  124.60 -    {
  124.61 -        guest_gsi = digl->gsi;
  124.62 -        machine_gsi = dpci->girq[guest_gsi].machine_gsi;
  124.63 -        device = digl->device;
  124.64 -        intx = digl->intx;
  124.65 -        hvm_pci_intx_deassert(irq_map->dom, device, intx);
  124.66 -    }
  124.67 -
  124.68 -    clear_bit(machine_gsi, dpci->dirq_mask);
  124.69 -    stop_timer(&dpci->hvm_timer[irq_to_vector(machine_gsi)]);
  124.70 -    spin_lock(&dpci->dirq_lock);
  124.71 -    dpci->mirq[machine_gsi].pending = 0;
  124.72 -    spin_unlock(&dpci->dirq_lock);
  124.73 -    pirq_guest_eoi(irq_map->dom, machine_gsi);
  124.74 -}
  124.75 -
  124.76 -int pt_irq_create_bind_vtd(
  124.77 -    struct domain *d, xen_domctl_bind_pt_irq_t *pt_irq_bind)
  124.78 -{
  124.79 -    struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
  124.80 -    uint32_t machine_gsi, guest_gsi;
  124.81 -    uint32_t device, intx, link;
  124.82 -    struct dev_intx_gsi_link *digl;
  124.83 -
  124.84 -    if ( hvm_irq_dpci == NULL )
  124.85 -    {
  124.86 -        hvm_irq_dpci = xmalloc(struct hvm_irq_dpci);
  124.87 -        if ( hvm_irq_dpci == NULL )
  124.88 -            return -ENOMEM;
  124.89 -
  124.90 -        memset(hvm_irq_dpci, 0, sizeof(*hvm_irq_dpci));
  124.91 -        spin_lock_init(&hvm_irq_dpci->dirq_lock);
  124.92 -        for ( int i = 0; i < NR_IRQS; i++ )
  124.93 -            INIT_LIST_HEAD(&hvm_irq_dpci->mirq[i].digl_list);
  124.94 -
  124.95 -        if ( cmpxchg((unsigned long *)&d->arch.hvm_domain.irq.dpci,
  124.96 -                     0, (unsigned long)hvm_irq_dpci) != 0 )
  124.97 -            xfree(hvm_irq_dpci);
  124.98 -
  124.99 -        hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
 124.100 -    }
 124.101 -
 124.102 -    machine_gsi = pt_irq_bind->machine_irq;
 124.103 -    device = pt_irq_bind->u.pci.device;
 124.104 -    intx = pt_irq_bind->u.pci.intx;
 124.105 -    guest_gsi = hvm_pci_intx_gsi(device, intx);
 124.106 -    link = hvm_pci_intx_link(device, intx);
 124.107 -    hvm_irq_dpci->link_cnt[link]++;
 124.108 -
 124.109 -    digl = xmalloc(struct dev_intx_gsi_link);
 124.110 -    if ( !digl )
 124.111 -        return -ENOMEM;
 124.112 -
 124.113 -    digl->device = device;
 124.114 -    digl->intx = intx;
 124.115 -    digl->gsi = guest_gsi;
 124.116 -    digl->link = link;
 124.117 -    list_add_tail(&digl->list,
 124.118 -                  &hvm_irq_dpci->mirq[machine_gsi].digl_list);
 124.119 -
 124.120 -    hvm_irq_dpci->girq[guest_gsi].valid = 1;
 124.121 -    hvm_irq_dpci->girq[guest_gsi].device = device;
 124.122 -    hvm_irq_dpci->girq[guest_gsi].intx = intx;
 124.123 -    hvm_irq_dpci->girq[guest_gsi].machine_gsi = machine_gsi;
 124.124 -
 124.125 -    /* Bind the same mirq once in the same domain */
 124.126 -    if ( !hvm_irq_dpci->mirq[machine_gsi].valid )
 124.127 -    {
 124.128 -        hvm_irq_dpci->mirq[machine_gsi].valid = 1;
 124.129 -        hvm_irq_dpci->mirq[machine_gsi].dom = d;
 124.130 -
 124.131 -        init_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(machine_gsi)],
 124.132 -                   pt_irq_time_out, &hvm_irq_dpci->mirq[machine_gsi], 0);
 124.133 -        /* Deal with gsi for legacy devices */
 124.134 -        pirq_guest_bind(d->vcpu[0], machine_gsi, BIND_PIRQ__WILL_SHARE);
 124.135 -    }
 124.136 -
 124.137 -    gdprintk(XENLOG_INFO VTDPREFIX,
 124.138 -             "VT-d irq bind: m_irq = %x device = %x intx = %x\n",
 124.139 -             machine_gsi, device, intx);
 124.140 -    return 0;
 124.141 -}
 124.142 -
 124.143 -int pt_irq_destroy_bind_vtd(
 124.144 -    struct domain *d, xen_domctl_bind_pt_irq_t *pt_irq_bind)
 124.145 -{
 124.146 -    struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
 124.147 -    uint32_t machine_gsi, guest_gsi;
 124.148 -    uint32_t device, intx, link;
 124.149 -    struct list_head *digl_list, *tmp;
 124.150 -    struct dev_intx_gsi_link *digl;
 124.151 -
 124.152 -    if ( hvm_irq_dpci == NULL )
 124.153 -        return 0;
 124.154 -
 124.155 -    machine_gsi = pt_irq_bind->machine_irq;
 124.156 -    device = pt_irq_bind->u.pci.device;
 124.157 -    intx = pt_irq_bind->u.pci.intx;
 124.158 -    guest_gsi = hvm_pci_intx_gsi(device, intx);
 124.159 -    link = hvm_pci_intx_link(device, intx);
 124.160 -    hvm_irq_dpci->link_cnt[link]--;
 124.161 -
 124.162 -    gdprintk(XENLOG_INFO,
 124.163 -            "pt_irq_destroy_bind_vtd: machine_gsi=%d, guest_gsi=%d, device=%d, intx=%d.\n",
 124.164 -            machine_gsi, guest_gsi, device, intx);
 124.165 -    memset(&hvm_irq_dpci->girq[guest_gsi], 0, sizeof(struct hvm_girq_dpci_mapping));
 124.166 -
 124.167 -    /* clear the mirq info */
 124.168 -    if ( hvm_irq_dpci->mirq[machine_gsi].valid )
 124.169 -    {
 124.170 -
 124.171 -        list_for_each_safe ( digl_list, tmp,
 124.172 -                &hvm_irq_dpci->mirq[machine_gsi].digl_list )
 124.173 -        {
 124.174 -            digl = list_entry(digl_list,
 124.175 -                    struct dev_intx_gsi_link, list);
 124.176 -            if ( digl->device == device &&
 124.177 -                 digl->intx   == intx &&
 124.178 -                 digl->link   == link &&
 124.179 -                 digl->gsi    == guest_gsi )
 124.180 -            {
 124.181 -                list_del(&digl->list);
 124.182 -                xfree(digl);
 124.183 -            }
 124.184 -        }
 124.185 -
 124.186 -        if ( list_empty(&hvm_irq_dpci->mirq[machine_gsi].digl_list) )
 124.187 -        {
 124.188 -            pirq_guest_unbind(d, machine_gsi);
 124.189 -            kill_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(machine_gsi)]);
 124.190 -            hvm_irq_dpci->mirq[machine_gsi].dom   = NULL;
 124.191 -            hvm_irq_dpci->mirq[machine_gsi].valid = 0;
 124.192 -        }
 124.193 -    }
 124.194 -
 124.195 -    gdprintk(XENLOG_INFO,
 124.196 -             "XEN_DOMCTL_irq_unmapping: m_irq = %x device = %x intx = %x\n",
 124.197 -             machine_gsi, device, intx);
 124.198 -
 124.199 -    return 0;
 124.200 -}
 124.201 -
 124.202 -int hvm_do_IRQ_dpci(struct domain *d, unsigned int mirq)
 124.203 -{
 124.204 -    struct hvm_irq *hvm_irq = &d->arch.hvm_domain.irq;
 124.205 -
 124.206 -    if ( !iommu_enabled || (d == dom0) || (hvm_irq->dpci == NULL) ||
 124.207 -         !hvm_irq->dpci->mirq[mirq].valid )
 124.208 -        return 0;
 124.209 -
 124.210 -    /*
 124.211 -     * Set a timer here to avoid situations where the IRQ line is shared, and
 124.212 -     * the device belonging to the pass-through guest is not yet active. In
 124.213 -     * this case the guest may not pick up the interrupt (e.g., masked at the
 124.214 -     * PIC) and we need to detect that.
 124.215 -     */
 124.216 -    set_bit(mirq, hvm_irq->dpci->dirq_mask);
 124.217 -    set_timer(&hvm_irq->dpci->hvm_timer[irq_to_vector(mirq)],
 124.218 -              NOW() + PT_IRQ_TIME_OUT);
 124.219 -    vcpu_kick(d->vcpu[0]);
 124.220 -
 124.221 -    return 1;
 124.222 -}
 124.223 -
 124.224 -static void hvm_dpci_isairq_eoi(struct domain *d, unsigned int isairq)
 124.225 -{
 124.226 -    struct hvm_irq *hvm_irq = &d->arch.hvm_domain.irq;
 124.227 -    struct hvm_irq_dpci *dpci = hvm_irq->dpci;
 124.228 -    struct dev_intx_gsi_link *digl, *tmp;
 124.229 -    int i;
 124.230 -
 124.231 -    ASSERT(isairq < NR_ISAIRQS);
 124.232 -    if ( !iommu_enabled || !dpci ||
 124.233 -         !test_bit(isairq, dpci->isairq_map) )
 124.234 -        return;
 124.235 -
 124.236 -    /* Multiple mirq may be mapped to one isa irq */
 124.237 -    for ( i = 0; i < NR_IRQS; i++ )
 124.238 -    {
 124.239 -        if ( !dpci->mirq[i].valid )
 124.240 -            continue;
 124.241 -
 124.242 -        list_for_each_entry_safe ( digl, tmp,
 124.243 -            &dpci->mirq[i].digl_list, list )
 124.244 -        {
 124.245 -            if ( hvm_irq->pci_link.route[digl->link] == isairq )
 124.246 -            {
 124.247 -                hvm_pci_intx_deassert(d, digl->device, digl->intx);
 124.248 -                spin_lock(&dpci->dirq_lock);
 124.249 -                if ( --dpci->mirq[i].pending == 0 )
 124.250 -                {
 124.251 -                    spin_unlock(&dpci->dirq_lock);
 124.252 -                    gdprintk(XENLOG_INFO VTDPREFIX,
 124.253 -                             "hvm_dpci_isairq_eoi:: mirq = %x\n", i);
 124.254 -                    stop_timer(&dpci->hvm_timer[irq_to_vector(i)]);
 124.255 -                    pirq_guest_eoi(d, i);
 124.256 -                }
 124.257 -                else
 124.258 -                    spin_unlock(&dpci->dirq_lock);
 124.259 -            }
 124.260 -        }
 124.261 -    }
 124.262 -}
 124.263 -
 124.264 -void hvm_dpci_eoi(struct domain *d, unsigned int guest_gsi,
 124.265 -                  union vioapic_redir_entry *ent)
 124.266 -{
 124.267 -    struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
 124.268 -    uint32_t device, intx, machine_gsi;
 124.269 -
 124.270 -    if ( !iommu_enabled || (hvm_irq_dpci == NULL) ||
 124.271 -         (guest_gsi >= NR_ISAIRQS &&
 124.272 -          !hvm_irq_dpci->girq[guest_gsi].valid) )
 124.273 -        return;
 124.274 -
 124.275 -    if ( guest_gsi < NR_ISAIRQS )
 124.276 -    {
 124.277 -        hvm_dpci_isairq_eoi(d, guest_gsi);
 124.278 -        return;
 124.279 -    }
 124.280 -
 124.281 -    machine_gsi = hvm_irq_dpci->girq[guest_gsi].machine_gsi;
 124.282 -    device = hvm_irq_dpci->girq[guest_gsi].device;
 124.283 -    intx = hvm_irq_dpci->girq[guest_gsi].intx;
 124.284 -    hvm_pci_intx_deassert(d, device, intx);
 124.285 -
 124.286 -    spin_lock(&hvm_irq_dpci->dirq_lock);
 124.287 -    if ( --hvm_irq_dpci->mirq[machine_gsi].pending == 0 )
 124.288 -    {
 124.289 -        spin_unlock(&hvm_irq_dpci->dirq_lock);
 124.290 -
 124.291 -        gdprintk(XENLOG_INFO VTDPREFIX,
 124.292 -                 "hvm_dpci_eoi:: mirq = %x\n", machine_gsi);
 124.293 -        stop_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(machine_gsi)]);
 124.294 -        if ( (ent == NULL) || !ent->fields.mask )
 124.295 -            pirq_guest_eoi(d, machine_gsi);
 124.296 -    }
 124.297 -    else
 124.298 -        spin_unlock(&hvm_irq_dpci->dirq_lock);
 124.299 -}
   125.1 --- a/xen/drivers/passthrough/vtd/iommu.c	Fri Mar 14 15:07:45 2008 -0600
   125.2 +++ b/xen/drivers/passthrough/vtd/iommu.c	Thu Mar 20 12:35:40 2008 -0600
   125.3 @@ -19,17 +19,12 @@
   125.4   * Copyright (C) Allen Kay <allen.m.kay@intel.com> - adapted to xen
   125.5   */
   125.6  
   125.7 -#include <xen/init.h>
   125.8  #include <xen/irq.h>
   125.9 -#include <xen/spinlock.h>
  125.10  #include <xen/sched.h>
  125.11  #include <xen/xmalloc.h>
  125.12  #include <xen/domain_page.h>
  125.13 -#include <asm/delay.h>
  125.14 -#include <asm/string.h>
  125.15 -#include <asm/mm.h>
  125.16 -#include <asm/iommu.h>
  125.17 -#include <asm/hvm/vmx/intel-iommu.h>
  125.18 +#include <xen/iommu.h>
  125.19 +#include "iommu.h"
  125.20  #include "dmar.h"
  125.21  #include "../pci-direct.h"
  125.22  #include "../pci_regs.h"
  125.23 @@ -39,8 +34,8 @@
  125.24  #define domain_iommu_domid(d) ((d)->arch.hvm_domain.hvm_iommu.iommu_domid)
  125.25  
  125.26  static spinlock_t domid_bitmap_lock;    /* protect domain id bitmap */
  125.27 -static int domid_bitmap_size;           /* domain id bitmap size in bit */
  125.28 -static void *domid_bitmap;              /* iommu domain id bitmap */
  125.29 +static int domid_bitmap_size;           /* domain id bitmap size in bits */
  125.30 +static unsigned long *domid_bitmap;     /* iommu domain id bitmap */
  125.31  
  125.32  #define DID_FIELD_WIDTH 16
  125.33  #define DID_HIGH_OFFSET 8
  125.34 @@ -74,6 +69,93 @@ static void iommu_domid_release(struct d
  125.35      }
  125.36  }
  125.37  
  125.38 +static struct intel_iommu *alloc_intel_iommu(void)
  125.39 +{
  125.40 +    struct intel_iommu *intel;
  125.41 +
  125.42 +    intel = xmalloc(struct intel_iommu);
  125.43 +    if ( !intel )
  125.44 +    {
  125.45 +        gdprintk(XENLOG_ERR VTDPREFIX,
  125.46 +                 "Allocate intel_iommu failed.\n");
  125.47 +        return NULL;
  125.48 +    }
  125.49 +    memset(intel, 0, sizeof(struct intel_iommu));
  125.50 +
  125.51 +    spin_lock_init(&intel->qi_ctrl.qinval_lock);
  125.52 +    spin_lock_init(&intel->qi_ctrl.qinval_poll_lock);
  125.53 +
  125.54 +    spin_lock_init(&intel->ir_ctrl.iremap_lock);
  125.55 +
  125.56 +    return intel;
  125.57 +}
  125.58 +
  125.59 +static void free_intel_iommu(struct intel_iommu *intel)
  125.60 +{
  125.61 +    if ( intel )
  125.62 +    {
  125.63 +        xfree(intel);
  125.64 +        intel = NULL;
  125.65 +    }
  125.66 +}
  125.67 +
  125.68 +struct qi_ctrl *iommu_qi_ctrl(struct iommu *iommu)
  125.69 +{
  125.70 +    if ( !iommu )
  125.71 +        return NULL;
  125.72 +
  125.73 +    if ( !iommu->intel )
  125.74 +    {
  125.75 +        iommu->intel = alloc_intel_iommu();
  125.76 +        if ( !iommu->intel )
  125.77 +        {
  125.78 +            dprintk(XENLOG_ERR VTDPREFIX,
  125.79 +                    "iommu_qi_ctrl: Allocate iommu->intel failed.\n");
  125.80 +            return NULL;
  125.81 +        }
  125.82 +    }
  125.83 +
  125.84 +    return &(iommu->intel->qi_ctrl);
  125.85 +}
  125.86 +
  125.87 +struct ir_ctrl *iommu_ir_ctrl(struct iommu *iommu)
  125.88 +{
  125.89 +    if ( !iommu )
  125.90 +        return NULL;
  125.91 +
  125.92 +    if ( !iommu->intel )
  125.93 +    {
  125.94 +        iommu->intel = alloc_intel_iommu();
  125.95 +        if ( !iommu->intel )
  125.96 +        {
  125.97 +            dprintk(XENLOG_ERR VTDPREFIX,
  125.98 +                    "iommu_ir_ctrl: Allocate iommu->intel failed.\n");
  125.99 +            return NULL;
 125.100 +        }
 125.101 +    }
 125.102 +
 125.103 +    return &(iommu->intel->ir_ctrl);
 125.104 +}
 125.105 +
 125.106 +struct iommu_flush *iommu_get_flush(struct iommu *iommu)
 125.107 +{
 125.108 +    if ( !iommu )
 125.109 +        return NULL;
 125.110 +
 125.111 +    if ( !iommu->intel )
 125.112 +    {
 125.113 +        iommu->intel = alloc_intel_iommu();
 125.114 +        if ( !iommu->intel )
 125.115 +        {
 125.116 +            dprintk(XENLOG_ERR VTDPREFIX,
 125.117 +                    "iommu_get_flush: Allocate iommu->intel failed.\n");
 125.118 +            return NULL;
 125.119 +        }
 125.120 +    }
 125.121 +
 125.122 +    return &(iommu->intel->flush);
 125.123 +}
 125.124 +
 125.125  unsigned int x86_clflush_size;
 125.126  void clflush_cache_range(void *adr, int size)
 125.127  {
 125.128 @@ -756,40 +838,34 @@ static int iommu_page_fault_do_one(struc
 125.129              PCI_SLOT(source_id & 0xFF), PCI_FUNC(source_id & 0xFF), addr,
 125.130              fault_reason, iommu->reg);
 125.131  
 125.132 -    if (fault_reason < 0x20) 
 125.133 +    if ( fault_reason < 0x20 )
 125.134          print_vtd_entries(current->domain, iommu, (source_id >> 8),
 125.135 -                          (source_id & 0xff), (addr >> PAGE_SHIFT)); 
 125.136 +                          (source_id & 0xff), (addr >> PAGE_SHIFT));
 125.137  
 125.138      return 0;
 125.139  }
 125.140  
 125.141  static void iommu_fault_status(u32 fault_status)
 125.142  {
 125.143 -    if (fault_status & DMA_FSTS_PFO)
 125.144 +    if ( fault_status & DMA_FSTS_PFO )
 125.145          dprintk(XENLOG_ERR VTDPREFIX,
 125.146              "iommu_fault_status: Fault Overflow\n");
 125.147 -    else
 125.148 -    if (fault_status & DMA_FSTS_PPF)
 125.149 +    else if ( fault_status & DMA_FSTS_PPF )
 125.150          dprintk(XENLOG_ERR VTDPREFIX,
 125.151              "iommu_fault_status: Primary Pending Fault\n");
 125.152 -    else
 125.153 -    if (fault_status & DMA_FSTS_AFO)
 125.154 +    else if ( fault_status & DMA_FSTS_AFO )
 125.155          dprintk(XENLOG_ERR VTDPREFIX,
 125.156              "iommu_fault_status: Advanced Fault Overflow\n");
 125.157 -    else
 125.158 -    if (fault_status & DMA_FSTS_APF)
 125.159 +    else if ( fault_status & DMA_FSTS_APF )
 125.160          dprintk(XENLOG_ERR VTDPREFIX,
 125.161              "iommu_fault_status: Advanced Pending Fault\n");
 125.162 -    else
 125.163 -    if (fault_status & DMA_FSTS_IQE)
 125.164 +    else if ( fault_status & DMA_FSTS_IQE )
 125.165          dprintk(XENLOG_ERR VTDPREFIX,
 125.166              "iommu_fault_status: Invalidation Queue Error\n");
 125.167 -    else
 125.168 -    if (fault_status & DMA_FSTS_ICE)
 125.169 +    else if ( fault_status & DMA_FSTS_ICE )
 125.170          dprintk(XENLOG_ERR VTDPREFIX,
 125.171              "iommu_fault_status: Invalidation Completion Error\n");
 125.172 -    else
 125.173 -    if (fault_status & DMA_FSTS_ITE)
 125.174 +    else if ( fault_status & DMA_FSTS_ITE )
 125.175          dprintk(XENLOG_ERR VTDPREFIX,
 125.176              "iommu_fault_status: Invalidation Time-out Error\n");
 125.177  }
 125.178 @@ -976,8 +1052,6 @@ struct iommu *iommu_alloc(void *hw_data)
 125.179  {
 125.180      struct acpi_drhd_unit *drhd = (struct acpi_drhd_unit *) hw_data;
 125.181      struct iommu *iommu;
 125.182 -    struct qi_ctrl *qi_ctrl;
 125.183 -    struct ir_ctrl *ir_ctrl;
 125.184  
 125.185      if ( nr_iommus > MAX_IOMMUS )
 125.186      {
 125.187 @@ -1014,12 +1088,7 @@ struct iommu *iommu_alloc(void *hw_data)
 125.188      spin_lock_init(&iommu->lock);
 125.189      spin_lock_init(&iommu->register_lock);
 125.190  
 125.191 -    qi_ctrl = iommu_qi_ctrl(iommu);
 125.192 -    spin_lock_init(&qi_ctrl->qinval_lock);
 125.193 -    spin_lock_init(&qi_ctrl->qinval_poll_lock);
 125.194 -
 125.195 -    ir_ctrl = iommu_ir_ctrl(iommu);
 125.196 -    spin_lock_init(&ir_ctrl->iremap_lock);
 125.197 +    iommu->intel = alloc_intel_iommu();
 125.198  
 125.199      drhd->iommu = iommu;
 125.200      return iommu;
 125.201 @@ -1036,6 +1105,7 @@ static void free_iommu(struct iommu *iom
 125.202          free_xenheap_page((void *)iommu->root_entry);
 125.203      if ( iommu->reg )
 125.204          iounmap(iommu->reg);
 125.205 +    free_intel_iommu(iommu->intel);
 125.206      free_irq(iommu->vector);
 125.207      xfree(iommu);
 125.208  }
 125.209 @@ -1063,7 +1133,7 @@ int intel_iommu_domain_init(struct domai
 125.210          iommu = drhd->iommu ? : iommu_alloc(drhd);
 125.211  
 125.212      /* calculate AGAW */
 125.213 -    if (guest_width > cap_mgaw(iommu->cap))
 125.214 +    if ( guest_width > cap_mgaw(iommu->cap) )
 125.215          guest_width = cap_mgaw(iommu->cap);
 125.216      adjust_width = guestwidth_to_adjustwidth(guest_width);
 125.217      agaw = width_to_agaw(adjust_width);
 125.218 @@ -1885,7 +1955,8 @@ int iommu_setup(void)
 125.219  
 125.220      /* Allocate domain id bitmap, and set bit 0 as reserved */
 125.221      domid_bitmap_size = cap_ndoms(iommu->cap);
 125.222 -    domid_bitmap = xmalloc_bytes(domid_bitmap_size / 8);
 125.223 +    domid_bitmap = xmalloc_array(unsigned long,
 125.224 +                                 BITS_TO_LONGS(domid_bitmap_size));
 125.225      if ( domid_bitmap == NULL )
 125.226          goto error;
 125.227      memset(domid_bitmap, 0, domid_bitmap_size / 8);
 125.228 @@ -1948,6 +2019,12 @@ int intel_iommu_assign_device(struct dom
 125.229      for_each_rmrr_device( rmrr, pdev )
 125.230          if ( pdev->bus == bus && pdev->devfn == devfn )
 125.231          {
 125.232 +            /* FIXME: Because USB RMRR conflicts with guest bios region,
 125.233 +             * ignore USB RMRR temporarily.
 125.234 +             */
 125.235 +            if ( is_usb_device(pdev) )
 125.236 +                return 0;
 125.237 +
 125.238              ret = iommu_prepare_rmrr_dev(d, rmrr, pdev);
 125.239              if ( ret )
 125.240              {
   126.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   126.2 +++ b/xen/drivers/passthrough/vtd/iommu.h	Thu Mar 20 12:35:40 2008 -0600
   126.3 @@ -0,0 +1,454 @@
   126.4 +/*
   126.5 + * Copyright (c) 2006, Intel Corporation.
   126.6 + *
   126.7 + * This program is free software; you can redistribute it and/or modify it
   126.8 + * under the terms and conditions of the GNU General Public License,
   126.9 + * version 2, as published by the Free Software Foundation.
  126.10 + *
  126.11 + * This program is distributed in the hope it will be useful, but WITHOUT
  126.12 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  126.13 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  126.14 + * more details.
  126.15 + *
  126.16 + * You should have received a copy of the GNU General Public License along with
  126.17 + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  126.18 + * Place - Suite 330, Boston, MA 02111-1307 USA.
  126.19 + *
  126.20 + * Copyright (C) Ashok Raj <ashok.raj@intel.com>
  126.21 + */
  126.22 +
  126.23 +#ifndef _INTEL_IOMMU_H_
  126.24 +#define _INTEL_IOMMU_H_
  126.25 +
  126.26 +#include <xen/types.h>
  126.27 +
  126.28 +/*
  126.29 + * Intel IOMMU register specification per version 1.0 public spec.
  126.30 + */
  126.31 +
  126.32 +#define    DMAR_VER_REG    0x0    /* Arch version supported by this IOMMU */
  126.33 +#define    DMAR_CAP_REG    0x8    /* Hardware supported capabilities */
  126.34 +#define    DMAR_ECAP_REG    0x10    /* Extended capabilities supported */
  126.35 +#define    DMAR_GCMD_REG    0x18    /* Global command register */
  126.36 +#define    DMAR_GSTS_REG    0x1c    /* Global status register */
  126.37 +#define    DMAR_RTADDR_REG    0x20    /* Root entry table */
  126.38 +#define    DMAR_CCMD_REG    0x28    /* Context command reg */
  126.39 +#define    DMAR_FSTS_REG    0x34    /* Fault Status register */
  126.40 +#define    DMAR_FECTL_REG    0x38    /* Fault control register */
  126.41 +#define    DMAR_FEDATA_REG    0x3c    /* Fault event interrupt data register */
  126.42 +#define    DMAR_FEADDR_REG    0x40    /* Fault event interrupt addr register */
  126.43 +#define    DMAR_FEUADDR_REG 0x44    /* Upper address register */
  126.44 +#define    DMAR_AFLOG_REG    0x58    /* Advanced Fault control */
  126.45 +#define    DMAR_PMEN_REG    0x64    /* Enable Protected Memory Region */
  126.46 +#define    DMAR_PLMBASE_REG 0x68    /* PMRR Low addr */
  126.47 +#define    DMAR_PLMLIMIT_REG 0x6c    /* PMRR low limit */
  126.48 +#define    DMAR_PHMBASE_REG 0x70    /* pmrr high base addr */
  126.49 +#define    DMAR_PHMLIMIT_REG 0x78    /* pmrr high limit */
  126.50 +#define    DMAR_IQH_REG    0x80    /* invalidation queue head */
  126.51 +#define    DMAR_IQT_REG    0x88    /* invalidation queue tail */
  126.52 +#define    DMAR_IQA_REG    0x90    /* invalidation queue addr */
  126.53 +#define    DMAR_IRTA_REG   0xB8    /* intr remap */
  126.54 +
  126.55 +#define OFFSET_STRIDE        (9)
  126.56 +#define dmar_readl(dmar, reg) readl(dmar + reg)
  126.57 +#define dmar_writel(dmar, reg, val) writel(val, dmar + reg)
  126.58 +#define dmar_readq(dmar, reg) ({ \
  126.59 +        u32 lo, hi; \
  126.60 +        lo = dmar_readl(dmar, reg); \
  126.61 +        hi = dmar_readl(dmar, reg + 4); \
  126.62 +        (((u64) hi) << 32) + lo; })
  126.63 +#define dmar_writeq(dmar, reg, val) do {\
  126.64 +        dmar_writel(dmar, reg, (u32)val); \
  126.65 +        dmar_writel(dmar, reg + 4, (u32)((u64) val >> 32)); \
  126.66 +    } while (0)
  126.67 +
  126.68 +#define VER_MAJOR(v)        (((v) & 0xf0) >> 4)
  126.69 +#define VER_MINOR(v)        ((v) & 0x0f)
  126.70 +
  126.71 +/*
  126.72 + * Decoding Capability Register
  126.73 + */
  126.74 +#define cap_read_drain(c)    (((c) >> 55) & 1)
  126.75 +#define cap_write_drain(c)    (((c) >> 54) & 1)
  126.76 +#define cap_max_amask_val(c)    (((c) >> 48) & 0x3f)
  126.77 +#define cap_num_fault_regs(c)    ((((c) >> 40) & 0xff) + 1)
  126.78 +#define cap_pgsel_inv(c)       (((c) >> 39) & 1)
  126.79 +
  126.80 +#define cap_super_page_val(c)    (((c) >> 34) & 0xf)
  126.81 +#define cap_super_offset(c)    (((find_first_bit(&cap_super_page_val(c), 4)) \
  126.82 +                    * OFFSET_STRIDE) + 21)
  126.83 +
  126.84 +#define cap_fault_reg_offset(c)    ((((c) >> 24) & 0x3ff) * 16)
  126.85 +
  126.86 +#define cap_isoch(c)        (((c) >> 23) & 1)
  126.87 +#define cap_qos(c)        (((c) >> 22) & 1)
  126.88 +#define cap_mgaw(c)        ((((c) >> 16) & 0x3f) + 1)
  126.89 +#define cap_sagaw(c)        (((c) >> 8) & 0x1f)
  126.90 +#define cap_caching_mode(c)    (((c) >> 7) & 1)
  126.91 +#define cap_phmr(c)        (((c) >> 6) & 1)
  126.92 +#define cap_plmr(c)        (((c) >> 5) & 1)
  126.93 +#define cap_rwbf(c)        (((c) >> 4) & 1)
  126.94 +#define cap_afl(c)        (((c) >> 3) & 1)
  126.95 +#define cap_ndoms(c)        (1 << (4 + 2 * ((c) & 0x7)))
  126.96 +
  126.97 +/*
  126.98 + * Extended Capability Register
  126.99 + */
 126.100 +
 126.101 +#define ecap_niotlb_iunits(e)    ((((e) >> 24) & 0xff) + 1)
 126.102 +#define ecap_iotlb_offset(e)     ((((e) >> 8) & 0x3ff) * 16)
 126.103 +#define ecap_coherent(e)         ((e >> 0) & 0x1)
 126.104 +#define ecap_queued_inval(e)     ((e >> 1) & 0x1)
 126.105 +#define ecap_dev_iotlb(e)        ((e >> 2) & 0x1)
 126.106 +#define ecap_intr_remap(e)       ((e >> 3) & 0x1)
 126.107 +#define ecap_ext_intr(e)         ((e >> 4) & 0x1)
 126.108 +#define ecap_cache_hints(e)      ((e >> 5) & 0x1)
 126.109 +#define ecap_pass_thru(e)        ((e >> 6) & 0x1)
 126.110 +
 126.111 +/* IOTLB_REG */
 126.112 +#define DMA_TLB_FLUSH_GRANU_OFFSET  60
 126.113 +#define DMA_TLB_GLOBAL_FLUSH (((u64)1) << 60)
 126.114 +#define DMA_TLB_DSI_FLUSH (((u64)2) << 60)
 126.115 +#define DMA_TLB_PSI_FLUSH (((u64)3) << 60)
 126.116 +#define DMA_TLB_IIRG(x) (((x) >> 60) & 7) 
 126.117 +#define DMA_TLB_IAIG(val) (((val) >> 57) & 7)
 126.118 +#define DMA_TLB_DID(x) (((u64)(x & 0xffff)) << 32)
 126.119 +
 126.120 +#define DMA_TLB_READ_DRAIN (((u64)1) << 49)
 126.121 +#define DMA_TLB_WRITE_DRAIN (((u64)1) << 48)
 126.122 +#define DMA_TLB_IVT (((u64)1) << 63)
 126.123 +
 126.124 +#define DMA_TLB_IVA_ADDR(x) ((((u64)x) >> 12) << 12)
 126.125 +#define DMA_TLB_IVA_HINT(x) ((((u64)x) & 1) << 6)
 126.126 +
 126.127 +/* GCMD_REG */
 126.128 +#define DMA_GCMD_TE     (((u64)1) << 31)
 126.129 +#define DMA_GCMD_SRTP   (((u64)1) << 30)
 126.130 +#define DMA_GCMD_SFL    (((u64)1) << 29)
 126.131 +#define DMA_GCMD_EAFL   (((u64)1) << 28)
 126.132 +#define DMA_GCMD_WBF    (((u64)1) << 27)
 126.133 +#define DMA_GCMD_QIE    (((u64)1) << 26)
 126.134 +#define DMA_GCMD_IRE    (((u64)1) << 25)
 126.135 +#define DMA_GCMD_SIRTP  (((u64)1) << 24)
 126.136 +#define DMA_GCMD_CFI    (((u64)1) << 23)
 126.137 +
 126.138 +/* GSTS_REG */
 126.139 +#define DMA_GSTS_TES    (((u64)1) << 31)
 126.140 +#define DMA_GSTS_RTPS   (((u64)1) << 30)
 126.141 +#define DMA_GSTS_FLS    (((u64)1) << 29)
 126.142 +#define DMA_GSTS_AFLS   (((u64)1) << 28)
 126.143 +#define DMA_GSTS_WBFS   (((u64)1) << 27)
 126.144 +#define DMA_GSTS_QIES   (((u64)1) <<26)
 126.145 +#define DMA_GSTS_IRES   (((u64)1) <<25)
 126.146 +#define DMA_GSTS_SIRTPS (((u64)1) << 24)
 126.147 +#define DMA_GSTS_CFIS   (((u64)1) <<23)
 126.148 +
 126.149 +/* PMEN_REG */
 126.150 +#define DMA_PMEN_EPM    (((u32)1) << 31)
 126.151 +#define DMA_PMEN_PRS    (((u32)1) << 0)
 126.152 +
 126.153 +/* CCMD_REG */
 126.154 +#define DMA_CCMD_INVL_GRANU_OFFSET  61
 126.155 +#define DMA_CCMD_ICC   (((u64)1) << 63)
 126.156 +#define DMA_CCMD_GLOBAL_INVL (((u64)1) << 61)
 126.157 +#define DMA_CCMD_DOMAIN_INVL (((u64)2) << 61)
 126.158 +#define DMA_CCMD_DEVICE_INVL (((u64)3) << 61)
 126.159 +#define DMA_CCMD_FM(m) (((u64)((m) & 0x3)) << 32)
 126.160 +#define DMA_CCMD_CIRG(x) ((((u64)3) << 61) & x)
 126.161 +#define DMA_CCMD_MASK_NOBIT 0
 126.162 +#define DMA_CCMD_MASK_1BIT 1
 126.163 +#define DMA_CCMD_MASK_2BIT 2
 126.164 +#define DMA_CCMD_MASK_3BIT 3
 126.165 +#define DMA_CCMD_SID(s) (((u64)((s) & 0xffff)) << 16)
 126.166 +#define DMA_CCMD_DID(d) ((u64)((d) & 0xffff))
 126.167 +
 126.168 +#define DMA_CCMD_CAIG_MASK(x) (((u64)x) & ((u64) 0x3 << 59))
 126.169 +
 126.170 +/* FECTL_REG */
 126.171 +#define DMA_FECTL_IM (((u64)1) << 31)
 126.172 +
 126.173 +/* FSTS_REG */
 126.174 +#define DMA_FSTS_PFO ((u64)1 << 0)
 126.175 +#define DMA_FSTS_PPF ((u64)1 << 1)
 126.176 +#define DMA_FSTS_AFO ((u64)1 << 2)
 126.177 +#define DMA_FSTS_APF ((u64)1 << 3)
 126.178 +#define DMA_FSTS_IQE ((u64)1 << 4)
 126.179 +#define DMA_FSTS_ICE ((u64)1 << 5)
 126.180 +#define DMA_FSTS_ITE ((u64)1 << 6)
 126.181 +#define DMA_FSTS_FAULTS    DMA_FSTS_PFO | DMA_FSTS_PPF | DMA_FSTS_AFO | DMA_FSTS_APF | DMA_FSTS_IQE | DMA_FSTS_ICE | DMA_FSTS_ITE
 126.182 +#define dma_fsts_fault_record_index(s) (((s) >> 8) & 0xff)
 126.183 +
 126.184 +/* FRCD_REG, 32 bits access */
 126.185 +#define DMA_FRCD_F (((u64)1) << 31)
 126.186 +#define dma_frcd_type(d) ((d >> 30) & 1)
 126.187 +#define dma_frcd_fault_reason(c) (c & 0xff)
 126.188 +#define dma_frcd_source_id(c) (c & 0xffff)
 126.189 +#define dma_frcd_page_addr(d) (d & (((u64)-1) << 12)) /* low 64 bit */
 126.190 +
 126.191 +/*
 126.192 + * 0: Present
 126.193 + * 1-11: Reserved
 126.194 + * 12-63: Context Ptr (12 - (haw-1))
 126.195 + * 64-127: Reserved
 126.196 + */
 126.197 +struct root_entry {
 126.198 +    u64    val;
 126.199 +    u64    rsvd1;
 126.200 +};
 126.201 +#define root_present(root)    ((root).val & 1)
 126.202 +#define set_root_present(root) do {(root).val |= 1;} while(0)
 126.203 +#define get_context_addr(root) ((root).val & PAGE_MASK_4K)
 126.204 +#define set_root_value(root, value) \
 126.205 +    do {(root).val |= ((value) & PAGE_MASK_4K);} while(0)
 126.206 +
 126.207 +struct context_entry {
 126.208 +    u64 lo;
 126.209 +    u64 hi;
 126.210 +};
 126.211 +#define ROOT_ENTRY_NR (PAGE_SIZE_4K/sizeof(struct root_entry))
 126.212 +#define context_present(c) ((c).lo & 1)
 126.213 +#define context_fault_disable(c) (((c).lo >> 1) & 1)
 126.214 +#define context_translation_type(c) (((c).lo >> 2) & 3)
 126.215 +#define context_address_root(c) ((c).lo & PAGE_MASK_4K)
 126.216 +#define context_address_width(c) ((c).hi &  7)
 126.217 +#define context_domain_id(c) (((c).hi >> 8) & ((1 << 16) - 1))
 126.218 +
 126.219 +#define context_set_present(c) do {(c).lo |= 1;} while(0)
 126.220 +#define context_clear_present(c) do {(c).lo &= ~1;} while(0)
 126.221 +#define context_set_fault_enable(c) \
 126.222 +    do {(c).lo &= (((u64)-1) << 2) | 1;} while(0)
 126.223 +
 126.224 +#define context_set_translation_type(c, val) do { \
 126.225 +        (c).lo &= (((u64)-1) << 4) | 3; \
 126.226 +        (c).lo |= (val & 3) << 2; \
 126.227 +    } while(0)
 126.228 +#define CONTEXT_TT_MULTI_LEVEL 0
 126.229 +#define CONTEXT_TT_DEV_IOTLB   1
 126.230 +#define CONTEXT_TT_PASS_THRU   2
 126.231 +
 126.232 +#define context_set_address_root(c, val) \
 126.233 +    do {(c).lo &= 0xfff; (c).lo |= (val) & PAGE_MASK_4K ;} while(0)
 126.234 +#define context_set_address_width(c, val) \
 126.235 +    do {(c).hi &= 0xfffffff8; (c).hi |= (val) & 7;} while(0)
 126.236 +#define context_clear_entry(c) do {(c).lo = 0; (c).hi = 0;} while(0)
 126.237 +
 126.238 +/* page table handling */
 126.239 +#define LEVEL_STRIDE       (9)
 126.240 +#define LEVEL_MASK         ((1 << LEVEL_STRIDE) - 1)
 126.241 +#define agaw_to_level(val) ((val) + 2)
 126.242 +#define agaw_to_width(val) (30 + val * LEVEL_STRIDE)
 126.243 +#define width_to_agaw(w)   ((w - 30)/LEVEL_STRIDE)
 126.244 +#define level_to_offset_bits(l) (12 + (l - 1) * LEVEL_STRIDE)
 126.245 +#define address_level_offset(addr, level) \
 126.246 +            ((addr >> level_to_offset_bits(level)) & LEVEL_MASK)
 126.247 +#define level_mask(l) (((u64)(-1)) << level_to_offset_bits(l))
 126.248 +#define level_size(l) (1 << level_to_offset_bits(l))
 126.249 +#define align_to_level(addr, l) ((addr + level_size(l) - 1) & level_mask(l))
 126.250 +
 126.251 +/*
 126.252 + * 0: readable
 126.253 + * 1: writable
 126.254 + * 2-6: reserved
 126.255 + * 7: super page
 126.256 + * 8-11: available
 126.257 + * 12-63: Host physcial address
 126.258 + */
 126.259 +struct dma_pte {
 126.260 +    u64 val;
 126.261 +};
 126.262 +#define dma_clear_pte(p)    do {(p).val = 0;} while(0)
 126.263 +#define dma_set_pte_readable(p) do {(p).val |= 1;} while(0)
 126.264 +#define dma_set_pte_writable(p) do {(p).val |= 2;} while(0)
 126.265 +#define dma_set_pte_superpage(p) do {(p).val |= 8;} while(0)
 126.266 +#define dma_set_pte_prot(p, prot) do { (p).val = (((p).val >> 2) << 2) | ((prot) & 3);} while (0)
 126.267 +#define dma_pte_addr(p) ((p).val & PAGE_MASK_4K)
 126.268 +#define dma_set_pte_addr(p, addr) do {(p).val |= ((addr) >> PAGE_SHIFT_4K) << PAGE_SHIFT_4K;} while(0)
 126.269 +#define DMA_PTE_READ (1)
 126.270 +#define DMA_PTE_WRITE (2)
 126.271 +#define dma_pte_present(p) (((p).val & 3) != 0)
 126.272 +
 126.273 +/* interrupt remap entry */
 126.274 +struct iremap_entry {
 126.275 +  union {
 126.276 +    u64 lo_val;
 126.277 +    struct {
 126.278 +        u64 p       : 1,
 126.279 +            fpd     : 1,
 126.280 +            dm      : 1,
 126.281 +            rh      : 1,
 126.282 +            tm      : 1,
 126.283 +            dlm     : 3,
 126.284 +            avail   : 4,
 126.285 +            res_1   : 4,
 126.286 +            vector  : 8,
 126.287 +            res_2   : 8,
 126.288 +            dst     : 32;
 126.289 +    }lo;
 126.290 +  };
 126.291 +  union {
 126.292 +    u64 hi_val;
 126.293 +    struct {
 126.294 +        u64 sid     : 16,
 126.295 +            sq      : 2,
 126.296 +            svt     : 2,
 126.297 +            res_1   : 44;
 126.298 +    }hi;
 126.299 +  };
 126.300 +};
 126.301 +#define IREMAP_ENTRY_NR (PAGE_SIZE_4K/sizeof(struct iremap_entry))
 126.302 +#define iremap_present(v) ((v).lo & 1)
 126.303 +#define iremap_fault_disable(v) (((v).lo >> 1) & 1)
 126.304 +
 126.305 +#define iremap_set_present(v) do {(v).lo |= 1;} while(0)
 126.306 +#define iremap_clear_present(v) do {(v).lo &= ~1;} while(0)
 126.307 +
 126.308 +/* queue invalidation entry */
 126.309 +struct qinval_entry {
 126.310 +    union {
 126.311 +        struct {
 126.312 +            struct {
 126.313 +                u64 type    : 4,
 126.314 +                    granu   : 2,
 126.315 +                    res_1   : 10,
 126.316 +                    did     : 16,
 126.317 +                    sid     : 16,
 126.318 +                    fm      : 2,
 126.319 +                    res_2   : 14;
 126.320 +            }lo;
 126.321 +            struct {
 126.322 +                u64 res;
 126.323 +            }hi;
 126.324 +        }cc_inv_dsc;
 126.325 +        struct {
 126.326 +            struct {
 126.327 +                u64 type    : 4,
 126.328 +                    granu   : 2,
 126.329 +                    dw      : 1,
 126.330 +                    dr      : 1,
 126.331 +                    res_1   : 8,
 126.332 +                    did     : 16,
 126.333 +                    res_2   : 32;
 126.334 +            }lo;
 126.335 +            struct {
 126.336 +                u64 am      : 6,
 126.337 +                    ih      : 1,
 126.338 +                    res_1   : 5,
 126.339 +                    addr    : 52;
 126.340 +            }hi;
 126.341 +        }iotlb_inv_dsc;
 126.342 +        struct {
 126.343 +            struct {
 126.344 +                u64 type    : 4,
 126.345 +                    res_1   : 12,
 126.346 +                    max_invs_pend: 5,
 126.347 +                    res_2   : 11,
 126.348 +                    sid     : 16,
 126.349 +                    res_3   : 16;
 126.350 +            }lo;
 126.351 +            struct {
 126.352 +                u64 size    : 1,
 126.353 +                    res_1   : 11,
 126.354 +                    addr    : 52;
 126.355 +            }hi;
 126.356 +        }dev_iotlb_inv_dsc;
 126.357 +        struct {
 126.358 +            struct {
 126.359 +                u64 type    : 4,
 126.360 +                    granu   : 1,
 126.361 +                    res_1   : 22,
 126.362 +                    im      : 5,
 126.363 +                    iidx    : 16,
 126.364 +                    res_2   : 16;
 126.365 +            }lo;
 126.366 +            struct {
 126.367 +                u64 res;
 126.368 +            }hi;
 126.369 +        }iec_inv_dsc;
 126.370 +        struct {
 126.371 +            struct {
 126.372 +                u64 type    : 4,
 126.373 +                    iflag   : 1,
 126.374 +                    sw      : 1,
 126.375 +                    fn      : 1,
 126.376 +                    res_1   : 25,
 126.377 +                    sdata   : 32;
 126.378 +            }lo;
 126.379 +            struct {
 126.380 +                u64 res_1   : 2,
 126.381 +                    saddr   : 62;
 126.382 +            }hi;
 126.383 +        }inv_wait_dsc;
 126.384 +    }q;
 126.385 +};
 126.386 +
 126.387 +struct poll_info {
 126.388 +    u64 saddr;
 126.389 +    u32 udata;
 126.390 +};
 126.391 +
 126.392 +#define QINVAL_ENTRY_NR (PAGE_SIZE_4K/sizeof(struct qinval_entry))
 126.393 +#define qinval_present(v) ((v).lo & 1)
 126.394 +#define qinval_fault_disable(v) (((v).lo >> 1) & 1)
 126.395 +
 126.396 +#define qinval_set_present(v) do {(v).lo |= 1;} while(0)
 126.397 +#define qinval_clear_present(v) do {(v).lo &= ~1;} while(0)
 126.398 +
 126.399 +#define RESERVED_VAL        0
 126.400 +
 126.401 +#define TYPE_INVAL_CONTEXT      0x1
 126.402 +#define TYPE_INVAL_IOTLB        0x2
 126.403 +#define TYPE_INVAL_DEVICE_IOTLB 0x3
 126.404 +#define TYPE_INVAL_IEC          0x4
 126.405 +#define TYPE_INVAL_WAIT         0x5
 126.406 +
 126.407 +#define NOTIFY_TYPE_POLL        1
 126.408 +#define NOTIFY_TYPE_INTR        1
 126.409 +#define INTERRUTP_FLAG          1
 126.410 +#define STATUS_WRITE            1
 126.411 +#define FENCE_FLAG              1
 126.412 +
 126.413 +#define IEC_GLOBAL_INVL         0
 126.414 +#define IEC_INDEX_INVL          1
 126.415 +#define IRTA_REG_EIME_SHIFT     11
 126.416 +#define IRTA_REG_TABLE_SIZE     7    // 4k page = 256 * 16 byte entries
 126.417 +                                     // 2^^(IRTA_REG_TABLE_SIZE + 1) = 256
 126.418 +                                     // IRTA_REG_TABLE_SIZE = 7
 126.419 +
 126.420 +#define VTD_PAGE_TABLE_LEVEL_3  3
 126.421 +#define VTD_PAGE_TABLE_LEVEL_4  4
 126.422 +
 126.423 +#define DEFAULT_DOMAIN_ADDRESS_WIDTH 48
 126.424 +#define MAX_IOMMU_REGS 0xc0
 126.425 +
 126.426 +extern struct list_head acpi_drhd_units;
 126.427 +extern struct list_head acpi_rmrr_units;
 126.428 +extern struct list_head acpi_ioapic_units;
 126.429 +
 126.430 +struct qi_ctrl {
 126.431 +    struct qinval_entry *qinval;         /* queue invalidation page */
 126.432 +    int qinval_index;                    /* queue invalidation index */
 126.433 +    spinlock_t qinval_lock;      /* lock for queue invalidation page */
 126.434 +    spinlock_t qinval_poll_lock; /* lock for queue invalidation poll addr */
 126.435 +    volatile u32 qinval_poll_status;     /* used by poll methord to sync */
 126.436 +};
 126.437 +
 126.438 +struct ir_ctrl {
 126.439 +    struct iremap_entry *iremap; /* interrupt remap table */
 126.440 +    int iremap_index;            /* interrupt remap index */
 126.441 +    spinlock_t iremap_lock;      /* lock for irq remappping table */
 126.442 +};
 126.443 +
 126.444 +struct iommu_flush {
 126.445 +    int (*context)(void *iommu, u16 did, u16 source_id,
 126.446 +                   u8 function_mask, u64 type, int non_present_entry_flush);
 126.447 +    int (*iotlb)(void *iommu, u16 did, u64 addr, unsigned int size_order,
 126.448 +                 u64 type, int non_present_entry_flush);
 126.449 +};
 126.450 +
 126.451 +struct intel_iommu {
 126.452 +    struct qi_ctrl qi_ctrl;
 126.453 +    struct ir_ctrl ir_ctrl;
 126.454 +    struct iommu_flush flush;
 126.455 +};
 126.456 +
 126.457 +#endif
   127.1 --- a/xen/drivers/passthrough/vtd/qinval.c	Fri Mar 14 15:07:45 2008 -0600
   127.2 +++ b/xen/drivers/passthrough/vtd/qinval.c	Thu Mar 20 12:35:40 2008 -0600
   127.3 @@ -19,15 +19,9 @@
   127.4   */
   127.5  
   127.6  
   127.7 -#include <xen/init.h>
   127.8 -#include <xen/irq.h>
   127.9 -#include <xen/spinlock.h>
  127.10  #include <xen/sched.h>
  127.11 -#include <xen/xmalloc.h>
  127.12 -#include <xen/domain_page.h>
  127.13 -#include <asm/delay.h>
  127.14 -#include <asm/string.h>
  127.15 -#include <asm/iommu.h>
  127.16 +#include <xen/iommu.h>
  127.17 +#include "iommu.h"
  127.18  #include "dmar.h"
  127.19  #include "vtd.h"
  127.20  #include "../pci-direct.h"
   128.1 --- a/xen/drivers/passthrough/vtd/utils.c	Fri Mar 14 15:07:45 2008 -0600
   128.2 +++ b/xen/drivers/passthrough/vtd/utils.c	Thu Mar 20 12:35:40 2008 -0600
   128.3 @@ -17,26 +17,28 @@
   128.4   * Copyright (C) Allen Kay <allen.m.kay@intel.com>
   128.5   */
   128.6  
   128.7 -#include <xen/init.h>
   128.8 -#include <xen/bitmap.h>
   128.9 -#include <xen/irq.h>
  128.10 -#include <xen/spinlock.h>
  128.11  #include <xen/sched.h>
  128.12  #include <xen/delay.h>
  128.13 -#include <asm/iommu.h>
  128.14 +#include <xen/iommu.h>
  128.15 +#include "iommu.h"
  128.16  #include "dmar.h"
  128.17  #include "../pci-direct.h"
  128.18  #include "../pci_regs.h"
  128.19  #include "msi.h"
  128.20  
  128.21 -#include <xen/mm.h>
  128.22 -#include <xen/xmalloc.h>
  128.23 -#include <xen/inttypes.h>
  128.24 -
  128.25  #define INTEL   0x8086
  128.26  #define SEABURG 0x4000
  128.27  #define C_STEP  2
  128.28  
  128.29 +int is_usb_device(struct pci_dev *pdev)
  128.30 +{
  128.31 +    u8 bus = pdev->bus;
  128.32 +    u8 dev = PCI_SLOT(pdev->devfn);
  128.33 +    u8 func = PCI_FUNC(pdev->devfn);
  128.34 +    u16 class = read_pci_config_16(bus, dev, func, PCI_CLASS_DEVICE);
  128.35 +    return (class == 0xc03);
  128.36 +}
  128.37 +
  128.38  int vtd_hw_check(void)
  128.39  {
  128.40      u16 vendor, device;
   129.1 --- a/xen/drivers/passthrough/vtd/vtd.h	Fri Mar 14 15:07:45 2008 -0600
   129.2 +++ b/xen/drivers/passthrough/vtd/vtd.h	Thu Mar 20 12:35:40 2008 -0600
   129.3 @@ -21,16 +21,7 @@
   129.4  #ifndef _VTD_H_
   129.5  #define _VTD_H_
   129.6  
   129.7 -#include <xen/list.h>
   129.8 -#include <asm/iommu.h>
   129.9 -
  129.10 -#define VTDPREFIX "[VT-D]"
  129.11 -
  129.12 -#define DMAR_OPERATION_TIMEOUT (HZ*60) /* 1m */
  129.13 -#define time_after(a,b)         \
  129.14 -        (typecheck(unsigned long, a) && \
  129.15 -         typecheck(unsigned long, b) && \
  129.16 -         ((long)(b) - (long)(a) < 0))
  129.17 +#include <xen/iommu.h>
  129.18  
  129.19  struct IO_APIC_route_remap_entry {
  129.20      union {
   130.1 --- a/xen/drivers/video/vesa.c	Fri Mar 14 15:07:45 2008 -0600
   130.2 +++ b/xen/drivers/video/vesa.c	Thu Mar 20 12:35:40 2008 -0600
   130.3 @@ -219,7 +219,7 @@ static void vesa_show_line(
   130.4                       ((font->width + 7) >> 3));
   130.5              for ( b = font->width; b--; )
   130.6              {
   130.7 -                pixel = test_bit(b, bits) ? pixel_on : 0;
   130.8 +                pixel = (*bits & (1u<<b)) ? pixel_on : 0;
   130.9                  memcpy(ptr, &pixel, bpp);
  130.10                  ptr += bpp;
  130.11              }
   131.1 --- a/xen/include/acpi/acconfig.h	Fri Mar 14 15:07:45 2008 -0600
   131.2 +++ b/xen/include/acpi/acconfig.h	Thu Mar 20 12:35:40 2008 -0600
   131.3 @@ -5,7 +5,7 @@
   131.4   *****************************************************************************/
   131.5  
   131.6  /*
   131.7 - * Copyright (C) 2000 - 2005, R. Byron Moore
   131.8 + * Copyright (C) 2000 - 2007, R. Byron Moore
   131.9   * All rights reserved.
  131.10   *
  131.11   * Redistribution and use in source and binary forms, with or without
  131.12 @@ -44,7 +44,6 @@
  131.13  #ifndef _ACCONFIG_H
  131.14  #define _ACCONFIG_H
  131.15  
  131.16 -
  131.17  /******************************************************************************
  131.18   *
  131.19   * Configuration options
  131.20 @@ -62,9 +61,9 @@
  131.21   *
  131.22   */
  131.23  
  131.24 -/* Version string */
  131.25 +/* Current ACPICA subsystem version in YYYYMMDD format */
  131.26  
  131.27 -#define ACPI_CA_VERSION                 0x20050211
  131.28 +#define ACPI_CA_VERSION                 0x20070126
  131.29  
  131.30  /*
  131.31   * OS name, used for the _OS object.  The _OS object is essentially obsolete,
  131.32 @@ -78,19 +77,18 @@
  131.33  
  131.34  /* Maximum objects in the various object caches */
  131.35  
  131.36 -#define ACPI_MAX_STATE_CACHE_DEPTH      64          /* State objects */
  131.37 -#define ACPI_MAX_PARSE_CACHE_DEPTH      96          /* Parse tree objects */
  131.38 -#define ACPI_MAX_EXTPARSE_CACHE_DEPTH   64          /* Parse tree objects */
  131.39 -#define ACPI_MAX_OBJECT_CACHE_DEPTH     64          /* Interpreter operand objects */
  131.40 -#define ACPI_MAX_WALK_CACHE_DEPTH       4           /* Objects for parse tree walks */
  131.41 +#define ACPI_MAX_STATE_CACHE_DEPTH      96	/* State objects */
  131.42 +#define ACPI_MAX_PARSE_CACHE_DEPTH      96	/* Parse tree objects */
  131.43 +#define ACPI_MAX_EXTPARSE_CACHE_DEPTH   96	/* Parse tree objects */
  131.44 +#define ACPI_MAX_OBJECT_CACHE_DEPTH     96	/* Interpreter operand objects */
  131.45 +#define ACPI_MAX_NAMESPACE_CACHE_DEPTH  96	/* Namespace objects */
  131.46  
  131.47  /*
  131.48 - * Should the subystem abort the loading of an ACPI table if the
  131.49 + * Should the subsystem abort the loading of an ACPI table if the
  131.50   * table checksum is incorrect?
  131.51   */
  131.52  #define ACPI_CHECKSUM_ABORT             FALSE
  131.53  
  131.54 -
  131.55  /******************************************************************************
  131.56   *
  131.57   * Subsystem Constants
  131.58 @@ -101,23 +99,25 @@
  131.59  
  131.60  #define ACPI_CA_SUPPORT_LEVEL           3
  131.61  
  131.62 -/* String size constants */
  131.63 -
  131.64 -#define ACPI_MAX_STRING_LENGTH          512
  131.65 -#define ACPI_PATHNAME_MAX               256         /* A full namespace pathname */
  131.66 -
  131.67  /* Maximum count for a semaphore object */
  131.68  
  131.69  #define ACPI_MAX_SEMAPHORE_COUNT        256
  131.70  
  131.71 -/* Max reference count (for debug only) */
  131.72 +/* Maximum object reference count (detects object deletion issues) */
  131.73  
  131.74 -#define ACPI_MAX_REFERENCE_COUNT        0x400
  131.75 +#define ACPI_MAX_REFERENCE_COUNT        0x1000
  131.76  
  131.77  /* Size of cached memory mapping for system memory operation region */
  131.78  
  131.79  #define ACPI_SYSMEM_REGION_WINDOW_SIZE  4096
  131.80  
  131.81 +/* owner_id tracking. 8 entries allows for 255 owner_ids */
  131.82 +
  131.83 +#define ACPI_NUM_OWNERID_MASKS          8
  131.84 +
  131.85 +/* Size of the root table array is increased by this increment */
  131.86 +
  131.87 +#define ACPI_ROOT_TABLE_SIZE_INCREMENT  4
  131.88  
  131.89  /******************************************************************************
  131.90   *
  131.91 @@ -130,23 +130,19 @@
  131.92  #define ACPI_MAX_GPE_BLOCKS             2
  131.93  #define ACPI_GPE_REGISTER_WIDTH         8
  131.94  
  131.95 -/*
  131.96 - * Method info (in WALK_STATE), containing local variables and argumetns
  131.97 - */
  131.98 +/* Method info (in WALK_STATE), containing local variables and argumetns */
  131.99 +
 131.100  #define ACPI_METHOD_NUM_LOCALS          8
 131.101  #define ACPI_METHOD_MAX_LOCAL           7
 131.102  
 131.103  #define ACPI_METHOD_NUM_ARGS            7
 131.104  #define ACPI_METHOD_MAX_ARG             6
 131.105  
 131.106 -/* Maximum length of resulting string when converting from a buffer */
 131.107 -
 131.108 -#define ACPI_MAX_STRING_CONVERSION      200
 131.109 -
 131.110 -/* Length of _HID, _UID, and _CID values */
 131.111 +/* Length of _HID, _UID, _CID, and UUID values */
 131.112  
 131.113  #define ACPI_DEVICE_ID_LENGTH           0x09
 131.114  #define ACPI_MAX_CID_LENGTH             48
 131.115 +#define ACPI_UUID_LENGTH                16
 131.116  
 131.117  /*
 131.118   * Operand Stack (in WALK_STATE), Must be large enough to contain METHOD_MAX_ARG
 131.119 @@ -157,15 +153,20 @@
 131.120  /* Names within the namespace are 4 bytes long */
 131.121  
 131.122  #define ACPI_NAME_SIZE                  4
 131.123 -#define ACPI_PATH_SEGMENT_LENGTH        5           /* 4 chars for name + 1 char for separator */
 131.124 +#define ACPI_PATH_SEGMENT_LENGTH        5	/* 4 chars for name + 1 char for separator */
 131.125  #define ACPI_PATH_SEPARATOR             '.'
 131.126  
 131.127 +/* Sizes for ACPI table headers */
 131.128 +
 131.129 +#define ACPI_OEM_ID_SIZE                6
 131.130 +#define ACPI_OEM_TABLE_ID_SIZE          8
 131.131 +
 131.132  /* Constants used in searching for the RSDP in low memory */
 131.133  
 131.134 -#define ACPI_EBDA_PTR_LOCATION          0x0000040E     /* Physical Address */
 131.135 +#define ACPI_EBDA_PTR_LOCATION          0x0000040E	/* Physical Address */
 131.136  #define ACPI_EBDA_PTR_LENGTH            2
 131.137  #define ACPI_EBDA_WINDOW_SIZE           1024
 131.138 -#define ACPI_HI_RSDP_WINDOW_BASE        0x000E0000     /* Physical Address */
 131.139 +#define ACPI_HI_RSDP_WINDOW_BASE        0x000E0000	/* Physical Address */
 131.140  #define ACPI_HI_RSDP_WINDOW_SIZE        0x00020000
 131.141  #define ACPI_RSDP_SCAN_STEP             16
 131.142  
 131.143 @@ -180,12 +181,7 @@
 131.144  
 131.145  /* Array sizes.  Used for range checking also */
 131.146  
 131.147 -#define ACPI_NUM_ACCESS_TYPES           6
 131.148 -#define ACPI_NUM_UPDATE_RULES           3
 131.149 -#define ACPI_NUM_LOCK_RULES             2
 131.150 -#define ACPI_NUM_MATCH_OPS              6
 131.151 -#define ACPI_NUM_OPCODES                256
 131.152 -#define ACPI_NUM_FIELD_NAMES            2
 131.153 +#define ACPI_MAX_MATCH_OPCODE           5
 131.154  
 131.155  /* RSDP checksums */
 131.156  
 131.157 @@ -196,22 +192,15 @@
 131.158  
 131.159  #define ACPI_SMBUS_BUFFER_SIZE          34
 131.160  
 131.161 -/* Number of strings associated with the _OSI reserved method */
 131.162 -
 131.163 -#define ACPI_NUM_OSI_STRINGS            9
 131.164 -
 131.165 -
 131.166  /******************************************************************************
 131.167   *
 131.168   * ACPI AML Debugger
 131.169   *
 131.170   *****************************************************************************/
 131.171  
 131.172 -#define ACPI_DEBUGGER_MAX_ARGS          8  /* Must be max method args + 1 */
 131.173 +#define ACPI_DEBUGGER_MAX_ARGS          8	/* Must be max method args + 1 */
 131.174  
 131.175  #define ACPI_DEBUGGER_COMMAND_PROMPT    '-'
 131.176  #define ACPI_DEBUGGER_EXECUTE_PROMPT    '%'
 131.177  
 131.178 -
 131.179 -#endif /* _ACCONFIG_H */
 131.180 -
 131.181 +#endif				/* _ACCONFIG_H */
   132.1 --- a/xen/include/acpi/acexcep.h	Fri Mar 14 15:07:45 2008 -0600
   132.2 +++ b/xen/include/acpi/acexcep.h	Thu Mar 20 12:35:40 2008 -0600
   132.3 @@ -5,7 +5,7 @@
   132.4   *****************************************************************************/
   132.5  
   132.6  /*
   132.7 - * Copyright (C) 2000 - 2005, R. Byron Moore
   132.8 + * Copyright (C) 2000 - 2007, R. Byron Moore
   132.9   * All rights reserved.
  132.10   *
  132.11   * Redistribution and use in source and binary forms, with or without
  132.12 @@ -44,11 +44,9 @@
  132.13  #ifndef __ACEXCEP_H__
  132.14  #define __ACEXCEP_H__
  132.15  
  132.16 -
  132.17  /*
  132.18   * Exceptions returned by external ACPI interfaces
  132.19   */
  132.20 -
  132.21  #define AE_CODE_ENVIRONMENTAL           0x0000
  132.22  #define AE_CODE_PROGRAMMER              0x1000
  132.23  #define AE_CODE_ACPI_TABLES             0x2000
  132.24 @@ -56,11 +54,9 @@
  132.25  #define AE_CODE_CONTROL                 0x4000
  132.26  #define AE_CODE_MASK                    0xF000
  132.27  
  132.28 -
  132.29  #define ACPI_SUCCESS(a)                 (!(a))
  132.30  #define ACPI_FAILURE(a)                 (a)
  132.31  
  132.32 -
  132.33  #define AE_OK                           (acpi_status) 0x0000
  132.34  
  132.35  /*
  132.36 @@ -96,8 +92,9 @@
  132.37  #define AE_ABORT_METHOD                 (acpi_status) (0x001C | AE_CODE_ENVIRONMENTAL)
  132.38  #define AE_SAME_HANDLER                 (acpi_status) (0x001D | AE_CODE_ENVIRONMENTAL)
  132.39  #define AE_WAKE_ONLY_GPE                (acpi_status) (0x001E | AE_CODE_ENVIRONMENTAL)
  132.40 +#define AE_OWNER_ID_LIMIT               (acpi_status) (0x001F | AE_CODE_ENVIRONMENTAL)
  132.41  
  132.42 -#define AE_CODE_ENV_MAX                 0x001E
  132.43 +#define AE_CODE_ENV_MAX                 0x001F
  132.44  
  132.45  /*
  132.46   * Programmer exceptions
  132.47 @@ -114,7 +111,6 @@
  132.48  
  132.49  #define AE_CODE_PGM_MAX                 0x0009
  132.50  
  132.51 -
  132.52  /*
  132.53   * Acpi table exceptions
  132.54   */
  132.55 @@ -127,7 +123,6 @@
  132.56  
  132.57  #define AE_CODE_TBL_MAX                 0x0006
  132.58  
  132.59 -
  132.60  /*
  132.61   * AML exceptions.  These are caused by problems with
  132.62   * the actual AML byte stream
  132.63 @@ -165,8 +160,9 @@
  132.64  #define AE_AML_BAD_RESOURCE_VALUE       (acpi_status) (0x001F | AE_CODE_AML)
  132.65  #define AE_AML_CIRCULAR_REFERENCE       (acpi_status) (0x0020 | AE_CODE_AML)
  132.66  #define AE_AML_BAD_RESOURCE_LENGTH      (acpi_status) (0x0021 | AE_CODE_AML)
  132.67 +#define AE_AML_ILLEGAL_ADDRESS          (acpi_status) (0x0022 | AE_CODE_AML)
  132.68  
  132.69 -#define AE_CODE_AML_MAX                 0x0021
  132.70 +#define AE_CODE_AML_MAX                 0x0022
  132.71  
  132.72  /*
  132.73   * Internal exceptions used for control
  132.74 @@ -182,9 +178,10 @@
  132.75  #define AE_CTRL_BREAK                   (acpi_status) (0x0009 | AE_CODE_CONTROL)
  132.76  #define AE_CTRL_CONTINUE                (acpi_status) (0x000A | AE_CODE_CONTROL)
  132.77  #define AE_CTRL_SKIP                    (acpi_status) (0x000B | AE_CODE_CONTROL)
  132.78 +#define AE_CTRL_PARSE_CONTINUE          (acpi_status) (0x000C | AE_CODE_CONTROL)
  132.79 +#define AE_CTRL_PARSE_PENDING           (acpi_status) (0x000D | AE_CODE_CONTROL)
  132.80  
  132.81 -#define AE_CODE_CTRL_MAX                0x000B
  132.82 -
  132.83 +#define AE_CODE_CTRL_MAX                0x000D
  132.84  
  132.85  #ifdef DEFINE_ACPI_GLOBALS
  132.86  
  132.87 @@ -192,8 +189,7 @@
  132.88   * String versions of the exception codes above
  132.89   * These strings must match the corresponding defines exactly
  132.90   */
  132.91 -char const   *acpi_gbl_exception_names_env[] =
  132.92 -{
  132.93 +char const *acpi_gbl_exception_names_env[] = {
  132.94  	"AE_OK",
  132.95  	"AE_ERROR",
  132.96  	"AE_NO_ACPI_TABLES",
  132.97 @@ -224,11 +220,11 @@ char const   *acpi_gbl_exception_names_e
  132.98  	"AE_LOGICAL_ADDRESS",
  132.99  	"AE_ABORT_METHOD",
 132.100  	"AE_SAME_HANDLER",
 132.101 -	"AE_WAKE_ONLY_GPE"
 132.102 +	"AE_WAKE_ONLY_GPE",
 132.103 +	"AE_OWNER_ID_LIMIT"
 132.104  };
 132.105  
 132.106 -char const   *acpi_gbl_exception_names_pgm[] =
 132.107 -{
 132.108 +char const *acpi_gbl_exception_names_pgm[] = {
 132.109  	"AE_BAD_PARAMETER",
 132.110  	"AE_BAD_CHARACTER",
 132.111  	"AE_BAD_PATHNAME",
 132.112 @@ -240,8 +236,7 @@ char const   *acpi_gbl_exception_names_p
 132.113  	"AE_BAD_DECIMAL_CONSTANT"
 132.114  };
 132.115  
 132.116 -char const   *acpi_gbl_exception_names_tbl[] =
 132.117 -{
 132.118 +char const *acpi_gbl_exception_names_tbl[] = {
 132.119  	"AE_BAD_SIGNATURE",
 132.120  	"AE_BAD_HEADER",
 132.121  	"AE_BAD_CHECKSUM",
 132.122 @@ -250,8 +245,7 @@ char const   *acpi_gbl_exception_names_t
 132.123  	"AE_INVALID_TABLE_LENGTH"
 132.124  };
 132.125  
 132.126 -char const   *acpi_gbl_exception_names_aml[] =
 132.127 -{
 132.128 +char const *acpi_gbl_exception_names_aml[] = {
 132.129  	"AE_AML_ERROR",
 132.130  	"AE_AML_PARSE",
 132.131  	"AE_AML_BAD_OPCODE",
 132.132 @@ -284,11 +278,11 @@ char const   *acpi_gbl_exception_names_a
 132.133  	"AE_AML_NO_RESOURCE_END_TAG",
 132.134  	"AE_AML_BAD_RESOURCE_VALUE",
 132.135  	"AE_AML_CIRCULAR_REFERENCE",
 132.136 -	"AE_AML_BAD_RESOURCE_LENGTH"
 132.137 +	"AE_AML_BAD_RESOURCE_LENGTH",
 132.138 +	"AE_AML_ILLEGAL_ADDRESS"
 132.139  };
 132.140  
 132.141 -char const   *acpi_gbl_exception_names_ctrl[] =
 132.142 -{
 132.143 +char const *acpi_gbl_exception_names_ctrl[] = {
 132.144  	"AE_CTRL_RETURN_VALUE",
 132.145  	"AE_CTRL_PENDING",
 132.146  	"AE_CTRL_TERMINATE",
 132.147 @@ -299,10 +293,11 @@ char const   *acpi_gbl_exception_names_c
 132.148  	"AE_CTRL_TRANSFER",
 132.149  	"AE_CTRL_BREAK",
 132.150  	"AE_CTRL_CONTINUE",
 132.151 -	"AE_CTRL_SKIP"
 132.152 +	"AE_CTRL_SKIP",
 132.153 +	"AE_CTRL_PARSE_CONTINUE",
 132.154 +	"AE_CTRL_PARSE_PENDING"
 132.155  };
 132.156  
 132.157 -#endif /* ACPI GLOBALS */
 132.158 +#endif				/* ACPI GLOBALS */
 132.159  
 132.160 -
 132.161 -#endif /* __ACEXCEP_H__ */
 132.162 +#endif				/* __ACEXCEP_H__ */
   133.1 --- a/xen/include/acpi/acglobal.h	Fri Mar 14 15:07:45 2008 -0600
   133.2 +++ b/xen/include/acpi/acglobal.h	Thu Mar 20 12:35:40 2008 -0600
   133.3 @@ -5,7 +5,7 @@
   133.4   *****************************************************************************/
   133.5  
   133.6  /*
   133.7 - * Copyright (C) 2000 - 2005, R. Byron Moore
   133.8 + * Copyright (C) 2000 - 2007, R. Byron Moore
   133.9   * All rights reserved.
  133.10   *
  133.11   * Redistribution and use in source and binary forms, with or without
  133.12 @@ -44,7 +44,6 @@
  133.13  #ifndef __ACGLOBAL_H__
  133.14  #define __ACGLOBAL_H__
  133.15  
  133.16 -
  133.17  /*
  133.18   * Ensure that the globals are actually defined and initialized only once.
  133.19   *
  133.20 @@ -59,30 +58,6 @@
  133.21  #define ACPI_INIT_GLOBAL(a,b) a
  133.22  #endif
  133.23  
  133.24 -/*
  133.25 - * Keep local copies of these FADT-based registers.  NOTE: These globals
  133.26 - * are first in this file for alignment reasons on 64-bit systems.
  133.27 - */
  133.28 -ACPI_EXTERN struct acpi_generic_address         acpi_gbl_xpm1a_enable;
  133.29 -ACPI_EXTERN struct acpi_generic_address         acpi_gbl_xpm1b_enable;
  133.30 -
  133.31 -
  133.32 -/*****************************************************************************
  133.33 - *
  133.34 - * Debug support
  133.35 - *
  133.36 - ****************************************************************************/
  133.37 -
  133.38 -/* Runtime configuration of debug print levels */
  133.39 -
  133.40 -extern      u32                                 acpi_dbg_level;
  133.41 -extern      u32                                 acpi_dbg_layer;
  133.42 -
  133.43 -/* Procedure nesting level for debug output */
  133.44 -
  133.45 -extern      u32                                 acpi_gbl_nesting_level;
  133.46 -
  133.47 -
  133.48  /*****************************************************************************
  133.49   *
  133.50   * Runtime configuration (static defaults that can be overriden at runtime)
  133.51 @@ -92,36 +67,64 @@ extern      u32                         
  133.52  /*
  133.53   * Enable "slack" in the AML interpreter?  Default is FALSE, and the
  133.54   * interpreter strictly follows the ACPI specification.  Setting to TRUE
  133.55 - * allows the interpreter to forgive certain bad AML constructs.  Currently:
  133.56 + * allows the interpreter to ignore certain errors and/or bad AML constructs.
  133.57 + *
  133.58 + * Currently, these features are enabled by this flag:
  133.59 + *
  133.60   * 1) Allow "implicit return" of last value in a control method
  133.61 - * 2) Allow access beyond end of operation region
  133.62 + * 2) Allow access beyond the end of an operation region
  133.63   * 3) Allow access to uninitialized locals/args (auto-init to integer 0)
  133.64   * 4) Allow ANY object type to be a source operand for the Store() operator
  133.65 + * 5) Allow unresolved references (invalid target name) in package objects
  133.66 + * 6) Enable warning messages for behavior that is not ACPI spec compliant
  133.67   */
  133.68 -ACPI_EXTERN u8       ACPI_INIT_GLOBAL (acpi_gbl_enable_interpreter_slack, FALSE);
  133.69 +ACPI_EXTERN u8 ACPI_INIT_GLOBAL(acpi_gbl_enable_interpreter_slack, FALSE);
  133.70  
  133.71  /*
  133.72   * Automatically serialize ALL control methods? Default is FALSE, meaning
  133.73   * to use the Serialized/not_serialized method flags on a per method basis.
  133.74   * Only change this if the ASL code is poorly written and cannot handle
  133.75 - * reentrancy even though methods are marked "not_serialized".
  133.76 + * reentrancy even though methods are marked "NotSerialized".
  133.77   */
  133.78 -ACPI_EXTERN u8       ACPI_INIT_GLOBAL (acpi_gbl_all_methods_serialized, FALSE);
  133.79 +ACPI_EXTERN u8 ACPI_INIT_GLOBAL(acpi_gbl_all_methods_serialized, FALSE);
  133.80  
  133.81  /*
  133.82   * Create the predefined _OSI method in the namespace? Default is TRUE
  133.83   * because ACPI CA is fully compatible with other ACPI implementations.
  133.84   * Changing this will revert ACPI CA (and machine ASL) to pre-OSI behavior.
  133.85   */
  133.86 -ACPI_EXTERN u8       ACPI_INIT_GLOBAL (acpi_gbl_create_osi_method, TRUE);
  133.87 +ACPI_EXTERN u8 ACPI_INIT_GLOBAL(acpi_gbl_create_osi_method, TRUE);
  133.88  
  133.89  /*
  133.90   * Disable wakeup GPEs during runtime? Default is TRUE because WAKE and
  133.91   * RUNTIME GPEs should never be shared, and WAKE GPEs should typically only
  133.92   * be enabled just before going to sleep.
  133.93   */
  133.94 -ACPI_EXTERN u8       ACPI_INIT_GLOBAL (acpi_gbl_leave_wake_gpes_disabled, TRUE);
  133.95 +ACPI_EXTERN u8 ACPI_INIT_GLOBAL(acpi_gbl_leave_wake_gpes_disabled, TRUE);
  133.96 +
  133.97 +/*****************************************************************************
  133.98 + *
  133.99 + * Debug support
 133.100 + *
 133.101 + ****************************************************************************/
 133.102 +
 133.103 +/* Runtime configuration of debug print levels */
 133.104 +
 133.105 +extern u32 acpi_dbg_level;
 133.106 +extern u32 acpi_dbg_layer;
 133.107  
 133.108 +/* Procedure nesting level for debug output */
 133.109 +
 133.110 +extern u32 acpi_gbl_nesting_level;
 133.111 +
 133.112 +/* Support for dynamic control method tracing mechanism */
 133.113 +
 133.114 +ACPI_EXTERN u32 acpi_gbl_original_dbg_level;
 133.115 +ACPI_EXTERN u32 acpi_gbl_original_dbg_layer;
 133.116 +ACPI_EXTERN acpi_name acpi_gbl_trace_method_name;
 133.117 +ACPI_EXTERN u32 acpi_gbl_trace_dbg_level;
 133.118 +ACPI_EXTERN u32 acpi_gbl_trace_dbg_layer;
 133.119 +ACPI_EXTERN u32 acpi_gbl_trace_flags;
 133.120  
 133.121  /*****************************************************************************
 133.122   *
 133.123 @@ -130,49 +133,56 @@ ACPI_EXTERN u8       ACPI_INIT_GLOBAL (a
 133.124   ****************************************************************************/
 133.125  
 133.126  /*
 133.127 - * Table pointers.
 133.128 - * Although these pointers are somewhat redundant with the global acpi_table,
 133.129 - * they are convenient because they are typed pointers.
 133.130 + * acpi_gbl_root_table_list is the master list of ACPI tables found in the
 133.131 + * RSDT/XSDT.
 133.132   *
 133.133 - * These tables are single-table only; meaning that there can be at most one
 133.134 - * of each in the system.  Each global points to the actual table.
 133.135 + * acpi_gbl_FADT is a local copy of the FADT, converted to a common format.
 133.136   */
 133.137 -ACPI_EXTERN u32                                 acpi_gbl_table_flags;
 133.138 -ACPI_EXTERN u32                                 acpi_gbl_rsdt_table_count;
 133.139 -ACPI_EXTERN struct rsdp_descriptor             *acpi_gbl_RSDP;
 133.140 -ACPI_EXTERN XSDT_DESCRIPTOR            *acpi_gbl_XSDT;
 133.141 -ACPI_EXTERN FADT_DESCRIPTOR            *acpi_gbl_FADT;
 133.142 -ACPI_EXTERN struct acpi_table_header           *acpi_gbl_DSDT;
 133.143 -ACPI_EXTERN FACS_DESCRIPTOR            *acpi_gbl_FACS;
 133.144 -ACPI_EXTERN struct acpi_common_facs             acpi_gbl_common_fACS;
 133.145 -/*
 133.146 - * Since there may be multiple SSDTs and PSDTS, a single pointer is not
 133.147 - * sufficient; Therefore, there isn't one!
 133.148 - */
 133.149 +ACPI_EXTERN struct acpi_internal_rsdt acpi_gbl_root_table_list;
 133.150 +ACPI_EXTERN struct acpi_table_fadt acpi_gbl_FADT;
 133.151 +extern acpi_native_uint acpi_gbl_permanent_mmap;
 133.152  
 133.153 +/* These addresses are calculated from FADT address values */
 133.154 +
 133.155 +ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1a_enable;
 133.156 +ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1b_enable;
 133.157  
 133.158  /*
 133.159 - * Handle both ACPI 1.0 and ACPI 2.0 Integer widths
 133.160 - * If we are running a method that exists in a 32-bit ACPI table.
 133.161 - * Use only 32 bits of the Integer for conversion.
 133.162 + * Handle both ACPI 1.0 and ACPI 2.0 Integer widths. The integer width is
 133.163 + * determined by the revision of the DSDT: If the DSDT revision is less than
 133.164 + * 2, use only the lower 32 bits of the internal 64-bit Integer.
 133.165   */
 133.166 -ACPI_EXTERN u8                                  acpi_gbl_integer_bit_width;
 133.167 -ACPI_EXTERN u8                                  acpi_gbl_integer_byte_width;
 133.168 -ACPI_EXTERN u8                                  acpi_gbl_integer_nybble_width;
 133.169 +ACPI_EXTERN u8 acpi_gbl_integer_bit_width;
 133.170 +ACPI_EXTERN u8 acpi_gbl_integer_byte_width;
 133.171 +ACPI_EXTERN u8 acpi_gbl_integer_nybble_width;
 133.172 +
 133.173 +/*****************************************************************************
 133.174 + *
 133.175 + * Mutual exlusion within ACPICA subsystem
 133.176 + *
 133.177 + ****************************************************************************/
 133.178  
 133.179  /*
 133.180 - * ACPI Table info arrays
 133.181 - */
 133.182 -extern      struct acpi_table_list              acpi_gbl_table_lists[NUM_ACPI_TABLE_TYPES];
 133.183 -extern      struct acpi_table_support           acpi_gbl_table_data[NUM_ACPI_TABLE_TYPES];
 133.184 -
 133.185 -/*
 133.186 - * Predefined mutex objects.  This array contains the
 133.187 + * Predefined mutex objects. This array contains the
 133.188   * actual OS mutex handles, indexed by the local ACPI_MUTEX_HANDLEs.
 133.189   * (The table maps local handles to the real OS handles)
 133.190   */
 133.191 -ACPI_EXTERN struct acpi_mutex_info              acpi_gbl_mutex_info[NUM_MUTEX];
 133.192 +ACPI_EXTERN struct acpi_mutex_info acpi_gbl_mutex_info[ACPI_NUM_MUTEX];
 133.193 +
 133.194 +/*
 133.195 + * Global lock semaphore works in conjunction with the actual HW global lock
 133.196 + */
 133.197 +ACPI_EXTERN acpi_mutex acpi_gbl_global_lock_mutex;
 133.198 +ACPI_EXTERN acpi_semaphore acpi_gbl_global_lock_semaphore;
 133.199  
 133.200 +/*
 133.201 + * Spinlocks are used for interfaces that can be possibly called at
 133.202 + * interrupt level
 133.203 + */
 133.204 +ACPI_EXTERN spinlock_t _acpi_gbl_gpe_lock;	/* For GPE data structs and registers */
 133.205 +ACPI_EXTERN spinlock_t _acpi_gbl_hardware_lock;	/* For ACPI H/W except GPE registers */
 133.206 +#define acpi_gbl_gpe_lock	&_acpi_gbl_gpe_lock
 133.207 +#define acpi_gbl_hardware_lock	&_acpi_gbl_hardware_lock
 133.208  
 133.209  /*****************************************************************************
 133.210   *
 133.211 @@ -180,41 +190,64 @@ ACPI_EXTERN struct acpi_mutex_info      
 133.212   *
 133.213   ****************************************************************************/
 133.214  
 133.215 +#ifdef ACPI_DBG_TRACK_ALLOCATIONS
 133.216  
 133.217 -ACPI_EXTERN struct acpi_memory_list             acpi_gbl_memory_lists[ACPI_NUM_MEM_LISTS];
 133.218 -ACPI_EXTERN struct acpi_object_notify_handler   acpi_gbl_device_notify;
 133.219 -ACPI_EXTERN struct acpi_object_notify_handler   acpi_gbl_system_notify;
 133.220 -ACPI_EXTERN acpi_exception_handler              acpi_gbl_exception_handler;
 133.221 -ACPI_EXTERN acpi_init_handler                   acpi_gbl_init_handler;
 133.222 -ACPI_EXTERN struct acpi_walk_state             *acpi_gbl_breakpoint_walk;
 133.223 -ACPI_EXTERN acpi_handle                         acpi_gbl_global_lock_semaphore;
 133.224 +/* Lists for tracking memory allocations */
 133.225 +
 133.226 +ACPI_EXTERN struct acpi_memory_list *acpi_gbl_global_list;
 133.227 +ACPI_EXTERN struct acpi_memory_list *acpi_gbl_ns_node_list;
 133.228 +ACPI_EXTERN u8 acpi_gbl_display_final_mem_stats;
 133.229 +#endif
 133.230 +
 133.231 +/* Object caches */
 133.232 +
 133.233 +ACPI_EXTERN acpi_cache_t *acpi_gbl_namespace_cache;
 133.234 +ACPI_EXTERN acpi_cache_t *acpi_gbl_state_cache;
 133.235 +ACPI_EXTERN acpi_cache_t *acpi_gbl_ps_node_cache;
 133.236 +ACPI_EXTERN acpi_cache_t *acpi_gbl_ps_node_ext_cache;
 133.237 +ACPI_EXTERN acpi_cache_t *acpi_gbl_operand_cache;
 133.238 +
 133.239 +/* Global handlers */
 133.240 +
 133.241 +ACPI_EXTERN struct acpi_object_notify_handler acpi_gbl_device_notify;
 133.242 +ACPI_EXTERN struct acpi_object_notify_handler acpi_gbl_system_notify;
 133.243 +ACPI_EXTERN acpi_exception_handler acpi_gbl_exception_handler;
 133.244 +ACPI_EXTERN acpi_init_handler acpi_gbl_init_handler;
 133.245 +ACPI_EXTERN struct acpi_walk_state *acpi_gbl_breakpoint_walk;
 133.246 +
 133.247 +/* Misc */
 133.248  
 133.249 -ACPI_EXTERN u32                                 acpi_gbl_global_lock_thread_count;
 133.250 -ACPI_EXTERN u32                                 acpi_gbl_original_mode;
 133.251 -ACPI_EXTERN u32                                 acpi_gbl_rsdp_original_location;
 133.252 -ACPI_EXTERN u32                                 acpi_gbl_ns_lookup_count;
 133.253 -ACPI_EXTERN u32                                 acpi_gbl_ps_find_count;
 133.254 -ACPI_EXTERN u16                                 acpi_gbl_pm1_enable_register_save;
 133.255 -ACPI_EXTERN u16                                 acpi_gbl_next_table_owner_id;
 133.256 -ACPI_EXTERN u16                                 acpi_gbl_next_method_owner_id;
 133.257 -ACPI_EXTERN u16                                 acpi_gbl_global_lock_handle;
 133.258