direct-io.hg

changeset 10137:72c5d8206d48

merge with xen-unstable.hg
author awilliam@xenbuild.aw
date Mon May 22 14:13:38 2006 -0600 (2006-05-22)
parents fbf676a36ee4 13d6d993d797
children 2d08d6db792b
files linux-2.6-xen-sparse/arch/ia64/xen/Makefile linux-2.6-xen-sparse/arch/ia64/xen/drivers/xenia64_init.c linux-2.6-xen-sparse/arch/ia64/xen/xen_ksyms.c linux-2.6-xen-sparse/arch/ia64/xen/xensetup.S linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h linux-2.6-xen-sparse/include/asm-ia64/xen/privop.h tools/libxc/xc_linux_build.c tools/xentrace/tbctl.c xen/include/asm-ia64/event.h xen/include/public/arch-ia64.h
line diff
     1.1 --- a/README	Mon May 22 08:53:26 2006 -0600
     1.2 +++ b/README	Mon May 22 14:13:38 2006 -0600
     1.3 @@ -1,9 +1,9 @@
     1.4  ################################
     1.5 - __  __            _____  ___  
     1.6 - \ \/ /___ _ __   |___ / / _ \ 
     1.7 + __  __            _____  ___
     1.8 + \ \/ /___ _ __   |___ / / _ \
     1.9    \  // _ \ '_ \    |_ \| | | |
    1.10    /  \  __/ | | |  ___) | |_| |
    1.11 - /_/\_\___|_| |_| |____(_)___/ 
    1.12 + /_/\_\___|_| |_| |____(_)___/
    1.13  
    1.14  ################################
    1.15  
    1.16 @@ -66,14 +66,14 @@ 2. Configure your bootloader to boot Xen
    1.17  
    1.18     The linux command line takes all the usual options, such as
    1.19     root=<root-dev> to specify your usual root partition (e.g.,
    1.20 -   /dev/hda1).  
    1.21 +   /dev/hda1).
    1.22  
    1.23     The Xen command line takes a number of optional arguments described
    1.24     in the manual. The most common is 'dom0_mem=xxxM' which sets the
    1.25     amount of memory to allocate for use by your initial virtual
    1.26     machine (known as domain 0). Note that Xen itself reserves about
    1.27     32MB memory for internal use, which is not available for allocation
    1.28 -   to virtual machines.  
    1.29 +   to virtual machines.
    1.30  
    1.31  3. Reboot your system and select the "Xen 3.0 / XenLinux 2.6" menu
    1.32     option. After booting Xen, Linux will start and your initialisation
    1.33 @@ -86,7 +86,7 @@ First, there are a number of prerequisit
    1.34  release. Make sure you have all the following installed, either by
    1.35  visiting the project webpage or installing a pre-built package
    1.36  provided by your Linux distributor:
    1.37 -    * GCC (preferably v3.2.x or v3.3.x; older versions are unsupported) 
    1.38 +    * GCC (preferably v3.2.x or v3.3.x; older versions are unsupported)
    1.39      * GNU Make
    1.40      * GNU Binutils
    1.41      * Development install of zlib (e.g., zlib-dev)
    1.42 @@ -122,19 +122,19 @@ 3. For the very first build, or if you w
    1.43      # make world
    1.44      # make install
    1.45  
    1.46 -   This will create and install onto the local machine. It will build 
    1.47 +   This will create and install onto the local machine. It will build
    1.48     the xen binary (xen.gz), and a linux kernel and modules that can be
    1.49     used in both dom0 and an unprivileged guest kernel (vmlinuz-2.6.x-xen),
    1.50     the tools and the documentation.
    1.51  
    1.52 -   You can override the destination for make install by setting DESTDIR 
    1.53 +   You can override the destination for make install by setting DESTDIR
    1.54     to some value.
    1.55  
    1.56 -   The make command line defaults to building the kernel vmlinuz-2.6.x-xen. 
    1.57 -   You can override this default by specifying KERNELS=kernelname. For 
    1.58 -   example, you can make two kernels - linux-2.6-xen0 
    1.59 -   and linux-2.6-xenU - which are smaller builds containing only selected 
    1.60 -   modules, intended primarily for developers that don't like to wait 
    1.61 +   The make command line defaults to building the kernel vmlinuz-2.6.x-xen.
    1.62 +   You can override this default by specifying KERNELS=kernelname. For
    1.63 +   example, you can make two kernels - linux-2.6-xen0
    1.64 +   and linux-2.6-xenU - which are smaller builds containing only selected
    1.65 +   modules, intended primarily for developers that don't like to wait
    1.66     for a full -xen kernel to build. The -xenU kernel is particularly small,
    1.67     as it does not contain any physical device drivers, and hence is
    1.68     only useful for guest domains.
    1.69 @@ -153,15 +153,15 @@ 4. To rebuild an existing tree without m
    1.70      # make dist
    1.71  
    1.72     This will build and install xen, kernels, tools, and
    1.73 -   docs into the local dist/ directory. 
    1.74 +   docs into the local dist/ directory.
    1.75  
    1.76 -   You can override the destination for make install by setting DISTDIR 
    1.77 +   You can override the destination for make install by setting DISTDIR
    1.78     to some value.
    1.79  
    1.80 -   make install and make dist differ in that make install does the 
    1.81 -   right things for your local machine (installing the appropriate 
    1.82 -   version of hotplug or udev scripts, for example), but make dist 
    1.83 -   includes all versions of those scripts, so that you can copy the dist 
    1.84 +   make install and make dist differ in that make install does the
    1.85 +   right things for your local machine (installing the appropriate
    1.86 +   version of hotplug or udev scripts, for example), but make dist
    1.87 +   includes all versions of those scripts, so that you can copy the dist
    1.88     directory to another machine and install from that distribution.
    1.89  
    1.90  5. To rebuild a kernel with a modified config:
    1.91 @@ -171,6 +171,6 @@ 5. To rebuild a kernel with a modified c
    1.92      # make linux-2.6-xen-install
    1.93  
    1.94     Depending on your config, you may need to use 'mkinitrd' to create
    1.95 -   an initial ram disk, just like a native system e.g. 
    1.96 +   an initial ram disk, just like a native system e.g.
    1.97      # depmod 2.6.16-xen
    1.98      # mkinitrd -v -f --with=aacraid --with=sd_mod --with=scsi_mod initrd-2.6.16-xen.img 2.6.16-xen
     2.1 --- a/buildconfigs/linux-defconfig_xen0_x86_32	Mon May 22 08:53:26 2006 -0600
     2.2 +++ b/buildconfigs/linux-defconfig_xen0_x86_32	Mon May 22 14:13:38 2006 -0600
     2.3 @@ -1,7 +1,7 @@
     2.4  #
     2.5  # Automatically generated make config: don't edit
     2.6 -# Linux kernel version: 2.6.16-xen0
     2.7 -# Sat Apr  8 11:34:07 2006
     2.8 +# Linux kernel version: 2.6.16.13-xen0
     2.9 +# Thu May 11 17:06:31 2006
    2.10  #
    2.11  CONFIG_X86_32=y
    2.12  CONFIG_SEMAPHORE_SLEEPERS=y
    2.13 @@ -1309,7 +1309,7 @@ CONFIG_CRYPTO_CRC32C=m
    2.14  #
    2.15  # CONFIG_CRYPTO_DEV_PADLOCK is not set
    2.16  CONFIG_XEN=y
    2.17 -CONFIG_XEN_INTERFACE_VERSION=0x00030101
    2.18 +CONFIG_XEN_INTERFACE_VERSION=0x00030202
    2.19  
    2.20  #
    2.21  # XEN
    2.22 @@ -1330,10 +1330,12 @@ CONFIG_XEN_NETDEV_LOOPBACK=y
    2.23  CONFIG_XEN_BLKDEV_FRONTEND=y
    2.24  CONFIG_XEN_NETDEV_FRONTEND=y
    2.25  # CONFIG_XEN_BLKDEV_TAP is not set
    2.26 -# CONFIG_XEN_TPMDEV_FRONTEND is not set
    2.27  CONFIG_XEN_SCRUB_PAGES=y
    2.28  CONFIG_XEN_DISABLE_SERIAL=y
    2.29  CONFIG_XEN_SYSFS=y
    2.30 +CONFIG_XEN_COMPAT_030002_AND_LATER=y
    2.31 +# CONFIG_XEN_COMPAT_LATEST_ONLY is not set
    2.32 +CONFIG_XEN_COMPAT_030002=y
    2.33  CONFIG_HAVE_ARCH_ALLOC_SKB=y
    2.34  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    2.35  CONFIG_NO_IDLE_HZ=y
     3.1 --- a/buildconfigs/linux-defconfig_xen0_x86_64	Mon May 22 08:53:26 2006 -0600
     3.2 +++ b/buildconfigs/linux-defconfig_xen0_x86_64	Mon May 22 14:13:38 2006 -0600
     3.3 @@ -1,7 +1,7 @@
     3.4  #
     3.5  # Automatically generated make config: don't edit
     3.6 -# Linux kernel version: 2.6.16-xen0
     3.7 -# Thu Apr 13 14:58:29 2006
     3.8 +# Linux kernel version: 2.6.16.13-xen0
     3.9 +# Thu May 11 17:17:19 2006
    3.10  #
    3.11  CONFIG_X86_64=y
    3.12  CONFIG_64BIT=y
    3.13 @@ -1250,7 +1250,7 @@ CONFIG_CRYPTO_CRC32C=m
    3.14  # Hardware crypto devices
    3.15  #
    3.16  CONFIG_XEN=y
    3.17 -CONFIG_XEN_INTERFACE_VERSION=0x00030101
    3.18 +CONFIG_XEN_INTERFACE_VERSION=0x00030202
    3.19  
    3.20  #
    3.21  # XEN
    3.22 @@ -1271,10 +1271,12 @@ CONFIG_XEN_NETDEV_LOOPBACK=y
    3.23  CONFIG_XEN_BLKDEV_FRONTEND=y
    3.24  CONFIG_XEN_NETDEV_FRONTEND=y
    3.25  # CONFIG_XEN_BLKDEV_TAP is not set
    3.26 -# CONFIG_XEN_TPMDEV_FRONTEND is not set
    3.27  CONFIG_XEN_SCRUB_PAGES=y
    3.28  CONFIG_XEN_DISABLE_SERIAL=y
    3.29  CONFIG_XEN_SYSFS=y
    3.30 +CONFIG_XEN_COMPAT_030002_AND_LATER=y
    3.31 +# CONFIG_XEN_COMPAT_LATEST_ONLY is not set
    3.32 +CONFIG_XEN_COMPAT_030002=y
    3.33  CONFIG_HAVE_ARCH_ALLOC_SKB=y
    3.34  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    3.35  CONFIG_NO_IDLE_HZ=y
     4.1 --- a/buildconfigs/linux-defconfig_xenU_x86_32	Mon May 22 08:53:26 2006 -0600
     4.2 +++ b/buildconfigs/linux-defconfig_xenU_x86_32	Mon May 22 14:13:38 2006 -0600
     4.3 @@ -1,7 +1,7 @@
     4.4  #
     4.5  # Automatically generated make config: don't edit
     4.6 -# Linux kernel version: 2.6.16-rc3-xen0
     4.7 -# Thu Feb 16 22:53:43 2006
     4.8 +# Linux kernel version: 2.6.16.13-xenU
     4.9 +# Thu May 11 17:08:12 2006
    4.10  #
    4.11  CONFIG_X86_32=y
    4.12  CONFIG_SEMAPHORE_SLEEPERS=y
    4.13 @@ -617,11 +617,7 @@ CONFIG_DUMMY_CONSOLE=y
    4.14  #
    4.15  
    4.16  #
    4.17 -# SN Devices
    4.18 -#
    4.19 -
    4.20 -#
    4.21 -# EDAC - error detection and reporting (RAS)
    4.22 +# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
    4.23  #
    4.24  # CONFIG_EDAC is not set
    4.25  
    4.26 @@ -852,7 +848,7 @@ CONFIG_CRYPTO_CRC32C=m
    4.27  #
    4.28  # CONFIG_CRYPTO_DEV_PADLOCK is not set
    4.29  CONFIG_XEN=y
    4.30 -CONFIG_NO_IDLE_HZ=y
    4.31 +CONFIG_XEN_INTERFACE_VERSION=0x00030202
    4.32  
    4.33  #
    4.34  # XEN
    4.35 @@ -862,12 +858,15 @@ CONFIG_XEN_UNPRIVILEGED_GUEST=y
    4.36  # CONFIG_XEN_BACKEND is not set
    4.37  CONFIG_XEN_BLKDEV_FRONTEND=y
    4.38  CONFIG_XEN_NETDEV_FRONTEND=y
    4.39 -# CONFIG_XEN_TPMDEV_FRONTEND is not set
    4.40  CONFIG_XEN_SCRUB_PAGES=y
    4.41  CONFIG_XEN_DISABLE_SERIAL=y
    4.42  CONFIG_XEN_SYSFS=y
    4.43 +CONFIG_XEN_COMPAT_030002_AND_LATER=y
    4.44 +# CONFIG_XEN_COMPAT_LATEST_ONLY is not set
    4.45 +CONFIG_XEN_COMPAT_030002=y
    4.46  CONFIG_HAVE_ARCH_ALLOC_SKB=y
    4.47  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    4.48 +CONFIG_NO_IDLE_HZ=y
    4.49  
    4.50  #
    4.51  # Library routines
    4.52 @@ -883,4 +882,6 @@ CONFIG_GENERIC_PENDING_IRQ=y
    4.53  CONFIG_X86_SMP=y
    4.54  CONFIG_X86_BIOS_REBOOT=y
    4.55  CONFIG_X86_TRAMPOLINE=y
    4.56 +CONFIG_X86_NO_TSS=y
    4.57 +CONFIG_X86_NO_IDT=y
    4.58  CONFIG_KTIME_SCALAR=y
     5.1 --- a/buildconfigs/linux-defconfig_xenU_x86_64	Mon May 22 08:53:26 2006 -0600
     5.2 +++ b/buildconfigs/linux-defconfig_xenU_x86_64	Mon May 22 14:13:38 2006 -0600
     5.3 @@ -1,7 +1,7 @@
     5.4  #
     5.5  # Automatically generated make config: don't edit
     5.6 -# Linux kernel version: 2.6.16-xenU
     5.7 -# Thu Apr 13 14:59:16 2006
     5.8 +# Linux kernel version: 2.6.16.13-xenU
     5.9 +# Thu May 11 17:17:57 2006
    5.10  #
    5.11  CONFIG_X86_64=y
    5.12  CONFIG_64BIT=y
    5.13 @@ -1135,7 +1135,7 @@ CONFIG_CRYPTO_CRC32C=m
    5.14  # Hardware crypto devices
    5.15  #
    5.16  CONFIG_XEN=y
    5.17 -CONFIG_XEN_INTERFACE_VERSION=0x00030101
    5.18 +CONFIG_XEN_INTERFACE_VERSION=0x00030202
    5.19  
    5.20  #
    5.21  # XEN
    5.22 @@ -1145,10 +1145,12 @@ CONFIG_XEN_UNPRIVILEGED_GUEST=y
    5.23  # CONFIG_XEN_BACKEND is not set
    5.24  CONFIG_XEN_BLKDEV_FRONTEND=y
    5.25  CONFIG_XEN_NETDEV_FRONTEND=y
    5.26 -# CONFIG_XEN_TPMDEV_FRONTEND is not set
    5.27  CONFIG_XEN_SCRUB_PAGES=y
    5.28  CONFIG_XEN_DISABLE_SERIAL=y
    5.29  CONFIG_XEN_SYSFS=y
    5.30 +CONFIG_XEN_COMPAT_030002_AND_LATER=y
    5.31 +# CONFIG_XEN_COMPAT_LATEST_ONLY is not set
    5.32 +CONFIG_XEN_COMPAT_030002=y
    5.33  CONFIG_HAVE_ARCH_ALLOC_SKB=y
    5.34  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    5.35  CONFIG_NO_IDLE_HZ=y
     6.1 --- a/buildconfigs/linux-defconfig_xen_x86_32	Mon May 22 08:53:26 2006 -0600
     6.2 +++ b/buildconfigs/linux-defconfig_xen_x86_32	Mon May 22 14:13:38 2006 -0600
     6.3 @@ -1,7 +1,7 @@
     6.4  #
     6.5  # Automatically generated make config: don't edit
     6.6 -# Linux kernel version: 2.6.16-xen
     6.7 -# Thu Apr 20 17:07:18 2006
     6.8 +# Linux kernel version: 2.6.16.13-xen
     6.9 +# Thu May 11 17:11:00 2006
    6.10  #
    6.11  CONFIG_X86_32=y
    6.12  CONFIG_SEMAPHORE_SLEEPERS=y
    6.13 @@ -888,7 +888,7 @@ CONFIG_MTD_NAND_DISKONCHIP=m
    6.14  # CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADVANCED is not set
    6.15  CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS=0
    6.16  CONFIG_MTD_NAND_DISKONCHIP_BBTWRITE=y
    6.17 -CONFIG_MTD_NAND_NANDSIM=y
    6.18 +CONFIG_MTD_NAND_NANDSIM=m
    6.19  
    6.20  #
    6.21  # OneNAND Flash Device Drivers
    6.22 @@ -3009,7 +3009,7 @@ CONFIG_CRYPTO_TEST=m
    6.23  #
    6.24  # CONFIG_CRYPTO_DEV_PADLOCK is not set
    6.25  CONFIG_XEN=y
    6.26 -CONFIG_XEN_INTERFACE_VERSION=0x00030101
    6.27 +CONFIG_XEN_INTERFACE_VERSION=0x00030202
    6.28  
    6.29  #
    6.30  # XEN
    6.31 @@ -3030,10 +3030,12 @@ CONFIG_XEN_NETDEV_LOOPBACK=y
    6.32  CONFIG_XEN_BLKDEV_FRONTEND=y
    6.33  CONFIG_XEN_NETDEV_FRONTEND=y
    6.34  # CONFIG_XEN_BLKDEV_TAP is not set
    6.35 -CONFIG_XEN_TPMDEV_FRONTEND=m
    6.36  CONFIG_XEN_SCRUB_PAGES=y
    6.37  CONFIG_XEN_DISABLE_SERIAL=y
    6.38  CONFIG_XEN_SYSFS=y
    6.39 +CONFIG_XEN_COMPAT_030002_AND_LATER=y
    6.40 +# CONFIG_XEN_COMPAT_LATEST_ONLY is not set
    6.41 +CONFIG_XEN_COMPAT_030002=y
    6.42  CONFIG_HAVE_ARCH_ALLOC_SKB=y
    6.43  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    6.44  CONFIG_NO_IDLE_HZ=y
     7.1 --- a/buildconfigs/linux-defconfig_xen_x86_64	Mon May 22 08:53:26 2006 -0600
     7.2 +++ b/buildconfigs/linux-defconfig_xen_x86_64	Mon May 22 14:13:38 2006 -0600
     7.3 @@ -1,7 +1,7 @@
     7.4  #
     7.5  # Automatically generated make config: don't edit
     7.6 -# Linux kernel version: 2.6.16-xen
     7.7 -# Thu Apr 20 17:05:48 2006
     7.8 +# Linux kernel version: 2.6.16.13-xen
     7.9 +# Thu May 11 17:18:58 2006
    7.10  #
    7.11  CONFIG_X86_64=y
    7.12  CONFIG_64BIT=y
    7.13 @@ -840,7 +840,7 @@ CONFIG_MTD_NAND_DISKONCHIP=m
    7.14  # CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADVANCED is not set
    7.15  CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS=0
    7.16  CONFIG_MTD_NAND_DISKONCHIP_BBTWRITE=y
    7.17 -CONFIG_MTD_NAND_NANDSIM=y
    7.18 +CONFIG_MTD_NAND_NANDSIM=m
    7.19  
    7.20  #
    7.21  # OneNAND Flash Device Drivers
    7.22 @@ -2841,7 +2841,7 @@ CONFIG_CRYPTO_TEST=m
    7.23  # Hardware crypto devices
    7.24  #
    7.25  CONFIG_XEN=y
    7.26 -CONFIG_XEN_INTERFACE_VERSION=0x00030101
    7.27 +CONFIG_XEN_INTERFACE_VERSION=0x00030202
    7.28  
    7.29  #
    7.30  # XEN
    7.31 @@ -2863,10 +2863,12 @@ CONFIG_XEN_TPMDEV_BACKEND=m
    7.32  CONFIG_XEN_BLKDEV_FRONTEND=y
    7.33  CONFIG_XEN_NETDEV_FRONTEND=y
    7.34  # CONFIG_XEN_BLKDEV_TAP is not set
    7.35 -CONFIG_XEN_TPMDEV_FRONTEND=m
    7.36  CONFIG_XEN_SCRUB_PAGES=y
    7.37  CONFIG_XEN_DISABLE_SERIAL=y
    7.38  CONFIG_XEN_SYSFS=y
    7.39 +CONFIG_XEN_COMPAT_030002_AND_LATER=y
    7.40 +# CONFIG_XEN_COMPAT_LATEST_ONLY is not set
    7.41 +CONFIG_XEN_COMPAT_030002=y
    7.42  CONFIG_HAVE_ARCH_ALLOC_SKB=y
    7.43  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    7.44  CONFIG_NO_IDLE_HZ=y
     8.1 --- a/docs/man/xend-config.sxp.pod.5	Mon May 22 08:53:26 2006 -0600
     8.2 +++ b/docs/man/xend-config.sxp.pod.5	Mon May 22 14:13:38 2006 -0600
     8.3 @@ -107,7 +107,7 @@ If the value is 0, all available CPUs wi
     8.4  =item I<enable-dump>
     8.5  
     8.6  A boolean value that tells xend whether or not core dumps of guest
     8.7 -domains should be saved when a crash occurrs.  Defaults to I<no>.
     8.8 +domains should be saved when a crash occurs.  Defaults to I<no>.
     8.9  
    8.10  =item I<external-migration-tool>
    8.11  
     9.1 --- a/docs/man/xm.pod.1	Mon May 22 08:53:26 2006 -0600
     9.2 +++ b/docs/man/xm.pod.1	Mon May 22 14:13:38 2006 -0600
     9.3 @@ -27,12 +27,12 @@ each of those sub commands.
     9.4  
     9.5  =head1 NOTES
     9.6  
     9.7 -All B<xm> opperations rely upon the Xen control daemon, aka B<xend>.
     9.8 +All B<xm> operations rely upon the Xen control daemon, aka B<xend>.
     9.9  For any xm commands to run xend must also be running.  For this reason
    9.10  you should start xend as a service when your system first boots using
    9.11  xen.
    9.12  
    9.13 -Most B<xm> commands require root privledges to run due to the
    9.14 +Most B<xm> commands require root privileges to run due to the
    9.15  communications channels used to talk to the hypervisor.  Running as
    9.16  non root will return an error.
    9.17  
    9.18 @@ -169,7 +169,7 @@ The domain is currently running on a CPU
    9.19  
    9.20  =item B<b - blocked>
    9.21  
    9.22 -The domain is blocked, and not running or runable.  This can be caused
    9.23 +The domain is blocked, and not running or runnable.  This can be caused
    9.24  because the domain is waiting on IO (a traditional wait state) or has
    9.25  gone to sleep because there was nothing else for it to do.
    9.26  
    9.27 @@ -260,7 +260,7 @@ careful when using this command on runni
    9.28  
    9.29  Migrate a domain to another Host machine. B<Xend> must be running on
    9.30  other host machine, it must be running the same version of xen, it
    9.31 -must have the migration tcp port open and accepting connections from
    9.32 +must have the migration TCP port open and accepting connections from
    9.33  the source host, and there must be sufficient resources for the domain
    9.34  to run (memory, disk, etc).
    9.35  
    9.36 @@ -337,7 +337,7 @@ severed upon restore, as TCP timeouts ma
    9.37  =item B<shutdown> I<[options]> I<domain-id>
    9.38  
    9.39  Gracefully shuts down a domain.  This coordinates with the domain OS
    9.40 -to perform graceful shutdown, so there is no guaruntee that it will
    9.41 +to perform graceful shutdown, so there is no guarantee that it will
    9.42  succeed, and may take a variable length of time depending on what
    9.43  services must be shutdown in the domain.  The command returns
    9.44  immediately after signally the domain unless that I<-w> flag is used.
    9.45 @@ -573,11 +573,11 @@ B<PARAMETERS>
    9.46  
    9.47  =item I<period>
    9.48  
    9.49 -The normal EDF scheduling usage in nanosecs
    9.50 +The normal EDF scheduling usage in nanoseconds
    9.51  
    9.52  =item I<slice>
    9.53  
    9.54 -The normal EDF scheduling usage in nanosecs
    9.55 +The normal EDF scheduling usage in nanoseconds
    9.56  
    9.57  FIXME: these are lame, should explain more.
    9.58  
    9.59 @@ -726,7 +726,7 @@ circumstances this should actually work.
    9.60  
    9.61  =item I<mac=macaddr>
    9.62  
    9.63 -The MAC address that the domain will see on its ethernet device.  If
    9.64 +The MAC address that the domain will see on its Ethernet device.  If
    9.65  the device is not specified it will be randomly generated with the
    9.66  00:16:3e vendor id prefix.
    9.67  
    9.68 @@ -768,7 +768,7 @@ formatted as a list or as an S-Expressio
    9.69  
    9.70  The Virtual Network interfaces for Xen.
    9.71  
    9.72 -FIXME: This needs a lot more explaination, or it needs to be ripped
    9.73 +FIXME: This needs a lot more explanation, or it needs to be ripped
    9.74  out entirely.
    9.75  
    9.76  =over 4
    10.1 --- a/docs/man/xmdomain.cfg.pod.5	Mon May 22 08:53:26 2006 -0600
    10.2 +++ b/docs/man/xmdomain.cfg.pod.5	Mon May 22 14:13:38 2006 -0600
    10.3 @@ -80,7 +80,7 @@ An array of block device stanzas, in the
    10.4  
    10.5      disk = [ "stanza1", "stanza2", ... ]
    10.6  
    10.7 -Each stanza has 3 terms, seperated by commas,
    10.8 +Each stanza has 3 terms, separated by commas,
    10.9  "backend-dev,frontend-dev,mode".
   10.10  
   10.11  =over 4
   10.12 @@ -112,7 +112,7 @@ I<r> (read-only), I<w> (read/write).
   10.13  
   10.14  =item B<vif>
   10.15  
   10.16 -An arrray of virtual interface stanzas in the form:
   10.17 +An array of virtual interface stanzas in the form:
   10.18  
   10.19      vif = [ "stanza1", "stanza2", ... ]
   10.20  
    11.1 --- a/extras/mini-os/Makefile	Mon May 22 08:53:26 2006 -0600
    11.2 +++ b/extras/mini-os/Makefile	Mon May 22 14:13:38 2006 -0600
    11.3 @@ -1,4 +1,5 @@
    11.4  debug ?= y
    11.5 +pae ?= n
    11.6  
    11.7  include $(CURDIR)/../../Config.mk
    11.8  
    11.9 @@ -6,18 +7,28 @@ include $(CURDIR)/../../Config.mk
   11.10  override TARGET_ARCH     := $(XEN_TARGET_ARCH)
   11.11  
   11.12  # NB. '-Wcast-qual' is nasty, so I omitted it.
   11.13 -CFLAGS := -fno-builtin -Wall -Werror -Iinclude/ -Wredundant-decls -Wno-format
   11.14 +CFLAGS := -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format
   11.15  CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
   11.16  
   11.17 +override CPPFLAGS := -Iinclude $(CPPFLAGS)
   11.18 +ASFLAGS = -D__ASSEMBLY__
   11.19 +
   11.20 +LDFLAGS := -N -T minios-$(TARGET_ARCH).lds
   11.21 +
   11.22  ifeq ($(TARGET_ARCH),x86_32)
   11.23  CFLAGS += -m32 -march=i686
   11.24 -LDFLAGS := -m elf_i386
   11.25 +LDFLAGS += -m elf_i386
   11.26 +endif
   11.27 +
   11.28 +ifeq ($(TARGET_ARCH)$(pae),x86_32y)
   11.29 +CFLAGS  += -DCONFIG_X86_PAE=1
   11.30 +ASFLAGS += -DCONFIG_X86_PAE=1
   11.31  endif
   11.32  
   11.33  ifeq ($(TARGET_ARCH),x86_64)
   11.34  CFLAGS += -m64 -mno-red-zone -fpic -fno-reorder-blocks
   11.35  CFLAGS += -fno-asynchronous-unwind-tables
   11.36 -LDFLAGS := -m elf_x86_64
   11.37 +LDFLAGS += -m elf_x86_64
   11.38  endif
   11.39  
   11.40  ifeq ($(debug),y)
   11.41 @@ -28,12 +39,12 @@ endif
   11.42  
   11.43  TARGET := mini-os
   11.44  
   11.45 -OBJS := $(TARGET_ARCH).o
   11.46 -OBJS += $(patsubst %.c,%.o,$(wildcard *.c))
   11.47 +HEAD := $(TARGET_ARCH).o
   11.48 +OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
   11.49  OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
   11.50  OBJS += $(patsubst %.c,%.o,$(wildcard xenbus/*.c))
   11.51  OBJS += $(patsubst %.c,%.o,$(wildcard console/*.c))
   11.52 -										   
   11.53 +
   11.54  HDRS := $(wildcard include/*.h)
   11.55  HDRS += $(wildcard include/xen/*.h)
   11.56  
   11.57 @@ -44,21 +55,25 @@ default: $(TARGET)
   11.58  links:
   11.59  	[ -e include/xen ] || ln -sf ../../../xen/include/public include/xen
   11.60  
   11.61 -$(TARGET): links $(OBJS)
   11.62 -	$(LD) -N -T minios-$(TARGET_ARCH).lds $(OBJS) -o $@.elf
   11.63 +libminios.a: $(OBJS) $(HEAD)
   11.64 +	ar r libminios.a $(HEAD) $(OBJS)
   11.65 +
   11.66 +$(TARGET): links libminios.a $(HEAD)
   11.67 +	$(LD) $(LDFLAGS) $(HEAD) -L. -lminios -o $@.elf
   11.68  	gzip -f -9 -c $@.elf >$@.gz
   11.69  
   11.70  .PHONY: clean
   11.71  clean:
   11.72  	find . -type f -name '*.o' | xargs rm -f
   11.73  	rm -f *.o *~ core $(TARGET).elf $(TARGET).raw $(TARGET) $(TARGET).gz
   11.74 +	rm -f libminios.a
   11.75  	find . -type l | xargs rm -f
   11.76  
   11.77  %.o: %.c $(HDRS) Makefile
   11.78 -	$(CC) $(CFLAGS) -c $< -o $@
   11.79 +	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
   11.80  
   11.81  %.o: %.S $(HDRS) Makefile
   11.82 -	$(CC) $(CFLAGS) -D__ASSEMBLY__ -c $< -o $@
   11.83 +	$(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@
   11.84  
   11.85  define all_sources
   11.86       ( find . -follow -name SCCS -prune -o -name '*.[chS]' -print )
    12.1 --- a/extras/mini-os/console/console.c	Mon May 22 08:53:26 2006 -0600
    12.2 +++ b/extras/mini-os/console/console.c	Mon May 22 14:13:38 2006 -0600
    12.3 @@ -45,6 +45,10 @@
    12.4  #include <xen/io/console.h>
    12.5  
    12.6  
    12.7 +/* Copies all print output to the Xen emergency console apart
    12.8 +   of standard dom0 handled console */
    12.9 +#define USE_XEN_CONSOLE
   12.10 +
   12.11  /* Low level functions defined in xencons_ring.c */
   12.12  extern int xencons_ring_init(void);
   12.13  extern int xencons_ring_send(const char *data, unsigned len);
   12.14 @@ -117,7 +121,9 @@ void print(int direct, const char *fmt, 
   12.15          (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf);
   12.16          return;
   12.17      } else {
   12.18 -        if(!console_initialised)
   12.19 +#ifndef USE_XEN_CONSOLE
   12.20 +    if(!console_initialised)
   12.21 +#endif    
   12.22              (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf);
   12.23          
   12.24          console_print(buf, strlen(buf));
   12.25 @@ -128,7 +134,7 @@ void printk(const char *fmt, ...)
   12.26  {
   12.27      va_list       args;
   12.28      va_start(args, fmt);
   12.29 -    print(1, fmt, args);
   12.30 +    print(0, fmt, args);
   12.31      va_end(args);        
   12.32  }
   12.33  
    13.1 --- a/extras/mini-os/include/mm.h	Mon May 22 08:53:26 2006 -0600
    13.2 +++ b/extras/mini-os/include/mm.h	Mon May 22 14:13:38 2006 -0600
    13.3 @@ -43,6 +43,8 @@
    13.4  
    13.5  #if defined(__i386__)
    13.6  
    13.7 +#if !defined(CONFIG_X86_PAE)
    13.8 +
    13.9  #define L2_PAGETABLE_SHIFT      22
   13.10  
   13.11  #define L1_PAGETABLE_ENTRIES    1024
   13.12 @@ -51,6 +53,30 @@
   13.13  #define PADDR_BITS              32
   13.14  #define PADDR_MASK              (~0UL)
   13.15  
   13.16 +#define UNMAPPED_PT_FRAMES        1
   13.17 +#define PRIpte "08lx"
   13.18 +typedef unsigned long pgentry_t;
   13.19 +
   13.20 +#else /* defined(CONFIG_X86_PAE) */
   13.21 +
   13.22 +#define L2_PAGETABLE_SHIFT      21
   13.23 +#define L3_PAGETABLE_SHIFT      30
   13.24 +
   13.25 +#define L1_PAGETABLE_ENTRIES    512
   13.26 +#define L2_PAGETABLE_ENTRIES    512
   13.27 +#define L3_PAGETABLE_ENTRIES    4
   13.28 +
   13.29 +#define PADDR_BITS              44
   13.30 +#define PADDR_MASK              ((1ULL << PADDR_BITS)-1)
   13.31 +
   13.32 +#define L2_MASK  ((1UL << L3_PAGETABLE_SHIFT) - 1)
   13.33 +
   13.34 +#define UNMAPPED_PT_FRAMES        2
   13.35 +#define PRIpte "016llx"
   13.36 +typedef uint64_t pgentry_t;
   13.37 +
   13.38 +#endif /* !defined(CONFIG_X86_PAE) */
   13.39 +
   13.40  #elif defined(__x86_64__)
   13.41  
   13.42  #define L2_PAGETABLE_SHIFT      21
   13.43 @@ -81,6 +107,10 @@
   13.44  #define L2_MASK  ((1UL << L3_PAGETABLE_SHIFT) - 1)
   13.45  #define L3_MASK  ((1UL << L4_PAGETABLE_SHIFT) - 1)
   13.46  
   13.47 +#define UNMAPPED_PT_FRAMES        3
   13.48 +#define PRIpte "016lx"
   13.49 +typedef unsigned long pgentry_t;
   13.50 +
   13.51  #endif
   13.52  
   13.53  #define L1_MASK  ((1UL << L2_PAGETABLE_SHIFT) - 1)
   13.54 @@ -90,9 +120,11 @@
   13.55    (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
   13.56  #define l2_table_offset(_a) \
   13.57    (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
   13.58 -#if defined(__x86_64__)
   13.59 +#if defined(__x86_64__) || defined(CONFIG_X86_PAE)
   13.60  #define l3_table_offset(_a) \
   13.61    (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
   13.62 +#endif
   13.63 +#if defined(__x86_64__)
   13.64  #define l4_table_offset(_a) \
   13.65    (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
   13.66  #endif
   13.67 @@ -111,14 +143,21 @@
   13.68  #if defined(__i386__)
   13.69  #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
   13.70  #define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY |_PAGE_USER)
   13.71 +#if defined(CONFIG_X86_PAE)
   13.72 +#define L3_PROT (_PAGE_PRESENT)
   13.73 +#endif /* CONFIG_X86_PAE */
   13.74  #elif defined(__x86_64__)
   13.75  #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
   13.76  #define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   13.77  #define L3_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   13.78  #define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   13.79 -#endif
   13.80 +#endif /* __i386__ || __x86_64__ */
   13.81  
   13.82 +#ifndef CONFIG_X86_PAE
   13.83  #define PAGE_SIZE       (1UL << L1_PAGETABLE_SHIFT)
   13.84 +#else
   13.85 +#define PAGE_SIZE       (1ULL << L1_PAGETABLE_SHIFT)
   13.86 +#endif
   13.87  #define PAGE_SHIFT      L1_PAGETABLE_SHIFT
   13.88  #define PAGE_MASK       (~(PAGE_SIZE-1))
   13.89  
   13.90 @@ -129,36 +168,41 @@
   13.91  /* to align the pointer to the (next) page boundary */
   13.92  #define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
   13.93  
   13.94 +/* Definitions for machine and pseudophysical addresses. */
   13.95 +#ifdef CONFIG_X86_PAE
   13.96 +typedef unsigned long long paddr_t;
   13.97 +typedef unsigned long long maddr_t;
   13.98 +#else
   13.99 +typedef unsigned long paddr_t;
  13.100 +typedef unsigned long maddr_t;
  13.101 +#endif
  13.102 +
  13.103  extern unsigned long *phys_to_machine_mapping;
  13.104 +extern char _text, _etext, _edata, _end;
  13.105  #define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)])
  13.106 -static __inline__ unsigned long phys_to_machine(unsigned long phys)
  13.107 +static __inline__ maddr_t phys_to_machine(paddr_t phys)
  13.108  {
  13.109 -    unsigned long machine = pfn_to_mfn(phys >> L1_PAGETABLE_SHIFT);
  13.110 -    machine = (machine << L1_PAGETABLE_SHIFT) | (phys & ~PAGE_MASK);
  13.111 -    return machine;
  13.112 +	maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
  13.113 +	machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
  13.114 +	return machine;
  13.115  }
  13.116  
  13.117 -
  13.118  #define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
  13.119 -static __inline__ unsigned long machine_to_phys(unsigned long machine)
  13.120 +static __inline__ paddr_t machine_to_phys(maddr_t machine)
  13.121  {
  13.122 -    unsigned long phys = mfn_to_pfn(machine >> L1_PAGETABLE_SHIFT);
  13.123 -    phys = (phys << L1_PAGETABLE_SHIFT) | (machine & ~PAGE_MASK);
  13.124 -    return phys;
  13.125 +	paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
  13.126 +	phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
  13.127 +	return phys;
  13.128  }
  13.129  
  13.130 -#if defined(__x86_64__)
  13.131 -#define VIRT_START              0xFFFFFFFF80000000UL
  13.132 -#elif defined(__i386__)
  13.133 -#define VIRT_START              0xC0000000UL
  13.134 -#endif
  13.135 +#define VIRT_START                 ((unsigned long)&_text)
  13.136  
  13.137  #define to_phys(x)                 ((unsigned long)(x)-VIRT_START)
  13.138  #define to_virt(x)                 ((void *)((unsigned long)(x)+VIRT_START))
  13.139  
  13.140  #define virt_to_pfn(_virt)         (PFN_DOWN(to_phys(_virt)))
  13.141  #define mach_to_virt(_mach)        (to_virt(machine_to_phys(_mach)))
  13.142 -#define mfn_to_virt(_mfn)          (mach_to_virt(_mfn << PAGE_SHIFT))
  13.143 +#define mfn_to_virt(_mfn)          (to_virt(mfn_to_pfn(_mfn) << PAGE_SHIFT))
  13.144  #define pfn_to_virt(_pfn)          (to_virt(_pfn << PAGE_SHIFT))
  13.145  
  13.146  /* Pagetable walking. */
    14.1 --- a/extras/mini-os/include/types.h	Mon May 22 08:53:26 2006 -0600
    14.2 +++ b/extras/mini-os/include/types.h	Mon May 22 14:13:38 2006 -0600
    14.3 @@ -43,14 +43,19 @@ typedef long long           quad_t;
    14.4  typedef unsigned long long  u_quad_t;
    14.5  typedef unsigned int        uintptr_t;
    14.6  
    14.7 +#if !defined(CONFIG_X86_PAE)
    14.8  typedef struct { unsigned long pte_low; } pte_t;
    14.9 +#else
   14.10 +typedef struct { unsigned long pte_low, pte_high; } pte_t;
   14.11 +#endif /* CONFIG_X86_PAE */
   14.12 +
   14.13  #elif defined(__x86_64__)
   14.14  typedef long                quad_t;
   14.15  typedef unsigned long       u_quad_t;
   14.16  typedef unsigned long       uintptr_t;
   14.17  
   14.18  typedef struct { unsigned long pte; } pte_t;
   14.19 -#endif
   14.20 +#endif /* __i386__ || __x86_64__ */
   14.21  
   14.22  typedef  u8 uint8_t;
   14.23  typedef  s8 int8_t;
    15.1 --- a/extras/mini-os/kernel.c	Mon May 22 08:53:26 2006 -0600
    15.2 +++ b/extras/mini-os/kernel.c	Mon May 22 14:13:38 2006 -0600
    15.3 @@ -63,7 +63,12 @@ void failsafe_callback(void);
    15.4  
    15.5  extern char shared_info[PAGE_SIZE];
    15.6  
    15.7 +#if !defined(CONFIG_X86_PAE)
    15.8  #define __pte(x) ((pte_t) { (x) } )
    15.9 +#else
   15.10 +#define __pte(x) ({ unsigned long long _x = (x);        \
   15.11 +    ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
   15.12 +#endif
   15.13  
   15.14  static shared_info_t *map_shared_info(unsigned long pa)
   15.15  {
   15.16 @@ -71,7 +76,7 @@ static shared_info_t *map_shared_info(un
   15.17          (unsigned long)shared_info, __pte(pa | 7), UVMF_INVLPG) )
   15.18      {
   15.19          printk("Failed to map shared_info!!\n");
   15.20 -        *(int*)0=0;
   15.21 +        do_exit();
   15.22      }
   15.23      return (shared_info_t *)shared_info;
   15.24  }
   15.25 @@ -106,6 +111,12 @@ void setup_xen_features(void)
   15.26      }
   15.27  }
   15.28  
   15.29 +/* This should be overridden by the application we are linked against. */
   15.30 +__attribute__((weak)) int app_main(start_info_t *si)
   15.31 +{
   15.32 +    printk("Dummy main: start_info=%p\n", si);
   15.33 +    return 0;
   15.34 +}
   15.35  
   15.36  /*
   15.37   * INITIAL C ENTRY POINT.
   15.38 @@ -120,6 +131,10 @@ void start_kernel(start_info_t *si)
   15.39      /* WARN: don't do printk before here, it uses information from
   15.40         shared_info. Use xprintk instead. */
   15.41      memcpy(&start_info, si, sizeof(*si));
   15.42 +    
   15.43 +    /* set up minimal memory infos */
   15.44 +    phys_to_machine_mapping = (unsigned long *)start_info.mfn_list;
   15.45 +
   15.46      /* Grab the shared_info pointer and put it in a safe place. */
   15.47      HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
   15.48  
   15.49 @@ -165,12 +180,15 @@ void start_kernel(start_info_t *si)
   15.50      /* Init the console driver. */
   15.51      init_console();
   15.52   
   15.53 -   /* Init scheduler. */
   15.54 +    /* Init scheduler. */
   15.55      init_sched();
   15.56   
   15.57      /* Init XenBus from a separate thread */
   15.58      create_thread("init_xs", init_xs, NULL);
   15.59  
   15.60 +    /* Call (possibly overridden) app_main() */
   15.61 +    app_main(&start_info);
   15.62 +
   15.63      /* Everything initialised, start idle thread */
   15.64      run_idle_thread();
   15.65  }
    16.1 --- a/extras/mini-os/mm.c	Mon May 22 08:53:26 2006 -0600
    16.2 +++ b/extras/mini-os/mm.c	Mon May 22 14:13:38 2006 -0600
    16.3 @@ -50,7 +50,6 @@
    16.4  
    16.5  unsigned long *phys_to_machine_mapping;
    16.6  extern char *stack;
    16.7 -extern char _text, _etext, _edata, _end;
    16.8  extern void page_walk(unsigned long virt_addr);
    16.9  
   16.10  /*********************
   16.11 @@ -369,7 +368,7 @@ void free_pages(void *pointer, int order
   16.12  void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn, 
   16.13                                  unsigned long offset, unsigned long level)
   16.14  {   
   16.15 -    unsigned long *tab = (unsigned long *)start_info.pt_base;
   16.16 +    pgentry_t *tab = (pgentry_t *)start_info.pt_base;
   16.17      unsigned long pt_page = (unsigned long)pfn_to_virt(*pt_pfn); 
   16.18      unsigned long prot_e, prot_t, pincmd;
   16.19      mmu_update_t mmu_updates[1];
   16.20 @@ -383,40 +382,45 @@ void new_pt_frame(unsigned long *pt_pfn,
   16.21         as a page table page */
   16.22      memset((unsigned long*)pfn_to_virt(*pt_pfn), 0, PAGE_SIZE);  
   16.23   
   16.24 -    if (level == L1_FRAME)
   16.25 +    switch ( level )
   16.26      {
   16.27 +    case L1_FRAME:
   16.28           prot_e = L1_PROT;
   16.29           prot_t = L2_PROT;
   16.30           pincmd = MMUEXT_PIN_L1_TABLE;
   16.31 -    }
   16.32 -#if (defined __x86_64__)
   16.33 -    else if (level == L2_FRAME)
   16.34 -    {
   16.35 +         break;
   16.36 +#if defined(__x86_64__) || defined(CONFIG_X86_PAE)
   16.37 +    case L2_FRAME:
   16.38           prot_e = L2_PROT;
   16.39           prot_t = L3_PROT;
   16.40           pincmd = MMUEXT_PIN_L2_TABLE;
   16.41 -    }
   16.42 -    else if (level == L3_FRAME)
   16.43 -    {
   16.44 +         break;
   16.45 +#endif
   16.46 +#if defined(__x86_64__)
   16.47 +    case L3_FRAME:
   16.48           prot_e = L3_PROT;
   16.49           prot_t = L4_PROT;
   16.50           pincmd = MMUEXT_PIN_L3_TABLE;
   16.51 -    }
   16.52 +         break;
   16.53  #endif
   16.54 -    else
   16.55 -    {
   16.56 +    default:
   16.57           printk("new_pt_frame() called with invalid level number %d\n", level);
   16.58           do_exit();
   16.59 -    }    
   16.60 +         break;
   16.61 +    }
   16.62  
   16.63      /* Update the entry */
   16.64 -#if (defined __x86_64__)
   16.65 +#if defined(__x86_64__)
   16.66      tab = pte_to_virt(tab[l4_table_offset(pt_page)]);
   16.67      tab = pte_to_virt(tab[l3_table_offset(pt_page)]);
   16.68  #endif
   16.69 -    mmu_updates[0].ptr = (tab[l2_table_offset(pt_page)] & PAGE_MASK) + 
   16.70 -                         sizeof(void *)* l1_table_offset(pt_page);
   16.71 -    mmu_updates[0].val = pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | 
   16.72 +#if defined(CONFIG_X86_PAE)
   16.73 +    tab = pte_to_virt(tab[l3_table_offset(pt_page)]);
   16.74 +#endif
   16.75 +
   16.76 +    mmu_updates[0].ptr = ((pgentry_t)tab[l2_table_offset(pt_page)] & PAGE_MASK) + 
   16.77 +                         sizeof(pgentry_t) * l1_table_offset(pt_page);
   16.78 +    mmu_updates[0].val = (pgentry_t)pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | 
   16.79                           (prot_e & ~_PAGE_RW);
   16.80      if(HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF) < 0)
   16.81      {
   16.82 @@ -435,8 +439,8 @@ void new_pt_frame(unsigned long *pt_pfn,
   16.83  
   16.84      /* Now fill the new page table page with entries.
   16.85         Update the page directory as well. */
   16.86 -    mmu_updates[0].ptr = (prev_l_mfn << PAGE_SHIFT) + sizeof(void *) * offset;
   16.87 -    mmu_updates[0].val = pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | prot_t;
   16.88 +    mmu_updates[0].ptr = ((pgentry_t)prev_l_mfn << PAGE_SHIFT) + sizeof(pgentry_t) * offset;
   16.89 +    mmu_updates[0].val = (pgentry_t)pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | prot_t;
   16.90      if(HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF) < 0) 
   16.91      {            
   16.92         printk("ERROR: mmu_update failed\n");
   16.93 @@ -451,16 +455,13 @@ void build_pagetable(unsigned long *star
   16.94      unsigned long start_address, end_address;
   16.95      unsigned long pfn_to_map, pt_pfn = *start_pfn;
   16.96      static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
   16.97 -    unsigned long *tab = (unsigned long *)start_info.pt_base;
   16.98 +    pgentry_t *tab = (pgentry_t *)start_info.pt_base, page;
   16.99      unsigned long mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
  16.100 -    unsigned long page, offset;
  16.101 +    unsigned long offset;
  16.102      int count = 0;
  16.103  
  16.104 -#if defined(__x86_64__)
  16.105 -    pfn_to_map = (start_info.nr_pt_frames - 3) * L1_PAGETABLE_ENTRIES;
  16.106 -#else
  16.107 -    pfn_to_map = (start_info.nr_pt_frames - 1) * L1_PAGETABLE_ENTRIES;
  16.108 -#endif
  16.109 +    pfn_to_map = (start_info.nr_pt_frames - UNMAPPED_PT_FRAMES) * L1_PAGETABLE_ENTRIES;
  16.110 +
  16.111      start_address = (unsigned long)pfn_to_virt(pfn_to_map);
  16.112      end_address = (unsigned long)pfn_to_virt(*max_pfn);
  16.113      
  16.114 @@ -469,7 +470,7 @@ void build_pagetable(unsigned long *star
  16.115  
  16.116      while(start_address < end_address)
  16.117      {
  16.118 -        tab = (unsigned long *)start_info.pt_base;
  16.119 +        tab = (pgentry_t *)start_info.pt_base;
  16.120          mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
  16.121  
  16.122  #if defined(__x86_64__)
  16.123 @@ -481,6 +482,8 @@ void build_pagetable(unsigned long *star
  16.124          page = tab[offset];
  16.125          mfn = pte_to_mfn(page);
  16.126          tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
  16.127 +#endif
  16.128 +#if defined(__x86_64__) || defined(CONFIG_X86_PAE)
  16.129          offset = l3_table_offset(start_address);
  16.130          /* Need new L2 pt frame */
  16.131          if(!(start_address & L2_MASK)) 
  16.132 @@ -499,9 +502,9 @@ void build_pagetable(unsigned long *star
  16.133          mfn = pte_to_mfn(page);
  16.134          offset = l1_table_offset(start_address);
  16.135  
  16.136 -        mmu_updates[count].ptr = (mfn << PAGE_SHIFT) + sizeof(void *) * offset;
  16.137 +        mmu_updates[count].ptr = ((pgentry_t)mfn << PAGE_SHIFT) + sizeof(pgentry_t) * offset;
  16.138          mmu_updates[count].val = 
  16.139 -            pfn_to_mfn(pfn_to_map++) << PAGE_SHIFT | L1_PROT;
  16.140 +            (pgentry_t)pfn_to_mfn(pfn_to_map++) << PAGE_SHIFT | L1_PROT;
  16.141          count++;
  16.142          if (count == L1_PAGETABLE_ENTRIES || pfn_to_map == *max_pfn)
  16.143          {
  16.144 @@ -558,9 +561,6 @@ void init_mm(void)
  16.145      printk("  stack start:  %p\n", &stack);
  16.146      printk("  _end:         %p\n", &_end);
  16.147  
  16.148 -    /* set up minimal memory infos */
  16.149 -    phys_to_machine_mapping = (unsigned long *)start_info.mfn_list;
  16.150 -   
  16.151      /* First page follows page table pages and 3 more pages (store page etc) */
  16.152      start_pfn = PFN_UP(to_phys(start_info.pt_base)) + 
  16.153                  start_info.nr_pt_frames + 3;
  16.154 @@ -570,7 +570,7 @@ void init_mm(void)
  16.155      printk("  max_pfn:      %lx\n", max_pfn);
  16.156  
  16.157      build_pagetable(&start_pfn, &max_pfn);
  16.158 -    
  16.159 +
  16.160      /*
  16.161       * now we can initialise the page allocator
  16.162       */
    17.1 --- a/extras/mini-os/traps.c	Mon May 22 08:53:26 2006 -0600
    17.2 +++ b/extras/mini-os/traps.c	Mon May 22 14:13:38 2006 -0600
    17.3 @@ -95,34 +95,47 @@ DO_ERROR(18, "machine check", machine_ch
    17.4  
    17.5  void page_walk(unsigned long virt_address)
    17.6  {
    17.7 -        unsigned long *tab = (unsigned long *)start_info.pt_base;
    17.8 -        unsigned long addr = virt_address, page;
    17.9 +        pgentry_t *tab = (pgentry_t *)start_info.pt_base, page;
   17.10 +        unsigned long addr = virt_address;
   17.11          printk("Pagetable walk from virt %lx, base %lx:\n", virt_address, start_info.pt_base);
   17.12      
   17.13  #if defined(__x86_64__)
   17.14          page = tab[l4_table_offset(addr)];
   17.15 -        tab = to_virt(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
   17.16 -        printk(" L4 = %p (%p)  [offset = %lx]\n", page, tab, l4_table_offset(addr));
   17.17 -
   17.18 +        tab = pte_to_virt(page);
   17.19 +        printk(" L4 = %"PRIpte" (%p)  [offset = %lx]\n", page, tab, l4_table_offset(addr));
   17.20 +#endif
   17.21 +#if defined(__x86_64__) || defined(CONFIG_X86_PAE)
   17.22          page = tab[l3_table_offset(addr)];
   17.23 -        tab = to_virt(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
   17.24 -        printk("  L3 = %p (%p)  [offset = %lx]\n", page, tab, l3_table_offset(addr));
   17.25 +        tab = pte_to_virt(page);
   17.26 +        printk("  L3 = %"PRIpte" (%p)  [offset = %lx]\n", page, tab, l3_table_offset(addr));
   17.27  #endif
   17.28          page = tab[l2_table_offset(addr)];
   17.29 -        tab =  to_virt(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
   17.30 -        printk("   L2 = %p (%p)  [offset = %lx]\n", page, tab, l2_table_offset(addr));
   17.31 +        tab = pte_to_virt(page);
   17.32 +        printk("   L2 = %"PRIpte" (%p)  [offset = %lx]\n", page, tab, l2_table_offset(addr));
   17.33          
   17.34          page = tab[l1_table_offset(addr)];
   17.35 -        printk("    L1 = %p (%p)  [offset = %lx]\n", page, tab, l1_table_offset(addr));
   17.36 +        printk("    L1 = %"PRIpte" (%p)  [offset = %lx]\n", page, tab, l1_table_offset(addr));
   17.37  
   17.38  }
   17.39  
   17.40  #define read_cr2() \
   17.41          (HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].arch.cr2)
   17.42  
   17.43 +static int handling_pg_fault = 0;
   17.44 +
   17.45  void do_page_fault(struct pt_regs *regs, unsigned long error_code)
   17.46  {
   17.47      unsigned long addr = read_cr2();
   17.48 +    /* If we are already handling a page fault, and got another one
   17.49 +       that means we faulted in pagetable walk. Continuing here would cause
   17.50 +       a recursive fault */       
   17.51 +    if(handling_pg_fault) 
   17.52 +    {
   17.53 +        printk("Page fault in pagetable walk (access to invalid memory?).\n"); 
   17.54 +        do_exit();
   17.55 +    }
   17.56 +    handling_pg_fault = 1;
   17.57 +
   17.58  #if defined(__x86_64__)
   17.59      printk("Page fault at linear address %p, rip %p, code %lx\n",
   17.60             addr, regs->rip, error_code);
   17.61 @@ -130,9 +143,12 @@ void do_page_fault(struct pt_regs *regs,
   17.62      printk("Page fault at linear address %p, eip %p, code %lx\n",
   17.63             addr, regs->eip, error_code);
   17.64  #endif
   17.65 +
   17.66      dump_regs(regs);
   17.67      page_walk(addr);
   17.68      do_exit();
   17.69 +    /* We should never get here ... but still */
   17.70 +    handling_pg_fault = 0;
   17.71  }
   17.72  
   17.73  void do_general_protection(struct pt_regs *regs, long error_code)
    18.1 --- a/extras/mini-os/x86_32.S	Mon May 22 08:53:26 2006 -0600
    18.2 +++ b/extras/mini-os/x86_32.S	Mon May 22 14:13:38 2006 -0600
    18.3 @@ -4,9 +4,15 @@
    18.4  .section __xen_guest
    18.5  	.ascii	"GUEST_OS=Mini-OS"
    18.6  	.ascii	",XEN_VER=xen-3.0"
    18.7 +	.ascii	",VIRT_BASE=0xc0000000" /* &_text from minios_x86_32.lds */
    18.8 +	.ascii	",ELF_PADDR_OFFSET=0xc0000000"
    18.9  	.ascii	",HYPERCALL_PAGE=0x2"
   18.10 +#ifdef CONFIG_X86_PAE
   18.11 +	.ascii	",PAE=yes"
   18.12 +#else
   18.13 +	.ascii	",PAE=no"
   18.14 +#endif
   18.15  	.ascii	",LOADER=generic"
   18.16 -	.ascii	",PT_MODE_WRITABLE"
   18.17  	.byte	0
   18.18  .text
   18.19  
    19.1 --- a/extras/mini-os/x86_64.S	Mon May 22 08:53:26 2006 -0600
    19.2 +++ b/extras/mini-os/x86_64.S	Mon May 22 14:13:38 2006 -0600
    19.3 @@ -4,9 +4,10 @@
    19.4  .section __xen_guest
    19.5  	.ascii	"GUEST_OS=Mini-OS"
    19.6  	.ascii	",XEN_VER=xen-3.0"
    19.7 +	.ascii	",VIRT_BASE=0xffffffff80000000" /* &_text from minios_x86_64.lds */
    19.8 +	.ascii	",ELF_PADDR_OFFSET=0xffffffff80000000"
    19.9  	.ascii	",HYPERCALL_PAGE=0x2"
   19.10  	.ascii	",LOADER=generic"
   19.11 -	.ascii	",PT_MODE_WRITABLE"
   19.12  	.byte	0
   19.13  .text
   19.14  
    20.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/fixup.c	Mon May 22 08:53:26 2006 -0600
    20.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/fixup.c	Mon May 22 14:13:38 2006 -0600
    20.3 @@ -84,13 +84,3 @@ static int __init fixup_init(void)
    20.4  	return 0;
    20.5  }
    20.6  __initcall(fixup_init);
    20.7 -
    20.8 -/*
    20.9 - * Local variables:
   20.10 - *  c-file-style: "linux"
   20.11 - *  indent-tabs-mode: t
   20.12 - *  c-indent-level: 8
   20.13 - *  c-basic-offset: 8
   20.14 - *  tab-width: 8
   20.15 - * End:
   20.16 - */
    21.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/head-xen.S	Mon May 22 08:53:26 2006 -0600
    21.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/head-xen.S	Mon May 22 14:13:38 2006 -0600
    21.3 @@ -23,6 +23,8 @@
    21.4  #define X86_CAPABILITY	new_cpu_data+CPUINFO_x86_capability
    21.5  #define X86_VENDOR_ID	new_cpu_data+CPUINFO_x86_vendor_id
    21.6  
    21.7 +#define VIRT_ENTRY_OFFSET 0x0
    21.8 +.org VIRT_ENTRY_OFFSET
    21.9  ENTRY(startup_32)
   21.10  	movl %esi,xen_start_info
   21.11  	cld
   21.12 @@ -155,6 +157,14 @@ ENTRY(cpu_gdt_table)
   21.13  	.ascii	",XEN_VER=xen-3.0"
   21.14  	.ascii	",VIRT_BASE=0x"
   21.15  		utoa __PAGE_OFFSET
   21.16 +#ifdef CONFIG_XEN_COMPAT_030002
   21.17 +	.ascii	",ELF_PADDR_OFFSET=0x"
   21.18 +		utoa __PAGE_OFFSET
   21.19 +#else
   21.20 +	.ascii	",ELF_PADDR_OFFSET=0x0"
   21.21 +#endif /* !CONFIG_XEN_COMPAT_030002 */
   21.22 +	.ascii	",VIRT_ENTRY=0x"
   21.23 +		utoa (__PAGE_OFFSET + __PHYSICAL_START + VIRT_ENTRY_OFFSET)
   21.24  	.ascii	",HYPERCALL_PAGE=0x"
   21.25  		utoa ((__PHYSICAL_START+HYPERCALL_PAGE_OFFSET)>>PAGE_SHIFT)
   21.26  	.ascii  ",FEATURES=writable_page_tables"
    22.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/pci-dma-xen.c	Mon May 22 08:53:26 2006 -0600
    22.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/pci-dma-xen.c	Mon May 22 14:13:38 2006 -0600
    22.3 @@ -342,13 +342,3 @@ dma_sync_single_for_device(struct device
    22.4  		swiotlb_sync_single_for_device(dev, dma_handle, size, direction);
    22.5  }
    22.6  EXPORT_SYMBOL(dma_sync_single_for_device);
    22.7 -
    22.8 -/*
    22.9 - * Local variables:
   22.10 - *  c-file-style: "linux"
   22.11 - *  indent-tabs-mode: t
   22.12 - *  c-indent-level: 8
   22.13 - *  c-basic-offset: 8
   22.14 - *  tab-width: 8
   22.15 - * End:
   22.16 - */
    23.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c	Mon May 22 08:53:26 2006 -0600
    23.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c	Mon May 22 14:13:38 2006 -0600
    23.3 @@ -71,9 +71,6 @@
    23.4  /* Forward Declaration. */
    23.5  void __init find_max_pfn(void);
    23.6  
    23.7 -/* Allows setting of maximum possible memory size  */
    23.8 -static unsigned long xen_override_max_pfn;
    23.9 -
   23.10  static int xen_panic_event(struct notifier_block *, unsigned long, void *);
   23.11  static struct notifier_block xen_panic_block = {
   23.12  	xen_panic_event, NULL, 0 /* try to go last */
   23.13 @@ -399,6 +396,26 @@ EXPORT_SYMBOL(phys_to_machine_mapping);
   23.14  start_info_t *xen_start_info;
   23.15  EXPORT_SYMBOL(xen_start_info);
   23.16  
   23.17 +static void __init add_memory_region(unsigned long long start,
   23.18 +                                  unsigned long long size, int type)
   23.19 +{
   23.20 +	int x;
   23.21 +
   23.22 +	if (!efi_enabled) {
   23.23 +       		x = e820.nr_map;
   23.24 +
   23.25 +		if (x == E820MAX) {
   23.26 +		    printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
   23.27 +		    return;
   23.28 +		}
   23.29 +
   23.30 +		e820.map[x].addr = start;
   23.31 +		e820.map[x].size = size;
   23.32 +		e820.map[x].type = type;
   23.33 +		e820.nr_map++;
   23.34 +	}
   23.35 +} /* add_memory_region */
   23.36 +
   23.37  static void __init limit_regions(unsigned long long size)
   23.38  {
   23.39  	unsigned long long current_addr = 0;
   23.40 @@ -442,28 +459,21 @@ static void __init limit_regions(unsigne
   23.41  		}
   23.42  		return;
   23.43  	}
   23.44 +#ifdef CONFIG_XEN
   23.45 +	if (i==e820.nr_map && current_addr < size) {
   23.46 +		/*
   23.47 +                 * The e820 map finished before our requested size so
   23.48 +                 * extend the final entry to the requested address.
   23.49 +                 */
   23.50 +		--i;
   23.51 +		if (e820.map[i].type == E820_RAM)
   23.52 +			e820.map[i].size -= current_addr - size;
   23.53 +		else
   23.54 +			add_memory_region(current_addr, size - current_addr, E820_RAM);
   23.55 +	}
   23.56 +#endif
   23.57  }
   23.58  
   23.59 -static void __init add_memory_region(unsigned long long start,
   23.60 -                                  unsigned long long size, int type)
   23.61 -{
   23.62 -	int x;
   23.63 -
   23.64 -	if (!efi_enabled) {
   23.65 -       		x = e820.nr_map;
   23.66 -
   23.67 -		if (x == E820MAX) {
   23.68 -		    printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
   23.69 -		    return;
   23.70 -		}
   23.71 -
   23.72 -		e820.map[x].addr = start;
   23.73 -		e820.map[x].size = size;
   23.74 -		e820.map[x].type = type;
   23.75 -		e820.nr_map++;
   23.76 -	}
   23.77 -} /* add_memory_region */
   23.78 -
   23.79  #define E820_DEBUG	1
   23.80  
   23.81  static void __init print_memory_map(char *who)
   23.82 @@ -492,7 +502,6 @@ static void __init print_memory_map(char
   23.83  	}
   23.84  }
   23.85  
   23.86 -#if 0
   23.87  /*
   23.88   * Sanitize the BIOS e820 map.
   23.89   *
   23.90 @@ -680,9 +689,13 @@ static int __init sanitize_e820_map(stru
   23.91   */
   23.92  static int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
   23.93  {
   23.94 +#ifndef CONFIG_XEN
   23.95  	/* Only one memory region (or negative)? Ignore it */
   23.96  	if (nr_map < 2)
   23.97  		return -1;
   23.98 +#else
   23.99 +	BUG_ON(nr_map < 1);
  23.100 +#endif
  23.101  
  23.102  	do {
  23.103  		unsigned long long start = biosmap->addr;
  23.104 @@ -694,6 +707,7 @@ static int __init copy_e820_map(struct e
  23.105  		if (start > end)
  23.106  			return -1;
  23.107  
  23.108 +#ifndef CONFIG_XEN
  23.109  		/*
  23.110  		 * Some BIOSes claim RAM in the 640k - 1M region.
  23.111  		 * Not right. Fix it up.
  23.112 @@ -708,11 +722,11 @@ static int __init copy_e820_map(struct e
  23.113  				size = end - start;
  23.114  			}
  23.115  		}
  23.116 +#endif
  23.117  		add_memory_region(start, size, type);
  23.118  	} while (biosmap++,--nr_map);
  23.119  	return 0;
  23.120  }
  23.121 -#endif
  23.122  
  23.123  #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  23.124  struct edd edd;
  23.125 @@ -785,13 +799,8 @@ static void __init parse_cmdline_early (
  23.126  				unsigned long long mem_size;
  23.127   
  23.128  				mem_size = memparse(from+4, &from);
  23.129 -#if 0
  23.130  				limit_regions(mem_size);
  23.131  				userdef=1;
  23.132 -#else
  23.133 -				xen_override_max_pfn =
  23.134 -					(unsigned long)(mem_size>>PAGE_SHIFT);
  23.135 -#endif
  23.136  			}
  23.137  		}
  23.138  
  23.139 @@ -984,7 +993,6 @@ static void __init parse_cmdline_early (
  23.140  	}
  23.141  }
  23.142  
  23.143 -#if 0 /* !XEN */
  23.144  /*
  23.145   * Callback for efi_memory_walk.
  23.146   */
  23.147 @@ -1036,21 +1044,6 @@ void __init find_max_pfn(void)
  23.148  		memory_present(0, start, end);
  23.149  	}
  23.150  }
  23.151 -#else
  23.152 -/* We don't use the fake e820 because we need to respond to user override. */
  23.153 -void __init find_max_pfn(void)
  23.154 -{
  23.155 -	if (xen_override_max_pfn == 0) {
  23.156 -		max_pfn = xen_start_info->nr_pages;
  23.157 -		/* Default 8MB slack (to balance backend allocations). */
  23.158 -		max_pfn += 8 << (20 - PAGE_SHIFT);
  23.159 -	} else if (xen_override_max_pfn > xen_start_info->nr_pages) {
  23.160 -		max_pfn = xen_override_max_pfn;
  23.161 -	} else {
  23.162 -		max_pfn = xen_start_info->nr_pages;
  23.163 -	}
  23.164 -}
  23.165 -#endif /* XEN */
  23.166  
  23.167  /*
  23.168   * Determine low and high memory ranges:
  23.169 @@ -1158,6 +1151,15 @@ static void __init register_bootmem_low_
  23.170  		 */
  23.171  		last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
  23.172  
  23.173 +#ifdef CONFIG_XEN
  23.174 +		/*
  23.175 +                 * Truncate to the number of actual pages currently
  23.176 +                 * present.
  23.177 +                 */
  23.178 +		if (last_pfn > xen_start_info->nr_pages)
  23.179 +			last_pfn = xen_start_info->nr_pages;
  23.180 +#endif
  23.181 +
  23.182  		if (last_pfn > max_low_pfn)
  23.183  			last_pfn = max_low_pfn;
  23.184  
  23.185 @@ -1351,83 +1353,33 @@ void __init remapped_pgdat_init(void)
  23.186   * and also for regions reported as reserved by the e820.
  23.187   */
  23.188  static void __init
  23.189 -legacy_init_iomem_resources(struct resource *code_resource, struct resource *data_resource)
  23.190 +legacy_init_iomem_resources(struct e820entry *e820, int nr_map,
  23.191 +			    struct resource *code_resource,
  23.192 +			    struct resource *data_resource)
  23.193  {
  23.194  	int i;
  23.195 -#ifdef CONFIG_XEN
  23.196 -	dom0_op_t op;
  23.197 -	struct dom0_memory_map_entry *map;
  23.198 -	unsigned long gapstart, gapsize;
  23.199 -	unsigned long long last;
  23.200 -#endif
  23.201  
  23.202 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST
  23.203 +#if defined(CONFIG_XEN_PRIVILEGED_GUEST) || !defined(CONFIG_XEN)
  23.204  	probe_roms();
  23.205  #endif
  23.206  
  23.207 -#ifdef CONFIG_XEN
  23.208 -	map = alloc_bootmem_low_pages(PAGE_SIZE);
  23.209 -	op.cmd = DOM0_PHYSICAL_MEMORY_MAP;
  23.210 -	set_xen_guest_handle(op.u.physical_memory_map.memory_map, map);
  23.211 -	op.u.physical_memory_map.max_map_entries =
  23.212 -		PAGE_SIZE / sizeof(struct dom0_memory_map_entry);
  23.213 -	BUG_ON(HYPERVISOR_dom0_op(&op));
  23.214 -
  23.215 -	last = 0x100000000ULL;
  23.216 -	gapstart = 0x10000000;
  23.217 -	gapsize = 0x400000;
  23.218 -
  23.219 -	for (i = op.u.physical_memory_map.nr_map_entries - 1; i >= 0; i--) {
  23.220 +	for (i = 0; i < nr_map; i++) {
  23.221  		struct resource *res;
  23.222 -
  23.223 -		if ((last > map[i].end) && ((last - map[i].end) > gapsize)) {
  23.224 -			gapsize = last - map[i].end;
  23.225 -			gapstart = map[i].end;
  23.226 -		}
  23.227 -		if (map[i].start < last)
  23.228 -			last = map[i].start;
  23.229 -
  23.230 -		if (map[i].end > 0x100000000ULL)
  23.231 +		if (e820[i].addr + e820[i].size > 0x100000000ULL)
  23.232  			continue;
  23.233  		res = alloc_bootmem_low(sizeof(struct resource));
  23.234 -		res->name = map[i].is_ram ? "System RAM" : "reserved";
  23.235 -		res->start = map[i].start;
  23.236 -		res->end = map[i].end - 1;
  23.237 -		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  23.238 -		request_resource(&iomem_resource, res);
  23.239 -	}
  23.240 -
  23.241 -	free_bootmem(__pa(map), PAGE_SIZE);
  23.242 -
  23.243 -	/*
  23.244 -	 * Start allocating dynamic PCI memory a bit into the gap,
  23.245 -	 * aligned up to the nearest megabyte.
  23.246 -	 *
  23.247 -	 * Question: should we try to pad it up a bit (do something
  23.248 -	 * like " + (gapsize >> 3)" in there too?). We now have the
  23.249 -	 * technology.
  23.250 -	 */
  23.251 -	pci_mem_start = (gapstart + 0xfffff) & ~0xfffff;
  23.252 -
  23.253 -	printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
  23.254 -		pci_mem_start, gapstart, gapsize);
  23.255 -#else
  23.256 -	for (i = 0; i < e820.nr_map; i++) {
  23.257 -		struct resource *res;
  23.258 -		if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
  23.259 -			continue;
  23.260 -		res = alloc_bootmem_low(sizeof(struct resource));
  23.261 -		switch (e820.map[i].type) {
  23.262 +		switch (e820[i].type) {
  23.263  		case E820_RAM:	res->name = "System RAM"; break;
  23.264  		case E820_ACPI:	res->name = "ACPI Tables"; break;
  23.265  		case E820_NVS:	res->name = "ACPI Non-volatile Storage"; break;
  23.266  		default:	res->name = "reserved";
  23.267  		}
  23.268 -		res->start = e820.map[i].addr;
  23.269 -		res->end = res->start + e820.map[i].size - 1;
  23.270 +		res->start = e820[i].addr;
  23.271 +		res->end = res->start + e820[i].size - 1;
  23.272  		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  23.273  		request_resource(&iomem_resource, res);
  23.274 -		if (e820.map[i].type == E820_RAM) {
  23.275 +#ifndef CONFIG_XEN
  23.276 +		if (e820[i].type == E820_RAM) {
  23.277  			/*
  23.278  			 *  We don't know which RAM region contains kernel data,
  23.279  			 *  so we try it repeatedly and let the resource manager
  23.280 @@ -1439,38 +1391,21 @@ legacy_init_iomem_resources(struct resou
  23.281  			request_resource(res, &crashk_res);
  23.282  #endif
  23.283  		}
  23.284 +#endif
  23.285  	}
  23.286 -#endif
  23.287  }
  23.288  
  23.289  /*
  23.290 - * Request address space for all standard resources
  23.291 + * Locate a unused range of the physical address space below 4G which
  23.292 + * can be used for PCI mappings.
  23.293   */
  23.294 -static void __init register_memory(void)
  23.295 +static void __init
  23.296 +e820_setup_gap(struct e820entry *e820, int nr_map)
  23.297  {
  23.298 -#ifndef CONFIG_XEN
  23.299  	unsigned long gapstart, gapsize, round;
  23.300  	unsigned long long last;
  23.301 -#endif
  23.302 -	int	      i;
  23.303 -
  23.304 -	/* Nothing to do if not running in dom0. */
  23.305 -	if (!(xen_start_info->flags & SIF_INITDOMAIN))
  23.306 -		return;
  23.307 +	int i;
  23.308  
  23.309 -	if (efi_enabled)
  23.310 -		efi_initialize_iomem_resources(&code_resource, &data_resource);
  23.311 -	else
  23.312 -		legacy_init_iomem_resources(&code_resource, &data_resource);
  23.313 -
  23.314 -	/* EFI systems may still have VGA */
  23.315 -	request_resource(&iomem_resource, &video_ram_resource);
  23.316 -
  23.317 -	/* request I/O space for devices used on all i[345]86 PCs */
  23.318 -	for (i = 0; i < STANDARD_IO_RESOURCES; i++)
  23.319 -		request_resource(&ioport_resource, &standard_io_resources[i]);
  23.320 -
  23.321 -#ifndef CONFIG_XEN
  23.322  	/*
  23.323  	 * Search for the bigest gap in the low 32 bits of the e820
  23.324  	 * memory space.
  23.325 @@ -1478,10 +1413,10 @@ static void __init register_memory(void)
  23.326  	last = 0x100000000ull;
  23.327  	gapstart = 0x10000000;
  23.328  	gapsize = 0x400000;
  23.329 -	i = e820.nr_map;
  23.330 +	i = nr_map;
  23.331  	while (--i >= 0) {
  23.332 -		unsigned long long start = e820.map[i].addr;
  23.333 -		unsigned long long end = start + e820.map[i].size;
  23.334 +		unsigned long long start = e820[i].addr;
  23.335 +		unsigned long long end = start + e820[i].size;
  23.336  
  23.337  		/*
  23.338  		 * Since "last" is at most 4GB, we know we'll
  23.339 @@ -1511,6 +1446,53 @@ static void __init register_memory(void)
  23.340  
  23.341  	printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
  23.342  		pci_mem_start, gapstart, gapsize);
  23.343 +}
  23.344 +
  23.345 +/*
  23.346 + * Request address space for all standard resources
  23.347 + */
  23.348 +static void __init register_memory(void)
  23.349 +{
  23.350 +#ifdef CONFIG_XEN
  23.351 +	struct e820entry *machine_e820;
  23.352 +	struct xen_memory_map memmap;
  23.353 +#endif
  23.354 +	int	      i;
  23.355 +
  23.356 +	/* Nothing to do if not running in dom0. */
  23.357 +	if (!(xen_start_info->flags & SIF_INITDOMAIN))
  23.358 +		return;
  23.359 +
  23.360 +#ifdef CONFIG_XEN
  23.361 +	machine_e820 = alloc_bootmem_low_pages(PAGE_SIZE);
  23.362 +
  23.363 +	memmap.nr_entries = E820MAX;
  23.364 +	set_xen_guest_handle(memmap.buffer, machine_e820);
  23.365 +
  23.366 +	BUG_ON(HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap));
  23.367 +
  23.368 +	legacy_init_iomem_resources(machine_e820, memmap.nr_entries,
  23.369 +				    &code_resource, &data_resource);
  23.370 +#else
  23.371 +	if (efi_enabled)
  23.372 +		efi_initialize_iomem_resources(&code_resource, &data_resource);
  23.373 +	else
  23.374 +		legacy_init_iomem_resources(e820.map, e820.nr_map,
  23.375 +					    &code_resource, &data_resource);
  23.376 +#endif
  23.377 +
  23.378 +	/* EFI systems may still have VGA */
  23.379 +	request_resource(&iomem_resource, &video_ram_resource);
  23.380 +
  23.381 +	/* request I/O space for devices used on all i[345]86 PCs */
  23.382 +	for (i = 0; i < STANDARD_IO_RESOURCES; i++)
  23.383 +		request_resource(&ioport_resource, &standard_io_resources[i]);
  23.384 +
  23.385 +#ifdef CONFIG_XEN
  23.386 +	e820_setup_gap(machine_e820, memmap.nr_entries);
  23.387 +	free_bootmem(__pa(machine_e820), PAGE_SIZE);
  23.388 +#else
  23.389 +	e820_setup_gap(e820.map, e820.nr_map);
  23.390  #endif
  23.391  }
  23.392  
    24.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c	Mon May 22 08:53:26 2006 -0600
    24.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c	Mon May 22 14:13:38 2006 -0600
    24.3 @@ -191,6 +191,7 @@ swiotlb_init(void)
    24.4  	if (swiotlb_force == 1) {
    24.5  		swiotlb = 1;
    24.6  	} else if ((swiotlb_force != -1) &&
    24.7 +		   is_running_on_xen() &&
    24.8  		   (xen_start_info->flags & SIF_INITDOMAIN)) {
    24.9  		/* Domain 0 always has a swiotlb. */
   24.10  		ram_end = HYPERVISOR_memory_op(XENMEM_maximum_ram_page, NULL);
   24.11 @@ -662,13 +663,3 @@ EXPORT_SYMBOL(swiotlb_map_page);
   24.12  EXPORT_SYMBOL(swiotlb_unmap_page);
   24.13  EXPORT_SYMBOL(swiotlb_dma_mapping_error);
   24.14  EXPORT_SYMBOL(swiotlb_dma_supported);
   24.15 -
   24.16 -/*
   24.17 - * Local variables:
   24.18 - *  c-file-style: "linux"
   24.19 - *  indent-tabs-mode: t
   24.20 - *  c-indent-level: 8
   24.21 - *  c-basic-offset: 8
   24.22 - *  tab-width: 8
   24.23 - * End:
   24.24 - */
    25.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c	Mon May 22 08:53:26 2006 -0600
    25.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c	Mon May 22 14:13:38 2006 -0600
    25.3 @@ -1085,13 +1085,3 @@ static int __init xen_sysctl_init(void)
    25.4  	return 0;
    25.5  }
    25.6  __initcall(xen_sysctl_init);
    25.7 -
    25.8 -/*
    25.9 - * Local variables:
   25.10 - *  c-file-style: "linux"
   25.11 - *  indent-tabs-mode: t
   25.12 - *  c-indent-level: 8
   25.13 - *  c-basic-offset: 8
   25.14 - *  tab-width: 8
   25.15 - * End:
   25.16 - */
    26.1 --- a/linux-2.6-xen-sparse/arch/i386/mm/hypervisor.c	Mon May 22 08:53:26 2006 -0600
    26.2 +++ b/linux-2.6-xen-sparse/arch/i386/mm/hypervisor.c	Mon May 22 14:13:38 2006 -0600
    26.3 @@ -412,13 +412,3 @@ int write_ldt_entry(void *ldt, int entry
    26.4  		mach_lp, (u64)entry_a | ((u64)entry_b<<32));
    26.5  }
    26.6  #endif
    26.7 -
    26.8 -/*
    26.9 - * Local variables:
   26.10 - *  c-file-style: "linux"
   26.11 - *  indent-tabs-mode: t
   26.12 - *  c-indent-level: 8
   26.13 - *  c-basic-offset: 8
   26.14 - *  tab-width: 8
   26.15 - * End:
   26.16 - */
    27.1 --- a/linux-2.6-xen-sparse/arch/i386/mm/init-xen.c	Mon May 22 08:53:26 2006 -0600
    27.2 +++ b/linux-2.6-xen-sparse/arch/i386/mm/init-xen.c	Mon May 22 14:13:38 2006 -0600
    27.3 @@ -228,6 +228,12 @@ static inline int page_kills_ppro(unsign
    27.4  	return 0;
    27.5  }
    27.6  
    27.7 +#else
    27.8 +
    27.9 +#define page_kills_ppro(p)	0
   27.10 +
   27.11 +#endif
   27.12 +
   27.13  extern int is_available_memory(efi_memory_desc_t *);
   27.14  
   27.15  int page_is_ram(unsigned long pagenr)
   27.16 @@ -269,13 +275,6 @@ int page_is_ram(unsigned long pagenr)
   27.17  	return 0;
   27.18  }
   27.19  
   27.20 -#else /* CONFIG_XEN */
   27.21 -
   27.22 -#define page_kills_ppro(p)	0
   27.23 -#define page_is_ram(p)		1
   27.24 -
   27.25 -#endif
   27.26 -
   27.27  #ifdef CONFIG_HIGHMEM
   27.28  pte_t *kmap_pte;
   27.29  pgprot_t kmap_prot;
    28.1 --- a/linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c	Mon May 22 08:53:26 2006 -0600
    28.2 +++ b/linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c	Mon May 22 14:13:38 2006 -0600
    28.3 @@ -478,13 +478,3 @@ void __init bt_iounmap(void *addr, unsig
    28.4  }
    28.5  
    28.6  #endif /* __i386__ */
    28.7 -
    28.8 -/*
    28.9 - * Local variables:
   28.10 - *  c-file-style: "linux"
   28.11 - *  indent-tabs-mode: t
   28.12 - *  c-indent-level: 8
   28.13 - *  c-basic-offset: 8
   28.14 - *  tab-width: 8
   28.15 - * End:
   28.16 - */
    29.1 --- a/linux-2.6-xen-sparse/arch/i386/mm/pgtable-xen.c	Mon May 22 08:53:26 2006 -0600
    29.2 +++ b/linux-2.6-xen-sparse/arch/i386/mm/pgtable-xen.c	Mon May 22 14:13:38 2006 -0600
    29.3 @@ -640,13 +640,3 @@ void _arch_exit_mmap(struct mm_struct *m
    29.4  	    (atomic_read(&mm->mm_count) == 1))
    29.5  		mm_unpin(mm);
    29.6  }
    29.7 -
    29.8 -/*
    29.9 - * Local variables:
   29.10 - *  c-file-style: "linux"
   29.11 - *  indent-tabs-mode: t
   29.12 - *  c-indent-level: 8
   29.13 - *  c-basic-offset: 8
   29.14 - *  tab-width: 8
   29.15 - * End:
   29.16 - */
    30.1 --- a/linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c	Mon May 22 08:53:26 2006 -0600
    30.2 +++ b/linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c	Mon May 22 14:13:38 2006 -0600
    30.3 @@ -141,56 +141,40 @@ xenoprof_ovf_interrupt(int irq, void * d
    30.4  }
    30.5  
    30.6  
    30.7 -static void unbind_virq_cpu(void * info)
    30.8 -{
    30.9 -	int cpu = smp_processor_id();
   30.10 -	if (ovf_irq[cpu] >= 0) {
   30.11 -		unbind_from_irqhandler(ovf_irq[cpu], NULL);
   30.12 -		ovf_irq[cpu] = -1;
   30.13 -	}
   30.14 -}
   30.15 -
   30.16 -
   30.17  static void unbind_virq(void)
   30.18  {
   30.19 -	on_each_cpu(unbind_virq_cpu, NULL, 0, 1);
   30.20 -}
   30.21 -
   30.22 -
   30.23 -int bind_virq_error;
   30.24 -
   30.25 -static void bind_virq_cpu(void * info)
   30.26 -{
   30.27 -	int result;
   30.28 -	int cpu = smp_processor_id();
   30.29 +	int i;
   30.30  
   30.31 -	result = bind_virq_to_irqhandler(VIRQ_XENOPROF,
   30.32 -					 cpu,
   30.33 -					 xenoprof_ovf_interrupt,
   30.34 -					 SA_INTERRUPT,
   30.35 -					 "xenoprof",
   30.36 -					 NULL);
   30.37 -
   30.38 -	if (result<0) {
   30.39 -		bind_virq_error = result;
   30.40 -		printk("xenoprof.c: binding VIRQ_XENOPROF to IRQ failed on CPU "
   30.41 -		       "%d\n", cpu);
   30.42 -	} else {
   30.43 -		ovf_irq[cpu] = result;
   30.44 +	for_each_cpu(i) {
   30.45 +		if (ovf_irq[i] >= 0) {
   30.46 +			unbind_from_irqhandler(ovf_irq[i], NULL);
   30.47 +			ovf_irq[i] = -1;
   30.48 +		}
   30.49  	}
   30.50  }
   30.51  
   30.52  
   30.53  static int bind_virq(void)
   30.54  {
   30.55 -	bind_virq_error = 0;
   30.56 -	on_each_cpu(bind_virq_cpu, NULL, 0, 1);
   30.57 -	if (bind_virq_error) {
   30.58 -		unbind_virq();
   30.59 -		return bind_virq_error;
   30.60 -	} else {
   30.61 -		return 0;
   30.62 +	int i, result;
   30.63 +
   30.64 +	for_each_cpu(i) {
   30.65 +		result = bind_virq_to_irqhandler(VIRQ_XENOPROF,
   30.66 +						 i,
   30.67 +						 xenoprof_ovf_interrupt,
   30.68 +						 SA_INTERRUPT,
   30.69 +						 "xenoprof",
   30.70 +						 NULL);
   30.71 +
   30.72 +		if (result < 0) {
   30.73 +			unbind_virq();
   30.74 +			return result;
   30.75 +		}
   30.76 +
   30.77 +		ovf_irq[i] = result;
   30.78  	}
   30.79 +		
   30.80 +	return 0;
   30.81  }
   30.82  
   30.83  
   30.84 @@ -305,9 +289,13 @@ static int xenoprof_set_active(int * act
   30.85  
   30.86  	for (i=0; i<adomains; i++) {
   30.87  		domid = active_domains[i];
   30.88 +		if (domid != active_domains[i]) {
   30.89 +			ret = -EINVAL;
   30.90 +			goto out;
   30.91 +		}
   30.92  		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_active, &domid);
   30.93  		if (ret)
   30.94 -			return (ret);
   30.95 +			goto out;
   30.96  		if (active_domains[i] == 0)
   30.97  			set_dom0 = 1;
   30.98  	}
   30.99 @@ -316,8 +304,11 @@ static int xenoprof_set_active(int * act
  30.100  		domid = 0;
  30.101  		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_active, &domid);
  30.102  	}
  30.103 -	
  30.104 -	active_defined = 1;
  30.105 +
  30.106 +out:
  30.107 +	if (ret)
  30.108 +		HYPERVISOR_xenoprof_op(XENOPROF_reset_active_list, NULL);
  30.109 +	active_defined = !ret;
  30.110  	return ret;
  30.111  }
  30.112  
    31.1 --- a/linux-2.6-xen-sparse/arch/ia64/kernel/setup.c	Mon May 22 08:53:26 2006 -0600
    31.2 +++ b/linux-2.6-xen-sparse/arch/ia64/kernel/setup.c	Mon May 22 14:13:38 2006 -0600
    31.3 @@ -514,6 +514,9 @@ setup_arch (char **cmdline_p)
    31.4  #ifdef CONFIG_XEN
    31.5  	if (running_on_xen) {
    31.6  		extern shared_info_t *HYPERVISOR_shared_info;
    31.7 +		extern int xen_init (void);
    31.8 +
    31.9 +		xen_init ();
   31.10  
   31.11  		/* xen_start_info isn't setup yet, get the flags manually */
   31.12  		if (HYPERVISOR_shared_info->arch.flags & SIF_INITDOMAIN) {
    32.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/Makefile	Mon May 22 08:53:26 2006 -0600
    32.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/Makefile	Mon May 22 14:13:38 2006 -0600
    32.3 @@ -2,7 +2,7 @@
    32.4  # Makefile for Xen components
    32.5  #
    32.6  
    32.7 -obj-y := hypercall.o xenivt.o xenentry.o xensetup.o xenpal.o xenhpski.o xenconsole.o xen_ksyms.o
    32.8 +obj-y := hypercall.o xenivt.o xenentry.o xensetup.o xenpal.o xenhpski.o xenconsole.o
    32.9  
   32.10  obj-$(CONFIG_XEN_IA64_DOM0_VP) += hypervisor.o pci-dma-xen.o util.o
   32.11 -pci-dma-xen-$(CONFIG_XEN_IA64_DOM0_VP) := ../../i386/kernel/pci-dma-xen.o
   32.12 \ No newline at end of file
   32.13 +pci-dma-xen-$(CONFIG_XEN_IA64_DOM0_VP) := ../../i386/kernel/pci-dma-xen.o
    33.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/drivers/xenia64_init.c	Mon May 22 08:53:26 2006 -0600
    33.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/drivers/xenia64_init.c	Mon May 22 14:13:38 2006 -0600
    33.3 @@ -11,17 +11,20 @@
    33.4  shared_info_t *HYPERVISOR_shared_info = (shared_info_t *)XSI_BASE;
    33.5  EXPORT_SYMBOL(HYPERVISOR_shared_info);
    33.6  
    33.7 -static int initialized;
    33.8  start_info_t *xen_start_info;
    33.9  
   33.10 +int running_on_xen;
   33.11 +EXPORT_SYMBOL(running_on_xen);
   33.12 +
   33.13  int xen_init(void)
   33.14  {
   33.15 +	static int initialized;
   33.16  	shared_info_t *s = HYPERVISOR_shared_info;
   33.17  
   33.18  	if (initialized)
   33.19  		return running_on_xen ? 0 : -1;
   33.20  
   33.21 -	if (!running_on_xen)
   33.22 +	if (!is_running_on_xen())
   33.23  		return -1;
   33.24  
   33.25  	xen_start_info = __va(s->arch.start_info_pfn << PAGE_SHIFT);
    34.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/xen_ksyms.c	Mon May 22 08:53:26 2006 -0600
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,12 +0,0 @@
    34.4 -/*
    34.5 - * Architecture-specific kernel symbols
    34.6 - *
    34.7 - * Don't put any exports here unless it's defined in an assembler file.
    34.8 - * All other exports should be put directly after the definition.
    34.9 - */
   34.10 -
   34.11 -#include <linux/config.h>
   34.12 -#include <linux/module.h>
   34.13 -
   34.14 -extern int is_running_on_xen(void);
   34.15 -EXPORT_SYMBOL(is_running_on_xen);
    35.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/xensetup.S	Mon May 22 08:53:26 2006 -0600
    35.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/xensetup.S	Mon May 22 14:13:38 2006 -0600
    35.3 @@ -8,12 +8,6 @@
    35.4  #include <asm/processor.h>
    35.5  #include <asm/asmmacro.h>
    35.6  
    35.7 -	.data
    35.8 -	.align 8
    35.9 -	.globl running_on_xen
   35.10 -running_on_xen:
   35.11 -	data4 0
   35.12 -
   35.13  #define isBP	p3	// are we the Bootstrap Processor?
   35.14  
   35.15  	.text
   35.16 @@ -28,9 +22,3 @@ GLOBAL_ENTRY(early_xen_setup)
   35.17  (p7)	mov cr.iva=r10
   35.18  	br.ret.sptk.many rp;;
   35.19  END(early_xen_setup)
   35.20 -
   35.21 -GLOBAL_ENTRY(is_running_on_xen)
   35.22 -	movl r9=running_on_xen;;
   35.23 -	ld4 r8=[r9]
   35.24 -	br.ret.sptk.many rp;;
   35.25 -END(is_running_on_xen)
    36.1 --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/e820-xen.c	Mon May 22 08:53:26 2006 -0600
    36.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/e820-xen.c	Mon May 22 14:13:38 2006 -0600
    36.3 @@ -26,53 +26,34 @@
    36.4  #include <asm/sections.h>
    36.5  #include <xen/interface/memory.h>
    36.6  
    36.7 -unsigned long pci_mem_start = 0xaeedbabe;
    36.8 -
    36.9  /* 
   36.10   * PFN of last memory page.
   36.11   */
   36.12  unsigned long end_pfn; 
   36.13  EXPORT_SYMBOL(end_pfn);
   36.14 -unsigned long end_user_pfn = MAXMEM>>PAGE_SHIFT;  
   36.15 -unsigned long end_pfn_map; 
   36.16 -
   36.17 -/* 
   36.18 - * Add a memory region to the kernel e820 map.
   36.19 - */ 
   36.20 -void __init add_memory_region(unsigned long start, unsigned long size, int type)
   36.21 -{
   36.22 -	int x = e820.nr_map;
   36.23 -
   36.24 -	if (x == E820MAX) {
   36.25 -		printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
   36.26 -		return;
   36.27 -	}
   36.28 -
   36.29 -	e820.map[x].addr = start;
   36.30 -	e820.map[x].size = size;
   36.31 -	e820.map[x].type = type;
   36.32 -	e820.nr_map++;
   36.33 -}
   36.34 -
   36.35 -#ifndef CONFIG_XEN
   36.36  
   36.37  /* 
   36.38   * end_pfn only includes RAM, while end_pfn_map includes all e820 entries.
   36.39   * The direct mapping extends to end_pfn_map, so that we can directly access
   36.40   * apertures, ACPI and other tables without having to play with fixmaps.
   36.41   */ 
   36.42 +unsigned long end_pfn_map; 
   36.43  
   36.44  /* 
   36.45   * Last pfn which the user wants to use.
   36.46   */
   36.47 +unsigned long end_user_pfn = MAXMEM>>PAGE_SHIFT;  
   36.48  
   36.49 +#ifndef CONFIG_XEN
   36.50  extern struct resource code_resource, data_resource;
   36.51 +#endif
   36.52  
   36.53  /* Check for some hardcoded bad areas that early boot is not allowed to touch */ 
   36.54  static inline int bad_addr(unsigned long *addrp, unsigned long size)
   36.55  { 
   36.56  	unsigned long addr = *addrp, last = addr + size; 
   36.57  
   36.58 +#ifndef CONFIG_XEN
   36.59  	/* various gunk below that needed for SMP startup */
   36.60  	if (addr < 0x8000) { 
   36.61  		*addrp = 0x8000;
   36.62 @@ -100,9 +81,16 @@ static inline int bad_addr(unsigned long
   36.63  		return 1;
   36.64  	}
   36.65  	/* XXX ramdisk image here? */ 
   36.66 +#else
   36.67 +	if (last < (table_end<<PAGE_SHIFT)) {
   36.68 +		*addrp = table_end << PAGE_SHIFT;
   36.69 +		return 1;
   36.70 +	}
   36.71 +#endif
   36.72  	return 0;
   36.73  } 
   36.74  
   36.75 +#ifndef CONFIG_XEN
   36.76  int __init e820_mapped(unsigned long start, unsigned long end, unsigned type) 
   36.77  { 
   36.78  	int i;
   36.79 @@ -116,6 +104,7 @@ int __init e820_mapped(unsigned long sta
   36.80  	} 
   36.81  	return 0;
   36.82  }
   36.83 +#endif
   36.84  
   36.85  /* 
   36.86   * Find a free area in a specific range. 
   36.87 @@ -246,22 +235,23 @@ e820_hole_size(unsigned long start_pfn, 
   36.88  /*
   36.89   * Mark e820 reserved areas as busy for the resource manager.
   36.90   */
   36.91 -void __init e820_reserve_resources(void)
   36.92 +void __init e820_reserve_resources(struct e820entry *e820, int nr_map)
   36.93  {
   36.94  	int i;
   36.95 -	for (i = 0; i < e820.nr_map; i++) {
   36.96 +	for (i = 0; i < nr_map; i++) {
   36.97  		struct resource *res;
   36.98  		res = alloc_bootmem_low(sizeof(struct resource));
   36.99 -		switch (e820.map[i].type) {
  36.100 +		switch (e820[i].type) {
  36.101  		case E820_RAM:	res->name = "System RAM"; break;
  36.102  		case E820_ACPI:	res->name = "ACPI Tables"; break;
  36.103  		case E820_NVS:	res->name = "ACPI Non-volatile Storage"; break;
  36.104  		default:	res->name = "reserved";
  36.105  		}
  36.106 -		res->start = e820.map[i].addr;
  36.107 -		res->end = res->start + e820.map[i].size - 1;
  36.108 +		res->start = e820[i].addr;
  36.109 +		res->end = res->start + e820[i].size - 1;
  36.110  		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  36.111  		request_resource(&iomem_resource, res);
  36.112 +#ifndef CONFIG_XEN
  36.113  		if (e820.map[i].type == E820_RAM) {
  36.114  			/*
  36.115  			 *  We don't know which RAM region contains kernel data,
  36.116 @@ -274,9 +264,27 @@ void __init e820_reserve_resources(void)
  36.117  			request_resource(res, &crashk_res);
  36.118  #endif
  36.119  		}
  36.120 +#endif
  36.121  	}
  36.122  }
  36.123 -#endif /* CONFIG_XEN */
  36.124 +
  36.125 +/* 
  36.126 + * Add a memory region to the kernel e820 map.
  36.127 + */ 
  36.128 +void __init add_memory_region(unsigned long start, unsigned long size, int type)
  36.129 +{
  36.130 +	int x = e820.nr_map;
  36.131 +
  36.132 +	if (x == E820MAX) {
  36.133 +		printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
  36.134 +		return;
  36.135 +	}
  36.136 +
  36.137 +	e820.map[x].addr = start;
  36.138 +	e820.map[x].size = size;
  36.139 +	e820.map[x].type = type;
  36.140 +	e820.nr_map++;
  36.141 +}
  36.142  
  36.143  void __init e820_print_map(char *who)
  36.144  {
  36.145 @@ -304,7 +312,6 @@ void __init e820_print_map(char *who)
  36.146  	}
  36.147  }
  36.148  
  36.149 -#ifndef CONFIG_XEN
  36.150  /*
  36.151   * Sanitize the BIOS e820 map.
  36.152   *
  36.153 @@ -491,9 +498,13 @@ static int __init sanitize_e820_map(stru
  36.154   */
  36.155  static int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
  36.156  {
  36.157 +#ifndef CONFIG_XEN
  36.158  	/* Only one memory region (or negative)? Ignore it */
  36.159  	if (nr_map < 2)
  36.160  		return -1;
  36.161 +#else
  36.162 +	BUG_ON(nr_map < 1);
  36.163 +#endif
  36.164  
  36.165  	do {
  36.166  		unsigned long start = biosmap->addr;
  36.167 @@ -505,6 +516,7 @@ static int __init copy_e820_map(struct e
  36.168  		if (start > end)
  36.169  			return -1;
  36.170  
  36.171 +#ifndef CONFIG_XEN
  36.172  		/*
  36.173  		 * Some BIOSes claim RAM in the 640k - 1M region.
  36.174  		 * Not right. Fix it up.
  36.175 @@ -523,12 +535,14 @@ static int __init copy_e820_map(struct e
  36.176  				size = end - start;
  36.177  			}
  36.178  		}
  36.179 +#endif
  36.180  
  36.181  		add_memory_region(start, size, type);
  36.182  	} while (biosmap++,--nr_map);
  36.183  	return 0;
  36.184  }
  36.185  
  36.186 +#ifndef CONFIG_XEN
  36.187  void __init setup_memory_region(void)
  36.188  {
  36.189  	char *who = "BIOS-e820";
  36.190 @@ -562,104 +576,63 @@ void __init setup_memory_region(void)
  36.191  
  36.192  #else  /* CONFIG_XEN */
  36.193  
  36.194 -extern unsigned long xen_override_max_pfn;
  36.195 -extern union xen_start_info_union xen_start_info_union;
  36.196 -
  36.197 -unsigned long __init e820_end_of_ram(void)
  36.198 +void __init setup_memory_region(void)
  36.199  {
  36.200 -	unsigned long max_end_pfn;
  36.201 -
  36.202 -	if (xen_override_max_pfn == 0) {
  36.203 -		max_end_pfn = xen_start_info->nr_pages;
  36.204 -		/* Default 8MB slack (to balance backend allocations). */
  36.205 -		max_end_pfn += 8 << (20 - PAGE_SHIFT);
  36.206 -	} else if (xen_override_max_pfn > xen_start_info->nr_pages) {
  36.207 -		max_end_pfn = xen_override_max_pfn;
  36.208 -	} else {
  36.209 -		max_end_pfn = xen_start_info->nr_pages;
  36.210 -	}
  36.211 -
  36.212 -	return max_end_pfn;
  36.213 -}
  36.214 +	int rc;
  36.215 +	struct xen_memory_map memmap;
  36.216 +	/*
  36.217 +	 * This is rather large for a stack variable but this early in
  36.218 +	 * the boot process we know we have plenty slack space.
  36.219 +	 */
  36.220 +	struct e820entry map[E820MAX];
  36.221  
  36.222 -unsigned long __init
  36.223 -e820_hole_size(unsigned long start_pfn, unsigned long end_pfn)
  36.224 -{
  36.225 -	return 0;
  36.226 -}
  36.227 -
  36.228 -void __init e820_reserve_resources(void) 
  36.229 -{
  36.230 -	dom0_op_t op;
  36.231 -	struct dom0_memory_map_entry *map;
  36.232 -	unsigned long gapstart, gapsize, round, last;
  36.233 -	int i, found = 0;
  36.234 -
  36.235 -	if (!(xen_start_info->flags & SIF_INITDOMAIN))
  36.236 -		return;
  36.237 -
  36.238 -	map = alloc_bootmem_low_pages(PAGE_SIZE);
  36.239 -	op.cmd = DOM0_PHYSICAL_MEMORY_MAP;
  36.240 -	set_xen_guest_handle(op.u.physical_memory_map.memory_map, map);
  36.241 -	op.u.physical_memory_map.max_map_entries =
  36.242 -		PAGE_SIZE / sizeof(struct dom0_memory_map_entry);
  36.243 -	BUG_ON(HYPERVISOR_dom0_op(&op));
  36.244 +	memmap.nr_entries = E820MAX;
  36.245 +	set_xen_guest_handle(memmap.buffer, map);
  36.246  
  36.247 -	last = 0x100000000ULL;
  36.248 -	gapstart = 0x10000000;
  36.249 -	gapsize = 0x400000;
  36.250 -
  36.251 -	for (i = op.u.physical_memory_map.nr_map_entries - 1; i >= 0; i--) {
  36.252 -		struct resource *res;
  36.253 -
  36.254 -		if ((last > map[i].end) && ((last - map[i].end) > gapsize)) {
  36.255 -			gapsize = last - map[i].end;
  36.256 -			gapstart = map[i].end;
  36.257 -			found = 1;
  36.258 -		}
  36.259 -		if (map[i].start < last)
  36.260 -			last = map[i].start;
  36.261 -
  36.262 -		if (map[i].end > 0x100000000ULL)
  36.263 -			continue;
  36.264 -		res = alloc_bootmem_low(sizeof(struct resource));
  36.265 -		res->name = map[i].is_ram ? "System RAM" : "reserved";
  36.266 -		res->start = map[i].start;
  36.267 -		res->end = map[i].end - 1;
  36.268 -		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  36.269 -		request_resource(&iomem_resource, res);
  36.270 +	rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
  36.271 +	if ( rc == -ENOSYS ) {
  36.272 +		memmap.nr_entries = 1;
  36.273 +		map[0].addr = 0ULL;
  36.274 +		map[0].size = xen_start_info->nr_pages << PAGE_SHIFT;
  36.275 +		/* 8MB slack (to balance backend allocations). */
  36.276 +		map[0].size += 8 << 20;
  36.277 +		map[0].type = E820_RAM;
  36.278 +		rc = 0;
  36.279  	}
  36.280 -
  36.281 -	free_bootmem(__pa(map), PAGE_SIZE);
  36.282 +	BUG_ON(rc);
  36.283  
  36.284 -	if (!found) {
  36.285 -		gapstart = HYPERVISOR_memory_op(XENMEM_maximum_ram_page, NULL);
  36.286 -		gapstart = (gapstart << PAGE_SHIFT) + 1024*1024;
  36.287 -		printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit address range\n"
  36.288 -		       KERN_ERR "PCI: Unassigned devices with 32bit resource registers may break!\n");
  36.289 -	}
  36.290 +	sanitize_e820_map(map, (char *)&memmap.nr_entries);
  36.291  
  36.292 -	/*
  36.293 -	 * See how much we want to round up: start off with
  36.294 -	 * rounding to the next 1MB area.
  36.295 -	 */
  36.296 -	round = 0x100000;
  36.297 -	while ((gapsize >> 4) > round)
  36.298 -		round += round;
  36.299 -	/* Fun with two's complement */
  36.300 -	pci_mem_start = (gapstart + round) & -round;
  36.301 +	BUG_ON(copy_e820_map(map, (char)memmap.nr_entries) < 0);
  36.302  
  36.303 -	printk(KERN_INFO "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
  36.304 -		pci_mem_start, gapstart, gapsize);
  36.305 +	printk(KERN_INFO "BIOS-provided physical RAM map:\n");
  36.306 +	e820_print_map("Xen");
  36.307  }
  36.308 -
  36.309  #endif
  36.310  
  36.311  void __init parse_memopt(char *p, char **from) 
  36.312  { 
  36.313 +	int i;
  36.314 +	unsigned long current_end;
  36.315 +	unsigned long end;
  36.316 +
  36.317  	end_user_pfn = memparse(p, from);
  36.318  	end_user_pfn >>= PAGE_SHIFT;	
  36.319 -	xen_override_max_pfn = (unsigned long) end_user_pfn;
  36.320 +
  36.321 +	end = end_user_pfn<<PAGE_SHIFT;
  36.322 +	i = e820.nr_map-1;
  36.323 +	current_end = e820.map[i].addr + e820.map[i].size;
  36.324 +
  36.325 +	if (current_end < end) {
  36.326 +		/*
  36.327 +                 * The e820 map ends before our requested size so
  36.328 +                 * extend the final entry to the requested address.
  36.329 +                 */
  36.330 +		if (e820.map[i].type == E820_RAM)
  36.331 +			e820.map[i].size = end - e820.map[i].addr;
  36.332 +		else
  36.333 +			add_memory_region(current_end, end - current_end, E820_RAM);
  36.334 +	}
  36.335  } 
  36.336  
  36.337  void __init parse_memmapopt(char *p, char **from)
  36.338 @@ -683,16 +656,17 @@ void __init parse_memmapopt(char *p, cha
  36.339  	p = *from;
  36.340  }
  36.341  
  36.342 +unsigned long pci_mem_start = 0xaeedbabe;
  36.343 +
  36.344  /*
  36.345   * Search for the biggest gap in the low 32 bits of the e820
  36.346   * memory space.  We pass this space to PCI to assign MMIO resources
  36.347   * for hotplug or unconfigured devices in.
  36.348   * Hopefully the BIOS let enough space left.
  36.349   */
  36.350 -__init void e820_setup_gap(void)
  36.351 +__init void e820_setup_gap(struct e820entry *e820, int nr_map)
  36.352  {
  36.353 -#ifndef CONFIG_XEN
  36.354 -	unsigned long gapstart, gapsize;
  36.355 +	unsigned long gapstart, gapsize, round;
  36.356  	unsigned long last;
  36.357  	int i;
  36.358  	int found = 0;
  36.359 @@ -700,10 +674,10 @@ void __init parse_memmapopt(char *p, cha
  36.360  	last = 0x100000000ull;
  36.361  	gapstart = 0x10000000;
  36.362  	gapsize = 0x400000;
  36.363 -	i = e820.nr_map;
  36.364 +	i = nr_map;
  36.365  	while (--i >= 0) {
  36.366 -		unsigned long long start = e820.map[i].addr;
  36.367 -		unsigned long long end = start + e820.map[i].size;
  36.368 +		unsigned long long start = e820[i].addr;
  36.369 +		unsigned long long end = start + e820[i].size;
  36.370  
  36.371  		/*
  36.372  		 * Since "last" is at most 4GB, we know we'll
  36.373 @@ -729,16 +703,15 @@ void __init parse_memmapopt(char *p, cha
  36.374  	}
  36.375  
  36.376  	/*
  36.377 -	 * Start allocating dynamic PCI memory a bit into the gap,
  36.378 -	 * aligned up to the nearest megabyte.
  36.379 -	 *
  36.380 -	 * Question: should we try to pad it up a bit (do something
  36.381 -	 * like " + (gapsize >> 3)" in there too?). We now have the
  36.382 -	 * technology.
  36.383 +	 * See how much we want to round up: start off with
  36.384 +	 * rounding to the next 1MB area.
  36.385  	 */
  36.386 -	pci_mem_start = (gapstart + 0xfffff) & ~0xfffff;
  36.387 +	round = 0x100000;
  36.388 +	while ((gapsize >> 4) > round)
  36.389 +		round += round;
  36.390 +	/* Fun with two's complement */
  36.391 +	pci_mem_start = (gapstart + round) & -round;
  36.392  
  36.393  	printk(KERN_INFO "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
  36.394  		pci_mem_start, gapstart, gapsize);
  36.395 -#endif
  36.396  }
    37.1 --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/head-xen.S	Mon May 22 08:53:26 2006 -0600
    37.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/head-xen.S	Mon May 22 14:13:38 2006 -0600
    37.3 @@ -24,6 +24,8 @@
    37.4  
    37.5  	.text
    37.6  	.code64
    37.7 +#define VIRT_ENTRY_OFFSET 0x0
    37.8 +.org VIRT_ENTRY_OFFSET
    37.9  	.globl startup_64
   37.10  startup_64:
   37.11  ENTRY(_start)
   37.12 @@ -146,8 +148,18 @@ gdt_end:
   37.13  .section __xen_guest
   37.14  	.ascii	"GUEST_OS=linux,GUEST_VER=2.6"
   37.15  	.ascii	",XEN_VER=xen-3.0"
   37.16 -	.ascii	",VIRT_BASE=0x"; utoh __START_KERNEL_map
   37.17 -	.ascii	",HYPERCALL_PAGE=0x"; utoh (phys_hypercall_page >> PAGE_SHIFT)
   37.18 +	.ascii	",VIRT_BASE=0x"
   37.19 +		utoh __START_KERNEL_map
   37.20 +#ifdef CONFIG_XEN_COMPAT_030002
   37.21 +	.ascii	",ELF_PADDR_OFFSET=0x"
   37.22 +		utoh __START_KERNEL_map
   37.23 +#else
   37.24 +	.ascii	",ELF_PADDR_OFFSET=0x0"
   37.25 +#endif /* !CONFIG_XEN_COMPAT_030002 */
   37.26 +	.ascii	",VIRT_ENTRY=0x"
   37.27 +		utoh (__START_KERNEL_map + __PHYSICAL_START + VIRT_ENTRY_OFFSET)
   37.28 +	.ascii	",HYPERCALL_PAGE=0x"
   37.29 +		utoh (phys_hypercall_page >> PAGE_SHIFT)
   37.30  	.ascii  ",FEATURES=writable_page_tables"
   37.31  	.ascii		 "|writable_descriptor_tables"
   37.32  	.ascii		 "|auto_translated_physmap"
    38.1 --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c	Mon May 22 08:53:26 2006 -0600
    38.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c	Mon May 22 14:13:38 2006 -0600
    38.3 @@ -76,8 +76,8 @@
    38.4  #include <xen/features.h>
    38.5  #define PFN_UP(x)       (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
    38.6  #define PFN_PHYS(x)     ((x) << PAGE_SHIFT)
    38.7 -#define end_pfn_map end_pfn
    38.8  #include <asm/mach-xen/setup_arch_post.h>
    38.9 +#include <xen/interface/memory.h>
   38.10  
   38.11  extern unsigned long start_pfn;
   38.12  extern struct edid_info edid_info;
   38.13 @@ -490,19 +490,6 @@ static __init void parse_cmdline_early (
   38.14  }
   38.15  
   38.16  #ifndef CONFIG_NUMA
   38.17 -#ifdef CONFIG_XEN
   38.18 -static void __init
   38.19 -contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
   38.20 -{
   38.21 -        unsigned long bootmap_size;
   38.22 -
   38.23 -        bootmap_size = init_bootmem(start_pfn, end_pfn);
   38.24 -        free_bootmem(0, xen_start_info->nr_pages << PAGE_SHIFT);   
   38.25 -        reserve_bootmem(HIGH_MEMORY,
   38.26 -                        (PFN_PHYS(start_pfn) + bootmap_size + PAGE_SIZE-1)
   38.27 -                        - HIGH_MEMORY);
   38.28 -}
   38.29 -#else
   38.30  static void __init
   38.31  contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
   38.32  {
   38.33 @@ -513,10 +500,13 @@ contig_initmem_init(unsigned long start_
   38.34  	if (bootmap == -1L)
   38.35  		panic("Cannot find bootmem map of size %ld\n",bootmap_size);
   38.36  	bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
   38.37 +#ifdef CONFIG_XEN
   38.38 +	e820_bootmem_free(NODE_DATA(0), 0, xen_start_info->nr_pages<<PAGE_SHIFT);
   38.39 +#else
   38.40  	e820_bootmem_free(NODE_DATA(0), 0, end_pfn << PAGE_SHIFT);
   38.41 +#endif
   38.42  	reserve_bootmem(bootmap, bootmap_size);
   38.43  } 
   38.44 -#endif	/* !CONFIG_XEN */
   38.45  #endif
   38.46  
   38.47  /* Use inline assembly to define this because the nops are defined 
   38.48 @@ -636,6 +626,11 @@ void __init setup_arch(char **cmdline_p)
   38.49  {
   38.50  	unsigned long kernel_end;
   38.51  
   38.52 +#if defined(CONFIG_XEN_PRIVILEGED_GUEST)
   38.53 +	struct e820entry *machine_e820;
   38.54 +	struct xen_memory_map memmap;
   38.55 +#endif
   38.56 +
   38.57  #ifdef CONFIG_XEN
   38.58  	/* Register a call for panic conditions. */
   38.59  	notifier_chain_register(&panic_notifier_list, &xen_panic_block);
   38.60 @@ -693,20 +688,18 @@ void __init setup_arch(char **cmdline_p)
   38.61  	rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
   38.62  	rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
   38.63  #endif
   38.64 +#endif	/* !CONFIG_XEN */
   38.65  	setup_memory_region();
   38.66  	copy_edd();
   38.67 -#endif	/* !CONFIG_XEN */
   38.68  
   38.69  	if (!MOUNT_ROOT_RDONLY)
   38.70  		root_mountflags &= ~MS_RDONLY;
   38.71  	init_mm.start_code = (unsigned long) &_text;
   38.72  	init_mm.end_code = (unsigned long) &_etext;
   38.73  	init_mm.end_data = (unsigned long) &_edata;
   38.74 -#ifdef CONFIG_XEN
   38.75 -	init_mm.brk = start_pfn << PAGE_SHIFT;
   38.76 -#else
   38.77 -	init_mm.brk = (unsigned long) &_end;	
   38.78 +	init_mm.brk = (unsigned long) &_end;
   38.79  
   38.80 +#ifndef CONFIG_XEN
   38.81  	code_resource.start = virt_to_phys(&_text);
   38.82  	code_resource.end = virt_to_phys(&_etext)-1;
   38.83  	data_resource.start = virt_to_phys(&_etext);
   38.84 @@ -735,12 +728,11 @@ void __init setup_arch(char **cmdline_p)
   38.85  #endif
   38.86  
   38.87  #ifdef CONFIG_NUMA
   38.88 -	numa_initmem_init(start_pfn, end_pfn); 
   38.89 +	numa_initmem_init(0, end_pfn); 
   38.90  #else
   38.91 -	contig_initmem_init(start_pfn, end_pfn);
   38.92 +	contig_initmem_init(0, end_pfn);
   38.93  #endif
   38.94  
   38.95 -#ifndef CONFIG_XEN
   38.96  	/* Reserve direct mapping */
   38.97  	reserve_bootmem_generic(table_start << PAGE_SHIFT, 
   38.98  				(table_end - table_start) << PAGE_SHIFT);
   38.99 @@ -749,6 +741,10 @@ void __init setup_arch(char **cmdline_p)
  38.100  	kernel_end = round_up(__pa_symbol(&_end),PAGE_SIZE);
  38.101  	reserve_bootmem_generic(HIGH_MEMORY, kernel_end - HIGH_MEMORY);
  38.102  
  38.103 +#ifdef CONFIG_XEN
  38.104 +	/* reserve physmap, start info and initial page tables */
  38.105 +	reserve_bootmem(kernel_end, (table_start<<PAGE_SHIFT)-kernel_end);
  38.106 +#else
  38.107  	/*
  38.108  	 * reserve physical page 0 - it's a special BIOS page on many boxes,
  38.109  	 * enabling clean reboots, SMP operation, laptop functions.
  38.110 @@ -933,13 +929,25 @@ void __init setup_arch(char **cmdline_p)
  38.111  	prefill_possible_map();
  38.112  #endif
  38.113  
  38.114 -#if defined(CONFIG_XEN_PRIVILEGED_GUEST) || !defined(CONFIG_XEN)
  38.115  	/*
  38.116  	 * Request address space for all standard RAM and ROM resources
  38.117  	 * and also for regions reported as reserved by the e820.
  38.118  	 */
  38.119 +#if defined(CONFIG_XEN_PRIVILEGED_GUEST)
  38.120  	probe_roms();
  38.121 -	e820_reserve_resources(); 
  38.122 +	if (xen_start_info->flags & SIF_INITDOMAIN) {
  38.123 +		machine_e820 = alloc_bootmem_low_pages(PAGE_SIZE);
  38.124 +
  38.125 +		memmap.nr_entries = E820MAX;
  38.126 +		set_xen_guest_handle(memmap.buffer, machine_e820);
  38.127 +
  38.128 +		BUG_ON(HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap));
  38.129 +
  38.130 +		e820_reserve_resources(machine_e820, memmap.nr_entries);
  38.131 +	}
  38.132 +#elif !defined(CONFIG_XEN)
  38.133 +	probe_roms();
  38.134 +	e820_reserve_resources(e820.map, e820.nr_map);
  38.135  #endif
  38.136  
  38.137  	request_resource(&iomem_resource, &video_ram_resource);
  38.138 @@ -951,7 +959,14 @@ void __init setup_arch(char **cmdline_p)
  38.139  		request_resource(&ioport_resource, &standard_io_resources[i]);
  38.140  	}
  38.141  
  38.142 -	e820_setup_gap();
  38.143 +#if defined(CONFIG_XEN_PRIVILEGED_GUEST)
  38.144 +	if (xen_start_info->flags & SIF_INITDOMAIN) {
  38.145 +		e820_setup_gap(machine_e820, memmap.nr_entries);
  38.146 +		free_bootmem(__pa(machine_e820), PAGE_SIZE);
  38.147 +	}
  38.148 +#elif !defined(CONFIG_XEN)
  38.149 +	e820_setup_gap(e820.map, e820.nr_map);
  38.150 +#endif
  38.151  
  38.152  #ifdef CONFIG_GART_IOMMU
  38.153  	iommu_hole_init();
    39.1 --- a/linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c	Mon May 22 08:53:26 2006 -0600
    39.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c	Mon May 22 14:13:38 2006 -0600
    39.3 @@ -370,7 +370,7 @@ void __set_fixmap_user (enum fixed_addre
    39.4  	set_pte_phys(address, phys, prot, SET_FIXMAP_USER); 
    39.5  }
    39.6  
    39.7 -unsigned long __initdata table_start, tables_space; 
    39.8 +unsigned long __initdata table_start, table_end; 
    39.9  
   39.10  unsigned long get_machine_pfn(unsigned long addr)
   39.11  {
   39.12 @@ -409,11 +409,17 @@ static inline int make_readonly(unsigned
   39.13  {
   39.14  	int readonly = 0;
   39.15  
   39.16 -	/* Make old and new page tables read-only. */
   39.17 +	/* Make new page tables read-only. */
   39.18 +	if (!xen_feature(XENFEAT_writable_page_tables)
   39.19 +	    && (paddr >= (table_start << PAGE_SHIFT))
   39.20 +	    && (paddr < (table_end << PAGE_SHIFT)))
   39.21 +		readonly = 1;
   39.22 +	/* Make old page tables read-only. */
   39.23  	if (!xen_feature(XENFEAT_writable_page_tables)
   39.24  	    && (paddr >= (xen_start_info->pt_base - __START_KERNEL_map))
   39.25 -	    && (paddr < ((table_start << PAGE_SHIFT) + tables_space)))
   39.26 +	    && (paddr < (start_pfn << PAGE_SHIFT)))
   39.27  		readonly = 1;
   39.28 +
   39.29  	/*
   39.30  	 * No need for writable mapping of kernel image. This also ensures that
   39.31  	 * page and descriptor tables embedded inside don't have writable
   39.32 @@ -544,7 +550,7 @@ void __init xen_init_pt(void)
   39.33  		mk_kernel_pgd(__pa_symbol(level3_user_pgt)));
   39.34  }
   39.35  
   39.36 -void __init extend_init_mapping(void) 
   39.37 +void __init extend_init_mapping(unsigned long tables_space)
   39.38  {
   39.39  	unsigned long va = __START_KERNEL_map;
   39.40  	unsigned long phys, addr, *pte_page;
   39.41 @@ -599,23 +605,23 @@ void __init extend_init_mapping(void)
   39.42  
   39.43  static void __init find_early_table_space(unsigned long end)
   39.44  {
   39.45 -	unsigned long puds, pmds, ptes; 
   39.46 +	unsigned long puds, pmds, ptes, tables; 
   39.47  
   39.48  	puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
   39.49  	pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT;
   39.50  	ptes = (end + PTE_SIZE - 1) >> PAGE_SHIFT;
   39.51  
   39.52 -	tables_space =
   39.53 -		round_up(puds * 8, PAGE_SIZE) + 
   39.54 +	tables = round_up(puds * 8, PAGE_SIZE) + 
   39.55  		round_up(pmds * 8, PAGE_SIZE) + 
   39.56  		round_up(ptes * 8, PAGE_SIZE); 
   39.57  
   39.58 -	extend_init_mapping();
   39.59 +	extend_init_mapping(tables);
   39.60  
   39.61  	table_start = start_pfn;
   39.62 +	table_end = table_start + (tables>>PAGE_SHIFT);
   39.63  
   39.64  	early_printk("kernel direct mapping tables up to %lx @ %lx-%lx\n",
   39.65 -		end, table_start << PAGE_SHIFT, start_pfn << PAGE_SHIFT);
   39.66 +		end, table_start << PAGE_SHIFT, table_end << PAGE_SHIFT);
   39.67  }
   39.68  
   39.69  /* Setup the direct mapping of the physical memory at PAGE_OFFSET.
   39.70 @@ -660,7 +666,7 @@ void __meminit init_memory_mapping(unsig
   39.71  			set_pgd(pgd_offset_k(start), mk_kernel_pgd(pud_phys));
   39.72  	}
   39.73  
   39.74 -	BUG_ON(!after_bootmem && start_pfn != table_start + (tables_space >> PAGE_SHIFT));
   39.75 +	BUG_ON(!after_bootmem && start_pfn != table_end);
   39.76  
   39.77  	__flush_tlb_all();
   39.78  }
   39.79 @@ -1089,13 +1095,3 @@ int in_gate_area_no_task(unsigned long a
   39.80  {
   39.81  	return (addr >= VSYSCALL_START) && (addr < VSYSCALL_END);
   39.82  }
   39.83 -
   39.84 -/*
   39.85 - * Local variables:
   39.86 - *  c-file-style: "linux"
   39.87 - *  indent-tabs-mode: t
   39.88 - *  c-indent-level: 8
   39.89 - *  c-basic-offset: 8
   39.90 - *  tab-width: 8
   39.91 - * End:
   39.92 - */
    40.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/Kconfig	Mon May 22 08:53:26 2006 -0600
    40.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/Kconfig	Mon May 22 14:13:38 2006 -0600
    40.3 @@ -53,10 +53,9 @@ config TCG_XEN
    40.4  	tristate "XEN TPM Interface"
    40.5  	depends on TCG_TPM && XEN
    40.6  	---help---
    40.7 -	  If you want to make TPM support available to a Xen
    40.8 -	  user domain, say Yes and it will
    40.9 -          be accessible from within Linux. To compile this driver
   40.10 -          as a module, choose M here; the module will be called
   40.11 -          tpm_xen.
   40.12 +	  If you want to make TPM support available to a Xen user domain,
   40.13 +	  say Yes and it will be accessible from within Linux.
   40.14 +	  To compile this driver as a module, choose M here; the module
   40.15 +	  will be called tpm_xenu.
   40.16  
   40.17  endmenu
    41.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/Makefile	Mon May 22 08:53:26 2006 -0600
    41.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/Makefile	Mon May 22 14:13:38 2006 -0600
    41.3 @@ -8,4 +8,5 @@ endif
    41.4  obj-$(CONFIG_TCG_NSC) += tpm_nsc.o
    41.5  obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o
    41.6  obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o
    41.7 -obj-$(CONFIG_TCG_XEN) += tpm_xen.o tpm_vtpm.o
    41.8 +obj-$(CONFIG_TCG_XEN) += tpm_xenu.o
    41.9 +tpm_xenu-y = tpm_xen.o tpm_vtpm.o
    42.1 --- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c	Mon May 22 08:53:26 2006 -0600
    42.2 +++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c	Mon May 22 14:13:38 2006 -0600
    42.3 @@ -416,7 +416,7 @@ static int tpmfront_suspend(struct xenbu
    42.4  		 */
    42.5  		interruptible_sleep_on_timeout(&tp->wait_q, 100);
    42.6  	}
    42.7 -	xenbus_switch_state(dev, XenbusStateClosed);
    42.8 +	xenbus_switch_state(dev, XenbusStateClosing);
    42.9  
   42.10  	if (atomic_read(&tp->tx_busy)) {
   42.11  		/*
   42.12 @@ -745,23 +745,12 @@ failexit:
   42.13  
   42.14  static void __exit tpmif_exit(void)
   42.15  {
   42.16 +	exit_tpm_xenbus();
   42.17  	cleanup_vtpm();
   42.18  	tpm_private_put();
   42.19 -	exit_tpm_xenbus();
   42.20  	gnttab_free_grant_references(gref_head);
   42.21  }
   42.22  
   42.23  module_init(tpmif_init);
   42.24 -module_exit(tpmif_exit);
   42.25  
   42.26  MODULE_LICENSE("Dual BSD/GPL");
   42.27 -
   42.28 -/*
   42.29 - * Local variables:
   42.30 - *  c-file-style: "linux"
   42.31 - *  indent-tabs-mode: t
   42.32 - *  c-indent-level: 8
   42.33 - *  c-basic-offset: 8
   42.34 - *  tab-width: 8
   42.35 - * End:
   42.36 - */
    43.1 --- a/linux-2.6-xen-sparse/drivers/xen/Kconfig	Mon May 22 08:53:26 2006 -0600
    43.2 +++ b/linux-2.6-xen-sparse/drivers/xen/Kconfig	Mon May 22 14:13:38 2006 -0600
    43.3 @@ -198,6 +198,22 @@ config XEN_SYSFS
    43.4  	help
    43.5  		Xen hypervisor attributes will show up under /sys/hypervisor/.
    43.6  
    43.7 +choice
    43.8 +	prompt "Xen version compatibility"
    43.9 +	default XEN_COMPAT_030002_AND_LATER
   43.10 +
   43.11 +	config XEN_COMPAT_030002_AND_LATER
   43.12 +		bool "3.0.2 and later"
   43.13 +
   43.14 +	config XEN_COMPAT_LATEST_ONLY
   43.15 +		bool "no compatibility code"
   43.16 +
   43.17 +endchoice
   43.18 +
   43.19 +config XEN_COMPAT_030002
   43.20 +	bool
   43.21 +	default XEN_COMPAT_030002_AND_LATER
   43.22 +
   43.23  endmenu
   43.24  
   43.25  config HAVE_ARCH_ALLOC_SKB
    44.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Mon May 22 08:53:26 2006 -0600
    44.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Mon May 22 14:13:38 2006 -0600
    44.3 @@ -468,8 +468,8 @@ static int __init balloon_init(void)
    44.4  
    44.5  	IPRINTK("Initialising balloon driver.\n");
    44.6  
    44.7 -	if (xen_init() < 0)
    44.8 -		return -1;
    44.9 +	if (!is_running_on_xen())
   44.10 +		return -ENODEV;
   44.11  
   44.12  	current_pages = min(xen_start_info->nr_pages, max_pfn);
   44.13  	totalram_pages = current_pages;
   44.14 @@ -603,13 +603,3 @@ EXPORT_SYMBOL_GPL(balloon_alloc_empty_pa
   44.15  EXPORT_SYMBOL_GPL(balloon_dealloc_empty_page_range);
   44.16  
   44.17  MODULE_LICENSE("Dual BSD/GPL");
   44.18 -
   44.19 -/*
   44.20 - * Local variables:
   44.21 - *  c-file-style: "linux"
   44.22 - *  indent-tabs-mode: t
   44.23 - *  c-indent-level: 8
   44.24 - *  c-basic-offset: 8
   44.25 - *  tab-width: 8
   44.26 - * End:
   44.27 - */
    45.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Mon May 22 08:53:26 2006 -0600
    45.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Mon May 22 14:13:38 2006 -0600
    45.3 @@ -526,7 +526,7 @@ static int __init blkif_init(void)
    45.4  	struct page *page;
    45.5  	int i;
    45.6  
    45.7 -	if (xen_init() < 0)
    45.8 +	if (!is_running_on_xen())
    45.9  		return -ENODEV;
   45.10  
   45.11  	mmap_pages            = blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST;
   45.12 @@ -571,27 +571,10 @@ static int __init blkif_init(void)
   45.13  		list_add_tail(&pending_reqs[i].free_list, &pending_free);
   45.14      
   45.15  	blkif_xenbus_init();
   45.16 -	__unsafe(THIS_MODULE);
   45.17 +
   45.18  	return 0;
   45.19  }
   45.20  
   45.21  module_init(blkif_init);
   45.22  
   45.23 -static void blkif_exit(void)
   45.24 -{
   45.25 -	BUG();
   45.26 -}
   45.27 -
   45.28 -module_exit(blkif_exit);
   45.29 -
   45.30  MODULE_LICENSE("Dual BSD/GPL");
   45.31 -
   45.32 -/*
   45.33 - * Local variables:
   45.34 - *  c-file-style: "linux"
   45.35 - *  indent-tabs-mode: t
   45.36 - *  c-indent-level: 8
   45.37 - *  c-basic-offset: 8
   45.38 - *  tab-width: 8
   45.39 - * End:
   45.40 - */
    46.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Mon May 22 08:53:26 2006 -0600
    46.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Mon May 22 14:13:38 2006 -0600
    46.3 @@ -34,6 +34,7 @@
    46.4  #include <linux/slab.h>
    46.5  #include <linux/blkdev.h>
    46.6  #include <linux/vmalloc.h>
    46.7 +#include <linux/wait.h>
    46.8  #include <asm/io.h>
    46.9  #include <asm/setup.h>
   46.10  #include <asm/pgalloc.h>
   46.11 @@ -90,21 +91,21 @@ typedef struct blkif_st {
   46.12  	int                 st_wr_req;
   46.13  	int                 st_oo_req;
   46.14  
   46.15 -	struct work_struct free_work;
   46.16 +	wait_queue_head_t waiting_to_free;
   46.17  
   46.18  	grant_handle_t shmem_handle;
   46.19  	grant_ref_t    shmem_ref;
   46.20  } blkif_t;
   46.21  
   46.22 -blkif_t *alloc_blkif(domid_t domid);
   46.23 -void free_blkif_callback(blkif_t *blkif);
   46.24 +blkif_t *blkif_alloc(domid_t domid);
   46.25 +void blkif_free(blkif_t *blkif);
   46.26  int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn);
   46.27  
   46.28  #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
   46.29  #define blkif_put(_b)					\
   46.30  	do {						\
   46.31  		if (atomic_dec_and_test(&(_b)->refcnt))	\
   46.32 -			free_blkif_callback(_b);	\
   46.33 +			wake_up(&(_b)->waiting_to_free);\
   46.34  	} while (0)
   46.35  
   46.36  /* Create a vbd. */
   46.37 @@ -133,13 +134,3 @@ irqreturn_t blkif_be_int(int irq, void *
   46.38  int blkif_schedule(void *arg);
   46.39  
   46.40  #endif /* __BLKIF__BACKEND__COMMON_H__ */
   46.41 -
   46.42 -/*
   46.43 - * Local variables:
   46.44 - *  c-file-style: "linux"
   46.45 - *  indent-tabs-mode: t
   46.46 - *  c-indent-level: 8
   46.47 - *  c-basic-offset: 8
   46.48 - *  tab-width: 8
   46.49 - * End:
   46.50 - */
    47.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Mon May 22 08:53:26 2006 -0600
    47.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Mon May 22 14:13:38 2006 -0600
    47.3 @@ -35,7 +35,7 @@
    47.4  
    47.5  static kmem_cache_t *blkif_cachep;
    47.6  
    47.7 -blkif_t *alloc_blkif(domid_t domid)
    47.8 +blkif_t *blkif_alloc(domid_t domid)
    47.9  {
   47.10  	blkif_t *blkif;
   47.11  
   47.12 @@ -49,6 +49,7 @@ blkif_t *alloc_blkif(domid_t domid)
   47.13  	atomic_set(&blkif->refcnt, 1);
   47.14  	init_waitqueue_head(&blkif->wq);
   47.15  	blkif->st_print = jiffies;
   47.16 +	init_waitqueue_head(&blkif->waiting_to_free);
   47.17  
   47.18  	return blkif;
   47.19  }
   47.20 @@ -138,45 +139,27 @@ int blkif_map(blkif_t *blkif, unsigned l
   47.21  	return 0;
   47.22  }
   47.23  
   47.24 -static void free_blkif(void *arg)
   47.25 +void blkif_free(blkif_t *blkif)
   47.26  {
   47.27 -	blkif_t *blkif = (blkif_t *)arg;
   47.28 +	atomic_dec(&blkif->refcnt);
   47.29 +	wait_event(blkif->waiting_to_free, atomic_read(&blkif->refcnt) == 0);
   47.30  
   47.31  	/* Already disconnected? */
   47.32 -	if (blkif->irq) {
   47.33 +	if (blkif->irq)
   47.34  		unbind_from_irqhandler(blkif->irq, blkif);
   47.35 -		blkif->irq = 0;
   47.36 -	}
   47.37  
   47.38  	vbd_free(&blkif->vbd);
   47.39  
   47.40  	if (blkif->blk_ring.sring) {
   47.41  		unmap_frontend_page(blkif);
   47.42  		free_vm_area(blkif->blk_ring_area);
   47.43 -		blkif->blk_ring.sring = NULL;
   47.44  	}
   47.45  
   47.46  	kmem_cache_free(blkif_cachep, blkif);
   47.47  }
   47.48  
   47.49 -void free_blkif_callback(blkif_t *blkif)
   47.50 -{
   47.51 -	INIT_WORK(&blkif->free_work, free_blkif, (void *)blkif);
   47.52 -	schedule_work(&blkif->free_work);
   47.53 -}
   47.54 -
   47.55  void __init blkif_interface_init(void)
   47.56  {
   47.57  	blkif_cachep = kmem_cache_create("blkif_cache", sizeof(blkif_t), 
   47.58  					 0, 0, NULL, NULL);
   47.59  }
   47.60 -
   47.61 -/*
   47.62 - * Local variables:
   47.63 - *  c-file-style: "linux"
   47.64 - *  indent-tabs-mode: t
   47.65 - *  c-indent-level: 8
   47.66 - *  c-basic-offset: 8
   47.67 - *  tab-width: 8
   47.68 - * End:
   47.69 - */
    48.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c	Mon May 22 08:53:26 2006 -0600
    48.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c	Mon May 22 14:13:38 2006 -0600
    48.3 @@ -55,6 +55,7 @@ int vbd_create(blkif_t *blkif, blkif_vde
    48.4  	       unsigned minor, int readonly)
    48.5  {
    48.6  	struct vbd *vbd;
    48.7 +	struct block_device *bdev;
    48.8  
    48.9  	vbd = &blkif->vbd;
   48.10  	vbd->handle   = handle; 
   48.11 @@ -63,15 +64,17 @@ int vbd_create(blkif_t *blkif, blkif_vde
   48.12  
   48.13  	vbd->pdevice  = MKDEV(major, minor);
   48.14  
   48.15 -	vbd->bdev = open_by_devnum(
   48.16 -		vbd->pdevice,
   48.17 -		vbd->readonly ? FMODE_READ : FMODE_WRITE);
   48.18 -	if (IS_ERR(vbd->bdev)) {
   48.19 -		DPRINTK("vbd_creat: device %08x doesn't exist.\n",
   48.20 +	bdev = open_by_devnum(vbd->pdevice,
   48.21 +			      vbd->readonly ? FMODE_READ : FMODE_WRITE);
   48.22 +
   48.23 +	if (IS_ERR(bdev)) {
   48.24 +		DPRINTK("vbd_creat: device %08x could not be opened.\n",
   48.25  			vbd->pdevice);
   48.26  		return -ENOENT;
   48.27  	}
   48.28  
   48.29 +	vbd->bdev = bdev;
   48.30 +
   48.31  	if (vbd->bdev->bd_disk == NULL) {
   48.32  		DPRINTK("vbd_creat: device %08x doesn't exist.\n",
   48.33  			vbd->pdevice);
   48.34 @@ -114,13 +117,3 @@ int vbd_translate(struct phys_req *req, 
   48.35   out:
   48.36  	return rc;
   48.37  }
   48.38 -
   48.39 -/*
   48.40 - * Local variables:
   48.41 - *  c-file-style: "linux"
   48.42 - *  indent-tabs-mode: t
   48.43 - *  c-indent-level: 8
   48.44 - *  c-basic-offset: 8
   48.45 - *  tab-width: 8
   48.46 - * End:
   48.47 - */
    49.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Mon May 22 08:53:26 2006 -0600
    49.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Mon May 22 14:13:38 2006 -0600
    49.3 @@ -108,7 +108,7 @@ static int blkback_remove(struct xenbus_
    49.4  	if (be->blkif) {
    49.5  		if (be->blkif->xenblkd)
    49.6  			kthread_stop(be->blkif->xenblkd);
    49.7 -		blkif_put(be->blkif);
    49.8 +		blkif_free(be->blkif);
    49.9  		be->blkif = NULL;
   49.10  	}
   49.11  
   49.12 @@ -140,7 +140,7 @@ static int blkback_probe(struct xenbus_d
   49.13  	be->dev = dev;
   49.14  	dev->data = be;
   49.15  
   49.16 -	be->blkif = alloc_blkif(dev->otherend_id);
   49.17 +	be->blkif = blkif_alloc(dev->otherend_id);
   49.18  	if (IS_ERR(be->blkif)) {
   49.19  		err = PTR_ERR(be->blkif);
   49.20  		be->blkif = NULL;
   49.21 @@ -408,14 +408,3 @@ void blkif_xenbus_init(void)
   49.22  {
   49.23  	xenbus_register_backend(&blkback);
   49.24  }
   49.25 -
   49.26 -
   49.27 -/*
   49.28 - * Local variables:
   49.29 - *  c-file-style: "linux"
   49.30 - *  indent-tabs-mode: t
   49.31 - *  c-indent-level: 8
   49.32 - *  c-basic-offset: 8
   49.33 - *  tab-width: 8
   49.34 - * End:
   49.35 - */
    50.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Mon May 22 08:53:26 2006 -0600
    50.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Mon May 22 14:13:38 2006 -0600
    50.3 @@ -792,7 +792,7 @@ static struct xenbus_driver blkfront = {
    50.4  
    50.5  static int __init xlblk_init(void)
    50.6  {
    50.7 -	if (xen_init() < 0)
    50.8 +	if (!is_running_on_xen())
    50.9  		return -ENODEV;
   50.10  
   50.11  	return xenbus_register_frontend(&blkfront);
   50.12 @@ -807,13 +807,3 @@ static void xlblk_exit(void)
   50.13  module_exit(xlblk_exit);
   50.14  
   50.15  MODULE_LICENSE("Dual BSD/GPL");
   50.16 -
   50.17 -/*
   50.18 - * Local variables:
   50.19 - *  c-file-style: "linux"
   50.20 - *  indent-tabs-mode: t
   50.21 - *  c-indent-level: 8
   50.22 - *  c-basic-offset: 8
   50.23 - *  tab-width: 8
   50.24 - * End:
   50.25 - */
    51.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h	Mon May 22 08:53:26 2006 -0600
    51.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h	Mon May 22 14:13:38 2006 -0600
    51.3 @@ -153,13 +153,3 @@ int xlvbd_add(blkif_sector_t capacity, i
    51.4  void xlvbd_del(struct blkfront_info *info);
    51.5  
    51.6  #endif /* __XEN_DRIVERS_BLOCK_H__ */
    51.7 -
    51.8 -/*
    51.9 - * Local variables:
   51.10 - *  c-file-style: "linux"
   51.11 - *  indent-tabs-mode: t
   51.12 - *  c-indent-level: 8
   51.13 - *  c-basic-offset: 8
   51.14 - *  tab-width: 8
   51.15 - * End:
   51.16 - */
    52.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c	Mon May 22 08:53:26 2006 -0600
    52.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c	Mon May 22 14:13:38 2006 -0600
    52.3 @@ -315,13 +315,3 @@ xlvbd_del(struct blkfront_info *info)
    52.4  	blk_cleanup_queue(info->rq);
    52.5  	info->rq = NULL;
    52.6  }
    52.7 -
    52.8 -/*
    52.9 - * Local variables:
   52.10 - *  c-file-style: "linux"
   52.11 - *  indent-tabs-mode: t
   52.12 - *  c-indent-level: 8
   52.13 - *  c-basic-offset: 8
   52.14 - *  tab-width: 8
   52.15 - * End:
   52.16 - */
    53.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Mon May 22 08:53:26 2006 -0600
    53.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Mon May 22 14:13:38 2006 -0600
    53.3 @@ -898,13 +898,3 @@ static int __init blkif_init(void)
    53.4  }
    53.5  
    53.6  __initcall(blkif_init);
    53.7 -
    53.8 -/*
    53.9 - * Local variables:
   53.10 - *  c-file-style: "linux"
   53.11 - *  indent-tabs-mode: t
   53.12 - *  c-indent-level: 8
   53.13 - *  c-basic-offset: 8
   53.14 - *  tab-width: 8
   53.15 - * End:
   53.16 - */
    54.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Mon May 22 08:53:26 2006 -0600
    54.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Mon May 22 14:13:38 2006 -0600
    54.3 @@ -98,13 +98,3 @@ void blkif_xenbus_init(void);
    54.4  irqreturn_t blkif_be_int(int irq, void *dev_id, struct pt_regs *regs);
    54.5  
    54.6  #endif /* __BLKIF__BACKEND__COMMON_H__ */
    54.7 -
    54.8 -/*
    54.9 - * Local variables:
   54.10 - *  c-file-style: "linux"
   54.11 - *  indent-tabs-mode: t
   54.12 - *  c-indent-level: 8
   54.13 - *  c-basic-offset: 8
   54.14 - *  tab-width: 8
   54.15 - * End:
   54.16 - */
    55.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Mon May 22 08:53:26 2006 -0600
    55.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Mon May 22 14:13:38 2006 -0600
    55.3 @@ -132,13 +132,3 @@ void __init blkif_interface_init(void)
    55.4  	blkif_cachep = kmem_cache_create(
    55.5  		"blkif_cache", sizeof(blkif_t), 0, 0, NULL, NULL);
    55.6  }
    55.7 -
    55.8 -/*
    55.9 - * Local variables:
   55.10 - *  c-file-style: "linux"
   55.11 - *  indent-tabs-mode: t
   55.12 - *  c-indent-level: 8
   55.13 - *  c-basic-offset: 8
   55.14 - *  tab-width: 8
   55.15 - * End:
   55.16 - */
    56.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Mon May 22 08:53:26 2006 -0600
    56.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Mon May 22 14:13:38 2006 -0600
    56.3 @@ -221,13 +221,3 @@ void blkif_xenbus_init(void)
    56.4  {
    56.5  	xenbus_register_backend(&blkback);
    56.6  }
    56.7 -
    56.8 -/*
    56.9 - * Local variables:
   56.10 - *  c-file-style: "linux"
   56.11 - *  indent-tabs-mode: t
   56.12 - *  c-indent-level: 8
   56.13 - *  c-basic-offset: 8
   56.14 - *  tab-width: 8
   56.15 - * End:
   56.16 - */
    57.1 --- a/linux-2.6-xen-sparse/drivers/xen/char/mem.c	Mon May 22 08:53:26 2006 -0600
    57.2 +++ b/linux-2.6-xen-sparse/drivers/xen/char/mem.c	Mon May 22 14:13:38 2006 -0600
    57.3 @@ -180,13 +180,3 @@ struct file_operations mem_fops = {
    57.4  	.mmap		= mmap_mem,
    57.5  	.open		= open_mem,
    57.6  };
    57.7 -
    57.8 -/*
    57.9 - * Local variables:
   57.10 - *  c-file-style: "linux"
   57.11 - *  indent-tabs-mode: t
   57.12 - *  c-indent-level: 8
   57.13 - *  c-basic-offset: 8
   57.14 - *  tab-width: 8
   57.15 - * End:
   57.16 - */
    58.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/console.c	Mon May 22 08:53:26 2006 -0600
    58.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/console.c	Mon May 22 14:13:38 2006 -0600
    58.3 @@ -183,7 +183,7 @@ static struct console kcons_info = {
    58.4  #define __RETCODE 0
    58.5  static int __init xen_console_init(void)
    58.6  {
    58.7 -	if (xen_init() < 0)
    58.8 +	if (!is_running_on_xen())
    58.9  		return __RETCODE;
   58.10  
   58.11  	if (xen_start_info->flags & SIF_INITDOMAIN) {
   58.12 @@ -566,7 +566,7 @@ static int __init xencons_init(void)
   58.13  {
   58.14  	int rc;
   58.15  
   58.16 -	if (xen_init() < 0)
   58.17 +	if (!is_running_on_xen())
   58.18  		return -ENODEV;
   58.19  
   58.20  	if (xc_mode == XC_OFF)
   58.21 @@ -636,13 +636,3 @@ static int __init xencons_init(void)
   58.22  module_init(xencons_init);
   58.23  
   58.24  MODULE_LICENSE("Dual BSD/GPL");
   58.25 -
   58.26 -/*
   58.27 - * Local variables:
   58.28 - *  c-file-style: "linux"
   58.29 - *  indent-tabs-mode: t
   58.30 - *  c-indent-level: 8
   58.31 - *  c-basic-offset: 8
   58.32 - *  tab-width: 8
   58.33 - * End:
   58.34 - */
    59.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Mon May 22 08:53:26 2006 -0600
    59.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Mon May 22 14:13:38 2006 -0600
    59.3 @@ -139,13 +139,3 @@ void xencons_resume(void)
    59.4  {
    59.5  	(void)xencons_ring_init();
    59.6  }
    59.7 -
    59.8 -/*
    59.9 - * Local variables:
   59.10 - *  c-file-style: "linux"
   59.11 - *  indent-tabs-mode: t
   59.12 - *  c-indent-level: 8
   59.13 - *  c-basic-offset: 8
   59.14 - *  tab-width: 8
   59.15 - * End:
   59.16 - */
    60.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/evtchn.c	Mon May 22 08:53:26 2006 -0600
    60.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/evtchn.c	Mon May 22 14:13:38 2006 -0600
    60.3 @@ -41,10 +41,10 @@
    60.4  #include <asm/system.h>
    60.5  #include <asm/ptrace.h>
    60.6  #include <asm/synch_bitops.h>
    60.7 +#include <xen/evtchn.h>
    60.8  #include <xen/interface/event_channel.h>
    60.9  #include <xen/interface/physdev.h>
   60.10  #include <asm/hypervisor.h>
   60.11 -#include <xen/evtchn.h>
   60.12  #include <linux/mc146818rtc.h> /* RTC_IRQ */
   60.13  
   60.14  /*
   60.15 @@ -163,6 +163,12 @@ static inline unsigned int cpu_from_evtc
   60.16  /* Upcall to generic IRQ layer. */
   60.17  #ifdef CONFIG_X86
   60.18  extern fastcall unsigned int do_IRQ(struct pt_regs *regs);
   60.19 +void __init xen_init_IRQ(void);
   60.20 +void __init init_IRQ(void)
   60.21 +{
   60.22 +	irq_ctx_init(0);
   60.23 +	xen_init_IRQ();
   60.24 +}
   60.25  #if defined (__i386__)
   60.26  static inline void exit_idle(void) {}
   60.27  #define IRQ_REG orig_eax
   60.28 @@ -804,13 +810,11 @@ void irq_resume(void)
   60.29  	}
   60.30  }
   60.31  
   60.32 -void __init init_IRQ(void)
   60.33 +void __init xen_init_IRQ(void)
   60.34  {
   60.35  	int i;
   60.36  	int cpu;
   60.37  
   60.38 -	irq_ctx_init(0);
   60.39 -
   60.40  	spin_lock_init(&irq_mapping_update_lock);
   60.41  
   60.42  	init_evtchn_cpu_bindings();
   60.43 @@ -860,13 +864,3 @@ void __init init_IRQ(void)
   60.44  		irq_desc[pirq_to_irq(i)].handler = &pirq_type;
   60.45  	}
   60.46  }
   60.47 -
   60.48 -/*
   60.49 - * Local variables:
   60.50 - *  c-file-style: "linux"
   60.51 - *  indent-tabs-mode: t
   60.52 - *  c-indent-level: 8
   60.53 - *  c-basic-offset: 8
   60.54 - *  tab-width: 8
   60.55 - * End:
   60.56 - */
    61.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/gnttab.c	Mon May 22 08:53:26 2006 -0600
    61.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/gnttab.c	Mon May 22 14:13:38 2006 -0600
    61.3 @@ -443,7 +443,7 @@ gnttab_init(void)
    61.4  {
    61.5  	int i;
    61.6  
    61.7 -	if (xen_init() < 0)
    61.8 +	if (!is_running_on_xen())
    61.9  		return -ENODEV;
   61.10  
   61.11  	if (gnttab_resume() < 0)
   61.12 @@ -459,13 +459,3 @@ gnttab_init(void)
   61.13  }
   61.14  
   61.15  core_initcall(gnttab_init);
   61.16 -
   61.17 -/*
   61.18 - * Local variables:
   61.19 - *  c-file-style: "linux"
   61.20 - *  indent-tabs-mode: t
   61.21 - *  c-indent-level: 8
   61.22 - *  c-basic-offset: 8
   61.23 - *  tab-width: 8
   61.24 - * End:
   61.25 - */
    62.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/hypervisor_sysfs.c	Mon May 22 08:53:26 2006 -0600
    62.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/hypervisor_sysfs.c	Mon May 22 14:13:38 2006 -0600
    62.3 @@ -49,6 +49,9 @@ static struct kobj_type hyp_sysfs_kobj_t
    62.4  
    62.5  static int __init hypervisor_subsys_init(void)
    62.6  {
    62.7 +	if (!is_running_on_xen())
    62.8 +		return -ENODEV;
    62.9 +
   62.10  	hypervisor_subsys.kset.kobj.ktype = &hyp_sysfs_kobj_type;
   62.11  	return subsystem_register(&hypervisor_subsys);
   62.12  }
    63.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/reboot.c	Mon May 22 08:53:26 2006 -0600
    63.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/reboot.c	Mon May 22 14:13:38 2006 -0600
    63.3 @@ -369,13 +369,3 @@ static int __init setup_shutdown_event(v
    63.4  }
    63.5  
    63.6  subsys_initcall(setup_shutdown_event);
    63.7 -
    63.8 -/*
    63.9 - * Local variables:
   63.10 - *  c-file-style: "linux"
   63.11 - *  indent-tabs-mode: t
   63.12 - *  c-indent-level: 8
   63.13 - *  c-basic-offset: 8
   63.14 - *  tab-width: 8
   63.15 - * End:
   63.16 - */
    64.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/skbuff.c	Mon May 22 08:53:26 2006 -0600
    64.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/skbuff.c	Mon May 22 14:13:38 2006 -0600
    64.3 @@ -132,13 +132,3 @@ static int __init skbuff_init(void)
    64.4  core_initcall(skbuff_init);
    64.5  
    64.6  EXPORT_SYMBOL(__dev_alloc_skb);
    64.7 -
    64.8 -/*
    64.9 - * Local variables:
   64.10 - *  c-file-style: "linux"
   64.11 - *  indent-tabs-mode: t
   64.12 - *  c-indent-level: 8
   64.13 - *  c-basic-offset: 8
   64.14 - *  tab-width: 8
   64.15 - * End:
   64.16 - */
    65.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/smpboot.c	Mon May 22 08:53:26 2006 -0600
    65.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/smpboot.c	Mon May 22 14:13:38 2006 -0600
    65.3 @@ -107,6 +107,18 @@ void __init smp_alloc_memory(void)
    65.4  {
    65.5  }
    65.6  
    65.7 +static inline void
    65.8 +set_cpu_sibling_map(int cpu)
    65.9 +{
   65.10 +	phys_proc_id[cpu] = cpu;
   65.11 +	cpu_core_id[cpu]  = 0;
   65.12 +
   65.13 +	cpu_sibling_map[cpu] = cpumask_of_cpu(cpu);
   65.14 +	cpu_core_map[cpu]    = cpumask_of_cpu(cpu);
   65.15 +
   65.16 +	cpu_data[cpu].booted_cores = 1;
   65.17 +}
   65.18 +
   65.19  static void xen_smp_intr_init(unsigned int cpu)
   65.20  {
   65.21  	sprintf(resched_name[cpu], "resched%d", cpu);
   65.22 @@ -230,14 +242,20 @@ void __init smp_prepare_cpus(unsigned in
   65.23  	struct Xgt_desc_struct *gdt_descr;
   65.24  #endif
   65.25  
   65.26 +	boot_cpu_data.apicid = 0;
   65.27  	cpu_data[0] = boot_cpu_data;
   65.28  
   65.29  	cpu_2_logical_apicid[0] = 0;
   65.30  	x86_cpu_to_apicid[0] = 0;
   65.31  
   65.32  	current_thread_info()->cpu = 0;
   65.33 -	cpu_sibling_map[0] = cpumask_of_cpu(0);
   65.34 -	cpu_core_map[0]    = cpumask_of_cpu(0);
   65.35 +
   65.36 +	for (cpu = 0; cpu < NR_CPUS; cpu++) {
   65.37 +		cpus_clear(cpu_sibling_map[cpu]);
   65.38 +		cpus_clear(cpu_core_map[cpu]);
   65.39 +	}
   65.40 +
   65.41 +	set_cpu_sibling_map(0);
   65.42  
   65.43  	xen_smp_intr_init(0);
   65.44  
   65.45 @@ -262,6 +280,8 @@ void __init smp_prepare_cpus(unsigned in
   65.46  			XENFEAT_writable_descriptor_tables);
   65.47  
   65.48  		cpu_data[cpu] = boot_cpu_data;
   65.49 +		cpu_data[cpu].apicid = cpu;
   65.50 +
   65.51  		cpu_2_logical_apicid[cpu] = cpu;
   65.52  		x86_cpu_to_apicid[cpu] = cpu;
   65.53  
   65.54 @@ -470,6 +490,18 @@ void smp_resume(void)
   65.55  		vcpu_hotplug(i);
   65.56  }
   65.57  
   65.58 +static void
   65.59 +remove_siblinginfo(int cpu)
   65.60 +{
   65.61 +	phys_proc_id[cpu] = BAD_APICID;
   65.62 +	cpu_core_id[cpu]  = BAD_APICID;
   65.63 +
   65.64 +	cpus_clear(cpu_sibling_map[cpu]);
   65.65 +	cpus_clear(cpu_core_map[cpu]);
   65.66 +
   65.67 +	cpu_data[cpu].booted_cores = 0;
   65.68 +}
   65.69 +
   65.70  int __cpu_disable(void)
   65.71  {
   65.72  	cpumask_t map = cpu_online_map;
   65.73 @@ -478,6 +510,8 @@ int __cpu_disable(void)
   65.74  	if (cpu == 0)
   65.75  		return -EBUSY;
   65.76  
   65.77 +	remove_siblinginfo(cpu);
   65.78 +
   65.79  	cpu_clear(cpu, map);
   65.80  	fixup_irqs(map);
   65.81  	cpu_clear(cpu, cpu_online_map);
   65.82 @@ -549,6 +583,10 @@ int __devinit __cpu_up(unsigned int cpu)
   65.83  		prepare_for_smp();
   65.84  #endif
   65.85  
   65.86 +	/* This must be done before setting cpu_online_map */
   65.87 +	set_cpu_sibling_map(cpu);
   65.88 +	wmb();
   65.89 +
   65.90  	xen_smp_intr_init(cpu);
   65.91  	cpu_set(cpu, cpu_online_map);
   65.92  
   65.93 @@ -569,13 +607,3 @@ int setup_profiling_timer(unsigned int m
   65.94  	return -EINVAL;
   65.95  }
   65.96  #endif
   65.97 -
   65.98 -/*
   65.99 - * Local variables:
  65.100 - *  c-file-style: "linux"
  65.101 - *  indent-tabs-mode: t
  65.102 - *  c-indent-level: 8
  65.103 - *  c-basic-offset: 8
  65.104 - *  tab-width: 8
  65.105 - * End:
  65.106 - */
    66.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/xen_proc.c	Mon May 22 08:53:26 2006 -0600
    66.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/xen_proc.c	Mon May 22 14:13:38 2006 -0600
    66.3 @@ -17,13 +17,3 @@ void remove_xen_proc_entry(const char *n
    66.4  {
    66.5  	remove_proc_entry(name, xen_base);
    66.6  }
    66.7 -
    66.8 -/*
    66.9 - * Local variables:
   66.10 - *  c-file-style: "linux"
   66.11 - *  indent-tabs-mode: t
   66.12 - *  c-indent-level: 8
   66.13 - *  c-basic-offset: 8
   66.14 - *  tab-width: 8
   66.15 - * End:
   66.16 - */
    67.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/xen_sysfs.c	Mon May 22 08:53:26 2006 -0600
    67.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/xen_sysfs.c	Mon May 22 14:13:38 2006 -0600
    67.3 @@ -276,7 +276,12 @@ static void xen_properties_destroy(void)
    67.4  
    67.5  static int __init hyper_sysfs_init(void)
    67.6  {
    67.7 -	int ret = xen_sysfs_type_init();
    67.8 +	int ret;
    67.9 +
   67.10 +	if (!is_running_on_xen())
   67.11 +		return -ENODEV;
   67.12 +
   67.13 +	ret = xen_sysfs_type_init();
   67.14  	if (ret)
   67.15  		goto out;
   67.16  	ret = xen_sysfs_version_init();
    68.1 --- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Mon May 22 08:53:26 2006 -0600
    68.2 +++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Mon May 22 14:13:38 2006 -0600
    68.3 @@ -429,6 +429,9 @@ static int __init evtchn_init(void)
    68.4  {
    68.5  	int err;
    68.6  
    68.7 +	if (!is_running_on_xen())
    68.8 +		return -ENODEV;
    68.9 +
   68.10  	spin_lock_init(&port_user_lock);
   68.11  	memset(port_user, 0, sizeof(port_user));
   68.12  
   68.13 @@ -453,13 +456,3 @@ module_init(evtchn_init);
   68.14  module_exit(evtchn_cleanup);
   68.15  
   68.16  MODULE_LICENSE("Dual BSD/GPL");
   68.17 -
   68.18 -/*
   68.19 - * Local variables:
   68.20 - *  c-file-style: "linux"
   68.21 - *  indent-tabs-mode: t
   68.22 - *  c-indent-level: 8
   68.23 - *  c-basic-offset: 8
   68.24 - *  tab-width: 8
   68.25 - * End:
   68.26 - */
    69.1 --- a/linux-2.6-xen-sparse/drivers/xen/net_driver_util.c	Mon May 22 08:53:26 2006 -0600
    69.2 +++ b/linux-2.6-xen-sparse/drivers/xen/net_driver_util.c	Mon May 22 14:13:38 2006 -0600
    69.3 @@ -56,13 +56,3 @@ int xen_net_read_mac(struct xenbus_devic
    69.4  	return 0;
    69.5  }
    69.6  EXPORT_SYMBOL_GPL(xen_net_read_mac);
    69.7 -
    69.8 -/*
    69.9 - * Local variables:
   69.10 - *  c-file-style: "linux"
   69.11 - *  indent-tabs-mode: t
   69.12 - *  c-indent-level: 8
   69.13 - *  c-basic-offset: 8
   69.14 - *  tab-width: 8
   69.15 - * End:
   69.16 - */
    70.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Mon May 22 08:53:26 2006 -0600
    70.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Mon May 22 14:13:38 2006 -0600
    70.3 @@ -38,6 +38,7 @@
    70.4  #include <linux/in.h>
    70.5  #include <linux/netdevice.h>
    70.6  #include <linux/etherdevice.h>
    70.7 +#include <linux/wait.h>
    70.8  #include <xen/evtchn.h>
    70.9  #include <xen/interface/io/netif.h>
   70.10  #include <asm/io.h>
   70.11 @@ -91,7 +92,7 @@ typedef struct netif_st {
   70.12  	struct net_device *dev;
   70.13  	struct net_device_stats stats;
   70.14  
   70.15 -	struct work_struct free_work;
   70.16 +	wait_queue_head_t waiting_to_free;
   70.17  } netif_t;
   70.18  
   70.19  #define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)
   70.20 @@ -99,8 +100,7 @@ typedef struct netif_st {
   70.21  
   70.22  void netif_disconnect(netif_t *netif);
   70.23  
   70.24 -netif_t *alloc_netif(domid_t domid, unsigned int handle, u8 be_mac[ETH_ALEN]);
   70.25 -void free_netif(netif_t *netif);
   70.26 +netif_t *netif_alloc(domid_t domid, unsigned int handle, u8 be_mac[ETH_ALEN]);
   70.27  int netif_map(netif_t *netif, unsigned long tx_ring_ref,
   70.28  	      unsigned long rx_ring_ref, unsigned int evtchn);
   70.29  
   70.30 @@ -108,7 +108,7 @@ int netif_map(netif_t *netif, unsigned l
   70.31  #define netif_put(_b)						\
   70.32  	do {							\
   70.33  		if ( atomic_dec_and_test(&(_b)->refcnt) )	\
   70.34 -			free_netif(_b);				\
   70.35 +			wake_up(&(_b)->waiting_to_free);	\
   70.36  	} while (0)
   70.37  
   70.38  void netif_xenbus_init(void);
   70.39 @@ -121,13 +121,3 @@ struct net_device_stats *netif_be_get_st
   70.40  irqreturn_t netif_be_int(int irq, void *dev_id, struct pt_regs *regs);
   70.41  
   70.42  #endif /* __NETIF__BACKEND__COMMON_H__ */
   70.43 -
   70.44 -/*
   70.45 - * Local variables:
   70.46 - *  c-file-style: "linux"
   70.47 - *  indent-tabs-mode: t
   70.48 - *  c-indent-level: 8
   70.49 - *  c-basic-offset: 8
   70.50 - *  tab-width: 8
   70.51 - * End:
   70.52 - */
    71.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Mon May 22 08:53:26 2006 -0600
    71.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Mon May 22 14:13:38 2006 -0600
    71.3 @@ -78,7 +78,7 @@ static struct ethtool_ops network_ethtoo
    71.4  	.set_tx_csum = ethtool_op_set_tx_csum,
    71.5  };
    71.6  
    71.7 -netif_t *alloc_netif(domid_t domid, unsigned int handle, u8 be_mac[ETH_ALEN])
    71.8 +netif_t *netif_alloc(domid_t domid, unsigned int handle, u8 be_mac[ETH_ALEN])
    71.9  {
   71.10  	int err = 0, i;
   71.11  	struct net_device *dev;
   71.12 @@ -97,7 +97,8 @@ netif_t *alloc_netif(domid_t domid, unsi
   71.13  	netif->domid  = domid;
   71.14  	netif->handle = handle;
   71.15  	netif->status = DISCONNECTED;
   71.16 -	atomic_set(&netif->refcnt, 0);
   71.17 +	atomic_set(&netif->refcnt, 1);
   71.18 +	init_waitqueue_head(&netif->waiting_to_free);
   71.19  	netif->dev = dev;
   71.20  
   71.21  	netif->credit_bytes = netif->remaining_credit = ~0UL;
   71.22 @@ -273,9 +274,10 @@ err_rx:
   71.23  	return err;
   71.24  }
   71.25  
   71.26 -static void free_netif_callback(void *arg)
   71.27 +static void netif_free(netif_t *netif)
   71.28  {
   71.29 -	netif_t *netif = (netif_t *)arg;
   71.30 +	atomic_dec(&netif->refcnt);
   71.31 +	wait_event(netif->waiting_to_free, atomic_read(&netif->refcnt) == 0);
   71.32  
   71.33  	if (netif->irq)
   71.34  		unbind_from_irqhandler(netif->irq, netif);
   71.35 @@ -291,12 +293,6 @@ static void free_netif_callback(void *ar
   71.36  	free_netdev(netif->dev);
   71.37  }
   71.38  
   71.39 -void free_netif(netif_t *netif)
   71.40 -{
   71.41 -	INIT_WORK(&netif->free_work, free_netif_callback, (void *)netif);
   71.42 -	schedule_work(&netif->free_work);
   71.43 -}
   71.44 -
   71.45  void netif_disconnect(netif_t *netif)
   71.46  {
   71.47  	switch (netif->status) {
   71.48 @@ -308,22 +304,11 @@ void netif_disconnect(netif_t *netif)
   71.49  			__netif_down(netif);
   71.50  		rtnl_unlock();
   71.51  		netif_put(netif);
   71.52 -		break;
   71.53 +		/* fall through */
   71.54  	case DISCONNECTED:
   71.55 -		BUG_ON(atomic_read(&netif->refcnt) != 0);
   71.56 -		free_netif(netif);
   71.57 +		netif_free(netif);
   71.58  		break;
   71.59  	default:
   71.60  		BUG();
   71.61  	}
   71.62  }
   71.63 -
   71.64 -/*
   71.65 - * Local variables:
   71.66 - *  c-file-style: "linux"
   71.67 - *  indent-tabs-mode: t
   71.68 - *  c-indent-level: 8
   71.69 - *  c-basic-offset: 8
   71.70 - *  tab-width: 8
   71.71 - * End:
   71.72 - */
    72.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/loopback.c	Mon May 22 08:53:26 2006 -0600
    72.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/loopback.c	Mon May 22 14:13:38 2006 -0600
    72.3 @@ -251,13 +251,3 @@ static void __exit loopback_exit(void)
    72.4  module_exit(loopback_exit);
    72.5  
    72.6  MODULE_LICENSE("Dual BSD/GPL");
    72.7 -
    72.8 -/*
    72.9 - * Local variables:
   72.10 - *  c-file-style: "linux"
   72.11 - *  indent-tabs-mode: t
   72.12 - *  c-indent-level: 8
   72.13 - *  c-basic-offset: 8
   72.14 - *  tab-width: 8
   72.15 - * End:
   72.16 - */
    73.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Mon May 22 08:53:26 2006 -0600
    73.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Mon May 22 14:13:38 2006 -0600
    73.3 @@ -170,7 +170,9 @@ int netif_be_start_xmit(struct sk_buff *
    73.4  		ret = skb_copy_bits(skb, -hlen, nskb->data - hlen,
    73.5  				     skb->len + hlen);
    73.6  		BUG_ON(ret);
    73.7 +		/* Copy only the header fields we use in this driver. */
    73.8  		nskb->dev = skb->dev;
    73.9 +		nskb->ip_summed = skb->ip_summed;
   73.10  		nskb->proto_data_valid = skb->proto_data_valid;
   73.11  		dev_kfree_skb(skb);
   73.12  		skb = nskb;
   73.13 @@ -808,6 +810,9 @@ static int __init netback_init(void)
   73.14  	int i;
   73.15  	struct page *page;
   73.16  
   73.17 +	if (!is_running_on_xen())
   73.18 +		return -ENODEV;
   73.19 +
   73.20  	/* We can increase reservation by this much in net_rx_action(). */
   73.21  	balloon_update_driver_allowance(NET_RX_RING_SIZE);
   73.22  
   73.23 @@ -848,27 +853,9 @@ static int __init netback_init(void)
   73.24  		&netif_be_dbg);
   73.25  #endif
   73.26  
   73.27 -	__unsafe(THIS_MODULE);
   73.28 -
   73.29  	return 0;
   73.30  }
   73.31  
   73.32 -static void netback_cleanup(void)
   73.33 -{
   73.34 -	BUG();
   73.35 -}
   73.36 -
   73.37  module_init(netback_init);
   73.38 -module_exit(netback_cleanup);
   73.39  
   73.40  MODULE_LICENSE("Dual BSD/GPL");
   73.41 -
   73.42 -/*
   73.43 - * Local variables:
   73.44 - *  c-file-style: "linux"
   73.45 - *  indent-tabs-mode: t
   73.46 - *  c-indent-level: 8
   73.47 - *  c-basic-offset: 8
   73.48 - *  tab-width: 8
   73.49 - * End:
   73.50 - */
    74.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Mon May 22 08:53:26 2006 -0600
    74.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Mon May 22 14:13:38 2006 -0600
    74.3 @@ -172,7 +172,7 @@ static void backend_changed(struct xenbu
    74.4  	if (be->netif == NULL) {
    74.5  		u8 be_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
    74.6  
    74.7 -		be->netif = alloc_netif(dev->otherend_id, handle, be_mac);
    74.8 +		be->netif = netif_alloc(dev->otherend_id, handle, be_mac);
    74.9  		if (IS_ERR(be->netif)) {
   74.10  			err = PTR_ERR(be->netif);
   74.11  			be->netif = NULL;
   74.12 @@ -353,14 +353,3 @@ void netif_xenbus_init(void)
   74.13  {
   74.14  	xenbus_register_backend(&netback);
   74.15  }
   74.16 -
   74.17 -
   74.18 -/*
   74.19 - * Local variables:
   74.20 - *  c-file-style: "linux"
   74.21 - *  indent-tabs-mode: t
   74.22 - *  c-indent-level: 8
   74.23 - *  c-basic-offset: 8
   74.24 - *  tab-width: 8
   74.25 - * End:
   74.26 - */
    75.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Mon May 22 08:53:26 2006 -0600
    75.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Mon May 22 14:13:38 2006 -0600
    75.3 @@ -1,25 +1,25 @@
    75.4  /******************************************************************************
    75.5   * Virtual network driver for conversing with remote driver backends.
    75.6 - * 
    75.7 + *
    75.8   * Copyright (c) 2002-2005, K A Fraser
    75.9   * Copyright (c) 2005, XenSource Ltd
   75.10 - * 
   75.11 + *
   75.12   * This program is free software; you can redistribute it and/or
   75.13   * modify it under the terms of the GNU General Public License version 2
   75.14   * as published by the Free Software Foundation; or, when distributed
   75.15   * separately from the Linux kernel or incorporated into other
   75.16   * software packages, subject to the following license:
   75.17 - * 
   75.18 + *
   75.19   * Permission is hereby granted, free of charge, to any person obtaining a copy
   75.20   * of this source file (the "Software"), to deal in the Software without
   75.21   * restriction, including without limitation the rights to use, copy, modify,
   75.22   * merge, publish, distribute, sublicense, and/or sell copies of the Software,
   75.23   * and to permit persons to whom the Software is furnished to do so, subject to
   75.24   * the following conditions:
   75.25 - * 
   75.26 + *
   75.27   * The above copyright notice and this permission notice shall be included in
   75.28   * all copies or substantial portions of the Software.
   75.29 - * 
   75.30 + *
   75.31   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   75.32   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   75.33   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   75.34 @@ -43,7 +43,6 @@
   75.35  #include <linux/skbuff.h>
   75.36  #include <linux/init.h>
   75.37  #include <linux/bitops.h>
   75.38 -#include <linux/proc_fs.h>
   75.39  #include <linux/ethtool.h>
   75.40  #include <linux/in.h>
   75.41  #include <net/sock.h>
   75.42 @@ -65,8 +64,8 @@
   75.43  
   75.44  #define GRANT_INVALID_REF	0
   75.45  
   75.46 -#define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)
   75.47 -#define NET_RX_RING_SIZE __RING_SIZE((netif_rx_sring_t *)0, PAGE_SIZE)
   75.48 +#define NET_TX_RING_SIZE __RING_SIZE((struct netif_tx_sring *)0, PAGE_SIZE)
   75.49 +#define NET_RX_RING_SIZE __RING_SIZE((struct netif_rx_sring *)0, PAGE_SIZE)
   75.50  
   75.51  static inline void init_skb_shinfo(struct sk_buff *skb)
   75.52  {
   75.53 @@ -75,16 +74,14 @@ static inline void init_skb_shinfo(struc
   75.54  	skb_shinfo(skb)->frag_list = NULL;
   75.55  }
   75.56  
   75.57 -struct netfront_info
   75.58 -{
   75.59 +struct netfront_info {
   75.60  	struct list_head list;
   75.61  	struct net_device *netdev;
   75.62  
   75.63  	struct net_device_stats stats;
   75.64 -	unsigned int tx_full;
   75.65  
   75.66 -	netif_tx_front_ring_t tx;
   75.67 -	netif_rx_front_ring_t rx;
   75.68 +	struct netif_tx_front_ring tx;
   75.69 +	struct netif_rx_front_ring rx;
   75.70  
   75.71  	spinlock_t   tx_lock;
   75.72  	spinlock_t   rx_lock;
   75.73 @@ -98,16 +95,11 @@ struct netfront_info
   75.74  #define BEST_CONNECTED    2
   75.75  	unsigned int backend_state;
   75.76  
   75.77 -	/* Is this interface open or closed (down or up)? */
   75.78 -#define UST_CLOSED        0
   75.79 -#define UST_OPEN          1
   75.80 -	unsigned int user_state;
   75.81 -
   75.82  	/* Receive-ring batched refills. */
   75.83  #define RX_MIN_TARGET 8
   75.84  #define RX_DFL_MIN_TARGET 64
   75.85  #define RX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256)
   75.86 -	int rx_min_target, rx_max_target, rx_target;
   75.87 +	unsigned rx_min_target, rx_max_target, rx_target;
   75.88  	struct sk_buff_head rx_batch;
   75.89  
   75.90  	struct timer_list rx_refill_timer;
   75.91 @@ -131,8 +123,8 @@ struct netfront_info
   75.92  	u8 mac[ETH_ALEN];
   75.93  
   75.94  	unsigned long rx_pfn_array[NET_RX_RING_SIZE];
   75.95 -	multicall_entry_t rx_mcl[NET_RX_RING_SIZE+1];
   75.96 -	mmu_update_t rx_mmu[NET_RX_RING_SIZE];
   75.97 +	struct multicall_entry rx_mcl[NET_RX_RING_SIZE+1];
   75.98 +	struct mmu_update rx_mmu[NET_RX_RING_SIZE];
   75.99  };
  75.100  
  75.101  /*
  75.102 @@ -153,7 +145,7 @@ static inline unsigned short get_id_from
  75.103  }
  75.104  
  75.105  #ifdef DEBUG
  75.106 -static char *be_state_name[] = {
  75.107 +static const char *be_state_name[] = {
  75.108  	[BEST_CLOSED]       = "closed",
  75.109  	[BEST_DISCONNECTED] = "disconnected",
  75.110  	[BEST_CONNECTED]    = "connected",
  75.111 @@ -170,7 +162,7 @@ static char *be_state_name[] = {
  75.112  
  75.113  static int talk_to_backend(struct xenbus_device *, struct netfront_info *);
  75.114  static int setup_device(struct xenbus_device *, struct netfront_info *);
  75.115 -static int create_netdev(int, struct xenbus_device *, struct net_device **);
  75.116 +static struct net_device *create_netdev(int, struct xenbus_device *);
  75.117  
  75.118  static void netfront_closing(struct xenbus_device *);
  75.119  
  75.120 @@ -188,25 +180,22 @@ static int send_fake_arp(struct net_devi
  75.121  
  75.122  static irqreturn_t netif_int(int irq, void *dev_id, struct pt_regs *ptregs);
  75.123  
  75.124 -#ifdef CONFIG_PROC_FS
  75.125 -static int xennet_proc_init(void);
  75.126 -static int xennet_proc_addif(struct net_device *dev);
  75.127 -static void xennet_proc_delif(struct net_device *dev);
  75.128 -#else
  75.129 -#define xennet_proc_init()   (0)
  75.130 -#define xennet_proc_addif(d) (0)
  75.131 -#define xennet_proc_delif(d) ((void)0)
  75.132 +#ifdef CONFIG_SYSFS
  75.133 +static int xennet_sysfs_addif(struct net_device *netdev);
  75.134 +static void xennet_sysfs_delif(struct net_device *netdev);
  75.135 +#else /* !CONFIG_SYSFS */
  75.136 +#define xennet_sysfs_addif(dev) (0)
  75.137 +#define xennet_sysfs_delif(dev) do { } while(0)
  75.138  #endif
  75.139  
  75.140 -
  75.141  /**
  75.142   * Entry point to this code when a new device is created.  Allocate the basic
  75.143   * structures and the ring buffers for communication with the backend, and
  75.144   * inform the backend of the appropriate details for those.  Switch to
  75.145   * Connected state.
  75.146   */
  75.147 -static int netfront_probe(struct xenbus_device *dev,
  75.148 -			  const struct xenbus_device_id *id)
  75.149 +static int __devinit netfront_probe(struct xenbus_device *dev,
  75.150 +				    const struct xenbus_device_id *id)
  75.151  {
  75.152  	int err;
  75.153  	struct net_device *netdev;
  75.154 @@ -219,8 +208,9 @@ static int netfront_probe(struct xenbus_
  75.155  		return err;
  75.156  	}
  75.157  
  75.158 -	err = create_netdev(handle, dev, &netdev);
  75.159 -	if (err) {
  75.160 +	netdev = create_netdev(handle, dev);
  75.161 +	if (IS_ERR(netdev)) {
  75.162 +		err = PTR_ERR(netdev);
  75.163  		xenbus_dev_fatal(dev, err, "creating netdev");
  75.164  		return err;
  75.165  	}
  75.166 @@ -230,7 +220,9 @@ static int netfront_probe(struct xenbus_
  75.167  
  75.168  	err = talk_to_backend(dev, info);
  75.169  	if (err) {
  75.170 -		kfree(info);
  75.171 +		xennet_sysfs_delif(info->netdev);
  75.172 +		unregister_netdev(netdev);
  75.173 +		free_netdev(netdev);
  75.174  		dev->data = NULL;
  75.175  		return err;
  75.176  	}
  75.177 @@ -325,8 +317,8 @@ again:
  75.178  
  75.179  static int setup_device(struct xenbus_device *dev, struct netfront_info *info)
  75.180  {
  75.181 -	netif_tx_sring_t *txs;
  75.182 -	netif_rx_sring_t *rxs;
  75.183 +	struct netif_tx_sring *txs;
  75.184 +	struct netif_rx_sring *rxs;
  75.185  	int err;
  75.186  	struct net_device *netdev = info->netdev;
  75.187  
  75.188 @@ -336,13 +328,13 @@ static int setup_device(struct xenbus_de
  75.189  	info->tx.sring = NULL;
  75.190  	info->irq = 0;
  75.191  
  75.192 -	txs = (netif_tx_sring_t *)__get_free_page(GFP_KERNEL);
  75.193 +	txs = (struct netif_tx_sring *)__get_free_page(GFP_KERNEL);
  75.194  	if (!txs) {
  75.195  		err = -ENOMEM;
  75.196  		xenbus_dev_fatal(dev, err, "allocating tx ring page");
  75.197  		goto fail;
  75.198  	}
  75.199 -	rxs = (netif_rx_sring_t *)__get_free_page(GFP_KERNEL);
  75.200 +	rxs = (struct netif_rx_sring *)__get_free_page(GFP_KERNEL);
  75.201  	if (!rxs) {
  75.202  		err = -ENOMEM;
  75.203  		xenbus_dev_fatal(dev, err, "allocating rx ring page");
  75.204 @@ -447,8 +439,6 @@ static int network_open(struct net_devic
  75.205  
  75.206  	memset(&np->stats, 0, sizeof(np->stats));
  75.207  
  75.208 -	np->user_state = UST_OPEN;
  75.209 -
  75.210  	network_alloc_rx_buffers(dev);
  75.211  	np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
  75.212  
  75.213 @@ -457,9 +447,20 @@ static int network_open(struct net_devic
  75.214  	return 0;
  75.215  }
  75.216  
  75.217 +static inline void network_maybe_wake_tx(struct net_device *dev)
  75.218 +{
  75.219 +	struct netfront_info *np = netdev_priv(dev);
  75.220 +
  75.221 +	if (unlikely(netif_queue_stopped(dev)) &&
  75.222 +	    !RING_FULL(&np->tx) &&
  75.223 +	    !gnttab_empty_grant_references(&np->gref_tx_head) &&
  75.224 +	    likely(netif_running(dev)))
  75.225 +		netif_wake_queue(dev);
  75.226 +}
  75.227 +
  75.228  static void network_tx_buf_gc(struct net_device *dev)
  75.229  {
  75.230 -	RING_IDX i, prod;
  75.231 +	RING_IDX cons, prod;
  75.232  	unsigned short id;
  75.233  	struct netfront_info *np = netdev_priv(dev);
  75.234  	struct sk_buff *skb;
  75.235 @@ -471,15 +472,15 @@ static void network_tx_buf_gc(struct net
  75.236  		prod = np->tx.sring->rsp_prod;
  75.237  		rmb(); /* Ensure we see responses up to 'rp'. */
  75.238  
  75.239 -		for (i = np->tx.rsp_cons; i != prod; i++) {
  75.240 -			id  = RING_GET_RESPONSE(&np->tx, i)->id;
  75.241 +		for (cons = np->tx.rsp_cons; cons != prod; cons++) {
  75.242 +			id  = RING_GET_RESPONSE(&np->tx, cons)->id;
  75.243  			skb = np->tx_skbs[id];
  75.244  			if (unlikely(gnttab_query_foreign_access(
  75.245  				np->grant_tx_ref[id]) != 0)) {
  75.246  				printk(KERN_ALERT "network_tx_buf_gc: warning "
  75.247  				       "-- grant still in use by backend "
  75.248  				       "domain.\n");
  75.249 -				goto out;
  75.250 +				break; /* bail immediately */
  75.251  			}
  75.252  			gnttab_end_foreign_access_ref(
  75.253  				np->grant_tx_ref[id], GNTMAP_readonly);
  75.254 @@ -503,16 +504,9 @@ static void network_tx_buf_gc(struct net
  75.255  		np->tx.sring->rsp_event =
  75.256  			prod + ((np->tx.sring->req_prod - prod) >> 1) + 1;
  75.257  		mb();
  75.258 -	} while (prod != np->tx.sring->rsp_prod);
  75.259 +	} while ((cons == prod) && (prod != np->tx.sring->rsp_prod));
  75.260  
  75.261 - out:
  75.262 -	if ((np->tx_full) &&
  75.263 -	    ((np->tx.sring->req_prod - prod) < NET_TX_RING_SIZE) &&
  75.264 -	    !gnttab_empty_grant_references(&np->gref_tx_head)) {
  75.265 -		np->tx_full = 0;
  75.266 -		if (np->user_state == UST_OPEN)
  75.267 -			netif_wake_queue(dev);
  75.268 -	}
  75.269 +	network_maybe_wake_tx(dev);
  75.270  }
  75.271  
  75.272  
  75.273 @@ -644,19 +638,12 @@ static int network_start_xmit(struct sk_
  75.274  {
  75.275  	unsigned short id;
  75.276  	struct netfront_info *np = netdev_priv(dev);
  75.277 -	netif_tx_request_t *tx;
  75.278 +	struct netif_tx_request *tx;
  75.279  	RING_IDX i;
  75.280  	grant_ref_t ref;
  75.281  	unsigned long mfn;
  75.282  	int notify;
  75.283  
  75.284 -	if (unlikely(np->tx_full)) {
  75.285 -		printk(KERN_ALERT "%s: full queue wasn't stopped!\n",
  75.286 -		       dev->name);
  75.287 -		netif_stop_queue(dev);
  75.288 -		goto drop;
  75.289 -	}
  75.290 -
  75.291  	if (unlikely((((unsigned long)skb->data & ~PAGE_MASK) + skb->len) >=
  75.292  		     PAGE_SIZE)) {
  75.293  		struct sk_buff *nskb;
  75.294 @@ -665,7 +652,10 @@ static int network_start_xmit(struct sk_
  75.295  			goto drop;
  75.296  		skb_put(nskb, skb->len);
  75.297  		memcpy(nskb->data, skb->data, skb->len);
  75.298 +		/* Copy only the header fields we use in this driver. */
  75.299  		nskb->dev = skb->dev;
  75.300 +		nskb->ip_summed = skb->ip_summed;
  75.301 +		nskb->proto_data_valid = skb->proto_data_valid;
  75.302  		dev_kfree_skb(skb);
  75.303  		skb = nskb;
  75.304  	}
  75.305 @@ -708,10 +698,8 @@ static int network_start_xmit(struct sk_
  75.306  	network_tx_buf_gc(dev);
  75.307  
  75.308  	if (RING_FULL(&np->tx) ||
  75.309 -	    gnttab_empty_grant_references(&np->gref_tx_head)) {
  75.310 -		np->tx_full = 1;
  75.311 +	    gnttab_empty_grant_references(&np->gref_tx_head))
  75.312  		netif_stop_queue(dev);
  75.313 -	}
  75.314  
  75.315  	spin_unlock_irq(&np->tx_lock);
  75.316  
  75.317 @@ -737,7 +725,7 @@ static irqreturn_t netif_int(int irq, vo
  75.318  	spin_unlock_irqrestore(&np->tx_lock, flags);
  75.319  
  75.320  	if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx) &&
  75.321 -	    (np->user_state == UST_OPEN))
  75.322 +	    likely(netif_running(dev)))
  75.323  		netif_rx_schedule(dev);
  75.324  
  75.325  	return IRQ_HANDLED;
  75.326 @@ -748,10 +736,10 @@ static int netif_poll(struct net_device 
  75.327  {
  75.328  	struct netfront_info *np = netdev_priv(dev);
  75.329  	struct sk_buff *skb, *nskb;
  75.330 -	netif_rx_response_t *rx;
  75.331 +	struct netif_rx_response *rx;
  75.332  	RING_IDX i, rp;
  75.333 -	mmu_update_t *mmu = np->rx_mmu;
  75.334 -	multicall_entry_t *mcl = np->rx_mcl;
  75.335 +	struct mmu_update *mmu = np->rx_mmu;
  75.336 +	struct multicall_entry *mcl = np->rx_mcl;
  75.337  	int work_done, budget, more_to_do = 1;
  75.338  	struct sk_buff_head rxq;
  75.339  	unsigned long flags;
  75.340 @@ -898,8 +886,11 @@ static int netif_poll(struct net_device 
  75.341  				skb_reserve(nskb, 2);
  75.342  				skb_put(nskb, skb->len);
  75.343  				memcpy(nskb->data, skb->data, skb->len);
  75.344 +				/* Copy any other fields we already set up. */
  75.345  				nskb->dev = skb->dev;
  75.346  				nskb->ip_summed = skb->ip_summed;
  75.347 +				nskb->proto_data_valid = skb->proto_data_valid;
  75.348 +				nskb->proto_csum_blank = skb->proto_csum_blank;
  75.349  			}
  75.350  
  75.351  			/* Reinitialise and then destroy the old skbuff. */
  75.352 @@ -956,7 +947,6 @@ static int netif_poll(struct net_device 
  75.353  static int network_close(struct net_device *dev)
  75.354  {
  75.355  	struct netfront_info *np = netdev_priv(dev);
  75.356 -	np->user_state = UST_CLOSED;
  75.357  	netif_stop_queue(np->netdev);
  75.358  	return 0;
  75.359  }
  75.360 @@ -972,7 +962,7 @@ static void network_connect(struct net_d
  75.361  {
  75.362  	struct netfront_info *np;
  75.363  	int i, requeue_idx;
  75.364 -	netif_tx_request_t *tx;
  75.365 +	struct netif_tx_request *tx;
  75.366  	struct sk_buff *skb;
  75.367  
  75.368  	np = netdev_priv(dev);
  75.369 @@ -981,11 +971,8 @@ static void network_connect(struct net_d
  75.370  
  75.371  	/* Recovery procedure: */
  75.372  
  75.373 -	/* Step 1: Reinitialise variables. */
  75.374 -	np->tx_full = 0;
  75.375 -
  75.376  	/*
  75.377 -	 * Step 2: Rebuild the RX and TX ring contents.
  75.378 +	 * Step 1: Rebuild the RX and TX ring contents.
  75.379  	 * NB. We could just free the queued TX packets now but we hope
  75.380  	 * that sending them out might do some good.  We have to rebuild
  75.381  	 * the RX ring because some of our pages are currently flipped out
  75.382 @@ -1049,7 +1036,7 @@ static void network_connect(struct net_d
  75.383  	RING_PUSH_REQUESTS(&np->rx);
  75.384  
  75.385  	/*
  75.386 -	 * Step 3: All public and private state should now be sane.  Get
  75.387 +	 * Step 2: All public and private state should now be sane.  Get
  75.388  	 * ready to start sending and receiving packets and give the driver
  75.389  	 * domain a kick because we've probably just requeued some
  75.390  	 * packets.
  75.391 @@ -1058,9 +1045,6 @@ static void network_connect(struct net_d
  75.392  	notify_remote_via_irq(np->irq);
  75.393  	network_tx_buf_gc(dev);
  75.394  
  75.395 -	if (np->user_state == UST_OPEN)
  75.396 -		netif_start_queue(dev);
  75.397 -
  75.398  	spin_unlock(&np->rx_lock);
  75.399  	spin_unlock_irq(&np->tx_lock);
  75.400  }
  75.401 @@ -1072,7 +1056,7 @@ static void show_device(struct netfront_
  75.402  		IPRINTK("<vif handle=%u %s(%s) evtchn=%u tx=%p rx=%p>\n",
  75.403  			np->handle,
  75.404  			be_state_name[np->backend_state],
  75.405 -			np->user_state ? "open" : "closed",
  75.406 +			netif_running(np->netdev) ? "open" : "closed",
  75.407  			np->evtchn,
  75.408  			np->tx,
  75.409  			np->rx);
  75.410 @@ -1094,6 +1078,141 @@ static struct ethtool_ops network_ethtoo
  75.411  	.set_tx_csum = ethtool_op_set_tx_csum,
  75.412  };
  75.413  
  75.414 +#ifdef CONFIG_SYSFS
  75.415 +static ssize_t show_rxbuf_min(struct class_device *cd, char *buf)
  75.416 +{
  75.417 +	struct net_device *netdev = container_of(cd, struct net_device,
  75.418 +						 class_dev);
  75.419 +	struct netfront_info *info = netdev_priv(netdev);
  75.420 +
  75.421 +	return sprintf(buf, "%u\n", info->rx_min_target);
  75.422 +}
  75.423 +
  75.424 +static ssize_t store_rxbuf_min(struct class_device *cd,
  75.425 +			       const char *buf, size_t len)
  75.426 +{
  75.427 +	struct net_device *netdev = container_of(cd, struct net_device,
  75.428 +						 class_dev);
  75.429 +	struct netfront_info *np = netdev_priv(netdev);
  75.430 +	char *endp;
  75.431 +	unsigned long target;
  75.432 +
  75.433 +	if (!capable(CAP_NET_ADMIN))
  75.434 +		return -EPERM;
  75.435 +
  75.436 +	target = simple_strtoul(buf, &endp, 0);
  75.437 +	if (endp == buf)
  75.438 +		return -EBADMSG;
  75.439 +
  75.440 +	if (target < RX_MIN_TARGET)
  75.441 +		target = RX_MIN_TARGET;
  75.442 +	if (target > RX_MAX_TARGET)
  75.443 +		target = RX_MAX_TARGET;
  75.444 +
  75.445 +	spin_lock(&np->rx_lock);
  75.446 +	if (target > np->rx_max_target)
  75.447 +		np->rx_max_target = target;
  75.448 +	np->rx_min_target = target;
  75.449 +	if (target > np->rx_target)
  75.450 +		np->rx_target = target;
  75.451 +
  75.452 +	network_alloc_rx_buffers(netdev);
  75.453 +
  75.454 +	spin_unlock(&np->rx_lock);
  75.455 +	return len;
  75.456 +}
  75.457 +
  75.458 +static ssize_t show_rxbuf_max(struct class_device *cd, char *buf)
  75.459 +{
  75.460 +	struct net_device *netdev = container_of(cd, struct net_device,
  75.461 +						 class_dev);
  75.462 +	struct netfront_info *info = netdev_priv(netdev);
  75.463 +
  75.464 +	return sprintf(buf, "%u\n", info->rx_max_target);
  75.465 +}
  75.466 +
  75.467 +static ssize_t store_rxbuf_max(struct class_device *cd,
  75.468 +			       const char *buf, size_t len)
  75.469 +{
  75.470 +	struct net_device *netdev = container_of(cd, struct net_device,
  75.471 +						 class_dev);
  75.472 +	struct netfront_info *np = netdev_priv(netdev);
  75.473 +	char *endp;
  75.474 +	unsigned long target;
  75.475 +
  75.476 +	if (!capable(CAP_NET_ADMIN))
  75.477 +		return -EPERM;
  75.478 +
  75.479 +	target = simple_strtoul(buf, &endp, 0);
  75.480 +	if (endp == buf)
  75.481 +		return -EBADMSG;
  75.482 +
  75.483 +	if (target < RX_MIN_TARGET)
  75.484 +		target = RX_MIN_TARGET;
  75.485 +	if (target > RX_MAX_TARGET)
  75.486 +		target = RX_MAX_TARGET;
  75.487 +
  75.488 +	spin_lock(&np->rx_lock);
  75.489 +	if (target < np->rx_min_target)
  75.490 +		np->rx_min_target = target;
  75.491 +	np->rx_max_target = target;
  75.492 +	if (target < np->rx_target)
  75.493 +		np->rx_target = target;
  75.494 +
  75.495 +	network_alloc_rx_buffers(netdev);
  75.496 +
  75.497 +	spin_unlock(&np->rx_lock);
  75.498 +	return len;
  75.499 +}
  75.500 +
  75.501 +static ssize_t show_rxbuf_cur(struct class_device *cd, char *buf)
  75.502 +{
  75.503 +	struct net_device *netdev = container_of(cd, struct net_device,
  75.504 +						 class_dev);
  75.505 +	struct netfront_info *info = netdev_priv(netdev);
  75.506 +
  75.507 +	return sprintf(buf, "%u\n", info->rx_target);
  75.508 +}
  75.509 +
  75.510 +static const struct class_device_attribute xennet_attrs[] = {
  75.511 +	__ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf_min, store_rxbuf_min),
  75.512 +	__ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf_max, store_rxbuf_max),
  75.513 +	__ATTR(rxbuf_cur, S_IRUGO, show_rxbuf_cur, NULL),
  75.514 +};
  75.515 +
  75.516 +static int xennet_sysfs_addif(struct net_device *netdev)
  75.517 +{
  75.518 +	int i;
  75.519 +	int error = 0;
  75.520 +
  75.521 +	for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
  75.522 +		error = class_device_create_file(&netdev->class_dev, 
  75.523 +						 &xennet_attrs[i]);
  75.524 +		if (error)
  75.525 +			goto fail;
  75.526 +	}
  75.527 +	return 0;
  75.528 +
  75.529 + fail:
  75.530 +	while (--i >= 0)
  75.531 +		class_device_remove_file(&netdev->class_dev,
  75.532 +					 &xennet_attrs[i]);
  75.533 +	return error;
  75.534 +}
  75.535 +
  75.536 +static void xennet_sysfs_delif(struct net_device *netdev)
  75.537 +{
  75.538 +	int i;
  75.539 +
  75.540 +	for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
  75.541 +		class_device_remove_file(&netdev->class_dev,
  75.542 +					 &xennet_attrs[i]);
  75.543 +	}
  75.544 +}
  75.545 +
  75.546 +#endif /* CONFIG_SYSFS */
  75.547 +
  75.548 +
  75.549  /*
  75.550   * Nothing to do here. Virtual interface is point-to-point and the
  75.551   * physical interface is probably promiscuous anyway.
  75.552 @@ -1107,23 +1226,22 @@ static void network_set_multicast_list(s
  75.553   * @param val return parameter for created device
  75.554   * @return 0 on success, error code otherwise
  75.555   */
  75.556 -static int create_netdev(int handle, struct xenbus_device *dev,
  75.557 -			 struct net_device **val)
  75.558 +static struct net_device * __devinit create_netdev(int handle,
  75.559 +						   struct xenbus_device *dev)
  75.560  {
  75.561  	int i, err = 0;
  75.562  	struct net_device *netdev = NULL;
  75.563  	struct netfront_info *np = NULL;
  75.564  
  75.565 -	if ((netdev = alloc_etherdev(sizeof(struct netfront_info))) == NULL) {
  75.566 +	netdev = alloc_etherdev(sizeof(struct netfront_info));
  75.567 +	if (!netdev) {
  75.568  		printk(KERN_WARNING "%s> alloc_etherdev failed.\n",
  75.569  		       __FUNCTION__);
  75.570 -		err = -ENOMEM;
  75.571 -		goto exit;
  75.572 +		return ERR_PTR(-ENOMEM);
  75.573  	}
  75.574  
  75.575  	np                = netdev_priv(netdev);
  75.576  	np->backend_state = BEST_CLOSED;
  75.577 -	np->user_state    = UST_CLOSED;
  75.578  	np->handle        = handle;
  75.579  	np->xbdev         = dev;
  75.580  
  75.581 @@ -1163,7 +1281,7 @@ static int create_netdev(int handle, str
  75.582  		printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n");
  75.583  		gnttab_free_grant_references(np->gref_tx_head);
  75.584  		err = -ENOMEM;
  75.585 -		goto exit;
  75.586 +		goto exit_free_tx;
  75.587  	}
  75.588  
  75.589  	netdev->open            = network_open;
  75.590 @@ -1180,30 +1298,32 @@ static int create_netdev(int handle, str
  75.591  	SET_MODULE_OWNER(netdev);
  75.592  	SET_NETDEV_DEV(netdev, &dev->dev);
  75.593  
  75.594 -	if ((err = register_netdev(netdev)) != 0) {
  75.595 +	err = register_netdev(netdev);
  75.596 +	if (err) {
  75.597  		printk(KERN_WARNING "%s> register_netdev err=%d\n",
  75.598  		       __FUNCTION__, err);
  75.599 -		goto exit_free_grefs;
  75.600 +		goto exit_free_rx;
  75.601  	}
  75.602  
  75.603 -	if ((err = xennet_proc_addif(netdev)) != 0) {
  75.604 -		unregister_netdev(netdev);
  75.605 -		goto exit_free_grefs;
  75.606 +	err = xennet_sysfs_addif(netdev);
  75.607 +	if (err) {
  75.608 +		/* This can be non-fatal: it only means no tuning parameters */
  75.609 +		printk(KERN_WARNING "%s> add sysfs failed err=%d\n",
  75.610 +		       __FUNCTION__, err);
  75.611  	}
  75.612  
  75.613  	np->netdev = netdev;
  75.614  
  75.615 +	return netdev;
  75.616 +
  75.617 +
  75.618 + exit_free_rx:
  75.619 +	gnttab_free_grant_references(np->gref_rx_head);
  75.620 + exit_free_tx:
  75.621 +	gnttab_free_grant_references(np->gref_tx_head);
  75.622   exit:
  75.623 -	if (err != 0)
  75.624 -		kfree(netdev);
  75.625 -	else if (val != NULL)
  75.626 -		*val = netdev;
  75.627 -	return err;
  75.628 -
  75.629 - exit_free_grefs:
  75.630 -	gnttab_free_grant_references(np->gref_tx_head);
  75.631 -	gnttab_free_grant_references(np->gref_rx_head);
  75.632 -	goto exit;
  75.633 +	free_netdev(netdev);
  75.634 +	return ERR_PTR(err);
  75.635  }
  75.636  
  75.637  /*
  75.638 @@ -1245,7 +1365,7 @@ static void netfront_closing(struct xenb
  75.639  }
  75.640  
  75.641  
  75.642 -static int netfront_remove(struct xenbus_device *dev)
  75.643 +static int __devexit netfront_remove(struct xenbus_device *dev)
  75.644  {
  75.645  	struct netfront_info *info = dev->data;
  75.646  
  75.647 @@ -1260,16 +1380,9 @@ static int netfront_remove(struct xenbus
  75.648  
  75.649  static void close_netdev(struct netfront_info *info)
  75.650  {
  75.651 -	spin_lock_irq(&info->netdev->xmit_lock);
  75.652 -	netif_stop_queue(info->netdev);
  75.653 -	spin_unlock_irq(&info->netdev->xmit_lock);
  75.654 -
  75.655 -#ifdef CONFIG_PROC_FS
  75.656 -	xennet_proc_delif(info->netdev);
  75.657 -#endif
  75.658 -
  75.659  	del_timer_sync(&info->rx_refill_timer);
  75.660  
  75.661 +	xennet_sysfs_delif(info->netdev);
  75.662  	unregister_netdev(info->netdev);
  75.663  }
  75.664  
  75.665 @@ -1325,7 +1438,7 @@ static struct xenbus_driver netfront = {
  75.666  	.owner = THIS_MODULE,
  75.667  	.ids = netfront_ids,
  75.668  	.probe = netfront_probe,
  75.669 -	.remove = netfront_remove,
  75.670 +	.remove = __devexit_p(netfront_remove),
  75.671  	.resume = netfront_resume,
  75.672  	.otherend_changed = backend_changed,
  75.673  };
  75.674 @@ -1339,14 +1452,12 @@ static struct notifier_block notifier_in
  75.675  
  75.676  static int __init netif_init(void)
  75.677  {
  75.678 -	int err = 0;
  75.679 +	if (!is_running_on_xen())
  75.680 +		return -ENODEV;
  75.681  
  75.682  	if (xen_start_info->flags & SIF_INITDOMAIN)
  75.683  		return 0;
  75.684  
  75.685 -	if ((err = xennet_proc_init()) != 0)
  75.686 -		return err;
  75.687 -
  75.688  	IPRINTK("Initialising virtual ethernet driver.\n");
  75.689  
  75.690  	(void)register_inetaddr_notifier(&notifier_inetdev);
  75.691 @@ -1356,7 +1467,7 @@ static int __init netif_init(void)
  75.692  module_init(netif_init);
  75.693  
  75.694  
  75.695 -static void netif_exit(void)
  75.696 +static void __exit netif_exit(void)
  75.697  {
  75.698  	unregister_inetaddr_notifier(&notifier_inetdev);
  75.699  
  75.700 @@ -1365,167 +1476,3 @@ static void netif_exit(void)
  75.701  module_exit(netif_exit);
  75.702  
  75.703  MODULE_LICENSE("Dual BSD/GPL");
  75.704 -
  75.705 -
  75.706 -/* ** /proc **/
  75.707 -
  75.708 -
  75.709 -#ifdef CONFIG_PROC_FS
  75.710 -
  75.711 -#define TARGET_MIN 0UL
  75.712 -#define TARGET_MAX 1UL
  75.713 -#define TARGET_CUR 2UL
  75.714 -
  75.715 -static int xennet_proc_read(
  75.716 -	char *page, char **start, off_t off, int count, int *eof, void *data)
  75.717 -{
  75.718 -	struct net_device *dev =
  75.719 -		(struct net_device *)((unsigned long)data & ~3UL);
  75.720 -	struct netfront_info *np = netdev_priv(dev);
  75.721 -	int len = 0, which_target = (long)data & 3;
  75.722 -
  75.723 -	switch (which_target) {
  75.724 -	case TARGET_MIN:
  75.725 -		len = sprintf(page, "%d\n", np->rx_min_target);
  75.726 -		break;
  75.727 -	case TARGET_MAX:
  75.728 -		len = sprintf(page, "%d\n", np->rx_max_target);
  75.729 -		break;
  75.730 -	case TARGET_CUR:
  75.731 -		len = sprintf(page, "%d\n", np->rx_target);
  75.732 -		break;
  75.733 -	}
  75.734 -
  75.735 -	*eof = 1;
  75.736 -	return len;
  75.737 -}
  75.738 -
  75.739 -static int xennet_proc_write(
  75.740 -	struct file *file, const char __user *buffer,
  75.741 -	unsigned long count, void *data)
  75.742 -{
  75.743 -	struct net_device *dev =
  75.744 -		(struct net_device *)((unsigned long)data & ~3UL);
  75.745 -	struct netfront_info *np = netdev_priv(dev);
  75.746 -	int which_target = (long)data & 3;
  75.747 -	char string[64];
  75.748 -	long target;
  75.749 -
  75.750 -	if (!capable(CAP_SYS_ADMIN))
  75.751 -		return -EPERM;
  75.752 -
  75.753 -	if (count <= 1)
  75.754 -		return -EBADMSG; /* runt */
  75.755 -	if (count > sizeof(string))
  75.756 -		return -EFBIG;   /* too long */
  75.757 -
  75.758 -	if (copy_from_user(string, buffer, count))
  75.759 -		return -EFAULT;
  75.760 -	string[sizeof(string)-1] = '\0';
  75.761 -
  75.762 -	target = simple_strtol(string, NULL, 10);
  75.763 -	if (target < RX_MIN_TARGET)
  75.764 -		target = RX_MIN_TARGET;
  75.765 -	if (target > RX_MAX_TARGET)
  75.766 -		target = RX_MAX_TARGET;
  75.767 -
  75.768 -	spin_lock(&np->rx_lock);
  75.769 -
  75.770 -	switch (which_target) {
  75.771 -	case TARGET_MIN:
  75.772 -		if (target > np->rx_max_target)
  75.773 -			np->rx_max_target = target;
  75.774 -		np->rx_min_target = target;
  75.775 -		if (target > np->rx_target)
  75.776 -			np->rx_target = target;
  75.777 -		break;
  75.778 -	case TARGET_MAX:
  75.779 -		if (target < np->rx_min_target)
  75.780 -			np->rx_min_target = target;
  75.781 -		np->rx_max_target = target;
  75.782 -		if (target < np->rx_target)
  75.783 -			np->rx_target = target;
  75.784 -		break;
  75.785 -	case TARGET_CUR:
  75.786 -		break;
  75.787 -	}
  75.788 -
  75.789 -	network_alloc_rx_buffers(dev);
  75.790 -
  75.791 -	spin_unlock(&np->rx_lock);
  75.792 -
  75.793 -	return count;
  75.794 -}
  75.795 -
  75.796 -static int xennet_proc_init(void)
  75.797 -{
  75.798 -	if (proc_mkdir("xen/net", NULL) == NULL)
  75.799 -		return -ENOMEM;
  75.800 -	return 0;
  75.801 -}
  75.802 -
  75.803 -static int xennet_proc_addif(struct net_device *dev)
  75.804 -{
  75.805 -	struct proc_dir_entry *dir, *min, *max, *cur;
  75.806 -	char name[30];
  75.807 -
  75.808 -	sprintf(name, "xen/net/%s", dev->name);
  75.809 -
  75.810 -	dir = proc_mkdir(name, NULL);
  75.811 -	if (!dir)
  75.812 -		goto nomem;
  75.813 -
  75.814 -	min = create_proc_entry("rxbuf_min", 0644, dir);
  75.815 -	max = create_proc_entry("rxbuf_max", 0644, dir);
  75.816 -	cur = create_proc_entry("rxbuf_cur", 0444, dir);
  75.817 -	if (!min || !max || !cur)
  75.818 -		goto nomem;
  75.819 -
  75.820 -	min->read_proc  = xennet_proc_read;
  75.821 -	min->write_proc = xennet_proc_write;
  75.822 -	min->data       = (void *)((unsigned long)dev | TARGET_MIN);
  75.823 -
  75.824 -	max->read_proc  = xennet_proc_read;
  75.825 -	max->write_proc = xennet_proc_write;
  75.826 -	max->data       = (void *)((unsigned long)dev | TARGET_MAX);
  75.827 -
  75.828 -	cur->read_proc  = xennet_proc_read;
  75.829 -	cur->write_proc = xennet_proc_write;
  75.830 -	cur->data       = (void *)((unsigned long)dev | TARGET_CUR);
  75.831 -
  75.832 -	return 0;
  75.833 -
  75.834 - nomem:
  75.835 -	xennet_proc_delif(dev);
  75.836 -	return -ENOMEM;
  75.837 -}
  75.838 -
  75.839 -static void xennet_proc_delif(struct net_device *dev)
  75.840 -{
  75.841 -	char name[30];
  75.842 -
  75.843 -	sprintf(name, "xen/net/%s/rxbuf_min", dev->name);
  75.844 -	remove_proc_entry(name, NULL);
  75.845 -
  75.846 -	sprintf(name, "xen/net/%s/rxbuf_max", dev->name);
  75.847 -	remove_proc_entry(name, NULL);
  75.848 -
  75.849 -	sprintf(name, "xen/net/%s/rxbuf_cur", dev->name);
  75.850 -	remove_proc_entry(name, NULL);
  75.851 -
  75.852 -	sprintf(name, "xen/net/%s", dev->name);
  75.853 -	remove_proc_entry(name, NULL);
  75.854 -}
  75.855 -
  75.856 -#endif
  75.857 -
  75.858 -
  75.859 -/*
  75.860 - * Local variables:
  75.861 - *  c-file-style: "linux"
  75.862 - *  indent-tabs-mode: t
  75.863 - *  c-indent-level: 8
  75.864 - *  c-basic-offset: 8
  75.865 - *  tab-width: 8
  75.866 - * End:
  75.867 - */
    76.1 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Mon May 22 08:53:26 2006 -0600
    76.2 +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Mon May 22 14:13:38 2006 -0600
    76.3 @@ -271,6 +271,9 @@ static int capabilities_read(char *page,
    76.4  
    76.5  static int __init privcmd_init(void)
    76.6  {
    76.7 +	if (!is_running_on_xen())
    76.8 +		return -ENODEV;
    76.9 +
   76.10  	/* Set of hypercalls that privileged applications may execute. */
   76.11  	set_bit(__HYPERVISOR_acm_op,           hypercall_permission_map);
   76.12  	set_bit(__HYPERVISOR_dom0_op,          hypercall_permission_map);
   76.13 @@ -293,13 +296,3 @@ static int __init privcmd_init(void)
   76.14  }
   76.15  
   76.16  __initcall(privcmd_init);
   76.17 -
   76.18 -/*
   76.19 - * Local variables:
   76.20 - *  c-file-style: "linux"
   76.21 - *  indent-tabs-mode: t
   76.22 - *  c-indent-level: 8
   76.23 - *  c-basic-offset: 8
   76.24 - *  tab-width: 8
   76.25 - * End:
   76.26 - */
    77.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Mon May 22 08:53:26 2006 -0600
    77.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Mon May 22 14:13:38 2006 -0600
    77.3 @@ -45,8 +45,6 @@ typedef struct tpmif_st {
    77.4  	long int tpm_instance;
    77.5  	unsigned long mmap_vstart;
    77.6  
    77.7 -	struct work_struct work;
    77.8 -
    77.9  	grant_handle_t shmem_handle;
   77.10  	grant_ref_t shmem_ref;
   77.11  	struct page *pagerange;
   77.12 @@ -82,13 +80,3 @@ extern int num_frontends;
   77.13  #define MMAP_VADDR(t,_req) ((t)->mmap_vstart + ((_req) * PAGE_SIZE))
   77.14  
   77.15  #endif /* __TPMIF__BACKEND__COMMON_H__ */
   77.16 -
   77.17 -/*
   77.18 - * Local variables:
   77.19 - *  c-file-style: "linux"
   77.20 - *  indent-tabs-mode: t
   77.21 - *  c-indent-level: 8
   77.22 - *  c-basic-offset: 8
   77.23 - *  tab-width: 8
   77.24 - * End:
   77.25 - */
    78.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Mon May 22 08:53:26 2006 -0600
    78.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Mon May 22 14:13:38 2006 -0600
    78.3 @@ -152,10 +152,8 @@ int tpmif_map(tpmif_t *tpmif, unsigned l
    78.4  	return 0;
    78.5  }
    78.6  
    78.7 -static void __tpmif_disconnect_complete(void *arg)
    78.8 +void tpmif_disconnect_complete(tpmif_t *tpmif)
    78.9  {
   78.10 -	tpmif_t *tpmif = (tpmif_t *) arg;
   78.11 -
   78.12  	if (tpmif->irq)
   78.13  		unbind_from_irqhandler(tpmif->irq, tpmif);
   78.14  
   78.15 @@ -167,29 +165,13 @@ static void __tpmif_disconnect_complete(
   78.16  	free_tpmif(tpmif);
   78.17  }
   78.18  
   78.19 -void tpmif_disconnect_complete(tpmif_t * tpmif)
   78.20 -{
   78.21 -	INIT_WORK(&tpmif->work, __tpmif_disconnect_complete, (void *)tpmif);
   78.22 -	schedule_work(&tpmif->work);
   78.23 -}
   78.24 -
   78.25  void __init tpmif_interface_init(void)
   78.26  {
   78.27  	tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof (tpmif_t),
   78.28  					 0, 0, NULL, NULL);
   78.29  }
   78.30  
   78.31 -void __init tpmif_interface_exit(void)
   78.32 +void __exit tpmif_interface_exit(void)
   78.33  {
   78.34  	kmem_cache_destroy(tpmif_cachep);
   78.35  }
   78.36 -
   78.37 -/*
   78.38 - * Local variables:
   78.39 - *  c-file-style: "linux"
   78.40 - *  indent-tabs-mode: t
   78.41 - *  c-indent-level: 8
   78.42 - *  c-basic-offset: 8
   78.43 - *  tab-width: 8
   78.44 - * End:
   78.45 - */
    79.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Mon May 22 08:53:26 2006 -0600
    79.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Mon May 22 14:13:38 2006 -0600
    79.3 @@ -1063,7 +1063,7 @@ static int __init tpmback_init(void)
    79.4  
    79.5  module_init(tpmback_init);
    79.6  
    79.7 -static void __exit tpmback_exit(void)
    79.8 +void __exit tpmback_exit(void)
    79.9  {
   79.10  	vtpm_release_packets(NULL, 0);
   79.11  	tpmif_xenbus_exit();
   79.12 @@ -1071,16 +1071,4 @@ static void __exit tpmback_exit(void)
   79.13  	misc_deregister(&vtpms_miscdevice);
   79.14  }
   79.15  
   79.16 -module_exit(tpmback_exit);
   79.17 -
   79.18  MODULE_LICENSE("Dual BSD/GPL");
   79.19 -
   79.20 -/*
   79.21 - * Local variables:
   79.22 - *  c-file-style: "linux"
   79.23 - *  indent-tabs-mode: t
   79.24 - *  c-indent-level: 8
   79.25 - *  c-basic-offset: 8
   79.26 - *  tab-width: 8
   79.27 - * End:
   79.28 - */
    80.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Mon May 22 08:53:26 2006 -0600
    80.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Mon May 22 14:13:38 2006 -0600
    80.3 @@ -150,7 +150,7 @@ static void frontend_changed(struct xenb
    80.4  		break;
    80.5  
    80.6  	case XenbusStateClosing:
    80.7 -		xenbus_switch_state(dev, XenbusStateClosing);
    80.8 +		be->tpmif->tpm_instance = -1;
    80.9  		break;
   80.10  
   80.11  	case XenbusStateClosed:
   80.12 @@ -304,13 +304,3 @@ void tpmif_xenbus_exit(void)
   80.13  {
   80.14  	xenbus_unregister_driver(&tpmback);
   80.15  }
   80.16 -
   80.17 -/*
   80.18 - * Local variables:
   80.19 - *  c-file-style: "linux"
   80.20 - *  indent-tabs-mode: t
   80.21 - *  c-indent-level: 8
   80.22 - *  c-basic-offset: 8
   80.23 - *  tab-width: 8
   80.24 - * End:
   80.25 - */
    81.1 --- a/linux-2.6-xen-sparse/drivers/xen/util.c	Mon May 22 08:53:26 2006 -0600
    81.2 +++ b/linux-2.6-xen-sparse/drivers/xen/util.c	Mon May 22 14:13:38 2006 -0600
    81.3 @@ -68,13 +68,3 @@ void unlock_vm_area(struct vm_struct *ar
    81.4  	preempt_enable();
    81.5  }
    81.6  EXPORT_SYMBOL_GPL(unlock_vm_area);
    81.7 -
    81.8 -/*
    81.9 - * Local variables:
   81.10 - *  c-file-style: "linux"
   81.11 - *  indent-tabs-mode: t
   81.12 - *  c-indent-level: 8
   81.13 - *  c-basic-offset: 8
   81.14 - *  tab-width: 8
   81.15 - * End:
   81.16 - */
    82.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c	Mon May 22 08:53:26 2006 -0600
    82.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c	Mon May 22 14:13:38 2006 -0600
    82.3 @@ -133,13 +133,3 @@ int xenbus_unmap_ring(struct xenbus_devi
    82.4  EXPORT_SYMBOL_GPL(xenbus_unmap_ring);
    82.5  
    82.6  MODULE_LICENSE("Dual BSD/GPL");
    82.7 -
    82.8 -/*
    82.9 - * Local variables:
   82.10 - *  c-file-style: "linux"
   82.11 - *  indent-tabs-mode: t
   82.12 - *  c-indent-level: 8
   82.13 - *  c-basic-offset: 8
   82.14 - *  tab-width: 8
   82.15 - * End:
   82.16 - */
    83.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c	Mon May 22 08:53:26 2006 -0600
    83.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c	Mon May 22 14:13:38 2006 -0600
    83.3 @@ -279,14 +279,3 @@ XenbusState xenbus_read_driver_state(con
    83.4  	return result;
    83.5  }
    83.6  EXPORT_SYMBOL_GPL(xenbus_read_driver_state);
    83.7 -
    83.8 -
    83.9 -/*
   83.10 - * Local variables:
   83.11 - *  c-file-style: "linux"
   83.12 - *  indent-tabs-mode: t
   83.13 - *  c-indent-level: 8
   83.14 - *  c-basic-offset: 8
   83.15 - *  tab-width: 8
   83.16 - * End:
   83.17 - */
    84.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Mon May 22 08:53:26 2006 -0600
    84.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Mon May 22 14:13:38 2006 -0600
    84.3 @@ -206,13 +206,3 @@ int xb_init_comms(void)
    84.4  
    84.5  	return 0;
    84.6  }
    84.7 -
    84.8 -/*
    84.9 - * Local variables:
   84.10 - *  c-file-style: "linux"
   84.11 - *  indent-tabs-mode: t
   84.12 - *  c-indent-level: 8
   84.13 - *  c-basic-offset: 8
   84.14 - *  tab-width: 8
   84.15 - * End:
   84.16 - */
    85.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h	Mon May 22 08:53:26 2006 -0600
    85.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h	Mon May 22 14:13:38 2006 -0600
    85.3 @@ -41,13 +41,3 @@ int xs_input_avail(void);
    85.4  extern wait_queue_head_t xb_waitq;
    85.5  
    85.6  #endif /* _XENBUS_COMMS_H */
    85.7 -
    85.8 -/*
    85.9 - * Local variables:
   85.10 - *  c-file-style: "linux"
   85.11 - *  indent-tabs-mode: t
   85.12 - *  c-indent-level: 8
   85.13 - *  c-basic-offset: 8
   85.14 - *  tab-width: 8
   85.15 - * End:
   85.16 - */
    86.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c	Mon May 22 08:53:26 2006 -0600
    86.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c	Mon May 22 14:13:38 2006 -0600
    86.3 @@ -243,13 +243,3 @@ xenbus_dev_init(void)
    86.4  }
    86.5  
    86.6  __initcall(xenbus_dev_init);
    86.7 -
    86.8 -/*
    86.9 - * Local variables:
   86.10 - *  c-file-style: "linux"
   86.11 - *  indent-tabs-mode: t
   86.12 - *  c-indent-level: 8
   86.13 - *  c-basic-offset: 8
   86.14 - *  tab-width: 8
   86.15 - * End:
   86.16 - */
    87.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Mon May 22 08:53:26 2006 -0600
    87.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Mon May 22 14:13:38 2006 -0600
    87.3 @@ -966,10 +966,8 @@ static int __init xenbus_probe_init(void
    87.4  
    87.5  	DPRINTK("");
    87.6  
    87.7 -	if (xen_init() < 0) {
    87.8 -		DPRINTK("failed");
    87.9 +	if (!is_running_on_xen())
   87.10  		return -ENODEV;
   87.11 -	}
   87.12  
   87.13  	/* Register ourselves with the kernel bus subsystem */
   87.14  	bus_register(&xenbus_frontend.bus);
   87.15 @@ -1069,10 +1067,8 @@ static int __init wait_for_devices(void)
   87.16  {
   87.17  	unsigned long timeout = jiffies + 10*HZ;
   87.18  
   87.19 -	if (xen_init() < 0) {
   87.20 -		DPRINTK("failed");
   87.21 +	if (!is_running_on_xen())
   87.22  		return -ENODEV;
   87.23 -	}
   87.24  
   87.25  	while (time_before(jiffies, timeout)) {
   87.26  		if (all_devices_ready())
   87.27 @@ -1085,14 +1081,3 @@ static int __init wait_for_devices(void)
   87.28  }
   87.29  
   87.30  late_initcall(wait_for_devices);
   87.31 -
   87.32 -
   87.33 -/*
   87.34 - * Local variables:
   87.35 - *  c-file-style: "linux"
   87.36 - *  indent-tabs-mode: t
   87.37 - *  c-indent-level: 8
   87.38 - *  c-basic-offset: 8
   87.39 - *  tab-width: 8
   87.40 - * End:
   87.41 - */
    88.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Mon May 22 08:53:26 2006 -0600
    88.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Mon May 22 14:13:38 2006 -0600
    88.3 @@ -844,13 +844,3 @@ int xs_init(void)
    88.4  
    88.5  	return 0;
    88.6  }
    88.7 -
    88.8 -/*
    88.9 - * Local variables:
   88.10 - *  c-file-style: "linux"
   88.11 - *  indent-tabs-mode: t
   88.12 - *  c-indent-level: 8
   88.13 - *  c-basic-offset: 8
   88.14 - *  tab-width: 8
   88.15 - * End:
   88.16 - */
    89.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h	Mon May 22 08:53:26 2006 -0600
    89.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h	Mon May 22 14:13:38 2006 -0600
    89.3 @@ -361,13 +361,3 @@ HYPERVISOR_xenoprof_op(
    89.4  
    89.5  
    89.6  #endif /* __HYPERCALL_H__ */
    89.7 -
    89.8 -/*
    89.9 - * Local variables:
   89.10 - *  c-file-style: "linux"
   89.11 - *  indent-tabs-mode: t
   89.12 - *  c-indent-level: 8
   89.13 - *  c-basic-offset: 8
   89.14 - *  tab-width: 8
   89.15 - * End:
   89.16 - */
    90.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h	Mon May 22 08:53:26 2006 -0600
    90.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h	Mon May 22 14:13:38 2006 -0600
    90.3 @@ -118,7 +118,7 @@ u64 jiffies_to_st(unsigned long jiffies)
    90.4  #define MULTI_UVMDOMID_INDEX 4
    90.5  #endif
    90.6  
    90.7 -#define xen_init()	(0)
    90.8 +#define is_running_on_xen() 1
    90.9  
   90.10  static inline int
   90.11  HYPERVISOR_yield(
    91.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h	Mon May 22 08:53:26 2006 -0600
    91.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h	Mon May 22 14:13:38 2006 -0600
    91.3 @@ -289,9 +289,10 @@ extern int page_is_ram(unsigned long pag
    91.4  #endif
    91.5  #define __KERNEL_START		(__PAGE_OFFSET + __PHYSICAL_START)
    91.6  
    91.7 +#ifdef CONFIG_XEN_COMPAT_030002
    91.8  #undef LOAD_OFFSET
    91.9  #define LOAD_OFFSET		0
   91.10 -
   91.11 +#endif /* CONFIG_XEN_COMPAT_030002 */
   91.12  
   91.13  #define PAGE_OFFSET		((unsigned long)__PAGE_OFFSET)
   91.14  #define VMALLOC_RESERVE		((unsigned long)__VMALLOC_RESERVE)
    92.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/setup_arch_post.h	Mon May 22 08:53:26 2006 -0600
    92.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/setup_arch_post.h	Mon May 22 14:13:38 2006 -0600
    92.3 @@ -10,10 +10,32 @@
    92.4  
    92.5  static char * __init machine_specific_memory_setup(void)
    92.6  {
    92.7 -	unsigned long max_pfn = xen_start_info->nr_pages;
    92.8 +	int rc;
    92.9 +	struct xen_memory_map memmap;
   92.10 +	/*
   92.11 +	 * This is rather large for a stack variable but this early in
   92.12 +	 * the boot process we know we have plenty slack space.
   92.13 +	 */
   92.14 +	struct e820entry map[E820MAX];
   92.15 +
   92.16 +	memmap.nr_entries = E820MAX;
   92.17 +	set_xen_guest_handle(memmap.buffer, map);
   92.18  
   92.19 -	e820.nr_map = 0;
   92.20 -	add_memory_region(0, PFN_PHYS(max_pfn), E820_RAM);
   92.21 +	rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
   92.22 +	if ( rc == -ENOSYS ) {
   92.23 +		memmap.nr_entries = 1;
   92.24 +		map[0].addr = 0ULL;
   92.25 +		map[0].size = xen_start_info->nr_pages << PAGE_SHIFT;
   92.26 +		/* 8MB slack (to balance backend allocations). */
   92.27 +		map[0].size += 8 << 20;
   92.28 +		map[0].type = E820_RAM;
   92.29 +		rc = 0;
   92.30 +	}
   92.31 +	BUG_ON(rc);
   92.32 +
   92.33 +	sanitize_e820_map(map, (char *)&memmap.nr_entries);
   92.34 +
   92.35 +	BUG_ON(copy_e820_map(map, (char)memmap.nr_entries) < 0);
   92.36  
   92.37  	return "Xen";
   92.38  }
    93.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h	Mon May 22 08:53:26 2006 -0600
    93.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h	Mon May 22 14:13:38 2006 -0600
    93.3 @@ -53,7 +53,7 @@ extern start_info_t *xen_start_info;
    93.4  
    93.5  void force_evtchn_callback(void);
    93.6  
    93.7 -int xen_init(void);
    93.8 +#define is_running_on_xen() running_on_xen
    93.9  
   93.10  /* Turn jiffies into Xen system time. XXX Implement me. */
   93.11  #define jiffies_to_st(j)	0
   93.12 @@ -158,7 +158,7 @@ xen_create_contiguous_region(unsigned lo
   93.13                               unsigned int order, unsigned int address_bits)
   93.14  {
   93.15  	int ret = 0;
   93.16 -	if (running_on_xen) {
   93.17 +	if (is_running_on_xen()) {
   93.18  		ret = __xen_create_contiguous_region(vstart, order,
   93.19  		                                     address_bits);
   93.20  	}
   93.21 @@ -169,7 +169,7 @@ void __xen_destroy_contiguous_region(uns
   93.22  static inline void
   93.23  xen_destroy_contiguous_region(unsigned long vstart, unsigned int order)
   93.24  {
   93.25 -	if (running_on_xen)
   93.26 +	if (is_running_on_xen())
   93.27  		__xen_destroy_contiguous_region(vstart, order);
   93.28  }
   93.29  
    94.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/xen/privop.h	Mon May 22 08:53:26 2006 -0600
    94.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/xen/privop.h	Mon May 22 14:13:38 2006 -0600
    94.3 @@ -42,12 +42,7 @@
    94.4  #endif
    94.5  
    94.6  #ifndef __ASSEMBLY__
    94.7 -#ifdef MODULE
    94.8 -extern int is_running_on_xen(void);
    94.9 -#define running_on_xen (is_running_on_xen())
   94.10 -#else
   94.11  extern int running_on_xen;
   94.12 -#endif
   94.13  
   94.14  #define	XEN_HYPER_SSM_I		asm("break %0" : : "i" (HYPERPRIVOP_SSM_I))
   94.15  #define	XEN_HYPER_GET_IVR	asm("break %0" : : "i" (HYPERPRIVOP_GET_IVR))
    95.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    95.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/e820.h	Mon May 22 14:13:38 2006 -0600
    95.3 @@ -0,0 +1,63 @@
    95.4 +/*
    95.5 + * structures and definitions for the int 15, ax=e820 memory map
    95.6 + * scheme.
    95.7 + *
    95.8 + * In a nutshell, setup.S populates a scratch table in the
    95.9 + * empty_zero_block that contains a list of usable address/size
   95.10 + * duples.  setup.c, this information is transferred into the e820map,
   95.11 + * and in init.c/numa.c, that new information is used to mark pages
   95.12 + * reserved or not.
   95.13 + */
   95.14 +#ifndef __E820_HEADER
   95.15 +#define __E820_HEADER
   95.16 +
   95.17 +#include <linux/mmzone.h>
   95.18 +
   95.19 +#define E820MAP	0x2d0		/* our map */
   95.20 +#define E820MAX	128		/* number of entries in E820MAP */
   95.21 +#define E820NR	0x1e8		/* # entries in E820MAP */
   95.22 +
   95.23 +#define E820_RAM	1
   95.24 +#define E820_RESERVED	2
   95.25 +#define E820_ACPI	3 /* usable as RAM once ACPI tables have been read */
   95.26 +#define E820_NVS	4
   95.27 +
   95.28 +#define HIGH_MEMORY	(1024*1024)
   95.29 +
   95.30 +#define LOWMEMSIZE()	(0x9f000)
   95.31 +
   95.32 +#ifndef __ASSEMBLY__
   95.33 +struct e820entry {
   95.34 +	u64 addr;	/* start of memory segment */
   95.35 +	u64 size;	/* size of memory segment */
   95.36 +	u32 type;	/* type of memory segment */
   95.37 +} __attribute__((packed));
   95.38 +
   95.39 +struct e820map {
   95.40 +    int nr_map;
   95.41 +	struct e820entry map[E820MAX];
   95.42 +};
   95.43 +
   95.44 +extern unsigned long find_e820_area(unsigned long start, unsigned long end, 
   95.45 +				    unsigned size);
   95.46 +extern void add_memory_region(unsigned long start, unsigned long size, 
   95.47 +			      int type);
   95.48 +extern void setup_memory_region(void);
   95.49 +extern void contig_e820_setup(void); 
   95.50 +extern unsigned long e820_end_of_ram(void);
   95.51 +extern void e820_reserve_resources(struct e820entry *e820, int nr_map);
   95.52 +extern void e820_print_map(char *who);
   95.53 +extern int e820_mapped(unsigned long start, unsigned long end, unsigned type);
   95.54 +
   95.55 +extern void e820_bootmem_free(pg_data_t *pgdat, unsigned long start,unsigned long end);
   95.56 +extern void e820_setup_gap(struct e820entry *e820, int nr_map);
   95.57 +extern unsigned long e820_hole_size(unsigned long start_pfn,
   95.58 +				    unsigned long end_pfn);
   95.59 +
   95.60 +extern void __init parse_memopt(char *p, char **end);
   95.61 +extern void __init parse_memmapopt(char *p, char **end);
   95.62 +
   95.63 +extern struct e820map e820;
   95.64 +#endif/*!__ASSEMBLY__*/
   95.65 +
   95.66 +#endif/*__E820_HEADER*/
    96.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h	Mon May 22 08:53:26 2006 -0600
    96.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h	Mon May 22 14:13:38 2006 -0600
    96.3 @@ -355,19 +355,9 @@ HYPERVISOR_callback_op(
    96.4  
    96.5  static inline int
    96.6  HYPERVISOR_xenoprof_op(
    96.7 -	int op, unsigned long arg1, unsigned long arg2)
    96.8 +	int op, void *arg)
    96.9  {
   96.10 -	return _hypercall3(int, xenoprof_op, op, arg1, arg2);
   96.11 +	return _hypercall2(int, xenoprof_op, op, arg);
   96.12  }
   96.13  
   96.14  #endif /* __HYPERCALL_H__ */
   96.15 -
   96.16 -/*
   96.17 - * Local variables:
   96.18 - *  c-file-style: "linux"
   96.19 - *  indent-tabs-mode: t
   96.20 - *  c-indent-level: 8
   96.21 - *  c-basic-offset: 8
   96.22 - *  tab-width: 8
   96.23 - * End:
   96.24 - */
    97.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h	Mon May 22 08:53:26 2006 -0600
    97.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h	Mon May 22 14:13:38 2006 -0600
    97.3 @@ -260,8 +260,10 @@ static inline pgd_t __pgd(unsigned long 
    97.4  #define __PAGE_OFFSET           0xffff880000000000
    97.5  #endif /* !__ASSEMBLY__ */
    97.6  
    97.7 +#ifdef CONFIG_XEN_COMPAT_030002
    97.8  #undef LOAD_OFFSET
    97.9  #define LOAD_OFFSET		0
   97.10 +#endif /* CONFIG_XEN_COMPAT_030002 */
   97.11  
   97.12  /* to align the pointer to the (next) page boundary */
   97.13  #define PAGE_ALIGN(addr)	(((addr)+PAGE_SIZE-1)&PAGE_MASK)
    98.1 --- a/linux-2.6-xen-sparse/include/xen/balloon.h	Mon May 22 08:53:26 2006 -0600
    98.2 +++ b/linux-2.6-xen-sparse/include/xen/balloon.h	Mon May 22 14:13:38 2006 -0600
    98.3 @@ -61,13 +61,3 @@ extern spinlock_t balloon_lock;
    98.4  #define balloon_unlock(__flags) spin_unlock_irqrestore(&balloon_lock, __flags)
    98.5  
    98.6  #endif /* __ASM_BALLOON_H__ */
    98.7 -
    98.8 -/*
    98.9 - * Local variables:
   98.10 - *  c-file-style: "linux"
   98.11 - *  indent-tabs-mode: t
   98.12 - *  c-indent-level: 8
   98.13 - *  c-basic-offset: 8
   98.14 - *  tab-width: 8
   98.15 - * End:
   98.16 - */
    99.1 --- a/linux-2.6-xen-sparse/include/xen/driver_util.h	Mon May 22 08:53:26 2006 -0600
    99.2 +++ b/linux-2.6-xen-sparse/include/xen/driver_util.h	Mon May 22 14:13:38 2006 -0600
    99.3 @@ -14,13 +14,3 @@ extern void lock_vm_area(struct vm_struc
    99.4  extern void unlock_vm_area(struct vm_struct *area);
    99.5  
    99.6  #endif /* __ASM_XEN_DRIVER_UTIL_H__ */
    99.7 -
    99.8 -/*
    99.9 - * Local variables:
   99.10 - *  c-file-style: "linux"
   99.11 - *  indent-tabs-mode: t
   99.12 - *  c-indent-level: 8
   99.13 - *  c-basic-offset: 8
   99.14 - *  tab-width: 8
   99.15 - * End:
   99.16 - */
   100.1 --- a/linux-2.6-xen-sparse/include/xen/evtchn.h	Mon May 22 08:53:26 2006 -0600
   100.2 +++ b/linux-2.6-xen-sparse/include/xen/evtchn.h	Mon May 22 14:13:38 2006 -0600
   100.3 @@ -112,13 +112,3 @@ static inline void notify_remote_via_evt
   100.4  extern void notify_remote_via_irq(int irq);
   100.5  
   100.6  #endif /* __ASM_EVTCHN_H__ */
   100.7 -
   100.8 -/*
   100.9 - * Local variables:
  100.10 - *  c-file-style: "linux"
  100.11 - *  indent-tabs-mode: t
  100.12 - *  c-indent-level: 8
  100.13 - *  c-basic-offset: 8
  100.14 - *  tab-width: 8
  100.15 - * End:
  100.16 - */
   101.1 --- a/linux-2.6-xen-sparse/include/xen/foreign_page.h	Mon May 22 08:53:26 2006 -0600
   101.2 +++ b/linux-2.6-xen-sparse/include/xen/foreign_page.h	Mon May 22 14:13:38 2006 -0600
   101.3 @@ -28,13 +28,3 @@
   101.4  	( (void (*) (struct page *)) (page)->mapping )
   101.5  
   101.6  #endif /* __ASM_XEN_FOREIGN_PAGE_H__ */
   101.7 -
   101.8 -/*
   101.9 - * Local variables:
  101.10 - *  c-file-style: "linux"
  101.11 - *  indent-tabs-mode: t
  101.12 - *  c-indent-level: 8
  101.13 - *  c-basic-offset: 8
  101.14 - *  tab-width: 8
  101.15 - * End:
  101.16 - */
   102.1 --- a/linux-2.6-xen-sparse/include/xen/gnttab.h	Mon May 22 08:53:26 2006 -0600
   102.2 +++ b/linux-2.6-xen-sparse/include/xen/gnttab.h	Mon May 22 14:13:38 2006 -0600
   102.3 @@ -148,13 +148,3 @@ gnttab_set_unmap_op(struct gnttab_unmap_
   102.4  }
   102.5  
   102.6  #endif /* __ASM_GNTTAB_H__ */
   102.7 -
   102.8 -/*
   102.9 - * Local variables:
  102.10 - *  c-file-style: "linux"
  102.11 - *  indent-tabs-mode: t
  102.12 - *  c-indent-level: 8
  102.13 - *  c-basic-offset: 8
  102.14 - *  tab-width: 8
  102.15 - * End:
  102.16 - */
   103.1 --- a/linux-2.6-xen-sparse/include/xen/net_driver_util.h	Mon May 22 08:53:26 2006 -0600
   103.2 +++ b/linux-2.6-xen-sparse/include/xen/net_driver_util.h	Mon May 22 14:13:38 2006 -0600
   103.3 @@ -46,13 +46,3 @@ int xen_net_read_mac(struct xenbus_devic
   103.4  
   103.5  
   103.6  #endif /* _ASM_XEN_NET_DRIVER_UTIL_H */
   103.7 -
   103.8 -/*
   103.9 - * Local variables:
  103.10 - *  c-file-style: "linux"
  103.11 - *  indent-tabs-mode: t
  103.12 - *  c-indent-level: 8
  103.13 - *  c-basic-offset: 8
  103.14 - *  tab-width: 8
  103.15 - * End:
  103.16 - */
   104.1 --- a/linux-2.6-xen-sparse/include/xen/public/evtchn.h	Mon May 22 08:53:26 2006 -0600
   104.2 +++ b/linux-2.6-xen-sparse/include/xen/public/evtchn.h	Mon May 22 14:13:38 2006 -0600
   104.3 @@ -89,13 +89,3 @@ struct ioctl_evtchn_notify {
   104.4  	_IOC(_IOC_NONE, 'E', 5, 0)
   104.5  
   104.6  #endif /* __LINUX_PUBLIC_EVTCHN_H__ */
   104.7 -
   104.8 -/*
   104.9 - * Local variables:
  104.10 - *  c-file-style: "linux"
  104.11 - *  indent-tabs-mode: t
  104.12 - *  c-indent-level: 8
  104.13 - *  c-basic-offset: 8
  104.14 - *  tab-width: 8
  104.15 - * End:
  104.16 - */
   105.1 --- a/linux-2.6-xen-sparse/include/xen/public/privcmd.h	Mon May 22 08:53:26 2006 -0600
   105.2 +++ b/linux-2.6-xen-sparse/include/xen/public/privcmd.h	Mon May 22 14:13:38 2006 -0600
   105.3 @@ -75,13 +75,3 @@ typedef struct privcmd_mmapbatch {
   105.4  	_IOC(_IOC_NONE, 'P', 3, sizeof(privcmd_mmapbatch_t))
   105.5  
   105.6  #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
   105.7 -
   105.8 -/*
   105.9 - * Local variables:
  105.10 - *  c-file-style: "linux"
  105.11 - *  indent-tabs-mode: t
  105.12 - *  c-indent-level: 8
  105.13 - *  c-basic-offset: 8
  105.14 - *  tab-width: 8
  105.15 - * End:
  105.16 - */
   106.1 --- a/linux-2.6-xen-sparse/include/xen/xen_proc.h	Mon May 22 08:53:26 2006 -0600
   106.2 +++ b/linux-2.6-xen-sparse/include/xen/xen_proc.h	Mon May 22 14:13:38 2006 -0600
   106.3 @@ -11,13 +11,3 @@ extern void remove_xen_proc_entry(
   106.4  	const char *name);
   106.5  
   106.6  #endif /* __ASM_XEN_PROC_H__ */
   106.7 -
   106.8 -/*
   106.9 - * Local variables:
  106.10 - *  c-file-style: "linux"
  106.11 - *  indent-tabs-mode: t
  106.12 - *  c-indent-level: 8
  106.13 - *  c-basic-offset: 8
  106.14 - *  tab-width: 8
  106.15 - * End:
  106.16 - */
   107.1 --- a/linux-2.6-xen-sparse/include/xen/xenbus.h	Mon May 22 08:53:26 2006 -0600
   107.2 +++ b/linux-2.6-xen-sparse/include/xen/xenbus.h	Mon May 22 14:13:38 2006 -0600
   107.3 @@ -294,13 +294,3 @@ void xenbus_dev_fatal(struct xenbus_devi
   107.4  
   107.5  
   107.6  #endif /* _XEN_XENBUS_H */
   107.7 -
   107.8 -/*
   107.9 - * Local variables:
  107.10 - *  c-file-style: "linux"
  107.11 - *  indent-tabs-mode: t
  107.12 - *  c-indent-level: 8
  107.13 - *  c-basic-offset: 8
  107.14 - *  tab-width: 8
  107.15 - * End:
  107.16 - */
   108.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   108.2 +++ b/patches/linux-2.6.16.13/xen-hotplug.patch	Mon May 22 14:13:38 2006 -0600
   108.3 @@ -0,0 +1,11 @@
   108.4 +--- ../pristine-linux-2.6.16.13/fs/proc/proc_misc.c	2006-05-02 22:38:44.000000000 +0100
   108.5 ++++ ./fs/proc/proc_misc.c	2006-05-22 15:29:34.000000000 +0100
   108.6 +@@ -433,7 +433,7 @@ static int show_stat(struct seq_file *p,
   108.7 + 		(unsigned long long)cputime64_to_clock_t(irq),
   108.8 + 		(unsigned long long)cputime64_to_clock_t(softirq),
   108.9 + 		(unsigned long long)cputime64_to_clock_t(steal));
  108.10 +-	for_each_online_cpu(i) {
  108.11 ++	for_each_cpu(i) {
  108.12 + 
  108.13 + 		/* Copy values here to work around gcc-2.95.3, gcc-2.96 */
  108.14 + 		user = kstat_cpu(i).cpustat.user;
   109.1 --- a/patches/linux-2.6.16.13/xenoprof-generic.patch	Mon May 22 08:53:26 2006 -0600
   109.2 +++ b/patches/linux-2.6.16.13/xenoprof-generic.patch	Mon May 22 14:13:38 2006 -0600
   109.3 @@ -225,19 +225,21 @@ diff -pruN ../pristine-linux-2.6.16.13/d
   109.4   struct oprofile_operations oprofile_ops;
   109.5   
   109.6   unsigned long oprofile_started;
   109.7 -@@ -33,6 +37,17 @@ static DECLARE_MUTEX(start_sem);
   109.8 +@@ -33,6 +37,19 @@ static DECLARE_MUTEX(start_sem);
   109.9    */
  109.10   static int timer = 0;
  109.11   
  109.12 -+extern unsigned int adomains;
  109.13 -+extern int active_domains[MAX_OPROF_DOMAINS];
  109.14 -+
  109.15 -+int oprofile_set_active(void)
  109.16 ++int oprofile_set_active(int active_domains[], unsigned int adomains)
  109.17  +{
  109.18 -+	if (oprofile_ops.set_active)
  109.19 -+		return oprofile_ops.set_active(active_domains, adomains);
  109.20 ++	int err;
  109.21 ++
  109.22 ++	if (!oprofile_ops.set_active)
  109.23 ++		return -EINVAL;
  109.24  +
  109.25 -+	return -EINVAL;
  109.26 ++	down(&start_sem);
  109.27 ++	err = oprofile_ops.set_active(active_domains, adomains);
  109.28 ++	up(&start_sem);
  109.29 ++	return err;
  109.30  +}
  109.31  +
  109.32   int oprofile_setup(void)
  109.33 @@ -251,7 +253,7 @@ diff -pruN ../pristine-linux-2.6.16.13/d
  109.34   
  109.35   int oprofile_set_backtrace(unsigned long depth);
  109.36  +
  109.37 -+int oprofile_set_active(void);
  109.38 ++int oprofile_set_active(int active_domains[], unsigned int adomains);
  109.39    
  109.40   #endif /* OPROF_H */
  109.41  diff -pruN ../pristine-linux-2.6.16.13/drivers/oprofile/oprofile_files.c ./drivers/oprofile/oprofile_files.c
  109.42 @@ -280,7 +282,7 @@ diff -pruN ../pristine-linux-2.6.16.13/d
  109.43   unsigned long fs_buffer_size = 131072;
  109.44   unsigned long fs_cpu_buffer_size = 8192;
  109.45   unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
  109.46 -@@ -117,11 +123,79 @@ static ssize_t dump_write(struct file * 
  109.47 +@@ -117,11 +123,108 @@ static ssize_t dump_write(struct file * 
  109.48   static struct file_operations dump_fops = {
  109.49   	.write		= dump_write,
  109.50   };
  109.51 @@ -288,63 +290,92 @@ diff -pruN ../pristine-linux-2.6.16.13/d
  109.52  +
  109.53  +#define TMPBUFSIZE 512
  109.54  +
  109.55 -+unsigned int adomains = 0;
  109.56 -+long active_domains[MAX_OPROF_DOMAINS];
  109.57 ++static unsigned int adomains = 0;
  109.58 ++static int active_domains[MAX_OPROF_DOMAINS + 1];
  109.59 ++static DEFINE_MUTEX(adom_mutex);
  109.60  +
  109.61  +static ssize_t adomain_write(struct file * file, char const __user * buf, 
  109.62  +			     size_t count, loff_t * offset)
  109.63  +{
  109.64 -+	char tmpbuf[TMPBUFSIZE];
  109.65 -+	char * startp = tmpbuf;
  109.66 -+	char * endp = tmpbuf;
  109.67 ++	char *tmpbuf;
  109.68 ++	char *startp, *endp;
  109.69  +	int i;
  109.70  +	unsigned long val;
  109.71 ++	ssize_t retval = count;
  109.72  +	
  109.73  +	if (*offset)
  109.74  +		return -EINVAL;	
  109.75 -+	if (!count)
  109.76 -+		return 0;
  109.77  +	if (count > TMPBUFSIZE - 1)
  109.78  +		return -EINVAL;
  109.79  +
  109.80 -+	memset(tmpbuf, 0x0, TMPBUFSIZE);
  109.81 ++	if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
  109.82 ++		return -ENOMEM;
  109.83  +
  109.84 -+	if (copy_from_user(tmpbuf, buf, count))
  109.85 ++	if (copy_from_user(tmpbuf, buf, count)) {
  109.86 ++		kfree(tmpbuf);
  109.87  +		return -EFAULT;
  109.88 -+	
  109.89 -+	for (i = 0; i < MAX_OPROF_DOMAINS; i++)
  109.90 -+		active_domains[i] = -1;
  109.91 -+	adomains = 0;
  109.92 ++	}
  109.93 ++	tmpbuf[count] = 0;
  109.94 ++
  109.95 ++	mutex_lock(&adom_mutex);
  109.96  +
  109.97 -+	while (1) {
  109.98 -+		val = simple_strtol(startp, &endp, 0);
  109.99 ++	startp = tmpbuf;
 109.100 ++	/* Parse one more than MAX_OPROF_DOMAINS, for easy error checking */
 109.101 ++	for (i = 0; i <= MAX_OPROF_DOMAINS; i++) {
 109.102 ++		val = simple_strtoul(startp, &endp, 0);
 109.103  +		if (endp == startp)
 109.104  +			break;
 109.105 -+		while (ispunct(*endp))
 109.106 ++		while (ispunct(*endp) || isspace(*endp))
 109.107  +			endp++;
 109.108 -+		active_domains[adomains++] = val;
 109.109 -+		if (adomains >= MAX_OPROF_DOMAINS)
 109.110 -+			break;
 109.111 ++		active_domains[i] = val;
 109.112 ++		if (active_domains[i] != val)
 109.113 ++			/* Overflow, force error below */
 109.114 ++			i = MAX_OPROF_DOMAINS + 1;
 109.115  +		startp = endp;
 109.116  +	}
 109.117 -+	if (oprofile_set_active())
 109.118 -+		return -EINVAL; 
 109.119 -+	return count;
 109.120 ++	/* Force error on trailing junk */
 109.121 ++	adomains = *startp ? MAX_OPROF_DOMAINS + 1 : i;
 109.122 ++
 109.123 ++	kfree(tmpbuf);
 109.124 ++
 109.125 ++	if (adomains > MAX_OPROF_DOMAINS
 109.126 ++	    || oprofile_set_active(active_domains, adomains)) {
 109.127 ++		adomains = 0;
 109.128 ++		retval = -EINVAL;
 109.129 ++	}
 109.130 ++
 109.131 ++	mutex_unlock(&adom_mutex);
 109.132 ++	return retval;
 109.133  +}
 109.134  +
 109.135  +static ssize_t adomain_read(struct file * file, char __user * buf, 
 109.136  +			    size_t count, loff_t * offset)
 109.137  +{
 109.138 -+	char tmpbuf[TMPBUFSIZE];
 109.139 -+	size_t len = 0;
 109.140 ++	char * tmpbuf;
 109.141 ++	size_t len;
 109.142  +	int i;
 109.143 -+	/* This is all screwed up if we run out of space */
 109.144 -+	for (i = 0; i < adomains; i++) 
 109.145 -+		len += snprintf(tmpbuf + len, TMPBUFSIZE - len, 
 109.146 -+				"%u ", (unsigned int)active_domains[i]);
 109.147 -+	len += snprintf(tmpbuf + len, TMPBUFSIZE - len, "\n");
 109.148 -+	return simple_read_from_buffer((void __user *)buf, count, 
 109.149 -+				       offset, tmpbuf, len);
 109.150 ++	ssize_t retval;
 109.151 ++
 109.152 ++	if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
 109.153 ++		return -ENOMEM;
 109.154 ++
 109.155 ++	mutex_lock(&adom_mutex);
 109.156 ++
 109.157 ++	len = 0;
 109.158 ++	for (i = 0; i < adomains; i++)
 109.159 ++		len += snprintf(tmpbuf + len,
 109.160 ++				len < TMPBUFSIZE ? TMPBUFSIZE - len : 0,
 109.161 ++				"%u ", active_domains[i]);
 109.162 ++	WARN_ON(len > TMPBUFSIZE);
 109.163 ++	if (len != 0 && len <= TMPBUFSIZE)
 109.164 ++		tmpbuf[len-1] = '\n';
 109.165 ++
 109.166 ++	mutex_unlock(&adom_mutex);
 109.167 ++
 109.168 ++	retval = simple_read_from_buffer(buf, count, offset, tmpbuf, len);
 109.169 ++
 109.170 ++	kfree(tmpbuf);
 109.171 ++	return retval;
 109.172  +}
 109.173  +
 109.174  +
   110.1 --- a/tools/examples/README	Mon May 22 08:53:26 2006 -0600
   110.2 +++ b/tools/examples/README	Mon May 22 14:13:38 2006 -0600
   110.3 @@ -13,6 +13,10 @@ block               - called by xen-back
   110.4  block-common.sh     - sourced by block, block-*
   110.5  block-enbd          - binds/unbinds network block devices
   110.6  block-nbd           - binds/unbinds network block devices
   110.7 +external-device-migrate - called by xend for migrating external devices
   110.8 +locking.sh          - locking functions to prevent concurrent access to
   110.9 +                      critical sections inside script files
  110.10 +logging.sh          - logging function to log output using syslog
  110.11  network-bridge      - xen network start/stop script when using bridging
  110.12  network-nat         - xen network start/stop script when using NAT
  110.13  network-route       - xen network start/stop script when using routing
  110.14 @@ -20,7 +24,14 @@ vif-bridge          - virtual network st
  110.15  vif-common.sh       - sourced by vif-bridge 
  110.16  vif-nat             - xen virtual network start/stop script in NAT mode 
  110.17  vif-route           - xen virtual network start/stop script in routed mode
  110.18 -xen-backend.agent   - calls block, vif-* scripts to add, remove, hotplug 
  110.19 +vtpm                - called by xen-backend.agent to bind/unbind vTPM devices
  110.20 +vtpm-addtodb        - script for adding a vTPM instance to the vTPM table
  110.21 +vtpm-common.sh      - common code for vTPM handling
  110.22 +vtpm-delete         - remove an entry from the vTPM table given the
  110.23 +                      domain's name
  110.24 +vtpm-hotplug-common.sh - sourced by vtpm
  110.25 +vtpm-migration.sh   - sourced by external-device-migrate
  110.26 +xen-backend.agent   - calls block, vif-*, vtpm scripts to add, remove, hotplug
  110.27                        devices  
  110.28  xen-backend.rules   - hotplug script rules
  110.29  xend-config.sxp     - default xend configuration file
   111.1 --- a/tools/examples/external-device-migrate	Mon May 22 08:53:26 2006 -0600
   111.2 +++ b/tools/examples/external-device-migrate	Mon May 22 14:13:38 2006 -0600
   111.3 @@ -27,59 +27,85 @@ dir=$(dirname "$0")
   111.4  . "$dir/logging.sh"
   111.5  
   111.6  
   111.7 -function usage() {
   111.8 -	echo " Pass the following command line paremeters to the script:"
   111.9 -	echo ""
  111.10 -	echo "-step <n>     : n-th migration step"
  111.11 -	echo "-host <host>  : the destination host"
  111.12 -	echo "-domname <domain name> : name of the domain that is migrating"
  111.13 -	echo "-type <device type>    : the type of device that is migrating"
  111.14 -	echo "-recover               : indicates recovery request; an error"
  111.15 -	echo "                         occurred during migration"
  111.16 -	echo "-help                  : display this help screen"
  111.17 +function ext_dev_migrate_usage() {
  111.18 +cat <<EOF
  111.19 +Pass the following command line parameters to the script:
  111.20 +
  111.21 +-step <n>              : n-th migration step
  111.22 +-host <host>           : the destination host
  111.23 +-domname <domain name> : name of the domain that is migrating
  111.24 +-type <device type>    : the type of device that is migrating
  111.25 +-subtype <dev. subtype>: the subtype of the device
  111.26 +-recover               : indicates recovery request; an error
  111.27 +                         occurred during migration
  111.28 +-help                  : display this help screen
  111.29 +EOF
  111.30  }
  111.31  
  111.32 -while [ 1 ]; do
  111.33 -	if [ "$1" == "-step" ]; then
  111.34 -		shift
  111.35 -		step=$1
  111.36 -	elif [ "$1" == "-host" ]; then
  111.37 -		shift
  111.38 -		host=$1
  111.39 -	elif [ "$1" == "-domname" ]; then
  111.40 +# Parse the command line paramters. The following parameters must be
  111.41 +# passed as the first ones in the sequence:
  111.42 +#  -step       [required]
  111.43 +#  -host       [required]
  111.44 +#  -domname    [required]
  111.45 +#  -type       [required]
  111.46 +#  -subtype    [optional]
  111.47 +#  -recover    [optional]
  111.48 +# The remaining ones will be passed to the called function.
  111.49 +function evaluate_params()
  111.50 +{
  111.51 +	local step host domname typ recover filename func stype
  111.52 +	stype=""
  111.53 +	while [ 1 ]; do
  111.54 +		if [ "$1" == "-step" ]; then
  111.55 +			shift
  111.56 +			step=$1
  111.57 +		elif [ "$1" == "-host" ]; then
  111.58 +			shift
  111.59 +			host=$1
  111.60 +		elif [ "$1" == "-domname" ]; then
  111.61 +			shift
  111.62 +			domname=$1
  111.63 +		elif [ "$1" == "-type" ]; then
  111.64 +			shift
  111.65 +			typ=$1
  111.66 +		elif [ "$1" == "-subtype" ]; then
  111.67 +			shift
  111.68 +			stype="_$1"
  111.69 +		elif [ "$1" == "-recover" ]; then
  111.70 +			recover=1
  111.71 +		elif [ "$1" == "-help" ]; then
  111.72 +			ext_dev_migrate_usage
  111.73 +			exit
  111.74 +		else
  111.75 +			break
  111.76 +		fi
  111.77  		shift
  111.78 -		domname=$1
  111.79 -	elif [ "$1" == "-type" ]; then
  111.80 -		shift
  111.81 -		typ=$1
  111.82 -	elif [ "$1" == "-recover" ]; then
  111.83 -		recover=1
  111.84 -	elif [ "$1" == "-help" ]; then
  111.85 -		usage
  111.86 +	done
  111.87 +
  111.88 +	if [ "$step"    == "" -o \
  111.89 +	     "$host"    == "" -o \
  111.90 +	     "$typ"     == "" -o \
  111.91 +	     "$domname" == "" ]; then
  111.92 +	 	echo "Error: Parameter(s) missing (-step/-host/-type/-domname)"
  111.93 +		echo ""
  111.94 +		echo "$0 -help for usage."
  111.95  		exit
  111.96 -	else
  111.97 -		break
  111.98  	fi
  111.99 -	shift
 111.100 -done
 111.101 +
 111.102 +	filename="$dir/$typ$stype-migration.sh"
 111.103 +	if [ ! -r $filename ]; then
 111.104 +		echo "Error: Could not find script '$filename'"
 111.105 +		return
 111.106 +	fi
 111.107 +	. "$filename"
 111.108  
 111.109 -if [ "$step"    == "" -o \
 111.110 -     "$host"    == "" -o \
 111.111 -     "$typ"     == "" -o \
 111.112 -     "$domname" == "" ]; then
 111.113 -	echo "Error: Parameter(s) missing (-step/-host/-type/-domname)"
 111.114 -set
 111.115 -	echo ""
 111.116 -	echo "$0 --help for usage."
 111.117 -	exit
 111.118 -fi
 111.119 +	if [ "$recover" == "1" ]; then
 111.120 +		func="$typ"_recover
 111.121 +		eval $func $host $domname $step $*
 111.122 +	else
 111.123 +		func="$typ"_migration_step
 111.124 +		eval $func $host $domname $step $*
 111.125 +	fi
 111.126 +}
 111.127  
 111.128 -. "$dir/$typ-migration.sh"
 111.129 -
 111.130 -if [ "$recover" == "1" ]; then
 111.131 -	func="$typ"_recover
 111.132 -	eval $func $host $domname $step
 111.133 -else
 111.134 -	func="$typ"_migration_step
 111.135 -	eval $func $host $domname $step
 111.136 -fi
 111.137 +evaluate_params $*
   112.1 --- a/tools/examples/network-bridge	Mon May 22 08:53:26 2006 -0600
   112.2 +++ b/tools/examples/network-bridge	Mon May 22 14:13:38 2006 -0600
   112.3 @@ -59,7 +59,7 @@ dir=$(dirname "$0")
   112.4  findCommand "$@"
   112.5  evalVariables "$@"
   112.6  
   112.7 -vifnum=${vifnum:-$(ip route list | awk '/^default / { sub(/eth/,"",$NF); print $NF }')}
   112.8 +vifnum=${vifnum:-$(ip route list | awk '/^default / { print $NF }' | sed 's/^[^0-9]*//')}
   112.9  bridge=${bridge:-xenbr${vifnum}}
  112.10  netdev=${netdev:-eth${vifnum}}
  112.11  antispoof=${antispoof:-no}
   113.1 --- a/tools/examples/vtpm	Mon May 22 08:53:26 2006 -0600
   113.2 +++ b/tools/examples/vtpm	Mon May 22 14:13:38 2006 -0600
   113.3 @@ -23,5 +23,6 @@ esac
   113.4  if [ $vtpm_fatal_error -eq 0 ]; then
   113.5  	log debug "Successful vTPM operation '$command'."
   113.6  	success
   113.7 +else
   113.8 +	fatal "Error while executing vTPM operation '$command'."
   113.9  fi
  113.10 -
   114.1 --- a/tools/examples/vtpm-common.sh	Mon May 22 08:53:26 2006 -0600
   114.2 +++ b/tools/examples/vtpm-common.sh	Mon May 22 14:13:38 2006 -0600
   114.3 @@ -64,8 +64,10 @@ fi
   114.4  #  Returns '0' if instance number could not be found, otherwise
   114.5  #  it returns the instance number in the variable 'instance'
   114.6  function vtpmdb_find_instance () {
   114.7 -	local vmname=$1
   114.8 -	local ret=0
   114.9 +	local vmname ret instance
  114.10 +	vmname=$1
  114.11 +	ret=0
  114.12 +
  114.13  	instance=$(cat $VTPMDB |                   \
  114.14  	          awk -vvmname=$vmname             \
  114.15  	          '{                               \
  114.16 @@ -86,8 +88,9 @@ function vtpmdb_find_instance () {
  114.17  # Check whether a particular instance number is still available
  114.18  # returns "0" if it is not available, "1" otherwise.
  114.19  function vtpmdb_is_free_instancenum () {
  114.20 -	local instance=$1
  114.21 -	local avail=1
  114.22 +	local instance instances avail i
  114.23 +	instance=$1
  114.24 +	avail=1
  114.25  	#Allowed instance number range: 1-255
  114.26  	if [ $instance -eq 0 -o $instance -gt 255 ]; then
  114.27  		avail=0
  114.28 @@ -113,9 +116,7 @@ function vtpmdb_is_free_instancenum () {
  114.29  # Get an available instance number given the database
  114.30  # Returns an unused instance number
  114.31  function vtpmdb_get_free_instancenum () {
  114.32 -	local ctr
  114.33 -	local instances
  114.34 -	local don
  114.35 +	local ctr instances don found
  114.36  	instances=$(cat $VTPMDB |                \
  114.37  	           gawk                          \
  114.38  	           '{                            \
  114.39 @@ -126,7 +127,6 @@ function vtpmdb_get_free_instancenum () 
  114.40  	ctr=1
  114.41  	don=0
  114.42  	while [ $don -eq 0 ]; do
  114.43 -		local found
  114.44  		found=0
  114.45  		for i in $instances; do
  114.46  			if [ $i -eq $ctr ]; then
  114.47 @@ -147,8 +147,9 @@ function vtpmdb_get_free_instancenum () 
  114.48  
  114.49  # Add a domain name and instance number to the DB file
  114.50  function vtpmdb_add_instance () {
  114.51 -	local vmname=$1
  114.52 -	local inst=$2
  114.53 +	local res vmname inst
  114.54 +	vmname=$1
  114.55 +	inst=$2
  114.56  
  114.57  	if [ ! -f $VTPMDB ]; then
  114.58  		echo "#Database for VM to vTPM association" > $VTPMDB
  114.59 @@ -165,9 +166,10 @@ function vtpmdb_add_instance () {
  114.60  #Validate whether an entry is the same as passed to this
  114.61  #function
  114.62  function vtpmdb_validate_entry () {
  114.63 -	local rc=0
  114.64 -	local vmname=$1
  114.65 -	local inst=$2
  114.66 +	local res rc vmname inst
  114.67 +	rc=0
  114.68 +	vmname=$1
  114.69 +	inst=$2
  114.70  
  114.71  	res=$(cat $VTPMDB |            \
  114.72  	     gawk -vvmname=$vmname     \
  114.73 @@ -188,9 +190,9 @@ function vtpmdb_validate_entry () {
  114.74  	     }')
  114.75  
  114.76  	if [ "$res" == "1" ]; then
  114.77 -		let rc=1
  114.78 +		rc=1
  114.79  	elif [ "$res" == "2" ]; then
  114.80 -		let rc=2
  114.81 +		rc=2
  114.82  	fi
  114.83  	echo "$rc"
  114.84  }
  114.85 @@ -199,9 +201,11 @@ function vtpmdb_validate_entry () {
  114.86  #Remove an entry from the vTPM database given its domain name
  114.87  #and instance number
  114.88  function vtpmdb_remove_entry () {
  114.89 -	local vmname=$1
  114.90 -	local instance=$2
  114.91 -	local VTPMDB_TMP="$VTPMDB".tmp
  114.92 +	local vmname instance VTPMDB_TMP
  114.93 +	vmname=$1
  114.94 +	instance=$2
  114.95 +	VTPMDB_TMP="$VTPMDB".tmp
  114.96 +
  114.97  	$(cat $VTPMDB |            \
  114.98  	 gawk -vvmname=$vmname     \
  114.99  	 '{                        \
 114.100 @@ -219,13 +223,14 @@ function vtpmdb_remove_entry () {
 114.101  
 114.102  
 114.103  # Find the reason for the creation of this device:
 114.104 -# Set global REASON variable to 'resume' or 'create'
 114.105 +# Returns 'resume' or 'create'
 114.106  function vtpm_get_create_reason () {
 114.107 -	local resume=$(xenstore-read $XENBUS_PATH/resume)
 114.108 +	local resume
 114.109 +	resume=$(xenstore-read $XENBUS_PATH/resume)
 114.110  	if [ "$resume" == "True" ]; then
 114.111 -		REASON="resume"
 114.112 +		echo "resume"
 114.113  	else
 114.114 -		REASON="create"
 114.115 +		echo "create"
 114.116  	fi
 114.117  }
 114.118  
 114.119 @@ -234,10 +239,9 @@ function vtpm_get_create_reason () {
 114.120  # If no entry in the TPM database is found, the instance is
 114.121  # created and an entry added to the database.
 114.122  function vtpm_create_instance () {
 114.123 -	local domname=$(xenstore_read "$XENBUS_PATH"/domain)
 114.124 -	local res
 114.125 -	local instance
 114.126 -	vtpm_get_create_reason
 114.127 +	local res instance domname reason
 114.128 +	domname=$(xenstore_read "$XENBUS_PATH"/domain)
 114.129 +	reason=$(vtpm_get_create_reason)
 114.130  
 114.131  	claim_lock vtpmdb
 114.132  	instance=$(vtpmdb_find_instance $domname)
 114.133 @@ -252,20 +256,20 @@ function vtpm_create_instance () {
 114.134  		else
 114.135  			instance=$(vtpmdb_get_free_instancenum)
 114.136  		fi
 114.137 -		vtpmdb_add_instance $domname $instance
 114.138 -		if [ "$REASON" == "create" ]; then
 114.139 +		if [ "$reason" == "create" ]; then
 114.140  			vtpm_create $instance
 114.141 -		elif [ "$REASON" == "resume" ]; then
 114.142 +		else
 114.143  			vtpm_resume $instance $domname
 114.144 -		else
 114.145 -			#default case for 'now'
 114.146 -			vtpm_create $instance
 114.147 +		fi
 114.148 +		if [ $vtpm_fatal_error -eq 0 ]; then
 114.149 +			vtpmdb_add_instance $domname $instance
 114.150  		fi
 114.151  	fi
 114.152  
 114.153  	release_lock vtpmdb
 114.154  
 114.155 -	if [ "$REASON" == "create" ]; then
 114.156 +	if [ $vtpm_fatal_error -eq 0 -a \
 114.157 +	     "$reason" == "create" ]; then
 114.158  		vtpm_reset $instance
 114.159  	fi
 114.160  	xenstore_write $XENBUS_PATH/instance $instance
 114.161 @@ -276,15 +280,18 @@ function vtpm_create_instance () {
 114.162  #Since it is assumed that the VM will appear again, the
 114.163  #entry is kept in the VTPMDB file.
 114.164  function vtpm_remove_instance () {
 114.165 -	local domname=$(xenstore_read "$XENBUS_PATH"/domain)
 114.166 +	local instance reason domname
 114.167 +	domname=$(xenstore_read "$XENBUS_PATH"/domain)
 114.168  
 114.169 -	claim_lock vtpmdb
 114.170 +	if [ "$doname" != "" ]; then
 114.171 +		claim_lock vtpmdb
 114.172  
 114.173 -	instance=$(vtpmdb_find_instance $domname)
 114.174 +		instance=$(vtpmdb_find_instance $domname)
 114.175  
 114.176 -	if [ "$instance" != "0" ]; then
 114.177 -		if [ "$REASON" == "suspend" ]; then
 114.178 -			vtpm_suspend $instance
 114.179 +		if [ "$instance" != "0" ]; then
 114.180 +			if [ "$reason" == "suspend" ]; then
 114.181 +				vtpm_suspend $instance
 114.182 +			fi
 114.183  		fi
 114.184  	fi
 114.185  
 114.186 @@ -295,7 +302,7 @@ function vtpm_remove_instance () {
 114.187  #Remove an entry in the VTPMDB file given the domain's name
 114.188  #1st parameter: The name of the domain
 114.189  function vtpm_delete_instance () {
 114.190 -	local rc
 114.191 +	local instance
 114.192  
 114.193  	claim_lock vtpmdb
 114.194  
 114.195 @@ -313,20 +320,21 @@ function vtpm_delete_instance () {
 114.196  #  "0"  : this is not an address of this machine
 114.197  #  "1"  : this is an address local to this machine
 114.198  function isLocalAddress() {
 114.199 -	local addr=$(ping $1 -c 1 |  \
 114.200 -	             gawk '{ print substr($3,2,length($3)-2); exit }')
 114.201 +	local addr res
 114.202 +	addr=$(ping $1 -c 1 |  \
 114.203 +	       gawk '{ print substr($3,2,length($3)-2); exit }')
 114.204  	if [ "$addr" == "" ]; then
 114.205  		echo "-1"
 114.206  		return
 114.207  	fi
 114.208 -	local res=$(ifconfig | grep "inet addr" |  \
 114.209 -	           gawk -vaddr=$addr               \
 114.210 -	           '{                              \
 114.211 -	              if ( addr == substr($2, 6)) {\
 114.212 -	                print "1";                 \
 114.213 -	              }                            \
 114.214 -	           }'                              \
 114.215 -	          )
 114.216 +	res=$(ifconfig | grep "inet addr" |  \
 114.217 +	     gawk -vaddr=$addr               \
 114.218 +	     '{                              \
 114.219 +	        if ( addr == substr($2, 6)) {\
 114.220 +	          print "1";                 \
 114.221 +	        }                            \
 114.222 +	     }'                              \
 114.223 +	    )
 114.224  	if [ "$res" == "" ]; then
 114.225  		echo "0"
 114.226  		return
 114.227 @@ -341,7 +349,8 @@ function isLocalAddress() {
 114.228  # 2nd: name of the domain to migrate
 114.229  # 3rd: the migration step to perform
 114.230  function vtpm_migration_step() {
 114.231 -	local instance=$(vtpmdb_find_instance $2)
 114.232 +	local instance res
 114.233 +	instance=$(vtpmdb_find_instance $2)
 114.234  	if [ "$instance" == "" ]; then
 114.235  		echo "Error: Translation of domain name ($2) to instance failed. Check /etc/xen/vtpm.db"
 114.236  		log err "Error during translation of domain name"
 114.237 @@ -360,6 +369,7 @@ function vtpm_migration_step() {
 114.238  # 2nd: name of the domain that was to be migrated
 114.239  # 3rd: the last successful migration step that was done
 114.240  function vtpm_recover() {
 114.241 +	local res
 114.242  	res=$(isLocalAddress $1)
 114.243  	if [ "$res" == "0" ]; then
 114.244  		vtpm_migrate_recover $1 $2 $3
   115.1 --- a/tools/examples/xmexample.hvm	Mon May 22 08:53:26 2006 -0600
   115.2 +++ b/tools/examples/xmexample.hvm	Mon May 22 14:13:38 2006 -0600
   115.3 @@ -30,6 +30,10 @@ memory = 128
   115.4  # A name for your domain. All domains must have different names.
   115.5  name = "ExampleHVMDomain"
   115.6  
   115.7 +# 128-bit UUID for the domain.  The default behavior is to generate a new UUID
   115.8 +# on each call to 'xm create'.
   115.9 +#uuid = "06ed00fe-1162-4fc4-b5d8-11993ee4a8b9"
  115.10 +
  115.11  #-----------------------------------------------------------------------------
  115.12  # the number of cpus guest platform has, default=1
  115.13  #vcpus=1
   116.1 --- a/tools/examples/xmexample1	Mon May 22 08:53:26 2006 -0600
   116.2 +++ b/tools/examples/xmexample1	Mon May 22 14:13:38 2006 -0600
   116.3 @@ -26,6 +26,10 @@ memory = 64
   116.4  # A name for your domain. All domains must have different names.
   116.5  name = "ExampleDomain"
   116.6  
   116.7 +# 128-bit UUID for the domain.  The default behavior is to generate a new UUID
   116.8 +# on each call to 'xm create'.
   116.9 +#uuid = "06ed00fe-1162-4fc4-b5d8-11993ee4a8b9"
  116.10 +
  116.11  # List of which CPUS this domain is allowed to use, default Xen picks
  116.12  #cpus = ""         # leave to Xen to pick
  116.13  #cpus = "0"        # all vcpus run on CPU0
   117.1 --- a/tools/examples/xmexample2	Mon May 22 08:53:26 2006 -0600
   117.2 +++ b/tools/examples/xmexample2	Mon May 22 14:13:38 2006 -0600
   117.3 @@ -55,6 +55,10 @@ memory = 64
   117.4  # so we use the vmid to create a name.
   117.5  name = "VM%d" % vmid
   117.6  
   117.7 +# 128-bit UUID for the domain.  The default behavior is to generate a new UUID
   117.8 +# on each call to 'xm create'.
   117.9 +#uuid = "06ed00fe-1162-4fc4-b5d8-11993ee4a8b9"
  117.10 +
  117.11  # List of which CPUS this domain is allowed to use, default Xen picks
  117.12  #cpus = ""         # leave to Xen to pick
  117.13  #cpus = "0"        # all vcpus run on CPU0
   118.1 --- a/tools/examples/xmexample3	Mon May 22 08:53:26 2006 -0600
   118.2 +++ b/tools/examples/xmexample3	Mon May 22 14:13:38 2006 -0600
   118.3 @@ -55,6 +55,10 @@ memory = 64
   118.4  # so we use the vmid to create a name.
   118.5  name = "VM%d" % vmid
   118.6  
   118.7 +# 128-bit UUID for the domain.  The default behavior is to generate a new UUID
   118.8 +# on each call to 'xm create'.
   118.9 +#uuid = "06ed00fe-1162-4fc4-b5d8-11993ee4a8b9"
  118.10 +
  118.11  # List of which CPUS this domain is allowed to use, default Xen picks
  118.12  #cpus = ""         # leave to Xen to pick
  118.13  #cpus = "0"        # all vcpus run on CPU0
   119.1 --- a/tools/firmware/acpi/acpi_dsdt.asl	Mon May 22 08:53:26 2006 -0600
   119.2 +++ b/tools/firmware/acpi/acpi_dsdt.asl	Mon May 22 14:13:38 2006 -0600
   119.3 @@ -37,6 +37,16 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
   119.4          Processor (CPU3, 0x03, 0x00000000, 0x00) {}
   119.5      }
   119.6  
   119.7 +/* Poweroff support - ties in with qemu emulation */
   119.8 +
   119.9 +    Name (\_S5, Package (0x04)
  119.10 +    {
  119.11 +        0x07, 
  119.12 +        0x07, 
  119.13 +        0x00, 
  119.14 +        0x00
  119.15 +    })
  119.16 +
  119.17      Scope (\_SB)
  119.18      {
  119.19          Device (PCI0)
   120.1 --- a/tools/firmware/acpi/acpi_dsdt.c	Mon May 22 08:53:26 2006 -0600
   120.2 +++ b/tools/firmware/acpi/acpi_dsdt.c	Mon May 22 14:13:38 2006 -0600
   120.3 @@ -1,161 +1,160 @@
   120.4  /*
   120.5   * 
   120.6   * Intel ACPI Component Architecture
   120.7 - * ASL Optimizing Compiler / AML Disassembler version 20050513 [Jun  8 2005]
   120.8 + * ASL Optimizing Compiler / AML Disassembler version 20050624 [Aug 24 2005]
   120.9   * Copyright (C) 2000 - 2005 Intel Corporation
  120.10   * Supports ACPI Specification Revision 3.0
  120.11   * 
  120.12 - * Compilation of "acpi_dsdt.asl" - Wed Jun 15 09:19:49 2005
  120.13 + * Compilation of "acpi_dsdt.asl" - Thu May  4 17:42:00 2006
  120.14   * 
  120.15   * C source code output
  120.16   *
  120.17   */
  120.18  unsigned char AmlCode[] = 
  120.19  {
  120.20 -    0x44,0x53,0x44,0x54,0x87,0x04,0x00,0x00,  /* 00000000    "DSDT...." */
  120.21 -    0x01,0x19,0x49,0x4E,0x54,0x45,0x4C,0x20,  /* 00000008    "..INTEL " */
  120.22 +    0x44,0x53,0x44,0x54,0x7C,0x04,0x00,0x00,  /* 00000000    "DSDT|..." */
  120.23 +    0x01,0x72,0x49,0x4E,0x54,0x45,0x4C,0x20,  /* 00000008    ".rINTEL " */
  120.24      0x58,0x45,0x4E,0x20,0x20,0x20,0x20,0x20,  /* 00000010    "XEN     " */
  120.25      0x02,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C,  /* 00000018    "....INTL" */
  120.26 -    0x13,0x05,0x05,0x20,0x08,0x5C,0x50,0x4D,  /* 00000020    "... .\PM" */
  120.27 -    0x42,0x53,0x0B,0x00,0x0C,0x08,0x5C,0x50,  /* 00000028    "BS....\P" */
  120.28 -    0x4D,0x4C,0x4E,0x0A,0x08,0x08,0x5C,0x49,  /* 00000030    "MLN...\I" */
  120.29 -    0x4F,0x42,0x31,0x0A,0x00,0x08,0x5C,0x49,  /* 00000038    "OB1...\I" */
  120.30 -    0x4F,0x4C,0x31,0x0A,0x00,0x08,0x5C,0x41,  /* 00000040    "OL1...\A" */
  120.31 -    0x50,0x43,0x42,0x0C,0x00,0x00,0xC0,0xFE,  /* 00000048    "PCB....." */
  120.32 -    0x08,0x5C,0x41,0x50,0x43,0x4C,0x0C,0x00,  /* 00000050    ".\APCL.." */
  120.33 -    0x00,0x01,0x00,0x08,0x5C,0x50,0x55,0x49,  /* 00000058    "....\PUI" */
  120.34 -    0x44,0x0A,0x00,0x10,0x3A,0x5C,0x5F,0x50,  /* 00000060    "D...:\_P" */
  120.35 -    0x52,0x5F,0x5B,0x83,0x0B,0x43,0x50,0x55,  /* 00000068    "R_[..CPU" */
  120.36 -    0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x5B,  /* 00000070    "0......[" */
  120.37 -    0x83,0x0B,0x43,0x50,0x55,0x31,0x01,0x00,  /* 00000078    "..CPU1.." */
  120.38 -    0x00,0x00,0x00,0x00,0x5B,0x83,0x0B,0x43,  /* 00000080    "....[..C" */
  120.39 -    0x50,0x55,0x32,0x02,0x00,0x00,0x00,0x00,  /* 00000088    "PU2....." */
  120.40 -    0x00,0x5B,0x83,0x0B,0x43,0x50,0x55,0x33,  /* 00000090    ".[..CPU3" */
  120.41 -    0x03,0x00,0x00,0x00,0x00,0x00,0x10,0x48,  /* 00000098    ".......H" */
  120.42 -    0x3E,0x5C,0x5F,0x53,0x42,0x5F,0x5B,0x82,  /* 000000A0    ">\_SB_[." */
  120.43 -    0x4F,0x3D,0x50,0x43,0x49,0x30,0x08,0x5F,  /* 000000A8    "O=PCI0._" */
  120.44 -    0x48,0x49,0x44,0x0C,0x41,0xD0,0x0A,0x03,  /* 000000B0    "HID.A..." */
  120.45 -    0x08,0x5F,0x55,0x49,0x44,0x0A,0x00,0x08,  /* 000000B8    "._UID..." */
  120.46 -    0x5F,0x41,0x44,0x52,0x0A,0x00,0x08,0x5F,  /* 000000C0    "_ADR..._" */
  120.47 -    0x42,0x42,0x4E,0x0A,0x00,0x14,0x4A,0x06,  /* 000000C8    "BBN...J." */
  120.48 -    0x5F,0x43,0x52,0x53,0x00,0x08,0x50,0x52,  /* 000000D0    "_CRS..PR" */
  120.49 -    0x54,0x30,0x11,0x48,0x05,0x0A,0x54,0x88,  /* 000000D8    "T0.H..T." */
  120.50 -    0x0D,0x00,0x02,0x0F,0x00,0x00,0x00,0x00,  /* 000000E0    "........" */
  120.51 -    0x00,0xFF,0x00,0x00,0x00,0x00,0x01,0x47,  /* 000000E8    ".......G" */
  120.52 -    0x01,0xF8,0x0C,0xF8,0x0C,0x01,0x08,0x88,  /* 000000F0    "........" */
  120.53 -    0x0D,0x00,0x01,0x0C,0x03,0x00,0x00,0x00,  /* 000000F8    "........" */
  120.54 -    0x00,0xF7,0x0C,0x00,0x00,0xF8,0x0C,0x88,  /* 00000100    "........" */
  120.55 -    0x0D,0x00,0x01,0x0C,0x03,0x00,0x00,0x00,  /* 00000108    "........" */
  120.56 -    0x0D,0xFF,0x0F,0x00,0x00,0x00,0x03,0x87,  /* 00000110    "........" */
  120.57 -    0x17,0x00,0x00,0x0C,0x02,0x00,0x00,0x00,  /* 00000118    "........" */
  120.58 -    0x00,0x00,0x00,0x0A,0x00,0xFF,0xFF,0x0F,  /* 00000120    "........" */
  120.59 -    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,  /* 00000128    "........" */
  120.60 -    0x00,0x79,0x00,0xA4,0x50,0x52,0x54,0x30,  /* 00000130    ".y..PRT0" */
  120.61 -    0x08,0x41,0x49,0x52,0x30,0x12,0x47,0x05,  /* 00000138    ".AIR0.G." */
  120.62 -    0x06,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x1F,  /* 00000140    "........" */
  120.63 -    0x00,0x0A,0x02,0x0A,0x00,0x0A,0x17,0x12,  /* 00000148    "........" */
  120.64 -    0x0D,0x04,0x0C,0xFF,0xFF,0x1F,0x00,0x0A,  /* 00000150    "........" */
  120.65 -    0x03,0x0A,0x00,0x0A,0x13,0x12,0x0D,0x04,  /* 00000158    "........" */
  120.66 -    0x0C,0xFF,0xFF,0x1D,0x00,0x0A,0x01,0x0A,  /* 00000160    "........" */
  120.67 -    0x00,0x0A,0x13,0x12,0x0D,0x04,0x0C,0xFF,  /* 00000168    "........" */
  120.68 -    0xFF,0x1D,0x00,0x0A,0x00,0x0A,0x00,0x0A,  /* 00000170    "........" */
  120.69 -    0x10,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x1D,  /* 00000178    "........" */
  120.70 -    0x00,0x0A,0x02,0x0A,0x00,0x0A,0x12,0x12,  /* 00000180    "........" */
  120.71 -    0x0D,0x04,0x0C,0xFF,0xFF,0x1D,0x00,0x0A,  /* 00000188    "........" */
  120.72 -    0x03,0x0A,0x00,0x0A,0x17,0x14,0x0B,0x5F,  /* 00000190    "......._" */
  120.73 -    0x50,0x52,0x54,0x00,0xA4,0x41,0x49,0x52,  /* 00000198    "PRT..AIR" */
  120.74 -    0x30,0x5B,0x82,0x44,0x2E,0x49,0x53,0x41,  /* 000001A0    "0[.D.ISA" */
  120.75 -    0x5F,0x08,0x5F,0x41,0x44,0x52,0x0C,0x00,  /* 000001A8    "_._ADR.." */
  120.76 -    0x00,0x01,0x00,0x5B,0x82,0x47,0x0B,0x53,  /* 000001B0    "...[.G.S" */
  120.77 -    0x59,0x53,0x52,0x08,0x5F,0x48,0x49,0x44,  /* 000001B8    "YSR._HID" */
  120.78 -    0x0C,0x41,0xD0,0x0C,0x02,0x08,0x5F,0x55,  /* 000001C0    ".A...._U" */
  120.79 -    0x49,0x44,0x0A,0x01,0x08,0x43,0x52,0x53,  /* 000001C8    "ID...CRS" */
  120.80 -    0x5F,0x11,0x4E,0x08,0x0A,0x8A,0x47,0x01,  /* 000001D0    "_.N...G." */
  120.81 -    0x10,0x00,0x10,0x00,0x00,0x10,0x47,0x01,  /* 000001D8    "......G." */
  120.82 -    0x22,0x00,0x22,0x00,0x00,0x0C,0x47,0x01,  /* 000001E0    ""."...G." */
  120.83 -    0x30,0x00,0x30,0x00,0x00,0x10,0x47,0x01,  /* 000001E8    "0.0...G." */
  120.84 -    0x44,0x00,0x44,0x00,0x00,0x1C,0x47,0x01,  /* 000001F0    "D.D...G." */
  120.85 -    0x62,0x00,0x62,0x00,0x00,0x02,0x47,0x01,  /* 000001F8    "b.b...G." */
  120.86 -    0x65,0x00,0x65,0x00,0x00,0x0B,0x47,0x01,  /* 00000200    "e.e...G." */
  120.87 -    0x72,0x00,0x72,0x00,0x00,0x0E,0x47,0x01,  /* 00000208    "r.r...G." */
  120.88 -    0x80,0x00,0x80,0x00,0x00,0x01,0x47,0x01,  /* 00000210    "......G." */
  120.89 -    0x84,0x00,0x84,0x00,0x00,0x03,0x47,0x01,  /* 00000218    "......G." */
  120.90 -    0x88,0x00,0x88,0x00,0x00,0x01,0x47,0x01,  /* 00000220    "......G." */
  120.91 -    0x8C,0x00,0x8C,0x00,0x00,0x03,0x47,0x01,  /* 00000228    "......G." */
  120.92 -    0x90,0x00,0x90,0x00,0x00,0x10,0x47,0x01,  /* 00000230    "......G." */
  120.93 -    0xA2,0x00,0xA2,0x00,0x00,0x1C,0x47,0x01,  /* 00000238    "......G." */
  120.94 -    0xE0,0x00,0xE0,0x00,0x00,0x10,0x47,0x01,  /* 00000240    "......G." */
  120.95 -    0xA0,0x08,0xA0,0x08,0x00,0x04,0x47,0x01,  /* 00000248    "......G." */
  120.96 -    0xC0,0x0C,0xC0,0x0C,0x00,0x10,0x47,0x01,  /* 00000250    "......G." */
  120.97 -    0xD0,0x04,0xD0,0x04,0x00,0x02,0x79,0x00,  /* 00000258    "......y." */
  120.98 -    0x14,0x0B,0x5F,0x43,0x52,0x53,0x00,0xA4,  /* 00000260    ".._CRS.." */
  120.99 -    0x43,0x52,0x53,0x5F,0x5B,0x82,0x2B,0x50,  /* 00000268    "CRS_[.+P" */
 120.100 -    0x49,0x43,0x5F,0x08,0x5F,0x48,0x49,0x44,  /* 00000270    "IC_._HID" */
 120.101 -    0x0B,0x41,0xD0,0x08,0x5F,0x43,0x52,0x53,  /* 00000278    ".A.._CRS" */
 120.102 -    0x11,0x18,0x0A,0x15,0x47,0x01,0x20,0x00,  /* 00000280    "....G. ." */
 120.103 -    0x20,0x00,0x01,0x02,0x47,0x01,0xA0,0x00,  /* 00000288    " ...G..." */
 120.104 -    0xA0,0x00,0x01,0x02,0x22,0x04,0x00,0x79,  /* 00000290    "...."..y" */
 120.105 -    0x00,0x5B,0x82,0x47,0x05,0x44,0x4D,0x41,  /* 00000298    ".[.G.DMA" */
 120.106 -    0x30,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 000002A0    "0._HID.A" */
 120.107 -    0xD0,0x02,0x00,0x08,0x5F,0x43,0x52,0x53,  /* 000002A8    "...._CRS" */
 120.108 -    0x11,0x41,0x04,0x0A,0x3D,0x2A,0x10,0x04,  /* 000002B0    ".A..=*.." */
 120.109 -    0x47,0x01,0x00,0x00,0x00,0x00,0x00,0x10,  /* 000002B8    "G......." */
 120.110 -    0x47,0x01,0x81,0x00,0x81,0x00,0x00,0x03,  /* 000002C0    "G......." */
 120.111 -    0x47,0x01,0x87,0x00,0x87,0x00,0x00,0x01,  /* 000002C8    "G......." */
 120.112 -    0x47,0x01,0x89,0x00,0x89,0x00,0x00,0x03,  /* 000002D0    "G......." */
 120.113 -    0x47,0x01,0x8F,0x00,0x8F,0x00,0x00,0x01,  /* 000002D8    "G......." */
 120.114 -    0x47,0x01,0xC0,0x00,0xC0,0x00,0x00,0x20,  /* 000002E0    "G...... " */
 120.115 -    0x47,0x01,0x80,0x04,0x80,0x04,0x00,0x10,  /* 000002E8    "G......." */
 120.116 -    0x79,0x00,0x5B,0x82,0x25,0x54,0x4D,0x52,  /* 000002F0    "y.[.%TMR" */
 120.117 -    0x5F,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 000002F8    "_._HID.A" */
 120.118 -    0xD0,0x01,0x00,0x08,0x5F,0x43,0x52,0x53,  /* 00000300    "...._CRS" */
 120.119 -    0x11,0x10,0x0A,0x0D,0x47,0x01,0x40,0x00,  /* 00000308    "....G.@." */
 120.120 -    0x40,0x00,0x00,0x04,0x22,0x01,0x00,0x79,  /* 00000310    "@..."..y" */
 120.121 -    0x00,0x5B,0x82,0x25,0x52,0x54,0x43,0x5F,  /* 00000318    ".[.%RTC_" */
 120.122 -    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 00000320    "._HID.A." */
 120.123 -    0x0B,0x00,0x08,0x5F,0x43,0x52,0x53,0x11,  /* 00000328    "..._CRS." */
 120.124 -    0x10,0x0A,0x0D,0x47,0x01,0x70,0x00,0x70,  /* 00000330    "...G.p.p" */
 120.125 -    0x00,0x00,0x02,0x22,0x00,0x01,0x79,0x00,  /* 00000338    "..."..y." */
 120.126 -    0x5B,0x82,0x22,0x53,0x50,0x4B,0x52,0x08,  /* 00000340    "[."SPKR." */
 120.127 -    0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x08,  /* 00000348    "_HID.A.." */
 120.128 -    0x00,0x08,0x5F,0x43,0x52,0x53,0x11,0x0D,  /* 00000350    ".._CRS.." */
 120.129 -    0x0A,0x0A,0x47,0x01,0x61,0x00,0x61,0x00,  /* 00000358    "..G.a.a." */
 120.130 -    0x00,0x01,0x79,0x00,0x5B,0x82,0x31,0x50,  /* 00000360    "..y.[.1P" */
 120.131 -    0x53,0x32,0x4D,0x08,0x5F,0x48,0x49,0x44,  /* 00000368    "S2M._HID" */
 120.132 -    0x0C,0x41,0xD0,0x0F,0x13,0x08,0x5F,0x43,  /* 00000370    ".A...._C" */
 120.133 -    0x49,0x44,0x0C,0x41,0xD0,0x0F,0x13,0x14,  /* 00000378    "ID.A...." */
 120.134 -    0x09,0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,  /* 00000380    "._STA..." */
 120.135 -    0x0F,0x08,0x5F,0x43,0x52,0x53,0x11,0x08,  /* 00000388    ".._CRS.." */
 120.136 -    0x0A,0x05,0x22,0x00,0x10,0x79,0x00,0x5B,  /* 00000390    ".."..y.[" */
 120.137 -    0x82,0x42,0x04,0x50,0x53,0x32,0x4B,0x08,  /* 00000398    ".B.PS2K." */
 120.138 -    0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x03,  /* 000003A0    "_HID.A.." */
 120.139 -    0x03,0x08,0x5F,0x43,0x49,0x44,0x0C,0x41,  /* 000003A8    ".._CID.A" */
 120.140 -    0xD0,0x03,0x0B,0x14,0x09,0x5F,0x53,0x54,  /* 000003B0    "....._ST" */
 120.141 -    0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,  /* 000003B8    "A....._C" */
 120.142 -    0x52,0x53,0x11,0x18,0x0A,0x15,0x47,0x01,  /* 000003C0    "RS....G." */
 120.143 -    0x60,0x00,0x60,0x00,0x00,0x01,0x47,0x01,  /* 000003C8    "`.`...G." */
 120.144 -    0x64,0x00,0x64,0x00,0x00,0x01,0x22,0x02,  /* 000003D0    "d.d..."." */
 120.145 -    0x00,0x79,0x00,0x5B,0x82,0x3A,0x46,0x44,  /* 000003D8    ".y.[.:FD" */
 120.146 -    0x43,0x30,0x08,0x5F,0x48,0x49,0x44,0x0C,  /* 000003E0    "C0._HID." */
 120.147 -    0x41,0xD0,0x07,0x00,0x14,0x09,0x5F,0x53,  /* 000003E8    "A....._S" */
 120.148 -    0x54,0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,  /* 000003F0    "TA....._" */
 120.149 -    0x43,0x52,0x53,0x11,0x1B,0x0A,0x18,0x47,  /* 000003F8    "CRS....G" */
 120.150 -    0x01,0xF0,0x03,0xF0,0x03,0x01,0x06,0x47,  /* 00000400    ".......G" */
 120.151 -    0x01,0xF7,0x03,0xF7,0x03,0x01,0x01,0x22,  /* 00000408    "......."" */
 120.152 -    0x40,0x00,0x2A,0x04,0x00,0x79,0x00,0x5B,  /* 00000410    "@.*..y.[" */
 120.153 -    0x82,0x36,0x55,0x41,0x52,0x31,0x08,0x5F,  /* 00000418    ".6UAR1._" */
 120.154 -    0x48,0x49,0x44,0x0C,0x41,0xD0,0x05,0x01,  /* 00000420    "HID.A..." */
 120.155 -    0x08,0x5F,0x55,0x49,0x44,0x0A,0x01,0x14,  /* 00000428    "._UID..." */
 120.156 -    0x09,0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,  /* 00000430    "._STA..." */
 120.157 -    0x0F,0x08,0x5F,0x43,0x52,0x53,0x11,0x10,  /* 00000438    ".._CRS.." */
 120.158 -    0x0A,0x0D,0x47,0x01,0xF8,0x03,0xF8,0x03,  /* 00000440    "..G....." */
 120.159 -    0x01,0x08,0x22,0x10,0x00,0x79,0x00,0x5B,  /* 00000448    ".."..y.[" */
 120.160 -    0x82,0x36,0x55,0x41,0x52,0x32,0x08,0x5F,  /* 00000450    ".6UAR2._" */
 120.161 -    0x48,0x49,0x44,0x0C,0x41,0xD0,0x05,0x01,  /* 00000458    "HID.A..." */
 120.162 -    0x08,0x5F,0x55,0x49,0x44,0x0A,0x02,0x14,  /* 00000460    "._UID..." */
 120.163 -    0x09,0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,  /* 00000468    "._STA..." */
 120.164 -    0x0F,0x08,0x5F,0x43,0x52,0x53,0x11,0x10,  /* 00000470    ".._CRS.." */
 120.165 -    0x0A,0x0D,0x47,0x01,0xF8,0x02,0xF8,0x02,  /* 00000478    "..G....." */
 120.166 -    0x01,0x08,0x22,0x08,0x00,0x79,0x00,
 120.167 +    0x24,0x06,0x05,0x20,0x08,0x50,0x4D,0x42,  /* 00000020    "$.. .PMB" */
 120.168 +    0x53,0x0B,0x00,0x0C,0x08,0x50,0x4D,0x4C,  /* 00000028    "S....PML" */
 120.169 +    0x4E,0x0A,0x08,0x08,0x49,0x4F,0x42,0x31,  /* 00000030    "N...IOB1" */
 120.170 +    0x00,0x08,0x49,0x4F,0x4C,0x31,0x00,0x08,  /* 00000038    "..IOL1.." */
 120.171 +    0x41,0x50,0x43,0x42,0x0C,0x00,0x00,0xC0,  /* 00000040    "APCB...." */
 120.172 +    0xFE,0x08,0x41,0x50,0x43,0x4C,0x0C,0x00,  /* 00000048    "..APCL.." */
 120.173 +    0x00,0x01,0x00,0x08,0x50,0x55,0x49,0x44,  /* 00000050    "....PUID" */
 120.174 +    0x00,0x10,0x39,0x5F,0x50,0x52,0x5F,0x5B,  /* 00000058    "..9_PR_[" */
 120.175 +    0x83,0x0B,0x43,0x50,0x55,0x30,0x00,0x00,  /* 00000060    "..CPU0.." */
 120.176 +    0x00,0x00,0x00,0x00,0x5B,0x83,0x0B,0x43,  /* 00000068    "....[..C" */
 120.177 +    0x50,0x55,0x31,0x01,0x00,0x00,0x00,0x00,  /* 00000070    "PU1....." */
 120.178 +    0x00,0x5B,0x83,0x0B,0x43,0x50,0x55,0x32,  /* 00000078    ".[..CPU2" */
 120.179 +    0x02,0x00,0x00,0x00,0x00,0x00,0x5B,0x83,  /* 00000080    "......[." */
 120.180 +    0x0B,0x43,0x50,0x55,0x33,0x03,0x00,0x00,  /* 00000088    ".CPU3..." */
 120.181 +    0x00,0x00,0x00,0x08,0x5F,0x53,0x35,0x5F,  /* 00000090    "...._S5_" */
 120.182 +    0x12,0x08,0x04,0x0A,0x07,0x0A,0x07,0x00,  /* 00000098    "........" */
 120.183 +    0x00,0x10,0x4A,0x3D,0x5F,0x53,0x42,0x5F,  /* 000000A0    "..J=_SB_" */
 120.184 +    0x5B,0x82,0x42,0x3D,0x50,0x43,0x49,0x30,  /* 000000A8    "[.B=PCI0" */
 120.185 +    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 000000B0    "._HID.A." */
 120.186 +    0x0A,0x03,0x08,0x5F,0x55,0x49,0x44,0x00,  /* 000000B8    "..._UID." */
 120.187 +    0x08,0x5F,0x41,0x44,0x52,0x00,0x08,0x5F,  /* 000000C0    "._ADR.._" */
 120.188 +    0x42,0x42,0x4E,0x00,0x14,0x4A,0x06,0x5F,  /* 000000C8    "BBN..J._" */
 120.189 +    0x43,0x52,0x53,0x00,0x08,0x50,0x52,0x54,  /* 000000D0    "CRS..PRT" */
 120.190 +    0x30,0x11,0x48,0x05,0x0A,0x54,0x88,0x0D,  /* 000000D8    "0.H..T.." */
 120.191 +    0x00,0x02,0x0F,0x00,0x00,0x00,0x00,0x00,  /* 000000E0    "........" */
 120.192 +    0xFF,0x00,0x00,0x00,0x00,0x01,0x47,0x01,  /* 000000E8    "......G." */
 120.193 +    0xF8,0x0C,0xF8,0x0C,0x01,0x08,0x88,0x0D,  /* 000000F0    "........" */
 120.194 +    0x00,0x01,0x0C,0x03,0x00,0x00,0x00,0x00,  /* 000000F8    "........" */
 120.195 +    0xF7,0x0C,0x00,0x00,0xF8,0x0C,0x88,0x0D,  /* 00000100    "........" */
 120.196 +    0x00,0x01,0x0C,0x03,0x00,0x00,0x00,0x0D,  /* 00000108    "........" */
 120.197 +    0xFF,0x0F,0x00,0x00,0x00,0x03,0x87,0x17,  /* 00000110    "........" */
 120.198 +    0x00,0x00,0x0C,0x02,0x00,0x00,0x00,0x00,  /* 00000118    "........" */
 120.199 +    0x00,0x00,0x0A,0x00,0xFF,0xFF,0x0F,0x00,  /* 00000120    "........" */
 120.200 +    0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,  /* 00000128    "........" */
 120.201 +    0x79,0x00,0xA4,0x50,0x52,0x54,0x30,0x08,  /* 00000130    "y..PRT0." */
 120.202 +    0x41,0x49,0x52,0x30,0x12,0x4F,0x04,0x06,  /* 00000138    "AIR0.O.." */
 120.203 +    0x12,0x0C,0x04,0x0C,0xFF,0xFF,0x1F,0x00,  /* 00000140    "........" */
 120.204 +    0x0A,0x02,0x00,0x0A,0x17,0x12,0x0C,0x04,  /* 00000148    "........" */
 120.205 +    0x0C,0xFF,0xFF,0x1F,0x00,0x0A,0x03,0x00,  /* 00000150    "........" */
 120.206 +    0x0A,0x13,0x12,0x0B,0x04,0x0C,0xFF,0xFF,  /* 00000158    "........" */
 120.207 +    0x1D,0x00,0x01,0x00,0x0A,0x13,0x12,0x0B,  /* 00000160    "........" */
 120.208 +    0x04,0x0C,0xFF,0xFF,0x1D,0x00,0x00,0x00,  /* 00000168    "........" */
 120.209 +    0x0A,0x10,0x12,0x0C,0x04,0x0C,0xFF,0xFF,  /* 00000170    "........" */
 120.210 +    0x1D,0x00,0x0A,0x02,0x00,0x0A,0x12,0x12,  /* 00000178    "........" */
 120.211 +    0x0C,0x04,0x0C,0xFF,0xFF,0x1D,0x00,0x0A,  /* 00000180    "........" */
 120.212 +    0x03,0x00,0x0A,0x17,0x14,0x0B,0x5F,0x50,  /* 00000188    "......_P" */
 120.213 +    0x52,0x54,0x00,0xA4,0x41,0x49,0x52,0x30,  /* 00000190    "RT..AIR0" */
 120.214 +    0x5B,0x82,0x42,0x2E,0x49,0x53,0x41,0x5F,  /* 00000198    "[.B.ISA_" */
 120.215 +    0x08,0x5F,0x41,0x44,0x52,0x0C,0x00,0x00,  /* 000001A0    "._ADR..." */
 120.216 +    0x01,0x00,0x5B,0x82,0x46,0x0B,0x53,0x59,  /* 000001A8    "..[.F.SY" */
 120.217 +    0x53,0x52,0x08,0x5F,0x48,0x49,0x44,0x0C,  /* 000001B0    "SR._HID." */
 120.218 +    0x41,0xD0,0x0C,0x02,0x08,0x5F,0x55,0x49,  /* 000001B8    "A...._UI" */
 120.219 +    0x44,0x01,0x08,0x43,0x52,0x53,0x5F,0x11,  /* 000001C0    "D..CRS_." */
 120.220 +    0x4E,0x08,0x0A,0x8A,0x47,0x01,0x10,0x00,  /* 000001C8    "N...G..." */
 120.221 +    0x10,0x00,0x00,0x10,0x47,0x01,0x22,0x00,  /* 000001D0    "....G."." */
 120.222 +    0x22,0x00,0x00,0x0C,0x47,0x01,0x30,0x00,  /* 000001D8    ""...G.0." */
 120.223 +    0x30,0x00,0x00,0x10,0x47,0x01,0x44,0x00,  /* 000001E0    "0...G.D." */
 120.224 +    0x44,0x00,0x00,0x1C,0x47,0x01,0x62,0x00,  /* 000001E8    "D...G.b." */
 120.225 +    0x62,0x00,0x00,0x02,0x47,0x01,0x65,0x00,  /* 000001F0    "b...G.e." */
 120.226 +    0x65,0x00,0x00,0x0B,0x47,0x01,0x72,0x00,  /* 000001F8    "e...G.r." */
 120.227 +    0x72,0x00,0x00,0x0E,0x47,0x01,0x80,0x00,  /* 00000200    "r...G..." */
 120.228 +    0x80,0x00,0x00,0x01,0x47,0x01,0x84,0x00,  /* 00000208    "....G..." */
 120.229 +    0x84,0x00,0x00,0x03,0x47,0x01,0x88,0x00,  /* 00000210    "....G..." */
 120.230 +    0x88,0x00,0x00,0x01,0x47,0x01,0x8C,0x00,  /* 00000218    "....G..." */
 120.231 +    0x8C,0x00,0x00,0x03,0x47,0x01,0x90,0x00,  /* 00000220    "....G..." */
 120.232 +    0x90,0x00,0x00,0x10,0x47,0x01,0xA2,0x00,  /* 00000228    "....G..." */
 120.233 +    0xA2,0x00,0x00,0x1C,0x47,0x01,0xE0,0x00,  /* 00000230    "....G..." */
 120.234 +    0xE0,0x00,0x00,0x10,0x47,0x01,0xA0,0x08,  /* 00000238    "....G..." */
 120.235 +    0xA0,0x08,0x00,0x04,0x47,0x01,0xC0,0x0C,  /* 00000240    "....G..." */
 120.236 +    0xC0,0x0C,0x00,0x10,0x47,0x01,0xD0,0x04,  /* 00000248    "....G..." */
 120.237 +    0xD0,0x04,0x00,0x02,0x79,0x00,0x14,0x0B,  /* 00000250    "....y..." */
 120.238 +    0x5F,0x43,0x52,0x53,0x00,0xA4,0x43,0x52,  /* 00000258    "_CRS..CR" */
 120.239 +    0x53,0x5F,0x5B,0x82,0x2B,0x50,0x49,0x43,  /* 00000260    "S_[.+PIC" */
 120.240 +    0x5F,0x08,0x5F,0x48,0x49,0x44,0x0B,0x41,  /* 00000268    "_._HID.A" */
 120.241 +    0xD0,0x08,0x5F,0x43,0x52,0x53,0x11,0x18,  /* 00000270    ".._CRS.." */
 120.242 +    0x0A,0x15,0x47,0x01,0x20,0x00,0x20,0x00,  /* 00000278    "..G. . ." */
 120.243 +    0x01,0x02,0x47,0x01,0xA0,0x00,0xA0,0x00,  /* 00000280    "..G....." */
 120.244 +    0x01,0x02,0x22,0x04,0x00,0x79,0x00,0x5B,  /* 00000288    ".."..y.[" */
 120.245 +    0x82,0x47,0x05,0x44,0x4D,0x41,0x30,0x08,  /* 00000290    ".G.DMA0." */
 120.246 +    0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x02,  /* 00000298    "_HID.A.." */
 120.247 +    0x00,0x08,0x5F,0x43,0x52,0x53,0x11,0x41,  /* 000002A0    ".._CRS.A" */
 120.248 +    0x04,0x0A,0x3D,0x2A,0x10,0x04,0x47,0x01,  /* 000002A8    "..=*..G." */
 120.249 +    0x00,0x00,0x00,0x00,0x00,0x10,0x47,0x01,  /* 000002B0    "......G." */
 120.250 +    0x81,0x00,0x81,0x00,0x00,0x03,0x47,0x01,  /* 000002B8    "......G." */
 120.251 +    0x87,0x00,0x87,0x00,0x00,0x01,0x47,0x01,  /* 000002C0    "......G." */
 120.252 +    0x89,0x00,0x89,0x00,0x00,0x03,0x47,0x01,  /* 000002C8    "......G." */
 120.253 +    0x8F,0x00,0x8F,0x00,0x00,0x01,0x47,0x01,  /* 000002D0    "......G." */
 120.254 +    0xC0,0x00,0xC0,0x00,0x00,0x20,0x47,0x01,  /* 000002D8    "..... G." */
 120.255 +    0x80,0x04,0x80,0x04,0x00,0x10,0x79,0x00,  /* 000002E0    "......y." */
 120.256 +    0x5B,0x82,0x25,0x54,0x4D,0x52,0x5F,0x08,  /* 000002E8    "[.%TMR_." */
 120.257 +    0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x01,  /* 000002F0    "_HID.A.." */
 120.258 +    0x00,0x08,0x5F,0x43,0x52,0x53,0x11,0x10,  /* 000002F8    ".._CRS.." */
 120.259 +    0x0A,0x0D,0x47,0x01,0x40,0x00,0x40,0x00,  /* 00000300    "..G.@.@." */
 120.260 +    0x00,0x04,0x22,0x01,0x00,0x79,0x00,0x5B,  /* 00000308    ".."..y.[" */
 120.261 +    0x82,0x25,0x52,0x54,0x43,0x5F,0x08,0x5F,  /* 00000310    ".%RTC_._" */
 120.262 +    0x48,0x49,0x44,0x0C,0x41,0xD0,0x0B,0x00,  /* 00000318    "HID.A..." */
 120.263 +    0x08,0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,  /* 00000320    "._CRS..." */
 120.264 +    0x0D,0x47,0x01,0x70,0x00,0x70,0x00,0x00,  /* 00000328    ".G.p.p.." */
 120.265 +    0x02,0x22,0x00,0x01,0x79,0x00,0x5B,0x82,  /* 00000330    "."..y.[." */
 120.266 +    0x22,0x53,0x50,0x4B,0x52,0x08,0x5F,0x48,  /* 00000338    ""SPKR._H" */
 120.267 +    0x49,0x44,0x0C,0x41,0xD0,0x08,0x00,0x08,  /* 00000340    "ID.A...." */
 120.268 +    0x5F,0x43,0x52,0x53,0x11,0x0D,0x0A,0x0A,  /* 00000348    "_CRS...." */
 120.269 +    0x47,0x01,0x61,0x00,0x61,0x00,0x00,0x01,  /* 00000350    "G.a.a..." */
 120.270 +    0x79,0x00,0x5B,0x82,0x31,0x50,0x53,0x32,  /* 00000358    "y.[.1PS2" */
 120.271 +    0x4D,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 00000360    "M._HID.A" */
 120.272 +    0xD0,0x0F,0x13,0x08,0x5F,0x43,0x49,0x44,  /* 00000368    "...._CID" */
 120.273 +    0x0C,0x41,0xD0,0x0F,0x13,0x14,0x09,0x5F,  /* 00000370    ".A....._" */
 120.274 +    0x53,0x54,0x41,0x00,0xA4,0x0A,0x0F,0x08,  /* 00000378    "STA....." */
 120.275 +    0x5F,0x43,0x52,0x53,0x11,0x08,0x0A,0x05,  /* 00000380    "_CRS...." */
 120.276 +    0x22,0x00,0x10,0x79,0x00,0x5B,0x82,0x42,  /* 00000388    ""..y.[.B" */
 120.277 +    0x04,0x50,0x53,0x32,0x4B,0x08,0x5F,0x48,  /* 00000390    ".PS2K._H" */
 120.278 +    0x49,0x44,0x0C,0x41,0xD0,0x03,0x03,0x08,  /* 00000398    "ID.A...." */
 120.279 +    0x5F,0x43,0x49,0x44,0x0C,0x41,0xD0,0x03,  /* 000003A0    "_CID.A.." */
 120.280 +    0x0B,0x14,0x09,0x5F,0x53,0x54,0x41,0x00,  /* 000003A8    "..._STA." */
 120.281 +    0xA4,0x0A,0x0F,0x08,0x5F,0x43,0x52,0x53,  /* 000003B0    "...._CRS" */
 120.282 +    0x11,0x18,0x0A,0x15,0x47,0x01,0x60,0x00,  /* 000003B8    "....G.`." */
 120.283 +    0x60,0x00,0x00,0x01,0x47,0x01,0x64,0x00,  /* 000003C0    "`...G.d." */
 120.284 +    0x64,0x00,0x00,0x01,0x22,0x02,0x00,0x79,  /* 000003C8    "d..."..y" */
 120.285 +    0x00,0x5B,0x82,0x3A,0x46,0x44,0x43,0x30,  /* 000003D0    ".[.:FDC0" */
 120.286 +    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 000003D8    "._HID.A." */
 120.287 +    0x07,0x00,0x14,0x09,0x5F,0x53,0x54,0x41,  /* 000003E0    "...._STA" */
 120.288 +    0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,0x52,  /* 000003E8    "....._CR" */
 120.289 +    0x53,0x11,0x1B,0x0A,0x18,0x47,0x01,0xF0,  /* 000003F0    "S....G.." */
 120.290 +    0x03,0xF0,0x03,0x01,0x06,0x47,0x01,0xF7,  /* 000003F8    ".....G.." */
 120.291 +    0x03,0xF7,0x03,0x01,0x01,0x22,0x40,0x00,  /* 00000400    "....."@." */
 120.292 +    0x2A,0x04,0x00,0x79,0x00,0x5B,0x82,0x35,  /* 00000408    "*..y.[.5" */
 120.293 +    0x55,0x41,0x52,0x31,0x08,0x5F,0x48,0x49,  /* 00000410    "UAR1._HI" */
 120.294 +    0x44,0x0C,0x41,0xD0,0x05,0x01,0x08,0x5F,  /* 00000418    "D.A...._" */
 120.295 +    0x55,0x49,0x44,0x01,0x14,0x09,0x5F,0x53,  /* 00000420    "UID..._S" */
 120.296 +    0x54,0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,  /* 00000428    "TA....._" */
 120.297 +    0x43,0x52,0x53,0x11,0x10,0x0A,0x0D,0x47,  /* 00000430    "CRS....G" */
 120.298 +    0x01,0xF8,0x03,0xF8,0x03,0x01,0x08,0x22,  /* 00000438    "......."" */
 120.299 +    0x10,0x00,0x79,0x00,0x5B,0x82,0x36,0x55,  /* 00000440    "..y.[.6U" */
 120.300 +    0x41,0x52,0x32,0x08,0x5F,0x48,0x49,0x44,  /* 00000448    "AR2._HID" */
 120.301 +    0x0C,0x41,0xD0,0x05,0x01,0x08,0x5F,0x55,  /* 00000450    ".A...._U" */
 120.302 +    0x49,0x44,0x0A,0x02,0x14,0x09,0x5F,0x53,  /* 00000458    "ID...._S" */
 120.303 +    0x54,0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,  /* 00000460    "TA....._" */
 120.304 +    0x43,0x52,0x53,0x11,0x10,0x0A,0x0D,0x47,  /* 00000468    "CRS....G" */
 120.305 +    0x01,0xF8,0x02,0xF8,0x02,0x01,0x08,0x22,  /* 00000470    "......."" */
 120.306 +    0x08,0x00,0x79,0x00,
 120.307  };
 120.308  int DsdtLen=sizeof(AmlCode);
   121.1 --- a/tools/firmware/acpi/acpi_fadt.h	Mon May 22 08:53:26 2006 -0600
   121.2 +++ b/tools/firmware/acpi/acpi_fadt.h	Mon May 22 14:13:38 2006 -0600
   121.3 @@ -59,7 +59,7 @@
   121.4  #define ACPI_PM1A_EVT_BLK_ADDRESS_SPACE_ID  ACPI_SYSTEM_IO
   121.5  #define ACPI_PM1A_EVT_BLK_BIT_WIDTH         0x00
   121.6  #define ACPI_PM1A_EVT_BLK_BIT_OFFSET        0x00
   121.7 -#define ACPI_PM1A_EVT_BLK_ADDRESS           0x0000000000000000
   121.8 +#define ACPI_PM1A_EVT_BLK_ADDRESS           0x0000000000008000
   121.9  
  121.10  //
  121.11  // PM1B Event Register Block Generic Address Information
  121.12 @@ -73,7 +73,7 @@
  121.13  // PM1A Control Register Block Generic Address Information
  121.14  //
  121.15  #define ACPI_PM1A_CNT_BLK_ADDRESS_SPACE_ID  ACPI_SYSTEM_IO
  121.16 -#define ACPI_PM1A_CNT_BLK_BIT_WIDTH         0x10
  121.17 +#define ACPI_PM1A_CNT_BLK_BIT_WIDTH         0x08
  121.18  #define ACPI_PM1A_CNT_BLK_BIT_OFFSET        0x00
  121.19  #define ACPI_PM1A_CNT_BLK_ADDRESS           (ACPI_PM1A_EVT_BLK_ADDRESS + 0x04)
  121.20  
   122.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   122.2 +++ b/tools/ioemu/hw/acpi.c	Mon May 22 14:13:38 2006 -0600
   122.3 @@ -0,0 +1,178 @@
   122.4 +/*
   122.5 + * ACPI emulation
   122.6 + * 
   122.7 + * Copyright (c) 2006 Virtual Iron Software
   122.8 + *
   122.9 + * This module provides the beginnings of some ACPI emulation.
  122.10 + * Initially, this code handles writes to the sleep state
  122.11 + * registers. This is done to detect requests to power-off
  122.12 + * a guest domain.
  122.13 + *
  122.14 + * Later, and driven by empirical evidence, additional capabilities
  122.15 + * and emulation might be added.
  122.16 + *
  122.17 + * Currently, the FADT specifies a small register set, of which
  122.18 + * only PM1_CNTa is available.  In addition, the ASL code specifies
  122.19 + * the proper values to write on an S5 (poweroff) request, which
  122.20 + * this code understands.
  122.21 + *
  122.22 + */
  122.23 +
  122.24 +#include "vl.h"
  122.25 +extern FILE* logfile;
  122.26 +
  122.27 +// Define some basic offsets to ACPI registers
  122.28 +
  122.29 +//#define DEBUG_ACPI
  122.30 +#define	PM1a_STS	0x0
  122.31 +#define	PM1a_EN		0x1
  122.32 +#define	PM1b_STS	0x2
  122.33 +#define	PM1b_EN		0x3
  122.34 +#define	PM1_CNTa	0x4
  122.35 +#define	PM1_CNTb	0x6
  122.36 +
  122.37 +// Values within PM1_CNTa that we need for power handling
  122.38 +
  122.39 +#define	SLP_TYP_MASK	0x1C00
  122.40 +#define	SLP_VAL		0x1C00
  122.41 +#define	SLP_EN		0x2000
  122.42 +
  122.43 +// Base ACPI register address
  122.44 +
  122.45 +static unsigned int acpi_base = 0;
  122.46 +
  122.47 +/* acpi_write_byte - handle byte writes for ACPI I/O region
  122.48 + *
  122.49 + * Input:
  122.50 + *	opaque	pointer to private data structure (currently NULL)
  122.51 + *	addr	I/O space address to be written
  122.52 + *	data	data to be written
  122.53 + *
  122.54 + * Output:
  122.55 + *	none
  122.56 + *
  122.57 + * Returns:
  122.58 + *	none
  122.59 + */
  122.60 +
  122.61 +static void acpi_write_byte(void *opaque, uint32_t addr, uint32_t data) {
  122.62 +
  122.63 +#ifdef DEBUG_ACPI
  122.64 +    fprintf(logfile, "%s - addr 0x%x, data 0x%x\n", __FUNCTION__, addr, data);
  122.65 +#endif
  122.66 +
  122.67 +    // All byte writes are currently ignored
  122.68 +
  122.69 +    return;
  122.70 +}
  122.71 +
  122.72 +/* acpi_write_word - handle word writes for ACPI I/O region
  122.73 + *
  122.74 + * Input:
  122.75 + *	opaque	pointer to private data structure (currently NULL)
  122.76 + *	addr	I/O space address to be written
  122.77 + *	data	data to be written
  122.78 + *
  122.79 + * Output:
  122.80 + *	none
  122.81 + *
  122.82 + * Returns:
  122.83 + *	none
  122.84 + */
  122.85 +
  122.86 +static void acpi_write_word(void *opaque, uint32_t addr, uint32_t data) {
  122.87 +
  122.88 +#ifdef DEBUG_ACPI
  122.89 +    fprintf(logfile, "%s - addr 0x%x, data 0x%x\n", __FUNCTION__, addr, data);
  122.90 +#endif
  122.91 +
  122.92 +    // Only a write to PM1_CNTa for power operations is handled
  122.93 +    // All others are ignored
  122.94 +
  122.95 +    if (addr == acpi_base + PM1_CNTa) {
  122.96 +        if ( ( (data & SLP_EN) != 0) &&
  122.97 +             ( (data & SLP_TYP_MASK) == SLP_VAL) ) {
  122.98 +            qemu_system_shutdown_request();
  122.99 +            fprintf(logfile, "%s - ACPI Power State 5 (poweroff) requested\n", __FUNCTION__);
 122.100 +        }
 122.101 +    }
 122.102 +
 122.103 +    return;
 122.104 +}
 122.105 +
 122.106 +/* acpi_read_byte - handle byte reads for ACPI I/O region
 122.107 + *
 122.108 + * Input:
 122.109 + *	opaque	pointer to private data structure (currently NULL)
 122.110 + *	addr	I/O space address to be written
 122.111 + *
 122.112 + * Output:
 122.113 + *	none
 122.114 + *
 122.115 + * Returns:
 122.116 + *	data read
 122.117 + */
 122.118 +
 122.119 +static uint32_t acpi_read_byte(void *opaque, uint32_t addr) {
 122.120 +
 122.121 +#ifdef DEBUG_ACPI
 122.122 +    fprintf(logfile, "%s - addr 0x%x\n", __FUNCTION__, addr);
 122.123 +#endif
 122.124 +
 122.125 +    // All reads return 0
 122.126 +
 122.127 +    return 0;
 122.128 +}
 122.129 +
 122.130 +/* acpi_read_word - handle word reads for ACPI I/O region
 122.131 + *
 122.132 + * Input:
 122.133 + *	opaque	pointer to private data structure (currently NULL)
 122.134 + *	addr	I/O space address to be written
 122.135 + *
 122.136 + * Output:
 122.137 + *	none
 122.138 + *
 122.139 + * Returns:
 122.140 + *	data read
 122.141 + */
 122.142 +
 122.143 +static uint32_t acpi_read_word(void *opaque, uint32_t addr) {
 122.144 +
 122.145 +#ifdef DEBUG_ACPI
 122.146 +    fprintf(logfile, "%s - addr 0x%x\n", __FUNCTION__, addr);
 122.147 +#endif
 122.148 +
 122.149 +    // All reads return 0
 122.150 +
 122.151 +    return 0;
 122.152 +}
 122.153 +
 122.154 +/* acpi_init - initialize for ACPI I/O space operation handling
 122.155 + *
 122.156 + * Input:
 122.157 + *	base	base I/O address
 122.158 + *
 122.159 + * Output:
 122.160 + *	none
 122.161 + *
 122.162 + * Returns:
 122.163 + *	status
 122.164 + */
 122.165 +
 122.166 +int acpi_init(unsigned int base) {
 122.167 +
 122.168 +    fprintf(logfile, "%s - registering ACPI addresses at 0x%x\n", __FUNCTION__, base);
 122.169 +
 122.170 +    // Map 16 bytes of reads/writes for bytes/words
 122.171 +
 122.172 +    register_ioport_write(base, 16, sizeof(unsigned char), acpi_write_byte, NULL);
 122.173 +    register_ioport_read(base,  16, sizeof(unsigned char), acpi_read_byte,  NULL);
 122.174 +
 122.175 +    register_ioport_write(base, 16, sizeof(unsigned short), acpi_write_word, NULL);
 122.176 +    register_ioport_read(base,  16, sizeof(unsigned short), acpi_read_word,  NULL);
 122.177 +
 122.178 +    acpi_base = base;
 122.179 +
 122.180 +    return 0;
 122.181 +}
   123.1 --- a/tools/ioemu/hw/cirrus_vga.c	Mon May 22 08:53:26 2006 -0600
   123.2 +++ b/tools/ioemu/hw/cirrus_vga.c	Mon May 22 14:13:38 2006 -0600
   123.3 @@ -28,6 +28,9 @@
   123.4   */
   123.5  #include "vl.h"
   123.6  #include "vga_int.h"
   123.7 +#ifndef _WIN32
   123.8 +#include <sys/mman.h>
   123.9 +#endif
  123.10  
  123.11  /*
  123.12   * TODO:
  123.13 @@ -269,7 +272,8 @@ typedef struct CirrusVGAState {
  123.14      int last_hw_cursor_y_end;
  123.15      int real_vram_size; /* XXX: suppress that */
  123.16      CPUWriteMemoryFunc **cirrus_linear_write;
  123.17 -    int set_mapping;
  123.18 +    unsigned long map_addr;
  123.19 +    unsigned long map_end;
  123.20  } CirrusVGAState;
  123.21  
  123.22  typedef struct PCICirrusVGAState {
  123.23 @@ -1187,6 +1191,17 @@ cirrus_hook_write_sr(CirrusVGAState * s,
  123.24  	s->hw_cursor_y = (reg_value << 3) | (reg_index >> 5);
  123.25  	break;
  123.26      case 0x07:			// Extended Sequencer Mode
  123.27 +	/* Win2K seems to assume that the VRAM is set to 0xff
  123.28 +	 *   whenever VGA/SVGA mode changes 
  123.29 +	 */
  123.30 +	if ((s->sr[0x07] ^ reg_value) & CIRRUS_SR7_BPP_SVGA)
  123.31 +	    memset(s->vram_ptr, 0xff, s->real_vram_size);
  123.32 +	s->sr[0x07] = reg_value;
  123.33 +#ifdef DEBUG_CIRRUS 
  123.34 +	printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
  123.35 +	       reg_index, reg_value);
  123.36 +#endif
  123.37 +	break;
  123.38      case 0x08:			// EEPROM Control
  123.39      case 0x09:			// Scratch Register 0
  123.40      case 0x0a:			// Scratch Register 1
  123.41 @@ -2444,14 +2459,97 @@ static CPUWriteMemoryFunc *cirrus_linear
  123.42      cirrus_linear_bitblt_writel,
  123.43  };
  123.44  
  123.45 +extern FILE *logfile;
  123.46 +#if defined(__i386__) || defined (__x86_64__)
  123.47 +static void * set_vram_mapping(unsigned long begin, unsigned long end)
  123.48 +{
  123.49 +    unsigned long * extent_start = NULL;
  123.50 +    unsigned long nr_extents;
  123.51 +    void *vram_pointer = NULL;
  123.52 +    int i;
  123.53 +
  123.54 +    /* align begin and end address */
  123.55 +    begin = begin & TARGET_PAGE_MASK;
  123.56 +    end = begin + VGA_RAM_SIZE;
  123.57 +    end = (end + TARGET_PAGE_SIZE -1 ) & TARGET_PAGE_MASK;
  123.58 +    nr_extents = (end - begin) >> TARGET_PAGE_BITS;
  123.59 +
  123.60 +    extent_start = malloc(sizeof(unsigned long) * nr_extents );
  123.61 +    if (extent_start == NULL)
  123.62 +    {
  123.63 +        fprintf(stderr, "Failed malloc on set_vram_mapping\n");
  123.64 +        return NULL;
  123.65 +    }
  123.66 +
  123.67 +    memset(extent_start, 0, sizeof(unsigned long) * nr_extents);
  123.68 +
  123.69 +    for (i = 0; i < nr_extents; i++)
  123.70 +    {
  123.71 +        extent_start[i] = (begin + i * TARGET_PAGE_SIZE) >> TARGET_PAGE_BITS;
  123.72 +    }
  123.73 +
  123.74 +    set_mm_mapping(xc_handle, domid, nr_extents, 0, extent_start);
  123.75 +
  123.76 +    if ( (vram_pointer =  xc_map_foreign_batch(xc_handle, domid,
  123.77 +                                               PROT_READ|PROT_WRITE,
  123.78 +                                               extent_start,
  123.79 +                                               nr_extents)) == NULL)
  123.80 +    {
  123.81 +        fprintf(logfile,
  123.82 +          "xc_map_foreign_batch vgaram returned error %d\n", errno);
  123.83 +        return NULL;
  123.84 +    }
  123.85 +
  123.86 +    memset(vram_pointer, 0, nr_extents * TARGET_PAGE_SIZE);
  123.87 +
  123.88 +    free(extent_start);
  123.89 +
  123.90 +    return vram_pointer;
  123.91 +}
  123.92 +
  123.93 +static int unset_vram_mapping(unsigned long begin, unsigned long end)
  123.94 +{
  123.95 +    unsigned long * extent_start = NULL;
  123.96 +    unsigned long nr_extents;
  123.97 +    int i;
  123.98 +
  123.99 +    /* align begin and end address */
 123.100 +
 123.101 +    end = begin + VGA_RAM_SIZE;
 123.102 +    begin = begin & TARGET_PAGE_MASK;
 123.103 +    end = (end + TARGET_PAGE_SIZE -1 ) & TARGET_PAGE_MASK;
 123.104 +    nr_extents = (end - begin) >> TARGET_PAGE_BITS;
 123.105 +
 123.106 +    extent_start = malloc(sizeof(unsigned long) * nr_extents );
 123.107 +
 123.108 +    if (extent_start == NULL)
 123.109 +    {
 123.110 +        fprintf(stderr, "Failed malloc on set_mm_mapping\n");
 123.111 +        return -1;
 123.112 +    }
 123.113 +
 123.114 +    memset(extent_start, 0, sizeof(unsigned long) * nr_extents);
 123.115 +
 123.116 +    for (i = 0; i < nr_extents; i++)
 123.117 +        extent_start[i] = (begin + (i * TARGET_PAGE_SIZE)) >> TARGET_PAGE_BITS;
 123.118 +
 123.119 +    unset_mm_mapping(xc_handle, domid, nr_extents, 0, extent_start);
 123.120 +
 123.121 +    free(extent_start);
 123.122 +
 123.123 +    return 0;
 123.124 +}
 123.125 +
 123.126 +#elif defined(__ia64__)
 123.127 +static void * set_vram_mapping(unsigned long addr, unsigned long end) {}
 123.128 +static int unset_vram_mapping(unsigned long addr, unsigned long end) {}
 123.129 +#endif
 123.130 +extern int vga_accelerate;
 123.131 +
 123.132  /* Compute the memory access functions */
 123.133  static void cirrus_update_memory_access(CirrusVGAState *s)
 123.134  {
 123.135      unsigned mode;
 123.136 -    extern void * set_vram_mapping(unsigned long addr, unsigned long end);
 123.137 -
 123.138 -    extern int unset_vram_mapping(unsigned long addr, unsigned long end);
 123.139 -    extern int vga_accelerate;
 123.140  
 123.141      if ((s->sr[0x17] & 0x44) == 0x44) {
 123.142          goto generic_io;
 123.143 @@ -2466,18 +2564,21 @@ static void cirrus_update_memory_access(
 123.144  
 123.145      mode = s->gr[0x05] & 0x7;
 123.146      if (mode < 4 || mode > 5 || ((s->gr[0x0B] & 0x4) == 0)) {
 123.147 -            if (vga_accelerate && s->cirrus_lfb_addr && s->cirrus_lfb_end) {
 123.148 -                if (!s->set_mapping) {
 123.149 -                    void * vram_pointer;
 123.150 -                    s->set_mapping = 1;
 123.151 -                    vram_pointer = set_vram_mapping(s->cirrus_lfb_addr ,s->cirrus_lfb_end);
 123.152 -                    if (!vram_pointer){
 123.153 +            if ( vga_accelerate && s->cirrus_lfb_addr && s->cirrus_lfb_end ) {
 123.154 +                if (!s->map_addr) {
 123.155 +                    void *vram_pointer, *old_vram;
 123.156 +
 123.157 +                    vram_pointer =
 123.158 +                      set_vram_mapping(s->cirrus_lfb_addr ,s->cirrus_lfb_end);
 123.159 +                    if (!vram_pointer) {
 123.160                          fprintf(stderr, "NULL vram_pointer\n");
 123.161 -                    } else
 123.162 -                    {
 123.163 -                        vga_update_vram((VGAState *)s, vram_pointer,
 123.164 +                    } else {
 123.165 +                        old_vram = vga_update_vram((VGAState *)s, vram_pointer,
 123.166                                          VGA_RAM_SIZE);
 123.167 +                        qemu_free(old_vram);
 123.168                      }
 123.169 +                    s->map_addr = s->cirrus_lfb_addr;
 123.170 +                    s->map_end = s->cirrus_lfb_end;
 123.171                  }
 123.172              }
 123.173              s->cirrus_linear_write[0] = cirrus_linear_mem_writeb;
 123.174 @@ -2486,13 +2587,19 @@ static void cirrus_update_memory_access(
 123.175          } else {
 123.176          generic_io:
 123.177              if (vga_accelerate && s->cirrus_lfb_addr && s->cirrus_lfb_end) {
 123.178 -                if(s->set_mapping) {
 123.179 +                if(s->map_addr) {
 123.180                      int error;
 123.181 -                    s->set_mapping = 0;
 123.182 +                    void *old_vram = NULL;
 123.183 +
 123.184                      error = unset_vram_mapping(s->cirrus_lfb_addr,
 123.185                                             s->cirrus_lfb_end);
 123.186                      if (!error)
 123.187 -                        vga_update_vram((VGAState *)s, NULL, VGA_RAM_SIZE);
 123.188 +                        old_vram =
 123.189 +                          vga_update_vram((VGAState *)s, NULL, VGA_RAM_SIZE);
 123.190 +
 123.191 +                    if (old_vram)
 123.192 +                        munmap(old_vram, s->map_addr - s->map_end);
 123.193 +                    s->map_addr = s->map_end = 0;
 123.194                  }
 123.195              }
 123.196  
 123.197 @@ -3021,10 +3128,6 @@ static void cirrus_init_common(CirrusVGA
 123.198      }
 123.199      s->cr[0x27] = device_id;
 123.200  
 123.201 -    /* Win2K seems to assume that the pattern buffer is at 0xff
 123.202 -       initially ! */
 123.203 -    memset(s->vram_ptr, 0xff, s->real_vram_size);
 123.204 -
 123.205      s->cirrus_hidden_dac_lockindex = 5;
 123.206      s->cirrus_hidden_dac_data = 0;
 123.207  
 123.208 @@ -3091,6 +3194,12 @@ static void cirrus_pci_lfb_map(PCIDevice
 123.209  				 s->cirrus_linear_io_addr);
 123.210      s->cirrus_lfb_addr = addr;
 123.211      s->cirrus_lfb_end = addr + VGA_RAM_SIZE;
 123.212 +
 123.213 +    if ( vga_accelerate && s->map_addr &&
 123.214 +         (s->cirrus_lfb_addr != s->map_addr) &&
 123.215 +         (s->cirrus_lfb_end != s->map_end))
 123.216 +        fprintf(logfile, "cirrus vga map change while on lfb mode\n");
 123.217 +
 123.218      cpu_register_physical_memory(addr + 0x1000000, 0x400000,
 123.219  				 s->cirrus_linear_bitblt_io_addr);
 123.220  }
   124.1 --- a/tools/ioemu/hw/mc146818rtc.c	Mon May 22 08:53:26 2006 -0600
   124.2 +++ b/tools/ioemu/hw/mc146818rtc.c	Mon May 22 14:13:38 2006 -0600
   124.3 @@ -178,10 +178,27 @@ static inline int from_bcd(RTCState *s, 
   124.4      }
   124.5  }
   124.6  
   124.7 +static void send_timeoffset_msg(time_t delta)
   124.8 +{
   124.9 +
  124.10 +/* This routine is used to inform another entity that the
  124.11 +   base time offset has changed. For instance, if you
  124.12 +   were using xenstore, you might want to write to the store
  124.13 +   at this point.  Or, you might use some other method.
  124.14 +   Whatever you might choose, here's a hook point to implement it.
  124.15 +
  124.16 +   One item of note is that this delta is in addition to
  124.17 +   any existing offset you might be already using. */
  124.18 +
  124.19 +    return;
  124.20 +}
  124.21 +
  124.22  static void rtc_set_time(RTCState *s)
  124.23  {
  124.24      struct tm *tm = &s->current_tm;
  124.25 -
  124.26 +    time_t before, after;
  124.27 +    
  124.28 +    before = mktime(tm);
  124.29      tm->tm_sec = from_bcd(s, s->cmos_data[RTC_SECONDS]);
  124.30      tm->tm_min = from_bcd(s, s->cmos_data[RTC_MINUTES]);
  124.31      tm->tm_hour = from_bcd(s, s->cmos_data[RTC_HOURS] & 0x7f);
  124.32 @@ -193,6 +210,12 @@ static void rtc_set_time(RTCState *s)
  124.33      tm->tm_mday = from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]);
  124.34      tm->tm_mon = from_bcd(s, s->cmos_data[RTC_MONTH]) - 1;
  124.35      tm->tm_year = from_bcd(s, s->cmos_data[RTC_YEAR]) + 100;
  124.36 +
  124.37 +    /* Compute, and send, the additional time delta
  124.38 +       We could compute the total time delta, but this is
  124.39 +       sufficient, and simple. */
  124.40 +    after = mktime(tm);
  124.41 +    send_timeoffset_msg(after-before);
  124.42  }
  124.43  
  124.44  static void rtc_copy_date(RTCState *s)
   125.1 --- a/tools/ioemu/hw/pc.c	Mon May 22 08:53:26 2006 -0600
   125.2 +++ b/tools/ioemu/hw/pc.c	Mon May 22 14:13:38 2006 -0600
   125.3 @@ -118,7 +118,7 @@ static void cmos_init_hd(int type_ofs, i
   125.4  }
   125.5  
   125.6  /* hd_table must contain 4 block drivers */
   125.7 -static void cmos_init(uint64_t ram_size, int boot_device, BlockDriverState **hd_table)
   125.8 +static void cmos_init(uint64_t ram_size, int boot_device, BlockDriverState **hd_table, time_t timeoffset)
   125.9  {
  125.10      RTCState *s = rtc_state;
  125.11      int val;
  125.12 @@ -129,6 +129,7 @@ static void cmos_init(uint64_t ram_size,
  125.13  
  125.14      /* set the CMOS date */
  125.15      time(&ti);
  125.16 +    ti += timeoffset;
  125.17      if (rtc_utc)
  125.18          tm = gmtime(&ti);
  125.19      else
  125.20 @@ -373,18 +374,20 @@ static int ne2000_irq[NE2000_NB_MAX] = {
  125.21  static int serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
  125.22  static int serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
  125.23  
  125.24 +extern int acpi_init(unsigned int base);
  125.25 +
  125.26  #define NOBIOS 1
  125.27  
  125.28  /* PC hardware initialisation */
  125.29  void pc_init(uint64_t ram_size, int vga_ram_size, int boot_device,
  125.30               DisplayState *ds, const char **fd_filename, int snapshot,
  125.31               const char *kernel_filename, const char *kernel_cmdline,
  125.32 -             const char *initrd_filename)
  125.33 +             const char *initrd_filename, time_t timeoffset)
  125.34  {
  125.35 +    SerialState *sp;
  125.36      char buf[1024];
  125.37      int ret, linux_boot, initrd_size, i, nb_nics1;
  125.38      PCIBus *pci_bus;
  125.39 -    extern void * shared_vram;
  125.40      
  125.41      linux_boot = (kernel_filename != NULL);
  125.42  
  125.43 @@ -511,14 +514,14 @@ void pc_init(uint64_t ram_size, int vga_
  125.44      if (cirrus_vga_enabled) {
  125.45          if (pci_enabled) {
  125.46              pci_cirrus_vga_init(pci_bus, 
  125.47 -                                ds, shared_vram, ram_size, 
  125.48 +                                ds, NULL, ram_size, 
  125.49                                  vga_ram_size);
  125.50          } else {
  125.51 -            isa_cirrus_vga_init(ds, shared_vram, ram_size, 
  125.52 +            isa_cirrus_vga_init(ds, NULL, ram_size, 
  125.53                                  vga_ram_size);
  125.54          }
  125.55      } else {
  125.56 -        vga_initialize(pci_bus, ds, shared_vram, ram_size, 
  125.57 +        vga_initialize(pci_bus, ds, NULL, ram_size, 
  125.58                         vga_ram_size);
  125.59      }
  125.60  
  125.61 @@ -533,7 +536,9 @@ void pc_init(uint64_t ram_size, int vga_
  125.62  
  125.63      for(i = 0; i < MAX_SERIAL_PORTS; i++) {
  125.64          if (serial_hds[i]) {
  125.65 -            serial_init(serial_io[i], serial_irq[i], serial_hds[i]);
  125.66 +            sp = serial_init(serial_io[i], serial_irq[i], serial_hds[i]);
  125.67 +            if (i == SUMMA_PORT)
  125.68 +		summa_init(sp, serial_hds[i]);
  125.69          }
  125.70      }
  125.71  
  125.72 @@ -573,7 +578,8 @@ void pc_init(uint64_t ram_size, int vga_
  125.73  
  125.74      floppy_controller = fdctrl_init(6, 2, 0, 0x3f0, fd_table);
  125.75  
  125.76 -    cmos_init(ram_size, boot_device, bs_table);
  125.77 +    cmos_init(ram_size, boot_device, bs_table, timeoffset);
  125.78 +    acpi_init(0x8000);
  125.79  
  125.80      /* must be done after all PCI devices are instanciated */
  125.81      /* XXX: should be done in the Bochs BIOS */
   126.1 --- a/tools/ioemu/hw/pckbd.c	Mon May 22 08:53:26 2006 -0600
   126.2 +++ b/tools/ioemu/hw/pckbd.c	Mon May 22 14:13:38 2006 -0600
   126.3 @@ -156,11 +156,24 @@ typedef struct KBDState {
   126.4      int mouse_dz;
   126.5      uint8_t mouse_buttons;
   126.6      CharDriverState *chr;
   126.7 -    void *cookie;
   126.8 +    SerialState *serial;
   126.9  } KBDState;
  126.10  
  126.11  KBDState kbd_state;
  126.12  
  126.13 +#define MODE_STREAM_SWITCH	0
  126.14 +#define MODE_STREAM		1
  126.15 +#define MODE_REMOTE		2
  126.16 +#define MODE_POINT		3
  126.17 +
  126.18 +#define ORIGIN_LOWER_LEFT	0
  126.19 +#define ORIGIN_UPPER_LEFT	1
  126.20 +
  126.21 +struct SummaState {
  126.22 +	int report_mode;
  126.23 +	int origin;
  126.24 +} SummaState;
  126.25 +
  126.26  int summa_ok;		/* Allow Summagraphics emulation if true */
  126.27  
  126.28  /* update irq and KBD_STAT_[MOUSE_]OBF */
  126.29 @@ -420,15 +433,19 @@ static int kbd_mouse_send_packet(KBDStat
  126.30      switch(s->mouse_type) {
  126.31    
  126.32      case TABLET:        /* Summagraphics pen tablet */
  126.33 -	dx1 = s->mouse_x;
  126.34 -	dy1 = s->mouse_y;
  126.35 -	dx1 = ((dx1 * SUMMA_MAXX) / mouse_maxx) + SUMMA_BORDER;
  126.36 -	dy1 = ((dy1 * SUMMA_MAXY) / mouse_maxy) + SUMMA_BORDER;
  126.37 -	ser_queue(s->cookie, 0x80 | (s->mouse_buttons & 7));
  126.38 -	ser_queue(s->cookie, dx1 & 0x7f);
  126.39 -	ser_queue(s->cookie, dx1 >> 7);
  126.40 -	ser_queue(s->cookie, dy1 & 0x7f);
  126.41 -	ser_queue(s->cookie, dy1 >> 7);
  126.42 +	if (SummaState.report_mode == MODE_STREAM) {
  126.43 +	    dx1 = s->mouse_x;
  126.44 +	    dy1 = s->mouse_y;
  126.45 +	    if (SummaState.origin == ORIGIN_LOWER_LEFT)
  126.46 +		dy1 = mouse_maxy - dy1;
  126.47 +	    dx1 = ((dx1 * SUMMA_MAXX) / mouse_maxx) + SUMMA_BORDER;
  126.48 +	    dy1 = ((dy1 * SUMMA_MAXY) / mouse_maxy) + SUMMA_BORDER;
  126.49 +	    ser_queue(s->serial, 0x80 | (s->mouse_buttons & 7));
  126.50 +	    ser_queue(s->serial, dx1 & 0x7f);
  126.51 +	    ser_queue(s->serial, dx1 >> 7);
  126.52 +	    ser_queue(s->serial, dy1 & 0x7f);
  126.53 +	    ser_queue(s->serial, dy1 >> 7);
  126.54 +	}
  126.55  	s->mouse_dx = 0; 
  126.56  	s->mouse_dy = 0;
  126.57  	s->mouse_dz = 0;
  126.58 @@ -509,43 +526,101 @@ static void pc_kbd_mouse_event(void *opa
  126.59      }
  126.60  }
  126.61  
  126.62 -static void summa(KBDState *s, int val)
  126.63 +static void summa(KBDState *s, uint8_t val)
  126.64  {
  126.65 -    static int summa = 0;
  126.66 +    static int zflg = 0;
  126.67  
  126.68 -    if (s->mouse_type == TABLET) {
  126.69 +    if (zflg) {
  126.70 +	zflg = 0;
  126.71  	switch (val) {
  126.72  
  126.73 -	case '?':	/* read firmware ID */
  126.74 -	    ser_queue(s->cookie, '0');
  126.75 +	case 'b':	/* binary report mode */
  126.76  	    break;
  126.77  
  126.78 -	case 'a':	/* read config */
  126.79 -	    /*
  126.80 -	     *  Config looks like a movement packet but, because of scaling
  126.81 -	     *    issues we can't use `kbd_send_packet' to do this.
  126.82 -	     */
  126.83 -	    ser_queue(s->cookie, 0);
  126.84 -	    ser_queue(s->cookie, (SUMMA_MAXX & 0x7f));
  126.85 -	    ser_queue(s->cookie, (SUMMA_MAXX >> 7));
  126.86 -	    ser_queue(s->cookie, (SUMMA_MAXY & 0x7f));
  126.87 -	    ser_queue(s->cookie, (SUMMA_MAXY >> 7));
  126.88 -	    break;
  126.89 -
  126.90 -	default:	/* ignore all others */
  126.91 +	case 't':	/* stylus type - we do 4 button cursor */
  126.92 +	    ser_queue(s->serial, 'C');
  126.93 +	    ser_queue(s->serial, 'S');
  126.94 +	    ser_queue(s->serial, 'R');
  126.95 +	    ser_queue(s->serial, '4');
  126.96 +	    ser_queue(s->serial, '\r');
  126.97  	    break;
  126.98  
  126.99  	}
 126.100  	return;
 126.101      }
 126.102 -    if (val == 'B') {
 126.103 -	summa++;
 126.104 -	return;
 126.105 -    } else if (summa && val == 'z') {
 126.106 +    zflg = 0;
 126.107 +
 126.108 +    switch (val) {
 126.109 +
 126.110 +    case 'B':	/* point mode */
 126.111 +	/* This is supposed to be `set to point mode' but the Linux driver
 126.112 +	 *   is broken and incorrectly sends a reset command (somebody
 126.113 +	 *   needs to learn that the address 0 does not necessarily contain
 126.114 +	 *   a zero).  This is the first valid command that Linux sends
 126.115 +	 *   out so we'll treat it as a reset
 126.116 +	 */
 126.117 +    case '\0':	/* reset */
 126.118  	s->mouse_type = TABLET;
 126.119 -	return;
 126.120 +	s->mouse_status |= MOUSE_STATUS_ENABLED;
 126.121 +	SummaState.origin = ORIGIN_LOWER_LEFT;
 126.122 +	SummaState.report_mode = (val == 'B') ? MODE_POINT : MODE_STREAM_SWITCH;
 126.123 +	break;
 126.124 +
 126.125 +    case 'z':	/* start of 2 byte command */
 126.126 +	zflg++;
 126.127 +	break;
 126.128 +
 126.129 +    case 'x':	/* code check */
 126.130 +	/*
 126.131 +	 *  Return checksum
 126.132 +	 */
 126.133 +	ser_queue(s->serial, '.');
 126.134 +	ser_queue(s->serial, '#');
 126.135 +	ser_queue(s->serial, '1');
 126.136 +	ser_queue(s->serial, '2');
 126.137 +	ser_queue(s->serial, '3');
 126.138 +	ser_queue(s->serial, '4');
 126.139 +	break;
 126.140 +
 126.141 +    case '?':	/* read firmware ID */
 126.142 +	ser_queue(s->serial, '0');
 126.143 +	break;
 126.144 +
 126.145 +    case 'a':	/* read config */
 126.146 +	/*
 126.147 +	 *  Config looks like a movement packet but, because of scaling
 126.148 +	 *    issues we can't use `kbd_send_packet' to do this.
 126.149 +	 */
 126.150 +	ser_queue(s->serial, 0x94);
 126.151 +	ser_queue(s->serial, (SUMMA_MAXX & 0x7f));
 126.152 +	ser_queue(s->serial, (SUMMA_MAXX >> 7));
 126.153 +	ser_queue(s->serial, (SUMMA_MAXY & 0x7f));
 126.154 +	ser_queue(s->serial, (SUMMA_MAXY >> 7));
 126.155 +	break;
 126.156 +
 126.157 +    case 'b':	/* origin at upper left */
 126.158 +	SummaState.origin = ORIGIN_UPPER_LEFT;
 126.159 +	break;
 126.160 +
 126.161 +    case 'c':	/* origin at lower left */
 126.162 +	SummaState.origin = ORIGIN_LOWER_LEFT;
 126.163 +	break;
 126.164 +
 126.165 +    case '@':	/* stream mode */
 126.166 +	SummaState.report_mode = MODE_STREAM;
 126.167 +	break;
 126.168 +
 126.169 +    case 'D':	/* remote request mode */
 126.170 +	SummaState.report_mode = MODE_REMOTE;
 126.171 +	break;
 126.172 +
 126.173 +    case 'P':	/* trigger, e.g. send report now */
 126.174 +    case 'R':	/* report rate = max/2 */
 126.175 +    default:	/* ignore all others */
 126.176 +	break;
 126.177 +
 126.178      }
 126.179 -    summa = 0;
 126.180 +
 126.181      return;
 126.182  }
 126.183  
 126.184 @@ -560,13 +635,13 @@ int summa_write(CharDriverState *chr, co
 126.185      return len;
 126.186  }
 126.187  
 126.188 -void summa_init(void *cookie, CharDriverState *chr)
 126.189 +void summa_init(SerialState *serial, CharDriverState *chr)
 126.190  {
 126.191  
 126.192      if (summa_ok == 0)
 126.193  	return;
 126.194      kbd_state.chr = chr;
 126.195 -    kbd_state.cookie = (void *)cookie;
 126.196 +    kbd_state.serial = serial;
 126.197      chr->chr_write = summa_write;
 126.198      chr->opaque = (void *)&kbd_state;
 126.199      return;
   127.1 --- a/tools/ioemu/hw/serial.c	Mon May 22 08:53:26 2006 -0600
   127.2 +++ b/tools/ioemu/hw/serial.c	Mon May 22 14:13:38 2006 -0600
   127.3 @@ -310,7 +310,6 @@ SerialState *serial_init(int base, int i
   127.4      register_ioport_write(base, 8, 1, serial_ioport_write, s);
   127.5      register_ioport_read(base, 8, 1, serial_ioport_read, s);
   127.6      s->chr = chr;
   127.7 -    summa_init(s, chr);
   127.8      qemu_chr_add_read_handler(chr, serial_can_receive1, serial_receive1, s);
   127.9      qemu_chr_add_event_handler(chr, serial_event);
  127.10      return s;
   128.1 --- a/tools/ioemu/hw/vga.c	Mon May 22 08:53:26 2006 -0600
   128.2 +++ b/tools/ioemu/hw/vga.c	Mon May 22 14:13:38 2006 -0600
   128.3 @@ -1946,11 +1946,11 @@ void vga_bios_init(VGAState *s)
   128.4  
   128.5  }
   128.6  
   128.7 +/* when used on xen environment, the vga_ram_base is not used */
   128.8  void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base, 
   128.9                       unsigned long vga_ram_offset, int vga_ram_size)
  128.10  {
  128.11      int i, j, v, b;
  128.12 -    extern void* shared_vram;
  128.13  
  128.14      for(i = 0;i < 256; i++) {
  128.15          v = 0;
  128.16 @@ -1979,11 +1979,7 @@ void vga_common_init(VGAState *s, Displa
  128.17  
  128.18      /* qemu's vga mem is not detached from phys_ram_base and can cause DM abort
  128.19       * when guest write vga mem, so allocate a new one */
  128.20 -#if defined(__i386__) || defined(__x86_64__)
  128.21 -    s->vram_ptr = shared_vram;
  128.22 -#else
  128.23      s->vram_ptr = qemu_malloc(vga_ram_size);
  128.24 -#endif
  128.25      check_sse2();
  128.26      s->vram_shadow = qemu_malloc(vga_ram_size+TARGET_PAGE_SIZE+1);
  128.27      if (s->vram_shadow == NULL)
  128.28 @@ -2090,12 +2086,14 @@ int vga_initialize(PCIBus *bus, DisplayS
  128.29      return 0;
  128.30  }
  128.31  
  128.32 -int vga_update_vram(VGAState *s, void *vga_ram_base, int vga_ram_size)
  128.33 +void *vga_update_vram(VGAState *s, void *vga_ram_base, int vga_ram_size)
  128.34  {
  128.35 +    uint8_t *old_pointer;
  128.36 +
  128.37      if (s->vram_size != vga_ram_size)
  128.38      {
  128.39          fprintf(stderr, "No support to change vga_ram_size\n");
  128.40 -        return -1;
  128.41 +        return NULL;
  128.42      }
  128.43  
  128.44      if ( !vga_ram_base )
  128.45 @@ -2104,15 +2102,16 @@ int vga_update_vram(VGAState *s, void *v
  128.46          if (!vga_ram_base)
  128.47          {
  128.48              fprintf(stderr, "reallocate error\n");
  128.49 -            return -1;
  128.50 +            return NULL;
  128.51          }
  128.52      }
  128.53  
  128.54      /* XXX lock needed? */
  128.55      memcpy(vga_ram_base, s->vram_ptr, vga_ram_size);
  128.56 +    old_pointer = s->vram_ptr;
  128.57      s->vram_ptr = vga_ram_base;
  128.58  
  128.59 -    return 0;
  128.60 +    return old_pointer;
  128.61  }
  128.62  
  128.63  /********************************************************/
   129.1 --- a/tools/ioemu/hw/vga_int.h	Mon May 22 08:53:26 2006 -0600
   129.2 +++ b/tools/ioemu/hw/vga_int.h	Mon May 22 14:13:38 2006 -0600
   129.3 @@ -165,6 +165,6 @@ void vga_draw_cursor_line_32(uint8_t *d1
   129.4                               unsigned int color0, unsigned int color1,
   129.5                               unsigned int color_xor);
   129.6  
   129.7 -int vga_update_vram(VGAState *s, void *vga_ram_base, int vga_ram_size);
   129.8 +void *vga_update_vram(VGAState *s, void *vga_ram_base, int vga_ram_size);
   129.9  extern const uint8_t sr_mask[8];
  129.10  extern const uint8_t gr_mask[16];
   130.1 --- a/tools/ioemu/target-i386-dm/Makefile	Mon May 22 08:53:26 2006 -0600
   130.2 +++ b/tools/ioemu/target-i386-dm/Makefile	Mon May 22 14:13:38 2006 -0600
   130.3 @@ -278,7 +278,7 @@ endif
   130.4  # Hardware support
   130.5  VL_OBJS+= ide.o ne2000.o pckbd.o vga.o dma.o
   130.6  VL_OBJS+= fdc.o mc146818rtc.o serial.o i8259_stub.o pc.o port-e9.o
   130.7 -VL_OBJS+= cirrus_vga.o pcnet.o
   130.8 +VL_OBJS+= cirrus_vga.o pcnet.o acpi.o
   130.9  VL_OBJS+= $(SOUND_HW) $(AUDIODRV) mixeng.o
  130.10  
  130.11  ifeq ($(TARGET_ARCH), ppc)
   131.1 --- a/tools/ioemu/vl.c	Mon May 22 08:53:26 2006 -0600
   131.2 +++ b/tools/ioemu/vl.c	Mon May 22 14:13:38 2006 -0600
   131.3 @@ -75,8 +75,6 @@
   131.4  #endif
   131.5  #endif /* CONFIG_SDL */
   131.6  
   131.7 -#include "xenctrl.h"
   131.8 -#include "xs.h"
   131.9  #include "exec-all.h"
  131.10  
  131.11  //#define DO_TB_FLUSH
  131.12 @@ -149,12 +147,7 @@ int repeat_key = 1;
  131.13  TextConsole *vga_console;
  131.14  CharDriverState *serial_hds[MAX_SERIAL_PORTS];
  131.15  int xc_handle;
  131.16 -unsigned long *vgapage_array;
  131.17 -unsigned long *freepage_array;
  131.18 -unsigned long free_pages;
  131.19 -void *vtop_table;
  131.20 -unsigned long toptab;
  131.21 -unsigned long vgaram_pages;
  131.22 +time_t timeoffset = 0;
  131.23  
  131.24  /***********************************************************/
  131.25  /* x86 ISA bus support */
  131.26 @@ -2255,9 +2248,10 @@ void help(void)
  131.27             "-s              wait gdb connection to port %d\n"
  131.28             "-p port         ioreq port for xen\n"
  131.29             "-d domain       domain that we're serving\n"
  131.30 -           "-domain-namn    domain name that we're serving\n"
  131.31 +           "-domain-name    domain name that we're serving\n"
  131.32             "-hdachs c,h,s   force hard disk 0 geometry (usually qemu can guess it)\n"
  131.33             "-L path         set the directory for the BIOS and VGA BIOS\n"
  131.34 +	   "-timeoffset     time offset (in seconds) from local time (Xen)\n"
  131.35  #ifdef USE_CODE_COPY
  131.36             "-no-code-copy   disable code copy acceleration\n"
  131.37  #endif
  131.38 @@ -2355,6 +2349,7 @@ enum {
  131.39      QEMU_OPTION_monitor,
  131.40      QEMU_OPTION_domainname,
  131.41      QEMU_OPTION_serial,
  131.42 +    QEMU_OPTION_timeoffset,
  131.43      QEMU_OPTION_loadvm,
  131.44      QEMU_OPTION_full_screen,
  131.45      QEMU_OPTION_vgaacc,
  131.46 @@ -2428,6 +2423,7 @@ const QEMUOption qemu_options[] = {
  131.47      { "std-vga", 0, QEMU_OPTION_std_vga },
  131.48      { "monitor", 1, QEMU_OPTION_monitor },
  131.49      { "domain-name", 1, QEMU_OPTION_domainname },
  131.50 +    { "timeoffset", HAS_ARG, QEMU_OPTION_timeoffset },
  131.51      { "serial", 1, QEMU_OPTION_serial },
  131.52      { "loadvm", HAS_ARG, QEMU_OPTION_loadvm },
  131.53      { "full-screen", 0, QEMU_OPTION_full_screen },
  131.54 @@ -2456,35 +2452,8 @@ static uint8_t *signal_stack;
  131.55  
  131.56  #include <xg_private.h>
  131.57  
  131.58 -#if defined(__i386__) || defined (__x86_64__)
  131.59 -#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
  131.60 -#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
  131.61 -
  131.62 -#ifdef __i386__
  131.63 -#define _LEVEL_3_ 0
  131.64 -#else
  131.65 -#define _LEVEL_3_ 1
  131.66 -#endif
  131.67 -
  131.68 -#if _LEVEL_3_
  131.69 -#define L3_PROT (_PAGE_PRESENT)
  131.70 -#define L1_PAGETABLE_ENTRIES    512
  131.71 -#else
  131.72 -#define L1_PAGETABLE_ENTRIES    1024
  131.73 -#endif
  131.74 -
  131.75 -inline int
  131.76 -get_vl2_table(unsigned long count, unsigned long start)
  131.77 -{
  131.78 -#if _LEVEL_3_
  131.79 -    return ((start + (count << PAGE_SHIFT)) >> L3_PAGETABLE_SHIFT) & 0x3;
  131.80 -#else
  131.81 -    return 0;
  131.82 -#endif
  131.83 -}
  131.84 -
  131.85  /* FIXME Flush the shadow page */
  131.86 -static int unset_mm_mapping(int xc_handle,
  131.87 +int unset_mm_mapping(int xc_handle,
  131.88                       uint32_t domid,
  131.89                       unsigned long nr_pages,
  131.90                       unsigned int address_bits,
  131.91 @@ -2517,13 +2486,12 @@ static int unset_mm_mapping(int xc_handl
  131.92      return err;
  131.93  }
  131.94  
  131.95 -static int set_mm_mapping(int xc_handle,
  131.96 +int set_mm_mapping(int xc_handle,
  131.97                      uint32_t domid,
  131.98                      unsigned long nr_pages,
  131.99                      unsigned int address_bits,
 131.100                      unsigned long *extent_start)
 131.101  {
 131.102 -    int i;
 131.103      xc_dominfo_t info;
 131.104      int err = 0;
 131.105  
 131.106 @@ -2564,91 +2532,6 @@ static int set_mm_mapping(int xc_handle,
 131.107      return 0;
 131.108  }
 131.109  
 131.110 -
 131.111 -void * set_vram_mapping(unsigned long begin, unsigned long end)
 131.112 -{
 131.113 -    unsigned long * extent_start = NULL;
 131.114 -    unsigned long nr_extents;
 131.115 -    void *vram_pointer = NULL;
 131.116 -    int i;
 131.117 -
 131.118 -    /* align begin and end address */
 131.119 -    begin = begin & PAGE_MASK;
 131.120 -    end = begin + VGA_RAM_SIZE;
 131.121 -    end = (end + PAGE_SIZE -1 )& PAGE_MASK;
 131.122 -    nr_extents = (end - begin) >> PAGE_SHIFT;
 131.123 -
 131.124 -    extent_start = malloc(sizeof(unsigned long) * nr_extents );
 131.125 -    if (extent_start == NULL)
 131.126 -    {
 131.127 -        fprintf(stderr, "Failed malloc on set_vram_mapping\n");
 131.128 -        return NULL;
 131.129 -    }
 131.130 -
 131.131 -    memset(extent_start, 0, sizeof(unsigned long) * nr_extents);
 131.132 -
 131.133 -    for (i = 0; i < nr_extents; i++)
 131.134 -    {
 131.135 -        extent_start[i] = (begin + i * PAGE_SIZE) >> PAGE_SHIFT;
 131.136 -    }
 131.137 -
 131.138 -    set_mm_mapping(xc_handle, domid, nr_extents, 0, extent_start);
 131.139 -
 131.140 -    if ( (vram_pointer =  xc_map_foreign_batch(xc_handle, domid,
 131.141 -                                               PROT_READ|PROT_WRITE,
 131.142 -                                               extent_start,
 131.143 -                                               nr_extents)) == NULL)
 131.144 -    {
 131.145 -        fprintf(logfile,
 131.146 -          "xc_map_foreign_batch vgaram returned error %d\n", errno);
 131.147 -        return NULL;
 131.148 -    }
 131.149 -
 131.150 -    memset(vram_pointer, 0, nr_extents * PAGE_SIZE);
 131.151 -
 131.152 -    free(extent_start);
 131.153 -
 131.154 -    return vram_pointer;
 131.155 -}
 131.156 -
 131.157 -int unset_vram_mapping(unsigned long begin, unsigned long end)
 131.158 -{
 131.159 -    unsigned long * extent_start = NULL;
 131.160 -    unsigned long nr_extents;
 131.161 -    int i;
 131.162 -
 131.163 -    /* align begin and end address */
 131.164 -
 131.165 -    end = begin + VGA_RAM_SIZE;
 131.166 -    begin = begin & PAGE_MASK;
 131.167 -    end = (end + PAGE_SIZE -1 ) & PAGE_MASK;
 131.168 -    nr_extents = (end - begin) >> PAGE_SHIFT;
 131.169 -
 131.170 -    extent_start = malloc(sizeof(unsigned long) * nr_extents );
 131.171 -
 131.172 -    if (extent_start == NULL)
 131.173 -    {
 131.174 -        fprintf(stderr, "Failed malloc on set_mm_mapping\n");
 131.175 -        return -1;
 131.176 -    }
 131.177 -
 131.178 -    memset(extent_start, 0, sizeof(unsigned long) * nr_extents);
 131.179 -
 131.180 -    for (i = 0; i < nr_extents; i++)
 131.181 -        extent_start[i] = (begin + (i * PAGE_SIZE)) >> PAGE_SHIFT;
 131.182 -
 131.183 -    unset_mm_mapping(xc_handle, domid, nr_extents, 0, extent_start);
 131.184 -
 131.185 -    free(extent_start);
 131.186 -
 131.187 -    return 0;
 131.188 -}
 131.189 -
 131.190 -#elif defined(__ia64__)
 131.191 -void set_vram_mapping(unsigned long addr, unsigned long end) {}
 131.192 -void unset_vram_mapping(unsigned long addr, unsigned long end) {}
 131.193 -#endif
 131.194 -
 131.195  int main(int argc, char **argv)
 131.196  {
 131.197  #ifdef CONFIG_GDBSTUB
 131.198 @@ -2673,10 +2556,8 @@ int main(int argc, char **argv)
 131.199      int serial_device_index;
 131.200      char qemu_dm_logfilename[64];
 131.201      const char *loadvm = NULL;
 131.202 -    unsigned long nr_pages, extra_pages, ram_pages, *page_array;
 131.203 -    xc_dominfo_t info;
 131.204 +    unsigned long nr_pages, *page_array;
 131.205      extern void *shared_page;
 131.206 -    extern void *shared_vram;
 131.207  
 131.208  #if !defined(CONFIG_SOFTMMU)
 131.209      /* we never want that malloc() uses mmap() */
 131.210 @@ -2707,7 +2588,8 @@ int main(int argc, char **argv)
 131.211      pstrcpy(monitor_device, sizeof(monitor_device), "vc");
 131.212  
 131.213      pstrcpy(serial_devices[0], sizeof(serial_devices[0]), "vc");
 131.214 -    for(i = 1; i < MAX_SERIAL_PORTS; i++)
 131.215 +    pstrcpy(serial_devices[1], sizeof(serial_devices[1]), "null");
 131.216 +    for(i = 2; i < MAX_SERIAL_PORTS; i++)
 131.217          serial_devices[i][0] = '\0';
 131.218      serial_device_index = 0;
 131.219  
 131.220 @@ -3058,7 +2940,10 @@ int main(int argc, char **argv)
 131.221              case QEMU_OPTION_domainname:
 131.222                  strncat(domain_name, optarg, sizeof(domain_name) - 20);
 131.223                  break;
 131.224 -
 131.225 +	    case QEMU_OPTION_timeoffset:
 131.226 +                timeoffset = strtol(optarg, NULL, 0);
 131.227 +	    	break;
 131.228 + 
 131.229              }
 131.230          }
 131.231      }
 131.232 @@ -3133,29 +3018,10 @@ int main(int argc, char **argv)
 131.233      /* init the memory */
 131.234      phys_ram_size = ram_size + vga_ram_size + bios_size;
 131.235  
 131.236 -    ram_pages = ram_size/PAGE_SIZE;
 131.237 -#if defined(__i386__) || defined(__x86_64__)
 131.238 -    vgaram_pages =  (vga_ram_size -1) / PAGE_SIZE + 1;
 131.239 -    free_pages = vgaram_pages / L1_PAGETABLE_ENTRIES;
 131.240 -    extra_pages = vgaram_pages + free_pages;
 131.241 -#else
 131.242 -    /* Test vga acceleration later */
 131.243 -    extra_pages = 0;
 131.244 -#endif
 131.245 +    nr_pages = ram_size/PAGE_SIZE;
 131.246  
 131.247      xc_handle = xc_interface_open();
 131.248  
 131.249 -    xc_domain_getinfo(xc_handle, domid, 1, &info);
 131.250 -
 131.251 -    nr_pages = info.nr_pages + extra_pages;
 131.252 -
 131.253 -    if ( xc_domain_setmaxmem(xc_handle, domid,
 131.254 -                             (nr_pages) * PAGE_SIZE/1024 ) != 0)
 131.255 -    {
 131.256 -        fprintf(logfile, "set maxmem returned error %d\n", errno);
 131.257 -        exit(-1);
 131.258 -    }
 131.259 -
 131.260      if ( (page_array = (unsigned long *)
 131.261                          malloc(nr_pages * sizeof(unsigned long))) == NULL)
 131.262      {
 131.263 @@ -3163,24 +3029,16 @@ int main(int argc, char **argv)
 131.264          exit(-1);
 131.265      }
 131.266  
 131.267 -    if (xc_domain_memory_increase_reservation(xc_handle, domid,
 131.268 -                                              extra_pages , 0, 0, NULL) != 0)
 131.269 -    {
 131.270 -        fprintf(logfile, "increase reservation returned error %d\n", errno);
 131.271 -        exit(-1);
 131.272 -    }
 131.273 -
 131.274  #if defined(__i386__) || defined(__x86_64__)
 131.275      if ( xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages )
 131.276      {
 131.277          fprintf(logfile, "xc_get_pfn_list returned error %d\n", errno);
 131.278          exit(-1);
 131.279      }
 131.280 -
 131.281      if ( (phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
 131.282                            PROT_READ|PROT_WRITE,
 131.283                            page_array,
 131.284 -                          ram_pages - 1)) == 0 )
 131.285 +                          nr_pages - 1)) == 0 )
 131.286      {
 131.287          fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
 131.288          exit(-1);
 131.289 @@ -3188,31 +3046,11 @@ int main(int argc, char **argv)
 131.290  
 131.291      shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
 131.292                                         PROT_READ|PROT_WRITE,
 131.293 -                                       page_array[ram_pages - 1]);
 131.294 -
 131.295 -    vgapage_array = &page_array[nr_pages - vgaram_pages];
 131.296 -
 131.297 -    if ( (shared_vram =  xc_map_foreign_batch(xc_handle, domid,
 131.298 -                                              PROT_READ|PROT_WRITE,
 131.299 -                                              vgapage_array,
 131.300 -                                              vgaram_pages)) == 0)
 131.301 -    {
 131.302 -        fprintf(logfile,
 131.303 -                "xc_map_foreign_batch vgaram returned error %d\n", errno);
 131.304 -        exit(-1);
 131.305 -    }
 131.306 -
 131.307 -    memset(shared_vram, 0, vgaram_pages * PAGE_SIZE);
 131.308 -    toptab = page_array[ram_pages] << PAGE_SHIFT;
 131.309 -
 131.310 -    vtop_table = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
 131.311 -                                      PROT_READ|PROT_WRITE,
 131.312 -                                      page_array[ram_pages]);
 131.313 -
 131.314 -    freepage_array = &page_array[nr_pages - extra_pages];
 131.315 +                                       page_array[nr_pages - 1]);
 131.316 +
 131.317  #elif defined(__ia64__)
 131.318 -    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array, 0, ram_pages)
 131.319 -         != ram_pages )
 131.320 +    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array, 0, nr_pages)
 131.321 +         != nr_pages)
 131.322      {
 131.323          fprintf(logfile, "xc_ia64_get_pfn_list returned error %d\n", errno);
 131.324          exit(-1);
 131.325 @@ -3221,7 +3059,7 @@ int main(int argc, char **argv)
 131.326      if ( (phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
 131.327                            PROT_READ|PROT_WRITE,
 131.328                            page_array,
 131.329 -                          ram_pages)) == 0 )
 131.330 +                          nr_pages)) == 0 )
 131.331      {
 131.332          fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
 131.333          exit(-1);
 131.334 @@ -3229,7 +3067,7 @@ int main(int argc, char **argv)
 131.335  
 131.336      if ( xc_ia64_get_pfn_list(xc_handle, domid,
 131.337                                page_array,
 131.338 -                              ram_pages + (GFW_SIZE >> PAGE_SHIFT), 1) != 1 )
 131.339 +                              nr_pages + (GFW_SIZE >> PAGE_SHIFT), 1) != 1 )
 131.340      {
 131.341          fprintf(logfile, "xc_ia64_get_pfn_list returned error %d\n", errno);
 131.342          exit(-1);
 131.343 @@ -3396,7 +3234,7 @@ int main(int argc, char **argv)
 131.344  #if defined(TARGET_I386)
 131.345      pc_init(ram_size, vga_ram_size, boot_device,
 131.346              ds, fd_filename, snapshot,
 131.347 -            kernel_filename, kernel_cmdline, initrd_filename);
 131.348 +            kernel_filename, kernel_cmdline, initrd_filename, timeoffset);
 131.349  #elif defined(TARGET_PPC)
 131.350      ppc_init(ram_size, vga_ram_size, boot_device,
 131.351              ds, fd_filename, snapshot,
   132.1 --- a/tools/ioemu/vl.h	Mon May 22 08:53:26 2006 -0600
   132.2 +++ b/tools/ioemu/vl.h	Mon May 22 14:13:38 2006 -0600
   132.3 @@ -38,6 +38,8 @@
   132.4  #include <fcntl.h>
   132.5  #include <sys/stat.h>
   132.6  #include "audio/audio.h"
   132.7 +#include "xenctrl.h"
   132.8 +#include "xs.h"
   132.9  
  132.10  #ifndef O_LARGEFILE
  132.11  #define O_LARGEFILE 0
  132.12 @@ -113,6 +115,19 @@ void qemu_system_shutdown_request(void);
  132.13  
  132.14  void main_loop_wait(int timeout);
  132.15  
  132.16 +int unset_mm_mapping(int xc_handle,
  132.17 +                     uint32_t domid,
  132.18 +                     unsigned long nr_pages,
  132.19 +                     unsigned int address_bits,
  132.20 +                     unsigned long *extent_start);
  132.21 +int set_mm_mapping(int xc_handle,
  132.22 +                    uint32_t domid,
  132.23 +                    unsigned long nr_pages,
  132.24 +                    unsigned int address_bits,
  132.25 +                    unsigned long *extent_start);
  132.26 +
  132.27 +extern int xc_handle;
  132.28 +extern int domid;
  132.29  extern int audio_enabled;
  132.30  extern int sb16_enabled;
  132.31  extern int adlib_enabled;
  132.32 @@ -223,6 +238,7 @@ void console_select(unsigned int index);
  132.33  /* serial ports */
  132.34  
  132.35  #define MAX_SERIAL_PORTS 4
  132.36 +#define SUMMA_PORT	1
  132.37  
  132.38  extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
  132.39  
  132.40 @@ -618,12 +634,6 @@ void kbd_init(void);
  132.41  extern const char* keyboard_layout;
  132.42  extern int repeat_key;
  132.43  
  132.44 -/* Mice */
  132.45 -
  132.46 -void summa_init(void *cookie, CharDriverState *chr);
  132.47 -
  132.48 -extern int summa_ok;
  132.49 -
  132.50  /* mc146818rtc.c */
  132.51  
  132.52  typedef struct RTCState RTCState;
  132.53 @@ -638,6 +648,12 @@ typedef struct SerialState SerialState;
  132.54  SerialState *serial_init(int base, int irq, CharDriverState *chr);
  132.55  void ser_queue(SerialState *s, unsigned char c);
  132.56  
  132.57 +/* Mice */
  132.58 +
  132.59 +void summa_init(SerialState *serial, CharDriverState *chr);
  132.60 +
  132.61 +extern int summa_ok;
  132.62 +
  132.63  /* i8259.c */
  132.64  
  132.65  void pic_set_irq(int irq, int level);
  132.66 @@ -663,7 +679,7 @@ int pit_get_out(PITState *pit, int chann
  132.67  void pc_init(uint64_t ram_size, int vga_ram_size, int boot_device,
  132.68               DisplayState *ds, const char **fd_filename, int snapshot,
  132.69               const char *kernel_filename, const char *kernel_cmdline,
  132.70 -             const char *initrd_filename);
  132.71 +             const char *initrd_filename, time_t timeoffset);
  132.72  
  132.73  /* ppc.c */
  132.74  void ppc_init (int ram_size, int vga_ram_size, int boot_device,
   133.1 --- a/tools/libxc/xc_acm.c	Mon May 22 08:53:26 2006 -0600
   133.2 +++ b/tools/libxc/xc_acm.c	Mon May 22 14:13:38 2006 -0600
   133.3 @@ -1,14 +1,11 @@
   133.4  /******************************************************************************
   133.5 + * xc_acm.c
   133.6   *
   133.7 - * Copyright (C) 2005 IBM Corporation
   133.8 + * Copyright (C) 2005, 2006 IBM Corporation, R Sailer
   133.9   *
  133.10   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  133.11   * Use is subject to license terms.
  133.12   *
  133.13 - * Authors:
  133.14 - * Reiner Sailer <sailer@watson.ibm.com>
  133.15 - * Stefan Berger <stefanb@watson.ibm.com>
  133.16 - *
  133.17   * This program is free software; you can redistribute it and/or
  133.18   * modify it under the terms of the GNU General Public License as
  133.19   * published by the Free Software Foundation, version 2 of the
  133.20 @@ -17,29 +14,23 @@
  133.21  
  133.22  #include "xc_private.h"
  133.23  
  133.24 -int xc_acm_op(int xc_handle, struct acm_op *op)
  133.25 +
  133.26 +int xc_acm_op(int xc_handle, int cmd, void *arg, size_t arg_size)
  133.27  {
  133.28      int ret = -1;
  133.29      DECLARE_HYPERCALL;
  133.30  
  133.31 -    op->interface_version = ACM_INTERFACE_VERSION;
  133.32 +    hypercall.op = __HYPERVISOR_acm_op;
  133.33 +    hypercall.arg[0] = cmd;
  133.34 +    hypercall.arg[1] = (unsigned long) arg;
  133.35  
  133.36 -    hypercall.op = __HYPERVISOR_acm_op;
  133.37 -    hypercall.arg[0] = (unsigned long) op;
  133.38 -
  133.39 -    if (mlock(op, sizeof(*op)) != 0) {
  133.40 -        PERROR("Could not lock memory for Xen policy hypercall");
  133.41 -        goto out1;
  133.42 +    if (mlock(arg, arg_size) != 0) {
  133.43 +        PERROR("xc_acm_op: arg mlock failed");
  133.44 +        goto out;
  133.45      }
  133.46 -
  133.47      ret = do_xen_hypercall(xc_handle, &hypercall);
  133.48 -    ret = ioctl(xc_handle, IOCTL_PRIVCMD_HYPERCALL, &hypercall);
  133.49 -    if (ret < 0) {
  133.50 -        goto out2;
  133.51 -    }
  133.52 - out2:
  133.53 -    safe_munlock(op, sizeof(*op));
  133.54 - out1:
  133.55 +    safe_munlock(arg, arg_size);
  133.56 + out:
  133.57      return ret;
  133.58  }
  133.59  
   134.1 --- a/tools/libxc/xc_linux_build.c	Mon May 22 08:53:26 2006 -0600
   134.2 +++ b/tools/libxc/xc_linux_build.c	Mon May 22 14:13:38 2006 -0600
   134.3 @@ -329,6 +329,13 @@ static int setup_pg_tables_pae(int xc_ha
   134.4          vl1e++;
   134.5      }
   134.6  
   134.7 +    /* Xen requires a mid-level pgdir mapping 0xC0000000 region. */
   134.8 +    if ( (vl3tab[3] & _PAGE_PRESENT) == 0 )
   134.9 +    {
  134.10 +        alloc_pt(l2tab, vl2tab, pl2tab);
  134.11 +        vl3tab[3] = l2tab | L3_PROT;
  134.12 +    }
  134.13 +
  134.14      munmap(vl1tab, PAGE_SIZE);
  134.15      munmap(vl2tab, PAGE_SIZE);
  134.16      munmap(vl3tab, PAGE_SIZE);
  134.17 @@ -727,25 +734,28 @@ static int setup_guest(int xc_handle,
  134.18          v_end            = (vstack_end + (1UL<<22)-1) & ~((1UL<<22)-1);
  134.19          if ( (v_end - vstack_end) < (512UL << 10) )
  134.20              v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */
  134.21 +#define NR(_l,_h,_s) \
  134.22 +    (((((_h) + ((1UL<<(_s))-1)) & ~((1UL<<(_s))-1)) - \
  134.23 +    ((_l) & ~((1UL<<(_s))-1))) >> (_s))
  134.24  #if defined(__i386__)
  134.25          if ( dsi.pae_kernel )
  134.26          {
  134.27 -            /* FIXME: assumes one L2 pgtable @ 0xc0000000 */
  134.28 -            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT_PAE)-1)) >>
  134.29 -                   L2_PAGETABLE_SHIFT_PAE) + 2) <= nr_pt_pages )
  134.30 +            if ( (1 + /* # L3 */
  134.31 +                  NR(dsi.v_start, v_end, L3_PAGETABLE_SHIFT_PAE) + /* # L2 */
  134.32 +                  NR(dsi.v_start, v_end, L2_PAGETABLE_SHIFT_PAE) + /* # L1 */
  134.33 +                  /* Include a fourth mid-level page directory for Xen. */
  134.34 +                  (v_end <= (3 << L3_PAGETABLE_SHIFT_PAE)))
  134.35 +                  <= nr_pt_pages )
  134.36                  break;
  134.37          }
  134.38          else
  134.39          {
  134.40 -            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >>
  134.41 -                   L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
  134.42 +            if ( (1 + /* # L2 */
  134.43 +                  NR(dsi.v_start, v_end, L2_PAGETABLE_SHIFT)) /* # L1 */
  134.44 +                 <= nr_pt_pages )
  134.45                  break;
  134.46          }
  134.47 -#endif
  134.48 -#if defined(__x86_64__)
  134.49 -#define NR(_l,_h,_s) \
  134.50 -    (((((_h) + ((1UL<<(_s))-1)) & ~((1UL<<(_s))-1)) - \
  134.51 -    ((_l) & ~((1UL<<(_s))-1))) >> (_s))
  134.52 +#elif defined(__x86_64__)
  134.53          if ( (1 + /* # L4 */
  134.54                NR(dsi.v_start, v_end, L4_PAGETABLE_SHIFT) + /* # L3 */
  134.55                NR(dsi.v_start, v_end, L3_PAGETABLE_SHIFT) + /* # L2 */
  134.56 @@ -794,9 +804,11 @@ static int setup_guest(int xc_handle,
  134.57          goto error_out;
  134.58      }
  134.59  
  134.60 -    (load_funcs.loadimage)(image, image_size,
  134.61 +    rc = (load_funcs.loadimage)(image, image_size,
  134.62                             xc_handle, dom, page_array,
  134.63                             &dsi);
  134.64 +    if ( rc != 0 )
  134.65 +        goto error_out;
  134.66  
  134.67      if ( load_initrd(xc_handle, dom, initrd,
  134.68                       vinitrd_start - dsi.v_start, page_array) )
   135.1 --- a/tools/libxc/xc_load_elf.c	Mon May 22 08:53:26 2006 -0600
   135.2 +++ b/tools/libxc/xc_load_elf.c	Mon May 22 14:13:38 2006 -0600
   135.3 @@ -58,10 +58,10 @@ static int parseelfimage(const char *ima
   135.4      Elf_Ehdr *ehdr = (Elf_Ehdr *)image;
   135.5      Elf_Phdr *phdr;
   135.6      Elf_Shdr *shdr;
   135.7 -    unsigned long kernstart = ~0UL, kernend=0UL;
   135.8 +    unsigned long kernstart = ~0UL, kernend=0UL, vaddr, virt_base, elf_pa_off;
   135.9      const char *shstrtab;
  135.10      char *guestinfo=NULL, *p;
  135.11 -    int h;
  135.12 +    int h, virt_base_defined, elf_pa_off_defined;
  135.13  
  135.14      if ( !IS_ELF(*ehdr) )
  135.15      {
  135.16 @@ -148,40 +148,65 @@ static int parseelfimage(const char *ima
  135.17  
  135.18      dsi->xen_guest_string = guestinfo;
  135.19  
  135.20 +    /* Initial guess for virt_base is 0 if it is not explicitly defined. */
  135.21 +    p = strstr(guestinfo, "VIRT_BASE=");
  135.22 +    virt_base_defined = (p != NULL);
  135.23 +    virt_base = virt_base_defined ? strtoul(p+10, &p, 0) : 0;
  135.24 +
  135.25 +    /* Initial guess for elf_pa_off is virt_base if not explicitly defined. */
  135.26 +    p = strstr(guestinfo, "ELF_PADDR_OFFSET=");
  135.27 +    elf_pa_off_defined = (p != NULL);
  135.28 +    elf_pa_off = elf_pa_off_defined ? strtoul(p+17, &p, 0) : virt_base;
  135.29 +
  135.30 +    if ( elf_pa_off_defined && !virt_base_defined )
  135.31 +        goto bad_image;
  135.32 +
  135.33      for ( h = 0; h < ehdr->e_phnum; h++ )
  135.34      {
  135.35          phdr = (Elf_Phdr *)(image + ehdr->e_phoff + (h*ehdr->e_phentsize));
  135.36          if ( !is_loadable_phdr(phdr) )
  135.37              continue;
  135.38 -        if ( phdr->p_paddr < kernstart )
  135.39 -            kernstart = phdr->p_paddr;
  135.40 -        if ( (phdr->p_paddr + phdr->p_memsz) > kernend )
  135.41 -            kernend = phdr->p_paddr + phdr->p_memsz;
  135.42 +        vaddr = phdr->p_paddr - elf_pa_off + virt_base;
  135.43 +        if ( (vaddr + phdr->p_memsz) < vaddr )
  135.44 +            goto bad_image;
  135.45 +        if ( vaddr < kernstart )
  135.46 +            kernstart = vaddr;
  135.47 +        if ( (vaddr + phdr->p_memsz) > kernend )
  135.48 +            kernend = vaddr + phdr->p_memsz;
  135.49      }
  135.50  
  135.51 +    /*
  135.52 +     * Legacy compatibility and images with no __xen_guest section: assume
  135.53 +     * header addresses are virtual addresses, and that guest memory should be
  135.54 +     * mapped starting at kernel load address.
  135.55 +     */
  135.56 +    dsi->v_start          = virt_base_defined  ? virt_base  : kernstart;
  135.57 +    dsi->elf_paddr_offset = elf_pa_off_defined ? elf_pa_off : dsi->v_start;
  135.58 +
  135.59 +    dsi->v_kernentry = ehdr->e_entry;
  135.60 +    if ( (p = strstr(guestinfo, "VIRT_ENTRY=")) != NULL )
  135.61 +        dsi->v_kernentry = strtoul(p+11, &p, 0);
  135.62 +
  135.63      if ( (kernstart > kernend) ||
  135.64 -         (ehdr->e_entry < kernstart) ||
  135.65 -         (ehdr->e_entry > kernend) )
  135.66 -    {
  135.67 -        ERROR("Malformed ELF image.");
  135.68 -        return -EINVAL;
  135.69 -    }
  135.70 -
  135.71 -    dsi->v_start = kernstart;
  135.72 -    if ( (p = strstr(guestinfo, "VIRT_BASE=")) != NULL )
  135.73 -        dsi->v_start = strtoul(p+10, &p, 0);
  135.74 +         (dsi->v_kernentry < kernstart) ||
  135.75 +         (dsi->v_kernentry > kernend) ||
  135.76 +         (dsi->v_start > kernstart) )
  135.77 +        goto bad_image;
  135.78  
  135.79      if ( (p = strstr(guestinfo, "BSD_SYMTAB")) != NULL )
  135.80          dsi->load_symtab = 1;
  135.81  
  135.82      dsi->v_kernstart = kernstart;
  135.83      dsi->v_kernend   = kernend;
  135.84 -    dsi->v_kernentry = ehdr->e_entry;
  135.85      dsi->v_end       = dsi->v_kernend;
  135.86  
  135.87      loadelfsymtab(image, 0, 0, NULL, dsi);
  135.88  
  135.89      return 0;
  135.90 +
  135.91 + bad_image:
  135.92 +    ERROR("Malformed ELF image.");
  135.93 +    return -EINVAL;
  135.94  }
  135.95  
  135.96  static int
  135.97 @@ -204,9 +229,11 @@ loadelfimage(
  135.98  
  135.99          for ( done = 0; done < phdr->p_filesz; done += chunksz )
 135.100          {
 135.101 -            pa = (phdr->p_paddr + done) - dsi->v_start;
 135.102 +            pa = (phdr->p_paddr + done) - dsi->elf_paddr_offset;
 135.103              va = xc_map_foreign_range(
 135.104                  xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
 135.105 +            if ( va == NULL )
 135.106 +                return -1;
 135.107              chunksz = phdr->p_filesz - done;
 135.108              if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
 135.109                  chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
 135.110 @@ -217,9 +244,11 @@ loadelfimage(
 135.111  
 135.112          for ( ; done < phdr->p_memsz; done += chunksz )
 135.113          {
 135.114 -            pa = (phdr->p_paddr + done) - dsi->v_start;
 135.115 +            pa = (phdr->p_paddr + done) - dsi->elf_paddr_offset;
 135.116              va = xc_map_foreign_range(
 135.117                  xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
 135.118 +            if ( va == NULL )
 135.119 +                return -1;
 135.120              chunksz = phdr->p_memsz - done;
 135.121              if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
 135.122                  chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
   136.1 --- a/tools/libxc/xc_ptrace.c	Mon May 22 08:53:26 2006 -0600
   136.2 +++ b/tools/libxc/xc_ptrace.c	Mon May 22 14:13:38 2006 -0600
   136.3 @@ -157,6 +157,27 @@ online_vcpus_changed(cpumap_t cpumap)
   136.4  static long                     nr_pages = 0;
   136.5  static unsigned long           *page_array = NULL;
   136.6  
   136.7 +
   136.8 +/*
   136.9 + * Translates physical addresses to machine addresses for HVM
  136.10 + * guests. For paravirtual domains the function will just return the
  136.11 + * given address.
  136.12 + *
  136.13 + * This function should be used when reading page directories/page
  136.14 + * tables.
  136.15 + *
  136.16 + */
  136.17 +static unsigned long
  136.18 +to_ma(int cpu,
  136.19 +      unsigned long in_addr)
  136.20 +{
  136.21 +    unsigned long maddr = in_addr;
  136.22 +
  136.23 +    if ( (ctxt[cpu].flags & VGCF_HVM_GUEST) && paging_enabled(&ctxt[cpu]) )
  136.24 +        maddr = page_array[maddr >> PAGE_SHIFT] << PAGE_SHIFT;
  136.25 +    return maddr;
  136.26 +}
  136.27 +
  136.28  static void *
  136.29  map_domain_va_32(
  136.30      int xc_handle,
  136.31 @@ -164,66 +185,34 @@ map_domain_va_32(
  136.32      void *guest_va,
  136.33      int perm)
  136.34  {
  136.35 -    unsigned long pde, page;
  136.36 -    unsigned long va = (unsigned long)guest_va;
  136.37 -
  136.38 -    static unsigned long  cr3_phys[MAX_VIRT_CPUS];
  136.39 -    static uint32_t *cr3_virt[MAX_VIRT_CPUS];
  136.40 -    static unsigned long  pde_phys[MAX_VIRT_CPUS];
  136.41 -    static uint32_t *pde_virt[MAX_VIRT_CPUS];
  136.42 -    static unsigned long  page_phys[MAX_VIRT_CPUS];
  136.43 -    static uint32_t *page_virt[MAX_VIRT_CPUS];
  136.44 -    static int            prev_perm[MAX_VIRT_CPUS];
  136.45 +    unsigned long l1p, p, va = (unsigned long)guest_va;
  136.46 +    uint32_t *l2, *l1;
  136.47 +    static void *v[MAX_VIRT_CPUS];
  136.48  
  136.49 -   if (ctxt[cpu].ctrlreg[3] == 0)
  136.50 -       return NULL;
  136.51 -   if ( ctxt[cpu].ctrlreg[3] != cr3_phys[cpu] )
  136.52 -    {
  136.53 -        cr3_phys[cpu] = ctxt[cpu].ctrlreg[3];
  136.54 -        if ( cr3_virt[cpu] )
  136.55 -            munmap(cr3_virt[cpu], PAGE_SIZE);
  136.56 -        cr3_virt[cpu] = xc_map_foreign_range(
  136.57 -            xc_handle, current_domid, PAGE_SIZE, PROT_READ,
  136.58 -            cr3_phys[cpu] >> PAGE_SHIFT);
  136.59 -        if ( cr3_virt[cpu] == NULL )
  136.60 -            return NULL;
  136.61 -    }
  136.62 -    if ( (pde = cr3_virt[cpu][vtopdi(va)]) == 0 )
  136.63 +    l2 = xc_map_foreign_range(
  136.64 +         xc_handle, current_domid, PAGE_SIZE, PROT_READ, ctxt[cpu].ctrlreg[3] >> PAGE_SHIFT);
  136.65 +    if ( l2 == NULL )
  136.66 +        return NULL;
  136.67 +
  136.68 +    l1p = to_ma(cpu, l2[l2_table_offset(va)]);
  136.69 +    munmap(l2, PAGE_SIZE);
  136.70 +    if ( !(l1p & _PAGE_PRESENT) )
  136.71          return NULL;
  136.72 -    if ( (ctxt[cpu].flags & VGCF_HVM_GUEST) && paging_enabled(&ctxt[cpu]) )
  136.73 -        pde = page_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
  136.74 -    if ( pde != pde_phys[cpu] )
  136.75 -    {
  136.76 -        pde_phys[cpu] = pde;
  136.77 -        if ( pde_virt[cpu] )
  136.78 -            munmap(pde_virt[cpu], PAGE_SIZE);
  136.79 -        pde_virt[cpu] = xc_map_foreign_range(
  136.80 -            xc_handle, current_domid, PAGE_SIZE, PROT_READ,
  136.81 -            pde_phys[cpu] >> PAGE_SHIFT);
  136.82 -        if ( pde_virt[cpu] == NULL )
  136.83 -            return NULL;
  136.84 -    }
  136.85 -    if ( (page = pde_virt[cpu][vtopti(va)]) == 0 )
  136.86 +    l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l1p >> PAGE_SHIFT);
  136.87 +    if ( l1 == NULL )
  136.88 +        return NULL;
  136.89 +
  136.90 +    p = to_ma(cpu, l1[l1_table_offset(va)]);
  136.91 +    munmap(l1, PAGE_SIZE);
  136.92 +    if ( !(p & _PAGE_PRESENT) )
  136.93          return NULL;
  136.94 -    if (ctxt[cpu].flags & VGCF_HVM_GUEST)
  136.95 -        page = page_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
  136.96 -    if ( (page != page_phys[cpu]) || (perm != prev_perm[cpu]) )
  136.97 -    {
  136.98 -        page_phys[cpu] = page;
  136.99 -        if ( page_virt[cpu] )
 136.100 -            munmap(page_virt[cpu], PAGE_SIZE);
 136.101 -        page_virt[cpu] = xc_map_foreign_range(
 136.102 -            xc_handle, current_domid, PAGE_SIZE, perm,
 136.103 -            page_phys[cpu] >> PAGE_SHIFT);
 136.104 -        if ( page_virt[cpu] == NULL )
 136.105 -        {
 136.106 -            page_phys[cpu] = 0;
 136.107 -            return NULL;
 136.108 -        }
 136.109 -        prev_perm[cpu] = perm;
 136.110 -    }
 136.111 +    if ( v[cpu] != NULL )
 136.112 +        munmap(v[cpu], PAGE_SIZE);
 136.113 +    v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
 136.114 +    if ( v[cpu] == NULL )
 136.115 +        return NULL;
 136.116  
 136.117 -    return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
 136.118 +    return (void *)((unsigned long)v[cpu] | (va & (PAGE_SIZE - 1)));
 136.119  }
 136.120  
 136.121  
 136.122 @@ -236,37 +225,40 @@ map_domain_va_pae(
 136.123  {
 136.124      unsigned long l2p, l1p, p, va = (unsigned long)guest_va;
 136.125      uint64_t *l3, *l2, *l1;
 136.126 -    static void *v;
 136.127 +    static void *v[MAX_VIRT_CPUS];
 136.128  
 136.129      l3 = xc_map_foreign_range(
 136.130          xc_handle, current_domid, PAGE_SIZE, PROT_READ, ctxt[cpu].ctrlreg[3] >> PAGE_SHIFT);
 136.131      if ( l3 == NULL )
 136.132          return NULL;
 136.133  
 136.134 -    l2p = l3[l3_table_offset_pae(va)] >> PAGE_SHIFT;
 136.135 -    l2p = page_array[l2p];
 136.136 -    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p);
 136.137 +    l2p = to_ma(cpu, l3[l3_table_offset_pae(va)]);
 136.138      munmap(l3, PAGE_SIZE);
 136.139 +    if ( !(l2p & _PAGE_PRESENT) )
 136.140 +        return NULL;
 136.141 +    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p >> PAGE_SHIFT);
 136.142      if ( l2 == NULL )
 136.143          return NULL;
 136.144  
 136.145 -    l1p = l2[l2_table_offset_pae(va)] >> PAGE_SHIFT;
 136.146 -    l1p = page_array[l1p];
 136.147 -    l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p);
 136.148 +    l1p = to_ma(cpu, l2[l2_table_offset_pae(va)]);
 136.149      munmap(l2, PAGE_SIZE);
 136.150 +    if ( !(l1p & _PAGE_PRESENT) )
 136.151 +        return NULL;
 136.152 +    l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p >> PAGE_SHIFT);
 136.153      if ( l1 == NULL )
 136.154          return NULL;
 136.155  
 136.156 -    p = l1[l1_table_offset_pae(va)] >> PAGE_SHIFT;
 136.157 -    p = page_array[p];
 136.158 -    if ( v != NULL )
 136.159 -        munmap(v, PAGE_SIZE);
 136.160 -    v = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p);
 136.161 +    p = to_ma(cpu, l1[l1_table_offset_pae(va)]);
 136.162      munmap(l1, PAGE_SIZE);
 136.163 -    if ( v == NULL )
 136.164 +    if ( !(p & _PAGE_PRESENT) )
 136.165 +        return NULL;
 136.166 +    if ( v[cpu] != NULL )
 136.167 +        munmap(v[cpu], PAGE_SIZE);
 136.168 +    v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
 136.169 +    if ( v[cpu] == NULL )
 136.170          return NULL;
 136.171  
 136.172 -    return (void *)((unsigned long)v | (va & (PAGE_SIZE - 1)));
 136.173 +    return (void *)((unsigned long)v[cpu] | (va & (PAGE_SIZE - 1)));
 136.174  }
 136.175  
 136.176  #ifdef __x86_64__
 136.177 @@ -279,7 +271,7 @@ map_domain_va_64(
 136.178  {
 136.179      unsigned long l3p, l2p, l1p, l1e, p, va = (unsigned long)guest_va;
 136.180      uint64_t *l4, *l3, *l2, *l1;
 136.181 -    static void *v;
 136.182 +    static void *v[MAX_VIRT_CPUS];
 136.183  
 136.184      if ((ctxt[cpu].ctrlreg[4] & 0x20) == 0 ) /* legacy ia32 mode */
 136.185          return map_domain_va_32(xc_handle, cpu, guest_va, perm);
 136.186 @@ -289,44 +281,50 @@ map_domain_va_64(
 136.187      if ( l4 == NULL )
 136.188          return NULL;
 136.189  
 136.190 -    l3p = l4[l4_table_offset(va)] >> PAGE_SHIFT;
 136.191 -    l3p = page_array[l3p];
 136.192 -    l3 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l3p);
 136.193 +    l3p = to_ma(cpu, l4[l4_table_offset(va)]);
 136.194      munmap(l4, PAGE_SIZE);
 136.195 +    if ( !(l3p & _PAGE_PRESENT) )
 136.196 +        return NULL;
 136.197 +    l3 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l3p >> PAGE_SHIFT);
 136.198      if ( l3 == NULL )
 136.199          return NULL;
 136.200  
 136.201 -    l2p = l3[l3_table_offset(va)] >> PAGE_SHIFT;
 136.202 -    l2p = page_array[l2p];
 136.203 -    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p);
 136.204 +    l2p = to_ma(cpu, l3[l3_table_offset(va)]);
 136.205      munmap(l3, PAGE_SIZE);
 136.206 +    if ( !(l2p & _PAGE_PRESENT) )
 136.207 +        return NULL;
 136.208 +    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p >> PAGE_SHIFT);
 136.209      if ( l2 == NULL )
 136.210          return NULL;
 136.211  
 136.212      l1 = NULL;
 136.213 -    l1e = l2[l2_table_offset(va)];
 136.214 +    l1e = to_ma(cpu, l2[l2_table_offset(va)]);
 136.215 +    if ( !(l1e & _PAGE_PRESENT) )
 136.216 +    {
 136.217 +        munmap(l2, PAGE_SIZE);
 136.218 +        return NULL;
 136.219 +    }
 136.220      l1p = l1e >> PAGE_SHIFT;
 136.221      if (l1e & 0x80)  { /* 2M pages */
 136.222 -        p = (l1p + l1_table_offset(va));
 136.223 +        p = to_ma(cpu, (l1p + l1_table_offset(va)) << PAGE_SHIFT);
 136.224      } else { /* 4K pages */
 136.225 -        l1p = page_array[l1p];
 136.226 -        l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p);
 136.227 +        l1p = to_ma(cpu, l1p);
 136.228 +        l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p >> PAGE_SHIFT);
 136.229          munmap(l2, PAGE_SIZE);
 136.230          if ( l1 == NULL )
 136.231              return NULL;
 136.232  
 136.233 -        p = l1[l1_table_offset(va)] >> PAGE_SHIFT;
 136.234 +        p = to_ma(cpu, l1[l1_table_offset(va)]);
 136.235      }
 136.236 -    p = page_array[p];
 136.237 -    if ( v != NULL )
 136.238 -        munmap(v, PAGE_SIZE);
 136.239 -    v = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p);
 136.240 +    if ( v[cpu] != NULL )
 136.241 +        munmap(v[cpu], PAGE_SIZE);
 136.242 +    v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
 136.243      if (l1)
 136.244          munmap(l1, PAGE_SIZE);
 136.245 -    if ( v == NULL )
 136.246 +    if ( v[cpu] == NULL )
 136.247          return NULL;
 136.248  
 136.249 -    return (void *)((unsigned long)v | (va & (PAGE_SIZE - 1)));
 136.250 +    return (void *)((unsigned long)v[cpu] | (va & (PAGE_SIZE - 1)));
 136.251  }
 136.252  #endif
 136.253  
 136.254 @@ -381,7 +379,7 @@ map_domain_va(
 136.255          if ( v != NULL )
 136.256              munmap(v, PAGE_SIZE);
 136.257  
 136.258 -        page = page_array[va >> PAGE_SHIFT] << PAGE_SHIFT;
 136.259 +        page = to_ma(cpu, page_array[va >> PAGE_SHIFT]);
 136.260  
 136.261          v = xc_map_foreign_range( xc_handle, current_domid, PAGE_SIZE,
 136.262                  perm, page >> PAGE_SHIFT);
 136.263 @@ -510,6 +508,11 @@ xc_ptrace(
 136.264          break;
 136.265  
 136.266      case PTRACE_GETFPREGS:
 136.267 +        if (!current_isfile && fetch_regs(xc_handle, cpu, NULL)) 
 136.268 +                goto out_error;
 136.269 +        memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof (elf_fpregset_t));
 136.270 +        break;
 136.271 +
 136.272      case PTRACE_GETFPXREGS:
 136.273          if (!current_isfile && fetch_regs(xc_handle, cpu, NULL))
 136.274                  goto out_error;
 136.275 @@ -518,7 +521,7 @@ xc_ptrace(
 136.276  
 136.277      case PTRACE_SETREGS:
 136.278          if (current_isfile)
 136.279 -                goto out_unspported; /* XXX not yet supported */
 136.280 +                goto out_unsupported; /* XXX not yet supported */
 136.281          SET_XC_REGS(((struct gdb_regs *)data), ctxt[cpu].user_regs);
 136.282          if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu,
 136.283                                  &ctxt[cpu])))
 136.284 @@ -526,8 +529,8 @@ xc_ptrace(
 136.285          break;
 136.286  
 136.287      case PTRACE_SINGLESTEP:
 136.288 -        if (!current_isfile)
 136.289 -              goto out_unspported; /* XXX not yet supported */
 136.290 +        if (current_isfile)
 136.291 +              goto out_unsupported; /* XXX not yet supported */
 136.292          /*  XXX we can still have problems if the user switches threads
 136.293           *  during single-stepping - but that just seems retarded
 136.294           */
 136.295 @@ -540,7 +543,7 @@ xc_ptrace(
 136.296      case PTRACE_CONT:
 136.297      case PTRACE_DETACH:
 136.298          if (current_isfile)
 136.299 -            goto out_unspported; /* XXX not yet supported */
 136.300 +            goto out_unsupported; /* XXX not yet supported */
 136.301          if ( request != PTRACE_SINGLESTEP )
 136.302          {
 136.303              FOREACH_CPU(cpumap, index) {
 136.304 @@ -603,7 +606,7 @@ xc_ptrace(
 136.305      case PTRACE_POKEUSER:
 136.306      case PTRACE_SYSCALL:
 136.307      case PTRACE_KILL:
 136.308 -        goto out_unspported; /* XXX not yet supported */
 136.309 +        goto out_unsupported; /* XXX not yet supported */
 136.310  
 136.311      case PTRACE_TRACEME:
 136.312          printf("PTRACE_TRACEME is an invalid request under Xen\n");
 136.313 @@ -618,7 +621,7 @@ xc_ptrace(
 136.314      errno = EINVAL;
 136.315      return retval;
 136.316  
 136.317 - out_unspported:
 136.318 + out_unsupported:
 136.319  #ifdef DEBUG
 136.320      printf("unsupported xc_ptrace request %s\n", ptrace_names[request]);
 136.321  #endif
   137.1 --- a/tools/libxc/xc_tbuf.c	Mon May 22 08:53:26 2006 -0600
   137.2 +++ b/tools/libxc/xc_tbuf.c	Mon May 22 14:13:38 2006 -0600
   137.3 @@ -16,7 +16,7 @@
   137.4  
   137.5  #include "xc_private.h"
   137.6  
   137.7 -int xc_tbuf_enable(int xc_handle, int enable)
   137.8 +static int tbuf_enable(int xc_handle, int enable)
   137.9  {
  137.10    DECLARE_DOM0_OP;
  137.11  
  137.12 @@ -30,7 +30,7 @@ int xc_tbuf_enable(int xc_handle, int en
  137.13    return xc_dom0_op(xc_handle, &op);
  137.14  }
  137.15  
  137.16 -int xc_tbuf_set_size(int xc_handle, uint32_t size)
  137.17 +int xc_tbuf_set_size(int xc_handle, unsigned long size)
  137.18  {
  137.19    DECLARE_DOM0_OP;
  137.20  
  137.21 @@ -42,7 +42,7 @@ int xc_tbuf_set_size(int xc_handle, uint
  137.22    return xc_dom0_op(xc_handle, &op);
  137.23  }
  137.24  
  137.25 -int xc_tbuf_get_size(int xc_handle, uint32_t *size)
  137.26 +int xc_tbuf_get_size(int xc_handle, unsigned long *size)
  137.27  {
  137.28    int rc;
  137.29    DECLARE_DOM0_OP;
  137.30 @@ -57,10 +57,17 @@ int xc_tbuf_get_size(int xc_handle, uint
  137.31    return rc;
  137.32  }
  137.33  
  137.34 -int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn)
  137.35 +int xc_tbuf_enable(int xc_handle, size_t cnt, unsigned long *mfn,
  137.36 +    unsigned long *size)
  137.37  {
  137.38 +    DECLARE_DOM0_OP;
  137.39      int rc;
  137.40 -    DECLARE_DOM0_OP;
  137.41 +
  137.42 +    if ( xc_tbuf_set_size(xc_handle, cnt) != 0 )
  137.43 +        return -1;
  137.44 +
  137.45 +    if ( tbuf_enable(xc_handle, 1) != 0 )
  137.46 +        return -1;
  137.47  
  137.48      op.cmd = DOM0_TBUFCONTROL;
  137.49      op.interface_version = DOM0_INTERFACE_VERSION;
  137.50 @@ -68,8 +75,17 @@ int xc_tbuf_get_mfn(int xc_handle, unsig
  137.51  
  137.52      rc = xc_dom0_op(xc_handle, &op);
  137.53      if ( rc == 0 )
  137.54 -      *mfn = op.u.tbufcontrol.buffer_mfn;
  137.55 -    return rc;
  137.56 +    {
  137.57 +        *size = op.u.tbufcontrol.size;
  137.58 +        *mfn = op.u.tbufcontrol.buffer_mfn;
  137.59 +    }
  137.60 +
  137.61 +    return 0;
  137.62 +}
  137.63 +
  137.64 +int xc_tbuf_disable(int xc_handle)
  137.65 +{
  137.66 +    return tbuf_enable(xc_handle, 0);
  137.67  }
  137.68  
  137.69  int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask)
  137.70 @@ -95,3 +111,4 @@ int xc_tbuf_set_evt_mask(int xc_handle, 
  137.71  
  137.72      return do_dom0_op(xc_handle, &op);
  137.73  }
  137.74 +
   138.1 --- a/tools/libxc/xenctrl.h	Mon May 22 08:53:26 2006 -0600
   138.2 +++ b/tools/libxc/xenctrl.h	Mon May 22 14:13:38 2006 -0600
   138.3 @@ -9,6 +9,7 @@
   138.4  #ifndef XENCTRL_H
   138.5  #define XENCTRL_H
   138.6  
   138.7 +#include <stddef.h>
   138.8  #include <stdint.h>
   138.9  #include <sys/ptrace.h>
  138.10  #include <xen/xen.h>
  138.11 @@ -529,15 +530,23 @@ long xc_get_tot_pages(int xc_handle, uin
  138.12   */
  138.13  
  138.14  /**
  138.15 - * This function enables or disables tracing. Trace buffer memory must
  138.16 - * be already allocated by setting the size to a non-zero value, otherwise
  138.17 - * tracing cannot be enabled.
  138.18 + * xc_tbuf_enable - enable tracing buffers
  138.19   *
  138.20   * @parm xc_handle a handle to an open hypervisor interface
  138.21 - * @parm enable the desired action, 1 for enable, 0 for disable
  138.22 - * @return 0 on success, -1 on failure.
  138.23 + * @parm cnt size of tracing buffers to create (in pages)
  138.24 + * @parm mfn location to store mfn of the trace buffers to
  138.25 + * @parm size location to store the size (in bytes) of a trace buffer to
  138.26 + *
  138.27 + * Gets the machine address of the trace pointer area and the size of the
  138.28 + * per CPU buffers.
  138.29   */
  138.30 -int xc_tbuf_enable(int xc_handle, int enable);
  138.31 +int xc_tbuf_enable(int xc_handle, size_t cnt, unsigned long *mfn,
  138.32 +    unsigned long *size);
  138.33 +
  138.34 +/*
  138.35 + * Disable tracing buffers.
  138.36 + */
  138.37 +int xc_tbuf_disable(int xc_handle);
  138.38  
  138.39  /**
  138.40   * This function sets the size of the trace buffers. Setting the size
  138.41 @@ -549,7 +558,7 @@ int xc_tbuf_enable(int xc_handle, int en
  138.42   * @parm size the size in pages per cpu for the trace buffers
  138.43   * @return 0 on success, -1 on failure.
  138.44   */
  138.45 -int xc_tbuf_set_size(int xc_handle, uint32_t size);
  138.46 +int xc_tbuf_set_size(int xc_handle, unsigned long size);
  138.47  
  138.48  /**
  138.49   * This function retrieves the current size of the trace buffers.
  138.50 @@ -559,16 +568,7 @@ int xc_tbuf_set_size(int xc_handle, uint
  138.51   * @parm size will contain the size in bytes for the trace buffers
  138.52   * @return 0 on success, -1 on failure.
  138.53   */
  138.54 -int xc_tbuf_get_size(int xc_handle, uint32_t *size);
  138.55 -
  138.56 -/**
  138.57 - * This function retrieves the machine frame of the trace buffer.
  138.58 -
  138.59 - * @parm xc_handle a handle to an open hypervisor interface
  138.60 - * @parm mfn will contain the machine frame of the buffer.
  138.61 - * @return 0 on success, -1 on failure.
  138.62 - */
  138.63 -int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn);
  138.64 +int xc_tbuf_get_size(int xc_handle, unsigned long *size);
  138.65  
  138.66  int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask);
  138.67  
  138.68 @@ -594,6 +594,6 @@ int xc_add_mmu_update(int xc_handle, xc_
  138.69                     unsigned long long ptr, unsigned long long val);
  138.70  int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
  138.71  
  138.72 -int xc_acm_op(int xc_handle, struct acm_op *op);
  138.73 +int xc_acm_op(int xc_handle, int cmd, void *arg, size_t arg_size);
  138.74  
  138.75  #endif
   139.1 --- a/tools/libxc/xg_private.h	Mon May 22 08:53:26 2006 -0600
   139.2 +++ b/tools/libxc/xg_private.h	Mon May 22 14:13:38 2006 -0600
   139.3 @@ -136,8 +136,11 @@ struct domain_setup_info
   139.4      unsigned long v_kernend;
   139.5      unsigned long v_kernentry;
   139.6  
   139.7 +    unsigned long elf_paddr_offset;
   139.8 +
   139.9 +    unsigned int  pae_kernel;
  139.10 +
  139.11      unsigned int  load_symtab;
  139.12 -    unsigned int  pae_kernel;
  139.13      unsigned long symtab_addr;
  139.14      unsigned long symtab_len;
  139.15  
   140.1 --- a/tools/python/xen/lowlevel/acm/acm.c	Mon May 22 08:53:26 2006 -0600
   140.2 +++ b/tools/python/xen/lowlevel/acm/acm.c	Mon May 22 14:13:38 2006 -0600
   140.3 @@ -38,7 +38,7 @@ fprintf(stderr, "ERROR: " _m " (%d = %s)
   140.4  /* generic shared function */
   140.5  void * __getssid(int domid, uint32_t *buflen)
   140.6  {
   140.7 -    struct acm_op op;
   140.8 +    struct acm_getssid getssid;
   140.9      int xc_handle;
  140.10      #define SSID_BUFFER_SIZE    4096
  140.11      void *buf = NULL;
  140.12 @@ -51,14 +51,13 @@ void * __getssid(int domid, uint32_t *bu
  140.13          goto out2;
  140.14      }
  140.15      memset(buf, 0, SSID_BUFFER_SIZE);
  140.16 -    op.cmd = ACM_GETSSID;
  140.17 -    op.interface_version = ACM_INTERFACE_VERSION;
  140.18 -    op.u.getssid.ssidbuf = buf;
  140.19 -    op.u.getssid.ssidbuf_size = SSID_BUFFER_SIZE;
  140.20 -    op.u.getssid.get_ssid_by = DOMAINID;
  140.21 -    op.u.getssid.id.domainid = domid;
  140.22 +    getssid.interface_version = ACM_INTERFACE_VERSION;
  140.23 +    getssid.ssidbuf = buf;
  140.24 +    getssid.ssidbuf_size = SSID_BUFFER_SIZE;
  140.25 +    getssid.get_ssid_by = DOMAINID;
  140.26 +    getssid.id.domainid = domid;
  140.27  
  140.28 -    if (xc_acm_op(xc_handle, &op) < 0) {
  140.29 +    if (xc_acm_op(xc_handle, ACMOP_getssid, &getssid, sizeof(getssid)) < 0) {
  140.30          if (errno == EACCES)
  140.31              PERROR("ACM operation failed.");
  140.32          free(buf);
  140.33 @@ -147,7 +146,7 @@ static PyObject *getssid(PyObject * self
  140.34  static PyObject *getdecision(PyObject * self, PyObject * args)
  140.35  {
  140.36      char *arg1_name, *arg1, *arg2_name, *arg2, *decision = NULL;
  140.37 -    struct acm_op op;
  140.38 +    struct acm_getdecision getdecision;
  140.39      int xc_handle;
  140.40  
  140.41      if (!PyArg_ParseTuple(args, "ssss", &arg1_name, &arg1, &arg2_name, &arg2)) {
  140.42 @@ -163,34 +162,33 @@ static PyObject *getdecision(PyObject * 
  140.43      (strcmp(arg2_name, "domid") && strcmp(arg2_name, "ssidref")))
  140.44          return NULL;
  140.45  
  140.46 -    op.cmd = ACM_GETDECISION;
  140.47 -    op.interface_version = ACM_INTERFACE_VERSION;
  140.48 -    op.u.getdecision.hook = SHARING;
  140.49 +    getdecision.interface_version = ACM_INTERFACE_VERSION;
  140.50 +    getdecision.hook = SHARING;
  140.51      if (!strcmp(arg1_name, "domid")) {
  140.52 -        op.u.getdecision.get_decision_by1 = DOMAINID;
  140.53 -        op.u.getdecision.id1.domainid = atoi(arg1);
  140.54 +        getdecision.get_decision_by1 = DOMAINID;
  140.55 +        getdecision.id1.domainid = atoi(arg1);
  140.56      } else {
  140.57 -        op.u.getdecision.get_decision_by1 = SSIDREF;
  140.58 -        op.u.getdecision.id1.ssidref = atol(arg1);
  140.59 +        getdecision.get_decision_by1 = SSIDREF;
  140.60 +        getdecision.id1.ssidref = atol(arg1);
  140.61      }
  140.62      if (!strcmp(arg2_name, "domid")) {
  140.63 -        op.u.getdecision.get_decision_by2 = DOMAINID;
  140.64 -        op.u.getdecision.id2.domainid = atoi(arg2);
  140.65 +        getdecision.get_decision_by2 = DOMAINID;
  140.66 +        getdecision.id2.domainid = atoi(arg2);
  140.67      } else {
  140.68 -        op.u.getdecision.get_decision_by2 = SSIDREF;
  140.69 -        op.u.getdecision.id2.ssidref = atol(arg2);
  140.70 +        getdecision.get_decision_by2 = SSIDREF;
  140.71 +        getdecision.id2.ssidref = atol(arg2);
  140.72      }
  140.73  
  140.74 -    if (xc_acm_op(xc_handle, &op) < 0) {
  140.75 +    if (xc_acm_op(xc_handle, ACMOP_getdecision, &getdecision, sizeof(getdecision)) < 0) {
  140.76          if (errno == EACCES)
  140.77              PERROR("ACM operation failed.");
  140.78      }
  140.79  
  140.80      xc_interface_close(xc_handle);
  140.81  
  140.82 -    if (op.u.getdecision.acm_decision == ACM_ACCESS_PERMITTED)
  140.83 +    if (getdecision.acm_decision == ACM_ACCESS_PERMITTED)
  140.84          decision = "PERMITTED";
  140.85 -    else if (op.u.getdecision.acm_decision == ACM_ACCESS_DENIED)
  140.86 +    else if (getdecision.acm_decision == ACM_ACCESS_DENIED)
  140.87          decision = "DENIED";
  140.88  
  140.89      return Py_BuildValue("s", decision);
   141.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Mon May 22 08:53:26 2006 -0600
   141.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Mon May 22 14:13:38 2006 -0600
   141.3 @@ -1172,7 +1172,7 @@ static int
   141.4  PyXc_init(XcObject *self, PyObject *args, PyObject *kwds)
   141.5  {
   141.6      if ((self->xc_handle = xc_interface_open()) == -1) {
   141.7 -        PyErr_SetFromErrno(PyExc_RuntimeError);
   141.8 +        PyErr_SetFromErrno(xc_error);
   141.9          return -1;
  141.10      }
  141.11  
  141.12 @@ -1245,7 +1245,7 @@ PyMODINIT_FUNC initxc(void)
  141.13      if (m == NULL)
  141.14        return;
  141.15  
  141.16 -    xc_error = PyErr_NewException(PKG ".error", NULL, NULL);
  141.17 +    xc_error = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL);
  141.18      zero = PyInt_FromLong(0);
  141.19  
  141.20      /* KAF: This ensures that we get debug output in a timely manner. */
  141.21 @@ -1254,6 +1254,9 @@ PyMODINIT_FUNC initxc(void)
  141.22  
  141.23      Py_INCREF(&PyXcType);
  141.24      PyModule_AddObject(m, CLS, (PyObject *)&PyXcType);
  141.25 +
  141.26 +    Py_INCREF(xc_error);
  141.27 +    PyModule_AddObject(m, "Error", xc_error);
  141.28  }
  141.29  
  141.30  
   142.1 --- a/tools/python/xen/xend/XendCheckpoint.py	Mon May 22 08:53:26 2006 -0600
   142.2 +++ b/tools/python/xen/xend/XendCheckpoint.py	Mon May 22 14:13:38 2006 -0600
   142.3 @@ -54,7 +54,7 @@ def read_exact(fd, size, errmsg):
   142.4  
   142.5  
   142.6  
   142.7 -def save(fd, dominfo, live, dst):
   142.8 +def save(fd, dominfo, network, live, dst):
   142.9      write_exact(fd, SIGNATURE, "could not write guest state file: signature")
  142.10  
  142.11      config = sxp.to_string(dominfo.sxpr())
  142.12 @@ -66,7 +66,7 @@ def save(fd, dominfo, live, dst):
  142.13      dominfo.setName('migrating-' + domain_name)
  142.14  
  142.15      try:
  142.16 -        dominfo.migrateDevices(live, dst, DEV_MIGRATE_STEP1, domain_name)
  142.17 +        dominfo.migrateDevices(network, dst, DEV_MIGRATE_STEP1, domain_name)
  142.18  
  142.19          write_exact(fd, pack("!i", len(config)),
  142.20                      "could not write guest state file: config len")
  142.21 @@ -88,10 +88,10 @@ def save(fd, dominfo, live, dst):
  142.22                  log.debug("Suspending %d ...", dominfo.getDomid())
  142.23                  dominfo.shutdown('suspend')
  142.24                  dominfo.waitForShutdown()
  142.25 -                dominfo.migrateDevices(live, dst, DEV_MIGRATE_STEP2,
  142.26 +                dominfo.migrateDevices(network, dst, DEV_MIGRATE_STEP2,
  142.27                                         domain_name)
  142.28                  log.info("Domain %d suspended.", dominfo.getDomid())
  142.29 -                dominfo.migrateDevices(live, dst, DEV_MIGRATE_STEP3,
  142.30 +                dominfo.migrateDevices(network, dst, DEV_MIGRATE_STEP3,
  142.31                                         domain_name)
  142.32                  tochild.write("done\n")
  142.33                  tochild.flush()
   143.1 --- a/tools/python/xen/xend/XendDomain.py	Mon May 22 08:53:26 2006 -0600
   143.2 +++ b/tools/python/xen/xend/XendDomain.py	Mon May 22 14:13:38 2006 -0600
   143.3 @@ -408,7 +408,7 @@ class XendDomain:
   143.4              raise XendError("Cannot migrate privileged domain %i" % domid)
   143.5  
   143.6          """ The following call may raise a XendError exception """
   143.7 -        dominfo.testMigrateDevices(live, dst)
   143.8 +        dominfo.testMigrateDevices(True, dst)
   143.9  
  143.10          if port == 0:
  143.11              port = xroot.get_xend_relocation_port()
  143.12 @@ -420,7 +420,7 @@ class XendDomain:
  143.13  
  143.14          sock.send("receive\n")
  143.15          sock.recv(80)
  143.16 -        XendCheckpoint.save(sock.fileno(), dominfo, live, dst)
  143.17 +        XendCheckpoint.save(sock.fileno(), dominfo, True, live, dst)
  143.18  
  143.19  
  143.20      def domain_save(self, domid, dst):
  143.21 @@ -440,7 +440,7 @@ class XendDomain:
  143.22              fd = os.open(dst, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
  143.23              try:
  143.24                  # For now we don't support 'live checkpoint' 
  143.25 -                return XendCheckpoint.save(fd, dominfo, False, dst)
  143.26 +                return XendCheckpoint.save(fd, dominfo, False, False, dst)
  143.27              finally:
  143.28                  os.close(fd)
  143.29          except OSError, ex:
   144.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon May 22 08:53:26 2006 -0600
   144.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon May 22 14:13:38 2006 -0600
   144.3 @@ -29,6 +29,7 @@ import logging
   144.4  import string
   144.5  import time
   144.6  import threading
   144.7 +import os
   144.8  
   144.9  import xen.lowlevel.xc
  144.10  from xen.util import asserts
  144.11 @@ -1264,7 +1265,14 @@ class XendDomainInfo:
  144.12              m = self.image.getDomainMemory(self.info['memory'] * 1024)
  144.13              balloon.free(m)
  144.14              xc.domain_setmaxmem(self.domid, m)
  144.15 -            xc.domain_memory_increase_reservation(self.domid, m, 0, 0)
  144.16 +
  144.17 +            init_reservation = self.info['memory'] * 1024
  144.18 +            if os.uname()[4] == 'ia64':
  144.19 +                # Workaround until ia64 properly supports ballooning.
  144.20 +                init_reservation = m
  144.21 +
  144.22 +            xc.domain_memory_increase_reservation(self.domid, init_reservation,
  144.23 +                                                  0, 0)
  144.24  
  144.25              self.createChannels()
  144.26  
  144.27 @@ -1443,36 +1451,40 @@ class XendDomainInfo:
  144.28  
  144.29      ## public:
  144.30  
  144.31 -    def testMigrateDevices(self, live, dst):
  144.32 +    def testMigrateDevices(self, network, dst):
  144.33          """ Notify all device about intention of migration
  144.34          @raise: XendError for a device that cannot be migrated
  144.35          """
  144.36          for (n, c) in self.info['device']:
  144.37 -            rc = self.migrateDevice(n, c, live, dst, DEV_MIGRATE_TEST)
  144.38 +            rc = self.migrateDevice(n, c, network, dst, DEV_MIGRATE_TEST)
  144.39              if rc != 0:
  144.40                  raise XendError("Device of type '%s' refuses migration." % n)
  144.41  
  144.42 -    def migrateDevices(self, live, dst, step, domName=''):
  144.43 +    def migrateDevices(self, network, dst, step, domName=''):
  144.44          """Notify the devices about migration
  144.45          """
  144.46          ctr = 0
  144.47          try:
  144.48              for (n, c) in self.info['device']:
  144.49 -                self.migrateDevice(n, c, live, dst, step, domName)
  144.50 +                self.migrateDevice(n, c, network, dst, step, domName)
  144.51                  ctr = ctr + 1
  144.52          except:
  144.53              for (n, c) in self.info['device']:
  144.54                  if ctr == 0:
  144.55                      step = step - 1
  144.56                  ctr = ctr - 1
  144.57 -                self.recoverMigrateDevice(n, c, live, dst, step, domName)
  144.58 +                self.recoverMigrateDevice(n, c, network, dst, step, domName)
  144.59              raise
  144.60  
  144.61 -    def migrateDevice(self, deviceClass, deviceConfig, live, dst, step, domName=''):
  144.62 -        return self.getDeviceController(deviceClass).migrate(deviceConfig, live, dst, step, domName)
  144.63 +    def migrateDevice(self, deviceClass, deviceConfig, network, dst,
  144.64 +                      step, domName=''):
  144.65 +        return self.getDeviceController(deviceClass).migrate(deviceConfig,
  144.66 +                                        network, dst, step, domName)
  144.67  
  144.68 -    def recoverMigrateDevice(self, deviceClass, deviceConfig, live, dst, step, domName=''):
  144.69 -        return self.getDeviceController(deviceClass).recover_migrate(deviceConfig, live, dst, step, domName)
  144.70 +    def recoverMigrateDevice(self, deviceClass, deviceConfig, network,
  144.71 +                             dst, step, domName=''):
  144.72 +        return self.getDeviceController(deviceClass).recover_migrate(
  144.73 +                     deviceConfig, network, dst, step, domName)
  144.74  
  144.75      def waitForDevices(self):
  144.76          """Wait for this domain's configured devices to connect.
   145.1 --- a/tools/python/xen/xend/image.py	Mon May 22 08:53:26 2006 -0600
   145.2 +++ b/tools/python/xen/xend/image.py	Mon May 22 14:13:38 2006 -0600
   145.3 @@ -19,6 +19,7 @@
   145.4  
   145.5  import os, string
   145.6  import re
   145.7 +import math
   145.8  
   145.9  import xen.lowlevel.xc
  145.10  from xen.xend import sxp
  145.11 @@ -141,11 +142,16 @@ class ImageHandler:
  145.12                            % (self.ostype, self.vm.getDomid(), str(result)))
  145.13  
  145.14  
  145.15 -    def getDomainMemory(self, mem):
  145.16 +    def getDomainMemory(self, mem_kb):
  145.17          """@return The memory required, in KiB, by the domain to store the
  145.18 -        given amount, also in KiB.  This is normally just mem, but HVM domains
  145.19 -        have overheads to account for."""
  145.20 -        return mem
  145.21 +        given amount, also in KiB."""
  145.22 +        if os.uname()[4] != 'ia64':
  145.23 +            # A little extra because auto-ballooning is broken w.r.t. HVM
  145.24 +            # guests. Also, slack is necessary for live migration since that
  145.25 +            # uses shadow page tables.
  145.26 +            if 'hvm' in xc.xeninfo()['xen_caps']:
  145.27 +                mem_kb += 4*1024;
  145.28 +        return mem_kb
  145.29  
  145.30      def buildDomain(self):
  145.31          """Build the domain. Define in subclass."""
  145.32 @@ -377,15 +383,20 @@ class HVMImageHandler(ImageHandler):
  145.33          os.waitpid(self.pid, 0)
  145.34          self.pid = 0
  145.35  
  145.36 -    def getDomainMemory(self, mem):
  145.37 +    def getDomainMemory(self, mem_kb):
  145.38          """@see ImageHandler.getDomainMemory"""
  145.39 -        page_kb = 4
  145.40 -        extra_pages = 0
  145.41          if os.uname()[4] == 'ia64':
  145.42              page_kb = 16
  145.43              # ROM size for guest firmware, ioreq page and xenstore page
  145.44              extra_pages = 1024 + 2
  145.45 -        return mem + extra_pages * page_kb
  145.46 +        else:
  145.47 +            page_kb = 4
  145.48 +            # This was derived emperically:
  145.49 +            #   2.4 MB overhead per 1024 MB RAM + 8 MB constant
  145.50 +            #   + 4 to avoid low-memory condition
  145.51 +            extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12;
  145.52 +            extra_pages = int( math.ceil( extra_mb*1024 / page_kb ))
  145.53 +        return mem_kb + extra_pages * page_kb
  145.54  
  145.55      def register_shutdown_watch(self):
  145.56          """ add xen store watch on control/shutdown """
   146.1 --- a/tools/python/xen/xend/server/DevController.py	Mon May 22 08:53:26 2006 -0600
   146.2 +++ b/tools/python/xen/xend/server/DevController.py	Mon May 22 14:13:38 2006 -0600
   146.3 @@ -267,9 +267,9 @@ class DevController:
   146.4  
   146.5          raise NotImplementedError()
   146.6  
   146.7 -    def migrate(self, deviceConfig, live, dst, step, domName):
   146.8 -        """ Migration of a device. The 'live' parameter indicates
   146.9 -            whether the device is live-migrated (live=1). 'dst' then gives
  146.10 +    def migrate(self, deviceConfig, network, dst, step, domName):
  146.11 +        """ Migration of a device. The 'network' parameter indicates
  146.12 +            whether the device is network-migrated (True). 'dst' then gives
  146.13              the hostname of the machine to migrate to.
  146.14          This function is called for 4 steps:
  146.15          If step == 0: Check whether the device is ready to be migrated
  146.16 @@ -296,7 +296,7 @@ class DevController:
  146.17          return 0
  146.18  
  146.19  
  146.20 -    def recover_migrate(self, deviceConfig, list, dst, step, domName):
  146.21 +    def recover_migrate(self, deviceConfig, network, dst, step, domName):
  146.22          """ Recover from device migration. The given step was the
  146.23              last one that was successfully executed.
  146.24          """
   147.1 --- a/tools/python/xen/xend/server/pciif.py	Mon May 22 08:53:26 2006 -0600
   147.2 +++ b/tools/python/xen/xend/server/pciif.py	Mon May 22 14:13:38 2006 -0600
   147.3 @@ -31,6 +31,7 @@ import xen.lowlevel.xc
   147.4  
   147.5  from xen.util.pci import PciDevice
   147.6  import resource
   147.7 +import re
   147.8  
   147.9  xc = xen.lowlevel.xc.xc()
  147.10  
  147.11 @@ -106,6 +107,30 @@ class PciController(DevController):
  147.12  
  147.13          return (0, back, {})
  147.14  
  147.15 +    def configuration(self, devid):
  147.16 +        """@see DevController.configuration"""
  147.17 +
  147.18 +        result = DevController.configuration(self, devid)
  147.19 +
  147.20 +        (num_devs) = self.readBackend(devid, 'num_devs')
  147.21 +
  147.22 +        for i in range(int(num_devs)):
  147.23 +            (dev_config) = self.readBackend(devid, 'dev-%d'%(i))
  147.24 +
  147.25 +            pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" + \
  147.26 +                    r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" + \
  147.27 +                    r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" + \
  147.28 +                    r"(?P<func>[0-9a-fA-F]{1,2})", dev_config)
  147.29 +            if pci_match!=None:
  147.30 +                pci_dev_info = pci_match.groupdict('0')
  147.31 +                result.append( ['dev', \
  147.32 +                        ['domain', '0x'+pci_dev_info['domain']], \
  147.33 +                        ['bus', '0x'+pci_dev_info['bus']], \
  147.34 +                        ['slot', '0x'+pci_dev_info['slot']], \
  147.35 +                        ['func', '0x'+pci_dev_info['func']]])
  147.36 +
  147.37 +        return result
  147.38 +
  147.39      def setupDevice(self, domain, bus, slot, func):
  147.40          """ Attach I/O resources for device to frontend domain
  147.41          """
   148.1 --- a/tools/python/xen/xend/server/tpmif.py	Mon May 22 08:53:26 2006 -0600
   148.2 +++ b/tools/python/xen/xend/server/tpmif.py	Mon May 22 14:13:38 2006 -0600
   148.3 @@ -71,12 +71,12 @@ class TPMifController(DevController):
   148.4  
   148.5          return result
   148.6  
   148.7 -    def migrate(self, deviceConfig, live, dst, step, domName):
   148.8 +    def migrate(self, deviceConfig, network, dst, step, domName):
   148.9          """@see DevContoller.migrate"""
  148.10 -        if live:
  148.11 +        if network:
  148.12              tool = xroot.get_external_migration_tool()
  148.13              if tool != '':
  148.14 -                log.info("Request to live-migrate device to %s. step=%d.",
  148.15 +                log.info("Request to network-migrate device to %s. step=%d.",
  148.16                           dst, step)
  148.17  
  148.18                  if step == DEV_MIGRATE_TEST:
  148.19 @@ -99,12 +99,12 @@ class TPMifController(DevController):
  148.20                  return -1
  148.21          return 0
  148.22  
  148.23 -    def recover_migrate(self, deviceConfig, live, dst, step, domName):
  148.24 +    def recover_migrate(self, deviceConfig, network, dst, step, domName):
  148.25          """@see DevContoller.recover_migrate"""
  148.26 -        if live:
  148.27 +        if network:
  148.28              tool = xroot.get_external_migration_tool()
  148.29              if tool != '':
  148.30 -                log.info("Request to recover live-migrated device. last good step=%d.",
  148.31 +                log.info("Request to recover network-migrated device. last good step=%d.",
  148.32                           step)
  148.33                  fd = os.popen("%s -type vtpm -step %d -host %s -domname %s -recover" %
  148.34                                (tool, step, dst, domName),
   149.1 --- a/tools/security/Makefile	Mon May 22 08:53:26 2006 -0600
   149.2 +++ b/tools/security/Makefile	Mon May 22 14:13:38 2006 -0600
   149.3 @@ -3,7 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
   149.4  
   149.5  CFLAGS   += -Werror
   149.6  CFLAGS   += -fno-strict-aliasing
   149.7 -CFLAGS   += -I.
   149.8 +CFLAGS   += -I. -I $(XEN_LIBXC)
   149.9  
  149.10  CPPFLAGS += -MMD -MF .$*.d
  149.11  PROG_DEPS = .*.d
  149.12 @@ -89,7 +89,7 @@ build: mk-symlinks $(ACM_INST_TOOLS) $(A
  149.13  	chmod 700 $(ACM_SCRIPTS)
  149.14  
  149.15  xensec_tool: $(OBJS_TOOL)
  149.16 -	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
  149.17 +	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -L$(XEN_LIBXC) -lxenctrl
  149.18  
  149.19  xensec_xml2bin: $(OBJS_XML2BIN)
  149.20  	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
   150.1 --- a/tools/security/secpol_tool.c	Mon May 22 08:53:26 2006 -0600
   150.2 +++ b/tools/security/secpol_tool.c	Mon May 22 14:13:38 2006 -0600
   150.3 @@ -231,14 +231,16 @@ void acm_dump_policy_buffer(void *buf, i
   150.4  uint8_t pull_buffer[PULL_CACHE_SIZE];
   150.5  int acm_domain_getpolicy(int xc_handle)
   150.6  {
   150.7 -    struct acm_op op;
   150.8 +    struct acm_getpolicy getpolicy;
   150.9      int ret;
  150.10  
  150.11      memset(pull_buffer, 0x00, sizeof(pull_buffer));
  150.12 -    op.cmd = ACM_GETPOLICY;
  150.13 -    op.u.getpolicy.pullcache = (void *) pull_buffer;
  150.14 -    op.u.getpolicy.pullcache_size = sizeof(pull_buffer);
  150.15 -    if ((ret = xc_acm_op(xc_handle, &op)) < 0) {
  150.16 +    getpolicy.interface_version = ACM_INTERFACE_VERSION;
  150.17 +    getpolicy.pullcache = (void *) pull_buffer;
  150.18 +    getpolicy.pullcache_size = sizeof(pull_buffer);
  150.19 +    ret = xc_acm_op(xc_handle, ACMOP_getpolicy, &getpolicy, sizeof(getpolicy));
  150.20 +
  150.21 +    if (ret < 0) {
  150.22          printf("ACM operation failed: errno=%d\n", errno);
  150.23          if (errno == EACCES)
  150.24              fprintf(stderr, "ACM operation failed -- need to"
  150.25 @@ -275,13 +277,13 @@ int acm_domain_loadpolicy(int xc_handle,
  150.26          goto free_out;
  150.27      }
  150.28      if (len == read(fd, buffer, len)) {
  150.29 -        struct acm_op op;
  150.30 +        struct acm_setpolicy setpolicy;
  150.31          /* dump it and then push it down into xen/acm */
  150.32          acm_dump_policy_buffer(buffer, len);
  150.33 -        op.cmd = ACM_SETPOLICY;
  150.34 -        op.u.setpolicy.pushcache = (void *) buffer;
  150.35 -        op.u.setpolicy.pushcache_size = len;
  150.36 -        ret = xc_acm_op(xc_handle, &op);
  150.37 +        setpolicy.interface_version = ACM_INTERFACE_VERSION;
  150.38 +        setpolicy.pushcache = (void *) buffer;
  150.39 +        setpolicy.pushcache_size = len;
  150.40 +        ret = xc_acm_op(xc_handle, ACMOP_setpolicy, &setpolicy, sizeof(setpolicy));
  150.41  
  150.42          if (ret)
  150.43              printf
  150.44 @@ -322,15 +324,15 @@ void dump_ste_stats(struct acm_ste_stats
  150.45  int acm_domain_dumpstats(int xc_handle)
  150.46  {
  150.47      uint8_t stats_buffer[PULL_STATS_SIZE];
  150.48 -    struct acm_op op;
  150.49 +    struct acm_dumpstats dumpstats;
  150.50      int ret;
  150.51      struct acm_stats_buffer *stats;
  150.52  
  150.53      memset(stats_buffer, 0x00, sizeof(stats_buffer));
  150.54 -    op.cmd = ACM_DUMPSTATS;
  150.55 -    op.u.dumpstats.pullcache = (void *) stats_buffer;
  150.56 -    op.u.dumpstats.pullcache_size = sizeof(stats_buffer);
  150.57 -    ret = xc_acm_op(xc_handle, &op);
  150.58 +    dumpstats.interface_version = ACM_INTERFACE_VERSION;
  150.59 +    dumpstats.pullcache = (void *) stats_buffer;
  150.60 +    dumpstats.pullcache_size = sizeof(stats_buffer);
  150.61 +    ret = xc_acm_op(xc_handle, ACMOP_dumpstats, &dumpstats, sizeof(dumpstats));
  150.62  
  150.63      if (ret < 0) {
  150.64          printf
   151.1 --- a/tools/tests/Makefile	Mon May 22 08:53:26 2006 -0600
   151.2 +++ b/tools/tests/Makefile	Mon May 22 14:13:38 2006 -0600
   151.3 @@ -4,8 +4,6 @@ include $(XEN_ROOT)/tools/Rules.mk
   151.4  
   151.5  TARGET := test_x86_emulator
   151.6  
   151.7 -HOSTCFLAGS += -D__TEST_HARNESS__
   151.8 -
   151.9  .PHONY: all
  151.10  all: $(TARGET)
  151.11  
   152.1 --- a/tools/vtpm/Makefile	Mon May 22 08:53:26 2006 -0600
   152.2 +++ b/tools/vtpm/Makefile	Mon May 22 14:13:38 2006 -0600
   152.3 @@ -21,7 +21,9 @@ build: $(TPM_EMULATOR_DIR) $(VTPM_DIR) b
   152.4  
   152.5  .PHONY: install
   152.6  install: build
   152.7 -	$(MAKE) -C $(TPM_EMULATOR_DIR) $@
   152.8 +	if [ "$(BUILD_EMULATOR)" = "y" ]; then \
   152.9 +		$(MAKE) -C $(TPM_EMULATOR_DIR) $@ ;\
  152.10 +	fi 
  152.11  	$(MAKE) -C $(VTPM_DIR) $@
  152.12  
  152.13  .PHONY: clean
  152.14 @@ -46,20 +48,21 @@ mrproper:
  152.15  # Create vtpm and TPM emulator dirs
  152.16  # apply patches for 1) used as dom0 tpm driver 2) used as vtpm device instance
  152.17  $(TPM_EMULATOR_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator.patch tpm_emulator-0.2b-x86_64.patch
  152.18 -	tar -xzf $(TPM_EMULATOR_TARFILE);
  152.19 -	rm -rf $(TPM_EMULATOR_DIR)
  152.20 -	mv tpm_emulator-0.2 $(TPM_EMULATOR_DIR); 
  152.21 -	
  152.22 -	-cd $(TPM_EMULATOR_DIR); \
  152.23 -	patch -p1 < ../tpm_emulator-0.2b-x86_64.patch; \
  152.24 -	patch -p1 <../tpm_emulator.patch
  152.25 +	if [ "$(BUILD_EMULATOR)" = "y" ]; then \
  152.26 +		tar -xzf $(TPM_EMULATOR_TARFILE); \
  152.27 +		rm -rf $(TPM_EMULATOR_DIR); \
  152.28 +		mv tpm_emulator-0.2 $(TPM_EMULATOR_DIR); \
  152.29 +		cd $(TPM_EMULATOR_DIR); \
  152.30 +		patch -p1 < ../tpm_emulator-0.2b-x86_64.patch; \
  152.31 +		patch -p1 <../tpm_emulator.patch; \
  152.32 +	fi
  152.33  
  152.34  $(VTPM_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator-0.2b-x86_64.patch vtpm.patch
  152.35  	tar -xzf $(TPM_EMULATOR_TARFILE);  
  152.36  	rm -rf $(VTPM_DIR)
  152.37  	mv tpm_emulator-0.2 $(VTPM_DIR); 
  152.38  
  152.39 -	-cd $(VTPM_DIR); \
  152.40 +	cd $(VTPM_DIR); \
  152.41  	patch -p1 < ../tpm_emulator-0.2b-x86_64.patch; \
  152.42  	patch -p1 <../vtpm.patch
  152.43  
   153.1 --- a/tools/vtpm/tpm_emulator.patch	Mon May 22 08:53:26 2006 -0600
   153.2 +++ b/tools/vtpm/tpm_emulator.patch	Mon May 22 14:13:38 2006 -0600
   153.3 @@ -52,7 +52,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   153.4  -KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
   153.5  +CUR_DIR        := $(shell pwd)
   153.6  +LINUX_VERSION  := $(shell cat $(CUR_DIR)/$(XEN_ROOT)/buildconfigs/mk.linux-2.6-xen | grep "LINUX_VER" | grep "2.6" | gawk '{ print $$3 }' )
   153.7 -+KERNEL_BUILD   := $(XEN_ROOT)/linux-$(LINUX_VERSION)-xen0
   153.8 ++KERNEL_BUILD   := $(XEN_ROOT)/linux-$(LINUX_VERSION)-xen
   153.9   MOD_SUBDIR     := misc
  153.10   COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
  153.11   
   154.1 --- a/tools/vtpm/vtpm.patch	Mon May 22 08:53:26 2006 -0600
   154.2 +++ b/tools/vtpm/vtpm.patch	Mon May 22 14:13:38 2006 -0600
   154.3 @@ -1,12 +1,12 @@
   154.4  diff -uprN orig/tpm_emulator-0.2-x86_64/AUTHORS vtpm/AUTHORS
   154.5  --- orig/tpm_emulator-0.2-x86_64/AUTHORS	2005-08-15 00:58:57.000000000 -0700
   154.6 -+++ vtpm/AUTHORS	2005-09-14 20:27:22.000000000 -0700
   154.7 ++++ vtpm/AUTHORS	2006-05-17 09:31:11.000000000 -0700
   154.8  @@ -1 +1,2 @@
   154.9   Mario Strasser <mast@gmx.net>
  154.10  +INTEL Corp <>
  154.11  diff -uprN orig/tpm_emulator-0.2-x86_64/ChangeLog vtpm/ChangeLog
  154.12  --- orig/tpm_emulator-0.2-x86_64/ChangeLog	2005-08-15 00:58:57.000000000 -0700
  154.13 -+++ vtpm/ChangeLog	2005-09-14 20:27:22.000000000 -0700
  154.14 ++++ vtpm/ChangeLog	2006-05-17 09:31:11.000000000 -0700
  154.15  @@ -1,3 +1,7 @@
  154.16  +2005-08-16 Intel Corp
  154.17  +	Moved module out of kernel to run as a ring 3 app
  154.18 @@ -16,8 +16,8 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  154.19   	* all: some typos corrected
  154.20   	* tpm_integrity.c: bug in TPM_Extend fixed
  154.21  diff -uprN orig/tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c vtpm/crypto/gmp_kernel_wrapper.c
  154.22 ---- orig/tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c	2005-09-15 19:21:42.508873032 -0700
  154.23 -+++ vtpm/crypto/gmp_kernel_wrapper.c	2005-09-15 19:25:37.319176440 -0700
  154.24 +--- orig/tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c	2006-05-17 09:34:13.000000000 -0700
  154.25 ++++ vtpm/crypto/gmp_kernel_wrapper.c	2006-05-17 09:31:11.000000000 -0700
  154.26  @@ -1,5 +1,6 @@
  154.27   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  154.28    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  154.29 @@ -59,10 +59,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  154.30   {
  154.31  -  void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
  154.32  -  if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
  154.33 --    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
  154.34  +  void *ret = (void*)malloc(new_size);
  154.35  +  if (!ret) error("GMP: Cannot reallocate memory "
  154.36 -+    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
  154.37 +     "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
  154.38     memcpy(ret, oldptr, old_size);
  154.39  -  kfree(oldptr);
  154.40  +  free(oldptr);
  154.41 @@ -80,7 +79,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  154.42   
  154.43  diff -uprN orig/tpm_emulator-0.2-x86_64/crypto/rsa.c vtpm/crypto/rsa.c
  154.44  --- orig/tpm_emulator-0.2-x86_64/crypto/rsa.c	2005-08-15 00:58:57.000000000 -0700
  154.45 -+++ vtpm/crypto/rsa.c	2005-09-14 20:27:22.000000000 -0700
  154.46 ++++ vtpm/crypto/rsa.c	2006-05-17 09:31:11.000000000 -0700
  154.47  @@ -1,5 +1,6 @@
  154.48   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  154.49    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  154.50 @@ -107,7 +106,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  154.51         if (memcmp(&msg[1], &msg[1 + SHA1_DIGEST_LENGTH], 
  154.52             SHA1_DIGEST_LENGTH) != 0) return -1;
  154.53  diff -uprN orig/tpm_emulator-0.2-x86_64/linux_module.c vtpm/linux_module.c
  154.54 ---- orig/tpm_emulator-0.2-x86_64/linux_module.c	2005-09-15 19:22:40.343080896 -0700
  154.55 +--- orig/tpm_emulator-0.2-x86_64/linux_module.c	2006-05-17 09:34:13.000000000 -0700
  154.56  +++ vtpm/linux_module.c	1969-12-31 16:00:00.000000000 -0800
  154.57  @@ -1,163 +0,0 @@
  154.58  -/* Software-Based Trusted Platform Module (TPM) Emulator for Linux 
  154.59 @@ -274,8 +273,8 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  154.60  -}
  154.61  -
  154.62  diff -uprN orig/tpm_emulator-0.2-x86_64/linux_module.h vtpm/linux_module.h
  154.63 ---- orig/tpm_emulator-0.2-x86_64/linux_module.h	2005-09-15 19:21:14.844078720 -0700
  154.64 -+++ vtpm/linux_module.h	2005-09-14 20:27:22.000000000 -0700
  154.65 +--- orig/tpm_emulator-0.2-x86_64/linux_module.h	2006-05-17 09:34:13.000000000 -0700
  154.66 ++++ vtpm/linux_module.h	2006-05-17 09:31:11.000000000 -0700
  154.67  @@ -1,5 +1,6 @@
  154.68   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  154.69    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  154.70 @@ -376,8 +375,8 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  154.71   #define LE16_TO_CPU(x) __le16_to_cpu(x)
  154.72   
  154.73  diff -uprN orig/tpm_emulator-0.2-x86_64/Makefile vtpm/Makefile
  154.74 ---- orig/tpm_emulator-0.2-x86_64/Makefile	2005-09-15 19:21:14.845078568 -0700
  154.75 -+++ vtpm/Makefile	2005-09-14 20:27:22.000000000 -0700
  154.76 +--- orig/tpm_emulator-0.2-x86_64/Makefile	2006-05-17 09:34:13.000000000 -0700
  154.77 ++++ vtpm/Makefile	2006-05-17 09:31:11.000000000 -0700
  154.78  @@ -1,22 +1,31 @@
  154.79   # Software-Based Trusted Platform Module (TPM) Emulator for Linux
  154.80   # Copyright (C) 2004 Mario Strasser <mast@gmx.net>
  154.81 @@ -410,7 +409,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  154.82  +
  154.83  +CC      := gcc
  154.84  +CFLAGS  += -g -Wall $(INCLUDE) -DDEBUG
  154.85 -+CFLAGS  += -I. -Itpm
  154.86 ++CFLAGS  += -I. -Itpm -I../../vtpm_manager/manager
  154.87  +
  154.88  +# Is the simulator running in it's own vm?
  154.89  +#CFLAGS += -DVTPM_MULTI_VM
  154.90 @@ -470,8 +469,8 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  154.91   $(src)/crypto/libgmp.a:
  154.92   	test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a
  154.93  diff -uprN orig/tpm_emulator-0.2-x86_64/README vtpm/README
  154.94 ---- orig/tpm_emulator-0.2-x86_64/README	2005-08-15 00:58:57.000000000 -0700
  154.95 -+++ vtpm/README	2005-09-14 20:27:22.000000000 -0700
  154.96 +--- orig/tpm_emulator-0.2-x86_64/README	2006-05-17 09:34:13.000000000 -0700
  154.97 ++++ vtpm/README	2006-05-17 09:31:11.000000000 -0700
  154.98  @@ -13,7 +13,8 @@ $Id: README 8 2005-01-25 21:11:45Z jmoli
  154.99   Copyright
 154.100   --------------------------------------------------------------------------
 154.101 @@ -484,7 +483,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.102   it under the terms of the GNU General Public License as published by
 154.103  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_audit.c vtpm/tpm/tpm_audit.c
 154.104  --- orig/tpm_emulator-0.2-x86_64/tpm/tpm_audit.c	2005-08-15 00:58:57.000000000 -0700
 154.105 -+++ vtpm/tpm/tpm_audit.c	2005-09-14 20:27:22.000000000 -0700
 154.106 ++++ vtpm/tpm/tpm_audit.c	2006-05-17 09:31:11.000000000 -0700
 154.107  @@ -1,6 +1,7 @@
 154.108   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.109    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.110 @@ -549,7 +548,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.111  -
 154.112  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_authorization.c vtpm/tpm/tpm_authorization.c
 154.113  --- orig/tpm_emulator-0.2-x86_64/tpm/tpm_authorization.c	2005-08-15 00:58:57.000000000 -0700
 154.114 -+++ vtpm/tpm/tpm_authorization.c	2005-09-14 20:27:22.000000000 -0700
 154.115 ++++ vtpm/tpm/tpm_authorization.c	2006-05-17 09:31:11.000000000 -0700
 154.116  @@ -1,6 +1,7 @@
 154.117   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.118    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.119 @@ -575,7 +574,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.120  -
 154.121  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_capability.c vtpm/tpm/tpm_capability.c
 154.122  --- orig/tpm_emulator-0.2-x86_64/tpm/tpm_capability.c	2005-08-15 00:58:57.000000000 -0700
 154.123 -+++ vtpm/tpm/tpm_capability.c	2005-09-14 20:27:22.000000000 -0700
 154.124 ++++ vtpm/tpm/tpm_capability.c	2006-05-17 09:31:11.000000000 -0700
 154.125  @@ -1,6 +1,7 @@
 154.126   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.127    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.128 @@ -600,7 +599,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.129  -
 154.130  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_cmd_handler.c vtpm/tpm/tpm_cmd_handler.c
 154.131  --- orig/tpm_emulator-0.2-x86_64/tpm/tpm_cmd_handler.c	2005-08-15 00:58:57.000000000 -0700
 154.132 -+++ vtpm/tpm/tpm_cmd_handler.c	2005-09-14 20:27:22.000000000 -0700
 154.133 ++++ vtpm/tpm/tpm_cmd_handler.c	2006-05-17 09:31:11.000000000 -0700
 154.134  @@ -1,6 +1,7 @@
 154.135   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.136    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.137 @@ -664,8 +663,8 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.138   }
 154.139  -
 154.140  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c vtpm/tpm/tpm_crypto.c
 154.141 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c	2005-09-15 19:21:14.846078416 -0700
 154.142 -+++ vtpm/tpm/tpm_crypto.c	2005-09-14 20:27:22.000000000 -0700
 154.143 +--- orig/tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c	2006-05-17 09:34:13.000000000 -0700
 154.144 ++++ vtpm/tpm/tpm_crypto.c	2006-05-17 09:31:11.000000000 -0700
 154.145  @@ -1,6 +1,7 @@
 154.146   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.147    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.148 @@ -689,8 +688,8 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.149   }
 154.150  -
 154.151  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_data.c vtpm/tpm/tpm_data.c
 154.152 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_data.c	2005-09-15 19:21:14.847078264 -0700
 154.153 -+++ vtpm/tpm/tpm_data.c	2005-09-14 20:27:22.000000000 -0700
 154.154 +--- orig/tpm_emulator-0.2-x86_64/tpm/tpm_data.c	2006-05-17 09:34:13.000000000 -0700
 154.155 ++++ vtpm/tpm/tpm_data.c	2006-05-17 09:31:11.000000000 -0700
 154.156  @@ -1,6 +1,7 @@
 154.157   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.158    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.159 @@ -760,8 +759,8 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.160  +#ifdef VTPM_MUTLI_VM
 154.161  + #define DEV_FE "/dev/tpm"
 154.162  +#else
 154.163 -+ #define VTPM_RX_FIFO_D  "/var/vtpm/fifos/vtpm-to-%d.fifo"
 154.164 -+ #define VTPM_TX_FIFO  "/var/vtpm/fifos/vtpm-from-all.fifo"
 154.165 ++ #define VTPM_RX_FIFO_D  "/var/vtpm/fifos/vtpm_rsp_to_%d.fifo"
 154.166 ++ #define VTPM_TX_FIFO  "/var/vtpm/fifos/vtpm_cmd_from_all.fifo"
 154.167  +
 154.168  + extern int dmi_id;
 154.169  + static char *vtpm_rx_name=NULL; 
 154.170 @@ -1021,7 +1020,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.171  -
 154.172  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_deprecated.c vtpm/tpm/tpm_deprecated.c
 154.173  --- orig/tpm_emulator-0.2-x86_64/tpm/tpm_deprecated.c	2005-08-15 00:58:57.000000000 -0700
 154.174 -+++ vtpm/tpm/tpm_deprecated.c	2005-09-14 20:27:22.000000000 -0700
 154.175 ++++ vtpm/tpm/tpm_deprecated.c	2006-05-17 09:31:11.000000000 -0700
 154.176  @@ -1,6 +1,7 @@
 154.177   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.178    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.179 @@ -1050,7 +1049,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.180     len = *authContextSize;
 154.181  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_emulator.h vtpm/tpm/tpm_emulator.h
 154.182  --- orig/tpm_emulator-0.2-x86_64/tpm/tpm_emulator.h	2005-08-15 00:58:57.000000000 -0700
 154.183 -+++ vtpm/tpm/tpm_emulator.h	2005-09-14 20:27:22.000000000 -0700
 154.184 ++++ vtpm/tpm/tpm_emulator.h	2006-05-17 09:31:11.000000000 -0700
 154.185  @@ -1,5 +1,6 @@
 154.186   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.187    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.188 @@ -1070,7 +1069,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.189    * tpm_emulator_init - initialises and starts the TPM emulator
 154.190  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_integrity.c vtpm/tpm/tpm_integrity.c
 154.191  --- orig/tpm_emulator-0.2-x86_64/tpm/tpm_integrity.c	2005-08-15 00:58:57.000000000 -0700
 154.192 -+++ vtpm/tpm/tpm_integrity.c	2005-09-14 20:27:22.000000000 -0700
 154.193 ++++ vtpm/tpm/tpm_integrity.c	2006-05-17 09:31:11.000000000 -0700
 154.194  @@ -1,6 +1,7 @@
 154.195   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.196    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.197 @@ -1086,7 +1085,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.198  -
 154.199  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_structures.h vtpm/tpm/tpm_structures.h
 154.200  --- orig/tpm_emulator-0.2-x86_64/tpm/tpm_structures.h	2005-08-15 00:58:57.000000000 -0700
 154.201 -+++ vtpm/tpm/tpm_structures.h	2005-09-14 20:27:22.000000000 -0700
 154.202 ++++ vtpm/tpm/tpm_structures.h	2006-05-17 09:31:11.000000000 -0700
 154.203  @@ -1,6 +1,7 @@
 154.204   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.205    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.206 @@ -1106,7 +1105,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.207   /*
 154.208  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_testing.c vtpm/tpm/tpm_testing.c
 154.209  --- orig/tpm_emulator-0.2-x86_64/tpm/tpm_testing.c	2005-08-15 00:58:57.000000000 -0700
 154.210 -+++ vtpm/tpm/tpm_testing.c	2005-09-14 20:27:22.000000000 -0700
 154.211 ++++ vtpm/tpm/tpm_testing.c	2006-05-17 09:31:11.000000000 -0700
 154.212  @@ -1,6 +1,7 @@
 154.213   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.214    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.215 @@ -1224,7 +1223,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.216   
 154.217  diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_ticks.c vtpm/tpm/tpm_ticks.c
 154.218  --- orig/tpm_emulator-0.2-x86_64/tpm/tpm_ticks.c	2005-08-15 00:58:57.000000000 -0700
 154.219 -+++ vtpm/tpm/tpm_ticks.c	2005-09-14 20:27:22.000000000 -0700
 154.220 ++++ vtpm/tpm/tpm_ticks.c	2006-05-17 09:31:11.000000000 -0700
 154.221  @@ -1,6 +1,7 @@
 154.222   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.223    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
 154.224 @@ -1307,139 +1306,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.225   }
 154.226     
 154.227   
 154.228 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/vtpm_manager.h vtpm/tpm/vtpm_manager.h
 154.229 ---- orig/tpm_emulator-0.2-x86_64/tpm/vtpm_manager.h	1969-12-31 16:00:00.000000000 -0800
 154.230 -+++ vtpm/tpm/vtpm_manager.h	2005-09-14 20:27:22.000000000 -0700
 154.231 -@@ -0,0 +1,126 @@
 154.232 -+// ===================================================================
 154.233 -+// 
 154.234 -+// Copyright (c) 2005, Intel Corp.
 154.235 -+// All rights reserved.
 154.236 -+//
 154.237 -+// Redistribution and use in source and binary forms, with or without 
 154.238 -+// modification, are permitted provided that the following conditions 
 154.239 -+// are met:
 154.240 -+//
 154.241 -+//   * Redistributions of source code must retain the above copyright 
 154.242 -+//     notice, this list of conditions and the following disclaimer.
 154.243 -+//   * Redistributions in binary form must reproduce the above 
 154.244 -+//     copyright notice, this list of conditions and the following 
 154.245 -+//     disclaimer in the documentation and/or other materials provided 
 154.246 -+//     with the distribution.
 154.247 -+//   * Neither the name of Intel Corporation nor the names of its 
 154.248 -+//     contributors may be used to endorse or promote products derived
 154.249 -+//     from this software without specific prior written permission.
 154.250 -+//
 154.251 -+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 154.252 -+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 154.253 -+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 154.254 -+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 154.255 -+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 154.256 -+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 154.257 -+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 154.258 -+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 154.259 -+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 154.260 -+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 154.261 -+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 154.262 -+// OF THE POSSIBILITY OF SUCH DAMAGE.
 154.263 -+// ===================================================================
 154.264 -+// 
 154.265 -+// vtpm_manager.h
 154.266 -+// 
 154.267 -+//  Public Interface header for VTPM Manager
 154.268 -+//
 154.269 -+// ==================================================================
 154.270 -+
 154.271 -+#ifndef __VTPM_MANAGER_H__
 154.272 -+#define __VTPM_MANAGER_H__
 154.273 -+
 154.274 -+#define VTPM_TAG_REQ 0x01c1
 154.275 -+#define VTPM_TAG_RSP 0x01c4
 154.276 -+#define COMMAND_BUFFER_SIZE 4096
 154.277 -+
 154.278 -+// Header sizes. Note Header MAY include the DMI
 154.279 -+#define VTPM_COMMAND_HEADER_SIZE_SRV ( sizeof(UINT32) + sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
 154.280 -+#define VTPM_COMMAND_HEADER_SIZE_CLT (                  sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
 154.281 -+
 154.282 -+//************************ Command Codes ****************************
 154.283 -+#define VTPM_ORD_OPEN              1   // ULM Creates New DMI
 154.284 -+#define VTPM_ORD_CLOSE             2   // ULM Closes a DMI
 154.285 -+#define VTPM_ORD_DELETE            3   // ULM Permemently Deletes DMI
 154.286 -+#define VTPM_ORD_SAVENVM          4   // DMI requests Secrets Unseal
 154.287 -+#define VTPM_ORD_LOADNVM          5   // DMI requests Secrets Saved
 154.288 -+#define VTPM_ORD_TPMCOMMAND       6   // DMI issues HW TPM Command
 154.289 -+
 154.290 -+//************************ Return Codes ****************************
 154.291 -+#define VTPM_SUCCESS               0
 154.292 -+#define VTPM_FAIL                  1
 154.293 -+#define VTPM_UNSUPPORTED           2
 154.294 -+#define VTPM_FORBIDDEN             3
 154.295 -+#define VTPM_RESTORE_CONTEXT_FAILED    4
 154.296 -+#define VTPM_INVALID_REQUEST       5
 154.297 -+
 154.298 -+/******************* Command Parameter API *************************
 154.299 -+
 154.300 -+VTPM Command Format
 154.301 -+  dmi: 4 bytes                  // Source of message. 
 154.302 -+                                // WARNING: This is prepended by the channel. 
 154.303 -+                                // Thus it is received by VTPM Manager, 
 154.304 -+                                // but not sent by DMI
 154.305 -+  tpm tag: 2 bytes
 154.306 -+  command size: 4 bytes         // Size of command including header but not DMI
 154.307 -+  ord: 4 bytes                  // Command ordinal above
 154.308 -+  parameters: size - 10 bytes   // Command Parameter
 154.309 -+
 154.310 -+VTPM Response Format
 154.311 -+  tpm tag: 2 bytes
 154.312 -+  response_size: 4 bytes
 154.313 -+  status: 4 bytes         
 154.314 -+  parameters: size - 10 bytes
 154.315 -+
 154.316 -+
 154.317 -+VTPM_Open:
 154.318 -+  Input Parameters:
 154.319 -+    Domain_type: 1 byte
 154.320 -+    domain_id: 4 bytes
 154.321 -+    instance_id: 4 bytes
 154.322 -+  Output Parameters:
 154.323 -+    None
 154.324 -+    
 154.325 -+VTPM_Close
 154.326 -+  Input Parameters:
 154.327 -+    instance_id: 4 bytes
 154.328 -+  Output Parameters:
 154.329 -+    None
 154.330 -+
 154.331 -+VTPM_Delete
 154.332 -+  Input Parameters:
 154.333 -+    instance_id: 4 bytes
 154.334 -+  Output Parameters:
 154.335 -+    None
 154.336 -+
 154.337 -+VTPM_SaveNVM
 154.338 -+  Input Parameters:
 154.339 -+    data: n bytes (Header indicates size of data)
 154.340 -+  Output Parameters:
 154.341 -+    None
 154.342 -+
 154.343 -+VTPM_LoadNVM
 154.344 -+  Input Parameters:
 154.345 -+    None
 154.346 -+  Output Parameters:
 154.347 -+    data: n bytes (Header indicates size of data)
 154.348 -+
 154.349 -+VTPM_TPMCommand
 154.350 -+  Input Parameters:
 154.351 -+    TPM Command Byte Stream: n bytes 
 154.352 -+  Output Parameters:
 154.353 -+    TPM Reponse Byte Stream: n bytes 
 154.354 -+
 154.355 -+*********************************************************************/
 154.356 -+
 154.357 -+#endif //_VTPM_MANAGER_H_
 154.358  diff -uprN orig/tpm_emulator-0.2-x86_64/tpmd.c vtpm/tpmd.c
 154.359  --- orig/tpm_emulator-0.2-x86_64/tpmd.c	1969-12-31 16:00:00.000000000 -0800
 154.360 -+++ vtpm/tpmd.c	2005-09-15 19:28:55.783005352 -0700
 154.361 ++++ vtpm/tpmd.c	2006-05-17 09:31:11.000000000 -0700
 154.362  @@ -0,0 +1,207 @@
 154.363  +/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 154.364  + * Copyright (C) 2005 INTEL Corp
 154.365 @@ -1471,8 +1340,8 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 154.366  +#ifdef VTPM_MULTI_VM
 154.367  + #define DEV_BE "/dev/vtpm"
 154.368  +#else
 154.369 -+ #define GUEST_RX_FIFO_D "/var/vtpm/fifos/guest-to-%d.fifo"
 154.370 -+ #define GUEST_TX_FIFO "/var/vtpm/fifos/guest-from-all.fifo"
 154.371 ++ #define GUEST_RX_FIFO_D "/var/vtpm/fifos/tpm_cmd_to_%d.fifo"
 154.372 ++ #define GUEST_TX_FIFO "/var/vtpm/fifos/tpm_rsp_from_all.fifo"
 154.373  +#endif
 154.374  +
 154.375  + int dmi_id;
   155.1 --- a/tools/vtpm_manager/Rules.mk	Mon May 22 08:53:26 2006 -0600
   155.2 +++ b/tools/vtpm_manager/Rules.mk	Mon May 22 14:13:38 2006 -0600
   155.3 @@ -40,6 +40,9 @@ OBJS	= $(patsubst %.c,%.o,$(SRCS))
   155.4  # Project-specific definitions
   155.5  #
   155.6  
   155.7 +# Need UNIX98 spec for pthread rwlocks
   155.8 +CFLAGS += -D_GNU_SOURCE
   155.9 +
  155.10  # Logging Level. See utils/tools.h for usage
  155.11  CFLAGS += -DLOGGING_MODULES="(BITMASK(VTPM_LOG_TCS)|BITMASK(VTPM_LOG_VTSP)|BITMASK(VTPM_LOG_VTPM)|BITMASK(VTPM_LOG_VTPM_DEEP))"
  155.12  
  155.13 @@ -50,7 +53,7 @@ CFLAGS += -DLOGGING_MODULES="(BITMASK(VT
  155.14  # Use frontend/backend pairs between manager & DMs?
  155.15  #CFLAGS += -DVTPM_MULTI_VM
  155.16  
  155.17 -# vtpm_manager listens on /tmp/in.fifo and /tmp/out.fifo rather than backend
  155.18 +# vtpm_manager listens on fifo's rather than backend
  155.19  #CFLAGS += -DDUMMY_BACKEND
  155.20  
  155.21  # Do not have manager launch DMs.
  155.22 @@ -59,9 +62,6 @@ CFLAGS += -DLOGGING_MODULES="(BITMASK(VT
  155.23  # Fixed OwnerAuth
  155.24  #CFLAGS += -DWELL_KNOWN_OWNER_AUTH
  155.25  
  155.26 -# TPM Hardware Device or TPM Simulator
  155.27 -#CFLAGS += -DTPM_HWDEV
  155.28 -
  155.29  # Include
  155.30  CFLAGS += -I$(XEN_ROOT)/tools/vtpm_manager/crypto
  155.31  CFLAGS += -I$(XEN_ROOT)/tools/vtpm_manager/util
   156.1 --- a/tools/vtpm_manager/manager/dmictl.c	Mon May 22 08:53:26 2006 -0600
   156.2 +++ b/tools/vtpm_manager/manager/dmictl.c	Mon May 22 14:13:38 2006 -0600
   156.3 @@ -55,66 +55,30 @@
   156.4  #include "log.h"
   156.5  #include "hashtable.h"
   156.6  #include "hashtable_itr.h"
   156.7 +#include "vtpm_ipc.h"
   156.8  
   156.9  #define TPM_EMULATOR_PATH "/usr/bin/vtpmd"
  156.10  
  156.11 -TPM_RESULT close_dmi( VTPM_DMI_RESOURCE *dmi_res) {
  156.12 -  TPM_RESULT status = TPM_FAIL;
  156.13 -  
  156.14 +TPM_RESULT close_dmi(VTPM_DMI_RESOURCE *dmi_res) {
  156.15    if (dmi_res == NULL) 
  156.16      return TPM_SUCCESS;
  156.17  
  156.18 -  status = TCS_CloseContext(dmi_res->TCSContext);
  156.19 +  TCS_CloseContext(dmi_res->TCSContext);
  156.20    free ( dmi_res->NVMLocation );
  156.21    dmi_res->connected = FALSE;
  156.22  
  156.23 -#ifndef VTPM_MULTI_VM	
  156.24 -  free(dmi_res->guest_tx_fname);
  156.25 -  free(dmi_res->vtpm_tx_fname);
  156.26 -	  
  156.27 -  close(dmi_res->guest_tx_fh); dmi_res->guest_tx_fh = -1;
  156.28 -  close(dmi_res->vtpm_tx_fh);  dmi_res->vtpm_tx_fh = -1; 
  156.29    vtpm_globals->connected_dmis--;
  156.30  
  156.31 -  if (vtpm_globals->connected_dmis == 0) {
  156.32 -    // No more DMI's connected. Close fifo to prevent a broken pipe.
  156.33 -    close(vtpm_globals->guest_rx_fh);
  156.34 -    vtpm_globals->guest_rx_fh = -1;
  156.35 -  }
  156.36 - #ifndef MANUAL_DM_LAUNCH
  156.37 -  if (dmi_res->dmi_id != VTPM_CTL_DM) {
  156.38 -    if (dmi_res->dmi_pid != 0) {
  156.39 -      vtpmloginfo(VTPM_LOG_VTPM, "Killing dmi on pid %d.\n", dmi_res->dmi_pid);
  156.40 -      if (kill(dmi_res->dmi_pid, SIGKILL) !=0) {
  156.41 -        vtpmloginfo(VTPM_LOG_VTPM, "DMI on pid %d is already dead.\n", dmi_res->dmi_pid);
  156.42 -      } else if (waitpid(dmi_res->dmi_pid, NULL, 0) != dmi_res->dmi_pid) {
  156.43 -        vtpmlogerror(VTPM_LOG_VTPM, "DMI on pid %d failed to stop.\n", dmi_res->dmi_pid);
  156.44 -        status = TPM_FAIL;
  156.45 -      }
  156.46 -    } else { 
  156.47 -      vtpmlogerror(VTPM_LOG_VTPM, "Could not kill dmi because it's pid was 0.\n");
  156.48 -      status = TPM_FAIL;
  156.49 -    }
  156.50 -  }
  156.51 - #endif
  156.52 -#endif
  156.53 -
  156.54 -  return status;
  156.55 +  return (VTPM_Close_DMI_Extra(dmi_res) );
  156.56  }
  156.57  	
  156.58 -TPM_RESULT VTPM_Handle_New_DMI( const buffer_t *param_buf) {
  156.59 +TPM_RESULT VTPM_Handle_New_DMI(const buffer_t *param_buf) {
  156.60    
  156.61    VTPM_DMI_RESOURCE *new_dmi=NULL;
  156.62    TPM_RESULT status=TPM_FAIL;
  156.63    BYTE type;
  156.64    UINT32 dmi_id, domain_id, *dmi_id_key; 
  156.65  
  156.66 -#ifndef VTPM_MULTI_VM
  156.67 -  int fh;
  156.68 -  char dmi_id_str[11]; // UINT32s are up to 10 digits + NULL
  156.69 -  struct stat file_info;
  156.70 -#endif
  156.71 -  
  156.72    if (param_buf == NULL) { // Assume creation of Dom 0 control
  156.73      type = 0;
  156.74      domain_id = VTPM_CTL_DM;
  156.75 @@ -156,7 +120,7 @@ TPM_RESULT VTPM_Handle_New_DMI( const bu
  156.76        status = TPM_FAIL;
  156.77        goto egress;
  156.78      }
  156.79 -    
  156.80 +   
  156.81    } else 
  156.82      vtpmloginfo(VTPM_LOG_VTPM, "Re-attaching DMI instance %d on domain %d .\n", dmi_id, domain_id);
  156.83    
  156.84 @@ -176,94 +140,16 @@ TPM_RESULT VTPM_Handle_New_DMI( const bu
  156.85    new_dmi->NVMLocation = (char *) malloc(11 + strlen(DMI_NVM_FILE));
  156.86    sprintf(new_dmi->NVMLocation, DMI_NVM_FILE, (uint32_t) new_dmi->dmi_id);
  156.87    
  156.88 -  // Measure DMI
  156.89 -  // FIXME: This will measure DMI. Until then use a fixed DMI_Measurement value
  156.90 -  /*
  156.91 -  fh = open(TPM_EMULATOR_PATH, O_RDONLY);
  156.92 -  stat_ret = fstat(fh, &file_stat);
  156.93 -  if (stat_ret == 0) 
  156.94 -    dmi_size = file_stat.st_size;
  156.95 -  else {
  156.96 -      vtpmlogerror(VTPM_LOG_VTPM, "Could not open tpm_emulator!!\n");
  156.97 -    status = TPM_IOERROR;
  156.98 -    goto abort_egress;
  156.99 -  }
 156.100 -  dmi_buffer
 156.101 -  */
 156.102 -  memset(&new_dmi->DMI_measurement, 0xcc, sizeof(TPM_DIGEST));
 156.103 -  
 156.104 -#ifndef VTPM_MULTI_VM
 156.105 -  if (dmi_id != VTPM_CTL_DM) {
 156.106 -    // Create a pair of fifo pipes
 156.107 -    if( (new_dmi->guest_tx_fname = (char *) malloc(11 + strlen(GUEST_TX_FIFO))) == NULL){ 
 156.108 -      status = TPM_RESOURCES;
 156.109 -      goto abort_egress;
 156.110 -    }
 156.111 -    sprintf(new_dmi->guest_tx_fname, GUEST_TX_FIFO, (uint32_t) dmi_id);
 156.112 -    
 156.113 -    if ((new_dmi->vtpm_tx_fname = (char *) malloc(11 + strlen(VTPM_TX_FIFO))) == NULL) {
 156.114 -      status = TPM_RESOURCES;
 156.115 -      goto abort_egress;
 156.116 -    }
 156.117 -    sprintf(new_dmi->vtpm_tx_fname, VTPM_TX_FIFO, (uint32_t) dmi_id);
 156.118 -    
 156.119 -    new_dmi->guest_tx_fh = -1;
 156.120 -    new_dmi->vtpm_tx_fh= -1;
 156.121 -    
 156.122 -    if ( stat(new_dmi->guest_tx_fname, &file_info) == -1) {
 156.123 -      if ( mkfifo(new_dmi->guest_tx_fname, S_IWUSR | S_IRUSR ) ){
 156.124 -	vtpmlogerror(VTPM_LOG_VTPM, "Failed to create dmi fifo.\n");
 156.125 -	status = TPM_IOERROR;
 156.126 -	goto abort_egress;
 156.127 -      }
 156.128 -    }
 156.129 -            
 156.130 -    if ( (fh = open(new_dmi->vtpm_tx_fname, O_RDWR)) == -1) {
 156.131 -      if ( mkfifo(new_dmi->vtpm_tx_fname, S_IWUSR | S_IRUSR ) ) {
 156.132 -	vtpmlogerror(VTPM_LOG_VTPM, "Failed to create dmi fifo.\n");
 156.133 -	status = TPM_IOERROR;
 156.134 -	goto abort_egress;
 156.135 -      }
 156.136 -    }
 156.137 -                
 156.138 -    // Launch DMI
 156.139 -    sprintf(dmi_id_str, "%d", (int) dmi_id);
 156.140 -#ifdef MANUAL_DM_LAUNCH
 156.141 -    vtpmlogerror(VTPM_LOG_VTPM, "FAKING starting vtpm with dmi=%s\n", dmi_id_str);
 156.142 -    new_dmi->dmi_pid = 0;
 156.143 -#else
 156.144 -    pid_t pid = fork();
 156.145 -    
 156.146 -    if (pid == -1) {
 156.147 -      vtpmlogerror(VTPM_LOG_VTPM, "Could not fork to launch vtpm\n");
 156.148 -      status = TPM_RESOURCES;
 156.149 -      goto abort_egress;
 156.150 -    } else if (pid == 0) {
 156.151 -      if ( stat(new_dmi->NVMLocation, &file_info) == -1)
 156.152 -	execl (TPM_EMULATOR_PATH, "vtmpd", "clear", dmi_id_str, NULL);
 156.153 -      else 
 156.154 -	execl (TPM_EMULATOR_PATH, "vtpmd", "save", dmi_id_str, NULL);
 156.155 -			
 156.156 -      // Returning from these at all is an error.
 156.157 -      vtpmlogerror(VTPM_LOG_VTPM, "Could not exec to launch vtpm\n");
 156.158 -    } else {
 156.159 -      new_dmi->dmi_pid = pid;
 156.160 -      vtpmloginfo(VTPM_LOG_VTPM, "Launching DMI on PID = %d\n", pid);
 156.161 -    }
 156.162 -#endif // MANUAL_DM_LAUNCH
 156.163 -  }
 156.164 -#else // VTPM_MUTLI_VM
 156.165 -  // FIXME: Measure DMI through call to Measurement agent in platform.
 156.166 -#endif 
 156.167 -	
 156.168 -  vtpm_globals->DMI_table_dirty = TRUE;
 156.169    new_dmi->connected = TRUE;  
 156.170 -  status=TPM_SUCCESS;
 156.171 +
 156.172 +  // Design specific new DMI code. 
 156.173 +  // Includes: create IPCs, Measuring DMI, and maybe launching DMI
 156.174 +  status = VTPM_New_DMI_Extra(new_dmi);
 156.175    goto egress;
 156.176    
 156.177   abort_egress:
 156.178    vtpmlogerror(VTPM_LOG_VTPM, "Failed to create DMI id=%d due to status=%s. Cleaning.\n", dmi_id, tpm_get_error_name(status));
 156.179 -  close_dmi( new_dmi );
 156.180 +  close_dmi(new_dmi );
 156.181  	
 156.182   egress:
 156.183    return status;
 156.184 @@ -293,7 +179,7 @@ TPM_RESULT VTPM_Handle_Close_DMI( const 
 156.185      goto abort_egress;
 156.186    }
 156.187  	
 156.188 -	if (!dmi_res->connected) {
 156.189 +  if (!dmi_res->connected) {
 156.190      vtpmlogerror(VTPM_LOG_VTPM, "Closing non-connected DMI.\n");
 156.191      status = TPM_BAD_PARAMETER;
 156.192      goto abort_egress;
   157.1 --- a/tools/vtpm_manager/manager/securestorage.c	Mon May 22 08:53:26 2006 -0600
   157.2 +++ b/tools/vtpm_manager/manager/securestorage.c	Mon May 22 14:13:38 2006 -0600
   157.3 @@ -197,9 +197,6 @@ TPM_RESULT VTPM_Handle_Save_NVM(VTPM_DMI
   157.4                                   &vtpm_globals->storageKey,
   157.5                                   &sealed_NVM) );
   157.6  				  
   157.7 -  // Mark DMI Table so new save state info will get pushed to disk on return.
   157.8 -  vtpm_globals->DMI_table_dirty = TRUE;
   157.9 -  
  157.10    // Write sealed blob off disk from NVMLocation
  157.11    // TODO: How to properly return from these. Do we care if we return failure
  157.12    //       after writing the file? We can't get the old one back.
  157.13 @@ -303,7 +300,7 @@ TPM_RESULT VTPM_Handle_Load_NVM(VTPM_DMI
  157.14  }
  157.15  
  157.16  
  157.17 -TPM_RESULT VTPM_SaveService(void) {
  157.18 +TPM_RESULT VTPM_SaveManagerData(void) {
  157.19    TPM_RESULT status=TPM_SUCCESS;
  157.20    int fh, dmis=-1;
  157.21  
  157.22 @@ -317,7 +314,7 @@ TPM_RESULT VTPM_SaveService(void) {
  157.23    struct hashtable_itr *dmi_itr;
  157.24    VTPM_DMI_RESOURCE *dmi_res;
  157.25  
  157.26 -  UINT32 boot_key_size, flat_dmis_size;
  157.27 +  UINT32 boot_key_size = 0, flat_dmis_size = 0;
  157.28  
  157.29    // Initially fill these with buffer sizes for each data type. Later fill
  157.30    // in actual size, once flattened.
  157.31 @@ -347,11 +344,11 @@ TPM_RESULT VTPM_SaveService(void) {
  157.32    BSG_PackConst(buffer_len(&enc_flat_global), 4, flat_enc);
  157.33  
  157.34    // Per DMI values to be saved (if any exit)
  157.35 -  if (hashtable_count(vtpm_globals->dmi_map) > 0) {
  157.36 +  if (hashtable_count(vtpm_globals->dmi_map) > 1) {
  157.37  
  157.38 -    flat_dmis_size = (hashtable_count(vtpm_globals->dmi_map) - 1) * // num DMIS (-1 for Dom0)
  157.39 -                     (sizeof(UINT32) + 2*sizeof(TPM_DIGEST)); // Per DMI info
  157.40 -    flat_dmis = (BYTE *) malloc( flat_dmis_size );
  157.41 +    flat_dmis = (BYTE *) malloc( 
  157.42 +                     (hashtable_count(vtpm_globals->dmi_map) - 1) * // num DMIS (-1 for Dom0)
  157.43 +                     (sizeof(UINT32) + 2*sizeof(TPM_DIGEST)) ); // Per DMI info
  157.44  
  157.45      dmi_itr = hashtable_iterator(vtpm_globals->dmi_map);
  157.46      do {
  157.47 @@ -387,8 +384,6 @@ TPM_RESULT VTPM_SaveService(void) {
  157.48      goto abort_egress;
  157.49   }
  157.50  
  157.51 -  vtpm_globals->DMI_table_dirty = FALSE;
  157.52 -
  157.53    goto egress;
  157.54  
  157.55   abort_egress:
  157.56 @@ -400,11 +395,11 @@ TPM_RESULT VTPM_SaveService(void) {
  157.57    free(flat_dmis);
  157.58    close(fh);
  157.59  
  157.60 -  vtpmloginfo(VTPM_LOG_VTPM, "Saved VTPM Service state (status = %d, dmis = %d)\n", (int) status, dmis);
  157.61 +  vtpmloginfo(VTPM_LOG_VTPM, "Saved VTPM Manager state (status = %d, dmis = %d)\n", (int) status, dmis);
  157.62    return status;
  157.63  }
  157.64  
  157.65 -TPM_RESULT VTPM_LoadService(void) {
  157.66 +TPM_RESULT VTPM_LoadManagerData(void) {
  157.67  
  157.68    TPM_RESULT status=TPM_SUCCESS;
  157.69    int fh, stat_ret, dmis=0;
   158.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   158.2 +++ b/tools/vtpm_manager/manager/vtpm_ipc.c	Mon May 22 14:13:38 2006 -0600
   158.3 @@ -0,0 +1,141 @@
   158.4 +// ===================================================================
   158.5 +// 
   158.6 +// Copyright (c) 2005, Intel Corp.
   158.7 +// All rights reserved.
   158.8 +//
   158.9 +// Redistribution and use in source and binary forms, with or without 
  158.10 +// modification, are permitted provided that the following conditions 
  158.11 +// are met:
  158.12 +//
  158.13 +//   * Redistributions of source code must retain the above copyright 
  158.14 +//     notice, this list of conditions and the following disclaimer.
  158.15 +//   * Redistributions in binary form must reproduce the above 
  158.16 +//     copyright notice, this list of conditions and the following 
  158.17 +//     disclaimer in the documentation and/or other materials provided 
  158.18 +//     with the distribution.
  158.19 +//   * Neither the name of Intel Corporation nor the names of its 
  158.20 +//     contributors may be used to endorse or promote products derived
  158.21 +//     from this software without specific prior written permission.
  158.22 +//
  158.23 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  158.24 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  158.25 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  158.26 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  158.27 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  158.28 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  158.29 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  158.30 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  158.31 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  158.32 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  158.33 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  158.34 +// OF THE POSSIBILITY OF SUCH DAMAGE.
  158.35 +// ===================================================================
  158.36 +//
  158.37 +// vtpm_ipc.c Implements ipc routines using file io. This file can
  158.38 +// be replaced with other ipc types.
  158.39 +//
  158.40 +// ===================================================================
  158.41 +
  158.42 +#include <sys/stat.h>
  158.43 +#include "vtpm_ipc.h"
  158.44 +#include "vtpmpriv.h"
  158.45 +#include "log.h"
  158.46 +
  158.47 +int vtpm_ipc_init(vtpm_ipc_handle_t *ipc_h, char* name, int flags, BOOL create) {
  158.48 +  ipc_h->name = name;
  158.49 +  ipc_h->flags = flags;
  158.50 +  ipc_h->fh = VTPM_IPC_CLOSED;
  158.51 +
  158.52 +  if (create)
  158.53 +    return(vtpm_ipc_create(ipc_h));
  158.54 +  else
  158.55 +    return 0;
  158.56 +}
  158.57 +
  158.58 +// Create the file that needs opening. Used only for FIFOs
  158.59 +// FYI: This may cause problems in other file IO schemes. We'll see.
  158.60 +int vtpm_ipc_create(vtpm_ipc_handle_t *ipc_h) {
  158.61 +  int fh;
  158.62 +  struct stat file_info;
  158.63 +
  158.64 +  if ((!ipc_h) || (!ipc_h->name))
  158.65 +    return -1;
  158.66 +
  158.67 +  if ( stat(ipc_h->name, &file_info) == -1) {
  158.68 +    if ( mkfifo(ipc_h->name, S_IWUSR | S_IRUSR ) ) {
  158.69 +      vtpmlogerror(VTPM_LOG_VTPM, "Failed to create fifo %s.\n", ipc_h->name);
  158.70 +      return -1;
  158.71 +    }
  158.72 +  }
  158.73 +
  158.74 +  ipc_h->fh = VTPM_IPC_CLOSED;
  158.75 +
  158.76 +  return 0;
  158.77 +}
  158.78 +
  158.79 +
  158.80 +// Read size bytes. If FH isn't open, open it.
  158.81 +int vtpm_ipc_read(vtpm_ipc_handle_t *ipc_h, vtpm_ipc_handle_t *alt_ipc_h, BYTE *bytes, UINT32 size){
  158.82 +  vtpm_ipc_handle_t *my_ipc_h;
  158.83 +  int result;
  158.84 +  
  158.85 +  if (ipc_h) {
  158.86 +    my_ipc_h = ipc_h;
  158.87 +  } else {
  158.88 +    my_ipc_h = alt_ipc_h;
  158.89 +  }
  158.90 +  
  158.91 +  if (my_ipc_h->fh == VTPM_IPC_CLOSED) {   
  158.92 +    my_ipc_h->fh = open(my_ipc_h->name, my_ipc_h->flags);
  158.93 +  }
  158.94 +
  158.95 +  if ( my_ipc_h->fh == VTPM_IPC_CLOSED ) {
  158.96 +    vtpmlogerror(VTPM_LOG_VTPM, "VTPM ERROR: Can't open %s for reading.\n", my_ipc_h->name);
  158.97 +    return -1;
  158.98 +  }
  158.99 +
 158.100 +  result = read(my_ipc_h->fh, bytes, size);
 158.101 +  if (result < 0) {
 158.102 +    my_ipc_h->fh = VTPM_IPC_CLOSED;
 158.103 +  }
 158.104 +
 158.105 +  return (result);
 158.106 +}
 158.107 +
 158.108 +// Write size bytes. If FH isn't open, open it.
 158.109 +int vtpm_ipc_write(vtpm_ipc_handle_t *ipc_h, vtpm_ipc_handle_t *alt_ipc_h, BYTE *bytes, UINT32 size) {
 158.110 +  vtpm_ipc_handle_t *my_ipc_h;
 158.111 +  int result;
 158.112 +
 158.113 +  if (ipc_h) {
 158.114 +    my_ipc_h = ipc_h;
 158.115 +  } else {
 158.116 +    my_ipc_h = alt_ipc_h;
 158.117 +  }
 158.118 +
 158.119 +  if (my_ipc_h->fh == VTPM_IPC_CLOSED) {
 158.120 +    my_ipc_h->fh = open(my_ipc_h->name, my_ipc_h->flags);
 158.121 +  }
 158.122 +
 158.123 +  if ( my_ipc_h->fh == VTPM_IPC_CLOSED ) {
 158.124 +    vtpmlogerror(VTPM_LOG_VTPM, "VTPM ERROR: Can't open %s for writing.\n", my_ipc_h->name);
 158.125 +    return -1;
 158.126 +  }
 158.127 +
 158.128 +  result = write(my_ipc_h->fh, bytes, size);
 158.129 +  if (result < 0) {
 158.130 +    my_ipc_h->fh = VTPM_IPC_CLOSED;
 158.131 +  }
 158.132 +
 158.133 +  return (result);
 158.134 +}
 158.135 +
 158.136 +// Mark file as closed and try and close it. Errors not reported.
 158.137 +void vtpm_ipc_close(vtpm_ipc_handle_t *ipc_h) {
 158.138 +
 158.139 +  if (ipc_h) {
 158.140 +    close(ipc_h->fh);
 158.141 +  }
 158.142 +  ipc_h->fh = VTPM_IPC_CLOSED;
 158.143 +
 158.144 +}
   159.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   159.2 +++ b/tools/vtpm_manager/manager/vtpm_ipc.h	Mon May 22 14:13:38 2006 -0600
   159.3 @@ -0,0 +1,71 @@
   159.4 +// ===================================================================
   159.5 +//
   159.6 +// Copyright (c) 2005, Intel Corp.
   159.7 +// All rights reserved.
   159.8 +//
   159.9 +// Redistribution and use in source and binary forms, with or without
  159.10 +// modification, are permitted provided that the following conditions
  159.11 +// are met:
  159.12 +//
  159.13 +//   * Redistributions of source code must retain the above copyright
  159.14 +//     notice, this list of conditions and the following disclaimer.
  159.15 +//   * Redistributions in binary form must reproduce the above
  159.16 +//     copyright notice, this list of conditions and the following
  159.17 +//     disclaimer in the documentation and/or other materials provided
  159.18 +//     with the distribution.
  159.19 +//   * Neither the name of Intel Corporation nor the names of its
  159.20 +//     contributors may be used to endorse or promote products derived
  159.21 +//     from this software without specific prior written permission.
  159.22 +//
  159.23 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  159.24 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  159.25 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  159.26 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  159.27 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  159.28 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  159.29 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  159.30 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  159.31 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  159.32 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  159.33 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  159.34 +// OF THE POSSIBILITY OF SUCH DAMAGE.
  159.35 +// ===================================================================
  159.36 +//
  159.37 +// vtpm_ipc.h Header for interprocess communication between VTPM manager
  159.38 +// and Guests or VTPMs
  159.39 +//
  159.40 +// ===================================================================
  159.41 +
  159.42 +#ifndef __VTPM_IO_H__
  159.43 +#define __VTPM_IO_H__
  159.44 +
  159.45 +#include "tcg.h"
  159.46 +
  159.47 +#define VTPM_IPC_CLOSED -1
  159.48 +
  159.49 +// Represents an (somewhat) abstracted io handle.
  159.50 +typedef struct vtpm_ipc_handle_t {
  159.51 +  int fh;              // IO handle.
  159.52 +  int flags;           // Flags for opening. This may need to become
  159.53 +                       // a void *, but for now files use an int.
  159.54 +  char *name;          // Names for debugging as well as filenames
  159.55 +                       // for file-based io.
  159.56 +} vtpm_ipc_handle_t;
  159.57 +
  159.58 +
  159.59 +int vtpm_ipc_init(vtpm_ipc_handle_t *ioh, char* name, int flags, BOOL create);
  159.60 +
  159.61 +// Create the file that needs opening. Used only for FIFOs
  159.62 +// FYI: This may cause problems in other file IO schemes. We'll see.
  159.63 +int vtpm_ipc_create(vtpm_ipc_handle_t *ioh);
  159.64 +
  159.65 +// Read size bytes. If FH isn't open, open it.
  159.66 +int vtpm_ipc_read(vtpm_ipc_handle_t *ioh, vtpm_ipc_handle_t *alt_ioh, BYTE *bytes, UINT32 size);
  159.67 +
  159.68 +// Write size bytes. If FH isn't open, open it.
  159.69 +int vtpm_ipc_write(vtpm_ipc_handle_t *ioh, vtpm_ipc_handle_t *alt_ioh, BYTE *bytes, UINT32 size);
  159.70 +
  159.71 +// Mark file as closed and try and close it. Errors not reported.
  159.72 +void vtpm_ipc_close(vtpm_ipc_handle_t *ioh);
  159.73 +
  159.74 +#endif
   160.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   160.2 +++ b/tools/vtpm_manager/manager/vtpm_lock.c	Mon May 22 14:13:38 2006 -0600
   160.3 @@ -0,0 +1,63 @@
   160.4 +// ===================================================================
   160.5 +//
   160.6 +// Copyright (c) 2005, Intel Corp.
   160.7 +// All rights reserved.
   160.8 +//
   160.9 +// Redistribution and use in source and binary forms, with or without
  160.10 +// modification, are permitted provided that the following conditions
  160.11 +// are met:
  160.12 +//
  160.13 +//   * Redistributions of source code must retain the above copyright
  160.14 +//     notice, this list of conditions and the following disclaimer.
  160.15 +//   * Redistributions in binary form must reproduce the above
  160.16 +//     copyright notice, this list of conditions and the following
  160.17 +//     disclaimer in the documentation and/or other materials provided
  160.18 +//     with the distribution.
  160.19 +//   * Neither the name of Intel Corporation nor the names of its
  160.20 +//     contributors may be used to endorse or promote products derived
  160.21 +//     from this software without specific prior written permission.
  160.22 +//
  160.23 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  160.24 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  160.25 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  160.26 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  160.27 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  160.28 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  160.29 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  160.30 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  160.31 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  160.32 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  160.33 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  160.34 +// OF THE POSSIBILITY OF SUCH DAMAGE.
  160.35 +// ===================================================================
  160.36 +//
  160.37 +// vtpm_lock.c Provided controlled sync around access to vtpm structures
  160.38 +//
  160.39 +// ===================================================================
  160.40 +
  160.41 +#include <pthread.h>
  160.42 +#include "vtpm_lock.h"
  160.43 +
  160.44 +static pthread_rwlock_t vtpm_lock;
  160.45 +
  160.46 +void vtpm_lock_init() {
  160.47 +
  160.48 +  pthread_rwlock_init( &vtpm_lock, NULL);
  160.49 +}
  160.50 +
  160.51 +void vtpm_lock_destroy(){
  160.52 +  pthread_rwlock_destroy(&vtpm_lock);
  160.53 +}
  160.54 +
  160.55 +void vtpm_lock_rdlock(){
  160.56 +  pthread_rwlock_rdlock(&vtpm_lock);
  160.57 +}
  160.58 +
  160.59 +void vtpm_lock_wrlock(){
  160.60 +  pthread_rwlock_wrlock(&vtpm_lock);
  160.61 +}
  160.62 +
  160.63 +void vtpm_lock_unlock(){
  160.64 +  pthread_rwlock_unlock(&vtpm_lock);
  160.65 +}
  160.66 +
   161.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   161.2 +++ b/tools/vtpm_manager/manager/vtpm_lock.h	Mon May 22 14:13:38 2006 -0600
   161.3 @@ -0,0 +1,48 @@
   161.4 +// ===================================================================
   161.5 +//
   161.6 +// Copyright (c) 2005, Intel Corp.
   161.7 +// All rights reserved.
   161.8 +//
   161.9 +// Redistribution and use in source and binary forms, with or without
  161.10 +// modification, are permitted provided that the following conditions
  161.11 +// are met:
  161.12 +//
  161.13 +//   * Redistributions of source code must retain the above copyright
  161.14 +//     notice, this list of conditions and the following disclaimer.
  161.15 +//   * Redistributions in binary form must reproduce the above
  161.16 +//     copyright notice, this list of conditions and the following
  161.17 +//     disclaimer in the documentation and/or other materials provided
  161.18 +//     with the distribution.
  161.19 +//   * Neither the name of Intel Corporation nor the names of its
  161.20 +//     contributors may be used to endorse or promote products derived
  161.21 +//     from this software without specific prior written permission.
  161.22 +//
  161.23 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  161.24 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  161.25 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  161.26 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  161.27 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  161.28 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  161.29 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  161.30 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  161.31 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  161.32 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  161.33 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  161.34 +// OF THE POSSIBILITY OF SUCH DAMAGE.
  161.35 +// ===================================================================
  161.36 +//
  161.37 +// vtpm_lock.h Provided controlled sync around access to vtpm structures
  161.38 +//
  161.39 +// ===================================================================
  161.40 +
  161.41 +#ifndef __VTPM_LOCK_H__
  161.42 +#define __VTPM_LOCK_H__
  161.43 +
  161.44 +void vtpm_lock_init();
  161.45 +void vtpm_lock_destroy();
  161.46 +
  161.47 +void vtpm_lock_rdlock();
  161.48 +void vtpm_lock_wrlock();
  161.49 +void vtpm_lock_unlock();
  161.50 +
  161.51 +#endif
   162.1 --- a/tools/vtpm_manager/manager/vtpm_manager.c	Mon May 22 08:53:26 2006 -0600
   162.2 +++ b/tools/vtpm_manager/manager/vtpm_manager.c	Mon May 22 14:13:38 2006 -0600
   162.3 @@ -39,18 +39,8 @@
   162.4  
   162.5  #include <stdio.h>
   162.6  #include <unistd.h>
   162.7 -#include <sys/types.h>
   162.8 -#include <sys/stat.h>
   162.9 -#include <fcntl.h>
  162.10  #include <string.h>
  162.11  
  162.12 -#ifndef VTPM_MULTI_VM
  162.13 -#include <pthread.h>
  162.14 -#include <errno.h>
  162.15 -#include <aio.h>
  162.16 -#include <time.h>
  162.17 -#endif
  162.18 -
  162.19  #include "vtpm_manager.h"
  162.20  #include "vtpmpriv.h"
  162.21  #include "vtsp.h"
  162.22 @@ -63,16 +53,6 @@
  162.23  
  162.24  VTPM_GLOBALS *vtpm_globals=NULL;
  162.25  
  162.26 -#ifdef VTPM_MULTI_VM
  162.27 - #define vtpmhandlerloginfo(module,fmt,args...) vtpmloginfo (module, fmt, ##args );
  162.28 - #define vtpmhandlerloginfomore(module,fmt,args...) vtpmloginfomore (module, fmt, ##args );
  162.29 - #define vtpmhandlerlogerror(module,fmt,args...) vtpmlogerror (module, fmt, ##args );
  162.30 -#else 
  162.31 - #define vtpmhandlerloginfo(module,fmt,args...) vtpmloginfo (module, "[%d]: " fmt, threadType, ##args );
  162.32 - #define vtpmhandlerloginfomore(module,fmt,args...) vtpmloginfomore (module, fmt, ##args );
  162.33 - #define vtpmhandlerlogerror(module,fmt,args...) vtpmlogerror (module, "[%d]: " fmt, threadType, ##args );
  162.34 -#endif
  162.35 -
  162.36  // --------------------------- Well Known Auths --------------------------
  162.37  const TPM_AUTHDATA SRK_AUTH = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  162.38                                    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  162.39 @@ -95,7 +75,7 @@ static int equals32(void *k1, void *k2) 
  162.40  
  162.41  // --------------------------- Functions ------------------------------
  162.42  
  162.43 -TPM_RESULT VTPM_Create_Service(){
  162.44 +TPM_RESULT VTPM_Create_Manager(){
  162.45    
  162.46    TPM_RESULT status = TPM_SUCCESS;
  162.47    
  162.48 @@ -184,562 +164,21 @@ TPM_RESULT VTPM_Create_Service(){
  162.49                                NULL,
  162.50                                &vtpm_globals->bootKey,
  162.51                                TRUE ) );
  162.52 +
  162.53 +  printf("***************************** FIXME: SAVE NEW STATE *******\n");
  162.54    goto egress;
  162.55    
  162.56   abort_egress:
  162.57    exit(1);
  162.58    
  162.59   egress:
  162.60 -  vtpmloginfo(VTPM_LOG_VTPM, "Finished initialized new VTPM service (Status = %d).\n", status);
  162.61 +  vtpmloginfo(VTPM_LOG_VTPM, "Finished initialized new VTPM manager (Status = %d).\n", status);
  162.62    return status;
  162.63    
  162.64  }
  162.65  
  162.66 -
  162.67 -//////////////////////////////////////////////////////////////////////////////
  162.68 -#ifdef VTPM_MULTI_VM
  162.69 -int VTPM_Service_Handler(){
  162.70 -#else
  162.71 -void *VTPM_Service_Handler(void *threadTypePtr){
  162.72 -#endif
  162.73 -  TPM_RESULT      status =  TPM_FAIL; // Should never return
  162.74 -  UINT32          dmi, in_param_size, cmd_size, out_param_size, out_message_size, out_message_size_full;
  162.75 -  BYTE            *cmd_header, *in_param, *out_message;
  162.76 -  buffer_t        *command_buf=NULL, *result_buf=NULL;
  162.77 -  TPM_TAG         tag;
  162.78 -  TPM_COMMAND_CODE ord;
  162.79 -  VTPM_DMI_RESOURCE *dmi_res;
  162.80 -  int  size_read, size_write, i;
  162.81 -  
  162.82 -#ifndef VTPM_MULTI_VM
  162.83 -  UINT32 dmi_cmd_size;
  162.84 -  BYTE *dmi_cmd;
  162.85 -  int threadType = *(int *) threadTypePtr;
  162.86 -  
  162.87 -  // async io structures
  162.88 -  struct aiocb dmi_aio;
  162.89 -  struct aiocb *dmi_aio_a[1];
  162.90 -  dmi_aio_a[0] = &dmi_aio;
  162.91 -#endif
  162.92 -  
  162.93 -#ifdef DUMMY_BACKEND
  162.94 -  int dummy_rx;  
  162.95 -#endif
  162.96 -  
  162.97 -  cmd_header = (BYTE *) malloc(VTPM_COMMAND_HEADER_SIZE_SRV);
  162.98 -  command_buf = (buffer_t *) malloc(sizeof(buffer_t));
  162.99 -  result_buf = (buffer_t *) malloc(sizeof(buffer_t));
 162.100 -  
 162.101 -#ifndef VTPM_MULTI_VM
 162.102 -  TPM_RESULT *ret_value = (TPM_RESULT *) malloc(sizeof(TPM_RESULT));
 162.103 -#endif
 162.104 -  
 162.105 -  int *tx_fh, // Pointer to the filehandle this function will write to
 162.106 -      *rx_fh; // Pointer to the filehandle this function will read from
 162.107 -              // For a multi VM VTPM system, this function tx/rx with the BE
 162.108 -              //   via vtpm_globals->be_fh.
 162.109 -              // For a single VM system, the BE_LISTENER_THREAD tx/rx with theBE
 162.110 -              //   via vtpm_globals->be_fh, and the DMI_LISTENER_THREAD rx from
 162.111 -	      //   vtpm_globals->vtpm_rx_fh and tx to dmi_res->vtpm_tx_fh
 162.112 -
 162.113 -  // Set rx_fh to point to the correct fh based on this mode.
 162.114 -#ifdef VTPM_MULTI_VM
 162.115 -  rx_fh = &vtpm_globals->be_fh;
 162.116 -#else
 162.117 -  if (threadType == BE_LISTENER_THREAD) {
 162.118 - #ifdef DUMMY_BACKEND    
 162.119 -    dummy_rx = -1;
 162.120 -    rx_fh = &dummy_rx;
 162.121 - #else
 162.122 -    rx_fh = &vtpm_globals->be_fh;
 162.123 - #endif
 162.124 -  } else { // DMI_LISTENER_THREAD
 162.125 -    rx_fh = &vtpm_globals->vtpm_rx_fh;
 162.126 -  }
 162.127 -#endif
 162.128 -  
 162.129 -  // Set tx_fh to point to the correct fh based on this mode (If static)
 162.130 -  // Create any fifos that these fh will use.  
 162.131 -#ifndef VTPM_MULTI_VM
 162.132 -  int fh;
 162.133 -  if (threadType == BE_LISTENER_THREAD) {
 162.134 -    tx_fh = &vtpm_globals->be_fh;
 162.135 -    if ( (fh = open(GUEST_RX_FIFO, O_RDWR)) == -1) {
 162.136 -      if ( mkfifo(GUEST_RX_FIFO, S_IWUSR | S_IRUSR ) ){
 162.137 -        vtpmlogerror(VTPM_LOG_VTPM, "Unable to create FIFO: %s.\n", GUEST_RX_FIFO);        
 162.138 -	*ret_value = TPM_FAIL;
 162.139 -	pthread_exit(ret_value);
 162.140 -      }
 162.141 -    } else 
 162.142 -      close(fh);
 162.143 -    
 162.144 -  } else { // else DMI_LISTENER_THREAD
 162.145 -    // tx_fh will be set once the DMI is identified
 162.146 -    // But we need to make sure the read pip is created.
 162.147 -    if ( (fh = open(VTPM_RX_FIFO, O_RDWR)) == -1) {
 162.148 -      if ( mkfifo(VTPM_RX_FIFO, S_IWUSR | S_IRUSR ) ){
 162.149 -        vtpmlogerror(VTPM_LOG_VTPM, "Unable to create FIFO: %s.\n", VTPM_RX_FIFO);
 162.150 -	*ret_value = TPM_FAIL;
 162.151 -	pthread_exit(ret_value);
 162.152 -      }
 162.153 -    } else 
 162.154 -      close(fh);
 162.155 -    
 162.156 -  }
 162.157 -#else
 162.158 -  tx_fh = &vtpm_globals->be_fh;
 162.159 -#endif
 162.160 -  
 162.161 -  ////////////////////////// Main Loop //////////////////////////////////
 162.162 -  while(1) {
 162.163 -    
 162.164 -#ifdef VTPM_MULTI_VM
 162.165 -    vtpmhandlerloginfo(VTPM_LOG_VTPM, "Waiting for DMI messages.\n");
 162.166 -#else
 162.167 -    if (threadType == BE_LISTENER_THREAD) {
 162.168 -      vtpmhandlerloginfo(VTPM_LOG_VTPM, "Waiting for Guest requests & ctrl messages.\n");
 162.169 -    } else    
 162.170 -      vtpmhandlerloginfo(VTPM_LOG_VTPM, "Waiting for DMI messages.\n");
 162.171 -#endif
 162.172 -
 162.173 -    // Check status of rx_fh. If necessary attempt to re-open it.    
 162.174 -    char* s = NULL;
 162.175 -    if (*rx_fh < 0) {
 162.176 -#ifdef VTPM_MULTI_VM
 162.177 -      s = VTPM_BE_DEV;
 162.178 -#else
 162.179 -      if (threadType == BE_LISTENER_THREAD) 
 162.180 -  #ifdef DUMMY_BACKEND
 162.181 -	s = "/tmp/in.fifo";
 162.182 -  #else
 162.183 -      s = VTPM_BE_DEV;
 162.184 -  #endif
 162.185 -      else  // DMI Listener   
 162.186 -	s = VTPM_RX_FIFO;
 162.187 -      *rx_fh = open(s, O_RDWR);
 162.188 -#endif    
 162.189 -    }
 162.190 -    
 162.191 -    // Respond to failures to open rx_fh
 162.192 -    if (*rx_fh < 0) {
 162.193 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Can't open inbound fh for %s.\n", s);
 162.194 -#ifdef VTPM_MULTI_VM
 162.195 -      return TPM_IOERROR; 
 162.196 -#else
 162.197 -      *ret_value = TPM_IOERROR;
 162.198 -      pthread_exit(ret_value);
 162.199 -#endif
 162.200 -    }
 162.201 -    
 162.202 -    // Read command header from rx_fh
 162.203 -    size_read = read(*rx_fh, cmd_header, VTPM_COMMAND_HEADER_SIZE_SRV);
 162.204 -    if (size_read > 0) {
 162.205 -      vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "RECV[%d}: 0x", size_read);
 162.206 -      for (i=0; i<size_read; i++) 
 162.207 -		vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", cmd_header[i]);
 162.208 -    } else {
 162.209 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Can't read from BE. Aborting... \n");
 162.210 -      close(*rx_fh);
 162.211 -      *rx_fh = -1;
 162.212 -      goto abort_command;
 162.213 -    }
 162.214 -
 162.215 -    if (size_read < (int) VTPM_COMMAND_HEADER_SIZE_SRV) {
 162.216 -      vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "\n");
 162.217 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Command shorter than normal header (%d bytes). Aborting...\n", size_read);
 162.218 -      goto abort_command;
 162.219 -    }
 162.220 -    
 162.221 -    // Unpack header
 162.222 -    BSG_UnpackList(cmd_header, 4,
 162.223 -		   BSG_TYPE_UINT32, &dmi,
 162.224 -		   BSG_TPM_TAG, &tag,
 162.225 -		   BSG_TYPE_UINT32, &in_param_size,
 162.226 -		   BSG_TPM_COMMAND_CODE, &ord );
 162.227 -    
 162.228 -    // Using the header info, read from rx_fh the parameters of the command
 162.229 -    // Note that in_param_size is in the client's context
 162.230 -    cmd_size = in_param_size - VTPM_COMMAND_HEADER_SIZE_CLT;
 162.231 -    if (cmd_size > 0) {
 162.232 -      in_param = (BYTE *) malloc(cmd_size);
 162.233 -      size_read = read( *rx_fh, in_param, cmd_size);
 162.234 -      if (size_read > 0) {
 162.235 -	for (i=0; i<size_read; i++) 
 162.236 -	  vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", in_param[i]);
 162.237 -	
 162.238 -      } else {
 162.239 -        vtpmhandlerlogerror(VTPM_LOG_VTPM, "Error reading from cmd. Aborting... \n");
 162.240 -	close(*rx_fh);
 162.241 -	*rx_fh = -1;
 162.242 -	goto abort_command;
 162.243 -      }
 162.244 -      vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "\n");
 162.245 -      
 162.246 -      if (size_read < (int) cmd_size) {
 162.247 -	vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "\n");
 162.248 -	vtpmhandlerlogerror(VTPM_LOG_VTPM, "Command read(%d) is shorter than header indicates(%d). Aborting...\n", size_read, cmd_size);
 162.249 -	goto abort_command;
 162.250 -      }
 162.251 -    } else {
 162.252 -      in_param = NULL;
 162.253 -      vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "\n");
 162.254 -    }            
 162.255 -
 162.256 -#ifndef VTPM_MULTI_VM
 162.257 -    // It's illegal to receive a Dom0 command from a DMI.
 162.258 -    if ((threadType != BE_LISTENER_THREAD) && (dmi == 0)) {
 162.259 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Attempt to access dom0 commands from DMI interface. Aborting...\n");
 162.260 -      goto abort_command;
 162.261 -    }
 162.262 -#endif
 162.263 -    
 162.264 -    // Fetch infomation about the DMI issuing the request.
 162.265 -    dmi_res = (VTPM_DMI_RESOURCE *) hashtable_search(vtpm_globals->dmi_map, &dmi);
 162.266 -    if (dmi_res == NULL) {
 162.267 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Attempted access to non-existent DMI in domain: %d. Aborting...\n", dmi);
 162.268 -      goto abort_command;
 162.269 -    }
 162.270 -    if (!dmi_res->connected) {
 162.271 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Attempted access to disconnected DMI in domain: %d. Aborting...\n", dmi);
 162.272 -      goto abort_command;
 162.273 -    }
 162.274 -
 162.275 -#ifndef VTPM_MULTI_VM
 162.276 -    // Now that we know which DMI this is, we can set the tx_fh handle.
 162.277 -    if (threadType != BE_LISTENER_THREAD) 
 162.278 -      tx_fh = &dmi_res->vtpm_tx_fh;
 162.279 -    // else we set this before the while loop since it doesn't change.
 162.280 -#endif 
 162.281 -   
 162.282 -    // Init the buffers used to handle the command and the response
 162.283 -    if ( (buffer_init_convert(command_buf, cmd_size, in_param) != TPM_SUCCESS) || 
 162.284 -	 (buffer_init(result_buf, 0, 0) != TPM_SUCCESS) ) {
 162.285 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Failed to setup buffers. Aborting...\n");
 162.286 -      goto abort_command;
 162.287 -    }
 162.288 -    
 162.289 -    // Dispatch it as either control or user request.
 162.290 -    if (tag == VTPM_TAG_REQ) { 
 162.291 -      if (dmi_res->dmi_id == VTPM_CTL_DM){ 
 162.292 -	switch (ord) {
 162.293 -	case VTPM_ORD_OPEN:
 162.294 -	  status = VTPM_Handle_New_DMI(command_buf);
 162.295 -	  break;
 162.296 -          
 162.297 -	case VTPM_ORD_CLOSE:
 162.298 -	  status = VTPM_Handle_Close_DMI(command_buf);
 162.299 -	  break;
 162.300 -          
 162.301 -	case VTPM_ORD_DELETE:
 162.302 -	  status = VTPM_Handle_Delete_DMI(command_buf);
 162.303 -	  break;
 162.304 -	default:
 162.305 -	  status = TPM_BAD_ORDINAL; 
 162.306 -	} // switch
 162.307 -      } else {
 162.308 -	
 162.309 -	switch (ord) {                
 162.310 -	case VTPM_ORD_SAVENVM:
 162.311 -	  status= VTPM_Handle_Save_NVM(dmi_res,
 162.312 -				       command_buf, 
 162.313 -				       result_buf);
 162.314 -	  break;
 162.315 -	case VTPM_ORD_LOADNVM:
 162.316 -	  status= VTPM_Handle_Load_NVM(dmi_res, 
 162.317 -				       command_buf, 
 162.318 -				       result_buf);
 162.319 -	  break;
 162.320 -	  
 162.321 -	case VTPM_ORD_TPMCOMMAND:
 162.322 -	  status= VTPM_Handle_TPM_Command(dmi_res, 
 162.323 -					  command_buf, 
 162.324 -					  result_buf);
 162.325 -	  break;
 162.326 -	  
 162.327 -	default:
 162.328 -	  status = TPM_BAD_ORDINAL; 
 162.329 -	} // switch
 162.330 -      }
 162.331 -    } else { // This is not a VTPM Command at all.
 162.332 -	     // This happens in two cases. 
 162.333 -	     // MULTI_VM = A DMI illegally sent a raw TPM command to the manager
 162.334 -	     // Single VM:
 162.335 -	     //   BE_LISTENER_THREAD: Guest issued a TPM command.
 162.336 -	     //                       Send this to DMI and wait for response
 162.337 -	     //   DMI_LISTENER_THREAD: A DMI illegally sent a raw TPM command.
 162.338 -    
 162.339 -#ifdef VTPM_MULTI_VM
 162.340 -      // Raw TPM commands are not supported from the DMI
 162.341 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Attempt to use unsupported direct access to TPM.\n");
 162.342 -      vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "Bad Command. dmi:%d, tag:%d, size:%d, ord:%d, Params: ", dmi, tag, in_param_size, ord);
 162.343 -      for (i=0; i<cmd_size; i++) 
 162.344 -	vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", in_param[i]);
 162.345 -      
 162.346 -      vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "\n");
 162.347 -      status = TPM_FAIL;
 162.348 -    
 162.349 -#else
 162.350 -      // If BE_LISTENER_THREAD then this is a TPM command from a guest
 162.351 -      if (threadType == BE_LISTENER_THREAD) {
 162.352 -	// Dom0 can't talk to the BE, so this must be a broken FE/BE or badness
 162.353 -	if (dmi == 0) {
 162.354 -	  vtpmhandlerlogerror(VTPM_LOG_VTPM, "Illegal use of TPM command from dom0\n");
 162.355 -	  status = TPM_FAIL;
 162.356 -	} else {
 162.357 -	  vtpmhandlerloginfo(VTPM_LOG_VTPM, "Forwarding command to DMI.\n");
 162.358 -	  
 162.359 -	  // open the dmi_res->guest_tx_fh to send command to DMI
 162.360 -	  if (dmi_res->guest_tx_fh < 0)
 162.361 -	    dmi_res->guest_tx_fh = open(dmi_res->guest_tx_fname, O_WRONLY | O_NONBLOCK);
 162.362 -
 162.363 -	  // handle failed opens dmi_res->guest_tx_fh        
 162.364 -	  if (dmi_res->guest_tx_fh < 0){
 162.365 -	    vtpmhandlerlogerror(VTPM_LOG_VTPM, "VTPM ERROR: Can't open outbound fh to dmi.\n");
 162.366 -	    status = TPM_IOERROR;
 162.367 -	    goto abort_with_error;
 162.368 -	  }        
 162.369 -          
 162.370 -	  //Forward TPM CMD stamped with dmi_id to DMI for handling
 162.371 -	  if (cmd_size) {
 162.372 -	    dmi_cmd = (BYTE *) malloc(VTPM_COMMAND_HEADER_SIZE_SRV + cmd_size);
 162.373 -	    dmi_cmd_size = VTPM_COMMAND_HEADER_SIZE_SRV + cmd_size;
 162.374 -	    memcpy(dmi_cmd, cmd_header, VTPM_COMMAND_HEADER_SIZE_SRV);
 162.375 -	    memcpy(dmi_cmd + VTPM_COMMAND_HEADER_SIZE_SRV, in_param, cmd_size);
 162.376 -	    size_write = write(dmi_res->guest_tx_fh, dmi_cmd, dmi_cmd_size);
 162.377 -	    
 162.378 -	    if (size_write > 0) {
 162.379 -	      vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "SENT (DMI): 0x");
 162.380 -	      for (i=0; i<VTPM_COMMAND_HEADER_SIZE_SRV + cmd_size; i++) {
 162.381 -		vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", dmi_cmd[i]);
 162.382 -	      }
 162.383 -	      vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "\n");
 162.384 -	    } else {
 162.385 -              vtpmhandlerlogerror(VTPM_LOG_VTPM, "Error writing to DMI. Aborting... \n");
 162.386 -	      close(dmi_res->guest_tx_fh);
 162.387 -	      dmi_res->guest_tx_fh = -1;
 162.388 -              status = TPM_IOERROR;
 162.389 -	      goto abort_with_error;
 162.390 -	    }
 162.391 -	    free(dmi_cmd);
 162.392 -	  } else {
 162.393 -	    dmi_cmd_size = VTPM_COMMAND_HEADER_SIZE_SRV;
 162.394 -	    size_write = write(dmi_res->guest_tx_fh, cmd_header, VTPM_COMMAND_HEADER_SIZE_SRV );
 162.395 -	    if (size_write > 0) {
 162.396 -	      for (i=0; i<VTPM_COMMAND_HEADER_SIZE_SRV; i++) 
 162.397 -		vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", cmd_header[i]);
 162.398 -	      
 162.399 -	      vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "\n");
 162.400 -	    } else {
 162.401 -              vtpmhandlerlogerror(VTPM_LOG_VTPM, "Error writing to DMI. Aborting... \n");
 162.402 -	      close(dmi_res->guest_tx_fh);
 162.403 -	      dmi_res->guest_tx_fh = -1;
 162.404 -              status = TPM_IOERROR;
 162.405 -	      goto abort_with_error;
 162.406 -	    }
 162.407 -	  }
 162.408 -         
 162.409 -	  if (size_write != (int) dmi_cmd_size) 
 162.410 -	    vtpmhandlerlogerror(VTPM_LOG_VTPM, "Could not write entire command to DMI (%d/%d)\n", size_write, dmi_cmd_size);
 162.411 -	  buffer_free(command_buf);
 162.412 -	 
 162.413 -	  // Open vtpm_globals->guest_rx_fh to receive DMI response	  
 162.414 -	  if (vtpm_globals->guest_rx_fh < 0) 
 162.415 -	    vtpm_globals->guest_rx_fh = open(GUEST_RX_FIFO, O_RDONLY);
 162.416 -          
 162.417 -	  // Handle open failures
 162.418 -	  if (vtpm_globals->guest_rx_fh < 0){
 162.419 -	    vtpmhandlerlogerror(VTPM_LOG_VTPM, "Can't open inbound fh to dmi.\n");
 162.420 -            status = TPM_IOERROR;
 162.421 -	    goto abort_with_error;
 162.422 -	  }                  
 162.423 -	  
 162.424 -	  // Read header for response to TPM command from DMI
 162.425 -          size_read = read( vtpm_globals->guest_rx_fh, cmd_header, VTPM_COMMAND_HEADER_SIZE_SRV);
 162.426 -	  if (size_read > 0) {
 162.427 -	    vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "RECV (DMI): 0x");
 162.428 -	    for (i=0; i<size_read; i++) 
 162.429 -	      vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", cmd_header[i]);
 162.430 -	    
 162.431 -	  } else {
 162.432 -            vtpmhandlerlogerror(VTPM_LOG_VTPM, "Error reading from DMI. Aborting... \n");
 162.433 -	    close(vtpm_globals->guest_rx_fh);
 162.434 -	    vtpm_globals->guest_rx_fh = -1;
 162.435 -            status = TPM_IOERROR;
 162.436 -	    goto abort_with_error;
 162.437 -	  }
 162.438 -          
 162.439 -	  if (size_read < (int) VTPM_COMMAND_HEADER_SIZE_SRV) {
 162.440 -	    //vtpmdeepsublog("\n");
 162.441 -	    vtpmhandlerlogerror(VTPM_LOG_VTPM, "Command from DMI shorter than normal header. Aborting...\n");
 162.442 -            status = TPM_IOERROR;
 162.443 -	    goto abort_with_error;
 162.444 -	  }
 162.445 -          
 162.446 -	  // Unpack response from DMI for TPM command
 162.447 -	  BSG_UnpackList(cmd_header, 4,
 162.448 -			 BSG_TYPE_UINT32, &dmi,
 162.449 -			 BSG_TPM_TAG, &tag,
 162.450 -			 BSG_TYPE_UINT32, &in_param_size,
 162.451 -			 BSG_TPM_COMMAND_CODE, &status );
 162.452 -        
 162.453 -	  // If response has parameters, read them.
 162.454 -	  // Note that in_param_size is in the client's context
 162.455 -	  cmd_size = in_param_size - VTPM_COMMAND_HEADER_SIZE_CLT;
 162.456 -	  if (cmd_size > 0) {
 162.457 -	    in_param = (BYTE *) malloc(cmd_size);
 162.458 -	    size_read = read( vtpm_globals->guest_rx_fh, in_param, cmd_size);
 162.459 -	    if (size_read > 0) {
 162.460 -	      for (i=0; i<size_read; i++) 
 162.461 -		vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", in_param[i]);
 162.462 -	      
 162.463 -	    } else {
 162.464 -              vtpmhandlerlogerror(VTPM_LOG_VTPM, "Error reading from BE. Aborting... \n");
 162.465 -	      close(vtpm_globals->guest_rx_fh);
 162.466 -	      vtpm_globals->guest_rx_fh = -1;
 162.467 -              status = TPM_IOERROR;
 162.468 -	      goto abort_with_error;
 162.469 -	    }
 162.470 -	    vtpmhandlerloginfomore(VTPM_LOG_VTPM, "\n");
 162.471 -            
 162.472 -	    if (size_read < (int)cmd_size) {
 162.473 -	      vtpmhandlerloginfomore(VTPM_LOG_VTPM, "\n");
 162.474 -	      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Command read(%d) from DMI is shorter than header indicates(%d). Aborting...\n", size_read, cmd_size);
 162.475 -              status = TPM_IOERROR;
 162.476 -	      goto abort_with_error;
 162.477 -	    }
 162.478 -	  } else {
 162.479 -	    in_param = NULL;
 162.480 -	    vtpmhandlerloginfomore(VTPM_LOG_VTPM, "\n");
 162.481 -	  }
 162.482 -          
 162.483 -	  if (buffer_init_convert(result_buf, cmd_size, in_param) != TPM_SUCCESS) {
 162.484 -	    vtpmhandlerlogerror(VTPM_LOG_VTPM, "Failed to setup buffers. Aborting...\n");
 162.485 -            status = TPM_FAIL;
 162.486 -	    goto abort_with_error;
 162.487 -	  }
 162.488 -	  
 162.489 -	  vtpmhandlerloginfo(VTPM_LOG_VTPM, "Sending DMI's response to guest.\n");
 162.490 -	} // end else for if (dmi==0)
 162.491 -        
 162.492 -      } else { // This is a DMI lister thread. Thus this is from a DMI
 162.493 -	// Raw TPM commands are not supported from the DMI
 162.494 -	vtpmhandlerlogerror(VTPM_LOG_VTPM, "Attempt to use unsupported direct access to TPM.\n");
 162.495 -	vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "Bad Command. dmi:%d, tag:%d, size:%d, ord:%d, Params: ", dmi, tag, in_param_size, ord);
 162.496 -	for (i=0; i<cmd_size; i++) 
 162.497 -	  vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", in_param[i]);
 162.498 -	
 162.499 -	vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "\n");
 162.500 -        
 162.501 -	status = TPM_FAIL;
 162.502 -      } // end else for if BE Listener
 162.503 -#endif
 162.504 -      
 162.505 -    } // end else for is VTPM Command
 162.506 -
 162.507 -    // This marks the beginning of preparing response to be sent out.
 162.508 -    // Errors while handling responses jump here to reply with error messages
 162.509 -    // NOTE: Currently there are no recoverable errors in multi-VM mode. If one
 162.510 -    //       is added to the code, this ifdef should be removed.
 162.511 -    //       Also note this is NOT referring to errors in commands, but rather
 162.512 -    //       this is about I/O errors and such.
 162.513 -#ifndef VTPM_MULTI_VM
 162.514 - abort_with_error:
 162.515 -#endif
 162.516 -    
 162.517 -    // Open tx_fh in preperation to send reponse back
 162.518 -    if (*tx_fh < 0) {
 162.519 -#ifdef VTPM_MULTI_VM
 162.520 -      *tx_fh = open(VTPM_BE_DEV, O_RDWR);
 162.521 -#else
 162.522 -      if (threadType == BE_LISTENER_THREAD) 
 162.523 - #ifdef DUMMY_BACKEND
 162.524 -	*tx_fh = open("/tmp/out.fifo", O_RDWR);
 162.525 - #else
 162.526 -        *tx_fh = open(VTPM_BE_DEV, O_RDWR);
 162.527 - #endif
 162.528 -      else  // DMI Listener
 162.529 -	*tx_fh = open(dmi_res->vtpm_tx_fname, O_WRONLY);
 162.530 -#endif
 162.531 -      }
 162.532 -
 162.533 -    
 162.534 -    // Handle failed open
 162.535 -    if (*tx_fh < 0) {
 162.536 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "VTPM ERROR: Can't open outbound fh.\n");
 162.537 -#ifdef VTPM_MULTI_VM
 162.538 -      return TPM_IOERROR; 
 162.539 -#else
 162.540 -      *ret_value = TPM_IOERROR;
 162.541 -      pthread_exit(ret_value);
 162.542 -#endif
 162.543 -    }        
 162.544 -    
 162.545 -    // Prepend VTPM header with destination DM stamped
 162.546 -    out_param_size = buffer_len(result_buf);
 162.547 -    out_message_size = VTPM_COMMAND_HEADER_SIZE_CLT + out_param_size;
 162.548 -    out_message_size_full = VTPM_COMMAND_HEADER_SIZE_SRV + out_param_size;
 162.549 -    out_message = (BYTE *) malloc (out_message_size_full);
 162.550 -    
 162.551 -    BSG_PackList(out_message, 4,
 162.552 -		 BSG_TYPE_UINT32, (BYTE *) &dmi,
 162.553 -		 BSG_TPM_TAG, (BYTE *) &tag,
 162.554 -		 BSG_TYPE_UINT32, (BYTE *) &out_message_size,
 162.555 -		 BSG_TPM_RESULT, (BYTE *) &status);
 162.556 -    
 162.557 -    if (buffer_len(result_buf) > 0) 
 162.558 -      memcpy(out_message + VTPM_COMMAND_HEADER_SIZE_SRV, result_buf->bytes, out_param_size);
 162.559 -    
 162.560 -    
 162.561 -    //Note: Send message + dmi_id
 162.562 -    size_write = write(*tx_fh, out_message, out_message_size_full );
 162.563 -    if (size_write > 0) {
 162.564 -      vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "SENT: 0x");
 162.565 -      for (i=0; i < out_message_size_full; i++) 
 162.566 -	vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", out_message[i]);
 162.567 -      
 162.568 -      vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "\n");            
 162.569 -    } else {
 162.570 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Error writing to BE. Aborting... \n");
 162.571 -      close(*tx_fh);
 162.572 -      *tx_fh = -1;
 162.573 -      goto abort_command;
 162.574 -    }
 162.575 -    free(out_message);
 162.576 -    
 162.577 -    if (size_write < (int)out_message_size_full) {
 162.578 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Unable to write full command to BE (%d/%d)\n", size_write, out_message_size_full);
 162.579 -      goto abort_command;
 162.580 -    }
 162.581 -    
 162.582 -    // On certain failures an error message cannot be sent. 
 162.583 -    // This marks the beginning of cleanup in preperation for the next command.
 162.584 -  abort_command:
 162.585 -    //free buffers
 162.586 -    bzero(cmd_header, VTPM_COMMAND_HEADER_SIZE_SRV);
 162.587 -    //free(in_param); // This was converted to command_buf. No need to free 
 162.588 -    if (command_buf != result_buf) 
 162.589 -      buffer_free(result_buf);
 162.590 -    
 162.591 -    buffer_free(command_buf);
 162.592 -    
 162.593 -#ifndef VTPM_MULTI_VM
 162.594 -    if (threadType != BE_LISTENER_THREAD) {
 162.595 -#endif
 162.596 -      if ( (vtpm_globals->DMI_table_dirty) &&
 162.597 -	   (VTPM_SaveService() != TPM_SUCCESS) ) {
 162.598 -	vtpmhandlerlogerror(VTPM_LOG_VTPM, "ERROR: Unable to save manager data.\n");
 162.599 -      }
 162.600 -#ifndef VTPM_MULTI_VM
 162.601 -    }
 162.602 -#endif
 162.603 -    
 162.604 -  } // End while(1)
 162.605 -  
 162.606 -}
 162.607 -
 162.608 -
 162.609  ///////////////////////////////////////////////////////////////////////////////
 162.610 -TPM_RESULT VTPM_Init_Service() {
 162.611 +TPM_RESULT VTPM_Init_Manager() {
 162.612    TPM_RESULT status = TPM_FAIL, serviceStatus;   
 162.613    BYTE *randomsead;
 162.614    UINT32 randomsize;
 162.615 @@ -749,20 +188,14 @@ TPM_RESULT VTPM_Init_Service() {
 162.616      goto abort_egress;
 162.617    }
 162.618    memset(vtpm_globals, 0, sizeof(VTPM_GLOBALS));
 162.619 -  vtpm_globals->be_fh = -1;
 162.620  
 162.621 -#ifndef VTPM_MULTI_VM
 162.622 -  vtpm_globals->vtpm_rx_fh = -1;
 162.623 -  vtpm_globals->guest_rx_fh = -1;
 162.624    vtpm_globals->connected_dmis = 0;
 162.625 -#endif
 162.626 +
 162.627    if ((vtpm_globals->dmi_map = create_hashtable(10, hashfunc32, equals32)) == NULL){
 162.628      status = TPM_FAIL;
 162.629      goto abort_egress;
 162.630    }
 162.631    
 162.632 -  vtpm_globals->DMI_table_dirty = FALSE;
 162.633 -  
 162.634    // Create new TCS Object
 162.635    vtpm_globals->manager_tcs_handle = 0;
 162.636   
 162.637 @@ -783,13 +216,14 @@ TPM_RESULT VTPM_Init_Service() {
 162.638  			   &vtpm_globals->keyAuth) );
 162.639    vtpm_globals->keyAuth.fContinueAuthSession = TRUE;
 162.640  
 162.641 -	// If failed, create new Service.
 162.642 -  serviceStatus = VTPM_LoadService();
 162.643 +	// If failed, create new Manager.
 162.644 +  serviceStatus = VTPM_LoadManagerData();
 162.645    if (serviceStatus == TPM_IOERROR) {
 162.646 -    vtpmloginfo(VTPM_LOG_VTPM, "Failed to read service file. Assuming first time initialization.\n");
 162.647 -    TPMTRYRETURN( VTPM_Create_Service() );    
 162.648 +    vtpmloginfo(VTPM_LOG_VTPM, "Failed to read manager file. Assuming first time initialization.\n");
 162.649 +    TPMTRYRETURN( VTPM_Create_Manager() );    
 162.650 +    TPMTRYRETURN( VTPM_SaveManagerData() );
 162.651    } else if (serviceStatus != TPM_SUCCESS) {
 162.652 -    vtpmlogerror(VTPM_LOG_VTPM, "Failed to read existing service file");
 162.653 +    vtpmlogerror(VTPM_LOG_VTPM, "Failed to read existing manager file");
 162.654      exit(1);
 162.655    }
 162.656  
 162.657 @@ -805,8 +239,6 @@ TPM_RESULT VTPM_Init_Service() {
 162.658  
 162.659    // Create entry for Dom0 for control messages
 162.660    TPMTRYRETURN( VTPM_Handle_New_DMI(NULL) );
 162.661 -    
 162.662 -  // --------------------- Command handlers ---------------------------
 162.663    
 162.664    goto egress;
 162.665    
 162.666 @@ -815,8 +247,9 @@ TPM_RESULT VTPM_Init_Service() {
 162.667    
 162.668    return(status);
 162.669  }
 162.670 - 
 162.671 -void VTPM_Stop_Service() {
 162.672 +
 162.673 +/////////////////////////////////////////////////////////////////////////////// 
 162.674 +void VTPM_Stop_Manager() {
 162.675    VTPM_DMI_RESOURCE *dmi_res;
 162.676    struct hashtable_itr *dmi_itr;
 162.677    
 162.678 @@ -832,7 +265,7 @@ void VTPM_Stop_Service() {
 162.679  		free (dmi_itr);
 162.680    }
 162.681    
 162.682 -  if ( (vtpm_globals->DMI_table_dirty) && (VTPM_SaveService() != TPM_SUCCESS) )
 162.683 +  if ( VTPM_SaveManagerData() != TPM_SUCCESS ) 
 162.684      vtpmlogerror(VTPM_LOG_VTPM, "Unable to save manager data.\n");
 162.685  
 162.686    TCS_CloseContext(vtpm_globals->manager_tcs_handle);
 162.687 @@ -841,7 +274,6 @@ void VTPM_Stop_Service() {
 162.688    hashtable_destroy(vtpm_globals->dmi_map, 1);
 162.689    free(vtpm_globals);
 162.690    
 162.691 -  close(vtpm_globals->be_fh);
 162.692    Crypto_Exit();
 162.693  	
 162.694    vtpmloginfo(VTPM_LOG_VTPM, "VTPM Manager stopped.\n");
   163.1 --- a/tools/vtpm_manager/manager/vtpm_manager.h	Mon May 22 08:53:26 2006 -0600
   163.2 +++ b/tools/vtpm_manager/manager/vtpm_manager.h	Mon May 22 14:13:38 2006 -0600
   163.3 @@ -40,32 +40,30 @@
   163.4  #ifndef __VTPM_MANAGER_H__
   163.5  #define __VTPM_MANAGER_H__
   163.6  
   163.7 -#include "tcg.h"
   163.8 -
   163.9  #define VTPM_TAG_REQ 0x01c1
  163.10  #define VTPM_TAG_RSP 0x01c4
  163.11  #define COMMAND_BUFFER_SIZE 4096
  163.12  
  163.13  // Header sizes. Note Header MAY include the DMI
  163.14 -#define VTPM_COMMAND_HEADER_SIZE_SRV ( sizeof(UINT32) + sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
  163.15 -#define VTPM_COMMAND_HEADER_SIZE_CLT (                  sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
  163.16 -
  163.17 -// ********************** Public Functions *************************
  163.18 -TPM_RESULT VTPM_Init_Service(); // Start VTPM Service
  163.19 -void VTPM_Stop_Service();  // Stop VTPM Service
  163.20 -#ifdef VTPM_MULTI_VM
  163.21 -int VTPM_Service_Handler();
  163.22 -#else
  163.23 -void *VTPM_Service_Handler(void *threadTypePtr);
  163.24 -#endif
  163.25 +#define VTPM_COMMAND_HEADER_SIZE_CLT ( 2 + 4 + 4)
  163.26 +//                    sizeof(TPM_TAG + UINT32 + TPM_COMMAND_CODE)
  163.27 +#define VTPM_COMMAND_HEADER_SIZE_SRV ( 4 + VTPM_COMMAND_HEADER_SIZE_CLT )
  163.28 +//                    sizeof( UINT32 + VTPM_COMMAND_HEADER_SIZE_CLT)
  163.29  
  163.30  //************************ Command Codes ****************************
  163.31 -#define VTPM_ORD_OPEN              1   // ULM Creates New DMI
  163.32 -#define VTPM_ORD_CLOSE             2   // ULM Closes a DMI
  163.33 -#define VTPM_ORD_DELETE            3   // ULM Permemently Deletes DMI
  163.34 -#define VTPM_ORD_SAVENVM          4   // DMI requests Secrets Unseal
  163.35 -#define VTPM_ORD_LOADNVM          5   // DMI requests Secrets Saved
  163.36 -#define VTPM_ORD_TPMCOMMAND       6   // DMI issues HW TPM Command
  163.37 +#define VTPM_ORD_BASE       0x0000
  163.38 +#define VTPM_PRIV_MASK      0x01000000 // Priviledged VTPM Command
  163.39 +#define VTPM_PRIV_BASE      (VTPM_ORD_BASE | VTPM_PRIV_MASK)
  163.40 +
  163.41 +// Non-priviledged VTPM Commands (From DMI's)
  163.42 +#define VTPM_ORD_SAVENVM    (VTPM_ORD_BASE + 1) // DMI Saves Secrets