WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] merge with xen-unstable.hg

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] merge with xen-unstable.hg
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 30 Aug 2006 22:10:29 +0000
Delivery-date: Wed, 30 Aug 2006 15:13:30 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User awilliam@xxxxxxxxxxx
# Node ID 79afceca906517b24cf9a94264a7f7ff97d9f458
# Parent  91169603a8e8dded9eba6cb6c3421b5d58a85a97
# Parent  0bb18319b8a0ee957ea9307ac3d9e40c31b456d4
merge with xen-unstable.hg
---
 extras/mini-os/include/hypercall-x86_32.h                                      
          |  326 
 extras/mini-os/include/hypercall-x86_64.h                                      
          |  326 
 extras/mini-os/include/os.h                                                    
          |  561 -
 extras/mini-os/include/spinlock.h                                              
          |  121 
 extras/mini-os/include/traps.h                                                 
          |   73 
 extras/mini-os/traps.c                                                         
          |  229 
 tools/ioemu/patches/qemu-fix-write-to-disk-synchronous                         
          |   66 
 tools/libxc/xc_ppc_linux_build.c                                               
          |  414 
 xen/arch/x86/audit.c                                                           
          |  984 --
 xen/arch/x86/shadow.c                                                          
          | 4199 ---------
 xen/arch/x86/shadow32.c                                                        
          | 3782 --------
 xen/arch/x86/shadow_guest32.c                                                  
          |   16 
 xen/arch/x86/shadow_guest32pae.c                                               
          |   16 
 xen/arch/x86/shadow_public.c                                                   
          | 2138 ----
 xen/include/asm-x86/shadow_64.h                                                
          |  587 -
 xen/include/asm-x86/shadow_ops.h                                               
          |  138 
 xen/include/asm-x86/shadow_public.h                                            
          |   61 
 .hgignore                                                                      
          |   17 
 buildconfigs/Rules.mk                                                          
          |    8 
 docs/src/user.tex                                                              
          |   13 
 extras/mini-os/Makefile                                                        
          |   53 
 extras/mini-os/arch/x86/traps.c                                                
          |  229 
 extras/mini-os/console/xencons_ring.c                                          
          |    8 
 extras/mini-os/include/hypervisor.h                                            
          |    3 
 extras/mini-os/include/types.h                                                 
          |    4 
 extras/mini-os/include/x86/os.h                                                
          |  561 +
 extras/mini-os/include/x86/spinlock.h                                          
          |  121 
 extras/mini-os/include/x86/traps.h                                             
          |   73 
 extras/mini-os/include/x86/x86_32/hypercall-x86_32.h                           
          |  326 
 extras/mini-os/include/x86/x86_64/hypercall-x86_64.h                           
          |  326 
 linux-2.6-xen-sparse/arch/i386/kernel/cpu/mtrr/main-xen.c                      
          |    2 
 linux-2.6-xen-sparse/arch/i386/kernel/io_apic-xen.c                            
          |    2 
 linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c                              
          |   55 
 linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c                                
          |    2 
 linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c                               
          |    8 
 linux-2.6-xen-sparse/arch/i386/kernel/vmlinux.lds.S                            
          |   12 
 linux-2.6-xen-sparse/arch/i386/mm/init-xen.c                                   
          |    2 
 linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c                                
          |    9 
 linux-2.6-xen-sparse/arch/i386/pci/irq-xen.c                                   
          |    6 
 linux-2.6-xen-sparse/arch/ia64/dig/setup.c                                     
          |  110 
 linux-2.6-xen-sparse/arch/ia64/kernel/setup.c                                  
          |    7 
 linux-2.6-xen-sparse/arch/ia64/xen/hypervisor.c                                
          |    2 
 linux-2.6-xen-sparse/arch/x86_64/kernel/entry-xen.S                            
          |   12 
 linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c                            
          |   74 
 linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c                                 
          |    8 
 linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c                                
          |    8 
 linux-2.6-xen-sparse/drivers/xen/Kconfig                                       
          |    2 
 linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c                             
          |   35 
 linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c                             
          |    4 
 linux-2.6-xen-sparse/drivers/xen/blkback/common.h                              
          |    8 
 linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c                              
          |   12 
 linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c                           
          |    3 
 linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c                               
          |   12 
 linux-2.6-xen-sparse/drivers/xen/blktap/common.h                               
          |    4 
 linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c                               
          |    5 
 linux-2.6-xen-sparse/drivers/xen/console/console.c                             
          |   14 
 linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c                        
          |    8 
 linux-2.6-xen-sparse/drivers/xen/core/cpu_hotplug.c                            
          |    2 
 linux-2.6-xen-sparse/drivers/xen/core/evtchn.c                                 
          |    3 
 linux-2.6-xen-sparse/drivers/xen/core/gnttab.c                                 
          |   54 
 linux-2.6-xen-sparse/drivers/xen/core/reboot.c                                 
          |    3 
 linux-2.6-xen-sparse/drivers/xen/core/skbuff.c                                 
          |    3 
 linux-2.6-xen-sparse/drivers/xen/core/smpboot.c                                
          |   20 
 linux-2.6-xen-sparse/drivers/xen/netback/common.h                              
          |    9 
 linux-2.6-xen-sparse/drivers/xen/netback/loopback.c                            
          |    2 
 linux-2.6-xen-sparse/drivers/xen/netback/netback.c                             
          |  382 
 linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c                              
          |   39 
 linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c                           
          |  682 -
 linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c                              
          |    1 
 linux-2.6-xen-sparse/drivers/xen/pcifront/xenbus.c                             
          |    1 
 linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c                             
          |   12 
 linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c                              
          |    6 
 linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c                        
          |    2 
 linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c                         
          |   15 
 linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h                         
          |    2 
 linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c                           
          |    6 
 linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c                         
          |  147 
 linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c                            
          |   10 
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h                 
          |   29 
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h                
          |   15 
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/maddr.h                     
          |  160 
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h                      
          |  129 
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h            
          |    1 
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h            
          |   12 
 linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h                             
          |    2 
 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h               
          |   29 
 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/maddr.h                   
          |  139 
 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h                    
          |  122 
 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgtable.h                 
          |   22 
 linux-2.6-xen-sparse/include/xen/balloon.h                                     
          |   10 
 linux-2.6-xen-sparse/include/xen/hvm.h                                         
          |   24 
 linux-2.6-xen-sparse/include/xen/xenbus.h                                      
          |    3 
 linux-2.6-xen-sparse/mm/memory.c                                               
          |    5 
 linux-2.6-xen-sparse/net/core/dev.c                                            
          |   10 
 patches/linux-2.6.16.13/net-gso-4-kill-warnon.patch                            
          |   28 
 patches/linux-2.6.16.13/series                                                 
          |   22 
 
patches/linux-2.6.16.13/x86-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch
    |   70 
 
patches/linux-2.6.16.13/x86_64-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch
 |   47 
 tools/blktap/lib/Makefile                                                      
          |    2 
 tools/examples/xen-network-common.sh                                           
          |    1 
 tools/examples/xend-config.sxp                                                 
          |    2 
 tools/examples/xmexample.hvm                                                   
          |    8 
 tools/examples/xmexample.vti                                                   
          |    4 
 tools/firmware/acpi/acpi_fadt.h                                                
          |    3 
 tools/firmware/hvmloader/Makefile                                              
          |    8 
 tools/firmware/hvmloader/hvmloader.c                                           
          |   22 
 tools/firmware/hvmloader/hypercall.h                                           
          |    2 
 tools/firmware/hvmloader/smbios.c                                              
          |  606 +
 tools/firmware/hvmloader/smbios.h                                              
          |   38 
 tools/firmware/hvmloader/smbios_types.h                                        
          |  182 
 tools/firmware/hvmloader/util.c                                                
          |   80 
 tools/firmware/hvmloader/util.h                                                
          |   12 
 tools/firmware/rombios/apmbios.S                                               
          |    3 
 tools/firmware/rombios/rombios.c                                               
          |   45 
 tools/firmware/vmxassist/head.S                                                
          |    5 
 tools/firmware/vmxassist/setup.c                                               
          |    8 
 tools/firmware/vmxassist/util.h                                                
          |   20 
 tools/firmware/vmxassist/vm86.c                                                
          |  103 
 tools/firmware/vmxassist/vmxassist.ld                                          
          |   12 
 tools/ioemu/Makefile.target                                                    
          |    1 
 tools/ioemu/block-bochs.c                                                      
          |    2 
 tools/ioemu/block-cloop.c                                                      
          |    2 
 tools/ioemu/block-cow.c                                                        
          |    2 
 tools/ioemu/block-qcow.c                                                       
          |    2 
 tools/ioemu/block-vmdk.c                                                       
          |    2 
 tools/ioemu/block.c                                                            
          |    2 
 tools/ioemu/hw/ide.c                                                           
          |   17 
 tools/ioemu/hw/pc.c                                                            
          |   72 
 tools/ioemu/hw/piix4acpi.c                                                     
          |    4 
 tools/ioemu/hw/piix_pci.c                                                      
          |    2 
 tools/ioemu/hw/xen_platform.c                                                  
          |  138 
 tools/ioemu/patches/acpi-poweroff-support                                      
          |    2 
 tools/ioemu/patches/acpi-support                                               
          |   50 
 tools/ioemu/patches/acpi-timer-support                                         
          |    6 
 tools/ioemu/patches/domain-destroy                                             
          |    8 
 tools/ioemu/patches/domain-reset                                               
          |   10 
 tools/ioemu/patches/domain-timeoffset                                          
          |   12 
 tools/ioemu/patches/hypervisor-pit                                             
          |    6 
 tools/ioemu/patches/ide-hd-multithread                                         
          |    2 
 tools/ioemu/patches/ioemu-ia64                                                 
          |   45 
 tools/ioemu/patches/qemu-allow-disable-sdl                                     
          |    2 
 tools/ioemu/patches/qemu-bootorder                                             
          |  124 
 tools/ioemu/patches/qemu-daemonize                                             
          |   16 
 tools/ioemu/patches/qemu-fix-memset-args                                       
          |    2 
 tools/ioemu/patches/qemu-tunable-ide-write-cache                               
          |   39 
 tools/ioemu/patches/serial-non-block                                           
          |    2 
 tools/ioemu/patches/series                                                     
          |    5 
 tools/ioemu/patches/shadow-vram                                                
          |    4 
 tools/ioemu/patches/shared-vram                                                
          |   14 
 tools/ioemu/patches/support-xm-console                                         
          |    2 
 tools/ioemu/patches/vnc-access-monitor-vt                                      
          |    2 
 tools/ioemu/patches/vnc-cleanup                                                
          |    4 
 tools/ioemu/patches/vnc-display-find-unused                                    
          |   10 
 tools/ioemu/patches/vnc-fixes                                                  
          |   10 
 tools/ioemu/patches/vnc-start-vncviewer                                        
          |   10 
 tools/ioemu/patches/vnc-title-domain-name                                      
          |    2 
 tools/ioemu/patches/xen-mm                                                     
          |   36 
 tools/ioemu/patches/xen-platform-device                                        
          |   37 
 tools/ioemu/patches/xen-support-buffered-ioreqs                                
          |   26 
 tools/ioemu/patches/xenstore-block-device-config                               
          |   23 
 tools/ioemu/patches/xenstore-write-vnc-port                                    
          |   10 
 tools/ioemu/target-i386-dm/exec-dm.c                                           
          |    6 
 tools/ioemu/vl.c                                                               
          |   95 
 tools/ioemu/vl.h                                                               
          |   11 
 tools/libaio/src/Makefile                                                      
          |    7 
 tools/libxc/Makefile                                                           
          |    7 
 tools/libxc/ia64/xc_ia64_linux_restore.c                                       
          |    4 
 tools/libxc/powerpc64/Makefile                                                 
          |    1 
 tools/libxc/powerpc64/xc_linux_build.c                                         
          |  408 
 tools/libxc/xc_domain.c                                                        
          |   13 
 tools/libxc/xc_evtchn.c                                                        
          |   11 
 tools/libxc/xc_hvm_build.c                                                     
          |  212 
 tools/libxc/xc_linux.c                                                         
          |   30 
 tools/libxc/xc_linux_build.c                                                   
          |   22 
 tools/libxc/xc_linux_restore.c                                                 
          |    7 
 tools/libxc/xc_linux_save.c                                                    
          |   26 
 tools/libxc/xenctrl.h                                                          
          |    9 
 tools/misc/xc_shadow.c                                                         
          |    2 
 tools/python/xen/lowlevel/xc/xc.c                                              
          |  184 
 tools/python/xen/util/xmlrpclib2.py                                            
          |   12 
 tools/python/xen/web/httpserver.py                                             
          |    7 
 tools/python/xen/xend/XendCheckpoint.py                                        
          |    4 
 tools/python/xen/xend/XendDomain.py                                            
          |   24 
 tools/python/xen/xend/XendDomainInfo.py                                        
          |   59 
 tools/python/xen/xend/XendLogging.py                                           
          |   28 
 tools/python/xen/xend/XendNode.py                                              
          |    6 
 tools/python/xen/xend/image.py                                                 
          |   29 
 tools/python/xen/xend/server/DevController.py                                  
          |   22 
 tools/python/xen/xend/server/XMLRPCServer.py                                   
          |    4 
 tools/python/xen/xend/server/blkif.py                                          
          |   19 
 tools/python/xen/xm/create.py                                                  
          |    9 
 tools/python/xen/xm/main.py                                                    
          |   82 
 tools/xcutils/xc_restore.c                                                     
          |   23 
 tools/xcutils/xc_save.c                                                        
          |   28 
 tools/xenmon/Makefile                                                          
          |   10 
 tools/xenmon/xenbaked.c                                                        
          |   19 
 tools/xenstore/Makefile                                                        
          |    2 
 tools/xenstore/xs.c                                                            
          |   22 
 tools/xentrace/Makefile                                                        
          |    4 
 tools/xentrace/xentrace.c                                                      
          |   21 
 tools/xm-test/lib/XmTestLib/XenDevice.py                                       
          |    1 
 unmodified_drivers/linux-2.6/Makefile                                          
          |    6 
 unmodified_drivers/linux-2.6/README                                            
          |    7 
 unmodified_drivers/linux-2.6/blkfront/Kbuild                                   
          |    5 
 unmodified_drivers/linux-2.6/mkbuildtree                                       
          |   49 
 unmodified_drivers/linux-2.6/netfront/Kbuild                                   
          |    4 
 unmodified_drivers/linux-2.6/overrides.mk                                      
          |   12 
 unmodified_drivers/linux-2.6/platform-pci/Kbuild                               
          |    7 
 unmodified_drivers/linux-2.6/platform-pci/evtchn.c                             
          |  173 
 unmodified_drivers/linux-2.6/platform-pci/platform-pci.c                       
          |  271 
 unmodified_drivers/linux-2.6/platform-pci/platform-pci.h                       
          |   45 
 unmodified_drivers/linux-2.6/platform-pci/xen_support.c                        
          |   43 
 unmodified_drivers/linux-2.6/xenbus/Kbuild                                     
          |   10 
 xen/Rules.mk                                                                   
          |    6 
 xen/acm/acm_core.c                                                             
          |    4 
 xen/acm/acm_simple_type_enforcement_hooks.c                                    
          |   28 
 xen/arch/ia64/Rules.mk                                                         
          |    1 
 xen/arch/ia64/vmx/mmio.c                                                       
          |    2 
 xen/arch/ia64/vmx/vlsapic.c                                                    
          |    2 
 xen/arch/ia64/vmx/vmx_init.c                                                   
          |    5 
 xen/arch/ia64/vmx/vmx_vcpu.c                                                   
          |    2 
 xen/arch/ia64/xen/domain.c                                                     
          |   25 
 xen/arch/ia64/xen/hyperprivop.S                                                
          |    2 
 xen/arch/ia64/xen/mm.c                                                         
          |   26 
 xen/arch/ia64/xen/vcpu.c                                                       
          |    2 
 xen/arch/ia64/xen/xenasm.S                                                     
          |    2 
 xen/arch/powerpc/Makefile                                                      
          |    7 
 xen/arch/powerpc/boot_of.c                                                     
          |   57 
 xen/arch/powerpc/dom0_ops.c                                                    
          |   43 
 xen/arch/powerpc/domain.c                                                      
          |   42 
 xen/arch/powerpc/domain_build.c                                                
          |    6 
 xen/arch/powerpc/htab.c                                                        
          |   13 
 xen/arch/powerpc/mm.c                                                          
          |   20 
 xen/arch/powerpc/of_handler/devtree.c                                          
          |    2 
 xen/arch/powerpc/ofd_fixup.c                                                   
          |    8 
 xen/arch/powerpc/papr/xlate.c                                                  
          |    2 
 xen/arch/powerpc/powerpc64/ppc970.c                                            
          |   12 
 xen/arch/powerpc/setup.c                                                       
          |   41 
 xen/arch/powerpc/usercopy.c                                                    
          |    4 
 xen/arch/x86/Makefile                                                          
          |   16 
 xen/arch/x86/Rules.mk                                                          
          |    1 
 xen/arch/x86/acpi/boot.c                                                       
          |    2 
 xen/arch/x86/apic.c                                                            
          |   12 
 xen/arch/x86/boot/x86_32.S                                                     
          |   28 
 xen/arch/x86/cpu/amd.c                                                         
          |    2 
 xen/arch/x86/cpu/cyrix.c                                                       
          |    2 
 xen/arch/x86/cpu/transmeta.c                                                   
          |    2 
 xen/arch/x86/delay.c                                                           
          |   14 
 xen/arch/x86/dmi_scan.c                                                        
          |   10 
 xen/arch/x86/dom0_ops.c                                                        
          |    4 
 xen/arch/x86/domain.c                                                          
          |  127 
 xen/arch/x86/domain_build.c                                                    
          |   32 
 xen/arch/x86/e820.c                                                            
          |   12 
 xen/arch/x86/extable.c                                                         
          |    4 
 xen/arch/x86/genapic/bigsmp.c                                                  
          |    2 
 xen/arch/x86/genapic/es7000.h                                                  
          |    4 
 xen/arch/x86/genapic/probe.c                                                   
          |    2 
 xen/arch/x86/hvm/hvm.c                                                         
          |  130 
 xen/arch/x86/hvm/i8254.c                                                       
          |    2 
 xen/arch/x86/hvm/i8259.c                                                       
          |   15 
 xen/arch/x86/hvm/intercept.c                                                   
          |    2 
 xen/arch/x86/hvm/io.c                                                          
          |   31 
 xen/arch/x86/hvm/platform.c                                                    
          |   12 
 xen/arch/x86/hvm/svm/emulate.c                                                 
          |    4 
 xen/arch/x86/hvm/svm/instrlen.c                                                
          |    2 
 xen/arch/x86/hvm/svm/intr.c                                                    
          |   61 
 xen/arch/x86/hvm/svm/svm.c                                                     
          | 1084 +-
 xen/arch/x86/hvm/svm/vmcb.c                                                    
          |  226 
 xen/arch/x86/hvm/svm/x86_32/exits.S                                            
          |   12 
 xen/arch/x86/hvm/svm/x86_64/exits.S                                            
          |   23 
 xen/arch/x86/hvm/vioapic.c                                                     
          |   18 
 xen/arch/x86/hvm/vlapic.c                                                      
          |   70 
 xen/arch/x86/hvm/vmx/io.c                                                      
          |   98 
 xen/arch/x86/hvm/vmx/vmcs.c                                                    
          |   31 
 xen/arch/x86/hvm/vmx/vmx.c                                                     
          |  310 
 xen/arch/x86/hvm/vmx/x86_32/exits.S                                            
          |    4 
 xen/arch/x86/hvm/vmx/x86_64/exits.S                                            
          |    4 
 xen/arch/x86/i387.c                                                            
          |    2 
 xen/arch/x86/io_apic.c                                                         
          |    2 
 xen/arch/x86/irq.c                                                             
          |   87 
 xen/arch/x86/microcode.c                                                       
          |    4 
 xen/arch/x86/mm.c                                                              
          | 1142 --
 xen/arch/x86/mpparse.c                                                         
          |    2 
 xen/arch/x86/nmi.c                                                             
          |    8 
 xen/arch/x86/oprofile/nmi_int.c                                                
          |    4 
 xen/arch/x86/oprofile/op_model_p4.c                                            
          |    2 
 xen/arch/x86/oprofile/xenoprof.c                                               
          |    6 
 xen/arch/x86/setup.c                                                           
          |   70 
 xen/arch/x86/shadow2-common.c                                                  
          | 3406 +++++++
 xen/arch/x86/shadow2.c                                                         
          | 4492 +++++++++
 xen/arch/x86/smpboot.c                                                         
          |    2 
 xen/arch/x86/traps.c                                                           
          |   78 
 xen/arch/x86/x86_32/asm-offsets.c                                              
          |    1 
 xen/arch/x86/x86_32/domain_page.c                                              
          |   66 
 xen/arch/x86/x86_32/entry.S                                                    
          |  105 
 xen/arch/x86/x86_32/mm.c                                                       
          |   12 
 xen/arch/x86/x86_32/traps.c                                                    
          |    9 
 xen/arch/x86/x86_64/asm-offsets.c                                              
          |    1 
 xen/arch/x86/x86_64/entry.S                                                    
          |   50 
 xen/arch/x86/x86_64/mm.c                                                       
          |   13 
 xen/arch/x86/x86_64/traps.c                                                    
          |   18 
 xen/common/acm_ops.c                                                           
          |    1 
 xen/common/dom0_ops.c                                                          
          |    9 
 xen/common/domain.c                                                            
          |    8 
 xen/common/elf.c                                                               
          |    1 
 xen/common/grant_table.c                                                       
          |  301 
 xen/common/keyhandler.c                                                        
          |   48 
 xen/common/memory.c                                                            
          |    3 
 xen/common/rangeset.c                                                          
          |    1 
 xen/common/sched_bvt.c                                                         
          |    3 
 xen/common/sched_credit.c                                                      
          |    2 
 xen/common/sched_sedf.c                                                        
          |   22 
 xen/common/schedule.c                                                          
          |    5 
 xen/common/timer.c                                                             
          |    6 
 xen/common/trace.c                                                             
          |    1 
 xen/drivers/Makefile                                                           
          |    1 
 xen/drivers/char/console.c                                                     
          |  239 
 xen/drivers/char/serial.c                                                      
          |    1 
 xen/drivers/video/Makefile                                                     
          |    4 
 xen/drivers/video/font.h                                                       
          |   22 
 xen/drivers/video/font_8x14.c                                                  
          | 4118 ++++++++
 xen/drivers/video/font_8x16.c                                                  
          | 4630 ++++++++++
 xen/drivers/video/font_8x8.c                                                   
          | 2582 +++++
 xen/drivers/video/vga.c                                                        
          |  690 +
 xen/include/acm/acm_core.h                                                     
          |    2 
 xen/include/asm-ia64/config.h                                                  
          |    2 
 xen/include/asm-ia64/domain.h                                                  
          |    2 
 xen/include/asm-ia64/event.h                                                   
          |    2 
 xen/include/asm-ia64/linux-null/asm/desc.h                                     
          |    1 
 xen/include/asm-ia64/linux-null/asm/ia32.h                                     
          |    1 
 xen/include/asm-ia64/linux-null/asm/mman.h                                     
          |    1 
 xen/include/asm-ia64/linux-null/asm/module.h                                   
          |    1 
 xen/include/asm-ia64/linux-null/asm/pdb.h                                      
          |    1 
 xen/include/asm-ia64/linux-null/asm/ptrace_offsets.h                           
          |    1 
 xen/include/asm-ia64/linux-null/asm/semaphore.h                                
          |    1 
 xen/include/asm-ia64/linux-null/asm/serial.h                                   
          |    1 
 xen/include/asm-ia64/linux-null/asm/sn/arch.h                                  
          |    1 
 xen/include/asm-ia64/linux-null/asm/sn/geo.h                                   
          |    1 
 xen/include/asm-ia64/linux-null/asm/sn/nodepda.h                               
          |    1 
 xen/include/asm-ia64/linux-null/asm/sn/sn_cpuid.h                              
          |    1 
 xen/include/asm-ia64/linux-null/asm/ustack.h                                   
          |    1 
 xen/include/asm-ia64/linux-null/linux/bootmem.h                                
          |    1 
 xen/include/asm-ia64/linux-null/linux/cpu.h                                    
          |    1 
 xen/include/asm-ia64/linux-null/linux/device.h                                 
          |    1 
 xen/include/asm-ia64/linux-null/linux/file.h                                   
          |    1 
 xen/include/asm-ia64/linux-null/linux/ioport.h                                 
          |    1 
 xen/include/asm-ia64/linux-null/linux/kallsyms.h                               
          |    1 
 xen/include/asm-ia64/linux-null/linux/kernel_stat.h                            
          |    1 
 xen/include/asm-ia64/linux-null/linux/mmzone.h                                 
          |    1 
 xen/include/asm-ia64/linux-null/linux/module.h                                 
          |    1 
 xen/include/asm-ia64/linux-null/linux/page-flags.h                             
          |    1 
 xen/include/asm-ia64/linux-null/linux/proc_fs.h                                
          |    1 
 xen/include/asm-ia64/linux-null/linux/profile.h                                
          |    1 
 xen/include/asm-ia64/linux-null/linux/ptrace.h                                 
          |    1 
 xen/include/asm-ia64/linux-null/linux/random.h                                 
          |    1 
 xen/include/asm-ia64/linux-null/linux/rtc.h                                    
          |    1 
 xen/include/asm-ia64/linux-null/linux/seq_file.h                               
          |    1 
 xen/include/asm-ia64/linux-null/linux/serial.h                                 
          |    1 
 xen/include/asm-ia64/linux-null/linux/serial_core.h                            
          |    1 
 xen/include/asm-ia64/linux-null/linux/signal.h                                 
          |    1 
 xen/include/asm-ia64/linux-null/linux/slab.h                                   
          |    1 
 xen/include/asm-ia64/linux-null/linux/smp_lock.h                               
          |    1 
 xen/include/asm-ia64/linux-null/linux/swap.h                                   
          |    1 
 xen/include/asm-ia64/linux-null/linux/threads.h                                
          |    1 
 xen/include/asm-ia64/linux-null/linux/tty.h                                    
          |    1 
 xen/include/asm-ia64/linux-null/linux/workqueue.h                              
          |    1 
 xen/include/asm-ia64/linux-xen/asm/ptrace.h                                    
          |    3 
 xen/include/asm-ia64/privop_stat.h                                             
          |    2 
 xen/include/asm-ia64/vcpu.h                                                    
          |    3 
 xen/include/asm-ia64/vmx_platform.h                                            
          |    1 
 xen/include/asm-ia64/vmx_vpd.h                                                 
          |    2 
 xen/include/asm-powerpc/config.h                                               
          |    1 
 xen/include/asm-powerpc/domain.h                                               
          |   13 
 xen/include/asm-powerpc/grant_table.h                                          
          |    2 
 xen/include/asm-powerpc/htab.h                                                 
          |    8 
 xen/include/asm-powerpc/mm.h                                                   
          |    4 
 xen/include/asm-powerpc/processor.h                                            
          |    1 
 xen/include/asm-powerpc/shadow.h                                               
          |   15 
 xen/include/asm-x86/acpi.h                                                     
          |    2 
 xen/include/asm-x86/bitops.h                                                   
          |   18 
 xen/include/asm-x86/config.h                                                   
          |   24 
 xen/include/asm-x86/domain.h                                                   
          |  116 
 xen/include/asm-x86/e820.h                                                     
          |   31 
 xen/include/asm-x86/genapic.h                                                  
          |    8 
 xen/include/asm-x86/grant_table.h                                              
          |    4 
 xen/include/asm-x86/hvm/domain.h                                               
          |    1 
 xen/include/asm-x86/hvm/hvm.h                                                  
          |   37 
 xen/include/asm-x86/hvm/io.h                                                   
          |    1 
 xen/include/asm-x86/hvm/support.h                                              
          |   15 
 xen/include/asm-x86/hvm/svm/svm.h                                              
          |   52 
 xen/include/asm-x86/hvm/svm/vmcb.h                                             
          |   32 
 xen/include/asm-x86/hvm/vcpu.h                                                 
          |   13 
 xen/include/asm-x86/hvm/vioapic.h                                              
          |    5 
 xen/include/asm-x86/hvm/vmx/vmcs.h                                             
          |    3 
 xen/include/asm-x86/hvm/vmx/vmx.h                                              
          |   74 
 xen/include/asm-x86/io.h                                                       
          |    1 
 xen/include/asm-x86/mach-es7000/mach_mpparse.h                                 
          |    2 
 xen/include/asm-x86/mach-generic/mach_mpparse.h                                
          |    4 
 xen/include/asm-x86/mm.h                                                       
          |  197 
 xen/include/asm-x86/msr.h                                                      
          |    6 
 xen/include/asm-x86/page-guest32.h                                             
          |    7 
 xen/include/asm-x86/page.h                                                     
          |   45 
 xen/include/asm-x86/perfc.h                                                    
          |   12 
 xen/include/asm-x86/perfc_defn.h                                               
          |   53 
 xen/include/asm-x86/processor.h                                                
          |   59 
 xen/include/asm-x86/shadow.h                                                   
          | 1791 ---
 xen/include/asm-x86/shadow2-multi.h                                            
          |  116 
 xen/include/asm-x86/shadow2-private.h                                          
          |  593 +
 xen/include/asm-x86/shadow2-types.h                                            
          |  705 +
 xen/include/asm-x86/shadow2.h                                                  
          |  626 +
 xen/include/asm-x86/string.h                                                   
          |    2 
 xen/include/asm-x86/system.h                                                   
          |    4 
 xen/include/asm-x86/uaccess.h                                                  
          |    6 
 xen/include/asm-x86/x86_32/page-2level.h                                       
          |    1 
 xen/include/asm-x86/x86_32/page-3level.h                                       
          |    3 
 xen/include/asm-x86/x86_64/page.h                                              
          |    5 
 xen/include/public/arch-ia64.h                                                 
          |    8 
 xen/include/public/arch-powerpc.h                                              
          |    6 
 xen/include/public/arch-x86_32.h                                               
          |   29 
 xen/include/public/arch-x86_64.h                                               
          |   29 
 xen/include/public/dom0_ops.h                                                  
          |   77 
 xen/include/public/grant_table.h                                               
          |   47 
 xen/include/public/hvm/e820.h                                                  
          |   32 
 xen/include/public/hvm/hvm_info_table.h                                        
          |    2 
 xen/include/public/xen-compat.h                                                
          |   23 
 xen/include/public/xen.h                                                       
          |   82 
 xen/include/xen/console.h                                                      
          |    3 
 xen/include/xen/domain_page.h                                                  
          |   37 
 xen/include/xen/gdbstub.h                                                      
          |   10 
 xen/include/xen/keyhandler.h                                                   
          |    6 
 xen/include/xen/lib.h                                                          
          |    6 
 xen/include/xen/list.h                                                         
          |   12 
 xen/include/xen/mm.h                                                           
          |    7 
 xen/include/xen/sched.h                                                        
          |    2 
 xen/include/xen/vga.h                                                          
          |   24 
 435 files changed, 32246 insertions(+), 20570 deletions(-)

diff -r 91169603a8e8 -r 79afceca9065 .hgignore
--- a/.hgignore Tue Aug 22 14:45:49 2006 -0600
+++ b/.hgignore Wed Aug 23 11:11:27 2006 -0600
@@ -151,7 +151,7 @@
 ^tools/vtpm_manager/manager/vtpm_managerd$
 ^tools/xcutils/xc_restore$
 ^tools/xcutils/xc_save$
-^tools/xenmon/setmask$
+^tools/xenmon/xentrace_setmask$
 ^tools/xenmon/xenbaked$
 ^tools/xenstat/xentop/xentop$
 ^tools/xenstore/testsuite/tmp/.*$
@@ -172,7 +172,7 @@
 ^tools/xenstore/xs_tdb_dump$
 ^tools/xenstore/xs_test$
 ^tools/xenstore/xs_watch_stress$
-^tools/xentrace/setsize$
+^tools/xentrace/xentrace_setsize$
 ^tools/xentrace/tbctl$
 ^tools/xentrace/xenctx$
 ^tools/xentrace/xentrace$
@@ -197,7 +197,12 @@
 ^xen/xen$
 ^xen/xen-syms$
 ^xen/xen\..*$
-^xen/arch/ppc/dom0\.bin$
-^xen/arch/ppc/asm-offsets\.s$
-^xen/arch/ppc/firmware
-^xen/arch/ppc/firmware_image
+^xen/arch/powerpc/dom0\.bin$
+^xen/arch/powerpc/asm-offsets\.s$
+^xen/arch/powerpc/firmware$
+^xen/arch/powerpc/firmware_image$
+^xen/arch/powerpc/xen\.lds$
+^unmodified_drivers/linux-2.6/\.tmp_versions
+^unmodified_drivers/linux-2.6/.*\.cmd$
+^unmodified_drivers/linux-2.6/.*\.ko$
+^unmodified_drivers/linux-2.6/.*\.mod\.c$
diff -r 91169603a8e8 -r 79afceca9065 buildconfigs/Rules.mk
--- a/buildconfigs/Rules.mk     Tue Aug 22 14:45:49 2006 -0600
+++ b/buildconfigs/Rules.mk     Wed Aug 23 11:11:27 2006 -0600
@@ -63,8 +63,12 @@ ref-%/.valid-ref: pristine-%/.valid-pris
        set -e
        rm -rf $(@D)
        cp -al $(<D) $(@D)
-       if [ -d patches/$* ] ; then \
-           for i in patches/$*/*.patch ; do patch -d $(@D) -p1 <$$i || exit 1 
; done ; \
+       if [ -d patches/$* ] ; then                                    \
+           echo Applying patches from patches/$*... ;                 \
+           for i in $$(cat patches/$*/series) ; do                    \
+               echo ... $$i ;                                         \
+               patch -d $(@D) -p1 --quiet <patches/$*/$$i || exit 1 ; \
+            done ;                                                    \
        fi
        touch $@ # update timestamp to avoid rebuild
 endif
diff -r 91169603a8e8 -r 79afceca9065 docs/src/user.tex
--- a/docs/src/user.tex Tue Aug 22 14:45:49 2006 -0600
+++ b/docs/src/user.tex Wed Aug 23 11:11:27 2006 -0600
@@ -1089,6 +1089,9 @@ The \path{xm list} command also supports
 The \path{xm list} command also supports a long output format when the
 \path{-l} switch is used.  This outputs the full details of the
 running domains in \xend's SXP configuration format.
+
+If you want to know how long your domains have been running for, then 
+you can use the \verb_# xm uptime_ command.
 
 
 You can get access to the console of a particular domain using 
@@ -3126,8 +3129,8 @@ editing \path{grub.conf}.
 \item [ console=$<$specifier list$>$ ] Specify the destination for Xen
   console I/O.  This is a comma-separated list of, for example:
   \begin{description}
-  \item[ vga ] Use VGA console (only until domain 0 boots, unless {\bf
-  vga[keep] } is specified).
+  \item[ vga ] Use VGA console (until domain 0 boots, unless {\bf
+  vga=keep } is specified).
   \item[ com1 ] Use serial port com1.
   \item[ com2H ] Use serial port com2. Transmitted chars will have the
     MSB set. Received chars must have MSB set.
@@ -3138,6 +3141,12 @@ editing \path{grub.conf}.
   subsystems (e.g.\ console and debugger). Sharing is controlled by
   MSB of each transmitted/received character.  [NB. Default for this
   option is `com1,vga']
+\item [ vga=$<$options$>$ ] This is a comma-separated list of options:
+  \begin{description}
+  \item[ text-$<$mode$>$ ] Select text-mode resolution, where mode is
+  one of 80x25, 80x28, 80x30, 80x34, 80x43, 80x50, 80x60.
+  \item[ keep ] Keep the VGA console even after domain 0 boots.
+  \end{description}
 \item [ sync\_console ] Force synchronous console output. This is
   useful if you system fails unexpectedly before it has sent all
   available output to the console. In most cases Xen will
diff -r 91169603a8e8 -r 79afceca9065 extras/mini-os/Makefile
--- a/extras/mini-os/Makefile   Tue Aug 22 14:45:49 2006 -0600
+++ b/extras/mini-os/Makefile   Wed Aug 23 11:11:27 2006 -0600
@@ -11,26 +11,54 @@ CFLAGS := -fno-builtin -Wall -Werror -Wr
 CFLAGS := -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format
 CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
 
-override CPPFLAGS := -Iinclude $(CPPFLAGS)
 ASFLAGS = -D__ASSEMBLY__
 
 LDLIBS =  -L. -lminios
 LDFLAGS := -N -T minios-$(TARGET_ARCH).lds
 
+# For possible special source directories.
+EXTRA_SRC =
+# For possible special header directories.
+EXTRA_INC =
+
+# Standard name for architecture specific subdirectories.
+TARGET_ARCH_DIR = $(TARGET_ARCH)
+# This is used for architecture specific links.
+ARCH_LINKS =
+
 ifeq ($(TARGET_ARCH),x86_32)
 CFLAGS += -m32 -march=i686
 LDFLAGS += -m elf_i386
+TARGET_ARCH_DIR = x86
+EXTRA_INC += $(TARGET_ARCH_DIR)/$(TARGET_ARCH)
+EXTRA_SRC += arch/$(EXTRA_INC)
 endif
 
 ifeq ($(TARGET_ARCH)$(pae),x86_32y)
 CFLAGS  += -DCONFIG_X86_PAE=1
 ASFLAGS += -DCONFIG_X86_PAE=1
+TARGET_ARCH_DIR = x86
+EXTRA_INC += $(TARGET_ARCH_DIR)/$(TARGET_ARCH)
+EXTRA_SRC += arch/$(EXTRA_INC)
 endif
 
 ifeq ($(TARGET_ARCH),x86_64)
 CFLAGS += -m64 -mno-red-zone -fpic -fno-reorder-blocks
 CFLAGS += -fno-asynchronous-unwind-tables
 LDFLAGS += -m elf_x86_64
+TARGET_ARCH_DIR = x86
+EXTRA_INC += $(TARGET_ARCH_DIR)/$(TARGET_ARCH)
+EXTRA_SRC += arch/$(EXTRA_INC)
+endif
+
+ifeq ($(TARGET_ARCH),ia64)
+CFLAGS += -mfixed-range=f12-f15,f32-f127
+ASFLAGS += -x assembler-with-cpp -ansi -Wall
+ASFLAGS += -mfixed-range=f12-f15,f32-f127
+ARCH_LINKS = IA64_LINKS                # Special link on ia64 needed
+define arch_links
+[ -e include/ia64/asm-xsi-offsets.h ] || ln -sf 
../../../../xen/include/asm-ia64/asm-xsi-offsets.h 
include/ia64/asm-xsi-offsets.h
+endef
 endif
 
 ifeq ($(debug),y)
@@ -39,6 +67,10 @@ CFLAGS += -O3
 CFLAGS += -O3
 endif
 
+# Add the special header directories to the include paths.
+extra_incl := $(foreach dir,$(EXTRA_INC),-Iinclude/$(dir))
+override CPPFLAGS := -Iinclude $(CPPFLAGS) -Iinclude/$(TARGET_ARCH_DIR)        
$(extra_incl)
+
 TARGET := mini-os
 
 HEAD := $(TARGET_ARCH).o
@@ -46,15 +78,32 @@ OBJS += $(patsubst %.c,%.o,$(wildcard li
 OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
 OBJS += $(patsubst %.c,%.o,$(wildcard xenbus/*.c))
 OBJS += $(patsubst %.c,%.o,$(wildcard console/*.c))
+OBJS += $(patsubst %.S,%.o,$(wildcard arch/$(TARGET_ARCH_DIR)/*.S))
+OBJS += $(patsubst %.c,%.o,$(wildcard arch/$(TARGET_ARCH_DIR)/*.c))
+# For special wanted source directories.
+extra_objs := $(foreach dir,$(EXTRA_SRC),$(patsubst %.c,%.o,$(wildcard 
$(dir)/*.c)))
+OBJS += $(extra_objs)
+extra_objs := $(foreach dir,$(EXTRA_SRC),$(patsubst %.S,%.o,$(wildcard 
$(dir)/*.S)))
+OBJS += $(extra_objs)
 
 HDRS := $(wildcard include/*.h)
 HDRS += $(wildcard include/xen/*.h)
+HDRS += $(wildcard include/$(TARGET_ARCH_DIR)/*.h)
+# For special wanted header directories.
+extra_heads := $(foreach dir,$(EXTRA_INC),$(wildcard $(dir)/*.h))
+HDRS += $(extra_heads)
 
 .PHONY: default
 default: $(TARGET)
 
+# Create special architecture specific links.
+ifneq ($(ARCH_LINKS),)
+$(ARCH_LINKS):
+       $(arch_links)
+endif
+
 .PHONY: links
-links:
+links: $(ARCH_LINKS)
        [ -e include/xen ] || ln -sf ../../../xen/include/public include/xen
 
 libminios.a: links $(OBJS) $(HEAD)
diff -r 91169603a8e8 -r 79afceca9065 extras/mini-os/console/xencons_ring.c
--- a/extras/mini-os/console/xencons_ring.c     Tue Aug 22 14:45:49 2006 -0600
+++ b/extras/mini-os/console/xencons_ring.c     Wed Aug 23 11:11:27 2006 -0600
@@ -14,13 +14,13 @@
 
 static inline struct xencons_interface *xencons_interface(void)
 {
-    return mfn_to_virt(start_info.console_mfn);
+    return mfn_to_virt(start_info.console.domU.mfn);
 }
 
 static inline void notify_daemon(void)
 {
     /* Use evtchn: this is called early, before irq is set up. */
-    notify_remote_via_evtchn(start_info.console_evtchn);
+    notify_remote_via_evtchn(start_info.console.domU.evtchn);
 }
 
 int xencons_ring_send_no_notify(const char *data, unsigned len)
@@ -80,10 +80,10 @@ int xencons_ring_init(void)
 {
        int err;
 
-       if (!start_info.console_evtchn)
+       if (!start_info.console.domU.evtchn)
                return 0;
 
-       err = bind_evtchn(start_info.console_evtchn, handle_input,
+       err = bind_evtchn(start_info.console.domU.evtchn, handle_input,
                          NULL);
        if (err <= 0) {
                printk("XEN console request chn bind failed %i\n", err);
diff -r 91169603a8e8 -r 79afceca9065 extras/mini-os/include/hypervisor.h
--- a/extras/mini-os/include/hypervisor.h       Tue Aug 22 14:45:49 2006 -0600
+++ b/extras/mini-os/include/hypervisor.h       Wed Aug 23 11:11:27 2006 -0600
@@ -7,6 +7,7 @@
  * Copyright (c) 2002, K A Fraser
  * Copyright (c) 2005, Grzegorz Milos
  * Updates: Aravindh Puthiyaparambil <aravindh.puthiyaparambil@xxxxxxxxxx>
+ * Updates: Dietmar Hahn <dietmar.hahn@xxxxxxxxxxxxxxxxxxx> for ia64
  */
 
 #ifndef _HYPERVISOR_H_
@@ -19,6 +20,8 @@
 #include <hypercall-x86_32.h>
 #elif defined(__x86_64__)
 #include <hypercall-x86_64.h>
+#elif defined(__ia64__)
+#include <hypercall-ia64.h>
 #else
 #error "Unsupported architecture"
 #endif
diff -r 91169603a8e8 -r 79afceca9065 extras/mini-os/include/types.h
--- a/extras/mini-os/include/types.h    Tue Aug 22 14:45:49 2006 -0600
+++ b/extras/mini-os/include/types.h    Wed Aug 23 11:11:27 2006 -0600
@@ -29,7 +29,7 @@ typedef unsigned int        u32;
 #ifdef __i386__
 typedef signed long long    s64;
 typedef unsigned long long  u64;
-#elif defined(__x86_64__)
+#elif defined(__x86_64__) || defined(__ia64__)
 typedef signed long         s64;
 typedef unsigned long       u64;
 #endif
@@ -49,7 +49,7 @@ typedef struct { unsigned long pte_low, 
 typedef struct { unsigned long pte_low, pte_high; } pte_t;
 #endif /* CONFIG_X86_PAE */
 
-#elif defined(__x86_64__)
+#elif defined(__x86_64__) || defined(__ia64__)
 typedef long                quad_t;
 typedef unsigned long       u_quad_t;
 typedef unsigned long       uintptr_t;
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/i386/kernel/cpu/mtrr/main-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/kernel/cpu/mtrr/main-xen.c Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/cpu/mtrr/main-xen.c Wed Aug 23 
11:11:27 2006 -0600
@@ -178,7 +178,7 @@ static int __init mtrr_init(void)
 {
        struct cpuinfo_x86 *c = &boot_cpu_data;
 
-       if (!(xen_start_info->flags & SIF_PRIVILEGED))
+       if (!is_initial_xendomain())
                return -ENODEV;
 
        if ((!cpu_has(c, X86_FEATURE_MTRR)) &&
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/i386/kernel/io_apic-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/kernel/io_apic-xen.c       Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/io_apic-xen.c       Wed Aug 23 
11:11:27 2006 -0600
@@ -2480,7 +2480,7 @@ static int __init io_apic_bug_finalize(v
 {
        if(sis_apic_bug == -1)
                sis_apic_bug = 0;
-       if (xen_start_info->flags & SIF_INITDOMAIN) {
+       if (is_initial_xendomain()) {
                dom0_op_t op = { .cmd = DOM0_PLATFORM_QUIRK };
                op.u.platform_quirk.quirk_id = sis_apic_bug ?
                        QUIRK_IOAPIC_BAD_REGSEL : QUIRK_IOAPIC_GOOD_REGSEL;
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c Wed Aug 23 11:11:27 
2006 -0600
@@ -184,7 +184,6 @@ static struct resource code_resource = {
        .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
 };
 
-#ifdef CONFIG_XEN_PRIVILEGED_GUEST
 static struct resource system_rom_resource = {
        .name   = "System ROM",
        .start  = 0xf0000,
@@ -240,7 +239,6 @@ static struct resource video_rom_resourc
        .end    = 0xc7fff,
        .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
 };
-#endif
 
 static struct resource video_ram_resource = {
        .name   = "Video RAM area",
@@ -299,7 +297,6 @@ static struct resource standard_io_resou
 #define STANDARD_IO_RESOURCES \
        (sizeof standard_io_resources / sizeof standard_io_resources[0])
 
-#ifdef CONFIG_XEN_PRIVILEGED_GUEST
 #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
 
 static int __init romchecksum(unsigned char *rom, unsigned long length)
@@ -317,9 +314,11 @@ static void __init probe_roms(void)
        unsigned char *rom;
        int           i;
 
+#ifdef CONFIG_XEN
        /* Nothing to do if not running in dom0. */
-       if (!(xen_start_info->flags & SIF_INITDOMAIN))
+       if (!is_initial_xendomain())
                return;
+#endif
 
        /* video rom */
        upper = adapter_rom_resources[0].start;
@@ -379,7 +378,6 @@ static void __init probe_roms(void)
                start = adapter_rom_resources[i++].end & ~2047UL;
        }
 }
-#endif
 
 /*
  * Point at the empty zero page to start with. We map the real shared_info
@@ -1359,9 +1357,7 @@ legacy_init_iomem_resources(struct e820e
 {
        int i;
 
-#if defined(CONFIG_XEN_PRIVILEGED_GUEST) || !defined(CONFIG_XEN)
        probe_roms();
-#endif
 
        for (i = 0; i < nr_map; i++) {
                struct resource *res;
@@ -1458,7 +1454,7 @@ static void __init register_memory(void)
        int           i;
 
        /* Nothing to do if not running in dom0. */
-       if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
+       if (!is_initial_xendomain()) {
                legacy_init_iomem_resources(e820.map, e820.nr_map,
                                            &code_resource, &data_resource);
                return;
@@ -1618,7 +1614,7 @@ void __init setup_arch(char **cmdline_p)
 
        /* Force a quick death if the kernel panics (not domain 0). */
        extern int panic_timeout;
-       if (!panic_timeout && !(xen_start_info->flags & SIF_INITDOMAIN))
+       if (!panic_timeout && !is_initial_xendomain())
                panic_timeout = 1;
 
        /* Register a call for panic conditions. */
@@ -1661,7 +1657,7 @@ void __init setup_arch(char **cmdline_p)
        }
        bootloader_type = LOADER_TYPE;
 
-       if (xen_start_info->flags & SIF_INITDOMAIN) {
+       if (is_initial_xendomain()) {
                /* This is drawn from a dump from vgacon:startup in
                 * standard Linux. */
                screen_info.orig_video_mode = 3; 
@@ -1670,6 +1666,35 @@ void __init setup_arch(char **cmdline_p)
                screen_info.orig_video_cols = 80;
                screen_info.orig_video_ega_bx = 3;
                screen_info.orig_video_points = 16;
+               if (xen_start_info->console.dom0.info_size >=
+                   sizeof(struct dom0_vga_console_info)) {
+                       const struct dom0_vga_console_info *info =
+                               (struct dom0_vga_console_info *)(
+                                       (char *)xen_start_info +
+                                       xen_start_info->console.dom0.info_off);
+                       screen_info.orig_video_mode = info->txt_mode;
+                       screen_info.orig_video_isVGA = info->video_type;
+                       screen_info.orig_video_lines = info->video_height;
+                       screen_info.orig_video_cols = info->video_width;
+                       screen_info.orig_video_points = info->txt_points;
+                       screen_info.lfb_width = info->video_width;
+                       screen_info.lfb_height = info->video_height;
+                       screen_info.lfb_depth = info->lfb_depth;
+                       screen_info.lfb_base = info->lfb_base;
+                       screen_info.lfb_size = info->lfb_size;
+                       screen_info.lfb_linelength = info->lfb_linelen;
+                       screen_info.red_size = info->red_size;
+                       screen_info.red_pos = info->red_pos;
+                       screen_info.green_size = info->green_size;
+                       screen_info.green_pos = info->green_pos;
+                       screen_info.blue_size = info->blue_size;
+                       screen_info.blue_pos = info->blue_pos;
+                       screen_info.rsvd_size = info->rsvd_size;
+                       screen_info.rsvd_pos = info->rsvd_pos;
+               }
+               screen_info.orig_y = screen_info.orig_video_lines - 1;
+               xen_start_info->console.domU.mfn = 0;
+               xen_start_info->console.domU.evtchn = 0;
        } else
                screen_info.orig_video_isVGA = 0;
 
@@ -1788,7 +1813,7 @@ void __init setup_arch(char **cmdline_p)
        }
 #endif
 
-       if (xen_start_info->flags & SIF_INITDOMAIN)
+       if (is_initial_xendomain())
                dmi_scan_machine();
 
 #ifdef CONFIG_X86_GENERICARCH
@@ -1805,7 +1830,7 @@ void __init setup_arch(char **cmdline_p)
 #endif
 
 #ifdef CONFIG_ACPI
-       if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
+       if (!is_initial_xendomain()) {
                printk(KERN_INFO "ACPI in unprivileged domain disabled\n");
                acpi_disabled = 1;
                acpi_ht = 0;
@@ -1831,11 +1856,7 @@ void __init setup_arch(char **cmdline_p)
 
        register_memory();
 
-       if (xen_start_info->flags & SIF_INITDOMAIN) {
-               if (!(xen_start_info->flags & SIF_PRIVILEGED))
-                       panic("Xen granted us console access "
-                             "but not privileged status");
-
+       if (is_initial_xendomain()) {
 #ifdef CONFIG_VT
 #if defined(CONFIG_VGA_CONSOLE)
                if (!efi_enabled ||
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c
--- a/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c   Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c   Wed Aug 23 11:11:27 
2006 -0600
@@ -199,7 +199,7 @@ swiotlb_init(void)
                swiotlb = 1;
        } else if ((swiotlb_force != -1) &&
                   is_running_on_xen() &&
-                  (xen_start_info->flags & SIF_INITDOMAIN)) {
+                  is_initial_xendomain()) {
                /* Domain 0 always has a swiotlb. */
                ram_end = HYPERVISOR_memory_op(XENMEM_maximum_ram_page, NULL);
                if (ram_end <= 0x7ffff)
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c  Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c  Wed Aug 23 11:11:27 
2006 -0600
@@ -470,8 +470,7 @@ int do_settimeofday(struct timespec *tv)
        sec = tv->tv_sec;
        __normalize_time(&sec, &nsec);
 
-       if ((xen_start_info->flags & SIF_INITDOMAIN) &&
-           !independent_wallclock) {
+       if (is_initial_xendomain() && !independent_wallclock) {
                op.cmd = DOM0_SETTIME;
                op.u.settime.secs        = sec;
                op.u.settime.nsecs       = nsec;
@@ -502,8 +501,7 @@ static void sync_xen_wallclock(unsigned 
        s64 nsec;
        dom0_op_t op;
 
-       if (!ntp_synced() || independent_wallclock ||
-           !(xen_start_info->flags & SIF_INITDOMAIN))
+       if (!ntp_synced() || independent_wallclock || !is_initial_xendomain())
                return;
 
        write_seqlock_irq(&xtime_lock);
@@ -532,7 +530,7 @@ static int set_rtc_mmss(unsigned long no
 
        WARN_ON(irqs_disabled());
 
-       if (independent_wallclock || !(xen_start_info->flags & SIF_INITDOMAIN))
+       if (independent_wallclock || !is_initial_xendomain())
                return 0;
 
        /* gets recalled with irq locally disabled */
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/i386/kernel/vmlinux.lds.S
--- a/linux-2.6-xen-sparse/arch/i386/kernel/vmlinux.lds.S       Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/vmlinux.lds.S       Wed Aug 23 
11:11:27 2006 -0600
@@ -12,6 +12,12 @@ OUTPUT_ARCH(i386)
 OUTPUT_ARCH(i386)
 ENTRY(phys_startup_32)
 jiffies = jiffies_64;
+
+PHDRS {
+       text PT_LOAD FLAGS(5);  /* R_E */
+       data PT_LOAD FLAGS(7);  /* RWE */
+       note PT_NOTE FLAGS(4);  /* R__ */
+}
 SECTIONS
 {
   . = __KERNEL_START;
@@ -25,7 +31,7 @@ SECTIONS
        KPROBES_TEXT
        *(.fixup)
        *(.gnu.warning)
-       } = 0x9090
+       } :text = 0x9090
 
   _etext = .;                  /* End of text section */
 
@@ -47,7 +53,7 @@ SECTIONS
   .data : AT(ADDR(.data) - LOAD_OFFSET) {      /* Data */
        *(.data)
        CONSTRUCTORS
-       }
+       } :data
 
   . = ALIGN(4096);
   __nosave_begin = .;
@@ -154,4 +160,6 @@ SECTIONS
   STABS_DEBUG
 
   DWARF_DEBUG
+
+  NOTES
 }
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/i386/mm/init-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/mm/init-xen.c      Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/mm/init-xen.c      Wed Aug 23 11:11:27 
2006 -0600
@@ -566,7 +566,7 @@ void __init paging_init(void)
 
        /* Setup mapping of lower 1st MB */
        for (i = 0; i < NR_FIX_ISAMAPS; i++)
-               if (xen_start_info->flags & SIF_PRIVILEGED)
+               if (is_initial_xendomain())
                        set_fixmap(FIX_ISAMAP_BEGIN - i, i * PAGE_SIZE);
                else
                        __set_fixmap(FIX_ISAMAP_BEGIN - i,
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c   Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c   Wed Aug 23 11:11:27 
2006 -0600
@@ -121,7 +121,7 @@ int direct_remap_pfn_range(struct vm_are
                           domid_t  domid)
 {
        /* Same as remap_pfn_range(). */
-       vma->vm_flags |= VM_IO | VM_RESERVED;
+       vma->vm_flags |= VM_IO | VM_RESERVED | VM_PFNMAP;
 
        if (domid == DOMID_SELF)
                return -EINVAL;
@@ -245,7 +245,7 @@ void __iomem * __ioremap(unsigned long p
        /*
         * Don't remap the low PCI/ISA area, it's always mapped..
         */
-       if (xen_start_info->flags & SIF_PRIVILEGED &&
+       if (is_initial_xendomain() &&
            phys_addr >= ISA_START_ADDRESS && last_addr < ISA_END_ADDRESS)
                return (void __iomem *) isa_bus_to_virt(phys_addr);
 
@@ -282,9 +282,6 @@ void __iomem * __ioremap(unsigned long p
        area->phys_addr = phys_addr;
        addr = (void __iomem *) area->addr;
        flags |= _PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED;
-#ifdef __x86_64__
-       flags |= _PAGE_USER;
-#endif
        if (__direct_remap_pfn_range(&init_mm, (unsigned long)addr,
                                     phys_addr>>PAGE_SHIFT,
                                     size, __pgprot(flags), domid)) {
@@ -425,7 +422,7 @@ void __init *bt_ioremap(unsigned long ph
        /*
         * Don't remap the low PCI/ISA area, it's always mapped..
         */
-       if (xen_start_info->flags & SIF_PRIVILEGED &&
+       if (is_initial_xendomain() &&
            phys_addr >= ISA_START_ADDRESS && last_addr < ISA_END_ADDRESS)
                return isa_bus_to_virt(phys_addr);
 
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/i386/pci/irq-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/pci/irq-xen.c      Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/pci/irq-xen.c      Wed Aug 23 11:11:27 
2006 -0600
@@ -95,7 +95,10 @@ static struct irq_routing_table * __init
        u8 *addr;
        struct irq_routing_table *rt;
 
-#ifdef CONFIG_XEN_PRIVILEGED_GUEST
+#ifdef CONFIG_XEN
+       if (!is_initial_xendomain())
+               return NULL;
+#endif
        if (pirq_table_addr) {
                rt = pirq_check_routing_table((u8 *) 
isa_bus_to_virt(pirq_table_addr));
                if (rt)
@@ -107,7 +110,6 @@ static struct irq_routing_table * __init
                if (rt)
                        return rt;
        }
-#endif
        
        return NULL;
 }
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/ia64/kernel/setup.c
--- a/linux-2.6-xen-sparse/arch/ia64/kernel/setup.c     Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/arch/ia64/kernel/setup.c     Wed Aug 23 11:11:27 
2006 -0600
@@ -545,12 +545,7 @@ setup_arch (char **cmdline_p)
                       "flags=0x%x\n", s->arch.start_info_pfn,
                       xen_start_info->nr_pages, xen_start_info->flags);
 
-               /* xen_start_info isn't setup yet, get the flags manually */
-               if (xen_start_info->flags & SIF_INITDOMAIN) {
-                       if (!(xen_start_info->flags & SIF_PRIVILEGED))
-                               panic("Xen granted us console access "
-                                     "but not privileged status");
-               } else {
+               if (!is_initial_xendomain()) {
                        extern int console_use_vt;
                        conswitchp = NULL;
                        console_use_vt = 0;
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/ia64/xen/hypervisor.c
--- a/linux-2.6-xen-sparse/arch/ia64/xen/hypervisor.c   Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/arch/ia64/xen/hypervisor.c   Wed Aug 23 11:11:27 
2006 -0600
@@ -82,7 +82,7 @@ ia64_xenmem_reservation_op(unsigned long
                        //    of a non-privileged domain, 
                        if ((op == XENMEM_increase_reservation ||
                             op == XENMEM_populate_physmap) &&
-                           !(xen_start_info->flags & SIF_PRIVILEGED) &&
+                           !is_initial_xendomain() &&
                            reservation.extent_order > 0)
                                return ret;
                }
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/x86_64/kernel/entry-xen.S
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/entry-xen.S       Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/entry-xen.S       Wed Aug 23 
11:11:27 2006 -0600
@@ -271,7 +271,7 @@ sysret_careful:
        CFI_RESTORE_STATE
        bt $TIF_NEED_RESCHED,%edx
        jnc sysret_signal
-        XEN_BLOCK_EVENTS(%rsi)        
+       XEN_UNBLOCK_EVENTS(%rsi)
        pushq %rdi
        CFI_ADJUST_CFA_OFFSET 8
        call schedule
@@ -295,7 +295,7 @@ 1:  movl $_TIF_NEED_RESCHED,%edi
 1:     movl $_TIF_NEED_RESCHED,%edi
        /* Use IRET because user could have changed frame. This
           works because ptregscall_common has called FIXUP_TOP_OF_STACK. */
-       cli
+       XEN_BLOCK_EVENTS(%rsi)
        jmp int_with_check
        
 badsys:
@@ -377,7 +377,7 @@ int_careful:
        call schedule
        popq %rdi
        CFI_ADJUST_CFA_OFFSET -8
-       cli
+       XEN_BLOCK_EVENTS(%rsi)
        jmp int_with_check
 
        /* handle signals and tracing -- both require a full stack frame */
@@ -395,7 +395,7 @@ int_very_careful:
        popq %rdi
        CFI_ADJUST_CFA_OFFSET -8
        andl $~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edi
-       cli
+       XEN_BLOCK_EVENTS(%rsi)
        jmp int_restore_rest
        
 int_signal:
@@ -407,7 +407,7 @@ 1:  movl $_TIF_NEED_RESCHED,%edi
 1:     movl $_TIF_NEED_RESCHED,%edi    
 int_restore_rest:
        RESTORE_REST
-       cli
+       XEN_BLOCK_EVENTS(%rsi)
        jmp int_with_check
        CFI_ENDPROC
                
@@ -535,8 +535,8 @@ retint_careful:
        call  schedule
        popq %rdi               
        CFI_ADJUST_CFA_OFFSET   -8
+       GET_THREAD_INFO(%rcx)
        XEN_BLOCK_EVENTS(%rsi)          
-       GET_THREAD_INFO(%rcx)
 /*     cli */
        jmp retint_check
        
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c       Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c       Wed Aug 23 
11:11:27 2006 -0600
@@ -189,7 +189,6 @@ struct resource code_resource = {
 
 #define IORESOURCE_ROM (IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM)
 
-#if defined(CONFIG_XEN_PRIVILEGED_GUEST) || !defined(CONFIG_XEN)
 static struct resource system_rom_resource = {
        .name = "System ROM",
        .start = 0xf0000,
@@ -218,19 +217,16 @@ static struct resource adapter_rom_resou
        { .name = "Adapter ROM", .start = 0, .end = 0,
                .flags = IORESOURCE_ROM }
 };
-#endif
 
 #define ADAPTER_ROM_RESOURCES \
        (sizeof adapter_rom_resources / sizeof adapter_rom_resources[0])
 
-#if defined(CONFIG_XEN_PRIVILEGED_GUEST) || !defined(CONFIG_XEN)
 static struct resource video_rom_resource = {
        .name = "Video ROM",
        .start = 0xc0000,
        .end = 0xc7fff,
        .flags = IORESOURCE_ROM,
 };
-#endif
 
 static struct resource video_ram_resource = {
        .name = "Video RAM area",
@@ -239,7 +235,6 @@ static struct resource video_ram_resourc
        .flags = IORESOURCE_RAM,
 };
 
-#if defined(CONFIG_XEN_PRIVILEGED_GUEST) || !defined(CONFIG_XEN)
 #define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
 
 static int __init romchecksum(unsigned char *rom, unsigned long length)
@@ -256,6 +251,12 @@ static void __init probe_roms(void)
        unsigned long start, length, upper;
        unsigned char *rom;
        int           i;
+
+#ifdef CONFIG_XEN
+       /* Nothing to do if not running in dom0. */
+       if (!is_initial_xendomain())
+               return;
+#endif
 
        /* video rom */
        upper = adapter_rom_resources[0].start;
@@ -315,7 +316,6 @@ static void __init probe_roms(void)
                start = adapter_rom_resources[i++].end & ~2047UL;
        }
 }
-#endif
 
 static __init void parse_cmdline_early (char ** cmdline_p)
 {
@@ -625,11 +625,8 @@ void __init setup_arch(char **cmdline_p)
 void __init setup_arch(char **cmdline_p)
 {
        unsigned long kernel_end;
-
-#if defined(CONFIG_XEN_PRIVILEGED_GUEST)
        struct e820entry *machine_e820;
        struct xen_memory_map memmap;
-#endif
 
 #ifdef CONFIG_XEN
        /* Register a call for panic conditions. */
@@ -639,7 +636,7 @@ void __init setup_arch(char **cmdline_p)
        kernel_end = 0;         /* dummy */
        screen_info = SCREEN_INFO;
 
-       if (xen_start_info->flags & SIF_INITDOMAIN) {
+       if (is_initial_xendomain()) {
                /* This is drawn from a dump from vgacon:startup in
                 * standard Linux. */
                screen_info.orig_video_mode = 3;
@@ -648,6 +645,35 @@ void __init setup_arch(char **cmdline_p)
                screen_info.orig_video_cols = 80;
                screen_info.orig_video_ega_bx = 3;
                screen_info.orig_video_points = 16;
+               if (xen_start_info->console.dom0.info_size >=
+                   sizeof(struct dom0_vga_console_info)) {
+                       const struct dom0_vga_console_info *info =
+                               (struct dom0_vga_console_info *)(
+                                       (char *)xen_start_info +
+                                       xen_start_info->console.dom0.info_off);
+                       screen_info.orig_video_mode = info->txt_mode;
+                       screen_info.orig_video_isVGA = info->video_type;
+                       screen_info.orig_video_lines = info->video_height;
+                       screen_info.orig_video_cols = info->video_width;
+                       screen_info.orig_video_points = info->txt_points;
+                       screen_info.lfb_width = info->video_width;
+                       screen_info.lfb_height = info->video_height;
+                       screen_info.lfb_depth = info->lfb_depth;
+                       screen_info.lfb_base = info->lfb_base;
+                       screen_info.lfb_size = info->lfb_size;
+                       screen_info.lfb_linelength = info->lfb_linelen;
+                       screen_info.red_size = info->red_size;
+                       screen_info.red_pos = info->red_pos;
+                       screen_info.green_size = info->green_size;
+                       screen_info.green_pos = info->green_pos;
+                       screen_info.blue_size = info->blue_size;
+                       screen_info.blue_pos = info->blue_pos;
+                       screen_info.rsvd_size = info->rsvd_size;
+                       screen_info.rsvd_pos = info->rsvd_pos;
+               }
+               screen_info.orig_y = screen_info.orig_video_lines - 1;
+               xen_start_info->console.domU.mfn = 0;
+               xen_start_info->console.domU.evtchn = 0;
        } else
                screen_info.orig_video_isVGA = 0;
 
@@ -860,8 +886,7 @@ void __init setup_arch(char **cmdline_p)
 
        }
 
-       if ( ! (xen_start_info->flags & SIF_INITDOMAIN))
-       {
+       if (!is_initial_xendomain()) {
                acpi_disabled = 1;
 #ifdef  CONFIG_ACPI
                acpi_ht = 0;
@@ -908,9 +933,9 @@ void __init setup_arch(char **cmdline_p)
         * Request address space for all standard RAM and ROM resources
         * and also for regions reported as reserved by the e820.
         */
-#if defined(CONFIG_XEN_PRIVILEGED_GUEST)
        probe_roms();
-       if (xen_start_info->flags & SIF_INITDOMAIN) {
+#ifdef CONFIG_XEN
+       if (is_initial_xendomain()) {
                machine_e820 = alloc_bootmem_low_pages(PAGE_SIZE);
 
                memmap.nr_entries = E820MAX;
@@ -919,14 +944,9 @@ void __init setup_arch(char **cmdline_p)
                BUG_ON(HYPERVISOR_memory_op(XENMEM_machine_memory_map, 
&memmap));
 
                e820_reserve_resources(machine_e820, memmap.nr_entries);
-       } else if (!(xen_start_info->flags & SIF_INITDOMAIN))
-               e820_reserve_resources(e820.map, e820.nr_map);
-#elif defined(CONFIG_XEN)
+       } else
+#endif
        e820_reserve_resources(e820.map, e820.nr_map);
-#else
-       probe_roms();
-       e820_reserve_resources(e820.map, e820.nr_map);
-#endif
 
        request_resource(&iomem_resource, &video_ram_resource);
 
@@ -937,12 +957,12 @@ void __init setup_arch(char **cmdline_p)
                request_resource(&ioport_resource, &standard_io_resources[i]);
        }
 
-#if defined(CONFIG_XEN_PRIVILEGED_GUEST)
-       if (xen_start_info->flags & SIF_INITDOMAIN) {
+#ifdef CONFIG_XEN
+       if (is_initial_xendomain()) {
                e820_setup_gap(machine_e820, memmap.nr_entries);
                free_bootmem(__pa(machine_e820), PAGE_SIZE);
        }
-#elif !defined(CONFIG_XEN)
+#else
        e820_setup_gap(e820.map, e820.nr_map);
 #endif
 
@@ -957,11 +977,7 @@ void __init setup_arch(char **cmdline_p)
                set_iopl.iopl = 1;
                HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
 
-               if (xen_start_info->flags & SIF_INITDOMAIN) {
-                       if (!(xen_start_info->flags & SIF_PRIVILEGED))
-                               panic("Xen granted us console access "
-                                     "but not privileged status");
-                      
+               if (is_initial_xendomain()) {
 #ifdef CONFIG_VT
 #if defined(CONFIG_VGA_CONSOLE)
                        conswitchp = &vga_con;
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c
--- a/linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c    Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c    Wed Aug 23 11:11:27 
2006 -0600
@@ -529,7 +529,7 @@ void __init xen_init_pt(void)
                mk_kernel_pgd(__pa_symbol(level3_kernel_pgt));
        level3_kernel_pgt[pud_index(__START_KERNEL_map)] = 
                __pud(__pa_symbol(level2_kernel_pgt) |
-                     _KERNPG_TABLE | _PAGE_USER);
+                     _KERNPG_TABLE);
        memcpy((void *)level2_kernel_pgt, page, PAGE_SIZE);
 
        early_make_page_readonly(init_level4_pgt,
@@ -578,7 +578,7 @@ void __init extend_init_mapping(unsigned
                        pte_page = alloc_static_page(&phys);
                        early_make_page_readonly(
                                pte_page, XENFEAT_writable_page_tables);
-                       set_pmd(pmd, __pmd(phys | _KERNPG_TABLE | _PAGE_USER));
+                       set_pmd(pmd, __pmd(phys | _KERNPG_TABLE));
                } else {
                        addr = page[pmd_index(va)];
                        addr_to_page(addr, pte_page);
@@ -587,7 +587,7 @@ void __init extend_init_mapping(unsigned
                if (pte_none(*pte)) {
                        new_pte = pfn_pte(
                                (va - __START_KERNEL_map) >> PAGE_SHIFT, 
-                               __pgprot(_KERNPG_TABLE | _PAGE_USER));
+                               __pgprot(_KERNPG_TABLE));
                        xen_l1_entry_update(pte, new_pte);
                }
                va += PAGE_SIZE;
@@ -789,7 +789,7 @@ void __init paging_init(void)
 
        /* Setup mapping of lower 1st MB */
        for (i = 0; i < NR_FIX_ISAMAPS; i++)
-               if (xen_start_info->flags & SIF_PRIVILEGED)
+               if (is_initial_xendomain())
                        set_fixmap(FIX_ISAMAP_BEGIN - i, i * PAGE_SIZE);
                else
                        __set_fixmap(FIX_ISAMAP_BEGIN - i,
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c
--- a/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c   Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c   Wed Aug 23 11:11:27 
2006 -0600
@@ -343,7 +343,6 @@ static void backend_changed(struct xenbu
        case XenbusStateInitialising:
        case XenbusStateInitWait:
        case XenbusStateInitialised:
-       case XenbusStateUnknown:
                break;
 
        case XenbusStateConnected:
@@ -354,10 +353,10 @@ static void backend_changed(struct xenbu
                tpmif_set_connected_state(tp, 0);
                break;
 
+       case XenbusStateUnknown:
        case XenbusStateClosed:
-               if (tp->is_suspended == 0) {
+               if (tp->is_suspended == 0)
                        device_unregister(&dev->dev);
-               }
                xenbus_switch_state(dev, XenbusStateClosed);
                break;
        }
@@ -718,9 +717,8 @@ static int __init tpmif_init(void)
        long rc = 0;
        struct tpm_private *tp;
 
-       if ((xen_start_info->flags & SIF_INITDOMAIN)) {
+       if (is_initial_xendomain())
                return -EPERM;
-       }
 
        tp = tpm_private_get();
        if (!tp) {
diff -r 91169603a8e8 -r 79afceca9065 linux-2.6-xen-sparse/drivers/xen/Kconfig
--- a/linux-2.6-xen-sparse/drivers/xen/Kconfig  Tue Aug 22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/Kconfig  Wed Aug 23 11:11:27 2006 -0600
@@ -13,7 +13,7 @@ if XEN
 if XEN
 config XEN_INTERFACE_VERSION
        hex
-       default 0x00030202
+       default 0x00030203
 
 menu "XEN"
 
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c
--- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c        Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c        Wed Aug 23 
11:11:27 2006 -0600
@@ -76,7 +76,7 @@ static unsigned long target_pages;
 static unsigned long target_pages;
 
 /* We increase/decrease in batches which fit in a page */
-static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)]; 
+static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)];
 
 /* VM /proc information for memory */
 extern unsigned long totalram_pages;
@@ -440,20 +440,16 @@ static int balloon_read(char *page, char
                "Requested target:   %8lu kB\n"
                "Low-mem balloon:    %8lu kB\n"
                "High-mem balloon:   %8lu kB\n"
+               "Driver pages:       %8lu kB\n"
                "Xen hard limit:     ",
                PAGES2KB(current_pages), PAGES2KB(target_pages), 
-               PAGES2KB(balloon_low), PAGES2KB(balloon_high));
-
-       if (hard_limit != ~0UL) {
-               len += sprintf(
-                       page + len, 
-                       "%8lu kB (inc. %8lu kB driver headroom)\n",
-                       PAGES2KB(hard_limit), PAGES2KB(driver_pages));
-       } else {
-               len += sprintf(
-                       page + len,
-                       "     ??? kB\n");
-       }
+               PAGES2KB(balloon_low), PAGES2KB(balloon_high),
+               PAGES2KB(driver_pages));
+
+       if (hard_limit != ~0UL)
+               len += sprintf(page + len, "%8lu kB\n", PAGES2KB(hard_limit));
+       else
+               len += sprintf(page + len, "     ??? kB\n");
 
        *eof = 1;
        return len;
@@ -610,8 +606,21 @@ void balloon_dealloc_empty_page_range(
        schedule_work(&balloon_worker);
 }
 
+void balloon_release_driver_page(struct page *page)
+{
+       unsigned long flags;
+
+       balloon_lock(flags);
+       balloon_append(page);
+       driver_pages--;
+       balloon_unlock(flags);
+
+       schedule_work(&balloon_worker);
+}
+
 EXPORT_SYMBOL_GPL(balloon_update_driver_allowance);
 EXPORT_SYMBOL_GPL(balloon_alloc_empty_page_range);
 EXPORT_SYMBOL_GPL(balloon_dealloc_empty_page_range);
+EXPORT_SYMBOL_GPL(balloon_release_driver_page);
 
 MODULE_LICENSE("Dual BSD/GPL");
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c        Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c        Wed Aug 23 
11:11:27 2006 -0600
@@ -341,7 +341,7 @@ static void dispatch_rw_block_io(blkif_t
                                 blkif_request_t *req,
                                 pending_req_t *pending_req)
 {
-       extern void ll_rw_block(int rw, int nr, struct buffer_head * bhs[]); 
+       extern void ll_rw_block(int rw, int nr, struct buffer_head * bhs[]);
        int operation = (req->operation == BLKIF_OP_WRITE) ? WRITE : READ;
        struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST];
        struct phys_req preq;
@@ -409,7 +409,7 @@ static void dispatch_rw_block_io(blkif_t
                DPRINTK("access denied: %s of [%llu,%llu] on dev=%04x\n", 
                        operation == READ ? "read" : "write",
                        preq.sector_number,
-                       preq.sector_number + preq.nr_sects, preq.dev); 
+                       preq.sector_number + preq.nr_sects, preq.dev);
                goto fail_flush;
        }
 
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/blkback/common.h
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Wed Aug 23 11:11:27 
2006 -0600
@@ -55,9 +55,9 @@ struct vbd {
        unsigned char  type;        /* VDISK_xxx */
        u32            pdevice;     /* phys device that this vbd maps to */
        struct block_device *bdev;
-}; 
+};
 
-struct backend_info; 
+struct backend_info;
 
 typedef struct blkif_st {
        /* Unique identifier for this interface. */
@@ -72,7 +72,7 @@ typedef struct blkif_st {
        /* The VBD attached to this interface. */
        struct vbd        vbd;
        /* Back pointer to the backend_info. */
-       struct backend_info *be; 
+       struct backend_info *be;
        /* Private fields. */
        spinlock_t       blk_ring_lock;
        atomic_t         refcnt;
@@ -122,7 +122,7 @@ struct phys_req {
        blkif_sector_t       sector_number;
 };
 
-int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation); 
+int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation);
 
 void blkif_interface_init(void);
 
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Wed Aug 23 11:11:27 
2006 -0600
@@ -194,7 +194,7 @@ static int blkback_probe(struct xenbus_d
        }
 
        /* setup back pointer */
-       be->blkif->be = be; 
+       be->blkif->be = be;
 
        err = xenbus_watch_path2(dev, dev->nodename, "physical-device",
                                 &be->backend_watch, backend_changed);
@@ -287,7 +287,7 @@ static void backend_changed(struct xenbu
                }
 
                /* We're potentially connected now */
-               update_blkif_status(be->blkif); 
+               update_blkif_status(be->blkif);
        }
 }
 
@@ -305,6 +305,11 @@ static void frontend_changed(struct xenb
 
        switch (frontend_state) {
        case XenbusStateInitialising:
+               if (dev->state == XenbusStateClosing) {
+                       printk("%s: %s: prepare for reconnect\n",
+                              __FUNCTION__, dev->nodename);
+                       xenbus_switch_state(dev, XenbusStateInitWait);
+               }
                break;
 
        case XenbusStateInitialised:
@@ -326,12 +331,11 @@ static void frontend_changed(struct xenb
                xenbus_switch_state(dev, XenbusStateClosing);
                break;
 
+       case XenbusStateUnknown:
        case XenbusStateClosed:
                device_unregister(&dev->dev);
                break;
 
-       case XenbusStateUnknown:
-       case XenbusStateInitWait:
        default:
                xenbus_dev_fatal(dev, -EINVAL, "saw state %d at frontend",
                                 frontend_state);
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c      Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c      Wed Aug 23 
11:11:27 2006 -0600
@@ -46,6 +46,7 @@
 #include <xen/interface/grant_table.h>
 #include <xen/gnttab.h>
 #include <asm/hypervisor.h>
+#include <asm/maddr.h>
 
 #define BLKIF_STATE_DISCONNECTED 0
 #define BLKIF_STATE_CONNECTED    1
@@ -255,10 +256,10 @@ static void backend_changed(struct xenbu
        DPRINTK("blkfront:backend_changed.\n");
 
        switch (backend_state) {
-       case XenbusStateUnknown:
        case XenbusStateInitialising:
        case XenbusStateInitWait:
        case XenbusStateInitialised:
+       case XenbusStateUnknown:
        case XenbusStateClosed:
                break;
 
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c  Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c  Wed Aug 23 11:11:27 
2006 -0600
@@ -157,7 +157,7 @@ typedef unsigned int PEND_RING_IDX;
 typedef unsigned int PEND_RING_IDX;
 
 static inline int MASK_PEND_IDX(int i) { 
-       return (i & (MAX_PENDING_REQS-1)); 
+       return (i & (MAX_PENDING_REQS-1));
 }
 
 static inline unsigned int RTN_PEND_IDX(pending_req_t *req, int idx) {
@@ -754,7 +754,7 @@ static int req_increase(void)
        if (!pending_reqs[mmap_alloc] || !pending_addrs[mmap_alloc]) {
                kfree(pending_reqs[mmap_alloc]);
                kfree(pending_addrs[mmap_alloc]);
-               WPRINTK("%s: out of memory\n", __FUNCTION__); 
+               WPRINTK("%s: out of memory\n", __FUNCTION__);
                ret = -ENOMEM;
                goto done;
        }
@@ -1051,7 +1051,7 @@ static int blktap_read_ufe_ring(int idx)
                        unsigned long kvaddr, uvaddr;
                        struct page **map = info->vma->vm_private_data;
                        struct page *pg;
-                       int offset; 
+                       int offset;
 
                        uvaddr  = MMAP_VADDR(info->user_vstart, usr_idx, j);
                        kvaddr = MMAP_VADDR(mmap_start[mmap_idx].start, 
@@ -1063,7 +1063,7 @@ static int blktap_read_ufe_ring(int idx)
                                >> PAGE_SHIFT;
                        map[offset] = NULL;
                }
-               fast_flush_area(pending_req, pending_idx, usr_idx, idx); 
+               fast_flush_area(pending_req, pending_idx, usr_idx, idx);
                make_response(blkif, pending_req->id, resp->operation,
                              resp->status);
                info->idx_map[usr_idx] = INVALID_REQ;
@@ -1118,7 +1118,7 @@ static int do_block_io_op(blkif_t *blkif
                               "ring does not exist!\n");
                        print_dbug = 0; /*We only print this message once*/
                }
-               return 1; 
+               return 1;
        }
 
        info = tapfds[blkif->dev_num];
@@ -1185,7 +1185,7 @@ static void dispatch_rw_block_io(blkif_t
                                 blkif_request_t *req,
                                 pending_req_t *pending_req)
 {
-       extern void ll_rw_block(int rw, int nr, struct buffer_head * bhs[]); 
+       extern void ll_rw_block(int rw, int nr, struct buffer_head * bhs[]);
        int op, operation = (req->operation == BLKIF_OP_WRITE) ? WRITE : READ;
        struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST*2];
        unsigned int nseg;
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/blktap/common.h
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h  Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h  Wed Aug 23 11:11:27 
2006 -0600
@@ -49,7 +49,7 @@
 
 #define WPRINTK(fmt, args...) printk(KERN_WARNING "blk_tap: " fmt, ##args)
 
-struct backend_info; 
+struct backend_info;
 
 typedef struct blkif_st {
        /* Unique identifier for this interface. */
@@ -62,7 +62,7 @@ typedef struct blkif_st {
        blkif_back_ring_t blk_ring;
        struct vm_struct *blk_ring_area;
        /* Back pointer to the backend_info. */
-       struct backend_info *be; 
+       struct backend_info *be;
        /* Private fields. */
        spinlock_t       blk_ring_lock;
        atomic_t         refcnt;
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c  Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c  Wed Aug 23 11:11:27 
2006 -0600
@@ -174,7 +174,7 @@ static int blktap_probe(struct xenbus_de
        }
 
        /* setup back pointer */
-       be->blkif->be = be; 
+       be->blkif->be = be;
        be->blkif->sectors = 0;
 
        /* set a watch on disk info, waiting for userspace to update details*/
@@ -267,12 +267,11 @@ static void tap_frontend_changed(struct 
                xenbus_switch_state(dev, XenbusStateClosing);
                break;
 
+       case XenbusStateUnknown:
        case XenbusStateClosed:
                device_unregister(&dev->dev);
                break;
 
-       case XenbusStateUnknown:
-       case XenbusStateInitWait:
        default:
                xenbus_dev_fatal(dev, -EINVAL, "saw state %d at frontend",
                                 frontend_state);
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/console/console.c
--- a/linux-2.6-xen-sparse/drivers/xen/console/console.c        Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/console/console.c        Wed Aug 23 
11:11:27 2006 -0600
@@ -178,7 +178,7 @@ static struct tty_driver *kcons_device(s
 
 static struct console kcons_info = {
        .device = kcons_device,
-       .flags  = CON_PRINTBUFFER,
+       .flags  = CON_PRINTBUFFER | CON_ENABLED,
        .index  = -1,
 };
 
@@ -188,12 +188,10 @@ static int __init xen_console_init(void)
        if (!is_running_on_xen())
                return __RETCODE;
 
-       if (xen_start_info->flags & SIF_INITDOMAIN) {
+       if (is_initial_xendomain()) {
                if (xc_mode == XC_DEFAULT)
                        xc_mode = XC_SERIAL;
                kcons_info.write = kcons_write_dom0;
-               if (xc_mode == XC_SERIAL)
-                       kcons_info.flags |= CON_ENABLED;
        } else {
                if (xc_mode == XC_DEFAULT)
                        xc_mode = XC_TTY;
@@ -249,7 +247,7 @@ void xencons_force_flush(void)
        int sz;
 
        /* Emergency console is synchronous, so there's nothing to flush. */
-       if (xen_start_info->flags & SIF_INITDOMAIN)
+       if (is_initial_xendomain())
                return;
 
        /* Spin until console data is flushed through to the daemon. */
@@ -320,7 +318,7 @@ static void __xencons_tx_flush(void)
        int sent, sz, work_done = 0;
 
        if (x_char) {
-               if (xen_start_info->flags & SIF_INITDOMAIN)
+               if (is_initial_xendomain())
                        kcons_write_dom0(NULL, &x_char, 1);
                else
                        while (x_char)
@@ -334,7 +332,7 @@ static void __xencons_tx_flush(void)
                sz = wp - wc;
                if (sz > (wbuf_size - WBUF_MASK(wc)))
                        sz = wbuf_size - WBUF_MASK(wc);
-               if (xen_start_info->flags & SIF_INITDOMAIN) {
+               if (is_initial_xendomain()) {
                        kcons_write_dom0(NULL, &wbuf[WBUF_MASK(wc)], sz);
                        wc += sz;
                } else {
@@ -624,7 +622,7 @@ static int __init xencons_init(void)
                return rc;
        }
 
-       if (xen_start_info->flags & SIF_INITDOMAIN) {
+       if (is_initial_xendomain()) {
                xencons_priv_irq = bind_virq_to_irqhandler(
                        VIRQ_CONSOLE,
                        0,
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c
--- a/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c   Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c   Wed Aug 23 
11:11:27 2006 -0600
@@ -52,13 +52,13 @@ static int xencons_irq;
 
 static inline struct xencons_interface *xencons_interface(void)
 {
-       return mfn_to_virt(xen_start_info->console_mfn);
+       return mfn_to_virt(xen_start_info->console.domU.mfn);
 }
 
 static inline void notify_daemon(void)
 {
        /* Use evtchn: this is called early, before irq is set up. */
-       notify_remote_via_evtchn(xen_start_info->console_evtchn);
+       notify_remote_via_evtchn(xen_start_info->console.domU.evtchn);
 }
 
 int xencons_ring_send(const char *data, unsigned len)
@@ -116,11 +116,11 @@ int xencons_ring_init(void)
                unbind_from_irqhandler(xencons_irq, NULL);
        xencons_irq = 0;
 
-       if (!xen_start_info->console_evtchn)
+       if (!xen_start_info->console.domU.evtchn)
                return 0;
 
        err = bind_evtchn_to_irqhandler(
-               xen_start_info->console_evtchn,
+               xen_start_info->console.domU.evtchn,
                handle_input, 0, "xencons", NULL);
        if (err <= 0) {
                printk(KERN_ERR "XEN console request irq failed %i\n", err);
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/core/cpu_hotplug.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/cpu_hotplug.c       Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/core/cpu_hotplug.c       Wed Aug 23 
11:11:27 2006 -0600
@@ -92,7 +92,7 @@ static int setup_cpu_watcher(struct noti
                .flags = XBWF_new_thread };
        (void)register_xenbus_watch(&cpu_watch);
 
-       if (!(xen_start_info->flags & SIF_INITDOMAIN)) {
+       if (!is_initial_xendomain()) {
                for_each_cpu(i)
                        vcpu_hotplug(i);
                printk(KERN_INFO "Brought up %ld CPUs\n",
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/core/evtchn.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/evtchn.c    Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/core/evtchn.c    Wed Aug 23 11:11:27 
2006 -0600
@@ -840,8 +840,7 @@ void __init xen_init_IRQ(void)
 
 #ifdef RTC_IRQ
                /* If not domain 0, force our RTC driver to fail its probe. */
-               if ((i == RTC_IRQ) &&
-                   !(xen_start_info->flags & SIF_INITDOMAIN))
+               if ((i == RTC_IRQ) && !is_initial_xendomain())
                        continue;
 #endif
 
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/core/gnttab.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/gnttab.c    Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/core/gnttab.c    Wed Aug 23 11:11:27 
2006 -0600
@@ -41,6 +41,8 @@
 #include <asm/pgtable.h>
 #include <asm/uaccess.h>
 #include <asm/synch_bitops.h>
+#include <asm/io.h>
+#include <xen/interface/memory.h>
 
 /* External tools reserve first few grant table entries. */
 #define NR_RESERVED_ENTRIES 8
@@ -350,6 +352,8 @@ void gnttab_cancel_free_callback(struct 
 }
 EXPORT_SYMBOL_GPL(gnttab_cancel_free_callback);
 
+#ifdef CONFIG_XEN
+
 #ifndef __ia64__
 static int map_pte_fn(pte_t *pte, struct page *pmd_page,
                      unsigned long addr, void *data)
@@ -410,17 +414,53 @@ int gnttab_resume(void)
 
 int gnttab_suspend(void)
 {
-
 #ifndef __ia64__
        apply_to_page_range(&init_mm, (unsigned long)shared,
                            PAGE_SIZE * NR_GRANT_FRAMES,
                            unmap_pte_fn, NULL);
 #endif
-
-       return 0;
-}
-
-static int __init gnttab_init(void)
+       return 0;
+}
+
+#else /* !CONFIG_XEN */
+
+#include <platform-pci.h>
+
+int gnttab_resume(void)
+{
+       unsigned long frames;
+       struct xen_add_to_physmap xatp;
+       unsigned int i;
+
+       frames = alloc_xen_mmio(PAGE_SIZE * NR_GRANT_FRAMES);
+
+       for (i = 0; i < NR_GRANT_FRAMES; i++) {
+               xatp.domid = DOMID_SELF;
+               xatp.idx = i;
+               xatp.space = XENMAPSPACE_grant_table;
+               xatp.gpfn = (frames >> PAGE_SHIFT) + i;
+               if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
+                       BUG();
+       }
+
+       shared = ioremap(frames, PAGE_SIZE * NR_GRANT_FRAMES);
+       if (shared == NULL) {
+               printk("error to ioremap gnttab share frames\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+int gnttab_suspend(void)
+{
+       iounmap(shared);
+       return 0;
+}
+
+#endif /* !CONFIG_XEN */
+
+int __init gnttab_init(void)
 {
        int i;
 
@@ -439,4 +479,6 @@ static int __init gnttab_init(void)
        return 0;
 }
 
+#ifdef CONFIG_XEN
 core_initcall(gnttab_init);
+#endif
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/core/reboot.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/reboot.c    Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/core/reboot.c    Wed Aug 23 11:11:27 
2006 -0600
@@ -106,7 +106,8 @@ static void pre_suspend(void)
        clear_fixmap(FIX_SHARED_INFO);
 
        xen_start_info->store_mfn = mfn_to_pfn(xen_start_info->store_mfn);
-       xen_start_info->console_mfn = mfn_to_pfn(xen_start_info->console_mfn);
+       xen_start_info->console.domU.mfn =
+               mfn_to_pfn(xen_start_info->console.domU.mfn);
 }
 
 static void post_suspend(void)
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/core/skbuff.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/skbuff.c    Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/core/skbuff.c    Wed Aug 23 11:11:27 
2006 -0600
@@ -121,8 +121,7 @@ static int __init skbuff_init(void)
        for (order = 0; order <= MAX_SKBUFF_ORDER; order++) {
                size = PAGE_SIZE << order;
                sprintf(name[order], "xen-skb-%lu", size);
-               if (is_running_on_xen() &&
-                   (xen_start_info->flags & SIF_PRIVILEGED))
+               if (is_running_on_xen() && is_initial_xendomain())
                        skbuff_order_cachep[order] = kmem_cache_create(
                                name[order], size, size, 0,
                                skbuff_ctor, skbuff_dtor);
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/core/smpboot.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/smpboot.c   Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/core/smpboot.c   Wed Aug 23 11:11:27 
2006 -0600
@@ -255,7 +255,14 @@ void __init smp_prepare_cpus(unsigned in
 
        xen_smp_intr_init(0);
 
-       for_each_cpu_mask (cpu, cpu_possible_map) {
+       /* Restrict the possible_map according to max_cpus. */
+       while ((num_possible_cpus() > 1) && (num_possible_cpus() > max_cpus)) {
+               for (cpu = NR_CPUS-1; !cpu_isset(cpu, cpu_possible_map); cpu--)
+                       continue;
+               cpu_clear(cpu, cpu_possible_map);
+       }
+
+       for_each_cpu (cpu) {
                if (cpu == 0)
                        continue;
 
@@ -266,7 +273,8 @@ void __init smp_prepare_cpus(unsigned in
 #endif
                gdt_descr->address = get_zeroed_page(GFP_KERNEL);
                if (unlikely(!gdt_descr->address)) {
-                       printk(KERN_CRIT "CPU%d failed to allocate GDT\n", cpu);
+                       printk(KERN_CRIT "CPU%d failed to allocate GDT\n",
+                              cpu);
                        continue;
                }
                gdt_descr->size = GDT_SIZE;
@@ -294,7 +302,7 @@ void __init smp_prepare_cpus(unsigned in
                irq_ctx_init(cpu);
 
 #ifdef CONFIG_HOTPLUG_CPU
-               if (xen_start_info->flags & SIF_INITDOMAIN)
+               if (is_initial_xendomain())
                        cpu_set(cpu, cpu_present_map);
 #else
                cpu_set(cpu, cpu_present_map);
@@ -304,12 +312,6 @@ void __init smp_prepare_cpus(unsigned in
        }
 
        init_xenbus_allowed_cpumask();
-
-       /* Currently, Xen gives no dynamic NUMA/HT info. */
-       for (cpu = 1; cpu < NR_CPUS; cpu++) {
-               cpu_sibling_map[cpu] = cpumask_of_cpu(cpu);
-               cpu_core_map[cpu]    = cpumask_of_cpu(cpu);
-       }
 
 #ifdef CONFIG_X86_IO_APIC
        /*
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/netback/common.h
--- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h Wed Aug 23 11:11:27 
2006 -0600
@@ -64,9 +64,9 @@ typedef struct netif_st {
 
        /* Physical parameters of the comms window. */
        grant_handle_t   tx_shmem_handle;
-       grant_ref_t      tx_shmem_ref; 
+       grant_ref_t      tx_shmem_ref;
        grant_handle_t   rx_shmem_handle;
-       grant_ref_t      rx_shmem_ref; 
+       grant_ref_t      rx_shmem_ref;
        unsigned int     evtchn;
        unsigned int     irq;
 
@@ -78,7 +78,10 @@ typedef struct netif_st {
 
        /* Set of features that can be turned on in dev->features. */
        int features;
-       int can_queue;
+
+       /* Internal feature information. */
+       int can_queue:1;        /* can queue packets for receiver? */
+       int copying_receiver:1; /* copy packets to receiver?       */
 
        /* Allow netif_be_start_xmit() to peek ahead in the rx request ring. */
        RING_IDX rx_req_cons_peek;
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/netback/loopback.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/loopback.c       Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/loopback.c       Wed Aug 23 
11:11:27 2006 -0600
@@ -218,7 +218,7 @@ static int __init make_loopback(int i)
        return err;
 }
 
-static void __init clean_loopback(int i)
+static void __exit clean_loopback(int i)
 {
        struct net_device *dev1, *dev2;
        char dev_name[IFNAMSIZ];
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/netback/netback.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c        Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c        Wed Aug 23 
11:11:27 2006 -0600
@@ -43,6 +43,7 @@ struct netbk_rx_meta {
 struct netbk_rx_meta {
        skb_frag_t frag;
        int id;
+       int copy:1;
 };
 
 static void netif_idx_release(u16 pending_idx);
@@ -68,13 +69,11 @@ static struct timer_list net_timer;
 #define MAX_PENDING_REQS 256
 
 static struct sk_buff_head rx_queue;
-static multicall_entry_t rx_mcl[NET_RX_RING_SIZE+1];
-static mmu_update_t rx_mmu[NET_RX_RING_SIZE];
-static gnttab_transfer_t grant_rx_op[NET_RX_RING_SIZE];
-static unsigned char rx_notify[NR_IRQS];
 
 static unsigned long mmap_vstart;
 #define MMAP_VADDR(_req) (mmap_vstart + ((_req) * PAGE_SIZE))
+
+static void *rx_mmap_area;
 
 #define PKT_PROT_LEN 64
 
@@ -147,6 +146,31 @@ static inline int is_xen_skb(struct sk_b
        return (cp == skbuff_cachep);
 }
 
+/*
+ * We can flip without copying the packet unless:
+ *  1. The data is not allocated from our special cache; or
+ *  2. The main data area is shared; or
+ *  3. One or more fragments are shared; or
+ *  4. There are chained fragments.
+ */
+static inline int is_flippable_skb(struct sk_buff *skb)
+{
+       int frag;
+
+       if (!is_xen_skb(skb) || skb_cloned(skb))
+               return 0;
+
+       for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
+               if (page_count(skb_shinfo(skb)->frags[frag].page) > 1)
+                       return 0;
+       }
+
+       if (skb_shinfo(skb)->frag_list != NULL)
+               return 0;
+
+       return 1;
+}
+
 static struct sk_buff *netbk_copy_skb(struct sk_buff *skb)
 {
        struct skb_shared_info *ninfo;
@@ -156,6 +180,8 @@ static struct sk_buff *netbk_copy_skb(st
        int len;
        int headlen;
 
+       BUG_ON(skb_shinfo(skb)->frag_list != NULL);
+
        nskb = alloc_skb(SKB_MAX_HEAD(0), GFP_ATOMIC);
        if (unlikely(!nskb))
                goto err;
@@ -254,13 +280,11 @@ int netif_be_start_xmit(struct sk_buff *
                goto drop;
        }
 
-       /*
-        * We do not copy the packet unless:
-        *  1. The data is shared; or
-        *  2. The data is not allocated from our special cache.
-        *  3. The data is fragmented.
-        */
-       if (skb_cloned(skb) || skb_is_nonlinear(skb) || !is_xen_skb(skb)) {
+       /* Copy the packet here if it's destined for a flipping
+          interface but isn't flippable (e.g. extra references to
+          data)
+       */
+       if (!netif->copying_receiver && !is_flippable_skb(skb)) {
                struct sk_buff *nskb = netbk_copy_skb(skb);
                if ( unlikely(nskb == NULL) )
                        goto drop;
@@ -306,7 +330,7 @@ static void xen_network_done_notify(void
 /* 
  * Add following to poll() function in NAPI driver (Tigon3 is example):
  *  if ( xen_network_done() )
- *      tg3_enable_ints(tp); 
+ *      tg3_enable_ints(tp);
  */
 int xen_network_done(void)
 {
@@ -314,66 +338,113 @@ int xen_network_done(void)
 }
 #endif
 
-static u16 netbk_gop_frag(netif_t *netif, struct page *page, int count, int i)
-{
-       multicall_entry_t *mcl = rx_mcl + count;
-       mmu_update_t *mmu = rx_mmu + count;
-       gnttab_transfer_t *gop = grant_rx_op + count;
+struct netrx_pending_operations {
+       unsigned trans_prod, trans_cons;
+       unsigned mmu_prod, mmu_cons;
+       unsigned mcl_prod, mcl_cons;
+       unsigned copy_prod, copy_cons;
+       unsigned meta_prod, meta_cons;
+       mmu_update_t *mmu;
+       gnttab_transfer_t *trans;
+       gnttab_copy_t *copy;
+       multicall_entry_t *mcl;
+       struct netbk_rx_meta *meta;
+};
+
+/* Set up the grant operations for this fragment.  If it's a flipping
+   interface, we also set up the unmap request from here. */
+static u16 netbk_gop_frag(netif_t *netif, struct netbk_rx_meta *meta,
+                         int i, struct netrx_pending_operations *npo,
+                         struct page *page, unsigned long size,
+                         unsigned long offset)
+{
+       mmu_update_t *mmu;
+       gnttab_transfer_t *gop;
+       gnttab_copy_t *copy_gop;
+       multicall_entry_t *mcl;
        netif_rx_request_t *req;
        unsigned long old_mfn, new_mfn;
 
        old_mfn = virt_to_mfn(page_address(page));
 
-       if (!xen_feature(XENFEAT_auto_translated_physmap)) {
-               new_mfn = alloc_mfn();
-
-               /*
-                * Set the new P2M table entry before reassigning
-                * the old data page. Heed the comment in
-                * pgtable-2level.h:pte_page(). :-)
-                */
-               set_phys_to_machine(page_to_pfn(page), new_mfn);
-
-               MULTI_update_va_mapping(mcl, (unsigned long)page_address(page),
-                                       pfn_pte_ma(new_mfn, PAGE_KERNEL), 0);
-
-               mmu->ptr = ((maddr_t)new_mfn << PAGE_SHIFT) |
-                       MMU_MACHPHYS_UPDATE;
-               mmu->val = page_to_pfn(page);
-       }
-
        req = RING_GET_REQUEST(&netif->rx, netif->rx.req_cons + i);
-       gop->mfn = old_mfn;
-       gop->domid = netif->domid;
-       gop->ref = req->gref;
+       if (netif->copying_receiver) {
+               /* The fragment needs to be copied rather than
+                  flipped. */
+               meta->copy = 1;
+               copy_gop = npo->copy + npo->copy_prod++;
+               copy_gop->source.domid = DOMID_SELF;
+               copy_gop->source.offset = offset;
+               copy_gop->source.u.gmfn = old_mfn;
+               copy_gop->dest.domid = netif->domid;
+               copy_gop->dest.offset = 0;
+               copy_gop->dest.u.ref = req->gref;
+               copy_gop->len = size;
+               copy_gop->flags = GNTCOPY_dest_gref;
+       } else {
+               meta->copy = 0;
+               if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+                       new_mfn = alloc_mfn();
+
+                       /*
+                        * Set the new P2M table entry before
+                        * reassigning the old data page. Heed the
+                        * comment in pgtable-2level.h:pte_page(). :-)
+                        */
+                       set_phys_to_machine(page_to_pfn(page), new_mfn);
+
+                       mcl = npo->mcl + npo->mcl_prod++;
+                       MULTI_update_va_mapping(mcl,
+                                            (unsigned long)page_address(page),
+                                            pfn_pte_ma(new_mfn, PAGE_KERNEL),
+                                            0);
+
+                       mmu = npo->mmu + npo->mmu_prod++;
+                       mmu->ptr = ((maddr_t)new_mfn << PAGE_SHIFT) |
+                               MMU_MACHPHYS_UPDATE;
+                       mmu->val = page_to_pfn(page);
+               }
+
+               gop = npo->trans + npo->trans_prod++;
+               gop->mfn = old_mfn;
+               gop->domid = netif->domid;
+               gop->ref = req->gref;
+       }
        return req->id;
 }
 
-static void netbk_gop_skb(struct sk_buff *skb, struct netbk_rx_meta *meta,
-                         int count)
+static void netbk_gop_skb(struct sk_buff *skb,
+                         struct netrx_pending_operations *npo)
 {
        netif_t *netif = netdev_priv(skb->dev);
        int nr_frags = skb_shinfo(skb)->nr_frags;
        int i;
        int extra;
-
-       meta[count].frag.page_offset = skb_shinfo(skb)->gso_type;
-       meta[count].frag.size = skb_shinfo(skb)->gso_size;
-       extra = !!meta[count].frag.size + 1;
+       struct netbk_rx_meta *head_meta, *meta;
+
+       head_meta = npo->meta + npo->meta_prod++;
+       head_meta->frag.page_offset = skb_shinfo(skb)->gso_type;
+       head_meta->frag.size = skb_shinfo(skb)->gso_size;
+       extra = !!head_meta->frag.size + 1;
 
        for (i = 0; i < nr_frags; i++) {
-               meta[++count].frag = skb_shinfo(skb)->frags[i];
-               meta[count].id = netbk_gop_frag(netif, meta[count].frag.page,
-                                               count, i + extra);
+               meta = npo->meta + npo->meta_prod++;
+               meta->frag = skb_shinfo(skb)->frags[i];
+               meta->id = netbk_gop_frag(netif, meta, i + extra, npo,
+                                         meta->frag.page,
+                                         meta->frag.size,
+                                         meta->frag.page_offset);
        }
 
        /*
         * This must occur at the end to ensure that we don't trash
         * skb_shinfo until we're done.
         */
-       meta[count - nr_frags].id = netbk_gop_frag(netif,
-                                                  virt_to_page(skb->data),
-                                                  count - nr_frags, 0);
+       head_meta->id = netbk_gop_frag(netif, head_meta, 0, npo,
+                                      virt_to_page(skb->data),
+                                      skb_headlen(skb),
+                                      offset_in_page(skb->data));
+
        netif->rx.req_cons += nr_frags + extra;
 }
 
@@ -385,32 +456,48 @@ static inline void netbk_free_pages(int 
                put_page(meta[i].frag.page);
 }
 
-static int netbk_check_gop(int nr_frags, domid_t domid, int count)
-{
-       multicall_entry_t *mcl = rx_mcl + count;
-       gnttab_transfer_t *gop = grant_rx_op + count;
+/* This is a twin to netbk_gop_skb.  Assume that netbk_gop_skb was
+   used to set up the operations on the top of
+   netrx_pending_operations, which have since been done.  Check that
+   they didn't give any errors and advance over them. */
+static int netbk_check_gop(int nr_frags, domid_t domid,
+                          struct netrx_pending_operations *npo)
+{
+       multicall_entry_t *mcl;
+       gnttab_transfer_t *gop;
+       gnttab_copy_t     *copy_op;
        int status = NETIF_RSP_OKAY;
        int i;
 
        for (i = 0; i <= nr_frags; i++) {
-               if (!xen_feature(XENFEAT_auto_translated_physmap)) {
-                       /* The update_va_mapping() must not fail. */
-                       BUG_ON(mcl->result != 0);
-                       mcl++;
-               }
-
-               /* Check the reassignment error code. */
-               if (gop->status != 0) { 
-                       DPRINTK("Bad status %d from grant transfer to DOM%u\n",
-                               gop->status, domid);
-                       /*
-                        * Page no longer belongs to us unless GNTST_bad_page,
-                        * but that should be a fatal error anyway.
-                        */
-                       BUG_ON(gop->status == GNTST_bad_page);
-                       status = NETIF_RSP_ERROR; 
-               }
-               gop++;
+               if (npo->meta[npo->meta_cons + i].copy) {
+                       copy_op = npo->copy + npo->copy_cons++;
+                       if (copy_op->status != GNTST_okay) {
+                               DPRINTK("Bad status %d from copy to DOM%d.\n",
+                                       gop->status, domid);
+                               status = NETIF_RSP_ERROR;
+                       }
+               } else {
+                       if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+                               mcl = npo->mcl + npo->mcl_cons++;
+                               /* The update_va_mapping() must not fail. */
+                               BUG_ON(mcl->result != 0);
+                       }
+
+                       gop = npo->trans + npo->trans_cons++;
+                       /* Check the reassignment error code. */
+                       if (gop->status != 0) {
+                               DPRINTK("Bad status %d from grant transfer to 
DOM%u\n",
+                                       gop->status, domid);
+                               /*
+                                * Page no longer belongs to us unless
+                                * GNTST_bad_page, but that should be
+                                * a fatal error anyway.
+                                */
+                               BUG_ON(gop->status == GNTST_bad_page);
+                               status = NETIF_RSP_ERROR;
+                       }
+               }
        }
 
        return status;
@@ -420,23 +507,27 @@ static void netbk_add_frag_responses(net
                                     struct netbk_rx_meta *meta, int nr_frags)
 {
        int i;
+       unsigned long offset;
 
        for (i = 0; i < nr_frags; i++) {
                int id = meta[i].id;
                int flags = (i == nr_frags - 1) ? 0 : NETRXF_more_data;
 
-               make_rx_response(netif, id, status, meta[i].frag.page_offset,
+               if (meta[i].copy)
+                       offset = 0;
+               else
+                       offset = meta[i].frag.page_offset;
+               make_rx_response(netif, id, status, offset,
                                 meta[i].frag.size, flags);
        }
 }
 
 static void net_rx_action(unsigned long unused)
 {
-       netif_t *netif = NULL; 
+       netif_t *netif = NULL;
        s8 status;
        u16 id, irq, flags;
        netif_rx_response_t *resp;
-       struct netif_extra_info *extra;
        multicall_entry_t *mcl;
        struct sk_buff_head rxq;
        struct sk_buff *skb;
@@ -444,13 +535,26 @@ static void net_rx_action(unsigned long 
        int ret;
        int nr_frags;
        int count;
+       unsigned long offset;
 
        /*
         * Putting hundreds of bytes on the stack is considered rude.
         * Static works because a tasklet can only be on one CPU at any time.
         */
+       static multicall_entry_t rx_mcl[NET_RX_RING_SIZE+3];
+       static mmu_update_t rx_mmu[NET_RX_RING_SIZE];
+       static gnttab_transfer_t grant_trans_op[NET_RX_RING_SIZE];
+       static gnttab_copy_t grant_copy_op[NET_RX_RING_SIZE];
+       static unsigned char rx_notify[NR_IRQS];
        static u16 notify_list[NET_RX_RING_SIZE];
        static struct netbk_rx_meta meta[NET_RX_RING_SIZE];
+
+       struct netrx_pending_operations npo = {
+               mmu: rx_mmu,
+               trans: grant_trans_op,
+               copy: grant_copy_op,
+               mcl: rx_mcl,
+               meta: meta};
 
        skb_queue_head_init(&rxq);
 
@@ -471,7 +575,7 @@ static void net_rx_action(unsigned long 
                        break;
                }
 
-               netbk_gop_skb(skb, meta, count);
+               netbk_gop_skb(skb, &npo);
 
                count += nr_frags + 1;
 
@@ -482,43 +586,74 @@ static void net_rx_action(unsigned long 
                        break;
        }
 
-       if (!count)
-               return;
-
-       if (!xen_feature(XENFEAT_auto_translated_physmap)) {
-               mcl = rx_mcl + count;
-
+       if (npo.mcl_prod &&
+           !xen_feature(XENFEAT_auto_translated_physmap)) {
+               mcl = npo.mcl + npo.mcl_prod++;
+
+               BUG_ON(mcl[-1].op != __HYPERVISOR_update_va_mapping);
                mcl[-1].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
 
                mcl->op = __HYPERVISOR_mmu_update;
                mcl->args[0] = (unsigned long)rx_mmu;
-               mcl->args[1] = count;
+               mcl->args[1] = npo.mmu_prod;
                mcl->args[2] = 0;
                mcl->args[3] = DOMID_SELF;
-
-               ret = HYPERVISOR_multicall(rx_mcl, count + 1);
-               BUG_ON(ret != 0);
-       }
-
-       ret = HYPERVISOR_grant_table_op(GNTTABOP_transfer, grant_rx_op, count);
+       }
+
+       if (npo.trans_prod) {
+               mcl = npo.mcl + npo.mcl_prod++;
+               mcl->op = __HYPERVISOR_grant_table_op;
+               mcl->args[0] = GNTTABOP_transfer;
+               mcl->args[1] = (unsigned long)grant_trans_op;
+               mcl->args[2] = npo.trans_prod;
+       }
+
+       if (npo.copy_prod) {
+               mcl = npo.mcl + npo.mcl_prod++;
+               mcl->op = __HYPERVISOR_grant_table_op;
+               mcl->args[0] = GNTTABOP_copy;
+               mcl->args[1] = (unsigned long)grant_copy_op;
+               mcl->args[2] = npo.copy_prod;
+       }
+
+       /* Nothing to do? */
+       if (!npo.mcl_prod)
+               return;
+
+       BUG_ON(npo.copy_prod > NET_RX_RING_SIZE);
+       BUG_ON(npo.mmu_prod > NET_RX_RING_SIZE);
+       BUG_ON(npo.trans_prod > NET_RX_RING_SIZE);
+       BUG_ON(npo.mcl_prod > NET_RX_RING_SIZE+3);
+       BUG_ON(npo.meta_prod > NET_RX_RING_SIZE);
+
+       ret = HYPERVISOR_multicall(npo.mcl, npo.mcl_prod);
        BUG_ON(ret != 0);
 
-       count = 0;
        while ((skb = __skb_dequeue(&rxq)) != NULL) {
                nr_frags = *(int *)skb->cb;
 
-               atomic_set(&(skb_shinfo(skb)->dataref), 1);
-               skb_shinfo(skb)->nr_frags = 0;
-               skb_shinfo(skb)->frag_list = NULL;
-
                netif = netdev_priv(skb->dev);
+               /* We can't rely on skb_release_data to release the
+                  pages used by fragments for us, since it tries to
+                  touch the pages in the fraglist.  If we're in
+                  flipping mode, that doesn't work.  In copying mode,
+                  we still have access to all of the pages, and so
+                  it's safe to let release_data deal with it. */
+               /* (Freeing the fragments is safe since we copy
+                  non-linear skbs destined for flipping interfaces) */
+               if (!netif->copying_receiver) {
+                       atomic_set(&(skb_shinfo(skb)->dataref), 1);
+                       skb_shinfo(skb)->frag_list = NULL;
+                       skb_shinfo(skb)->nr_frags = 0;
+                       netbk_free_pages(nr_frags, meta + npo.meta_cons + 1);
+               }
+
                netif->stats.tx_bytes += skb->len;
                netif->stats.tx_packets++;
 
-               netbk_free_pages(nr_frags, meta + count + 1);
-               status = netbk_check_gop(nr_frags, netif->domid, count);
-
-               id = meta[count].id;
+               status = netbk_check_gop(nr_frags, netif->domid, &npo);
+
+               id = meta[npo.meta_cons].id;
                flags = nr_frags ? NETRXF_more_data : 0;
 
                if (skb->ip_summed == CHECKSUM_HW) /* local packet? */
@@ -526,34 +661,32 @@ static void net_rx_action(unsigned long 
                else if (skb->proto_data_valid) /* remote but checksummed? */
                        flags |= NETRXF_data_validated;
 
-               resp = make_rx_response(netif, id, status,
-                                       offset_in_page(skb->data),
+               if (meta[npo.meta_cons].copy)
+                       offset = 0;
+               else
+                       offset = offset_in_page(skb->data);
+               resp = make_rx_response(netif, id, status, offset,
                                        skb_headlen(skb), flags);
 
-               extra = NULL;
-
-               if (meta[count].frag.size) {
+               if (meta[npo.meta_cons].frag.size) {
                        struct netif_extra_info *gso =
                                (struct netif_extra_info *)
                                RING_GET_RESPONSE(&netif->rx,
                                                  netif->rx.rsp_prod_pvt++);
 
-                       if (extra)
-                               extra->flags |= XEN_NETIF_EXTRA_FLAG_MORE;
-                       else
-                               resp->flags |= NETRXF_extra_info;
-
-                       gso->u.gso.size = meta[count].frag.size;
+                       resp->flags |= NETRXF_extra_info;
+
+                       gso->u.gso.size = meta[npo.meta_cons].frag.size;
                        gso->u.gso.type = XEN_NETIF_GSO_TYPE_TCPV4;
                        gso->u.gso.pad = 0;
                        gso->u.gso.features = 0;
 
                        gso->type = XEN_NETIF_EXTRA_TYPE_GSO;
                        gso->flags = 0;
-                       extra = gso;
-               }
-
-               netbk_add_frag_responses(netif, status, meta + count + 1,
+               }
+
+               netbk_add_frag_responses(netif, status,
+                                        meta + npo.meta_cons + 1,
                                         nr_frags);
 
                RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netif->rx, ret);
@@ -569,7 +702,7 @@ static void net_rx_action(unsigned long 
 
                netif_put(netif);
                dev_kfree_skb(skb);
-               count += nr_frags + 1;
+               npo.meta_cons += nr_frags + 1;
        }
 
        while (notify_nr != 0) {
@@ -1029,7 +1162,7 @@ static void net_tx_action(unsigned long 
                if (unlikely(txreq.size < ETH_HLEN)) {
                        DPRINTK("Bad packet size: %d\n", txreq.size);
                        netbk_tx_err(netif, &txreq, i);
-                       continue; 
+                       continue;
                }
 
                /* No crossing a page as the payload mustn't fragment. */
@@ -1085,6 +1218,9 @@ static void net_tx_action(unsigned long 
                        skb_shinfo(skb)->nr_frags++;
                        skb_shinfo(skb)->frags[0].page =
                                (void *)(unsigned long)pending_idx;
+               } else {
+                       /* Discriminate from any valid pending_idx value. */
+                       skb_shinfo(skb)->frags[0].page = (void *)~0UL;
                }
 
                __skb_queue_tail(&tx_queue, skb);
@@ -1185,6 +1321,12 @@ static void netif_page_release(struct pa
        set_page_count(page, 1);
 
        netif_idx_release(pending_idx);
+}
+
+static void netif_rx_page_release(struct page *page)
+{
+       /* Ready for next use. */
+       set_page_count(page, 1);
 }
 
 irqreturn_t netif_be_int(int irq, void *dev_id, struct pt_regs *regs)
@@ -1317,6 +1459,16 @@ static int __init netback_init(void)
                SetPageForeign(page, netif_page_release);
        }
 
+       page = balloon_alloc_empty_page_range(NET_RX_RING_SIZE);
+       BUG_ON(page == NULL);
+       rx_mmap_area = pfn_to_kaddr(page_to_pfn(page));
+
+       for (i = 0; i < NET_RX_RING_SIZE; i++) {
+               page = virt_to_page(rx_mmap_area + (i * PAGE_SIZE));
+               set_page_count(page, 1);
+               SetPageForeign(page, netif_rx_page_release);
+       }
+
        pending_cons = 0;
        pending_prod = MAX_PENDING_REQS;
        for (i = 0; i < MAX_PENDING_REQS; i++)
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c Wed Aug 23 11:11:27 
2006 -0600
@@ -108,6 +108,12 @@ static int netback_probe(struct xenbus_d
                        goto abort_transaction;
                }
 
+               err = xenbus_printf(xbt, dev->nodename, "feature-rx-copy", 
"%d", 1);
+               if (err) {
+                       message = "writing feature-copying";
+                       goto abort_transaction;
+               }
+
                err = xenbus_transaction_end(xbt, 0);
        } while (err == -EAGAIN);
 
@@ -228,10 +234,25 @@ static void frontend_changed(struct xenb
 
        switch (frontend_state) {
        case XenbusStateInitialising:
+               if (dev->state == XenbusStateClosing) {
+                       printk("%s: %s: prepare for reconnect\n",
+                              __FUNCTION__, dev->nodename);
+                       if (be->netif) {
+                               netif_disconnect(be->netif);
+                               be->netif = NULL;
+                       }
+                       xenbus_switch_state(dev, XenbusStateInitWait);
+               }
+               break;
+
        case XenbusStateInitialised:
                break;
 
        case XenbusStateConnected:
+               if (!be->netif) {
+                       /* reconnect: setup be->netif */
+                       backend_changed(&be->backend_watch, NULL, 0);
+               }
                maybe_connect(be);
                break;
 
@@ -239,14 +260,13 @@ static void frontend_changed(struct xenb
                xenbus_switch_state(dev, XenbusStateClosing);
                break;
 
+       case XenbusStateUnknown:
        case XenbusStateClosed:
                if (be->netif != NULL)
                        kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
                device_unregister(&dev->dev);
                break;
 
-       case XenbusStateUnknown:
-       case XenbusStateInitWait:
        default:
                xenbus_dev_fatal(dev, -EINVAL, "saw state %d at frontend",
                                 frontend_state);
@@ -349,7 +369,7 @@ static int connect_rings(struct backend_
 {
        struct xenbus_device *dev = be->dev;
        unsigned long tx_ring_ref, rx_ring_ref;
-       unsigned int evtchn;
+       unsigned int evtchn, rx_copy;
        int err;
        int val;
 
@@ -365,6 +385,19 @@ static int connect_rings(struct backend_
                                 dev->otherend);
                return err;
        }
+
+       err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy", "%u",
+                          &rx_copy);
+       if (err == -ENOENT) {
+               err = 0;
+               rx_copy = 0;
+       }
+       if (err < 0) {
+               xenbus_dev_fatal(dev, err, "reading %s/request-rx-copy",
+                                dev->otherend);
+               return err;
+       }
+       be->netif->copying_receiver = !!rx_copy;
 
        if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-rx-notify", "%d",
                         &val) < 0)
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c      Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c      Wed Aug 23 
11:11:27 2006 -0600
@@ -58,12 +58,27 @@
 #include <xen/interface/memory.h>
 #include <xen/balloon.h>
 #include <asm/page.h>
+#include <asm/maddr.h>
 #include <asm/uaccess.h>
 #include <xen/interface/grant_table.h>
 #include <xen/gnttab.h>
 
 #define RX_COPY_THRESHOLD 256
 
+/* If we don't have GSO, fake things up so that we never try to use it. */
+#ifndef NETIF_F_GSO
+#define netif_needs_gso(dev, skb)      0
+#define dev_disable_gso_features(dev)  ((void)0)
+#else
+#define HAVE_GSO                       1
+static inline void dev_disable_gso_features(struct net_device *dev)
+{
+       /* Turn off all GSO bits except ROBUST. */
+       dev->features &= (1 << NETIF_F_GSO_SHIFT) - 1;
+       dev->features |= NETIF_F_GSO_ROBUST;
+}
+#endif
+
 #define GRANT_INVALID_REF      0
 
 #define NET_TX_RING_SIZE __RING_SIZE((struct netif_tx_sring *)0, PAGE_SIZE)
@@ -83,6 +98,7 @@ struct netfront_info {
 
        unsigned int handle;
        unsigned int evtchn, irq;
+       unsigned int copying_receiver;
 
        /* Receive-ring batched refills. */
 #define RX_MIN_TARGET 8
@@ -171,7 +187,7 @@ static inline grant_ref_t xennet_get_rx_
 
 static int talk_to_backend(struct xenbus_device *, struct netfront_info *);
 static int setup_device(struct xenbus_device *, struct netfront_info *);
-static struct net_device *create_netdev(int, struct xenbus_device *);
+static struct net_device *create_netdev(int, int, struct xenbus_device *);
 
 static void netfront_closing(struct xenbus_device *);
 
@@ -213,6 +229,7 @@ static int __devinit netfront_probe(stru
        struct net_device *netdev;
        struct netfront_info *info;
        unsigned int handle;
+       unsigned feature_rx_copy;
 
        err = xenbus_scanf(XBT_NIL, dev->nodename, "handle", "%u", &handle);
        if (err != 1) {
@@ -220,7 +237,22 @@ static int __devinit netfront_probe(stru
                return err;
        }
 
-       netdev = create_netdev(handle, dev);
+#ifndef CONFIG_XEN
+       err = xenbus_scanf(XBT_NIL, dev->otherend, "feature-rx-copy", "%u",
+                          &feature_rx_copy);
+       if (err != 1) {
+               xenbus_dev_fatal(dev, err, "reading feature-rx-copy");
+               return err;
+       }
+       if (!feature_rx_copy) {
+               xenbus_dev_fatal(dev, 0, "need a copy-capable backend");
+               return -EINVAL;
+       }
+#else
+       feature_rx_copy = 0;
+#endif
+
+       netdev = create_netdev(handle, feature_rx_copy, dev);
        if (IS_ERR(netdev)) {
                err = PTR_ERR(netdev);
                xenbus_dev_fatal(dev, err, "creating netdev");
@@ -326,6 +358,13 @@ again:
                goto abort_transaction;
        }
 
+       err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u",
+                           info->copying_receiver);
+       if (err) {
+               message = "writing request-rx-copy";
+               goto abort_transaction;
+       }
+
        err = xenbus_printf(xbt, dev->nodename, "feature-rx-notify", "%d", 1);
        if (err) {
                message = "writing feature-rx-notify";
@@ -338,11 +377,13 @@ again:
                goto abort_transaction;
        }
 
+#ifdef HAVE_GSO
        err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4", "%d", 1);
        if (err) {
                message = "writing feature-gso-tcpv4";
                goto abort_transaction;
        }
+#endif
 
        err = xenbus_transaction_end(xbt, 0);
        if (err) {
@@ -415,7 +456,8 @@ static int setup_device(struct xenbus_de
 
        memcpy(netdev->dev_addr, info->mac, ETH_ALEN);
        err = bind_evtchn_to_irqhandler(info->evtchn, netif_int,
-                                       SA_SAMPLE_RANDOM, netdev->name, netdev);
+                                       SA_SAMPLE_RANDOM, netdev->name,
+                                       netdev);
        if (err < 0)
                goto fail;
        info->irq = err;
@@ -494,11 +536,14 @@ static int network_open(struct net_devic
 
        memset(&np->stats, 0, sizeof(np->stats));
 
-       network_alloc_rx_buffers(dev);
-       np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
-
-       if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
-               netif_rx_schedule(dev);
+       spin_lock(&np->rx_lock);
+       if (netif_carrier_ok(dev)) {
+               network_alloc_rx_buffers(dev);
+               np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
+               if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
+                       netif_rx_schedule(dev);
+       }
+       spin_unlock(&np->rx_lock);
 
        netif_start_queue(dev);
 
@@ -527,8 +572,7 @@ static void network_tx_buf_gc(struct net
        struct netfront_info *np = netdev_priv(dev);
        struct sk_buff *skb;
 
-       if (unlikely(!netif_carrier_ok(dev)))
-               return;
+       BUG_ON(!netif_carrier_ok(dev));
 
        do {
                prod = np->tx.sring->rsp_prod;
@@ -597,6 +641,8 @@ static void network_alloc_rx_buffers(str
        grant_ref_t ref;
        unsigned long pfn;
        void *vaddr;
+       int nr_flips;
+       netif_rx_request_t *req;
 
        if (unlikely(!netif_carrier_ok(dev)))
                return;
@@ -609,9 +655,14 @@ static void network_alloc_rx_buffers(str
         */
        batch_target = np->rx_target - (req_prod - np->rx.rsp_cons);
        for (i = skb_queue_len(&np->rx_batch); i < batch_target; i++) {
-               /* Allocate an skb and a page. */
-               skb = __dev_alloc_skb(RX_COPY_THRESHOLD,
-                                     GFP_ATOMIC | __GFP_NOWARN);
+               /*
+                * Allocate an skb and a page. Do not use __dev_alloc_skb as
+                * that will allocate page-sized buffers which is not
+                * necessary here.
+                * 16 bytes added as necessary headroom for netif_receive_skb.
+                */
+               skb = alloc_skb(RX_COPY_THRESHOLD + 16,
+                               GFP_ATOMIC | __GFP_NOWARN);
                if (unlikely(!skb))
                        goto no_skb;
 
@@ -628,6 +679,7 @@ no_skb:
                        break;
                }
 
+               skb_reserve(skb, 16); /* mimic dev_alloc_skb() */
                skb_shinfo(skb)->frags[0].page = page;
                skb_shinfo(skb)->nr_frags = 1;
                __skb_queue_tail(&np->rx_batch, skb);
@@ -646,7 +698,7 @@ no_skb:
                np->rx_target = np->rx_max_target;
 
  refill:
-       for (i = 0; ; i++) {
+       for (nr_flips = i = 0; ; i++) {
                if ((skb = __skb_dequeue(&np->rx_batch)) == NULL)
                        break;
 
@@ -657,7 +709,6 @@ no_skb:
                BUG_ON(np->rx_skbs[id]);
                np->rx_skbs[id] = skb;
 
-               RING_GET_REQUEST(&np->rx, req_prod + i)->id = id;
                ref = gnttab_claim_grant_reference(&np->gref_rx_head);
                BUG_ON((signed short)ref < 0);
                np->grant_rx_ref[id] = ref;
@@ -665,49 +716,68 @@ no_skb:
                pfn = page_to_pfn(skb_shinfo(skb)->frags[0].page);
                vaddr = page_address(skb_shinfo(skb)->frags[0].page);
 
-               gnttab_grant_foreign_transfer_ref(ref,
-                                                 np->xbdev->otherend_id, pfn);
-               RING_GET_REQUEST(&np->rx, req_prod + i)->gref = ref;
-               np->rx_pfn_array[i] = pfn_to_mfn(pfn);
+               req = RING_GET_REQUEST(&np->rx, req_prod + i);
+               if (!np->copying_receiver) {
+                       gnttab_grant_foreign_transfer_ref(ref,
+                                                         
np->xbdev->otherend_id,
+                                                         pfn);
+                       np->rx_pfn_array[nr_flips] = pfn_to_mfn(pfn);
+                       if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+                               /* Remove this page before passing
+                                * back to Xen. */
+                               set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
+                               MULTI_update_va_mapping(np->rx_mcl+i,
+                                                       (unsigned long)vaddr,
+                                                       __pte(0), 0);
+                       }
+                       nr_flips++;
+               } else {
+                       gnttab_grant_foreign_access_ref(ref,
+                                                       np->xbdev->otherend_id,
+                                                       pfn,
+                                                       0);
+               }
+
+               req->id = id;
+               req->gref = ref;
+       }
+
+       if ( nr_flips != 0 ) {
+               /* Tell the ballon driver what is going on. */
+               balloon_update_driver_allowance(i);
+
+               set_xen_guest_handle(reservation.extent_start,
+                                    np->rx_pfn_array);
+               reservation.nr_extents   = nr_flips;
+               reservation.extent_order = 0;
+               reservation.address_bits = 0;
+               reservation.domid        = DOMID_SELF;
 
                if (!xen_feature(XENFEAT_auto_translated_physmap)) {
-                       /* Remove this page before passing back to Xen. */
-                       set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
-                       MULTI_update_va_mapping(np->rx_mcl+i,
-                                               (unsigned long)vaddr,
-                                               __pte(0), 0);
+                       /* After all PTEs have been zapped, flush the TLB. */
+                       np->rx_mcl[i-1].args[MULTI_UVMFLAGS_INDEX] =
+                               UVMF_TLB_FLUSH|UVMF_ALL;
+
+                       /* Give away a batch of pages. */
+                       np->rx_mcl[i].op = __HYPERVISOR_memory_op;
+                       np->rx_mcl[i].args[0] = XENMEM_decrease_reservation;
+                       np->rx_mcl[i].args[1] = (unsigned long)&reservation;
+
+                       /* Zap PTEs and give away pages in one big
+                        * multicall. */
+                       (void)HYPERVISOR_multicall(np->rx_mcl, i+1);
+
+                       /* Check return status of HYPERVISOR_memory_op(). */
+                       if (unlikely(np->rx_mcl[i].result != i))
+                               panic("Unable to reduce memory reservation\n");
+               } else {
+                       if (HYPERVISOR_memory_op(XENMEM_decrease_reservation,
+                                                &reservation) != i)
+                               panic("Unable to reduce memory reservation\n");
                }
-       }
-
-       /* Tell the ballon driver what is going on. */
-       balloon_update_driver_allowance(i);
-
-       set_xen_guest_handle(reservation.extent_start, np->rx_pfn_array);
-       reservation.nr_extents   = i;
-       reservation.extent_order = 0;
-       reservation.address_bits = 0;
-       reservation.domid        = DOMID_SELF;
-
-       if (!xen_feature(XENFEAT_auto_translated_physmap)) {
-               /* After all PTEs have been zapped, flush the TLB. */
-               np->rx_mcl[i-1].args[MULTI_UVMFLAGS_INDEX] =
-                       UVMF_TLB_FLUSH|UVMF_ALL;
-
-               /* Give away a batch of pages. */
-               np->rx_mcl[i].op = __HYPERVISOR_memory_op;
-               np->rx_mcl[i].args[0] = XENMEM_decrease_reservation;
-               np->rx_mcl[i].args[1] = (unsigned long)&reservation;
-
-               /* Zap PTEs and give away pages in one big multicall. */
-               (void)HYPERVISOR_multicall(np->rx_mcl, i+1);
-
-               /* Check return status of HYPERVISOR_memory_op(). */
-               if (unlikely(np->rx_mcl[i].result != i))
-                       panic("Unable to reduce memory reservation\n");
-       } else
-               if (HYPERVISOR_memory_op(XENMEM_decrease_reservation,
-                                        &reservation) != i)
-                       panic("Unable to reduce memory reservation\n");
+       } else {
+               wmb();
+       }
 
        /* Above is a suitable barrier to ensure backend will see requests. */
        np->rx.req_prod_pvt = req_prod + i;
@@ -834,9 +904,12 @@ static int network_start_xmit(struct sk_
 
        if (skb->ip_summed == CHECKSUM_HW) /* local packet? */
                tx->flags |= NETTXF_csum_blank | NETTXF_data_validated;
+#ifdef CONFIG_XEN
        if (skb->proto_data_valid) /* remote but checksummed? */
                tx->flags |= NETTXF_data_validated;
-
+#endif
+
+#ifdef HAVE_GSO
        if (skb_shinfo(skb)->gso_size) {
                struct netif_extra_info *gso = (struct netif_extra_info *)
                        RING_GET_REQUEST(&np->tx, ++i);
@@ -855,6 +928,7 @@ static int network_start_xmit(struct sk_
                gso->flags = 0;
                extra = gso;
        }
+#endif
 
        np->tx.req_prod_pvt = i + 1;
 
@@ -890,12 +964,15 @@ static irqreturn_t netif_int(int irq, vo
        unsigned long flags;
 
        spin_lock_irqsave(&np->tx_lock, flags);
-       network_tx_buf_gc(dev);
+
+       if (likely(netif_carrier_ok(dev))) {
+               network_tx_buf_gc(dev);
+               /* Under tx_lock: protects access to rx shared-ring indexes. */
+               if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
+                       netif_rx_schedule(dev);
+       }
+
        spin_unlock_irqrestore(&np->tx_lock, flags);
-
-       if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx) &&
-           likely(netif_running(dev)))
-               netif_rx_schedule(dev);
 
        return IRQ_HANDLED;
 }
@@ -941,8 +1018,10 @@ int xennet_get_extras(struct netfront_in
                                WPRINTK("Invalid extra type: %d\n",
                                        extra->type);
                        err = -EINVAL;
-               } else
-                       memcpy(&extras[extra->type - 1], extra, sizeof(*extra));
+               } else {
+                       memcpy(&extras[extra->type - 1], extra,
+                              sizeof(*extra));
+               }
 
                skb = xennet_get_rx_skb(np, cons);
                ref = xennet_get_rx_ref(np, cons);
@@ -955,10 +1034,12 @@ int xennet_get_extras(struct netfront_in
 
 static int xennet_get_responses(struct netfront_info *np,
                                struct netfront_rx_info *rinfo, RING_IDX rp,
-                               struct sk_buff_head *list, int count)
-{
-       struct mmu_update *mmu = np->rx_mmu + count;
-       struct multicall_entry *mcl = np->rx_mcl + count;
+                               struct sk_buff_head *list,
+                               int *pages_flipped_p)
+{
+       int pages_flipped = *pages_flipped_p;
+       struct mmu_update *mmu;
+       struct multicall_entry *mcl;
        struct netif_rx_response *rx = &rinfo->rx;
        struct netif_extra_info *extras = rinfo->extras;
        RING_IDX cons = np->rx.rsp_cons;
@@ -967,6 +1048,7 @@ static int xennet_get_responses(struct n
        int max = MAX_SKB_FRAGS + (rx->status <= RX_COPY_THRESHOLD);
        int frags = 1;
        int err = 0;
+       unsigned long ret;
 
        if (rx->flags & NETRXF_extra_info) {
                err = xennet_get_extras(np, extras, rp);
@@ -982,6 +1064,7 @@ static int xennet_get_responses(struct n
                                WPRINTK("rx->offset: %x, size: %u\n",
                                        rx->offset, rx->status);
                        err = -EINVAL;
+                       goto next;
                }
 
                /*
@@ -995,35 +1078,47 @@ static int xennet_get_responses(struct n
                        goto next;
                }
 
-               /* Memory pressure, insufficient buffer headroom, ... */
-               if ((mfn = gnttab_end_foreign_transfer_ref(ref)) == 0) {
-                       if (net_ratelimit())
-                               WPRINTK("Unfulfilled rx req (id=%d, st=%d).\n",
-                                       rx->id, rx->status);
-                       xennet_move_rx_slot(np, skb, ref);
-                       err = -ENOMEM;
-                       goto next;
+               if (!np->copying_receiver) {
+                       /* Memory pressure, insufficient buffer
+                        * headroom, ... */
+                       if (!(mfn = gnttab_end_foreign_transfer_ref(ref))) {
+                               if (net_ratelimit())
+                                       WPRINTK("Unfulfilled rx req "
+                                               "(id=%d, st=%d).\n",
+                                               rx->id, rx->status);
+                               xennet_move_rx_slot(np, skb, ref);
+                               err = -ENOMEM;
+                               goto next;
+                       }
+
+                       if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+                               /* Remap the page. */
+                               struct page *page =
+                                       skb_shinfo(skb)->frags[0].page;
+                               unsigned long pfn = page_to_pfn(page);
+                               void *vaddr = page_address(page);
+
+                               mcl = np->rx_mcl + pages_flipped;
+                               mmu = np->rx_mmu + pages_flipped;
+
+                               MULTI_update_va_mapping(mcl,
+                                                       (unsigned long)vaddr,
+                                                       pfn_pte_ma(mfn,
+                                                                  PAGE_KERNEL),
+                                                       0);
+                               mmu->ptr = ((maddr_t)mfn << PAGE_SHIFT)
+                                       | MMU_MACHPHYS_UPDATE;
+                               mmu->val = pfn;
+
+                               set_phys_to_machine(pfn, mfn);
+                       }
+                       pages_flipped++;
+               } else {
+                       ret = gnttab_end_foreign_access_ref(ref, 0);
+                       BUG_ON(!ret);
                }
 
                gnttab_release_grant_reference(&np->gref_rx_head, ref);
-
-               if (!xen_feature(XENFEAT_auto_translated_physmap)) {
-                       /* Remap the page. */
-                       struct page *page = skb_shinfo(skb)->frags[0].page;
-                       unsigned long pfn = page_to_pfn(page);
-                       void *vaddr = page_address(page);
-
-                       MULTI_update_va_mapping(mcl, (unsigned long)vaddr,
-                                               pfn_pte_ma(mfn, PAGE_KERNEL),
-                                               0);
-                       mcl++;
-                       mmu->ptr = ((maddr_t)mfn << PAGE_SHIFT)
-                               | MMU_MACHPHYS_UPDATE;
-                       mmu->val = pfn;
-                       mmu++;
-
-                       set_phys_to_machine(pfn, mfn);
-               }
 
                __skb_queue_tail(list, skb);
 
@@ -1050,6 +1145,8 @@ next:
                err = -E2BIG;
        }
 
+       *pages_flipped_p = pages_flipped;
+
        return err;
 }
 
@@ -1084,7 +1181,8 @@ static RING_IDX xennet_fill_frags(struct
        return cons;
 }
 
-static int xennet_set_skb_gso(struct sk_buff *skb, struct netif_extra_info 
*gso)
+static int xennet_set_skb_gso(struct sk_buff *skb,
+                             struct netif_extra_info *gso)
 {
        if (!gso->u.gso.size) {
                if (net_ratelimit())
@@ -1099,6 +1197,7 @@ static int xennet_set_skb_gso(struct sk_
                return -EINVAL;
        }
 
+#ifdef HAVE_GSO
        skb_shinfo(skb)->gso_size = gso->u.gso.size;
        skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
 
@@ -1107,6 +1206,11 @@ static int xennet_set_skb_gso(struct sk_
        skb_shinfo(skb)->gso_segs = 0;
 
        return 0;
+#else
+       if (net_ratelimit())
+               WPRINTK("GSO unsupported by this kernel.\n");
+       return -EINVAL;
+#endif
 }
 
 static int netif_poll(struct net_device *dev, int *pbudget)
@@ -1124,7 +1228,7 @@ static int netif_poll(struct net_device 
        struct sk_buff_head tmpq;
        unsigned long flags;
        unsigned int len;
-       int pages_done;
+       int pages_flipped = 0;
        int err;
 
        spin_lock(&np->rx_lock);
@@ -1143,14 +1247,14 @@ static int netif_poll(struct net_device 
        rp = np->rx.sring->rsp_prod;
        rmb(); /* Ensure we see queued responses up to 'rp'. */
 
-       for (i = np->rx.rsp_cons, work_done = 0, pages_done = 0;
+       for (i = np->rx.rsp_cons, work_done = 0;
             (i != rp) && (work_done < budget);
             np->rx.rsp_cons = ++i, work_done++) {
                memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx));
                memset(extras, 0, sizeof(extras));
 
-               err = xennet_get_responses(np, &rinfo, rp, &tmpq, pages_done);
-               pages_done += skb_queue_len(&tmpq);
+               err = xennet_get_responses(np, &rinfo, rp, &tmpq,
+                                          &pages_flipped);
 
                if (unlikely(err)) {
 err:
@@ -1193,40 +1297,63 @@ err:
                }
 
                i = xennet_fill_frags(np, skb, &tmpq);
-               skb->truesize += skb->data_len;
+
+               /*
+                * Truesize must approximates the size of true data plus
+                * any supervisor overheads. Adding hypervisor overheads
+                * has been shown to significantly reduce achievable
+                * bandwidth with the default receive buffer size. It is
+                * therefore not wise to account for it here.
+                *
+                * After alloc_skb(RX_COPY_THRESHOLD), truesize is set to
+                * RX_COPY_THRESHOLD + the supervisor overheads. Here, we
+                * add the size of the data pulled in xennet_fill_frags().
+                *
+                * We also adjust for any unused space in the main data
+                * area by subtracting (RX_COPY_THRESHOLD - len). This is
+                * especially important with drivers which split incoming
+                * packets into header and data, using only 66 bytes of
+                * the main data area (see the e1000 driver for example.)
+                * On such systems, without this last adjustement, our
+                * achievable receive throughout using the standard receive
+                * buffer size was cut by 25%(!!!).
+                */
+               skb->truesize += skb->data_len - (RX_COPY_THRESHOLD - len);
                skb->len += skb->data_len;
 
                /*
                 * Old backends do not assert data_validated but we
                 * can infer it from csum_blank so test both flags.
                 */
-               if (rx->flags & (NETRXF_data_validated|NETRXF_csum_blank)) {
+               if (rx->flags & (NETRXF_data_validated|NETRXF_csum_blank))
                        skb->ip_summed = CHECKSUM_UNNECESSARY;
-                       skb->proto_data_valid = 1;
-               } else {
+               else
                        skb->ip_summed = CHECKSUM_NONE;
-                       skb->proto_data_valid = 0;
-               }
+#ifdef CONFIG_XEN
+               skb->proto_data_valid = (skb->ip_summed != CHECKSUM_NONE);
                skb->proto_csum_blank = !!(rx->flags & NETRXF_csum_blank);
-
+#endif
                np->stats.rx_packets++;
                np->stats.rx_bytes += skb->len;
 
                __skb_queue_tail(&rxq, skb);
        }
 
-       /* Some pages are no longer absent... */
-       balloon_update_driver_allowance(-pages_done);
-
-       /* Do all the remapping work, and M2P updates, in one big hypercall. */
-       if (likely(pages_done)) {
-               mcl = np->rx_mcl + pages_done;
-               mcl->op = __HYPERVISOR_mmu_update;
-               mcl->args[0] = (unsigned long)np->rx_mmu;
-               mcl->args[1] = pages_done;
-               mcl->args[2] = 0;
-               mcl->args[3] = DOMID_SELF;
-               (void)HYPERVISOR_multicall(np->rx_mcl, pages_done + 1);
+       if (pages_flipped) {
+               /* Some pages are no longer absent... */
+               balloon_update_driver_allowance(-pages_flipped);
+
+               /* Do all the remapping work and M2P updates. */
+               if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+                       mcl = np->rx_mcl + pages_flipped;
+                       mcl->op = __HYPERVISOR_mmu_update;
+                       mcl->args[0] = (unsigned long)np->rx_mmu;
+                       mcl->args[1] = pages_flipped;
+                       mcl->args[2] = 0;
+                       mcl->args[3] = DOMID_SELF;
+                       (void)HYPERVISOR_multicall(np->rx_mcl,
+                                                  pages_flipped + 1);
+               }
        }
 
        while ((skb = __skb_dequeue(&errq)))
@@ -1277,97 +1404,12 @@ err:
        return more_to_do;
 }
 
-
-static int network_close(struct net_device *dev)
-{
-       struct netfront_info *np = netdev_priv(dev);
-       netif_stop_queue(np->netdev);
-       return 0;
-}
-
-
-static struct net_device_stats *network_get_stats(struct net_device *dev)
-{
-       struct netfront_info *np = netdev_priv(dev);
-       return &np->stats;
-}
-
-static int xennet_change_mtu(struct net_device *dev, int mtu)
-{
-       int max = xennet_can_sg(dev) ? 65535 - ETH_HLEN : ETH_DATA_LEN;
-
-       if (mtu > max)
-               return -EINVAL;
-       dev->mtu = mtu;
-       return 0;
-}
-
-static int xennet_set_sg(struct net_device *dev, u32 data)
-{
-       if (data) {
-               struct netfront_info *np = netdev_priv(dev);
-               int val;
-
-               if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, "feature-sg",
-                                "%d", &val) < 0)
-                       val = 0;
-               if (!val)
-                       return -ENOSYS;
-       } else if (dev->mtu > ETH_DATA_LEN)
-               dev->mtu = ETH_DATA_LEN;
-
-       return ethtool_op_set_sg(dev, data);
-}
-
-static int xennet_set_tso(struct net_device *dev, u32 data)
-{
-       if (data) {
-               struct netfront_info *np = netdev_priv(dev);
-               int val;
-
-               if (xenbus_scanf(XBT_NIL, np->xbdev->otherend,
-                                "feature-gso-tcpv4", "%d", &val) < 0)
-                       val = 0;
-               if (!val)
-                       return -ENOSYS;
-       }
-
-       return ethtool_op_set_tso(dev, data);
-}
-
-static void xennet_set_features(struct net_device *dev)
-{
-       /* Turn off all GSO bits except ROBUST. */
-       dev->features &= (1 << NETIF_F_GSO_SHIFT) - 1;
-       dev->features |= NETIF_F_GSO_ROBUST;
-       xennet_set_sg(dev, 0);
-
-       if (!xennet_set_sg(dev, 1))
-               xennet_set_tso(dev, 1);
-}
-
-static void network_connect(struct net_device *dev)
-{
-       struct netfront_info *np = netdev_priv(dev);
-       int i, requeue_idx;
+static void netif_release_tx_bufs(struct netfront_info *np)
+{
        struct sk_buff *skb;
-       grant_ref_t ref;
-
-       xennet_set_features(dev);
-
-       spin_lock_irq(&np->tx_lock);
-       spin_lock(&np->rx_lock);
-
-       /*
-         * Recovery procedure:
-        *  NB. Freelist index entries are always going to be less than
-        *  PAGE_OFFSET, whereas pointers to skbs will always be equal or
-        *  greater than PAGE_OFFSET: we use this property to distinguish
-        *  them.
-         */
-
-       /* Step 1: Discard all pending TX packet fragments. */
-       for (requeue_idx = 0, i = 1; i <= NET_TX_RING_SIZE; i++) {
+       int i;
+
+       for (i = 1; i <= NET_TX_RING_SIZE; i++) {
                if ((unsigned long)np->tx_skbs[i] < PAGE_OFFSET)
                        continue;
 
@@ -1380,6 +1422,191 @@ static void network_connect(struct net_d
                add_id_to_freelist(np->tx_skbs, i);
                dev_kfree_skb_irq(skb);
        }
+}
+
+static void netif_release_rx_bufs(struct netfront_info *np)
+{
+       struct mmu_update      *mmu = np->rx_mmu;
+       struct multicall_entry *mcl = np->rx_mcl;
+       struct sk_buff_head free_list;
+       struct sk_buff *skb;
+       unsigned long mfn;
+       int xfer = 0, noxfer = 0, unused = 0;
+       int id, ref;
+
+       if (np->copying_receiver) {
+               printk("%s: fix me for copying receiver.\n", __FUNCTION__);
+               return;
+       }
+
+       skb_queue_head_init(&free_list);
+
+       spin_lock(&np->rx_lock);
+
+       for (id = 0; id < NET_RX_RING_SIZE; id++) {
+               if ((ref = np->grant_rx_ref[id]) == GRANT_INVALID_REF) {
+                       unused++;
+                       continue;
+               }
+
+               skb = np->rx_skbs[id];
+               mfn = gnttab_end_foreign_transfer_ref(ref);
+               gnttab_release_grant_reference(&np->gref_rx_head, ref);
+               np->grant_rx_ref[id] = GRANT_INVALID_REF;
+               add_id_to_freelist(np->rx_skbs, id);
+
+               if (0 == mfn) {
+                       struct page *page = skb_shinfo(skb)->frags[0].page;
+                       balloon_release_driver_page(page);
+                       skb_shinfo(skb)->nr_frags = 0;
+                       dev_kfree_skb(skb);
+                       noxfer++;
+                       continue;
+               }
+
+               if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+                       /* Remap the page. */
+                       struct page *page = skb_shinfo(skb)->frags[0].page;
+                       unsigned long pfn = page_to_pfn(page);
+                       void *vaddr = page_address(page);
+
+                       MULTI_update_va_mapping(mcl, (unsigned long)vaddr,
+                                               pfn_pte_ma(mfn, PAGE_KERNEL),
+                                               0);
+                       mcl++;
+                       mmu->ptr = ((maddr_t)mfn << PAGE_SHIFT)
+                               | MMU_MACHPHYS_UPDATE;
+                       mmu->val = pfn;
+                       mmu++;
+
+                       set_phys_to_machine(pfn, mfn);
+               }
+               __skb_queue_tail(&free_list, skb);
+               xfer++;
+       }
+
+       printk("%s: %d xfer, %d noxfer, %d unused\n",
+              __FUNCTION__, xfer, noxfer, unused);
+
+       if (xfer) {
+               /* Some pages are no longer absent... */
+               balloon_update_driver_allowance(-xfer);
+
+               if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+                       /* Do all the remapping work and M2P updates. */
+                       mcl->op = __HYPERVISOR_mmu_update;
+                       mcl->args[0] = (unsigned long)np->rx_mmu;
+                       mcl->args[1] = mmu - np->rx_mmu;
+                       mcl->args[2] = 0;
+                       mcl->args[3] = DOMID_SELF;
+                       mcl++;
+                       HYPERVISOR_multicall(np->rx_mcl, mcl - np->rx_mcl);
+               }
+       }
+
+       while ((skb = __skb_dequeue(&free_list)) != NULL)
+               dev_kfree_skb(skb);
+
+       spin_unlock(&np->rx_lock);
+}
+
+static int network_close(struct net_device *dev)
+{
+       struct netfront_info *np = netdev_priv(dev);
+       netif_stop_queue(np->netdev);
+       return 0;
+}
+
+
+static struct net_device_stats *network_get_stats(struct net_device *dev)
+{
+       struct netfront_info *np = netdev_priv(dev);
+       return &np->stats;
+}
+
+static int xennet_change_mtu(struct net_device *dev, int mtu)
+{
+       int max = xennet_can_sg(dev) ? 65535 - ETH_HLEN : ETH_DATA_LEN;
+
+       if (mtu > max)
+               return -EINVAL;
+       dev->mtu = mtu;
+       return 0;
+}
+
+static int xennet_set_sg(struct net_device *dev, u32 data)
+{
+       if (data) {
+               struct netfront_info *np = netdev_priv(dev);
+               int val;
+
+               if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, "feature-sg",
+                                "%d", &val) < 0)
+                       val = 0;
+               if (!val)
+                       return -ENOSYS;
+       } else if (dev->mtu > ETH_DATA_LEN)
+               dev->mtu = ETH_DATA_LEN;
+
+       return ethtool_op_set_sg(dev, data);
+}
+
+static int xennet_set_tso(struct net_device *dev, u32 data)
+{
+#ifdef HAVE_GSO
+       if (data) {
+               struct netfront_info *np = netdev_priv(dev);
+               int val;
+
+               if (xenbus_scanf(XBT_NIL, np->xbdev->otherend,
+                                "feature-gso-tcpv4", "%d", &val) < 0)
+                       val = 0;
+               if (!val)
+                       return -ENOSYS;
+       }
+
+       return ethtool_op_set_tso(dev, data);
+#else
+       return -ENOSYS;
+#endif
+}
+
+static void xennet_set_features(struct net_device *dev)
+{
+       dev_disable_gso_features(dev);
+       xennet_set_sg(dev, 0);
+
+       /* We need checksum offload to enable scatter/gather and TSO. */
+       if (!(dev->features & NETIF_F_IP_CSUM))
+               return;
+
+       if (!xennet_set_sg(dev, 1))
+               xennet_set_tso(dev, 1);
+}
+
+static void network_connect(struct net_device *dev)
+{
+       struct netfront_info *np = netdev_priv(dev);
+       int i, requeue_idx;
+       struct sk_buff *skb;
+       grant_ref_t ref;
+       netif_rx_request_t *req;
+
+       xennet_set_features(dev);
+
+       spin_lock_irq(&np->tx_lock);
+       spin_lock(&np->rx_lock);
+
+       /*
+        * Recovery procedure:
+        *  NB. Freelist index entries are always going to be less than
+        *  PAGE_OFFSET, whereas pointers to skbs will always be equal or
+        *  greater than PAGE_OFFSET: we use this property to distinguish
+        *  them.
+        */
+
+       /* Step 1: Discard all pending TX packet fragments. */
+       netif_release_tx_bufs(np);
 
        /* Step 2: Rebuild the RX buffer freelist and the RX ring itself. */
        for (requeue_idx = 0, i = 0; i < NET_RX_RING_SIZE; i++) {
@@ -1388,13 +1615,20 @@ static void network_connect(struct net_d
 
                skb = np->rx_skbs[requeue_idx] = xennet_get_rx_skb(np, i);
                ref = np->grant_rx_ref[requeue_idx] = xennet_get_rx_ref(np, i);
-
-               gnttab_grant_foreign_transfer_ref(
-                       ref, np->xbdev->otherend_id,
-                       page_to_pfn(skb_shinfo(skb)->frags->page));
-
-               RING_GET_REQUEST(&np->rx, requeue_idx)->gref = ref;
-               RING_GET_REQUEST(&np->rx, requeue_idx)->id   = requeue_idx;
+               req = RING_GET_REQUEST(&np->rx, requeue_idx);
+
+               if (!np->copying_receiver) {
+                       gnttab_grant_foreign_transfer_ref(
+                               ref, np->xbdev->otherend_id,
+                               page_to_pfn(skb_shinfo(skb)->frags->page));
+               } else {
+                       gnttab_grant_foreign_access_ref(
+                               ref, np->xbdev->otherend_id,
+                               page_to_pfn(skb_shinfo(skb)->frags->page),
+                               0);
+               }
+               req->gref = ref;
+               req->id   = requeue_idx;
 
                requeue_idx++;
        }
@@ -1419,6 +1653,8 @@ static void netif_uninit(struct net_devi
 static void netif_uninit(struct net_device *dev)
 {
        struct netfront_info *np = netdev_priv(dev);
+       netif_release_tx_bufs(np);
+       netif_release_rx_bufs(np);
        gnttab_free_grant_references(np->gref_tx_head);
        gnttab_free_grant_references(np->gref_rx_head);
 }
@@ -1577,13 +1813,8 @@ static void network_set_multicast_list(s
 {
 }
 
-/** Create a network device.
- * @param handle device handle
- * @param val return parameter for created device
- * @return 0 on success, error code otherwise
- */
-static struct net_device * __devinit create_netdev(int handle,
-                                                  struct xenbus_device *dev)
+static struct net_device * __devinit
+create_netdev(int handle, int copying_receiver, struct xenbus_device *dev)
 {
        int i, err = 0;
        struct net_device *netdev = NULL;
@@ -1596,9 +1827,10 @@ static struct net_device * __devinit cre
                return ERR_PTR(-ENOMEM);
        }
 
-       np                = netdev_priv(netdev);
-       np->handle        = handle;
-       np->xbdev         = dev;
+       np                   = netdev_priv(netdev);
+       np->handle           = handle;
+       np->xbdev            = dev;
+       np->copying_receiver = copying_receiver;
 
        netif_carrier_off(netdev);
 
@@ -1812,7 +2044,7 @@ static int __init netif_init(void)
        if (!is_running_on_xen())
                return -ENODEV;
 
-       if (xen_start_info->flags & SIF_INITDOMAIN)
+       if (is_initial_xendomain())
                return 0;
 
        IPRINTK("Initialising virtual ethernet driver.\n");
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c Wed Aug 23 11:11:27 
2006 -0600
@@ -181,6 +181,7 @@ static void pciback_frontend_changed(str
                xenbus_switch_state(xdev, XenbusStateClosing);
                break;
 
+       case XenbusStateUnknown:
        case XenbusStateClosed:
                dev_dbg(&xdev->dev, "frontend is gone! unregister device\n");
                device_unregister(&xdev->dev);
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/pcifront/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/pcifront/xenbus.c        Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/pcifront/xenbus.c        Wed Aug 23 
11:11:27 2006 -0600
@@ -225,6 +225,7 @@ static void pcifront_backend_changed(str
                pcifront_try_disconnect(pdev);
                break;
 
+       case XenbusStateUnknown:
        case XenbusStateClosed:
                dev_warn(&xdev->dev, "backend went away!\n");
                pcifront_try_disconnect(pdev);
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c
--- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c        Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c        Wed Aug 23 
11:11:27 2006 -0600
@@ -108,13 +108,15 @@ static int privcmd_ioctl(struct inode *i
        }
        break;
 
-#if defined(CONFIG_XEN_PRIVILEGED_GUEST)
        case IOCTL_PRIVCMD_MMAP: {
 #define PRIVCMD_MMAP_SZ 32
                privcmd_mmap_t mmapcmd;
                privcmd_mmap_entry_t msg[PRIVCMD_MMAP_SZ];
                privcmd_mmap_entry_t __user *p;
                int i, rc;
+
+               if (!is_initial_xendomain())
+                       return -EPERM;
 
                if (copy_from_user(&mmapcmd, udata, sizeof(mmapcmd)))
                        return -EFAULT;
@@ -162,8 +164,11 @@ static int privcmd_ioctl(struct inode *i
                privcmd_mmapbatch_t m;
                struct vm_area_struct *vma = NULL;
                xen_pfn_t __user *p;
-               unsigned long addr, mfn; 
+               unsigned long addr, mfn;
                int i;
+
+               if (!is_initial_xendomain())
+                       return -EPERM;
 
                if (copy_from_user(&m, udata, sizeof(m))) {
                        ret = -EFAULT;
@@ -215,7 +220,6 @@ static int privcmd_ioctl(struct inode *i
                break;
        }
        break;
-#endif
 
        default:
                ret = -EINVAL;
@@ -246,7 +250,7 @@ static int capabilities_read(char *page,
        int len = 0;
        *page = 0;
 
-       if (xen_start_info->flags & SIF_INITDOMAIN)
+       if (is_initial_xendomain())
                len = sprintf( page, "control_d\n" );
 
        *eof = 1;
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c Wed Aug 23 11:11:27 
2006 -0600
@@ -34,7 +34,6 @@ struct backend_info
 
        /* watch front end for changes */
        struct xenbus_watch backend_watch;
-       enum xenbus_state frontend_state;
 };
 
 static void maybe_connect(struct backend_info *be);
@@ -143,8 +142,6 @@ static void frontend_changed(struct xenb
        struct backend_info *be = dev->dev.driver_data;
        int err;
 
-       be->frontend_state = frontend_state;
-
        switch (frontend_state) {
        case XenbusStateInitialising:
        case XenbusStateInitialised:
@@ -162,13 +159,12 @@ static void frontend_changed(struct xenb
                be->instance = -1;
                break;
 
+       case XenbusStateUnknown:
        case XenbusStateClosed:
                device_unregister(&be->dev->dev);
                tpmback_remove(dev);
                break;
 
-       case XenbusStateUnknown:
-       case XenbusStateInitWait:
        default:
                xenbus_dev_fatal(dev, -EINVAL,
                                 "saw state %d at frontend",
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c   Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c   Wed Aug 23 
11:11:27 2006 -0600
@@ -274,7 +274,7 @@ enum xenbus_state xenbus_read_driver_sta
        enum xenbus_state result;
        int err = xenbus_gather(XBT_NIL, path, "state", "%d", &result, NULL);
        if (err)
-               result = XenbusStateClosed;
+               result = XenbusStateUnknown;
 
        return result;
 }
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c    Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c    Wed Aug 23 
11:11:27 2006 -0600
@@ -47,11 +47,6 @@ static DECLARE_WORK(probe_work, xenbus_p
 
 DECLARE_WAIT_QUEUE_HEAD(xb_waitq);
 
-static inline struct xenstore_domain_interface *xenstore_domain_interface(void)
-{
-       return mfn_to_virt(xen_start_info->store_mfn);
-}
-
 static irqreturn_t wake_waiting(int irq, void *unused, struct pt_regs *regs)
 {
        if (unlikely(xenstored_ready == 0)) {
@@ -90,7 +85,7 @@ static const void *get_input_chunk(XENST
 
 int xb_write(const void *data, unsigned len)
 {
-       struct xenstore_domain_interface *intf = xenstore_domain_interface();
+       struct xenstore_domain_interface *intf = xen_store_interface;
        XENSTORE_RING_IDX cons, prod;
        int rc;
 
@@ -129,7 +124,7 @@ int xb_write(const void *data, unsigned 
                intf->req_prod += avail;
 
                /* This implies mb() before other side sees interrupt. */
-               notify_remote_via_evtchn(xen_start_info->store_evtchn);
+               notify_remote_via_evtchn(xen_store_evtchn);
        }
 
        return 0;
@@ -137,7 +132,7 @@ int xb_write(const void *data, unsigned 
 
 int xb_read(void *data, unsigned len)
 {
-       struct xenstore_domain_interface *intf = xenstore_domain_interface();
+       struct xenstore_domain_interface *intf = xen_store_interface;
        XENSTORE_RING_IDX cons, prod;
        int rc;
 
@@ -180,7 +175,7 @@ int xb_read(void *data, unsigned len)
                pr_debug("Finished read of %i bytes (%i to go)\n", avail, len);
 
                /* Implies mb(): they will see new header. */
-               notify_remote_via_evtchn(xen_start_info->store_evtchn);
+               notify_remote_via_evtchn(xen_store_evtchn);
        }
 
        return 0;
@@ -195,7 +190,7 @@ int xb_init_comms(void)
                unbind_from_irqhandler(xenbus_irq, &xb_waitq);
 
        err = bind_evtchn_to_irqhandler(
-               xen_start_info->store_evtchn, wake_waiting,
+               xen_store_evtchn, wake_waiting,
                0, "xenbus", &xb_waitq);
        if (err <= 0) {
                printk(KERN_ERR "XENBUS request irq failed %i\n", err);
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h    Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h    Wed Aug 23 
11:11:27 2006 -0600
@@ -39,5 +39,7 @@ int xb_read(void *data, unsigned len);
 int xb_read(void *data, unsigned len);
 int xs_input_avail(void);
 extern wait_queue_head_t xb_waitq;
+extern struct xenstore_domain_interface *xen_store_interface;
+extern int xen_store_evtchn;
 
 #endif /* _XENBUS_COMMS_H */
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c      Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c      Wed Aug 23 
11:11:27 2006 -0600
@@ -285,7 +285,7 @@ static int xenbus_dev_open(struct inode 
 {
        struct xenbus_dev_data *u;
 
-       if (xen_start_info->store_evtchn == 0)
+       if (xen_store_evtchn == 0)
                return -ENOENT;
 
        nonseekable_open(inode, filp);
@@ -346,7 +346,7 @@ static struct file_operations xenbus_dev
        .poll = xenbus_dev_poll,
 };
 
-static int __init
+int __init
 xenbus_dev_init(void)
 {
        xenbus_dev_intf = create_xen_proc_entry("xenbus", 0400);
@@ -355,5 +355,3 @@ xenbus_dev_init(void)
 
        return 0;
 }
-
-__initcall(xenbus_dev_init);
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Wed Aug 23 
11:11:27 2006 -0600
@@ -45,18 +45,34 @@
 
 #include <asm/io.h>
 #include <asm/page.h>
+#include <asm/maddr.h>
 #include <asm/pgtable.h>
 #include <asm/hypervisor.h>
 #include <xen/xenbus.h>
 #include <xen/xen_proc.h>
 #include <xen/evtchn.h>
 #include <xen/features.h>
+#include <xen/hvm.h>
 
 #include "xenbus_comms.h"
 
+int xen_store_evtchn;
+struct xenstore_domain_interface *xen_store_interface;
+static unsigned long xen_store_mfn;
+
 extern struct mutex xenwatch_mutex;
 
 static struct notifier_block *xenstore_chain;
+
+static void wait_for_devices(struct xenbus_driver *xendrv);
+
+static int xenbus_probe_frontend(const char *type, const char *name);
+static int xenbus_uevent_backend(struct device *dev, char **envp,
+                                int num_envp, char *buffer, int buffer_size);
+static int xenbus_probe_backend(const char *type, const char *domid);
+
+static int xenbus_dev_probe(struct device *_dev);
+static int xenbus_dev_remove(struct device *_dev);
 
 /* If something in array of ids matches this device, return it. */
 static const struct xenbus_device_id *
@@ -166,15 +182,16 @@ static int read_frontend_details(struct 
 
 
 /* Bus type for frontend drivers. */
-static int xenbus_probe_frontend(const char *type, const char *name);
 static struct xen_bus_type xenbus_frontend = {
        .root = "device",
        .levels = 2,            /* device/type/<id> */
        .get_bus_id = frontend_bus_id,
        .probe = xenbus_probe_frontend,
        .bus = {
-               .name  = "xen",
-               .match = xenbus_match,
+               .name     = "xen",
+               .match    = xenbus_match,
+               .probe    = xenbus_dev_probe,
+               .remove   = xenbus_dev_remove,
        },
        .dev = {
                .bus_id = "xen",
@@ -219,18 +236,17 @@ static int backend_bus_id(char bus_id[BU
        return 0;
 }
 
-static int xenbus_uevent_backend(struct device *dev, char **envp,
-                                int num_envp, char *buffer, int buffer_size);
-static int xenbus_probe_backend(const char *type, const char *domid);
 static struct xen_bus_type xenbus_backend = {
        .root = "backend",
        .levels = 3,            /* backend/type/<frontend>/<id> */
        .get_bus_id = backend_bus_id,
        .probe = xenbus_probe_backend,
        .bus = {
-               .name  = "xen-backend",
-               .match = xenbus_match,
-               .uevent = xenbus_uevent_backend,
+               .name     = "xen-backend",
+               .match    = xenbus_match,
+               .probe    = xenbus_dev_probe,
+               .remove   = xenbus_dev_remove,
+               .uevent   = xenbus_uevent_backend,
        },
        .dev = {
                .bus_id = "xen-backend",
@@ -397,8 +413,6 @@ static int xenbus_register_driver_common
        drv->driver.name = drv->name;
        drv->driver.bus = &bus->bus;
        drv->driver.owner = drv->owner;
-       drv->driver.probe = xenbus_dev_probe;
-       drv->driver.remove = xenbus_dev_remove;
 
        mutex_lock(&xenwatch_mutex);
        ret = driver_register(&drv->driver);
@@ -408,9 +422,18 @@ static int xenbus_register_driver_common
 
 int xenbus_register_frontend(struct xenbus_driver *drv)
 {
+       int ret;
+
        drv->read_otherend_details = read_backend_details;
 
-       return xenbus_register_driver_common(drv, &xenbus_frontend);
+       ret = xenbus_register_driver_common(drv, &xenbus_frontend);
+       if (ret)
+               return ret;
+
+       /* If this driver is loaded as a module wait for devices to attach. */
+       wait_for_devices(drv);
+
+       return 0;
 }
 EXPORT_SYMBOL_GPL(xenbus_register_frontend);
 
@@ -829,7 +852,7 @@ static int resume_dev(struct device *dev
                        printk(KERN_WARNING
                               "xenbus: resume %s failed: %i\n", 
                               dev->bus_id, err);
-                       return err; 
+                       return err;
                }
        }
 
@@ -841,7 +864,7 @@ static int resume_dev(struct device *dev
                return err;
        }
 
-       return 0; 
+       return 0;
 }
 
 void xenbus_suspend(void)
@@ -917,8 +940,7 @@ static int xsd_kva_mmap(struct file *fil
        if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
                return -EINVAL;
 
-       if (remap_pfn_range(vma, vma->vm_start,
-                           mfn_to_pfn(xen_start_info->store_mfn),
+       if (remap_pfn_range(vma, vma->vm_start, mfn_to_pfn(xen_store_mfn),
                            size, vma->vm_page_prot))
                return -EAGAIN;
 
@@ -930,7 +952,7 @@ static int xsd_kva_read(char *page, char
 {
        int len;
 
-       len  = sprintf(page, "0x%p", mfn_to_virt(xen_start_info->store_mfn));
+       len  = sprintf(page, "0x%p", xen_store_interface);
        *eof = 1;
        return len;
 }
@@ -940,16 +962,15 @@ static int xsd_port_read(char *page, cha
 {
        int len;
 
-       len  = sprintf(page, "%d", xen_start_info->store_evtchn);
+       len  = sprintf(page, "%d", xen_store_evtchn);
        *eof = 1;
        return len;
 }
 #endif
 
-
 static int __init xenbus_probe_init(void)
 {
-       int err = 0, dom0;
+       int err = 0;
        unsigned long page = 0;
 
        DPRINTK("");
@@ -964,9 +985,7 @@ static int __init xenbus_probe_init(void
        /*
         * Domain0 doesn't have a store_evtchn or store_mfn yet.
         */
-       dom0 = (xen_start_info->store_evtchn == 0);
-
-       if (dom0) {
+       if (is_initial_xendomain()) {
                struct evtchn_alloc_unbound alloc_unbound;
 
                /* Allocate page. */
@@ -974,7 +993,7 @@ static int __init xenbus_probe_init(void
                if (!page)
                        return -ENOMEM;
 
-               xen_start_info->store_mfn =
+               xen_store_mfn = xen_start_info->store_mfn =
                        pfn_to_mfn(virt_to_phys((void *)page) >>
                                   PAGE_SHIFT);
 
@@ -987,7 +1006,8 @@ static int __init xenbus_probe_init(void
                if (err == -ENOSYS)
                        goto err;
                BUG_ON(err);
-               xen_start_info->store_evtchn = alloc_unbound.port;
+               xen_store_evtchn = xen_start_info->store_evtchn =
+                       alloc_unbound.port;
 
 #ifdef CONFIG_PROC_FS
                /* And finally publish the above info in /proc/xen */
@@ -1003,8 +1023,23 @@ static int __init xenbus_probe_init(void
                if (xsd_port_intf)
                        xsd_port_intf->read_proc = xsd_port_read;
 #endif
-       } else
+               xen_store_interface = mfn_to_virt(xen_store_mfn);
+       } else {
                xenstored_ready = 1;
+#ifdef CONFIG_XEN
+               xen_store_evtchn = xen_start_info->store_evtchn;
+               xen_store_mfn = xen_start_info->store_mfn;
+               xen_store_interface = mfn_to_virt(xen_store_mfn);
+#else
+               xen_store_evtchn = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
+               xen_store_mfn = hvm_get_parameter(HVM_PARAM_STORE_PFN);
+               xen_store_interface = ioremap(xen_store_mfn << PAGE_SHIFT,
+                                             PAGE_SIZE);
+#endif
+       }
+
+
+       xenbus_dev_init();
 
        /* Initialize the interface to xenstore. */
        err = xs_init();
@@ -1018,7 +1053,7 @@ static int __init xenbus_probe_init(void
        device_register(&xenbus_frontend.dev);
        device_register(&xenbus_backend.dev);
 
-       if (!dom0)
+       if (!is_initial_xendomain())
                xenbus_probe(NULL);
 
        return 0;
@@ -1038,10 +1073,13 @@ static int __init xenbus_probe_init(void
 
 postcore_initcall(xenbus_probe_init);
 
+MODULE_LICENSE("Dual BSD/GPL");
+
 
 static int is_disconnected_device(struct device *dev, void *data)
 {
        struct xenbus_device *xendev = to_xenbus_device(dev);
+       struct device_driver *drv = data;
 
        /*
         * A device with no driver will never connect. We care only about
@@ -1050,18 +1088,27 @@ static int is_disconnected_device(struct
        if (!dev->driver)
                return 0;
 
+       /* Is this search limited to a particular driver? */
+       if (drv && (dev->driver != drv))
+               return 0;
+
        return (xendev->state != XenbusStateConnected);
 }
 
-static int exists_disconnected_device(void)
-{
-       return bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL,
+static int exists_disconnected_device(struct device_driver *drv)
+{
+       return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv,
                                is_disconnected_device);
 }
 
 static int print_device_status(struct device *dev, void *data)
 {
        struct xenbus_device *xendev = to_xenbus_device(dev);
+       struct device_driver *drv = data;
+
+       /* Is this operation limited to a particular driver? */
+       if (drv && (dev->driver != drv))
+               return 0;
 
        if (!dev->driver) {
                /* Information only: is this too noisy? */
@@ -1075,6 +1122,9 @@ static int print_device_status(struct de
 
        return 0;
 }
+
+/* We only wait for device setup after most initcalls have run. */
+static int ready_to_wait_for_devices;
 
 /*
  * On a 10 second timeout, wait for all devices currently configured.  We need
@@ -1090,20 +1140,31 @@ static int print_device_status(struct de
  * boot slightly, but of course needs tools or manual intervention to set up
  * those flags correctly.
  */
-static int __init wait_for_devices(void)
+static void wait_for_devices(struct xenbus_driver *xendrv)
 {
        unsigned long timeout = jiffies + 10*HZ;
-
-       if (!is_running_on_xen())
-               return -ENODEV;
-
-       while (time_before(jiffies, timeout) && exists_disconnected_device())
+       struct device_driver *drv = xendrv ? &xendrv->driver : NULL;
+
+       if (!ready_to_wait_for_devices || !is_running_on_xen())
+               return;
+
+       while (exists_disconnected_device(drv)) {
+               if (time_after(jiffies, timeout))
+                       break;
                schedule_timeout_interruptible(HZ/10);
-
-       bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL,
+       }
+
+       bus_for_each_dev(&xenbus_frontend.bus, NULL, drv,
                         print_device_status);
-
-       return 0;
-}
-
-late_initcall(wait_for_devices);
+}
+
+#ifndef MODULE
+static int __init boot_wait_for_devices(void)
+{
+       ready_to_wait_for_devices = 1;
+       wait_for_devices(NULL);
+       return 0;
+}
+
+late_initcall(boot_wait_for_devices);
+#endif
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c       Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c       Wed Aug 23 
11:11:27 2006 -0600
@@ -665,7 +665,17 @@ EXPORT_SYMBOL_GPL(unregister_xenbus_watc
 
 void xs_suspend(void)
 {
+       struct xenbus_watch *watch;
+       char token[sizeof(watch) * 2 + 1];
+
        down_write(&xs_state.suspend_mutex);
+
+       /* No need for watches_lock: the suspend_mutex is sufficient. */
+       list_for_each_entry(watch, &watches, list) {
+               sprintf(token, "%lX", (long)watch);
+               xs_unwatch(watch->node, token);
+       }
+
        mutex_lock(&xs_state.request_mutex);
 }
 
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h
--- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h    Tue Aug 
22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h    Wed Aug 
23 11:11:27 2006 -0600
@@ -42,11 +42,21 @@
 #define __STR(x) #x
 #define STR(x) __STR(x)
 
+#ifdef CONFIG_XEN
+#define HYPERCALL_STR(name)                                    \
+       "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
+#else
+#define HYPERCALL_STR(name)                                    \
+       "mov hypercall_stubs,%%eax; "                           \
+       "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "        \
+       "call *%%eax"
+#endif
+
 #define _hypercall0(type, name)                        \
 ({                                             \
        long __res;                             \
        asm volatile (                          \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)             \
                : "=a" (__res)                  \
                :                               \
                : "memory" );                   \
@@ -57,7 +67,7 @@
 ({                                                             \
        long __res, __ign1;                                     \
        asm volatile (                                          \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)                             \
                : "=a" (__res), "=b" (__ign1)                   \
                : "1" ((long)(a1))                              \
                : "memory" );                                   \
@@ -68,7 +78,7 @@
 ({                                                             \
        long __res, __ign1, __ign2;                             \
        asm volatile (                                          \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)                             \
                : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
                : "1" ((long)(a1)), "2" ((long)(a2))            \
                : "memory" );                                   \
@@ -79,7 +89,7 @@
 ({                                                             \
        long __res, __ign1, __ign2, __ign3;                     \
        asm volatile (                                          \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)                             \
                : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
                "=d" (__ign3)                                   \
                : "1" ((long)(a1)), "2" ((long)(a2)),           \
@@ -92,7 +102,7 @@
 ({                                                             \
        long __res, __ign1, __ign2, __ign3, __ign4;             \
        asm volatile (                                          \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)                             \
                : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
                "=d" (__ign3), "=S" (__ign4)                    \
                : "1" ((long)(a1)), "2" ((long)(a2)),           \
@@ -105,7 +115,7 @@
 ({                                                             \
        long __res, __ign1, __ign2, __ign3, __ign4, __ign5;     \
        asm volatile (                                          \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)                             \
                : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
                "=d" (__ign3), "=S" (__ign4), "=D" (__ign5)     \
                : "1" ((long)(a1)), "2" ((long)(a2)),           \
@@ -354,6 +364,13 @@ HYPERVISOR_nmi_op(
        return _hypercall2(int, nmi_op, op, arg);
 }
 
+static inline unsigned long
+HYPERVISOR_hvm_op(
+    int op, void *arg)
+{
+    return _hypercall2(unsigned long, hvm_op, op, arg);
+}
+
 static inline int
 HYPERVISOR_callback_op(
        int cmd, void *arg)
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h
--- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h   Tue Aug 
22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h   Wed Aug 
23 11:11:27 2006 -0600
@@ -58,6 +58,11 @@ extern shared_info_t *HYPERVISOR_shared_
 
 /* arch/xen/i386/kernel/setup.c */
 extern start_info_t *xen_start_info;
+#ifdef CONFIG_XEN_PRIVILEGED_GUEST
+#define is_initial_xendomain() (xen_start_info->flags & SIF_INITDOMAIN)
+#else
+#define is_initial_xendomain() 0
+#endif
 
 /* arch/xen/kernel/evtchn.c */
 /* Force a proper event-channel callback from Xen. */
@@ -198,6 +203,16 @@ MULTI_update_va_mapping(
 }
 
 static inline void
+MULTI_grant_table_op(multicall_entry_t *mcl, unsigned int cmd,
+                    void *uop, unsigned int count)
+{
+    mcl->op = __HYPERVISOR_grant_table_op;
+    mcl->args[0] = cmd;
+    mcl->args[1] = (unsigned long)uop;
+    mcl->args[2] = count;
+}
+
+static inline void
 MULTI_update_va_mapping_otherdomain(
     multicall_entry_t *mcl, unsigned long va,
     pte_t new_val, unsigned long flags, domid_t domid)
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h
--- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h Wed Aug 23 
11:11:27 2006 -0600
@@ -60,123 +60,6 @@
 #define clear_user_page(page, vaddr, pg)       clear_page(page)
 #define copy_user_page(to, from, vaddr, pg)    copy_page(to, from)
 
-/**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
-#define INVALID_P2M_ENTRY      (~0UL)
-#define FOREIGN_FRAME_BIT      (1UL<<31)
-#define FOREIGN_FRAME(m)       ((m) | FOREIGN_FRAME_BIT)
-
-extern unsigned long *phys_to_machine_mapping;
-
-#undef machine_to_phys_mapping
-extern unsigned long *machine_to_phys_mapping;
-extern unsigned int   machine_to_phys_order;
-
-static inline unsigned long pfn_to_mfn(unsigned long pfn)
-{
-       if (xen_feature(XENFEAT_auto_translated_physmap))
-               return pfn;
-       return phys_to_machine_mapping[(unsigned int)(pfn)] &
-               ~FOREIGN_FRAME_BIT;
-}
-
-static inline int phys_to_machine_mapping_valid(unsigned long pfn)
-{
-       if (xen_feature(XENFEAT_auto_translated_physmap))
-               return 1;
-       return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
-}
-
-static inline unsigned long mfn_to_pfn(unsigned long mfn)
-{
-       extern unsigned long max_mapnr;
-       unsigned long pfn;
-
-       if (xen_feature(XENFEAT_auto_translated_physmap))
-               return mfn;
-
-       if (unlikely((mfn >> machine_to_phys_order) != 0))
-               return max_mapnr;
-
-       /* The array access can fail (e.g., device space beyond end of RAM). */
-       asm (
-               "1:     movl %1,%0\n"
-               "2:\n"
-               ".section .fixup,\"ax\"\n"
-               "3:     movl %2,%0\n"
-               "       jmp  2b\n"
-               ".previous\n"
-               ".section __ex_table,\"a\"\n"
-               "       .align 4\n"
-               "       .long 1b,3b\n"
-               ".previous"
-               : "=r" (pfn)
-               : "m" (machine_to_phys_mapping[mfn]), "m" (max_mapnr) );
-
-       return pfn;
-}
-
-/*
- * We detect special mappings in one of two ways:
- *  1. If the MFN is an I/O page then Xen will set the m2p entry
- *     to be outside our maximum possible pseudophys range.
- *  2. If the MFN belongs to a different domain then we will certainly
- *     not have MFN in our p2m table. Conversely, if the page is ours,
- *     then we'll have p2m(m2p(MFN))==MFN.
- * If we detect a special mapping then it doesn't have a 'struct page'.
- * We force !pfn_valid() by returning an out-of-range pointer.
- *
- * NB. These checks require that, for any MFN that is not in our reservation,
- * there is no PFN such that p2m(PFN) == MFN. Otherwise we can get confused if
- * we are foreign-mapping the MFN, and the other domain as m2p(MFN) == PFN.
- * Yikes! Various places must poke in INVALID_P2M_ENTRY for safety.
- *
- * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
- *      use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
- *      require. In all the cases we care about, the FOREIGN_FRAME bit is
- *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
- */
-static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
-{
-       extern unsigned long max_mapnr;
-       unsigned long pfn = mfn_to_pfn(mfn);
-       if ((pfn < max_mapnr)
-           && !xen_feature(XENFEAT_auto_translated_physmap)
-           && (phys_to_machine_mapping[pfn] != mfn))
-               return max_mapnr; /* force !pfn_valid() */
-       return pfn;
-}
-
-static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
-{
-       if (xen_feature(XENFEAT_auto_translated_physmap)) {
-               BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
-               return;
-       }
-       phys_to_machine_mapping[pfn] = mfn;
-}
-
-/* Definitions for machine and pseudophysical addresses. */
-#ifdef CONFIG_X86_PAE
-typedef unsigned long long paddr_t;
-typedef unsigned long long maddr_t;
-#else
-typedef unsigned long paddr_t;
-typedef unsigned long maddr_t;
-#endif
-
-static inline maddr_t phys_to_machine(paddr_t phys)
-{
-       maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
-       machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
-       return machine;
-}
-static inline paddr_t machine_to_phys(maddr_t machine)
-{
-       paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
-       phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
-       return phys;
-}
-
 /*
  * These are used to make use of C type-checking..
  */
@@ -187,6 +70,8 @@ typedef struct { unsigned long long pmd;
 typedef struct { unsigned long long pmd; } pmd_t;
 typedef struct { unsigned long long pgd; } pgd_t;
 typedef struct { unsigned long long pgprot; } pgprot_t;
+#define pgprot_val(x)  ((x).pgprot)
+#include <asm/maddr.h>
 #define __pte(x) ({ unsigned long long _x = (x);        \
     if (_x & 1) _x = phys_to_machine(_x);               \
     ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
@@ -227,6 +112,8 @@ typedef struct { unsigned long pte_low; 
 typedef struct { unsigned long pte_low; } pte_t;
 typedef struct { unsigned long pgd; } pgd_t;
 typedef struct { unsigned long pgprot; } pgprot_t;
+#define pgprot_val(x)  ((x).pgprot)
+#include <asm/maddr.h>
 #define boot_pte_t pte_t /* or would you rather have a typedef */
 #define pte_val(x)     (((x).pte_low & 1) ? machine_to_phys((x).pte_low) : \
                         (x).pte_low)
@@ -252,9 +139,6 @@ static inline unsigned long pgd_val(pgd_
 #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
 #endif
 
-#define pgprot_val(x)  ((x).pgprot)
-
-#define __pte_ma(x)    ((pte_t) { (x) } )
 #define __pgprot(x)    ((pgprot_t) { (x) } )
 
 #endif /* !__ASSEMBLY__ */
@@ -323,11 +207,6 @@ extern int page_is_ram(unsigned long pag
        ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
                 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
 
-/* VIRT <-> MACHINE conversion */
-#define virt_to_machine(v)     (phys_to_machine(__pa(v)))
-#define virt_to_mfn(v)         (pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
-#define mfn_to_virt(m)         (__va(mfn_to_pfn(m) << PAGE_SHIFT))
-
 #define __HAVE_ARCH_GATE_AREA 1
 
 #endif /* __KERNEL__ */
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h
--- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h       
Tue Aug 22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h       
Wed Aug 23 11:11:27 2006 -0600
@@ -45,7 +45,6 @@
 
 #define pte_none(x)            (!(x).pte_low)
 #define pfn_pte(pfn, prot)     __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
-#define pfn_pte_ma(pfn, prot)  __pte_ma(((pfn) << PAGE_SHIFT) | 
pgprot_val(prot))
 #define pfn_pmd(pfn, prot)     __pmd(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
 
 /*
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h
--- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h       
Tue Aug 22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h       
Wed Aug 23 11:11:27 2006 -0600
@@ -151,18 +151,6 @@ static inline int pte_none(pte_t pte)
 
 extern unsigned long long __supported_pte_mask;
 
-static inline pte_t pfn_pte_ma(unsigned long page_nr, pgprot_t pgprot)
-{
-       pte_t pte;
-
-       pte.pte_high = (page_nr >> (32 - PAGE_SHIFT)) | \
-                                       (pgprot_val(pgprot) >> 32);
-       pte.pte_high &= (__supported_pte_mask >> 32);
-       pte.pte_low = ((page_nr << PAGE_SHIFT) | pgprot_val(pgprot)) & \
-                                                       __supported_pte_mask;
-       return pte;
-}
-
 static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
 {
        return pfn_pte_ma(pfn_to_mfn(page_nr), pgprot);
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h
--- a/linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h        Tue Aug 22 
14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h        Wed Aug 23 
11:11:27 2006 -0600
@@ -58,6 +58,8 @@ extern int running_on_xen;
 
 extern shared_info_t *HYPERVISOR_shared_info;
 extern start_info_t *xen_start_info;
+
+#define is_initial_xendomain() (xen_start_info->flags & SIF_INITDOMAIN)
 
 void force_evtchn_callback(void);
 
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h
--- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h  Tue Aug 
22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h  Wed Aug 
23 11:11:27 2006 -0600
@@ -46,11 +46,21 @@
 #define __STR(x) #x
 #define STR(x) __STR(x)
 
+#ifdef CONFIG_XEN
+#define HYPERCALL_STR(name)                                    \
+       "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
+#else
+#define HYPERCALL_STR(name)                                    \
+       "mov hypercall_stubs,%%rax; "                           \
+       "add $("STR(__HYPERVISOR_##name)" * 32),%%rax; "        \
+       "call *%%rax"
+#endif
+
 #define _hypercall0(type, name)                        \
 ({                                             \
        long __res;                             \
        asm volatile (                          \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)             \
                : "=a" (__res)                  \
                :                               \
                : "memory" );                   \
@@ -61,7 +71,7 @@
 ({                                                             \
        long __res, __ign1;                                     \
        asm volatile (                                          \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)                             \
                : "=a" (__res), "=D" (__ign1)                   \
                : "1" ((long)(a1))                              \
                : "memory" );                                   \
@@ -72,7 +82,7 @@
 ({                                                             \
        long __res, __ign1, __ign2;                             \
        asm volatile (                                          \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)                             \
                : "=a" (__res), "=D" (__ign1), "=S" (__ign2)    \
                : "1" ((long)(a1)), "2" ((long)(a2))            \
                : "memory" );                                   \
@@ -83,7 +93,7 @@
 ({                                                             \
        long __res, __ign1, __ign2, __ign3;                     \
        asm volatile (                                          \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)                             \
                : "=a" (__res), "=D" (__ign1), "=S" (__ign2),   \
                "=d" (__ign3)                                   \
                : "1" ((long)(a1)), "2" ((long)(a2)),           \
@@ -97,7 +107,7 @@
        long __res, __ign1, __ign2, __ign3;                     \
        asm volatile (                                          \
                "movq %7,%%r10; "                               \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)                             \
                : "=a" (__res), "=D" (__ign1), "=S" (__ign2),   \
                "=d" (__ign3)                                   \
                : "1" ((long)(a1)), "2" ((long)(a2)),           \
@@ -111,7 +121,7 @@
        long __res, __ign1, __ign2, __ign3;                     \
        asm volatile (                                          \
                "movq %7,%%r10; movq %8,%%r8; "                 \
-               "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
+               HYPERCALL_STR(name)                             \
                : "=a" (__res), "=D" (__ign1), "=S" (__ign2),   \
                "=d" (__ign3)                                   \
                : "1" ((long)(a1)), "2" ((long)(a2)),           \
@@ -355,6 +365,13 @@ HYPERVISOR_nmi_op(
        return _hypercall2(int, nmi_op, op, arg);
 }
 
+static inline unsigned long
+HYPERVISOR_hvm_op(
+    int op, void *arg)
+{
+    return _hypercall2(unsigned long, hvm_op, op, arg);
+}
+
 static inline int
 HYPERVISOR_callback_op(
        int cmd, void *arg)
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h
--- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h       Tue Aug 
22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h       Wed Aug 
23 11:11:27 2006 -0600
@@ -7,7 +7,6 @@
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <asm/bug.h>
-#include <xen/features.h>
 #endif
 #include <xen/interface/xen.h> 
 #include <xen/foreign_page.h>
@@ -69,6 +68,8 @@
 
 extern unsigned long end_pfn;
 
+#include <asm/maddr.h>
+
 void clear_page(void *);
 void copy_page(void *, void *);
 
@@ -77,118 +78,6 @@ void copy_page(void *, void *);
 
 #define alloc_zeroed_user_highpage(vma, vaddr) alloc_page_vma(GFP_HIGHUSER | 
__GFP_ZERO, vma, vaddr)
 #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
-
-/**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
-#define INVALID_P2M_ENTRY      (~0UL)
-#define FOREIGN_FRAME_BIT      (1UL<<63)
-#define FOREIGN_FRAME(m)       ((m) | FOREIGN_FRAME_BIT)
-
-extern unsigned long *phys_to_machine_mapping;
-
-#undef machine_to_phys_mapping
-extern unsigned long *machine_to_phys_mapping;
-extern unsigned int   machine_to_phys_order;
-
-static inline unsigned long pfn_to_mfn(unsigned long pfn)
-{
-       if (xen_feature(XENFEAT_auto_translated_physmap))
-               return pfn;
-       return phys_to_machine_mapping[(unsigned int)(pfn)] &
-               ~FOREIGN_FRAME_BIT;
-}
-
-static inline int phys_to_machine_mapping_valid(unsigned long pfn)
-{
-       if (xen_feature(XENFEAT_auto_translated_physmap))
-               return 1;
-       return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
-}
-
-static inline unsigned long mfn_to_pfn(unsigned long mfn)
-{
-       unsigned long pfn;
-
-       if (xen_feature(XENFEAT_auto_translated_physmap))
-               return mfn;
-
-       if (unlikely((mfn >> machine_to_phys_order) != 0))
-               return end_pfn;
-
-       /* The array access can fail (e.g., device space beyond end of RAM). */
-       asm (
-               "1:     movq %1,%0\n"
-               "2:\n"
-               ".section .fixup,\"ax\"\n"
-               "3:     movq %2,%0\n"
-               "       jmp  2b\n"
-               ".previous\n"
-               ".section __ex_table,\"a\"\n"
-               "       .align 8\n"
-               "       .quad 1b,3b\n"
-               ".previous"
-               : "=r" (pfn)
-               : "m" (machine_to_phys_mapping[mfn]), "m" (end_pfn) );
-
-       return pfn;
-}
-
-/*
- * We detect special mappings in one of two ways:
- *  1. If the MFN is an I/O page then Xen will set the m2p entry
- *     to be outside our maximum possible pseudophys range.
- *  2. If the MFN belongs to a different domain then we will certainly
- *     not have MFN in our p2m table. Conversely, if the page is ours,
- *     then we'll have p2m(m2p(MFN))==MFN.
- * If we detect a special mapping then it doesn't have a 'struct page'.
- * We force !pfn_valid() by returning an out-of-range pointer.
- *
- * NB. These checks require that, for any MFN that is not in our reservation,
- * there is no PFN such that p2m(PFN) == MFN. Otherwise we can get confused if
- * we are foreign-mapping the MFN, and the other domain as m2p(MFN) == PFN.
- * Yikes! Various places must poke in INVALID_P2M_ENTRY for safety.
- *
- * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
- *      use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
- *      require. In all the cases we care about, the FOREIGN_FRAME bit is
- *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
- */
-static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
-{
-       unsigned long pfn = mfn_to_pfn(mfn);
-       if ((pfn < end_pfn)
-           && !xen_feature(XENFEAT_auto_translated_physmap)
-           && (phys_to_machine_mapping[pfn] != mfn))
-               return end_pfn; /* force !pfn_valid() */
-       return pfn;
-}
-
-
-static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
-{
-       if (xen_feature(XENFEAT_auto_translated_physmap)) {
-               BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
-               return;
-       }
-       phys_to_machine_mapping[pfn] = mfn;
-}
-
-/* Definitions for machine and pseudophysical addresses. */
-typedef unsigned long paddr_t;
-typedef unsigned long maddr_t;
-
-static inline maddr_t phys_to_machine(paddr_t phys)
-{
-       maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
-       machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
-       return machine;
-}
-
-static inline paddr_t machine_to_phys(maddr_t machine)
-{
-       paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
-       phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
-       return phys;
-}
 
 /*
  * These are used to make use of C type-checking..
@@ -227,8 +116,6 @@ static inline unsigned long pgd_val(pgd_
 }
 
 #define pgprot_val(x)  ((x).pgprot)
-
-#define __pte_ma(x)     ((pte_t) { (x) } )
 
 static inline pte_t __pte(unsigned long x)
 {
@@ -310,11 +197,6 @@ static inline pgd_t __pgd(unsigned long 
 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
 #define pfn_to_kaddr(pfn)      __va((pfn) << PAGE_SHIFT)
 
-/* VIRT <-> MACHINE conversion */
-#define virt_to_machine(v)     (phys_to_machine(__pa(v)))
-#define virt_to_mfn(v)         (pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
-#define mfn_to_virt(m)         (__va(mfn_to_pfn(m) << PAGE_SHIFT))
-
 #define VM_DATA_DEFAULT_FLAGS \
        (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
         VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
diff -r 91169603a8e8 -r 79afceca9065 
linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgtable.h
--- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgtable.h    Tue Aug 
22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgtable.h    Wed Aug 
23 11:11:27 2006 -0600
@@ -206,7 +206,7 @@ static inline pte_t ptep_get_and_clear_f
 #define _PAGE_NX        (1UL<<_PAGE_BIT_NX)
 
 #define _PAGE_TABLE    (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED 
| _PAGE_DIRTY)
-#define _KERNPG_TABLE  _PAGE_TABLE
+#define _KERNPG_TABLE  (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | 
_PAGE_DIRTY)
 
 #define _PAGE_CHG_MASK (PTE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
 
@@ -219,22 +219,21 @@ static inline pte_t ptep_get_and_clear_f
 #define PAGE_READONLY  __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | 
_PAGE_NX)
 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | 
_PAGE_ACCESSED)
 #define __PAGE_KERNEL \
-       (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_NX | 
_PAGE_USER )
+       (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_NX)
 #define __PAGE_KERNEL_EXEC \
-       (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_USER )
+       (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
 #define __PAGE_KERNEL_NOCACHE \
-       (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_PCD | _PAGE_ACCESSED | 
_PAGE_NX | _PAGE_USER )
+       (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_PCD | _PAGE_ACCESSED | 
_PAGE_NX)
 #define __PAGE_KERNEL_RO \
-       (_PAGE_PRESENT | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_NX | _PAGE_USER )
+       (_PAGE_PRESENT | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_NX)
 #define __PAGE_KERNEL_VSYSCALL \
-       (_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_USER )
+       (_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
 #define __PAGE_KERNEL_VSYSCALL_NOCACHE \
-       (_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_PCD | _PAGE_USER )
+       (_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_PCD)
 #define __PAGE_KERNEL_LARGE \
-       (__PAGE_KERNEL | _PAGE_PSE | _PAGE_USER )
+       (__PAGE_KERNEL | _PAGE_PSE)
 #define __PAGE_KERNEL_LARGE_EXEC \
-       (__PAGE_KERNEL_EXEC | _PAGE_PSE | _PAGE_USER )
-
+       (__PAGE_KERNEL_EXEC | _PAGE_PSE)
 
 /*
  * We don't support GLOBAL page in xenolinux64
@@ -312,7 +311,6 @@ static inline pte_t pfn_pte(unsigned lon
        return pte;
 }
 
-#define pfn_pte_ma(pfn, prot)  __pte_ma((((pfn) << PAGE_SHIFT) | 
pgprot_val(prot)) & __supported_pte_mask)
 /*
  * The following only work if pte_present() is true.
  * Undefined behaviour if not..
@@ -424,7 +422,7 @@ static inline pud_t *pud_offset_k(pgd_t 
    can temporarily clear it. */
 #define pmd_present(x) (pmd_val(x))
 #define pmd_clear(xp)  do { set_pmd(xp, __pmd(0)); } while (0)
-#define        pmd_bad(x)      ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_PRESENT)) 
!= (_KERNPG_TABLE & ~_PAGE_PRESENT))
+#define        pmd_bad(x)      ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER & 
~_PAGE_PRESENT)) != (_KERNPG_TABLE & ~_PAGE_PRESENT))
 #define pfn_pmd(nr,prot) (__pmd(((nr) << PAGE_SHIFT) | pgprot_val(prot)))
 #define pmd_pfn(x)  ((pmd_val(x) & __PHYSICAL_MASK) >> PAGE_SHIFT)
 
diff -r 91169603a8e8 -r 79afceca9065 linux-2.6-xen-sparse/include/xen/balloon.h
--- a/linux-2.6-xen-sparse/include/xen/balloon.h        Tue Aug 22 14:45:49 
2006 -0600
+++ b/linux-2.6-xen-sparse/include/xen/balloon.h        Wed Aug 23 11:11:27 
2006 -0600
@@ -38,19 +38,23 @@
  * Inform the balloon driver that it should allow some slop for device-driver
  * memory activities.
  */
-extern void
+void
 balloon_update_driver_allowance(
        long delta);
 
 /* Allocate an empty low-memory page range. */
-extern struct page *
+struct page *
 balloon_alloc_empty_page_range(
        unsigned long nr_pages);
 
 /* Deallocate an empty page range, adding to the balloon. */
-extern void
+void
 balloon_dealloc_empty_page_range(
        struct page *page, unsigned long nr_pages);
+
+void
+balloon_release_driver_page(
+       struct page *page);
 
 /*
  * Prevent the balloon driver from changing the memory reservation during
diff -r 91169603a8e8 -r 79afceca9065 linux-2.6-xen-sparse/include/xen/xenbus.h
--- a/linux-2.6-xen-sparse/include/xen/xenbus.h Tue Aug 22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/include/xen/xenbus.h Wed Aug 23 11:11:27 2006 -0600
@@ -274,7 +274,7 @@ int xenbus_free_evtchn(struct xenbus_dev
 
 /**
  * Return the state of the driver rooted at the given store path, or
- * XenbusStateClosed if no state can be read.
+ * XenbusStateUnknown if no state can be read.
  */
 enum xenbus_state xenbus_read_driver_state(const char *path);
 
@@ -295,5 +295,6 @@ void xenbus_dev_fatal(struct xenbus_devi
 void xenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt,
                      ...);
 
+int __init xenbus_dev_init(void);
 
 #endif /* _XEN_XENBUS_H */
diff -r 91169603a8e8 -r 79afceca9065 linux-2.6-xen-sparse/mm/memory.c
--- a/linux-2.6-xen-sparse/mm/memory.c  Tue Aug 22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/mm/memory.c  Wed Aug 23 11:11:27 2006 -0600
@@ -390,7 +390,7 @@ struct page *vm_normal_page(struct vm_ar
 
        if (vma->vm_flags & VM_PFNMAP) {
                unsigned long off = (addr - vma->vm_start) >> PAGE_SHIFT;
-               if (pfn == vma->vm_pgoff + off)
+               if ((pfn == vma->vm_pgoff + off) || !pfn_valid(pfn))
                        return NULL;
                if (!is_cow_mapping(vma->vm_flags))
                        return NULL;
@@ -405,8 +405,7 @@ struct page *vm_normal_page(struct vm_ar
         * Remove this test eventually!
         */
        if (unlikely(!pfn_valid(pfn))) {
-               if (!(vma->vm_flags & VM_RESERVED))
-                       print_bad_pte(vma, pte, addr);
+               print_bad_pte(vma, pte, addr);
                return NULL;
        }
 
diff -r 91169603a8e8 -r 79afceca9065 linux-2.6-xen-sparse/net/core/dev.c
--- a/linux-2.6-xen-sparse/net/core/dev.c       Tue Aug 22 14:45:49 2006 -0600
+++ b/linux-2.6-xen-sparse/net/core/dev.c       Wed Aug 23 11:11:27 2006 -0600
@@ -1093,11 +1093,6 @@ int skb_checksum_help(struct sk_buff *sk
                goto out_set_summed;
 
        if (unlikely(skb_shinfo(skb)->gso_size)) {
-               static int warned;
-
-               WARN_ON(!warned);
-               warned = 1;
-
                /* Let GSO fix up the checksum. */
                goto out_set_summed;
        }
@@ -1147,11 +1142,6 @@ struct sk_buff *skb_gso_segment(struct s
        __skb_pull(skb, skb->mac_len);
 
        if (unlikely(skb->ip_summed != CHECKSUM_HW)) {
-               static int warned;
-
-               WARN_ON(!warned);
-               warned = 1;
-
                if (skb_header_cloned(skb) &&
                    (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
                        return ERR_PTR(err);
diff -r 91169603a8e8 -r 79afceca9065 tools/blktap/lib/Makefile
--- a/tools/blktap/lib/Makefile Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/blktap/lib/Makefile Wed Aug 23 11:11:27 2006 -0600
@@ -61,7 +61,7 @@ libblktap.a: $(OBJS)
              -o libblktap.so.$(MAJOR).$(MINOR) $^ $(LIBS)
        ln -sf libblktap.so.$(MAJOR).$(MINOR) libblktap.so.$(MAJOR)
        ln -sf libblktap.so.$(MAJOR) libblktap.so
-       ar rc $@ libblktap.so
+       $(AR) rc $@ libblktap.so
 
 .PHONY: TAGS all build clean install libblktap
 
diff -r 91169603a8e8 -r 79afceca9065 tools/examples/xen-network-common.sh
--- a/tools/examples/xen-network-common.sh      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/examples/xen-network-common.sh      Wed Aug 23 11:11:27 2006 -0600
@@ -143,6 +143,7 @@ add_to_bridge () {
 
     # Don't add $dev to $bridge if it's already on a bridge.
     if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
+       ip link set ${dev} up || true
        return
     fi
     brctl addif ${bridge} ${dev}
diff -r 91169603a8e8 -r 79afceca9065 tools/examples/xend-config.sxp
--- a/tools/examples/xend-config.sxp    Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/examples/xend-config.sxp    Wed Aug 23 11:11:27 2006 -0600
@@ -54,7 +54,7 @@
 #  (xend-relocation-hosts-allow '^localhost$ ^.*\.example\.org$')
 #
 #(xend-relocation-hosts-allow '')
-(xend-relocation-hosts-allow '^localhost$ ^localhost\.localdomain$')
+(xend-relocation-hosts-allow '^localhost$ ^localhost\\.localdomain$')
 
 # The limit (in kilobytes) on the size of the console buffer
 #(console-limit 1024)
diff -r 91169603a8e8 -r 79afceca9065 tools/examples/xmexample.hvm
--- a/tools/examples/xmexample.hvm      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/examples/xmexample.hvm      Wed Aug 23 11:11:27 2006 -0600
@@ -26,6 +26,10 @@ builder='hvm'
 #          memory errors. The domain needs enough memory to boot kernel
 #          and modules. Allocating less than 32MBs is not recommended.
 memory = 128
+
+# Shadow pagetable memory for the domain, in MB.
+# Should be at least 2KB per MB of domain memory, plus a few MB per vcpu.
+shadow_memory = 8
 
 # A name for your domain. All domains must have different names.
 name = "ExampleHVMDomain"
@@ -112,7 +116,9 @@ device_model = '/usr/' + arch_libdir + '
 
 #-----------------------------------------------------------------------------
 # boot on floppy (a), hard disk (c) or CD-ROM (d) 
-#boot=[a|c|d]
+# default: hard disk, cd-rom, floppy
+#boot="cda"
+
 #-----------------------------------------------------------------------------
 #  write to temporary files instead of disk image files
 #snapshot=1
diff -r 91169603a8e8 -r 79afceca9065 tools/examples/xmexample.vti
--- a/tools/examples/xmexample.vti      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/examples/xmexample.vti      Wed Aug 23 11:11:27 2006 -0600
@@ -66,7 +66,9 @@ device_model = '/usr/' + arch_libdir + '
 
 #-----------------------------------------------------------------------------
 # boot on floppy (a), hard disk (c) or CD-ROM (d) 
-#boot=[a|c|d]
+# default: hard disk, cd-rom, floppy
+#boot="cda"
+
 #-----------------------------------------------------------------------------
 #  write to temporary files instead of disk image files
 #snapshot=1
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/acpi/acpi_fadt.h
--- a/tools/firmware/acpi/acpi_fadt.h   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/acpi/acpi_fadt.h   Wed Aug 23 11:11:27 2006 -0600
@@ -59,8 +59,7 @@
 #define ACPI_PM1A_EVT_BLK_ADDRESS_SPACE_ID  ACPI_SYSTEM_IO
 #define ACPI_PM1A_EVT_BLK_BIT_WIDTH         0x20
 #define ACPI_PM1A_EVT_BLK_BIT_OFFSET        0x00
-//#define ACPI_PM1A_EVT_BLK_ADDRESS           0x000000000000c010
-#define ACPI_PM1A_EVT_BLK_ADDRESS           0x000000000000c040
+#define ACPI_PM1A_EVT_BLK_ADDRESS           0x000000000000c010
 
 //
 // PM1B Event Register Block Generic Address Information
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/hvmloader/Makefile
--- a/tools/firmware/hvmloader/Makefile Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/hvmloader/Makefile Wed Aug 23 11:11:27 2006 -0600
@@ -31,8 +31,6 @@ DEFINES  =-DDEBUG
 DEFINES  =-DDEBUG
 XENINC   =-I$(XEN_ROOT)/tools/libxc
 
-OBJECTS         = hvmloader.o acpi_madt.o 
-
 # Disable PIE/SSP if GCC supports them. They can break us.
 CFLAGS  += $(call test-gcc-flag,$(CC),-nopie)
 CFLAGS  += $(call test-gcc-flag,$(CC),-fno-stack-protector)
@@ -42,7 +40,7 @@ CFLAGS  += $(DEFINES) -I. $(XENINC) -fno
 CFLAGS  += $(DEFINES) -I. $(XENINC) -fno-builtin -O2 -msoft-float
 LDFLAGS  = -m32 -nostdlib -Wl,-N -Wl,-Ttext -Wl,$(LOADADDR)
 
-SRCS = hvmloader.c acpi_madt.c mp_tables.c util.c
+SRCS = hvmloader.c acpi_madt.c mp_tables.c util.c smbios.c
 OBJS = $(patsubst %.c,%.o,$(SRCS))
 
 .PHONY: all
@@ -54,7 +52,7 @@ hvmloader: roms.h $(SRCS)
        $(OBJCOPY) hvmloader.tmp hvmloader
        rm -f hvmloader.tmp
 
-roms.h:        ../rombios/BIOS-bochs-latest ../vgabios/VGABIOS-lgpl-latest.bin 
../vgabios/VGABIOS-lgpl-latest.cirrus.bin ../vmxassist/vmxassist.bin
+roms.h:        ../rombios/BIOS-bochs-latest ../vgabios/VGABIOS-lgpl-latest.bin 
../vgabios/VGABIOS-lgpl-latest.cirrus.bin ../vmxassist/vmxassist.bin 
../acpi/acpi.bin
        sh ./mkhex rombios ../rombios/BIOS-bochs-latest > roms.h
        sh ./mkhex vgabios_stdvga ../vgabios/VGABIOS-lgpl-latest.bin >> roms.h
        sh ./mkhex vgabios_cirrusvga ../vgabios/VGABIOS-lgpl-latest.cirrus.bin 
>> roms.h
@@ -64,5 +62,5 @@ roms.h:       ../rombios/BIOS-bochs-latest ../
 .PHONY: clean
 clean:
        rm -f roms.h acpi.h
-       rm -f hvmloader hvmloader.tmp hvmloader.o $(OBJECTS)
+       rm -f hvmloader hvmloader.tmp hvmloader.o $(OBJS)
 
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/hvmloader/hvmloader.c
--- a/tools/firmware/hvmloader/hvmloader.c      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/hvmloader/hvmloader.c      Wed Aug 23 11:11:27 2006 -0600
@@ -25,8 +25,9 @@
 #include "../acpi/acpi2_0.h"  /* for ACPI_PHYSICAL_ADDRESS */
 #include "hypercall.h"
 #include "util.h"
+#include "smbios.h"
 #include <xen/version.h>
-#include <xen/hvm/hvm_info_table.h>
+#include <xen/hvm/params.h>
 
 /* memory map */
 #define HYPERCALL_PHYSICAL_ADDRESS     0x00080000
@@ -116,15 +117,6 @@ check_amd(void)
 }
 
 static void
-cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
-{
-       __asm__ __volatile__(
-               "cpuid"
-               : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
-               : "0" (idx) );
-}
-
-static void
 wrmsr(uint32_t idx, uint64_t v)
 {
        __asm__ __volatile__(
@@ -172,7 +164,7 @@ int
 int
 main(void)
 {
-       struct hvm_info_table *t = get_hvm_info_table();
+       struct xen_hvm_param hvm_param;
 
        puts("HVM Loader\n");
 
@@ -180,7 +172,10 @@ main(void)
 
        puts("Loading ROMBIOS ...\n");
        memcpy((void *)ROMBIOS_PHYSICAL_ADDRESS, rombios, sizeof(rombios));
-       if (t->apic_enabled)
+
+       hvm_param.domid = DOMID_SELF;
+       hvm_param.index = HVM_PARAM_APIC_ENABLED;
+       if (!hypercall_hvm_op(HVMOP_get_param, &hvm_param) && hvm_param.value)
                create_mp_tables();
        
        if (cirrus_check()) {
@@ -206,6 +201,9 @@ main(void)
                }
        }
 
+       puts("Writing SMBIOS tables ...\n");
+       hvm_write_smbios_tables();
+
        if (check_amd()) {
                /* AMD implies this is SVM */
                 puts("SVM go ...\n");
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/hvmloader/hypercall.h
--- a/tools/firmware/hvmloader/hypercall.h      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/hvmloader/hypercall.h      Wed Aug 23 11:11:27 2006 -0600
@@ -30,6 +30,8 @@
 
 #ifndef __HVMLOADER_HYPERCALL_H__
 #define __HVMLOADER_HYPERCALL_H__
+
+#include <xen/xen.h>
 
 /*
  * NB. Hypercall address needs to be relative to a linkage symbol for
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/hvmloader/util.c
--- a/tools/firmware/hvmloader/util.c   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/hvmloader/util.c   Wed Aug 23 11:11:27 2006 -0600
@@ -20,6 +20,7 @@
 
 #include "../acpi/acpi2_0.h"  /* for ACPI_PHYSICAL_ADDRESS */
 #include "util.h"
+#include <stdint.h>
 
 void outw(uint16_t addr, uint16_t val)
 {
@@ -94,3 +95,82 @@ void puts(const char *s)
        while (*s)
                outb(0xE9, *s++);
 }
+
+char *
+strcpy(char *dest, const char *src)
+{
+       char *p = dest;
+       while (*src)
+               *p++ = *src++;
+       *p = 0;
+       return dest;
+}
+
+char *
+strncpy(char *dest, const char *src, unsigned n)
+{
+       int i = 0;
+       char *p = dest;
+
+       /* write non-NUL characters from src into dest until we run
+          out of room in dest or encounter a NUL in src */
+       while (i < n && *src) {
+               *p++ = *src++;
+               ++i;
+       }
+
+       /* pad remaining bytes of dest with NUL bytes */
+       while (i < n) {
+               *p++ = 0;
+               ++i;
+       }
+
+       return dest;
+}
+
+unsigned
+strlen(const char *s)
+{
+       int i = 0;
+       while (*s++)
+               ++i;
+       return i;
+}
+
+void *
+memset(void *s, int c, unsigned n)
+{
+       uint8_t b = (uint8_t) c;
+       uint8_t *p = (uint8_t *)s;
+       int i;
+       for (i = 0; i < n; ++i)
+               *p++ = b;
+       return s;
+}
+
+int
+memcmp(const void *s1, const void *s2, unsigned n)
+{
+       unsigned i;
+       uint8_t *p1 = (uint8_t *) s1;
+       uint8_t *p2 = (uint8_t *) s2;
+
+       for (i = 0; i < n; ++i) {
+               if (p1[i] < p2[i])
+                       return -1;
+               else if (p1[i] > p2[i])
+                       return 1;
+       }
+
+       return 0;
+}
+
+void
+cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
+{
+       __asm__ __volatile__(
+               "cpuid"
+               : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+               : "0" (idx) );
+}
+
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/hvmloader/util.h   Wed Aug 23 11:11:27 2006 -0600
@@ -8,9 +8,21 @@ void outb(uint16_t addr, uint8_t val);
 /* I/O input */
 uint8_t inb(uint16_t addr);
 
+/* Do cpuid instruction, with operation 'idx' */
+void cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx,
+           uint32_t *ecx, uint32_t *edx);
+
+/* Return number of vcpus. */
+int get_vcpu_nr(void);
+
 /* String and memory functions */
 int strcmp(const char *cs, const char *ct);
+char *strcpy(char *dest, const char *src);
+char *strncpy(char *dest, const char *src, unsigned n);
+unsigned strlen(const char *s);
+int memcmp(const void *s1, const void *s2, unsigned n);
 void *memcpy(void *dest, const void *src, unsigned n);
+void *memset(void *s, int c, unsigned n);
 char *itoa(char *a, unsigned int i);
 
 /* Debug output */
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/rombios/apmbios.S
--- a/tools/firmware/rombios/apmbios.S  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/rombios/apmbios.S  Wed Aug 23 11:11:27 2006 -0600
@@ -225,7 +225,10 @@ APMSYM(05):
 APMSYM(05):
   cmp al, #0x05
   jne APMSYM(07)
+  pushf ; XEN
+  sti   ; XEN: OS calls us with ints disabled -- better re-enable here!
   hlt
+  popf  ; XEN
   jmp APMSYM(ok)
 
 ;-----------------
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/rombios/rombios.c
--- a/tools/firmware/rombios/rombios.c  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/rombios/rombios.c  Wed Aug 23 11:11:27 2006 -0600
@@ -9443,6 +9443,43 @@ rom_scan_increment:
   mov  ds, ax
   ret
 
+#ifdef HVMASSIST
+
+; Copy the SMBIOS entry point over from 0x9f000, where hvmloader left it.
+; The entry point must be somewhere in 0xf0000-0xfffff on a 16-byte boundary,
+; but the tables themeselves can be elsewhere.
+smbios_init:
+  push ax
+  push cx
+  push es
+  push ds
+  push di
+  push si
+
+  mov cx, #0x001f ; 0x1f bytes to copy
+  mov ax, #0xf000
+  mov es, ax      ; destination segment is 0xf0000
+  mov di, #smbios_entry_point ; destination offset
+  mov ax, #0x9f00
+  mov ds, ax      ; source segment is 0x9f000
+  mov si, #0x0000 ; source offset is 0
+  cld
+  rep
+    movsb
+
+  pop si
+  pop di
+  pop ds
+  pop es
+  pop cx
+  pop ax
+
+  ret
+
+#endif
+
+
+
 ;; for 'C' strings and other data, insert them here with
 ;; a the following hack:
 ;; DATA_SEG_DEFS_HERE
@@ -9724,6 +9761,7 @@ post_default_ints:
 
 #ifdef HVMASSIST
   call _copy_e820_table
+  call smbios_init
 #endif
 
   call rom_scan
@@ -10538,6 +10576,13 @@ dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;; 768 bytes
 dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;; 832 bytes
 dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;; 896 bytes
+
+.align 16
+smbios_entry_point:
+db 0,0,0,0,0,0,0,0 ; 8 bytes
+db 0,0,0,0,0,0,0,0 ; 16 bytes
+db 0,0,0,0,0,0,0,0 ; 24 bytes
+db 0,0,0,0,0,0,0   ; 31 bytes
 ASM_END
 
 #else // !HVMASSIST
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/vmxassist/head.S
--- a/tools/firmware/vmxassist/head.S   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/vmxassist/head.S   Wed Aug 23 11:11:27 2006 -0600
@@ -114,8 +114,6 @@ _start:
 #ifdef TEST
        xorl    %edx, %edx
 #endif
-       movl    %edx, booting_cpu
-       movl    %ebx, booting_vector
 
        /* clear bss */
        cld
@@ -124,6 +122,9 @@ _start:
        movl    $_ebss, %ecx
        subl    %edi, %ecx
        rep     stosb
+
+       movl    %edx, booting_cpu
+       movl    %ebx, booting_vector
 
        /* make sure we are in a sane world */
        clts
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/vmxassist/setup.c
--- a/tools/firmware/vmxassist/setup.c  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/vmxassist/setup.c  Wed Aug 23 11:11:27 2006 -0600
@@ -56,7 +56,7 @@ struct e820entry e820map[] = {
        { 0x00000000000A0000ULL, 0x0000000000020000ULL, E820_IO },
        { 0x00000000000C0000ULL, 0x0000000000040000ULL, E820_RESERVED },
        { 0x0000000000100000ULL, 0x0000000000000000ULL, E820_RAM },
-       { 0x0000000000000000ULL, 0x0000000000001000ULL, E820_SHARED },
+       { 0x0000000000000000ULL, 0x0000000000001000ULL, E820_SHARED_PAGE },
        { 0x0000000000000000ULL, 0x0000000000003000ULL, E820_NVS },
        { 0x0000000000003000ULL, 0x000000000000A000ULL, E820_ACPI },
        { 0x00000000FEC00000ULL, 0x0000000001400000ULL, E820_IO },
@@ -94,13 +94,13 @@ banner(void)
        e820map[6].addr = memory_size;
        e820map[7].addr += memory_size;
 
-       *LINUX_E820_MAP_NR = sizeof(e820map)/sizeof(e820map[0]);
-       memcpy(LINUX_E820_MAP, e820map, sizeof(e820map));
+       *E820_MAP_NR = sizeof(e820map)/sizeof(e820map[0]);
+       memcpy(E820_MAP, e820map, sizeof(e820map));
 #endif
 
        printf("Memory size %ld MB\n", memory_size >> 20);
        printf("E820 map:\n");
-       print_e820_map(LINUX_E820_MAP, *LINUX_E820_MAP_NR);
+       print_e820_map(E820_MAP, *E820_MAP_NR);
        printf("\n");
 }
 
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/vmxassist/util.h
--- a/tools/firmware/vmxassist/util.h   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/vmxassist/util.h   Wed Aug 23 11:11:27 2006 -0600
@@ -23,23 +23,9 @@
 #include <stdarg.h>
 #include <vm86.h>
 
-
-#define        LINUX_E820_MAP_NR       ((unsigned char *)0x901E8)
-#define        LINUX_E820_MAP          ((struct e820entry *)0x902D0)
-
-#define        E820_RAM        1
-#define        E820_RESERVED   2
-#define        E820_ACPI       3
-#define        E820_NVS        4
-#define        E820_IO         16
-#define        E820_SHARED     17
-
-struct e820entry {
-       unsigned long long      addr;
-       unsigned long long      size;
-       unsigned long           type;
-} __attribute__((packed));
-
+#include <xen/hvm/e820.h>
+#define E820_MAP_NR ((unsigned char *)E820_MAP_PAGE + E820_MAP_NR_OFFSET)
+#define E820_MAP    ((struct e820entry *)(E820_MAP_PAGE + E820_MAP_OFFSET))
 
 #define        offsetof(type, member)  ((unsigned) &((type *)0)->member)
 
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/vmxassist/vm86.c
--- a/tools/firmware/vmxassist/vm86.c   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/vmxassist/vm86.c   Wed Aug 23 11:11:27 2006 -0600
@@ -983,7 +983,9 @@ set_mode(struct regs *regs, enum vm86_mo
        case VM86_PROTECTED:
                if (mode == VM86_REAL_TO_PROTECTED) {
                        protected_mode(regs);
-                       break;
+//                     printf("<VM86_PROTECTED>\n");
+                       mode = newmode;
+                       return;
                } else
                        panic("unexpected protected mode transition");
                break;
@@ -1170,6 +1172,26 @@ inbyte(struct regs *regs, unsigned prefi
        return 1;
 }
 
+static void
+pushrm(struct regs *regs, int prefix, unsigned modrm)
+{
+       unsigned n = regs->eip;
+       unsigned addr;
+       unsigned data;
+
+       addr  = operand(prefix, regs, modrm);
+       
+       if (prefix & DATA32) {
+               data = read32(addr);
+               push32(regs, data);
+       } else {
+               data = read16(addr);
+               push16(regs, data);
+       }
+
+       TRACE((regs, (regs->eip - n) + 1, "push *0x%x", addr));
+}
+
 enum { OPC_INVALID, OPC_EMULATED };
 
 /*
@@ -1186,6 +1208,14 @@ opcode(struct regs *regs)
 
        for (;;) {
                switch ((opc = fetch8(regs))) {
+               case 0x07:
+                       if (prefix & DATA32)
+                               regs->ves = pop32(regs);
+                       else
+                               regs->ves = pop16(regs);
+                       TRACE((regs, regs->eip - eip, "pop %%es"));
+                       return OPC_EMULATED;
+
                case 0x0F: /* two byte opcode */
                        if (mode == VM86_PROTECTED)
                                goto invalid;
@@ -1288,6 +1318,22 @@ opcode(struct regs *regs)
                         return OPC_EMULATED;
 
                case 0x89: /* addr32 mov r16, r/m16 */
+                       if (mode == VM86_PROTECTED_TO_REAL) {
+                               unsigned modrm = fetch8(regs);
+                               unsigned addr = operand(prefix, regs, modrm);
+                               unsigned val, r = (modrm >> 3) & 7;
+                               
+                               if (prefix & DATA32) {
+                                       val = getreg16(regs, r);
+                                       write32(addr, val);
+                               } else {
+                                       val = getreg32(regs, r);
+                                       write16(addr, MASK16(val));
+                               }
+                               TRACE((regs, regs->eip - eip,
+                                       "mov %%%s, *0x%x", rnames[r], addr));
+                               return OPC_EMULATED;
+                       }
                case 0x8B: /* addr32 mov r/m16, r16 */
                        if (mode != VM86_REAL && mode != VM86_REAL_TO_PROTECTED)
                                goto invalid;
@@ -1324,6 +1370,37 @@ opcode(struct regs *regs)
                                regs->eflags = (regs->eflags & 0xFFFF0000L) |
                                                                pop16(regs);
                        regs->eflags |= EFLAGS_VM;
+                       return OPC_EMULATED;
+
+               case 0xA1: /* mov ax, r/m16 */ 
+                       {
+                               int addr, data;
+                               int seg = segment(prefix, regs, regs->vds);
+                               if (prefix & DATA32) {
+                                       addr = address(regs, seg, 
fetch32(regs));
+                                       data = read32(addr);
+                                       setreg32(regs, 0, data);
+                               } else {
+                                       addr = address(regs, seg, 
fetch16(regs));
+                                       data = read16(addr);
+                                       setreg16(regs, 0, data);
+                               }
+                               TRACE((regs, regs->eip - eip, "mov *0x%x, 
%%ax", addr));
+                       }
+                       return OPC_EMULATED;
+
+               case 0xBB: /* mov bx, imm16 */
+                       {
+                               int data;
+                               if (prefix & DATA32) {
+                                       data = fetch32(regs);
+                                       setreg32(regs, 3, data);
+                               } else {
+                                       data = fetch16(regs);
+                                       setreg16(regs, 3, data);
+                               }
+                               TRACE((regs, regs->eip - eip, "mov $0x%x, 
%%bx", data));
+                       }
                        return OPC_EMULATED;
 
                case 0xC6: /* addr32 movb $imm, r/m8 */
@@ -1380,21 +1457,25 @@ opcode(struct regs *regs)
                        goto invalid;
 
                case 0xFF: /* jmpl (indirect) */
-                       if ((mode == VM86_REAL_TO_PROTECTED) ||
-                           (mode == VM86_PROTECTED_TO_REAL)) {
-                               unsigned modrm = fetch8(regs);
-                               
+                       {
+                               unsigned modrm = fetch8(regs);
                                switch((modrm >> 3) & 7) {
-                               case 5:
-                                 jmpl_indirect(regs, prefix, modrm);
-                                 return OPC_INVALID;
+                               case 5: /* jmpl (indirect) */
+                                       if ((mode == VM86_REAL_TO_PROTECTED) ||
+                                           (mode == VM86_PROTECTED_TO_REAL)) {
+                                               jmpl_indirect(regs, prefix, 
modrm);
+                                               return OPC_INVALID;
+                                       }
+                                       goto invalid;
+
+                               case 6: /* push r/m16 */
+                                       pushrm(regs, prefix, modrm);
+                                       return OPC_EMULATED;
 
                                default:
-                                 break;
+                                       goto invalid;
                                }
-
                        }
-                       goto invalid;
 
                case 0xEB: /* short jump */
                        if ((mode == VM86_REAL_TO_PROTECTED) ||
diff -r 91169603a8e8 -r 79afceca9065 tools/firmware/vmxassist/vmxassist.ld
--- a/tools/firmware/vmxassist/vmxassist.ld     Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/firmware/vmxassist/vmxassist.ld     Wed Aug 23 11:11:27 2006 -0600
@@ -6,27 +6,27 @@ ENTRY(_start)
 
 SECTIONS
 {
+       _btext = .;
        .text TEXTADDR : 
        {
-               _btext = .;
                *(.text)
                *(.rodata)
                *(.rodata.*)
-               _etext = .;
        }
+       _etext = .;
 
+       _bdata = .;
        .data :
        {
-               _bdata = .;
                *(.data)
-               _edata = .;
        }
+       _edata = .;
 
+       _bbss = .;
        .bss :
        {
-               _bbss = .;
                *(.bss)
-               _ebss = .;
        }
+       _ebss = .;
 }
 
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/Makefile.target
--- a/tools/ioemu/Makefile.target       Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/Makefile.target       Wed Aug 23 11:11:27 2006 -0600
@@ -359,6 +359,7 @@ VL_OBJS+= usb-uhci.o
 VL_OBJS+= usb-uhci.o
 VL_OBJS+= piix4acpi.o
 VL_OBJS+= xenstore.o
+VL_OBJS+= xen_platform.o
 DEFINES += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), ppc)
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/block-bochs.c
--- a/tools/ioemu/block-bochs.c Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/block-bochs.c Wed Aug 23 11:11:27 2006 -0600
@@ -91,7 +91,7 @@ static int bochs_open(BlockDriverState *
     int fd, i;
     struct bochs_header bochs;
 
-    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC);
+    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
     if (fd < 0) {
         fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
         if (fd < 0)
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/block-cloop.c
--- a/tools/ioemu/block-cloop.c Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/block-cloop.c Wed Aug 23 11:11:27 2006 -0600
@@ -55,7 +55,7 @@ static int cloop_open(BlockDriverState *
     BDRVCloopState *s = bs->opaque;
     uint32_t offsets_size,max_compressed_block_size=1,i;
 
-    s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE | O_SYNC);
+    s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
     if (s->fd < 0)
         return -1;
     bs->read_only = 1;
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/block-cow.c
--- a/tools/ioemu/block-cow.c   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/block-cow.c   Wed Aug 23 11:11:27 2006 -0600
@@ -69,7 +69,7 @@ static int cow_open(BlockDriverState *bs
     struct cow_header_v2 cow_header;
     int64_t size;
 
-    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC);
+    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
     if (fd < 0) {
         fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
         if (fd < 0)
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/block-qcow.c
--- a/tools/ioemu/block-qcow.c  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/block-qcow.c  Wed Aug 23 11:11:27 2006 -0600
@@ -95,7 +95,7 @@ static int qcow_open(BlockDriverState *b
     int fd, len, i, shift;
     QCowHeader header;
     
-    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC);
+    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
     if (fd < 0) {
         fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
         if (fd < 0)
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/block-vmdk.c
--- a/tools/ioemu/block-vmdk.c  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/block-vmdk.c  Wed Aug 23 11:11:27 2006 -0600
@@ -96,7 +96,7 @@ static int vmdk_open(BlockDriverState *b
     uint32_t magic;
     int l1_size;
 
-    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC);
+    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
     if (fd < 0) {
         fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
         if (fd < 0)
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/block.c
--- a/tools/ioemu/block.c       Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/block.c       Wed Aug 23 11:11:27 2006 -0600
@@ -685,7 +685,7 @@ static int raw_open(BlockDriverState *bs
     int rv;
 #endif
 
-    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC);
+    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
     if (fd < 0) {
         fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
         if (fd < 0)
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/hw/ide.c
--- a/tools/ioemu/hw/ide.c      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/hw/ide.c      Wed Aug 23 11:11:27 2006 -0600
@@ -305,6 +305,7 @@ typedef struct IDEState {
     PCIDevice *pci_dev;
     struct BMDMAState *bmdma;
     int drive_serial;
+    int write_cache;
     /* ide regs */
     uint8_t feature;
     uint8_t error;
@@ -789,6 +790,9 @@ static void ide_sector_write(IDEState *s
     }
     ide_set_sector(s, sector_num + n);
     
+    if (!s->write_cache)
+        bdrv_flush(s->bs);
+    
 #ifdef TARGET_I386
     if (win2k_install_hack && ((++s->irq_count % 16) == 0)) {
         /* It seems there is a bug in the Windows 2000 installer HDD
@@ -863,6 +867,10 @@ static int ide_write_dma_cb(IDEState *s,
         transfer_size -= len;
         phys_addr += len;
     }
+    /* Ensure the data hit disk before telling the guest OS so. */
+    if (!s->write_cache)
+        bdrv_flush(s->bs);
+
     return transfer_size1 - transfer_size;
 }
 
@@ -1672,7 +1680,15 @@ static void ide_ioport_write(void *opaqu
             /* XXX: valid for CDROM ? */
             switch(s->feature) {
             case 0x02: /* write cache enable */
+                s->write_cache = 1;
+                s->status = READY_STAT | SEEK_STAT;
+                ide_set_irq(s);
+                break;
             case 0x82: /* write cache disable */
+                s->write_cache = 0;
+                s->status = READY_STAT | SEEK_STAT;
+                ide_set_irq(s);
+                break;
             case 0xaa: /* read look-ahead enable */
             case 0x55: /* read look-ahead disable */
                 s->status = READY_STAT | SEEK_STAT;
@@ -2090,6 +2106,7 @@ static void ide_init2(IDEState *ide_stat
         s->irq = irq;
         s->sector_write_timer = qemu_new_timer(vm_clock, 
                                                ide_sector_write_timer_cb, s);
+        s->write_cache = 0;
         ide_reset(s);
     }
 }
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/hw/pc.c
--- a/tools/ioemu/hw/pc.c       Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/hw/pc.c       Wed Aug 23 11:11:27 2006 -0600
@@ -158,8 +158,23 @@ static void cmos_init_hd(int type_ofs, i
     rtc_set_memory(s, info_ofs + 8, sectors);
 }
 
+static int get_bios_disk(char *boot_device, int index) {
+
+    if (index < strlen(boot_device)) {
+        switch (boot_device[index]) {
+        case 'a':
+            return 0x01;            /* floppy */
+        case 'c':
+            return 0x02;            /* hard drive */
+        case 'd':
+            return 0x03;            /* cdrom */
+        }
+    }
+    return 0x00;                /* no device */
+}
+
 /* hd_table must contain 4 block drivers */
-static void cmos_init(uint64_t ram_size, int boot_device, BlockDriverState 
**hd_table, time_t timeoffset)
+static void cmos_init(uint64_t ram_size, char *boot_device, BlockDriverState 
**hd_table, time_t timeoffset)
 {
     RTCState *s = rtc_state;
     int val;
@@ -205,21 +220,14 @@ static void cmos_init(uint64_t ram_size,
     rtc_set_memory(s, 0x34, val);
     rtc_set_memory(s, 0x35, val >> 8);
     
-    switch(boot_device) {
-    case 'a':
-    case 'b':
-        rtc_set_memory(s, 0x3d, 0x01); /* floppy boot */
-        if (!fd_bootchk)
-            rtc_set_memory(s, 0x38, 0x01); /* disable signature check */
-        break;
-    default:
-    case 'c':
-        rtc_set_memory(s, 0x3d, 0x02); /* hard drive boot */
-        break;
-    case 'd':
-        rtc_set_memory(s, 0x3d, 0x03); /* CD-ROM boot */
-        break;
-    }
+    if (boot_device == NULL) {
+        /* default to hd, then cd, then floppy. */
+        boot_device = "cda";
+    }
+    rtc_set_memory(s, 0x3d, get_bios_disk(boot_device, 0) |
+                   (get_bios_disk(boot_device, 1) << 4));
+    rtc_set_memory(s, 0x38, (get_bios_disk(boot_device, 2) << 4) |
+                   (!fd_bootchk ? 0x01 : 0x00));
 
     /* floppy type */
 
@@ -572,9 +580,6 @@ static int parallel_io[MAX_PARALLEL_PORT
 static int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
 static int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };
 
-/* PIIX4 acpi pci configuration space, func 3 */
-extern void pci_piix4_acpi_init(PCIBus *bus, int devfn);
-
 #ifdef HAS_AUDIO
 static void audio_init (PCIBus *pci_bus)
 {
@@ -620,7 +625,7 @@ static void pc_init_ne2k_isa(NICInfo *nd
 #define NOBIOS 1
 
 /* PC hardware initialisation */
-static void pc_init1(uint64_t ram_size, int vga_ram_size, int boot_device,
+static void pc_init1(uint64_t ram_size, int vga_ram_size, char *boot_device,
                      DisplayState *ds, const char **fd_filename, int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, time_t timeoffset,
@@ -826,6 +831,9 @@ static void pc_init1(uint64_t ram_size, 
     }
 #endif /* !CONFIG_DM */
 
+    if (pci_enabled)
+        pci_xen_platform_init(pci_bus);
+
     for(i = 0; i < MAX_SERIAL_PORTS; i++) {
         if (serial_hds[i]) {
             serial_init(&pic_set_irq_new, isa_pic,
@@ -879,15 +887,17 @@ static void pc_init1(uint64_t ram_size, 
 
     /* using PIIX4 acpi model */
     if (pci_enabled && acpi_enabled)
-        pci_piix4_acpi_init(pci_bus, piix3_devfn + 3);
+        pci_piix4_acpi_init(pci_bus, piix3_devfn + 2);
 
     if (pci_enabled && usb_enabled) {
-        usb_uhci_init(pci_bus, piix3_devfn + 2);
-    }
-
-    if (pci_enabled && acpi_enabled && 0) {
+        usb_uhci_init(pci_bus, piix3_devfn + (acpi_enabled ? 3 : 2));
+    }
+
+#ifndef CONFIG_DM
+    if (pci_enabled && acpi_enabled) {
         piix4_pm_init(pci_bus, piix3_devfn + 3);
     }
+#endif /* !CONFIG_DM */
 
 #if 0
     /* ??? Need to figure out some way for the user to
@@ -910,12 +920,14 @@ static void pc_init1(uint64_t ram_size, 
     /* XXX: should be done in the Bochs BIOS */
     if (pci_enabled) {
         pci_bios_init();
+#ifndef CONFIG_DM
         if (acpi_enabled)
             acpi_bios_init();
-    }
-}
-
-static void pc_init_pci(uint64_t ram_size, int vga_ram_size, int boot_device,
+#endif /* !CONFIG_DM */
+    }
+}
+
+static void pc_init_pci(uint64_t ram_size, int vga_ram_size, char *boot_device,
                         DisplayState *ds, const char **fd_filename, 
                         int snapshot, 
                         const char *kernel_filename, 
@@ -929,7 +941,7 @@ static void pc_init_pci(uint64_t ram_siz
              initrd_filename, timeoffset, 1);
 }
 
-static void pc_init_isa(uint64_t ram_size, int vga_ram_size, int boot_device,
+static void pc_init_isa(uint64_t ram_size, int vga_ram_size, char *boot_device,
                         DisplayState *ds, const char **fd_filename, 
                         int snapshot, 
                         const char *kernel_filename, 
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/hw/piix4acpi.c
--- a/tools/ioemu/hw/piix4acpi.c        Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/hw/piix4acpi.c        Wed Aug 23 11:11:27 2006 -0600
@@ -374,13 +374,13 @@ static void acpi_map(PCIDevice *pci_dev,
     register_ioport_read(addr + 8, 4, 4, acpiPm1Timer_readl, d);
 }
 
-/* PIIX4 acpi pci configuration space, func 3 */
+/* PIIX4 acpi pci configuration space, func 2 */
 void pci_piix4_acpi_init(PCIBus *bus, int devfn)
 {
     PCIAcpiState *d;
     uint8_t *pci_conf;
 
-    /* register a function 3 of PIIX4 */
+    /* register a function 2 of PIIX4 */
     d = (PCIAcpiState *)pci_register_device(
         bus, "PIIX4 ACPI", sizeof(PCIAcpiState),
         devfn, NULL, NULL);
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/hw/piix_pci.c
--- a/tools/ioemu/hw/piix_pci.c Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/hw/piix_pci.c Wed Aug 23 11:11:27 2006 -0600
@@ -415,7 +415,7 @@ void pci_bios_init(void)
     uint8_t elcr[2];
 
     pci_bios_io_addr = 0xc000;
-    pci_bios_mem_addr = 0xf0000000;
+    pci_bios_mem_addr = HVM_BELOW_4G_MMIO_START;
 
     /* activate IRQ mappings */
     elcr[0] = 0x00;
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/acpi-poweroff-support
--- a/tools/ioemu/patches/acpi-poweroff-support Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/acpi-poweroff-support Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/hw/piix4acpi.c
 Index: ioemu/hw/piix4acpi.c
 ===================================================================
---- ioemu.orig/hw/piix4acpi.c  2006-08-06 02:30:29.288761563 +0100
-+++ ioemu/hw/piix4acpi.c       2006-08-06 02:30:42.131331446 +0100
+--- ioemu.orig/hw/piix4acpi.c  2006-08-17 19:50:05.060576667 +0100
++++ ioemu/hw/piix4acpi.c       2006-08-17 19:50:07.563300039 +0100
 @@ -45,6 +45,10 @@
  #define GBL_RLS           (1 << 2)
  #define SLP_EN            (1 << 13)
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/acpi-support
--- a/tools/ioemu/patches/acpi-support  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/acpi-support  Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/Makefile.target
 Index: ioemu/Makefile.target
 ===================================================================
---- ioemu.orig/Makefile.target 2006-08-06 02:23:23.000000000 +0100
-+++ ioemu/Makefile.target      2006-08-07 17:38:47.698306442 +0100
+--- ioemu.orig/Makefile.target 2006-08-17 19:49:50.228216099 +0100
++++ ioemu/Makefile.target      2006-08-17 19:50:02.405870095 +0100
 @@ -357,6 +357,7 @@
  VL_OBJS+= fdc.o mc146818rtc.o serial.o pc.o
  VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
@@ -12,39 +12,44 @@ Index: ioemu/Makefile.target
  ifeq ($(TARGET_BASE_ARCH), ppc)
 Index: ioemu/hw/pc.c
 ===================================================================
---- ioemu.orig/hw/pc.c 2006-08-06 02:23:45.000000000 +0100
-+++ ioemu/hw/pc.c      2006-08-07 17:42:00.939426374 +0100
-@@ -572,6 +572,9 @@
- static int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
- static int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };
- 
-+/* PIIX4 acpi pci configuration space, func 3 */
-+extern void pci_piix4_acpi_init(PCIBus *bus, int devfn);
-+
- #ifdef HAS_AUDIO
- static void audio_init (PCIBus *pci_bus)
- {
-@@ -874,11 +877,15 @@
+--- ioemu.orig/hw/pc.c 2006-08-17 19:49:59.312212039 +0100
++++ ioemu/hw/pc.c      2006-08-17 19:50:02.406869984 +0100
+@@ -874,13 +874,19 @@
  
      cmos_init(ram_size, boot_device, bs_table, timeoffset);
  
 +    /* using PIIX4 acpi model */
 +    if (pci_enabled && acpi_enabled)
-+        pci_piix4_acpi_init(pci_bus, piix3_devfn + 3);
++        pci_piix4_acpi_init(pci_bus, piix3_devfn + 2);
 +
      if (pci_enabled && usb_enabled) {
-         usb_uhci_init(pci_bus, piix3_devfn + 2);
+-        usb_uhci_init(pci_bus, piix3_devfn + 2);
++        usb_uhci_init(pci_bus, piix3_devfn + (acpi_enabled ? 3 : 2));
      }
  
--    if (pci_enabled && acpi_enabled) {
-+    if (pci_enabled && acpi_enabled && 0) {
++#ifndef CONFIG_DM
+     if (pci_enabled && acpi_enabled) {
          piix4_pm_init(pci_bus, piix3_devfn + 3);
      }
++#endif /* !CONFIG_DM */
+ 
+ #if 0
+     /* ??? Need to figure out some way for the user to
+@@ -903,8 +909,10 @@
+     /* XXX: should be done in the Bochs BIOS */
+     if (pci_enabled) {
+         pci_bios_init();
++#ifndef CONFIG_DM
+         if (acpi_enabled)
+             acpi_bios_init();
++#endif /* !CONFIG_DM */
+     }
+ }
  
 Index: ioemu/hw/piix4acpi.c
 ===================================================================
 --- /dev/null  1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/hw/piix4acpi.c       2006-08-07 17:41:41.932577728 +0100
++++ ioemu/hw/piix4acpi.c       2006-08-17 19:50:02.407869874 +0100
 @@ -0,0 +1,388 @@
 +/*
 + * PIIX4 ACPI controller emulation
@@ -405,13 +410,13 @@ Index: ioemu/hw/piix4acpi.c
 +}
 +                                                                              
                        
 +
-+/* PIIX4 acpi pci configuration space, func 3 */
++/* PIIX4 acpi pci configuration space, func 2 */
 +void pci_piix4_acpi_init(PCIBus *bus, int devfn)
 +{
 +    PCIAcpiState *d;
 +    uint8_t *pci_conf;
 +
-+    /* register a function 3 of PIIX4 */
++    /* register a function 2 of PIIX4 */
 +    d = (PCIAcpiState *)pci_register_device(
 +        bus, "PIIX4 ACPI", sizeof(PCIAcpiState),
 +        devfn, NULL, NULL);
@@ -436,8 +441,8 @@ Index: ioemu/hw/piix4acpi.c
 +}
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-06 02:23:45.000000000 +0100
-+++ ioemu/vl.c 2006-08-07 17:41:40.613727012 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:49:59.315211708 +0100
++++ ioemu/vl.c 2006-08-17 19:50:02.410869542 +0100
 @@ -156,7 +156,7 @@
  #else
  #define MAX_CPUS 1
@@ -483,9 +488,9 @@ Index: ioemu/vl.c
      }
 Index: ioemu/vl.h
 ===================================================================
---- ioemu.orig/vl.h    2006-08-06 02:23:45.000000000 +0100
-+++ ioemu/vl.h 2006-08-07 17:38:47.847289567 +0100
-@@ -167,6 +167,7 @@
+--- ioemu.orig/vl.h    2006-08-17 19:49:59.316211597 +0100
++++ ioemu/vl.h 2006-08-17 19:50:02.411869432 +0100
+@@ -168,6 +168,7 @@
  extern int kqemu_allowed;
  extern int win2k_install_hack;
  extern int usb_enabled;
@@ -493,10 +498,20 @@ Index: ioemu/vl.h
  extern int smp_cpus;
  
  /* XXX: make it dynamic */
+@@ -923,6 +924,9 @@
+ void piix4_pm_init(PCIBus *bus, int devfn);
+ void acpi_bios_init(void);
+ 
++/* piix4acpi.c */
++extern void pci_piix4_acpi_init(PCIBus *bus, int devfn);
++
+ /* pc.c */
+ extern QEMUMachine pc_machine;
+ extern QEMUMachine isapc_machine;
 Index: ioemu/hw/piix_pci.c
 ===================================================================
---- ioemu.orig/hw/piix_pci.c   2006-08-06 02:29:41.000000000 +0100
-+++ ioemu/hw/piix_pci.c        2006-08-07 17:38:57.480198468 +0100
+--- ioemu.orig/hw/piix_pci.c   2006-08-17 19:38:05.806252180 +0100
++++ ioemu/hw/piix_pci.c        2006-08-17 19:50:02.411869432 +0100
 @@ -241,7 +241,7 @@
  static uint32_t pci_bios_io_addr;
  static uint32_t pci_bios_mem_addr;
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/acpi-timer-support
--- a/tools/ioemu/patches/acpi-timer-support    Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/acpi-timer-support    Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/hw/piix4acpi.c
 Index: ioemu/hw/piix4acpi.c
 ===================================================================
---- ioemu.orig/hw/piix4acpi.c  2006-08-06 02:24:54.262068457 +0100
-+++ ioemu/hw/piix4acpi.c       2006-08-06 02:30:29.288761563 +0100
+--- ioemu.orig/hw/piix4acpi.c  2006-08-17 19:50:02.407869874 +0100
++++ ioemu/hw/piix4acpi.c       2006-08-17 19:50:05.060576667 +0100
 @@ -24,31 +24,30 @@
   */
  
@@ -184,8 +184,8 @@ Index: ioemu/hw/piix4acpi.c
  }
 -                                                                              
                        
  
- /* PIIX4 acpi pci configuration space, func 3 */
- void pci_piix4_acpi_init(PCIBus *bus)
+ /* PIIX4 acpi pci configuration space, func 2 */
+ void pci_piix4_acpi_init(PCIBus *bus, int devfn)
 @@ -384,5 +383,5 @@
      pci_register_io_region((PCIDevice *)d, 4, 0x10,
                             PCI_ADDRESS_SPACE_IO, acpi_map);
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/domain-destroy
--- a/tools/ioemu/patches/domain-destroy        Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/domain-destroy        Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/monitor.c
 Index: ioemu/monitor.c
 ===================================================================
---- ioemu.orig/monitor.c       2006-08-08 11:27:48.555190337 +0100
-+++ ioemu/monitor.c    2006-08-08 11:27:53.984584612 +0100
+--- ioemu.orig/monitor.c       2006-08-17 19:37:36.489509621 +0100
++++ ioemu/monitor.c    2006-08-17 19:49:44.491850141 +0100
 @@ -308,6 +308,7 @@
  
  static void do_quit(void)
@@ -12,8 +12,8 @@ Index: ioemu/monitor.c
  
 Index: ioemu/target-i386-dm/helper2.c
 ===================================================================
---- ioemu.orig/target-i386-dm/helper2.c        2006-08-08 11:27:53.063687351 
+0100
-+++ ioemu/target-i386-dm/helper2.c     2006-08-08 11:27:54.011581601 +0100
+--- ioemu.orig/target-i386-dm/helper2.c        2006-08-17 19:49:40.116333768 
+0100
++++ ioemu/target-i386-dm/helper2.c     2006-08-17 19:49:44.491850141 +0100
 @@ -488,5 +488,25 @@
              xc_evtchn_notify(xce_handle, ioreq_local_port[send_vcpu]);
          }
@@ -42,9 +42,9 @@ Index: ioemu/target-i386-dm/helper2.c
 +}
 Index: ioemu/vl.h
 ===================================================================
---- ioemu.orig/vl.h    2006-08-08 11:27:53.067686905 +0100
-+++ ioemu/vl.h 2006-08-08 11:27:54.061576023 +0100
-@@ -1189,4 +1189,7 @@
+--- ioemu.orig/vl.h    2006-08-17 19:49:40.120333326 +0100
++++ ioemu/vl.h 2006-08-17 19:49:44.492850031 +0100
+@@ -1190,4 +1190,7 @@
  void kqemu_record_dump(void);
  
  extern char domain_name[];
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/domain-reset
--- a/tools/ioemu/patches/domain-reset  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/domain-reset  Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/target-i386-dm/helper2.c
 Index: ioemu/target-i386-dm/helper2.c
 ===================================================================
---- ioemu.orig/target-i386-dm/helper2.c        2006-08-08 11:27:45.566523765 
+0100
-+++ ioemu/target-i386-dm/helper2.c     2006-08-08 11:27:53.063687351 +0100
+--- ioemu.orig/target-i386-dm/helper2.c        2006-08-17 19:37:36.530505066 
+0100
++++ ioemu/target-i386-dm/helper2.c     2006-08-17 19:49:40.116333768 +0100
 @@ -127,6 +127,25 @@
  /* called from main_cpu_reset */
  void cpu_reset(CPUX86State *env)
@@ -41,8 +41,8 @@ Index: ioemu/target-i386-dm/helper2.c
          /* Wait up to 10 msec. */
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-08 11:27:52.994695048 +0100
-+++ ioemu/vl.c 2006-08-08 11:27:53.066687017 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:49:39.442408257 +0100
++++ ioemu/vl.c 2006-08-17 19:49:40.119333436 +0100
 @@ -4948,7 +4948,7 @@
  } QEMUResetEntry;
  
@@ -54,9 +54,9 @@ Index: ioemu/vl.c
  
 Index: ioemu/vl.h
 ===================================================================
---- ioemu.orig/vl.h    2006-08-08 11:27:48.757167803 +0100
-+++ ioemu/vl.h 2006-08-08 11:27:53.067686905 +0100
-@@ -130,6 +130,7 @@
+--- ioemu.orig/vl.h    2006-08-17 19:47:32.680418959 +0100
++++ ioemu/vl.h 2006-08-17 19:49:40.120333326 +0100
+@@ -131,6 +131,7 @@
  
  void qemu_register_reset(QEMUResetHandler *func, void *opaque);
  void qemu_system_reset_request(void);
@@ -64,7 +64,7 @@ Index: ioemu/vl.h
  void qemu_system_shutdown_request(void);
  void qemu_system_powerdown_request(void);
  #if !defined(TARGET_SPARC)
-@@ -139,6 +140,8 @@
+@@ -140,6 +141,8 @@
  void qemu_system_powerdown(void);
  #endif
  
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/domain-timeoffset
--- a/tools/ioemu/patches/domain-timeoffset     Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/domain-timeoffset     Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/hw/mc146818rtc.c
 Index: ioemu/hw/mc146818rtc.c
 ===================================================================
---- ioemu.orig/hw/mc146818rtc.c        2006-08-09 15:04:17.857242121 +0100
-+++ ioemu/hw/mc146818rtc.c     2006-08-09 15:04:24.588603423 +0100
+--- ioemu.orig/hw/mc146818rtc.c        2006-08-17 19:58:03.222720593 +0100
++++ ioemu/hw/mc146818rtc.c     2006-08-17 19:58:08.528134087 +0100
 @@ -178,10 +178,27 @@
      }
  }
@@ -46,8 +46,8 @@ Index: ioemu/hw/mc146818rtc.c
  static void rtc_copy_date(RTCState *s)
 Index: ioemu/hw/pc.c
 ===================================================================
---- ioemu.orig/hw/pc.c 2006-08-09 15:04:24.316629266 +0100
-+++ ioemu/hw/pc.c      2006-08-09 15:04:24.589603328 +0100
+--- ioemu.orig/hw/pc.c 2006-08-17 19:58:08.252164595 +0100
++++ ioemu/hw/pc.c      2006-08-17 19:58:08.529133976 +0100
 @@ -159,7 +159,7 @@
  }
  
@@ -117,8 +117,8 @@ Index: ioemu/hw/pc.c
  QEMUMachine pc_machine = {
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-09 15:04:24.457615869 +0100
-+++ ioemu/vl.c 2006-08-09 15:04:24.592603043 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:58:08.395148788 +0100
++++ ioemu/vl.c 2006-08-17 19:58:08.532133645 +0100
 @@ -163,6 +163,8 @@
  
  int xc_handle;
@@ -162,7 +162,7 @@ Index: ioemu/vl.c
              }
          }
      }
-@@ -6489,7 +6497,8 @@
+@@ -6507,7 +6515,8 @@
  
      machine->init(ram_size, vga_ram_size, boot_device,
                    ds, fd_filename, snapshot,
@@ -174,9 +174,9 @@ Index: ioemu/vl.c
      if (usb_enabled) {
 Index: ioemu/vl.h
 ===================================================================
---- ioemu.orig/vl.h    2006-08-09 15:04:24.321628791 +0100
-+++ ioemu/vl.h 2006-08-09 15:04:24.593602948 +0100
-@@ -575,7 +575,7 @@
+--- ioemu.orig/vl.h    2006-08-17 19:58:08.257164042 +0100
++++ ioemu/vl.h 2006-08-17 19:58:08.532133645 +0100
+@@ -576,7 +576,7 @@
                                   int boot_device,
               DisplayState *ds, const char **fd_filename, int snapshot,
               const char *kernel_filename, const char *kernel_cmdline,
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/hypervisor-pit
--- a/tools/ioemu/patches/hypervisor-pit        Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/hypervisor-pit        Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/Makefile.target
 Index: ioemu/Makefile.target
 ===================================================================
---- ioemu.orig/Makefile.target 2006-08-06 02:22:26.380544784 +0100
-+++ ioemu/Makefile.target      2006-08-06 02:23:23.059226607 +0100
+--- ioemu.orig/Makefile.target 2006-08-17 19:49:33.813030472 +0100
++++ ioemu/Makefile.target      2006-08-17 19:49:50.228216099 +0100
 @@ -354,7 +354,7 @@
  ifeq ($(TARGET_BASE_ARCH), i386)
  # Hardware support
@@ -13,8 +13,8 @@ Index: ioemu/Makefile.target
  DEFINES += -DHAS_AUDIO
 Index: ioemu/hw/pc.c
 ===================================================================
---- ioemu.orig/hw/pc.c 2006-08-06 02:22:35.588518336 +0100
-+++ ioemu/hw/pc.c      2006-08-06 02:23:07.875919141 +0100
+--- ioemu.orig/hw/pc.c 2006-08-17 19:49:35.507843144 +0100
++++ ioemu/hw/pc.c      2006-08-17 19:49:50.229215988 +0100
 @@ -38,7 +38,9 @@
  
  static fdctrl_t *floppy_controller;
@@ -38,8 +38,8 @@ Index: ioemu/hw/pc.c
          pic_set_alt_irq_func(isa_pic, ioapic_set_irq, ioapic);
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-06 02:23:05.216215627 +0100
-+++ ioemu/vl.c 2006-08-06 02:23:07.878918807 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:49:48.566399780 +0100
++++ ioemu/vl.c 2006-08-17 19:49:50.231215767 +0100
 @@ -5570,6 +5570,7 @@
  
  #ifdef HAS_AUDIO
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/ide-hd-multithread
--- a/tools/ioemu/patches/ide-hd-multithread    Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/ide-hd-multithread    Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/hw/ide.c
 Index: ioemu/hw/ide.c
 ===================================================================
---- ioemu.orig/hw/ide.c        2006-08-06 02:03:50.520919718 +0100
-+++ ioemu/hw/ide.c     2006-08-06 02:23:41.153209614 +0100
+--- ioemu.orig/hw/ide.c        2006-08-17 19:37:36.267534285 +0100
++++ ioemu/hw/ide.c     2006-08-17 19:49:57.830375828 +0100
 @@ -22,6 +22,7 @@
   * THE SOFTWARE.
   */
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/ioemu-ia64
--- a/tools/ioemu/patches/ioemu-ia64    Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/ioemu-ia64    Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/hw/iommu.c
 Index: ioemu/hw/iommu.c
 ===================================================================
---- ioemu.orig/hw/iommu.c      2006-08-06 01:55:03.240628184 +0100
-+++ ioemu/hw/iommu.c   2006-08-06 02:18:54.843126039 +0100
+--- ioemu.orig/hw/iommu.c      2006-08-17 19:37:36.791476068 +0100
++++ ioemu/hw/iommu.c   2006-08-17 19:48:27.357375720 +0100
 @@ -82,7 +82,11 @@
  #define IOPTE_VALID         0x00000002 /* IOPTE is valid */
  #define IOPTE_WAZ           0x00000001 /* Write as zeros */
@@ -16,8 +16,8 @@ Index: ioemu/hw/iommu.c
  
 Index: ioemu/cpu-all.h
 ===================================================================
---- ioemu.orig/cpu-all.h       2006-08-06 02:17:09.392881406 +0100
-+++ ioemu/cpu-all.h    2006-08-06 02:18:54.844125928 +0100
+--- ioemu.orig/cpu-all.h       2006-08-17 19:37:36.791476068 +0100
++++ ioemu/cpu-all.h    2006-08-17 19:48:27.358375609 +0100
 @@ -835,6 +835,31 @@
                  :"=m" (*(volatile long *)addr)
                  :"dIr" (nr));
@@ -52,21 +52,21 @@ Index: ioemu/cpu-all.h
  /* memory API */
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-06 02:18:45.608155528 +0100
-+++ ioemu/vl.c 2006-08-06 02:18:54.847125593 +0100
-@@ -6140,6 +6140,11 @@
-     /* init the memory */
-     phys_ram_size = ram_size + vga_ram_size + bios_size;
+--- ioemu.orig/vl.c    2006-08-17 19:47:08.538087284 +0100
++++ ioemu/vl.c 2006-08-17 19:57:50.666108706 +0100
+@@ -6144,6 +6144,11 @@
+ 
+     xc_handle = xc_interface_open();
  
 +#if defined (__ia64__)
 +    if (ram_size > MMIO_START)
-+      ram_size += 1 * MEM_G; /* skip 3G-4G MMIO, LEGACY_IO_SPACE etc. */
++        ram_size += 1 * MEM_G; /* skip 3G-4G MMIO, LEGACY_IO_SPACE etc. */
 +#endif
 +
- #ifdef CONFIG_DM
- 
      nr_pages = ram_size/PAGE_SIZE;
-@@ -6151,6 +6156,7 @@
+     tmp_nr_pages = nr_pages;
+ 
+@@ -6161,6 +6166,7 @@
          exit(-1);
      }
  
@@ -74,7 +74,7 @@ Index: ioemu/vl.c
      if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
          fprintf(logfile, "xc_get_pfn_list returned error %d\n", errno);
          exit(-1);
-@@ -6173,6 +6179,41 @@
+@@ -6191,6 +6197,41 @@
  
      free(page_array);
  
@@ -100,9 +100,9 @@ Index: ioemu/vl.c
 +    }
 +
 +    if (ram_size > MMIO_START) {      
-+      for (i = 0 ; i < MEM_G >> PAGE_SHIFT; i++)
-+          page_array[MMIO_START >> PAGE_SHIFT + i] =
-+              page_array[IO_PAGE_START >> PAGE_SHIFT + 1];
++        for (i = 0 ; i < MEM_G >> PAGE_SHIFT; i++)
++            page_array[MMIO_START >> PAGE_SHIFT + i] =
++                page_array[IO_PAGE_START >> PAGE_SHIFT + 1];
 +    }
 +
 +    phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
@@ -118,8 +118,8 @@ Index: ioemu/vl.c
      phys_ram_base = qemu_vmalloc(phys_ram_size);
 Index: ioemu/target-i386-dm/exec-dm.c
 ===================================================================
---- ioemu.orig/target-i386-dm/exec-dm.c        2006-08-06 02:15:01.776108064 
+0100
-+++ ioemu/target-i386-dm/exec-dm.c     2006-08-06 02:18:54.848125482 +0100
+--- ioemu.orig/target-i386-dm/exec-dm.c        2006-08-17 19:37:36.792475957 
+0100
++++ ioemu/target-i386-dm/exec-dm.c     2006-08-17 19:48:27.361375278 +0100
 @@ -341,6 +341,23 @@
      return io_mem_read[io_index >> IO_MEM_SHIFT];
  }
@@ -144,20 +144,20 @@ Index: ioemu/target-i386-dm/exec-dm.c
  /* physical memory access (slow version, mainly for debug) */
  #if defined(CONFIG_USER_ONLY)
  void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, 
-@@ -456,6 +473,9 @@
-                 ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) + 
-                     (addr & ~TARGET_PAGE_MASK);
-                 memcpy(buf, ptr, l);
+@@ -432,6 +449,9 @@
+                 /* RAM case */
+                 ptr = phys_ram_base + addr1;
+                 memcpy(ptr, buf, l);
 +#ifdef __ia64__
 +                sync_icache((unsigned long)ptr, l);
 +#endif 
-             } else {
-                 /* unreported MMIO space */
-                 memset(buf, 0xff, len);
+             }
+         } else {
+             if (io_index) {
 Index: ioemu/exec-all.h
 ===================================================================
---- ioemu.orig/exec-all.h      2006-08-06 02:14:09.796902750 +0100
-+++ ioemu/exec-all.h   2006-08-06 02:18:54.848125482 +0100
+--- ioemu.orig/exec-all.h      2006-08-17 19:37:36.791476068 +0100
++++ ioemu/exec-all.h   2006-08-17 19:48:27.362375167 +0100
 @@ -462,12 +462,13 @@
  }
  #endif
@@ -177,8 +177,8 @@ Index: ioemu/exec-all.h
  
 Index: ioemu/target-i386-dm/cpu.h
 ===================================================================
---- ioemu.orig/target-i386-dm/cpu.h    2006-08-06 02:15:01.776108064 +0100
-+++ ioemu/target-i386-dm/cpu.h 2006-08-06 02:18:54.848125482 +0100
+--- ioemu.orig/target-i386-dm/cpu.h    2006-08-17 19:37:36.792475957 +0100
++++ ioemu/target-i386-dm/cpu.h 2006-08-17 19:48:27.362375167 +0100
 @@ -80,7 +80,11 @@
  /* helper2.c */
  int main_loop(void);
@@ -194,7 +194,7 @@ Index: ioemu/ia64_intrinsic.h
 Index: ioemu/ia64_intrinsic.h
 ===================================================================
 --- /dev/null  1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/ia64_intrinsic.h     2006-08-06 02:18:54.849125370 +0100
++++ ioemu/ia64_intrinsic.h     2006-08-17 19:48:27.363375057 +0100
 @@ -0,0 +1,276 @@
 +#ifndef IA64_INTRINSIC_H
 +#define IA64_INTRINSIC_H
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/qemu-allow-disable-sdl
--- a/tools/ioemu/patches/qemu-allow-disable-sdl        Tue Aug 22 14:45:49 
2006 -0600
+++ b/tools/ioemu/patches/qemu-allow-disable-sdl        Wed Aug 23 11:11:27 
2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/configure
 Index: ioemu/configure
 ===================================================================
---- ioemu.orig/configure       2006-08-06 02:15:01.771108621 +0100
-+++ ioemu/configure    2006-08-06 02:42:26.213918476 +0100
+--- ioemu.orig/configure       2006-08-17 19:37:35.772589281 +0100
++++ ioemu/configure    2006-08-17 19:50:24.735401975 +0100
 @@ -228,8 +228,6 @@
    ;;
    --enable-cocoa) cocoa="yes" ; coreaudio="yes" ; sdl="no"
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/qemu-fix-memset-args
--- a/tools/ioemu/patches/qemu-fix-memset-args  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/qemu-fix-memset-args  Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/audio/audio.c
 Index: ioemu/audio/audio.c
 ===================================================================
---- ioemu.orig/audio/audio.c   2006-08-06 02:03:50.013976165 +0100
-+++ ioemu/audio/audio.c        2006-08-06 02:42:28.991609008 +0100
+--- ioemu.orig/audio/audio.c   2006-08-17 19:37:35.755591169 +0100
++++ ioemu/audio/audio.c        2006-08-17 19:50:26.867166346 +0100
 @@ -605,11 +605,11 @@
      }
  
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/serial-non-block
--- a/tools/ioemu/patches/serial-non-block      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/serial-non-block      Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/vl.c
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-06 02:23:29.827472129 +0100
-+++ ioemu/vl.c 2006-08-06 02:23:36.856688561 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:49:52.162002356 +0100
++++ ioemu/vl.c 2006-08-17 19:49:56.273547905 +0100
 @@ -1175,19 +1175,34 @@
  
  static int unix_write(int fd, const uint8_t *buf, int len1)
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/series
--- a/tools/ioemu/patches/series        Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/series        Wed Aug 23 11:11:27 2006 -0600
@@ -39,5 +39,8 @@ xenstore-write-vnc-port
 xenstore-write-vnc-port
 qemu-allow-disable-sdl
 qemu-fix-memset-args
-qemu-fix-write-to-disk-synchronous
 xen-support-buffered-ioreqs
+qemu-daemonize
+xen-platform-device
+qemu-bootorder
+qemu-tunable-ide-write-cache
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/shadow-vram
--- a/tools/ioemu/patches/shadow-vram   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/shadow-vram   Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/hw/vga.c
 Index: ioemu/hw/vga.c
 ===================================================================
---- ioemu.orig/hw/vga.c        2006-08-06 02:23:29.824472464 +0100
-+++ ioemu/hw/vga.c     2006-08-06 02:23:33.873021159 +0100
+--- ioemu.orig/hw/vga.c        2006-08-17 19:49:52.159002688 +0100
++++ ioemu/hw/vga.c     2006-08-17 19:49:54.575735565 +0100
 @@ -1359,6 +1359,105 @@
      }
  }
@@ -137,8 +137,8 @@ Index: ioemu/hw/vga.c
      s->vram_size = vga_ram_size;
 Index: ioemu/hw/vga_int.h
 ===================================================================
---- ioemu.orig/hw/vga_int.h    2006-08-06 02:23:29.824472464 +0100
-+++ ioemu/hw/vga_int.h 2006-08-06 02:23:33.874021048 +0100
+--- ioemu.orig/hw/vga_int.h    2006-08-17 19:49:52.159002688 +0100
++++ ioemu/hw/vga_int.h 2006-08-17 19:49:54.575735565 +0100
 @@ -79,6 +79,7 @@
  
  #define VGA_STATE_COMMON                                                \
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/shared-vram
--- a/tools/ioemu/patches/shared-vram   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/shared-vram   Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/hw/cirrus_vga.c
 Index: ioemu/hw/cirrus_vga.c
 ===================================================================
---- ioemu.orig/hw/cirrus_vga.c 2006-08-06 01:55:02.822674718 +0100
-+++ ioemu/hw/cirrus_vga.c      2006-08-06 02:23:29.822472686 +0100
+--- ioemu.orig/hw/cirrus_vga.c 2006-08-17 19:37:36.372522620 +0100
++++ ioemu/hw/cirrus_vga.c      2006-08-17 19:49:52.157002909 +0100
 @@ -28,6 +28,9 @@
   */
  #include "vl.h"
@@ -176,8 +176,8 @@ Index: ioemu/hw/cirrus_vga.c
  }
 Index: ioemu/hw/pc.c
 ===================================================================
---- ioemu.orig/hw/pc.c 2006-08-06 02:23:07.875919141 +0100
-+++ ioemu/hw/pc.c      2006-08-06 02:23:29.823472575 +0100
+--- ioemu.orig/hw/pc.c 2006-08-17 19:49:50.229215988 +0100
++++ ioemu/hw/pc.c      2006-08-17 19:49:52.158002799 +0100
 @@ -790,14 +790,14 @@
      if (cirrus_vga_enabled) {
          if (pci_enabled) {
@@ -198,8 +198,8 @@ Index: ioemu/hw/pc.c
  
 Index: ioemu/hw/vga.c
 ===================================================================
---- ioemu.orig/hw/vga.c        2006-08-06 02:22:46.606290142 +0100
-+++ ioemu/hw/vga.c     2006-08-06 02:23:29.824472464 +0100
+--- ioemu.orig/hw/vga.c        2006-08-17 19:49:37.764593706 +0100
++++ ioemu/hw/vga.c     2006-08-17 19:49:52.159002688 +0100
 @@ -1858,6 +1858,7 @@
      /* TODO: add vbe support if enabled */
  }
@@ -251,8 +251,8 @@ Index: ioemu/hw/vga.c
  
 Index: ioemu/hw/vga_int.h
 ===================================================================
---- ioemu.orig/hw/vga_int.h    2006-08-06 02:14:09.797902638 +0100
-+++ ioemu/hw/vga_int.h 2006-08-06 02:23:29.824472464 +0100
+--- ioemu.orig/hw/vga_int.h    2006-08-17 19:37:36.372522620 +0100
++++ ioemu/hw/vga_int.h 2006-08-17 19:49:52.159002688 +0100
 @@ -169,5 +169,6 @@
                               unsigned int color0, unsigned int color1,
                               unsigned int color_xor);
@@ -262,8 +262,8 @@ Index: ioemu/hw/vga_int.h
  extern const uint8_t gr_mask[16];
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-06 02:23:07.878918807 +0100
-+++ ioemu/vl.c 2006-08-06 02:23:29.827472129 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:49:50.231215767 +0100
++++ ioemu/vl.c 2006-08-17 19:49:52.162002356 +0100
 @@ -5693,6 +5693,78 @@
  
  #define MAX_NET_CLIENTS 32
@@ -345,9 +345,9 @@ Index: ioemu/vl.c
  #ifdef CONFIG_GDBSTUB
 Index: ioemu/vl.h
 ===================================================================
---- ioemu.orig/vl.h    2006-08-06 02:23:02.271543880 +0100
-+++ ioemu/vl.h 2006-08-06 02:23:29.828472018 +0100
-@@ -144,6 +144,13 @@
+--- ioemu.orig/vl.h    2006-08-17 19:49:44.492850031 +0100
++++ ioemu/vl.h 2006-08-17 19:49:52.163002246 +0100
+@@ -145,6 +145,13 @@
  
  void main_loop_wait(int timeout);
  
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/support-xm-console
--- a/tools/ioemu/patches/support-xm-console    Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/support-xm-console    Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/vl.c
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-06 02:22:59.254880158 +0100
-+++ ioemu/vl.c 2006-08-06 02:23:05.216215627 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:49:40.119333436 +0100
++++ ioemu/vl.c 2006-08-17 19:49:48.566399780 +0100
 @@ -1536,26 +1536,65 @@
      return chr;
  }
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/vnc-access-monitor-vt
--- a/tools/ioemu/patches/vnc-access-monitor-vt Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/vnc-access-monitor-vt Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/vnc.c
 Index: ioemu/vnc.c
 ===================================================================
---- ioemu.orig/vnc.c   2006-08-07 17:44:33.084748631 +0100
-+++ ioemu/vnc.c        2006-08-07 17:44:33.224733389 +0100
+--- ioemu.orig/vnc.c   2006-08-17 19:50:14.623519661 +0100
++++ ioemu/vnc.c        2006-08-17 19:50:15.956372339 +0100
 @@ -32,6 +32,10 @@
  #include "vnc_keysym.h"
  #include "keymaps.c"
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/vnc-cleanup
--- a/tools/ioemu/patches/vnc-cleanup   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/vnc-cleanup   Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/vnc.c
 Index: ioemu/vnc.c
 ===================================================================
---- ioemu.orig/vnc.c   2006-08-07 17:42:21.888055419 +0100
-+++ ioemu/vnc.c        2006-08-07 17:42:28.001363557 +0100
+--- ioemu.orig/vnc.c   2006-08-17 19:37:36.091553839 +0100
++++ ioemu/vnc.c        2006-08-17 19:50:10.313996001 +0100
 @@ -143,13 +143,16 @@
  static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
  {
@@ -65,8 +65,8 @@ Index: ioemu/vnc.c
  static void vnc_timer_init(VncState *vs)
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-07 17:42:27.807385506 +0100
-+++ ioemu/vl.c 2006-08-07 17:42:28.004363230 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:50:02.410869542 +0100
++++ ioemu/vl.c 2006-08-17 19:50:10.316995669 +0100
 @@ -5120,10 +5120,10 @@
          /* XXX: better handling of removal */
          for(ioh = first_io_handler; ioh != NULL; ioh = ioh_next) {
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/vnc-display-find-unused
--- a/tools/ioemu/patches/vnc-display-find-unused       Tue Aug 22 14:45:49 
2006 -0600
+++ b/tools/ioemu/patches/vnc-display-find-unused       Wed Aug 23 11:11:27 
2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/vnc.c
 Index: ioemu/vnc.c
 ===================================================================
---- ioemu.orig/vnc.c   2006-08-09 14:44:44.721942535 +0100
-+++ ioemu/vnc.c        2006-08-09 14:52:37.262165292 +0100
+--- ioemu.orig/vnc.c   2006-08-17 19:50:15.956372339 +0100
++++ ioemu/vnc.c        2006-08-17 19:50:17.083247783 +0100
 @@ -1183,7 +1183,7 @@
      }
  }
@@ -50,8 +50,8 @@ Index: ioemu/vnc.c
  int vnc_start_viewer(int port)
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-09 14:44:44.721942535 +0100
-+++ ioemu/vl.c 2006-08-09 14:52:06.783905832 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:50:13.152682236 +0100
++++ ioemu/vl.c 2006-08-17 19:50:17.086247452 +0100
 @@ -121,6 +121,7 @@
  static DisplayState display_state;
  int nographic;
@@ -104,7 +104,7 @@ Index: ioemu/vl.c
              }
          }
      }
-@@ -6465,7 +6475,7 @@
+@@ -6483,7 +6493,7 @@
      if (nographic) {
          dumb_display_init(ds);
      } else if (vnc_display != -1) {
@@ -115,9 +115,9 @@ Index: ioemu/vl.c
      } else {
 Index: ioemu/vl.h
 ===================================================================
---- ioemu.orig/vl.h    2006-08-09 14:44:44.721942535 +0100
-+++ ioemu/vl.h 2006-08-09 14:52:06.783905832 +0100
-@@ -784,7 +784,7 @@
+--- ioemu.orig/vl.h    2006-08-17 19:50:13.153682125 +0100
++++ ioemu/vl.h 2006-08-17 19:50:17.087247341 +0100
+@@ -785,7 +785,7 @@
  void cocoa_display_init(DisplayState *ds, int full_screen);
  
  /* vnc.c */
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/vnc-fixes
--- a/tools/ioemu/patches/vnc-fixes     Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/vnc-fixes     Wed Aug 23 11:11:27 2006 -0600
@@ -1,8 +1,8 @@ Index: ioemu/vl.c
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-07 17:42:28.004363230 +0100
-+++ ioemu/vl.c 2006-08-07 17:43:16.361100898 +0100
-@@ -6516,8 +6516,10 @@
+--- ioemu.orig/vl.c    2006-08-17 19:50:10.316995669 +0100
++++ ioemu/vl.c 2006-08-17 19:50:12.100798502 +0100
+@@ -6534,8 +6534,10 @@
          }
      }
  
@@ -17,8 +17,8 @@ Index: ioemu/vl.c
      if (use_gdbstub) {
 Index: ioemu/vnc.c
 ===================================================================
---- ioemu.orig/vnc.c   2006-08-07 17:42:28.001363557 +0100
-+++ ioemu/vnc.c        2006-08-07 17:43:33.593225293 +0100
+--- ioemu.orig/vnc.c   2006-08-17 19:50:10.313996001 +0100
++++ ioemu/vnc.c        2006-08-17 19:50:12.101798392 +0100
 @@ -3,6 +3,7 @@
   * 
   * Copyright (C) 2006 Anthony Liguori <anthony@xxxxxxxxxxxxx>
@@ -524,9 +524,9 @@ Index: ioemu/vnc.c
  }
 Index: ioemu/vl.h
 ===================================================================
---- ioemu.orig/vl.h    2006-08-07 17:42:27.807385506 +0100
-+++ ioemu/vl.h 2006-08-07 17:43:16.361100898 +0100
-@@ -318,6 +318,7 @@
+--- ioemu.orig/vl.h    2006-08-17 19:50:02.411869432 +0100
++++ ioemu/vl.h 2006-08-17 19:50:12.102798281 +0100
+@@ -319,6 +319,7 @@
  int is_graphic_console(void);
  CharDriverState *text_console_init(DisplayState *ds);
  void console_select(unsigned int index);
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/vnc-start-vncviewer
--- a/tools/ioemu/patches/vnc-start-vncviewer   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/vnc-start-vncviewer   Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/vnc.c
 Index: ioemu/vnc.c
 ===================================================================
---- ioemu.orig/vnc.c   2006-08-07 17:44:32.852773890 +0100
-+++ ioemu/vnc.c        2006-08-07 17:44:32.915767031 +0100
+--- ioemu.orig/vnc.c   2006-08-17 19:50:12.101798392 +0100
++++ ioemu/vnc.c        2006-08-17 19:50:13.149682567 +0100
 @@ -1175,3 +1175,25 @@
  
      vnc_dpy_resize(vs->ds, 640, 400);
@@ -30,8 +30,8 @@ Index: ioemu/vnc.c
 +}
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-07 17:44:32.851773999 +0100
-+++ ioemu/vl.c 2006-08-07 17:44:32.918766704 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:50:12.100798502 +0100
++++ ioemu/vl.c 2006-08-17 19:50:13.152682236 +0100
 @@ -120,6 +120,7 @@
  int bios_size;
  static DisplayState display_state;
@@ -82,7 +82,7 @@ Index: ioemu/vl.c
              }
          }
      }
-@@ -6458,6 +6466,8 @@
+@@ -6476,6 +6484,8 @@
          dumb_display_init(ds);
      } else if (vnc_display != -1) {
        vnc_display_init(ds, vnc_display);
@@ -93,9 +93,9 @@ Index: ioemu/vl.c
          sdl_display_init(ds, full_screen);
 Index: ioemu/vl.h
 ===================================================================
---- ioemu.orig/vl.h    2006-08-07 17:44:32.853773781 +0100
-+++ ioemu/vl.h 2006-08-07 17:44:32.919766595 +0100
-@@ -785,6 +785,7 @@
+--- ioemu.orig/vl.h    2006-08-17 19:50:12.102798281 +0100
++++ ioemu/vl.h 2006-08-17 19:50:13.153682125 +0100
+@@ -786,6 +786,7 @@
  
  /* vnc.c */
  void vnc_display_init(DisplayState *ds, int display);
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/vnc-title-domain-name
--- a/tools/ioemu/patches/vnc-title-domain-name Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/vnc-title-domain-name Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/vnc.c
 Index: ioemu/vnc.c
 ===================================================================
---- ioemu.orig/vnc.c   2006-08-07 17:44:32.915767031 +0100
-+++ ioemu/vnc.c        2006-08-07 17:44:33.084748631 +0100
+--- ioemu.orig/vnc.c   2006-08-17 19:50:13.149682567 +0100
++++ ioemu/vnc.c        2006-08-17 19:50:14.623519661 +0100
 @@ -1014,6 +1014,7 @@
  
  static int protocol_client_init(VncState *vs, char *data, size_t len)
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/xen-mm
--- a/tools/ioemu/patches/xen-mm        Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/patches/xen-mm        Wed Aug 23 11:11:27 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/hw/pc.c
 Index: ioemu/hw/pc.c
 ===================================================================
---- ioemu.orig/hw/pc.c 2006-08-06 02:15:39.708879311 +0100
-+++ ioemu/hw/pc.c      2006-08-06 02:18:18.875135656 +0100
+--- ioemu.orig/hw/pc.c 2006-08-17 19:36:00.588166019 +0100
++++ ioemu/hw/pc.c      2006-08-17 19:37:36.704485734 +0100
 @@ -646,7 +646,9 @@
      }
  
@@ -25,8 +25,8 @@ Index: ioemu/hw/pc.c
      isa_bios_size = bios_size;
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-06 02:18:12.550840673 +0100
-+++ ioemu/vl.c 2006-08-06 02:18:45.608155528 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:36:00.667157242 +0100
++++ ioemu/vl.c 2006-08-17 19:47:08.538087284 +0100
 @@ -158,6 +158,8 @@
  int acpi_enabled = 1;
  int fd_bootchk = 1;
@@ -40,7 +40,7 @@ Index: ioemu/vl.c
      QEMUMachine *machine;
      char usb_devices[MAX_USB_CMDLINE][128];
      int usb_devices_index;
-+    unsigned long nr_pages;
++    unsigned long nr_pages, tmp_nr_pages, shared_page_nr;
 +    xen_pfn_t *page_array;
 +    extern void *shared_page;
  
@@ -60,16 +60,26 @@ Index: ioemu/vl.c
                  break;
              case QEMU_OPTION_l:
                  {
-@@ -6133,12 +6140,49 @@
+@@ -6133,12 +6140,67 @@
      /* init the memory */
      phys_ram_size = ram_size + vga_ram_size + bios_size;
  
 +#ifdef CONFIG_DM
 +
-+    nr_pages = ram_size/PAGE_SIZE;
 +    xc_handle = xc_interface_open();
 +
-+    page_array = (xen_pfn_t *)malloc(nr_pages * sizeof(xen_pfn_t));
++    nr_pages = ram_size/PAGE_SIZE;
++    tmp_nr_pages = nr_pages;
++
++#if defined(__i386__) || defined(__x86_64__)
++    if (ram_size > HVM_BELOW_4G_RAM_END) {
++        tmp_nr_pages += HVM_BELOW_4G_MMIO_LENGTH >> PAGE_SHIFT;
++        shared_page_nr = (HVM_BELOW_4G_RAM_END >> PAGE_SHIFT) - 1;
++    } else
++        shared_page_nr = nr_pages - 1;
++#endif
++
++    page_array = (xen_pfn_t *)malloc(tmp_nr_pages * sizeof(xen_pfn_t));
 +    if (page_array == NULL) {
 +        fprintf(logfile, "malloc returned error %d\n", errno);
 +        exit(-1);
@@ -80,20 +90,28 @@ Index: ioemu/vl.c
 +        exit(-1);
 +    }
 +
++    if (ram_size > HVM_BELOW_4G_RAM_END)
++        for (i = 0; i < nr_pages - (HVM_BELOW_4G_RAM_END >> PAGE_SHIFT); i++)
++            page_array[tmp_nr_pages - 1 - i] = page_array[nr_pages - 1 - i];
++
 +    phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
 +                                         PROT_READ|PROT_WRITE, page_array,
-+                                         nr_pages - 1);
-+    if (phys_ram_base == 0) {
-+        fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
++                                         tmp_nr_pages);
++    if (phys_ram_base == NULL) {
++        fprintf(logfile, "batch map guest memory returned error %d\n", errno);
 +        exit(-1);
 +    }
 +
 +    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
 +                                       PROT_READ|PROT_WRITE,
-+                                       page_array[nr_pages - 1]);
++                                       page_array[shared_page_nr]);
++    if (shared_page == NULL) {
++        fprintf(logfile, "map shared IO page returned error %d\n", errno);
++        exit(-1);
++    }
 +
-+    fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n", nr_pages - 1,
-+            (uint64_t)(page_array[nr_pages - 1]));
++    fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n",
++            shared_page_nr, (uint64_t)(page_array[shared_page_nr]));
 +
 +    free(page_array);
 +
@@ -110,3 +128,28 @@ Index: ioemu/vl.c
      /* we always create the cdrom drive, even if no disk is there */
      bdrv_init();
      if (cdrom_index >= 0) {
+Index: ioemu/hw/piix_pci.c
+===================================================================
+--- ioemu.orig/hw/piix_pci.c   2006-08-17 19:37:36.189542951 +0100
++++ ioemu/hw/piix_pci.c        2006-08-17 19:38:05.806252180 +0100
+@@ -399,7 +399,7 @@
+     uint8_t elcr[2];
+ 
+     pci_bios_io_addr = 0xc000;
+-    pci_bios_mem_addr = 0xf0000000;
++    pci_bios_mem_addr = HVM_BELOW_4G_MMIO_START;
+ 
+     /* activate IRQ mappings */
+     elcr[0] = 0x00;
+Index: ioemu/vl.h
+===================================================================
+--- ioemu.orig/vl.h    2006-08-17 19:37:36.529505177 +0100
++++ ioemu/vl.h 2006-08-17 19:47:32.680418959 +0100
+@@ -39,6 +39,7 @@
+ #include <sys/stat.h>
+ #include "xenctrl.h"
+ #include "xs.h"
++#include <xen/hvm/e820.h>
+ 
+ #ifndef O_LARGEFILE
+ #define O_LARGEFILE 0
diff -r 91169603a8e8 -r 79afceca9065 
tools/ioemu/patches/xen-support-buffered-ioreqs
--- a/tools/ioemu/patches/xen-support-buffered-ioreqs   Tue Aug 22 14:45:49 
2006 -0600
+++ b/tools/ioemu/patches/xen-support-buffered-ioreqs   Wed Aug 23 11:11:27 
2006 -0600
@@ -1,38 +1,38 @@ Index: ioemu/vl.c
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-09 15:04:25.583508863 +0100
-+++ ioemu/vl.c 2006-08-09 15:04:26.034465993 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:50:22.277673633 +0100
++++ ioemu/vl.c 2006-08-17 19:55:21.878556486 +0100
 @@ -5838,6 +5838,7 @@
-     unsigned long nr_pages;
+     unsigned long nr_pages, tmp_nr_pages, shared_page_nr;
      xen_pfn_t *page_array;
      extern void *shared_page;
 +    extern void *buffered_io_page;
  
      char qemu_dm_logfilename[64];
  
-@@ -6388,12 +6389,17 @@
- 
-     phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
-                                          PROT_READ|PROT_WRITE, page_array,
--                                         nr_pages - 1);
-+                                         nr_pages - 3);
-     if (phys_ram_base == 0) {
-         fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
-         exit(-1);
-     }
+@@ -6419,6 +6420,18 @@
+     fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n",
+             shared_page_nr, (uint64_t)(page_array[shared_page_nr]));
  
 +    /* not yet add for IA64 */
 +    buffered_io_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
-+                                       PROT_READ|PROT_WRITE,
-+                                       page_array[nr_pages - 3]);
++                                            PROT_READ|PROT_WRITE,
++                                            page_array[shared_page_nr - 2]);
++    if (buffered_io_page == NULL) {
++        fprintf(logfile, "map buffered IO page returned error %d\n", errno);
++        exit(-1);
++    }
 +
-     shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
-                                        PROT_READ|PROT_WRITE,
-                                        page_array[nr_pages - 1]);
++    fprintf(logfile, "buffered io page at pfn:%lx, mfn: %"PRIx64"\n",
++            shared_page_nr - 2, (uint64_t)(page_array[shared_page_nr - 2]));
++
+     free(page_array);
+ 
+ #elif defined(__ia64__)
 Index: ioemu/target-i386-dm/helper2.c
 ===================================================================
---- ioemu.orig/target-i386-dm/helper2.c        2006-08-09 15:04:24.105649313 
+0100
-+++ ioemu/target-i386-dm/helper2.c     2006-08-09 15:04:26.040465422 +0100
+--- ioemu.orig/target-i386-dm/helper2.c        2006-08-17 19:49:44.491850141 
+0100
++++ ioemu/target-i386-dm/helper2.c     2006-08-17 19:50:41.490549986 +0100
 @@ -76,6 +76,10 @@
  
  shared_iopage_t *shared_page = NULL;
diff -r 91169603a8e8 -r 79afceca9065 
tools/ioemu/patches/xenstore-block-device-config
--- a/tools/ioemu/patches/xenstore-block-device-config  Tue Aug 22 14:45:49 
2006 -0600
+++ b/tools/ioemu/patches/xenstore-block-device-config  Wed Aug 23 11:11:27 
2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/Makefile.target
 Index: ioemu/Makefile.target
 ===================================================================
---- ioemu.orig/Makefile.target 2006-08-09 15:04:24.795583755 +0100
-+++ ioemu/Makefile.target      2006-08-09 15:04:25.373528824 +0100
+--- ioemu.orig/Makefile.target 2006-08-17 19:50:02.405870095 +0100
++++ ioemu/Makefile.target      2006-08-17 19:50:18.866050726 +0100
 @@ -358,6 +358,7 @@
  VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
  VL_OBJS+= usb-uhci.o
@@ -13,7 +13,7 @@ Index: ioemu/xenstore.c
 Index: ioemu/xenstore.c
 ===================================================================
 --- /dev/null  1970-01-01 00:00:00.000000000 +0000
-+++ ioemu/xenstore.c   2006-08-09 15:04:25.374528729 +0100
++++ ioemu/xenstore.c   2006-08-17 19:50:18.867050616 +0100
 @@ -0,0 +1,187 @@
 +/*
 + * This file is subject to the terms and conditions of the GNU General
@@ -204,8 +204,8 @@ Index: ioemu/xenstore.c
 +}
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-09 15:04:25.312534622 +0100
-+++ ioemu/vl.c 2006-08-09 15:04:25.377528443 +0100
+--- ioemu.orig/vl.c    2006-08-17 19:50:17.086247452 +0100
++++ ioemu/vl.c 2006-08-17 19:50:18.870050284 +0100
 @@ -5243,9 +5243,11 @@
             "Standard options:\n"
             "-M machine      select emulated machine (-M ? for list)\n"
@@ -359,7 +359,7 @@ Index: ioemu/vl.c
  
      setvbuf(stdout, NULL, _IOLBF, 0);
      
-@@ -6417,6 +6448,7 @@
+@@ -6435,6 +6466,7 @@
  
  #endif /* !CONFIG_DM */
  
@@ -367,7 +367,7 @@ Index: ioemu/vl.c
      /* we always create the cdrom drive, even if no disk is there */
      bdrv_init();
      if (cdrom_index >= 0) {
-@@ -6443,6 +6475,7 @@
+@@ -6461,6 +6493,7 @@
              }
          }
      }
@@ -375,7 +375,7 @@ Index: ioemu/vl.c
  
      /* we always create at least one floppy disk */
      fd_table[0] = bdrv_new("fda");
-@@ -6521,6 +6554,8 @@
+@@ -6539,6 +6572,8 @@
          }
      }
  
@@ -386,8 +386,8 @@ Index: ioemu/vl.c
                    kernel_filename, kernel_cmdline, initrd_filename,
 Index: ioemu/monitor.c
 ===================================================================
---- ioemu.orig/monitor.c       2006-08-09 15:04:24.105649313 +0100
-+++ ioemu/monitor.c    2006-08-09 15:04:25.379528253 +0100
+--- ioemu.orig/monitor.c       2006-08-17 19:49:44.491850141 +0100
++++ ioemu/monitor.c    2006-08-17 19:50:18.871050174 +0100
 @@ -24,6 +24,7 @@
  #include "vl.h"
  #include "disas.h"
@@ -416,8 +416,8 @@ Index: ioemu/monitor.c
      int i;
 Index: ioemu/block.c
 ===================================================================
---- ioemu.orig/block.c 2006-08-09 15:04:17.487277167 +0100
-+++ ioemu/block.c      2006-08-09 15:04:25.379528253 +0100
+--- ioemu.orig/block.c 2006-08-17 19:37:35.865578948 +0100
++++ ioemu/block.c      2006-08-17 19:50:18.872050063 +0100
 @@ -758,6 +758,7 @@
  static void raw_close(BlockDriverState *bs)
  {
@@ -428,9 +428,9 @@ Index: ioemu/block.c
  
 Index: ioemu/vl.h
 ===================================================================
---- ioemu.orig/vl.h    2006-08-09 15:04:25.313534527 +0100
-+++ ioemu/vl.h 2006-08-09 15:04:25.380528158 +0100
-@@ -1184,6 +1184,8 @@
+--- ioemu.orig/vl.h    2006-08-17 19:50:17.087247341 +0100
++++ ioemu/vl.h 2006-08-17 19:50:18.872050063 +0100
+@@ -1188,6 +1188,8 @@
  void term_print_help(void);
  void monitor_readline(const char *prompt, int is_password,
                        char *buf, int buf_size);
@@ -439,7 +439,7 @@ Index: ioemu/vl.h
  
  /* readline.c */
  typedef void ReadLineFunc(void *opaque, const char *str);
-@@ -1196,6 +1198,13 @@
+@@ -1200,6 +1202,13 @@
  void readline_start(const char *prompt, int is_password,
                      ReadLineFunc *readline_func, void *opaque);
  
@@ -455,8 +455,8 @@ Index: ioemu/vl.h
  extern char domain_name[];
 Index: ioemu/hw/ide.c
 ===================================================================
---- ioemu.orig/hw/ide.c        2006-08-09 15:04:24.524609503 +0100
-+++ ioemu/hw/ide.c     2006-08-09 15:04:25.381528063 +0100
+--- ioemu.orig/hw/ide.c        2006-08-17 19:49:57.830375828 +0100
++++ ioemu/hw/ide.c     2006-08-17 19:50:18.874049842 +0100
 @@ -1158,6 +1158,7 @@
          } else {
              ide_atapi_cmd_error(s, SENSE_NOT_READY, 
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/patches/xenstore-write-vnc-port
--- a/tools/ioemu/patches/xenstore-write-vnc-port       Tue Aug 22 14:45:49 
2006 -0600
+++ b/tools/ioemu/patches/xenstore-write-vnc-port       Wed Aug 23 11:11:27 
2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/xenstore.c
 Index: ioemu/xenstore.c
 ===================================================================
---- ioemu.orig/xenstore.c      2006-08-09 15:04:25.374528729 +0100
-+++ ioemu/xenstore.c   2006-08-09 15:04:25.579509243 +0100
+--- ioemu.orig/xenstore.c      2006-08-17 19:50:18.867050616 +0100
++++ ioemu/xenstore.c   2006-08-17 19:50:22.274673964 +0100
 @@ -185,3 +185,31 @@
      free(image);
      free(vec);
@@ -36,9 +36,9 @@ Index: ioemu/xenstore.c
 +}
 Index: ioemu/vl.c
 ===================================================================
---- ioemu.orig/vl.c    2006-08-09 15:04:25.377528443 +0100
-+++ ioemu/vl.c 2006-08-09 15:04:25.583508863 +0100
-@@ -6511,6 +6511,7 @@
+--- ioemu.orig/vl.c    2006-08-17 19:50:18.870050284 +0100
++++ ioemu/vl.c 2006-08-17 19:50:22.277673633 +0100
+@@ -6529,6 +6529,7 @@
        vnc_display = vnc_display_init(ds, vnc_display, vncunused);
        if (vncviewer)
            vnc_start_viewer(vnc_display);
@@ -48,9 +48,9 @@ Index: ioemu/vl.c
          sdl_display_init(ds, full_screen);
 Index: ioemu/vl.h
 ===================================================================
---- ioemu.orig/vl.h    2006-08-09 15:04:25.380528158 +0100
-+++ ioemu/vl.h 2006-08-09 15:04:25.584508768 +0100
-@@ -1203,6 +1203,7 @@
+--- ioemu.orig/vl.h    2006-08-17 19:50:18.872050063 +0100
++++ ioemu/vl.h 2006-08-17 19:50:22.278673522 +0100
+@@ -1207,6 +1207,7 @@
  int xenstore_fd(void);
  void xenstore_process_event(void *opaque);
  void xenstore_check_new_media_present(int timeout);
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/target-i386-dm/exec-dm.c
--- a/tools/ioemu/target-i386-dm/exec-dm.c      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/target-i386-dm/exec-dm.c      Wed Aug 23 11:11:27 2006 -0600
@@ -449,6 +449,9 @@ void cpu_physical_memory_rw(target_phys_
                 /* RAM case */
                 ptr = phys_ram_base + addr1;
                 memcpy(ptr, buf, l);
+#ifdef __ia64__
+                sync_icache((unsigned long)ptr, l);
+#endif 
             }
         } else {
             if (io_index) {
@@ -473,9 +476,6 @@ void cpu_physical_memory_rw(target_phys_
                 ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) + 
                     (addr & ~TARGET_PAGE_MASK);
                 memcpy(buf, ptr, l);
-#ifdef __ia64__
-                sync_icache((unsigned long)ptr, l);
-#endif 
             } else {
                 /* unreported MMIO space */
                 memset(buf, 0xff, len);
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/vl.c
--- a/tools/ioemu/vl.c  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/vl.c  Wed Aug 23 11:11:27 2006 -0600
@@ -124,7 +124,7 @@ int vncunused;
 int vncunused;
 const char* keyboard_layout = NULL;
 int64_t ticks_per_sec;
-int boot_device = 'c';
+char *boot_device = NULL;
 uint64_t ram_size;
 int pit_min_timer_count = 0;
 int nb_nics;
@@ -5835,7 +5835,7 @@ int main(int argc, char **argv)
     QEMUMachine *machine;
     char usb_devices[MAX_USB_CMDLINE][128];
     int usb_devices_index;
-    unsigned long nr_pages;
+    unsigned long nr_pages, tmp_nr_pages, shared_page_nr;
     xen_pfn_t *page_array;
     extern void *shared_page;
     extern void *buffered_io_page;
@@ -6036,10 +6036,11 @@ int main(int argc, char **argv)
                 }
                 break;
             case QEMU_OPTION_nographic:
-                pstrcpy(monitor_device, sizeof(monitor_device), "stdio");
+                if(!strcmp(monitor_device, "vc"))
+                    pstrcpy(monitor_device, sizeof(monitor_device), "null");
                 if(!strcmp(serial_devices[0], "vc"))
                     pstrcpy(serial_devices[0], sizeof(serial_devices[0]),
-                            "stdio");
+                            "null");
                 nographic = 1;
                 break;
             case QEMU_OPTION_kernel:
@@ -6056,14 +6057,14 @@ int main(int argc, char **argv)
                 break;
 #endif /* !CONFIG_DM */
             case QEMU_OPTION_boot:
-                boot_device = optarg[0];
-                if (boot_device != 'a' && 
+                boot_device = strdup(optarg);
+                if (strspn(boot_device, "acd"
 #ifdef TARGET_SPARC
-                   // Network boot
-                   boot_device != 'n' &&
-#endif
-                    boot_device != 'c' && boot_device != 'd') {
-                    fprintf(stderr, "qemu: invalid boot device '%c'\n", 
boot_device);
+                           "n"
+#endif
+                        ) != strlen(boot_device)) {
+                    fprintf(stderr, "qemu: invalid boot device in '%s'\n",
+                            boot_device);
                     exit(1);
                 }
                 break;
@@ -6327,6 +6328,7 @@ int main(int argc, char **argv)
         fd_filename[0] == '\0')
         help();
     
+#if 0
     /* boot to cd by default if no hard disk */
     if (hd_filename[0] == '\0' && boot_device == 'c') {
         if (fd_filename[0] != '\0')
@@ -6334,6 +6336,7 @@ int main(int argc, char **argv)
         else
             boot_device = 'd';
     }
+#endif
 #endif /* !CONFIG_DM */
 
     setvbuf(stdout, NULL, _IOLBF, 0);
@@ -6365,17 +6368,27 @@ int main(int argc, char **argv)
     /* init the memory */
     phys_ram_size = ram_size + vga_ram_size + bios_size;
 
+#ifdef CONFIG_DM
+
+    xc_handle = xc_interface_open();
+
 #if defined (__ia64__)
     if (ram_size > MMIO_START)
-       ram_size += 1 * MEM_G; /* skip 3G-4G MMIO, LEGACY_IO_SPACE etc. */
-#endif
-
-#ifdef CONFIG_DM
+        ram_size += 1 * MEM_G; /* skip 3G-4G MMIO, LEGACY_IO_SPACE etc. */
+#endif
 
     nr_pages = ram_size/PAGE_SIZE;
-    xc_handle = xc_interface_open();
-
-    page_array = (xen_pfn_t *)malloc(nr_pages * sizeof(xen_pfn_t));
+    tmp_nr_pages = nr_pages;
+
+#if defined(__i386__) || defined(__x86_64__)
+    if (ram_size > HVM_BELOW_4G_RAM_END) {
+        tmp_nr_pages += HVM_BELOW_4G_MMIO_LENGTH >> PAGE_SHIFT;
+        shared_page_nr = (HVM_BELOW_4G_RAM_END >> PAGE_SHIFT) - 1;
+    } else
+        shared_page_nr = nr_pages - 1;
+#endif
+
+    page_array = (xen_pfn_t *)malloc(tmp_nr_pages * sizeof(xen_pfn_t));
     if (page_array == NULL) {
         fprintf(logfile, "malloc returned error %d\n", errno);
         exit(-1);
@@ -6387,25 +6400,40 @@ int main(int argc, char **argv)
         exit(-1);
     }
 
+    if (ram_size > HVM_BELOW_4G_RAM_END)
+        for (i = 0; i < nr_pages - (HVM_BELOW_4G_RAM_END >> PAGE_SHIFT); i++)
+            page_array[tmp_nr_pages - 1 - i] = page_array[nr_pages - 1 - i];
+
     phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
                                          PROT_READ|PROT_WRITE, page_array,
-                                         nr_pages - 3);
-    if (phys_ram_base == 0) {
-        fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
+                                         tmp_nr_pages);
+    if (phys_ram_base == NULL) {
+        fprintf(logfile, "batch map guest memory returned error %d\n", errno);
         exit(-1);
     }
+
+    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
+                                       PROT_READ|PROT_WRITE,
+                                       page_array[shared_page_nr]);
+    if (shared_page == NULL) {
+        fprintf(logfile, "map shared IO page returned error %d\n", errno);
+        exit(-1);
+    }
+
+    fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n",
+            shared_page_nr, (uint64_t)(page_array[shared_page_nr]));
 
     /* not yet add for IA64 */
     buffered_io_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
-                                       PROT_READ|PROT_WRITE,
-                                       page_array[nr_pages - 3]);
-
-    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
-                                       PROT_READ|PROT_WRITE,
-                                       page_array[nr_pages - 1]);
-
-    fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n", nr_pages - 1,
-            (uint64_t)(page_array[nr_pages - 1]));
+                                            PROT_READ|PROT_WRITE,
+                                            page_array[shared_page_nr - 2]);
+    if (buffered_io_page == NULL) {
+        fprintf(logfile, "map buffered IO page returned error %d\n", errno);
+        exit(-1);
+    }
+
+    fprintf(logfile, "buffered io page at pfn:%lx, mfn: %"PRIx64"\n",
+            shared_page_nr - 2, (uint64_t)(page_array[shared_page_nr - 2]));
 
     free(page_array);
 
@@ -6431,9 +6459,9 @@ int main(int argc, char **argv)
     }
 
     if (ram_size > MMIO_START) {       
-       for (i = 0 ; i < MEM_G >> PAGE_SHIFT; i++)
-           page_array[MMIO_START >> PAGE_SHIFT + i] =
-               page_array[IO_PAGE_START >> PAGE_SHIFT + 1];
+        for (i = 0 ; i < MEM_G >> PAGE_SHIFT; i++)
+            page_array[MMIO_START >> PAGE_SHIFT + i] =
+                page_array[IO_PAGE_START >> PAGE_SHIFT + 1];
     }
 
     phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
@@ -6567,6 +6595,7 @@ int main(int argc, char **argv)
                   ds, fd_filename, snapshot,
                   kernel_filename, kernel_cmdline, initrd_filename,
                   timeoffset);
+    free(boot_device);
 
     /* init USB devices */
     if (usb_enabled) {
diff -r 91169603a8e8 -r 79afceca9065 tools/ioemu/vl.h
--- a/tools/ioemu/vl.h  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/ioemu/vl.h  Wed Aug 23 11:11:27 2006 -0600
@@ -39,6 +39,7 @@
 #include <sys/stat.h>
 #include "xenctrl.h"
 #include "xs.h"
+#include <xen/hvm/e820.h>
 
 #ifndef O_LARGEFILE
 #define O_LARGEFILE 0
@@ -574,7 +575,7 @@ int qcow_compress_cluster(BlockDriverSta
 #ifndef QEMU_TOOL
 
 typedef void QEMUMachineInitFunc(uint64_t ram_size, int vga_ram_size, 
-                                 int boot_device,
+                                 char *boot_device,
              DisplayState *ds, const char **fd_filename, int snapshot,
              const char *kernel_filename, const char *kernel_cmdline,
              const char *initrd_filename, time_t timeoffset);
@@ -925,6 +926,9 @@ void piix4_pm_init(PCIBus *bus, int devf
 void piix4_pm_init(PCIBus *bus, int devfn);
 void acpi_bios_init(void);
 
+/* piix4acpi.c */
+extern void pci_piix4_acpi_init(PCIBus *bus, int devfn);
+
 /* pc.c */
 extern QEMUMachine pc_machine;
 extern QEMUMachine isapc_machine;
@@ -1016,7 +1020,7 @@ void NVRAM_set_crc (m48t59_t *nvram, uin
                     uint32_t start, uint32_t count);
 int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
                           const unsigned char *arch,
-                          uint32_t RAM_size, int boot_device,
+                          uint32_t RAM_size, char *boot_device,
                           uint32_t kernel_image, uint32_t kernel_size,
                           const char *cmdline,
                           uint32_t initrd_image, uint32_t initrd_size,
@@ -1205,6 +1209,9 @@ void xenstore_check_new_media_present(in
 void xenstore_check_new_media_present(int timeout);
 void xenstore_write_vncport(int vnc_display);
 
+/* xen_platform.c */
+void pci_xen_platform_init(PCIBus *bus);
+
 
 void kqemu_record_dump(void);
 
diff -r 91169603a8e8 -r 79afceca9065 tools/libaio/src/Makefile
--- a/tools/libaio/src/Makefile Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libaio/src/Makefile Wed Aug 23 11:11:27 2006 -0600
@@ -1,3 +1,6 @@ prefix=/usr
+XEN_ROOT = ../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
 prefix=/usr
 includedir=$(prefix)/include
 libdir=$(prefix)/lib
@@ -44,8 +47,8 @@ libaio_sobjs := $(patsubst %.c,%.os,$(li
 
 libaio.a: $(libaio_objs)
        rm -f libaio.a
-       ar r libaio.a $^
-       ranlib libaio.a
+       $(AR) r libaio.a $^
+       $(RANLIB) libaio.a
 
 $(libname): $(libaio_sobjs) libaio.map
        $(CC) $(SO_CFLAGS) -Wl,--version-script=libaio.map 
-Wl,-soname=$(soname) -o $@ $(libaio_sobjs) $(LINK_FLAGS)
diff -r 91169603a8e8 -r 79afceca9065 tools/libxc/Makefile
--- a/tools/libxc/Makefile      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libxc/Makefile      Wed Aug 23 11:11:27 2006 -0600
@@ -29,7 +29,6 @@ GUEST_SRCS-y += xc_load_bin.c
 GUEST_SRCS-y += xc_load_bin.c
 GUEST_SRCS-y += xc_load_elf.c
 GUEST_SRCS-y += xg_private.c
-GUEST_SRCS-$(CONFIG_POWERPC) += xc_ppc_linux_build.c
 GUEST_SRCS-$(CONFIG_X86) += xc_linux_build.c
 GUEST_SRCS-$(CONFIG_IA64) += xc_linux_build.c
 GUEST_SRCS-$(CONFIG_MIGRATE) += xc_linux_restore.c xc_linux_save.c
@@ -100,8 +99,9 @@ TAGS:
 
 .PHONY: clean
 clean:
-       rm -rf *.a *.so* *.o *.opic *.rpm $(LIB) *~ $(DEPS) xen
-       rm -rf ia64/*.o ia64/*.opic
+       rm -rf *.rpm $(LIB) *~ $(DEPS) xen \
+            $(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS) \
+            $(GUEST_LIB_OBJS) $(GUEST_PIC_OBJS)
 
 .PHONY: rpm
 rpm: build
@@ -140,3 +140,4 @@ libxenguest.so.$(MAJOR).$(MINOR): $(GUES
        $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenguest.so.$(MAJOR) 
-shared -o $@ $^ -lz -lxenctrl
 
 -include $(DEPS)
+
diff -r 91169603a8e8 -r 79afceca9065 tools/libxc/ia64/xc_ia64_linux_restore.c
--- a/tools/libxc/ia64/xc_ia64_linux_restore.c  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libxc/ia64/xc_ia64_linux_restore.c  Wed Aug 23 11:11:27 2006 -0600
@@ -288,8 +288,8 @@ xc_linux_restore(int xc_handle, int io_f
     start_info->flags = 0;
     *store_mfn = page_array[start_info->store_mfn];
     start_info->store_evtchn = store_evtchn;
-    *console_mfn = page_array[start_info->console_mfn];
-    start_info->console_evtchn = console_evtchn;
+    *console_mfn = page_array[start_info->console.domU.mfn];
+    start_info->console.domU.evtchn = console_evtchn;
     munmap(start_info, PAGE_SIZE);
 
     /*
diff -r 91169603a8e8 -r 79afceca9065 tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libxc/xc_domain.c   Wed Aug 23 11:11:27 2006 -0600
@@ -213,21 +213,28 @@ int xc_shadow_control(int xc_handle,
                       unsigned int sop,
                       unsigned long *dirty_bitmap,
                       unsigned long pages,
-                      xc_shadow_control_stats_t *stats )
+                      unsigned long *mb,
+                      uint32_t mode,
+                      xc_shadow_control_stats_t *stats)
 {
     int rc;
     DECLARE_DOM0_OP;
     op.cmd = DOM0_SHADOW_CONTROL;
     op.u.shadow_control.domain = (domid_t)domid;
     op.u.shadow_control.op     = sop;
+    op.u.shadow_control.pages  = pages;
+    op.u.shadow_control.mb     = mb ? *mb : 0;
+    op.u.shadow_control.mode   = mode;
     set_xen_guest_handle(op.u.shadow_control.dirty_bitmap, dirty_bitmap);
-    op.u.shadow_control.pages  = pages;
 
     rc = do_dom0_op(xc_handle, &op);
 
     if ( stats )
         memcpy(stats, &op.u.shadow_control.stats,
                sizeof(xc_shadow_control_stats_t));
+    
+    if ( mb ) 
+        *mb = op.u.shadow_control.mb;
 
     return (rc == 0) ? op.u.shadow_control.pages : rc;
 }
@@ -391,7 +398,7 @@ int xc_domain_memory_populate_physmap(in
 
     if ( err > 0 )
     {
-        DPRINTF("Failed deallocation for dom %d: %ld pages order %d\n",
+        DPRINTF("Failed allocation for dom %d: %ld pages order %d\n",
                 domid, nr_extents, extent_order);
         errno = EBUSY;
         err = -1;
diff -r 91169603a8e8 -r 79afceca9065 tools/libxc/xc_evtchn.c
--- a/tools/libxc/xc_evtchn.c   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libxc/xc_evtchn.c   Wed Aug 23 11:11:27 2006 -0600
@@ -49,14 +49,3 @@ int xc_evtchn_alloc_unbound(int xc_handl
 
     return rc;
 }
-
-
-int xc_evtchn_status(int xc_handle,
-                     uint32_t dom,
-                     evtchn_port_t port,
-                     xc_evtchn_status_t *status)
-{
-    status->dom  = (domid_t)dom;
-    status->port = port;
-    return do_evtchn_op(xc_handle, EVTCHNOP_status, status, sizeof(*status));
-}
diff -r 91169603a8e8 -r 79afceca9065 tools/libxc/xc_hvm_build.c
--- a/tools/libxc/xc_hvm_build.c        Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libxc/xc_hvm_build.c        Wed Aug 23 11:11:27 2006 -0600
@@ -14,29 +14,9 @@
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/ioreq.h>
 #include <xen/hvm/params.h>
+#include <xen/hvm/e820.h>
 
 #define HVM_LOADER_ENTR_ADDR  0x00100000
-
-#define E820MAX     128
-
-#define E820_RAM          1
-#define E820_RESERVED     2
-#define E820_ACPI         3
-#define E820_NVS          4
-#define E820_IO          16
-#define E820_SHARED_PAGE 17
-#define E820_XENSTORE    18
-#define E820_BUFFERED_IO 19
-
-#define E820_MAP_PAGE       0x00090000
-#define E820_MAP_NR_OFFSET  0x000001E8
-#define E820_MAP_OFFSET     0x000002D0
-
-struct e820entry {
-    uint64_t addr;
-    uint64_t size;
-    uint32_t type;
-} __attribute__((packed));
 
 static int
 parseelfimage(
@@ -74,16 +54,26 @@ static void build_e820map(void *e820_pag
 {
     struct e820entry *e820entry =
         (struct e820entry *)(((unsigned char *)e820_page) + E820_MAP_OFFSET);
+    unsigned long long extra_mem_size = 0;
     unsigned char nr_map = 0;
 
-    /* XXX: Doesn't work for > 4GB yet */
+    /*
+     * physical address space from HVM_BELOW_4G_RAM_END to 4G is reserved
+     * for PCI devices MMIO. So if HVM has more than HVM_BELOW_4G_RAM_END
+     * RAM, memory beyond HVM_BELOW_4G_RAM_END will go to 4G above.
+     */
+    if ( mem_size > HVM_BELOW_4G_RAM_END ) {
+        extra_mem_size = mem_size - HVM_BELOW_4G_RAM_END;
+        mem_size = HVM_BELOW_4G_RAM_END;
+    }
+
     e820entry[nr_map].addr = 0x0;
-    e820entry[nr_map].size = 0x9F800;
+    e820entry[nr_map].size = 0x9F000;
     e820entry[nr_map].type = E820_RAM;
     nr_map++;
 
-    e820entry[nr_map].addr = 0x9F800;
-    e820entry[nr_map].size = 0x800;
+    e820entry[nr_map].addr = 0x9F000;
+    e820entry[nr_map].size = 0x1000;
     e820entry[nr_map].type = E820_RESERVED;
     nr_map++;
 
@@ -97,53 +87,86 @@ static void build_e820map(void *e820_pag
     e820entry[nr_map].type = E820_RESERVED;
     nr_map++;
 
-#define STATIC_PAGES    3
-    /* 3 static pages:
-     * - ioreq buffer.
-     * - xenstore.
-     * - shared_page.
-     */
+/* ACPI data: 10 pages. */
+#define ACPI_DATA_PAGES     10
+/* ACPI NVS: 3 pages.   */
+#define ACPI_NVS_PAGES      3
+/* buffered io page.    */
+#define BUFFERED_IO_PAGES   1
+/* xenstore page.       */
+#define XENSTORE_PAGES      1
+/* shared io page.      */
+#define SHARED_IO_PAGES     1
+/* totally 16 static pages are reserved in E820 table */
 
     /* Most of the ram goes here */
     e820entry[nr_map].addr = 0x100000;
-    e820entry[nr_map].size = mem_size - 0x100000 - STATIC_PAGES * PAGE_SIZE;
+    e820entry[nr_map].size = mem_size - 0x100000 - PAGE_SIZE *
+                                                (ACPI_DATA_PAGES +
+                                                 ACPI_NVS_PAGES +
+                                                 BUFFERED_IO_PAGES +
+                                                 XENSTORE_PAGES +
+                                                 SHARED_IO_PAGES);
     e820entry[nr_map].type = E820_RAM;
     nr_map++;
 
     /* Statically allocated special pages */
 
+    /* For ACPI data */
+    e820entry[nr_map].addr = mem_size - PAGE_SIZE *
+                                        (ACPI_DATA_PAGES +
+                                         ACPI_NVS_PAGES +
+                                         BUFFERED_IO_PAGES +
+                                         XENSTORE_PAGES +
+                                         SHARED_IO_PAGES);
+    e820entry[nr_map].size = PAGE_SIZE * ACPI_DATA_PAGES;
+    e820entry[nr_map].type = E820_ACPI;
+    nr_map++;
+
+    /* For ACPI NVS */
+    e820entry[nr_map].addr = mem_size - PAGE_SIZE *
+                                        (ACPI_NVS_PAGES +
+                                         BUFFERED_IO_PAGES +
+                                         XENSTORE_PAGES +
+                                         SHARED_IO_PAGES);
+    e820entry[nr_map].size = PAGE_SIZE * ACPI_NVS_PAGES;
+    e820entry[nr_map].type = E820_NVS;
+    nr_map++;
+
     /* For buffered IO requests */
-    e820entry[nr_map].addr = mem_size - 3 * PAGE_SIZE;
-    e820entry[nr_map].size = PAGE_SIZE;
+    e820entry[nr_map].addr = mem_size - PAGE_SIZE *
+                                        (BUFFERED_IO_PAGES +
+                                         XENSTORE_PAGES +
+                                         SHARED_IO_PAGES);
+    e820entry[nr_map].size = PAGE_SIZE * BUFFERED_IO_PAGES;
     e820entry[nr_map].type = E820_BUFFERED_IO;
     nr_map++;
 
     /* For xenstore */
-    e820entry[nr_map].addr = mem_size - 2 * PAGE_SIZE;
-    e820entry[nr_map].size = PAGE_SIZE;
+    e820entry[nr_map].addr = mem_size - PAGE_SIZE *
+                                        (XENSTORE_PAGES +
+                                         SHARED_IO_PAGES);
+    e820entry[nr_map].size = PAGE_SIZE * XENSTORE_PAGES;
     e820entry[nr_map].type = E820_XENSTORE;
     nr_map++;
 
     /* Shared ioreq_t page */
-    e820entry[nr_map].addr = mem_size - PAGE_SIZE;
-    e820entry[nr_map].size = PAGE_SIZE;
+    e820entry[nr_map].addr = mem_size - PAGE_SIZE * SHARED_IO_PAGES;
+    e820entry[nr_map].size = PAGE_SIZE * SHARED_IO_PAGES;
     e820entry[nr_map].type = E820_SHARED_PAGE;
-    nr_map++;
-
-    e820entry[nr_map].addr = mem_size;
-    e820entry[nr_map].size = 0x3 * PAGE_SIZE;
-    e820entry[nr_map].type = E820_NVS;
-    nr_map++;
-
-    e820entry[nr_map].addr = mem_size + 0x3 * PAGE_SIZE;
-    e820entry[nr_map].size = 0xA * PAGE_SIZE;
-    e820entry[nr_map].type = E820_ACPI;
     nr_map++;
 
     e820entry[nr_map].addr = 0xFEC00000;
     e820entry[nr_map].size = 0x1400000;
     e820entry[nr_map].type = E820_IO;
     nr_map++;
+
+    if ( extra_mem_size ) {
+        e820entry[nr_map].addr = (1ULL << 32);
+        e820entry[nr_map].size = extra_mem_size;
+        e820entry[nr_map].type = E820_RAM;
+        nr_map++;
+    }
 
     *(((unsigned char *)e820_page) + E820_MAP_NR_OFFSET) = nr_map;
 }
@@ -167,7 +190,7 @@ static void set_hvm_info_checksum(struct
  */
 static int set_hvm_info(int xc_handle, uint32_t dom,
                         xen_pfn_t *pfn_list, unsigned int vcpus,
-                        unsigned int pae, unsigned int acpi, unsigned int apic)
+                        unsigned int acpi)
 {
     char *va_map;
     struct hvm_info_table *va_hvm;
@@ -185,16 +208,11 @@ static int set_hvm_info(int xc_handle, u
     strncpy(va_hvm->signature, "HVM INFO", 8);
     va_hvm->length       = sizeof(struct hvm_info_table);
     va_hvm->acpi_enabled = acpi;
-    va_hvm->apic_enabled = apic;
-    va_hvm->pae_enabled  = pae;
     va_hvm->nr_vcpus     = vcpus;
 
     set_hvm_info_checksum(va_hvm);
 
     munmap(va_map, PAGE_SIZE);
-
-    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_APIC_ENABLED, apic);
-    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_PAE_ENABLED, pae);
 
     return 0;
 }
@@ -223,11 +241,7 @@ static int setup_guest(int xc_handle,
     struct domain_setup_info dsi;
     uint64_t v_end;
 
-    unsigned long shared_page_frame = 0;
-    shared_iopage_t *sp;
-
-    unsigned long ioreq_buffer_frame = 0;
-    void *ioreq_buffer_page;
+    unsigned long shared_page_nr;
 
     memset(&dsi, 0, sizeof(struct domain_setup_info));
 
@@ -279,21 +293,38 @@ static int setup_guest(int xc_handle,
     /* Write the machine->phys table entries. */
     for ( count = 0; count < nr_pages; count++ )
     {
+        unsigned long gpfn_count_skip;
+
         ptr = (unsigned long long)page_array[count] << PAGE_SHIFT;
+
+        gpfn_count_skip = 0;
+
+        /*
+         * physical address space from HVM_BELOW_4G_RAM_END to 4G is reserved
+         * for PCI devices MMIO. So if HVM has more than HVM_BELOW_4G_RAM_END
+         * RAM, memory beyond HVM_BELOW_4G_RAM_END will go to 4G above.
+         */
+        if ( count >= (HVM_BELOW_4G_RAM_END >> PAGE_SHIFT) )
+            gpfn_count_skip = HVM_BELOW_4G_MMIO_LENGTH >> PAGE_SHIFT;
+
         if ( xc_add_mmu_update(xc_handle, mmu,
-                               ptr | MMU_MACHPHYS_UPDATE, count) )
+                               ptr | MMU_MACHPHYS_UPDATE,
+                               count + gpfn_count_skip) )
             goto error_out;
     }
 
-    if ( set_hvm_info(xc_handle, dom, page_array, vcpus, pae, acpi, apic) )
+    if ( set_hvm_info(xc_handle, dom, page_array, vcpus, acpi) )
     {
         ERROR("Couldn't set hvm info for HVM guest.\n");
         goto error_out;
     }
+
+    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_PAE_ENABLED, pae);
+    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_APIC_ENABLED, apic);
 
     if ( (e820_page = xc_map_foreign_range(
               xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
-              page_array[E820_MAP_PAGE >> PAGE_SHIFT])) == 0 )
+              page_array[E820_MAP_PAGE >> PAGE_SHIFT])) == NULL )
         goto error_out;
     memset(e820_page, 0, PAGE_SIZE);
     build_e820map(e820_page, v_end);
@@ -302,40 +333,33 @@ static int setup_guest(int xc_handle,
     /* shared_info page starts its life empty. */
     if ( (shared_info = xc_map_foreign_range(
               xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
-              shared_info_frame)) == 0 )
-        goto error_out;
-    memset(shared_info, 0, sizeof(shared_info_t));
+              shared_info_frame)) == NULL )
+        goto error_out;
+    memset(shared_info, 0, PAGE_SIZE);
     /* Mask all upcalls... */
     for ( i = 0; i < MAX_VIRT_CPUS; i++ )
         shared_info->vcpu_info[i].evtchn_upcall_mask = 1;
     munmap(shared_info, PAGE_SIZE);
 
+    if ( v_end > HVM_BELOW_4G_RAM_END )
+        shared_page_nr = (HVM_BELOW_4G_RAM_END >> PAGE_SHIFT) - 1;
+    else
+        shared_page_nr = (v_end >> PAGE_SHIFT) - 1;
+
+    *store_mfn = page_array[shared_page_nr - 1];
+
+    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_STORE_PFN, shared_page_nr - 1);
+    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_STORE_EVTCHN, store_evtchn);
+
     /* Paranoia */
-    shared_page_frame = page_array[(v_end >> PAGE_SHIFT) - 1];
-    if ( (sp = (shared_iopage_t *) xc_map_foreign_range(
-              xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
-              shared_page_frame)) == 0 )
-        goto error_out;
-    memset(sp, 0, PAGE_SIZE);
-    munmap(sp, PAGE_SIZE);
+    /* clean the shared IO requests page */
+    if ( xc_clear_domain_page(xc_handle, dom, page_array[shared_page_nr]) )
+        goto error_out;
 
     /* clean the buffered IO requests page */
-    ioreq_buffer_frame = page_array[(v_end >> PAGE_SHIFT) - 3];
-    ioreq_buffer_page = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
-                                             PROT_READ | PROT_WRITE,
-                                             ioreq_buffer_frame);
-
-    if ( ioreq_buffer_page == NULL )
-        goto error_out;
-
-    memset(ioreq_buffer_page, 0, PAGE_SIZE);
-
-    munmap(ioreq_buffer_page, PAGE_SIZE);
-
-    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_STORE_PFN, (v_end >> 
PAGE_SHIFT) - 2);
-    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_STORE_EVTCHN, store_evtchn);
-
-    *store_mfn = page_array[(v_end >> PAGE_SHIFT) - 2];
+    if ( xc_clear_domain_page(xc_handle, dom, page_array[shared_page_nr - 2]) )
+        goto error_out;
+
     if ( xc_clear_domain_page(xc_handle, dom, *store_mfn) )
         goto error_out;
 
@@ -416,6 +440,18 @@ static int xc_hvm_build_internal(int xc_
         PERROR("Could not get info on domain");
         goto error_out;
     }
+
+    /* HVM domains must be put into shadow2 mode at the start of day */
+    if ( xc_shadow_control(xc_handle, domid, DOM0_SHADOW_CONTROL_OP_ENABLE,
+                           NULL, 0, NULL, 
+                           DOM0_SHADOW_ENABLE_REFCOUNT  |
+                           DOM0_SHADOW_ENABLE_TRANSLATE |
+                           DOM0_SHADOW_ENABLE_EXTERNAL, 
+                           NULL) )
+    {
+        PERROR("Could not enable shadow paging for domain.\n");
+        goto error_out;
+    }        
 
     memset(ctxt, 0, sizeof(*ctxt));
 
diff -r 91169603a8e8 -r 79afceca9065 tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c    Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libxc/xc_linux.c    Wed Aug 23 11:11:27 2006 -0600
@@ -13,13 +13,43 @@
 
 #include <xen/memory.h>
 #include <xen/sys/evtchn.h>
+#include <unistd.h>
+#include <fcntl.h>
 
 int xc_interface_open(void)
 {
+    int flags, saved_errno;
     int fd = open("/proc/xen/privcmd", O_RDWR);
+
     if ( fd == -1 )
+    {
         PERROR("Could not obtain handle on privileged command interface");
+        return -1;
+    }
+
+    /* Although we return the file handle as the 'xc handle' the API
+       does not specify / guarentee that this integer is in fact
+       a file handle. Thus we must take responsiblity to ensure
+       it doesn't propagate (ie leak) outside the process */
+    if ( (flags = fcntl(fd, F_GETFD)) < 0 )
+    {
+        PERROR("Could not get file handle flags");
+        goto error;
+    }
+    flags |= FD_CLOEXEC;
+    if ( fcntl(fd, F_SETFD, flags) < 0 )
+    {
+        PERROR("Could not set file handle flags");
+        goto error;
+    }
+
     return fd;
+
+ error:
+    saved_errno = errno;
+    close(fd);
+    errno = saved_errno;
+    return -1;
 }
 
 int xc_interface_close(int xc_handle)
diff -r 91169603a8e8 -r 79afceca9065 tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libxc/xc_linux_build.c      Wed Aug 23 11:11:27 2006 -0600
@@ -16,15 +16,11 @@
 /* Handy for printing out '0' prepended values at native pointer size */
 #define _p(a) ((void *) ((ulong)a))
 
-#if defined(__i386__)
 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
 #define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
+#if defined(__i386__)
 #define L3_PROT (_PAGE_PRESENT)
-#endif
-
-#if defined(__x86_64__)
-#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
-#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
+#elif defined(__x86_64__)
 #define L3_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
 #define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
 #endif
@@ -569,8 +565,8 @@ static int setup_guest(int xc_handle,
     start_info->flags        = flags;
     start_info->store_mfn    = nr_pages - 2;
     start_info->store_evtchn = store_evtchn;
-    start_info->console_mfn   = nr_pages - 1;
-    start_info->console_evtchn = console_evtchn;
+    start_info->console.domU.mfn   = nr_pages - 1;
+    start_info->console.domU.evtchn = console_evtchn;
     start_info->nr_pages       = nr_pages; // FIXME?: nr_pages - 2 ????
 
     bp = (struct xen_ia64_boot_param *)(start_info + 1);
@@ -593,7 +589,7 @@ static int setup_guest(int xc_handle,
         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, shared_info_frame);
     printf("shared_info = %p, err=%s frame=%lx\n",
            shared_info, strerror (errno), shared_info_frame);
-    //memset(shared_info, 0, sizeof(shared_info_t));
+    //memset(shared_info, 0, PAGE_SIZE);
     /* Mask all upcalls... */
     for ( i = 0; i < MAX_VIRT_CPUS; i++ )
         shared_info->vcpu_info[i].evtchn_upcall_mask = 1;
@@ -972,7 +968,7 @@ static int setup_guest(int xc_handle,
         /* Enable shadow translate mode */
         if ( xc_shadow_control(xc_handle, dom,
                                DOM0_SHADOW_CONTROL_OP_ENABLE_TRANSLATE,
-                               NULL, 0, NULL) < 0 )
+                               NULL, 0, NULL, 0, NULL) < 0 )
         {
             PERROR("Could not enable translation mode");
             goto error_out;
@@ -1047,8 +1043,8 @@ static int setup_guest(int xc_handle,
     start_info->mfn_list     = vphysmap_start;
     start_info->store_mfn    = guest_store_mfn;
     start_info->store_evtchn = store_evtchn;
-    start_info->console_mfn   = guest_console_mfn;
-    start_info->console_evtchn = console_evtchn;
+    start_info->console.domU.mfn   = guest_console_mfn;
+    start_info->console.domU.evtchn = console_evtchn;
     if ( initrd->len != 0 )
     {
         start_info->mod_start    = vinitrd_start;
@@ -1064,7 +1060,7 @@ static int setup_guest(int xc_handle,
     /* shared_info page starts its life empty. */
     shared_info = xc_map_foreign_range(
         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, shared_info_frame);
-    memset(shared_info, 0, sizeof(shared_info_t));
+    memset(shared_info, 0, PAGE_SIZE);
     /* Mask all upcalls... */
     for ( i = 0; i < MAX_VIRT_CPUS; i++ )
         shared_info->vcpu_info[i].evtchn_upcall_mask = 1;
diff -r 91169603a8e8 -r 79afceca9065 tools/libxc/xc_linux_restore.c
--- a/tools/libxc/xc_linux_restore.c    Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libxc/xc_linux_restore.c    Wed Aug 23 11:11:27 2006 -0600
@@ -690,8 +690,9 @@ int xc_linux_restore(int xc_handle, int 
     start_info->flags       = 0;
     *store_mfn = start_info->store_mfn       = p2m[start_info->store_mfn];
     start_info->store_evtchn                 = store_evtchn;
-    *console_mfn = start_info->console_mfn   = p2m[start_info->console_mfn];
-    start_info->console_evtchn               = console_evtchn;
+    start_info->console.domU.mfn    = p2m[start_info->console.domU.mfn];
+    start_info->console.domU.evtchn = console_evtchn;
+    *console_mfn                    = start_info->console.domU.mfn;
     munmap(start_info, PAGE_SIZE);
 
     /* Uncanonicalise each GDT frame number. */
@@ -737,7 +738,7 @@ int xc_linux_restore(int xc_handle, int 
     /* Copy saved contents of shared-info page. No checking needed. */
     page = xc_map_foreign_range(
         xc_handle, dom, PAGE_SIZE, PROT_WRITE, shared_info_frame);
-    memcpy(page, shared_info, sizeof(shared_info_t));
+    memcpy(page, shared_info, PAGE_SIZE);
     munmap(page, PAGE_SIZE);
 
     /* Uncanonicalise the pfn-to-mfn table frame-number list. */
diff -r 91169603a8e8 -r 79afceca9065 tools/libxc/xc_linux_save.c
--- a/tools/libxc/xc_linux_save.c       Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libxc/xc_linux_save.c       Wed Aug 23 11:11:27 2006 -0600
@@ -338,19 +338,17 @@ static int analysis_phase(int xc_handle,
         int i;
 
         xc_shadow_control(xc_handle, domid, DOM0_SHADOW_CONTROL_OP_CLEAN,
-                          arr, max_pfn, NULL);
+                          arr, max_pfn, NULL, 0, NULL);
         DPRINTF("#Flush\n");
         for ( i = 0; i < 40; i++ ) {
             usleep(50000);
             now = llgettimeofday();
             xc_shadow_control(xc_handle, domid, DOM0_SHADOW_CONTROL_OP_PEEK,
-                              NULL, 0, &stats);
-
-            DPRINTF("now= %lld faults= %" PRId32 " dirty= %" PRId32
-                    " dirty_net= %" PRId32 " dirty_block= %" PRId32"\n",
+                              NULL, 0, NULL, 0, &stats);
+
+            DPRINTF("now= %lld faults= %"PRId32" dirty= %"PRId32"\n",
                     ((now-start)+500)/1000,
-                    stats.fault_count, stats.dirty_count,
-                    stats.dirty_net_count, stats.dirty_block_count);
+                    stats.fault_count, stats.dirty_count);
         }
     }
 
@@ -727,7 +725,7 @@ int xc_linux_save(int xc_handle, int io_
 
         if (xc_shadow_control(xc_handle, dom,
                               DOM0_SHADOW_CONTROL_OP_ENABLE_LOGDIRTY,
-                              NULL, 0, NULL ) < 0) {
+                              NULL, 0, NULL, 0, NULL) < 0) {
             ERR("Couldn't enable shadow mode");
             goto out;
         }
@@ -879,7 +877,7 @@ int xc_linux_save(int xc_handle, int io_
                but this is fast enough for the moment. */
             if (!last_iter && xc_shadow_control(
                     xc_handle, dom, DOM0_SHADOW_CONTROL_OP_PEEK,
-                    to_skip, max_pfn, NULL) != max_pfn) {
+                    to_skip, max_pfn, NULL, 0, NULL) != max_pfn) {
                 ERR("Error peeking shadow bitmap");
                 goto out;
             }
@@ -1084,8 +1082,9 @@ int xc_linux_save(int xc_handle, int io_
                         (unsigned long)ctxt.user_regs.edx);
             }
 
-            if (xc_shadow_control(xc_handle, dom, DOM0_SHADOW_CONTROL_OP_CLEAN,
-                                  to_send, max_pfn, &stats ) != max_pfn) {
+            if (xc_shadow_control(xc_handle, dom, 
+                                  DOM0_SHADOW_CONTROL_OP_CLEAN, to_send, 
+                                  max_pfn, NULL, 0, &stats) != max_pfn) {
                 ERR("Error flushing shadow PT");
                 goto out;
             }
@@ -1174,8 +1173,9 @@ int xc_linux_save(int xc_handle, int io_
  out:
 
     if (live) {
-        if(xc_shadow_control(xc_handle, dom, DOM0_SHADOW_CONTROL_OP_OFF,
-                             NULL, 0, NULL ) < 0) {
+        if(xc_shadow_control(xc_handle, dom, 
+                             DOM0_SHADOW_CONTROL_OP_OFF,
+                             NULL, 0, NULL, 0, NULL) < 0) {
             DPRINTF("Warning - couldn't disable shadow mode");
         }
     }
diff -r 91169603a8e8 -r 79afceca9065 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h     Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/libxc/xenctrl.h     Wed Aug 23 11:11:27 2006 -0600
@@ -323,6 +323,8 @@ int xc_shadow_control(int xc_handle,
                       unsigned int sop,
                       unsigned long *dirty_bitmap,
                       unsigned long pages,
+                      unsigned long *mb,
+                      uint32_t mode,
                       xc_shadow_control_stats_t *stats);
 
 int xc_bvtsched_global_set(int xc_handle,
@@ -367,8 +369,6 @@ int xc_sched_credit_domain_get(int xc_ha
                                uint32_t domid,
                                struct sched_credit_adjdom *sdom);
 
-typedef evtchn_status_t xc_evtchn_status_t;
-
 /*
  * EVENT CHANNEL FUNCTIONS
  */
@@ -386,11 +386,6 @@ int xc_evtchn_alloc_unbound(int xc_handl
 int xc_evtchn_alloc_unbound(int xc_handle,
                             uint32_t dom,
                             uint32_t remote_dom);
-
-int xc_evtchn_status(int xc_handle,
-                     uint32_t dom, /* may be DOMID_SELF */
-                     evtchn_port_t port,
-                     xc_evtchn_status_t *status);
 
 int xc_physdev_pci_access_modify(int xc_handle,
                                  uint32_t domid,
diff -r 91169603a8e8 -r 79afceca9065 tools/misc/xc_shadow.c
--- a/tools/misc/xc_shadow.c    Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/misc/xc_shadow.c    Wed Aug 23 11:11:27 2006 -0600
@@ -60,6 +60,8 @@ int main(int argc, char *argv[])
                            mode, 
                            NULL,
                            0,
+                           NULL,
+                           0,
                            NULL) < 0 )
     {    
         fprintf(stderr, "Error reseting performance counters: %d (%s)\n",
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/lowlevel/xc/xc.c Wed Aug 23 11:11:27 2006 -0600
@@ -165,8 +165,8 @@ static PyObject *pyxc_vcpu_setaffinity(X
 }
 
 static PyObject *pyxc_domain_setcpuweight(XcObject *self,
-                                         PyObject *args,
-                                         PyObject *kwds)
+                                          PyObject *args,
+                                          PyObject *kwds)
 {
     uint32_t dom;
     float cpuweight = 1;
@@ -334,29 +334,29 @@ static PyObject *pyxc_linux_build(XcObje
 
     static char *kwd_list[] = { "dom", "store_evtchn",
                                 "console_evtchn", "image",
-                               /* optional */
-                               "ramdisk", "cmdline", "flags",
-                               "features", NULL };
+                                /* optional */
+                                "ramdisk", "cmdline", "flags",
+                                "features", NULL };
 
     if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|ssis", kwd_list,
                                       &dom, &store_evtchn,
-                                     &console_evtchn, &image,
-                                     /* optional */
-                                     &ramdisk, &cmdline, &flags,
-                                     &features) )
+                                      &console_evtchn, &image,
+                                      /* optional */
+                                      &ramdisk, &cmdline, &flags,
+                                      &features) )
         return NULL;
 
     if ( xc_linux_build(self->xc_handle, dom, image,
                         ramdisk, cmdline, features, flags,
                         store_evtchn, &store_mfn,
-                       console_evtchn, &console_mfn) != 0 ) {
+                        console_evtchn, &console_mfn) != 0 ) {
         if (!errno)
              errno = EINVAL;
         return PyErr_SetFromErrno(xc_error);
     }
     return Py_BuildValue("{s:i,s:i}", 
-                        "store_mfn", store_mfn,
-                        "console_mfn", console_mfn);
+                         "store_mfn", store_mfn,
+                         "console_mfn", console_mfn);
 }
 
 static PyObject *pyxc_hvm_build(XcObject *self,
@@ -373,16 +373,16 @@ static PyObject *pyxc_hvm_build(XcObject
     int apic = 0;
     unsigned long store_mfn = 0;
 
-    static char *kwd_list[] = { "dom", "store_evtchn",
-                               "memsize", "image", "vcpus", "pae", "acpi", 
"apic",
-                               NULL };
+    static char *kwd_list[] = { "dom", "store_evtchn", "memsize", "image",
+                                "vcpus", "pae", "acpi", "apic",
+                                NULL };
     if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiisiiii", kwd_list,
                                       &dom, &store_evtchn, &memsize,
                                       &image, &vcpus, &pae, &acpi, &apic) )
         return NULL;
 
     if ( xc_hvm_build(self->xc_handle, dom, memsize, image,
-                     vcpus, pae, acpi, apic, store_evtchn, &store_mfn) != 0 )
+                      vcpus, pae, acpi, apic, store_evtchn, &store_mfn) != 0 )
         return PyErr_SetFromErrno(xc_error);
 
     return Py_BuildValue("{s:i}", "store_mfn", store_mfn);
@@ -484,60 +484,6 @@ static PyObject *pyxc_evtchn_alloc_unbou
     return PyInt_FromLong(port);
 }
 
-static PyObject *pyxc_evtchn_status(XcObject *self,
-                                    PyObject *args,
-                                    PyObject *kwds)
-{
-    PyObject *dict;
-
-    uint32_t dom = DOMID_SELF;
-    int port, ret;
-    xc_evtchn_status_t status;
-
-    static char *kwd_list[] = { "port", "dom", NULL };
-
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list, 
-                                      &port, &dom) )
-        return NULL;
-
-    ret = xc_evtchn_status(self->xc_handle, dom, port, &status);
-    if ( ret != 0 )
-        return PyErr_SetFromErrno(xc_error);
-
-    switch ( status.status )
-    {
-    case EVTCHNSTAT_closed:
-        dict = Py_BuildValue("{s:s}", 
-                             "status", "closed");
-        break;
-    case EVTCHNSTAT_unbound:
-        dict = Py_BuildValue("{s:s}", 
-                             "status", "unbound");
-        break;
-    case EVTCHNSTAT_interdomain:
-        dict = Py_BuildValue("{s:s,s:i,s:i}", 
-                             "status", "interdomain",
-                             "dom", status.u.interdomain.dom,
-                             "port", status.u.interdomain.port);
-        break;
-    case EVTCHNSTAT_pirq:
-        dict = Py_BuildValue("{s:s,s:i}", 
-                             "status", "pirq",
-                             "irq", status.u.pirq);
-        break;
-    case EVTCHNSTAT_virq:
-        dict = Py_BuildValue("{s:s,s:i}", 
-                             "status", "virq",
-                             "irq", status.u.virq);
-        break;
-    default:
-        dict = Py_BuildValue("{}");
-        break;
-    }
-    
-    return dict;
-}
-
 static PyObject *pyxc_physdev_pci_access_modify(XcObject *self,
                                                 PyObject *args,
                                                 PyObject *kwds)
@@ -613,7 +559,7 @@ static PyObject *pyxc_physinfo(XcObject 
     {
         p+=sprintf(p,"%08x:",info.hw_cap[i]);
         if(info.hw_cap[i])
-           q=p;
+            q=p;
     }
     if(q>cpu_cap)
         *(q-1)=0;
@@ -718,9 +664,62 @@ static PyObject *pyxc_sedf_domain_get(Xc
                          "domain",    domid,
                          "period",    period,
                          "slice",     slice,
-                        "latency",   latency,
-                        "extratime", extratime,
+                         "latency",   latency,
+                         "extratime", extratime,
                          "weight",    weight);
+}
+
+static PyObject *pyxc_shadow_control(PyObject *self,
+                                     PyObject *args,
+                                     PyObject *kwds)
+{
+    XcObject *xc = (XcObject *)self;
+
+    uint32_t dom;
+    int op=0;
+
+    static char *kwd_list[] = { "dom", "op", NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list, 
+                                      &dom, &op) )
+        return NULL;
+    
+    if ( xc_shadow_control(xc->xc_handle, dom, op, NULL, 0, NULL, 0, NULL) 
+         < 0 )
+        return PyErr_SetFromErrno(xc_error);
+    
+    Py_INCREF(zero);
+    return zero;
+}
+
+static PyObject *pyxc_shadow_mem_control(PyObject *self,
+                                         PyObject *args,
+                                         PyObject *kwds)
+{
+    XcObject *xc = (XcObject *)self;
+    int op;
+    uint32_t dom;
+    int mbarg = -1;
+    unsigned long mb;
+
+    static char *kwd_list[] = { "dom", "mb", NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list, 
+                                      &dom, &mbarg) )
+        return NULL;
+    
+    if ( mbarg < 0 ) 
+        op = DOM0_SHADOW_CONTROL_OP_GET_ALLOCATION;
+    else 
+    {
+        mb = mbarg;
+        op = DOM0_SHADOW_CONTROL_OP_SET_ALLOCATION;
+    }
+    if ( xc_shadow_control(xc->xc_handle, dom, op, NULL, 0, &mb, 0, NULL) < 0 )
+        return PyErr_SetFromErrno(xc_error);
+    
+    mbarg = mb;
+    return Py_BuildValue("i", mbarg);
 }
 
 static PyObject *pyxc_sched_credit_domain_set(XcObject *self,
@@ -782,8 +781,8 @@ static PyObject *pyxc_domain_setmaxmem(X
 }
 
 static PyObject *pyxc_domain_memory_increase_reservation(XcObject *self,
-                                                        PyObject *args,
-                                                        PyObject *kwds)
+                                                         PyObject *args,
+                                                         PyObject *kwds)
 {
     uint32_t dom;
     unsigned long mem_kb;
@@ -800,8 +799,8 @@ static PyObject *pyxc_domain_memory_incr
        know what they are doing */
     nr_extents = (mem_kb / (XC_PAGE_SIZE/1024)) >> extent_order;
     if ( xc_domain_memory_increase_reservation(self->xc_handle, dom, 
-                                              nr_extents, extent_order, 
-                                              address_bits, NULL) )
+                                               nr_extents, extent_order, 
+                                               address_bits, NULL) )
         return PyErr_SetFromErrno(xc_error);
     
     Py_INCREF(zero);
@@ -1141,21 +1140,6 @@ static PyMethodDef pyxc_methods[] = {
       " remote_dom [int]: Remote domain to accept connections from.\n\n"
       "Returns: [int] Unbound event-channel port.\n" },
 
-    { "evtchn_status", 
-      (PyCFunction)pyxc_evtchn_status, 
-      METH_VARARGS | METH_KEYWORDS, "\n"
-      "Query the status of an event channel.\n"
-      " dom  [int, SELF]: Dom-id of one endpoint of the channel.\n"
-      " port [int]:       Port-id of one endpoint of the channel.\n\n"
-      "Returns: [dict] dictionary is empty on failure.\n"
-      " status [str]:  'closed', 'unbound', 'interdomain', 'pirq',"
-      " or 'virq'.\n"
-      "The following are returned if 'status' is 'interdomain':\n"
-      " dom  [int]: Dom-id of remote endpoint.\n"
-      " port [int]: Port-id of remote endpoint.\n"
-      "The following are returned if 'status' is 'pirq' or 'virq':\n"
-      " irq  [int]: IRQ number.\n" },
-
     { "physdev_pci_access_modify",
       (PyCFunction)pyxc_physdev_pci_access_modify,
       METH_VARARGS | METH_KEYWORDS, "\n"
@@ -1187,6 +1171,22 @@ static PyMethodDef pyxc_methods[] = {
       "Get information about the Xen host\n"
       "Returns [dict]: information about Xen"
       "        [None]: on failure.\n" },
+
+    { "shadow_control", 
+      (PyCFunction)pyxc_shadow_control, 
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Set parameter for shadow pagetable interface\n"
+      " dom [int]:   Identifier of domain.\n"
+      " op [int, 0]: operation\n\n"
+      "Returns: [int] 0 on success; -1 on error.\n" },
+
+    { "shadow_mem_control", 
+      (PyCFunction)pyxc_shadow_mem_control, 
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Set or read shadow pagetable memory use\n"
+      " dom [int]:   Identifier of domain.\n"
+      " mb [int, -1]: MB of shadow memory this domain should have.\n\n"
+      "Returns: [int] MB of shadow memory in use by this domain.\n" },
 
     { "domain_setmaxmem", 
       (PyCFunction)pyxc_domain_setmaxmem, 
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/util/xmlrpclib2.py
--- a/tools/python/xen/util/xmlrpclib2.py       Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/util/xmlrpclib2.py       Wed Aug 23 11:11:27 2006 -0600
@@ -22,6 +22,7 @@ An enhanced XML-RPC client/server interf
 
 import string
 import types
+import fcntl
 
 from httplib import HTTPConnection, HTTP
 from xmlrpclib import Transport
@@ -136,6 +137,17 @@ class TCPXMLRPCServer(SocketServer.Threa
                  logRequests=1):
         SimpleXMLRPCServer.__init__(self, addr, requestHandler, logRequests)
 
+        flags = fcntl.fcntl(self.fileno(), fcntl.F_GETFD)
+        flags |= fcntl.FD_CLOEXEC
+        fcntl.fcntl(self.fileno(), fcntl.F_SETFD, flags)
+
+    def get_request(self):
+        (client, addr) = SimpleXMLRPCServer.get_request(self)
+        flags = fcntl.fcntl(client.fileno(), fcntl.F_GETFD)
+        flags |= fcntl.FD_CLOEXEC
+        fcntl.fcntl(client.fileno(), fcntl.F_SETFD, flags)
+        return (client, addr)
+                                                                               
 
     def _marshaled_dispatch(self, data, dispatch_method = None):
         params, method = xmlrpclib.loads(data)
         if False:
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/web/httpserver.py
--- a/tools/python/xen/web/httpserver.py        Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/web/httpserver.py        Wed Aug 23 11:11:27 2006 -0600
@@ -24,6 +24,7 @@ from urllib import quote, unquote
 from urllib import quote, unquote
 import os
 import os.path
+import fcntl
 
 from xen.xend import sxp
 from xen.xend.Args import ArgError
@@ -294,6 +295,9 @@ class HttpServer:
 
     def bind(self):
         self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        flags = fcntl.fcntl(self.socket.fileno(), fcntl.F_GETFD)
+        flags |= fcntl.FD_CLOEXEC
+        fcntl.fcntl(self.socket.fileno(), fcntl.F_SETFD, flags)
         self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         self.socket.bind((self.interface, self.port))
 
@@ -338,3 +342,6 @@ class UnixHttpServer(HttpServer):
         
     def bind(self):
         self.socket = unix.bind(self.path)
+        flags = fcntl.fcntl(self.socket.fileno(), fcntl.F_GETFD)
+        flags |= fcntl.FD_CLOEXEC
+        fcntl.fcntl(self.socket.fileno(), fcntl.F_SETFD, flags)
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/xend/XendCheckpoint.py
--- a/tools/python/xen/xend/XendCheckpoint.py   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/xend/XendCheckpoint.py   Wed Aug 23 11:11:27 2006 -0600
@@ -78,7 +78,7 @@ def save(fd, dominfo, network, live, dst
         # enabled. Passing "0" simply uses the defaults compiled into
         # libxenguest; see the comments and/or code in xc_linux_save() for
         # more information.
-        cmd = [xen.util.auxbin.pathTo(XC_SAVE), str(xc.handle()), str(fd),
+        cmd = [xen.util.auxbin.pathTo(XC_SAVE), str(fd),
                str(dominfo.getDomid()), "0", "0", str(int(live)) ]
         log.debug("[xc_save]: %s", string.join(cmd))
 
@@ -150,7 +150,7 @@ def restore(xd, fd):
         balloon.free(xc.pages_to_kib(nr_pfns))
 
         cmd = map(str, [xen.util.auxbin.pathTo(XC_RESTORE),
-                        xc.handle(), fd, dominfo.getDomid(), nr_pfns,
+                        fd, dominfo.getDomid(), nr_pfns,
                         store_port, console_port])
         log.debug("[xc_restore]: %s", string.join(cmd))
 
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/xend/XendDomain.py       Wed Aug 23 11:11:27 2006 -0600
@@ -532,6 +532,30 @@ class XendDomain:
         except Exception, ex:
             raise XendError(str(ex))
 
+    def domain_shadow_control(self, domid, op):
+        """Shadow page control."""
+        dominfo = self.domain_lookup(domid)
+        try:
+            return xc.shadow_control(dominfo.getDomid(), op)
+        except Exception, ex:
+            raise XendError(str(ex))
+
+    def domain_shadow_mem_get(self, domid):
+        """Get shadow pagetable memory allocation."""
+        dominfo = self.domain_lookup(domid)
+        try:
+            return xc.shadow_mem_control(dominfo.getDomid())
+        except Exception, ex:
+            raise XendError(str(ex))
+
+    def domain_shadow_mem_set(self, domid, mb):
+        """Set shadow pagetable memory allocation."""
+        dominfo = self.domain_lookup(domid)
+        try:
+            return xc.shadow_mem_control(dominfo.getDomid(), mb=mb)
+        except Exception, ex:
+            raise XendError(str(ex))
+
     def domain_sched_credit_get(self, domid):
         """Get credit scheduler parameters for a domain.
         """
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/xend/XendDomainInfo.py   Wed Aug 23 11:11:27 2006 -0600
@@ -30,6 +30,7 @@ import time
 import time
 import threading
 import os
+import math
 
 import xen.lowlevel.xc
 from xen.util import asserts
@@ -126,16 +127,17 @@ VM_CONFIG_PARAMS = [
 # don't come out of xc in the same form as they are specified in the config
 # file, so those are handled separately.
 ROUNDTRIPPING_CONFIG_ENTRIES = [
-    ('uuid',       str),
-    ('vcpus',      int),
-    ('vcpu_avail', int),
-    ('cpu_weight', float),
-    ('memory',     int),
-    ('maxmem',     int),
-    ('bootloader', str),
+    ('uuid',            str),
+    ('vcpus',           int),
+    ('vcpu_avail',      int),
+    ('cpu_weight',      float),
+    ('memory',          int),
+    ('shadow_memory',   int),
+    ('maxmem',          int),
+    ('bootloader',      str),
     ('bootloader_args', str),
-    ('features', str),
-    ('localtime', int),
+    ('features',        str),
+    ('localtime',       int),
     ]
 
 ROUNDTRIPPING_CONFIG_ENTRIES += VM_CONFIG_PARAMS
@@ -146,12 +148,13 @@ ROUNDTRIPPING_CONFIG_ENTRIES += VM_CONFI
 # entries written to the store that cannot be reconfigured on-the-fly.
 #
 VM_STORE_ENTRIES = [
-    ('uuid',       str),
-    ('vcpus',      int),
-    ('vcpu_avail', int),
-    ('memory',     int),
-    ('maxmem',     int),
-    ('start_time', float),
+    ('uuid',          str),
+    ('vcpus',         int),
+    ('vcpu_avail',    int),
+    ('memory',        int),
+    ('shadow_memory', int),
+    ('maxmem',        int),
+    ('start_time',    float),
     ]
 
 VM_STORE_ENTRIES += VM_CONFIG_PARAMS
@@ -572,6 +575,7 @@ class XendDomainInfo:
             defaultInfo('vcpu_avail',   lambda: (1 << self.info['vcpus']) - 1)
 
             defaultInfo('memory',       lambda: 0)
+            defaultInfo('shadow_memory', lambda: 0)
             defaultInfo('maxmem',       lambda: 0)
             defaultInfo('bootloader',   lambda: None)
             defaultInfo('bootloader_args', lambda: None)            
@@ -1272,18 +1276,26 @@ class XendDomainInfo:
             # repin domain vcpus if a restricted cpus list is provided
             # this is done prior to memory allocation to aide in memory
             # distribution for NUMA systems.
-            cpus = self.info['cpus']
-            if cpus is not None and len(cpus) > 0:
+            if self.info['cpus'] is not None and len(self.info['cpus']) > 0:
                 for v in range(0, self.info['max_vcpu_id']+1):
-                    # pincpu takes a list of ints
-                    cpu = [ int( cpus[v % len(cpus)] ) ]
-                    xc.vcpu_setaffinity(self.domid, v, cpu)
+                    xc.vcpu_setaffinity(self.domid, v, self.info['cpus'])
 
             # set domain maxmem in KiB
             xc.domain_setmaxmem(self.domid, self.info['maxmem'] * 1024)
 
             m = self.image.getDomainMemory(self.info['memory'] * 1024)
-            balloon.free(m)
+
+            # get the domain's shadow memory requirement
+            sm = int(math.ceil(self.image.getDomainShadowMemory(m) / 1024.0))
+            if self.info['shadow_memory'] > sm:
+                sm = self.info['shadow_memory']
+
+            # Make sure there's enough RAM available for the domain
+            balloon.free(m + sm * 1024)
+
+            # Set up the shadow memory
+            sm = xc.shadow_mem_control(self.domid, mb=sm)
+            self.info['shadow_memory'] = sm
 
             init_reservation = self.info['memory'] * 1024
             if os.uname()[4] in ('ia64', 'ppc64'):
@@ -1530,13 +1542,12 @@ class XendDomainInfo:
         return self.getDeviceController(dev_type).sxpr(devid)
 
 
-    def device_configure(self, dev_config, devid):
+    def device_configure(self, dev_config):
         """Configure an existing device.
         @param dev_config: device configuration
-        @param devid:      device id
         """
         deviceClass = sxp.name(dev_config)
-        self.reconfigureDevice(deviceClass, devid, dev_config)
+        self.reconfigureDevice(deviceClass, None, dev_config)
 
 
     def pause(self):
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/xend/XendLogging.py
--- a/tools/python/xen/xend/XendLogging.py      Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/xend/XendLogging.py      Wed Aug 23 11:11:27 2006 -0600
@@ -21,6 +21,7 @@ import types
 import types
 import logging
 import logging.handlers
+import fcntl
 
 from xen.xend.server import params
 
@@ -49,6 +50,27 @@ DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
 
 logfilename = None
 
+class XendRotatingFileHandler(logging.handlers.RotatingFileHandler):
+
+    def __init__(self, fname, mode, maxBytes, backupCount):
+        logging.handlers.RotatingFileHandler.__init__(self, fname, mode, 
maxBytes, backupCount)
+        self.setCloseOnExec()
+
+    def doRollover(self):
+        logging.handlers.RotatingFileHandler.doRollover(self)
+        self.setCloseOnExec()
+
+    # NB yes accessing 'self.stream' violates OO encapsulation somewhat,
+    # but python logging API gives no other way to access the file handle
+    # and the entire python logging stack is already full of OO encapsulation
+    # violations. The other alternative is copy-and-paste duplicating the
+    # entire FileHandler, StreamHandler & RotatingFileHandler classes which
+    # is even worse
+    def setCloseOnExec(self):
+        flags = fcntl.fcntl(self.stream.fileno(), fcntl.F_GETFD)
+        flags |= fcntl.FD_CLOEXEC
+        fcntl.fcntl(self.stream.fileno(), fcntl.F_SETFD, flags)
+        
 
 def init(filename, level):
     """Initialise logging.  Logs to the given filename, and logs to stderr if
@@ -58,9 +80,9 @@ def init(filename, level):
     global logfilename
 
     def openFileHandler(fname):
-        return logging.handlers.RotatingFileHandler(fname, mode = 'a',
-                                                    maxBytes = MAX_BYTES,
-                                                    backupCount = BACKUP_COUNT)
+        return XendRotatingFileHandler(fname, mode = 'a',
+                                       maxBytes = MAX_BYTES,
+                                       backupCount = BACKUP_COUNT)
 
     # Rather unintuitively, getLevelName will get the number corresponding to
     # a level name, as well as getting the name corresponding to a level
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/xend/XendNode.py Wed Aug 23 11:11:27 2006 -0600
@@ -46,7 +46,8 @@ class XendNode:
         return self.xc.bvtsched_global_get()
     
     def info(self):
-        return self.nodeinfo() + self.physinfo() + self.xeninfo()
+        return (self.nodeinfo() + self.physinfo() + self.xeninfo() +
+                self.xendinfo())
 
     def nodeinfo(self):
         (sys, host, rel, ver, mch) = os.uname()
@@ -100,6 +101,9 @@ class XendNode:
 
         return [[k, info[k]] for k in ITEM_ORDER]
 
+    def xendinfo(self):
+        return [['xend_config_format',  2]]
+
 
 def instance():
     global inst
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py    Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/xend/image.py    Wed Aug 23 11:11:27 2006 -0600
@@ -153,6 +153,12 @@ class ImageHandler:
                 mem_kb += 4*1024;
         return mem_kb
 
+    def getDomainShadowMemory(self, mem_kb):
+        """@return The minimum shadow memory required, in KiB, for a domain 
+        with mem_kb KiB of RAM."""
+        # PV domains don't need any shadow memory
+        return 0
+
     def buildDomain(self):
         """Build the domain. Define in subclass."""
         raise NotImplementedError()
@@ -251,7 +257,7 @@ class HVMImageHandler(ImageHandler):
     def parseDeviceModelArgs(self, imageConfig, deviceConfig):
         dmargs = [ 'boot', 'fda', 'fdb', 'soundhw',
                    'localtime', 'serial', 'stdvga', 'isa', 'vcpus',
-                  'acpi', 'usb', 'usbdevice']
+                   'acpi', 'usb', 'usbdevice']
         ret = []
         for a in dmargs:
             v = sxp.child_value(imageConfig, a)
@@ -305,9 +311,6 @@ class HVMImageHandler(ImageHandler):
     def configVNC(self, config):
         # Handle graphics library related options
         vnc = sxp.child_value(config, 'vnc')
-        vncdisplay = sxp.child_value(config, 'vncdisplay',
-                                     int(self.vm.getDomid()))
-        vncunused = sxp.child_value(config, 'vncunused')
         sdl = sxp.child_value(config, 'sdl')
         ret = []
         nographic = sxp.child_value(config, 'nographic')
@@ -315,9 +318,12 @@ class HVMImageHandler(ImageHandler):
             ret.append('-nographic')
             return ret
         if vnc:
+            vncdisplay = sxp.child_value(config, 'vncdisplay',
+                                         int(self.vm.getDomid()))
             ret = ret + ['-vnc', '%d' % vncdisplay, '-k', 'en-us']
-        if vncunused:
-            ret += ['-vncunused']
+            vncunused = sxp.child_value(config, 'vncunused')
+            if vncunused:
+                ret += ['-vncunused']
         return ret
 
     def createDeviceModel(self):
@@ -364,6 +370,17 @@ class HVMImageHandler(ImageHandler):
             extra_pages = int( math.ceil( extra_mb*1024 / page_kb ))
         return mem_kb + extra_pages * page_kb
 
+    def getDomainShadowMemory(self, mem_kb):
+        """@return The minimum shadow memory required, in KiB, for a domain 
+        with mem_kb KiB of RAM."""
+        if os.uname()[4] in ('ia64', 'ppc64'):
+            # Explicit shadow memory is not a concept 
+            return 0
+        else:
+            # 1MB per vcpu plus 4Kib/Mib of RAM.  This is higher than 
+            # the minimum that Xen would allocate if no value were given.
+            return 1024 * self.vm.getVCpuCount() + mem_kb / 256
+
     def register_shutdown_watch(self):
         """ add xen store watch on control/shutdown """
         self.shutdownWatch = xswatch(self.vm.dompath + "/control/shutdown", \
diff -r 91169603a8e8 -r 79afceca9065 
tools/python/xen/xend/server/DevController.py
--- a/tools/python/xen/xend/server/DevController.py     Tue Aug 22 14:45:49 
2006 -0600
+++ b/tools/python/xen/xend/server/DevController.py     Wed Aug 23 11:11:27 
2006 -0600
@@ -206,15 +206,9 @@ class DevController:
         """
 
         devid = int(devid)
-        
-        frontpath = self.frontendPath(devid)
-        backpath = xstransact.Read(frontpath, "backend")
-
-        if backpath:
-            xstransact.Write(backpath, 'state', str(xenbusState['Closing']))
-        else:
-            raise VmError("Device %s not connected" % devid)
-           
+
+        self.writeBackend(devid, 'state', str(xenbusState['Closing']))
+
 
     def configurations(self):
         return map(self.configuration, self.deviceIDs())
@@ -355,6 +349,16 @@ class DevController:
             return map(int, xstransact.List(fe))
 
 
+    def writeBackend(self, devid, *args):
+        frontpath = self.frontendPath(devid)
+        backpath = xstransact.Read(frontpath, "backend")
+
+        if backpath:
+            xstransact.Write(backpath, *args)
+        else:
+            raise VmError("Device %s not connected" % devid)
+
+
 ## private:
 
     def addStoreEntries(self, config, devid, backDetails, frontDetails):
diff -r 91169603a8e8 -r 79afceca9065 
tools/python/xen/xend/server/XMLRPCServer.py
--- a/tools/python/xen/xend/server/XMLRPCServer.py      Tue Aug 22 14:45:49 
2006 -0600
+++ b/tools/python/xen/xend/server/XMLRPCServer.py      Wed Aug 23 11:11:27 
2006 -0600
@@ -24,6 +24,7 @@ from xen.util.xmlrpclib2 import UnixXMLR
 
 from xen.xend.XendClient import XML_RPC_SOCKET, ERROR_INVALID_DOMAIN
 from xen.xend.XendError import *
+from xen.xend.XendLogging import log
 from types import ListType
 
 def lookup(domid):
@@ -74,7 +75,8 @@ def get_log():
     finally:
         f.close()
 
-methods = ['device_create', 'destroyDevice', 'getDeviceSxprs',
+methods = ['device_create', 'device_configure', 'destroyDevice',
+           'getDeviceSxprs',
            'setMemoryTarget', 'setName', 'setVCpuCount', 'shutdown',
            'send_sysrq', 'getVCPUInfo', 'waitForDevices']
 
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/xend/server/blkif.py
--- a/tools/python/xen/xend/server/blkif.py     Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/xend/server/blkif.py     Wed Aug 23 11:11:27 2006 -0600
@@ -13,7 +13,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #============================================================================
 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@xxxxxx>
-# Copyright (C) 2005 XenSource Ltd
+# Copyright (C) 2005, 2006 XenSource Inc.
 #============================================================================
 
 
@@ -76,6 +76,23 @@ class BlkifController(DevController):
         return (devid, back, front)
 
 
+    def reconfigureDevice(self, _, config):
+        """@see DevController.reconfigureDevice"""
+        (devid, new_back, new_front) = self.getDeviceDetails(config)
+
+        (dev, mode) = self.readBackend(devid, 'dev', 'mode')
+        dev_type = self.readFrontend(devid, 'device-type')
+
+        if (dev_type == 'cdrom' and new_front['device-type'] == 'cdrom' and
+            dev == new_back['dev'] and mode == 'r'):
+            self.writeBackend(devid,
+                              'type', new_back['type'],
+                              'params', new_back['params'])
+        else:
+            raise VmError('Refusing to reconfigure device %s:%d to %s' %
+                          (self.deviceClass, devid, config))
+
+
     def configuration(self, devid):
         """@see DevController.configuration"""
 
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py     Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/xm/create.py     Wed Aug 23 11:11:27 2006 -0600
@@ -157,6 +157,10 @@ gopts.var('maxmem', val='MEMORY',
 gopts.var('maxmem', val='MEMORY',
           fn=set_int, default=None,
           use="Maximum domain memory in MB.")
+
+gopts.var('shadow_memory', val='MEMORY',
+          fn=set_int, default=0,
+          use="Domain shadow memory in MB.")
 
 gopts.var('cpu', val='CPU',
           fn=set_int, default=None,
@@ -666,8 +670,9 @@ def make_config(vals):
             if v:
                 config.append([n, v])
 
-    map(add_conf, ['name', 'memory', 'maxmem', 'restart', 'on_poweroff',
-                   'on_reboot', 'on_crash', 'vcpus', 'features'])
+    map(add_conf, ['name', 'memory', 'maxmem', 'shadow_memory',
+                   'restart', 'on_poweroff', 'on_reboot', 'on_crash',
+                   'vcpus', 'features'])
 
     if vals.uuid is not None:
         config.append(['uuid', vals.uuid])
diff -r 91169603a8e8 -r 79afceca9065 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/python/xen/xm/main.py       Wed Aug 23 11:11:27 2006 -0600
@@ -31,6 +31,7 @@ warnings.filterwarnings('ignore', catego
 warnings.filterwarnings('ignore', category=FutureWarning)
 import xmlrpclib
 import traceback
+import datetime
 
 import xen.xend.XendProtocol
 
@@ -70,6 +71,7 @@ shutdown_help ="shutdown <DomId> [-w][-a
 shutdown_help ="shutdown <DomId> [-w][-a][-R|-H] Shutdown a domain"
 top_help =     "top                              Monitor system and domains in 
real-time"
 unpause_help = "unpause <DomId>                  Unpause a paused domain"
+uptime_help  = "uptime [-s|--short] [DomId, ...] List uptime for domains"
 
 help_spacer = """
    """
@@ -111,6 +113,8 @@ block_detach_help = """block-detach  <Do
                                     or the device name as mounted in the 
guest"""
 
 block_list_help = "block-list <DomId> [--long]      List virtual block devices 
for a domain"
+block_configure_help = """block-configure <DomId> <BackDev> <FrontDev> <Mode>
+                   [BackDomId] Change block device configuration"""
 network_attach_help = """network-attach  <DomID> [script=<script>] [ip=<ip>] 
[mac=<mac>]
                            [bridge=<bridge>] [backend=<backDomID>]
                                     Create a new virtual network device """
@@ -149,6 +153,7 @@ short_command_list = [
     "shutdown",
     "top",
     "unpause",
+    "uptime",
     "vcpu-set",
     ]
 
@@ -172,6 +177,7 @@ domain_commands = [
     "sysrq",
     "top",
     "unpause",
+    "uptime",
     "vcpu-list",
     "vcpu-pin",
     "vcpu-set",
@@ -195,6 +201,7 @@ device_commands = [
     "block-attach",
     "block-detach",
     "block-list",
+    "block-configure",
     "network-attach",
     "network-detach",
     "network-list",
@@ -412,6 +419,7 @@ def parse_doms_info(info):
         'vcpus'    : get_info('online_vcpus', int,   0),
         'state'    : get_info('state',        str,   '??'),
         'cpu_time' : get_info('cpu_time',     float, 0),
+        'up_time'  : get_info('up_time',      float, -1),
         'seclabel' : security.get_security_printlabel(info),
         }
 
@@ -818,6 +826,59 @@ def xm_console(args):
     domid = int(sxp.child_value(info, 'domid', '-1'))
     console.execConsole(domid)
 
+def xm_uptime(args):
+    short_mode = 0
+
+    try:
+        (options, params) = getopt.gnu_getopt(args, 's', ['short'])
+    except getopt.GetoptError, opterr:
+        err(opterr)
+        sys.exit(1)
+
+    for (k, v) in options:
+        if k in ['-s', '--short']:
+            short_mode = 1
+
+    doms = getDomains(params)
+
+    if short_mode == 0:
+        print 'Name                              ID Uptime'
+
+    for dom in doms:
+        d = parse_doms_info(dom)
+        if d['dom'] > 0:
+            uptime = int(round(d['up_time']))
+        else:
+            f=open('/proc/uptime', 'r')
+            upfile = f.read()
+            uptime = int(round(float(upfile.split(' ')[0])))
+            f.close()
+
+        days = int(uptime / 86400)
+        uptime -= (days * 86400)
+        hours = int(uptime / 3600)
+        uptime -= (hours * 3600)
+        minutes = int(uptime / 60)
+        uptime -= (minutes * 60)
+        seconds = uptime
+            
+        upstring = ""
+        if days > 0:
+            upstring += str(days) + " day"
+            if days > 1:
+                upstring += "s"
+            upstring += ", "
+        upstring += '%(hours)2d:%(minutes)02d' % vars()
+
+        if short_mode:
+            now = datetime.datetime.now()
+            upstring = now.strftime(" %H:%M:%S") + " up " + upstring
+            upstring += ", " + d['name'] + " (" + str(d['dom']) + ")"
+        else:
+            upstring += ':%(seconds)02d' % vars()
+            upstring = ("%(name)-32s %(dom)3d " % d) + upstring
+
+        print upstring
 
 def xm_top(args):
     arg_check(args, "top", 0)
@@ -997,9 +1058,8 @@ def xm_vtpm_list(args):
                    "%(be-path)-30s  "
                    % ni)
 
-def xm_block_attach(args):
-    arg_check(args, 'block-attach', 4, 5)
-
+
+def parse_block_configuration(args):
     dom = args[0]
 
     if args[1].startswith('tap:'):
@@ -1029,7 +1089,21 @@ def xm_block_attach(args):
         traceback.print_exc(limit=1)
         sys.exit(1)
 
+    return (dom, vbd)
+
+
+def xm_block_attach(args):
+    arg_check(args, 'block-attach', 4, 5)
+
+    (dom, vbd) = parse_block_configuration(args)
     server.xend.domain.device_create(dom, vbd)
+
+
+def xm_block_configure(args):
+    arg_check(args, 'block-configure', 4, 5)
+
+    (dom, vbd) = parse_block_configuration(args)
+    server.xend.domain.device_configure(dom, vbd)
 
 
 def xm_network_attach(args):
@@ -1117,6 +1191,7 @@ commands = {
     "save": xm_save,
     "reboot": xm_reboot,
     "shutdown": xm_shutdown,
+    "uptime": xm_uptime,
     "list": xm_list,
     # memory commands
     "mem-max": xm_mem_max,
@@ -1142,6 +1217,7 @@ commands = {
     "block-attach": xm_block_attach,
     "block-detach": xm_block_detach,
     "block-list": xm_block_list,
+    "block-configure": xm_block_configure,
     # network
     "network-attach": xm_network_attach,
     "network-detach": xm_network_detach,
diff -r 91169603a8e8 -r 79afceca9065 tools/xcutils/xc_restore.c
--- a/tools/xcutils/xc_restore.c        Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/xcutils/xc_restore.c        Wed Aug 23 11:11:27 2006 -0600
@@ -12,6 +12,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#include <xenctrl.h>
 #include <xenguest.h>
 
 int
@@ -21,17 +22,20 @@ main(int argc, char **argv)
     int ret;
     unsigned long store_mfn, console_mfn;
 
-    if (argc != 7)
+    if (argc != 6)
        errx(1,
-            "usage: %s xcfd iofd domid nr_pfns store_evtchn console_evtchn",
+            "usage: %s iofd domid nr_pfns store_evtchn console_evtchn",
             argv[0]);
 
-    xc_fd = atoi(argv[1]);
-    io_fd = atoi(argv[2]);
-    domid = atoi(argv[3]);
-    nr_pfns = atoi(argv[4]);
-    store_evtchn = atoi(argv[5]);
-    console_evtchn = atoi(argv[6]);
+    xc_fd = xc_interface_open();
+    if (xc_fd < 0)
+        errx(1, "failed to open control interface");
+
+    io_fd = atoi(argv[1]);
+    domid = atoi(argv[2]);
+    nr_pfns = atoi(argv[3]);
+    store_evtchn = atoi(argv[4]);
+    console_evtchn = atoi(argv[5]);
 
     ret = xc_linux_restore(xc_fd, io_fd, domid, nr_pfns, store_evtchn,
                           &store_mfn, console_evtchn, &console_mfn);
@@ -40,5 +44,8 @@ main(int argc, char **argv)
        printf("console-mfn %li\n", console_mfn);
        fflush(stdout);
     }
+
+    xc_interface_close(xc_fd);
+
     return ret;
 }
diff -r 91169603a8e8 -r 79afceca9065 tools/xcutils/xc_save.c
--- a/tools/xcutils/xc_save.c   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/xcutils/xc_save.c   Wed Aug 23 11:11:27 2006 -0600
@@ -13,8 +13,8 @@
 #include <string.h>
 #include <stdio.h>
 
+#include <xenctrl.h>
 #include <xenguest.h>
-
 
 /**
  * Issue a suspend request through stdout, and receive the acknowledgement
@@ -36,16 +36,24 @@ main(int argc, char **argv)
 main(int argc, char **argv)
 {
     unsigned int xc_fd, io_fd, domid, maxit, max_f, flags; 
+    int ret;
 
-    if (argc != 7)
-       errx(1, "usage: %s xcfd iofd domid maxit maxf flags", argv[0]);
+    if (argc != 6)
+       errx(1, "usage: %s iofd domid maxit maxf flags", argv[0]);
 
-    xc_fd = atoi(argv[1]);
-    io_fd = atoi(argv[2]);
-    domid = atoi(argv[3]);
-    maxit = atoi(argv[4]);
-    max_f = atoi(argv[5]);
-    flags = atoi(argv[6]);
+    xc_fd = xc_interface_open();
+    if (xc_fd < 0)
+        errx(1, "failed to open control interface");
 
-    return xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags, &suspend);
+    io_fd = atoi(argv[1]);
+    domid = atoi(argv[2]);
+    maxit = atoi(argv[3]);
+    max_f = atoi(argv[4]);
+    flags = atoi(argv[5]);
+
+    ret = xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags, &suspend);
+
+    xc_interface_close(xc_fd);
+
+    return ret;
 }
diff -r 91169603a8e8 -r 79afceca9065 tools/xenmon/Makefile
--- a/tools/xenmon/Makefile     Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/xenmon/Makefile     Wed Aug 23 11:11:27 2006 -0600
@@ -25,7 +25,7 @@ CFLAGS  += -I $(XEN_LIBXC)
 CFLAGS  += -I $(XEN_LIBXC)
 LDFLAGS += -L $(XEN_LIBXC)
 
-BIN = setmask xenbaked
+BIN = xentrace_setmask xenbaked
 SCRIPTS = xenmon.py
 
 .PHONY: all
@@ -35,10 +35,10 @@ build: $(BIN)
 build: $(BIN)
 
 .PHONY: install
-install: xenbaked setmask
+install: build
        [ -d $(DESTDIR)$(sbindir) ] || $(INSTALL_DIR) $(DESTDIR)$(sbindir)
        $(INSTALL_PROG) xenbaked $(DESTDIR)$(sbindir)/xenbaked
-       $(INSTALL_PROG) setmask  $(DESTDIR)$(sbindir)/setmask
+       $(INSTALL_PROG) xentrace_setmask  $(DESTDIR)$(sbindir)/xentrace_setmask
        $(INSTALL_PROG) xenmon.py  $(DESTDIR)$(sbindir)/xenmon.py
 
 .PHONY: clean
@@ -48,5 +48,5 @@ clean:
 
 %: %.c Makefile
        $(CC) $(CFLAGS) $(LDFLAGS) -lxenctrl -o $@ $<
-
-
+xentrace_%: %.c Makefile
+       $(CC) $(CFLAGS) $(LDFLAGS) -lxenctrl -o $@ $<
diff -r 91169603a8e8 -r 79afceca9065 tools/xenmon/xenbaked.c
--- a/tools/xenmon/xenbaked.c   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/xenmon/xenbaked.c   Wed Aug 23 11:11:27 2006 -0600
@@ -444,14 +444,11 @@ struct t_rec **init_rec_ptrs(struct t_bu
  */
 unsigned int get_num_cpus(void)
 {
-    dom0_op_t op;
+    xc_physinfo_t physinfo;
     int xc_handle = xc_interface_open();
     int ret;
 
-    op.cmd = DOM0_PHYSINFO;
-    op.interface_version = DOM0_INTERFACE_VERSION;
-
-    ret = xc_dom0_op(xc_handle, &op);
+    ret = xc_physinfo(xc_handle, &physinfo);
 
     if ( ret != 0 )
     {
@@ -460,12 +457,12 @@ unsigned int get_num_cpus(void)
     }
 
     xc_interface_close(xc_handle);
-    opts.cpu_freq = (double)op.u.physinfo.cpu_khz/1000.0;
-
-    return (op.u.physinfo.threads_per_core *
-            op.u.physinfo.cores_per_socket *
-            op.u.physinfo.sockets_per_node *
-            op.u.physinfo.nr_nodes);
+    opts.cpu_freq = (double)physinfo.cpu_khz/1000.0;
+
+    return (physinfo.threads_per_core *
+            physinfo.cores_per_socket *
+            physinfo.sockets_per_node *
+            physinfo.nr_nodes);
 }
 
 
diff -r 91169603a8e8 -r 79afceca9065 tools/xenstore/Makefile
--- a/tools/xenstore/Makefile   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/xenstore/Makefile   Wed Aug 23 11:11:27 2006 -0600
@@ -98,7 +98,7 @@ libxenstore.so.$(MAJOR).$(MINOR): xs.opi
        $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenstore.so.$(MAJOR) 
-shared -o $@ $^ -lpthread
 
 libxenstore.a: xs.o xs_lib.o
-       ar rcs libxenstore.a $^
+       $(AR) rcs libxenstore.a $^
 
 .PHONY: clean
 clean: testsuite-clean
diff -r 91169603a8e8 -r 79afceca9065 tools/xenstore/xs.c
--- a/tools/xenstore/xs.c       Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/xenstore/xs.c       Wed Aug 23 11:11:27 2006 -0600
@@ -101,23 +101,31 @@ static int get_socket(const char *connec
 static int get_socket(const char *connect_to)
 {
        struct sockaddr_un addr;
-       int sock, saved_errno;
+       int sock, saved_errno, flags;
 
        sock = socket(PF_UNIX, SOCK_STREAM, 0);
        if (sock < 0)
                return -1;
 
+       if ((flags = fcntl(sock, F_GETFD)) < 0)
+               goto error;
+       flags |= FD_CLOEXEC;
+       if (fcntl(sock, F_SETFD, flags) < 0)
+               goto error;
+
        addr.sun_family = AF_UNIX;
        strcpy(addr.sun_path, connect_to);
 
-       if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
-               saved_errno = errno;
-               close(sock);
-               errno = saved_errno;
-               return -1;
-       }
+       if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != 0)
+               goto error;
 
        return sock;
+
+error:
+       saved_errno = errno;
+       close(sock);
+       errno = saved_errno;
+       return -1;
 }
 
 static int get_dev(const char *connect_to)
diff -r 91169603a8e8 -r 79afceca9065 tools/xentrace/Makefile
--- a/tools/xentrace/Makefile   Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/xentrace/Makefile   Wed Aug 23 11:11:27 2006 -0600
@@ -14,7 +14,7 @@ HDRS     = $(wildcard *.h)
 HDRS     = $(wildcard *.h)
 OBJS     = $(patsubst %.c,%.o,$(wildcard *.c))
 
-BIN      = xentrace setsize
+BIN      = xentrace xentrace_setsize
 LIBBIN   = 
 SCRIPTS  = xentrace_format
 MAN1     = $(wildcard *.1)
@@ -58,3 +58,5 @@ clean:
 
 %: %.c $(HDRS) Makefile
        $(CC) $(CFLAGS) -o $@ $< -L$(XEN_LIBXC) -lxenctrl
+xentrace_%: %.c $(HDRS) Makefile
+       $(CC) $(CFLAGS) -o $@ $< -L$(XEN_LIBXC) -lxenctrl
diff -r 91169603a8e8 -r 79afceca9065 tools/xentrace/xentrace.c
--- a/tools/xentrace/xentrace.c Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/xentrace/xentrace.c Wed Aug 23 11:11:27 2006 -0600
@@ -55,6 +55,7 @@ typedef struct settings_st {
     unsigned long new_data_thresh;
     uint32_t evt_mask;
     uint32_t cpu_mask;
+    unsigned long tbuf_size;
 } settings_t;
 
 settings_t opts;
@@ -111,7 +112,10 @@ static void get_tbufs(unsigned long *mfn
         exit(EXIT_FAILURE);
     }
 
-    ret = xc_tbuf_enable(xc_handle, DEFAULT_TBUF_SIZE, mfn, size);
+    if(!opts.tbuf_size)
+      opts.tbuf_size = DEFAULT_TBUF_SIZE;
+
+    ret = xc_tbuf_enable(xc_handle, opts.tbuf_size, mfn, size);
 
     if ( ret != 0 )
     {
@@ -400,6 +404,15 @@ error_t cmd_parser(int key, char *arg, s
     }
     break;
     
+    case 'S': /* set tbuf size (given in pages) */
+    {
+        char *inval;
+        setup->tbuf_size = strtol(arg, &inval, 0);
+        if ( inval == arg )
+            argp_usage(state);
+    }
+    break;
+
     case ARGP_KEY_ARG:
     {
         if ( state->arg_num == 0 )
@@ -438,6 +451,12 @@ const struct argp_option cmd_opts[] =
     { .name = "evt-mask", .key='e', .arg="e",
       .doc = 
       "set evt-mask " },
+
+    { .name = "trace-buf-size", .key='S', .arg="N",
+      .doc =
+      "Set trace buffer size in pages (default " xstr(DEFAULT_TBUF_SIZE) "). "
+      "N.B. that the trace buffer cannot be resized.  If it has "
+      "already been set this boot cycle, this argument will be ignored." },
 
     {0}
 };
diff -r 91169603a8e8 -r 79afceca9065 tools/xm-test/lib/XmTestLib/XenDevice.py
--- a/tools/xm-test/lib/XmTestLib/XenDevice.py  Tue Aug 22 14:45:49 2006 -0600
+++ b/tools/xm-test/lib/XmTestLib/XenDevice.py  Wed Aug 23 11:11:27 2006 -0600
@@ -265,6 +265,7 @@ class XenNetDevice(XenDevice):
             self.ip = xmtest_netconf.getIP(self.domain.getName(), self.id)
 
         self.addIfconfigCmd()
+        self.config["ip"] = str(self.ip)
 
         # Setup an alias for Dom0
         self.dom0_alias_ip = xmtest_netconf.getIP("domain0", 
self.domain.getName())
diff -r 91169603a8e8 -r 79afceca9065 xen/Rules.mk
--- a/xen/Rules.mk      Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/Rules.mk      Wed Aug 23 11:11:27 2006 -0600
@@ -8,6 +8,9 @@ perfc_arrays?= n
 perfc_arrays?= n
 crash_debug ?= n
 
+XEN_ROOT=$(BASEDIR)/..
+include $(XEN_ROOT)/Config.mk
+
 # Hardcoded configuration implications and dependencies.
 # Do this is a neater way if it becomes unwieldy.
 ifeq ($(debug),y)
@@ -16,9 +19,6 @@ ifeq ($(perfc_arrays),y)
 ifeq ($(perfc_arrays),y)
 perfc := y
 endif
-
-XEN_ROOT=$(BASEDIR)/..
-include $(XEN_ROOT)/Config.mk
 
 # Set ARCH/SUBARCH appropriately.
 override COMPILE_SUBARCH := $(XEN_COMPILE_ARCH)
diff -r 91169603a8e8 -r 79afceca9065 xen/acm/acm_core.c
--- a/xen/acm/acm_core.c        Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/acm/acm_core.c        Wed Aug 23 11:11:27 2006 -0600
@@ -206,7 +206,7 @@ acm_setup(unsigned int *initrdidx,
     for (i = mbi->mods_count-1; i >= 1; i--)
     {
         struct acm_policy_buffer *pol;
-        char *_policy_start; 
+        char *_policy_start;
         unsigned long _policy_len;
 #if defined(__i386__)
         _policy_start = (char *)(initial_images_start + 
(mod[i].mod_start-mod[0].mod_start));
@@ -342,7 +342,7 @@ acm_init_domain_ssid(domid_t id, ssidref
     {
         printk("%s: ERROR instantiating individual ssids for domain 0x%02x.\n",
                __func__, subj->domain_id);
-        acm_free_domain_ssid(ssid); 
+        acm_free_domain_ssid(ssid);
         put_domain(subj);
         return ACM_INIT_SSID_ERROR;
     }
diff -r 91169603a8e8 -r 79afceca9065 xen/acm/acm_simple_type_enforcement_hooks.c
--- a/xen/acm/acm_simple_type_enforcement_hooks.c       Tue Aug 22 14:45:49 
2006 -0600
+++ b/xen/acm/acm_simple_type_enforcement_hooks.c       Wed Aug 23 11:11:27 
2006 -0600
@@ -86,10 +86,10 @@ int acm_init_ste_policy(void)
 
     /* init stats */
     atomic_set(&(ste_bin_pol.ec_eval_count), 0);
-    atomic_set(&(ste_bin_pol.ec_denied_count), 0); 
+    atomic_set(&(ste_bin_pol.ec_denied_count), 0);
     atomic_set(&(ste_bin_pol.ec_cachehit_count), 0);
     atomic_set(&(ste_bin_pol.gt_eval_count), 0);
-    atomic_set(&(ste_bin_pol.gt_denied_count), 0); 
+    atomic_set(&(ste_bin_pol.gt_denied_count), 0);
     atomic_set(&(ste_bin_pol.gt_cachehit_count), 0);
     return ACM_OK;
 }
@@ -100,7 +100,7 @@ ste_init_domain_ssid(void **ste_ssid, ss
 ste_init_domain_ssid(void **ste_ssid, ssidref_t ssidref)
 {
     int i;
-    struct ste_ssid *ste_ssidp = xmalloc(struct ste_ssid); 
+    struct ste_ssid *ste_ssidp = xmalloc(struct ste_ssid);
     traceprintk("%s.\n", __func__);
 
     if (ste_ssidp == NULL)
@@ -309,7 +309,7 @@ ste_set_policy(u8 *buf, u32 buf_size)
            sizeof(domaintype_t),
            ste_buf->ste_max_ssidrefs*ste_buf->ste_max_types);
 
-    /* 2. now re-calculate sharing decisions based on running domains; 
+    /* 2. now re-calculate sharing decisions based on running domains;
      *    this can fail if new policy is conflicting with sharing of running 
domains 
      *    now: reject violating new policy; future: adjust sharing through 
revoking sharing */
     if (ste_init_state(ste_buf, (domaintype_t *)ssidrefsbuf)) {
@@ -349,11 +349,11 @@ ste_dump_stats(u8 *buf, u16 buf_len)
     stats.ec_eval_count = htonl(atomic_read(&ste_bin_pol.ec_eval_count));
     stats.gt_eval_count = htonl(atomic_read(&ste_bin_pol.gt_eval_count));
     stats.ec_denied_count = htonl(atomic_read(&ste_bin_pol.ec_denied_count));
-    stats.gt_denied_count = htonl(atomic_read(&ste_bin_pol.gt_denied_count)); 
+    stats.gt_denied_count = htonl(atomic_read(&ste_bin_pol.gt_denied_count));
     stats.ec_cachehit_count = 
htonl(atomic_read(&ste_bin_pol.ec_cachehit_count));
     stats.gt_cachehit_count = 
htonl(atomic_read(&ste_bin_pol.gt_cachehit_count));
 
-    if (buf_len < sizeof(struct acm_ste_stats_buffer))
+    if (buf_len < sizeof(struct acm_ste_stats_buffer)
         return -ENOMEM;
 
     memcpy(buf, &stats, sizeof(struct acm_ste_stats_buffer));
@@ -523,8 +523,8 @@ ste_pre_eventchannel_unbound(domid_t id1
         cache_result(subj, obj);
         ret = ACM_ACCESS_PERMITTED;
     } else {
-        atomic_inc(&ste_bin_pol.ec_denied_count); 
-        ret = ACM_ACCESS_DENIED; 
+        atomic_inc(&ste_bin_pol.ec_denied_count);
+        ret = ACM_ACCESS_DENIED;
     }
   out:
     if (obj != NULL)
@@ -569,8 +569,8 @@ ste_pre_eventchannel_interdomain(domid_t
         cache_result(subj, obj);
         ret = ACM_ACCESS_PERMITTED;
     } else {
-        atomic_inc(&ste_bin_pol.ec_denied_count); 
-        ret = ACM_ACCESS_DENIED; 
+        atomic_inc(&ste_bin_pol.ec_denied_count);
+        ret = ACM_ACCESS_DENIED;
     }
  out:
     if (obj != NULL)
@@ -599,9 +599,9 @@ ste_pre_grant_map_ref (domid_t id) {
         cache_result(subj, obj);
         ret = ACM_ACCESS_PERMITTED;
     } else {
-        atomic_inc(&ste_bin_pol.gt_denied_count); 
+        atomic_inc(&ste_bin_pol.gt_denied_count);
         printkd("%s: ACCESS DENIED!\n", __func__);
-        ret = ACM_ACCESS_DENIED; 
+        ret = ACM_ACCESS_DENIED;
     }
     if (obj != NULL)
         put_domain(obj);
@@ -637,8 +637,8 @@ ste_pre_grant_setup (domid_t id) {
         cache_result(subj, obj);
         ret = ACM_ACCESS_PERMITTED;
     } else {
-        atomic_inc(&ste_bin_pol.gt_denied_count); 
-        ret = ACM_ACCESS_DENIED; 
+        atomic_inc(&ste_bin_pol.gt_denied_count);
+        ret = ACM_ACCESS_DENIED;
     }
     if (obj != NULL)
         put_domain(obj);
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/ia64/Rules.mk
--- a/xen/arch/ia64/Rules.mk    Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/ia64/Rules.mk    Wed Aug 23 11:11:27 2006 -0600
@@ -2,6 +2,7 @@
 # ia64-specific definitions
 
 HAS_ACPI := y
+HAS_VGA  := y
 VALIDATE_VT    ?= n
 no_warns ?= n
 
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/ia64/vmx/mmio.c
--- a/xen/arch/ia64/vmx/mmio.c  Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/ia64/vmx/mmio.c  Wed Aug 23 11:11:27 2006 -0600
@@ -33,7 +33,7 @@
 #include <public/hvm/ioreq.h>
 #include <asm/vmx.h>
 #include <public/event_channel.h>
-#include <public/arch-ia64.h>
+#include <public/xen.h>
 #include <linux/event.h>
 #include <xen/domain.h>
 /*
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/ia64/vmx/vlsapic.c
--- a/xen/arch/ia64/vmx/vlsapic.c       Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/ia64/vmx/vlsapic.c       Wed Aug 23 11:11:27 2006 -0600
@@ -21,7 +21,7 @@
  */
 
 #include <linux/sched.h>
-#include <public/arch-ia64.h>
+#include <public/xen.h>
 #include <asm/ia64_int.h>
 #include <asm/vcpu.h>
 #include <asm/regionreg.h>
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/ia64/vmx/vmx_init.c
--- a/xen/arch/ia64/vmx/vmx_init.c      Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/ia64/vmx/vmx_init.c      Wed Aug 23 11:11:27 2006 -0600
@@ -41,15 +41,14 @@
 #include <asm/vmx_vcpu.h>
 #include <xen/lib.h>
 #include <asm/vmmu.h>
-#include <public/arch-ia64.h>
+#include <public/xen.h>
 #include <public/hvm/ioreq.h>
+#include <public/event_channel.h>
 #include <asm/vmx_phy_mode.h>
 #include <asm/processor.h>
 #include <asm/vmx.h>
 #include <xen/mm.h>
-#include <public/arch-ia64.h>
 #include <asm/hvm/vioapic.h>
-#include <public/event_channel.h>
 #include <xen/event.h>
 #include <asm/vlsapic.h>
 
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/ia64/vmx/vmx_vcpu.c
--- a/xen/arch/ia64/vmx/vmx_vcpu.c      Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/ia64/vmx/vmx_vcpu.c      Wed Aug 23 11:11:27 2006 -0600
@@ -24,7 +24,7 @@
  */
 
 #include <xen/sched.h>
-#include <public/arch-ia64.h>
+#include <public/xen.h>
 #include <asm/ia64_int.h>
 #include <asm/vmx_vcpu.h>
 #include <asm/regionreg.h>
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/ia64/xen/domain.c
--- a/xen/arch/ia64/xen/domain.c        Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/ia64/xen/domain.c        Wed Aug 23 11:11:27 2006 -0600
@@ -35,14 +35,13 @@
 #include <asm/pgalloc.h>
 #include <asm/offsets.h>  /* for IA64_THREAD_INFO_SIZE */
 #include <asm/vcpu.h>   /* for function declarations */
-#include <public/arch-ia64.h>
+#include <public/xen.h>
 #include <xen/domain.h>
 #include <asm/vmx.h>
 #include <asm/vmx_vcpu.h>
 #include <asm/vmx_vpd.h>
 #include <asm/vmx_phy_mode.h>
 #include <asm/vhpt.h>
-#include <public/arch-ia64.h>
 #include <asm/tlbflush.h>
 #include <asm/regionreg.h>
 #include <asm/dom_fw.h>
@@ -665,11 +664,6 @@ int shadow_mode_control(struct domain *d
                }
                break;
 
-       case DOM0_SHADOW_CONTROL_OP_FLUSH:
-               atomic64_set(&d->arch.shadow_fault_count, 0);
-               atomic64_set(&d->arch.shadow_dirty_count, 0);
-               break;
-   
        case DOM0_SHADOW_CONTROL_OP_CLEAN:
          {
                int nbr_longs;
@@ -876,6 +870,7 @@ int construct_dom0(struct domain *d,
 {
        int i, rc;
        start_info_t *si;
+       dom0_vga_console_info_t *ci;
        struct vcpu *v = d->vcpu[0];
        unsigned long max_pages;
 
@@ -1012,6 +1007,9 @@ int construct_dom0(struct domain *d,
        //if ( initrd_len != 0 )
        //    memcpy((void *)vinitrd_start, initrd_start, initrd_len);
 
+       BUILD_BUG_ON(sizeof(start_info_t) + sizeof(dom0_vga_console_info_t) +
+                    sizeof(struct ia64_boot_param) > PAGE_SIZE);
+
        /* Set up start info area. */
        d->shared_info->arch.start_info_pfn = pstart_info >> PAGE_SHIFT;
        start_info_page = assign_new_domain_page(d, pstart_info);
@@ -1046,7 +1044,8 @@ int construct_dom0(struct domain *d,
        strncpy((char *)si->cmd_line, dom0_command_line, sizeof(si->cmd_line));
        si->cmd_line[sizeof(si->cmd_line)-1] = 0;
 
-       bp = (struct ia64_boot_param *)(si + 1);
+       bp = (struct ia64_boot_param *)((unsigned char *)si +
+                                       sizeof(start_info_t));
        bp->command_line = pstart_info + offsetof (start_info_t, cmd_line);
 
        /* We assume console has reached the last line!  */
@@ -1060,6 +1059,16 @@ int construct_dom0(struct domain *d,
                     (PAGE_ALIGN(ia64_boot_param->initrd_size) + 4*1024*1024);
        bp->initrd_size = ia64_boot_param->initrd_size;
 
+       ci = (dom0_vga_console_info_t *)((unsigned char *)si +
+                                        sizeof(start_info_t) +
+                                        sizeof(struct ia64_boot_param));
+
+       if (fill_console_start_info(ci)) {
+               si->console.dom0.info_off = sizeof(start_info_t) +
+                                           sizeof(struct ia64_boot_param);
+               si->console.dom0.info_size = sizeof(dom0_vga_console_info_t);
+       }
+
        vcpu_init_regs (v);
 
        vcpu_regs(v)->r28 = bp_mpa;
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/ia64/xen/hyperprivop.S
--- a/xen/arch/ia64/xen/hyperprivop.S   Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/ia64/xen/hyperprivop.S   Wed Aug 23 11:11:27 2006 -0600
@@ -14,7 +14,7 @@
 #include <asm/system.h>
 #include <asm/debugger.h>
 #include <asm/asm-xsi-offsets.h>
-#include <public/arch-ia64.h>
+#include <public/xen.h>
 
 
 #define        _PAGE_PPN_MASK  0x0003fffffffff000 //asm/pgtable.h doesn't do 
assembly
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/ia64/xen/mm.c
--- a/xen/arch/ia64/xen/mm.c    Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/ia64/xen/mm.c    Wed Aug 23 11:11:27 2006 -0600
@@ -1581,11 +1581,6 @@ void pgtable_quicklist_free(void *pgtabl
        free_xenheap_page(pgtable_entry);
 }
 
-void cleanup_writable_pagetable(struct domain *d)
-{
-  return;
-}
-
 void put_page_type(struct page_info *page)
 {
     u32 nx, x, y = page->u.inuse.type_info;
@@ -1693,22 +1688,6 @@ int get_page_type(struct page_info *page
             {
                 if ( unlikely((x & PGT_type_mask) != (type & PGT_type_mask) ) )
                 {
-                    if ( current->domain == page_get_owner(page) )
-                    {
-                        /*
-                         * This ensures functions like set_gdt() see up-to-date
-                         * type info without needing to clean up writable p.t.
-                         * state on the fast path.
-                         */
-                        LOCK_BIGLOCK(current->domain);
-                        cleanup_writable_pagetable(current->domain);
-                        y = page->u.inuse.type_info;
-                        UNLOCK_BIGLOCK(current->domain);
-                        /* Can we make progress now? */
-                        if ( ((y & PGT_type_mask) == (type & PGT_type_mask)) ||
-                             ((y & PGT_count_mask) == 0) )
-                            goto again;
-                    }
                     if ( ((x & PGT_type_mask) != PGT_l2_page_table) ||
                          ((type & PGT_type_mask) != PGT_l1_page_table) )
                         MEM_LOG("Bad type (saw %08x != exp %08x) "
@@ -1768,6 +1747,11 @@ int get_page_type(struct page_info *page
     return 1;
 }
 
+int memory_is_conventional_ram(paddr_t p)
+{
+    return (efi_mem_type(p) == EFI_CONVENTIONAL_MEMORY);
+}
+
 /*
  * Local variables:
  * mode: C
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/ia64/xen/vcpu.c
--- a/xen/arch/ia64/xen/vcpu.c  Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/ia64/xen/vcpu.c  Wed Aug 23 11:11:27 2006 -0600
@@ -7,7 +7,7 @@
  */
 
 #include <linux/sched.h>
-#include <public/arch-ia64.h>
+#include <public/xen.h>
 #include <xen/mm.h>
 #include <asm/ia64_int.h>
 #include <asm/vcpu.h>
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/ia64/xen/xenasm.S
--- a/xen/arch/ia64/xen/xenasm.S        Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/ia64/xen/xenasm.S        Wed Aug 23 11:11:27 2006 -0600
@@ -11,7 +11,7 @@
 #include <asm/pgtable.h>
 #include <asm/vhpt.h>
 #include <asm/asm-xsi-offsets.h>
-#include <public/arch-ia64.h>
+#include <public/xen.h>
        
 // Change rr7 to the passed value while ensuring
 // Xen is mapped into the new region.
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/powerpc/Makefile
--- a/xen/arch/powerpc/Makefile Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/powerpc/Makefile Wed Aug 23 11:11:27 2006 -0600
@@ -49,7 +49,7 @@ PPC_C_WARNINGS += -Wundef -Wmissing-prot
 PPC_C_WARNINGS += -Wundef -Wmissing-prototypes -Wmissing-declarations
 CFLAGS += $(PPC_C_WARNINGS)
 
-LINK=0x3000000
+LINK=0x400000
 boot32_link_base = $(LINK)
 xen_link_offset  = 100
 xen_link_base    = $(patsubst %000,%$(xen_link_offset),$(LINK))
@@ -82,6 +82,11 @@ physdev.o: ../x86/physdev.c
 physdev.o: ../x86/physdev.c
 
 HDRS += $(wildcard *.h)
+
+# The first token in the arguments will be silently dropped.
+IMAGENAME = xen
+CMDLINE = ""
+boot_of.o: CFLAGS += -DCMDLINE="\"$(IMAGENAME) $(CMDLINE)\""
 
 start.o: boot/start.S
        $(CC) $(CFLAGS) -D__ASSEMBLY__ -c $< -o $@
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/powerpc/boot_of.c
--- a/xen/arch/powerpc/boot_of.c        Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/powerpc/boot_of.c        Wed Aug 23 11:11:27 2006 -0600
@@ -13,7 +13,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
- * Copyright (C) IBM Corp. 2005
+ * Copyright (C) IBM Corp. 2005, 2006
  *
  * Authors: Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
  */
@@ -36,6 +36,10 @@ static int of_out;
 static int of_out;
 static ofdn_t boot_cpu;
 static char bootargs[256];
+
+#define COMMAND_LINE_SIZE 512
+static char builtin_cmdline[COMMAND_LINE_SIZE]
+    __attribute__((section("__builtin_cmdline"))) = CMDLINE;
 
 extern struct ns16550_defaults ns16550;
 
@@ -300,12 +304,11 @@ static int __init of_instance_to_path(in
 
 static int __init of_start_cpu(int cpu, u32 pc, u32 reg)
 {
-    int rets[1] = { OF_FAILURE };
-
-    if ( of_call("start-cpu", 3, 0, rets, cpu, pc, reg) == OF_FAILURE )
-        return OF_FAILURE;
-
-    return rets[0];
+    int ret;
+
+    ret = of_call("start-cpu", 3, 0, NULL, cpu, pc, reg);
+
+    return ret;
 }
 
 static void __init of_test(const char *of_method_name)
@@ -449,8 +452,8 @@ static void boot_of_bootargs(multiboot_i
     int rc;
 
     rc = of_getprop(bof_chosen, "bootargs", &bootargs, sizeof (bootargs));
-    if (rc == OF_FAILURE) {
-        strcpy(bootargs, "xen");
+    if (rc == OF_FAILURE || bootargs[0] == '\0') {
+        strlcpy(bootargs, builtin_cmdline, sizeof(bootargs));
     }
 
     mbi->flags |= MBI_CMDLINE;
@@ -756,19 +759,30 @@ static int __init boot_of_serial(void *o
     if (n == OF_FAILURE) {
         of_panic("instance-to-package of /chosen/stdout: failed\n");
     }
-
-    /* prune this from the oftree */
-    rc = of_package_to_path(n, buf, sizeof(buf));
-    if (rc == OF_FAILURE) {
-        of_panic("package-to-path of /chosen/stdout: failed\n");
-    }
-    of_printf("Pruning from devtree: %s\n"
-              "  since Xen will be using it for console\n", buf);
-    rc = ofd_prune_path(oftree, buf);
-    if (rc < 0) {
-        of_panic("prune path \"%s\" failed\n", buf);
-    }
     
+    /* Prune all serial devices from the device tree, including the
+     * one pointed to by /chosen/stdout, because a guest domain can
+     * initialize them and in so doing corrupt our console output.
+     */
+    for (p = n; p > 0; p = of_getpeer(p)) {
+        char type[32];
+
+        rc = of_package_to_path(p, buf, sizeof(buf));
+        if (rc == OF_FAILURE)
+            of_panic("package-to-path failed\n");
+
+        rc = of_getprop(p, "device_type", type, sizeof (type));
+        if (rc == OF_FAILURE)
+            of_panic("fetching device type failed\n");
+
+        if (strcmp(type, "serial") != 0)
+            continue;
+
+        of_printf("pruning `%s' from devtree\n", buf);
+        rc = ofd_prune_path(oftree, buf);
+        if (rc < 0)
+            of_panic("prune of `%s' failed\n", buf);
+    }
 
     p = of_getparent(n);
     if (p == OF_FAILURE) {
@@ -795,7 +809,6 @@ static int __init boot_of_serial(void *o
     if (rc == OF_FAILURE) {
         of_panic("%s: no location for serial port\n", __func__);
     }
-    ns16550.io_base = val[1];
 
     ns16550.baud = BAUD_AUTO;
     ns16550.data_bits = 8;
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/powerpc/dom0_ops.c
--- a/xen/arch/powerpc/dom0_ops.c       Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/powerpc/dom0_ops.c       Wed Aug 23 11:11:27 2006 -0600
@@ -40,23 +40,40 @@ long arch_do_dom0_op(struct dom0_op *op,
     long ret = 0;
 
     switch (op->cmd) {
-    case DOM0_GETMEMLIST: {
-        /* XXX 64M hackage */
-        const int memsize = (64UL<<20);
-        int domain_pfns = memsize>>12;
-        int max_pfns = op->u.getmemlist.max_pfns;
-        int domid = op->u.getmemlist.domain;
+    case DOM0_GETMEMLIST:
+    {
         int i;
+        struct domain *d = find_domain_by_id(op->u.getmemlist.domain);
+        unsigned long max_pfns = op->u.getmemlist.max_pfns;
+        xen_pfn_t mfn;
+        struct list_head *list_ent;
 
-        for (i = 0; (i < max_pfns) && (i < domain_pfns); i++) {
-            xen_pfn_t mfn = (((domid + 1) * memsize) >> 12) + i;
-            if (copy_to_guest_offset(op->u.getmemlist.buffer, i, &mfn, 1)) {
-                ret = -EFAULT;
-                break;
+        ret = -EINVAL;
+        if ( d != NULL )
+        {
+            ret = 0;
+
+            spin_lock(&d->page_alloc_lock);
+            list_ent = d->page_list.next;
+            for ( i = 0; (i < max_pfns) && (list_ent != &d->page_list); i++ )
+            {
+                mfn = page_to_mfn(list_entry(
+                    list_ent, struct page_info, list));
+                if ( copy_to_guest_offset(op->u.getmemlist.buffer,
+                                          i, &mfn, 1) )
+                {
+                    ret = -EFAULT;
+                    break;
+                }
+                list_ent = mfn_to_page(mfn)->list.next;
             }
+            spin_unlock(&d->page_alloc_lock);
+
+            op->u.getmemlist.num_pfns = i;
+            copy_to_guest(u_dom0_op, op, 1);
+            
+            put_domain(d);
         }
-        op->u.getmemlist.num_pfns = i;
-        copy_to_guest(u_dom0_op, op, 1);
     }
     break;
 
diff -r 91169603a8e8 -r 79afceca9065 xen/arch/powerpc/domain.c
--- a/xen/arch/powerpc/domain.c Tue Aug 22 14:45:49 2006 -0600
+++ b/xen/arch/powerpc/domain.c Wed Aug 23 11:11:27 2006 -0600
@@ -73,6 +73,9 @@ unsigned long hypercall_create_continuat
 
 int arch_domain_create(struct domain *d)
 {
+    unsigned long rma_base;
+    unsigned long rma_sz;
+    uint htab_order;
 
     if (d->domain_id == IDLE_DOMAIN_ID) {
         d->shared_info = (void *)alloc_xenheap_page();
@@ -81,27 +84,44 @@ int arch_domain_create(struct domain *d)
         return 0;
     }
 
-    /* XXX the hackage... hardcode 64M domains */
-    d->arch.rma_base = (64<<20) * (d->domain_id + 1);
-    d->arch.rma_size = (64<<20);
-
-    printk("clearing RMO: 0x%lx[0x%lx]\n", d->arch.rma_base, d->arch.rma_size);
-    memset((void*)d->arch.rma_base, 0, d->arch.rma_size);
-
-    htab_alloc(d, LOG_DEFAULT_HTAB_BYTES);
+    d->arch.rma_order = cpu_rma_order();
+    rma_sz = rma_size(d->arch.rma_order);
+
+    /* allocate the real mode area */
+    d->max_pages = 1UL << d->arch.rma_order;
+    d->tot_pages = 0;
+    d->arch.rma_page = alloc_domheap_pages(d, d->arch.rma_order, 0);
+    if (NULL == d->arch.rma_page)
+        return 1;
+    rma_base = page_to_maddr(d->arch.rma_page);
+
+    BUG_ON(rma_base & (rma_sz - 1)); /* check alignment */
+
+    printk("clearing RMO: 0x%lx[0x%lx]\n", rma_base, rma_sz);
+    memset((void *)rma_base, 0, rma_sz);
 
     d->shared_info = (shared_info_t *)
-        (rma_addr(&d->arch, RMA_SHARED_INFO) + d->arch.rma_base);
+        (rma_addr(&d->arch, RMA_SHARED_INFO) + rma_base);
 
     d->arch.large_page_sizes = 1;
     d->arch.large_page_shift[0] = 24; /* 16 M for 970s */
 
+    /* FIXME: we need to the the maximum addressible memory for this
+     * domain to calculate this correctly. It should probably be set
+     * by the managment tools */
+    htab_order = d->arch.rma_order - 6; /* (1/64) */
+    if (test_bit(_DOMF_privileged, &d->domain_flags)) {
+        /* bump the htab size of privleged domains */
+        ++htab_order;
+    }
+    htab_alloc(d, htab_order);
+
     return 0;
 }
 
 void arch_domain_destroy(struct domain *d)
 {
-    unimplemented();
+    htab_free(d);
 }
 
 void machine_halt(void)
@@ -243,7 +263,7 @@ void sync_vcpu_execstate(struct vcpu *v)
 
 void domain_relinquish_resources(struct domain *d)
 {
-    /* nothing to do? */
+    free_domheap_pages(d->arch.rma_page, d->arch.rma_order);
 }
 
 void arch_dump_domain_info(struct domain *d)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog