ia64/xen-unstable

changeset 8186:28bd01c9b596

Merge
author djm@kirby.fc.hp.com
date Fri Dec 02 12:52:25 2005 -0600 (2005-12-02)
parents eae5812f33f1 e13c994bdccb
children d616f22ffdd9
files xen/Rules.mk xen/arch/ia64/xen/domain.c
line diff
     1.1 --- a/Config.mk	Fri Dec 02 12:12:11 2005 -0600
     1.2 +++ b/Config.mk	Fri Dec 02 12:52:25 2005 -0600
     1.3 @@ -38,19 +38,32 @@ EXTRA_INCLUDES += $(EXTRA_PREFIX)/includ
     1.4  EXTRA_LIB += $(EXTRA_PREFIX)/$(LIBDIR)
     1.5  endif
     1.6  
     1.7 +test-gcc-flag = $(shell $(CC) -v --help 2>&1 | grep -q " $(1) " && echo $(1))
     1.8 +
     1.9 +HOSTCFLAGS += $(call test-gcc-flag,-Wdeclaration-after-statement)
    1.10 +CFLAGS     += $(call test-gcc-flag,-Wdeclaration-after-statement)
    1.11 +
    1.12  LDFLAGS += $(foreach i, $(EXTRA_LIB), -L$(i)) 
    1.13  CFLAGS += $(foreach i, $(EXTRA_INCLUDES), -I$(i))
    1.14  
    1.15  # Choose the best mirror to download linux kernel
    1.16  KERNEL_REPO = http://www.kernel.org
    1.17  
    1.18 -# ACM_USE_SECURITY_POLICY is set to security policy of Xen
    1.19 +# If ACM_SECURITY = y, then the access control module is compiled
    1.20 +# into Xen and the policy type can be set by the boot policy file
    1.21 +#        y - Build the Xen ACM framework
    1.22 +#        n - Do not build the Xen ACM framework
    1.23 +ACM_SECURITY ?= n
    1.24 +
    1.25 +# If ACM_SECURITY = y and no boot policy file is installed,
    1.26 +# then the ACM defaults to the security policy set by
    1.27 +# ACM_DEFAULT_SECURITY_POLICY
    1.28  # Supported models are:
    1.29 -#	ACM_NULL_POLICY (ACM will not be built with this policy)
    1.30 +#	ACM_NULL_POLICY
    1.31  #	ACM_CHINESE_WALL_POLICY
    1.32  #	ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY
    1.33  #	ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY
    1.34 -ACM_USE_SECURITY_POLICY ?= ACM_NULL_POLICY
    1.35 +ACM_DEFAULT_SECURITY_POLICY ?= ACM_NULL_POLICY
    1.36  
    1.37  # Optional components
    1.38  XENSTAT_XENTOP ?= y
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/docs/README.xen-bugtool	Fri Dec 02 12:52:25 2005 -0600
     2.3 @@ -0,0 +1,16 @@
     2.4 +xen-bugtool
     2.5 +===========
     2.6 +
     2.7 +The xen-bugtool command line application will collate the Xen dmesg output,
     2.8 +details of the hardware configuration of your machine, information about the
     2.9 +build of Xen that you are using, plus, if you allow it, various logs.
    2.10 +
    2.11 +The information collated can either be posted to a Xen Bugzilla bug (this bug
    2.12 +must already exist in the system, and you must be a registered user there), or
    2.13 +it can be saved as a .tar.bz2 for sending or archiving.
    2.14 +
    2.15 +The collated logs may contain private information, and if you are at all
    2.16 +worried about that, you should not use this tool, or you should explicitly
    2.17 +exclude those logs from the archive.
    2.18 +
    2.19 +xen-bugtool is wholly interactive, so simply run it, and answer the questions.
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/docs/man/xend-config.sxp.pod.5	Fri Dec 02 12:52:25 2005 -0600
     3.3 @@ -0,0 +1,142 @@
     3.4 +=head1 NAME
     3.5 +
     3.6 +xend-config.sxp - Xen daemon configuration file
     3.7 +
     3.8 +=head1 SYNOPSIS
     3.9 +
    3.10 +/etc/xen/xend-config.sxp
    3.11 +
    3.12 +=head1 DESCRIPTION
    3.13 +
    3.14 +The xend(1) program requires xend-config.sxp to specify operating
    3.15 +parameters which determine the behavior of the daemon at runtime.
    3.16 +
    3.17 +The parameters are specified in S-expression format.  See the example
    3.18 +configuration file in I</etc/xen/xend-config.sxp> for details.
    3.19 +
    3.20 +=head1 OPTIONS
    3.21 +
    3.22 +The following lists the daemon configuration parameters:
    3.23 +
    3.24 +=over 4
    3.25 +
    3.26 +=item I<logfile>
    3.27 +
    3.28 +The location of the file to record runtime log messages.  Defaults to
    3.29 +I</var/log/xend.log>.
    3.30 +
    3.31 +=item I<loglevel>
    3.32 +
    3.33 +Filters out messages below the specified level.  Possible values are
    3.34 +DEBUG, INFO, WARNING, ERROR, CRITICAL.  Defaults to I<DEBUG>.
    3.35 +
    3.36 +=item I<xend-http-server>
    3.37 +
    3.38 +A boolean value that tells xend whether or not to start the http
    3.39 +stream socket management server.  Defaults to I<no>.
    3.40 +
    3.41 +=item I<xend-unix-server>
    3.42 +
    3.43 +A boolean value that tells xend whether or not to start the unix
    3.44 +domain socket management server.  This is required for the CLI tools
    3.45 +to operate.  Defaults to I<yes>.
    3.46 +
    3.47 +=item I<xend-relocation-server>
    3.48 +
    3.49 +A boolean value that tells xend whether or not to start the relocation
    3.50 +server.  This is required for cross-machine migrations.  Defaults to
    3.51 +I<no>.
    3.52 +
    3.53 +=item I<xend-unix-path>
    3.54 +
    3.55 +The location of the unix domain socket the xend-unix-server will use
    3.56 +to communicate with the management tools.  Defaults to
    3.57 +I</var/lib/xend/xend-socket>.
    3.58 +
    3.59 +=item I<xend-port>
    3.60 +
    3.61 +The port that will be used by the http management server.  Defaults to
    3.62 +I<8000>.
    3.63 +
    3.64 +=item I<xend-relocation-port>
    3.65 +
    3.66 +The port that will be used by the relocation server.  Defaults to
    3.67 +I<8002>.
    3.68 +
    3.69 +=item I<xend-address> 
    3.70 +
    3.71 +The address to which the http management server will bind.  Defaults
    3.72 +to I<''> which means "all interfaces".
    3.73 +
    3.74 +=item I<xend-relocation-address>
    3.75 +
    3.76 +The address to which the relocation server will bind.  Defaults to
    3.77 +I<''> which means "all interfaces".
    3.78 +
    3.79 +=item I<console-limit>
    3.80 +
    3.81 +The kilobyte buffer limit that will be enforced by the console server.
    3.82 +This limit is set per-domain, and is needed to prevent a single domain
    3.83 +from overwhelming the console server with massive amounts of data.
    3.84 +Defaults to I<1024>.
    3.85 +
    3.86 +=item I<network-script>
    3.87 +
    3.88 +The name of the script in I</etc/xen/scripts> that will be run to
    3.89 +setup the networking environment.  This can be any name, but in
    3.90 +general is either I<network-bridge> or I<network-route>.
    3.91 +
    3.92 +=item I<vif-script>
    3.93 +
    3.94 +The name of the script in I</etc/xen/scripts> that will be run to
    3.95 +setup a virtual interface when it is created or destroyed.  This needs
    3.96 +to (in general) work in unison with the I<network-script>.
    3.97 +
    3.98 +=item I<dom0-min-mem>
    3.99 +
   3.100 +This specifies the minimum number of megabytes that will be reserved
   3.101 +for Domain0.  If this value is positive, Domain0 will be automatically
   3.102 +ballooned down to this limit to make space for new domains.  If this
   3.103 +is set to 0, Domain0 will not be automatically ballooned.
   3.104 +
   3.105 +=item I<dom0-cpus>
   3.106 +
   3.107 +This specifies the number of CPUs that Domain0 will be allowed to use.
   3.108 +If the value is 0, all available CPUs will be used by Domain0.
   3.109 +
   3.110 +=item I<enable-dump>
   3.111 +
   3.112 +A boolean value that tells xend whether or not core dumps of guest
   3.113 +domains should be saved when a crash occurrs.  Defaults to I<no>.
   3.114 +
   3.115 +=back
   3.116 +
   3.117 +=head1 EXAMPLES
   3.118 +
   3.119 +An example configuration with relocation enabled for the local network:
   3.120 +
   3.121 +=over 4
   3.122 +
   3.123 + (xend-relocation-server yes)
   3.124 + (xend-relocation-address 192.168.1.1)
   3.125 + (network-script network-bridge)
   3.126 + (vif-script vif-bridge)
   3.127 + (dom0-min-mem 0)
   3.128 + (dom0-cpus 0)
   3.129 +
   3.130 +=back
   3.131 +
   3.132 +=head1 CAVEATS
   3.133 +
   3.134 +Note that relocation is currently unsecured and is very dangerous if
   3.135 +left enabled.  No authentication is performed, and very little sanity
   3.136 +checking takes place.  Enable at your own risk.
   3.137 +
   3.138 +=head1 SEE ALSO
   3.139 +
   3.140 +B<xend>(1)
   3.141 +
   3.142 +=head1 AUTHOR
   3.143 +
   3.144 +Dan Smith <danms@us.ibm.com>
   3.145 +
     4.1 --- a/docs/misc/vtpm.txt	Fri Dec 02 12:12:11 2005 -0600
     4.2 +++ b/docs/misc/vtpm.txt	Fri Dec 02 12:52:25 2005 -0600
     4.3 @@ -73,7 +73,14 @@ information about the domain where the v
     4.4  where the TPM backend has been compiled into - this has to be 
     4.5  domain 0  at the moment - and which TPM instance the user domain
     4.6  is supposed to talk to. Note that each running VM must use a 
     4.7 -different instance and that using instance 0 is NOT allowed.
     4.8 +different instance and that using instance 0 is NOT allowed. The
     4.9 +instance parameter is taken as the desired instance number, but
    4.10 +the actual instance number that is assigned to the virtual machine
    4.11 +can be different. This is the case if for example that particular
    4.12 +instance is already used by another virtual machine. The association
    4.13 +of which TPM instance number is used by which virtual machine is
    4.14 +kept in the file /etc/xen/vtpm.db. Associations are maintained by
    4.15 +domain name and instance number.
    4.16  
    4.17  Note: If you do not want TPM functionality for your user domain simply
    4.18  leave out the 'vtpm' line in the configuration file.
     5.1 --- a/install.sh	Fri Dec 02 12:12:11 2005 -0600
     5.2 +++ b/install.sh	Fri Dec 02 12:52:25 2005 -0600
     5.3 @@ -27,7 +27,10 @@ echo "Installing Xen from '$src' to '$ds
     5.4  cp -fdRL $src/etc/init.d/* $dst/etc/init.d/
     5.5  echo "All done."
     5.6  
     5.7 -if [ -x /sbin/udev ] && [ ! -z `/sbin/udev -V` ] && [ `/sbin/udev -V` -ge 059 ]; then
     5.8 +[ -x "$(which udevinfo)" ] && \
     5.9 +  UDEV_VERSION=$(udevinfo -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/')
    5.10 +
    5.11 +if [ -n "$UDEV_VERSION" ] && [ $UDEV_VERSION -ge 059 ]; then
    5.12    cp -f $src/etc/udev/rules.d/*.rules $dst/etc/udev/rules.d/
    5.13  else
    5.14    cp -f $src/etc/hotplug/*.agent $dst/etc/hotplug/
     6.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/drivers/evtchn_ia64.c	Fri Dec 02 12:12:11 2005 -0600
     6.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/drivers/evtchn_ia64.c	Fri Dec 02 12:52:25 2005 -0600
     6.3 @@ -155,7 +155,7 @@ irqreturn_t evtchn_interrupt(int irq, vo
     6.4      unsigned int   l1i, l2i, port;
     6.5      irqreturn_t (*handler)(int, void *, struct pt_regs *);
     6.6      shared_info_t *s = HYPERVISOR_shared_info;
     6.7 -    vcpu_info_t   *vcpu_info = &s->vcpu_data[smp_processor_id()];
     6.8 +    vcpu_info_t   *vcpu_info = &s->vcpu_info[smp_processor_id()];
     6.9  
    6.10      vcpu_info->evtchn_upcall_mask = 1;
    6.11      vcpu_info->evtchn_upcall_pending = 0;
    6.12 @@ -203,7 +203,7 @@ int evtchn_irq = 0xe9;
    6.13  void __init evtchn_init(void)
    6.14  {
    6.15      shared_info_t *s = HYPERVISOR_shared_info;
    6.16 -    vcpu_info_t   *vcpu_info = &s->vcpu_data[smp_processor_id()];
    6.17 +    vcpu_info_t   *vcpu_info = &s->vcpu_info[smp_processor_id()];
    6.18  
    6.19  #if 0
    6.20      int ret;
     7.1 --- a/linux-2.6-xen-sparse/arch/xen/Kconfig	Fri Dec 02 12:12:11 2005 -0600
     7.2 +++ b/linux-2.6-xen-sparse/arch/xen/Kconfig	Fri Dec 02 12:52:25 2005 -0600
     7.3 @@ -70,6 +70,19 @@ config XEN_NETDEV_BACKEND
     7.4  	  network devices to other guests via a high-performance shared-memory
     7.5  	  interface.
     7.6  
     7.7 +config XEN_NETDEV_PIPELINED_TRANSMITTER
     7.8 +	bool "Pipelined transmitter (DANGEROUS)"
     7.9 +	depends on XEN_NETDEV_BACKEND
    7.10 +	default n
    7.11 +	help
    7.12 +	  If the net backend is a dumb domain, such as a transparent Ethernet
    7.13 +	  bridge with no local IP interface, it is safe to say Y here to get
    7.14 +	  slightly lower network overhead.
    7.15 +	  If the backend has a local IP interface; or may be doing smart things
    7.16 +	  like reassembling packets to perform firewall filtering; or if you
    7.17 +	  are unsure; or if you experience network hangs when this option is
    7.18 +	  enabled; then you must say N here.
    7.19 +
    7.20  config XEN_TPMDEV_FRONTEND
    7.21          bool "TPM-device frontend driver"
    7.22          default n
    7.23 @@ -111,23 +124,6 @@ config XEN_NETDEV_FRONTEND
    7.24  	  dedicated device-driver domain, or your master control domain
    7.25  	  (domain 0), then you almost certainly want to say Y here.
    7.26  
    7.27 -config XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER
    7.28 -	bool "Pipelined transmitter (DANGEROUS)"
    7.29 -	depends on XEN_NETDEV_FRONTEND
    7.30 -	default n
    7.31 -	help
    7.32 -	  The driver will assume that the backend is pipelining packets for
    7.33 -	  transmission: whenever packets are pending in the remote backend,
    7.34 -	  the driver will not send asynchronous notifications when it queues
    7.35 -	  additional packets for transmission.
    7.36 -	  If the backend is a dumb domain, such as a transparent Ethernet
    7.37 -	  bridge with no local IP interface, it is safe to say Y here to get
    7.38 -	  slightly lower network overhead.
    7.39 -	  If the backend has a local IP interface; or may be doing smart things
    7.40 -	  like reassembling packets to perform firewall filtering; or if you
    7.41 -	  are unsure; or if you experience network hangs when this option is
    7.42 -	  enabled; then you must say N here.
    7.43 -
    7.44  config XEN_BLKDEV_TAP
    7.45  	bool "Block device tap driver"
    7.46  	default n
     8.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32	Fri Dec 02 12:12:11 2005 -0600
     8.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32	Fri Dec 02 12:52:25 2005 -0600
     8.3 @@ -15,11 +15,11 @@ CONFIG_XEN_PHYSDEV_ACCESS=y
     8.4  CONFIG_XEN_BLKDEV_BACKEND=y
     8.5  # CONFIG_XEN_BLKDEV_TAP_BE is not set
     8.6  CONFIG_XEN_NETDEV_BACKEND=y
     8.7 +# CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set
     8.8  # CONFIG_XEN_TPMDEV_FRONTEND is not set
     8.9  # CONFIG_XEN_TPMDEV_BACKEND is not set
    8.10  CONFIG_XEN_BLKDEV_FRONTEND=y
    8.11  CONFIG_XEN_NETDEV_FRONTEND=y
    8.12 -# CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    8.13  # CONFIG_XEN_BLKDEV_TAP is not set
    8.14  # CONFIG_XEN_SHADOW_MODE is not set
    8.15  CONFIG_XEN_SCRUB_PAGES=y
    8.16 @@ -35,7 +35,6 @@ CONFIG_EXPERIMENTAL=y
    8.17  # CONFIG_CLEAN_COMPILE is not set
    8.18  CONFIG_BROKEN=y
    8.19  CONFIG_BROKEN_ON_SMP=y
    8.20 -CONFIG_LOCK_KERNEL=y
    8.21  CONFIG_INIT_ENV_ARG_LIMIT=32
    8.22  
    8.23  #
    8.24 @@ -125,8 +124,6 @@ CONFIG_X86_USE_PPRO_CHECKSUM=y
    8.25  # CONFIG_HPET_TIMER is not set
    8.26  # CONFIG_HPET_EMULATE_RTC is not set
    8.27  # CONFIG_SMP is not set
    8.28 -CONFIG_PREEMPT=y
    8.29 -CONFIG_PREEMPT_BKL=y
    8.30  # CONFIG_X86_REBOOTFIXUPS is not set
    8.31  CONFIG_MICROCODE=y
    8.32  CONFIG_X86_CPUID=y
    8.33 @@ -141,7 +138,6 @@ CONFIG_HIGHMEM4G=y
    8.34  # CONFIG_HIGHMEM64G is not set
    8.35  CONFIG_HIGHMEM=y
    8.36  CONFIG_MTRR=y
    8.37 -CONFIG_HAVE_DEC_LOCK=y
    8.38  # CONFIG_REGPARM is not set
    8.39  CONFIG_X86_LOCAL_APIC=y
    8.40  CONFIG_X86_IO_APIC=y
    8.41 @@ -1259,7 +1255,6 @@ CONFIG_MAGIC_SYSRQ=y
    8.42  CONFIG_LOG_BUF_SHIFT=14
    8.43  # CONFIG_SCHEDSTATS is not set
    8.44  # CONFIG_DEBUG_SLAB is not set
    8.45 -# CONFIG_DEBUG_PREEMPT is not set
    8.46  # CONFIG_DEBUG_SPINLOCK is not set
    8.47  # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
    8.48  # CONFIG_DEBUG_KOBJECT is not set
     9.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64	Fri Dec 02 12:12:11 2005 -0600
     9.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64	Fri Dec 02 12:52:25 2005 -0600
     9.3 @@ -15,11 +15,11 @@ CONFIG_XEN_PHYSDEV_ACCESS=y
     9.4  CONFIG_XEN_BLKDEV_BACKEND=y
     9.5  # CONFIG_XEN_BLKDEV_TAP_BE is not set
     9.6  CONFIG_XEN_NETDEV_BACKEND=y
     9.7 +# CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set
     9.8  # CONFIG_XEN_TPMDEV_FRONTEND is not set
     9.9  # CONFIG_XEN_TPMDEV_BACKEND is not set
    9.10  CONFIG_XEN_BLKDEV_FRONTEND=y
    9.11  CONFIG_XEN_NETDEV_FRONTEND=y
    9.12 -# CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    9.13  # CONFIG_XEN_BLKDEV_TAP is not set
    9.14  # CONFIG_XEN_SHADOW_MODE is not set
    9.15  CONFIG_XEN_SCRUB_PAGES=y
    9.16 @@ -90,7 +90,6 @@ CONFIG_GENERIC_CALIBRATE_DELAY=y
    9.17  CONFIG_X86_GOOD_APIC=y
    9.18  # CONFIG_HPET_TIMER is not set
    9.19  # CONFIG_SMP is not set
    9.20 -# CONFIG_PREEMPT is not set
    9.21  CONFIG_MICROCODE=y
    9.22  # CONFIG_X86_CPUID is not set
    9.23  CONFIG_SWIOTLB=y
    10.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32	Fri Dec 02 12:12:11 2005 -0600
    10.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32	Fri Dec 02 12:52:25 2005 -0600
    10.3 @@ -16,7 +16,6 @@ CONFIG_NO_IDLE_HZ=y
    10.4  # CONFIG_XEN_TPMDEV_BACKEND is not set
    10.5  CONFIG_XEN_BLKDEV_FRONTEND=y
    10.6  CONFIG_XEN_NETDEV_FRONTEND=y
    10.7 -# CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    10.8  # CONFIG_XEN_BLKDEV_TAP is not set
    10.9  # CONFIG_XEN_SHADOW_MODE is not set
   10.10  CONFIG_XEN_SCRUB_PAGES=y
   10.11 @@ -125,8 +124,6 @@ CONFIG_SMP=y
   10.12  CONFIG_SMP_ALTERNATIVES=y
   10.13  CONFIG_NR_CPUS=8
   10.14  # CONFIG_SCHED_SMT is not set
   10.15 -CONFIG_PREEMPT=y
   10.16 -CONFIG_PREEMPT_BKL=y
   10.17  # CONFIG_X86_REBOOTFIXUPS is not set
   10.18  CONFIG_X86_CPUID=y
   10.19  
   10.20 @@ -550,7 +547,6 @@ CONFIG_MAGIC_SYSRQ=y
   10.21  CONFIG_LOG_BUF_SHIFT=14
   10.22  # CONFIG_SCHEDSTATS is not set
   10.23  # CONFIG_DEBUG_SLAB is not set
   10.24 -# CONFIG_DEBUG_PREEMPT is not set
   10.25  # CONFIG_DEBUG_SPINLOCK is not set
   10.26  # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
   10.27  # CONFIG_DEBUG_KOBJECT is not set
    11.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64	Fri Dec 02 12:12:11 2005 -0600
    11.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64	Fri Dec 02 12:52:25 2005 -0600
    11.3 @@ -16,7 +16,6 @@ CONFIG_NO_IDLE_HZ=y
    11.4  # CONFIG_XEN_TPMDEV_BACKEND is not set
    11.5  CONFIG_XEN_BLKDEV_FRONTEND=y
    11.6  CONFIG_XEN_NETDEV_FRONTEND=y
    11.7 -# CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    11.8  # CONFIG_XEN_BLKDEV_TAP is not set
    11.9  # CONFIG_XEN_SHADOW_MODE is not set
   11.10  CONFIG_XEN_SCRUB_PAGES=y
   11.11 @@ -92,7 +91,6 @@ CONFIG_X86_GOOD_APIC=y
   11.12  CONFIG_SMP=y
   11.13  CONFIG_NR_CPUS=8
   11.14  # CONFIG_SCHED_SMT is not set
   11.15 -# CONFIG_PREEMPT is not set
   11.16  # CONFIG_MICROCODE is not set
   11.17  CONFIG_X86_CPUID=y
   11.18  # CONFIG_NUMA is not set
    12.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32	Fri Dec 02 12:12:11 2005 -0600
    12.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32	Fri Dec 02 12:52:25 2005 -0600
    12.3 @@ -1,7 +1,7 @@
    12.4  #
    12.5  # Automatically generated make config: don't edit
    12.6 -# Linux kernel version: 2.6.12-xen0
    12.7 -# Sat Oct 15 00:13:28 2005
    12.8 +# Linux kernel version: 2.6.12.6-xen
    12.9 +# Mon Nov 28 11:04:51 2005
   12.10  #
   12.11  CONFIG_XEN=y
   12.12  CONFIG_ARCH_XEN=y
   12.13 @@ -15,11 +15,11 @@ CONFIG_XEN_PHYSDEV_ACCESS=y
   12.14  CONFIG_XEN_BLKDEV_BACKEND=y
   12.15  # CONFIG_XEN_BLKDEV_TAP_BE is not set
   12.16  CONFIG_XEN_NETDEV_BACKEND=y
   12.17 +# CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set
   12.18  # CONFIG_XEN_TPMDEV_FRONTEND is not set
   12.19  # CONFIG_XEN_TPMDEV_BACKEND is not set
   12.20  CONFIG_XEN_BLKDEV_FRONTEND=y
   12.21  CONFIG_XEN_NETDEV_FRONTEND=y
   12.22 -# CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
   12.23  # CONFIG_XEN_BLKDEV_TAP is not set
   12.24  # CONFIG_XEN_SHADOW_MODE is not set
   12.25  CONFIG_XEN_SCRUB_PAGES=y
   12.26 @@ -132,10 +132,8 @@ CONFIG_SMP=y
   12.27  CONFIG_SMP_ALTERNATIVES=y
   12.28  CONFIG_NR_CPUS=8
   12.29  # CONFIG_SCHED_SMT is not set
   12.30 -CONFIG_PREEMPT=y
   12.31 -CONFIG_PREEMPT_BKL=y
   12.32  # CONFIG_X86_REBOOTFIXUPS is not set
   12.33 -CONFIG_MICROCODE=m
   12.34 +CONFIG_MICROCODE=y
   12.35  CONFIG_X86_CPUID=m
   12.36  CONFIG_SWIOTLB=y
   12.37  
   12.38 @@ -434,71 +432,71 @@ CONFIG_IOSCHED_NOOP=y
   12.39  CONFIG_IOSCHED_AS=y
   12.40  CONFIG_IOSCHED_DEADLINE=y
   12.41  CONFIG_IOSCHED_CFQ=y
   12.42 -# CONFIG_ATA_OVER_ETH is not set
   12.43 +CONFIG_ATA_OVER_ETH=m
   12.44  
   12.45  #
   12.46  # ATA/ATAPI/MFM/RLL support
   12.47  #
   12.48 -CONFIG_IDE=m
   12.49 -CONFIG_BLK_DEV_IDE=m
   12.50 +CONFIG_IDE=y
   12.51 +CONFIG_BLK_DEV_IDE=y
   12.52  
   12.53  #
   12.54  # Please see Documentation/ide.txt for help/info on IDE drives
   12.55  #
   12.56  # CONFIG_BLK_DEV_IDE_SATA is not set
   12.57  # CONFIG_BLK_DEV_HD_IDE is not set
   12.58 -CONFIG_BLK_DEV_IDEDISK=m
   12.59 -# CONFIG_IDEDISK_MULTI_MODE is not set
   12.60 +CONFIG_BLK_DEV_IDEDISK=y
   12.61 +CONFIG_IDEDISK_MULTI_MODE=y
   12.62  CONFIG_BLK_DEV_IDECS=m
   12.63 -CONFIG_BLK_DEV_IDECD=m
   12.64 +CONFIG_BLK_DEV_IDECD=y
   12.65  CONFIG_BLK_DEV_IDETAPE=m
   12.66 -CONFIG_BLK_DEV_IDEFLOPPY=m
   12.67 +CONFIG_BLK_DEV_IDEFLOPPY=y
   12.68  CONFIG_BLK_DEV_IDESCSI=m
   12.69  # CONFIG_IDE_TASK_IOCTL is not set
   12.70  
   12.71  #
   12.72  # IDE chipset support/bugfixes
   12.73  #
   12.74 -CONFIG_IDE_GENERIC=m
   12.75 +CONFIG_IDE_GENERIC=y
   12.76  CONFIG_BLK_DEV_CMD640=y
   12.77 -# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
   12.78 -# CONFIG_BLK_DEV_IDEPNP is not set
   12.79 +CONFIG_BLK_DEV_CMD640_ENHANCED=y
   12.80 +CONFIG_BLK_DEV_IDEPNP=y
   12.81  CONFIG_BLK_DEV_IDEPCI=y
   12.82  CONFIG_IDEPCI_SHARE_IRQ=y
   12.83  # CONFIG_BLK_DEV_OFFBOARD is not set
   12.84 -CONFIG_BLK_DEV_GENERIC=m
   12.85 +CONFIG_BLK_DEV_GENERIC=y
   12.86  CONFIG_BLK_DEV_OPTI621=m
   12.87 -CONFIG_BLK_DEV_RZ1000=m
   12.88 +CONFIG_BLK_DEV_RZ1000=y
   12.89  CONFIG_BLK_DEV_IDEDMA_PCI=y
   12.90  # CONFIG_BLK_DEV_IDEDMA_FORCED is not set
   12.91  CONFIG_IDEDMA_PCI_AUTO=y
   12.92  # CONFIG_IDEDMA_ONLYDISK is not set
   12.93 -CONFIG_BLK_DEV_AEC62XX=m
   12.94 -CONFIG_BLK_DEV_ALI15X3=m
   12.95 +CONFIG_BLK_DEV_AEC62XX=y
   12.96 +CONFIG_BLK_DEV_ALI15X3=y
   12.97  # CONFIG_WDC_ALI15X3 is not set
   12.98 -CONFIG_BLK_DEV_AMD74XX=m
   12.99 -CONFIG_BLK_DEV_ATIIXP=m
  12.100 -CONFIG_BLK_DEV_CMD64X=m
  12.101 -CONFIG_BLK_DEV_TRIFLEX=m
  12.102 -CONFIG_BLK_DEV_CY82C693=m
  12.103 -CONFIG_BLK_DEV_CS5520=m
  12.104 -CONFIG_BLK_DEV_CS5530=m
  12.105 -CONFIG_BLK_DEV_HPT34X=m
  12.106 +CONFIG_BLK_DEV_AMD74XX=y
  12.107 +CONFIG_BLK_DEV_ATIIXP=y
  12.108 +CONFIG_BLK_DEV_CMD64X=y
  12.109 +CONFIG_BLK_DEV_TRIFLEX=y
  12.110 +CONFIG_BLK_DEV_CY82C693=y
  12.111 +CONFIG_BLK_DEV_CS5520=y
  12.112 +CONFIG_BLK_DEV_CS5530=y
  12.113 +CONFIG_BLK_DEV_HPT34X=y
  12.114  # CONFIG_HPT34X_AUTODMA is not set
  12.115 -CONFIG_BLK_DEV_HPT366=m
  12.116 +CONFIG_BLK_DEV_HPT366=y
  12.117  CONFIG_BLK_DEV_SC1200=m
  12.118 -CONFIG_BLK_DEV_PIIX=m
  12.119 +CONFIG_BLK_DEV_PIIX=y
  12.120  CONFIG_BLK_DEV_NS87415=m
  12.121 -CONFIG_BLK_DEV_PDC202XX_OLD=m
  12.122 +CONFIG_BLK_DEV_PDC202XX_OLD=y
  12.123  CONFIG_PDC202XX_BURST=y
  12.124 -CONFIG_BLK_DEV_PDC202XX_NEW=m
  12.125 +CONFIG_BLK_DEV_PDC202XX_NEW=y
  12.126  CONFIG_PDC202XX_FORCE=y
  12.127 -CONFIG_BLK_DEV_SVWKS=m
  12.128 -CONFIG_BLK_DEV_SIIMAGE=m
  12.129 -CONFIG_BLK_DEV_SIS5513=m
  12.130 -CONFIG_BLK_DEV_SLC90E66=m
  12.131 +CONFIG_BLK_DEV_SVWKS=y
  12.132 +CONFIG_BLK_DEV_SIIMAGE=y
  12.133 +CONFIG_BLK_DEV_SIS5513=y
  12.134 +CONFIG_BLK_DEV_SLC90E66=y
  12.135  CONFIG_BLK_DEV_TRM290=m
  12.136 -CONFIG_BLK_DEV_VIA82CXXX=m
  12.137 +CONFIG_BLK_DEV_VIA82CXXX=y
  12.138  # CONFIG_IDE_ARM is not set
  12.139  # CONFIG_IDE_CHIPSETS is not set
  12.140  CONFIG_BLK_DEV_IDEDMA=y
  12.141 @@ -654,10 +652,10 @@ CONFIG_PCMCIA_SYM53C500=m
  12.142  CONFIG_CD_NO_IDESCSI=y
  12.143  CONFIG_AZTCD=m
  12.144  CONFIG_GSCD=m
  12.145 -CONFIG_SBPCD=m
  12.146 +# CONFIG_SBPCD is not set
  12.147  CONFIG_MCDX=m
  12.148  CONFIG_OPTCD=m
  12.149 -CONFIG_CM206=m
  12.150 +# CONFIG_CM206 is not set
  12.151  CONFIG_SJCD=m
  12.152  CONFIG_ISP16_CDI=m
  12.153  CONFIG_CDU31A=m
  12.154 @@ -1044,7 +1042,7 @@ CONFIG_ROSE=m
  12.155  CONFIG_MKISS=m
  12.156  CONFIG_6PACK=m
  12.157  CONFIG_BPQETHER=m
  12.158 -CONFIG_DMASCC=m
  12.159 +# CONFIG_DMASCC is not set
  12.160  CONFIG_SCC=m
  12.161  # CONFIG_SCC_DELAY is not set
  12.162  # CONFIG_SCC_TRXECHO is not set
  12.163 @@ -1204,7 +1202,7 @@ CONFIG_DE4X5=m
  12.164  CONFIG_WINBOND_840=m
  12.165  CONFIG_DM9102=m
  12.166  CONFIG_PCMCIA_XIRCOM=m
  12.167 -CONFIG_PCMCIA_XIRTULIP=m
  12.168 +# CONFIG_PCMCIA_XIRTULIP is not set
  12.169  CONFIG_AT1700=m
  12.170  CONFIG_DEPCA=m
  12.171  CONFIG_HP100=m
  12.172 @@ -1473,7 +1471,7 @@ CONFIG_ISDN_X25=y
  12.173  #
  12.174  # ISDN feature submodules
  12.175  #
  12.176 -CONFIG_ISDN_DRV_LOOP=m
  12.177 +# CONFIG_ISDN_DRV_LOOP is not set
  12.178  # CONFIG_ISDN_DIVERSION is not set
  12.179  
  12.180  #
  12.181 @@ -1554,8 +1552,7 @@ CONFIG_ISDN_DRV_ICN=m
  12.182  CONFIG_ISDN_DRV_PCBIT=m
  12.183  CONFIG_ISDN_DRV_SC=m
  12.184  CONFIG_ISDN_DRV_ACT2000=m
  12.185 -CONFIG_HYSDN=m
  12.186 -CONFIG_HYSDN_CAPI=y
  12.187 +# CONFIG_HYSDN is not set
  12.188  
  12.189  #
  12.190  # CAPI subsystem
  12.191 @@ -1611,7 +1608,7 @@ CONFIG_INPUT=y
  12.192  #
  12.193  # Userland interfaces
  12.194  #
  12.195 -CONFIG_INPUT_MOUSEDEV=m
  12.196 +CONFIG_INPUT_MOUSEDEV=y
  12.197  CONFIG_INPUT_MOUSEDEV_PSAUX=y
  12.198  CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
  12.199  CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
  12.200 @@ -1632,7 +1629,7 @@ CONFIG_KEYBOARD_LKKBD=m
  12.201  CONFIG_KEYBOARD_XTKBD=m
  12.202  CONFIG_KEYBOARD_NEWTON=m
  12.203  CONFIG_INPUT_MOUSE=y
  12.204 -CONFIG_MOUSE_PS2=m
  12.205 +CONFIG_MOUSE_PS2=y
  12.206  CONFIG_MOUSE_SERIAL=m
  12.207  CONFIG_MOUSE_INPORT=m
  12.208  # CONFIG_MOUSE_ATIXL is not set
  12.209 @@ -1791,31 +1788,7 @@ CONFIG_SONYPI=m
  12.210  #
  12.211  # Ftape, the floppy tape device driver
  12.212  #
  12.213 -CONFIG_FTAPE=m
  12.214 -CONFIG_ZFTAPE=m
  12.215 -CONFIG_ZFT_DFLT_BLK_SZ=10240
  12.216 -
  12.217 -#
  12.218 -# The compressor will be built as a module only!
  12.219 -#
  12.220 -CONFIG_ZFT_COMPRESSOR=m
  12.221 -CONFIG_FT_NR_BUFFERS=3
  12.222 -CONFIG_FT_PROC_FS=y
  12.223 -CONFIG_FT_NORMAL_DEBUG=y
  12.224 -# CONFIG_FT_FULL_DEBUG is not set
  12.225 -# CONFIG_FT_NO_TRACE is not set
  12.226 -# CONFIG_FT_NO_TRACE_AT_ALL is not set
  12.227 -
  12.228 -#
  12.229 -# Hardware configuration
  12.230 -#
  12.231 -CONFIG_FT_STD_FDC=y
  12.232 -# CONFIG_FT_MACH2 is not set
  12.233 -# CONFIG_FT_PROBE_FC10 is not set
  12.234 -# CONFIG_FT_ALT_FDC is not set
  12.235 -CONFIG_FT_FDC_THR=8
  12.236 -CONFIG_FT_FDC_MAX_RATE=2000
  12.237 -CONFIG_FT_ALPHA_CLOCK=0
  12.238 +# CONFIG_FTAPE is not set
  12.239  CONFIG_AGP=m
  12.240  CONFIG_AGP_ALI=m
  12.241  CONFIG_AGP_ATI=m
  12.242 @@ -2474,8 +2447,8 @@ CONFIG_USB_HIDDEV=y
  12.243  #
  12.244  # USB HID Boot Protocol drivers
  12.245  #
  12.246 -CONFIG_USB_KBD=y
  12.247 -CONFIG_USB_MOUSE=y
  12.248 +CONFIG_USB_KBD=m
  12.249 +CONFIG_USB_MOUSE=m
  12.250  CONFIG_USB_AIPTEK=m
  12.251  CONFIG_USB_WACOM=m
  12.252  CONFIG_USB_KBTAB=m
  12.253 @@ -2751,7 +2724,7 @@ CONFIG_NTFS_FS=m
  12.254  CONFIG_PROC_FS=y
  12.255  CONFIG_PROC_KCORE=y
  12.256  CONFIG_SYSFS=y
  12.257 -CONFIG_DEVFS_FS=y
  12.258 +# CONFIG_DEVFS_FS is not set
  12.259  # CONFIG_DEVFS_MOUNT is not set
  12.260  # CONFIG_DEVFS_DEBUG is not set
  12.261  CONFIG_DEVPTS_FS_XATTR=y
  12.262 @@ -2976,7 +2949,6 @@ CONFIG_MAGIC_SYSRQ=y
  12.263  CONFIG_LOG_BUF_SHIFT=14
  12.264  # CONFIG_SCHEDSTATS is not set
  12.265  # CONFIG_DEBUG_SLAB is not set
  12.266 -CONFIG_DEBUG_PREEMPT=y
  12.267  # CONFIG_DEBUG_SPINLOCK is not set
  12.268  # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
  12.269  # CONFIG_DEBUG_KOBJECT is not set
    13.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64	Fri Dec 02 12:12:11 2005 -0600
    13.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64	Fri Dec 02 12:52:25 2005 -0600
    13.3 @@ -15,11 +15,11 @@ CONFIG_XEN_PHYSDEV_ACCESS=y
    13.4  CONFIG_XEN_BLKDEV_BACKEND=y
    13.5  # CONFIG_XEN_BLKDEV_TAP_BE is not set
    13.6  CONFIG_XEN_NETDEV_BACKEND=y
    13.7 +# CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set
    13.8  # CONFIG_XEN_TPMDEV_FRONTEND is not set
    13.9  # CONFIG_XEN_TPMDEV_BACKEND is not set
   13.10  CONFIG_XEN_BLKDEV_FRONTEND=y
   13.11  CONFIG_XEN_NETDEV_FRONTEND=y
   13.12 -# CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
   13.13  # CONFIG_XEN_BLKDEV_TAP is not set
   13.14  # CONFIG_XEN_SHADOW_MODE is not set
   13.15  CONFIG_XEN_SCRUB_PAGES=y
   13.16 @@ -95,7 +95,6 @@ CONFIG_X86_GOOD_APIC=y
   13.17  CONFIG_SMP=y
   13.18  CONFIG_NR_CPUS=8
   13.19  # CONFIG_SCHED_SMT is not set
   13.20 -# CONFIG_PREEMPT is not set
   13.21  CONFIG_MICROCODE=y
   13.22  # CONFIG_X86_CPUID is not set
   13.23  # CONFIG_NUMA is not set
   13.24 @@ -2202,7 +2201,7 @@ CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
   13.25  CONFIG_PROC_FS=y
   13.26  CONFIG_PROC_KCORE=y
   13.27  CONFIG_SYSFS=y
   13.28 -CONFIG_DEVFS_FS=y
   13.29 +# CONFIG_DEVFS_FS is not set
   13.30  CONFIG_DEVPTS_FS_XATTR=y
   13.31  CONFIG_DEVPTS_FS_SECURITY=y
   13.32  CONFIG_TMPFS=y
    14.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/Kconfig	Fri Dec 02 12:12:11 2005 -0600
    14.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/Kconfig	Fri Dec 02 12:52:25 2005 -0600
    14.3 @@ -415,17 +415,17 @@ config SCHED_SMT
    14.4  	  cost of slightly increased overhead in some places. If unsure say
    14.5  	  N here.
    14.6  
    14.7 -config PREEMPT
    14.8 -	bool "Preemptible Kernel"
    14.9 -	help
   14.10 -	  This option reduces the latency of the kernel when reacting to
   14.11 -	  real-time or interactive events by allowing a low priority process to
   14.12 -	  be preempted even if it is in kernel mode executing a system call.
   14.13 -	  This allows applications to run more reliably even when the system is
   14.14 -	  under load.
   14.15 -
   14.16 -	  Say Y here if you are building a kernel for a desktop, embedded
   14.17 -	  or real-time system.  Say N if you are unsure.
   14.18 +#config PREEMPT
   14.19 +#	bool "Preemptible Kernel"
   14.20 +#	help
   14.21 +#	  This option reduces the latency of the kernel when reacting to
   14.22 +#	  real-time or interactive events by allowing a low priority process to
   14.23 +#	  be preempted even if it is in kernel mode executing a system call.
   14.24 +#	  This allows applications to run more reliably even when the system is
   14.25 +#	  under load.
   14.26 +#
   14.27 +#	  Say Y here if you are building a kernel for a desktop, embedded
   14.28 +#	  or real-time system.  Say N if you are unsure.
   14.29  
   14.30  config PREEMPT_BKL
   14.31  	bool "Preempt The Big Kernel Lock"
    15.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile	Fri Dec 02 12:12:11 2005 -0600
    15.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile	Fri Dec 02 12:52:25 2005 -0600
    15.3 @@ -11,7 +11,7 @@ extra-y := head.o init_task.o
    15.4  
    15.5  obj-y	:= process.o signal.o entry.o traps.o \
    15.6  		time.o ioport.o ldt.o setup.o \
    15.7 -		pci-dma.o i386_ksyms.o irq.o quirks.o
    15.8 +		pci-dma.o i386_ksyms.o irq.o quirks.o fixup.o
    15.9  
   15.10  c-obj-y	:= semaphore.o vm86.o \
   15.11  		ptrace.o sys_i386.o \
    16.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S	Fri Dec 02 12:12:11 2005 -0600
    16.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S	Fri Dec 02 12:52:25 2005 -0600
    16.3 @@ -81,7 +81,7 @@ VM_MASK		= 0x00020000
    16.4  #define evtchn_upcall_pending		/* 0 */
    16.5  #define evtchn_upcall_mask		1
    16.6  
    16.7 -#define sizeof_vcpu_shift		4
    16.8 +#define sizeof_vcpu_shift		6
    16.9  
   16.10  #ifdef CONFIG_SMP
   16.11  #define preempt_disable(reg)	incl TI_preempt_count(reg)
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/fixup.c	Fri Dec 02 12:52:25 2005 -0600
    17.3 @@ -0,0 +1,95 @@
    17.4 +/******************************************************************************
    17.5 + * fixup.c
    17.6 + * 
    17.7 + * Binary-rewriting of certain IA32 instructions, on notification by Xen.
    17.8 + * Used to avoid repeated slow emulation of common instructions used by the
    17.9 + * user-space TLS (Thread-Local Storage) libraries.
   17.10 + * 
   17.11 + * **** NOTE ****
   17.12 + *  Issues with the binary rewriting have caused it to be removed. Instead
   17.13 + *  we rely on Xen's emulator to boot the kernel, and then print a banner
   17.14 + *  message recommending that the user disables /lib/tls.
   17.15 + * 
   17.16 + * Copyright (c) 2004, K A Fraser
   17.17 + * 
   17.18 + * This program is free software; you can redistribute it and/or modify
   17.19 + * it under the terms of the GNU General Public License as published by
   17.20 + * the Free Software Foundation; either version 2 of the License, or
   17.21 + * (at your option) any later version.
   17.22 + * 
   17.23 + * This program is distributed in the hope that it will be useful,
   17.24 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.25 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.26 + * GNU General Public License for more details.
   17.27 + * 
   17.28 + * You should have received a copy of the GNU General Public License
   17.29 + * along with this program; if not, write to the Free Software
   17.30 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17.31 + */
   17.32 +
   17.33 +#include <linux/config.h>
   17.34 +#include <linux/init.h>
   17.35 +#include <linux/sched.h>
   17.36 +#include <linux/slab.h>
   17.37 +#include <linux/kernel.h>
   17.38 +#include <linux/delay.h>
   17.39 +#include <linux/version.h>
   17.40 +
   17.41 +#define DP(_f, _args...) printk(KERN_ALERT "  " _f "\n" , ## _args )
   17.42 +
   17.43 +fastcall void do_fixup_4gb_segment(struct pt_regs *regs, long error_code)
   17.44 +{
   17.45 +	static unsigned long printed = 0;
   17.46 +	char info[100];
   17.47 +	int i;
   17.48 +
   17.49 +	if (test_and_set_bit(0, &printed))
   17.50 +		return;
   17.51 +
   17.52 +	HYPERVISOR_vm_assist(
   17.53 +		VMASST_CMD_disable, VMASST_TYPE_4gb_segments_notify);
   17.54 +
   17.55 +	sprintf(info, "%s (pid=%d)", current->comm, current->tgid);
   17.56 +
   17.57 +
   17.58 +	DP("");
   17.59 +	DP("***************************************************************");
   17.60 +	DP("***************************************************************");
   17.61 +	DP("** WARNING: Currently emulating unsupported memory accesses  **");
   17.62 +	DP("**          in /lib/tls glibc libraries. The emulation is    **");
   17.63 +	DP("**          slow. To ensure full performance you should      **");
   17.64 +	DP("**          install a 'xen-friendly' (nosegneg) version of   **");
   17.65 +	DP("**          the library, or disable tls support by executing **");
   17.66 +	DP("**          the following as root:                           **");
   17.67 +	DP("**          mv /lib/tls /lib/tls.disabled                    **");
   17.68 +	DP("** Offending process: %-38.38s **", info);
   17.69 +	DP("***************************************************************");
   17.70 +	DP("***************************************************************");
   17.71 +	DP("");
   17.72 +
   17.73 +	for (i = 5; i > 0; i--) {
   17.74 +		printk("Pausing... %d", i);
   17.75 +		mdelay(1000);
   17.76 +		printk("\b\b\b\b\b\b\b\b\b\b\b\b");
   17.77 +	}
   17.78 +
   17.79 +	printk("Continuing...\n\n");
   17.80 +}
   17.81 +
   17.82 +static int __init fixup_init(void)
   17.83 +{
   17.84 +	HYPERVISOR_vm_assist(
   17.85 +		VMASST_CMD_enable, VMASST_TYPE_4gb_segments_notify);
   17.86 +	return 0;
   17.87 +}
   17.88 +__initcall(fixup_init);
   17.89 +
   17.90 +/*
   17.91 + * Local variables:
   17.92 + *  c-file-style: "linux"
   17.93 + *  indent-tabs-mode: t
   17.94 + *  c-indent-level: 8
   17.95 + *  c-basic-offset: 8
   17.96 + *  tab-width: 8
   17.97 + * End:
   17.98 + */
    18.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c	Fri Dec 02 12:12:11 2005 -0600
    18.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c	Fri Dec 02 12:52:25 2005 -0600
    18.3 @@ -1752,7 +1752,7 @@ void __init setup_arch(char **cmdline_p)
    18.4  #endif
    18.5  #endif
    18.6  	} else {
    18.7 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST
    18.8 +#ifdef CONFIG_XEN_PHYSDEV_ACCESS
    18.9  		extern const struct consw xennull_con;
   18.10  		extern int console_use_vt;
   18.11  #if defined(CONFIG_VGA_CONSOLE)
    19.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/smp.c	Fri Dec 02 12:12:11 2005 -0600
    19.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/smp.c	Fri Dec 02 12:52:25 2005 -0600
    19.3 @@ -28,8 +28,6 @@
    19.4  #endif
    19.5  #include <asm-xen/evtchn.h>
    19.6  
    19.7 -#define xxprint(msg) HYPERVISOR_console_io(CONSOLEIO_write, strlen(msg), msg)
    19.8 -
    19.9  /*
   19.10   *	Some notes on x86 processor bugs affecting SMP operation:
   19.11   *
   19.12 @@ -542,9 +540,7 @@ static void stop_this_cpu (void * dummy)
   19.13  	 */
   19.14  	cpu_clear(smp_processor_id(), cpu_online_map);
   19.15  	local_irq_disable();
   19.16 -#if 1
   19.17 -	xxprint("stop_this_cpu disable_local_APIC\n");
   19.18 -#else
   19.19 +#if 0
   19.20  	disable_local_APIC();
   19.21  #endif
   19.22  	if (cpu_data[smp_processor_id()].hlt_works_ok)
   19.23 @@ -561,9 +557,7 @@ void smp_send_stop(void)
   19.24  	smp_call_function(stop_this_cpu, NULL, 1, 0);
   19.25  
   19.26  	local_irq_disable();
   19.27 -#if 1
   19.28 -	xxprint("smp_send_stop disable_local_APIC\n");
   19.29 -#else
   19.30 +#if 0
   19.31  	disable_local_APIC();
   19.32  #endif
   19.33  	local_irq_enable();
    20.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c	Fri Dec 02 12:12:11 2005 -0600
    20.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c	Fri Dec 02 12:52:25 2005 -0600
    20.3 @@ -24,6 +24,7 @@
    20.4  #include <asm/io.h>
    20.5  #include <asm/pci.h>
    20.6  #include <asm/dma.h>
    20.7 +#include <asm-xen/xen-public/memory.h>
    20.8  
    20.9  #define OFFSET(val,align) ((unsigned long)((val) & ( (align) - 1)))
   20.10  
   20.11 @@ -177,6 +178,8 @@ swiotlb_init_with_default_size (size_t d
   20.12  void
   20.13  swiotlb_init(void)
   20.14  {
   20.15 +	long ram_end;
   20.16 +
   20.17  	/* The user can forcibly enable swiotlb. */
   20.18  	if (swiotlb_force)
   20.19  		swiotlb = 1;
   20.20 @@ -186,10 +189,8 @@ swiotlb_init(void)
   20.21           * which we take to mean more than 2GB.
   20.22           */
   20.23  	if (xen_start_info->flags & SIF_INITDOMAIN) {
   20.24 -		dom0_op_t op;
   20.25 -		op.cmd = DOM0_PHYSINFO;
   20.26 -		if ((HYPERVISOR_dom0_op(&op) == 0) &&
   20.27 -		    (op.u.physinfo.total_pages > 0x7ffff))
   20.28 +		ram_end = HYPERVISOR_memory_op(XENMEM_maximum_ram_page, NULL);
   20.29 +		if (ram_end > 0x7ffff)
   20.30  			swiotlb = 1;
   20.31  	}
   20.32  
    21.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c	Fri Dec 02 12:12:11 2005 -0600
    21.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c	Fri Dec 02 12:52:25 2005 -0600
    21.3 @@ -204,7 +204,8 @@ static inline u64 scale_delta(u64 delta,
    21.4  void init_cpu_khz(void)
    21.5  {
    21.6  	u64 __cpu_khz = 1000000ULL << 32;
    21.7 -	struct vcpu_time_info *info = &HYPERVISOR_shared_info->vcpu_time[0];
    21.8 +	struct vcpu_time_info *info;
    21.9 +	info = &HYPERVISOR_shared_info->vcpu_info[0].time;
   21.10  	do_div(__cpu_khz, info->tsc_to_system_mul);
   21.11  	if ( info->tsc_shift < 0 )
   21.12  		cpu_khz = __cpu_khz << -info->tsc_shift;
   21.13 @@ -284,7 +285,7 @@ static void get_time_values_from_xen(voi
   21.14  	struct vcpu_time_info   *src;
   21.15  	struct shadow_time_info *dst;
   21.16  
   21.17 -	src = &s->vcpu_time[smp_processor_id()];
   21.18 +	src = &s->vcpu_info[smp_processor_id()].time;
   21.19  	dst = &per_cpu(shadow_time, smp_processor_id());
   21.20  
   21.21  	do {
   21.22 @@ -306,7 +307,7 @@ static inline int time_values_up_to_date
   21.23  	struct vcpu_time_info   *src;
   21.24  	struct shadow_time_info *dst;
   21.25  
   21.26 -	src = &HYPERVISOR_shared_info->vcpu_time[cpu]; 
   21.27 +	src = &HYPERVISOR_shared_info->vcpu_info[cpu].time;
   21.28  	dst = &per_cpu(shadow_time, cpu); 
   21.29  
   21.30  	return (dst->version == src->version);
    22.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c	Fri Dec 02 12:12:11 2005 -0600
    22.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c	Fri Dec 02 12:52:25 2005 -0600
    22.3 @@ -291,7 +291,7 @@ fastcall void do_page_fault(struct pt_re
    22.4  	int write;
    22.5  	siginfo_t info;
    22.6  
    22.7 -	address = HYPERVISOR_shared_info->vcpu_data[
    22.8 +	address = HYPERVISOR_shared_info->vcpu_info[
    22.9  		smp_processor_id()].arch.cr2;
   22.10  
   22.11  	/* Set the "privileged fault" bit to something sane. */
    23.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c	Fri Dec 02 12:12:11 2005 -0600
    23.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c	Fri Dec 02 12:52:25 2005 -0600
    23.3 @@ -708,7 +708,7 @@ void __init pgtable_cache_init(void)
    23.4  			panic("pgtable_cache_init(): cannot create pmd cache");
    23.5  	}
    23.6  	pgd_cache = kmem_cache_create("pgd",
    23.7 -#if 0 /* How the heck _this_ works in native linux ??? */
    23.8 +#ifndef CONFIG_XEN
    23.9  				PTRS_PER_PGD*sizeof(pgd_t),
   23.10  				PTRS_PER_PGD*sizeof(pgd_t),
   23.11  #else
   23.12 @@ -717,7 +717,7 @@ void __init pgtable_cache_init(void)
   23.13  #endif
   23.14  				0,
   23.15  				pgd_ctor,
   23.16 -				pgd_dtor);
   23.17 +				PTRS_PER_PMD == 1 ? pgd_dtor : NULL);
   23.18  	if (!pgd_cache)
   23.19  		panic("pgtable_cache_init(): Cannot create pgd cache");
   23.20  }
    24.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c	Fri Dec 02 12:12:11 2005 -0600
    24.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c	Fri Dec 02 12:52:25 2005 -0600
    24.3 @@ -27,8 +27,7 @@
    24.4  #include <asm-xen/foreign_page.h>
    24.5  #include <asm/hypervisor.h>
    24.6  
    24.7 -static void __pgd_pin(pgd_t *pgd);
    24.8 -static void __pgd_unpin(pgd_t *pgd);
    24.9 +static void pgd_test_and_unpin(pgd_t *pgd);
   24.10  
   24.11  void show_mem(void)
   24.12  {
   24.13 @@ -278,75 +277,79 @@ void pgd_ctor(void *pgd, kmem_cache_t *c
   24.14  {
   24.15  	unsigned long flags;
   24.16  
   24.17 -#ifdef CONFIG_X86_PAE
   24.18 -	/* Ensure pgd resides below 4GB. */
   24.19 -	int rc = xen_create_contiguous_region((unsigned long)pgd, 0, 32);
   24.20 -	BUG_ON(rc);
   24.21 -#endif
   24.22 -
   24.23 -	if (!HAVE_SHARED_KERNEL_PMD)
   24.24 +	if (PTRS_PER_PMD > 1) {
   24.25 +		/* Ensure pgd resides below 4GB. */
   24.26 +		int rc = xen_create_contiguous_region(
   24.27 +			(unsigned long)pgd, 0, 32);
   24.28 +		BUG_ON(rc);
   24.29 +		if (HAVE_SHARED_KERNEL_PMD)
   24.30 +			memcpy((pgd_t *)pgd + USER_PTRS_PER_PGD,
   24.31 +			       swapper_pg_dir + USER_PTRS_PER_PGD,
   24.32 +			       (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
   24.33 +	} else {
   24.34  		spin_lock_irqsave(&pgd_lock, flags);
   24.35 -
   24.36 -	memcpy((pgd_t *)pgd + USER_PTRS_PER_PGD,
   24.37 -			swapper_pg_dir + USER_PTRS_PER_PGD,
   24.38 -			(PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
   24.39 -
   24.40 -	if (HAVE_SHARED_KERNEL_PMD)
   24.41 -		return;
   24.42 -
   24.43 -	pgd_list_add(pgd);
   24.44 -	spin_unlock_irqrestore(&pgd_lock, flags);
   24.45 -	memset(pgd, 0, USER_PTRS_PER_PGD*sizeof(pgd_t));
   24.46 +		memcpy((pgd_t *)pgd + USER_PTRS_PER_PGD,
   24.47 +		       swapper_pg_dir + USER_PTRS_PER_PGD,
   24.48 +		       (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
   24.49 +		memset(pgd, 0, USER_PTRS_PER_PGD*sizeof(pgd_t));
   24.50 +		pgd_list_add(pgd);
   24.51 +		spin_unlock_irqrestore(&pgd_lock, flags);
   24.52 +	}
   24.53  }
   24.54  
   24.55 +/* never called when PTRS_PER_PMD > 1 */
   24.56  void pgd_dtor(void *pgd, kmem_cache_t *cache, unsigned long unused)
   24.57  {
   24.58  	unsigned long flags; /* can be called from interrupt context */
   24.59  
   24.60 -	BUG_ON(test_bit(PG_pinned, &virt_to_page(pgd)->flags));
   24.61 -
   24.62 -	if (HAVE_SHARED_KERNEL_PMD)
   24.63 -		return;
   24.64 -
   24.65  	spin_lock_irqsave(&pgd_lock, flags);
   24.66  	pgd_list_del(pgd);
   24.67  	spin_unlock_irqrestore(&pgd_lock, flags);
   24.68 +
   24.69 +	pgd_test_and_unpin(pgd);
   24.70  }
   24.71  
   24.72  pgd_t *pgd_alloc(struct mm_struct *mm)
   24.73  {
   24.74 -	int i = 0;
   24.75 +	int i;
   24.76  	pgd_t *pgd = kmem_cache_alloc(pgd_cache, GFP_KERNEL);
   24.77  
   24.78 -	BUG_ON(test_bit(PG_pinned, &virt_to_page(pgd)->flags));
   24.79 +	pgd_test_and_unpin(pgd);
   24.80  
   24.81  	if (PTRS_PER_PMD == 1 || !pgd)
   24.82  		return pgd;
   24.83  
   24.84 -	if (!HAVE_SHARED_KERNEL_PMD) {
   24.85 -		/* alloc and copy kernel pmd */
   24.86 -		unsigned long flags;
   24.87 -		pgd_t *copy_pgd = pgd_offset_k(PAGE_OFFSET);
   24.88 -		pud_t *copy_pud = pud_offset(copy_pgd, PAGE_OFFSET);
   24.89 -		pmd_t *copy_pmd = pmd_offset(copy_pud, PAGE_OFFSET);
   24.90 -		pmd_t *pmd = kmem_cache_alloc(pmd_cache, GFP_KERNEL);
   24.91 -		if (0 == pmd)
   24.92 -			goto out_oom;
   24.93 -
   24.94 -		spin_lock_irqsave(&pgd_lock, flags);
   24.95 -		memcpy(pmd, copy_pmd, PAGE_SIZE);
   24.96 -		spin_unlock_irqrestore(&pgd_lock, flags);
   24.97 -		make_lowmem_page_readonly(pmd);
   24.98 -		set_pgd(&pgd[USER_PTRS_PER_PGD], __pgd(1 + __pa(pmd)));
   24.99 -	}
  24.100 -
  24.101 -	/* alloc user pmds */
  24.102  	for (i = 0; i < USER_PTRS_PER_PGD; ++i) {
  24.103  		pmd_t *pmd = kmem_cache_alloc(pmd_cache, GFP_KERNEL);
  24.104  		if (!pmd)
  24.105  			goto out_oom;
  24.106  		set_pgd(&pgd[i], __pgd(1 + __pa(pmd)));
  24.107  	}
  24.108 +
  24.109 +	if (!HAVE_SHARED_KERNEL_PMD) {
  24.110 +		unsigned long flags;
  24.111 +
  24.112 +		for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
  24.113 +			pmd_t *pmd = kmem_cache_alloc(pmd_cache, GFP_KERNEL);
  24.114 +			if (!pmd)
  24.115 +				goto out_oom;
  24.116 +			set_pgd(&pgd[USER_PTRS_PER_PGD], __pgd(1 + __pa(pmd)));
  24.117 +		}
  24.118 +
  24.119 +		spin_lock_irqsave(&pgd_lock, flags);
  24.120 +		for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
  24.121 +			unsigned long v = (unsigned long)i << PGDIR_SHIFT;
  24.122 +			pgd_t *kpgd = pgd_offset_k(v);
  24.123 +			pud_t *kpud = pud_offset(kpgd, v);
  24.124 +			pmd_t *kpmd = pmd_offset(kpud, v);
  24.125 +			pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
  24.126 +			memcpy(pmd, kpmd, PAGE_SIZE);
  24.127 +			make_lowmem_page_readonly(pmd);
  24.128 +		}
  24.129 +		pgd_list_add(pgd);
  24.130 +		spin_unlock_irqrestore(&pgd_lock, flags);
  24.131 +	}
  24.132 +
  24.133  	return pgd;
  24.134  
  24.135  out_oom:
  24.136 @@ -360,21 +363,25 @@ void pgd_free(pgd_t *pgd)
  24.137  {
  24.138  	int i;
  24.139  
  24.140 -	if (test_bit(PG_pinned, &virt_to_page(pgd)->flags))
  24.141 -		__pgd_unpin(pgd);
  24.142 +	pgd_test_and_unpin(pgd);
  24.143  
  24.144  	/* in the PAE case user pgd entries are overwritten before usage */
  24.145  	if (PTRS_PER_PMD > 1) {
  24.146  		for (i = 0; i < USER_PTRS_PER_PGD; ++i) {
  24.147  			pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
  24.148 -			make_lowmem_page_writable(pmd);
  24.149  			kmem_cache_free(pmd_cache, pmd);
  24.150  		}
  24.151  		if (!HAVE_SHARED_KERNEL_PMD) {
  24.152 -			pmd_t *pmd = (void *)__va(pgd_val(pgd[USER_PTRS_PER_PGD])-1);
  24.153 -			make_lowmem_page_writable(pmd);
  24.154 -			memset(pmd, 0, PTRS_PER_PMD*sizeof(pmd_t));
  24.155 -			kmem_cache_free(pmd_cache, pmd);
  24.156 +			unsigned long flags;
  24.157 +			spin_lock_irqsave(&pgd_lock, flags);
  24.158 +			pgd_list_del(pgd);
  24.159 +			spin_unlock_irqrestore(&pgd_lock, flags);
  24.160 +			for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
  24.161 +				pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
  24.162 +				make_lowmem_page_writable(pmd);
  24.163 +				memset(pmd, 0, PTRS_PER_PMD*sizeof(pmd_t));
  24.164 +				kmem_cache_free(pmd_cache, pmd);
  24.165 +			}
  24.166  		}
  24.167  	}
  24.168  	/* in the non-PAE case, free_pgtables() clears user pgd entries */
  24.169 @@ -382,7 +389,6 @@ void pgd_free(pgd_t *pgd)
  24.170  }
  24.171  
  24.172  #ifndef CONFIG_XEN_SHADOW_MODE
  24.173 -asmlinkage int xprintk(const char *fmt, ...);
  24.174  void make_lowmem_page_readonly(void *va)
  24.175  {
  24.176  	pte_t *pte = virt_to_ptep(va);
  24.177 @@ -513,6 +519,12 @@ static void __pgd_unpin(pgd_t *pgd)
  24.178  	clear_bit(PG_pinned, &virt_to_page(pgd)->flags);
  24.179  }
  24.180  
  24.181 +static void pgd_test_and_unpin(pgd_t *pgd)
  24.182 +{
  24.183 +	if (test_bit(PG_pinned, &virt_to_page(pgd)->flags))
  24.184 +		__pgd_unpin(pgd);
  24.185 +}
  24.186 +
  24.187  void mm_pin(struct mm_struct *mm)
  24.188  {
  24.189  	spin_lock(&mm->page_table_lock);
    25.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/Makefile	Fri Dec 02 12:12:11 2005 -0600
    25.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/Makefile	Fri Dec 02 12:52:25 2005 -0600
    25.3 @@ -11,8 +11,8 @@ CPPFLAGS_vmlinux.lds += -U$(XENARCH)
    25.4  
    25.5  extra-y += vmlinux.lds
    25.6  
    25.7 -obj-y   := evtchn.o fixup.o reboot.o gnttab.o devmem.o
    25.8 +obj-y   := evtchn.o reboot.o gnttab.o
    25.9  
   25.10  obj-$(CONFIG_PROC_FS) += xen_proc.o
   25.11  obj-$(CONFIG_NET)     += skbuff.o
   25.12 -obj-$(CONFIG_SMP)     += smp.o smpboot.o
   25.13 +obj-$(CONFIG_SMP)     += smpboot.o
    26.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/devmem.c	Fri Dec 02 12:12:11 2005 -0600
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,157 +0,0 @@
    26.4 -/*
    26.5 - *  Originally from linux/drivers/char/mem.c
    26.6 - *
    26.7 - *  Copyright (C) 1991, 1992  Linus Torvalds
    26.8 - *
    26.9 - *  Added devfs support. 
   26.10 - *    Jan-11-1998, C. Scott Ananian <cananian@alumni.princeton.edu>
   26.11 - *  Shared /dev/zero mmaping support, Feb 2000, Kanoj Sarcar <kanoj@sgi.com>
   26.12 - */
   26.13 -
   26.14 -#include <linux/config.h>
   26.15 -#include <linux/mm.h>
   26.16 -#include <linux/miscdevice.h>
   26.17 -#include <linux/slab.h>
   26.18 -#include <linux/vmalloc.h>
   26.19 -#include <linux/mman.h>
   26.20 -#include <linux/random.h>
   26.21 -#include <linux/init.h>
   26.22 -#include <linux/raw.h>
   26.23 -#include <linux/tty.h>
   26.24 -#include <linux/capability.h>
   26.25 -#include <linux/smp_lock.h>
   26.26 -#include <linux/devfs_fs_kernel.h>
   26.27 -#include <linux/ptrace.h>
   26.28 -#include <linux/device.h>
   26.29 -#include <asm/pgalloc.h>
   26.30 -#include <asm/uaccess.h>
   26.31 -#include <asm/io.h>
   26.32 -#include <asm/hypervisor.h>
   26.33 -
   26.34 -static inline int uncached_access(struct file *file)
   26.35 -{
   26.36 -        if (file->f_flags & O_SYNC)
   26.37 -                return 1;
   26.38 -        /* Xen sets correct MTRR type on non-RAM for us. */
   26.39 -        return 0;
   26.40 -}
   26.41 -
   26.42 -/*
   26.43 - * This funcion reads the *physical* memory. The f_pos points directly to the 
   26.44 - * memory location. 
   26.45 - */
   26.46 -static ssize_t read_mem(struct file * file, char __user * buf,
   26.47 -			size_t count, loff_t *ppos)
   26.48 -{
   26.49 -	unsigned long i, p = *ppos;
   26.50 -	ssize_t read = -EFAULT;
   26.51 -	void *v;
   26.52 -
   26.53 -	if ((v = ioremap(p, count)) == NULL) {
   26.54 -		/*
   26.55 -		 * Some programs (e.g., dmidecode) groove off into weird RAM
   26.56 -		 * areas where no table scan possibly exist (because Xen will
   26.57 -		 * have stomped on them!). These programs get rather upset if
   26.58 -                 * we let them know that Xen failed their access, so we fake
   26.59 -                 * out a read of all zeroes. :-)
   26.60 -		 */
   26.61 -		for (i = 0; i < count; i++)
   26.62 -			if (put_user(0, buf+i))
   26.63 -				return -EFAULT;
   26.64 -		return count;
   26.65 -	}
   26.66 -	if (copy_to_user(buf, v, count))
   26.67 -		goto out;
   26.68 -
   26.69 -	read = count;
   26.70 -	*ppos += read;
   26.71 -out:
   26.72 -	iounmap(v);
   26.73 -	return read;
   26.74 -}
   26.75 -
   26.76 -static ssize_t write_mem(struct file * file, const char __user * buf, 
   26.77 -			 size_t count, loff_t *ppos)
   26.78 -{
   26.79 -	unsigned long p = *ppos;
   26.80 -	ssize_t written = -EFAULT;
   26.81 -	void *v;
   26.82 -
   26.83 -	if ((v = ioremap(p, count)) == NULL)
   26.84 -		return -EFAULT;
   26.85 -	if (copy_from_user(v, buf, count))
   26.86 -		goto out;
   26.87 -
   26.88 -	written = count;
   26.89 -	*ppos += written;
   26.90 -out:
   26.91 -	iounmap(v);
   26.92 -	return written;
   26.93 -}
   26.94 -
   26.95 -static int mmap_mem(struct file * file, struct vm_area_struct * vma)
   26.96 -{
   26.97 -	if (uncached_access(file))
   26.98 -		vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
   26.99 -
  26.100 -	if (direct_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  26.101 -				   vma->vm_end - vma->vm_start,
  26.102 -				   vma->vm_page_prot, DOMID_IO))
  26.103 -		return -EAGAIN;
  26.104 -
  26.105 -	return 0;
  26.106 -}
  26.107 -
  26.108 -/*
  26.109 - * The memory devices use the full 32/64 bits of the offset, and so we cannot
  26.110 - * check against negative addresses: they are ok. The return value is weird,
  26.111 - * though, in that case (0).
  26.112 - *
  26.113 - * also note that seeking relative to the "end of file" isn't supported:
  26.114 - * it has no meaning, so it returns -EINVAL.
  26.115 - */
  26.116 -static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
  26.117 -{
  26.118 -	loff_t ret;
  26.119 -
  26.120 -	down(&file->f_dentry->d_inode->i_sem);
  26.121 -	switch (orig) {
  26.122 -		case 0:
  26.123 -			file->f_pos = offset;
  26.124 -			ret = file->f_pos;
  26.125 -			force_successful_syscall_return();
  26.126 -			break;
  26.127 -		case 1:
  26.128 -			file->f_pos += offset;
  26.129 -			ret = file->f_pos;
  26.130 -			force_successful_syscall_return();
  26.131 -			break;
  26.132 -		default:
  26.133 -			ret = -EINVAL;
  26.134 -	}
  26.135 -	up(&file->f_dentry->d_inode->i_sem);
  26.136 -	return ret;
  26.137 -}
  26.138 -
  26.139 -static int open_mem(struct inode * inode, struct file * filp)
  26.140 -{
  26.141 -	return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
  26.142 -}
  26.143 -
  26.144 -struct file_operations mem_fops = {
  26.145 -	.llseek		= memory_lseek,
  26.146 -	.read		= read_mem,
  26.147 -	.write		= write_mem,
  26.148 -	.mmap		= mmap_mem,
  26.149 -	.open		= open_mem,
  26.150 -};
  26.151 -
  26.152 -/*
  26.153 - * Local variables:
  26.154 - *  c-file-style: "linux"
  26.155 - *  indent-tabs-mode: t
  26.156 - *  c-indent-level: 8
  26.157 - *  c-basic-offset: 8
  26.158 - *  tab-width: 8
  26.159 - * End:
  26.160 - */
    27.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/evtchn.c	Fri Dec 02 12:12:11 2005 -0600
    27.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/evtchn.c	Fri Dec 02 12:52:25 2005 -0600
    27.3 @@ -154,7 +154,7 @@ asmlinkage void evtchn_do_upcall(struct 
    27.4  	unsigned int   l1i, l2i, port;
    27.5  	int            irq, cpu = smp_processor_id();
    27.6  	shared_info_t *s = HYPERVISOR_shared_info;
    27.7 -	vcpu_info_t   *vcpu_info = &s->vcpu_data[cpu];
    27.8 +	vcpu_info_t   *vcpu_info = &s->vcpu_info[cpu];
    27.9  
   27.10  	vcpu_info->evtchn_upcall_pending = 0;
   27.11  
    28.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/fixup.c	Fri Dec 02 12:12:11 2005 -0600
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,93 +0,0 @@
    28.4 -/******************************************************************************
    28.5 - * fixup.c
    28.6 - * 
    28.7 - * Binary-rewriting of certain IA32 instructions, on notification by Xen.
    28.8 - * Used to avoid repeated slow emulation of common instructions used by the
    28.9 - * user-space TLS (Thread-Local Storage) libraries.
   28.10 - * 
   28.11 - * **** NOTE ****
   28.12 - *  Issues with the binary rewriting have caused it to be removed. Instead
   28.13 - *  we rely on Xen's emulator to boot the kernel, and then print a banner
   28.14 - *  message recommending that the user disables /lib/tls.
   28.15 - * 
   28.16 - * Copyright (c) 2004, K A Fraser
   28.17 - * 
   28.18 - * This program is free software; you can redistribute it and/or modify
   28.19 - * it under the terms of the GNU General Public License as published by
   28.20 - * the Free Software Foundation; either version 2 of the License, or
   28.21 - * (at your option) any later version.
   28.22 - * 
   28.23 - * This program is distributed in the hope that it will be useful,
   28.24 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   28.25 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   28.26 - * GNU General Public License for more details.
   28.27 - * 
   28.28 - * You should have received a copy of the GNU General Public License
   28.29 - * along with this program; if not, write to the Free Software
   28.30 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   28.31 - */
   28.32 -
   28.33 -#include <linux/config.h>
   28.34 -#include <linux/init.h>
   28.35 -#include <linux/sched.h>
   28.36 -#include <linux/slab.h>
   28.37 -#include <linux/kernel.h>
   28.38 -#include <linux/delay.h>
   28.39 -#include <linux/version.h>
   28.40 -
   28.41 -#define DP(_f, _args...) printk(KERN_ALERT "  " _f "\n" , ## _args )
   28.42 -
   28.43 -fastcall void do_fixup_4gb_segment(struct pt_regs *regs, long error_code)
   28.44 -{
   28.45 -	static unsigned long printed = 0;
   28.46 -	char info[100];
   28.47 -	int i;
   28.48 -
   28.49 -	if (test_and_set_bit(0, &printed))
   28.50 -		return;
   28.51 -
   28.52 -	HYPERVISOR_vm_assist(
   28.53 -		VMASST_CMD_disable, VMASST_TYPE_4gb_segments_notify);
   28.54 -
   28.55 -	sprintf(info, "%s (pid=%d)", current->comm, current->tgid);
   28.56 -
   28.57 -
   28.58 -	DP("");
   28.59 -	DP("***************************************************************");
   28.60 -	DP("***************************************************************");
   28.61 -	DP("** WARNING: Currently emulating unsupported memory accesses  **");
   28.62 -	DP("**          in /lib/tls libraries. The emulation is very     **");
   28.63 -	DP("**          slow. To ensure full performance you should      **");
   28.64 -	DP("**          execute the following as root:                   **");
   28.65 -	DP("**          mv /lib/tls /lib/tls.disabled                    **");
   28.66 -	DP("** Offending process: %-38.38s **", info);
   28.67 -	DP("***************************************************************");
   28.68 -	DP("***************************************************************");
   28.69 -	DP("");
   28.70 -
   28.71 -	for (i = 5; i > 0; i--) {
   28.72 -		printk("Pausing... %d", i);
   28.73 -		mdelay(1000);
   28.74 -		printk("\b\b\b\b\b\b\b\b\b\b\b\b");
   28.75 -	}
   28.76 -
   28.77 -	printk("Continuing...\n\n");
   28.78 -}
   28.79 -
   28.80 -static int __init fixup_init(void)
   28.81 -{
   28.82 -	HYPERVISOR_vm_assist(
   28.83 -		VMASST_CMD_enable, VMASST_TYPE_4gb_segments_notify);
   28.84 -	return 0;
   28.85 -}
   28.86 -__initcall(fixup_init);
   28.87 -
   28.88 -/*
   28.89 - * Local variables:
   28.90 - *  c-file-style: "linux"
   28.91 - *  indent-tabs-mode: t
   28.92 - *  c-indent-level: 8
   28.93 - *  c-basic-offset: 8
   28.94 - *  tab-width: 8
   28.95 - * End:
   28.96 - */
    29.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c	Fri Dec 02 12:12:11 2005 -0600
    29.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c	Fri Dec 02 12:52:25 2005 -0600
    29.3 @@ -229,20 +229,29 @@ gnttab_grant_foreign_transfer_ref(grant_
    29.4  unsigned long
    29.5  gnttab_end_foreign_transfer_ref(grant_ref_t ref)
    29.6  {
    29.7 -	unsigned long frame = 0;
    29.8 +	unsigned long frame;
    29.9  	u16           flags;
   29.10  
   29.11 -	flags = shared[ref].flags;
   29.12 -
   29.13  	/*
   29.14 -	 * If a transfer is committed then wait for the frame address to
   29.15 -	 * appear. Otherwise invalidate the grant entry against future use.
   29.16 -	 */
   29.17 -	if (likely(flags != GTF_accept_transfer) ||
   29.18 -	    (synch_cmpxchg(&shared[ref].flags, flags, 0) !=
   29.19 -	     GTF_accept_transfer))
   29.20 -		while (unlikely((frame = shared[ref].frame) == 0))
   29.21 -			cpu_relax();
   29.22 +         * If a transfer is not even yet started, try to reclaim the grant
   29.23 +         * reference and return failure (== 0).
   29.24 +         */
   29.25 +	while (!((flags = shared[ref].flags) & GTF_transfer_committed)) {
   29.26 +		if ( synch_cmpxchg(&shared[ref].flags, flags, 0) == flags )
   29.27 +			return 0;
   29.28 +		cpu_relax();
   29.29 +	}
   29.30 +
   29.31 +	/* If a transfer is in progress then wait until it is completed. */
   29.32 +	while (!(flags & GTF_transfer_completed)) {
   29.33 +		flags = shared[ref].flags;
   29.34 +		cpu_relax();
   29.35 +	}
   29.36 +
   29.37 +	/* Read the frame number /after/ reading completion status. */
   29.38 +	rmb();
   29.39 +	frame = shared[ref].frame;
   29.40 +	BUG_ON(frame == 0);
   29.41  
   29.42  	return frame;
   29.43  }
    30.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c	Fri Dec 02 12:12:11 2005 -0600
    30.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c	Fri Dec 02 12:52:25 2005 -0600
    30.3 @@ -189,17 +189,16 @@ static int __do_suspend(void *ignore)
    30.4  #endif
    30.5  
    30.6  	/* 
    30.7 -	** Only resume xenbus /after/ we've prepared our VCPUs; otherwise
    30.8 -	** the VCPU hotplug callback can race with our vcpu_prepare
    30.9 -	*/
   30.10 +	 * Only resume xenbus /after/ we've prepared our VCPUs; otherwise
   30.11 +	 * the VCPU hotplug callback can race with our vcpu_prepare
   30.12 +	 */
   30.13  	xenbus_resume();
   30.14  
   30.15 -
   30.16  #ifdef CONFIG_SMP
   30.17   out_reenable_cpus:
   30.18  	for_each_cpu_mask(i, prev_online_cpus) {
   30.19  		j = cpu_up(i);
   30.20 -		if (j != 0) {
   30.21 +		if ((j != 0) && !cpu_online(i)) {
   30.22  			printk(KERN_CRIT "Failed to bring cpu "
   30.23  			       "%d back up (%d).\n",
   30.24  			       i, j);
    31.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/smp.c	Fri Dec 02 12:12:11 2005 -0600
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,25 +0,0 @@
    31.4 -/* Copyright (C) 2004, Christian Limpach */
    31.5 -
    31.6 -#include <linux/init.h>
    31.7 -#include <linux/kernel.h>
    31.8 -#include <linux/threads.h>
    31.9 -
   31.10 -/*
   31.11 - * the frequency of the profiling timer can be changed
   31.12 - * by writing a multiplier value into /proc/profile.
   31.13 - */
   31.14 -int setup_profiling_timer(unsigned int multiplier)
   31.15 -{
   31.16 -	printk("setup_profiling_timer\n");
   31.17 -	return 0;
   31.18 -}
   31.19 -
   31.20 -/*
   31.21 - * Local variables:
   31.22 - *  c-file-style: "linux"
   31.23 - *  indent-tabs-mode: t
   31.24 - *  c-indent-level: 8
   31.25 - *  c-basic-offset: 8
   31.26 - *  tab-width: 8
   31.27 - * End:
   31.28 - */
    32.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c	Fri Dec 02 12:12:11 2005 -0600
    32.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c	Fri Dec 02 12:52:25 2005 -0600
    32.3 @@ -420,6 +420,12 @@ void __init smp_cpus_done(unsigned int m
    32.4  {
    32.5  }
    32.6  
    32.7 +int setup_profiling_timer(unsigned int multiplier)
    32.8 +{
    32.9 +	/* Dummy function. */
   32.10 +	return 0;
   32.11 +}
   32.12 +
   32.13  /*
   32.14   * Local variables:
   32.15   *  c-file-style: "linux"
    33.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/Kconfig	Fri Dec 02 12:12:11 2005 -0600
    33.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/Kconfig	Fri Dec 02 12:52:25 2005 -0600
    33.3 @@ -224,21 +224,21 @@ config SMP
    33.4  
    33.5  	  If you don't know what to do here, say N.
    33.6  
    33.7 -config PREEMPT
    33.8 -	bool "Preemptible Kernel"
    33.9 -	---help---
   33.10 -	  This option reduces the latency of the kernel when reacting to
   33.11 -	  real-time or interactive events by allowing a low priority process to
   33.12 -	  be preempted even if it is in kernel mode executing a system call.
   33.13 -	  This allows applications to run more reliably even when the system is
   33.14 -	  under load. On contrary it may also break your drivers and add
   33.15 -	  priority inheritance problems to your system. Don't select it if
   33.16 -	  you rely on a stable system or have slightly obscure hardware.
   33.17 -	  It's also not very well tested on x86-64 currently.
   33.18 -	  You have been warned.
   33.19 -
   33.20 -	  Say Y here if you are feeling brave and building a kernel for a
   33.21 -	  desktop, embedded or real-time system.  Say N if you are unsure.
   33.22 +#config PREEMPT
   33.23 +#	bool "Preemptible Kernel"
   33.24 +#	---help---
   33.25 +#	  This option reduces the latency of the kernel when reacting to
   33.26 +#	  real-time or interactive events by allowing a low priority process to
   33.27 +#	  be preempted even if it is in kernel mode executing a system call.
   33.28 +#	  This allows applications to run more reliably even when the system is
   33.29 +#	  under load. On contrary it may also break your drivers and add
   33.30 +#	  priority inheritance problems to your system. Don't select it if
   33.31 +#	  you rely on a stable system or have slightly obscure hardware.
   33.32 +#	  It's also not very well tested on x86-64 currently.
   33.33 +#	  You have been warned.
   33.34 +#
   33.35 +#	  Say Y here if you are feeling brave and building a kernel for a
   33.36 +#	  desktop, embedded or real-time system.  Say N if you are unsure.
   33.37  
   33.38  config SCHED_SMT
   33.39  	bool "SMT (Hyperthreading) scheduler support"
   33.40 @@ -288,10 +288,10 @@ config HAVE_DEC_LOCK
   33.41  # actually 64 maximum, but you need to fix the APIC code first
   33.42  # to use clustered mode or whatever your big iron needs
   33.43  config NR_CPUS
   33.44 -	int "Maximum number of CPUs (2-8)"
   33.45 -	range 2 8
   33.46 +	int "Maximum number of CPUs (2-255)"
   33.47 +	range 2 255
   33.48  	depends on SMP
   33.49 -	default "8"
   33.50 +	default "16"
   33.51  	help
   33.52  	  This allows you to specify the maximum number of CPUs which this
   33.53  	  kernel will support.  The maximum supported value is 32 and the
    34.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/ia32/Makefile	Fri Dec 02 12:12:11 2005 -0600
    34.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/ia32/Makefile	Fri Dec 02 12:52:25 2005 -0600
    34.3 @@ -21,6 +21,12 @@ c-obj-$(CONFIG_IA32_AOUT) += ia32_aout.o
    34.4  $(obj)/syscall32.o: $(src)/syscall32.c \
    34.5  	$(foreach F,int80 sysenter syscall,$(obj)/vsyscall-$F.so)
    34.6  
    34.7 +# syscall32.c currently contains inline asm which has .incbin directives.
    34.8 +# This defeats ccache's signature checks, and also breaks distcc.
    34.9 +# Make sure neither ccache nor distcc compiles this file.
   34.10 +#
   34.11 +$(obj)/syscall32.o: override CC := env CCACHE_DISABLE=1 DISTCC_HOSTS=localhost $(CC)
   34.12 +
   34.13  # Teach kbuild about targets
   34.14  targets := $(foreach F,int80 sysenter syscall,vsyscall-$F.o vsyscall-$F.so)
   34.15  
    35.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/e820.c	Fri Dec 02 12:12:11 2005 -0600
    35.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/e820.c	Fri Dec 02 12:52:25 2005 -0600
    35.3 @@ -586,7 +586,7 @@ void __init e820_reserve_resources(void)
    35.4  	free_bootmem(__pa(map), PAGE_SIZE);
    35.5  
    35.6  	if (!found) {
    35.7 -		HYPERVISOR_memory_op(XENMEM_maximum_ram_page, &gapstart);
    35.8 +		gapstart = HYPERVISOR_memory_op(XENMEM_maximum_ram_page, NULL);
    35.9  		gapstart = (gapstart << PAGE_SHIFT) + 1024*1024;
   35.10  		printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit address range\n"
   35.11  		       KERN_ERR "PCI: Unassigned devices with 32bit resource registers may break!\n");
    36.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/smp.c	Fri Dec 02 12:12:11 2005 -0600
    36.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/smp.c	Fri Dec 02 12:52:25 2005 -0600
    36.3 @@ -31,8 +31,6 @@
    36.4  #ifdef CONFIG_XEN
    36.5  #include <asm-xen/evtchn.h>
    36.6  
    36.7 -#define xxprint(msg) HYPERVISOR_console_io(CONSOLEIO_write, strlen(msg), msg)
    36.8 -
    36.9  #else
   36.10  /*
   36.11   *	Smarter SMP flushing macros. 
   36.12 @@ -379,8 +377,6 @@ void smp_stop_cpu(void)
   36.13  	local_irq_disable();
   36.14  #ifndef CONFIG_XEN
   36.15  	disable_local_APIC();
   36.16 -#else
   36.17 -	xxprint("stop_this_cpu disable_local_APIC\n");
   36.18  #endif
   36.19  	local_irq_enable(); 
   36.20  }
   36.21 @@ -409,9 +405,7 @@ void smp_send_stop(void)
   36.22  		spin_unlock(&call_lock);
   36.23  
   36.24  	local_irq_disable();
   36.25 -#ifdef CONFIG_XEN
   36.26 -	xxprint("stop_this_cpu disable_local_APIC\n");
   36.27 -#else
   36.28 +#ifndef CONFIG_XEN
   36.29  	disable_local_APIC();
   36.30  #endif
   36.31  	local_irq_enable();
    37.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S	Fri Dec 02 12:12:11 2005 -0600
    37.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S	Fri Dec 02 12:52:25 2005 -0600
    37.3 @@ -5,7 +5,7 @@
    37.4  #define evtchn_upcall_pending		0
    37.5  #define evtchn_upcall_mask		1
    37.6  
    37.7 -#define sizeof_vcpu_shift		5
    37.8 +#define sizeof_vcpu_shift		6
    37.9  
   37.10  #ifdef CONFIG_SMP
   37.11  //#define preempt_disable(reg)	incl threadinfo_preempt_count(reg)
    38.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c	Fri Dec 02 12:12:11 2005 -0600
    38.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c	Fri Dec 02 12:52:25 2005 -0600
    38.3 @@ -344,7 +344,7 @@ asmlinkage void do_page_fault(struct pt_
    38.4  #endif
    38.5  
    38.6  	/* get the address */
    38.7 -	address = HYPERVISOR_shared_info->vcpu_data[
    38.8 +	address = HYPERVISOR_shared_info->vcpu_info[
    38.9  		smp_processor_id()].arch.cr2;
   38.10  
   38.11  	if (notify_die(DIE_PAGE_FAULT, "page fault", regs, error_code, 14,
    39.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/Kconfig	Fri Dec 02 12:12:11 2005 -0600
    39.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/Kconfig	Fri Dec 02 12:52:25 2005 -0600
    39.3 @@ -18,15 +18,6 @@ config TCG_TPM
    39.4  	  compile this driver as a module, choose M here; the module 
    39.5  	  will be called tpm. If unsure, say N.
    39.6  
    39.7 -config TCG_TIS
    39.8 -	tristate "TPM Interface Specification 1.2 Interface"
    39.9 -	depends on TCG_TPM
   39.10 -	---help---
   39.11 -	  If you have a TPM security chip that is compliant with the
   39.12 -	  TCG TIS 1.2 TPM specification say Yes and it will be accessible
   39.13 -	  from within Linux.  To compile this driver as a module, choose
   39.14 -	  M here; the module will be called tpm_tis.
   39.15 -
   39.16  config TCG_NSC
   39.17  	tristate "National Semiconductor TPM Interface"
   39.18  	depends on TCG_TPM
    40.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c	Fri Dec 02 12:12:11 2005 -0600
    40.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c	Fri Dec 02 12:52:25 2005 -0600
    40.3 @@ -22,7 +22,7 @@
    40.4  
    40.5  #include <asm/uaccess.h>
    40.6  #include <linux/list.h>
    40.7 -#include <linux/tpmfe.h>
    40.8 +#include <asm-xen/tpmfe.h>
    40.9  #include <linux/device.h>
   40.10  #include <linux/interrupt.h>
   40.11  #include "tpm.h"
    41.1 --- a/linux-2.6-xen-sparse/drivers/xen/Makefile	Fri Dec 02 12:12:11 2005 -0600
    41.2 +++ b/linux-2.6-xen-sparse/drivers/xen/Makefile	Fri Dec 02 12:52:25 2005 -0600
    41.3 @@ -2,6 +2,7 @@
    41.4  obj-y	+= net_driver_util.o
    41.5  obj-y	+= util.o
    41.6  
    41.7 +obj-y	+= char/
    41.8  obj-y	+= console/
    41.9  obj-y	+= evtchn/
   41.10  obj-y	+= balloon/
    42.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Fri Dec 02 12:12:11 2005 -0600
    42.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Fri Dec 02 12:52:25 2005 -0600
    42.3 @@ -88,10 +88,10 @@ static inline void flush_plugged_queue(v
    42.4   * handle returned must be used to unmap the frame. This is needed to
    42.5   * drop the ref count on the frame.
    42.6   */
    42.7 -static u16 pending_grant_handles[MMAP_PAGES];
    42.8 +static grant_handle_t pending_grant_handles[MMAP_PAGES];
    42.9  #define pending_handle(_idx, _i) \
   42.10      (pending_grant_handles[((_idx) * BLKIF_MAX_SEGMENTS_PER_REQUEST) + (_i)])
   42.11 -#define BLKBACK_INVALID_HANDLE (0xFFFF)
   42.12 +#define BLKBACK_INVALID_HANDLE (~0)
   42.13  
   42.14  #ifdef CONFIG_XEN_BLKDEV_TAP_BE
   42.15  /*
   42.16 @@ -114,7 +114,7 @@ static void fast_flush_area(int idx, int
   42.17  {
   42.18  	struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
   42.19  	unsigned int i, invcount = 0;
   42.20 -	u16 handle;
   42.21 +	grant_handle_t handle;
   42.22  	int ret;
   42.23  
   42.24  	for (i = 0; i < nr_pages; i++) {
   42.25 @@ -335,7 +335,6 @@ static void dispatch_rw_block_io(blkif_t
   42.26  {
   42.27  	extern void ll_rw_block(int rw, int nr, struct buffer_head * bhs[]); 
   42.28  	int operation = (req->operation == BLKIF_OP_WRITE) ? WRITE : READ;
   42.29 -	unsigned long fas = 0;
   42.30  	int i, pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)];
   42.31  	pending_req_t *pending_req;
   42.32  	struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST];
   42.33 @@ -362,16 +361,17 @@ static void dispatch_rw_block_io(blkif_t
   42.34  	preq.nr_sects      = 0;
   42.35  
   42.36  	for (i = 0; i < nseg; i++) {
   42.37 -		fas         = req->frame_and_sects[i];
   42.38 -		seg[i].nsec = blkif_last_sect(fas) - blkif_first_sect(fas) + 1;
   42.39 +		seg[i].nsec = req->seg[i].last_sect -
   42.40 +			req->seg[i].first_sect + 1;
   42.41  
   42.42 -		if (seg[i].nsec <= 0)
   42.43 +		if ((req->seg[i].last_sect >= (PAGE_SIZE >> 9)) ||
   42.44 +		    (seg[i].nsec <= 0))
   42.45  			goto bad_descriptor;
   42.46  		preq.nr_sects += seg[i].nsec;
   42.47  
   42.48  		map[i].host_addr = MMAP_VADDR(pending_idx, i);
   42.49  		map[i].dom = blkif->domid;
   42.50 -		map[i].ref = blkif_gref_from_fas(fas);
   42.51 +		map[i].ref = req->seg[i].gref;
   42.52  		map[i].flags = GNTMAP_host_map;
   42.53  		if ( operation == WRITE )
   42.54  			map[i].flags |= GNTMAP_readonly;
   42.55 @@ -381,7 +381,7 @@ static void dispatch_rw_block_io(blkif_t
   42.56  	BUG_ON(ret);
   42.57  
   42.58  	for (i = 0; i < nseg; i++) {
   42.59 -		if (likely(map[i].handle >= 0)) {
   42.60 +		if (likely(map[i].status == 0)) {
   42.61  			pending_handle(pending_idx, i) = map[i].handle;
   42.62  #ifdef __ia64__
   42.63  			MMAP_VADDR(pending_idx,i) = gnttab_map_vaddr(map[i]);
   42.64 @@ -390,9 +390,8 @@ static void dispatch_rw_block_io(blkif_t
   42.65  				pending_idx, i)) >> PAGE_SHIFT,
   42.66  				FOREIGN_FRAME(map[i].dev_bus_addr>>PAGE_SHIFT));
   42.67  #endif
   42.68 -			fas        = req->frame_and_sects[i];
   42.69 -			seg[i].buf = map[i].dev_bus_addr | 
   42.70 -				(blkif_first_sect(fas) << 9);
   42.71 +			seg[i].buf = map[i].dev_bus_addr |
   42.72 +				(req->seg[i].first_sect << 9);
   42.73  		} else {
   42.74  			errors++;
   42.75  		}
   42.76 @@ -482,6 +481,7 @@ static void make_response(blkif_t *blkif
   42.77  	blkif_response_t *resp;
   42.78  	unsigned long     flags;
   42.79  	blkif_back_ring_t *blk_ring = &blkif->blk_ring;
   42.80 +	int notify;
   42.81  
   42.82  	/* Place on the response ring for the relevant domain. */ 
   42.83  	spin_lock_irqsave(&blkif->blk_ring_lock, flags);
   42.84 @@ -489,13 +489,27 @@ static void make_response(blkif_t *blkif
   42.85  	resp->id        = id;
   42.86  	resp->operation = op;
   42.87  	resp->status    = st;
   42.88 -	wmb(); /* Ensure other side can see the response fields. */
   42.89  	blk_ring->rsp_prod_pvt++;
   42.90 -	RING_PUSH_RESPONSES(blk_ring);
   42.91 +	RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(blk_ring, notify);
   42.92  	spin_unlock_irqrestore(&blkif->blk_ring_lock, flags);
   42.93  
   42.94 -	/* Kick the relevant domain. */
   42.95 -	notify_remote_via_irq(blkif->irq);
   42.96 +	/*
   42.97 +         * Tail check for pending requests. Allows frontend to avoid
   42.98 +         * notifications if requests are already in flight (lower overheads
   42.99 +         * and promotes batching).
  42.100 +         */
  42.101 +	mb();
  42.102 +	if (!__on_blkdev_list(blkif)) {
  42.103 +		int more_to_do;
  42.104 +		RING_FINAL_CHECK_FOR_REQUESTS(blk_ring, more_to_do);
  42.105 +		if (more_to_do) {
  42.106 +			add_to_blkdev_list_tail(blkif);
  42.107 +			maybe_trigger_blkio_schedule();
  42.108 +		}
  42.109 +	}
  42.110 +
  42.111 +	if (notify)
  42.112 +		notify_remote_via_irq(blkif->irq);
  42.113  }
  42.114  
  42.115  void blkif_deschedule(blkif_t *blkif)
    43.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Fri Dec 02 12:12:11 2005 -0600
    43.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Fri Dec 02 12:52:25 2005 -0600
    43.3 @@ -38,6 +38,8 @@ struct vbd {
    43.4  	struct block_device *bdev;
    43.5  }; 
    43.6  
    43.7 +struct backend_info; 
    43.8 +
    43.9  typedef struct blkif_st {
   43.10  	/* Unique identifier for this interface. */
   43.11  	domid_t           domid;
   43.12 @@ -48,8 +50,10 @@ typedef struct blkif_st {
   43.13  	/* Comms information. */
   43.14  	blkif_back_ring_t blk_ring;
   43.15  	struct vm_struct *blk_ring_area;
   43.16 -	/* VBDs attached to this interface. */
   43.17 +	/* The VBD attached to this interface. */
   43.18  	struct vbd        vbd;
   43.19 +	/* Back pointer to the backend_info. */
   43.20 +	struct backend_info *be; 
   43.21  	/* Private fields. */
   43.22  	enum { DISCONNECTED, CONNECTED } status;
   43.23  #ifdef CONFIG_XEN_BLKDEV_TAP_BE
   43.24 @@ -62,8 +66,8 @@ typedef struct blkif_st {
   43.25  
   43.26  	struct work_struct free_work;
   43.27  
   43.28 -	u16         shmem_handle;
   43.29 -	grant_ref_t shmem_ref;
   43.30 +	grant_handle_t shmem_handle;
   43.31 +	grant_ref_t    shmem_ref;
   43.32  } blkif_t;
   43.33  
   43.34  blkif_t *alloc_blkif(domid_t domid);
   43.35 @@ -78,8 +82,8 @@ int blkif_map(blkif_t *blkif, unsigned l
   43.36  	} while (0)
   43.37  
   43.38  /* Create a vbd. */
   43.39 -int vbd_create(blkif_t *blkif, blkif_vdev_t vdevice, u32 pdevice,
   43.40 -	       int readonly);
   43.41 +int vbd_create(blkif_t *blkif, blkif_vdev_t vdevice, unsigned major,
   43.42 +	       unsigned minor, int readonly);
   43.43  void vbd_free(struct vbd *vbd);
   43.44  
   43.45  unsigned long vbd_size(struct vbd *vbd);
   43.46 @@ -103,6 +107,8 @@ void blkif_xenbus_init(void);
   43.47  
   43.48  irqreturn_t blkif_be_int(int irq, void *dev_id, struct pt_regs *regs);
   43.49  
   43.50 +void update_blkif_status(blkif_t *blkif); 
   43.51 +
   43.52  #endif /* __BLKIF__BACKEND__COMMON_H__ */
   43.53  
   43.54  /*
    44.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Fri Dec 02 12:12:11 2005 -0600
    44.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Fri Dec 02 12:52:25 2005 -0600
    44.3 @@ -43,9 +43,9 @@ static int map_frontend_page(blkif_t *bl
    44.4  	unlock_vm_area(blkif->blk_ring_area);
    44.5  	BUG_ON(ret);
    44.6  
    44.7 -	if (op.handle < 0) {
    44.8 +	if (op.status) {
    44.9  		DPRINTK(" Grant table operation failure !\n");
   44.10 -		return op.handle;
   44.11 +		return op.status;
   44.12  	}
   44.13  
   44.14  	blkif->shmem_ref = shared_page;
   44.15 @@ -107,12 +107,13 @@ int blkif_map(blkif_t *blkif, unsigned l
   44.16  	blkif->evtchn = op.u.bind_interdomain.local_port;
   44.17  
   44.18  	sring = (blkif_sring_t *)blkif->blk_ring_area->addr;
   44.19 -	SHARED_RING_INIT(sring);
   44.20  	BACK_RING_INIT(&blkif->blk_ring, sring, PAGE_SIZE);
   44.21  
   44.22  	blkif->irq = bind_evtchn_to_irqhandler(
   44.23  		blkif->evtchn, blkif_be_int, 0, "blkif-backend", blkif);
   44.24 -	blkif->status = CONNECTED;
   44.25 +
   44.26 +	/* We're potentially connected now */
   44.27 +	update_blkif_status(blkif); 
   44.28  
   44.29  	return 0;
   44.30  }
    45.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c	Fri Dec 02 12:12:11 2005 -0600
    45.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c	Fri Dec 02 12:52:25 2005 -0600
    45.3 @@ -9,10 +9,6 @@
    45.4  #include "common.h"
    45.5  #include <asm-xen/xenbus.h>
    45.6  
    45.7 -static inline dev_t vbd_map_devnum(u32 cookie)
    45.8 -{
    45.9 -	return MKDEV(BLKIF_MAJOR(cookie), BLKIF_MINOR(cookie));
   45.10 -}
   45.11  #define vbd_sz(_v)   ((_v)->bdev->bd_part ?				\
   45.12  	(_v)->bdev->bd_part->nr_sects : (_v)->bdev->bd_disk->capacity)
   45.13  #define bdev_put(_b) blkdev_put(_b)
   45.14 @@ -32,8 +28,8 @@ unsigned long vbd_secsize(struct vbd *vb
   45.15  	return bdev_hardsect_size(vbd->bdev);
   45.16  }
   45.17  
   45.18 -int vbd_create(blkif_t *blkif, blkif_vdev_t handle,
   45.19 -	       u32 pdevice, int readonly)
   45.20 +int vbd_create(blkif_t *blkif, blkif_vdev_t handle, unsigned major,
   45.21 +	       unsigned minor, int readonly)
   45.22  {
   45.23  	struct vbd *vbd;
   45.24  
   45.25 @@ -42,10 +38,10 @@ int vbd_create(blkif_t *blkif, blkif_vde
   45.26  	vbd->readonly = readonly;
   45.27  	vbd->type     = 0;
   45.28  
   45.29 -	vbd->pdevice  = pdevice;
   45.30 +	vbd->pdevice  = MKDEV(major, minor);
   45.31  
   45.32  	vbd->bdev = open_by_devnum(
   45.33 -		vbd_map_devnum(vbd->pdevice),
   45.34 +		vbd->pdevice,
   45.35  		vbd->readonly ? FMODE_READ : FMODE_WRITE);
   45.36  	if (IS_ERR(vbd->bdev)) {
   45.37  		DPRINTK("vbd_creat: device %08x doesn't exist.\n",
    46.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Fri Dec 02 12:12:11 2005 -0600
    46.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Fri Dec 02 12:52:25 2005 -0600
    46.3 @@ -37,8 +37,9 @@ struct backend_info
    46.4  	blkif_t *blkif;
    46.5  	struct xenbus_watch backend_watch;
    46.6  
    46.7 -	long int pdev;
    46.8 -	long int readonly;
    46.9 +	unsigned major;
   46.10 +	unsigned minor;
   46.11 +	char *mode;
   46.12  };
   46.13  
   46.14  
   46.15 @@ -49,6 +50,35 @@ static void backend_changed(struct xenbu
   46.16  			    unsigned int);
   46.17  
   46.18  
   46.19 +void update_blkif_status(blkif_t *blkif)
   46.20 +{ 
   46.21 +	if(blkif->irq && blkif->vbd.bdev) {
   46.22 +		blkif->status = CONNECTED; 
   46.23 +		(void)blkif_be_int(0, blkif, NULL); 
   46.24 +	}
   46.25 +	maybe_connect(blkif->be); 
   46.26 +}
   46.27 +
   46.28 +
   46.29 +static ssize_t show_physical_device(struct device *_dev, char *buf)
   46.30 +{
   46.31 +	struct xenbus_device *dev = to_xenbus_device(_dev);
   46.32 +	struct backend_info *be = dev->data;
   46.33 +	return sprintf(buf, "%x:%x\n", be->major, be->minor);
   46.34 +}
   46.35 +DEVICE_ATTR(physical_device, S_IRUSR | S_IRGRP | S_IROTH,
   46.36 +	    show_physical_device, NULL);
   46.37 +
   46.38 +
   46.39 +static ssize_t show_mode(struct device *_dev, char *buf)
   46.40 +{
   46.41 +	struct xenbus_device *dev = to_xenbus_device(_dev);
   46.42 +	struct backend_info *be = dev->data;
   46.43 +	return sprintf(buf, "%s\n", be->mode);
   46.44 +}
   46.45 +DEVICE_ATTR(mode, S_IRUSR | S_IRGRP | S_IROTH, show_mode, NULL);
   46.46 +
   46.47 +
   46.48  static int blkback_remove(struct xenbus_device *dev)
   46.49  {
   46.50  	struct backend_info *be = dev->data;
   46.51 @@ -61,9 +91,14 @@ static int blkback_remove(struct xenbus_
   46.52  		be->backend_watch.node = NULL;
   46.53  	}
   46.54  	if (be->blkif) {
   46.55 +		be->blkif->status = DISCONNECTED; 
   46.56  		blkif_put(be->blkif);
   46.57  		be->blkif = NULL;
   46.58  	}
   46.59 +
   46.60 +	device_remove_file(&dev->dev, &dev_attr_physical_device);
   46.61 +	device_remove_file(&dev->dev, &dev_attr_mode);
   46.62 +
   46.63  	kfree(be);
   46.64  	dev->data = NULL;
   46.65  	return 0;
   46.66 @@ -73,7 +108,7 @@ static int blkback_remove(struct xenbus_
   46.67  /**
   46.68   * Entry point to this code when a new device is created.  Allocate the basic
   46.69   * structures, and watch the store waiting for the hotplug scripts to tell us
   46.70 - * the device's physical-device.  Switch to InitWait.
   46.71 + * the device's physical major and minor numbers.  Switch to InitWait.
   46.72   */
   46.73  static int blkback_probe(struct xenbus_device *dev,
   46.74  			 const struct xenbus_device_id *id)
   46.75 @@ -99,6 +134,9 @@ static int blkback_probe(struct xenbus_d
   46.76  		goto fail;
   46.77  	}
   46.78  
   46.79 +	/* setup back pointer */
   46.80 +	be->blkif->be = be; 
   46.81 +
   46.82  	err = xenbus_watch_path2(dev, dev->nodename, "physical-device",
   46.83  				 &be->backend_watch, backend_changed);
   46.84  	if (err)
   46.85 @@ -119,66 +157,74 @@ fail:
   46.86  
   46.87  /**
   46.88   * Callback received when the hotplug scripts have placed the physical-device
   46.89 - * node.  Read it and the read-only node, and create a vbd.  If the frontend
   46.90 - * is ready, connect.
   46.91 + * node.  Read it and the mode node, and create a vbd.  If the frontend is
   46.92 + * ready, connect.
   46.93   */
   46.94  static void backend_changed(struct xenbus_watch *watch,
   46.95  			    const char **vec, unsigned int len)
   46.96  {
   46.97  	int err;
   46.98 -	char *p;
   46.99 -	long pdev;
  46.100 +	unsigned major;
  46.101 +	unsigned minor;
  46.102  	struct backend_info *be
  46.103  		= container_of(watch, struct backend_info, backend_watch);
  46.104  	struct xenbus_device *dev = be->dev;
  46.105  
  46.106  	DPRINTK("");
  46.107  
  46.108 -	err = xenbus_scanf(NULL, dev->nodename,
  46.109 -			   "physical-device", "%li", &pdev);
  46.110 +	err = xenbus_scanf(NULL, dev->nodename, "physical-device", "%x:%x",
  46.111 +			   &major, &minor);
  46.112  	if (XENBUS_EXIST_ERR(err)) {
  46.113  		/* Since this watch will fire once immediately after it is
  46.114  		   registered, we expect this.  Ignore it, and wait for the
  46.115  		   hotplug scripts. */
  46.116  		return;
  46.117  	}
  46.118 -	if (err != 1) {
  46.119 +	if (err != 2) {
  46.120  		xenbus_dev_fatal(dev, err, "reading physical-device");
  46.121  		return;
  46.122  	}
  46.123 -	if (be->pdev && be->pdev != pdev) {
  46.124 +
  46.125 +	if (be->major && be->minor &&
  46.126 +	    (be->major != major || be->minor != minor)) {
  46.127  		printk(KERN_WARNING
  46.128 -		       "blkback: changing physical-device (from %ld to %ld) "
  46.129 -		       "not supported.\n", be->pdev, pdev);
  46.130 +		       "blkback: changing physical device (from %x:%x to "
  46.131 +		       "%x:%x) not supported.\n", be->major, be->minor,
  46.132 +		       major, minor);
  46.133 +		return;
  46.134 +	}
  46.135 +
  46.136 +	be->mode = xenbus_read(NULL, dev->nodename, "mode", NULL);
  46.137 +	if (IS_ERR(be->mode)) {
  46.138 +		err = PTR_ERR(be->mode);
  46.139 +		be->mode = NULL;
  46.140 +		xenbus_dev_fatal(dev, err, "reading mode");
  46.141  		return;
  46.142  	}
  46.143  
  46.144 -	/* If there's a read-only node, we're read only. */
  46.145 -	p = xenbus_read(NULL, dev->nodename, "read-only", NULL);
  46.146 -	if (!IS_ERR(p)) {
  46.147 -		be->readonly = 1;
  46.148 -		kfree(p);
  46.149 -	}
  46.150 -
  46.151 -	if (be->pdev == 0L) {
  46.152 +	if (be->major == 0 && be->minor == 0) {
  46.153  		/* Front end dir is a number, which is used as the handle. */
  46.154  
  46.155 -		long handle;
  46.156 +		char *p = strrchr(dev->otherend, '/') + 1;
  46.157 +		long handle = simple_strtoul(p, NULL, 0);
  46.158  
  46.159 -		p = strrchr(dev->otherend, '/') + 1;
  46.160 -		handle = simple_strtoul(p, NULL, 0);
  46.161 +		be->major = major;
  46.162 +		be->minor = minor;
  46.163  
  46.164 -		be->pdev = pdev;
  46.165 -
  46.166 -		err = vbd_create(be->blkif, handle, be->pdev, be->readonly);
  46.167 +		err = vbd_create(be->blkif, handle, major, minor,
  46.168 +				 (NULL == strchr(be->mode, 'w')));
  46.169  		if (err) {
  46.170 -			be->pdev = 0L;
  46.171 -			xenbus_dev_fatal(dev, err,
  46.172 -					 "creating vbd structure");
  46.173 +			be->major = 0;
  46.174 +			be->minor = 0;
  46.175 +			xenbus_dev_fatal(dev, err, "creating vbd structure");
  46.176  			return;
  46.177  		}
  46.178  
  46.179 -		maybe_connect(be);
  46.180 +		device_create_file(&dev->dev, &dev_attr_physical_device);
  46.181 +		device_create_file(&dev->dev, &dev_attr_mode);
  46.182 +
  46.183 +		/* We're potentially connected now */
  46.184 +		update_blkif_status(be->blkif); 
  46.185  	}
  46.186  }
  46.187  
  46.188 @@ -204,7 +250,7 @@ static void frontend_changed(struct xenb
  46.189  		if (err) {
  46.190  			return;
  46.191  		}
  46.192 -		maybe_connect(be);
  46.193 +		update_blkif_status(be->blkif); 
  46.194  		break;
  46.195  
  46.196  	case XenbusStateClosing:
  46.197 @@ -230,9 +276,9 @@ static void frontend_changed(struct xenb
  46.198  
  46.199  static void maybe_connect(struct backend_info *be)
  46.200  {
  46.201 -	if (be->pdev != 0L && be->blkif->status == CONNECTED) {
  46.202 +	if ((be->major != 0 || be->minor != 0) &&
  46.203 +	    be->blkif->status == CONNECTED)
  46.204  		connect(be);
  46.205 -	}
  46.206  }
  46.207  
  46.208  
    47.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Fri Dec 02 12:12:11 2005 -0600
    47.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Fri Dec 02 12:52:25 2005 -0600
    47.3 @@ -32,7 +32,6 @@
    47.4   * IN THE SOFTWARE.
    47.5   */
    47.6  
    47.7 -
    47.8  #if 1
    47.9  #define ASSERT(p)							   \
   47.10  	if (!(p)) { printk("Assertion '%s' failed, line %d, file %s", #p , \
   47.11 @@ -41,7 +40,6 @@
   47.12  #define ASSERT(_p)
   47.13  #endif
   47.14  
   47.15 -
   47.16  #include <linux/version.h>
   47.17  #include "block.h"
   47.18  #include <linux/cdrom.h>
   47.19 @@ -54,16 +52,14 @@
   47.20  #include <asm-xen/gnttab.h>
   47.21  #include <asm/hypervisor.h>
   47.22  
   47.23 -
   47.24  #define BLKIF_STATE_DISCONNECTED 0
   47.25  #define BLKIF_STATE_CONNECTED    1
   47.26  #define BLKIF_STATE_SUSPENDED    2
   47.27  
   47.28  #define MAXIMUM_OUTSTANDING_BLOCK_REQS \
   47.29 -    (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE)
   47.30 +    (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLK_RING_SIZE)
   47.31  #define GRANT_INVALID_REF	0
   47.32  
   47.33 -
   47.34  static void connect(struct blkfront_info *);
   47.35  static void blkfront_closing(struct xenbus_device *);
   47.36  static int blkfront_remove(struct xenbus_device *);
   47.37 @@ -117,6 +113,8 @@ static int blkfront_probe(struct xenbus_
   47.38  		info->shadow[i].req.id = i+1;
   47.39  	info->shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff;
   47.40  
   47.41 +	info->users = 0;
   47.42 +
   47.43  	/* Front end dir is a number, which is used as the id. */
   47.44  	info->handle = simple_strtoul(strrchr(dev->nodename,'/')+1, NULL, 0);
   47.45  	dev->data = info;
   47.46 @@ -265,6 +263,7 @@ static void backend_changed(struct xenbu
   47.47  			    XenbusState backend_state)
   47.48  {
   47.49  	struct blkfront_info *info = dev->data;
   47.50 +	struct block_device *bd;
   47.51  
   47.52  	DPRINTK("blkfront:backend_changed.\n");
   47.53  
   47.54 @@ -281,7 +280,18 @@ static void backend_changed(struct xenbu
   47.55  		break;
   47.56  
   47.57  	case XenbusStateClosing:
   47.58 -		blkfront_closing(dev);
   47.59 +		bd = bdget(info->dev);
   47.60 +		if (bd == NULL)
   47.61 +			xenbus_dev_fatal(dev, -ENODEV, "bdget failed");
   47.62 +
   47.63 +		down(&bd->bd_sem);
   47.64 +		if (info->users > 0)
   47.65 +			xenbus_dev_error(dev, -EBUSY,
   47.66 +					 "Device in use; refusing to close");
   47.67 +		else
   47.68 +			blkfront_closing(dev);
   47.69 +		up(&bd->bd_sem);
   47.70 +		bdput(bd);
   47.71  		break;
   47.72  	}
   47.73  }
   47.74 @@ -290,6 +300,10 @@ static void backend_changed(struct xenbu
   47.75  /* ** Connection ** */
   47.76  
   47.77  
   47.78 +/* 
   47.79 +** Invoked when the backend is finally 'ready' (and has told produced 
   47.80 +** the details about the physical device - #sectors, size, etc). 
   47.81 +*/
   47.82  static void connect(struct blkfront_info *info)
   47.83  {
   47.84  	unsigned long sectors, sector_size;
   47.85 @@ -297,7 +311,7 @@ static void connect(struct blkfront_info
   47.86  	int err;
   47.87  
   47.88          if( (info->connected == BLKIF_STATE_CONNECTED) || 
   47.89 -	    (info->connected == BLKIF_STATE_SUSPENDED) ) 
   47.90 +	    (info->connected == BLKIF_STATE_SUSPENDED) )
   47.91  		return;
   47.92  
   47.93  	DPRINTK("blkfront.c:connect:%s.\n", info->xbdev->otherend);
   47.94 @@ -313,21 +327,20 @@ static void connect(struct blkfront_info
   47.95  				 info->xbdev->otherend);
   47.96  		return;
   47.97  	}
   47.98 -	
   47.99 -        info->connected = BLKIF_STATE_CONNECTED;
  47.100 +
  47.101          xlvbd_add(sectors, info->vdevice, binfo, sector_size, info);
  47.102 -	
  47.103 -	err = xenbus_switch_state(info->xbdev, NULL, XenbusStateConnected);
  47.104 -	if (err)
  47.105 -		return;
  47.106 -	
  47.107 +
  47.108 +	(void)xenbus_switch_state(info->xbdev, NULL, XenbusStateConnected); 
  47.109 +
  47.110  	/* Kick pending requests. */
  47.111  	spin_lock_irq(&blkif_io_lock);
  47.112 +	info->connected = BLKIF_STATE_CONNECTED;
  47.113  	kick_pending_request_queues(info);
  47.114  	spin_unlock_irq(&blkif_io_lock);
  47.115 +
  47.116 +	add_disk(info->gd);
  47.117  }
  47.118  
  47.119 -
  47.120  /**
  47.121   * Handle the change of state of the backend to Closing.  We must delete our
  47.122   * device-layer structures now, to ensure that writes are flushed through to
  47.123 @@ -384,8 +397,12 @@ static inline void ADD_ID_TO_FREELIST(
  47.124  
  47.125  static inline void flush_requests(struct blkfront_info *info)
  47.126  {
  47.127 -	RING_PUSH_REQUESTS(&info->ring);
  47.128 -	notify_remote_via_irq(info->irq);
  47.129 +	int notify;
  47.130 +
  47.131 +	RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&info->ring, notify);
  47.132 +
  47.133 +	if (notify)
  47.134 +		notify_remote_via_irq(info->irq);
  47.135  }
  47.136  
  47.137  static void kick_pending_request_queues(struct blkfront_info *info)
  47.138 @@ -414,12 +431,26 @@ static void blkif_restart_queue_callback
  47.139  
  47.140  int blkif_open(struct inode *inode, struct file *filep)
  47.141  {
  47.142 +	struct blkfront_info *info = inode->i_bdev->bd_disk->private_data;
  47.143 +	info->users++;
  47.144  	return 0;
  47.145  }
  47.146  
  47.147  
  47.148  int blkif_release(struct inode *inode, struct file *filep)
  47.149  {
  47.150 +	struct blkfront_info *info = inode->i_bdev->bd_disk->private_data;
  47.151 +	info->users--;
  47.152 +	if (info->users == 0) {
  47.153 +		/* Check whether we have been instructed to close.  We will
  47.154 +		   have ignored this request initially, as the device was
  47.155 +		   still mounted. */
  47.156 +		struct xenbus_device * dev = info->xbdev;
  47.157 +		XenbusState state = xenbus_read_driver_state(dev->otherend);
  47.158 +
  47.159 +		if (state == XenbusStateClosing)
  47.160 +			blkfront_closing(dev);
  47.161 +	}
  47.162  	return 0;
  47.163  }
  47.164  
  47.165 @@ -441,7 +472,7 @@ int blkif_ioctl(struct inode *inode, str
  47.166  	case CDROMMULTISESSION:
  47.167  		DPRINTK("FIXME: support multisession CDs later\n");
  47.168  		for (i = 0; i < sizeof(struct cdrom_multisession); i++)
  47.169 -			if (put_user(0, (char *)(argument + i)))
  47.170 +			if (put_user(0, (char __user *)(argument + i)))
  47.171  				return -EFAULT;
  47.172  		return 0;
  47.173  
  47.174 @@ -523,8 +554,11 @@ static int blkif_queue_request(struct re
  47.175  			info->shadow[id].frame[ring_req->nr_segments] =
  47.176  				mfn_to_pfn(buffer_mfn);
  47.177  
  47.178 -			ring_req->frame_and_sects[ring_req->nr_segments] =
  47.179 -				blkif_fas_from_gref(ref, fsect, lsect);
  47.180 +			ring_req->seg[ring_req->nr_segments] =
  47.181 +				(struct blkif_request_segment) {
  47.182 +					.gref       = ref,
  47.183 +					.first_sect = fsect, 
  47.184 +					.last_sect  = lsect };
  47.185  
  47.186  			ring_req->nr_segments++;
  47.187  		}
  47.188 @@ -556,7 +590,6 @@ void do_blkif_request(request_queue_t *r
  47.189  
  47.190  	while ((req = elv_next_request(rq)) != NULL) {
  47.191  		info = req->rq_disk->private_data;
  47.192 -
  47.193  		if (!blk_fs_request(req)) {
  47.194  			end_request(req, 0);
  47.195  			continue;
  47.196 @@ -604,6 +637,7 @@ static irqreturn_t blkif_int(int irq, vo
  47.197  		return IRQ_HANDLED;
  47.198  	}
  47.199  
  47.200 + again:
  47.201  	rp = info->ring.sring->rsp_prod;
  47.202  	rmb(); /* Ensure we see queued responses up to 'rp'. */
  47.203  
  47.204 @@ -639,6 +673,15 @@ static irqreturn_t blkif_int(int irq, vo
  47.205  
  47.206  	info->ring.rsp_cons = i;
  47.207  
  47.208 +	if (i != info->ring.req_prod_pvt) {
  47.209 +		int more_to_do;
  47.210 +		RING_FINAL_CHECK_FOR_RESPONSES(&info->ring, more_to_do);
  47.211 +		if (more_to_do)
  47.212 +			goto again;
  47.213 +	} else {
  47.214 +		info->ring.sring->rsp_event = i + 1;
  47.215 +	}
  47.216 +
  47.217  	kick_pending_request_queues(info);
  47.218  
  47.219  	spin_unlock_irqrestore(&blkif_io_lock, flags);
  47.220 @@ -671,8 +714,7 @@ static void blkif_completion(struct blk_
  47.221  {
  47.222  	int i;
  47.223  	for (i = 0; i < s->req.nr_segments; i++)
  47.224 -		gnttab_end_foreign_access(
  47.225 -			blkif_gref_from_fas(s->req.frame_and_sects[i]), 0, 0UL);
  47.226 +		gnttab_end_foreign_access(s->req.seg[i].gref, 0, 0UL);
  47.227  }
  47.228  
  47.229  static void blkif_recover(struct blkfront_info *info)
  47.230 @@ -712,7 +754,7 @@ static void blkif_recover(struct blkfron
  47.231  		/* Rewrite any grant references invalidated by susp/resume. */
  47.232  		for (j = 0; j < req->nr_segments; j++)
  47.233  			gnttab_grant_foreign_access_ref(
  47.234 -				blkif_gref_from_fas(req->frame_and_sects[j]),
  47.235 +				req->seg[j].gref,
  47.236  				info->xbdev->otherend_id,
  47.237  				pfn_to_mfn(info->shadow[req->id].frame[j]),
  47.238  				rq_data_dir(
  47.239 @@ -725,14 +767,20 @@ static void blkif_recover(struct blkfron
  47.240  
  47.241  	kfree(copy);
  47.242  
  47.243 -	/* info->ring->req_prod will be set when we flush_requests().*/
  47.244 -	wmb();
  47.245 +	(void)xenbus_switch_state(info->xbdev, NULL, XenbusStateConnected); 
  47.246 +	
  47.247 +	/* Now safe for us to use the shared ring */
  47.248 +	spin_lock_irq(&blkif_io_lock);
  47.249 +        info->connected = BLKIF_STATE_CONNECTED;
  47.250 +	spin_unlock_irq(&blkif_io_lock);
  47.251  
  47.252 -	/* Kicks things back into life. */
  47.253 +	/* Send off requeued requests */
  47.254  	flush_requests(info);
  47.255  
  47.256 -	/* Now safe to let other people use the interface. */
  47.257 -	info->connected = BLKIF_STATE_CONNECTED;
  47.258 +	/* Kick any other new requests queued since we resumed */
  47.259 +	spin_lock_irq(&blkif_io_lock);
  47.260 +	kick_pending_request_queues(info);
  47.261 +	spin_unlock_irq(&blkif_io_lock);
  47.262  }
  47.263  
  47.264  
    48.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h	Fri Dec 02 12:12:11 2005 -0600
    48.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h	Fri Dec 02 12:52:25 2005 -0600
    48.3 @@ -127,6 +127,12 @@ struct blkfront_info
    48.4  	struct gnttab_free_callback callback;
    48.5  	struct blk_shadow shadow[BLK_RING_SIZE];
    48.6  	unsigned long shadow_free;
    48.7 +
    48.8 +	/**
    48.9 +	 * The number of people holding this device open.  We won't allow a
   48.10 +	 * hot-unplug unless this is 0.
   48.11 +	 */
   48.12 +	int users;
   48.13  };
   48.14  
   48.15  extern spinlock_t blkif_io_lock;
   48.16 @@ -140,6 +146,9 @@ extern int blkif_revalidate(dev_t dev);
   48.17  extern void do_blkif_request (request_queue_t *rq); 
   48.18  
   48.19  /* Virtual block-device subsystem. */
   48.20 +/* Note that xlvbd_add doesn't call add_disk for you: you're expected
   48.21 +   to call add_disk on info->gd once the disk is properly connected
   48.22 +   up. */
   48.23  int xlvbd_add(blkif_sector_t capacity, int device,
   48.24  	      u16 vdisk_info, u16 sector_size, struct blkfront_info *info);
   48.25  void xlvbd_del(struct blkfront_info *info);
    49.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c	Fri Dec 02 12:12:11 2005 -0600
    49.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c	Fri Dec 02 12:52:25 2005 -0600
    49.3 @@ -33,6 +33,9 @@
    49.4  #include <linux/blkdev.h>
    49.5  #include <linux/list.h>
    49.6  
    49.7 +#define BLKIF_MAJOR(dev) ((dev)>>8)
    49.8 +#define BLKIF_MINOR(dev) ((dev) & 0xff)
    49.9 +
   49.10  /*
   49.11   * For convenience we distinguish between ide, scsi and 'other' (i.e.,
   49.12   * potentially combinations of the two) in the naming scheme and in a few other
   49.13 @@ -258,7 +261,6 @@ xlvbd_alloc_gendisk(int minor, blkif_sec
   49.14  	if (vdisk_info & VDISK_CDROM)
   49.15  		gd->flags |= GENHD_FL_CD;
   49.16  
   49.17 -	add_disk(gd);
   49.18  	info->gd = gd;
   49.19  
   49.20  	return 0;
    50.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Fri Dec 02 12:12:11 2005 -0600
    50.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Fri Dec 02 12:52:25 2005 -0600
    50.3 @@ -177,8 +177,8 @@ extern inline domid_t ID_TO_DOM(unsigned
    50.4   */
    50.5  struct grant_handle_pair
    50.6  {
    50.7 -	u16  kernel;
    50.8 -	u16  user;
    50.9 +	grant_handle_t kernel;
   50.10 +	grant_handle_t user;
   50.11  };
   50.12  static struct grant_handle_pair pending_grant_handles[MMAP_PAGES];
   50.13  #define pending_handle(_idx, _i) \
   50.14 @@ -375,7 +375,7 @@ static int blktap_ioctl(struct inode *in
   50.15  static unsigned int blktap_poll(struct file *file, poll_table *wait)
   50.16  {
   50.17  	poll_wait(file, &blktap_wait, wait);
   50.18 -	if (RING_HAS_UNPUSHED_REQUESTS(&blktap_ufe_ring)) {
   50.19 +	if (blktap_ufe_ring.req_prod_pvt != blktap_ufe_ring.sring->req_prod) {
   50.20  		flush_tlb_all();
   50.21  		RING_PUSH_REQUESTS(&blktap_ufe_ring);
   50.22  		return POLLIN | POLLRDNORM;
   50.23 @@ -713,7 +713,7 @@ static void dispatch_rw_block_io(blkif_t
   50.24  		/* Map the remote page to kernel. */
   50.25  		map[op].host_addr = kvaddr;
   50.26  		map[op].dom   = blkif->domid;
   50.27 -		map[op].ref   = blkif_gref_from_fas(req->frame_and_sects[i]);
   50.28 +		map[op].ref   = req->seg[i].gref;
   50.29  		map[op].flags = GNTMAP_host_map;
   50.30  		/* This needs a bit more thought in terms of interposition: 
   50.31  		 * If we want to be able to modify pages during write using 
   50.32 @@ -733,7 +733,7 @@ static void dispatch_rw_block_io(blkif_t
   50.33  
   50.34  		map[op].host_addr = ptep;
   50.35  		map[op].dom       = blkif->domid;
   50.36 -		map[op].ref       = blkif_gref_from_fas(req->frame_and_sects[i]);
   50.37 +		map[op].ref       = req->seg[i].gref;
   50.38  		map[op].flags     = GNTMAP_host_map | GNTMAP_application_map
   50.39  			| GNTMAP_contains_pte;
   50.40  		/* Above interposition comment applies here as well. */
   50.41 @@ -755,17 +755,17 @@ static void dispatch_rw_block_io(blkif_t
   50.42  		uvaddr = MMAP_VADDR(user_vstart, pending_idx, i/2);
   50.43  		kvaddr = MMAP_VADDR(mmap_vstart, pending_idx, i/2);
   50.44  
   50.45 -		if (unlikely(map[i].handle < 0)) {
   50.46 +		if (unlikely(map[i].status)) {
   50.47  			DPRINTK("Error on kernel grant mapping (%d)\n",
   50.48 -				map[i].handle);
   50.49 -			ret = map[i].handle;
   50.50 +				map[i].status);
   50.51 +			ret = map[i].status;
   50.52  			cancel = 1;
   50.53  		}
   50.54  
   50.55 -		if (unlikely(map[i+1].handle < 0)) {
   50.56 +		if (unlikely(map[i+1].status)) {
   50.57  			DPRINTK("Error on user grant mapping (%d)\n",
   50.58 -				map[i+1].handle);
   50.59 -			ret = map[i+1].handle;
   50.60 +				map[i+1].status);
   50.61 +			ret = map[i+1].status;
   50.62  			cancel = 1;
   50.63  		}
   50.64  
    51.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Fri Dec 02 12:12:11 2005 -0600
    51.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Fri Dec 02 12:52:25 2005 -0600
    51.3 @@ -64,7 +64,7 @@ typedef struct blkif_st {
    51.4  
    51.5  	struct work_struct free_work;
    51.6  
    51.7 -	u16              shmem_handle;
    51.8 +	grant_handle_t   shmem_handle;
    51.9  	grant_ref_t      shmem_ref;
   51.10  } blkif_t;
   51.11  
    52.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Fri Dec 02 12:12:11 2005 -0600
    52.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Fri Dec 02 12:52:25 2005 -0600
    52.3 @@ -43,9 +43,9 @@ static int map_frontend_page(blkif_t *bl
    52.4  	unlock_vm_area(blkif->blk_ring_area);
    52.5  	BUG_ON(ret);
    52.6  
    52.7 -	if (op.handle < 0) {
    52.8 +	if (op.status) {
    52.9  		DPRINTK(" Grant table operation failure !\n");
   52.10 -		return op.handle;
   52.11 +		return op.status;
   52.12  	}
   52.13  
   52.14  	blkif->shmem_ref    = shared_page;
   52.15 @@ -97,7 +97,6 @@ int blkif_map(blkif_t *blkif, unsigned l
   52.16  	blkif->evtchn = op.u.bind_interdomain.local_port;
   52.17  
   52.18  	sring = (blkif_sring_t *)blkif->blk_ring_area->addr;
   52.19 -	SHARED_RING_INIT(sring);
   52.20  	BACK_RING_INIT(&blkif->blk_ring, sring, PAGE_SIZE);
   52.21  
   52.22  	blkif->irq = bind_evtchn_to_irqhandler(
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/linux-2.6-xen-sparse/drivers/xen/char/Makefile	Fri Dec 02 12:52:25 2005 -0600
    53.3 @@ -0,0 +1,2 @@
    53.4 +
    53.5 +obj-y	:= mem.o
    54.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.2 +++ b/linux-2.6-xen-sparse/drivers/xen/char/mem.c	Fri Dec 02 12:52:25 2005 -0600
    54.3 @@ -0,0 +1,157 @@
    54.4 +/*
    54.5 + *  Originally from linux/drivers/char/mem.c
    54.6 + *
    54.7 + *  Copyright (C) 1991, 1992  Linus Torvalds
    54.8 + *
    54.9 + *  Added devfs support. 
   54.10 + *    Jan-11-1998, C. Scott Ananian <cananian@alumni.princeton.edu>
   54.11 + *  Shared /dev/zero mmaping support, Feb 2000, Kanoj Sarcar <kanoj@sgi.com>
   54.12 + */
   54.13 +
   54.14 +#include <linux/config.h>
   54.15 +#include <linux/mm.h>
   54.16 +#include <linux/miscdevice.h>
   54.17 +#include <linux/slab.h>
   54.18 +#include <linux/vmalloc.h>
   54.19 +#include <linux/mman.h>
   54.20 +#include <linux/random.h>
   54.21 +#include <linux/init.h>
   54.22 +#include <linux/raw.h>
   54.23 +#include <linux/tty.h>
   54.24 +#include <linux/capability.h>
   54.25 +#include <linux/smp_lock.h>
   54.26 +#include <linux/devfs_fs_kernel.h>
   54.27 +#include <linux/ptrace.h>
   54.28 +#include <linux/device.h>
   54.29 +#include <asm/pgalloc.h>
   54.30 +#include <asm/uaccess.h>
   54.31 +#include <asm/io.h>
   54.32 +#include <asm/hypervisor.h>
   54.33 +
   54.34 +static inline int uncached_access(struct file *file)
   54.35 +{
   54.36 +        if (file->f_flags & O_SYNC)
   54.37 +                return 1;
   54.38 +        /* Xen sets correct MTRR type on non-RAM for us. */
   54.39 +        return 0;
   54.40 +}
   54.41 +
   54.42 +/*
   54.43 + * This funcion reads the *physical* memory. The f_pos points directly to the 
   54.44 + * memory location. 
   54.45 + */
   54.46 +static ssize_t read_mem(struct file * file, char __user * buf,
   54.47 +			size_t count, loff_t *ppos)
   54.48 +{
   54.49 +	unsigned long i, p = *ppos;
   54.50 +	ssize_t read = -EFAULT;
   54.51 +	void __iomem *v;
   54.52 +
   54.53 +	if ((v = ioremap(p, count)) == NULL) {
   54.54 +		/*
   54.55 +		 * Some programs (e.g., dmidecode) groove off into weird RAM
   54.56 +		 * areas where no table scan possibly exist (because Xen will
   54.57 +		 * have stomped on them!). These programs get rather upset if
   54.58 +                 * we let them know that Xen failed their access, so we fake
   54.59 +                 * out a read of all zeroes. :-)
   54.60 +		 */
   54.61 +		for (i = 0; i < count; i++)
   54.62 +			if (put_user(0, buf+i))
   54.63 +				return -EFAULT;
   54.64 +		return count;
   54.65 +	}
   54.66 +	if (copy_to_user(buf, v, count))
   54.67 +		goto out;
   54.68 +
   54.69 +	read = count;
   54.70 +	*ppos += read;
   54.71 +out:
   54.72 +	iounmap(v);
   54.73 +	return read;
   54.74 +}
   54.75 +
   54.76 +static ssize_t write_mem(struct file * file, const char __user * buf, 
   54.77 +			 size_t count, loff_t *ppos)
   54.78 +{
   54.79 +	unsigned long p = *ppos;
   54.80 +	ssize_t written = -EFAULT;
   54.81 +	void __iomem *v;
   54.82 +
   54.83 +	if ((v = ioremap(p, count)) == NULL)
   54.84 +		return -EFAULT;
   54.85 +	if (copy_from_user(v, buf, count))
   54.86 +		goto out;
   54.87 +
   54.88 +	written = count;
   54.89 +	*ppos += written;
   54.90 +out:
   54.91 +	iounmap(v);
   54.92 +	return written;
   54.93 +}
   54.94 +
   54.95 +static int mmap_mem(struct file * file, struct vm_area_struct * vma)
   54.96 +{
   54.97 +	if (uncached_access(file))
   54.98 +		vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
   54.99 +
  54.100 +	if (direct_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  54.101 +				   vma->vm_end - vma->vm_start,
  54.102 +				   vma->vm_page_prot, DOMID_IO))
  54.103 +		return -EAGAIN;
  54.104 +
  54.105 +	return 0;
  54.106 +}
  54.107 +
  54.108 +/*
  54.109 + * The memory devices use the full 32/64 bits of the offset, and so we cannot
  54.110 + * check against negative addresses: they are ok. The return value is weird,
  54.111 + * though, in that case (0).
  54.112 + *
  54.113 + * also note that seeking relative to the "end of file" isn't supported:
  54.114 + * it has no meaning, so it returns -EINVAL.
  54.115 + */
  54.116 +static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
  54.117 +{
  54.118 +	loff_t ret;
  54.119 +
  54.120 +	down(&file->f_dentry->d_inode->i_sem);
  54.121 +	switch (orig) {
  54.122 +		case 0:
  54.123 +			file->f_pos = offset;
  54.124 +			ret = file->f_pos;
  54.125 +			force_successful_syscall_return();
  54.126 +			break;
  54.127 +		case 1:
  54.128 +			file->f_pos += offset;
  54.129 +			ret = file->f_pos;
  54.130 +			force_successful_syscall_return();
  54.131 +			break;
  54.132 +		default:
  54.133 +			ret = -EINVAL;
  54.134 +	}
  54.135 +	up(&file->f_dentry->d_inode->i_sem);
  54.136 +	return ret;
  54.137 +}
  54.138 +
  54.139 +static int open_mem(struct inode * inode, struct file * filp)
  54.140 +{
  54.141 +	return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
  54.142 +}
  54.143 +
  54.144 +struct file_operations mem_fops = {
  54.145 +	.llseek		= memory_lseek,
  54.146 +	.read		= read_mem,
  54.147 +	.write		= write_mem,
  54.148 +	.mmap		= mmap_mem,
  54.149 +	.open		= open_mem,
  54.150 +};
  54.151 +
  54.152 +/*
  54.153 + * Local variables:
  54.154 + *  c-file-style: "linux"
  54.155 + *  indent-tabs-mode: t
  54.156 + *  c-indent-level: 8
  54.157 + *  c-basic-offset: 8
  54.158 + *  tab-width: 8
  54.159 + * End:
  54.160 + */
    55.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/console.c	Fri Dec 02 12:12:11 2005 -0600
    55.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/console.c	Fri Dec 02 12:52:25 2005 -0600
    55.3 @@ -55,7 +55,6 @@
    55.4  #include <asm-xen/evtchn.h>
    55.5  #include <asm-xen/xencons.h>
    55.6  
    55.7 -#include "xencons_ring.h"
    55.8  /*
    55.9   * Modes:
   55.10   *  'xencons=off'  [XC_OFF]:     Console is disabled.
   55.11 @@ -135,20 +134,22 @@ static struct tty_driver *xencons_driver
   55.12  static void kcons_write(
   55.13  	struct console *c, const char *s, unsigned int count)
   55.14  {
   55.15 -	int           i;
   55.16 +	int           i = 0;
   55.17  	unsigned long flags;
   55.18  
   55.19  	spin_lock_irqsave(&xencons_lock, flags);
   55.20 -    
   55.21 -	for (i = 0; i < count; i++) {
   55.22 -		if ((wp - wc) >= (wbuf_size - 1))
   55.23 -			break;
   55.24 -		if ((wbuf[WBUF_MASK(wp++)] = s[i]) == '\n')
   55.25 -			wbuf[WBUF_MASK(wp++)] = '\r';
   55.26 +
   55.27 +	while (i < count) {
   55.28 +		for (; i < count; i++) {
   55.29 +			if ((wp - wc) >= (wbuf_size - 1))
   55.30 +				break;
   55.31 +			if ((wbuf[WBUF_MASK(wp++)] = s[i]) == '\n')
   55.32 +				wbuf[WBUF_MASK(wp++)] = '\r';
   55.33 +		}
   55.34 +
   55.35 +		__xencons_tx_flush();
   55.36  	}
   55.37  
   55.38 -	__xencons_tx_flush();
   55.39 -
   55.40  	spin_unlock_irqrestore(&xencons_lock, flags);
   55.41  }
   55.42  
   55.43 @@ -247,7 +248,6 @@ void xencons_force_flush(void)
   55.44  	if (xen_start_info->flags & SIF_INITDOMAIN)
   55.45  		return;
   55.46  
   55.47 -
   55.48  	/* Spin until console data is flushed through to the daemon. */
   55.49  	while (wc != wp) {
   55.50  		int sent = 0;
   55.51 @@ -271,8 +271,7 @@ static struct tty_struct *xencons_tty;
   55.52  static int xencons_priv_irq;
   55.53  static char x_char;
   55.54  
   55.55 -/* Non-privileged receive callback. */
   55.56 -static void xencons_rx(char *buf, unsigned len, struct pt_regs *regs)
   55.57 +void xencons_rx(char *buf, unsigned len, struct pt_regs *regs)
   55.58  {
   55.59  	int           i;
   55.60  	unsigned long flags;
   55.61 @@ -311,10 +310,9 @@ static void xencons_rx(char *buf, unsign
   55.62  	spin_unlock_irqrestore(&xencons_lock, flags);
   55.63  }
   55.64  
   55.65 -/* Privileged and non-privileged transmit worker. */
   55.66  static void __xencons_tx_flush(void)
   55.67  {
   55.68 -	int sz, work_done = 0;
   55.69 +	int sent, sz, work_done = 0;
   55.70  
   55.71  	if (xen_start_info->flags & SIF_INITDOMAIN) {
   55.72  		if (x_char) {
   55.73 @@ -340,20 +338,18 @@ static void __xencons_tx_flush(void)
   55.74  		}
   55.75  
   55.76  		while (wc != wp) {
   55.77 -			int sent;
   55.78  			sz = wp - wc;
   55.79  			if (sz > (wbuf_size - WBUF_MASK(wc)))
   55.80  				sz = wbuf_size - WBUF_MASK(wc);
   55.81  			sent = xencons_ring_send(&wbuf[WBUF_MASK(wc)], sz);
   55.82 -			if (sent > 0) {
   55.83 -				wc += sent;
   55.84 -				work_done = 1;
   55.85 -			}
   55.86 +			if (sent == 0)
   55.87 +				break;
   55.88 +			wc += sent;
   55.89 +			work_done = 1;
   55.90  		}
   55.91  	}
   55.92  
   55.93 -	if (work_done && (xencons_tty != NULL))
   55.94 -	{
   55.95 +	if (work_done && (xencons_tty != NULL)) {
   55.96  		wake_up_interruptible(&xencons_tty->write_wait);
   55.97  		if ((xencons_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
   55.98  		    (xencons_tty->ldisc.write_wakeup != NULL))
   55.99 @@ -361,31 +357,26 @@ static void __xencons_tx_flush(void)
  55.100  	}
  55.101  }
  55.102  
  55.103 +void xencons_tx(void)
  55.104 +{
  55.105 +	unsigned long flags;
  55.106 +
  55.107 +	spin_lock_irqsave(&xencons_lock, flags);
  55.108 +	__xencons_tx_flush();
  55.109 +	spin_unlock_irqrestore(&xencons_lock, flags);
  55.110 +}
  55.111 +
  55.112  /* Privileged receive callback and transmit kicker. */
  55.113  static irqreturn_t xencons_priv_interrupt(int irq, void *dev_id,
  55.114                                            struct pt_regs *regs)
  55.115  {
  55.116 -	static char   rbuf[16];
  55.117 -	int           i, l;
  55.118 -	unsigned long flags;
  55.119 -
  55.120 -	spin_lock_irqsave(&xencons_lock, flags);
  55.121 +	static char rbuf[16];
  55.122 +	int         l;
  55.123  
  55.124 -	if (xencons_tty != NULL)
  55.125 -	{
  55.126 -		/* Receive work. */
  55.127 -		while ((l = HYPERVISOR_console_io(
  55.128 -			CONSOLEIO_read, 16, rbuf)) > 0)
  55.129 -			for (i = 0; i < l; i++)
  55.130 -				tty_insert_flip_char(xencons_tty, rbuf[i], 0);
  55.131 -		if (xencons_tty->flip.count != 0)
  55.132 -			tty_flip_buffer_push(xencons_tty);
  55.133 -	}
  55.134 +	while ((l = HYPERVISOR_console_io(CONSOLEIO_read, 16, rbuf)) > 0)
  55.135 +		xencons_rx(rbuf, l, regs);
  55.136  
  55.137 -	/* Transmit work. */
  55.138 -	__xencons_tx_flush();
  55.139 -
  55.140 -	spin_unlock_irqrestore(&xencons_lock, flags);
  55.141 +	xencons_tx();
  55.142  
  55.143  	return IRQ_HANDLED;
  55.144  }
  55.145 @@ -579,7 +570,7 @@ static struct tty_operations xencons_ops
  55.146  	.wait_until_sent = xencons_wait_until_sent,
  55.147  };
  55.148  
  55.149 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST
  55.150 +#ifdef CONFIG_XEN_PHYSDEV_ACCESS
  55.151  static const char *xennullcon_startup(void)
  55.152  {
  55.153  	return NULL;
  55.154 @@ -664,7 +655,8 @@ static int __init xencons_init(void)
  55.155  	if ((rc = tty_register_driver(DRV(xencons_driver))) != 0) {
  55.156  		printk("WARNING: Failed to register Xen virtual "
  55.157  		       "console driver as '%s%d'\n",
  55.158 -		       DRV(xencons_driver)->name, DRV(xencons_driver)->name_base);
  55.159 +		       DRV(xencons_driver)->name,
  55.160 +		       DRV(xencons_driver)->name_base);
  55.161  		put_tty_driver(xencons_driver);
  55.162  		xencons_driver = NULL;
  55.163  		return rc;
  55.164 @@ -681,8 +673,6 @@ static int __init xencons_init(void)
  55.165  			"console",
  55.166  			NULL);
  55.167  		BUG_ON(xencons_priv_irq < 0);
  55.168 -	} else {
  55.169 -		xencons_ring_register_receiver(xencons_rx);
  55.170  	}
  55.171  
  55.172  	printk("Xen virtual console successfully installed as %s%d\n",
    56.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Fri Dec 02 12:12:11 2005 -0600
    56.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Fri Dec 02 12:52:25 2005 -0600
    56.3 @@ -15,15 +15,14 @@
    56.4  
    56.5  #include <asm/hypervisor.h>
    56.6  #include <asm-xen/evtchn.h>
    56.7 +#include <asm-xen/xencons.h>
    56.8  #include <linux/wait.h>
    56.9  #include <linux/interrupt.h>
   56.10  #include <linux/sched.h>
   56.11  #include <linux/err.h>
   56.12 -#include "xencons_ring.h"
   56.13  #include <asm-xen/xen-public/io/console.h>
   56.14  
   56.15  static int xencons_irq;
   56.16 -static xencons_receiver_func *xencons_receiver;
   56.17  
   56.18  static inline struct xencons_interface *xencons_interface(void)
   56.19  {
   56.20 @@ -69,10 +68,8 @@ static irqreturn_t handle_input(int irq,
   56.21  	BUG_ON((prod - cons) > sizeof(intf->in));
   56.22  
   56.23  	while (cons != prod) {
   56.24 -		if (xencons_receiver != NULL)
   56.25 -			xencons_receiver(
   56.26 -				intf->in + MASK_XENCONS_IDX(cons++, intf->in),
   56.27 -				1, regs);
   56.28 +		xencons_rx(intf->in+MASK_XENCONS_IDX(cons,intf->in), 1, regs);
   56.29 +		cons++;
   56.30  	}
   56.31  
   56.32  	mb();
   56.33 @@ -80,12 +77,9 @@ static irqreturn_t handle_input(int irq,
   56.34  
   56.35  	notify_daemon();
   56.36  
   56.37 -	return IRQ_HANDLED;
   56.38 -}
   56.39 +	xencons_tx();
   56.40  
   56.41 -void xencons_ring_register_receiver(xencons_receiver_func *f)
   56.42 -{
   56.43 -	xencons_receiver = f;
   56.44 +	return IRQ_HANDLED;
   56.45  }
   56.46  
   56.47  int xencons_ring_init(void)
   56.48 @@ -103,7 +97,7 @@ int xencons_ring_init(void)
   56.49  		xen_start_info->console_evtchn,
   56.50  		handle_input, 0, "xencons", NULL);
   56.51  	if (err <= 0) {
   56.52 -		xprintk("XEN console request irq failed %i\n", err);
   56.53 +		printk(KERN_ERR "XEN console request irq failed %i\n", err);
   56.54  		return err;
   56.55  	}
   56.56  
    57.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.h	Fri Dec 02 12:12:11 2005 -0600
    57.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.3 @@ -1,23 +0,0 @@
    57.4 -#ifndef _XENCONS_RING_H
    57.5 -#define _XENCONS_RING_H
    57.6 -
    57.7 -asmlinkage int xprintk(const char *fmt, ...);
    57.8 -
    57.9 -int xencons_ring_init(void);
   57.10 -int xencons_ring_send(const char *data, unsigned len);
   57.11 -
   57.12 -typedef void (xencons_receiver_func)(
   57.13 -	char *buf, unsigned len, struct pt_regs *regs);
   57.14 -void xencons_ring_register_receiver(xencons_receiver_func *f);
   57.15 -
   57.16 -#endif /* _XENCONS_RING_H */
   57.17 -
   57.18 -/*
   57.19 - * Local variables:
   57.20 - *  c-file-style: "linux"
   57.21 - *  indent-tabs-mode: t
   57.22 - *  c-indent-level: 8
   57.23 - *  c-basic-offset: 8
   57.24 - *  tab-width: 8
   57.25 - * End:
   57.26 - */
    58.1 --- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Fri Dec 02 12:12:11 2005 -0600
    58.2 +++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Fri Dec 02 12:52:25 2005 -0600
    58.3 @@ -50,9 +50,9 @@
    58.4  
    58.5  struct per_user_data {
    58.6  	/* Notification ring, accessed via /dev/xen/evtchn. */
    58.7 -#define EVTCHN_RING_SIZE     2048  /* 2048 16-bit entries */
    58.8 +#define EVTCHN_RING_SIZE     (PAGE_SIZE / sizeof(evtchn_port_t))
    58.9  #define EVTCHN_RING_MASK(_i) ((_i)&(EVTCHN_RING_SIZE-1))
   58.10 -	u16 *ring;
   58.11 +	evtchn_port_t *ring;
   58.12  	unsigned int ring_cons, ring_prod, ring_overflow;
   58.13  
   58.14  	/* Processes wait on this queue when ring is empty. */
   58.15 @@ -75,7 +75,7 @@ void evtchn_device_upcall(int port)
   58.16  
   58.17  	if ((u = port_user[port]) != NULL) {
   58.18  		if ((u->ring_prod - u->ring_cons) < EVTCHN_RING_SIZE) {
   58.19 -			u->ring[EVTCHN_RING_MASK(u->ring_prod)] = (u16)port;
   58.20 +			u->ring[EVTCHN_RING_MASK(u->ring_prod)] = port;
   58.21  			if (u->ring_cons == u->ring_prod++) {
   58.22  				wake_up_interruptible(&u->evtchn_wait);
   58.23  				kill_fasync(&u->evtchn_async_queue,
   58.24 @@ -89,57 +89,45 @@ void evtchn_device_upcall(int port)
   58.25  	spin_unlock(&port_user_lock);
   58.26  }
   58.27  
   58.28 -static ssize_t evtchn_read(struct file *file, char *buf,
   58.29 +static ssize_t evtchn_read(struct file *file, char __user *buf,
   58.30                             size_t count, loff_t *ppos)
   58.31  {
   58.32  	int rc;
   58.33  	unsigned int c, p, bytes1 = 0, bytes2 = 0;
   58.34 -	DECLARE_WAITQUEUE(wait, current);
   58.35  	struct per_user_data *u = file->private_data;
   58.36  
   58.37 -	add_wait_queue(&u->evtchn_wait, &wait);
   58.38 -
   58.39 -	count &= ~1; /* even number of bytes */
   58.40 +	/* Whole number of ports. */
   58.41 +	count &= ~(sizeof(evtchn_port_t)-1);
   58.42  
   58.43 -	if (count == 0) {
   58.44 -		rc = 0;
   58.45 -		goto out;
   58.46 -	}
   58.47 +	if (count == 0)
   58.48 +		return 0;
   58.49  
   58.50  	if (count > PAGE_SIZE)
   58.51  		count = PAGE_SIZE;
   58.52  
   58.53  	for (;;) {
   58.54 -		set_current_state(TASK_INTERRUPTIBLE);
   58.55 +		if (u->ring_overflow)
   58.56 +			return -EFBIG;
   58.57  
   58.58  		if ((c = u->ring_cons) != (p = u->ring_prod))
   58.59  			break;
   58.60  
   58.61 -		if (u->ring_overflow) {
   58.62 -			rc = -EFBIG;
   58.63 -			goto out;
   58.64 -		}
   58.65 +		if (file->f_flags & O_NONBLOCK)
   58.66 +			return -EAGAIN;
   58.67  
   58.68 -		if (file->f_flags & O_NONBLOCK) {
   58.69 -			rc = -EAGAIN;
   58.70 -			goto out;
   58.71 -		}
   58.72 -
   58.73 -		if (signal_pending(current)) {
   58.74 -			rc = -ERESTARTSYS;
   58.75 -			goto out;
   58.76 -		}
   58.77 -
   58.78 -		schedule();
   58.79 +		rc = wait_event_interruptible(
   58.80 +			u->evtchn_wait, u->ring_cons != u->ring_prod);
   58.81 +		if (rc)
   58.82 +			return rc;
   58.83  	}
   58.84  
   58.85  	/* Byte lengths of two chunks. Chunk split (if any) is at ring wrap. */
   58.86  	if (((c ^ p) & EVTCHN_RING_SIZE) != 0) {
   58.87  		bytes1 = (EVTCHN_RING_SIZE - EVTCHN_RING_MASK(c)) *
   58.88 -			sizeof(u16);
   58.89 -		bytes2 = EVTCHN_RING_MASK(p) * sizeof(u16);
   58.90 +			sizeof(evtchn_port_t);
   58.91 +		bytes2 = EVTCHN_RING_MASK(p) * sizeof(evtchn_port_t);
   58.92  	} else {
   58.93 -		bytes1 = (p - c) * sizeof(u16);
   58.94 +		bytes1 = (p - c) * sizeof(evtchn_port_t);
   58.95  		bytes2 = 0;
   58.96  	}
   58.97  
   58.98 @@ -153,32 +141,26 @@ static ssize_t evtchn_read(struct file *
   58.99  
  58.100  	if (copy_to_user(buf, &u->ring[EVTCHN_RING_MASK(c)], bytes1) ||
  58.101  	    ((bytes2 != 0) &&
  58.102 -	     copy_to_user(&buf[bytes1], &u->ring[0], bytes2))) {
  58.103 -		rc = -EFAULT;
  58.104 -		goto out;
  58.105 -	}
  58.106 -
  58.107 -	u->ring_cons += (bytes1 + bytes2) / sizeof(u16);
  58.108 +	     copy_to_user(&buf[bytes1], &u->ring[0], bytes2)))
  58.109 +		return -EFAULT;
  58.110  
  58.111 -	rc = bytes1 + bytes2;
  58.112 +	u->ring_cons += (bytes1 + bytes2) / sizeof(evtchn_port_t);
  58.113  
  58.114 - out:
  58.115 -	__set_current_state(TASK_RUNNING);
  58.116 -	remove_wait_queue(&u->evtchn_wait, &wait);
  58.117 -	return rc;
  58.118 +	return bytes1 + bytes2;
  58.119  }
  58.120  
  58.121 -static ssize_t evtchn_write(struct file *file, const char *buf,
  58.122 +static ssize_t evtchn_write(struct file *file, const char __user *buf,
  58.123                              size_t count, loff_t *ppos)
  58.124  {
  58.125  	int  rc, i;
  58.126 -	u16 *kbuf = (u16 *)__get_free_page(GFP_KERNEL);
  58.127 +	evtchn_port_t *kbuf = (evtchn_port_t *)__get_free_page(GFP_KERNEL);
  58.128  	struct per_user_data *u = file->private_data;
  58.129  
  58.130  	if (kbuf == NULL)
  58.131  		return -ENOMEM;
  58.132  
  58.133 -	count &= ~1; /* even number of bytes */
  58.134 +	/* Whole number of ports. */
  58.135 +	count &= ~(sizeof(evtchn_port_t)-1);
  58.136  
  58.137  	if (count == 0) {
  58.138  		rc = 0;
  58.139 @@ -194,7 +176,7 @@ static ssize_t evtchn_write(struct file 
  58.140  	}
  58.141  
  58.142  	spin_lock_irq(&port_user_lock);
  58.143 -	for (i = 0; i < (count/2); i++)
  58.144 +	for (i = 0; i < (count/sizeof(evtchn_port_t)); i++)
  58.145  		if ((kbuf[i] < NR_EVENT_CHANNELS) && (port_user[kbuf[i]] == u))
  58.146  			unmask_evtchn(kbuf[i]);
  58.147  	spin_unlock_irq(&port_user_lock);
  58.148 @@ -220,6 +202,7 @@ static int evtchn_ioctl(struct inode *in
  58.149  {
  58.150  	int rc;
  58.151  	struct per_user_data *u = file->private_data;
  58.152 +	void __user *uarg = (void __user *) arg;
  58.153  	evtchn_op_t op = { 0 };
  58.154  
  58.155  	switch (cmd) {
  58.156 @@ -227,7 +210,7 @@ static int evtchn_ioctl(struct inode *in
  58.157  		struct ioctl_evtchn_bind_virq bind;
  58.158  
  58.159  		rc = -EFAULT;
  58.160 -		if (copy_from_user(&bind, (void *)arg, sizeof(bind)))
  58.161 +		if (copy_from_user(&bind, uarg, sizeof(bind)))
  58.162  			break;
  58.163  
  58.164  		op.cmd = EVTCHNOP_bind_virq;
  58.165 @@ -246,7 +229,7 @@ static int evtchn_ioctl(struct inode *in
  58.166  		struct ioctl_evtchn_bind_interdomain bind;
  58.167  
  58.168  		rc = -EFAULT;
  58.169 -		if (copy_from_user(&bind, (void *)arg, sizeof(bind)))
  58.170 +		if (copy_from_user(&bind, uarg, sizeof(bind)))
  58.171  			break;
  58.172  
  58.173  		op.cmd = EVTCHNOP_bind_interdomain;
  58.174 @@ -265,7 +248,7 @@ static int evtchn_ioctl(struct inode *in
  58.175  		struct ioctl_evtchn_bind_unbound_port bind;
  58.176  
  58.177  		rc = -EFAULT;
  58.178 -		if (copy_from_user(&bind, (void *)arg, sizeof(bind)))
  58.179 +		if (copy_from_user(&bind, uarg, sizeof(bind)))
  58.180  			break;
  58.181  
  58.182  		op.cmd = EVTCHNOP_alloc_unbound;
  58.183 @@ -285,7 +268,7 @@ static int evtchn_ioctl(struct inode *in
  58.184  		int ret;
  58.185  
  58.186  		rc = -EFAULT;
  58.187 -		if (copy_from_user(&unbind, (void *)arg, sizeof(unbind)))
  58.188 +		if (copy_from_user(&unbind, uarg, sizeof(unbind)))
  58.189  			break;
  58.190  
  58.191  		rc = -EINVAL;
  58.192 @@ -318,7 +301,7 @@ static int evtchn_ioctl(struct inode *in
  58.193  		struct ioctl_evtchn_notify notify;
  58.194  
  58.195  		rc = -EFAULT;
  58.196 -		if (copy_from_user(&notify, (void *)arg, sizeof(notify)))
  58.197 +		if (copy_from_user(&notify, uarg, sizeof(notify)))
  58.198  			break;
  58.199  
  58.200  		if (notify.port >= NR_EVENT_CHANNELS) {
  58.201 @@ -378,8 +361,8 @@ static int evtchn_open(struct inode *ino
  58.202  	memset(u, 0, sizeof(*u));
  58.203  	init_waitqueue_head(&u->evtchn_wait);
  58.204  
  58.205 -	if ((u->ring = (u16 *)__get_free_page(GFP_KERNEL)) == NULL)
  58.206 -	{
  58.207 +	u->ring = (evtchn_port_t *)__get_free_page(GFP_KERNEL);
  58.208 +	if (u->ring == NULL) {
  58.209  		kfree(u);
  58.210  		return -ENOMEM;
  58.211  	}
  58.212 @@ -399,8 +382,7 @@ static int evtchn_release(struct inode *
  58.213  
  58.214  	free_page((unsigned long)u->ring);
  58.215  
  58.216 -	for (i = 0; i < NR_EVENT_CHANNELS; i++)
  58.217 -	{
  58.218 +	for (i = 0; i < NR_EVENT_CHANNELS; i++) {
  58.219  		int ret;
  58.220  		if (port_user[i] != u)
  58.221  			continue;
  58.222 @@ -446,10 +428,9 @@ static int __init evtchn_init(void)
  58.223  	spin_lock_init(&port_user_lock);
  58.224  	memset(port_user, 0, sizeof(port_user));
  58.225  
  58.226 -	/* (DEVFS) create '/dev/misc/evtchn'. */
  58.227 +	/* Create '/dev/misc/evtchn'. */
  58.228  	err = misc_register(&evtchn_miscdev);
  58.229 -	if (err != 0)
  58.230 -	{
  58.231 +	if (err != 0) {
  58.232  		printk(KERN_ALERT "Could not register /dev/misc/evtchn\n");
  58.233  		return err;
  58.234  	}
    59.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Fri Dec 02 12:12:11 2005 -0600
    59.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Fri Dec 02 12:52:25 2005 -0600
    59.3 @@ -45,24 +45,20 @@ typedef struct netif_st {
    59.4  	u8               fe_dev_addr[6];
    59.5  
    59.6  	/* Physical parameters of the comms window. */
    59.7 -	u16              tx_shmem_handle;
    59.8 +	grant_handle_t   tx_shmem_handle;
    59.9  	grant_ref_t      tx_shmem_ref; 
   59.10 -	u16              rx_shmem_handle;
   59.11 +	grant_handle_t   rx_shmem_handle;
   59.12  	grant_ref_t      rx_shmem_ref; 
   59.13  	unsigned int     evtchn;
   59.14  	unsigned int     irq;
   59.15  
   59.16  	/* The shared rings and indexes. */
   59.17 -	netif_tx_interface_t *tx;
   59.18 -	netif_rx_interface_t *rx;
   59.19 +	netif_tx_back_ring_t tx;
   59.20 +	netif_rx_back_ring_t rx;
   59.21  	struct vm_struct *comms_area;
   59.22  
   59.23 -	/* Private indexes into shared ring. */
   59.24 -	NETIF_RING_IDX rx_req_cons;
   59.25 -	NETIF_RING_IDX rx_resp_prod; /* private version of shared variable */
   59.26 -	NETIF_RING_IDX rx_resp_prod_copy;
   59.27 -	NETIF_RING_IDX tx_req_cons;
   59.28 -	NETIF_RING_IDX tx_resp_prod; /* private version of shared variable */
   59.29 +	/* Allow netif_be_start_xmit() to peek ahead in the rx request ring. */
   59.30 +	RING_IDX rx_req_cons_peek;
   59.31  
   59.32  	/* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
   59.33  	unsigned long   credit_bytes;
   59.34 @@ -81,6 +77,9 @@ typedef struct netif_st {
   59.35  	struct work_struct free_work;
   59.36  } netif_t;
   59.37  
   59.38 +#define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)
   59.39 +#define NET_RX_RING_SIZE __RING_SIZE((netif_rx_sring_t *)0, PAGE_SIZE)
   59.40 +
   59.41  void netif_creditlimit(netif_t *netif);
   59.42  int  netif_disconnect(netif_t *netif);
   59.43  
    60.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Fri Dec 02 12:12:11 2005 -0600
    60.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Fri Dec 02 12:52:25 2005 -0600
    60.3 @@ -127,9 +127,9 @@ static int map_frontend_pages(
    60.4  	unlock_vm_area(netif->comms_area);
    60.5  	BUG_ON(ret);
    60.6  
    60.7 -	if (op.handle < 0) { 
    60.8 +	if (op.status) { 
    60.9  		DPRINTK(" Gnttab failure mapping tx_ring_ref!\n");
   60.10 -		return op.handle;
   60.11 +		return op.status;
   60.12  	}
   60.13  
   60.14  	netif->tx_shmem_ref    = tx_ring_ref;
   60.15 @@ -145,9 +145,9 @@ static int map_frontend_pages(
   60.16  	unlock_vm_area(netif->comms_area);
   60.17  	BUG_ON(ret);
   60.18  
   60.19 -	if (op.handle < 0) { 
   60.20 +	if (op.status) {
   60.21  		DPRINTK(" Gnttab failure mapping rx_ring_ref!\n");
   60.22 -		return op.handle;
   60.23 +		return op.status;
   60.24  	}
   60.25  
   60.26  	netif->rx_shmem_ref    = rx_ring_ref;
   60.27 @@ -184,6 +184,8 @@ int netif_map(netif_t *netif, unsigned l
   60.28  	      unsigned long rx_ring_ref, unsigned int evtchn)
   60.29  {
   60.30  	int err;
   60.31 +	netif_tx_sring_t *txs;
   60.32 +	netif_rx_sring_t *rxs;
   60.33  	evtchn_op_t op = {
   60.34  		.cmd = EVTCHNOP_bind_interdomain,
   60.35  		.u.bind_interdomain.remote_dom = netif->domid,
   60.36 @@ -216,10 +218,15 @@ int netif_map(netif_t *netif, unsigned l
   60.37  		netif->evtchn, netif_be_int, 0, netif->dev->name, netif);
   60.38  	disable_irq(netif->irq);
   60.39  
   60.40 -	netif->tx = (netif_tx_interface_t *)netif->comms_area->addr;
   60.41 -	netif->rx = (netif_rx_interface_t *)
   60.42 +	txs = (netif_tx_sring_t *)netif->comms_area->addr;
   60.43 +	BACK_RING_INIT(&netif->tx, txs, PAGE_SIZE);
   60.44 +
   60.45 +	rxs = (netif_rx_sring_t *)
   60.46  		((char *)netif->comms_area->addr + PAGE_SIZE);
   60.47 -	netif->tx->resp_prod = netif->rx->resp_prod = 0;
   60.48 +	BACK_RING_INIT(&netif->rx, rxs, PAGE_SIZE);
   60.49 +
   60.50 +	netif->rx_req_cons_peek = 0;
   60.51 +
   60.52  	netif_get(netif);
   60.53  	wmb(); /* Other CPUs see new state before interface is started. */
   60.54  
   60.55 @@ -246,7 +253,7 @@ static void free_netif_callback(void *ar
   60.56  
   60.57  	unregister_netdev(netif->dev);
   60.58  
   60.59 -	if (netif->tx) {
   60.60 +	if (netif->tx.sring) {
   60.61  		unmap_frontend_pages(netif);
   60.62  		free_vm_area(netif->comms_area);
   60.63  	}
    61.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Fri Dec 02 12:12:11 2005 -0600
    61.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Fri Dec 02 12:52:25 2005 -0600
    61.3 @@ -25,7 +25,7 @@ static int  make_rx_response(netif_t *ne
    61.4                               s8       st,
    61.5                               u16      offset,
    61.6                               u16      size,
    61.7 -                             u16      csum_valid);
    61.8 +                             u16      flags);
    61.9  
   61.10  static void net_tx_action(unsigned long unused);
   61.11  static DECLARE_TASKLET(net_tx_tasklet, net_tx_action, 0);
   61.12 @@ -38,15 +38,12 @@ static struct timer_list net_timer;
   61.13  #define MAX_PENDING_REQS 256
   61.14  
   61.15  static struct sk_buff_head rx_queue;
   61.16 -static multicall_entry_t rx_mcl[NETIF_RX_RING_SIZE*2+1];
   61.17 -static mmu_update_t rx_mmu[NETIF_RX_RING_SIZE];
   61.18 +static multicall_entry_t rx_mcl[NET_RX_RING_SIZE*2+1];
   61.19 +static mmu_update_t rx_mmu[NET_RX_RING_SIZE];
   61.20  
   61.21  static gnttab_transfer_t grant_rx_op[MAX_PENDING_REQS];
   61.22  static unsigned char rx_notify[NR_IRQS];
   61.23  
   61.24 -/* Don't currently gate addition of an interface to the tx scheduling list. */
   61.25 -#define tx_work_exists(_if) (1)
   61.26 -
   61.27  static unsigned long mmap_vstart;
   61.28  #define MMAP_VADDR(_req) (mmap_vstart + ((_req) * PAGE_SIZE))
   61.29  
   61.30 @@ -68,7 +65,7 @@ static PEND_RING_IDX dealloc_prod, deall
   61.31  
   61.32  static struct sk_buff_head tx_queue;
   61.33  
   61.34 -static u16 grant_tx_ref[MAX_PENDING_REQS];
   61.35 +static grant_handle_t grant_tx_handle[MAX_PENDING_REQS];
   61.36  static gnttab_unmap_grant_ref_t tx_unmap_ops[MAX_PENDING_REQS];
   61.37  static gnttab_map_grant_ref_t tx_map_ops[MAX_PENDING_REQS];
   61.38  
   61.39 @@ -99,29 +96,6 @@ static unsigned long alloc_mfn(void)
   61.40  	return mfn;
   61.41  }
   61.42  
   61.43 -#if 0
   61.44 -static void free_mfn(unsigned long mfn)
   61.45 -{
   61.46 -	unsigned long flags;
   61.47 -	struct xen_memory_reservation reservation = {
   61.48 -		.extent_start = &mfn,
   61.49 -		.nr_extents   = 1,
   61.50 -		.extent_order = 0,
   61.51 -		.domid        = DOMID_SELF
   61.52 -	};
   61.53 -	spin_lock_irqsave(&mfn_lock, flags);
   61.54 -	if ( alloc_index != MAX_MFN_ALLOC )
   61.55 -		mfn_list[alloc_index++] = mfn;
   61.56 -	else {
   61.57 -		int ret;
   61.58 -		ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
   61.59 -					    &reservation);
   61.60 -		BUG_ON(ret != 1);
   61.61 -	}
   61.62 -	spin_unlock_irqrestore(&mfn_lock, flags);
   61.63 -}
   61.64 -#endif
   61.65 -
   61.66  static inline void maybe_schedule_tx_action(void)
   61.67  {
   61.68  	smp_mb();
   61.69 @@ -149,8 +123,9 @@ int netif_be_start_xmit(struct sk_buff *
   61.70  
   61.71  	/* Drop the packet if the target domain has no receive buffers. */
   61.72  	if (!netif->active || 
   61.73 -	    (netif->rx_req_cons == netif->rx->req_prod) ||
   61.74 -	    ((netif->rx_req_cons-netif->rx_resp_prod) == NETIF_RX_RING_SIZE))
   61.75 +	    (netif->rx_req_cons_peek == netif->rx.sring->req_prod) ||
   61.76 +	    ((netif->rx_req_cons_peek - netif->rx.rsp_prod_pvt) ==
   61.77 +	     NET_RX_RING_SIZE))
   61.78  		goto drop;
   61.79  
   61.80  	/*
   61.81 @@ -177,7 +152,7 @@ int netif_be_start_xmit(struct sk_buff *
   61.82  		skb = nskb;
   61.83  	}
   61.84  
   61.85 -	netif->rx_req_cons++;
   61.86 +	netif->rx_req_cons_peek++;
   61.87  	netif_get(netif);
   61.88  
   61.89  	skb_queue_tail(&rx_queue, skb);
   61.90 @@ -221,7 +196,7 @@ static void net_rx_action(unsigned long 
   61.91  	unsigned long vdata, old_mfn, new_mfn;
   61.92  	struct sk_buff_head rxq;
   61.93  	struct sk_buff *skb;
   61.94 -	u16 notify_list[NETIF_RX_RING_SIZE];
   61.95 +	u16 notify_list[NET_RX_RING_SIZE];
   61.96  	int notify_nr = 0;
   61.97  	int ret;
   61.98  
   61.99 @@ -256,9 +231,9 @@ static void net_rx_action(unsigned long 
  61.100  
  61.101  		gop->mfn = old_mfn;
  61.102  		gop->domid = netif->domid;
  61.103 -		gop->ref = netif->rx->ring[
  61.104 -			MASK_NETIF_RX_IDX(netif->rx_resp_prod_copy)].req.gref;
  61.105 -		netif->rx_resp_prod_copy++;
  61.106 +		gop->ref = RING_GET_REQUEST(
  61.107 +			&netif->rx, netif->rx.req_cons)->gref;
  61.108 +		netif->rx.req_cons++;
  61.109  		gop++;
  61.110  
  61.111  		mmu->ptr = ((maddr_t)new_mfn << PAGE_SHIFT) |
  61.112 @@ -287,28 +262,19 @@ static void net_rx_action(unsigned long 
  61.113  	ret = HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl);
  61.114  	BUG_ON(ret != 0);
  61.115  
  61.116 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_transfer, grant_rx_op, 
  61.117 +					gop - grant_rx_op);
  61.118 +	BUG_ON(ret != 0);
  61.119 +
  61.120  	mcl = rx_mcl;
  61.121 -	if( HYPERVISOR_grant_table_op(GNTTABOP_transfer, grant_rx_op, 
  61.122 -				      gop - grant_rx_op)) { 
  61.123 -		/*
  61.124 -		 * The other side has given us a bad grant ref, or has no 
  61.125 -		 * headroom, or has gone away. Unfortunately the current grant
  61.126 -		 * table code doesn't inform us which is the case, so not much
  61.127 -		 * we can do. 
  61.128 -		 */
  61.129 -		DPRINTK("net_rx: transfer to DOM%u failed; dropping (up to) "
  61.130 -			"%d packets.\n",
  61.131 -			grant_rx_op[0].domid, gop - grant_rx_op); 
  61.132 -	}
  61.133  	gop = grant_rx_op;
  61.134 -
  61.135  	while ((skb = __skb_dequeue(&rxq)) != NULL) {
  61.136  		netif   = netdev_priv(skb->dev);
  61.137  		size    = skb->tail - skb->data;
  61.138  
  61.139  		/* Rederive the machine addresses. */
  61.140 -		new_mfn = mcl[0].args[1] >> PAGE_SHIFT;
  61.141 -		old_mfn = 0; /* XXX Fix this so we can free_mfn() on error! */
  61.142 +		new_mfn = mcl->args[1] >> PAGE_SHIFT;
  61.143 +		old_mfn = gop->mfn;
  61.144  		atomic_set(&(skb_shinfo(skb)->dataref), 1);
  61.145  		skb_shinfo(skb)->nr_frags = 0;
  61.146  		skb_shinfo(skb)->frag_list = NULL;
  61.147 @@ -317,22 +283,26 @@ static void net_rx_action(unsigned long 
  61.148  		netif->stats.tx_packets++;
  61.149  
  61.150  		/* The update_va_mapping() must not fail. */
  61.151 -		BUG_ON(mcl[0].result != 0);
  61.152 +		BUG_ON(mcl->result != 0);
  61.153  
  61.154  		/* Check the reassignment error code. */
  61.155  		status = NETIF_RSP_OKAY;
  61.156 -		if(gop->status != 0) { 
  61.157 +		if (gop->status != 0) { 
  61.158  			DPRINTK("Bad status %d from grant transfer to DOM%u\n",
  61.159  				gop->status, netif->domid);
  61.160 -			/* XXX SMH: should free 'old_mfn' here */
  61.161 +			/*
  61.162 +                         * Page no longer belongs to us unless GNTST_bad_page,
  61.163 +                         * but that should be a fatal error anyway.
  61.164 +                         */
  61.165 +			BUG_ON(gop->status == GNTST_bad_page);
  61.166  			status = NETIF_RSP_ERROR; 
  61.167  		}
  61.168  		irq = netif->irq;
  61.169 -		id = netif->rx->ring[
  61.170 -			MASK_NETIF_RX_IDX(netif->rx_resp_prod)].req.id;
  61.171 +		id = RING_GET_REQUEST(&netif->rx, netif->rx.rsp_prod_pvt)->id;
  61.172  		if (make_rx_response(netif, id, status,
  61.173  				     (unsigned long)skb->data & ~PAGE_MASK,
  61.174 -				     size, skb->proto_csum_valid) &&
  61.175 +				     size, skb->proto_csum_valid ?
  61.176 +				     NETRXF_csum_valid : 0) &&
  61.177  		    (rx_notify[irq] == 0)) {
  61.178  			rx_notify[irq] = 1;
  61.179  			notify_list[notify_nr++] = irq;
  61.180 @@ -399,10 +369,25 @@ static void add_to_net_schedule_list_tai
  61.181  	spin_unlock_irq(&net_schedule_list_lock);
  61.182  }
  61.183  
  61.184 +/*
  61.185 + * Note on CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER:
  61.186 + * If this driver is pipelining transmit requests then we can be very
  61.187 + * aggressive in avoiding new-packet notifications -- frontend only needs to
  61.188 + * send a notification if there are no outstanding unreceived responses.
  61.189 + * If we may be buffer transmit buffers for any reason then we must be rather
  61.190 + * more conservative and treat this as the final check for pending work.
  61.191 + */
  61.192  void netif_schedule_work(netif_t *netif)
  61.193  {
  61.194 -	if ((netif->tx_req_cons != netif->tx->req_prod) &&
  61.195 -	    ((netif->tx_req_cons-netif->tx_resp_prod) != NETIF_TX_RING_SIZE)) {
  61.196 +	int more_to_do;
  61.197 +
  61.198 +#ifdef CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER
  61.199 +	more_to_do = RING_HAS_UNCONSUMED_REQUESTS(&netif->tx);
  61.200 +#else
  61.201 +	RING_FINAL_CHECK_FOR_REQUESTS(&netif->tx, more_to_do);
  61.202 +#endif
  61.203 +
  61.204 +	if (more_to_do) {
  61.205  		add_to_net_schedule_list_tail(netif);
  61.206  		maybe_schedule_tx_action();
  61.207  	}
  61.208 @@ -440,7 +425,7 @@ inline static void net_tx_action_dealloc
  61.209  		pending_idx = dealloc_ring[MASK_PEND_IDX(dc++)];
  61.210  		gop->host_addr    = MMAP_VADDR(pending_idx);
  61.211  		gop->dev_bus_addr = 0;
  61.212 -		gop->handle       = grant_tx_ref[pending_idx];
  61.213 +		gop->handle       = grant_tx_handle[pending_idx];
  61.214  		gop++;
  61.215  	}
  61.216  	ret = HYPERVISOR_grant_table_op(
  61.217 @@ -457,19 +442,6 @@ inline static void net_tx_action_dealloc
  61.218          
  61.219  		pending_ring[MASK_PEND_IDX(pending_prod++)] = pending_idx;
  61.220  
  61.221 -		/*
  61.222 -		 * Scheduling checks must happen after the above response is
  61.223 -		 * posted. This avoids a possible race with a guest OS on
  61.224 -		 * another CPU if that guest is testing against 'resp_prod'
  61.225 -		 * when deciding whether to notify us when it queues additional
  61.226 -                 * packets.
  61.227 -		 */
  61.228 -		mb();
  61.229 -		if ((netif->tx_req_cons != netif->tx->req_prod) &&
  61.230 -		    ((netif->tx_req_cons-netif->tx_resp_prod) !=
  61.231 -		     NETIF_TX_RING_SIZE))
  61.232 -			add_to_net_schedule_list_tail(netif);
  61.233 -        
  61.234  		netif_put(netif);
  61.235  	}
  61.236  }
  61.237 @@ -482,10 +454,10 @@ static void net_tx_action(unsigned long 
  61.238  	netif_t *netif;
  61.239  	netif_tx_request_t txreq;
  61.240  	u16 pending_idx;
  61.241 -	NETIF_RING_IDX i;
  61.242 +	RING_IDX i;
  61.243  	gnttab_map_grant_ref_t *mop;
  61.244  	unsigned int data_len;
  61.245 -	int ret;
  61.246 +	int ret, work_to_do;
  61.247  
  61.248  	if (dealloc_cons != dealloc_prod)
  61.249  		net_tx_action_dealloc();
  61.250 @@ -499,17 +471,15 @@ static void net_tx_action(unsigned long 
  61.251  		netif_get(netif);
  61.252  		remove_from_net_schedule_list(netif);
  61.253  
  61.254 -		/* Work to do? */
  61.255 -		i = netif->tx_req_cons;
  61.256 -		if ((i == netif->tx->req_prod) ||
  61.257 -		    ((i-netif->tx_resp_prod) == NETIF_TX_RING_SIZE)) {
  61.258 +		RING_FINAL_CHECK_FOR_REQUESTS(&netif->tx, work_to_do);
  61.259 +		if (!work_to_do) {
  61.260  			netif_put(netif);
  61.261  			continue;
  61.262  		}
  61.263  
  61.264 +		i = netif->tx.req_cons;
  61.265  		rmb(); /* Ensure that we see the request before we copy it. */
  61.266 -		memcpy(&txreq, &netif->tx->ring[MASK_NETIF_TX_IDX(i)].req, 
  61.267 -		       sizeof(txreq));
  61.268 +		memcpy(&txreq, RING_GET_REQUEST(&netif->tx, i), sizeof(txreq));
  61.269  		/* Credit-based scheduling. */
  61.270  		if (txreq.size > netif->remaining_credit) {
  61.271  			unsigned long now = jiffies;
  61.272 @@ -543,12 +513,7 @@ static void net_tx_action(unsigned long 
  61.273  		}
  61.274  		netif->remaining_credit -= txreq.size;
  61.275  
  61.276 -		/*
  61.277 -		 * Why the barrier? It ensures that the frontend sees updated
  61.278 -		 * req_cons before we check for more work to schedule.
  61.279 -		 */
  61.280 -		netif->tx->req_cons = ++netif->tx_req_cons;
  61.281 -		mb();
  61.282 +		netif->tx.req_cons++;
  61.283  
  61.284  		netif_schedule_work(netif);
  61.285  
  61.286 @@ -620,7 +585,7 @@ static void net_tx_action(unsigned long 
  61.287  		       sizeof(txreq));
  61.288  
  61.289  		/* Check the remap error code. */
  61.290 -		if (unlikely(mop->handle < 0)) {
  61.291 +		if (unlikely(mop->status)) {
  61.292  			printk(KERN_ALERT "#### netback grant fails\n");
  61.293  			make_tx_response(netif, txreq.id, NETIF_RSP_ERROR);
  61.294  			netif_put(netif);
  61.295 @@ -633,7 +598,7 @@ static void net_tx_action(unsigned long 
  61.296  		set_phys_to_machine(
  61.297  			__pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT,
  61.298  			FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT));
  61.299 -		grant_tx_ref[pending_idx] = mop->handle;
  61.300 +		grant_tx_handle[pending_idx] = mop->handle;
  61.301  
  61.302  		data_len = (txreq.size > PKT_PROT_LEN) ?
  61.303  			PKT_PROT_LEN : txreq.size;
  61.304 @@ -668,7 +633,7 @@ static void net_tx_action(unsigned long 
  61.305                   */
  61.306  		skb->ip_summed        = CHECKSUM_UNNECESSARY;
  61.307  		skb->proto_csum_valid = 1;
  61.308 -		skb->proto_csum_blank = txreq.csum_blank;
  61.309 +		skb->proto_csum_blank = !!(txreq.flags & NETTXF_csum_blank);
  61.310  
  61.311  		netif->stats.rx_bytes += txreq.size;
  61.312  		netif->stats.rx_packets++;
  61.313 @@ -705,10 +670,8 @@ static void netif_page_release(struct pa
  61.314  irqreturn_t netif_be_int(int irq, void *dev_id, struct pt_regs *regs)
  61.315  {
  61.316  	netif_t *netif = dev_id;
  61.317 -	if (tx_work_exists(netif)) {
  61.318 -		add_to_net_schedule_list_tail(netif);
  61.319 -		maybe_schedule_tx_action();
  61.320 -	}
  61.321 +	add_to_net_schedule_list_tail(netif);
  61.322 +	maybe_schedule_tx_action();
  61.323  	return IRQ_HANDLED;
  61.324  }
  61.325  
  61.326 @@ -716,18 +679,27 @@ static void make_tx_response(netif_t *ne
  61.327                               u16      id,
  61.328                               s8       st)
  61.329  {
  61.330 -	NETIF_RING_IDX i = netif->tx_resp_prod;
  61.331 +	RING_IDX i = netif->tx.rsp_prod_pvt;
  61.332  	netif_tx_response_t *resp;
  61.333 +	int notify;
  61.334  
  61.335 -	resp = &netif->tx->ring[MASK_NETIF_TX_IDX(i)].resp;
  61.336 +	resp = RING_GET_RESPONSE(&netif->tx, i);
  61.337  	resp->id     = id;
  61.338  	resp->status = st;
  61.339 -	wmb();
  61.340 -	netif->tx->resp_prod = netif->tx_resp_prod = ++i;
  61.341 +
  61.342 +	netif->tx.rsp_prod_pvt = ++i;
  61.343 +	RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netif->tx, notify);
  61.344 +	if (notify)
  61.345 +		notify_remote_via_irq(netif->irq);
  61.346  
  61.347 -	mb(); /* Update producer before checking event threshold. */
  61.348 -	if (i == netif->tx->event)
  61.349 -		notify_remote_via_irq(netif->irq);
  61.350 +#ifdef CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER
  61.351 +	if (i == netif->tx.req_cons) {
  61.352 +		int more_to_do;
  61.353 +		RING_FINAL_CHECK_FOR_REQUESTS(&netif->tx, more_to_do);
  61.354 +		if (more_to_do)
  61.355 +			add_to_net_schedule_list_tail(netif);
  61.356 +	}
  61.357 +#endif
  61.358  }
  61.359  
  61.360  static int make_rx_response(netif_t *netif, 
  61.361 @@ -735,23 +707,24 @@ static int make_rx_response(netif_t *net
  61.362                              s8       st,
  61.363                              u16      offset,
  61.364                              u16      size,
  61.365 -                            u16      csum_valid)
  61.366 +                            u16      flags)
  61.367  {
  61.368 -	NETIF_RING_IDX i = netif->rx_resp_prod;
  61.369 +	RING_IDX i = netif->rx.rsp_prod_pvt;
  61.370  	netif_rx_response_t *resp;
  61.371 +	int notify;
  61.372  
  61.373 -	resp = &netif->rx->ring[MASK_NETIF_RX_IDX(i)].resp;
  61.374 +	resp = RING_GET_RESPONSE(&netif->rx, i);
  61.375  	resp->offset     = offset;
  61.376 -	resp->csum_valid = csum_valid;
  61.377 +	resp->flags      = flags;
  61.378  	resp->id         = id;
  61.379  	resp->status     = (s16)size;
  61.380  	if (st < 0)
  61.381  		resp->status = (s16)st;
  61.382 -	wmb();
  61.383 -	netif->rx->resp_prod = netif->rx_resp_prod = ++i;
  61.384  
  61.385 -	mb(); /* Update producer before checking event threshold. */
  61.386 -	return (i == netif->rx->event);
  61.387 +	netif->rx.rsp_prod_pvt = ++i;
  61.388 +	RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netif->rx, notify);
  61.389 +
  61.390 +	return notify;
  61.391  }
  61.392  
  61.393  static irqreturn_t netif_be_dbg(int irq, void *dev_id, struct pt_regs *regs)
  61.394 @@ -767,16 +740,16 @@ static irqreturn_t netif_be_dbg(int irq,
  61.395  		netif = list_entry(ent, netif_t, list);
  61.396  		printk(KERN_ALERT " %d: private(rx_req_cons=%08x "
  61.397  		       "rx_resp_prod=%08x\n",
  61.398 -		       i, netif->rx_req_cons, netif->rx_resp_prod);
  61.399 +		       i, netif->rx.req_cons, netif->rx.rsp_prod_pvt);
  61.400  		printk(KERN_ALERT "   tx_req_cons=%08x tx_resp_prod=%08x)\n",
  61.401 -		       netif->tx_req_cons, netif->tx_resp_prod);
  61.402 +		       netif->tx.req_cons, netif->tx.rsp_prod_pvt);
  61.403  		printk(KERN_ALERT "   shared(rx_req_prod=%08x "
  61.404  		       "rx_resp_prod=%08x\n",
  61.405 -		       netif->rx->req_prod, netif->rx->resp_prod);
  61.406 +		       netif->rx.sring->req_prod, netif->rx.sring->rsp_prod);
  61.407  		printk(KERN_ALERT "   rx_event=%08x tx_req_prod=%08x\n",
  61.408 -		       netif->rx->event, netif->tx->req_prod);
  61.409 +		       netif->rx.sring->rsp_event, netif->tx.sring->req_prod);
  61.410  		printk(KERN_ALERT "   tx_resp_prod=%08x, tx_event=%08x)\n",
  61.411 -		       netif->tx->resp_prod, netif->tx->event);
  61.412 +		       netif->tx.sring->rsp_prod, netif->tx.sring->rsp_event);
  61.413  		i++;
  61.414  	}
  61.415  
  61.416 @@ -792,7 +765,7 @@ static int __init netback_init(void)
  61.417  	struct page *page;
  61.418  
  61.419  	/* We can increase reservation by this much in net_rx_action(). */
  61.420 -	balloon_update_driver_allowance(NETIF_RX_RING_SIZE);
  61.421 +	balloon_update_driver_allowance(NET_RX_RING_SIZE);
  61.422  
  61.423  	skb_queue_head_init(&rx_queue);
  61.424  	skb_queue_head_init(&tx_queue);
    62.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Fri Dec 02 12:12:11 2005 -0600
    62.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Fri Dec 02 12:52:25 2005 -0600
    62.3 @@ -216,13 +216,14 @@ static void frontend_changed(struct xenb
    62.4  		break;
    62.5  
    62.6  	case XenbusStateClosed:
    62.7 -		device_unregister(&be->dev->dev);
    62.8 +		kobject_hotplug(&dev->dev.kobj, KOBJ_OFFLINE);
    62.9 +		device_unregister(&dev->dev);
   62.10  		break;
   62.11  
   62.12  	case XenbusStateUnknown:
   62.13  	case XenbusStateInitWait:
   62.14  	default:
   62.15 -		xenbus_dev_fatal(be->dev, -EINVAL, "saw state %d at frontend",
   62.16 +		xenbus_dev_fatal(dev, -EINVAL, "saw state %d at frontend",
   62.17  				 frontend_state);
   62.18  		break;
   62.19  	}
    63.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Fri Dec 02 12:12:11 2005 -0600
    63.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Fri Dec 02 12:52:25 2005 -0600
    63.3 @@ -61,6 +61,9 @@
    63.4  
    63.5  #define GRANT_INVALID_REF	0
    63.6  
    63.7 +#define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)
    63.8 +#define NET_RX_RING_SIZE __RING_SIZE((netif_rx_sring_t *)0, PAGE_SIZE)
    63.9 +
   63.10  #ifndef __GFP_NOWARN
   63.11  #define __GFP_NOWARN 0
   63.12  #endif
   63.13 @@ -76,22 +79,9 @@
   63.14  /* Allow headroom on each rx pkt for Ethernet header, alignment padding, ... */
   63.15  #define RX_HEADROOM 200
   63.16  
   63.17 -/*
   63.18 - * If the backend driver is pipelining transmit requests then we can be very
   63.19 - * aggressive in avoiding new-packet notifications -- only need to send a
   63.20 - * notification if there are no outstanding unreceived responses.
   63.21 - * If the backend may be buffering our transmit buffers for any reason then we
   63.22 - * are rather more conservative.
   63.23 - */
   63.24 -#ifdef CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER
   63.25 -#define TX_TEST_IDX resp_prod /* aggressive: any outstanding responses? */
   63.26 -#else
   63.27 -#define TX_TEST_IDX req_cons  /* conservative: not seen all our requests? */
   63.28 -#endif
   63.29 -
   63.30 -static unsigned long rx_pfn_array[NETIF_RX_RING_SIZE];
   63.31 -static multicall_entry_t rx_mcl[NETIF_RX_RING_SIZE+1];
   63.32 -static mmu_update_t rx_mmu[NETIF_RX_RING_SIZE];
   63.33 +static unsigned long rx_pfn_array[NET_RX_RING_SIZE];
   63.34 +static multicall_entry_t rx_mcl[NET_RX_RING_SIZE+1];
   63.35 +static mmu_update_t rx_mmu[NET_RX_RING_SIZE];
   63.36  
   63.37  struct netfront_info
   63.38  {
   63.39 @@ -99,11 +89,10 @@ struct netfront_info
   63.40  	struct net_device *netdev;
   63.41  
   63.42  	struct net_device_stats stats;
   63.43 -	NETIF_RING_IDX rx_resp_cons, tx_resp_cons;
   63.44  	unsigned int tx_full;
   63.45      
   63.46 -	netif_tx_interface_t *tx;
   63.47 -	netif_rx_interface_t *rx;
   63.48 +	netif_tx_front_ring_t tx;
   63.49 +	netif_rx_front_ring_t rx;
   63.50  
   63.51  	spinlock_t   tx_lock;
   63.52  	spinlock_t   rx_lock;
   63.53 @@ -124,7 +113,7 @@ struct netfront_info
   63.54  
   63.55  	/* Receive-ring batched refills. */
   63.56  #define RX_MIN_TARGET 8
   63.57 -#define RX_MAX_TARGET NETIF_RX_RING_SIZE
   63.58 +#define RX_MAX_TARGET NET_RX_RING_SIZE
   63.59  	int rx_min_target, rx_max_target, rx_target;
   63.60  	struct sk_buff_head rx_batch;
   63.61  
   63.62 @@ -132,13 +121,13 @@ struct netfront_info
   63.63  	 * {tx,rx}_skbs store outstanding skbuffs. The first entry in each
   63.64  	 * array is an index into a chain of free entries.
   63.65  	 */
   63.66 -	struct sk_buff *tx_skbs[NETIF_TX_RING_SIZE+1];
   63.67 -	struct sk_buff *rx_skbs[NETIF_RX_RING_SIZE+1];
   63.68 +	struct sk_buff *tx_skbs[NET_TX_RING_SIZE+1];
   63.69 +	struct sk_buff *rx_skbs[NET_RX_RING_SIZE+1];
   63.70  
   63.71  	grant_ref_t gref_tx_head;
   63.72 -	grant_ref_t grant_tx_ref[NETIF_TX_RING_SIZE + 1]; 
   63.73 +	grant_ref_t grant_tx_ref[NET_TX_RING_SIZE + 1]; 
   63.74  	grant_ref_t gref_rx_head;
   63.75 -	grant_ref_t grant_rx_ref[NETIF_TX_RING_SIZE + 1]; 
   63.76 +	grant_ref_t grant_rx_ref[NET_TX_RING_SIZE + 1]; 
   63.77  
   63.78  	struct xenbus_device *xbdev;
   63.79  	int tx_ring_ref;
   63.80 @@ -337,37 +326,45 @@ again:
   63.81  
   63.82  static int setup_device(struct xenbus_device *dev, struct netfront_info *info)
   63.83  {
   63.84 +	netif_tx_sring_t *txs;
   63.85 +	netif_rx_sring_t *rxs;
   63.86  	int err;
   63.87  	struct net_device *netdev = info->netdev;
   63.88  
   63.89  	info->tx_ring_ref = GRANT_INVALID_REF;
   63.90  	info->rx_ring_ref = GRANT_INVALID_REF;
   63.91 -	info->rx = NULL;
   63.92 -	info->tx = NULL;
   63.93 +	info->rx.sring = NULL;
   63.94 +	info->tx.sring = NULL;
   63.95  	info->irq = 0;
   63.96  
   63.97 -	info->tx = (netif_tx_interface_t *)__get_free_page(GFP_KERNEL);
   63.98 -	if (!info->tx) {
   63.99 +	txs = (netif_tx_sring_t *)__get_free_page(GFP_KERNEL);
  63.100 +	if (!txs) {
  63.101  		err = -ENOMEM;
  63.102  		xenbus_dev_fatal(dev, err, "allocating tx ring page");
  63.103  		goto fail;
  63.104  	}
  63.105 -	info->rx = (netif_rx_interface_t *)__get_free_page(GFP_KERNEL);
  63.106 -	if (!info->rx) {
  63.107 +	rxs = (netif_rx_sring_t *)__get_free_page(GFP_KERNEL);
  63.108 +	if (!rxs) {
  63.109  		err = -ENOMEM;
  63.110  		xenbus_dev_fatal(dev, err, "allocating rx ring page");
  63.111  		goto fail;
  63.112  	}
  63.113 -	memset(info->tx, 0, PAGE_SIZE);
  63.114 -	memset(info->rx, 0, PAGE_SIZE);
  63.115 +	memset(txs, 0, PAGE_SIZE);
  63.116 +	memset(rxs, 0, PAGE_SIZE);
  63.117  	info->backend_state = BEST_DISCONNECTED;
  63.118  
  63.119 -	err = xenbus_grant_ring(dev, virt_to_mfn(info->tx));
  63.120 +	SHARED_RING_INIT(txs);
  63.121 +	FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
  63.122 +
  63.123 +	SHARED_RING_INIT(rxs);
  63.124 +	FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE);
  63.125 +
  63.126 +	err = xenbus_grant_ring(dev, virt_to_mfn(txs));
  63.127  	if (err < 0)
  63.128  		goto fail;
  63.129  	info->tx_ring_ref = err;
  63.130  
  63.131 -	err = xenbus_grant_ring(dev, virt_to_mfn(info->rx));
  63.132 +	err = xenbus_grant_ring(dev, virt_to_mfn(rxs));
  63.133  	if (err < 0)
  63.134  		goto fail;
  63.135  	info->rx_ring_ref = err;
  63.136 @@ -454,7 +451,7 @@ static int network_open(struct net_devic
  63.137  	np->user_state = UST_OPEN;
  63.138  
  63.139  	network_alloc_rx_buffers(dev);
  63.140 -	np->rx->event = np->rx_resp_cons + 1;
  63.141 +	np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
  63.142  
  63.143  	netif_start_queue(dev);
  63.144  
  63.145 @@ -463,7 +460,7 @@ static int network_open(struct net_devic
  63.146  
  63.147  static void network_tx_buf_gc(struct net_device *dev)
  63.148  {
  63.149 -	NETIF_RING_IDX i, prod;
  63.150 +	RING_IDX i, prod;
  63.151  	unsigned short id;
  63.152  	struct netfront_info *np = netdev_priv(dev);
  63.153  	struct sk_buff *skb;
  63.154 @@ -472,11 +469,11 @@ static void network_tx_buf_gc(struct net
  63.155  		return;
  63.156  
  63.157  	do {
  63.158 -		prod = np->tx->resp_prod;
  63.159 +		prod = np->tx.sring->rsp_prod;
  63.160  		rmb(); /* Ensure we see responses up to 'rp'. */
  63.161  
  63.162 -		for (i = np->tx_resp_cons; i != prod; i++) {
  63.163 -			id  = np->tx->ring[MASK_NETIF_TX_IDX(i)].resp.id;
  63.164 +		for (i = np->tx.rsp_cons; i != prod; i++) {
  63.165 +			id  = RING_GET_RESPONSE(&np->tx, i)->id;
  63.166  			skb = np->tx_skbs[id];
  63.167  			if (unlikely(gnttab_query_foreign_access(
  63.168  				np->grant_tx_ref[id]) != 0)) {
  63.169 @@ -494,7 +491,7 @@ static void network_tx_buf_gc(struct net
  63.170  			dev_kfree_skb_irq(skb);
  63.171  		}
  63.172          
  63.173 -		np->tx_resp_cons = prod;
  63.174 +		np->tx.rsp_cons = prod;
  63.175          
  63.176  		/*
  63.177  		 * Set a new event, then check for race with update of tx_cons.
  63.178 @@ -504,12 +501,14 @@ static void network_tx_buf_gc(struct net
  63.179  		 * data is outstanding: in such cases notification from Xen is
  63.180  		 * likely to be the only kick that we'll get.
  63.181  		 */
  63.182 -		np->tx->event = prod + ((np->tx->req_prod - prod) >> 1) + 1;
  63.183 +		np->tx.sring->rsp_event =
  63.184 +			prod + ((np->tx.sring->req_prod - prod) >> 1) + 1;
  63.185  		mb();
  63.186 -	} while (prod != np->tx->resp_prod);
  63.187 +	} while (prod != np->tx.sring->rsp_prod);
  63.188  
  63.189   out: 
  63.190 -	if (np->tx_full && ((np->tx->req_prod - prod) < NETIF_TX_RING_SIZE)) {
  63.191 +	if (np->tx_full &&
  63.192 +	    ((np->tx.sring->req_prod - prod) < NET_TX_RING_SIZE)) {
  63.193  		np->tx_full = 0;
  63.194  		if (np->user_state == UST_OPEN)
  63.195  			netif_wake_queue(dev);
  63.196 @@ -523,7 +522,7 @@ static void network_alloc_rx_buffers(str
  63.197  	struct netfront_info *np = netdev_priv(dev);
  63.198  	struct sk_buff *skb;
  63.199  	int i, batch_target;
  63.200 -	NETIF_RING_IDX req_prod = np->rx->req_prod;
  63.201 +	RING_IDX req_prod = np->rx.req_prod_pvt;
  63.202  	struct xen_memory_reservation reservation;
  63.203  	grant_ref_t ref;
  63.204  
  63.205 @@ -536,7 +535,7 @@ static void network_alloc_rx_buffers(str
  63.206  	 * allocator, so should reduce the chance of failed allocation requests
  63.207  	 *  both for ourself and for other kernel subsystems.
  63.208  	 */
  63.209 -	batch_target = np->rx_target - (req_prod - np->rx_resp_cons);
  63.210 +	batch_target = np->rx_target - (req_prod - np->rx.rsp_cons);
  63.211  	for (i = skb_queue_len(&np->rx_batch); i < batch_target; i++) {
  63.212  		skb = alloc_xen_skb(dev->mtu + RX_HEADROOM);
  63.213  		if (skb == NULL)
  63.214 @@ -558,13 +557,13 @@ static void network_alloc_rx_buffers(str
  63.215  
  63.216  		np->rx_skbs[id] = skb;
  63.217          
  63.218 -		np->rx->ring[MASK_NETIF_RX_IDX(req_prod + i)].req.id = id;
  63.219 +		RING_GET_REQUEST(&np->rx, req_prod + i)->id = id;
  63.220  		ref = gnttab_claim_grant_reference(&np->gref_rx_head);
  63.221  		BUG_ON((signed short)ref < 0);
  63.222  		np->grant_rx_ref[id] = ref;
  63.223  		gnttab_grant_foreign_transfer_ref(ref,
  63.224  						  np->xbdev->otherend_id);
  63.225 -		np->rx->ring[MASK_NETIF_RX_IDX(req_prod + i)].req.gref = ref;
  63.226 +		RING_GET_REQUEST(&np->rx, req_prod + i)->gref = ref;
  63.227  		rx_pfn_array[i] = virt_to_mfn(skb->head);
  63.228  
  63.229  		/* Remove this page from map before passing back to Xen. */
  63.230 @@ -599,10 +598,11 @@ static void network_alloc_rx_buffers(str
  63.231  		panic("Unable to reduce memory reservation\n");
  63.232  
  63.233  	/* Above is a suitable barrier to ensure backend will see requests. */
  63.234 -	np->rx->req_prod = req_prod + i;
  63.235 +	np->rx.req_prod_pvt = req_prod + i;
  63.236 +	RING_PUSH_REQUESTS(&np->rx);
  63.237  
  63.238  	/* Adjust our fill target if we risked running out of buffers. */
  63.239 -	if (((req_prod - np->rx->resp_prod) < (np->rx_target / 4)) &&
  63.240 +	if (((req_prod - np->rx.sring->rsp_prod) < (np->rx_target / 4)) &&
  63.241  	    ((np->rx_target *= 2) > np->rx_max_target))
  63.242  		np->rx_target = np->rx_max_target;
  63.243  }
  63.244 @@ -613,9 +613,10 @@ static int network_start_xmit(struct sk_
  63.245  	unsigned short id;
  63.246  	struct netfront_info *np = netdev_priv(dev);
  63.247  	netif_tx_request_t *tx;
  63.248 -	NETIF_RING_IDX i;
  63.249 +	RING_IDX i;
  63.250  	grant_ref_t ref;
  63.251  	unsigned long mfn;
  63.252 +	int notify;
  63.253  
  63.254  	if (unlikely(np->tx_full)) {
  63.255  		printk(KERN_ALERT "%s: full queue wasn't stopped!\n",
  63.256 @@ -643,12 +644,12 @@ static int network_start_xmit(struct sk_
  63.257  		goto drop;
  63.258  	}
  63.259  
  63.260 -	i = np->tx->req_prod;
  63.261 +	i = np->tx.req_prod_pvt;
  63.262  
  63.263  	id = GET_ID_FROM_FREELIST(np->tx_skbs);
  63.264  	np->tx_skbs[id] = skb;
  63.265  
  63.266 -	tx = &np->tx->ring[MASK_NETIF_TX_IDX(i)].req;
  63.267 +	tx = RING_GET_REQUEST(&np->tx, i);
  63.268  
  63.269  	tx->id   = id;
  63.270  	ref = gnttab_claim_grant_reference(&np->gref_tx_head);
  63.271 @@ -659,14 +660,16 @@ static int network_start_xmit(struct sk_
  63.272  	tx->gref = np->grant_tx_ref[id] = ref;
  63.273  	tx->offset = (unsigned long)skb->data & ~PAGE_MASK;
  63.274  	tx->size = skb->len;
  63.275 -	tx->csum_blank = (skb->ip_summed == CHECKSUM_HW);
  63.276 +	tx->flags = (skb->ip_summed == CHECKSUM_HW) ? NETTXF_csum_blank : 0;
  63.277  
  63.278 -	wmb(); /* Ensure that backend will see the request. */
  63.279 -	np->tx->req_prod = i + 1;
  63.280 +	np->tx.req_prod_pvt = i + 1;
  63.281 +	RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->tx, notify);
  63.282 +	if (notify)
  63.283 +		notify_remote_via_irq(np->irq);
  63.284  
  63.285  	network_tx_buf_gc(dev);
  63.286  
  63.287 -	if ((i - np->tx_resp_cons) == (NETIF_TX_RING_SIZE - 1)) {
  63.288 +	if (RING_FULL(&np->tx)) {
  63.289  		np->tx_full = 1;
  63.290  		netif_stop_queue(dev);
  63.291  	}
  63.292 @@ -676,11 +679,6 @@ static int network_start_xmit(struct sk_
  63.293  	np->stats.tx_bytes += skb->len;
  63.294  	np->stats.tx_packets++;
  63.295  
  63.296 -	/* Only notify Xen if we really have to. */
  63.297 -	mb();
  63.298 -	if (np->tx->TX_TEST_IDX == i)
  63.299 -		notify_remote_via_irq(np->irq);
  63.300 -
  63.301  	return 0;
  63.302  
  63.303   drop:
  63.304 @@ -699,7 +697,7 @@ static irqreturn_t netif_int(int irq, vo
  63.305  	network_tx_buf_gc(dev);
  63.306  	spin_unlock_irqrestore(&np->tx_lock, flags);
  63.307  
  63.308 -	if ((np->rx_resp_cons != np->rx->resp_prod) &&
  63.309 +	if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx) &&
  63.310  	    (np->user_state == UST_OPEN))
  63.311  		netif_rx_schedule(dev);
  63.312  
  63.313 @@ -712,7 +710,7 @@ static int netif_poll(struct net_device 
  63.314  	struct netfront_info *np = netdev_priv(dev);
  63.315  	struct sk_buff *skb, *nskb;
  63.316  	netif_rx_response_t *rx;
  63.317 -	NETIF_RING_IDX i, rp;
  63.318 +	RING_IDX i, rp;
  63.319  	mmu_update_t *mmu = rx_mmu;
  63.320  	multicall_entry_t *mcl = rx_mcl;
  63.321  	int work_done, budget, more_to_do = 1;
  63.322 @@ -732,46 +730,42 @@ static int netif_poll(struct net_device 
  63.323  
  63.324  	if ((budget = *pbudget) > dev->quota)
  63.325  		budget = dev->quota;
  63.326 -	rp = np->rx->resp_prod;
  63.327 +	rp = np->rx.sring->rsp_prod;
  63.328  	rmb(); /* Ensure we see queued responses up to 'rp'. */
  63.329  
  63.330 -	for (i = np->rx_resp_cons, work_done = 0; 
  63.331 +	for (i = np->rx.rsp_cons, work_done = 0; 
  63.332  	     (i != rp) && (work_done < budget);
  63.333  	     i++, work_done++) {
  63.334 -		rx = &np->rx->ring[MASK_NETIF_RX_IDX(i)].resp;
  63.335 +		rx = RING_GET_RESPONSE(&np->rx, i);
  63.336 +
  63.337  		/*
  63.338 -		 * An error here is very odd. Usually indicates a backend bug,
  63.339 -		 * low-mem condition, or we didn't have reservation headroom.
  63.340 -		 */
  63.341 -		if (unlikely(rx->status <= 0)) {
  63.342 -			if (net_ratelimit())
  63.343 -				printk(KERN_WARNING "Bad rx buffer "
  63.344 -				       "(memory squeeze?).\n");
  63.345 -			np->rx->ring[MASK_NETIF_RX_IDX(np->rx->req_prod)].
  63.346 -				req.id = rx->id;
  63.347 -			wmb();
  63.348 -			np->rx->req_prod++;
  63.349 +                 * This definitely indicates a bug, either in this driver or
  63.350 +                 * in the backend driver. In future this should flag the bad
  63.351 +                 * situation to the system controller to reboot the backed.
  63.352 +                 */
  63.353 +		if ((ref = np->grant_rx_ref[rx->id]) == GRANT_INVALID_REF) {
  63.354 +			WPRINTK("Bad rx response id %d.\n", rx->id);
  63.355  			work_done--;
  63.356  			continue;
  63.357  		}
  63.358  
  63.359 -		ref = np->grant_rx_ref[rx->id]; 
  63.360 -
  63.361 -		if(ref == GRANT_INVALID_REF) { 
  63.362 -			printk(KERN_WARNING "Bad rx grant reference %d "
  63.363 -			       "from dom %d.\n",
  63.364 -			       ref, np->xbdev->otherend_id);
  63.365 -			np->rx->ring[MASK_NETIF_RX_IDX(np->rx->req_prod)].
  63.366 -				req.id = rx->id;
  63.367 -			wmb();
  63.368 -			np->rx->req_prod++;
  63.369 +		/* Memory pressure, insufficient buffer headroom, ... */
  63.370 +		if ((mfn = gnttab_end_foreign_transfer_ref(ref)) == 0) {
  63.371 +			if (net_ratelimit())
  63.372 +				WPRINTK("Unfulfilled rx req (id=%d, st=%d).\n",
  63.373 +					rx->id, rx->status);
  63.374 +			RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->id =
  63.375 +				rx->id;
  63.376 +			RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->gref =
  63.377 +				ref;
  63.378 +			np->rx.req_prod_pvt++;
  63.379 +			RING_PUSH_REQUESTS(&np->rx);
  63.380  			work_done--;
  63.381  			continue;
  63.382  		}
  63.383  
  63.384 +		gnttab_release_grant_reference(&np->gref_rx_head, ref);
  63.385  		np->grant_rx_ref[rx->id] = GRANT_INVALID_REF;
  63.386 -		mfn = gnttab_end_foreign_transfer_ref(ref);
  63.387 -		gnttab_release_grant_reference(&np->gref_rx_head, ref);
  63.388  
  63.389  		skb = np->rx_skbs[rx->id];
  63.390  		ADD_ID_TO_FREELIST(np->rx_skbs, rx->id);
  63.391 @@ -781,7 +775,7 @@ static int netif_poll(struct net_device 
  63.392  		skb->len  = rx->status;
  63.393  		skb->tail = skb->data + skb->len;
  63.394  
  63.395 -		if ( rx->csum_valid )
  63.396 +		if ( rx->flags & NETRXF_csum_valid )
  63.397  			skb->ip_summed = CHECKSUM_UNNECESSARY;
  63.398  
  63.399  		np->stats.rx_packets++;
  63.400 @@ -867,11 +861,11 @@ static int netif_poll(struct net_device 
  63.401  		dev->last_rx = jiffies;
  63.402  	}
  63.403  
  63.404 -	np->rx_resp_cons = i;
  63.405 +	np->rx.rsp_cons = i;
  63.406  
  63.407  	/* If we get a callback with very few responses, reduce fill target. */
  63.408  	/* NB. Note exponential increase, linear decrease. */
  63.409 -	if (((np->rx->req_prod - np->rx->resp_prod) >
  63.410 +	if (((np->rx.req_prod_pvt - np->rx.sring->rsp_prod) >
  63.411  	     ((3*np->rx_target) / 4)) &&
  63.412  	    (--np->rx_target < np->rx_min_target))
  63.413  		np->rx_target = np->rx_min_target;
  63.414 @@ -884,14 +878,9 @@ static int netif_poll(struct net_device 
  63.415  	if (work_done < budget) {
  63.416  		local_irq_save(flags);
  63.417  
  63.418 -		np->rx->event = i + 1;
  63.419 -    
  63.420 -		/* Deal with hypervisor racing our resetting of rx_event. */
  63.421 -		mb();
  63.422 -		if (np->rx->resp_prod == i) {
  63.423 +		RING_FINAL_CHECK_FOR_RESPONSES(&np->rx, more_to_do);
  63.424 +		if (!more_to_do)
  63.425  			__netif_rx_complete(dev);
  63.426 -			more_to_do = 0;
  63.427 -		}
  63.428  
  63.429  		local_irq_restore(flags);
  63.430  	}
  63.431 @@ -931,8 +920,7 @@ static void network_connect(struct net_d
  63.432  	/* Recovery procedure: */
  63.433  
  63.434  	/* Step 1: Reinitialise variables. */
  63.435 -	np->rx_resp_cons = np->tx_resp_cons = np->tx_full = 0;
  63.436 -	np->rx->event = np->tx->event = 1;
  63.437 +	np->tx_full = 0;
  63.438  
  63.439  	/*
  63.440  	 * Step 2: Rebuild the RX and TX ring contents.
  63.441 @@ -952,13 +940,14 @@ static void network_connect(struct net_d
  63.442  	 * to avoid this but maybe it doesn't matter so much given the
  63.443  	 * interface has been down.
  63.444  	 */
  63.445 -	for (requeue_idx = 0, i = 1; i <= NETIF_TX_RING_SIZE; i++) {
  63.446 +	for (requeue_idx = 0, i = 1; i <= NET_TX_RING_SIZE; i++) {
  63.447  		if ((unsigned long)np->tx_skbs[i] < __PAGE_OFFSET)
  63.448  			continue;
  63.449  
  63.450  		skb = np->tx_skbs[i];
  63.451  
  63.452 -		tx = &np->tx->ring[requeue_idx++].req;
  63.453 +		tx = RING_GET_REQUEST(&np->tx, requeue_idx);
  63.454 +		requeue_idx++;
  63.455  
  63.456  		tx->id = i;
  63.457  		gnttab_grant_foreign_access_ref(
  63.458 @@ -968,27 +957,30 @@ static void network_connect(struct net_d
  63.459  		tx->gref = np->grant_tx_ref[i];
  63.460  		tx->offset = (unsigned long)skb->data & ~PAGE_MASK;
  63.461  		tx->size = skb->len;
  63.462 -		tx->csum_blank = (skb->ip_summed == CHECKSUM_HW);
  63.463 +		tx->flags = (skb->ip_summed == CHECKSUM_HW) ?
  63.464 +			NETTXF_csum_blank : 0;
  63.465  
  63.466  		np->stats.tx_bytes += skb->len;
  63.467  		np->stats.tx_packets++;
  63.468  	}
  63.469 -	wmb();
  63.470 -	np->tx->req_prod = requeue_idx;
  63.471 +
  63.472 +	np->tx.req_prod_pvt = requeue_idx;
  63.473 +	RING_PUSH_REQUESTS(&np->tx);
  63.474  
  63.475  	/* Rebuild the RX buffer freelist and the RX ring itself. */
  63.476 -	for (requeue_idx = 0, i = 1; i <= NETIF_RX_RING_SIZE; i++) { 
  63.477 +	for (requeue_idx = 0, i = 1; i <= NET_RX_RING_SIZE; i++) { 
  63.478  		if ((unsigned long)np->rx_skbs[i] < __PAGE_OFFSET)
  63.479  			continue;
  63.480  		gnttab_grant_foreign_transfer_ref(
  63.481  			np->grant_rx_ref[i], np->xbdev->otherend_id);
  63.482 -		np->rx->ring[requeue_idx].req.gref =
  63.483 +		RING_GET_REQUEST(&np->rx, requeue_idx)->gref =
  63.484  			np->grant_rx_ref[i];
  63.485 -		np->rx->ring[requeue_idx].req.id = i;
  63.486 +		RING_GET_REQUEST(&np->rx, requeue_idx)->id = i;
  63.487  		requeue_idx++; 
  63.488  	}
  63.489 -	wmb();                
  63.490 -	np->rx->req_prod = requeue_idx;
  63.491 +
  63.492 +	np->rx.req_prod_pvt = requeue_idx;
  63.493 +	RING_PUSH_REQUESTS(&np->rx);
  63.494  
  63.495  	/*
  63.496  	 * Step 3: All public and private state should now be sane.  Get
  63.497 @@ -997,7 +989,6 @@ static void network_connect(struct net_d
  63.498  	 * packets.
  63.499  	 */
  63.500  	np->backend_state = BEST_CONNECTED;
  63.501 -	wmb();
  63.502  	notify_remote_via_irq(np->irq);
  63.503  	network_tx_buf_gc(dev);
  63.504  
  63.505 @@ -1072,25 +1063,25 @@ static int create_netdev(int handle, str
  63.506  	np->rx_max_target = RX_MAX_TARGET;
  63.507  
  63.508  	/* Initialise {tx,rx}_skbs as a free chain containing every entry. */
  63.509 -	for (i = 0; i <= NETIF_TX_RING_SIZE; i++) {
  63.510 +	for (i = 0; i <= NET_TX_RING_SIZE; i++) {
  63.511  		np->tx_skbs[i] = (void *)((unsigned long) i+1);
  63.512  		np->grant_tx_ref[i] = GRANT_INVALID_REF;
  63.513  	}
  63.514  
  63.515 -	for (i = 0; i <= NETIF_RX_RING_SIZE; i++) {
  63.516 +	for (i = 0; i <= NET_RX_RING_SIZE; i++) {
  63.517  		np->rx_skbs[i] = (void *)((unsigned long) i+1);
  63.518  		np->grant_rx_ref[i] = GRANT_INVALID_REF;
  63.519  	}
  63.520  
  63.521  	/* A grant for every tx ring slot */
  63.522 -	if (gnttab_alloc_grant_references(NETIF_TX_RING_SIZE,
  63.523 +	if (gnttab_alloc_grant_references(NET_TX_RING_SIZE,
  63.524  					  &np->gref_tx_head) < 0) {
  63.525  		printk(KERN_ALERT "#### netfront can't alloc tx grant refs\n");
  63.526  		err = -ENOMEM;
  63.527  		goto exit;
  63.528  	}
  63.529  	/* A grant for every rx ring slot */
  63.530 -	if (gnttab_alloc_grant_references(NETIF_RX_RING_SIZE,
  63.531 +	if (gnttab_alloc_grant_references(NET_RX_RING_SIZE,
  63.532  					  &np->gref_rx_head) < 0) {
  63.533  		printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n");
  63.534  		gnttab_free_grant_references(np->gref_tx_head);
  63.535 @@ -1218,12 +1209,12 @@ static void netif_disconnect_backend(str
  63.536  	spin_unlock(&info->rx_lock);
  63.537  	spin_unlock_irq(&info->tx_lock);
  63.538      
  63.539 -	end_access(info->tx_ring_ref, info->tx);
  63.540 -	end_access(info->rx_ring_ref, info->rx);
  63.541 +	end_access(info->tx_ring_ref, info->tx.sring);
  63.542 +	end_access(info->rx_ring_ref, info->rx.sring);
  63.543  	info->tx_ring_ref = GRANT_INVALID_REF;
  63.544  	info->rx_ring_ref = GRANT_INVALID_REF;
  63.545 -	info->tx = NULL;
  63.546 -	info->rx = NULL;
  63.547 +	info->tx.sring = NULL;
  63.548 +	info->rx.sring = NULL;
  63.549  
  63.550  	if (info->irq)
  63.551  		unbind_from_irqhandler(info->irq, info->netdev);
    64.1 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Fri Dec 02 12:12:11 2005 -0600
    64.2 +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Fri Dec 02 12:52:25 2005 -0600
    64.3 @@ -33,18 +33,19 @@
    64.4  #include <asm-xen/xen_proc.h>
    64.5  
    64.6  static struct proc_dir_entry *privcmd_intf;
    64.7 +static struct proc_dir_entry *capabilities_intf;
    64.8  
    64.9  static int privcmd_ioctl(struct inode *inode, struct file *file,
   64.10                           unsigned int cmd, unsigned long data)
   64.11  {
   64.12  	int ret = -ENOSYS;
   64.13 +	void __user *udata = (void __user *) data;
   64.14  
   64.15  	switch (cmd) {
   64.16  	case IOCTL_PRIVCMD_HYPERCALL: {
   64.17  		privcmd_hypercall_t hypercall;
   64.18    
   64.19 -		if (copy_from_user(&hypercall, (void *)data,
   64.20 -				   sizeof(hypercall)))
   64.21 +		if (copy_from_user(&hypercall, udata, sizeof(hypercall)))
   64.22  			return -EFAULT;
   64.23  
   64.24  #if defined(__i386__)
   64.25 @@ -97,10 +98,11 @@ static int privcmd_ioctl(struct inode *i
   64.26  	case IOCTL_PRIVCMD_MMAP: {
   64.27  #define PRIVCMD_MMAP_SZ 32
   64.28  		privcmd_mmap_t mmapcmd;
   64.29 -		privcmd_mmap_entry_t msg[PRIVCMD_MMAP_SZ], *p;
   64.30 +		privcmd_mmap_entry_t msg[PRIVCMD_MMAP_SZ];
   64.31 +		privcmd_mmap_entry_t __user *p;
   64.32  		int i, rc;
   64.33  
   64.34 -		if (copy_from_user(&mmapcmd, (void *)data, sizeof(mmapcmd)))
   64.35 +		if (copy_from_user(&mmapcmd, udata, sizeof(mmapcmd)))
   64.36  			return -EFAULT;
   64.37  
   64.38  		p = mmapcmd.entry;
   64.39 @@ -146,12 +148,12 @@ static int privcmd_ioctl(struct inode *i
   64.40  		mmu_update_t u;
   64.41  		privcmd_mmapbatch_t m;
   64.42  		struct vm_area_struct *vma = NULL;
   64.43 -		unsigned long *p, addr;
   64.44 -		unsigned long mfn; 
   64.45 +		unsigned long __user *p;
   64.46 +		unsigned long addr, mfn; 
   64.47  		uint64_t ptep;
   64.48  		int i;
   64.49  
   64.50 -		if (copy_from_user(&m, (void *)data, sizeof(m))) {
   64.51 +		if (copy_from_user(&m, udata, sizeof(m))) {
   64.52  			ret = -EFAULT;
   64.53  			goto batch_err;
   64.54  		}
   64.55 @@ -212,43 +214,6 @@ static int privcmd_ioctl(struct inode *i
   64.56  	break;
   64.57  #endif
   64.58  
   64.59 -#ifndef __ia64__
   64.60 -	case IOCTL_PRIVCMD_GET_MACH2PHYS_MFNS: {
   64.61 -		pgd_t *pgd; 
   64.62 -		pud_t *pud; 
   64.63 -		pmd_t *pmd; 
   64.64 -		unsigned long m2pv, m2p_mfn; 	
   64.65 -		privcmd_m2pmfns_t m; 
   64.66 -		unsigned long *p; 
   64.67 -		int i; 
   64.68 -
   64.69 -		if (copy_from_user(&m, (void *)data, sizeof(m)))
   64.70 -			return -EFAULT;
   64.71 -
   64.72 -		m2pv = (unsigned long)machine_to_phys_mapping;
   64.73 -
   64.74 -		p = m.arr; 
   64.75 -
   64.76 -		for (i=0; i < m.num; i++) { 
   64.77 -			pgd = pgd_offset_k(m2pv);
   64.78 -			pud = pud_offset(pgd, m2pv);
   64.79 -			pmd = pmd_offset(pud, m2pv);
   64.80 -			m2p_mfn  = (*(uint64_t *)pmd >> PAGE_SHIFT)&0xFFFFFFFF;
   64.81 -			m2p_mfn += pte_index(m2pv);
   64.82 -
   64.83 -			if (put_user(m2p_mfn, p + i))
   64.84 -				return -EFAULT;
   64.85 -
   64.86 -			m2pv += (1 << 21); 
   64.87 -		}
   64.88 -
   64.89 -		ret = 0; 
   64.90 -		break; 
   64.91 -
   64.92 -	}
   64.93 -	break;
   64.94 -#endif
   64.95 -
   64.96  	default:
   64.97  		ret = -EINVAL;
   64.98  		break;
   64.99 @@ -270,6 +235,18 @@ static struct file_operations privcmd_fi
  64.100  	.mmap  = privcmd_mmap,
  64.101  };
  64.102  
  64.103 +static int capabilities_read(char *page, char **start, off_t off,
  64.104 +                        int count, int *eof, void *data)
  64.105 +{
  64.106 +	int len = 0;
  64.107 +	*page = 0;
  64.108 +
  64.109 +	if (xen_start_info->flags & SIF_INITDOMAIN)
  64.110 +		len = sprintf( page, "control_d\n" );
  64.111 +
  64.112 +	*eof = 1;
  64.113 +	return len;
  64.114 +}
  64.115  
  64.116  static int __init privcmd_init(void)
  64.117  {
  64.118 @@ -277,6 +254,10 @@ static int __init privcmd_init(void)
  64.119  	if (privcmd_intf != NULL)
  64.120  		privcmd_intf->proc_fops = &privcmd_file_ops;
  64.121  
  64.122 +	capabilities_intf = create_xen_proc_entry("capabilities", 0400 );
  64.123 +	if (capabilities_intf != NULL)
  64.124 +		capabilities_intf->read_proc = capabilities_read;
  64.125 +
  64.126  	return 0;
  64.127  }
  64.128  
    65.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Fri Dec 02 12:12:11 2005 -0600
    65.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Fri Dec 02 12:52:25 2005 -0600
    65.3 @@ -12,6 +12,7 @@
    65.4  #include <linux/slab.h>
    65.5  #include <asm-xen/evtchn.h>
    65.6  #include <asm-xen/driver_util.h>
    65.7 +#include <asm-xen/xen-public/grant_table.h>
    65.8  #include <asm-xen/xen-public/io/tpmif.h>
    65.9  #include <asm/io.h>
   65.10  #include <asm/pgalloc.h>
   65.11 @@ -28,7 +29,7 @@
   65.12  #endif
   65.13  
   65.14  typedef struct tpmif_st {
   65.15 -        struct list_head tpmif_list;
   65.16 +	struct list_head tpmif_list;
   65.17  	/* Unique identifier for this interface. */
   65.18  	domid_t domid;
   65.19  	unsigned int handle;
   65.20 @@ -54,7 +55,7 @@ typedef struct tpmif_st {
   65.21  
   65.22  	struct work_struct work;
   65.23  
   65.24 -	u16 shmem_handle;
   65.25 +	grant_handle_t shmem_handle;
   65.26  	grant_ref_t shmem_ref;
   65.27  } tpmif_t;
   65.28  
   65.29 @@ -83,6 +84,11 @@ extern int num_frontends;
   65.30  
   65.31  #define MMAP_VADDR(t,_req) ((t)->mmap_vstart + ((_req) * PAGE_SIZE))
   65.32  
   65.33 +#ifndef TRUE
   65.34 +#define TRUE 1
   65.35 +#define FALSE 0
   65.36 +#endif
   65.37 +
   65.38  #endif /* __TPMIF__BACKEND__COMMON_H__ */
   65.39  
   65.40  /*
    66.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Fri Dec 02 12:12:11 2005 -0600
    66.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Fri Dec 02 12:52:25 2005 -0600
    66.3 @@ -91,9 +91,9 @@ map_frontend_page(tpmif_t *tpmif, unsign
    66.4  	unlock_vm_area(tpmif->tx_area);
    66.5  	BUG_ON(ret);
    66.6  
    66.7 -	if (op.handle < 0) {
    66.8 +	if (op.status) {
    66.9  		DPRINTK(" Grant table operation failure !\n");
   66.10 -		return op.handle;
   66.11 +		return op.status;
   66.12  	}
   66.13  
   66.14  	tpmif->shmem_ref = shared_page;
   66.15 @@ -127,6 +127,10 @@ tpmif_map(tpmif_t *tpmif, unsigned long 
   66.16  		.u.bind_interdomain.remote_dom = tpmif->domid,
   66.17  		.u.bind_interdomain.remote_port = evtchn };
   66.18  
   66.19 +        if (tpmif->irq) {
   66.20 +                return 0;
   66.21 +        }
   66.22 +
   66.23  	if ((tpmif->tx_area = alloc_vm_area(PAGE_SIZE)) == NULL)
   66.24  		return -ENOMEM;
   66.25  
   66.26 @@ -149,7 +153,6 @@ tpmif_map(tpmif_t *tpmif, unsigned long 
   66.27  
   66.28  	tpmif->irq = bind_evtchn_to_irqhandler(
   66.29  		tpmif->evtchn, tpmif_be_int, 0, "tpmif-backend", tpmif);
   66.30 -	tpmif->status = CONNECTED;
   66.31  	tpmif->shmem_ref = shared_page;
   66.32  	tpmif->active = 1;
   66.33  
    67.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Fri Dec 02 12:12:11 2005 -0600
    67.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Fri Dec 02 12:52:25 2005 -0600
    67.3 @@ -249,7 +249,7 @@ static int
    67.4  	 * and send it to the front end.
    67.5  	 */
    67.6  	tpmif_t *tpmif = pak->tpmif;
    67.7 -	u16 handle;
    67.8 +	grant_handle_t handle;
    67.9  	int rc = 0;
   67.10  	unsigned int i = 0;
   67.11  	unsigned int offset = 0;
   67.12 @@ -290,7 +290,7 @@ static int
   67.13  
   67.14  		handle = map_op.handle;
   67.15  
   67.16 -		if (map_op.handle < 0) {
   67.17 +		if (map_op.status) {
   67.18  			DPRINTK(" Grant table operation failure !\n");
   67.19  			return 0;
   67.20  		}
   67.21 @@ -427,7 +427,7 @@ packet_read_shmem(struct packet *pak,
   67.22  	u32 i = (last_read / PAGE_SIZE);
   67.23  	u32 pg_offset = last_read & (PAGE_SIZE - 1);
   67.24  	u32 to_copy;
   67.25 -	u16 handle;
   67.26 +	grant_handle_t handle;
   67.27  
   67.28  	tpmif_tx_request_t *tx;
   67.29  	tx = &tpmif->tx->ring[0].req;
   67.30 @@ -455,7 +455,7 @@ packet_read_shmem(struct packet *pak,
   67.31  			BUG();
   67.32  		}
   67.33  
   67.34 -		if (map_op.handle < 0) {
   67.35 +		if (map_op.status) {
   67.36  			DPRINTK(" Grant table operation failure !\n");
   67.37  			return -EFAULT;
   67.38  		}
    68.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Fri Dec 02 12:12:11 2005 -0600
    68.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Fri Dec 02 12:52:25 2005 -0600
    68.3 @@ -1,4 +1,5 @@
    68.4  /*  Xenbus code for tpmif backend
    68.5 +    Copyright (C) 2005 IBM Corporation
    68.6      Copyright (C) 2005 Rusty Russell <rusty@rustcorp.com.au>
    68.7  
    68.8      This program is free software; you can redistribute it and/or modify
    68.9 @@ -29,72 +30,189 @@ struct backend_info
   68.10  
   68.11  	long int frontend_id;
   68.12  	long int instance; // instance of TPM
   68.13 +	u8 is_instance_set;// whether instance number has been set
   68.14  
   68.15  	/* watch front end for changes */
   68.16  	struct xenbus_watch backend_watch;
   68.17 +	XenbusState frontend_state;
   68.18 +};
   68.19  
   68.20 -	struct xenbus_watch watch;
   68.21 -	char * frontpath;
   68.22 -};
   68.23 +static void maybe_connect(struct backend_info *be);
   68.24 +static void connect(struct backend_info *be);
   68.25 +static int connect_ring(struct backend_info *be);
   68.26 +static void backend_changed(struct xenbus_watch *watch,
   68.27 +                            const char **vec, unsigned int len);
   68.28 +static void frontend_changed(struct xenbus_device *dev,
   68.29 +                             XenbusState frontend_state);
   68.30  
   68.31  static int tpmback_remove(struct xenbus_device *dev)
   68.32  {
   68.33  	struct backend_info *be = dev->data;
   68.34  
   68.35 -	if (be->watch.node)
   68.36 -		unregister_xenbus_watch(&be->watch);
   68.37 -	unregister_xenbus_watch(&be->backend_watch);
   68.38 +	if (be->backend_watch.node) {
   68.39 +		unregister_xenbus_watch(&be->backend_watch);
   68.40 +		kfree(be->backend_watch.node);
   68.41 +		be->backend_watch.node = NULL;
   68.42 +	}
   68.43 +	if (be->tpmif) {
   68.44 +		tpmif_put(be->tpmif);
   68.45 +		be->tpmif = NULL;
   68.46 +	}
   68.47 +	kfree(be);
   68.48 +	dev->data = NULL;
   68.49 +	return 0;
   68.50 +}
   68.51  
   68.52 -	tpmif_vtpm_close(be->instance);
   68.53 +static int tpmback_probe(struct xenbus_device *dev,
   68.54 +                         const struct xenbus_device_id *id)
   68.55 +{
   68.56 +	int err;
   68.57 +	struct backend_info *be = kmalloc(sizeof(struct backend_info),
   68.58 +	                                  GFP_KERNEL);
   68.59  
   68.60 -	if (be->tpmif)
   68.61 -		tpmif_put(be->tpmif);
   68.62 +	if (!be) {
   68.63 +		xenbus_dev_fatal(dev, -ENOMEM,
   68.64 +		                 "allocating backend structure");
   68.65 +		return -ENOMEM;
   68.66 +	}
   68.67 +
   68.68 +	memset(be, 0, sizeof(*be));
   68.69 +
   68.70 +	be->is_instance_set = FALSE;
   68.71 +	be->dev = dev;
   68.72 +	dev->data = be;
   68.73  
   68.74 -	kfree(be->frontpath);
   68.75 -	kfree(be);
   68.76 +	err = xenbus_watch_path2(dev, dev->nodename,
   68.77 +	                        "instance", &be->backend_watch,
   68.78 +	                        backend_changed);
   68.79 +	if (err) {
   68.80 +		goto fail;
   68.81 +	}
   68.82 +
   68.83 +	err = xenbus_switch_state(dev, NULL, XenbusStateInitWait);
   68.84 +	if (err) {
   68.85 +		goto fail;
   68.86 +	}
   68.87  	return 0;
   68.88 +fail:
   68.89 +	tpmback_remove(dev);
   68.90 +	return err;
   68.91  }
   68.92  
   68.93  
   68.94 -static void frontend_changed(struct xenbus_watch *watch,
   68.95 -			     const char **vec, unsigned int len)
   68.96 +static void backend_changed(struct xenbus_watch *watch,
   68.97 +                            const char **vec, unsigned int len)
   68.98  {
   68.99 -	unsigned long ringref;
  68.100 -	unsigned int evtchn;
  68.101 -	unsigned long ready = 1;
  68.102  	int err;
  68.103 -	struct xenbus_transaction *xbt;
  68.104 +	long instance;
  68.105  	struct backend_info *be
  68.106 -		= container_of(watch, struct backend_info, watch);
  68.107 +		= container_of(watch, struct backend_info, backend_watch);
  68.108 +	struct xenbus_device *dev = be->dev;
  68.109 +
  68.110 +	err = xenbus_scanf(NULL, dev->nodename,
  68.111 +	                   "instance","%li", &instance);
  68.112 +	if (XENBUS_EXIST_ERR(err)) {
  68.113 +		return;
  68.114 +	}
  68.115  
  68.116 -	/* If other end is gone, delete ourself. */
  68.117 -	if (vec && !xenbus_exists(NULL, be->frontpath, "")) {
  68.118 -		xenbus_rm(NULL, be->dev->nodename, "");
  68.119 -		device_unregister(&be->dev->dev);
  68.120 +	if (err != 1) {
  68.121 +		xenbus_dev_fatal(dev, err, "reading instance");
  68.122 +		return;
  68.123 +	}
  68.124 +
  68.125 +	if (be->is_instance_set != FALSE && be->instance != instance) {
  68.126 +		printk(KERN_WARNING
  68.127 +		       "tpmback: changing instance (from %ld to %ld) "
  68.128 +		       "not allowed.\n",
  68.129 +		       be->instance, instance);
  68.130  		return;
  68.131  	}
  68.132  
  68.133 +	if (be->is_instance_set == FALSE) {
  68.134 +		be->tpmif = tpmif_find(dev->otherend_id,
  68.135 +		                       instance);
  68.136 +		if (IS_ERR(be->tpmif)) {
  68.137 +			err = PTR_ERR(be->tpmif);
  68.138 +			be->tpmif = NULL;
  68.139 +			xenbus_dev_fatal(dev,err,"creating block interface");
  68.140 +			return;
  68.141 +		}
  68.142 +		be->instance = instance;
  68.143 +		be->is_instance_set = TRUE;
  68.144 +
  68.145 +		/*
  68.146 +		 * There's an unfortunate problem:
  68.147 +		 * Sometimes after a suspend/resume the
  68.148 +		 * state switch to XenbusStateInitialised happens
  68.149 +		 * *before* I get to this point here. Since then
  68.150 +		 * the connect_ring() must have failed (be->tpmif is
  68.151 +		 * still NULL), I just call it here again indirectly.
  68.152 +		 */
  68.153 +		if (be->frontend_state == XenbusStateInitialised) {
  68.154 +			frontend_changed(dev, be->frontend_state);
  68.155 +		}
  68.156 +	}
  68.157 +}
  68.158 +
  68.159 +
  68.160 +static void frontend_changed(struct xenbus_device *dev,
  68.161 +                             XenbusState frontend_state)
  68.162 +{
  68.163 +	struct backend_info *be = dev->data;
  68.164 +	int err;
  68.165 +
  68.166 +	be->frontend_state = frontend_state;
  68.167 +
  68.168 +	switch (frontend_state) {
  68.169 +	case XenbusStateInitialising:
  68.170 +	case XenbusStateConnected:
  68.171 +		break;
  68.172 +
  68.173 +	case XenbusStateInitialised:
  68.174 +		err = connect_ring(be);
  68.175 +		if (err) {
  68.176 +			return;
  68.177 +		}
  68.178 +		maybe_connect(be);
  68.179 +		break;
  68.180 +
  68.181 +	case XenbusStateClosing:
  68.182 +		xenbus_switch_state(dev, NULL, XenbusStateClosing);
  68.183 +		break;
  68.184 +
  68.185 +	case XenbusStateClosed:
  68.186 +		/*
  68.187 +		 * Notify the vTPM manager about the front-end
  68.188 +		 * having left.
  68.189 +		 */
  68.190 +		tpmif_vtpm_close(be->instance);
  68.191 +		device_unregister(&be->dev->dev);
  68.192 +		break;
  68.193 +
  68.194 +	case XenbusStateUnknown:
  68.195 +	case XenbusStateInitWait:
  68.196 +	default:
  68.197 +		xenbus_dev_fatal(dev, -EINVAL,
  68.198 +		                 "saw state %d at frontend",
  68.199 +		                 frontend_state);
  68.200 +		break;
  68.201 +	}
  68.202 +}
  68.203 +
  68.204 +
  68.205 +
  68.206 +static void maybe_connect(struct backend_info *be)
  68.207 +{
  68.208 +	int err;
  68.209 +
  68.210  	if (be->tpmif == NULL || be->tpmif->status == CONNECTED)
  68.211  		return;
  68.212  
  68.213 -	err = xenbus_gather(NULL, be->frontpath,
  68.214 -	                    "ring-ref", "%lu", &ringref,
  68.215 -			    "event-channel", "%u", &evtchn, NULL);
  68.216 -	if (err) {
  68.217 -		xenbus_dev_error(be->dev, err,
  68.218 -				 "reading %s/ring-ref and event-channel",
  68.219 -				 be->frontpath);
  68.220 -		return;
  68.221 -	}
  68.222 +	connect(be);
  68.223  
  68.224 -	err = tpmif_map(be->tpmif, ringref, evtchn);
  68.225 -	if (err) {
  68.226 -		xenbus_dev_error(be->dev, err,
  68.227 -				 "mapping shared-frame %lu port %u",
  68.228 -				 ringref, evtchn);
  68.229 -		return;
  68.230 -	}
  68.231 -
  68.232 +	/*
  68.233 +	 * Notify the vTPM manager about a new front-end.
  68.234 +	 */
  68.235  	err = tpmif_vtpm_open(be->tpmif,
  68.236  	                      be->frontend_id,
  68.237  	                      be->instance);
  68.238 @@ -107,157 +225,75 @@ static void frontend_changed(struct xenb
  68.239  		 */
  68.240  		return;
  68.241  	}
  68.242 +}
  68.243  
  68.244 -	/*
  68.245 -	 * Tell the front-end that we are ready to go -
  68.246 -	 * unless something bad happens
  68.247 -	 */
  68.248 +
  68.249 +static void connect(struct backend_info *be)
  68.250 +{
  68.251 +	struct xenbus_transaction *xbt;
  68.252 +	int err;
  68.253 +	struct xenbus_device *dev = be->dev;
  68.254 +	unsigned long ready = 1;
  68.255 +
  68.256  again:
  68.257  	xbt = xenbus_transaction_start();
  68.258  	if (IS_ERR(xbt)) {
  68.259 -		xenbus_dev_error(be->dev, err, "starting transaction");
  68.260 +		err = PTR_ERR(xbt);
  68.261 +		xenbus_dev_fatal(be->dev, err, "starting transaction");
  68.262  		return;
  68.263  	}
  68.264  
  68.265  	err = xenbus_printf(xbt, be->dev->nodename,
  68.266  	                    "ready", "%lu", ready);
  68.267  	if (err) {
  68.268 -		xenbus_dev_error(be->dev, err, "writing 'ready'");
  68.269 +		xenbus_dev_fatal(be->dev, err, "writing 'ready'");
  68.270  		goto abort;
  68.271  	}
  68.272  
  68.273 +	err = xenbus_switch_state(dev, xbt, XenbusStateConnected);
  68.274 +	if (err)
  68.275 +		goto abort;
  68.276 +
  68.277 +	be->tpmif->status = CONNECTED;
  68.278 +
  68.279  	err = xenbus_transaction_end(xbt, 0);
  68.280  	if (err == -EAGAIN)
  68.281  		goto again;
  68.282  	if (err) {
  68.283 -		xenbus_dev_error(be->dev, err, "end of transaction");
  68.284 -		goto abort;
  68.285 +		xenbus_dev_fatal(be->dev, err, "end of transaction");
  68.286  	}
  68.287 -
  68.288 -	xenbus_dev_ok(be->dev);
  68.289  	return;
  68.290  abort:
  68.291  	xenbus_transaction_end(xbt, 1);
  68.292  }
  68.293  
  68.294  
  68.295 -static void backend_changed(struct xenbus_watch *watch,
  68.296 -			    const char **vec, unsigned int len)
  68.297 +static int connect_ring(struct backend_info *be)
  68.298  {
  68.299 -	int err;
  68.300 -	long int instance;
  68.301 -	struct backend_info *be
  68.302 -		= container_of(watch, struct backend_info, backend_watch);
  68.303  	struct xenbus_device *dev = be->dev;
  68.304 -
  68.305 -	err = xenbus_scanf(NULL, dev->nodename, "instance", "%li", &instance);
  68.306 -	if (XENBUS_EXIST_ERR(err))
  68.307 -		return;
  68.308 -	if (err < 0) {
  68.309 -		xenbus_dev_error(dev, err, "reading 'instance' variable");
  68.310 -		return;
  68.311 -	}
  68.312 -
  68.313 -	if (be->instance != -1 && be->instance != instance) {
  68.314 -		printk(KERN_WARNING
  68.315 -		       "cannot change the instance\n");
  68.316 -		return;
  68.317 -	}
  68.318 -	be->instance = instance;
  68.319 -
  68.320 -	if (be->tpmif == NULL) {
  68.321 -		unsigned int len = max(XS_WATCH_PATH, XS_WATCH_TOKEN) + 1;
  68.322 -		const char *vec[len];
  68.323 -
  68.324 -		be->tpmif = tpmif_find(be->frontend_id,
  68.325 -		                       instance);
  68.326 -		if (IS_ERR(be->tpmif)) {
  68.327 -			err = PTR_ERR(be->tpmif);
  68.328 -			be->tpmif = NULL;
  68.329 -			xenbus_dev_error(dev, err, "creating interface");
  68.330 -			return;
  68.331 -		}
  68.332 -
  68.333 -		vec[XS_WATCH_PATH] = be->frontpath;
  68.334 -		vec[XS_WATCH_TOKEN] = NULL;
  68.335 -
  68.336 -		/* Pass in NULL node to skip exist test. */
  68.337 -		frontend_changed(&be->watch, vec, len);
  68.338 -	}
  68.339 -}
  68.340 -
  68.341 -
  68.342 -static int tpmback_probe(struct xenbus_device *dev,
  68.343 -			 const struct xenbus_device_id *id)
  68.344 -{
  68.345 -	struct backend_info *be;
  68.346 -	char *frontend;
  68.347 +	unsigned long ring_ref;
  68.348 +	unsigned int evtchn;
  68.349  	int err;
  68.350  
  68.351 -	be = kmalloc(sizeof(*be), GFP_KERNEL);
  68.352 -	if (!be) {
  68.353 -		xenbus_dev_error(dev, -ENOMEM, "allocating backend structure");
  68.354 -		err = -ENOMEM;
  68.355 -	}
  68.356 -
  68.357 -	memset(be, 0, sizeof(*be));
  68.358 -
  68.359 -	frontend = NULL;
  68.360 -	err = xenbus_gather(NULL, dev->nodename,
  68.361 -			    "frontend-id", "%li", &be->frontend_id,
  68.362 -			    "frontend", NULL, &frontend,
  68.363 -			    NULL);
  68.364 -	if (XENBUS_EXIST_ERR(err))
  68.365 -		goto free_be;
  68.366 -	if (err < 0) {
  68.367 +	err = xenbus_gather(NULL, dev->otherend,
  68.368 +	                    "ring-ref", "%lu", &ring_ref,
  68.369 +			    "event-channel", "%u", &evtchn, NULL);
  68.370 +	if (err) {
  68.371  		xenbus_dev_error(dev, err,
  68.372 -				 "reading %s/frontend or frontend-id",
  68.373 -				 dev->nodename);
  68.374 -		goto free_be;
  68.375 -	}
  68.376 -	if (strlen(frontend) == 0 || !xenbus_exists(NULL, frontend, "")) {
  68.377 -		/* If we can't get a frontend path and a frontend-id,
  68.378 -		 * then our bus-id is no longer valid and we need to
  68.379 -		 * destroy the backend device.
  68.380 -		 */
  68.381 -		err = -ENOENT;
  68.382 -		goto free_be;
  68.383 +				 "reading %s/ring-ref and event-channel",
  68.384 +				 dev->otherend);
  68.385 +		return err;
  68.386  	}
  68.387 -
  68.388 -	be->dev = dev;
  68.389 -	be->backend_watch.node     = dev->nodename;
  68.390 -	/* Implicitly calls backend_changed() once. */
  68.391 -	be->backend_watch.callback = backend_changed;
  68.392 -	be->instance = -1;
  68.393 -	err = register_xenbus_watch(&be->backend_watch);
  68.394 -	if (err) {
  68.395 -		be->backend_watch.node = NULL;
  68.396 -		xenbus_dev_error(dev, err, "adding backend watch on %s",
  68.397 -				 dev->nodename);
  68.398 -		goto free_be;
  68.399 +	if (be->tpmif != NULL) {
  68.400 +		err = tpmif_map(be->tpmif, ring_ref, evtchn);
  68.401 +		if (err) {
  68.402 +			xenbus_dev_error(dev, err,
  68.403 +			    	         "mapping shared-frame %lu port %u",
  68.404 +				         ring_ref, evtchn);
  68.405 +			return err;
  68.406 +		}
  68.407  	}
  68.408 -
  68.409 -	be->frontpath = frontend;
  68.410 -	be->watch.node = be->frontpath;
  68.411 -	be->watch.callback = frontend_changed;
  68.412 -	err = register_xenbus_watch(&be->watch);
  68.413 -	if (err) {
  68.414 -		be->watch.node = NULL;
  68.415 -		xenbus_dev_error(dev, err,
  68.416 -				 "adding frontend watch on %s",
  68.417 -				 be->frontpath);
  68.418 -		goto free_be;
  68.419 -	}
  68.420 -
  68.421 -	dev->data = be;
  68.422 -	return err;
  68.423 -
  68.424 -free_be:
  68.425 -	if (be->backend_watch.node)
  68.426 -		unregister_xenbus_watch(&be->backend_watch);
  68.427 -	kfree(frontend);
  68.428 -	kfree(be);
  68.429 -	return err;
  68.430 +	return 0;
  68.431  }
  68.432  
  68.433  
  68.434 @@ -273,6 +309,7 @@ static struct xenbus_driver tpmback = {
  68.435  	.ids = tpmback_ids,
  68.436  	.probe = tpmback_probe,
  68.437  	.remove = tpmback_remove,
  68.438 +	.otherend_changed = frontend_changed,
  68.439  };
  68.440  
  68.441  
    69.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Fri Dec 02 12:12:11 2005 -0600
    69.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Fri Dec 02 12:52:25 2005 -0600
    69.3 @@ -38,12 +38,13 @@
    69.4  #include <linux/errno.h>
    69.5  #include <linux/interrupt.h>
    69.6  #include <linux/init.h>
    69.7 -#include <linux/tpmfe.h>
    69.8 +#include <asm-xen/tpmfe.h>
    69.9  #include <linux/err.h>
   69.10  
   69.11  #include <asm/semaphore.h>
   69.12  #include <asm/io.h>
   69.13  #include <asm-xen/evtchn.h>
   69.14 +#include <asm-xen/xen-public/grant_table.h>
   69.15  #include <asm-xen/xen-public/io/tpmif.h>
   69.16  #include <asm/uaccess.h>
   69.17  #include <asm-xen/xenbus.h>
   69.18 @@ -73,7 +74,8 @@ static void tpmif_rx_action(unsigned lon
   69.19  static void tpmif_connect(u16 evtchn, domid_t domid);
   69.20  static DECLARE_TASKLET(tpmif_rx_tasklet, tpmif_rx_action, 0);
   69.21  static int tpm_allocate_buffers(struct tpm_private *tp);
   69.22 -static void tpmif_set_connected_state(struct tpm_private *tp, int newstate);
   69.23 +static void tpmif_set_connected_state(struct tpm_private *tp,
   69.24 +                                      u8 newstate);
   69.25  static int tpm_xmit(struct tpm_private *tp,
   69.26                      const u8 * buf, size_t count, int userbuffer,
   69.27                      void *remember);
   69.28 @@ -212,87 +214,46 @@ static int tpm_fe_send_upperlayer(const 
   69.29   XENBUS support code
   69.30  **************************************************************/
   69.31  
   69.32 -static void watch_for_status(struct xenbus_watch *watch,
   69.33 -			     const char **vec, unsigned int len)
   69.34 -{
   69.35 -	struct tpmfront_info *info;
   69.36 -	int err;
   69.37 -	unsigned long ready;
   69.38 -	struct tpm_private *tp = &my_private;
   69.39 -	const char *node = vec[XS_WATCH_PATH];
   69.40 -
   69.41 -	info = container_of(watch, struct tpmfront_info, watch);
   69.42 -	node += strlen(watch->node);
   69.43 -
   69.44 -	if (tp->connected)
   69.45 -		return;
   69.46 -
   69.47 -	err = xenbus_gather(NULL, watch->node,
   69.48 -	                    "ready", "%lu", &ready,
   69.49 -	                    NULL);
   69.50 -	if (err) {
   69.51 -		xenbus_dev_error(info->dev, err, "reading 'ready' field");
   69.52 -		return;
   69.53 -	}
   69.54 -
   69.55 -	tpmif_set_connected_state(tp, 1);
   69.56 -
   69.57 -	xenbus_dev_ok(info->dev);
   69.58 -}
   69.59 -
   69.60 -
   69.61  static int setup_tpmring(struct xenbus_device *dev,
   69.62 -                         struct tpmfront_info * info,
   69.63 -                         domid_t backend_id)
   69.64 +                         struct tpmfront_info * info)
   69.65  {
   69.66  	tpmif_tx_interface_t *sring;
   69.67  	struct tpm_private *tp = &my_private;
   69.68  	int err;
   69.69 -	evtchn_op_t op = {
   69.70 -		.cmd = EVTCHNOP_alloc_unbound,
   69.71 -		.u.alloc_unbound.dom = DOMID_SELF,
   69.72 -		.u.alloc_unbound.remote_dom = backend_id } ;
   69.73  
   69.74  	sring = (void *)__get_free_page(GFP_KERNEL);
   69.75  	if (!sring) {
   69.76 -		xenbus_dev_error(dev, -ENOMEM, "allocating shared ring");
   69.77 +		xenbus_dev_fatal(dev, -ENOMEM, "allocating shared ring");
   69.78  		return -ENOMEM;
   69.79  	}
   69.80  	tp->tx = sring;
   69.81  
   69.82  	tpm_allocate_buffers(tp);
   69.83  
   69.84 -	err = gnttab_grant_foreign_access(backend_id,
   69.85 -					  (virt_to_machine(tp->tx) >> PAGE_SHIFT),
   69.86 -					  0);
   69.87 -
   69.88 -	if (err == -ENOSPC) {
   69.89 +	err = xenbus_grant_ring(dev, virt_to_mfn(tp->tx));
   69.90 +	if (err < 0) {
   69.91  		free_page((unsigned long)sring);
   69.92  		tp->tx = NULL;
   69.93 -		xenbus_dev_error(dev, err, "allocating grant reference");
   69.94 -		return err;
   69.95 +		xenbus_dev_fatal(dev, err, "allocating grant reference");
   69.96 +		goto fail;
   69.97  	}
   69.98  	info->ring_ref = err;
   69.99  
  69.100 -	err = HYPERVISOR_event_channel_op(&op);
  69.101 -	if (err) {
  69.102 -		gnttab_end_foreign_access(info->ring_ref, 0,
  69.103 -					  (unsigned long)sring);
  69.104 -		tp->tx = NULL;
  69.105 -		xenbus_dev_error(dev, err, "allocating event channel");
  69.106 -		return err;
  69.107 -	}
  69.108 +	err = xenbus_alloc_evtchn(dev, &tp->evtchn);
  69.109 +	if (err)
  69.110 +		goto fail;
  69.111  
  69.112 -	tpmif_connect(op.u.alloc_unbound.port, backend_id);
  69.113 +	tpmif_connect(tp->evtchn, dev->otherend_id);
  69.114  
  69.115  	return 0;
  69.116 +fail:
  69.117 +	return err;
  69.118  }
  69.119  
  69.120  
  69.121  static void destroy_tpmring(struct tpmfront_info *info, struct tpm_private *tp)
  69.122  {
  69.123 -	tpmif_set_connected_state(tp,0);
  69.124 -
  69.125 +	tpmif_set_connected_state(tp, FALSE);
  69.126  	if ( tp->tx != NULL ) {
  69.127  		gnttab_end_foreign_access(info->ring_ref, 0,
  69.128  					  (unsigned long)tp->tx);
  69.129 @@ -308,42 +269,20 @@ static void destroy_tpmring(struct tpmfr
  69.130  static int talk_to_backend(struct xenbus_device *dev,
  69.131                             struct tpmfront_info *info)
  69.132  {
  69.133 -	char *backend;
  69.134 -	const char *message;
  69.135 +	const char *message = NULL;
  69.136  	int err;
  69.137 -	int backend_id;
  69.138  	struct xenbus_transaction *xbt;
  69.139  
  69.140 -	backend = NULL;
  69.141 -	err = xenbus_gather(NULL, dev->nodename,
  69.142 -			    "backend-id", "%i", &backend_id,
  69.143 -			    "backend", NULL, &backend,
  69.144 -			    NULL);
  69.145 -	if (XENBUS_EXIST_ERR(err))
  69.146 -		goto out;
  69.147 -	if (backend && strlen(backend) == 0) {
  69.148 -		err = -ENOENT;
  69.149 -		goto out;
  69.150 -	}
  69.151 -	if (err < 0) {
  69.152 -		xenbus_dev_error(dev, err, "reading %s/backend or backend-id",
  69.153 -				 dev->nodename);
  69.154 -		goto out;
  69.155 -	}
  69.156 -
  69.157 -	info->backend_id      = backend_id;
  69.158 -	my_private.backend_id = backend_id;
  69.159 -
  69.160 -	err = setup_tpmring(dev, info, backend_id);
  69.161 +	err = setup_tpmring(dev, info);
  69.162  	if (err) {
  69.163 -		xenbus_dev_error(dev, err, "setting up ring");
  69.164 +		xenbus_dev_fatal(dev, err, "setting up ring");
  69.165  		goto out;
  69.166  	}
  69.167  
  69.168  again:
  69.169  	xbt = xenbus_transaction_start();
  69.170  	if (IS_ERR(xbt)) {
  69.171 -		xenbus_dev_error(dev, err, "starting transaction");
  69.172 +		xenbus_dev_fatal(dev, err, "starting transaction");
  69.173  		goto destroy_tpmring;
  69.174  	}
  69.175  
  69.176 @@ -361,36 +300,62 @@ again:
  69.177  		goto abort_transaction;
  69.178  	}
  69.179  
  69.180 +	err = xenbus_switch_state(dev, xbt, XenbusStateInitialised);
  69.181 +	if (err) {
  69.182 +		goto abort_transaction;
  69.183 +	}
  69.184 +
  69.185  	err = xenbus_transaction_end(xbt, 0);
  69.186  	if (err == -EAGAIN)
  69.187  		goto again;
  69.188  	if (err) {
  69.189 -		xenbus_dev_error(dev, err, "completing transaction");
  69.190 +		xenbus_dev_fatal(dev, err, "completing transaction");
  69.191  		goto destroy_tpmring;
  69.192  	}
  69.193 -
  69.194 -	info->watch.node = backend;
  69.195 -	info->watch.callback = watch_for_status;
  69.196 -	err = register_xenbus_watch(&info->watch);
  69.197 -	if (err) {
  69.198 -		xenbus_dev_error(dev, err, "registering watch on backend");
  69.199 -		goto destroy_tpmring;
  69.200 -	}
  69.201 -
  69.202 -	info->backend = backend;
  69.203 -
  69.204  	return 0;
  69.205  
  69.206  abort_transaction:
  69.207  	xenbus_transaction_end(xbt, 1);
  69.208 -	xenbus_dev_error(dev, err, "%s", message);
  69.209 +	if (message)
  69.210 +		xenbus_dev_error(dev, err, "%s", message);
  69.211  destroy_tpmring:
  69.212  	destroy_tpmring(info, &my_private);
  69.213  out:
  69.214 -	kfree(backend);
  69.215  	return err;
  69.216  }
  69.217  
  69.218 +/**
  69.219 + * Callback received when the backend's state changes.
  69.220 + */
  69.221 +static void backend_changed(struct xenbus_device *dev,
  69.222 +			    XenbusState backend_state)
  69.223 +{
  69.224 +	struct tpm_private *tp = &my_private;
  69.225 +	DPRINTK("\n");
  69.226 +
  69.227 +	switch (backend_state) {
  69.228 +	case XenbusStateInitialising:
  69.229 +	case XenbusStateInitWait:
  69.230 +	case XenbusStateInitialised:
  69.231 +	case XenbusStateUnknown:
  69.232 +		break;
  69.233 +
  69.234 +	case XenbusStateConnected:
  69.235 +		tpmif_set_connected_state(tp, TRUE);
  69.236 +		break;
  69.237 +
  69.238 +	case XenbusStateClosing:
  69.239 +		tpmif_set_connected_state(tp, FALSE);
  69.240 +		break;
  69.241 +
  69.242 +	case XenbusStateClosed:
  69.243 +        	if (tp->is_suspended == FALSE) {
  69.244 +        	        device_unregister(&dev->dev);
  69.245 +        	}
  69.246 +	        break;
  69.247 +	}
  69.248 +}
  69.249 +
  69.250  
  69.251  static int tpmfront_probe(struct xenbus_device *dev,
  69.252                            const struct xenbus_device_id *id)
  69.253 @@ -398,8 +363,6 @@ static int tpmfront_probe(struct xenbus_
  69.254  	int err;
  69.255  	struct tpmfront_info *info;
  69.256  	int handle;
  69.257 -	int len = max(XS_WATCH_PATH, XS_WATCH_TOKEN) + 1;
  69.258 -	const char *vec[len];
  69.259  
  69.260  	err = xenbus_scanf(NULL, dev->nodename,
  69.261  	                   "handle", "%i", &handle);
  69.262 @@ -407,19 +370,19 @@ static int tpmfront_probe(struct xenbus_
  69.263  		return err;
  69.264  
  69.265  	if (err < 0) {
  69.266 -		xenbus_dev_error(dev,err,"reading virtual-device");
  69.267 +		xenbus_dev_fatal(dev,err,"reading virtual-device");
  69.268  		return err;
  69.269  	}
  69.270  
  69.271  	info = kmalloc(sizeof(*info), GFP_KERNEL);
  69.272  	if (!info) {
  69.273 -		xenbus_dev_error(dev,err,"allocating info structure");
  69.274 +		err = -ENOMEM;
  69.275 +		xenbus_dev_fatal(dev,err,"allocating info structure");
  69.276  		return err;
  69.277  	}
  69.278  	memset(info, 0x0, sizeof(*info));
  69.279  
  69.280  	info->dev = dev;
  69.281 -	info->handle = handle;
  69.282  	dev->data = info;
  69.283  
  69.284  	err = talk_to_backend(dev, info);
  69.285 @@ -428,41 +391,33 @@ static int tpmfront_probe(struct xenbus_
  69.286  		dev->data = NULL;
  69.287  		return err;
  69.288  	}
  69.289 -
  69.290 -	vec[XS_WATCH_PATH]  = info->watch.node;
  69.291 -	vec[XS_WATCH_TOKEN] = NULL;
  69.292 -	watch_for_status(&info->watch, vec, len);
  69.293 -
  69.294  	return 0;
  69.295  }
  69.296  
  69.297 +
  69.298  static int tpmfront_remove(struct xenbus_device *dev)
  69.299  {
  69.300  	struct tpmfront_info *info = dev->data;
  69.301 -	if (info->backend)
  69.302 -		unregister_xenbus_watch(&info->watch);
  69.303  
  69.304  	destroy_tpmring(info, &my_private);
  69.305  
  69.306 -	kfree(info->backend);
  69.307  	kfree(info);
  69.308 -
  69.309  	return 0;
  69.310  }
  69.311  
  69.312  static int
  69.313  tpmfront_suspend(struct xenbus_device *dev)
  69.314  {
  69.315 -	struct tpmfront_info *info = dev->data;
  69.316  	struct tpm_private *tp = &my_private;
  69.317  	u32 ctr = 0;
  69.318  
  69.319  	/* lock, so no app can send */
  69.320  	down(&suspend_lock);
  69.321 +	tp->is_suspended = TRUE;
  69.322  
  69.323  	while (atomic_read(&tp->tx_busy) && ctr <= 25) {
  69.324 -	        if ((ctr % 10) == 0)
  69.325 -			printk("INFO: Waiting for outstanding request.\n");
  69.326 +		if ((ctr % 10) == 0)
  69.327 +			printk("TPM-FE [INFO]: Waiting for outstanding request.\n");
  69.328  		/*
  69.329  		 * Wait for a request to be responded to.
  69.330  		 */
  69.331 @@ -474,15 +429,10 @@ tpmfront_suspend(struct xenbus_device *d
  69.332  		/*
  69.333  		 * A temporary work-around.
  69.334  		 */
  69.335 -		printk("WARNING: Resetting busy flag.");
  69.336 +		printk("TPM-FE [WARNING]: Resetting busy flag.");
  69.337  		atomic_set(&tp->tx_busy, 0);
  69.338  	}
  69.339  
  69.340 -	unregister_xenbus_watch(&info->watch);
  69.341 -
  69.342 -	kfree(info->backend);
  69.343 -	info->backend = NULL;
  69.344 -
  69.345  	return 0;
  69.346  }
  69.347  
  69.348 @@ -492,8 +442,6 @@ tpmfront_resume(struct xenbus_device *de
  69.349  	struct tpmfront_info *info = dev->data;
  69.350  	int err = talk_to_backend(dev, info);
  69.351  
  69.352 -	/* unlock, so apps can resume sending */
  69.353 -	up(&suspend_lock);
  69.354  
  69.355  	return err;
  69.356  }
  69.357 @@ -530,12 +478,13 @@ static struct xenbus_driver tpmfront = {
  69.358  	.probe = tpmfront_probe,
  69.359  	.remove =  tpmfront_remove,
  69.360  	.resume = tpmfront_resume,
  69.361 +	.otherend_changed = backend_changed,
  69.362  	.suspend = tpmfront_suspend,
  69.363  };
  69.364  
  69.365  static void __init init_tpm_xenbus(void)
  69.366  {
  69.367 -	xenbus_register_driver(&tpmfront);
  69.368 +	xenbus_register_frontend(&tpmfront);
  69.369  }
  69.370  
  69.371  
  69.372 @@ -628,12 +577,13 @@ tpm_xmit(struct tpm_private *tp,
  69.373  	spin_lock_irq(&tp->tx_lock);
  69.374  
  69.375  	if (unlikely(atomic_read(&tp->tx_busy))) {
  69.376 -		printk("There's an outstanding request/response on the way!\n");
  69.377 +		printk("tpm_xmit: There's an outstanding request/response "
  69.378 +		       "on the way!\n");
  69.379  		spin_unlock_irq(&tp->tx_lock);
  69.380  		return -EBUSY;
  69.381  	}
  69.382  
  69.383 -	if (tp->connected != 1) {
  69.384 +	if (tp->is_connected != TRUE) {
  69.385  		spin_unlock_irq(&tp->tx_lock);
  69.386  		return -EIO;
  69.387  	}
  69.388 @@ -705,24 +655,40 @@ static void tpmif_notify_upperlayer(stru
  69.389  	down(&upperlayer_lock);
  69.390  
  69.391  	if (upperlayer_tpmfe != NULL) {
  69.392 -		switch (tp->connected) {
  69.393 -			case 1:
  69.394 -				upperlayer_tpmfe->status(TPMFE_STATUS_CONNECTED);
  69.395 -			break;
  69.396 -
  69.397 -			default:
  69.398 -				upperlayer_tpmfe->status(0);
  69.399 -			break;
  69.400 +		if (tp->is_connected) {
  69.401 +			upperlayer_tpmfe->status(TPMFE_STATUS_CONNECTED);
  69.402 +		} else {
  69.403 +			upperlayer_tpmfe->status(0);
  69.404  		}
  69.405  	}
  69.406  	up(&upperlayer_lock);
  69.407  }
  69.408  
  69.409  
  69.410 -static void tpmif_set_connected_state(struct tpm_private *tp, int newstate)
  69.411 +static void tpmif_set_connected_state(struct tpm_private *tp, u8 is_connected)
  69.412  {
  69.413 -	if (newstate != tp->connected) {
  69.414 -		tp->connected = newstate;
  69.415 +	/*
  69.416 +	 * Don't notify upper layer if we are in suspend mode and
  69.417 +	 * should disconnect - assumption is that we will resume
  69.418 +	 * The semaphore keeps apps from sending.
  69.419 +	 */
  69.420 +	if (is_connected == FALSE && tp->is_suspended == TRUE) {
  69.421 +		return;
  69.422 +	}
  69.423 +
  69.424 +	/*
  69.425 +	 * Unlock the semaphore if we are connected again
  69.426 +	 * after being suspended - now resuming.
  69.427 +	 * This also removes the suspend state.
  69.428 +	 */
  69.429 +	if (is_connected == TRUE && tp->is_suspended == TRUE) {
  69.430 +		tp->is_suspended = FALSE;
  69.431 +		/* unlock, so apps can resume sending */
  69.432 +		up(&suspend_lock);
  69.433 +	}
  69.434 +
  69.435 +	if (is_connected != tp->is_connected) {
  69.436 +		tp->is_connected = is_connected;
  69.437  		tpmif_notify_upperlayer(tp);
  69.438  	}
  69.439  }
    70.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h	Fri Dec 02 12:12:11 2005 -0600
    70.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h	Fri Dec 02 12:52:25 2005 -0600
    70.3 @@ -1,12 +1,17 @@
    70.4  #ifndef TPM_FRONT_H
    70.5  #define TPM_FRONT_H
    70.6  
    70.7 +#ifndef TRUE
    70.8 +#define TRUE 1
    70.9 +#define FALSE 0
   70.10 +#endif
   70.11  
   70.12 -struct tpm_private
   70.13 -{
   70.14 +struct tpm_private {
   70.15  	tpmif_tx_interface_t *tx;
   70.16 -	unsigned int evtchn, irq;
   70.17 -	int connected;
   70.18 +	unsigned int evtchn;
   70.19 +	unsigned int irq;
   70.20 +	u8 is_connected;
   70.21 +	u8 is_suspended;
   70.22  
   70.23  	spinlock_t tx_lock;
   70.24  
   70.25 @@ -16,25 +21,18 @@ struct tpm_private
   70.26  	void *tx_remember;
   70.27  	domid_t backend_id;
   70.28  	wait_queue_head_t wait_q;
   70.29 +
   70.30  };
   70.31  
   70.32 -
   70.33 -struct tpmfront_info
   70.34 -{
   70.35 -	struct xenbus_watch watch;
   70.36 -	int handle;
   70.37 +struct tpmfront_info {
   70.38  	struct xenbus_device *dev;
   70.39 -	char *backend;
   70.40  	int ring_ref;
   70.41 -	domid_t backend_id;
   70.42  };
   70.43  
   70.44 -
   70.45 -struct tx_buffer
   70.46 -{
   70.47 +struct tx_buffer {
   70.48  	unsigned int size;	// available space in data
   70.49  	unsigned int len;	// used space in data
   70.50 -	unsigned char *data;    // pointer to a page
   70.51 +	unsigned char *data;	// pointer to a page
   70.52  };
   70.53  
   70.54  #endif
    71.1 --- a/linux-2.6-xen-sparse/drivers/xen/util.c	Fri Dec 02 12:12:11 2005 -0600
    71.2 +++ b/linux-2.6-xen-sparse/drivers/xen/util.c	Fri Dec 02 12:52:25 2005 -0600
    71.3 @@ -56,7 +56,7 @@ void lock_vm_area(struct vm_struct *area
    71.4  	 * page-fault path will copy the page directory pointers from init_mm.
    71.5  	 */
    71.6  	for (i = 0; i < area->size; i += PAGE_SIZE)
    71.7 -		(void)__get_user(c, (char *)area->addr + i);
    71.8 +		(void)__get_user(c, (char __user *)area->addr + i);
    71.9  }
   71.10  
   71.11  void unlock_vm_area(struct vm_struct *area)
    72.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c	Fri Dec 02 12:12:11 2005 -0600
    72.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c	Fri Dec 02 12:52:25 2005 -0600
    72.3 @@ -97,14 +97,17 @@ int xenbus_switch_state(struct xenbus_de
    72.4  	/* We check whether the state is currently set to the given value, and
    72.5  	   if not, then the state is set.  We don't want to unconditionally
    72.6  	   write the given state, because we don't want to fire watches
    72.7 -	   unnecessarily.
    72.8 +	   unnecessarily.  Furthermore, if the node has gone, we don't write
    72.9 +	   to it, as the device will be tearing down, and we don't want to
   72.10 +	   resurrect that directory.
   72.11  	 */
   72.12  
   72.13  	int current_state;
   72.14  
   72.15  	int err = xenbus_scanf(xbt, dev->nodename, "state", "%d",
   72.16  			       &current_state);
   72.17 -	if (err == 1 && (XenbusState)current_state == state)
   72.18 +	if ((err == 1 && (XenbusState)current_state == state) ||
   72.19 +	    err == -ENOENT)
   72.20  		return 0;
   72.21  
   72.22  	err = xenbus_printf(xbt, dev->nodename, "state", "%d", state);
    73.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/system.h	Fri Dec 02 12:12:11 2005 -0600
    73.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/system.h	Fri Dec 02 12:52:25 2005 -0600
    73.3 @@ -501,7 +501,7 @@ unsigned long __set_mb_temp;            
    73.4  do {									\
    73.5  	vcpu_info_t *_vcpu;						\
    73.6  	preempt_disable();						\
    73.7 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
    73.8 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
    73.9  	_vcpu->evtchn_upcall_mask = 1;					\
   73.10  	preempt_enable_no_resched();					\
   73.11  	barrier();							\
   73.12 @@ -512,7 +512,7 @@ do {									\
   73.13  	vcpu_info_t *_vcpu;						\
   73.14  	barrier();							\
   73.15  	preempt_disable();						\
   73.16 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   73.17 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
   73.18  	_vcpu->evtchn_upcall_mask = 0;					\
   73.19  	barrier(); /* unmask then check (avoid races) */		\
   73.20  	if ( unlikely(_vcpu->evtchn_upcall_pending) )			\
   73.21 @@ -524,7 +524,7 @@ do {									\
   73.22  do {									\
   73.23  	vcpu_info_t *_vcpu;						\
   73.24  	preempt_disable();						\
   73.25 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   73.26 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
   73.27  	(x) = _vcpu->evtchn_upcall_mask;				\
   73.28  	preempt_enable();						\
   73.29  } while (0)
   73.30 @@ -534,7 +534,7 @@ do {									\
   73.31  	vcpu_info_t *_vcpu;						\
   73.32  	barrier();							\
   73.33  	preempt_disable();						\
   73.34 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   73.35 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
   73.36  	if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {			\
   73.37  		barrier(); /* unmask then check (avoid races) */	\
   73.38  		if ( unlikely(_vcpu->evtchn_upcall_pending) )		\
   73.39 @@ -550,7 +550,7 @@ do {									\
   73.40  do {									\
   73.41  	vcpu_info_t *_vcpu;						\
   73.42  	preempt_disable();						\
   73.43 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   73.44 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
   73.45  	(x) = _vcpu->evtchn_upcall_mask;				\
   73.46  	_vcpu->evtchn_upcall_mask = 1;					\
   73.47  	preempt_enable_no_resched();					\
   73.48 @@ -568,7 +568,7 @@ do {									\
   73.49  ({	int ___x;							\
   73.50  	vcpu_info_t *_vcpu;						\
   73.51  	preempt_disable();						\
   73.52 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   73.53 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
   73.54  	___x = (_vcpu->evtchn_upcall_mask != 0);			\
   73.55  	preempt_enable_no_resched();					\
   73.56  	___x; })
    74.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/system.h	Fri Dec 02 12:12:11 2005 -0600
    74.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/system.h	Fri Dec 02 12:52:25 2005 -0600
    74.3 @@ -325,7 +325,7 @@ static inline unsigned long __cmpxchg(vo
    74.4  do {									\
    74.5  	vcpu_info_t *_vcpu;						\
    74.6  	preempt_disable();						\
    74.7 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
    74.8 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
    74.9  	_vcpu->evtchn_upcall_mask = 1;					\
   74.10  	preempt_enable_no_resched();					\
   74.11  	barrier();							\
   74.12 @@ -336,7 +336,7 @@ do {									\
   74.13  	vcpu_info_t *_vcpu;						\
   74.14  	barrier();							\
   74.15  	preempt_disable();						\
   74.16 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   74.17 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
   74.18  	_vcpu->evtchn_upcall_mask = 0;					\
   74.19  	barrier(); /* unmask then check (avoid races) */		\
   74.20  	if ( unlikely(_vcpu->evtchn_upcall_pending) )			\
   74.21 @@ -348,7 +348,7 @@ do {									\
   74.22  do {									\
   74.23  	vcpu_info_t *_vcpu;						\
   74.24  	preempt_disable();						\
   74.25 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   74.26 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
   74.27  	(x) = _vcpu->evtchn_upcall_mask;				\
   74.28  	preempt_enable();						\
   74.29  } while (0)
   74.30 @@ -358,7 +358,7 @@ do {									\
   74.31  	vcpu_info_t *_vcpu;						\
   74.32  	barrier();							\
   74.33  	preempt_disable();						\
   74.34 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   74.35 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
   74.36  	if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {			\
   74.37  		barrier(); /* unmask then check (avoid races) */	\
   74.38  		if ( unlikely(_vcpu->evtchn_upcall_pending) )		\
   74.39 @@ -374,7 +374,7 @@ do {									\
   74.40  do {									\
   74.41  	vcpu_info_t *_vcpu;						\
   74.42  	preempt_disable();						\
   74.43 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   74.44 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
   74.45  	(x) = _vcpu->evtchn_upcall_mask;				\
   74.46  	_vcpu->evtchn_upcall_mask = 1;					\
   74.47  	preempt_enable_no_resched();					\
   74.48 @@ -394,7 +394,7 @@ void cpu_idle_wait(void);
   74.49  ({	int ___x;							\
   74.50  	vcpu_info_t *_vcpu;						\
   74.51  	preempt_disable();						\
   74.52 -	_vcpu = &HYPERVISOR_shared_info->vcpu_data[smp_processor_id()];	\
   74.53 +	_vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()];	\
   74.54  	___x = (_vcpu->evtchn_upcall_mask != 0);			\
   74.55  	preempt_enable_no_resched();					\
   74.56  	___x; })
    75.1 --- a/linux-2.6-xen-sparse/include/asm-xen/evtchn.h	Fri Dec 02 12:12:11 2005 -0600
    75.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/evtchn.h	Fri Dec 02 12:52:25 2005 -0600
    75.3 @@ -102,7 +102,7 @@ static inline void mask_evtchn(int port)
    75.4  static inline void unmask_evtchn(int port)
    75.5  {
    75.6  	shared_info_t *s = HYPERVISOR_shared_info;
    75.7 -	vcpu_info_t *vcpu_info = &s->vcpu_data[smp_processor_id()];
    75.8 +	vcpu_info_t *vcpu_info = &s->vcpu_info[smp_processor_id()];
    75.9  
   75.10  	synch_clear_bit(port, &s->evtchn_mask[0]);
   75.11  
    76.1 --- a/linux-2.6-xen-sparse/include/asm-xen/linux-public/privcmd.h	Fri Dec 02 12:12:11 2005 -0600
    76.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/linux-public/privcmd.h	Fri Dec 02 12:52:25 2005 -0600
    76.3 @@ -30,6 +30,10 @@
    76.4  #ifndef __LINUX_PUBLIC_PRIVCMD_H__
    76.5  #define __LINUX_PUBLIC_PRIVCMD_H__
    76.6  
    76.7 +#ifndef __user
    76.8 +#define __user
    76.9 +#endif
   76.10 +
   76.11  typedef struct privcmd_hypercall
   76.12  {
   76.13  	unsigned long op;
   76.14 @@ -45,21 +49,16 @@ typedef struct privcmd_mmap_entry {
   76.15  typedef struct privcmd_mmap {
   76.16  	int num;
   76.17  	domid_t dom; /* target domain */
   76.18 -	privcmd_mmap_entry_t *entry;
   76.19 +	privcmd_mmap_entry_t __user *entry;
   76.20  } privcmd_mmap_t; 
   76.21  
   76.22  typedef struct privcmd_mmapbatch {
   76.23  	int num;     /* number of pages to populate */
   76.24  	domid_t dom; /* target domain */
   76.25  	unsigned long addr;  /* virtual address */
   76.26 -	unsigned long *arr; /* array of mfns - top nibble set on err */
   76.27 +	unsigned long __user *arr; /* array of mfns - top nibble set on err */
   76.28  } privcmd_mmapbatch_t; 
   76.29  
   76.30 -typedef struct privcmd_m2pmfns { 
   76.31 -	int num;    /* max number of mfns to return */
   76.32 -	unsigned long *arr; /* array of mfns */
   76.33 -} privcmd_m2pmfns_t; 
   76.34 -
   76.35  typedef struct privcmd_blkmsg
   76.36  {
   76.37  	unsigned long op;
   76.38 @@ -78,8 +77,6 @@ typedef struct privcmd_blkmsg
   76.39  	_IOC(_IOC_NONE, 'P', 2, sizeof(privcmd_mmap_t))
   76.40  #define IOCTL_PRIVCMD_MMAPBATCH					\
   76.41  	_IOC(_IOC_NONE, 'P', 3, sizeof(privcmd_mmapbatch_t))
   76.42 -#define IOCTL_PRIVCMD_GET_MACH2PHYS_MFNS			\
   76.43 -	_IOC(_IOC_READ, 'P', 4, sizeof(unsigned long))
   76.44  
   76.45  #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
   76.46  
    77.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/tpmfe.h	Fri Dec 02 12:52:25 2005 -0600
    77.3 @@ -0,0 +1,33 @@
    77.4 +#ifndef TPM_FE_H
    77.5 +#define TPM_FE_H
    77.6 +
    77.7 +struct tpmfe_device {
    77.8 +	/*
    77.9 +	 * Let upper layer receive data from front-end
   77.10 +	 */
   77.11 +	int (*receive)(const u8 *buffer, size_t count, const void *ptr);
   77.12 +	/*
   77.13 +	 * Indicate the status of the front-end to the upper
   77.14 +	 * layer.
   77.15 +	 */
   77.16 +	void (*status)(unsigned int flags);
   77.17 +
   77.18 +	/*
   77.19 +	 * This field indicates the maximum size the driver can
   77.20 +	 * transfer in one chunk. It is filled out by the front-end
   77.21 +	 * driver and should be propagated to the generic tpm driver
   77.22 +	 * for allocation of buffers.
   77.23 +	 */
   77.24 +	unsigned int max_tx_size;
   77.25 +};
   77.26 +
   77.27 +enum {
   77.28 +	TPMFE_STATUS_DISCONNECTED = 0x0,
   77.29 +	TPMFE_STATUS_CONNECTED = 0x1
   77.30 +};
   77.31 +
   77.32 +int tpm_fe_send(const u8 * buf, size_t count, void *ptr);
   77.33 +int tpm_fe_register_receiver(struct tpmfe_device *);
   77.34 +void tpm_fe_unregister_receiver(void);
   77.35 +
   77.36 +#endif
    78.1 --- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h	Fri Dec 02 12:12:11 2005 -0600
    78.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h	Fri Dec 02 12:52:25 2005 -0600
    78.3 @@ -4,6 +4,7 @@
    78.4   * Talks to Xen Store to figure out what devices we have.
    78.5   *
    78.6   * Copyright (C) 2005 Rusty Russell, IBM Corporation
    78.7 + * Copyright (C) 2005 XenSource Ltd.
    78.8   * 
    78.9   * This file may be distributed separately from the Linux kernel, or
   78.10   * incorporated into other software packages, subject to the following license:
   78.11 @@ -33,6 +34,7 @@
   78.12  #include <linux/device.h>
   78.13  #include <linux/notifier.h>
   78.14  #include <asm/semaphore.h>
   78.15 +#include <asm-xen/xen-public/io/xenbus.h>
   78.16  #include <asm-xen/xen-public/io/xs_wire.h>
   78.17  
   78.18  /* Register callback to watch this node. */
   78.19 @@ -49,27 +51,6 @@ struct xenbus_watch
   78.20  };
   78.21  
   78.22  
   78.23 -/* The state of either end of the Xenbus, i.e. the current communication
   78.24 -   status of initialisation across the bus.  States here imply nothing about
   78.25 -   the state of the connection between the driver and the kernel's device
   78.26 -   layers.  */
   78.27 -typedef enum
   78.28 -{
   78.29 -  XenbusStateUnknown      = 0,
   78.30 -  XenbusStateInitialising = 1,
   78.31 -  XenbusStateInitWait     = 2,  /* Finished early initialisation, but waiting
   78.32 -                                   for information from the peer or hotplug
   78.33 -				   scripts. */
   78.34 -  XenbusStateInitialised  = 3,  /* Initialised and waiting for a connection
   78.35 -				   from the peer. */
   78.36 -  XenbusStateConnected    = 4,
   78.37 -  XenbusStateClosing      = 5,  /* The device is being closed due to an error
   78.38 -				   or an unplug event. */
   78.39 -  XenbusStateClosed       = 6
   78.40 -
   78.41 -} XenbusState;
   78.42 -
   78.43 -
   78.44  /* A xenbus device. */
   78.45  struct xenbus_device {
   78.46  	const char *devicetype;
    79.1 --- a/linux-2.6-xen-sparse/include/asm-xen/xencons.h	Fri Dec 02 12:12:11 2005 -0600
    79.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/xencons.h	Fri Dec 02 12:52:25 2005 -0600
    79.3 @@ -4,4 +4,11 @@
    79.4  void xencons_force_flush(void);
    79.5  void xencons_resume(void);
    79.6  
    79.7 +/* Interrupt work hooks. Receive data, or kick data out. */
    79.8 +void xencons_rx(char *buf, unsigned len, struct pt_regs *regs);
    79.9 +void xencons_tx(void);
   79.10 +
   79.11 +int xencons_ring_init(void);
   79.12 +int xencons_ring_send(const char *data, unsigned len);
   79.13 +
   79.14  #endif /* __ASM_XENCONS_H__ */
    80.1 --- a/linux-2.6-xen-sparse/include/linux/tpmfe.h	Fri Dec 02 12:12:11 2005 -0600
    80.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.3 @@ -1,33 +0,0 @@
    80.4 -#ifndef TPM_FE_H
    80.5 -#define TPM_FE_H
    80.6 -
    80.7 -struct tpmfe_device {
    80.8 -	/*
    80.9 -	 * Let upper layer receive data from front-end
   80.10 -	 */
   80.11 -	int (*receive)(const u8 *buffer, size_t count, const void *ptr);
   80.12 -	/*
   80.13 -	 * Indicate the status of the front-end to the upper
   80.14 -	 * layer.
   80.15 -	 */
   80.16 -	void (*status)(unsigned int flags);
   80.17 -
   80.18 -	/*
   80.19 -	 * This field indicates the maximum size the driver can
   80.20 -	 * transfer in one chunk. It is filled out by the front-end
   80.21 -	 * driver and should be propagated to the generic tpm driver
   80.22 -	 * for allocation of buffers.
   80.23 -	 */
   80.24 -	unsigned int max_tx_size;
   80.25 -};
   80.26 -
   80.27 -enum {
   80.28 -	TPMFE_STATUS_DISCONNECTED = 0x0,
   80.29 -	TPMFE_STATUS_CONNECTED = 0x1
   80.30 -};
   80.31 -
   80.32 -int tpm_fe_send(const u8 * buf, size_t count, void *ptr);
   80.33 -int tpm_fe_register_receiver(struct tpmfe_device *);
   80.34 -void tpm_fe_unregister_receiver(void);
   80.35 -
   80.36 -#endif
    81.1 --- a/linux-2.6-xen-sparse/net/core/dev.c	Fri Dec 02 12:12:11 2005 -0600
    81.2 +++ b/linux-2.6-xen-sparse/net/core/dev.c	Fri Dec 02 12:52:25 2005 -0600
    81.3 @@ -1283,6 +1283,11 @@ int dev_queue_xmit(struct sk_buff *skb)
    81.4  			skb->csum = offsetof(struct udphdr, check);
    81.5  			break;
    81.6  		default:
    81.7 +			if (net_ratelimit())
    81.8 +				printk(KERN_ERR "Attempting to checksum a non-"
    81.9 +				       "TCP/UDP packet, dropping a protocol"
   81.10 +				       " %d packet", skb->nh.iph->protocol);
   81.11 +			rc = -EPROTO;
   81.12  			goto out_kfree_skb;
   81.13  		}
   81.14  		if ((skb->h.raw + skb->csum + 2) > skb->tail)
    82.1 --- a/patches/linux-2.6.12/pmd-shared.patch	Fri Dec 02 12:12:11 2005 -0600
    82.2 +++ b/patches/linux-2.6.12/pmd-shared.patch	Fri Dec 02 12:52:25 2005 -0600
    82.3 @@ -1,15 +1,3 @@
    82.4 -diff -urNpP linux-2.6.12/arch/i386/mm/init.c linux-2.6.12.new/arch/i386/mm/init.c
    82.5 ---- linux-2.6.12/arch/i386/mm/init.c	2005-06-17 20:48:29.000000000 +0100
    82.6 -+++ linux-2.6.12.new/arch/i386/mm/init.c	2005-07-11 16:28:09.778165582 +0100
    82.7 -@@ -634,7 +634,7 @@ void __init pgtable_cache_init(void)
    82.8 - 				PTRS_PER_PGD*sizeof(pgd_t),
    82.9 - 				0,
   82.10 - 				pgd_ctor,
   82.11 --				PTRS_PER_PMD == 1 ? pgd_dtor : NULL);
   82.12 -+				pgd_dtor);
   82.13 - 	if (!pgd_cache)
   82.14 - 		panic("pgtable_cache_init(): Cannot create pgd cache");
   82.15 - }
   82.16  diff -urNpP linux-2.6.12/arch/i386/mm/pageattr.c linux-2.6.12.new/arch/i386/mm/pageattr.c
   82.17  --- linux-2.6.12/arch/i386/mm/pageattr.c	2005-06-17 20:48:29.000000000 +0100
   82.18  +++ linux-2.6.12.new/arch/i386/mm/pageattr.c	2005-07-11 16:28:09.775165494 +0100
   82.19 @@ -23,72 +11,73 @@ diff -urNpP linux-2.6.12/arch/i386/mm/pa
   82.20   
   82.21   	spin_lock_irqsave(&pgd_lock, flags);
   82.22  diff -urNpP linux-2.6.12/arch/i386/mm/pgtable.c linux-2.6.12.new/arch/i386/mm/pgtable.c
   82.23 ---- linux-2.6.12/arch/i386/mm/pgtable.c	2005-06-17 20:48:29.000000000 +0100
   82.24 -+++ linux-2.6.12.new/arch/i386/mm/pgtable.c	2005-07-11 16:32:01.478023726 +0100
   82.25 -@@ -199,14 +199,14 @@ void pgd_ctor(void *pgd, kmem_cache_t *c
   82.26 +--- linux-2.6.12/arch/i386/mm/pgtable.c	2005-11-26 09:55:10.000000000 +0000
   82.27 ++++ linux-2.6.12.new/arch/i386/mm/pgtable.c	2005-11-26 10:20:36.000000000 +0000
   82.28 +@@ -199,19 +199,20 @@ void pgd_ctor(void *pgd, kmem_cache_t *c
   82.29   {
   82.30   	unsigned long flags;
   82.31   
   82.32  -	if (PTRS_PER_PMD == 1)
   82.33 -+	if (!HAVE_SHARED_KERNEL_PMD)
   82.34 ++	if (PTRS_PER_PMD > 1) {
   82.35 ++		if (HAVE_SHARED_KERNEL_PMD)
   82.36 ++			memcpy((pgd_t *)pgd + USER_PTRS_PER_PGD,
   82.37 ++			       swapper_pg_dir + USER_PTRS_PER_PGD,
   82.38 ++			       (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
   82.39 ++	} else {
   82.40   		spin_lock_irqsave(&pgd_lock, flags);
   82.41 - 
   82.42 - 	memcpy((pgd_t *)pgd + USER_PTRS_PER_PGD,
   82.43 - 			swapper_pg_dir + USER_PTRS_PER_PGD,
   82.44 - 			(PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
   82.45 - 
   82.46 +-
   82.47 +-	memcpy((pgd_t *)pgd + USER_PTRS_PER_PGD,
   82.48 +-			swapper_pg_dir + USER_PTRS_PER_PGD,
   82.49 +-			(PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
   82.50 +-
   82.51  -	if (PTRS_PER_PMD > 1)
   82.52 -+	if (HAVE_SHARED_KERNEL_PMD)
   82.53 - 		return;
   82.54 - 
   82.55 - 	pgd_list_add(pgd);
   82.56 -@@ -214,11 +214,13 @@ void pgd_ctor(void *pgd, kmem_cache_t *c
   82.57 - 	memset(pgd, 0, USER_PTRS_PER_PGD*sizeof(pgd_t));
   82.58 +-		return;
   82.59 +-
   82.60 +-	pgd_list_add(pgd);
   82.61 +-	spin_unlock_irqrestore(&pgd_lock, flags);
   82.62 +-	memset(pgd, 0, USER_PTRS_PER_PGD*sizeof(pgd_t));
   82.63 ++		memcpy((pgd_t *)pgd + USER_PTRS_PER_PGD,
   82.64 ++		       swapper_pg_dir + USER_PTRS_PER_PGD,
   82.65 ++		       (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
   82.66 ++		memset(pgd, 0, USER_PTRS_PER_PGD*sizeof(pgd_t));
   82.67 ++		pgd_list_add(pgd);
   82.68 ++		spin_unlock_irqrestore(&pgd_lock, flags);
   82.69 ++	}
   82.70   }
   82.71   
   82.72 --/* never called when PTRS_PER_PMD > 1 */
   82.73 - void pgd_dtor(void *pgd, kmem_cache_t *cache, unsigned long unused)
   82.74 - {
   82.75 - 	unsigned long flags; /* can be called from interrupt context */
   82.76 - 
   82.77 -+	if (HAVE_SHARED_KERNEL_PMD)
   82.78 -+		return;
   82.79 + /* never called when PTRS_PER_PMD > 1 */
   82.80 +@@ -238,6 +239,30 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
   82.81 + 			goto out_oom;
   82.82 + 		set_pgd(&pgd[i], __pgd(1 + __pa(pmd)));
   82.83 + 	}
   82.84  +
   82.85 - 	spin_lock_irqsave(&pgd_lock, flags);
   82.86 - 	pgd_list_del(pgd);
   82.87 - 	spin_unlock_irqrestore(&pgd_lock, flags);
   82.88 -@@ -226,12 +228,29 @@ void pgd_dtor(void *pgd, kmem_cache_t *c
   82.89 - 
   82.90 - pgd_t *pgd_alloc(struct mm_struct *mm)
   82.91 - {
   82.92 --	int i;
   82.93 -+	int i = 0;
   82.94 - 	pgd_t *pgd = kmem_cache_alloc(pgd_cache, GFP_KERNEL);
   82.95 - 
   82.96 - 	if (PTRS_PER_PMD == 1 || !pgd)
   82.97 - 		return pgd;
   82.98 - 
   82.99  +	if (!HAVE_SHARED_KERNEL_PMD) {
  82.100 -+		/* alloc and copy kernel pmd */
  82.101  +		unsigned long flags;
  82.102 -+		pgd_t *copy_pgd = pgd_offset_k(PAGE_OFFSET);
  82.103 -+		pud_t *copy_pud = pud_offset(copy_pgd, PAGE_OFFSET);
  82.104 -+		pmd_t *copy_pmd = pmd_offset(copy_pud, PAGE_OFFSET);
  82.105 -+		pmd_t *pmd = kmem_cache_alloc(pmd_cache, GFP_KERNEL);
  82.106 -+		if (0 == pmd)
  82.107 -+			goto out_oom;
  82.108 ++
  82.109 ++		for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
  82.110 ++			pmd_t *pmd = kmem_cache_alloc(pmd_cache, GFP_KERNEL);
  82.111 ++			if (!pmd)
  82.112 ++				goto out_oom;
  82.113 ++			set_pgd(&pgd[USER_PTRS_PER_PGD], __pgd(1 + __pa(pmd)));
  82.114 ++		}
  82.115  +
  82.116  +		spin_lock_irqsave(&pgd_lock, flags);
  82.117 -+		memcpy(pmd, copy_pmd, PAGE_SIZE);
  82.118 ++		for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
  82.119 ++			unsigned long v = (unsigned long)i << PGDIR_SHIFT;
  82.120 ++			pgd_t *kpgd = pgd_offset_k(v);
  82.121 ++			pud_t *kpud = pud_offset(kpgd, v);
  82.122 ++			pmd_t *kpmd = pmd_offset(kpud, v);
  82.123 ++			pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
  82.124 ++			memcpy(pmd, kpmd, PAGE_SIZE);
  82.125 ++		}
  82.126 ++		pgd_list_add(pgd);
  82.127  +		spin_unlock_irqrestore(&pgd_lock, flags);
  82.128 -+		set_pgd(&pgd[USER_PTRS_PER_PGD], __pgd(1 + __pa(pmd)));
  82.129  +	}
  82.130  +
  82.131 -+	/* alloc user pmds */
  82.132 - 	for (i = 0; i < USER_PTRS_PER_PGD; ++i) {
  82.133 - 		pmd_t *pmd = kmem_cache_alloc(pmd_cache, GFP_KERNEL);
  82.134 - 		if (!pmd)
  82.135 -@@ -252,9 +271,16 @@ void pgd_free(pgd_t *pgd)
  82.136 + 	return pgd;
  82.137 + 
  82.138 + out_oom:
  82.139 +@@ -252,9 +277,23 @@ void pgd_free(pgd_t *pgd)
  82.140   	int i;
  82.141   
  82.142   	/* in the PAE case user pgd entries are overwritten before usage */
  82.143 @@ -101,8 +90,15 @@ diff -urNpP linux-2.6.12/arch/i386/mm/pg
  82.144  +			kmem_cache_free(pmd_cache, pmd);
  82.145  +		}
  82.146  +		if (!HAVE_SHARED_KERNEL_PMD) {
  82.147 -+			pmd_t *pmd = (void *)__va(pgd_val(pgd[USER_PTRS_PER_PGD])-1);
  82.148 -+			kmem_cache_free(pmd_cache, pmd);
  82.149 ++			unsigned long flags;
  82.150 ++			spin_lock_irqsave(&pgd_lock, flags);
  82.151 ++			pgd_list_del(pgd);
  82.152 ++			spin_unlock_irqrestore(&pgd_lock, flags);
  82.153 ++			for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
  82.154 ++				pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
  82.155 ++				memset(pmd, 0, PTRS_PER_PMD*sizeof(pmd_t));
  82.156 ++				kmem_cache_free(pmd_cache, pmd);
  82.157 ++			}
  82.158  +		}
  82.159  +	}
  82.160   	/* in the non-PAE case, free_pgtables() clears user pgd entries */
    83.1 --- a/tools/Rules.mk	Fri Dec 02 12:12:11 2005 -0600
    83.2 +++ b/tools/Rules.mk	Fri Dec 02 12:52:25 2005 -0600
    83.3 @@ -1,5 +1,8 @@
    83.4  #  -*- mode: Makefile; -*-
    83.5  
    83.6 +# `all' is the default target
    83.7 +all:
    83.8 +
    83.9  include $(XEN_ROOT)/Config.mk
   83.10  
   83.11  XEN_XC             = $(XEN_ROOT)/tools/python/xen/lowlevel/xc
   83.12 @@ -27,3 +30,13 @@ X11_LDPATH = -L/usr/X11R6/$(LIBDIR)
   83.13  
   83.14  %.o: %.cc
   83.15  	$(CC) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
   83.16 +
   83.17 +mk-symlinks: LINUX_ROOT=$(XEN_ROOT)/linux-2.6-xen-sparse
   83.18 +mk-symlinks:
   83.19 +	mkdir -p xen
   83.20 +	( cd xen && ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
   83.21 +	mkdir -p xen/io
   83.22 +	( cd xen/io && ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
   83.23 +	mkdir -p xen/linux
   83.24 +	( cd xen/linux && \
   83.25 +	  ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
    84.1 --- a/tools/blktap/Makefile	Fri Dec 02 12:12:11 2005 -0600
    84.2 +++ b/tools/blktap/Makefile	Fri Dec 02 12:52:25 2005 -0600
    84.3 @@ -47,17 +47,6 @@ all: mk-symlinks libblktap.so #blkdump
    84.4  		$(MAKE) -C $$subdir $@;       \
    84.5  	done
    84.6  
    84.7 -LINUX_ROOT := $(wildcard $(XEN_ROOT)/linux-2.6.*-xen-sparse)
    84.8 -mk-symlinks:
    84.9 -	[ -e xen/linux ] || mkdir -p xen/linux
   84.10 -	[ -e xen/io ]    || mkdir -p xen/io
   84.11 -	( cd xen >/dev/null ; \
   84.12 -	  ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
   84.13 -	( cd xen/io >/dev/null ; \
   84.14 -	   ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
   84.15 -	( cd xen/linux >/dev/null ; \
   84.16 -	  ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
   84.17 -
   84.18  install: all
   84.19  	$(INSTALL_DIR) -p $(DESTDIR)/usr/$(LIBDIR)
   84.20  	$(INSTALL_DIR) -p $(DESTDIR)/usr/include
    85.1 --- a/tools/blktap/blkdump.c	Fri Dec 02 12:12:11 2005 -0600
    85.2 +++ b/tools/blktap/blkdump.c	Fri Dec 02 12:52:25 2005 -0600
    85.3 @@ -11,7 +11,6 @@
    85.4  int request_print(blkif_request_t *req)
    85.5  {
    85.6      int i;
    85.7 -    unsigned long fas;
    85.8      
    85.9      if ( (req->operation == BLKIF_OP_READ) ||
   85.10           (req->operation == BLKIF_OP_WRITE) )
   85.11 @@ -24,12 +23,10 @@ int request_print(blkif_request_t *req)
   85.12          
   85.13          
   85.14          for (i=0; i < req->nr_segments; i++) {
   85.15 -            fas = req->frame_and_sects[i];
   85.16 -            printf("              (pf: 0x%8lx start: %lu stop: %lu)\n",
   85.17 -                    (fas & PAGE_MASK),
   85.18 -                    blkif_first_sect(fas),
   85.19 -                    blkif_last_sect(fas)
   85.20 -                    );
   85.21 +            printf("              (gref: 0x%8x start: %u stop: %u)\n",
   85.22 +                   req->seg[i].gref,
   85.23 +                   req->seg[i].first_sect,
   85.24 +                   req->seg[i].last_sect);
   85.25          }
   85.26              
   85.27      } else {
    86.1 --- a/tools/blktap/blktaplib.c	Fri Dec 02 12:12:11 2005 -0600
    86.2 +++ b/tools/blktap/blktaplib.c	Fri Dec 02 12:52:25 2005 -0600
    86.3 @@ -244,8 +244,8 @@ int blktap_listen(void)
    86.4      RING_IDX          rp, i, pfd_count; 
    86.5      
    86.6      /* pending rings */
    86.7 -    blkif_request_t req_pending[BLKIF_RING_SIZE];
    86.8 -    /* blkif_response_t rsp_pending[BLKIF_RING_SIZE] */;
    86.9 +    blkif_request_t req_pending[BLK_RING_SIZE];
   86.10 +    /* blkif_response_t rsp_pending[BLK_RING_SIZE] */;
   86.11      
   86.12      /* handler hooks: */
   86.13      request_hook_t   *req_hook;
    87.1 --- a/tools/blktap/blktaplib.h	Fri Dec 02 12:12:11 2005 -0600
    87.2 +++ b/tools/blktap/blktaplib.h	Fri Dec 02 12:52:25 2005 -0600
    87.3 @@ -18,11 +18,13 @@
    87.4  #include <xen/io/domain_controller.h>
    87.5  #include <xs.h>
    87.6  
    87.7 +#define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
    87.8 +
    87.9  /* /dev/xen/blktap resides at device number major=10, minor=202        */ 
   87.10  #define BLKTAP_MINOR 202
   87.11  
   87.12  /* size of the extra VMA area to map in attached pages. */
   87.13 -#define BLKTAP_VMA_PAGES BLKIF_RING_SIZE
   87.14 +#define BLKTAP_VMA_PAGES BLK_RING_SIZE
   87.15  
   87.16  /* blktap IOCTLs:                                                      */
   87.17  #define BLKTAP_IOCTL_KICK_FE         1
    88.1 --- a/tools/blktap/parallax/parallax.c	Fri Dec 02 12:12:11 2005 -0600
    88.2 +++ b/tools/blktap/parallax/parallax.c	Fri Dec 02 12:52:25 2005 -0600
    88.3 @@ -280,8 +280,7 @@ int parallax_probe(blkif_request_t *req,
    88.4        goto err;
    88.5  
    88.6      /* Make sure the buffer is page-sized. */
    88.7 -    if ( (blkif_first_sect(req->frame_and_sects[0]) != 0) ||
    88.8 -       (blkif_last_sect (req->frame_and_sects[0]) != 7) )
    88.9 +    if ( (req->seg[0].first_sect != 0) || (req->seg[0].last_sect != 7) )
   88.10        goto err;
   88.11  
   88.12      /* fill the list of devices */
   88.13 @@ -350,17 +349,16 @@ static void read_cb(struct io_ret r, voi
   88.14      /* Calculate read size and offset within the read block. */
   88.15  
   88.16      offset = (param->sector << SECTOR_SHIFT) % BLOCK_SIZE;
   88.17 -    size = ( blkif_last_sect (req->frame_and_sects[segment]) -
   88.18 -             blkif_first_sect(req->frame_and_sects[segment]) + 1
   88.19 -        ) << SECTOR_SHIFT;
   88.20 -    start = blkif_first_sect(req->frame_and_sects[segment]) 
   88.21 -        << SECTOR_SHIFT;
   88.22 +    size = (req->seg[segment].last_sect - req->seg[segment].first_sect + 1) <<
   88.23 +        SECTOR_SHIFT;
   88.24 +    start = req->seg[segment].first_sect << SECTOR_SHIFT;
   88.25  
   88.26      DPRINTF("ParallaxRead: sect: %lld (%ld,%ld),  "
   88.27              "vblock %llx, "
   88.28              "size %lx\n", 
   88.29 -            param->sector, blkif_first_sect(p->req->frame_and_sects[segment]),
   88.30 -            blkif_last_sect (p->req->frame_and_sects[segment]),
   88.31 +            param->sector,
   88.32 +            p->req->seg[segment].first_sect,
   88.33 +            p->req->seg[segment].last_sect,
   88.34              param->vblock, size); 
   88.35  
   88.36      memcpy(dpage + start, spage + offset, size);
   88.37 @@ -506,16 +504,15 @@ int parallax_write(blkif_request_t *req,
   88.38          /* Calculate read size and offset within the read block. */
   88.39          
   88.40          offset = (sector << SECTOR_SHIFT) % BLOCK_SIZE;
   88.41 -        size = ( blkif_last_sect (req->frame_and_sects[i]) -
   88.42 -                 blkif_first_sect(req->frame_and_sects[i]) + 1
   88.43 -            ) << SECTOR_SHIFT;
   88.44 -        start = blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT;
   88.45 +        size = (req->seg[i].last_sect - req->seg[i].first_sect + 1) <<
   88.46 +            SECTOR_SHIFT;
   88.47 +        start = req->seg[i].first_sect << SECTOR_SHIFT;
   88.48  
   88.49          DPRINTF("ParallaxWrite: sect: %lld (%ld,%ld),  "
   88.50                  "vblock %llx, gblock %llx, "
   88.51                  "size %lx\n", 
   88.52 -                sector, blkif_first_sect(req->frame_and_sects[i]),
   88.53 -                blkif_last_sect (req->frame_and_sects[i]),
   88.54 +                sector, 
   88.55 +                req->seg[i].first_sect, req->seg[i].last_sect,
   88.56                  vblock, gblock, size); 
   88.57        
   88.58          /* XXX: For now we just freak out if they try to write a   */
    89.1 --- a/tools/blktap/ublkback/ublkbacklib.c	Fri Dec 02 12:12:11 2005 -0600
    89.2 +++ b/tools/blktap/ublkback/ublkbacklib.c	Fri Dec 02 12:52:25 2005 -0600
    89.3 @@ -233,8 +233,7 @@ int ublkback_request(blkif_t *blkif, blk
    89.4      case BLKIF_OP_WRITE:
    89.5      {
    89.6          unsigned long size;
    89.7 -        
    89.8 -        
    89.9 +
   89.10          batch_count++;
   89.11  
   89.12          idx = ID_TO_IDX(req->id);
   89.13 @@ -247,18 +246,17 @@ int ublkback_request(blkif_t *blkif, blk
   89.14              
   89.15              sector = req->sector_number + (8*i);
   89.16              
   89.17 -            size = blkif_last_sect (req->frame_and_sects[i]) -
   89.18 -                   blkif_first_sect(req->frame_and_sects[i]) + 1;
   89.19 +            size = req->seg[i].last_sect - req->seg[i].first_sect + 1;
   89.20              
   89.21 -            if (blkif_first_sect(req->frame_and_sects[i]) != 0)
   89.22 -            DPRINTF("iWR: sec_nr: %10llu sec: %10llu (%1lu,%1lu) pos: %15lu\n",
   89.23 -                    req->sector_number, sector, 
   89.24 -                    blkif_first_sect(req->frame_and_sects[i]),
   89.25 -                    blkif_last_sect (req->frame_and_sects[i]),
   89.26 -                    (long)(sector << SECTOR_SHIFT));
   89.27 +            if (req->seg[i].first_sect != 0)
   89.28 +                DPRINTF("iWR: sec_nr: %10llu sec: %10llu (%1lu,%1lu) "
   89.29 +                        "pos: %15lu\n",
   89.30 +                        req->sector_number, sector, 
   89.31 +                        req->seg[i].first_sect, req->seg[i].last_sect,
   89.32 +                        (long)(sector << SECTOR_SHIFT));
   89.33                          
   89.34              spage  = (char *)MMAP_VADDR(ID_TO_IDX(req->id), i);
   89.35 -            spage += blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT;
   89.36 +            spage += req->seg[i].first_sect << SECTOR_SHIFT;
   89.37              
   89.38              /*convert size and sector to byte offsets */
   89.39              size   <<= SECTOR_SHIFT;
   89.40 @@ -297,19 +295,17 @@ int ublkback_request(blkif_t *blkif, blk
   89.41              
   89.42              sector  = req->sector_number + (8*i);
   89.43              
   89.44 -            size = blkif_last_sect (req->frame_and_sects[i]) -
   89.45 -                   blkif_first_sect(req->frame_and_sects[i]) + 1;
   89.46 -            
   89.47 +            size = req->seg[i].last_sect - req->seg[i].first_sect + 1;
   89.48 +
   89.49              dpage  = (char *)MMAP_VADDR(ID_TO_IDX(req->id), i);
   89.50 -            dpage += blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT;
   89.51 +            dpage += req->seg[i].first_sect << SECTOR_SHIFT;
   89.52              
   89.53 -            if (blkif_first_sect(req->frame_and_sects[i]) != 0)
   89.54 -            DPRINTF("iRD : sec_nr: %10llu sec: %10llu (%1lu,%1lu) "
   89.55 -                    "pos: %15lu dpage: %p\n", 
   89.56 -                    req->sector_number, sector, 
   89.57 -                    blkif_first_sect(req->frame_and_sects[i]),
   89.58 -                    blkif_last_sect (req->frame_and_sects[i]),
   89.59 -                    (long)(sector << SECTOR_SHIFT), dpage);
   89.60 +            if (req->seg[i].first_sect != 0)
   89.61 +                DPRINTF("iRD : sec_nr: %10llu sec: %10llu (%1lu,%1lu) "
   89.62 +                        "pos: %15lu dpage: %p\n", 
   89.63 +                        req->sector_number, sector, 
   89.64 +                        req->seg[i].first_sect, req->seg[i].last_sect,
   89.65 +                        (long)(sector << SECTOR_SHIFT), dpage);
   89.66              
   89.67              /*convert size and sector to byte offsets */
   89.68              size   <<= SECTOR_SHIFT;
    90.1 --- a/tools/check/check_hotplug	Fri Dec 02 12:12:11 2005 -0600
    90.2 +++ b/tools/check/check_hotplug	Fri Dec 02 12:52:25 2005 -0600
    90.3 @@ -6,8 +6,10 @@ function error {
    90.4     echo '  *** Check for the hotplug scripts (hotplug) FAILED'
    90.5     exit 1
    90.6  }
    90.7 +[ -x "$(which udevinfo)" ] && \
    90.8 +  UDEV_VERSION=$(udevinfo -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/')
    90.9  
   90.10 -if [ -x /sbin/udev ] && [ ! -z `/sbin/udev -V` ] && [ `/sbin/udev -V` -ge 059 ]; then
   90.11 +if [ -n "$UDEV_VERSION" ] && [ $UDEV_VERSION -ge 059 ]; then
   90.12    exit 0
   90.13  fi
   90.14  
    91.1 --- a/tools/console/daemon/io.c	Fri Dec 02 12:12:11 2005 -0600
    91.2 +++ b/tools/console/daemon/io.c	Fri Dec 02 12:52:25 2005 -0600
    91.3 @@ -62,7 +62,7 @@ struct domain
    91.4  	struct domain *next;
    91.5  	char *conspath;
    91.6  	int ring_ref;
    91.7 -	int local_port;
    91.8 +	evtchn_port_t local_port;
    91.9  	int evtchn_fd;
   91.10  	struct xencons_interface *interface;
   91.11  };
   91.12 @@ -376,9 +376,6 @@ static void remove_domain(struct domain 
   91.13  
   91.14  static void cleanup_domain(struct domain *d)
   91.15  {
   91.16 -	if (!buffer_empty(&d->buffer))
   91.17 -		return;
   91.18 -
   91.19  	if (d->tty_fd != -1) {
   91.20  		close(d->tty_fd);
   91.21  		d->tty_fd = -1;
   91.22 @@ -491,7 +488,7 @@ static void handle_tty_write(struct doma
   91.23  
   91.24  static void handle_ring_read(struct domain *dom)
   91.25  {
   91.26 -	uint16_t v;
   91.27 +	evtchn_port_t v;
   91.28  
   91.29  	if (!read_sync(dom->evtchn_fd, &v, sizeof(v)))
   91.30  		return;
    92.1 --- a/tools/examples/Makefile	Fri Dec 02 12:12:11 2005 -0600
    92.2 +++ b/tools/examples/Makefile	Fri Dec 02 12:52:25 2005 -0600
    92.3 @@ -26,9 +26,10 @@ XEN_SCRIPTS += network-route vif-route
    92.4  XEN_SCRIPTS += network-nat vif-nat
    92.5  XEN_SCRIPTS += block
    92.6  XEN_SCRIPTS += block-enbd block-nbd
    92.7 +XEN_SCRIPTS += vtpm
    92.8  XEN_SCRIPT_DATA = xen-script-common.sh
    92.9  XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
   92.10 -XEN_SCRIPT_DATA += block-common.sh
   92.11 +XEN_SCRIPT_DATA += block-common.sh vtpm-common.sh
   92.12  
   92.13  XEN_HOTPLUG_DIR = /etc/hotplug
   92.14  XEN_HOTPLUG_SCRIPTS = xen-backend.agent
    93.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    93.2 +++ b/tools/examples/README.incompatibilities	Fri Dec 02 12:52:25 2005 -0600
    93.3 @@ -0,0 +1,31 @@
    93.4 +Command Incompatibilities
    93.5 +=========================
    93.6 +
    93.7 +Known incompatibilities with various commands on various distributions, and
    93.8 +the workarounds we use.
    93.9 +
   93.10 +
   93.11 +brctl
   93.12 +-----
   93.13 +
   93.14 +brctl show <bridge> fails on SLES9 SP2.  Workaround is to use brctl show
   93.15 +without arguments, and grep, though this would be difficult were you to need
   93.16 +to check for a specific bridge-interface pair, since brctl does not show the 
   93.17 +bridge name on every line.
   93.18 +
   93.19 +
   93.20 +ifup / ifdown
   93.21 +-------------
   93.22 +
   93.23 +SuSE requires an extra parameter to ifup, which is created by calling getcfg
   93.24 +appropriately.  See xen-network-common.sh for details.
   93.25 +
   93.26 +Gentoo doesn't have ifup/ifdown; appropriate alternatives are defined in
   93.27 +xen-network-common.sh.
   93.28 +
   93.29 +
   93.30 +sed
   93.31 +---
   93.32 +
   93.33 +\s is not supported in regexps on Debian etch (sed 4.1.2), Ubuntu 4.10.  We
   93.34 +hand-craft character classes instead.
    94.1 --- a/tools/examples/block	Fri Dec 02 12:12:11 2005 -0600
    94.2 +++ b/tools/examples/block	Fri Dec 02 12:52:25 2005 -0600
    94.3 @@ -3,12 +3,6 @@
    94.4  dir=$(dirname "$0")
    94.5  . "$dir/block-common.sh"
    94.6  
    94.7 -case "$command" in
    94.8 -    online | offline)
    94.9 -        exit 0
   94.10 -        ;;
   94.11 -esac
   94.12 -
   94.13  expand_dev() {
   94.14    local dev
   94.15    case $1 in
   94.16 @@ -22,27 +16,287 @@ expand_dev() {
   94.17    echo -n $dev
   94.18  }
   94.19  
   94.20 -t=$(xenstore_read_default "$XENBUS_PATH"/type "MISSING")
   94.21 +
   94.22 +##
   94.23 +# canonicalise_mode mode
   94.24 +#
   94.25 +# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or variations
   94.26 +# thereof, and canonicalises them to one of
   94.27 +#
   94.28 +#   'r': perform checks for a new read-only mount;
   94.29 +#   'w': perform checks for a read-write mount; or
   94.30 +#   '!': perform no checks at all.
   94.31 +#
   94.32 +canonicalise_mode()
   94.33 +{
   94.34 +  local mode="$1"
   94.35 +
   94.36 +  if ! expr index "$mode" 'w' >/dev/null
   94.37 +  then
   94.38 +    echo 'r'
   94.39 +  elif ! expr index "$mode" '!' >/dev/null
   94.40 +  then
   94.41 +    echo 'w'
   94.42 +  else
   94.43 +    echo '!'
   94.44 +  fi
   94.45 +}
   94.46 +
   94.47 +
   94.48 +##
   94.49 +# check_sharing device mode
   94.50 +#
   94.51 +# Check whether the device requested is already in use.  To use the device in
   94.52 +# read-only mode, it may be in use in read-only mode, but may not be in use in
   94.53 +# read-write anywhere at all.  To use the device in read-write mode, it must
   94.54 +# not be in use anywhere at all.
   94.55 +#
   94.56 +# Prints one of
   94.57 +#
   94.58 +#    'local': the device may not be used because it is mounted in the current
   94.59 +#             (i.e. the privileged domain) in a way incompatible with the
   94.60 +#             requested mode;
   94.61 +#    'guest': the device may not be used because it already mounted by a guest
   94.62 +#             in a way incompatible with the requested mode; or
   94.63 +#    'ok':    the device may be used.
   94.64 +#
   94.65 +check_sharing()
   94.66 +{
   94.67 +  local dev="$1"
   94.68 +  local mode="$2"
   94.69 +
   94.70 +  local devmm=$(device_major_minor "$dev")
   94.71 +  local file
   94.72 +
   94.73 +  if [ "$mode" == 'w' ]
   94.74 +  then
   94.75 +    toskip="^$"
   94.76 +  else
   94.77 +    toskip="^[^ ]* [^ ]* [^ ]* ro "
   94.78 +  fi
   94.79 +
   94.80 +  for file in $(cat /proc/mounts | grep -v "$toskip" | cut -f 1 -d ' ')
   94.81 +  do
   94.82 +    if [ -e "$file" ]
   94.83 +    then
   94.84 +      local d=$(device_major_minor "$file")
   94.85 +
   94.86 +      if [ "$d" == "$devmm" ]
   94.87 +      then
   94.88 +        echo 'local'
   94.89 +        return
   94.90 +      fi
   94.91 +    fi
   94.92 +  done
   94.93 +
   94.94 +##
   94.95 +## XXX SMH: the below causes live migration on localhost to fail sometimes
   94.96 +## since the source domain may still appear to be using a local device. 
   94.97 +## For now simply comment it out - a proper fix will come in due course. 
   94.98 +
   94.99 +#   for file in /sys/devices/xen-backend/*/physical_device
  94.100 +#   do
  94.101 +#     if [ -e "$file" ] # Cope with no devices, i.e. the * above did not expand.
  94.102 +#     then
  94.103 +#       local d=$(cat "$file")
  94.104 +#       if [ "$d" == "$devmm" ]
  94.105 +#       then
  94.106 +#         if [ "$mode" == 'w' ]
  94.107 +#         then
  94.108 +#           echo 'guest'
  94.109 +#           return
  94.110 +#         else
  94.111 +#           local m=$(cat "${file/physical_device/mode}")
  94.112 +
  94.113 +#           if expr index "$m" 'w' >/dev/null
  94.114 +#           then
  94.115 +#             echo 'guest'
  94.116 +#             return
  94.117 +#           fi
  94.118 +#         fi
  94.119 +#       fi
  94.120 +#     fi
  94.121 +#   done
  94.122  
  94.123 -case "$command" in 
  94.124 +  echo 'ok'
  94.125 +}
  94.126 +
  94.127 +
  94.128 +##
  94.129 +# check_device_sharing dev mode
  94.130 +#
  94.131 +# Perform the sharing check for the given physical device and mode.
  94.132 +#
  94.133 +check_device_sharing()
  94.134 +{
  94.135 +  local dev="$1"
  94.136 +  local mode=$(canonicalise_mode "$2")
  94.137 +  local result
  94.138 +
  94.139 +  if [ "$mode" == '!' ]
  94.140 +  then
  94.141 +    return 0
  94.142 +  fi
  94.143 +
  94.144 +  result=$(check_sharing "$dev" "$mode")
  94.145 +
  94.146 +  if [ "$result" != 'ok' ]
  94.147 +  then
  94.148 +    do_ebusy "Device $dev is mounted " "$mode" "$result"
  94.149 +  fi
  94.150 +}
  94.151 +
  94.152 +
  94.153 +##
  94.154 +# check_device_sharing file dev mode
  94.155 +#
  94.156 +# Perform the sharing check for the given file mounted through the given
  94.157 +# loopback interface, in the given mode.
  94.158 +#
  94.159 +check_file_sharing()
  94.160 +{
  94.161 +  local file="$1"
  94.162 +  local dev="$2"
  94.163 +  local mode="$3"
  94.164 +
  94.165 +  result=$(check_sharing "$dev" "$mode")
  94.166 +
  94.167 +  if [ "$result" != 'ok' ]
  94.168 +  then
  94.169 +    do_ebusy "File $file is loopback-mounted through $dev,
  94.170 +which is mounted " "$mode" "$result"
  94.171 +  fi
  94.172 +}
  94.173 +
  94.174 +
  94.175 +##
  94.176 +# do_ebusy prefix mode result
  94.177 +#
  94.178 +# Helper function for check_device_sharing check_file_sharing, calling ebusy
  94.179 +# with an error message constructed from the given prefix, mode, and result
  94.180 +# from a call to check_sharing.
  94.181 +#
  94.182 +do_ebusy()
  94.183 +{
  94.184 +  local prefix="$1"
  94.185 +  local mode="$2"
  94.186 +  local result="$3"
  94.187 +
  94.188 +  if [ "$result" == 'guest' ]
  94.189 +  then
  94.190 +    dom='a guest '
  94.191 +    when='now'
  94.192 +  else
  94.193 +    dom='the privileged '
  94.194 +    when='by a guest'
  94.195 +  fi
  94.196 +
  94.197 +  if [ "$mode" == 'w' ]
  94.198 +  then
  94.199 +    m1=''
  94.200 +    m2=''
  94.201 +  else
  94.202 +    m1='read-write '
  94.203 +    m2='read-only '
  94.204 +  fi
  94.205 +
  94.206 +  ebusy \
  94.207 +"${prefix}${m1}in ${dom}domain,
  94.208 +and so cannot be mounted ${m2}${when}."
  94.209 +}
  94.210 +
  94.211 +
  94.212 +t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING')
  94.213 +
  94.214 +case "$command" in
  94.215    add)
  94.216 -    p=$(xenstore_read "$XENBUS_PATH"/params)
  94.217 +    phys=$(xenstore_read_default "$XENBUS_PATH/physical-device" 'MISSING')
  94.218 +    if [ "$phys" != 'MISSING' ]
  94.219 +    then
  94.220 +      # Depending upon the hotplug configuration, it is possible for this
  94.221 +      # script to be called twice, so just bail.
  94.222 +      exit 0
  94.223 +    fi
  94.224 +
  94.225 +    p=$(xenstore_read "$XENBUS_PATH/params")
  94.226 +    mode=$(xenstore_read "$XENBUS_PATH/mode")
  94.227 +
  94.228      case $t in 
  94.229        phy)
  94.230          dev=$(expand_dev $p)
  94.231 +        check_device_sharing "$dev" "$mode"
  94.232  	write_dev "$dev"
  94.233  	exit 0
  94.234  	;;
  94.235  
  94.236        file)
  94.237 -	for dev in /dev/loop* ; do
  94.238 -	  echo "dev is $dev, p is $p"
  94.239 -	  if losetup $dev $p; then
  94.240 -	    write_dev "$dev"
  94.241 +        # Canonicalise the file, for sharing check comparison, and the mode
  94.242 +        # for ease of use here.
  94.243 +        file=$(readlink -f "$p")
  94.244 +        mode=$(canonicalise_mode "$mode")
  94.245 +
  94.246 +        if [ "$mode" == 'w' ] && ! stat "$file" -c %A | grep -q w
  94.247 +        then
  94.248 +          ebusy \
  94.249 +"File $file is read-only, and so I will not
  94.250 +mount it read-write in a guest domain."
  94.251 +        fi
  94.252 +
  94.253 +
  94.254 +	while true
  94.255 +        do 
  94.256 +          loopdev=''
  94.257 +          for dev in /dev/loop*
  94.258 +          do
  94.259 +            if [ ! -b "$dev" ]
  94.260 +            then
  94.261 +              continue
  94.262 +            fi
  94.263 +
  94.264 +            f=$(losetup "$dev" 2>/dev/null) || f='()'
  94.265 +            f=$(echo "$f" | sed -e 's/.*(\(.*\)).*/\1/g')
  94.266 +
  94.267 +            log err "$file $f $dev"
  94.268 +
  94.269 +            if [ "$f" ]
  94.270 +            then
  94.271 +              # $dev is in use.  Check sharing.
  94.272 +              if [ "$mode" == '!' ]
  94.273 +              then
  94.274 +                continue
  94.275 +              fi
  94.276 +
  94.277 +              f=$(readlink -f "$f")
  94.278 +
  94.279 +              if [ "$f" == "$file" ]
  94.280 +              then
  94.281 +                check_file_sharing "$file" "$dev" "$mode"
  94.282 +              fi
  94.283 +            else
  94.284 +              # $dev is not in use, so we'll remember it for use later; we want
  94.285 +              # to finish the sharing check first.
  94.286 +              
  94.287 +              if [ "$loopdev" == '' ]
  94.288 +              then
  94.289 +                loopdev="$dev"
  94.290 +              fi
  94.291 +            fi
  94.292 +          done
  94.293 +
  94.294 +          if [ "$loopdev" == '' ]
  94.295 +          then
  94.296 +            fatal 'Failed to find an unused loop device'
  94.297 +          fi
  94.298 +          if losetup "$loopdev" "$file"
  94.299 +          then
  94.300 +	    log err "mapped $file using $loopdev"
  94.301 +            xenstore_write "$XENBUS_PATH/node" "$loopdev"
  94.302 +            write_dev "$loopdev"
  94.303              exit 0
  94.304 -	  fi
  94.305 +          else
  94.306 +            log err "losetup $loopdev $file failed, retry"
  94.307 +          fi
  94.308  	done
  94.309 -	exit 1
  94.310  	;;
  94.311      esac
  94.312      ;;
  94.313 @@ -54,8 +308,8 @@ case "$command" in
  94.314  	;;
  94.315  
  94.316        file)
  94.317 -        node=$(xenstore_read "$XENBUS_PATH"/node)
  94.318 -	losetup -d $node
  94.319 +        node=$(xenstore_read "$XENBUS_PATH/node")
  94.320 +	losetup -d "$node"
  94.321  	exit 0
  94.322  	;;
  94.323      esac
    95.1 --- a/tools/examples/block-common.sh	Fri Dec 02 12:12:11 2005 -0600
    95.2 +++ b/tools/examples/block-common.sh	Fri Dec 02 12:52:25 2005 -0600
    95.3 @@ -21,9 +21,7 @@ dir=$(dirname "$0")
    95.4  
    95.5  findCommand "$@"
    95.6  
    95.7 -if [ "$command" != "online" ]  &&
    95.8 -   [ "$command" != "offline" ] &&
    95.9 -   [ "$command" != "add" ]     &&
   95.10 +if [ "$command" != "add" ] &&
   95.11     [ "$command" != "remove" ]
   95.12  then
   95.13    log err "Invalid command: $command"
   95.14 @@ -34,28 +32,42 @@ fi
   95.15  XENBUS_PATH="${XENBUS_PATH:?}"
   95.16  
   95.17  
   95.18 +ebusy()
   95.19 +{
   95.20 +  xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \
   95.21 +                 "$XENBUS_PATH/hotplug-status" busy
   95.22 +  log err "$@"
   95.23 +  exit 1
   95.24 +}
   95.25 +
   95.26 +
   95.27  ##
   95.28 -# Write physical-device = 0xMMmm and node = device to the store, where MM
   95.29 -# and mm are the major and minor numbers of device.
   95.30 +# Print the given device's major and minor numbers, written in hex and
   95.31 +# separated by a colon.
   95.32 +device_major_minor()
   95.33 +{
   95.34 +  stat -L -c %t:%T "$1"
   95.35 +}
   95.36 +
   95.37 +
   95.38 +##
   95.39 +# Write physical-device = MM,mm to the store, where MM and mm are the major 
   95.40 +# and minor numbers of device respectively.
   95.41  #
   95.42  # @param device The device from which major and minor numbers are read, which
   95.43  #               will be written into the store.
   95.44  #
   95.45  write_dev() {
   95.46 -  local major
   95.47 -  local minor
   95.48 -  local pdev
   95.49 +  local mm
   95.50    
   95.51 -  major=$(stat -L -c %t "$1")
   95.52 -  minor=$(stat -L -c %T "$1")
   95.53 +  mm=$(device_major_minor "$1")
   95.54   
   95.55 -  if [ -z $major  -o -z $minor ]; then
   95.56 +  if [ -z $mm ]
   95.57 +  then
   95.58      fatal "Backend device does not exist"
   95.59    fi
   95.60   
   95.61 -  pdev=$(printf "0x%02x%02x" "0x$major" "0x$minor")
   95.62 -  xenstore_write "$XENBUS_PATH"/physical-device "$pdev" \
   95.63 -                 "$XENBUS_PATH"/node "$1"
   95.64 +  xenstore_write "$XENBUS_PATH/physical-device" "$mm"
   95.65  
   95.66    success
   95.67  }
    96.1 --- a/tools/examples/block-enbd	Fri Dec 02 12:12:11 2005 -0600
    96.2 +++ b/tools/examples/block-enbd	Fri Dec 02 12:52:25 2005 -0600
    96.3 @@ -11,7 +11,7 @@ dir=$(dirname "$0")
    96.4  . "$dir/block-common.sh"
    96.5  
    96.6  case "$command" in
    96.7 -  bind)
    96.8 +  add)
    96.9      for dev in /dev/nd*; do
   96.10        if nbd-client $2:$3 $dev; then
   96.11          write_dev $dev
   96.12 @@ -20,7 +20,7 @@ case "$command" in
   96.13      done
   96.14      exit 1
   96.15      ;;
   96.16 -  unbind)
   96.17 +  remove)
   96.18      nbd-client -d $2
   96.19      exit 0
   96.20      ;;
    97.1 --- a/tools/examples/block-nbd	Fri Dec 02 12:12:11 2005 -0600
    97.2 +++ b/tools/examples/block-nbd	Fri Dec 02 12:52:25 2005 -0600
    97.3 @@ -11,7 +11,7 @@ dir=$(dirname "$0")
    97.4  . "$dir/block-common.sh"
    97.5  
    97.6  case "$command" in
    97.7 -  bind)
    97.8 +  add)
    97.9      for dev in /dev/nbd*; do
   97.10        if nbd-client $2 $3 $dev; then
   97.11          write_dev $dev
   97.12 @@ -20,7 +20,7 @@ case "$command" in
   97.13      done
   97.14      exit 1
   97.15      ;;
   97.16 -  unbind)
   97.17 +  remove)
   97.18      nbd-client -d $2
   97.19      exit 0
   97.20      ;;
    98.1 --- a/tools/examples/network-nat	Fri Dec 02 12:12:11 2005 -0600
    98.2 +++ b/tools/examples/network-nat	Fri Dec 02 12:52:25 2005 -0600
    98.3 @@ -13,35 +13,69 @@
    98.4  #
    98.5  # netdev     The gateway interface (default eth0).
    98.6  # antispoof  Whether to use iptables to prevent spoofing (default no).
    98.7 +# dhcp       Whether to alter the local DHCP configuration (default no).
    98.8  #
    98.9  #============================================================================
   98.10  
   98.11 -
   98.12 -
   98.13 -# Exit if anything goes wrong.
   98.14 -set -e 
   98.15 +dir=$(dirname "$0")
   98.16 +. "$dir/xen-script-common.sh"
   98.17 +. "$dir/xen-network-common.sh"
   98.18  
   98.19 -# First arg is the operation.
   98.20 -OP=$1
   98.21 -shift
   98.22 -
   98.23 -# Pull variables in args in to environment.
   98.24 -for arg ; do export "${arg}" ; done
   98.25 +findCommand "$@"
   98.26 +evalVariables "$@"
   98.27  
   98.28  netdev=${netdev:-eth0}
   98.29  # antispoofing not yet implemented
   98.30  antispoof=${antispoof:-no}
   98.31 +dhcp=${dhcp:-no}
   98.32  
   98.33 -echo "*network-nat $OP netdev=$netdev antispoof=$antispoof" >&2
   98.34 +if [ "$dhcp" != 'no' ]
   98.35 +then
   98.36 +  dhcpd_conf_file=$(find_dhcpd_conf_file)
   98.37 +  dhcpd_init_file=$(find_dhcpd_init_file)
   98.38 +  if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ]
   98.39 +  then
   98.40 +    echo 'Failed to find dhcpd configuration or init file.' >&2
   98.41 +    exit 1
   98.42 +  fi
   98.43 +fi
   98.44 +
   98.45 +
   98.46 +function dhcp_start()
   98.47 +{
   98.48 +  if ! grep -q "subnet 10.0.0.0" "$dhcpd_conf_file"
   98.49 +  then
   98.50 +    echo >>"$dhcpd_conf_file" "subnet 10.0.0.0 netmask 255.255.0.0 {}"
   98.51 +  fi
   98.52 +
   98.53 +  "$dhcpd_init_file" restart
   98.54 +}
   98.55 +
   98.56 +
   98.57 +function dhcp_stop()
   98.58 +{
   98.59 +  local tmpfile=$(mktemp)
   98.60 +  grep -v "subnet 10.0.0.0" "$dhcpd_conf_file" >"$tmpfile"
   98.61 +  if diff "$tmpfile" "$dhcpd_conf_file" >&/dev/null
   98.62 +  then
   98.63 +    rm "$tmpfile"
   98.64 +  else
   98.65 +    mv "$tmpfile" "$dhcpd_conf_file"
   98.66 +  fi
   98.67 +
   98.68 +  "$dhcpd_init_file" restart
   98.69 +}
   98.70  
   98.71  
   98.72  op_start() {
   98.73  	echo 1 >/proc/sys/net/ipv4/ip_forward
   98.74  	iptables -t nat -A POSTROUTING -o ${netdev} -j MASQUERADE
   98.75 +        [ "$dhcp" != 'no' ] && dhcp_start
   98.76  }
   98.77  
   98.78  
   98.79  op_stop() {
   98.80 +        [ "$dhcp" != 'no' ] && dhcp_stop
   98.81  	iptables -t nat -D POSTROUTING -o ${netdev} -j MASQUERADE
   98.82  }
   98.83  
   98.84 @@ -57,7 +91,7 @@ show_status() {
   98.85  
   98.86  }
   98.87  
   98.88 -case ${OP} in
   98.89 +case "$command" in
   98.90      start)
   98.91          op_start
   98.92          ;;
   98.93 @@ -71,7 +105,7 @@ case ${OP} in
   98.94         ;;
   98.95  
   98.96      *)
   98.97 -       echo 'Unknown command: ' ${OP} >&2
   98.98 +       echo "Unknown command: $command" >&2
   98.99         echo 'Valid commands are: start, stop, status' >&2
  98.100         exit 1
  98.101  esac
    99.1 --- a/tools/examples/vif-bridge	Fri Dec 02 12:12:11 2005 -0600
    99.2 +++ b/tools/examples/vif-bridge	Fri Dec 02 12:52:25 2005 -0600
    99.3 @@ -48,9 +48,9 @@ fi
    99.4  
    99.5  case "$command" in
    99.6      online)
    99.7 -        if brctl show "$bridge" | grep "$vif" >&/dev/null
    99.8 +        if brctl show | grep -q "$vif"
    99.9          then
   99.10 -          log debug "$vif already attached to $bridge"
   99.11 +          log debug "$vif already attached to a bridge"
   99.12            exit 0
   99.13          fi
   99.14  
   99.15 @@ -61,12 +61,16 @@ case "$command" in
   99.16          ;;
   99.17  
   99.18      offline)
   99.19 -        # vifs are auto-removed from bridge.
   99.20 -        ifconfig "$vif" down || fatal "ifconfig $vif down failed"
   99.21 +        brctl delif "$bridge" "$vif" ||
   99.22 +          log debug "brctl delif $bridge $vif failed"
   99.23 +        ifconfig "$vif" down || log debug "ifconfig $vif down failed"
   99.24          ;;
   99.25  esac
   99.26  
   99.27  handle_iptable
   99.28  
   99.29 -log debug "Successful vif-bridge operation for $vif, bridge $bridge."
   99.30 -success
   99.31 +log debug "Successful vif-bridge $command for $vif, bridge $bridge."
   99.32 +if [ "$command" == "online" ]
   99.33 +then
   99.34 +  success
   99.35 +fi
   100.1 --- a/tools/examples/vif-common.sh	Fri Dec 02 12:12:11 2005 -0600
   100.2 +++ b/tools/examples/vif-common.sh	Fri Dec 02 12:52:25 2005 -0600
   100.3 @@ -63,6 +63,7 @@ function frob_iptable()
   100.4    fi
   100.5  
   100.6    iptables "$c" FORWARD -m physdev --physdev-in "$vif" "$@" -j ACCEPT ||
   100.7 +    [ "$c" == "-D" ] ||
   100.8      log err \
   100.9       "iptables $c FORWARD -m physdev --physdev-in $vif $@ -j ACCEPT failed.
  100.10  If you are using iptables, this may affect networking for guest domains."
  100.11 @@ -82,7 +83,7 @@ function handle_iptable()
  100.12    # binary is not sufficient, because the user may not have the appropriate
  100.13    # modules installed.  If iptables is not working, then there's no need to do
  100.14    # anything with it, so we can just return.
  100.15 -  if ! iptables -L >&/dev/null
  100.16 +  if ! iptables -L -n >&/dev/null
  100.17    then
  100.18      return
  100.19    fi
  100.20 @@ -102,3 +103,37 @@ function handle_iptable()
  100.21        frob_iptable
  100.22    fi
  100.23  }
  100.24 +
  100.25 +
  100.26 +##
  100.27 +# ip_of interface
  100.28 +#
  100.29 +# Print the IP address currently in use at the given interface, or nothing if
  100.30 +# the interface is not up.
  100.31 +#
  100.32 +function ip_of()
  100.33 +{
  100.34 +  ip addr show "$1" | sed -n 's/^.*inet \([0-9.]*\).*$/\1/p'
  100.35 +}
  100.36 +
  100.37 +
  100.38 +##
  100.39 +# dom0_ip
  100.40 +#
  100.41 +# Print the IP address of the interface in dom0 through which we are routing.
  100.42 +# This is the IP address on the interface specified as "netdev" as a parameter
  100.43 +# to these scripts, or eth0 by default.  This function will call fatal if no
  100.44 +# such interface could be found.
  100.45 +#
  100.46 +function dom0_ip()
  100.47 +{
  100.48 +  local nd=${netdev:-eth0}
  100.49 +  local result=$(ip_of "$nd")
  100.50 +  if [ -z "$result" ]
  100.51 +  then
  100.52 +      fatal
  100.53 +"$netdev is not up.  Bring it up or specify another interface with " \
  100.54 +"netdev=<if> as a parameter to $0."
  100.55 +  fi
  100.56 +  echo "$result"
  100.57 +}
   101.1 --- a/tools/examples/vif-nat	Fri Dec 02 12:12:11 2005 -0600
   101.2 +++ b/tools/examples/vif-nat	Fri Dec 02 12:52:25 2005 -0600
   101.3 @@ -15,44 +15,146 @@
   101.4  # vif         vif interface name (required).
   101.5  # XENBUS_PATH path to this device's details in the XenStore (required).
   101.6  #
   101.7 +# Parameters:
   101.8 +# dhcp        Whether to alter the local DHCP configuration to include this
   101.9 +#             new host (default no).
  101.10 +#
  101.11  # Read from the store:
  101.12  # ip      list of IP networks for the vif, space-separated (default given in
  101.13  #         this script).
  101.14  #============================================================================
  101.15  
  101.16 +
  101.17  dir=$(dirname "$0")
  101.18  . "$dir/vif-common.sh"
  101.19  
  101.20 +dhcp=${dhcp:-no}
  101.21 +
  101.22 +if [ "$dhcp" != 'no' ]
  101.23 +then
  101.24 +  dhcpd_conf_file=$(find_dhcpd_conf_file)
  101.25 +  dhcpd_init_file=$(find_dhcpd_init_file)
  101.26 +  if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ]
  101.27 +  then
  101.28 +    echo 'Failed to find dhcpd configuration or init file.' >&2
  101.29 +    exit 1
  101.30 +  fi
  101.31 +fi
  101.32 +
  101.33 +
  101.34 +ip_from_dom()
  101.35 +{
  101.36 +  local domid=$(echo "$XENBUS_PATH" | sed -n 's#.*/\([0-9]*\)/[0-9]*$#\1#p')
  101.37 +  local vifid=$(echo "$XENBUS_PATH" | sed -n 's#.*/[0-9]*/\([0-9]*\)$#\1#p')
  101.38 +
  101.39 +  local domid1=$(( $domid / 256 ))
  101.40 +  local domid2=$(( $domid % 256 ))
  101.41 +  vifid=$(( $vifid + 1 ))
  101.42 +
  101.43 +  echo "10.$domid1.$domid2.$vifid/16"
  101.44 +}
  101.45 +
  101.46 +
  101.47 +routing_ip()
  101.48 +{
  101.49 +  echo $(echo $1 | awk -F. '{print $1"."$2"."$3"."$4 + 127}')
  101.50 +}
  101.51 +
  101.52 +
  101.53 +dotted_quad()
  101.54 +{
  101.55 + echo\
  101.56 + $(( ($1 & 0xFF000000) >> 24))\
  101.57 +.$(( ($1 & 0x00FF0000) >> 16))\
  101.58 +.$(( ($1 & 0x0000FF00) >> 8 ))\
  101.59 +.$((  $1 & 0x000000FF       ))
  101.60 +}
  101.61 +
  101.62 +
  101.63  if [ "$ip" == "" ]
  101.64  then
  101.65 -  ip='169.254.1.1/24'
  101.66 +  ip=$(ip_from_dom)
  101.67  fi
  101.68  
  101.69 -#determine ip address and netmask 
  101.70 +router_ip=$(routing_ip "$ip")
  101.71 +
  101.72 +# Split the given IP/bits pair.
  101.73  vif_ip=`echo ${ip} | awk -F/ '{print $1}'`
  101.74  bits=`echo ${ip} | awk -F/ '{print $2}'`
  101.75 -intmask=$(( ((0xFFFFFFFF << ((32 - $bits)))) & 0xFFFFFFFF ))
  101.76 -netmask=$(( (($intmask & 0xFF000000)) >> 24 ))
  101.77 -netmask=$netmask.$(( (($intmask & 0x00FF0000)) >> 16 ))
  101.78 -netmask=$netmask.$(( (($intmask & 0x0000FF00)) >> 8 ))
  101.79 -netmask=$netmask.$(( $intmask & 0x000000FF ))
  101.80 +
  101.81 +# Convert $bits and $vif_ip to integers, mask appropriately to get a network
  101.82 +# address, and convert them both to dotted quads.
  101.83 +
  101.84 +intmask=$(( (0xFFFFFFFF << (32 - $bits)) & 0xFFFFFFFF ))
  101.85 +vif_int=$(( $(echo "((($vif_ip" | sed -e 's#\.#)\*256\+#g') ))
  101.86 +
  101.87 +netmask=$(dotted_quad $intmask)
  101.88 +network=$(dotted_quad $(( $vif_int & $intmask )) )
  101.89 +
  101.90 +main_ip=$(dom0_ip)
  101.91 +
  101.92  
  101.93 -main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
  101.94 +dhcp_remove_entry()
  101.95 +{
  101.96 +  local tmpfile=$(mktemp)
  101.97 +  grep -v "host Xen-${vif/./-}" "$dhcpd_conf_file" >"$tmpfile"
  101.98 +  if diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
  101.99 +  then
 101.100 +    rm "$tmpfile"
 101.101 +  else
 101.102 +    mv "$tmpfile" "$dhcpd_conf_file"
 101.103 +  fi
 101.104 +}
 101.105 +
 101.106 +
 101.107 +dhcp_up()
 101.108 +{
 101.109 +  dhcp_remove_entry
 101.110 +  mac=$(xenstore_read "$XENBUS_PATH/mac")
 101.111 +  echo >>"$dhcpd_conf_file" \
 101.112 +"host Xen-${vif/./-} { hardware ethernet $mac; fixed-address $vif_ip; option routers $router_ip; }"
 101.113 +
 101.114 +  "$dhcpd_init_file" restart
 101.115 +}
 101.116 +
 101.117 +
 101.118 +dhcp_down()
 101.119 +{
 101.120 +  dhcp_remove_entry
 101.121 +  "$dhcpd_init_file" restart || true # We need to ignore failure because
 101.122 +                                     # ISC dhcpd 3 borks if there is nothing
 101.123 +                                     # for it to do, which is the case if
 101.124 +                                     # the outgoing interface is not
 101.125 +                                     # configured to offer leases and there
 101.126 +                                     # are no vifs.
 101.127 +}
 101.128 +
 101.129  
 101.130  case "$command" in
 101.131      online)
 101.132 -        ifconfig ${vif} ${vif_ip} netmask ${netmask} up
 101.133 +        if ip route | grep -q "dev $vif"
 101.134 +        then
 101.135 +          log debug "$vif already up"
 101.136 +          exit 0
 101.137 +        fi
 101.138 +
 101.139 +        do_or_die ip link set "$vif" up arp on
 101.140 +        do_or_die ip addr add "$router_ip" dev "$vif"
 101.141 +        do_or_die ip route add "$vif_ip" dev "$vif" src "$main_ip"
 101.142          echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
 101.143 -        ipcmd='a'
 101.144 +        [ "$dhcp" != 'no' ] && dhcp_up
 101.145          ;;
 101.146      offline)
 101.147 -        ifconfig ${vif} down
 101.148 -        ipcmd='d'
 101.149 +        [ "$dhcp" != 'no' ] && dhcp_down
 101.150 +        ifconfig "$vif" down || true
 101.151          ;;
 101.152  esac
 101.153  
 101.154 -ip r ${ipcmd} ${ip} dev ${vif} src ${main_ip}
 101.155  
 101.156  handle_iptable
 101.157  
 101.158 -success
 101.159 +log debug "Successful vif-nat $command for $vif."
 101.160 +if [ "$command" == "online" ]
 101.161 +then
 101.162 +  success
 101.163 +fi
   102.1 --- a/tools/examples/vif-route	Fri Dec 02 12:12:11 2005 -0600
   102.2 +++ b/tools/examples/vif-route	Fri Dec 02 12:52:25 2005 -0600
   102.3 @@ -23,7 +23,7 @@
   102.4  dir=$(dirname "$0")
   102.5  . "$dir/vif-common.sh"
   102.6  
   102.7 -main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
   102.8 +main_ip=$(dom0_ip)
   102.9  
  102.10  case "$command" in
  102.11      online)
  102.12 @@ -47,4 +47,8 @@ fi
  102.13  
  102.14  handle_iptable
  102.15  
  102.16 -success
  102.17 +log debug "Successful vif-route $command for $vif."
  102.18 +if [ "$command" == "online" ]
  102.19 +then
  102.20 +  success
  102.21 +fi
   103.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   103.2 +++ b/tools/examples/vtpm	Fri Dec 02 12:52:25 2005 -0600
   103.3 @@ -0,0 +1,23 @@
   103.4 +#!/bin/sh
   103.5 +
   103.6 +dir=$(dirname "$0")
   103.7 +. "$dir/vtpm-common.sh"
   103.8 +
   103.9 +
  103.10 +case "$command" in
  103.11 +    online | offline)
  103.12 +        exit 0
  103.13 +        ;;
  103.14 +esac
  103.15 +
  103.16 +case "$command" in
  103.17 +  add)
  103.18 +    vtpm_create_instance
  103.19 +  ;;
  103.20 +  remove)
  103.21 +    vtpm_remove_instance
  103.22 +  ;;
  103.23 +esac
  103.24 +
  103.25 +log debug "Successful vTPM operation '$command'."
  103.26 +success
   104.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   104.2 +++ b/tools/examples/vtpm-common.sh	Fri Dec 02 12:52:25 2005 -0600
   104.3 @@ -0,0 +1,281 @@
   104.4 +#
   104.5 +# Copyright (c) 2005 IBM Corporation
   104.6 +# Copyright (c) 2005 XenSource Ltd.
   104.7 +#
   104.8 +# This library is free software; you can redistribute it and/or
   104.9 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
  104.10 +# License as published by the Free Software Foundation.
  104.11 +#
  104.12 +# This library is distributed in the hope that it will be useful,
  104.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  104.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  104.15 +# Lesser General Public License for more details.
  104.16 +#
  104.17 +# You should have received a copy of the GNU Lesser General Public
  104.18 +# License along with this library; if not, write to the Free Software
  104.19 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  104.20 +#
  104.21 +
  104.22 +dir=$(dirname "$0")
  104.23 +. "$dir/xen-hotplug-common.sh"
  104.24 +
  104.25 +findCommand "$@"
  104.26 +if [ "$command" != "online" ]  &&
  104.27 +   [ "$command" != "offline" ] &&
  104.28 +   [ "$command" != "add" ]     &&
  104.29 +   [ "$command" != "remove" ]
  104.30 +then
  104.31 +	log err "Invalid command: $command"
  104.32 +	exit 1
  104.33 +fi
  104.34 +
  104.35 +
  104.36 +XENBUS_PATH="${XENBUS_PATH:?}"
  104.37 +
  104.38 +
  104.39 +VTPMDB="/etc/xen/vtpm.db"
  104.40 +
  104.41 +#In the vtpm-impl file some commands should be defined:
  104.42 +#      vtpm_create, vtpm_setup, vtpm_reset, etc. (see below)
  104.43 +#This should be indicated by setting VTPM_IMPL_DEFINED.
  104.44 +if [ -r "$dir/vtpm-impl" ]; then
  104.45 +	. "$dir/vtpm-impl"
  104.46 +fi
  104.47 +
  104.48 +if [ -z "$VTPM_IMPL_DEFINED" ]; then
  104.49 +	function vtpm_create () {
  104.50 +		true
  104.51 +	}
  104.52 +	function vtpm_setup() {
  104.53 +		true
  104.54 +	}
  104.55 +	function vtpm_reset() {
  104.56 +		true
  104.57 +	}
  104.58 +	function vtpm_suspend() {
  104.59 +		true
  104.60 +	}
  104.61 +	function vtpm_resume() {
  104.62 +		true
  104.63 +	}
  104.64 +fi
  104.65 +
  104.66 +#Find the instance number for the vtpm given the name of the domain
  104.67 +# Parameters
  104.68 +# - vmname : the name of the vm
  104.69 +# Return value
  104.70 +#  Returns '0' if instance number could not be found, otherwise
  104.71 +#  it returns the instance number in the variable 'instance'
  104.72 +function find_instance () {
  104.73 +	local vmname=$1
  104.74 +	local ret=0
  104.75 +	instance=`cat $VTPMDB |                    \
  104.76 +	          awk -vvmname=$vmname             \
  104.77 +	          '{                               \
  104.78 +	             if ( 1 != index($1,"#")) {    \
  104.79 +	               if ( $1 == vmname ) {       \
  104.80 +	                 print $2;                 \
  104.81 +	                 exit;                     \
  104.82 +	               }                           \
  104.83 +	             }                             \
  104.84 +	           }'`
  104.85 +	if [ "$instance" != "" ]; then
  104.86 +		ret=1
  104.87 +	fi
  104.88 +	return $ret
  104.89 +}
  104.90 +
  104.91 +
  104.92 +# Check whether a particular instance number is still available
  104.93 +# returns '1' if it is available
  104.94 +function is_free_instancenum () {
  104.95 +	local instance=$1
  104.96 +	local avail=1
  104.97 +
  104.98 +	#Allowed instance number range: 1-255
  104.99 +	if [ $instance -eq 0 -o $instance -gt 255 ]; then
 104.100 +		avail=0
 104.101 +	else
 104.102 +		instances=`cat $VTPMDB |                 \
 104.103 +		           gawk                          \
 104.104 +		           '{                            \
 104.105 +		               if (1 != index($1,"#")) { \
 104.106 +		                 printf("%s ",$2);       \
 104.107 +		               }                         \
 104.108 +		            }'`
 104.109 +		for i in $instances; do
 104.110 +			if [ $i -eq $instance ]; then
 104.111 +				avail=0
 104.112 +				break
 104.113 +			fi
 104.114 +		done
 104.115 +	fi
 104.116 +	return $avail
 104.117 +}
 104.118 +
 104.119 +
 104.120 +# Get an available instance number given the database
 104.121 +# Returns an unused instance number
 104.122 +function get_free_instancenum () {
 104.123 +	local ctr
 104.124 +	local instances
 104.125 +	local don
 104.126 +	instances=`cat $VTPMDB |                 \
 104.127 +	           gawk                          \
 104.128 +	           '{                            \
 104.129 +	               if (1 != index($1,"#")) { \
 104.130 +	                 printf("%s ",$2);       \
 104.131 +	               }                         \
 104.132 +	            }'`
 104.133 +	ctr=1
 104.134 +	don=0
 104.135 +	while [ $don -eq 0 ]; do
 104.136 +		local found
 104.137 +		found=0
 104.138 +		for i in $instances; do
 104.139 +			if [ $i -eq $ctr ]; then
 104.140 +				found=1;
 104.141 +				break;
 104.142 +			fi
 104.143 +		done
 104.144 +
 104.145 +		if [ $found -eq 0 ]; then
 104.146 +			don=1
 104.147 +			break
 104.148 +		fi
 104.149 +		let ctr=ctr+1
 104.150 +	done
 104.151 +	let instance=$ctr
 104.152 +}
 104.153 +
 104.154 +
 104.155 +# Add a domain name and instance number to the DB file
 104.156 +function add_instance () {
 104.157 +	local vmname=$1
 104.158 +	local inst=$2
 104.159 +
 104.160 +	if [ ! -f $VTPMDB ]; then
 104.161 +		echo "#Database for VM to vTPM association" > $VTPMDB
 104.162 +		echo "#1st column: domain name" >> $VTPMDB
 104.163 +		echo "#2nd column: TPM instance number" >> $VTPMDB
 104.164 +	fi
 104.165 +	validate_entry $vmname $inst
 104.166 +	if [ $? -eq 0 ]; then
 104.167 +		echo "$vmname $inst" >> $VTPMDB
 104.168 +	fi
 104.169 +}
 104.170 +
 104.171 +
 104.172 +#Validate whether an entry is the same as passed to this
 104.173 +#function
 104.174 +function validate_entry () {
 104.175 +	local rc=0
 104.176 +	local vmname=$1
 104.177 +	local inst=$2
 104.178 +	local res
 104.179 +	res=`cat $VTPMDB |             \
 104.180 +	     gawk -vvmname=$vmname     \
 104.181 +	          -vinst=$inst         \
 104.182 +	     '{                        \
 104.183 +	         if ( 1 == index($1,"#")) {\
 104.184 +	         } else                \
 104.185 +	         if ( $1 == vmname &&  \
 104.186 +	              $2 == inst) {    \
 104.187 +	            printf("1");       \
 104.188 +	            exit;              \
 104.189 +	         } else                \
 104.190 +	         if ( $1 == vmname ||  \
 104.191 +	              $2 == inst) {    \
 104.192 +	            printf("2");       \
 104.193 +	            exit;              \
 104.194 +	         }                     \
 104.195 +	     }'`
 104.196 +
 104.197 +	if [ "$res" == "1" ]; then
 104.198 +		let rc=1
 104.199 +	elif [ "$res" == "2" ]; then
 104.200 +		let rc=2
 104.201 +	fi
 104.202 +	return $rc
 104.203 +}
 104.204 +
 104.205 +
 104.206 +#Remove an entry from the vTPM database given its domain name
 104.207 +function remove_entry () {
 104.208 +	local vmname=$1
 104.209 +	local VTPMDB_TMP="$VTPMDB".tmp
 104.210 +	`cat $VTPMDB |             \
 104.211 +	 gawk -vvmname=$vmname     \
 104.212 +	 '{                        \
 104.213 +	    if ( $1 != vmname ) {  \
 104.214 +	      print $0;            \
 104.215 +	    }                      \
 104.216 +	 '} > $VTPMDB_TMP`
 104.217 +	if [ -e $VTPMDB_TMP ]; then
 104.218 +		mv -f $VTPMDB_TMP $VTPMDB
 104.219 +	else
 104.220 +		log err "Error creating temporary file '$VTPMDB_TMP'."
 104.221 +	fi
 104.222 +}
 104.223 +
 104.224 +
 104.225 +#Create a vTPM instance
 104.226 +# If no entry in the TPM database is found, the instance is
 104.227 +# created and an entry added to the database.
 104.228 +function vtpm_create_instance () {
 104.229 +	local domname=$(xenstore_read "$XENBUS_PATH"/domain)
 104.230 +	local res
 104.231 +	set +e
 104.232 +	find_instance $domname
 104.233 +	res=$?
 104.234 +	if [ $res -eq 0 ]; then
 104.235 +		#Try to give the preferred instance to the domain
 104.236 +		instance=$(xenstore_read "$XENBUS_PATH"/pref_instance)
 104.237 +		if [ "$instance" != "" ]; then
 104.238 +			is_free_instancenum $instance
 104.239 +			res=$?
 104.240 +			if [ $res -eq 0 ]; then
 104.241 +				get_free_instancenum
 104.242 +			fi
 104.243 +		else
 104.244 +			get_free_instancenum
 104.245 +		fi
 104.246 +		add_instance $domname $instance
 104.247 +		if [ "$REASON" == "create" ]; then
 104.248 +			vtpm_create $instance
 104.249 +		elif [ "$REASON" == "hibernate" ]; then
 104.250 +			vtpm_resume $instance $domname
 104.251 +		else
 104.252 +			#default case for 'now'
 104.253 +			vtpm_create $instance
 104.254 +		fi
 104.255 +	fi
 104.256 +	if [ "$REASON" == "create" ]; then
 104.257 +		vtpm_reset $instance
 104.258 +	elif [ "$REASON" == "hibernate" ]; then
 104.259 +		vtpm_setup $instance
 104.260 +	else
 104.261 +		#default case for 'now'
 104.262 +		vtpm_reset $instance
 104.263 +	fi
 104.264 +	xenstore_write $XENBUS_PATH/instance $instance
 104.265 +	set -e
 104.266 +}
 104.267 +
 104.268 +
 104.269 +#Remove an instance
 104.270 +function vtpm_remove_instance () {
 104.271 +	local domname=$(xenstore_read "$XENBUS_PATH"/domain)
 104.272 +	set +e
 104.273 +	find_instance $domname
 104.274 +	res=$?
 104.275 +	if [ $res -eq 0 ]; then
 104.276 +		#Something is really wrong with the DB
 104.277 +		log err "vTPM DB file $VTPMDB has no entry for '$domname'"
 104.278 +	else
 104.279 +		if [ "$REASON" == "hibernate" ]; then
 104.280 +			vtpm_suspend $instance
 104.281 +		fi
 104.282 +	fi
 104.283 +	set -e
 104.284 +}
   105.1 --- a/tools/examples/xen-backend.agent	Fri Dec 02 12:12:11 2005 -0600
   105.2 +++ b/tools/examples/xen-backend.agent	Fri Dec 02 12:52:25 2005 -0600
   105.3 @@ -6,6 +6,9 @@ case "$XENBUS_TYPE" in
   105.4    vbd)
   105.5      /etc/xen/scripts/block "$ACTION"
   105.6      ;;
   105.7 +  vtpm)
   105.8 +    /etc/xen/scripts/vtpm "$ACTION"
   105.9 +    ;;
  105.10    vif)
  105.11      [ -n "$script" ] && $script "$ACTION"
  105.12      ;;
  105.13 @@ -15,6 +18,9 @@ case "$ACTION" in
  105.14    add)
  105.15      ;;
  105.16    remove)
  105.17 +    # remove device frontend store entries
  105.18 +    xenstore-rm -t $(xenstore-read "$XENBUS_PATH/frontend") || true
  105.19 +
  105.20      # remove device backend store entries
  105.21      xenstore-rm -t "$XENBUS_PATH"       || true
  105.22      xenstore-rm -t "error/$XENBUS_PATH" || true
   106.1 --- a/tools/examples/xen-backend.rules	Fri Dec 02 12:12:11 2005 -0600
   106.2 +++ b/tools/examples/xen-backend.rules	Fri Dec 02 12:52:25 2005 -0600
   106.3 @@ -1,5 +1,7 @@
   106.4  SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}"
   106.5 +SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}"
   106.6  SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} online"
   106.7  SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="offline", RUN+="$env{script} offline"
   106.8 +SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/bin/bash -c '/usr/bin/xenstore-rm -t $$(/usr/bin/xenstore-read $env{XENBUS_PATH}/frontend)'"
   106.9  SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/usr/bin/xenstore-rm -t $env{XENBUS_PATH}"
  106.10  SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/usr/bin/xenstore-rm -t error/$env{XENBUS_PATH}"
   107.1 --- a/tools/examples/xen-hotplug-common.sh	Fri Dec 02 12:12:11 2005 -0600
   107.2 +++ b/tools/examples/xen-hotplug-common.sh	Fri Dec 02 12:52:25 2005 -0600
   107.3 @@ -40,6 +40,17 @@ success() {
   107.4    xenstore_write "$XENBUS_PATH"/hotplug-status connected
   107.5  }
   107.6  
   107.7 +do_or_die() {
   107.8 +  "$@" || fatal "$@ failed"
   107.9 +}
  107.10 +
  107.11 +sigerr() {
  107.12 +  fatal "$0" "$@" "failed; error detected."
  107.13 +}
  107.14 +
  107.15 +trap sigerr ERR
  107.16 +
  107.17 +
  107.18  ##
  107.19  # xenstore_read <path>+
  107.20  #
   108.1 --- a/tools/examples/xen-network-common.sh	Fri Dec 02 12:12:11 2005 -0600
   108.2 +++ b/tools/examples/xen-network-common.sh	Fri Dec 02 12:52:25 2005 -0600
   108.3 @@ -69,3 +69,29 @@ else
   108.4      true
   108.5    }
   108.6  fi
   108.7 +
   108.8 +
   108.9 +first_file()
  108.10 +{
  108.11 +  t="$1"
  108.12 +  shift
  108.13 +  for file in $@
  108.14 +  do
  108.15 +    if [ "$t" "$file" ]
  108.16 +    then
  108.17 +      echo "$file"
  108.18 +      return
  108.19 +    fi
  108.20 +  done
  108.21 +}
  108.22 +
  108.23 +find_dhcpd_conf_file()
  108.24 +{
  108.25 +  first_file -f /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf
  108.26 +}
  108.27 +
  108.28 +
  108.29 +find_dhcpd_init_file()
  108.30 +{
  108.31 +  first_file -x /etc/init.d/dhcp3-server /etc/init.d/dhcp
  108.32 +}
   109.1 --- a/tools/ioemu/exec.c	Fri Dec 02 12:12:11 2005 -0600
   109.2 +++ b/tools/ioemu/exec.c	Fri Dec 02 12:52:25 2005 -0600
   109.3 @@ -262,13 +262,24 @@ void cpu_register_physical_memory(target
   109.4                                    unsigned long size,
   109.5                                    unsigned long phys_offset)
   109.6  {
   109.7 -        if (mmio_cnt == MAX_MMIO) {
   109.8 -                fprintf(logfile, "too many mmio regions\n");
   109.9 -                exit(-1);
  109.10 +    int i;
  109.11 +
  109.12 +    for (i = 0; i < mmio_cnt; i++) { 
  109.13 +        if(mmio[i].start == start_addr) {
  109.14 +            mmio[i].io_index = phys_offset;
  109.15 +            mmio[i].size = size;
  109.16 +            return;
  109.17          }
  109.18 -        mmio[mmio_cnt].io_index = phys_offset;
  109.19 -        mmio[mmio_cnt].start = start_addr;
  109.20 -        mmio[mmio_cnt++].size = size;
  109.21 +    }
  109.22 +
  109.23 +    if (mmio_cnt == MAX_MMIO) {
  109.24 +        fprintf(logfile, "too many mmio regions\n");
  109.25 +        exit(-1);
  109.26 +    }
  109.27 +
  109.28 +    mmio[mmio_cnt].io_index = phys_offset;
  109.29 +    mmio[mmio_cnt].start = start_addr;
  109.30 +    mmio[mmio_cnt++].size = size;
  109.31  }
  109.32  
  109.33  /* mem_read and mem_write are arrays of functions containing the
   110.1 --- a/tools/ioemu/hw/ide.c	Fri Dec 02 12:12:11 2005 -0600
   110.2 +++ b/tools/ioemu/hw/ide.c	Fri Dec 02 12:52:25 2005 -0600
   110.3 @@ -669,6 +669,8 @@ static int ide_read_dma_cb(IDEState *s,
   110.4      }
   110.5      if (s->io_buffer_index >= s->io_buffer_size && s->nsector == 0) {
   110.6          s->status = READY_STAT | SEEK_STAT;
   110.7 +        s->bmdma->status &= ~BM_STATUS_DMAING;
   110.8 +        s->bmdma->status |= BM_STATUS_INT;
   110.9          ide_set_irq(s);
  110.10  #ifdef DEBUG_IDE_ATAPI
  110.11          printf("dma status=0x%x\n", s->status);
  110.12 @@ -736,6 +738,8 @@ static int ide_write_dma_cb(IDEState *s,
  110.13              if (n == 0) {
  110.14                  /* end of transfer */
  110.15                  s->status = READY_STAT | SEEK_STAT;
  110.16 +                s->bmdma->status &= ~BM_STATUS_DMAING;
  110.17 +                s->bmdma->status |= BM_STATUS_INT;
  110.18                  ide_set_irq(s);
  110.19                  return 0;
  110.20              }
  110.21 @@ -983,6 +987,8 @@ static int ide_atapi_cmd_read_dma_cb(IDE
  110.22      if (s->packet_transfer_size <= 0) {
  110.23          s->status = READY_STAT;
  110.24          s->nsector = (s->nsector & ~7) | ATAPI_INT_REASON_IO | ATAPI_INT_REASON_CD;
  110.25 +        s->bmdma->status &= ~BM_STATUS_DMAING;
  110.26 +        s->bmdma->status |= BM_STATUS_INT;
  110.27          ide_set_irq(s);
  110.28  #ifdef DEBUG_IDE_ATAPI
  110.29          printf("dma status=0x%x\n", s->status);
  110.30 @@ -2065,8 +2071,6 @@ static void ide_dma_loop(BMDMAState *bm)
  110.31      }
  110.32      /* end of transfer */
  110.33   the_end:
  110.34 -    bm->status &= ~BM_STATUS_DMAING;
  110.35 -    bm->status |= BM_STATUS_INT;
  110.36      bm->dma_cb = NULL;
  110.37      bm->ide_if = NULL;
  110.38  }
   111.1 --- a/tools/ioemu/hw/vga.c	Fri Dec 02 12:12:11 2005 -0600
   111.2 +++ b/tools/ioemu/hw/vga.c	Fri Dec 02 12:52:25 2005 -0600
   111.3 @@ -1834,16 +1834,6 @@ void vga_bios_init(VGAState *s)
   111.4  
   111.5      /* TODO:add vbe support if enable it */
   111.6  
   111.7 -    FILE *qemuf = fopen("/etc/xen/qemu-vgaram-bin", "rb");
   111.8 -    if (!qemuf) {
   111.9 -        fprintf(logfile, "open qemu vgaram binary failed!\n");
  111.10 -    } else {
  111.11 -        /*load vram contents, else vga console can't boot */
  111.12 -        qemu_get_buffer(qemuf, s->vram_ptr, 256*1024);
  111.13 -
  111.14 -        fclose(qemuf);
  111.15 -    }
  111.16 -
  111.17  }
  111.18  
  111.19  void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base, 
   112.1 --- a/tools/ioemu/target-i386-dm/helper2.c	Fri Dec 02 12:12:11 2005 -0600
   112.2 +++ b/tools/ioemu/target-i386-dm/helper2.c	Fri Dec 02 12:52:25 2005 -0600
   112.3 @@ -1,6 +1,6 @@
   112.4  /*
   112.5   *  i386 helpers (without register variable usage)
   112.6 - * 
   112.7 + *
   112.8   *  Copyright (c) 2003 Fabrice Bellard
   112.9   *
  112.10   * This library is free software; you can redistribute it and/or
  112.11 @@ -56,6 +56,7 @@
  112.12  #include "vl.h"
  112.13  
  112.14  extern int domid;
  112.15 +extern int vcpus;
  112.16  
  112.17  void *shared_vram;
  112.18  
  112.19 @@ -93,7 +94,7 @@ void cpu_x86_close(CPUX86State *env)
  112.20  }
  112.21  
  112.22  
  112.23 -void cpu_dump_state(CPUState *env, FILE *f, 
  112.24 +void cpu_dump_state(CPUState *env, FILE *f,
  112.25                      int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
  112.26                      int flags)
  112.27  {
  112.28 @@ -121,270 +122,273 @@ target_ulong cpu_get_phys_page_debug(CPU
  112.29  
  112.30  //the evtchn fd for polling
  112.31  int evtchn_fd = -1;
  112.32 -//the evtchn port for polling the notification, should be inputed as bochs's parameter
  112.33 -uint16_t ioreq_remote_port, ioreq_local_port;
  112.34 +
  112.35 +//the evtchn port for polling the notification,
  112.36 +//should be inputed as bochs's parameter
  112.37 +evtchn_port_t ioreq_remote_port, ioreq_local_port;
  112.38  
  112.39  //some functions to handle the io req packet
  112.40 -void
  112.41 -sp_info()
  112.42 +void sp_info()
  112.43  {
  112.44 -	ioreq_t *req;
  112.45 +    ioreq_t *req;
  112.46 +    int i;
  112.47  
  112.48 -	req = &(shared_page->vcpu_iodata[0].vp_ioreq);
  112.49 -        term_printf("event port: %d\n", shared_page->sp_global.eport);
  112.50 -        term_printf("req state: %x, pvalid: %x, addr: %llx, data: %llx, count: %llx, size: %llx\n", req->state, req->pdata_valid, req->addr, req->u.data, req->count, req->size);
  112.51 +    term_printf("event port: %d\n", shared_page->sp_global.eport);
  112.52 +    for ( i = 0; i < vcpus; i++ ) {
  112.53 +        req = &(shared_page->vcpu_iodata[i].vp_ioreq);
  112.54 +        term_printf("vcpu %d:\n", i);
  112.55 +        term_printf("  req state: %x, pvalid: %x, addr: %llx, "
  112.56 +                    "data: %llx, count: %llx, size: %llx\n",
  112.57 +                    req->state, req->pdata_valid, req->addr,
  112.58 +                    req->u.data, req->count, req->size);
  112.59 +    }
  112.60  }
  112.61  
  112.62  //get the ioreq packets from share mem
  112.63  ioreq_t* __cpu_get_ioreq(void)
  112.64  {
  112.65 -	ioreq_t *req;
  112.66 +    ioreq_t *req;
  112.67  
  112.68 -	req = &(shared_page->vcpu_iodata[0].vp_ioreq);
  112.69 -	if (req->state == STATE_IOREQ_READY) {
  112.70 -		req->state = STATE_IOREQ_INPROCESS;
  112.71 -	} else {
  112.72 -		fprintf(logfile, "False I/O request ... in-service already: %x, pvalid: %x,port: %llx, data: %llx, count: %llx, size: %llx\n", req->state, req->pdata_valid, req->addr, req->u.data, req->count, req->size);
  112.73 -		req = NULL;
  112.74 -	}
  112.75 +    req = &(shared_page->vcpu_iodata[0].vp_ioreq);
  112.76 +    if (req->state == STATE_IOREQ_READY) {
  112.77 +        req->state = STATE_IOREQ_INPROCESS;
  112.78 +    } else {
  112.79 +        fprintf(logfile, "False I/O request ... in-service already: "
  112.80 +                         "%x, pvalid: %x, port: %llx, "
  112.81 +                         "data: %llx, count: %llx, size: %llx\n",
  112.82 +                         req->state, req->pdata_valid, req->addr,
  112.83 +                         req->u.data, req->count, req->size);
  112.84 +        req = NULL;
  112.85 +    }
  112.86  
  112.87 -	return req;
  112.88 +    return req;
  112.89  }
  112.90  
  112.91  //use poll to get the port notification
  112.92 -//ioreq_vec--out,the 
  112.93 +//ioreq_vec--out,the
  112.94  //retval--the number of ioreq packet
  112.95  ioreq_t* cpu_get_ioreq(void)
  112.96  {
  112.97 -	int rc;
  112.98 -	uint16_t port;
  112.99 -	rc = read(evtchn_fd, &port, sizeof(port));
 112.100 -	if ((rc == sizeof(port)) && (port == ioreq_local_port)) {
 112.101 -		// unmask the wanted port again
 112.102 -		write(evtchn_fd, &ioreq_local_port, 2);
 112.103 +    int rc;
 112.104 +    evtchn_port_t port;
 112.105  
 112.106 -		//get the io packet from shared memory
 112.107 -		return __cpu_get_ioreq();
 112.108 -	}
 112.109 +    rc = read(evtchn_fd, &port, sizeof(port));
 112.110 +    if ((rc == sizeof(port)) && (port == ioreq_local_port)) {
 112.111 +        // unmask the wanted port again
 112.112 +        write(evtchn_fd, &ioreq_local_port, sizeof(port));
 112.113  
 112.114 -	//read error or read nothing
 112.115 -	return NULL;
 112.116 +        //get the io packet from shared memory
 112.117 +        return __cpu_get_ioreq();
 112.118 +    }
 112.119 +
 112.120 +    //read error or read nothing
 112.121 +    return NULL;
 112.122  }
 112.123  
 112.124 -unsigned long
 112.125 -do_inp(CPUState *env, unsigned long addr, unsigned long size)
 112.126 +unsigned long do_inp(CPUState *env, unsigned long addr, unsigned long size)
 112.127  {
 112.128 -	switch(size) {
 112.129 -	case 1:
 112.130 -		return cpu_inb(env, addr);
 112.131 -	case 2:
 112.132 -		return cpu_inw(env, addr);
 112.133 -	case 4:
 112.134 -		return cpu_inl(env, addr);
 112.135 -	default:
 112.136 -		fprintf(logfile, "inp: bad size: %lx %lx\n", addr, size);
 112.137 -		exit(-1);
 112.138 -	}
 112.139 +    switch(size) {
 112.140 +    case 1:
 112.141 +        return cpu_inb(env, addr);
 112.142 +    case 2:
 112.143 +        return cpu_inw(env, addr);
 112.144 +    case 4:
 112.145 +        return cpu_inl(env, addr);
 112.146 +    default:
 112.147 +        fprintf(logfile, "inp: bad size: %lx %lx\n", addr, size);
 112.148 +        exit(-1);
 112.149 +    }
 112.150  }
 112.151  
 112.152 -void
 112.153 -do_outp(CPUState *env, unsigned long addr, unsigned long size, 
 112.154 -        unsigned long val)
 112.155 +void do_outp(CPUState *env, unsigned long addr,
 112.156 +             unsigned long size, unsigned long val)
 112.157  {
 112.158 -	switch(size) {
 112.159 -	case 1:
 112.160 -		return cpu_outb(env, addr, val);
 112.161 -	case 2:
 112.162 -		return cpu_outw(env, addr, val);
 112.163 -	case 4:
 112.164 -		return cpu_outl(env, addr, val);
 112.165 -	default:
 112.166 -		fprintf(logfile, "outp: bad size: %lx %lx\n", addr, size);
 112.167 -		exit(-1);
 112.168 -	}
 112.169 +    switch(size) {
 112.170 +    case 1:
 112.171 +        return cpu_outb(env, addr, val);
 112.172 +    case 2:
 112.173 +        return cpu_outw(env, addr, val);
 112.174 +    case 4:
 112.175 +        return cpu_outl(env, addr, val);
 112.176 +    default:
 112.177 +        fprintf(logfile, "outp: bad size: %lx %lx\n", addr, size);
 112.178 +        exit(-1);
 112.179 +    }
 112.180  }
 112.181  
 112.182 -extern void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, 
 112.183 +extern void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
 112.184                                     int len, int is_write);
 112.185  
 112.186 -static inline void
 112.187 -read_physical(uint64_t addr, unsigned long size, void *val)
 112.188 +static inline void read_physical(uint64_t addr, unsigned long size, void *val)
 112.189  {
 112.190 -        return cpu_physical_memory_rw((target_phys_addr_t)addr, val, size, 0);
 112.191 +    return cpu_physical_memory_rw((target_phys_addr_t)addr, val, size, 0);
 112.192  }
 112.193  
 112.194 -static inline void
 112.195 -write_physical(uint64_t addr, unsigned long size, void *val)
 112.196 +static inline void write_physical(uint64_t addr, unsigned long size, void *val)
 112.197  {
 112.198 -        return cpu_physical_memory_rw((target_phys_addr_t)addr, val, size, 1);
 112.199 +    return cpu_physical_memory_rw((target_phys_addr_t)addr, val, size, 1);
 112.200  }
 112.201  
 112.202 -void
 112.203 -cpu_ioreq_pio(CPUState *env, ioreq_t *req)
 112.204 +void cpu_ioreq_pio(CPUState *env, ioreq_t *req)
 112.205  {
 112.206 -	int i, sign;
 112.207 +    int i, sign;
 112.208 +
 112.209 +    sign = req->df ? -1 : 1;
 112.210  
 112.211 -	sign = req->df ? -1 : 1;
 112.212 -
 112.213 -	if (req->dir == IOREQ_READ) {
 112.214 -		if (!req->pdata_valid) {
 112.215 -			req->u.data = do_inp(env, req->addr, req->size);
 112.216 -		} else {
 112.217 -			unsigned long tmp; 
 112.218 +    if (req->dir == IOREQ_READ) {
 112.219 +        if (!req->pdata_valid) {
 112.220 +            req->u.data = do_inp(env, req->addr, req->size);
 112.221 +        } else {
 112.222 +            unsigned long tmp;
 112.223  
 112.224 -			for (i = 0; i < req->count; i++) {
 112.225 -				tmp = do_inp(env, req->addr, req->size);
 112.226 -				write_physical((target_phys_addr_t) req->u.pdata
 112.227 -						+ (sign * i * req->size), 
 112.228 -					req->size, &tmp);
 112.229 -			}
 112.230 -		}
 112.231 -	} else if (req->dir == IOREQ_WRITE) {
 112.232 -		if (!req->pdata_valid) {
 112.233 -			do_outp(env, req->addr, req->size, req->u.data);
 112.234 -		} else {
 112.235 -			for (i = 0; i < req->count; i++) {
 112.236 -				unsigned long tmp;
 112.237 +            for (i = 0; i < req->count; i++) {
 112.238 +                tmp = do_inp(env, req->addr, req->size);
 112.239 +                write_physical((target_phys_addr_t) req->u.pdata
 112.240 +                  + (sign * i * req->size),
 112.241 +                  req->size, &tmp);
 112.242 +            }
 112.243 +        }
 112.244 +    } else if (req->dir == IOREQ_WRITE) {
 112.245 +        if (!req->pdata_valid) {
 112.246 +            do_outp(env, req->addr, req->size, req->u.data);
 112.247 +        } else {
 112.248 +            for (i = 0; i < req->count; i++) {
 112.249 +                unsigned long tmp;
 112.250  
 112.251 -				read_physical((target_phys_addr_t) req->u.pdata
 112.252 -						+ (sign * i * req->size),
 112.253 -					req->size, &tmp);
 112.254 -				do_outp(env, req->addr, req->size, tmp);
 112.255 -			}
 112.256 -		}
 112.257 -	}
 112.258 +                read_physical((target_phys_addr_t) req->u.pdata
 112.259 +                  + (sign * i * req->size),
 112.260 +                  req->size, &tmp);
 112.261 +                do_outp(env, req->addr, req->size, tmp);
 112.262 +            }
 112.263 +        }
 112.264 +    }
 112.265  }
 112.266  
 112.267 -void
 112.268 -cpu_ioreq_move(CPUState *env, ioreq_t *req)
 112.269 +void cpu_ioreq_move(CPUState *env, ioreq_t *req)
 112.270  {
 112.271 -	int i, sign;
 112.272 +    int i, sign;
 112.273  
 112.274 -	sign = req->df ? -1 : 1;
 112.275 +    sign = req->df ? -1 : 1;
 112.276  
 112.277 -	if (!req->pdata_valid) {
 112.278 -		if (req->dir == IOREQ_READ) {
 112.279 -			for (i = 0; i < req->count; i++) {
 112.280 -				read_physical(req->addr
 112.281 -						+ (sign * i * req->size),
 112.282 -					req->size, &req->u.data);
 112.283 -			}
 112.284 -		} else if (req->dir == IOREQ_WRITE) {
 112.285 -			for (i = 0; i < req->count; i++) {
 112.286 -				write_physical(req->addr
 112.287 -						+ (sign * i * req->size),
 112.288 -					req->size, &req->u.data);
 112.289 -			}
 112.290 -		}
 112.291 -	} else {
 112.292 -		unsigned long tmp;
 112.293 +    if (!req->pdata_valid) {
 112.294 +        if (req->dir == IOREQ_READ) {
 112.295 +            for (i = 0; i < req->count; i++) {
 112.296 +                read_physical(req->addr
 112.297 +                  + (sign * i * req->size),
 112.298 +                  req->size, &req->u.data);
 112.299 +            }
 112.300 +        } else if (req->dir == IOREQ_WRITE) {
 112.301 +            for (i = 0; i < req->count; i++) {
 112.302 +                write_physical(req->addr
 112.303 +                  + (sign * i * req->size),
 112.304 +                  req->size, &req->u.data);
 112.305 +            }
 112.306 +        }
 112.307 +    } else {
 112.308 +        unsigned long tmp;
 112.309  
 112.310 -		if (req->dir == IOREQ_READ) {
 112.311 -			for (i = 0; i < req->count; i++) {
 112.312 -				read_physical(req->addr
 112.313 -						+ (sign * i * req->size),
 112.314 -					req->size, &tmp);
 112.315 -				write_physical((target_phys_addr_t )req->u.pdata
 112.316 -						+ (sign * i * req->size),
 112.317 -					req->size, &tmp);
 112.318 -			}
 112.319 -		} else if (req->dir == IOREQ_WRITE) {
 112.320 -			for (i = 0; i < req->count; i++) {
 112.321 -				read_physical((target_phys_addr_t) req->u.pdata
 112.322 -						+ (sign * i * req->size),
 112.323 -					req->size, &tmp);
 112.324 -				write_physical(req->addr
 112.325 -						+ (sign * i * req->size),
 112.326 -					req->size, &tmp);
 112.327 -			}
 112.328 -		}
 112.329 -	}
 112.330 +        if (req->dir == IOREQ_READ) {
 112.331 +            for (i = 0; i < req->count; i++) {
 112.332 +                read_physical(req->addr
 112.333 +                  + (sign * i * req->size),
 112.334 +                  req->size, &tmp);
 112.335 +                write_physical((target_phys_addr_t )req->u.pdata
 112.336 +                  + (sign * i * req->size),
 112.337 +                  req->size, &tmp);
 112.338 +            }
 112.339 +        } else if (req->dir == IOREQ_WRITE) {
 112.340 +            for (i = 0; i < req->count; i++) {
 112.341 +                read_physical((target_phys_addr_t) req->u.pdata
 112.342 +                  + (sign * i * req->size),
 112.343 +                  req->size, &tmp);
 112.344 +                write_physical(req->addr
 112.345 +                  + (sign * i * req->size),
 112.346 +                  req->size, &tmp);
 112.347 +            }
 112.348 +        }
 112.349 +    }
 112.350  }
 112.351  
 112.352 -void
 112.353 -cpu_ioreq_and(CPUState *env, ioreq_t *req)
 112.354 +void cpu_ioreq_and(CPUState *env, ioreq_t *req)
 112.355  {
 112.356 -	unsigned long tmp1, tmp2;
 112.357 +    unsigned long tmp1, tmp2;
 112.358 +
 112.359 +    if (req->pdata_valid != 0)
 112.360 +        hw_error("expected scalar value");
 112.361  
 112.362 -	if (req->pdata_valid != 0)
 112.363 -		hw_error("expected scalar value");
 112.364 -
 112.365 -	read_physical(req->addr, req->size, &tmp1);
 112.366 -	if (req->dir == IOREQ_WRITE) {
 112.367 -		tmp2 = tmp1 & (unsigned long) req->u.data;
 112.368 -		write_physical(req->addr, req->size, &tmp2);
 112.369 -	}
 112.370 -	req->u.data = tmp1;
 112.371 +    read_physical(req->addr, req->size, &tmp1);
 112.372 +    if (req->dir == IOREQ_WRITE) {
 112.373 +        tmp2 = tmp1 & (unsigned long) req->u.data;
 112.374 +        write_physical(req->addr, req->size, &tmp2);
 112.375 +    }
 112.376 +    req->u.data = tmp1;
 112.377  }
 112.378  
 112.379 -void
 112.380 -cpu_ioreq_or(CPUState *env, ioreq_t *req)
 112.381 +void cpu_ioreq_or(CPUState *env, ioreq_t *req)
 112.382  {
 112.383 -	unsigned long tmp1, tmp2;
 112.384 +    unsigned long tmp1, tmp2;
 112.385 +
 112.386 +    if (req->pdata_valid != 0)
 112.387 +        hw_error("expected scalar value");
 112.388  
 112.389 -	if (req->pdata_valid != 0)
 112.390 -		hw_error("expected scalar value");
 112.391 -
 112.392 -	read_physical(req->addr, req->size, &tmp1);
 112.393 -	if (req->dir == IOREQ_WRITE) {
 112.394 -		tmp2 = tmp1 | (unsigned long) req->u.data;
 112.395 -		write_physical(req->addr, req->size, &tmp2);
 112.396 -	}
 112.397 -	req->u.data = tmp1;
 112.398 +    read_physical(req->addr, req->size, &tmp1);
 112.399 +    if (req->dir == IOREQ_WRITE) {
 112.400 +        tmp2 = tmp1 | (unsigned long) req->u.data;
 112.401 +        write_physical(req->addr, req->size, &tmp2);
 112.402 +    }
 112.403 +    req->u.data = tmp1;
 112.404  }
 112.405  
 112.406 -void
 112.407 -cpu_ioreq_xor(CPUState *env, ioreq_t *req)
 112.408 +void cpu_ioreq_xor(CPUState *env, ioreq_t *req)
 112.409  {
 112.410 -	unsigned long tmp1, tmp2;
 112.411 +    unsigned long tmp1, tmp2;
 112.412 +
 112.413 +    if (req->pdata_valid != 0)
 112.414 +        hw_error("expected scalar value");
 112.415  
 112.416 -	if (req->pdata_valid != 0)
 112.417 -		hw_error("expected scalar value");
 112.418 -
 112.419 -	read_physical(req->addr, req->size, &tmp1);
 112.420 -	if (req->dir == IOREQ_WRITE) {
 112.421 -		tmp2 = tmp1 ^ (unsigned long) req->u.data;
 112.422 -		write_physical(req->addr, req->size, &tmp2);
 112.423 -	}
 112.424 -	req->u.data = tmp1;
 112.425 +    read_physical(req->addr, req->size, &tmp1);
 112.426 +    if (req->dir == IOREQ_WRITE) {
 112.427 +        tmp2 = tmp1 ^ (unsigned long) req->u.data;
 112.428 +        write_physical(req->addr, req->size, &tmp2);
 112.429 +    }
 112.430 +    req->u.data = tmp1;
 112.431  }
 112.432  
 112.433 -void
 112.434 -cpu_handle_ioreq(CPUState *env)
 112.435 +void cpu_handle_ioreq(CPUState *env)
 112.436  {
 112.437 -	ioreq_t *req = cpu_get_ioreq();
 112.438 +    ioreq_t *req = cpu_get_ioreq();
 112.439  
 112.440 -	if (req) {
 112.441 -		if ((!req->pdata_valid) && (req->dir == IOREQ_WRITE)) {
 112.442 -			if (req->size != 4)
 112.443 -				req->u.data &= (1UL << (8 * req->size))-1;
 112.444 -		}
 112.445 +    if (req) {
 112.446 +        if ((!req->pdata_valid) && (req->dir == IOREQ_WRITE)) {
 112.447 +            if (req->size != 4)
 112.448 +                req->u.data &= (1UL << (8 * req->size))-1;
 112.449 +        }
 112.450  
 112.451 -		switch (req->type) {
 112.452 -		case IOREQ_TYPE_PIO:
 112.453 -			cpu_ioreq_pio(env, req);
 112.454 -			break;
 112.455 -		case IOREQ_TYPE_COPY:
 112.456 -			cpu_ioreq_move(env, req);
 112.457 -			break;
 112.458 -		case IOREQ_TYPE_AND:
 112.459 -			cpu_ioreq_and(env, req);
 112.460 -			break;
 112.461 -		case IOREQ_TYPE_OR:
 112.462 -			cpu_ioreq_or(env, req);
 112.463 -			break;
 112.464 -		case IOREQ_TYPE_XOR:
 112.465 -			cpu_ioreq_xor(env, req);
 112.466 -			break;
 112.467 -		default:
 112.468 -			hw_error("Invalid ioreq type 0x%x", req->type);
 112.469 -		}
 112.470 +        switch (req->type) {
 112.471 +        case IOREQ_TYPE_PIO:
 112.472 +            cpu_ioreq_pio(env, req);
 112.473 +            break;
 112.474 +        case IOREQ_TYPE_COPY:
 112.475 +            cpu_ioreq_move(env, req);
 112.476 +            break;
 112.477 +        case IOREQ_TYPE_AND:
 112.478 +            cpu_ioreq_and(env, req);
 112.479 +            break;
 112.480 +        case IOREQ_TYPE_OR:
 112.481 +            cpu_ioreq_or(env, req);
 112.482 +            break;
 112.483 +        case IOREQ_TYPE_XOR:
 112.484 +            cpu_ioreq_xor(env, req);
 112.485 +            break;
 112.486 +        default:
 112.487 +            hw_error("Invalid ioreq type 0x%x\n", req->type);
 112.488 +        }
 112.489  
 112.490 -		/* No state change if state = STATE_IORESP_HOOK */
 112.491 -		if (req->state == STATE_IOREQ_INPROCESS)
 112.492 -			req->state = STATE_IORESP_READY;
 112.493 -		env->send_event = 1;
 112.494 -	}
 112.495 +        /* No state change if state = STATE_IORESP_HOOK */
 112.496 +        if (req->state == STATE_IOREQ_INPROCESS)
 112.497 +            req->state = STATE_IORESP_READY;
 112.498 +        env->send_event = 1;
 112.499 +    }
 112.500  }
 112.501  
 112.502  int xc_handle;
 112.503 @@ -393,7 +397,8 @@ void
 112.504  destroy_vmx_domain(void)
 112.505  {
 112.506      extern FILE* logfile;
 112.507 -    char destroy_cmd[20];
 112.508 +    char destroy_cmd[32];
 112.509 +
 112.510      sprintf(destroy_cmd, "xm destroy %d", domid);
 112.511      if (system(destroy_cmd) == -1)
 112.512          fprintf(logfile, "%s failed.!\n", destroy_cmd);
 112.513 @@ -403,40 +408,41 @@ fd_set wakeup_rfds;
 112.514  int    highest_fds;
 112.515  int main_loop(void)
 112.516  {
 112.517 - 	fd_set rfds;
 112.518 -	struct timeval tv;
 112.519 -	extern CPUState *global_env;
 112.520 -        extern int vm_running;
 112.521 -        extern int shutdown_requested;
 112.522 -	CPUState *env = global_env;
 112.523 -	int retval;
 112.524 -        extern void main_loop_wait(int);
 112.525 +    fd_set rfds;
 112.526 +    struct timeval tv;
 112.527 +    extern CPUState *global_env;
 112.528 +    extern int vm_running;
 112.529 +    extern int shutdown_requested;
 112.530 +    CPUState *env = global_env;
 112.531 +    int retval;
 112.532 +    extern void main_loop_wait(int);
 112.533 +
 112.534 +    /* Watch stdin (fd 0) to see when it has input. */
 112.535 +    FD_ZERO(&wakeup_rfds);
 112.536 +    FD_SET(evtchn_fd, &wakeup_rfds);
 112.537 +    highest_fds = evtchn_fd;
 112.538 +    env->send_event = 0;
 112.539  
 112.540 - 	/* Watch stdin (fd 0) to see when it has input. */
 112.541 -	FD_ZERO(&wakeup_rfds);
 112.542 -	FD_SET(evtchn_fd, &wakeup_rfds);
 112.543 -	highest_fds = evtchn_fd;
 112.544 -	env->send_event = 0;
 112.545 -	while (1) {
 112.546 -                if (vm_running) {
 112.547 -                    if (shutdown_requested) {
 112.548 -                        break;
 112.549 -                    }
 112.550 -                    if (reset_requested){
 112.551 -                        qemu_system_reset();
 112.552 -                        reset_requested = 0;
 112.553 -                    }
 112.554 -                }
 112.555 +    while (1) {
 112.556 +        if (vm_running) {
 112.557 +            if (shutdown_requested) {
 112.558 +                break;
 112.559 +            }
 112.560 +            if (reset_requested){
 112.561 +                qemu_system_reset();
 112.562 +                reset_requested = 0;
 112.563 +            }
 112.564 +        }
 112.565  
 112.566 -		/* Wait up to one seconds. */
 112.567 -		tv.tv_sec = 0;
 112.568 -		tv.tv_usec = 100000;
 112.569 +        /* Wait up to one seconds. */
 112.570 +        tv.tv_sec = 0;
 112.571 +        tv.tv_usec = 100000;
 112.572  
 112.573 -		retval = select(highest_fds+1, &wakeup_rfds, NULL, NULL, &tv);
 112.574 -		if (retval == -1) {
 112.575 -			perror("select");
 112.576 -			return 0;
 112.577 -		}
 112.578 +        retval = select(highest_fds+1, &wakeup_rfds, NULL, NULL, &tv);
 112.579 +        if (retval == -1) {
 112.580 +            fprintf(logfile, "select returned error %d\n", errno);
 112.581 +            return 0;
 112.582 +        }
 112.583          rfds = wakeup_rfds;
 112.584          FD_ZERO(&wakeup_rfds);
 112.585          FD_SET(evtchn_fd, &wakeup_rfds);
 112.586 @@ -451,65 +457,64 @@ int main_loop(void)
 112.587          if ( FD_ISSET(evtchn_fd, &rfds) ) {
 112.588              cpu_handle_ioreq(env);
 112.589          }
 112.590 -		main_loop_wait(0);
 112.591 -		if (env->send_event) {
 112.592 -		    env->send_event = 0;
 112.593 -			struct ioctl_evtchn_notify notify;
 112.594 -			notify.port = ioreq_local_port;
 112.595 -			(void)ioctl(evtchn_fd, IOCTL_EVTCHN_NOTIFY, &notify);
 112.596 -		}
 112.597 -	}
 112.598 -        destroy_vmx_domain();
 112.599 -	return 0;
 112.600 +        main_loop_wait(0);
 112.601 +
 112.602 +        if (env->send_event) {
 112.603 +            struct ioctl_evtchn_notify notify;
 112.604 +
 112.605 +            env->send_event = 0;
 112.606 +            notify.port = ioreq_local_port;
 112.607 +            (void)ioctl(evtchn_fd, IOCTL_EVTCHN_NOTIFY, &notify);
 112.608 +        }
 112.609 +    }
 112.610 +    destroy_vmx_domain();
 112.611 +    return 0;
 112.612  }
 112.613  
 112.614 -static void
 112.615 -qemu_vmx_reset(void *unused)
 112.616 +static void qemu_vmx_reset(void *unused)
 112.617  {
 112.618 -    char cmd[255];
 112.619 +    char cmd[64];
 112.620  
 112.621 -    /* pause domain first, to avoid repeated reboot request*/ 
 112.622 -    xc_domain_pause (xc_handle, domid);
 112.623 +    /* pause domain first, to avoid repeated reboot request*/
 112.624 +    xc_domain_pause(xc_handle, domid);
 112.625  
 112.626 -    sprintf(cmd,"xm shutdown -R %d", domid);
 112.627 -    system (cmd);
 112.628 +    sprintf(cmd, "xm shutdown -R %d", domid);
 112.629 +    system(cmd);
 112.630  }
 112.631  
 112.632 -CPUState *
 112.633 -cpu_init()
 112.634 +CPUState * cpu_init()
 112.635  {
 112.636 -	CPUX86State *env;
 112.637 -	struct ioctl_evtchn_bind_interdomain bind;
 112.638 -	int rc;
 112.639 -      
 112.640 -        cpu_exec_init();
 112.641 -        qemu_register_reset(qemu_vmx_reset, NULL);
 112.642 -	env = malloc(sizeof(CPUX86State));
 112.643 -	if (!env)
 112.644 -		return NULL;
 112.645 -	memset(env, 0, sizeof(CPUX86State));
 112.646 +    CPUX86State *env;
 112.647 +    struct ioctl_evtchn_bind_interdomain bind;
 112.648 +    int rc;
 112.649  
 112.650 -	cpu_single_env = env;
 112.651 +    cpu_exec_init();
 112.652 +    qemu_register_reset(qemu_vmx_reset, NULL);
 112.653 +    env = malloc(sizeof(CPUX86State));
 112.654 +    if (!env)
 112.655 +        return NULL;
 112.656 +    memset(env, 0, sizeof(CPUX86State));
 112.657  
 112.658 -	if (evtchn_fd != -1)//the evtchn has been opened by another cpu object
 112.659 -		return NULL;
 112.660 +    cpu_single_env = env;
 112.661 +
 112.662 +    if (evtchn_fd != -1)//the evtchn has been opened by another cpu object
 112.663 +        return NULL;
 112.664  
 112.665 -	//use nonblock reading not polling, may change in future.
 112.666 -	evtchn_fd = open("/dev/xen/evtchn", O_RDWR|O_NONBLOCK); 
 112.667 -	if (evtchn_fd == -1) {
 112.668 -		perror("open");
 112.669 -		return NULL;
 112.670 -	}
 112.671 +    //use nonblock reading not polling, may change in future.
 112.672 +    evtchn_fd = open("/dev/xen/evtchn", O_RDWR|O_NONBLOCK);
 112.673 +    if (evtchn_fd == -1) {
 112.674 +        fprintf(logfile, "open evtchn device error %d\n", errno);
 112.675 +        return NULL;
 112.676 +    }
 112.677  
 112.678 -	bind.remote_domain = domid;
 112.679 -	bind.remote_port   = ioreq_remote_port;
 112.680 -	rc = ioctl(evtchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
 112.681 -	if (rc == -1) {
 112.682 -		perror("ioctl");
 112.683 -		return NULL;
 112.684 -	}
 112.685 -	ioreq_local_port = rc;
 112.686 +    bind.remote_domain = domid;
 112.687 +    bind.remote_port   = ioreq_remote_port;
 112.688 +    rc = ioctl(evtchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
 112.689 +    if (rc == -1) {
 112.690 +        fprintf(logfile, "bind interdomain ioctl error %d\n", errno);
 112.691 +        return NULL;
 112.692 +    }
 112.693 +    ioreq_local_port = rc;
 112.694  
 112.695 -	return env;
 112.696 +    return env;
 112.697  }
 112.698 -
   113.1 --- a/tools/ioemu/vl.c	Fri Dec 02 12:12:11 2005 -0600
   113.2 +++ b/tools/ioemu/vl.c	Fri Dec 02 12:52:25 2005 -0600
   113.3 @@ -1,8 +1,8 @@
   113.4  /*
   113.5   * QEMU System Emulator
   113.6 - * 
   113.7 + *
   113.8   * Copyright (c) 2003-2004 Fabrice Bellard
   113.9 - * 
  113.10 + *
  113.11   * Permission is hereby granted, free of charge, to any person obtaining a copy
  113.12   * of this software and associated documentation files (the "Software"), to deal
  113.13   * in the Software without restriction, including without limitation the rights
  113.14 @@ -221,7 +221,7 @@ void init_ioports(void)
  113.15  }
  113.16  
  113.17  /* size is the word size in byte */
  113.18 -int register_ioport_read(int start, int length, int size, 
  113.19 +int register_ioport_read(int start, int length, int size,
  113.20                           IOPortReadFunc *func, void *opaque)
  113.21  {
  113.22      int i, bsize;
  113.23 @@ -246,7 +246,7 @@ int register_ioport_read(int start, int 
  113.24  }
  113.25  
  113.26  /* size is the word size in byte */
  113.27 -int register_ioport_write(int start, int length, int size, 
  113.28 +int register_ioport_write(int start, int length, int size,
  113.29                            IOPortWriteFunc *func, void *opaque)
  113.30  {
  113.31      int i, bsize;
  113.32 @@ -307,7 +307,7 @@ char *pstrcat(char *buf, int buf_size, c
  113.33  {
  113.34      int len;
  113.35      len = strlen(buf);
  113.36 -    if (len < buf_size) 
  113.37 +    if (len < buf_size)
  113.38          pstrcpy(buf + len, buf_size - len, s);
  113.39      return buf;
  113.40  }
  113.41 @@ -362,7 +362,7 @@ void cpu_outb(CPUState *env, int addr, i
  113.42  #ifdef DEBUG_IOPORT
  113.43      if (loglevel & CPU_LOG_IOPORT)
  113.44          fprintf(logfile, "outb: %04x %02x\n", addr, val);
  113.45 -#endif    
  113.46 +#endif
  113.47      ioport_write_table[0][addr](ioport_opaque[addr], addr, val);
  113.48  }
  113.49  
  113.50 @@ -371,7 +371,7 @@ void cpu_outw(CPUState *env, int addr, i
  113.51  #ifdef DEBUG_IOPORT
  113.52      if (loglevel & CPU_LOG_IOPORT)
  113.53          fprintf(logfile, "outw: %04x %04x\n", addr, val);
  113.54 -#endif    
  113.55 +#endif
  113.56      ioport_write_table[1][addr](ioport_opaque[addr], addr, val);
  113.57  }
  113.58  
  113.59 @@ -465,7 +465,7 @@ void kbd_put_keycode(int keycode)
  113.60  void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
  113.61  {
  113.62      if (qemu_put_mouse_event) {
  113.63 -        qemu_put_mouse_event(qemu_put_mouse_event_opaque, 
  113.64 +        qemu_put_mouse_event(qemu_put_mouse_event_opaque,
  113.65                               dx, dy, dz, buttons_state);
  113.66      }
  113.67  }
  113.68 @@ -475,14 +475,14 @@ void kbd_mouse_event(int dx, int dy, int
  113.69  
  113.70  #if defined(__powerpc__)
  113.71  
  113.72 -static inline uint32_t get_tbl(void) 
  113.73 +static inline uint32_t get_tbl(void)
  113.74  {
  113.75      uint32_t tbl;
  113.76      asm volatile("mftb %0" : "=r" (tbl));
  113.77      return tbl;
  113.78  }
  113.79  
  113.80 -static inline uint32_t get_tbu(void) 
  113.81 +static inline uint32_t get_tbu(void)
  113.82  {
  113.83  	uint32_t tbl;
  113.84  	asm volatile("mftbu %0" : "=r" (tbl));
  113.85 @@ -604,7 +604,7 @@ uint64_t muldiv64(uint64_t a, uint32_t b
  113.86              uint32_t high, low;
  113.87  #else
  113.88              uint32_t low, high;
  113.89 -#endif            
  113.90 +#endif
  113.91          } l;
  113.92      } u, res;
  113.93      uint64_t rl, rh;
  113.94 @@ -707,7 +707,7 @@ void qemu_mod_timer(QEMUTimer *ts, int64
  113.95          t = *pt;
  113.96          if (!t)
  113.97              break;
  113.98 -        if (t->expire_time > expire_time) 
  113.99 +        if (t->expire_time > expire_time)
 113.100              break;
 113.101          pt = &t->next;
 113.102      }
 113.103 @@ -736,7 +736,7 @@ static inline int qemu_timer_expired(QEM
 113.104  static void qemu_run_timers(QEMUTimer **ptimer_head, int64_t current_time)
 113.105  {
 113.106      QEMUTimer *ts;
 113.107 -    
 113.108 +
 113.109      for(;;) {
 113.110          ts = *ptimer_head;
 113.111          if (!ts || ts->expire_time > current_time)
 113.112 @@ -744,7 +744,7 @@ static void qemu_run_timers(QEMUTimer **
 113.113          /* remove timer from the list before calling the callback */
 113.114          *ptimer_head = ts->next;
 113.115          ts->next = NULL;
 113.116 -        
 113.117 +
 113.118          /* run the callback (the timer list can be modified) */
 113.119          ts->cb(ts->opaque);
 113.120      }
 113.121 @@ -814,17 +814,17 @@ static void init_timers(void)
 113.122                                 host_alarm_handler, // function
 113.123                                 (DWORD)&count,  // user parameter
 113.124                                 TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
 113.125 - 	if( !timerID ) {
 113.126 -            perror("failed timer alarm");
 113.127 +        if( !timerID ) {
 113.128 +            fprintf(logfile, "failed timer alarm");
 113.129              exit(1);
 113.130 - 	}
 113.131 +        }
 113.132      }
 113.133      pit_min_timer_count = ((uint64_t)10000 * PIT_FREQ) / 1000000;
 113.134  #else
 113.135      {
 113.136          /* get times() syscall frequency */
 113.137          timer_freq = sysconf(_SC_CLK_TCK);
 113.138 -      
 113.139 +
 113.140  #ifndef TARGET_VMX
 113.141          /* timer signal */
 113.142          sigfillset(&act.sa_mask);
 113.143 @@ -860,11 +860,11 @@ static void init_timers(void)
 113.144              sigaction(SIGIO, &act, NULL);
 113.145              fcntl(rtc_fd, F_SETFL, O_ASYNC);
 113.146              fcntl(rtc_fd, F_SETOWN, getpid());
 113.147 -        } else 
 113.148 +        } else
 113.149  #endif /* defined(__linux__) */
 113.150          {
 113.151          use_itimer:
 113.152 -            pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec * 
 113.153 +            pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec *
 113.154                                     PIT_FREQ) / 1000000;
 113.155          }
 113.156  #endif /* TARGET_VMX */
 113.157 @@ -903,13 +903,13 @@ void qemu_chr_send_event(CharDriverState
 113.158          s->chr_send_event(s, event);
 113.159  }
 113.160  
 113.161 -void qemu_chr_add_read_handler(CharDriverState *s, 
 113.162 -                               IOCanRWHandler *fd_can_read, 
 113.163 +void qemu_chr_add_read_handler(CharDriverState *s,
 113.164 +                               IOCanRWHandler *fd_can_read,
 113.165                                 IOReadHandler *fd_read, void *opaque)
 113.166  {
 113.167      s->chr_add_read_handler(s, fd_can_read, fd_read, opaque);
 113.168  }
 113.169 -             
 113.170 +
 113.171  void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event)
 113.172  {
 113.173      s->chr_event = chr_event;
 113.174 @@ -920,8 +920,8 @@ static int null_chr_write(CharDriverStat
 113.175      return len;
 113.176  }
 113.177  
 113.178 -static void null_chr_add_read_handler(CharDriverState *chr, 
 113.179 -                                    IOCanRWHandler *fd_can_read, 
 113.180 +static void null_chr_add_read_handler(CharDriverState *chr,
 113.181 +                                    IOCanRWHandler *fd_can_read,
 113.182                                      IOReadHandler *fd_read, void *opaque)
 113.183  {
 113.184  }
 113.185 @@ -943,7 +943,7 @@ CharDriverState *qemu_chr_open_null(void
 113.186  typedef struct {
 113.187      int fd_in, fd_out;
 113.188      /* for nographic stdio only */
 113.189 -    IOCanRWHandler *fd_can_read; 
 113.190 +    IOCanRWHandler *fd_can_read;
 113.191      IOReadHandler *fd_read;
 113.192      void *fd_opaque;
 113.193  } FDCharDriver;
 113.194 @@ -979,8 +979,8 @@ static int fd_chr_write(CharDriverState 
 113.195      return unix_write(s->fd_out, buf, len);
 113.196  }
 113.197  
 113.198 -static void fd_chr_add_read_handler(CharDriverState *chr, 
 113.199 -                                    IOCanRWHandler *fd_can_read, 
 113.200 +static void fd_chr_add_read_handler(CharDriverState *chr,
 113.201 +                                    IOCanRWHandler *fd_can_read,
 113.202                                      IOReadHandler *fd_read, void *opaque)
 113.203  {
 113.204      FDCharDriver *s = chr->opaque;
 113.205 @@ -1047,7 +1047,7 @@ static void stdio_received_byte(int ch)
 113.206          case 'x':
 113.207              exit(0);
 113.208              break;
 113.209 -        case 's': 
 113.210 +        case 's':
 113.211              {
 113.212                  int i;
 113.213                  for (i = 0; i < MAX_DISKS; i++) {
 113.214 @@ -1087,13 +1087,13 @@ static void stdio_received_byte(int ch)
 113.215              uint8_t buf[1];
 113.216              CharDriverState *chr;
 113.217              FDCharDriver *s;
 113.218 -            
 113.219 +
 113.220              chr = stdio_clients[client_index];
 113.221              s = chr->opaque;
 113.222              buf[0] = ch;
 113.223              /* XXX: should queue the char if the device is not
 113.224                 ready */
 113.225 -            if (s->fd_can_read(s->fd_opaque) > 0) 
 113.226 +            if (s->fd_can_read(s->fd_opaque) > 0)
 113.227                  s->fd_read(s->fd_opaque, buf, 1);
 113.228          }
 113.229      }
 113.230 @@ -1141,7 +1141,7 @@ static void term_init(void)
 113.231      tty.c_cflag |= CS8;
 113.232      tty.c_cc[VMIN] = 1;
 113.233      tty.c_cc[VTIME] = 0;
 113.234 -    
 113.235 +
 113.236      tcsetattr (0, TCSANOW, &tty);
 113.237  
 113.238      atexit(term_exit);
 113.239 @@ -1176,7 +1176,6 @@ CharDriverState *qemu_chr_open_stdio(voi
 113.240  int store_console_dev(int domid, char *pts)
 113.241  {
 113.242      int xc_handle;
 113.243 -    unsigned int len = 0;
 113.244      struct xs_handle *xs;
 113.245      char *path;
 113.246  
 113.247 @@ -1191,7 +1190,7 @@ int store_console_dev(int domid, char *p
 113.248          fprintf(logfile, "xc_interface_open() error\n");
 113.249          return -1;
 113.250      }
 113.251 -    
 113.252 +
 113.253      path = xs_get_domain_path(xs, domid);
 113.254      if (path == NULL) {
 113.255          fprintf(logfile, "xs_get_domain_path() error\n");
 113.256 @@ -1207,7 +1206,7 @@ int store_console_dev(int domid, char *p
 113.257          fprintf(logfile, "xs_write for console fail");
 113.258          return -1;
 113.259      }
 113.260 -    
 113.261 +
 113.262      free(path);
 113.263      xs_daemon_close(xs);
 113.264      close(xc_handle);
 113.265 @@ -1218,15 +1217,19 @@ int store_console_dev(int domid, char *p
 113.266  #if defined(__linux__)
 113.267  CharDriverState *qemu_chr_open_pty(void)
 113.268  {
 113.269 -    char slave_name[1024];
 113.270      int master_fd, slave_fd;
 113.271 -    
 113.272 -    /* Not satisfying */
 113.273 -    if (openpty(&master_fd, &slave_fd, slave_name, NULL, NULL) < 0) {
 113.274 +    struct termios term;
 113.275 +
 113.276 +    if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) < 0)
 113.277          return NULL;
 113.278 -    }
 113.279 -    fprintf(stderr, "char device redirected to %s\n", slave_name);
 113.280 -    store_console_dev(domid, slave_name);
 113.281 +
 113.282 +    /* Set raw attributes on the pty. */
 113.283 +    cfmakeraw(&term);
 113.284 +    tcsetattr(slave_fd, TCSAFLUSH, &term);
 113.285 +
 113.286 +    fprintf(stderr, "char device redirected to %s\n", ptsname(master_fd));
 113.287 +    store_console_dev(domid, ptsname(master_fd));
 113.288 +
 113.289      return qemu_chr_open_fd(master_fd, master_fd);
 113.290  }
 113.291  #else
 113.292 @@ -1244,13 +1247,13 @@ CharDriverState *qemu_chr_open(const cha
 113.293          return text_console_init(&display_state);
 113.294      } else if (!strcmp(filename, "null")) {
 113.295          return qemu_chr_open_null();
 113.296 -    } else 
 113.297 +    } else
 113.298  #ifndef _WIN32
 113.299      if (!strcmp(filename, "pty")) {
 113.300          return qemu_chr_open_pty();
 113.301      } else if (!strcmp(filename, "stdio")) {
 113.302          return qemu_chr_open_stdio();
 113.303 -    } else 
 113.304 +    } else
 113.305  #endif
 113.306      {
 113.307          return NULL;
 113.308 @@ -1291,7 +1294,7 @@ void qemu_send_packet(NetDriverState *nd
 113.309      nd->send_packet(nd, buf, size);
 113.310  }
 113.311  
 113.312 -void qemu_add_read_packet(NetDriverState *nd, IOCanRWHandler *fd_can_read, 
 113.313 +void qemu_add_read_packet(NetDriverState *nd, IOCanRWHandler *fd_can_read,
 113.314                            IOReadHandler *fd_read, void *opaque)
 113.315  {
 113.316      nd->add_read_packet(nd, fd_can_read, fd_read, opaque);
 113.317 @@ -1303,8 +1306,8 @@ static void dummy_send_packet(NetDriverS
 113.318  {
 113.319  }
 113.320  
 113.321 -static void dummy_add_read_packet(NetDriverState *nd, 
 113.322 -                                  IOCanRWHandler *fd_can_read, 
 113.323 +static void dummy_add_read_packet(NetDriverState *nd,
 113.324 +                                  IOCanRWHandler *fd_can_read,
 113.325                                    IOReadHandler *fd_read, void *opaque)
 113.326  {
 113.327  }
 113.328 @@ -1349,8 +1352,8 @@ static void slirp_send_packet(NetDriverS
 113.329      slirp_input(buf, size);
 113.330  }
 113.331  
 113.332 -static void slirp_add_read_packet(NetDriverState *nd, 
 113.333 -                                  IOCanRWHandler *fd_can_read, 
 113.334 +static void slirp_add_read_packet(NetDriverState *nd,
 113.335 +                                  IOCanRWHandler *fd_can_read,
 113.336                                    IOReadHandler *fd_read, void *opaque)
 113.337  {
 113.338      slirp_fd_opaque = opaque;
 113.339 @@ -1397,7 +1400,7 @@ static void net_slirp_redir(const char *
 113.340      const char *p;
 113.341      struct in_addr guest_addr;
 113.342      int host_port, guest_port;
 113.343 -    
 113.344 +
 113.345      if (!slirp_inited) {
 113.346          slirp_inited = 1;
 113.347          slirp_init();
 113.348 @@ -1427,11 +1430,11 @@ static void net_slirp_redir(const char *
 113.349      }
 113.350      if (!inet_aton(buf, &guest_addr))
 113.351          goto fail;
 113.352 -    
 113.353 +
 113.354      guest_port = strtol(p, &r, 0);
 113.355      if (r == p)
 113.356          goto fail;
 113.357 -    
 113.358 +
 113.359      if (slirp_redir(is_udp, host_port, guest_addr, guest_port) < 0) {
 113.360          fprintf(stderr, "qemu: could not set up redirection\n");
 113.361          exit(1);
 113.362 @@ -1441,7 +1444,7 @@ static void net_slirp_redir(const char *
 113.363      fprintf(stderr, "qemu: syntax: -redir [tcp|udp]:host-port:[guest-host]:guest-port\n");
 113.364      exit(1);
 113.365  }
 113.366 -    
 113.367 +
 113.368  #ifndef _WIN32
 113.369  
 113.370  char smb_dir[1024];
 113.371 @@ -1460,7 +1463,7 @@ static void smb_exit(void)
 113.372              break;
 113.373          if (strcmp(de->d_name, ".") != 0 &&
 113.374              strcmp(de->d_name, "..") != 0) {
 113.375 -            snprintf(filename, sizeof(filename), "%s/%s", 
 113.376 +            snprintf(filename, sizeof(filename), "%s/%s",
 113.377                       smb_dir, de->d_name);
 113.378              unlink(filename);
 113.379          }
 113.380 @@ -1488,13 +1491,13 @@ void net_slirp_smb(const char *exported_
 113.381          exit(1);
 113.382      }
 113.383      snprintf(smb_conf, sizeof(smb_conf), "%s/%s", smb_dir, "smb.conf");
 113.384 -    
 113.385 +
 113.386      f = fopen(smb_conf, "w");
 113.387      if (!f) {
 113.388          fprintf(stderr, "qemu: could not create samba server configuration file '%s'\n", smb_conf);
 113.389          exit(1);
 113.390      }
 113.391 -    fprintf(f, 
 113.392 +    fprintf(f,
 113.393              "[global]\n"
 113.394              "pid directory=%s\n"
 113.395              "lock directory=%s\n"
 113.396 @@ -1516,7 +1519,7 @@ void net_slirp_smb(const char *exported_
 113.397  
 113.398      snprintf(smb_cmdline, sizeof(smb_cmdline), "/usr/sbin/smbd -s %s",
 113.399               smb_conf);
 113.400 -    
 113.401 +
 113.402      slirp_add_exec(0, smb_cmdline, 4, 139);
 113.403  }
 113.404  
 113.405 @@ -1550,7 +1553,7 @@ static int tun_open(char *ifname, int if
 113.406  {
 113.407      struct ifreq ifr;
 113.408      int fd, ret;
 113.409 -    
 113.410 +
 113.411      fd = open("/dev/net/tun", O_RDWR);
 113.412      if (fd < 0) {
 113.413          fprintf(stderr, "warning: could not open /dev/net/tun: no virtual network emulation\n");
 113.414 @@ -1565,7 +1568,7 @@ static int tun_open(char *ifname, int if
 113.415          close(fd);
 113.416          return -1;
 113.417      }
 113.418 -    printf("Connected to host network interface: %s\n", ifr.ifr_name);
 113.419 +    fprintf(logfile, "Connected to host network interface: %s\n", ifr.ifr_name);
 113.420      pstrcpy(ifname, ifname_size, ifr.ifr_name);
 113.421      fcntl(fd, F_SETFL, O_NONBLOCK);
 113.422      return fd;
 113.423 @@ -1577,8 +1580,8 @@ static void tun_send_packet(NetDriverSta
 113.424      write(nd->fd, buf, size);
 113.425  }
 113.426  
 113.427 -static void tun_add_read_packet(NetDriverState *nd, 
 113.428 -                                IOCanRWHandler *fd_can_read, 
 113.429 +static void tun_add_read_packet(NetDriverState *nd,
 113.430 +                                IOCanRWHandler *fd_can_read,
 113.431                                  IOReadHandler *fd_read, void *opaque)
 113.432  {
 113.433      qemu_add_fd_event_read_handler(nd->fd, fd_can_read, fd_read, opaque);
 113.434 @@ -1660,7 +1663,7 @@ void dumb_display_init(DisplayState *ds)
 113.435  #if !defined(CONFIG_SOFTMMU)
 113.436  /***********************************************************/
 113.437  /* cpu signal handler */
 113.438 -static void host_segv_handler(int host_signum, siginfo_t *info, 
 113.439 +static void host_segv_handler(int host_signum, siginfo_t *info,
 113.440                                void *puc)
 113.441  {
 113.442      abort();
 113.443 @@ -1686,7 +1689,7 @@ typedef struct IOHandlerRecord {
 113.444  static IOHandlerRecord *first_io_handler;
 113.445  static IOHandlerRecord *first_eventio_handler;
 113.446  
 113.447 -int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read, 
 113.448 +int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read,
 113.449                               IOReadHandler *fd_read, void *opaque)
 113.450  {
 113.451      IOHandlerRecord *ioh;
 113.452 @@ -1703,7 +1706,7 @@ int qemu_add_fd_read_handler(int fd, IOC
 113.453      return 0;
 113.454  }
 113.455  
 113.456 -int qemu_add_fd_event_read_handler(int fd, IOCanRWHandler *fd_can_read, 
 113.457 +int qemu_add_fd_event_read_handler(int fd, IOCanRWHandler *fd_can_read,
 113.458                               IOReadHandler *fd_read, void *opaque)
 113.459  {
 113.460      IOHandlerRecord *ioh;
 113.461 @@ -1835,8 +1838,8 @@ typedef struct SaveStateEntry {
 113.462  
 113.463  static SaveStateEntry *first_se;
 113.464  
 113.465 -int register_savevm(const char *idstr, 
 113.466 -                    int instance_id, 
 113.467 +int register_savevm(const char *idstr,
 113.468 +                    int instance_id,
 113.469                      int version_id,
 113.470                      SaveStateHandler *save_state,
 113.471                      LoadStateHandler *load_state,
 113.472 @@ -1896,7 +1899,7 @@ int qemu_savevm(const char *filename)
 113.473          /* record size: filled later */
 113.474          len_pos = ftell(f);
 113.475          qemu_put_be32(f, 0);
 113.476 -        
 113.477 +
 113.478          se->save_state(f, se->opaque);
 113.479  
 113.480          /* fill record size */
 113.481 @@ -1920,7 +1923,7 @@ static SaveStateEntry *find_se(const cha
 113.482      SaveStateEntry *se;
 113.483  
 113.484      for(se = first_se; se != NULL; se = se->next) {
 113.485 -        if (!strcmp(se->idstr, idstr) && 
 113.486 +        if (!strcmp(se->idstr, idstr) &&
 113.487              instance_id == se->instance_id)
 113.488              return se;
 113.489      }
 113.490 @@ -1935,7 +1938,7 @@ int qemu_loadvm(const char *filename)
 113.491      int saved_vm_running;
 113.492      unsigned int v;
 113.493      char idstr[256];
 113.494 -    
 113.495 +
 113.496      saved_vm_running = vm_running;
 113.497      vm_stop(0);
 113.498  
 113.499 @@ -1968,18 +1971,18 @@ int qemu_loadvm(const char *filename)
 113.500          version_id = qemu_get_be32(f);
 113.501          record_len = qemu_get_be32(f);
 113.502  #if 0
 113.503 -        printf("idstr=%s instance=0x%x version=%d len=%d\n", 
 113.504 +        printf("idstr=%s instance=0x%x version=%d len=%d\n",
 113.505                 idstr, instance_id, version_id, record_len);
 113.506  #endif
 113.507          cur_pos = ftell(f);
 113.508          se = find_se(idstr, instance_id);
 113.509          if (!se) {
 113.510 -            fprintf(stderr, "qemu: warning: instance 0x%x of device '%s' not present in current VM\n", 
 113.511 +            fprintf(stderr, "qemu: warning: instance 0x%x of device '%s' not present in current VM\n",
 113.512                      instance_id, idstr);
 113.513          } else {
 113.514              ret = se->load_state(f, se->opaque, version_id);
 113.515              if (ret < 0) {
 113.516 -                fprintf(stderr, "qemu: warning: error while loading state for instance 0x%x of device '%s'\n", 
 113.517 +                fprintf(stderr, "qemu: warning: error while loading state for instance 0x%x of device '%s'\n",
 113.518                          instance_id, idstr);
 113.519              }
 113.520          }
 113.521 @@ -2042,7 +2045,7 @@ void polling_handler(void *opaque)
 113.522              }
 113.523              ioh->max_size = max_size;
 113.524          }
 113.525 -        
 113.526 +
 113.527          ret = poll(ufds, pf - ufds, timeout);
 113.528          if (ret > 0) {
 113.529              /* XXX: better handling of removal */
 113.530 @@ -2096,7 +2099,7 @@ void vm_start(void)
 113.531      }
 113.532  }
 113.533  
 113.534 -void vm_stop(int reason) 
 113.535 +void vm_stop(int reason)
 113.536  {
 113.537      if (vm_running) {
 113.538          cpu_disable_ticks();
 113.539 @@ -2160,14 +2163,14 @@ void qemu_system_shutdown_request(void)
 113.540  void main_loop_wait(int timeout)
 113.541  {
 113.542          if (vm_running) {
 113.543 -            qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], 
 113.544 +            qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL],
 113.545                              qemu_get_clock(vm_clock));
 113.546              /* run dma transfers, if any */
 113.547              DMA_run();
 113.548          }
 113.549  
 113.550          /* real time timers */
 113.551 -        qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME], 
 113.552 +        qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME],
 113.553                          qemu_get_clock(rt_clock));
 113.554  }
 113.555  
 113.556 @@ -2184,19 +2187,19 @@ void help(void)
 113.557             "-hdc/-hdd file  use 'file' as IDE hard disk 2/3 image\n"
 113.558             "-cdrom file     use 'file' as IDE cdrom image (cdrom is ide1 master)\n"
 113.559             "-boot [a|c|d]   boot on floppy (a), hard disk (c) or CD-ROM (d)\n"
 113.560 -	   "-snapshot       write to temporary files instead of disk image files\n"
 113.561 +           "-snapshot       write to temporary files instead of disk image files\n"
 113.562             "-m megs         set virtual RAM size to megs MB [default=%d]\n"
 113.563             "-nographic      disable graphical output and redirect serial I/Os to console\n"
 113.564             "-vcpus          set CPU number of guest platform\n"
 113.565  #ifdef CONFIG_VNC
 113.566 -	   "-vnc port             use vnc instead of sdl\n"
 113.567 -	   "-vncport port         use a different port\n"
 113.568 -	   "-vncconnect host:port do a reverse connect\n"
 113.569 +           "-vnc port             use vnc instead of sdl\n"
 113.570 +           "-vncport port         use a different port\n"
 113.571 +           "-vncconnect host:port do a reverse connect\n"
 113.572  #ifdef CONFIG_SDL
 113.573 -	   "-vnc-and-sdl    use vnc and sdl simultaneously\n"
 113.574 +           "-vnc-and-sdl    use vnc and sdl simultaneously\n"
 113.575  #endif
 113.576  #endif
 113.577 -	   "-k <language>   use keyboard layout (for example \"fr\" for french)\n"
 113.578 +           "-k <language>   use keyboard layout (for example \"fr\" for french)\n"
 113.579             "-enable-audio   enable audio support\n"
 113.580             "-localtime      set the real time clock to local time [default=utc]\n"
 113.581             "-full-screen    start in full screen\n"
 113.582 @@ -2234,7 +2237,7 @@ void help(void)
 113.583             "-S              freeze CPU at startup (use 'c' to start execution)\n"
 113.584             "-s              wait gdb connection to port %d\n"
 113.585             "-p port         ioreq port for xen\n"
 113.586 -           "-d domain	    domain that we're serving\n"
 113.587 +           "-d domain       domain that we're serving\n"
 113.588             "-hdachs c,h,s   force hard disk 0 geometry (usually qemu can guess it)\n"
 113.589             "-L path         set the directory for the BIOS and VGA BIOS\n"
 113.590  #ifdef USE_CODE_COPY
 113.591 @@ -2408,7 +2411,7 @@ const QEMUOption qemu_options[] = {
 113.592      { "serial", 1, QEMU_OPTION_serial },
 113.593      { "loadvm", HAS_ARG, QEMU_OPTION_loadvm },
 113.594      { "full-screen", 0, QEMU_OPTION_full_screen },
 113.595 -    
 113.596 +
 113.597      /* temporary options */
 113.598      { "pci", 0, QEMU_OPTION_pci },
 113.599      { "nic-ne2000", 0, QEMU_OPTION_nic_ne2000 },
 113.600 @@ -2460,7 +2463,9 @@ get_vl2_table(unsigned long count, unsig
 113.601  }
 113.602  
 113.603  int
 113.604 -setup_mapping(int xc_handle, uint32_t dom, unsigned long toptab, unsigned long  *mem_page_array, unsigned long *page_table_array, unsigned long v_start, unsigned long v_end)
 113.605 +setup_mapping(int xc_handle, uint32_t dom, unsigned long toptab,
 113.606 +              unsigned long  *mem_page_array, unsigned long *page_table_array,
 113.607 +              unsigned long v_start, unsigned long v_end)
 113.608  {
 113.609      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
 113.610      l2_pgentry_t *vl2tab[4] = {NULL, NULL, NULL, NULL};
 113.611 @@ -2472,23 +2477,24 @@ setup_mapping(int xc_handle, uint32_t do
 113.612  #if _LEVEL_3_
 113.613      l3_pgentry_t *vl3tab = NULL;
 113.614      unsigned long l2tab;
 113.615 -    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
 113.616 -                                        PROT_READ|PROT_WRITE, 
 113.617 +
 113.618 +    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
 113.619 +                                        PROT_READ|PROT_WRITE,
 113.620                                          toptab >> PAGE_SHIFT)) == NULL )
 113.621          goto error_out;
 113.622      for (i = 0; i < 4 ; i++) {
 113.623          l2tab = vl3tab[i] & PAGE_MASK;
 113.624          vl2tab[i] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
 113.625 -          PROT_READ|PROT_WRITE,
 113.626 -          l2tab >> PAGE_SHIFT);
 113.627 +                                         PROT_READ|PROT_WRITE,
 113.628 +                                         l2tab >> PAGE_SHIFT);
 113.629          if(vl2tab[i] == NULL)
 113.630              goto error_out;
 113.631      }
 113.632      munmap(vl3tab, PAGE_SIZE);
 113.633      vl3tab = NULL;
 113.634  #else
 113.635 -    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
 113.636 -                                           PROT_READ|PROT_WRITE, 
 113.637 +    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
 113.638 +                                           PROT_READ|PROT_WRITE,
 113.639                                             toptab >> PAGE_SHIFT)) == NULL )
 113.640          goto error_out;
 113.641  #endif
 113.642 @@ -2498,8 +2504,8 @@ setup_mapping(int xc_handle, uint32_t do
 113.643          if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
 113.644          {
 113.645              vl2_table = vl2tab[get_vl2_table(count, v_start)];
 113.646 -            vl2e = &vl2_table[l2_table_offset(
 113.647 -                v_start + (count << PAGE_SHIFT))];
 113.648 +            vl2e = &vl2_table[l2_table_offset(v_start +
 113.649 +                                              (count << PAGE_SHIFT))];
 113.650  
 113.651              l1tab = page_table_array[ppt_alloc++] << PAGE_SHIFT;
 113.652              if ( vl1tab != NULL )
 113.653 @@ -2520,14 +2526,16 @@ setup_mapping(int xc_handle, uint32_t do
 113.654          vl1e++;
 113.655      }
 113.656  error_out:
 113.657 -    if(vl1tab)  munmap(vl1tab, PAGE_SIZE);
 113.658 +    if (vl1tab)
 113.659 +        munmap(vl1tab, PAGE_SIZE);
 113.660      for(i = 0; i < 4; i++)
 113.661          if(vl2tab[i]) munmap(vl2tab[i], PAGE_SIZE);
 113.662      return ppt_alloc;
 113.663  }
 113.664  
 113.665  void
 113.666 -unsetup_mapping(int xc_handle, uint32_t dom, unsigned long toptab, unsigned long v_start, unsigned long v_end)
 113.667 +unsetup_mapping(int xc_handle, uint32_t dom, unsigned long toptab,
 113.668 +                unsigned long v_start, unsigned long v_end)
 113.669  {
 113.670      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
 113.671      l2_pgentry_t *vl2tab[4], *vl2e=NULL, *vl2_table = NULL;
 113.672 @@ -2537,28 +2545,29 @@ unsetup_mapping(int xc_handle, uint32_t 
 113.673  #if _LEVEL_3_
 113.674      l3_pgentry_t *vl3tab = NULL;
 113.675      unsigned long l2tab;
 113.676 -    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
 113.677 -                                        PROT_READ|PROT_WRITE, 
 113.678 +
 113.679 +    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
 113.680 +                                        PROT_READ|PROT_WRITE,
 113.681                                          toptab >> PAGE_SHIFT)) == NULL )
 113.682          goto error_out;
 113.683 -    for (i = 0; i < 4 ; i ++){
 113.684 +    for (i = 0; i < 4 ; i ++) {
 113.685          l2tab = vl3tab[i] & PAGE_MASK;
 113.686          vl2tab[i] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
 113.687 -          PROT_READ|PROT_WRITE,
 113.688 -          l2tab >> PAGE_SHIFT);
 113.689 -        if(vl2tab[i] == NULL)
 113.690 +                                         PROT_READ|PROT_WRITE,
 113.691 +                                         l2tab >> PAGE_SHIFT);
 113.692 +        if (vl2tab[i] == NULL)
 113.693              goto error_out;
 113.694      }
 113.695      munmap(vl3tab, PAGE_SIZE);
 113.696      vl3tab = NULL;
 113.697  #else
 113.698 -    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
 113.699 -                                        PROT_READ|PROT_WRITE, 
 113.700 -                                        toptab >> PAGE_SHIFT)) == NULL )
 113.701 +    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
 113.702 +                                           PROT_READ|PROT_WRITE,
 113.703 +                                           toptab >> PAGE_SHIFT)) == NULL )
 113.704          goto error_out;
 113.705  #endif
 113.706  
 113.707 -    for ( count = 0; count < ((v_end-v_start)>>PAGE_SHIFT); count++ ){
 113.708 +    for ( count = 0; count < ((v_end-v_start)>>PAGE_SHIFT); count++ ) {
 113.709          if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
 113.710          {
 113.711              vl2_table = vl2tab[get_vl2_table(count, v_start)];
 113.712 @@ -2571,8 +2580,8 @@ unsetup_mapping(int xc_handle, uint32_t 
 113.713                  munmap(vl1tab, PAGE_SIZE);
 113.714  
 113.715              if ( (vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
 113.716 -                      PROT_READ|PROT_WRITE,
 113.717 -                      l1tab >> PAGE_SHIFT)) == NULL )
 113.718 +                                                PROT_READ|PROT_WRITE,
 113.719 +                                                l1tab >> PAGE_SHIFT)) == NULL )
 113.720              {
 113.721                  goto error_out;
 113.722              }
 113.723 @@ -2583,17 +2592,20 @@ unsetup_mapping(int xc_handle, uint32_t 
 113.724          *vl1e = 0;
 113.725          vl1e++;
 113.726      }
 113.727 +
 113.728  error_out:
 113.729 -    if(vl1tab)  munmap(vl1tab, PAGE_SIZE);
 113.730 +    if (vl1tab)
 113.731 +        munmap(vl1tab, PAGE_SIZE);
 113.732      for(i = 0; i < 4; i++)
 113.733 -        if(vl2tab[i]) munmap(vl2tab[i], PAGE_SIZE);
 113.734 +        if (vl2tab[i])
 113.735 +            munmap(vl2tab[i], PAGE_SIZE);
 113.736  }
 113.737  
 113.738  void set_vram_mapping(unsigned long addr, unsigned long end)
 113.739  {
 113.740      end = addr + VGA_RAM_SIZE;
 113.741      setup_mapping(xc_handle, domid, toptab,
 113.742 -      vgapage_array, freepage_array, addr, end);
 113.743 +                  vgapage_array, freepage_array, addr, end);
 113.744  }
 113.745  
 113.746  void unset_vram_mapping(unsigned long addr, unsigned long end)
 113.747 @@ -2633,9 +2645,7 @@ int main(int argc, char **argv)
 113.748      unsigned long nr_pages, extra_pages, ram_pages, *page_array;
 113.749      extern void *shared_page;
 113.750      extern void *shared_vram;
 113.751 -    /* change the qemu-dm to daemon, just like bochs dm */
 113.752 -//    daemon(0, 0);
 113.753 -    
 113.754 +
 113.755  #if !defined(CONFIG_SOFTMMU)
 113.756      /* we never want that malloc() uses mmap() */
 113.757      mallopt(M_MMAP_THRESHOLD, 4096 * 1024);
 113.758 @@ -2668,7 +2678,7 @@ int main(int argc, char **argv)
 113.759      for(i = 1; i < MAX_SERIAL_PORTS; i++)
 113.760          serial_devices[i][0] = '\0';
 113.761      serial_device_index = 0;
 113.762 -    
 113.763 +
 113.764      nb_tun_fds = 0;
 113.765      net_if_type = -1;
 113.766      nb_nics = 1;
 113.767 @@ -2679,7 +2689,7 @@ int main(int argc, char **argv)
 113.768      macaddr[3] = 0x12;
 113.769      macaddr[4] = 0x34;
 113.770      macaddr[5] = 0x56;
 113.771 -    
 113.772 +
 113.773      /* init debug */
 113.774      cpu_set_log(0);
 113.775  
 113.776 @@ -2697,7 +2707,7 @@ int main(int argc, char **argv)
 113.777              popt = qemu_options;
 113.778              for(;;) {
 113.779                  if (!popt->name) {
 113.780 -                    fprintf(stderr, "%s: invalid option -- '%s'\n", 
 113.781 +                    fprintf(stderr, "%s: invalid option -- '%s'\n",
 113.782                              argv[0], r);
 113.783                      exit(1);
 113.784                  }
 113.785 @@ -2756,25 +2766,23 @@ int main(int argc, char **argv)
 113.786                  nographic = 1;
 113.787                  break;
 113.788  #ifdef CONFIG_VNC
 113.789 -	    case QEMU_OPTION_vnc:
 113.790 -            usevnc = 1;
 113.791 -            break;  
 113.792 -	    case QEMU_OPTION_vncport:
 113.793 -        {
 113.794 -            const char *p;
 113.795 -            p = optarg;
 113.796 -            vncport= strtol(optarg, (char **)&p, 0);
 113.797 -        }
 113.798 -        break;
 113.799 -	    case QEMU_OPTION_vncconnect:
 113.800 -        {
 113.801 -            vncconnect=optarg;
 113.802 -        }
 113.803 -        break;
 113.804 +            case QEMU_OPTION_vnc:
 113.805 +                usevnc = 1;
 113.806 +                break;
 113.807 +            case QEMU_OPTION_vncport:
 113.808 +                {
 113.809 +                    const char *p;
 113.810 +                    p = optarg;
 113.811 +                    vncport= strtol(optarg, (char **)&p, 0);
 113.812 +                }
 113.813 +                break;
 113.814 +            case QEMU_OPTION_vncconnect:
 113.815 +                vncconnect = optarg;
 113.816 +                break;
 113.817  #ifdef CONFIG_SDL
 113.818 -	    case QEMU_OPTION_vnc_and_sdl:
 113.819 -		usevnc = 2;
 113.820 -		break;
 113.821 +            case QEMU_OPTION_vnc_and_sdl:
 113.822 +                usevnc = 2;
 113.823 +                break;
 113.824  #endif
 113.825  #endif
 113.826              case QEMU_OPTION_kernel:
 113.827 @@ -2783,21 +2791,23 @@ int main(int argc, char **argv)
 113.828              case QEMU_OPTION_append:
 113.829                  kernel_cmdline = optarg;
 113.830                  break;
 113.831 -	    case QEMU_OPTION_tun_fd:
 113.832 +            case QEMU_OPTION_tun_fd:
 113.833                  {
 113.834                      const char *p;
 113.835                      int fd;
 113.836                      net_if_type = NET_IF_TUN;
 113.837 -                    if (nb_tun_fds < MAX_NICS) {
 113.838 +                    if ( nb_tun_fds < MAX_NICS ) {
 113.839                          fd = strtol(optarg, (char **)&p, 0);
 113.840                          if (*p != '\0') {
 113.841 -                            fprintf(stderr, "qemu: invalid fd for network interface %d\n", nb_tun_fds);
 113.842 +                            fprintf(stderr,
 113.843 +                                    "qemu: invalid fd for network interface %d\n",
 113.844 +                                    nb_tun_fds);
 113.845                              exit(1);
 113.846                          }
 113.847                          tun_fds[nb_tun_fds++] = fd;
 113.848                      }
 113.849                  }
 113.850 -		break;
 113.851 +                break;
 113.852              case QEMU_OPTION_hdc:
 113.853                  hd_filename[2] = optarg;
 113.854                  has_cdrom = 0;
 113.855 @@ -2811,9 +2821,11 @@ int main(int argc, char **argv)
 113.856                  break;
 113.857              case QEMU_OPTION_boot:
 113.858                  boot_device = optarg[0];
 113.859 -                if (boot_device != 'a' && 
 113.860 -                    boot_device != 'c' && boot_device != 'd') {
 113.861 -                    fprintf(stderr, "qemu: invalid boot device '%c'\n", boot_device);
 113.862 +                if ( boot_device != 'a' &&
 113.863 +                     boot_device != 'c' &&
 113.864 +                     boot_device != 'd' ) {
 113.865 +                    fprintf(stderr, "qemu: invalid boot device '%c'\n",
 113.866 +                                    boot_device);
 113.867                      exit(1);
 113.868                  }
 113.869                  break;
 113.870 @@ -2826,7 +2838,8 @@ int main(int argc, char **argv)
 113.871              case QEMU_OPTION_nics:
 113.872                  nb_nics = atoi(optarg);
 113.873                  if (nb_nics < 0 || nb_nics > MAX_NICS) {
 113.874 -                    fprintf(stderr, "qemu: invalid number of network interfaces\n");
 113.875 +                    fprintf(stderr,
 113.876 +                            "qemu: invalid number of network interfaces\n");
 113.877                      exit(1);
 113.878                  }
 113.879                  break;
 113.880 @@ -2837,16 +2850,18 @@ int main(int argc, char **argv)
 113.881                  {
 113.882                      const char *p;
 113.883                      int i;
 113.884 +
 113.885                      p = optarg;
 113.886 -                    for(i = 0; i < 6; i++) {
 113.887 +                    for (i = 0; i < 6; i++) {
 113.888                          macaddr[i] = strtol(p, (char **)&p, 16);
 113.889                          if (i == 5) {
 113.890 -                            if (*p != '\0') 
 113.891 +                            if (*p != '\0')
 113.892                                  goto macaddr_error;
 113.893                          } else {
 113.894                              if (*p != ':') {
 113.895                              macaddr_error:
 113.896 -                                fprintf(stderr, "qemu: invalid syntax for ethernet address\n");
 113.897 +                                fprintf(stderr, "qemu: invalid syntax "
 113.898 +                                                "for ethernet address\n");
 113.899                                  exit(1);
 113.900                              }
 113.901                              p++;
 113.902 @@ -2856,18 +2871,18 @@ int main(int argc, char **argv)
 113.903                  break;
 113.904  #ifdef CONFIG_SLIRP
 113.905              case QEMU_OPTION_tftp:
 113.906 -		tftp_prefix = optarg;
 113.907 +                tftp_prefix = optarg;
 113.908                  break;
 113.909  #ifndef _WIN32
 113.910              case QEMU_OPTION_smb:
 113.911 -		net_slirp_smb(optarg);
 113.912 +                net_slirp_smb(optarg);
 113.913                  break;
 113.914  #endif
 113.915              case QEMU_OPTION_user_net:
 113.916                  net_if_type = NET_IF_USER;
 113.917                  break;
 113.918              case QEMU_OPTION_redir:
 113.919 -                net_slirp_redir(optarg);                
 113.920 +                net_slirp_redir(optarg);
 113.921                  break;
 113.922  #endif
 113.923              case QEMU_OPTION_dummy_net:
 113.924 @@ -2886,24 +2901,23 @@ int main(int argc, char **argv)
 113.925                  break;
 113.926              case QEMU_OPTION_d:
 113.927                  {
 113.928 -                  domid = atoi(optarg);
 113.929 -                  printf("domid: %d\n", domid);
 113.930 +                    domid = atoi(optarg);
 113.931 +                    fprintf(logfile, "domid: %d\n", domid);
 113.932                  }
 113.933                  break;
 113.934 -
 113.935              case QEMU_OPTION_p:
 113.936                  {
 113.937 -                  extern uint16_t ioreq_remote_port;
 113.938 -                  ioreq_remote_port = atoi(optarg);
 113.939 -                  printf("port: %d\n", ioreq_remote_port);
 113.940 +                    extern evtchn_port_t ioreq_remote_port;
 113.941 +                    ioreq_remote_port = atoi(optarg);
 113.942 +                    fprintf(logfile, "eport: %d\n", ioreq_remote_port);
 113.943                  }
 113.944                  break;
 113.945              case QEMU_OPTION_l:
 113.946                  {
 113.947 -                  int mask;
 113.948 -                  mask = cpu_str_to_log_mask(optarg);
 113.949 -                  printf("mask: %x\n", mask);
 113.950 -                  cpu_set_log(mask);
 113.951 +                    int mask;
 113.952 +                    mask = cpu_str_to_log_mask(optarg);
 113.953 +                    fprintf(logfile, "mask: %x\n", mask);
 113.954 +                    cpu_set_log(mask);
 113.955                  }
 113.956                  break;
 113.957              case QEMU_OPTION_n:
 113.958 @@ -2935,9 +2949,9 @@ int main(int argc, char **argv)
 113.959              case QEMU_OPTION_prep:
 113.960                  prep_enabled = 1;
 113.961                  break;
 113.962 -	    case QEMU_OPTION_k:
 113.963 -		keyboard_layout = optarg;
 113.964 -		break;
 113.965 +            case QEMU_OPTION_k:
 113.966 +                keyboard_layout = optarg;
 113.967 +                break;
 113.968              case QEMU_OPTION_localtime:
 113.969                  rtc_utc = 0;
 113.970                  break;
 113.971 @@ -2953,8 +2967,8 @@ int main(int argc, char **argv)
 113.972                          fprintf(stderr, "qemu: invalid vgaacc option\n");
 113.973                          exit(1);
 113.974                      }
 113.975 -                    break;
 113.976                  }
 113.977 +                break;
 113.978              case QEMU_OPTION_std_vga:
 113.979                  cirrus_vga_enabled = 0;
 113.980                  break;
 113.981 @@ -2978,7 +2992,7 @@ int main(int argc, char **argv)
 113.982                      if (*p == 'x') {
 113.983                          p++;
 113.984                          depth = strtol(p, (char **)&p, 10);
 113.985 -                        if (depth != 8 && depth != 15 && depth != 16 && 
 113.986 +                        if (depth != 8 && depth != 15 && depth != 16 &&
 113.987                              depth != 24 && depth != 32)
 113.988                              goto graphic_error;
 113.989                      } else if (*p == '\0') {
 113.990 @@ -2986,7 +3000,7 @@ int main(int argc, char **argv)
 113.991                      } else {
 113.992                          goto graphic_error;
 113.993                      }
 113.994 -                    
 113.995 +
 113.996                      graphic_width = w;
 113.997                      graphic_height = h;
 113.998                      graphic_depth = depth;
 113.999 @@ -3000,13 +3014,13 @@ int main(int argc, char **argv)
113.1000                      fprintf(stderr, "qemu: too many serial ports\n");
113.1001                      exit(1);
113.1002                  }
113.1003 -                pstrcpy(serial_devices[serial_device_index], 
113.1004 +                pstrcpy(serial_devices[serial_device_index],
113.1005                          sizeof(serial_devices[0]), optarg);
113.1006                  serial_device_index++;
113.1007                  break;
113.1008 -	    case QEMU_OPTION_loadvm:
113.1009 -		loadvm = optarg;
113.1010 -		break;
113.1011 +            case QEMU_OPTION_loadvm:
113.1012 +                loadvm = optarg;
113.1013 +                break;
113.1014              case QEMU_OPTION_full_screen:
113.1015                  full_screen = 1;
113.1016                  break;
113.1017 @@ -3015,11 +3029,11 @@ int main(int argc, char **argv)
113.1018      }
113.1019  
113.1020      linux_boot = (kernel_filename != NULL);
113.1021 -        
113.1022 -    if (!linux_boot && hd_filename[0] == '\0' && hd_filename[2] == '\0' &&
113.1023 -        fd_filename[0] == '\0')
113.1024 +
113.1025 +    if ( !linux_boot && hd_filename[0] == '\0' &&
113.1026 +         hd_filename[2] == '\0' && fd_filename[0] == '\0' )
113.1027          help();
113.1028 -    
113.1029 +
113.1030      /* boot to cd by default if no hard disk */
113.1031      if (hd_filename[0] == '\0' && boot_device == 'c') {
113.1032          if (fd_filename[0] != '\0')
113.1033 @@ -3102,89 +3116,96 @@ int main(int argc, char **argv)
113.1034      nr_pages = info.nr_pages + extra_pages;
113.1035  
113.1036      if ( xc_domain_setmaxmem(xc_handle, domid,
113.1037 -            (nr_pages) * PAGE_SIZE/1024 ) != 0)
113.1038 +                             (nr_pages) * PAGE_SIZE/1024 ) != 0)
113.1039      {
113.1040 -        perror("set maxmem");
113.1041 +        fprintf(logfile, "set maxmem returned error %d\n", errno);
113.1042          exit(-1);
113.1043      }
113.1044 -   
113.1045 +
113.1046      if ( (page_array = (unsigned long *)
113.1047 -	  malloc(nr_pages * sizeof(unsigned long))) == NULL)
113.1048 +                        malloc(nr_pages * sizeof(unsigned long))) == NULL)
113.1049      {
113.1050 -	    perror("malloc");
113.1051 -	    exit(-1);
113.1052 +        fprintf(logfile, "malloc returned error %d\n", errno);
113.1053 +        exit(-1);
113.1054      }
113.1055  
113.1056 -    if (xc_domain_memory_increase_reservation(xc_handle, domid, 
113.1057 -          extra_pages , 0, 0, NULL) != 0) {
113.1058 -        perror("increase reservation");
113.1059 +    if (xc_domain_memory_increase_reservation(xc_handle, domid,
113.1060 +                                              extra_pages , 0, 0, NULL) != 0)
113.1061 +    {
113.1062 +        fprintf(logfile, "increase reservation returned error %d\n", errno);
113.1063          exit(-1);
113.1064      }
113.1065  
113.1066  #if defined(__i386__) || defined(__x86_64__)
113.1067      if ( xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages )
113.1068      {
113.1069 -	    perror("xc_get_pfn_list");
113.1070 -	    exit(-1);
113.1071 +        fprintf(logfile, "xc_get_pfn_list returned error %d\n", errno);
113.1072 +        exit(-1);
113.1073      }
113.1074  
113.1075 -    if ((phys_ram_base =  xc_map_foreign_batch(xc_handle, domid,
113.1076 -						 PROT_READ|PROT_WRITE,
113.1077 -						 page_array,
113.1078 -						 ram_pages - 1)) == 0) {
113.1079 -	    perror("xc_map_foreign_batch");
113.1080 -	    exit(-1);
113.1081 +    if ( (phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
113.1082 +                          PROT_READ|PROT_WRITE,
113.1083 +                          page_array,
113.1084 +                          ram_pages - 1)) == 0 )
113.1085 +    {
113.1086 +        fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
113.1087 +        exit(-1);
113.1088      }
113.1089  
113.1090      shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
113.1091 -				       PROT_READ|PROT_WRITE,
113.1092 - 				       page_array[ram_pages - 1]);
113.1093 +                                       PROT_READ|PROT_WRITE,
113.1094 +                                       page_array[ram_pages - 1]);
113.1095  
113.1096      vgapage_array = &page_array[nr_pages - vgaram_pages];
113.1097  
113.1098 -    if ((shared_vram =  xc_map_foreign_batch(xc_handle, domid,
113.1099 - 						 PROT_READ|PROT_WRITE,
113.1100 - 						 vgapage_array,
113.1101 - 						 vgaram_pages)) == 0) {
113.1102 - 	    perror("xc_map_foreign_batch vgaram ");
113.1103 - 	    exit(-1);
113.1104 -     }
113.1105 +    if ( (shared_vram =  xc_map_foreign_batch(xc_handle, domid,
113.1106 +                                              PROT_READ|PROT_WRITE,
113.1107 +                                              vgapage_array,
113.1108 +                                              vgaram_pages)) == 0)
113.1109 +    {
113.1110 +        fprintf(logfile,
113.1111 +                "xc_map_foreign_batch vgaram returned error %d\n", errno);
113.1112 +        exit(-1);
113.1113 +    }
113.1114  
113.1115      memset(shared_vram, 0, vgaram_pages * PAGE_SIZE);
113.1116      toptab = page_array[ram_pages] << PAGE_SHIFT;
113.1117  
113.1118      vtop_table = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
113.1119 -				       PROT_READ|PROT_WRITE,
113.1120 - 				       page_array[ram_pages]);
113.1121 +                                      PROT_READ|PROT_WRITE,
113.1122 +                                      page_array[ram_pages]);
113.1123  
113.1124      freepage_array = &page_array[nr_pages - extra_pages];
113.1125  #elif defined(__ia64__)
113.1126 -    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array, 0, ram_pages) != ram_pages)
113.1127 +    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array, 0, ram_pages)
113.1128 +         != ram_pages )
113.1129      {
113.1130 -        perror("xc_ia64_get_pfn_list");
113.1131 +        fprintf(logfile, "xc_ia64_get_pfn_list returned error %d\n", errno);
113.1132          exit(-1);
113.1133      }
113.1134  
113.1135 -    if ((phys_ram_base =  xc_map_foreign_batch(xc_handle, domid,
113.1136 -						 PROT_READ|PROT_WRITE,
113.1137 -						 page_array,
113.1138 -						 ram_pages)) == 0) {
113.1139 -	    perror("xc_map_foreign_batch");
113.1140 -	    exit(-1);
113.1141 +    if ( (phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
113.1142 +                          PROT_READ|PROT_WRITE,
113.1143 +                          page_array,
113.1144 +                          ram_pages)) == 0 )
113.1145 +    {
113.1146 +        fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
113.1147 +        exit(-1);
113.1148      }
113.1149  
113.1150 -    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array, IO_PAGE_START>>PAGE_SHIFT, 1) != 1)
113.1151 +    if ( xc_ia64_get_pfn_list(xc_handle, domid,
113.1152 +                              page_array, IO_PAGE_START >> PAGE_SHIFT, 1) != 1 )
113.1153      {
113.1154 -        perror("xc_ia64_get_pfn_list");
113.1155 +        fprintf(logfile, "xc_ia64_get_pfn_list returned error %d\n", errno);
113.1156          exit(-1);
113.1157      }
113.1158  
113.1159      shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
113.1160 -				       PROT_READ|PROT_WRITE,
113.1161 - 				       page_array[0]);
113.1162 -#endif 
113.1163 -
113.1164 -    fprintf(logfile, "shared page at pfn:%lx, mfn: %lx\n", (nr_pages-1), 
113.1165 +                                       PROT_READ|PROT_WRITE,
113.1166 +                                       page_array[0]);
113.1167 +#endif
113.1168 +
113.1169 +    fprintf(logfile, "shared page at pfn:%lx, mfn: %lx\n", (nr_pages-1),
113.1170             (page_array[nr_pages - 1]));
113.1171  
113.1172      /* we always create the cdrom drive, even if no disk is there */
113.1173 @@ -3207,7 +3228,7 @@ int main(int argc, char **argv)
113.1174                          hd_filename[i]);
113.1175                  exit(1);
113.1176              }
113.1177 -            if (i == 0 && cyls != 0) 
113.1178 +            if (i == 0 && cyls != 0)
113.1179                  bdrv_set_geometry_hint(bs_table[i], cyls, heads, secs);
113.1180          }
113.1181      }
113.1182 @@ -3246,23 +3267,23 @@ int main(int argc, char **argv)
113.1183      if (nographic) {
113.1184          dumb_display_init(ds);
113.1185      } else {
113.1186 -	if (usevnc) {
113.1187 +        if (usevnc) {
113.1188  #ifdef CONFIG_VNC
113.1189 -	    vnc_display_init(ds, (usevnc==2), vncport, vncconnect);
113.1190 +            vnc_display_init(ds, (usevnc==2), vncport, vncconnect);
113.1191  #else
113.1192 -	    perror("qemu not configured with vnc support");
113.1193 +            fprintf(logfile, "qemu not configured with vnc support\n");
113.1194  #endif
113.1195 -	} else {
113.1196 +        } else {
113.1197  #ifdef CONFIG_SDL
113.1198 -        sdl_display_init(ds, full_screen);
113.1199 +            sdl_display_init(ds, full_screen);
113.1200  #else
113.1201 -        dumb_display_init(ds);
113.1202 +            dumb_display_init(ds);
113.1203  #endif
113.1204 -    }
113.1205 +        }
113.1206      }
113.1207  
113.1208      vga_console = graphic_console_init(ds);
113.1209 -    
113.1210 +
113.1211      monitor_hd = qemu_chr_open(monitor_device);
113.1212      if (!monitor_hd) {
113.1213          fprintf(stderr, "qemu: could not open monitor device '%s'\n", monitor_device);
113.1214 @@ -3274,7 +3295,7 @@ int main(int argc, char **argv)
113.1215          if (serial_devices[i][0] != '\0') {
113.1216              serial_hds[i] = qemu_chr_open(serial_devices[i]);
113.1217              if (!serial_hds[i]) {
113.1218 -                fprintf(stderr, "qemu: could not open serial device '%s'\n", 
113.1219 +                fprintf(stderr, "qemu: could not open serial device '%s'\n",
113.1220                          serial_devices[i]);
113.1221                  exit(1);
113.1222              }
113.1223 @@ -3285,7 +3306,7 @@ int main(int argc, char **argv)
113.1224  
113.1225      /* setup cpu signal handlers for MMU / self modifying code handling */
113.1226  #if !defined(CONFIG_SOFTMMU)
113.1227 -    
113.1228 +
113.1229  #if defined (TARGET_I386) && defined(USE_CODE_COPY)
113.1230      {
113.1231          stack_t stk;
113.1232 @@ -3295,14 +3316,14 @@ int main(int argc, char **argv)
113.1233          stk.ss_flags = 0;
113.1234  
113.1235          if (sigaltstack(&stk, NULL) < 0) {
113.1236 -            perror("sigaltstack");
113.1237 +            fprintf(logfile, "sigaltstack returned error %d\n", errno);
113.1238              exit(1);
113.1239          }
113.1240      }
113.1241  #endif
113.1242      {
113.1243          struct sigaction act;
113.1244 -        
113.1245 +
113.1246          sigfillset(&act.sa_mask);
113.1247          act.sa_flags = SA_SIGINFO;
113.1248  #if defined (TARGET_I386) && defined(USE_CODE_COPY)
113.1249 @@ -3334,8 +3355,8 @@ int main(int argc, char **argv)
113.1250              kernel_filename, kernel_cmdline, initrd_filename);
113.1251  #elif defined(TARGET_PPC)
113.1252      ppc_init(ram_size, vga_ram_size, boot_device,
113.1253 -	     ds, fd_filename, snapshot,
113.1254 -	     kernel_filename, kernel_cmdline, initrd_filename);
113.1255 +            ds, fd_filename, snapshot,
113.1256 +            kernel_filename, kernel_cmdline, initrd_filename);
113.1257  #elif defined(TARGET_SPARC)
113.1258      sun4m_init(ram_size, vga_ram_size, boot_device,
113.1259              ds, fd_filename, snapshot,
113.1260 @@ -3351,13 +3372,13 @@ int main(int argc, char **argv)
113.1261  #ifdef CONFIG_GDBSTUB
113.1262      if (use_gdbstub) {
113.1263          if (gdbserver_start(gdbstub_port) < 0) {
113.1264 -            fprintf(stderr, "Could not open gdbserver socket on port %d\n", 
113.1265 +            fprintf(stderr, "Could not open gdbserver socket on port %d\n",
113.1266                      gdbstub_port);
113.1267              exit(1);
113.1268          } else {
113.1269 -            printf("Waiting gdb connection on port %d\n", gdbstub_port);
113.1270 +            fprintf(logfile, "Waiting gdb connection on port %d\n", gdbstub_port);
113.1271          }
113.1272 -    } else 
113.1273 +    } else
113.1274  #endif
113.1275      if (loadvm)
113.1276          qemu_loadvm(loadvm);
113.1277 @@ -3389,7 +3410,7 @@ void tun_receive_handler(fd_set *rfds)
113.1278                  n = read(ioh->fd, buf, max_size);
113.1279                  if (n >= 0) {
113.1280                      ioh->fd_read(ioh->opaque, buf, n);
113.1281 -                } 
113.1282 +                }
113.1283              }
113.1284          }
113.1285      }
113.1286 @@ -3411,5 +3432,3 @@ void update_select_wakeup_events(void)
113.1287          }
113.1288      }
113.1289  }
113.1290 -
113.1291 -
   114.1 --- a/tools/libxc/Makefile	Fri Dec 02 12:12:11 2005 -0600
   114.2 +++ b/tools/libxc/Makefile	Fri Dec 02 12:52:25 2005 -0600
   114.3 @@ -49,6 +49,11 @@ CFLAGS   += -Werror
   114.4  CFLAGS   += -O3
   114.5  CFLAGS   += -fno-strict-aliasing
   114.6  CFLAGS   += $(INCLUDES) -I.
   114.7 +
   114.8 +# Define this to make it possible to run valgrind on code linked with these
   114.9 +# libraries.
  114.10 +#CFLAGS   += -DVALGRIND -O0 -ggdb3
  114.11 +
  114.12  # Get gcc to generate the dependencies for us.
  114.13  CFLAGS   += -Wp,-MD,.$(@F).d
  114.14  LDFLAGS  += -L.
  114.15 @@ -78,17 +83,6 @@ check-for-zlib:
  114.16  	false; \
  114.17  	fi
  114.18  
  114.19 -LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse
  114.20 -mk-symlinks:
  114.21 -	[ -e xen/linux ] || mkdir -p xen/linux
  114.22 -	[ -e xen/io ]    || mkdir -p xen/io
  114.23 -	( cd xen >/dev/null ; \
  114.24 -	  ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
  114.25 -	( cd xen/io >/dev/null ; \
  114.26 -	   ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
  114.27 -	( cd xen/linux >/dev/null ; \
  114.28 -	  ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
  114.29 -
  114.30  install: build
  114.31  	[ -d $(DESTDIR)/usr/$(LIBDIR) ] || $(INSTALL_DIR) $(DESTDIR)/usr/$(LIBDIR)
  114.32  	[ -d $(DESTDIR)/usr/include ] || $(INSTALL_DIR) $(DESTDIR)/usr/include
   115.1 --- a/tools/libxc/xc_bvtsched.c	Fri Dec 02 12:12:11 2005 -0600
   115.2 +++ b/tools/libxc/xc_bvtsched.c	Fri Dec 02 12:52:25 2005 -0600
   115.3 @@ -11,7 +11,7 @@
   115.4  int xc_bvtsched_global_set(int xc_handle,
   115.5                             unsigned long ctx_allow)
   115.6  {
   115.7 -    dom0_op_t op;
   115.8 +    DECLARE_DOM0_OP;
   115.9  
  115.10      op.cmd = DOM0_SCHEDCTL;
  115.11      op.u.schedctl.sched_id = SCHED_BVT;
  115.12 @@ -24,7 +24,7 @@ int xc_bvtsched_global_set(int xc_handle
  115.13  int xc_bvtsched_global_get(int xc_handle,
  115.14                             unsigned long *ctx_allow)
  115.15  {
  115.16 -    dom0_op_t op;
  115.17 +    DECLARE_DOM0_OP;
  115.18      int ret;
  115.19      
  115.20      op.cmd = DOM0_SCHEDCTL;
  115.21 @@ -46,7 +46,7 @@ int xc_bvtsched_domain_set(int xc_handle
  115.22                             long long warpl,
  115.23                             long long warpu)
  115.24  {
  115.25 -    dom0_op_t op;
  115.26 +    DECLARE_DOM0_OP;
  115.27      struct bvt_adjdom *bvtadj = &op.u.adjustdom.u.bvt;
  115.28  
  115.29      op.cmd = DOM0_ADJUSTDOM;
  115.30 @@ -72,7 +72,7 @@ int xc_bvtsched_domain_get(int xc_handle
  115.31                             long long *warpu)
  115.32  {
  115.33      
  115.34 -    dom0_op_t op;
  115.35 +    DECLARE_DOM0_OP;
  115.36      int ret;
  115.37      struct bvt_adjdom *adjptr = &op.u.adjustdom.u.bvt;
  115.38  
   116.1 --- a/tools/libxc/xc_domain.c	Fri Dec 02 12:12:11 2005 -0600
   116.2 +++ b/tools/libxc/xc_domain.c	Fri Dec 02 12:52:25 2005 -0600
   116.3 @@ -15,7 +15,7 @@ int xc_domain_create(int xc_handle,
   116.4                       uint32_t *pdomid)
   116.5  {
   116.6      int err;
   116.7 -    dom0_op_t op;
   116.8 +    DECLARE_DOM0_OP;
   116.9  
  116.10      op.cmd = DOM0_CREATEDOMAIN;
  116.11      op.u.createdomain.domain = (domid_t)*pdomid;
  116.12 @@ -32,7 +32,7 @@ int xc_domain_create(int xc_handle,
  116.13  int xc_domain_pause(int xc_handle, 
  116.14                      uint32_t domid)
  116.15  {
  116.16 -    dom0_op_t op;
  116.17 +    DECLARE_DOM0_OP;
  116.18      op.cmd = DOM0_PAUSEDOMAIN;
  116.19      op.u.pausedomain.domain = (domid_t)domid;
  116.20      return do_dom0_op(xc_handle, &op);
  116.21 @@ -42,7 +42,7 @@ int xc_domain_pause(int xc_handle,
  116.22  int xc_domain_unpause(int xc_handle,
  116.23                        uint32_t domid)
  116.24  {
  116.25 -    dom0_op_t op;
  116.26 +    DECLARE_DOM0_OP;
  116.27      op.cmd = DOM0_UNPAUSEDOMAIN;
  116.28      op.u.unpausedomain.domain = (domid_t)domid;
  116.29      return do_dom0_op(xc_handle, &op);
  116.30 @@ -52,7 +52,7 @@ int xc_domain_unpause(int xc_handle,
  116.31  int xc_domain_destroy(int xc_handle,
  116.32                        uint32_t domid)
  116.33  {
  116.34 -    dom0_op_t op;
  116.35 +    DECLARE_DOM0_OP;
  116.36      op.cmd = DOM0_DESTROYDOMAIN;
  116.37      op.u.destroydomain.domain = (domid_t)domid;
  116.38      return do_dom0_op(xc_handle, &op);
  116.39 @@ -63,7 +63,7 @@ int xc_domain_pincpu(int xc_handle,
  116.40                       int vcpu,
  116.41                       cpumap_t cpumap)
  116.42  {
  116.43 -    dom0_op_t op;
  116.44 +    DECLARE_DOM0_OP;
  116.45      op.cmd = DOM0_PINCPUDOMAIN;
  116.46      op.u.pincpudomain.domain  = (domid_t)domid;
  116.47      op.u.pincpudomain.vcpu    = vcpu;
  116.48 @@ -79,7 +79,7 @@ int xc_domain_getinfo(int xc_handle,
  116.49  {
  116.50      unsigned int nr_doms;
  116.51      uint32_t next_domid = first_domid;
  116.52 -    dom0_op_t op;
  116.53 +    DECLARE_DOM0_OP;
  116.54      int rc = 0; 
  116.55  
  116.56      memset(info, 0, max_doms*sizeof(xc_dominfo_t));
  116.57 @@ -134,7 +134,7 @@ int xc_domain_getinfolist(int xc_handle,
  116.58                            xc_domaininfo_t *info)
  116.59  {
  116.60      int ret = 0;
  116.61 -    dom0_op_t op;
  116.62 +    DECLARE_DOM0_OP;
  116.63  
  116.64      if ( mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
  116.65          return -1;
  116.66 @@ -161,7 +161,7 @@ int xc_domain_get_vcpu_context(int xc_ha
  116.67                                 vcpu_guest_context_t *ctxt)
  116.68  {
  116.69      int rc;
  116.70 -    dom0_op_t op;
  116.71 +    DECLARE_DOM0_OP;
  116.72  
  116.73      op.cmd = DOM0_GETVCPUCONTEXT;
  116.74      op.u.getvcpucontext.domain = (domid_t)domid;
  116.75 @@ -187,7 +187,7 @@ int xc_shadow_control(int xc_handle,
  116.76                        xc_shadow_control_stats_t *stats )
  116.77  {
  116.78      int rc;
  116.79 -    dom0_op_t op;
  116.80 +    DECLARE_DOM0_OP;
  116.81      op.cmd = DOM0_SHADOW_CONTROL;
  116.82      op.u.shadow_control.domain = (domid_t)domid;
  116.83      op.u.shadow_control.op     = sop;
  116.84 @@ -250,7 +250,7 @@ int xc_domain_setmaxmem(int xc_handle,
  116.85                          uint32_t domid, 
  116.86                          unsigned int max_memkb)
  116.87  {
  116.88 -    dom0_op_t op;
  116.89 +    DECLARE_DOM0_OP;
  116.90      op.cmd = DOM0_SETDOMAINMAXMEM;
  116.91      op.u.setdomainmaxmem.domain = (domid_t)domid;
  116.92      op.u.setdomainmaxmem.max_memkb = max_memkb;
  116.93 @@ -328,7 +328,7 @@ int xc_domain_memory_decrease_reservatio
  116.94  
  116.95  int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
  116.96  {
  116.97 -    dom0_op_t op;
  116.98 +    DECLARE_DOM0_OP;
  116.99      op.cmd = DOM0_MAX_VCPUS;
 116.100      op.u.max_vcpus.domain = (domid_t)domid;
 116.101      op.u.max_vcpus.max    = max;
 116.102 @@ -338,7 +338,7 @@ int xc_domain_max_vcpus(int xc_handle, u
 116.103  int xc_domain_sethandle(int xc_handle, uint32_t domid, 
 116.104                          xen_domain_handle_t handle)
 116.105  {
 116.106 -    dom0_op_t op;
 116.107 +    DECLARE_DOM0_OP;
 116.108      op.cmd = DOM0_SETDOMAINHANDLE;
 116.109      op.u.setdomainhandle.domain = (domid_t)domid;
 116.110      memcpy(op.u.setdomainhandle.handle, handle, sizeof(xen_domain_handle_t));
 116.111 @@ -351,8 +351,7 @@ int xc_domain_get_vcpu_info(int xc_handl
 116.112                              xc_vcpuinfo_t *info)
 116.113  {
 116.114      int rc;
 116.115 -    dom0_op_t op;
 116.116 -
 116.117 +    DECLARE_DOM0_OP;
 116.118      op.cmd = DOM0_GETVCPUINFO;
 116.119      op.u.getvcpuinfo.domain = (domid_t)domid;
 116.120      op.u.getvcpuinfo.vcpu   = (uint16_t)vcpu;
 116.121 @@ -366,11 +365,11 @@ int xc_domain_get_vcpu_info(int xc_handl
 116.122  
 116.123  int xc_domain_ioport_permission(int xc_handle,
 116.124                                  uint32_t domid,
 116.125 -                                uint16_t first_port,
 116.126 -                                uint16_t nr_ports,
 116.127 -                                uint16_t allow_access)
 116.128 +                                uint32_t first_port,
 116.129 +                                uint32_t nr_ports,
 116.130 +                                uint32_t allow_access)
 116.131  {
 116.132 -    dom0_op_t op;
 116.133 +    DECLARE_DOM0_OP;
 116.134  
 116.135      op.cmd = DOM0_IOPORT_PERMISSION;
 116.136      op.u.ioport_permission.domain = (domid_t)domid;
   117.1 --- a/tools/libxc/xc_evtchn.c	Fri Dec 02 12:12:11 2005 -0600
   117.2 +++ b/tools/libxc/xc_evtchn.c	Fri Dec 02 12:52:25 2005 -0600
   117.3 @@ -12,7 +12,7 @@
   117.4  static int do_evtchn_op(int xc_handle, evtchn_op_t *op)
   117.5  {
   117.6      int ret = -1;
   117.7 -    privcmd_hypercall_t hypercall;
   117.8 +    DECLARE_HYPERCALL;
   117.9  
  117.10      hypercall.op     = __HYPERVISOR_event_channel_op;
  117.11      hypercall.arg[0] = (unsigned long)op;
  117.12 @@ -51,7 +51,7 @@ int xc_evtchn_alloc_unbound(int xc_handl
  117.13  
  117.14  int xc_evtchn_status(int xc_handle,
  117.15                       uint32_t dom,
  117.16 -                     int port,
  117.17 +                     evtchn_port_t port,
  117.18                       xc_evtchn_status_t *status)
  117.19  {
  117.20      int         rc;
   118.1 --- a/tools/libxc/xc_gnttab.c	Fri Dec 02 12:12:11 2005 -0600
   118.2 +++ b/tools/libxc/xc_gnttab.c	Fri Dec 02 12:52:25 2005 -0600
   118.3 @@ -17,7 +17,7 @@ do_gnttab_op(int xc_handle,
   118.4               unsigned long count)
   118.5  {
   118.6      int ret = -1;
   118.7 -    privcmd_hypercall_t hypercall;
   118.8 +    DECLARE_HYPERCALL;
   118.9  
  118.10      hypercall.op     = __HYPERVISOR_grant_table_op;
  118.11      hypercall.arg[0] = cmd;
  118.12 @@ -42,9 +42,10 @@ do_gnttab_op(int xc_handle,
  118.13  int xc_gnttab_map_grant_ref(int         xc_handle,
  118.14                              uint64_t    host_virt_addr,
  118.15                              uint32_t    dom,
  118.16 -                            uint16_t    ref,
  118.17 +                            grant_ref_t ref,
  118.18                              uint16_t    flags,
  118.19 -                            int16_t    *handle,
  118.20 +                            int16_t    *status,
  118.21 +                            grant_handle_t *handle,
  118.22                              uint64_t   *dev_bus_addr)
  118.23  {
  118.24      struct gnttab_map_grant_ref op;
  118.25 @@ -58,6 +59,7 @@ int xc_gnttab_map_grant_ref(int         
  118.26      if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref,
  118.27                              &op, 1)) == 0 )
  118.28      {
  118.29 +        *status         = op.status;
  118.30          *handle         = op.handle;
  118.31          *dev_bus_addr   = op.dev_bus_addr;
  118.32      }
  118.33 @@ -69,7 +71,7 @@ int xc_gnttab_map_grant_ref(int         
  118.34  int xc_gnttab_unmap_grant_ref(int       xc_handle,
  118.35                                uint64_t  host_virt_addr,
  118.36                                uint64_t  dev_bus_addr,
  118.37 -                              uint16_t  handle,
  118.38 +                              grant_handle_t handle,
  118.39                                int16_t  *status)
  118.40  {
  118.41      struct gnttab_unmap_grant_ref op;
   119.1 --- a/tools/libxc/xc_linux_build.c	Fri Dec 02 12:12:11 2005 -0600
   119.2 +++ b/tools/libxc/xc_linux_build.c	Fri Dec 02 12:52:25 2005 -0600
   119.3 @@ -657,7 +657,7 @@ static int setup_guest(int xc_handle,
   119.4      memset(shared_info, 0, sizeof(shared_info_t));
   119.5      /* Mask all upcalls... */
   119.6      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
   119.7 -        shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
   119.8 +        shared_info->vcpu_info[i].evtchn_upcall_mask = 1;
   119.9  
  119.10      munmap(shared_info, PAGE_SIZE);
  119.11  
  119.12 @@ -692,7 +692,8 @@ int xc_linux_build(int xc_handle,
  119.13                     unsigned int console_evtchn,
  119.14                     unsigned long *console_mfn)
  119.15  {
  119.16 -    dom0_op_t launch_op, op;
  119.17 +    dom0_op_t launch_op;
  119.18 +    DECLARE_DOM0_OP;
  119.19      int initrd_fd = -1;
  119.20      gzFile initrd_gfd = NULL;
  119.21      int rc, i;
  119.22 @@ -728,6 +729,10 @@ int xc_linux_build(int xc_handle,
  119.23          }
  119.24      }
  119.25  
  119.26 +#ifdef VALGRIND
  119.27 +    memset(&st_ctxt, 0, sizeof(st_ctxt));
  119.28 +#endif
  119.29 +
  119.30      if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
  119.31      {   
  119.32          PERROR("%s: ctxt mlock failed", __func__);
   120.1 --- a/tools/libxc/xc_linux_restore.c	Fri Dec 02 12:12:11 2005 -0600
   120.2 +++ b/tools/libxc/xc_linux_restore.c	Fri Dec 02 12:52:25 2005 -0600
   120.3 @@ -78,6 +78,7 @@ int uncanonicalize_pagetable(unsigned lo
   120.4              pfn = (pte >> PAGE_SHIFT) & 0xffffffff;
   120.5              
   120.6              if(pfn >= max_pfn) { 
   120.7 +                /* This "page table page" is probably not one; bail. */
   120.8                  ERR("Frame number in type %lu page table is out of range: "
   120.9                      "i=%d pfn=0x%lx max_pfn=%lu", 
  120.10                      type >> 28, i, pfn, max_pfn);
  120.11 @@ -106,11 +107,12 @@ int xc_linux_restore(int xc_handle, int 
  120.12                       unsigned int store_evtchn, unsigned long *store_mfn,
  120.13                       unsigned int console_evtchn, unsigned long *console_mfn)
  120.14  {
  120.15 -    dom0_op_t op;
  120.16 +    DECLARE_DOM0_OP;
  120.17      int rc = 1, i, n;
  120.18      unsigned long mfn, pfn; 
  120.19      unsigned int prev_pc, this_pc;
  120.20      int verify = 0;
  120.21 +    int nraces = 0; 
  120.22  
  120.23      /* The new domain's shared-info frame number. */
  120.24      unsigned long shared_info_frame;
  120.25 @@ -219,7 +221,7 @@ int xc_linux_restore(int xc_handle, int 
  120.26      
  120.27      if(xc_domain_memory_increase_reservation(
  120.28             xc_handle, dom, max_pfn, 0, 0, NULL) != 0) { 
  120.29 -        ERR("Failed to increase reservation by %lx KB\n", PFN_TO_KB(max_pfn));
  120.30 +        ERR("Failed to increase reservation by %lx KB", PFN_TO_KB(max_pfn));
  120.31          errno = ENOMEM;
  120.32          goto out;
  120.33      }
  120.34 @@ -344,8 +346,15 @@ int xc_linux_restore(int xc_handle, int 
  120.35                  if(pt_levels != 3 || pagetype != L1TAB) { 
  120.36  
  120.37                      if(!uncanonicalize_pagetable(pagetype, page)) {
  120.38 -                        ERR("failed uncanonicalize pt!\n"); 
  120.39 -                        goto out; 
  120.40 +                        /* 
  120.41 +                        ** Failing to uncanonicalize a page table can be ok
  120.42 +                        ** under live migration since the pages type may have
  120.43 +                        ** changed by now (and we'll get an update later). 
  120.44 +                        */
  120.45 +                        DPRINTF("PT L%ld race on pfn=%08lx mfn=%08lx\n", 
  120.46 +                                pagetype >> 28, pfn, mfn); 
  120.47 +                        nraces++; 
  120.48 +                        continue; 
  120.49                      }
  120.50  
  120.51                  } 
  120.52 @@ -394,7 +403,7 @@ int xc_linux_restore(int xc_handle, int 
  120.53          n+= j; /* crude stats */
  120.54      }
  120.55  
  120.56 -    DPRINTF("Received all pages\n");
  120.57 +    DPRINTF("Received all pages (%d races)\n", nraces);
  120.58  
  120.59      if(pt_levels == 3) { 
  120.60  
  120.61 @@ -478,7 +487,7 @@ int xc_linux_restore(int xc_handle, int 
  120.62                  for(k = 0; k < j; k++) {
  120.63                      if(!uncanonicalize_pagetable(L1TAB, 
  120.64                                                   region_base + k*PAGE_SIZE)) {
  120.65 -                        ERR("failed uncanonicalize pt!\n"); 
  120.66 +                        ERR("failed uncanonicalize pt!"); 
  120.67                          goto out; 
  120.68                      } 
  120.69                  }
  120.70 @@ -662,7 +671,7 @@ int xc_linux_restore(int xc_handle, int 
  120.71      memset(&(shared_info->evtchn_pending[0]), 0,
  120.72             sizeof (shared_info->evtchn_pending));
  120.73      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
  120.74 -        shared_info->vcpu_data[i].evtchn_pending_sel = 0;
  120.75 +        shared_info->vcpu_info[i].evtchn_pending_sel = 0;
  120.76  
  120.77      /* Copy saved contents of shared-info page. No checking needed. */
  120.78      page = xc_map_foreign_range(
   121.1 --- a/tools/libxc/xc_linux_save.c	Fri Dec 02 12:12:11 2005 -0600
   121.2 +++ b/tools/libxc/xc_linux_save.c	Fri Dec 02 12:52:25 2005 -0600
   121.3 @@ -44,6 +44,9 @@ static unsigned long *live_p2m = NULL;
   121.4  /* Live mapping of system MFN to PFN table. */
   121.5  static unsigned long *live_m2p = NULL;
   121.6  
   121.7 +/* grep fodder: machine_to_phys */
   121.8 +
   121.9 +#define mfn_to_pfn(_mfn) live_m2p[(_mfn)]
  121.10  
  121.11  /*
  121.12   * Returns TRUE if the given machine frame number has a unique mapping
  121.13 @@ -51,8 +54,8 @@ static unsigned long *live_m2p = NULL;
  121.14   */
  121.15  #define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn)          \
  121.16  (((_mfn) < (max_mfn)) &&                        \
  121.17 - ((live_m2p[_mfn] < (max_pfn)) &&               \
  121.18 -  (live_p2m[live_m2p[_mfn]] == (_mfn))))
  121.19 + ((mfn_to_pfn(_mfn) < (max_pfn)) &&               \
  121.20 +  (live_p2m[mfn_to_pfn(_mfn)] == (_mfn))))
  121.21      
  121.22   
  121.23  /* Returns TRUE if MFN is successfully converted to a PFN. */
  121.24 @@ -63,7 +66,7 @@ static unsigned long *live_m2p = NULL;
  121.25      if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) )                       \
  121.26          _res = 0;                                               \
  121.27      else                                                        \
  121.28 -        *(_pmfn) = live_m2p[mfn];                               \
  121.29 +        *(_pmfn) = mfn_to_pfn(mfn);                             \
  121.30      _res;                                                       \
  121.31  })
  121.32  
  121.33 @@ -454,6 +457,15 @@ void canonicalize_pagetable(unsigned lon
  121.34              xen_start = (hvirt_start >> L2_PAGETABLE_SHIFT_PAE) & 0x1ff; 
  121.35      }
  121.36  
  121.37 +    if (pt_levels == 4 && type == L4TAB) { 
  121.38 +        /*
  121.39 +        ** XXX SMH: should compute these from hvirt_start (which we have) 
  121.40 +        ** and hvirt_end (which we don't) 
  121.41 +        */
  121.42 +        xen_start = 256; 
  121.43 +        xen_end   = 272; 
  121.44 +    }
  121.45 +
  121.46      /* Now iterate through the page table, canonicalizing each PTE */
  121.47      for (i = 0; i < pte_last; i++ ) {
  121.48  
  121.49 @@ -470,19 +482,14 @@ void canonicalize_pagetable(unsigned lon
  121.50          if (pte & _PAGE_PRESENT) {
  121.51              
  121.52              mfn = (pte >> PAGE_SHIFT) & 0xfffffff;      
  121.53 -            pfn = live_m2p[mfn];
  121.54 -            
  121.55              if (!MFN_IS_IN_PSEUDOPHYS_MAP(mfn)) {
  121.56 -                /* I don't think this should ever happen */
  121.57 -                DPRINTF("FNI: [%08lx,%d] pte=%llx,"
  121.58 -                        " mfn=%08lx, pfn=%08lx [mfn]=%08lx\n",
  121.59 -                        type, i, (unsigned long long)pte, mfn, 
  121.60 -                        live_m2p[mfn],
  121.61 -                        (live_m2p[mfn] < max_pfn) ? 
  121.62 -                        live_p2m[live_m2p[mfn]] : 0xdeadbeaf);
  121.63 -                
  121.64 -                pfn = 0; /* be suspicious */
  121.65 -            }
  121.66 +                /* This will happen if the type info is stale which 
  121.67 +                   is quite feasible under live migration */
  121.68 +                DPRINTF("PT Race: [%08lx,%d] pte=%llx, mfn=%08lx\n",
  121.69 +                        type, i, (unsigned long long)pte, mfn); 
  121.70 +                pfn = 0; /* zap it - we'll retransmit this page later */
  121.71 +            } else 
  121.72 +                pfn = mfn_to_pfn(mfn);
  121.73              
  121.74              pte &= 0xffffff0000000fffULL;
  121.75              pte |= (uint64_t)pfn << PAGE_SHIFT;
  121.76 @@ -504,7 +511,7 @@ static unsigned long *xc_map_m2p(int xc_
  121.77                                   unsigned long max_mfn, 
  121.78                                   int prot) 
  121.79  { 
  121.80 -    privcmd_m2pmfns_t m2p_mfns; 
  121.81 +    struct xen_machphys_mfn_list xmml;
  121.82      privcmd_mmap_t ioctlx; 
  121.83      privcmd_mmap_entry_t *entries; 
  121.84      unsigned long m2p_chunks, m2p_size; 
  121.85 @@ -514,50 +521,45 @@ static unsigned long *xc_map_m2p(int xc_
  121.86      m2p_size   = M2P_SIZE(max_mfn); 
  121.87      m2p_chunks = M2P_CHUNKS(max_mfn); 
  121.88  
  121.89 -
  121.90 -    m2p_mfns.num = m2p_chunks; 
  121.91 -
  121.92 -    if(!(m2p_mfns.arr = malloc(m2p_chunks * sizeof(unsigned long)))) { 
  121.93 -        ERR("failed to allocate space for m2p mfns!\n"); 
  121.94 +    xmml.max_extents = m2p_chunks;
  121.95 +    if (!(xmml.extent_start = malloc(m2p_chunks * sizeof(unsigned long)))) { 
  121.96 +        ERR("failed to allocate space for m2p mfns"); 
  121.97          return NULL; 
  121.98      } 
  121.99  
 121.100 -    if (ioctl(xc_handle, IOCTL_PRIVCMD_GET_MACH2PHYS_MFNS, &m2p_mfns) < 0) {
 121.101 -        ERR("xc_get_m2p_mfns:"); 
 121.102 +    if (xc_memory_op(xc_handle, XENMEM_machphys_mfn_list, &xmml) ||
 121.103 +        (xmml.nr_extents != m2p_chunks)) {
 121.104 +        ERR("xc_get_m2p_mfns"); 
 121.105          return NULL;
 121.106      }
 121.107  
 121.108 -    if((m2p = mmap(NULL, m2p_size, prot, 
 121.109 -                   MAP_SHARED, xc_handle, 0)) == MAP_FAILED) {
 121.110 +    if ((m2p = mmap(NULL, m2p_size, prot, 
 121.111 +                    MAP_SHARED, xc_handle, 0)) == MAP_FAILED) {
 121.112          ERR("failed to mmap m2p"); 
 121.113          return NULL; 
 121.114      } 
 121.115 -    
 121.116  
 121.117 -    if(!(entries = malloc(m2p_chunks * sizeof(privcmd_mmap_entry_t)))) { 
 121.118 -        ERR("failed to allocate space for mmap entries!\n"); 
 121.119 +    if (!(entries = malloc(m2p_chunks * sizeof(privcmd_mmap_entry_t)))) { 
 121.120 +        ERR("failed to allocate space for mmap entries"); 
 121.121          return NULL; 
 121.122      } 
 121.123  
 121.124 -
 121.125      ioctlx.num   = m2p_chunks;
 121.126      ioctlx.dom   = DOMID_XEN; 
 121.127      ioctlx.entry = entries; 
 121.128      
 121.129 -    for(i=0; i < m2p_chunks; i++) { 
 121.130 -        
 121.131 +    for (i=0; i < m2p_chunks; i++) { 
 121.132          entries[i].va = (unsigned long)(((void *)m2p) + (i * M2P_CHUNK_SIZE)); 
 121.133 -        entries[i].mfn = m2p_mfns.arr[i]; 
 121.134 +        entries[i].mfn = xmml.extent_start[i];
 121.135          entries[i].npages = M2P_CHUNK_SIZE >> PAGE_SHIFT;
 121.136 -
 121.137      }
 121.138  
 121.139 -    if((rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx)) < 0) {
 121.140 +    if ((rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx)) < 0) {
 121.141          ERR("ioctl_mmap failed (rc = %d)", rc); 
 121.142          return NULL; 
 121.143      }
 121.144 -        
 121.145 -    free(m2p_mfns.arr); 
 121.146 +
 121.147 +    free(xmml.extent_start);
 121.148      free(entries); 
 121.149  
 121.150      return m2p; 
 121.151 @@ -675,7 +677,7 @@ int xc_linux_save(int xc_handle, int io_
 121.152                               live_shinfo->arch.pfn_to_mfn_frame_list_list);
 121.153  
 121.154      if (!live_p2m_frame_list_list) {
 121.155 -        ERR("Couldn't map p2m_frame_list_list");
 121.156 +        ERR("Couldn't map p2m_frame_list_list (errno %d)", errno);
 121.157          goto out;
 121.158      }
 121.159  
 121.160 @@ -728,12 +730,6 @@ int xc_linux_save(int xc_handle, int io_
 121.161      }
 121.162  
 121.163      /* Domain is still running at this point */
 121.164 -
 121.165 -    if (live && (pt_levels != 2)) {
 121.166 -        ERR("Live migration supported only for 32-bit non-pae");
 121.167 -        goto out;
 121.168 -    }
 121.169 -
 121.170      if (live) {
 121.171  
 121.172          if (xc_shadow_control(xc_handle, dom, 
 121.173 @@ -798,6 +794,7 @@ int xc_linux_save(int xc_handle, int io_
 121.174      pfn_batch = calloc(MAX_BATCH_SIZE, sizeof(unsigned long));
 121.175  
 121.176      if ((pfn_type == NULL) || (pfn_batch == NULL)) {
 121.177 +        ERR("failed to alloc memory for pfn_type and/or pfn_batch arrays"); 
 121.178          errno = ENOMEM;
 121.179          goto out;
 121.180      }
 121.181 @@ -817,9 +814,9 @@ int xc_linux_save(int xc_handle, int io_
 121.182          for (i = 0; i < max_pfn; i++) {
 121.183  
 121.184              mfn = live_p2m[i];
 121.185 -            if((live_m2p[mfn] != i) && (mfn != 0xffffffffUL)) { 
 121.186 +            if((mfn != INVALID_P2M_ENTRY) && (mfn_to_pfn(mfn) != i)) { 
 121.187                  DPRINTF("i=0x%x mfn=%lx live_m2p=%lx\n", i, 
 121.188 -                        mfn, live_m2p[mfn]);
 121.189 +                        mfn, mfn_to_pfn(mfn));
 121.190                  err++;
 121.191              }
 121.192          }
 121.193 @@ -884,7 +881,7 @@ int xc_linux_save(int xc_handle, int io_
 121.194                      DPRINTF("%d pfn= %08lx mfn= %08lx %d  [mfn]= %08lx\n",
 121.195                              iter, (unsigned long)n, live_p2m[n],
 121.196                              test_bit(n, to_send), 
 121.197 -                            live_m2p[live_p2m[n]&0xFFFFF]);
 121.198 +                            mfn_to_pfn(live_p2m[n]&0xFFFFF));
 121.199                  }
 121.200                  
 121.201                  if (!last_iter && test_bit(n, to_send)&& test_bit(n, to_skip)) 
 121.202 @@ -912,7 +909,7 @@ int xc_linux_save(int xc_handle, int io_
 121.203                         unless its sent sooner anyhow */
 121.204  
 121.205                      set_bit(n, to_fix);
 121.206 -                    if(iter > 1)
 121.207 +                    if( (iter > 1) && IS_REAL_PFN(n) )
 121.208                          DPRINTF("netbuf race: iter %d, pfn %x. mfn %lx\n",
 121.209                                  iter, n, pfn_type[batch]);
 121.210                      continue;
 121.211 @@ -956,7 +953,7 @@ int xc_linux_save(int xc_handle, int io_
 121.212                              iter, 
 121.213                              (pfn_type[j] & LTAB_MASK) | pfn_batch[j],
 121.214                              pfn_type[j],
 121.215 -                            live_m2p[pfn_type[j]&(~LTAB_MASK)],
 121.216 +                            mfn_to_pfn(pfn_type[j]&(~LTAB_MASK)),
 121.217                              csum_page(region_base + (PAGE_SIZE*j)));
 121.218                  
 121.219                  /* canonicalise mfn->pfn */
 121.220 @@ -1030,7 +1027,7 @@ int xc_linux_save(int xc_handle, int io_
 121.221  
 121.222          if (last_iter && debug){
 121.223              int minusone = -1;
 121.224 -            memset( to_send, 0xff, (max_pfn+8)/8 );
 121.225 +            memset(to_send, 0xff, BITMAP_SIZE); 
 121.226              debug = 0;
 121.227              fprintf(stderr, "Entering debug resend-all mode\n");
 121.228      
 121.229 @@ -1143,7 +1140,7 @@ int xc_linux_save(int xc_handle, int io_
 121.230          ERR("PT base is not in range of pseudophys map");
 121.231          goto out;
 121.232      }
 121.233 -    ctxt.ctrlreg[3] = live_m2p[ctxt.ctrlreg[3] >> PAGE_SHIFT] <<
 121.234 +    ctxt.ctrlreg[3] = mfn_to_pfn(ctxt.ctrlreg[3] >> PAGE_SHIFT) <<
 121.235          PAGE_SHIFT;
 121.236  
 121.237      if (!write_exact(io_fd, &ctxt, sizeof(ctxt)) ||
 121.238 @@ -1157,6 +1154,13 @@ int xc_linux_save(int xc_handle, int io_
 121.239  
 121.240   out:
 121.241  
 121.242 +    if (live) {
 121.243 +        if(xc_shadow_control(xc_handle, dom, DOM0_SHADOW_CONTROL_OP_OFF, 
 121.244 +                             NULL, 0, NULL ) < 0) { 
 121.245 +            DPRINTF("Warning - couldn't disable shadow mode");
 121.246 +        }
 121.247 +    }
 121.248 +    
 121.249      if (live_shinfo)
 121.250          munmap(live_shinfo, PAGE_SIZE);
 121.251      
   122.1 --- a/tools/libxc/xc_misc.c	Fri Dec 02 12:12:11 2005 -0600
   122.2 +++ b/tools/libxc/xc_misc.c	Fri Dec 02 12:52:25 2005 -0600
   122.3 @@ -25,7 +25,7 @@ int xc_readconsolering(int xc_handle,
   122.4                         int clear)
   122.5  {
   122.6      int ret;
   122.7 -    dom0_op_t op;
   122.8 +    DECLARE_DOM0_OP;
   122.9      char *buffer = *pbuffer;
  122.10      unsigned int nr_chars = *pnr_chars;
  122.11  
  122.12 @@ -52,7 +52,7 @@ int xc_physinfo(int xc_handle,
  122.13                  xc_physinfo_t *put_info)
  122.14  {
  122.15      int ret;
  122.16 -    dom0_op_t op;
  122.17 +    DECLARE_DOM0_OP;
  122.18      
  122.19      op.cmd = DOM0_PHYSINFO;
  122.20      op.interface_version = DOM0_INTERFACE_VERSION;
  122.21 @@ -69,7 +69,7 @@ int xc_sched_id(int xc_handle,
  122.22                  int *sched_id)
  122.23  {
  122.24      int ret;
  122.25 -    dom0_op_t op;
  122.26 +    DECLARE_DOM0_OP;
  122.27      
  122.28      op.cmd = DOM0_SCHED_ID;
  122.29      op.interface_version = DOM0_INTERFACE_VERSION;
  122.30 @@ -83,25 +83,25 @@ int xc_sched_id(int xc_handle,
  122.31  }
  122.32  
  122.33  int xc_perfc_control(int xc_handle,
  122.34 -                     uint32_t op,
  122.35 +                     uint32_t opcode,
  122.36                       xc_perfc_desc_t *desc)
  122.37  {
  122.38      int rc;
  122.39 -    dom0_op_t dop;
  122.40 +    DECLARE_DOM0_OP;
  122.41  
  122.42 -    dop.cmd = DOM0_PERFCCONTROL;
  122.43 -    dop.u.perfccontrol.op   = op;
  122.44 -    dop.u.perfccontrol.desc = desc;
  122.45 +    op.cmd = DOM0_PERFCCONTROL;
  122.46 +    op.u.perfccontrol.op   = opcode;
  122.47 +    op.u.perfccontrol.desc = desc;
  122.48  
  122.49 -    rc = do_dom0_op(xc_handle, &dop);
  122.50 +    rc = do_dom0_op(xc_handle, &op);
  122.51  
  122.52 -    return (rc == 0) ? dop.u.perfccontrol.nr_counters : rc;
  122.53 +    return (rc == 0) ? op.u.perfccontrol.nr_counters : rc;
  122.54  }
  122.55  
  122.56  long long xc_msr_read(int xc_handle, int cpu_mask, int msr)
  122.57  {
  122.58      int rc;    
  122.59 -    dom0_op_t op;
  122.60 +    DECLARE_DOM0_OP;
  122.61      
  122.62      op.cmd = DOM0_MSR;
  122.63      op.u.msr.write = 0;
  122.64 @@ -117,7 +117,7 @@ int xc_msr_write(int xc_handle, int cpu_
  122.65                    unsigned int high)
  122.66  {
  122.67      int rc;    
  122.68 -    dom0_op_t op;
  122.69 +    DECLARE_DOM0_OP;
  122.70      
  122.71      op.cmd = DOM0_MSR;
  122.72      op.u.msr.write = 1;
   123.1 --- a/tools/libxc/xc_private.c	Fri Dec 02 12:12:11 2005 -0600
   123.2 +++ b/tools/libxc/xc_private.c	Fri Dec 02 12:52:25 2005 -0600
   123.3 @@ -68,7 +68,7 @@ void *xc_map_foreign_range(int xc_handle
   123.4  int xc_get_pfn_type_batch(int xc_handle, 
   123.5                            uint32_t dom, int num, unsigned long *arr)
   123.6  {
   123.7 -    dom0_op_t op;
   123.8 +    DECLARE_DOM0_OP;
   123.9      op.cmd = DOM0_GETPAGEFRAMEINFO2;
  123.10      op.u.getpageframeinfo2.domain = (domid_t)dom;
  123.11      op.u.getpageframeinfo2.num    = num;
  123.12 @@ -81,7 +81,7 @@ unsigned int get_pfn_type(int xc_handle,
  123.13                            unsigned long mfn, 
  123.14                            uint32_t dom)
  123.15  {
  123.16 -    dom0_op_t op;
  123.17 +    DECLARE_DOM0_OP;
  123.18      op.cmd = DOM0_GETPAGEFRAMEINFO;
  123.19      op.u.getpageframeinfo.pfn    = mfn;
  123.20      op.u.getpageframeinfo.domain = (domid_t)dom;
  123.21 @@ -99,7 +99,7 @@ int xc_mmuext_op(
  123.22      unsigned int nr_ops,
  123.23      domid_t dom)
  123.24  {
  123.25 -    privcmd_hypercall_t hypercall;
  123.26 +    DECLARE_HYPERCALL;
  123.27      long ret = -EINVAL;
  123.28  
  123.29      hypercall.op     = __HYPERVISOR_mmuext_op;
  123.30 @@ -125,7 +125,7 @@ int xc_mmuext_op(
  123.31  static int flush_mmu_updates(int xc_handle, xc_mmu_t *mmu)
  123.32  {
  123.33      int err = 0;
  123.34 -    privcmd_hypercall_t hypercall;
  123.35 +    DECLARE_HYPERCALL;
  123.36  
  123.37      if ( mmu->idx == 0 )
  123.38          return 0;
  123.39 @@ -188,8 +188,9 @@ int xc_memory_op(int xc_handle,
  123.40                   int cmd,
  123.41                   void *arg)
  123.42  {
  123.43 -    privcmd_hypercall_t hypercall;
  123.44 +    DECLARE_HYPERCALL;
  123.45      struct xen_memory_reservation *reservation = arg;
  123.46 +    struct xen_machphys_mfn_list *xmml = arg;
  123.47      long ret = -EINVAL;
  123.48  
  123.49      hypercall.op     = __HYPERVISOR_memory_op;
  123.50 @@ -214,12 +215,19 @@ int xc_memory_op(int xc_handle,
  123.51              goto out1;
  123.52          }
  123.53          break;
  123.54 -    case XENMEM_maximum_ram_page:
  123.55 -        if ( mlock(arg, sizeof(unsigned long)) != 0 )
  123.56 +    case XENMEM_machphys_mfn_list:
  123.57 +        if ( mlock(xmml, sizeof(*xmml)) != 0 )
  123.58          {
  123.59              PERROR("Could not mlock");
  123.60              goto out1;
  123.61          }
  123.62 +        if ( mlock(xmml->extent_start,
  123.63 +                   xmml->max_extents * sizeof(unsigned long)) != 0 )
  123.64 +        {
  123.65 +            PERROR("Could not mlock");
  123.66 +            safe_munlock(xmml, sizeof(*xmml));
  123.67 +            goto out1;
  123.68 +        }
  123.69          break;
  123.70      }
  123.71  
  123.72 @@ -234,8 +242,10 @@ int xc_memory_op(int xc_handle,
  123.73              safe_munlock(reservation->extent_start,
  123.74                           reservation->nr_extents * sizeof(unsigned long));
  123.75          break;
  123.76 -    case XENMEM_maximum_ram_page:
  123.77 -        safe_munlock(arg, sizeof(unsigned long));
  123.78 +    case XENMEM_machphys_mfn_list:
  123.79 +        safe_munlock(xmml, sizeof(*xmml));
  123.80 +        safe_munlock(xmml->extent_start,
  123.81 +                     xmml->max_extents * sizeof(unsigned long));
  123.82          break;
  123.83      }
  123.84  
  123.85 @@ -246,7 +256,7 @@ int xc_memory_op(int xc_handle,
  123.86  
  123.87  long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid, int vcpu )
  123.88  {
  123.89 -    dom0_op_t op;
  123.90 +    DECLARE_DOM0_OP;
  123.91  
  123.92      op.cmd = DOM0_GETVCPUINFO;
  123.93      op.u.getvcpuinfo.domain = (domid_t)domid;
  123.94 @@ -265,13 +275,16 @@ int xc_get_pfn_list(int xc_handle,
  123.95                      unsigned long *pfn_buf, 
  123.96                      unsigned long max_pfns)
  123.97  {
  123.98 -    dom0_op_t op;
  123.99 +    DECLARE_DOM0_OP;
 123.100      int ret;
 123.101      op.cmd = DOM0_GETMEMLIST;
 123.102      op.u.getmemlist.domain   = (domid_t)domid;
 123.103      op.u.getmemlist.max_pfns = max_pfns;
 123.104      op.u.getmemlist.buffer   = pfn_buf;
 123.105  
 123.106 +#ifdef VALGRIND
 123.107 +    memset(pfn_buf, 0, max_pfns * sizeof(unsigned long));
 123.108 +#endif
 123.109  
 123.110      if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 )
 123.111      {
 123.112 @@ -303,7 +316,7 @@ int xc_get_pfn_list(int xc_handle,
 123.113  
 123.114  long xc_get_tot_pages(int xc_handle, uint32_t domid)
 123.115  {
 123.116 -    dom0_op_t op;
 123.117 +    DECLARE_DOM0_OP;
 123.118      op.cmd = DOM0_GETDOMAININFO;
 123.119      op.u.getdomaininfo.domain = (domid_t)domid;
 123.120      return (do_dom0_op(xc_handle, &op) < 0) ? 
 123.121 @@ -413,6 +426,11 @@ int xc_version(int xc_handle, int cmd, v
 123.122          return -ENOMEM;
 123.123      }
 123.124  
 123.125 +#ifdef VALGRIND
 123.126 +    if (argsize != 0)
 123.127 +        memset(arg, 0, argsize);
 123.128 +#endif
 123.129 +
 123.130      rc = do_xen_version(xc_handle, cmd, arg);
 123.131  
 123.132      if ( argsize != 0 )
   124.1 --- a/tools/libxc/xc_private.h	Fri Dec 02 12:12:11 2005 -0600
   124.2 +++ b/tools/libxc/xc_private.h	Fri Dec 02 12:52:25 2005 -0600
   124.3 @@ -17,6 +17,18 @@
   124.4  
   124.5  #include <xen/linux/privcmd.h>
   124.6  
   124.7 +/* valgrind cannot see when a hypercall has filled in some values.  For this
   124.8 +   reason, we must zero the privcmd_hypercall_t or dom0_op_t instance before a
   124.9 +   call, if using valgrind.  */
  124.10 +#ifdef VALGRIND
  124.11 +#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall = { 0 }
  124.12 +#define DECLARE_DOM0_OP dom0_op_t op = { 0 }
  124.13 +#else
  124.14 +#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall
  124.15 +#define DECLARE_DOM0_OP dom0_op_t op
  124.16 +#endif
  124.17 +
  124.18 +
  124.19  #define PAGE_SHIFT              XC_PAGE_SHIFT
  124.20  #define PAGE_SIZE               (1UL << PAGE_SHIFT)
  124.21  #define PAGE_MASK               (~(PAGE_SIZE-1))
  124.22 @@ -61,7 +73,7 @@ static inline int do_xen_hypercall(int x
  124.23  
  124.24  static inline int do_xen_version(int xc_handle, int cmd, void *dest)
  124.25  {
  124.26 -    privcmd_hypercall_t hypercall;
  124.27 +    DECLARE_HYPERCALL;
  124.28  
  124.29      hypercall.op     = __HYPERVISOR_xen_version;
  124.30      hypercall.arg[0] = (unsigned long) cmd;
  124.31 @@ -73,7 +85,7 @@ static inline int do_xen_version(int xc_
  124.32  static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
  124.33  {
  124.34      int ret = -1;
  124.35 -    privcmd_hypercall_t hypercall;
  124.36 +    DECLARE_HYPERCALL;
  124.37  
  124.38      op->interface_version = DOM0_INTERFACE_VERSION;
  124.39  
   125.1 --- a/tools/libxc/xc_ptrace.c	Fri Dec 02 12:12:11 2005 -0600
   125.2 +++ b/tools/libxc/xc_ptrace.c	Fri Dec 02 12:52:25 2005 -0600
   125.3 @@ -283,7 +283,7 @@ xc_waitdomain(
   125.4      int *status,
   125.5      int options)
   125.6  {
   125.7 -    dom0_op_t op;
   125.8 +    DECLARE_DOM0_OP;
   125.9      int retval;
  125.10      struct timespec ts;
  125.11      ts.tv_sec = 0;
  125.12 @@ -323,7 +323,7 @@ xc_ptrace(
  125.13      long eaddr,
  125.14      long edata)
  125.15  {
  125.16 -    dom0_op_t       op;
  125.17 +    DECLARE_DOM0_OP;
  125.18      int             status = 0;
  125.19      struct gdb_regs pt;
  125.20      long            retval = 0;
   126.1 --- a/tools/libxc/xc_sedf.c	Fri Dec 02 12:12:11 2005 -0600
   126.2 +++ b/tools/libxc/xc_sedf.c	Fri Dec 02 12:52:25 2005 -0600
   126.3 @@ -13,7 +13,7 @@
   126.4  int xc_sedf_domain_set(int xc_handle,
   126.5                            uint32_t domid, uint64_t period, uint64_t slice,uint64_t latency, uint16_t extratime,uint16_t weight)
   126.6  {
   126.7 -    dom0_op_t op;
   126.8 +    DECLARE_DOM0_OP;
   126.9      struct sedf_adjdom *p = &op.u.adjustdom.u.sedf;
  126.10  
  126.11      op.cmd = DOM0_ADJUSTDOM;
  126.12 @@ -31,7 +31,7 @@ int xc_sedf_domain_set(int xc_handle,
  126.13  
  126.14  int xc_sedf_domain_get(int xc_handle, uint32_t domid, uint64_t *period, uint64_t *slice, uint64_t* latency, uint16_t* extratime, uint16_t* weight)
  126.15  {
  126.16 -    dom0_op_t op;
  126.17 +    DECLARE_DOM0_OP;
  126.18      int ret;
  126.19      struct sedf_adjdom *p = &op.u.adjustdom.u.sedf;
  126.20  
   127.1 --- a/tools/libxc/xc_tbuf.c	Fri Dec 02 12:12:11 2005 -0600
   127.2 +++ b/tools/libxc/xc_tbuf.c	Fri Dec 02 12:52:25 2005 -0600
   127.3 @@ -10,7 +10,7 @@
   127.4  
   127.5  int xc_tbuf_enable(int xc_handle, int enable)
   127.6  {
   127.7 -  dom0_op_t op;
   127.8 +  DECLARE_DOM0_OP;
   127.9  
  127.10    op.cmd = DOM0_TBUFCONTROL;
  127.11    op.interface_version = DOM0_INTERFACE_VERSION;
  127.12 @@ -24,7 +24,7 @@ int xc_tbuf_enable(int xc_handle, int en
  127.13  
  127.14  int xc_tbuf_set_size(int xc_handle, uint32_t size)
  127.15  {
  127.16 -  dom0_op_t op;
  127.17 +  DECLARE_DOM0_OP;
  127.18  
  127.19    op.cmd = DOM0_TBUFCONTROL;
  127.20    op.interface_version = DOM0_INTERFACE_VERSION;
  127.21 @@ -37,7 +37,7 @@ int xc_tbuf_set_size(int xc_handle, uint
  127.22  int xc_tbuf_get_size(int xc_handle, uint32_t *size)
  127.23  {
  127.24    int rc;
  127.25 -  dom0_op_t op;
  127.26 +  DECLARE_DOM0_OP;
  127.27  
  127.28    op.cmd = DOM0_TBUFCONTROL;
  127.29    op.interface_version = DOM0_INTERFACE_VERSION;
   128.1 --- a/tools/libxc/xc_vmx_build.c	Fri Dec 02 12:12:11 2005 -0600
   128.2 +++ b/tools/libxc/xc_vmx_build.c	Fri Dec 02 12:52:25 2005 -0600
   128.3 @@ -524,7 +524,7 @@ static int setup_guest(int xc_handle,
   128.4      memset(shared_info, 0, sizeof(shared_info_t));
   128.5      /* Mask all upcalls... */
   128.6      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
   128.7 -        shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
   128.8 +        shared_info->vcpu_info[i].evtchn_upcall_mask = 1;
   128.9  
  128.10      munmap(shared_info, PAGE_SIZE);
  128.11  
   129.1 --- a/tools/libxc/xenctrl.h	Fri Dec 02 12:12:11 2005 -0600
   129.2 +++ b/tools/libxc/xenctrl.h	Fri Dec 02 12:52:25 2005 -0600
   129.3 @@ -13,6 +13,7 @@
   129.4  #include <sys/ptrace.h>
   129.5  #include <xen/xen.h>
   129.6  #include <xen/dom0_ops.h>
   129.7 +#include <xen/grant_table.h>
   129.8  #include <xen/version.h>
   129.9  #include <xen/event_channel.h>
  129.10  #include <xen/sched.h>
  129.11 @@ -333,7 +334,7 @@ int xc_evtchn_alloc_unbound(int xc_handl
  129.12  
  129.13  int xc_evtchn_status(int xc_handle,
  129.14                       uint32_t dom, /* may be DOMID_SELF */
  129.15 -                     int port,
  129.16 +                     evtchn_port_t port,
  129.17                       xc_evtchn_status_t *status);
  129.18  
  129.19  int xc_physdev_pci_access_modify(int xc_handle,
  129.20 @@ -374,9 +375,9 @@ int xc_domain_memory_decrease_reservatio
  129.21  
  129.22  int xc_domain_ioport_permission(int xc_handle,
  129.23                                  uint32_t domid,
  129.24 -                                uint16_t first_port,
  129.25 -                                uint16_t nr_ports,
  129.26 -                                uint16_t allow_access);
  129.27 +                                uint32_t first_port,
  129.28 +                                uint32_t nr_ports,
  129.29 +                                uint32_t allow_access);
  129.30  
  129.31  unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid, 
  129.32  				    unsigned long mfn);
  129.33 @@ -475,15 +476,16 @@ int xc_grant_interface_close(int xc_hand
  129.34  int xc_gnttab_map_grant_ref(int      xc_handle,
  129.35                              uint64_t host_virt_addr,
  129.36                              uint32_t dom,
  129.37 -                            uint16_t ref,
  129.38 +                            grant_ref_t ref,
  129.39                              uint16_t flags,
  129.40 -                            int16_t *handle,
  129.41 +                            int16_t *status,
  129.42 +                            grant_handle_t *handle,
  129.43                              uint64_t *dev_bus_addr);
  129.44  
  129.45  int xc_gnttab_unmap_grant_ref(int  xc_handle,
  129.46                                uint64_t  host_virt_addr,
  129.47                                uint64_t  dev_bus_addr,
  129.48 -                              uint16_t  handle,
  129.49 +                              grant_handle_t handle,
  129.50                                int16_t *status);
  129.51  
  129.52  int xc_gnttab_setup_table(int        xc_handle,
   130.1 --- a/tools/libxc/xg_private.h	Fri Dec 02 12:12:11 2005 -0600
   130.2 +++ b/tools/libxc/xg_private.h	Fri Dec 02 12:52:25 2005 -0600
   130.3 @@ -16,6 +16,16 @@
   130.4  #include <xen/linux/privcmd.h>
   130.5  #include <xen/memory.h>
   130.6  
   130.7 +/* valgrind cannot see when a hypercall has filled in some values.  For this
   130.8 +   reason, we must zero the dom0_op_t instance before a call, if using
   130.9 +   valgrind.  */
  130.10 +#ifdef VALGRIND
  130.11 +#define DECLARE_DOM0_OP dom0_op_t op = { 0 }
  130.12 +#else
  130.13 +#define DECLARE_DOM0_OP dom0_op_t op
  130.14 +#endif
  130.15 +
  130.16 +
  130.17  char *xc_read_kernel_image(const char *filename, unsigned long *size);
  130.18  unsigned long csum_page (void * page);
  130.19  
   131.1 --- a/tools/libxc/xg_save_restore.h	Fri Dec 02 12:12:11 2005 -0600
   131.2 +++ b/tools/libxc/xg_save_restore.h	Fri Dec 02 12:52:25 2005 -0600
   131.3 @@ -10,7 +10,7 @@
   131.4  #define PROGRESS 0
   131.5  
   131.6  #define ERR(_f, _a...) do {                     \
   131.7 -    fprintf(stderr, _f "\n" , ## _a);           \
   131.8 +    fprintf(stderr, _f ": %d\n" , ## _a, errno);\
   131.9      fflush(stderr); }                           \
  131.10  while (0)
  131.11  
  131.12 @@ -64,7 +64,6 @@ static int get_platform_info(int xc_hand
  131.13  { 
  131.14      xen_capabilities_info_t xen_caps = "";
  131.15      xen_platform_parameters_t xen_params;
  131.16 -    
  131.17  
  131.18      if (xc_version(xc_handle, XENVER_platform_parameters, &xen_params) != 0)
  131.19          return 0;
  131.20 @@ -72,8 +71,7 @@ static int get_platform_info(int xc_hand
  131.21      if (xc_version(xc_handle, XENVER_capabilities, &xen_caps) != 0)
  131.22          return 0;
  131.23  
  131.24 -    if (xc_memory_op(xc_handle, XENMEM_maximum_ram_page, max_mfn) != 0)
  131.25 -        return 0; 
  131.26 +    *max_mfn = xc_memory_op(xc_handle, XENMEM_maximum_ram_page, NULL);
  131.27      
  131.28      *hvirt_start = xen_params.virt_start;
  131.29  
  131.30 @@ -125,6 +123,12 @@ static int get_platform_info(int xc_hand
  131.31  /* Number of entries in the pfn_to_mfn_frame_list_list */
  131.32  #define P2M_FLL_ENTRIES (((max_pfn)+(ulpp*ulpp)-1)/(ulpp*ulpp))
  131.33  
  131.34 +/* Current guests allow 8MB 'slack' in their P2M */
  131.35 +#define NR_SLACK_ENTRIES   ((8 * 1024 * 1024) / PAGE_SIZE)
  131.36 +
  131.37 +/* Is the given PFN within the 'slack' region at the top of the P2M? */
  131.38 +#define IS_REAL_PFN(_pfn)  ((max_pfn - (_pfn)) > NR_SLACK_ENTRIES) 
  131.39 +
  131.40  /* Returns TRUE if the PFN is currently mapped */
  131.41  #define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
  131.42  
   132.1 --- a/tools/misc/Makefile	Fri Dec 02 12:12:11 2005 -0600
   132.2 +++ b/tools/misc/Makefile	Fri Dec 02 12:52:25 2005 -0600
   132.3 @@ -16,7 +16,7 @@ HDRS     = $(wildcard *.h)
   132.4  TARGETS  = xenperf xc_shadow
   132.5  
   132.6  INSTALL_BIN  = $(TARGETS) xencons
   132.7 -INSTALL_SBIN = netfix xm xend xenperf
   132.8 +INSTALL_SBIN = netfix xm xen-bugtool xend xenperf
   132.9  
  132.10  all: build
  132.11  build: $(TARGETS)
   133.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   133.2 +++ b/tools/misc/xen-bugtool	Fri Dec 02 12:52:25 2005 -0600
   133.3 @@ -0,0 +1,20 @@
   133.4 +#!/usr/bin/env python
   133.5 +
   133.6 +#  -*- mode: python; -*-
   133.7 +
   133.8 +# Copyright (c) 2005, XenSource Ltd.
   133.9 +
  133.10 +import sys
  133.11 +
  133.12 +sys.path.append('/usr/lib/python')
  133.13 +sys.path.append('/usr/lib64/python')
  133.14 +
  133.15 +from xen.util import bugtool
  133.16 +
  133.17 +
  133.18 +if __name__ == "__main__":
  133.19 +    try:
  133.20 +        sys.exit(bugtool.main())
  133.21 +    except KeyboardInterrupt:
  133.22 +        print "\nInterrupted."
  133.23 +        sys.exit(1)
   134.1 --- a/tools/python/setup.py	Fri Dec 02 12:12:11 2005 -0600
   134.2 +++ b/tools/python/setup.py	Fri Dec 02 12:52:25 2005 -0600
   134.3 @@ -45,6 +45,7 @@ setup(name            = 'xen',
   134.4                           'xen.sv',
   134.5  
   134.6                           'xen.xend.tests',
   134.7 +                         'xen.xend.server.tests',
   134.8                           'xen.xm.tests'
   134.9                           ],
  134.10        ext_package = "xen.lowlevel",
   135.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Fri Dec 02 12:12:11 2005 -0600
   135.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Fri Dec 02 12:52:25 2005 -0600
   135.3 @@ -23,7 +23,8 @@
   135.4  #define PyMODINIT_FUNC DL_EXPORT(void)
   135.5  #endif
   135.6  
   135.7 -#define XENPKG "xen.lowlevel.xc"
   135.8 +#define PKG "xen.lowlevel.xc"
   135.9 +#define CLS "xc"
  135.10  
  135.11  static PyObject *xc_error, *zero;
  135.12  
  135.13 @@ -32,48 +33,38 @@ typedef struct {
  135.14      int xc_handle;
  135.15  } XcObject;
  135.16  
  135.17 -/*
  135.18 - * Definitions for the 'xc' object type.
  135.19 - */
  135.20 +
  135.21 +static PyObject *dom_op(XcObject *self, PyObject *args,
  135.22 +                        int (*fn)(int, uint32_t));
  135.23  
  135.24 -static PyObject *pyxc_domain_dumpcore(PyObject *self,
  135.25 -				      PyObject *args,
  135.26 -				      PyObject *kwds)
  135.27 +
  135.28 +static PyObject *pyxc_domain_dumpcore(XcObject *self, PyObject *args)
  135.29  {
  135.30 -    XcObject *xc = (XcObject *)self;
  135.31 -
  135.32      uint32_t dom;
  135.33      char *corefile;
  135.34  
  135.35 -    static char *kwd_list[] = { "dom", "corefile", NULL };
  135.36 -
  135.37 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,
  135.38 -                                      &dom, &corefile) )
  135.39 +    if (!PyArg_ParseTuple(args, "is", &dom, &corefile))
  135.40          return NULL;
  135.41  
  135.42      if ( (corefile == NULL) || (corefile[0] == '\0') )
  135.43          return NULL;
  135.44  
  135.45 -    if ( xc_domain_dumpcore(xc->xc_handle, dom, corefile) != 0 )
  135.46 +    if (xc_domain_dumpcore(self->xc_handle, dom, corefile) != 0)
  135.47          return PyErr_SetFromErrno(xc_error);
  135.48      
  135.49      Py_INCREF(zero);
  135.50      return zero;
  135.51  }
  135.52  
  135.53 -static PyObject *pyxc_handle(PyObject *self)
  135.54 +static PyObject *pyxc_handle(XcObject *self)
  135.55  {
  135.56 -    XcObject *xc = (XcObject *)self;
  135.57 -
  135.58 -    return PyInt_FromLong(xc->xc_handle);
  135.59 +    return PyInt_FromLong(self->xc_handle);
  135.60  }
  135.61  
  135.62 -static PyObject *pyxc_domain_create(PyObject *self,
  135.63 +static PyObject *pyxc_domain_create(XcObject *self,
  135.64                                      PyObject *args,
  135.65                                      PyObject *kwds)
  135.66  {
  135.67 -    XcObject *xc = (XcObject *)self;
  135.68 -
  135.69      uint32_t dom = 0;
  135.70      int      ret, i;
  135.71      uint32_t ssidref = 0;
  135.72 @@ -103,7 +94,7 @@ static PyObject *pyxc_domain_create(PyOb
  135.73          }
  135.74      }
  135.75  
  135.76 -    if ( (ret = xc_domain_create(xc->xc_handle, ssidref, handle, &dom)) < 0 )
  135.77 +    if ( (ret = xc_domain_create(self->xc_handle, ssidref, handle, &dom)) < 0 )
  135.78          return PyErr_SetFromErrno(xc_error);
  135.79  
  135.80      return PyInt_FromLong(dom);
  135.81 @@ -114,92 +105,40 @@ out_exception:
  135.82      return NULL;
  135.83  }
  135.84  
  135.85 -static PyObject *pyxc_domain_max_vcpus(PyObject *self,
  135.86 -                                            PyObject *args,
  135.87 -                                            PyObject *kwds)
  135.88 +static PyObject *pyxc_domain_max_vcpus(XcObject *self, PyObject *args)
  135.89  {
  135.90 -    XcObject *xc = (XcObject *)self;
  135.91 -
  135.92      uint32_t dom, max;
  135.93  
  135.94 -    static char *kwd_list[] = { "dom", "max", NULL };
  135.95 -
  135.96 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, &dom, &max) )
  135.97 -        return NULL;
  135.98 -
  135.99 -    if ( xc_domain_max_vcpus(xc->xc_handle, dom, max) != 0 )
 135.100 -        return PyErr_SetFromErrno(xc_error);
 135.101 -    
 135.102 -    Py_INCREF(zero);
 135.103 -    return zero;
 135.104